diff --git a/resources/assets/js/components/NewInvoice.vue b/resources/assets/js/components/NewInvoice.vue index 22b570e4..b2cc0918 100644 --- a/resources/assets/js/components/NewInvoice.vue +++ b/resources/assets/js/components/NewInvoice.vue @@ -266,18 +266,6 @@ - - - - Rounding - - - plus or minus some number - - -   - - @@ -290,13 +278,25 @@   + + + + Adjustment + + + {{ adjustment || 'auto' }} + + +   + + - Service Charge + Billing Charge - {{ service_charge }} + {{ billing_charge }}   @@ -504,7 +504,8 @@ export default { amount: null, user_bankslip_path: null, china_bankslip_path: null, - marking: null + marking: null, + billing_charge: null } } } @@ -536,7 +537,7 @@ export default { } }, rate: 0, - service_charge: 0, + billing_charge: 0, amount: 0, bia: 0, invoice_total: 0, @@ -546,7 +547,8 @@ export default { total: 0, role: null, currentStatus: null, - statuses: [] + statuses: [], + adjustment: 0 } }, computed: { @@ -620,7 +622,8 @@ export default { tax, bia, amount, - rate + rate, + billing_charge } = this.booking_details this.form.formData.marking = marking @@ -628,8 +631,8 @@ export default { this.amount = amount this.bia = bia this.rate = rate - this.service_charge = parseFloat(this.bia - (this.amount / this.rate)).toFixed(2) - this.total = this.service_charge // Will not work if there is tax. Temporary fix. + this.billing_charge = billing_charge + this.total = this.billing_charge // Will not work if there is tax. Temporary fix. } }, mounted () { @@ -680,11 +683,21 @@ export default { setTotal: function () { if (this.form.formData.lines.length < 1) { this.subtotal = 0 - this.total = this.service_charge // Temporary fix. Will return error if GST is implemented. + this.adjustment = 0 + this.total = this.billing_charge // Temporary fix. Will return error if GST is implemented. return } + this.subtotal = parseFloat(this.form.formData.lines.map(line => line.total).reduce((a, b) => parseFloat(a) + parseFloat(b))).toFixed(2) - this.total = parseFloat(+this.subtotal + (+this.subtotal * (+this.tax || 0) / 100) + +this.service_charge).toFixed(2) + + // Set Adjustment if CNY total is equal to Invoice CNY Total + const cnyTotal = this.form.formData.lines.map(l => +l.unit_price_rmb * +l.quantity).reduce((a, b) => a + b) + if (cnyTotal === this.amount) { + this.adjustment = parseFloat(+this.bia - +this.subtotal - this.billing_charge).toFixed(2) + } else { + this.adjustment = 0 + } + this.total = parseFloat(+this.subtotal + (+this.subtotal * (+this.tax || 0) / 100) + +this.billing_charge + +this.adjustment).toFixed(2) }, clearAddLine: function () { this.form.addLine.order = null @@ -772,6 +785,8 @@ export default { this.currentStatus = resp.data.status[resp.data.status.length - 1].status + this.adjustment = resp.data.adjustment + this.setTotal() }) },