From a2cdc2c3d9ce31324472cc1f1c381124407a9021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 10 Feb 2020 00:24:18 +0300 Subject: [PATCH] Invoice/ bill item price row calculate.. --- .../assets/js/components/AkauntingMoney.vue | 63 +++++++++++++---- .../assets/js/components/AkauntingSelect.vue | 3 + .../js/components/AkauntingSelectRemote.vue | 3 + resources/assets/js/plugins/bulk-action.js | 3 - resources/assets/js/views/purchases/bills.js | 41 +++++++++++- resources/assets/js/views/sales/invoices.js | 41 +++++++++++- .../views/partials/form/money_group.blade.php | 18 ++++- .../views/purchases/bills/create.blade.php | 10 ++- .../views/purchases/bills/edit.blade.php | 8 ++- .../views/purchases/bills/item.blade.php | 67 ++++++++++++------- .../views/sales/invoices/create.blade.php | 5 +- resources/views/sales/invoices/edit.blade.php | 8 ++- resources/views/sales/invoices/item.blade.php | 67 ++++++++++++------- 13 files changed, 259 insertions(+), 78 deletions(-) diff --git a/resources/assets/js/components/AkauntingMoney.vue b/resources/assets/js/components/AkauntingMoney.vue index b584299eb..4f9d733b1 100644 --- a/resources/assets/js/components/AkauntingMoney.vue +++ b/resources/assets/js/components/AkauntingMoney.vue @@ -10,7 +10,7 @@ - +
@@ -43,11 +43,7 @@ export default { default: null, description: "Selectbox attribute name" }, - value: { - type: String, - default: null, - description: "Selectbox selected value" - }, + value: 0, icon: { type: String, description: "Prepend icon (left)" @@ -67,6 +63,11 @@ export default { default: null, description: "Selectbox disabled status" }, + required: { + type: Boolean, + default: false, + description: "Selectbox disabled status" + }, readonly: { type: Boolean, default: false, @@ -77,6 +78,19 @@ export default { default: false, description: "Selectbox disabled status" }, + dynamicCurrency: { + type: Object, + default: function () { + return { + decimal_mark: '.', + thousands_separator: ',', + symbol_first: 1, + symbol: '$', + precision: 2, + }; + }, + description: "Dynamic currency" + }, currency: { type: Object, default: function () { @@ -85,7 +99,7 @@ export default { thousands_separator: ',', symbol_first: 1, symbol: '$', - precision: '2', + precision: 2, }; }, description: "Default currency" @@ -105,7 +119,7 @@ export default { thousands: this.currency.thousands_separator, prefix: (this.currency.symbol_first) ? this.currency.symbol : '', suffix: (!this.currency.symbol_first) ? this.currency.symbol : '', - precision: this.currency.precision, + precision: parseInt(this.currency.precision), masked: this.masked } } @@ -117,16 +131,41 @@ export default { methods: { change() { - this.$emit('change', this.model); - this.$emit('interface', this.model); + //this.$emit('change', this.model); + //this.$emit('interface', this.model); }, + input(event) { + console.log(event); + this.model = event; + this.$emit('change', event); + this.$emit('interface', event); + } }, watch: { - model: function (options) { - + dynamicCurrency: function (currency) { + this.money = { + decimal: currency.decimal_mark, + thousands: currency.thousands_separator, + prefix: (currency.symbol_first) ? currency.symbol : '', + suffix: (!currency.symbol_first) ? currency.symbol : '', + precision: parseInt(currency.precision), + masked: this.masked + }; + }, + value: function (value) { + this.model = value; + }, + model: function (model) { + this.$emit('change', this.model); this.$emit('interface', this.model); } }, } + + diff --git a/resources/assets/js/components/AkauntingSelect.vue b/resources/assets/js/components/AkauntingSelect.vue index d3ae98aea..8197bf468 100644 --- a/resources/assets/js/components/AkauntingSelect.vue +++ b/resources/assets/js/components/AkauntingSelect.vue @@ -603,6 +603,9 @@ export default { options: function (options) { // update options this.selectOptions = options; + }, + value: function (value) { + this.real_model = value; } }, } diff --git a/resources/assets/js/components/AkauntingSelectRemote.vue b/resources/assets/js/components/AkauntingSelectRemote.vue index c3a93d76f..410ff88aa 100644 --- a/resources/assets/js/components/AkauntingSelectRemote.vue +++ b/resources/assets/js/components/AkauntingSelectRemote.vue @@ -705,6 +705,9 @@ export default { options: function (options) { // update options //this.selectOptions = options; + }, + value: function (value) { + this.real_model = value; } }, } diff --git a/resources/assets/js/plugins/bulk-action.js b/resources/assets/js/plugins/bulk-action.js index 0c89fbd4b..45b447a68 100644 --- a/resources/assets/js/plugins/bulk-action.js +++ b/resources/assets/js/plugins/bulk-action.js @@ -79,11 +79,8 @@ export default class BulkAction { 'selected': this.selected }) .then(response => { - //this.loading = false; - //this.modal = false; if (response.data.redirect) { window.location.reload(false); - } else { } }) .catch(error => { diff --git a/resources/assets/js/views/purchases/bills.js b/resources/assets/js/views/purchases/bills.js index 914e7727d..e8a6fdb6e 100644 --- a/resources/assets/js/views/purchases/bills.js +++ b/resources/assets/js/views/purchases/bills.js @@ -50,7 +50,8 @@ const app = new Vue({ }, transaction: [], items: '', - discount: false + discount: false, + currency: null, } }, @@ -105,6 +106,7 @@ const app = new Vue({ } }) .then(response => { + this.currency = response.data; this.form.currency_code = response.data.currency_code; this.form.currency_rate = response.data.currency_rate; }) @@ -113,6 +115,37 @@ const app = new Vue({ }, onCalculateTotal() { + let sub_total = 0; + let discount_total = 0; + let tax_total = 0; + let grand_total = 0; + let items = this.form.items; + let discount = this.form.discount; + + if (items.length) { + let index = 0; + + for (index = 0; index < items.length; index++) { + let item = items[index]; + + let item_sub_total = item.price * item.quantity; + let item_tax_total = 0; + let item_discount_total = (discount) ? item_sub_total - (item_sub_total * (discount / 100)) : 0; + + items[index].total = item_sub_total; + + sub_total += items[index].total; + discount_total += item_discount_total; + tax_total += item_tax_total; + grand_total += sub_total + tax_total; + } + } + + this.totals.sub = sub_total; + this.totals.discount = discount_total; + this.totals.tax = tax_total; + this.totals.total = grand_total; + /* axios.post(url + '/common/items/total', { items: this.form.items, discount: this.form.discount, @@ -134,9 +167,10 @@ const app = new Vue({ this.totals.discount_text = response.data.discount_text; }) .catch(error => { - }); + });*/ }, + // add bill item row onAddItem() { let row = []; @@ -182,9 +216,10 @@ const app = new Vue({ this.form.items[index].price = (item.purchase_price).toFixed(2); this.form.items[index].quantity = 1; this.form.items[index].tax_id = [item.tax_id.toString()]; - this.form.items[index].total = item.total; + this.form.items[index].total = (item.purchase_price).toFixed(2); }, + // remove bill item row => row_id = index onDeleteItem(index) { this.form.items.splice(index, 1); }, diff --git a/resources/assets/js/views/sales/invoices.js b/resources/assets/js/views/sales/invoices.js index c42787214..e3a07c3bc 100644 --- a/resources/assets/js/views/sales/invoices.js +++ b/resources/assets/js/views/sales/invoices.js @@ -50,7 +50,8 @@ const app = new Vue({ }, transaction: [], items: '', - discount: false + discount: false, + currency: null, } }, @@ -105,6 +106,7 @@ const app = new Vue({ } }) .then(response => { + this.currency = response.data; this.form.currency_code = response.data.currency_code; this.form.currency_rate = response.data.currency_rate; }) @@ -113,6 +115,37 @@ const app = new Vue({ }, onCalculateTotal() { + let sub_total = 0; + let discount_total = 0; + let tax_total = 0; + let grand_total = 0; + let items = this.form.items; + let discount = this.form.discount; + + if (items.length) { + let index = 0; + + for (index = 0; index < items.length; index++) { + let item = items[index]; + + let item_sub_total = item.price * item.quantity; + let item_tax_total = 0; + let item_discount_total = (discount) ? item_sub_total - (item_sub_total * (discount / 100)) : 0; + + items[index].total = item_sub_total; + + sub_total += items[index].total; + discount_total += item_discount_total; + tax_total += item_tax_total; + grand_total += sub_total + tax_total; + } + } + + this.totals.sub = sub_total; + this.totals.discount = discount_total; + this.totals.tax = tax_total; + this.totals.total = grand_total; + /* axios.post(url + '/common/items/total', { items: this.form.items, discount: this.form.discount, @@ -134,9 +167,10 @@ const app = new Vue({ this.totals.discount_text = response.data.discount_text; }) .catch(error => { - }); + });*/ }, + // add invoice item row onAddItem() { let row = []; @@ -182,9 +216,10 @@ const app = new Vue({ this.form.items[index].price = (item.purchase_price).toFixed(2); this.form.items[index].quantity = 1; this.form.items[index].tax_id = [item.tax_id.toString()]; - this.form.items[index].total = item.total; + this.form.items[index].total = (item.purchase_price).toFixed(2); }, + // remove invocie item row => row_id = index onDeleteItem(index) { this.form.items.splice(index, 1); }, diff --git a/resources/views/partials/form/money_group.blade.php b/resources/views/partials/form/money_group.blade.php index 0db137599..969e8aed6 100644 --- a/resources/views/partials/form/money_group.blade.php +++ b/resources/views/partials/form/money_group.blade.php @@ -1,7 +1,9 @@ @stack($name . '_input_start') - + + + @stack('add_item_td_end') @@ -76,6 +79,7 @@ {{ trans('bills.sub_total') }} + {{ Form::moneyGroup('sub_total', '', '', ['disabled' => 'disabled', 'required' => 'required', 'v-model' => 'totals.sub', 'currency' => $currency, 'dynamic-currency' => 'currency', 'masked' => 'true'], 0.00, 'text-right d-none') }} 0 @@ -112,7 +116,7 @@