Procházet zdrojové kódy

Update problems with transactions not accurately displaying count of recipes

Lee Morgan před 6 roky
rodič
revize
63aae5492f

+ 2 - 0
views/dashboardPage/Merchant.js

@@ -44,8 +44,10 @@ class Transaction{
         this.recipes = [];
 
         for(let i = 0; i < recipes.length; i++){
+            let found = false;
             for(let j = 0; j < parent.recipes.length; j++){
                 if(recipes[i].recipe === parent.recipes[j].id){
+                    found = true;
                     this.recipes.push({
                         recipe: parent.recipes[j],
                         quantity: recipes[i].quantity

+ 26 - 0
views/dashboardPage/dashboard.ejs

@@ -61,6 +61,14 @@
                 </svg>
                 <p>Orders</p>
             </button>
+
+            <button id="transactionsBtn" onclick="changeStrand('transactionsStrand')">
+                <svg width="25" height="25" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
+                    <rect x="1" y="4" width="22" height="16" rx="2" ry="2"></rect>
+                    <line x1="1" y1="10" x2="23" y2="10"></line>
+                </svg>
+                <p>Transactions</p>
+            </button>
         
             <a class="logout" href="/logout">
                 <p>Logout</p>
@@ -261,6 +269,21 @@
             </div>
         </div>
 
+        <div id="transactionsStrand" class="strand">
+            <div class="strandHead">
+                <h1 class="strandTitle">Transactions</h1>
+            </div>
+
+            <div id="transactionsList"></div>
+
+            <template id="transaction">
+                <div class="itemDisplay">
+                    <p></p>
+                    <p></p>
+                </div>
+            </template>
+        </div>
+
         <div id="sidebarDiv" class="sidebarHide">
             <% include ./sidebars/addIngredients %>
 
@@ -281,10 +304,12 @@
 
         <script src="/dashboardPage/Merchant.js"></script>
         <script>
+            console.time("Load");
             let merchant = new Merchant(
                 <%- JSON.stringify(merchant) %>,
                 <%- JSON.stringify(transactions) %>
             );
+            console.timeEnd("Load");
         </script>
         <script src="../shared/graphs.js"></script>
         <script src="/dashboardPage/home.js"></script>
@@ -293,6 +318,7 @@
         <script src="/dashboardPage/sidebars/sidebars.js"></script>
         <script src="/dashboardPage/controller.js"></script>
         <script src="/dashboardPage/orders.js"></script>
+        <script src="/dashboardPage/transactions.js"></script>
         <script src="../shared/validation.js"></script>
 
         <noscript>Please turn on javascript for this site to work properly</noscript>

+ 22 - 0
views/dashboardPage/transactions.js

@@ -0,0 +1,22 @@
+window.transactionsStrandObj = {
+    isPopulated: false, 
+
+    display: function(){
+        if(!this.isPopulated){
+            let now = new Date();
+            let firstOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
+
+            let dates = merchant.transactionIndices(firstOfMonth);
+            let transactionsList = document.getElementById("transactionsList");
+            let template = document.getElementById("transaction").content.children[0];
+
+            for(let i = dates[0]; i < dates[1]; i++){
+                let transaction = template.cloneNode(true);
+                transactionsList.appendChild(transaction);
+
+                transaction.children[0].innerText = `${merchant.transactions[i].date.toLocaleDateString()} ${merchant.transactions[i].date.toLocaleTimeString()}`;
+                transaction.children[1].innerText = `${merchant.transactions[i].recipes.length} recipes sold`;
+            }
+        }
+    }
+}