From 9f5407b62d47901b4f5b80782c1eaa124162a444 Mon Sep 17 00:00:00 2001 From: express achiever Date: Tue, 3 Sep 2019 13:12:38 +0800 Subject: [PATCH 1/2] refactor code counter sales javascript functions to CounterSalesFunctions.js --- CounterSales.php | 101 +++--------------- javascripts/CounterSalesFunctions.js | 151 +++++++++++++++++++++++++++ 2 files changed, 164 insertions(+), 88 deletions(-) create mode 100644 javascripts/CounterSalesFunctions.js diff --git a/CounterSales.php b/CounterSales.php index 39cbb8e45..090049f21 100644 --- a/CounterSales.php +++ b/CounterSales.php @@ -2417,95 +2417,20 @@ functionalexrate, } echo ''; } +echo ''; ?> - - ; + defaultdeliverydate: "", + SetDefaultDeliveryDate: function(val) + { + this.defaultdeliverydate = val; + }, + + AddQuickEntry: function(itemcode) + { + // prevent form submitting + event.preventDefault(); + + var itemlist = this.itemlist; + + if(itemlist.includes(itemcode.value.trim())) + { + var table = document.getElementById(this.quickentrytableid); + + // loop quick entry table rows + for (var j = 0, row; row = table.rows[j]; j++) + { + found = false; + col = row.cells[0]; + var input_itemcode = col.firstElementChild; + + if(input_itemcode) + { + // check if item already in list or fill in the first empty row + if(input_itemcode.value == '' || input_itemcode.value == itemcode.value.trim()) + { + // set item code + input_itemcode.value = itemcode.value.trim(); + // set qty + row.cells[1].firstElementChild.value = row.cells[1].firstElementChild.value ? parseInt(row.cells[1].firstElementChild.value) + 1 : '1'; + found = true; + break; + } + } + } + + // when no rows matched and no more empty rows + if(!found) + { + this.AddQuickEntryRow(itemcode) + } + } + else + { + alert("item code not found!"); + } + + itemcode.value = ""; + + }, + + AddQuickEntryRow: function (itemcode) + { + var table = document.getElementById(this.quickentrytableid); + var row = table.insertRow(-1); + var cell1 = row.insertCell(0); + var cell2 = row.insertCell(1); + + cell1.innerHTML = ""; + cell2.innerHTML = ""; + + totalquickentry = document.getElementById(this.quickentryrowid); + totalquickentry.value = parseInt(totalquickentry.value) + 1; + + this.IncreaseRowCounter(); + }, + + + totaldue: 0, + SetTotalDue: function(val) + { + this.totaldue = val; + }, + + decimal: 2, + SetDecimal: function(val) + { + this.decimal = val; + }, + + cashreceivedid: "", + SetCashReceivedId: function(val) + { + this.cashreceivedid = val; + }, + + amountpaidid: "", + SetAmountPaidId: function(val) + { + this.amountpaidid = val; + }, + + changedueid: "", + SetChangeDueId: function(val) + { + this.changedueid = val; + }, + + CalculateChangeDue: function () + { + received_amount = document.getElementById(this.cashreceivedid); + paid_amount = document.getElementById(this.amountpaidid); + change_due = document.getElementById(this.changedueid); + + if(received_amount.value >= this.totaldue) + { + paid_amount.value = Number(this.totaldue).toFixed(this.decimal); + change_due.value = Number(received_amount.value - this.totaldue).toFixed(this.decimal); + } + else + { + paid_amount.value = 0; + change_due.value = 0; + } + } +} \ No newline at end of file From 6fe8e8a095247098f8ceafe48b99e0ea2c1a64ac Mon Sep 17 00:00:00 2001 From: express achiever Date: Tue, 3 Sep 2019 13:12:38 +0800 Subject: [PATCH 2/2] refactor code counter sales javascript functions to CounterSalesFunctions.js --- CounterSales.php | 101 +++--------------- javascripts/CounterSalesFunctions.js | 147 +++++++++++++++++++++++++++ 2 files changed, 160 insertions(+), 88 deletions(-) create mode 100644 javascripts/CounterSalesFunctions.js diff --git a/CounterSales.php b/CounterSales.php index 39cbb8e45..090049f21 100644 --- a/CounterSales.php +++ b/CounterSales.php @@ -2417,95 +2417,20 @@ functionalexrate, } echo ''; } +echo ''; ?> - - "; + cell2.innerHTML = ""; + + totalquickentry = document.getElementById(this.quickentryrowid); + totalquickentry.value = parseInt(totalquickentry.value) + 1; + + this.IncreaseRowCounter(); + }, + + + totaldue: 0, + SetTotalDue: function(val) + { + this.totaldue = val; + }, + + decimal: 2, + SetDecimal: function(val) + { + this.decimal = val; + }, + + cashreceivedid: "", + SetCashReceivedId: function(val) + { + this.cashreceivedid = val; + }, + + amountpaidid: "", + SetAmountPaidId: function(val) + { + this.amountpaidid = val; + }, + + changedueid: "", + SetChangeDueId: function(val) + { + this.changedueid = val; + }, + + CalculateChangeDue: function () + { + received_amount = document.getElementById(this.cashreceivedid); + paid_amount = document.getElementById(this.amountpaidid); + change_due = document.getElementById(this.changedueid); + + if(received_amount.value >= this.totaldue) + { + paid_amount.value = Number(this.totaldue).toFixed(this.decimal); + change_due.value = Number(received_amount.value - this.totaldue).toFixed(this.decimal); + } + else + { + paid_amount.value = 0; + change_due.value = 0; + } + } +} \ No newline at end of file