| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- let transactionDetails = {
- transaction: {},
- display: function(transaction){
- this.transaction = transaction;
- let recipeList = document.getElementById("transactionRecipes");
- let template = document.getElementById("transactionRecipe").content.children[0];
- let totalRecipes = 0;
- let totalPrice = 0;
- while(recipeList.children.length > 0){
- recipeList.removeChild(recipeList.firstChild);
- }
- for(let i = 0; i < transaction.recipes.length; i++){
- let recipe = template.cloneNode(true);
- let price = transaction.recipes[i].quantity * transaction.recipes[i].recipe.price;
- recipe.children[0].innerText = transaction.recipes[i].recipe.name;
- recipe.children[1].innerText = `${transaction.recipes[i].quantity} x $${parseFloat(transaction.recipes[i].recipe.price / 100).toFixed(2)}`;
- recipe.children[2].innerText = `$${(price / 100).toFixed(2)}`;
- recipeList.appendChild(recipe);
- totalRecipes += transaction.recipes[i].quantity;
- totalPrice += price;
- }
- let months = ["January", "Fecbruary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
- let days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
- let dateString = `${days[transaction.date.getDay()]}, ${months[transaction.date.getMonth()]} ${transaction.date.getDate()}, ${transaction.date.getFullYear()}`;
- document.getElementById("transactionDate").innerText = dateString;
- document.getElementById("transactionTime").innerText = transaction.date.toLocaleTimeString();
- document.getElementById("totalRecipes").innerText = `${totalRecipes} recipes`;
- document.getElementById("totalPrice").innerText = `$${(totalPrice / 100).toFixed(2)}`;
- if(merchant.pos === "none"){
- document.getElementById("removeTransBtn").onclick = ()=>{this.remove()};
- }
- },
- remove: function(){
- let loader = document.getElementById("loaderContainer");
- loader.style.display = "flex";
- fetch(`/transaction/${this.transaction.id}`, {
- method: "delete",
- headers: {
- "Content-Type": "application/json;charset=utf-8"
- },
- })
- .then(response => response.json())
- .then((response)=>{
- if(typeof(response) === "string"){
- banner.createError(response);
- }else{
- let ingredients = {};
- for(let i = 0; i < this.transaction.recipes.length; i++){
- let recipe = this.transaction.recipes[i];
- for(let j = 0; j < recipe.recipe.ingredients.length; j++){
- ingredient = recipe.recipe.ingredients[j];
- ingredients[ingredient.ingredient.id] = ingredient.quantity * recipe.quantity;
- }
- }
- merchant.editTransactions(this.transaction, ingredients, true);
- banner.createNotification("TRANSACTION REMOVED");
- }
- })
- .catch((err)=>{
- banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
- })
- .finally(()=>{
- loader.style.display = "none";
- });
- },
- }
- module.exports = transactionDetails;
|