|
|
@@ -1,5 +1,6 @@
|
|
|
window.homeStrandObj = {
|
|
|
isPopulated: false,
|
|
|
+ graph: {},
|
|
|
|
|
|
display: function(){
|
|
|
if(!this.isPopulated){
|
|
|
@@ -24,6 +25,28 @@ window.homeStrandObj = {
|
|
|
document.querySelector("#revenueChange p").innerText = `${Math.abs(revenueChange).toFixed(2)}% vs last month`;
|
|
|
document.querySelector("#revenueChange img").src = img;
|
|
|
|
|
|
+ this.graph = new LineGraph(
|
|
|
+ document.querySelector("#graphCanvas"),
|
|
|
+ "$",
|
|
|
+ "Date"
|
|
|
+ )
|
|
|
+
|
|
|
+ let thirtyAgo = new Date(today);
|
|
|
+ thirtyAgo.setDate(today.getDate() - 29);
|
|
|
+
|
|
|
+ this.graph.addData(
|
|
|
+ this.graphData(dateIndices(thirtyAgo)),
|
|
|
+ [thirtyAgo, new Date()],
|
|
|
+ "Revenue"
|
|
|
+ );
|
|
|
+
|
|
|
+ let ul = document.querySelector("#inventoryCheckCard ul");
|
|
|
+ for(let i = 0; i < 5; i++){
|
|
|
+ let li = document.createElement("li");
|
|
|
+ li.innerText = merchant.inventory[i].ingredient.name;
|
|
|
+ ul.appendChild(li);
|
|
|
+ }
|
|
|
+
|
|
|
this.isPopulated = true;
|
|
|
}
|
|
|
},
|
|
|
@@ -42,5 +65,28 @@ window.homeStrandObj = {
|
|
|
}
|
|
|
|
|
|
return total / 100;
|
|
|
+ },
|
|
|
+
|
|
|
+ graphData: function(indices){
|
|
|
+ let dataList = new Array(30).fill(0);
|
|
|
+ let currentDate = transactions[indices[0]].date;
|
|
|
+ let arrayIndex = 0;
|
|
|
+
|
|
|
+ for(let i = indices[0]; i <= indices[1]; i++){
|
|
|
+ if(transactions[i].date.getDate() !== currentDate.getDate()){
|
|
|
+ currentDate = transactions[i].date;
|
|
|
+ arrayIndex++;
|
|
|
+ }
|
|
|
+ for(let recipe of transactions[i].recipes){
|
|
|
+ for(let merchRecipe of merchant.recipes){
|
|
|
+ if(recipe.recipe === merchRecipe._id){
|
|
|
+ dataList[arrayIndex] = parseFloat((dataList[arrayIndex] + (recipe.quantity * merchRecipe.price) / 100).toFixed(2));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return dataList;
|
|
|
}
|
|
|
}
|