瀏覽代碼

Fix revenue graph not displaying data

Lee Morgan 6 年之前
父節點
當前提交
6479d101d7
共有 2 個文件被更改,包括 31 次插入34 次删除
  1. 30 0
      views/dashboardPage/Merchant.js
  2. 1 34
      views/dashboardPage/home.js

+ 30 - 0
views/dashboardPage/Merchant.js

@@ -320,6 +320,36 @@ class Merchant{
 
         return recipeList;
     }
+
+    /*
+    Create revenue data for graphing
+    Input:
+        dateRange: [start index, end index] (this.transactionIndices)
+    Return:
+        [total revenue for each day]
+    */
+    graphDailyRevenue(dateRange){
+        if(!dateRange){
+            return false;
+        }
+
+        let dataList = new Array(30).fill(0);
+        let currentDate = this.transactions[dateRange[0]].date;
+        let arrayIndex = 0;
+
+        for(let i = dateRange[0]; i <= dateRange[1]; i++){
+            if(this.transactions[i].date.getDate() !== currentDate.getDate()){
+                currentDate = this.transactions[i].date;
+                arrayIndex++;
+            }
+
+            for(let j = 0; j < this.transactions[i].recipes.length; j++){
+                dataList[arrayIndex] += this.transactions[i].recipes[j].recipe.price * this.transactions[i].recipes[j].quantity;
+            }
+        }
+
+        return dataList;
+    }
 }
 
 class Order{

+ 1 - 34
views/dashboardPage/home.js

@@ -49,7 +49,7 @@ window.homeStrandObj = {
         let thirtyAgo = new Date(today);
         thirtyAgo.setDate(today.getDate() - 29);
 
-        let data = this.graphData(merchant.transactionIndices(thirtyAgo));
+        let data = merchant.graphDailyRevenue(merchant.transactionIndices(thirtyAgo));
         if(data){
             this.graph.addData(
                 data,
@@ -146,39 +146,6 @@ window.homeStrandObj = {
         }
     },
 
-    /*
-    Create the data for the revenue graph
-    Input: 
-        dateRange: Array containing start and end indices for transactions
-    Return: List of revenue by day between the dates specified
-    */
-    graphData: function(dateRange){
-        if(!dateRange){
-            return false;
-        }
-
-        let dataList = new Array(30).fill(0);
-        let currentDate = merchant.transactions[dateRange[0]].date;
-        let arrayIndex = 0;
-
-        for(let i = dateRange[0]; i <= dateRange[1]; i++){
-            if(merchant.transactions[i].date.getDate() !== currentDate.getDate()){
-                currentDate = merchant.transactions[i].date;
-                arrayIndex++;
-            }
-            for(let j = 0; j < merchant.transactions[i].recipes.length; j++){
-                for(let merchRecipe of merchant.recipes){
-                    if(merchant.transactions[i].recipes[j].recipe === merchRecipe._id){
-                        dataList[arrayIndex] = parseFloat((dataList[arrayIndex] + (merchant.transactions[i].recipes[j].quantity * merchRecipe.price) / 100).toFixed(2));
-                        break;
-                    }
-                }
-            }
-        }
-
-        return dataList;
-    },
-
     submitInventoryCheck: function(){
         let lis = document.querySelectorAll("#inventoryCheckCard li");