|
|
@@ -539,14 +539,15 @@ class Transaction{
|
|
|
|
|
|
module.exports = Transaction;
|
|
|
},{}],6:[function(require,module,exports){
|
|
|
-const Transaction = require("./Transaction");
|
|
|
-
|
|
|
let analytics = {
|
|
|
+ dateChange: false,
|
|
|
transactions: [],
|
|
|
ingredient: {},
|
|
|
recipe: {},
|
|
|
|
|
|
- display: function(){
|
|
|
+ display: function(Transaction){
|
|
|
+ document.getElementById("analDateBtn").onclick = ()=>{this.changeDates(Transaction)};
|
|
|
+
|
|
|
if(this.transactions.length === 0){
|
|
|
let startDate = new Date();
|
|
|
startDate.setMonth(startDate.getMonth() - 1);
|
|
|
@@ -556,7 +557,7 @@ let analytics = {
|
|
|
}
|
|
|
|
|
|
let slider = document.getElementById("analSlider");
|
|
|
- slider.onchange = ()=>{this.display()};
|
|
|
+ slider.onchange = ()=>{this.display(Transaction)};
|
|
|
|
|
|
let ingredientContent = document.getElementById("analIngredientContent");
|
|
|
let recipeContent = document.getElementById("analRecipeContent");
|
|
|
@@ -575,13 +576,6 @@ let analytics = {
|
|
|
displayIngredients: function(){
|
|
|
const itemsList = document.getElementById("itemsList");
|
|
|
|
|
|
- let now = new Date();
|
|
|
- let lastMonth = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate(), now.getHours(), now.getMinutes());
|
|
|
-
|
|
|
- document.getElementById("analStartDate").valueAsDate = lastMonth;
|
|
|
- document.getElementById("analEndDate").valueAsDate = now;
|
|
|
- document.getElementById("analDateBtn").onclick = ()=>{this.changeDates()};
|
|
|
-
|
|
|
while(itemsList.children.length > 0){
|
|
|
itemsList.removeChild(itemsList.firstChild);
|
|
|
}
|
|
|
@@ -604,6 +598,11 @@ let analytics = {
|
|
|
};
|
|
|
itemsList.appendChild(li);
|
|
|
}
|
|
|
+
|
|
|
+ if(this.dateChange && Object.keys(this.ingredient).length !== 0){
|
|
|
+ this.ingredientDisplay();
|
|
|
+ }
|
|
|
+ this.dateChange = false;
|
|
|
},
|
|
|
|
|
|
displayRecipes: function(){
|
|
|
@@ -630,6 +629,11 @@ let analytics = {
|
|
|
|
|
|
recipeList.appendChild(li);
|
|
|
}
|
|
|
+
|
|
|
+ if(this.dateChange && Object.keys(this.recipe).length !== 0){
|
|
|
+ this.recipeDisplay();
|
|
|
+ }
|
|
|
+ this.dateChange = false;
|
|
|
},
|
|
|
|
|
|
ingredientDisplay: function(){
|
|
|
@@ -783,12 +787,10 @@ let analytics = {
|
|
|
}
|
|
|
|
|
|
document.getElementById("recipeAvgUse").innerText = (sum / quantities.length).toFixed(2);
|
|
|
- console.log(sum / quantities.length);
|
|
|
- console.log(this.recipe.price);
|
|
|
document.getElementById("recipeAvgRevenue").innerText = `$${(((sum / quantities.length) * this.recipe.price) / 100).toFixed(2)}`;
|
|
|
},
|
|
|
|
|
|
- changeDates: function(){
|
|
|
+ changeDates: function(Transaction){
|
|
|
let dates = {
|
|
|
from: document.getElementById("analStartDate").valueAsDate,
|
|
|
to: document.getElementById("analEndDate").valueAsDate
|
|
|
@@ -814,7 +816,7 @@ let analytics = {
|
|
|
if(typeof(response) === "string"){
|
|
|
banner.createError(response.data);
|
|
|
}else{
|
|
|
- this.transactions = [];
|
|
|
+ this.transactions = [];
|
|
|
|
|
|
for(let i = 0; i < response.length; i++){
|
|
|
this.transactions.push(new Transaction(
|
|
|
@@ -824,8 +826,15 @@ let analytics = {
|
|
|
merchant
|
|
|
));
|
|
|
}
|
|
|
+
|
|
|
+ let isRecipe = document.getElementById("analSlider").checked;
|
|
|
+ if(isRecipe && Object.keys(this.recipe).length !== 0){
|
|
|
+ this.recipeDisplay();
|
|
|
+ }else if(!isRecipe && Object.keys(this.ingredient).length !== 0){
|
|
|
+ this.ingredientDisplay();
|
|
|
+ }
|
|
|
|
|
|
- this.ingredientDisplay();
|
|
|
+ this.dateChange = true;
|
|
|
}
|
|
|
})
|
|
|
.catch((err)=>{
|
|
|
@@ -838,7 +847,7 @@ let analytics = {
|
|
|
}
|
|
|
|
|
|
module.exports = analytics;
|
|
|
-},{"./Transaction":5}],7:[function(require,module,exports){
|
|
|
+},{}],7:[function(require,module,exports){
|
|
|
const home = require("./home.js");
|
|
|
const ingredients = require("./ingredients.js");
|
|
|
const recipeBook = require("./recipeBook.js");
|
|
|
@@ -898,7 +907,7 @@ controller = {
|
|
|
case "analytics":
|
|
|
activeButton = document.getElementById("analyticsBtn");
|
|
|
document.getElementById("analyticsStrand").style.display = "flex";
|
|
|
- analytics.display();
|
|
|
+ analytics.display(Transaction);
|
|
|
break;
|
|
|
case "orders":
|
|
|
activeButton = document.getElementById("ordersBtn");
|