Przeglądaj źródła

Fix bug of incorrect dates being used for data

Lee Morgan 6 lat temu
rodzic
commit
8c84860936

+ 2 - 2
views/dataPage/data.ejs

@@ -108,11 +108,11 @@
         <div id="recipeStrand" class="strand">
             <div class="dates">
                 <label>From:
-                    <input id="recipeFrom" type="date" onchange="window.ingredientObj.newDates()">
+                    <input id="recipeFrom" type="date" onchange="window.recipeObj.newDates()">
                 </label>
                 
                 <label>To:
-                    <input id="recipeTo" type="date" onchange="window.ingredientObj.newDates()">
+                    <input id="recipeTo" type="date" onchange="window.recipeObj.newDates()">
                 </label>
             </div>
 

+ 12 - 3
views/dataPage/home.js

@@ -12,7 +12,8 @@ window.homeObj = {
         if(!this.isPopulated){
             this.populate(data.transactions);
 
-            document.querySelector("#homeFrom").valueAsDate = new Date(new Date().getFullYear(), new Date().getMonth(), 1);
+            let date = new Date(new Date().getFullYear(), new Date().getMonth(), 1);
+            document.querySelector("#homeFrom").valueAsDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 12);
             document.querySelector("#homeTo").valueAsDate = new Date();
 
             this.isPopulated = true;
@@ -20,7 +21,6 @@ window.homeObj = {
     },
 
     populate: function(transactions){
-        console.log(transactions);
         this.recipeTotal = 0;
         this.revenueTotal = 0;
         
@@ -60,7 +60,12 @@ window.homeObj = {
         }
         
         //Populate number of recipes sold
+        let i = 0;
         for(let transaction of transactions){
+            // if(i === 0){
+            //     console.log(transaction);
+            //     i++;
+            // }
             for(let recipe of transaction.recipes){
                 for(let newRecipe of recipes){
                     if(recipe.recipe === newRecipe.id){
@@ -183,6 +188,9 @@ window.homeObj = {
         }else{
             from = new Date(from);
             to = new Date(to);
+
+            from.setMinutes(from.getMinutes() + from.getTimezoneOffset());
+            to.setMinutes(to.getMinutes() + to.getTimezoneOffset());
         }
 
         if(validator.transaction.date(from, to)){
@@ -204,7 +212,8 @@ window.homeObj = {
                     }
                 }
     
-                this.populate(data.transactions.slice(startIndex, endIndex));
+                let newData = data.transactions.slice(startIndex, endIndex);
+                this.populate(newData);
             });
         }
     }

+ 7 - 3
views/dataPage/ingredient.js

@@ -8,7 +8,8 @@ window.ingredientObj = {
         document.querySelector("strand-selector").setAttribute("strand", "ingredient");
 
         if(!this.isPopulated){
-            document.querySelector("#ingredientFrom").valueAsDate = new Date(new Date().getFullYear(), new Date().getMonth(), 1);
+            let date = new Date(new Date().getFullYear(), new Date().getMonth(), 1);
+            document.querySelector("#ingredientFrom").valueAsDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 12);
             document.querySelector("#ingredientTo").valueAsDate = new Date();
 
             let ingredientsDiv = document.querySelector("#ingredientOptions");
@@ -96,8 +97,8 @@ window.ingredientObj = {
     },
 
     newDates: function(){
-        let from = document.querySelector("#ingredientFrom").valueAsDate;
-        let to  = document.querySelector("#ingredientTo").valueAsDate;
+        let from = document.querySelector("#ingredientFrom").value;
+        let to  = document.querySelector("#ingredientTo").value;
 
         if(from === "" || to === ""){
             banner.createError("Invalid date");
@@ -105,6 +106,9 @@ window.ingredientObj = {
         }else{
             from = new Date(from);
             to = new Date(to);
+
+            from.setMinutes(from.getMinutes() + from.getTimezoneOffset());
+            to.setMinutes(to.getMinutes() + to.getTimezoneOffset());
         }
 
         if(validator.transaction.date(from, to)){

+ 7 - 3
views/dataPage/recipe.js

@@ -8,7 +8,8 @@ window.recipeObj = {
         document.querySelector("strand-selector").setAttribute("strand", "recipe");
 
         if(!this.isPopulated){
-            document.querySelector("#recipeFrom").valueAsDate = new Date(new Date().getFullYear(), new Date().getMonth(), 1);
+            let date = new Date(new Date().getFullYear(), new Date().getMonth(), 1);
+            document.querySelector("#recipeFrom").valueAsDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 12);
             document.querySelector("#recipeTo").valueAsDate = new Date();
 
             let recipesDiv = document.querySelector("#recipeOptions");
@@ -89,8 +90,8 @@ window.recipeObj = {
     },
 
     newDates: function(){
-        let from = document.querySelector("recipeFrom").valueAsDate;
-        let to = document.querySelector("recipeTo").valueAsDate;
+        let from = document.querySelector("#recipeFrom").value;
+        let to = document.querySelector("#recipeTo").value;
 
         if(from === "" || to === ""){
             banner.createError("Invalid date");
@@ -98,6 +99,9 @@ window.recipeObj = {
         }else{
             from = new Date(from);
             to = new Date(to);
+
+            from.setMinutes(from.getMinutes() + from.getTimezoneOffset());
+            to.setMinutes(to.getMinutes() + to.getTimezoneOffset());
         }
 
         if(validator.transaction.date(from, to)){