Bläddra i källkod

Update home page for a bug introduced from changing transaction list order

Lee Morgan 5 år sedan
förälder
incheckning
9aefd6a816
3 ändrade filer med 18 tillägg och 10 borttagningar
  1. 9 5
      views/dashboardPage/bundle.js
  2. 6 3
      views/dashboardPage/js/dashboard.js
  3. 3 2
      views/dashboardPage/js/home.js

+ 9 - 5
views/dashboardPage/bundle.js

@@ -1071,17 +1071,19 @@ controller = {
     Note: Will return false if it cannot find both necessary dates
     */
     transactionIndices(transactions, from, to = new Date()){
+        console.log(from);
+        console.log(to);
         let indices = [];
 
         for(let i = 0; i < transactions.length; i++){
-            if(transactions[i].date > from){
+            if(transactions[i].date < to){
                 indices.push(i);
                 break;
             }
         }
 
-        for(let i = transactions.length - 1; i >=0; i--){
-            if(transactions[i].date < to){
+        for(let i = transactions.length - 1; i >= 0; i--){
+            if(transactions[i].date > from){
                 indices.push(i);
                 break;
             }
@@ -1091,6 +1093,7 @@ controller = {
             return false;
         }
 
+        console.log(indices);
         return indices;
     },
 
@@ -1201,12 +1204,13 @@ let home = {
         let firstOfLastMonth = new Date(today.getFullYear(), today.getMonth() - 1, 1);
         let lastMonthToDay = new Date(new Date().setMonth(today.getMonth() - 1));
 
+        console.log("here");
         let revenueThisMonth = merchant.revenue(controller.transactionIndices(merchant.transactions, firstOfMonth));
-        let revenueLastmonthToDay = merchant.revenue(controller.transactionIndices(merchant.transactions, firstOfLastMonth, lastMonthToDay));
+        let revenueLastMonthToDay = merchant.revenue(controller.transactionIndices(merchant.transactions, firstOfLastMonth, lastMonthToDay));
 
         document.getElementById("revenue").innerText = `$${revenueThisMonth.toLocaleString("en")}`;
 
-        let revenueChange = ((revenueThisMonth - revenueLastmonthToDay) / revenueLastmonthToDay) * 100;
+        let revenueChange = ((revenueThisMonth - revenueLastMonthToDay) / revenueLastMonthToDay) * 100;
         
         let img = "";
         if(revenueChange >= 0){

+ 6 - 3
views/dashboardPage/js/dashboard.js

@@ -255,17 +255,19 @@ controller = {
     Note: Will return false if it cannot find both necessary dates
     */
     transactionIndices(transactions, from, to = new Date()){
+        console.log(from);
+        console.log(to);
         let indices = [];
 
         for(let i = 0; i < transactions.length; i++){
-            if(transactions[i].date > from){
+            if(transactions[i].date < to){
                 indices.push(i);
                 break;
             }
         }
 
-        for(let i = transactions.length - 1; i >=0; i--){
-            if(transactions[i].date < to){
+        for(let i = transactions.length - 1; i >= 0; i--){
+            if(transactions[i].date > from){
                 indices.push(i);
                 break;
             }
@@ -275,6 +277,7 @@ controller = {
             return false;
         }
 
+        console.log(indices);
         return indices;
     },
 

+ 3 - 2
views/dashboardPage/js/home.js

@@ -18,12 +18,13 @@ let home = {
         let firstOfLastMonth = new Date(today.getFullYear(), today.getMonth() - 1, 1);
         let lastMonthToDay = new Date(new Date().setMonth(today.getMonth() - 1));
 
+        console.log("here");
         let revenueThisMonth = merchant.revenue(controller.transactionIndices(merchant.transactions, firstOfMonth));
-        let revenueLastmonthToDay = merchant.revenue(controller.transactionIndices(merchant.transactions, firstOfLastMonth, lastMonthToDay));
+        let revenueLastMonthToDay = merchant.revenue(controller.transactionIndices(merchant.transactions, firstOfLastMonth, lastMonthToDay));
 
         document.getElementById("revenue").innerText = `$${revenueThisMonth.toLocaleString("en")}`;
 
-        let revenueChange = ((revenueThisMonth - revenueLastmonthToDay) / revenueLastmonthToDay) * 100;
+        let revenueChange = ((revenueThisMonth - revenueLastMonthToDay) / revenueLastMonthToDay) * 100;
         
         let img = "";
         if(revenueChange >= 0){