From dfe55cc6f991581c171c3f01d1c8870879a64181 Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Wed, 23 Sep 2020 22:08:20 +0800 Subject: [PATCH 01/18] removed amount from props --- resources/assets/js/components/NewInvoice.vue | 3 --- 1 file changed, 3 deletions(-) diff --git a/resources/assets/js/components/NewInvoice.vue b/resources/assets/js/components/NewInvoice.vue index 84afda88..229fd5bd 100644 --- a/resources/assets/js/components/NewInvoice.vue +++ b/resources/assets/js/components/NewInvoice.vue @@ -476,7 +476,6 @@ export default { default: function () { return { id: null, - amount: null, bia: null, user_bankslip_path: null, china_bankslip_path: null, @@ -593,7 +592,6 @@ export default { marking, tax, service_charge, - amount, bia, rate } = this.booking_details @@ -601,7 +599,6 @@ export default { this.form.formData.marking = marking this.tax = tax this.service_charge = service_charge - this.amount = amount this.bia = bia this.rate = rate } From 11506bb857ba1cb63e29a423e263d9862137afac Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Wed, 23 Sep 2020 22:09:36 +0800 Subject: [PATCH 02/18] validate total to bia instead of total in editPO --- app/Http/Controllers/InvoiceController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index c56f38ff..8da96f12 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -216,9 +216,9 @@ class InvoiceController extends Controller $total = array_reduce($subtotalArray, function ($v1, $v2) { return $v1 + $v2; }); - if ($total != $booking->amount) { + if ($total != $booking->bia) { return response()->json([ - 'message' => 'Booking amount expected is '.$booking->amount.'. Your Invoice amount is '.$total + 'message' => 'Booking amount expected is '.$booking->bia.'. Your Invoice amount is '.$total ], 400); } From 810084609b76d681d2d2e9b6bbd29252997c3116 Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Wed, 23 Sep 2020 22:09:36 +0800 Subject: [PATCH 03/18] add service_charge to bookings --- app/Http/Controllers/InvoiceController.php | 4 +-- ..._154412_add_service_charge_to_bookings.php | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2020_09_25_154412_add_service_charge_to_bookings.php diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index c56f38ff..8da96f12 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -216,9 +216,9 @@ class InvoiceController extends Controller $total = array_reduce($subtotalArray, function ($v1, $v2) { return $v1 + $v2; }); - if ($total != $booking->amount) { + if ($total != $booking->bia) { return response()->json([ - 'message' => 'Booking amount expected is '.$booking->amount.'. Your Invoice amount is '.$total + 'message' => 'Booking amount expected is '.$booking->bia.'. Your Invoice amount is '.$total ], 400); } diff --git a/database/migrations/2020_09_25_154412_add_service_charge_to_bookings.php b/database/migrations/2020_09_25_154412_add_service_charge_to_bookings.php new file mode 100644 index 00000000..114601b7 --- /dev/null +++ b/database/migrations/2020_09_25_154412_add_service_charge_to_bookings.php @@ -0,0 +1,32 @@ +double('service_charge')->default(null)->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('bookings', function (Blueprint $table) { + $table->dropColumn('service_charge'); + }); + } +} From 837d37b3954b44b486a02b51d3f5e0f25af0f505 Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Fri, 25 Sep 2020 15:52:25 +0800 Subject: [PATCH 04/18] add adjustment to invoices --- ...9_25_154539_add_adjustment_to_invoices.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 database/migrations/2020_09_25_154539_add_adjustment_to_invoices.php diff --git a/database/migrations/2020_09_25_154539_add_adjustment_to_invoices.php b/database/migrations/2020_09_25_154539_add_adjustment_to_invoices.php new file mode 100644 index 00000000..815200ad --- /dev/null +++ b/database/migrations/2020_09_25_154539_add_adjustment_to_invoices.php @@ -0,0 +1,32 @@ +double('adjustment')->default(null)->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('invoices', function (Blueprint $table) { + $table->dropColumn('adjustment'); + }); + } +} From 30b3f7554ea7b0873c279c431c18d82d298e9cea Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Fri, 25 Sep 2020 15:55:27 +0800 Subject: [PATCH 05/18] adjustment fillable in invoice model --- app/Invoice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Invoice.php b/app/Invoice.php index 647b3bff..9e3bffa8 100644 --- a/app/Invoice.php +++ b/app/Invoice.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; class Invoice extends Model { - protected $fillable = ['invoice_url','amount','booking_id', 'buyer_company', 'address', 'contact_no', 'po_number']; + protected $fillable = ['invoice_url','amount','booking_id', 'buyer_company', 'address', 'contact_no', 'po_number', 'adjustment']; public function booking(){ return $this->belongsTo('App\Booking'); From c51a8d6e250abc5fba3ada7d8609076e6366fe63 Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Fri, 25 Sep 2020 15:57:13 +0800 Subject: [PATCH 06/18] service_charge fillable in booking model --- app/Booking.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Booking.php b/app/Booking.php index 43bd80d4..68b48b8b 100644 --- a/app/Booking.php +++ b/app/Booking.php @@ -24,7 +24,7 @@ class Booking extends Model "usd_book_bank_branch"); protected $fillable = ['id', 'term', 'rate_id', 'user_id', 'amount', 'account_name', 'account_num', 'bank_name', - 'bank_branch', 'company_name']; + 'bank_branch', 'company_name', 'service_charge']; public $timestamps = true; From 44096eb29cc09cef4e5dfc33473051caeec7c2ee Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Fri, 25 Sep 2020 15:59:41 +0800 Subject: [PATCH 07/18] fix invoices documentation --- fixinvoice.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 fixinvoice.txt diff --git a/fixinvoice.txt b/fixinvoice.txt new file mode 100644 index 00000000..d857f15b --- /dev/null +++ b/fixinvoice.txt @@ -0,0 +1,9 @@ +1. create migration field service_charge in bookings. (nullable, default null, double) +2. create migration field adjustment in invoices. (nullable, default null, double) +3. save service charge on confirm +4. pass service from backend +5. display in frontend. +6. When RMB value match auto adjustment. +7. Vue validation before post and edit. +8. post and edit invoice needs to have adjustment. validate. +9. change pdf documents. From 82e72bfc6d634ea208dcedd261d85ac4870a6539 Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Fri, 25 Sep 2020 16:01:18 +0800 Subject: [PATCH 08/18] removed utils. not using dompdf --- utils | 1 - 1 file changed, 1 deletion(-) delete mode 160000 utils diff --git a/utils b/utils deleted file mode 160000 index 47ddd6de..00000000 --- a/utils +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 47ddd6dedb1f32c45b66b701f5300dacc71bd715 From eac4336774126f1415a877f1d91075891aa3c28f Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Fri, 25 Sep 2020 16:04:02 +0800 Subject: [PATCH 09/18] add adjustment row in new invoice --- resources/assets/js/components/NewInvoice.vue | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/resources/assets/js/components/NewInvoice.vue b/resources/assets/js/components/NewInvoice.vue index 229fd5bd..22b570e4 100644 --- a/resources/assets/js/components/NewInvoice.vue +++ b/resources/assets/js/components/NewInvoice.vue @@ -266,6 +266,18 @@ + + + + Rounding + + + plus or minus some number + + +   + + @@ -278,6 +290,18 @@   + + + + Service Charge + + + {{ service_charge }} + + +   + + @@ -477,6 +501,7 @@ export default { return { id: null, bia: null, + amount: null, user_bankslip_path: null, china_bankslip_path: null, marking: null @@ -513,8 +538,10 @@ export default { rate: 0, service_charge: 0, amount: 0, + bia: 0, invoice_total: 0, tax: 0, + billing_fee: 0, subtotal: 0, total: 0, role: null, @@ -591,16 +618,18 @@ export default { const { marking, tax, - service_charge, bia, + amount, rate } = this.booking_details this.form.formData.marking = marking this.tax = tax - this.service_charge = service_charge + 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. } }, mounted () { @@ -651,11 +680,11 @@ export default { setTotal: function () { if (this.form.formData.lines.length < 1) { this.subtotal = 0 - this.total = 0 + this.total = this.service_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)).toFixed(2) + this.total = parseFloat(+this.subtotal + (+this.subtotal * (+this.tax || 0) / 100) + +this.service_charge).toFixed(2) }, clearAddLine: function () { this.form.addLine.order = null From a3a6ee1f94b58384808f755e159266abb575ccd2 Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Fri, 25 Sep 2020 16:26:38 +0800 Subject: [PATCH 10/18] add booking_charge to booking table --- app/Booking.php | 2 +- ..._161945_add_billing_charge_to_bookings.php | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2020_09_25_161945_add_billing_charge_to_bookings.php diff --git a/app/Booking.php b/app/Booking.php index 68b48b8b..f0decadf 100644 --- a/app/Booking.php +++ b/app/Booking.php @@ -24,7 +24,7 @@ class Booking extends Model "usd_book_bank_branch"); protected $fillable = ['id', 'term', 'rate_id', 'user_id', 'amount', 'account_name', 'account_num', 'bank_name', - 'bank_branch', 'company_name', 'service_charge']; + 'bank_branch', 'company_name', 'service_charge', 'billing_charge']; public $timestamps = true; diff --git a/database/migrations/2020_09_25_161945_add_billing_charge_to_bookings.php b/database/migrations/2020_09_25_161945_add_billing_charge_to_bookings.php new file mode 100644 index 00000000..ebfd7e76 --- /dev/null +++ b/database/migrations/2020_09_25_161945_add_billing_charge_to_bookings.php @@ -0,0 +1,32 @@ +double('billing_charge')->default(null)->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('bookings', function (Blueprint $table) { + $table->dropColumn('billing_charge'); + }); + } +} From b823152a51d87ac1f311f2262e098d7a8bdfe6fa Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Fri, 25 Sep 2020 16:44:37 +0800 Subject: [PATCH 11/18] save service_charge and billing_charge to bookings --- app/Http/Controllers/BookingController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/BookingController.php b/app/Http/Controllers/BookingController.php index 9c82209f..7641c6bf 100644 --- a/app/Http/Controllers/BookingController.php +++ b/app/Http/Controllers/BookingController.php @@ -448,6 +448,8 @@ class BookingController extends Controller $bankin_amount = round($subtotal + $taxAmount + $billingChargeAmount , 2); $booking = new Booking(); + $booking->billing_charge = $billingChargeAmount; + $booking->service_charge = $svcharge; $booking->account_name = $request->input('account_name'); $booking->account_num = $request->input('account_num'); $booking->bank_name = $request->input('bank_name'); From e616689ef1efaf1ff46e5ff853470f8c44748896 Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Fri, 25 Sep 2020 18:26:27 +0800 Subject: [PATCH 12/18] add adjustment to frontend --- resources/assets/js/components/NewInvoice.vue | 59 ++++++++++++------- 1 file changed, 37 insertions(+), 22 deletions(-) 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() }) }, From b99e88187a810422d95d1a265f390160f6e0ff79 Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Fri, 25 Sep 2020 18:34:55 +0800 Subject: [PATCH 13/18] put adjustment into formData --- resources/assets/js/components/NewInvoice.vue | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/resources/assets/js/components/NewInvoice.vue b/resources/assets/js/components/NewInvoice.vue index b2cc0918..b6d5b3c4 100644 --- a/resources/assets/js/components/NewInvoice.vue +++ b/resources/assets/js/components/NewInvoice.vue @@ -284,7 +284,7 @@ Adjustment - {{ adjustment || 'auto' }} + {{ form.formData.adjustment || 'auto' }}   @@ -520,6 +520,7 @@ export default { marking: this.booking_details.marking, gst_id: '', reg_no: '', + adjustment: '', lines: [] }, addLine: { @@ -547,8 +548,7 @@ export default { total: 0, role: null, currentStatus: null, - statuses: [], - adjustment: 0 + statuses: [] } }, computed: { @@ -577,6 +577,8 @@ export default { }, gst_id: { + }, + adjustment: { } }, addLine: { @@ -683,7 +685,7 @@ export default { setTotal: function () { if (this.form.formData.lines.length < 1) { this.subtotal = 0 - this.adjustment = 0 + this.form.formData.adjustment = 0 this.total = this.billing_charge // Temporary fix. Will return error if GST is implemented. return } @@ -693,11 +695,11 @@ export default { // 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) + this.form.formData.adjustment = parseFloat(+this.bia - +this.subtotal - this.billing_charge).toFixed(2) } else { - this.adjustment = 0 + this.form.formData.adjustment = 0 } - this.total = parseFloat(+this.subtotal + (+this.subtotal * (+this.tax || 0) / 100) + +this.billing_charge + +this.adjustment).toFixed(2) + this.total = parseFloat(+this.subtotal + (+this.subtotal * (+this.tax || 0) / 100) + +this.billing_charge + +this.form.formData.adjustment).toFixed(2) }, clearAddLine: function () { this.form.addLine.order = null @@ -785,7 +787,7 @@ export default { this.currentStatus = resp.data.status[resp.data.status.length - 1].status - this.adjustment = resp.data.adjustment + this.form.formData.adjustment = resp.data.adjustment this.setTotal() }) From 3bb65873994097e22a914e9c6dbdb27c218a5b32 Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Fri, 25 Sep 2020 18:37:17 +0800 Subject: [PATCH 14/18] validation for adjustment in controller --- app/Http/Controllers/InvoiceController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 8da96f12..e3b94c3c 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -65,6 +65,7 @@ class InvoiceController extends Controller 'contact_no' => 'required', 'marking' => 'required', 'reg_no' => 'required', + 'adjustment' => 'required|numeric', 'lines.*.order' => 'required|numeric', 'lines.*.stock_code' => 'required', 'lines.*.description' => 'max:256', @@ -174,6 +175,7 @@ class InvoiceController extends Controller 'contact_no' => 'required', 'marking' => 'required', 'reg_no' => 'required', + 'adjustment' => 'required|numeric', 'lines.*.order' => 'required|numeric', 'lines.*.stock_code' => 'required', 'lines.*.description' => 'max:256', From 56f288e05c71098325f1562f5916ddd5c3a15c06 Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Fri, 25 Sep 2020 18:54:45 +0800 Subject: [PATCH 15/18] validate total and save --- app/Http/Controllers/InvoiceController.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index e3b94c3c..a78b6800 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -93,9 +93,13 @@ class InvoiceController extends Controller function ($line) { return $line['total']; }, $validatedData['lines'] ); - $total = array_reduce($subtotalArray, function ($v1, $v2) { + $subtotal = array_reduce($subtotalArray, function ($v1, $v2) { return $v1 + $v2; }); + $adjustment = $request->adjustment; + $billing_charges = $booking->billing_charge; + $total = $subtotal + $adjustment + $billing_charges; + if ($total !== $booking->bia) { return response()->json([ 'message' => 'Booking amount expected is '.$booking->bia.'. Your Invoice amount is '.$total @@ -121,6 +125,7 @@ class InvoiceController extends Controller $invoice->address = $validatedData['address']; $invoice->contact_no = $validatedData['contact_no']; $invoice->po_number = $po_number; + $invoice->adjustment = $adjustment; $invoice->save(); if (!$invoice) { @@ -215,10 +220,14 @@ class InvoiceController extends Controller function ($line) { return $line['total']; }, $validatedData['lines'] ); - $total = array_reduce($subtotalArray, function ($v1, $v2) { + $subtotal = array_reduce($subtotalArray, function ($v1, $v2) { return $v1 + $v2; }); - if ($total != $booking->bia) { + $adjustment = $request->adjustment; + $billing_charges = $booking->billing_charge; + $total = $subtotal + $adjustment + $billing_charges; + + if ($total !== $booking->bia) { return response()->json([ 'message' => 'Booking amount expected is '.$booking->bia.'. Your Invoice amount is '.$total ], 400); @@ -235,6 +244,7 @@ class InvoiceController extends Controller $invoice->address = $validatedData['address']; $invoice->contact_no = $validatedData['contact_no']; $invoice->po_number = $po_number; + $invoice->adjustment = $adjustment; $invoice->save(); if (!$invoice) { From 853911035913372d630c753d018eb6038a8b6c64 Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Sat, 26 Sep 2020 01:27:59 +0800 Subject: [PATCH 16/18] add new fields into pdf --- app/Http/Controllers/InvoiceController.php | 44 +++++++++++++++++----- resources/views/pdf/invoice.blade.php | 29 ++++++++++---- resources/views/pdf/po.blade.php | 27 ++++++++++--- 3 files changed, 79 insertions(+), 21 deletions(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index a78b6800..97b09fc8 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -359,17 +359,16 @@ class InvoiceController extends Controller } } - // Ensure Invoice Status is Approve - // if ($this->invoiceStatus($id) !== 'approve') { - // return response()->json(['message' => 'Invoice must and exist and approve status.'], 403); - // } - // Generate PO $booking = Booking::where('id', $id)->first(); $invoice = Invoice::where('booking_id', $booking['id'])->first(); $lines = InvoiceDetails::where('invoice_id', $invoice->id)->get(); $marking = User::find($booking->user_id)->marking; + $subtotal = InvoiceDetails::where('invoice_id', $invoice->id)->sum('total'); + $adjustment = $invoice->adjustment; + $billing_charges = $booking->billing_charge; + $total = $subtotal + $adjustment + $billing_charges; $data = [ 'title' => 'Purchase Order', @@ -395,7 +394,10 @@ class InvoiceController extends Controller 'phone' => '018 2909252', ], 'lines' => $lines, - 'amount' => $invoice->amount + 'subtotal' => $subtotal, + 'adjustment' => $adjustment, + 'billingcharges' => $billing_charges, + 'total' => $total ]; $defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults(); @@ -456,6 +458,10 @@ class InvoiceController extends Controller $lines = InvoiceDetails::where('invoice_id', $invoice->id)->get(); $supplierbooking = SupplierBooking::where('booking_id', $id)->first(); $supplier = SettingSupplier::where('id', $supplierbooking->supplier_id)->first(); + $subtotal = InvoiceDetails::where('invoice_id', $invoice->id)->sum('total'); + $adjustment = $invoice->adjustment; + $billing_charges = $booking->billing_charge; + $total = $subtotal + $adjustment + $billing_charges; $data = [ 'title' => 'Delivery Order', @@ -481,7 +487,10 @@ class InvoiceController extends Controller 'phone' => '', ], 'lines' => $lines, - 'amount' => $invoice->amount + 'subtotal' => $subtotal, + 'adjustment' => $adjustment, + 'billingcharges' => $billing_charges, + 'total' => $total ]; $defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults(); $fontDirs = $defaultConfig['fontDir']; @@ -532,6 +541,11 @@ class InvoiceController extends Controller $booking = Booking::where('id', $id)->first(); $invoice = Invoice::where('booking_id', $booking['id'])->first(); $lines = InvoiceDetails::where('invoice_id', $invoice->id)->get(); + $subtotal = InvoiceDetails::where('invoice_id', $invoice->id)->sum('total'); + $adjustment = $invoice->adjustment; + $billing_charges = $booking->billing_charge; + $total = $subtotal + $adjustment + $billing_charges; + $data = [ 'title' => 'Invoice', @@ -551,7 +565,10 @@ class InvoiceController extends Controller ], 'total_page' => (count($lines) / 10), 'lines' => $lines, - 'amount' => $invoice->amount + 'subtotal' => $subtotal, + 'adjustment' => $adjustment, + 'billingcharges' => $billing_charges, + 'total' => $total ]; $defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults(); @@ -603,6 +620,11 @@ class InvoiceController extends Controller $booking = Booking::where('id', $id)->first(); $invoice = Invoice::where('booking_id', $booking['id'])->first(); $lines = InvoiceDetails::where('invoice_id', $invoice->id)->get(); + $subtotal = InvoiceDetails::where('invoice_id', $invoice->id)->sum('total'); + $adjustment = $invoice->adjustment; + $billing_charges = $booking->billing_charge; + $total = $subtotal + $adjustment + $billing_charges; + $data = [ 'title' => 'Delivery Order', @@ -621,7 +643,10 @@ class InvoiceController extends Controller 'marking_no' => '' ], 'lines' => $lines, - 'amount' => $invoice->amount + 'subtotal' => $subtotal, + 'adjustment' => $adjustment, + 'billingcharges' => $billing_charges, + 'total' => $total ]; $defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults(); @@ -629,6 +654,7 @@ class InvoiceController extends Controller $defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults(); $fontData = $defaultFontConfig['fontdata']; + $mpdf = new \Mpdf\Mpdf([ 'fontDir' => array_merge($fontDirs, [ __DIR__ . '/custom/font/directory', diff --git a/resources/views/pdf/invoice.blade.php b/resources/views/pdf/invoice.blade.php index a8c8eb16..5b30de30 100644 --- a/resources/views/pdf/invoice.blade.php +++ b/resources/views/pdf/invoice.blade.php @@ -87,6 +87,9 @@ td.address { text-align: left; } + .right { + text-align: right; + } @@ -169,26 +172,38 @@ {{$line->description}} {{$line->quantity}} {{number_format($line->unit_price_rm, 2)}} - {{number_format($line->total, 2)}} + {{number_format($line->total, 2)}} @endforeach - Subtotal - {{ number_format($amount, 2) }} + Subtotal + {{ number_format($subtotal, 2) }} + @if($adjustment) + + + Adjustment + {{ number_format($adjustment, 2) }} + + @endif + @if($billingcharges) + + + Billing Charges + {{ number_format($billingcharges, 2) }} + + @endif - Total - {{ number_format($amount, 2) }} + Total + {{ number_format($total, 2) }} - - \ No newline at end of file diff --git a/resources/views/pdf/po.blade.php b/resources/views/pdf/po.blade.php index 885c3c43..fd2b32d9 100644 --- a/resources/views/pdf/po.blade.php +++ b/resources/views/pdf/po.blade.php @@ -46,6 +46,9 @@ .center { text-align: center; } + .right { + text-align: right; + } .middle { vertical-align: middle; } @@ -147,20 +150,34 @@ {{$line->description}} {{$line->quantity}} {{number_format($line->unit_price_rm, 2)}} - {{number_format($line->total, 2)}} + {{number_format($line->total, 2)}} @endforeach - Subtotal - {{ number_format($amount, 2) }} + Subtotal + {{ number_format($subtotal, 2) }} + @if($adjustment) + + + Adjustment + {{ number_format($adjustment, 2) }} + + @endif + @if($billingcharges) + + + Billing Charges + {{ number_format($billingcharges, 2) }} + + @endif - Total - {{ number_format($amount, 2) }} + Total + {{ number_format($total, 2) }} From 63410cfbc9ef402aa620588a30e8d9c5ff0761e5 Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Sat, 26 Sep 2020 02:45:54 +0800 Subject: [PATCH 17/18] fix problem with ei and edo duplicate --- app/Http/Controllers/InvoiceController.php | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 97b09fc8..a4c07886 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -312,13 +312,28 @@ class InvoiceController extends Controller $booking = Booking::find($id); - $monthlycount = Invoice::where('ei', 'like', 'EI-'.Carbon::createFromFormat('Y-m-d H:i:s', $booking->created_at)->format('Ym').'%')->count() + 1; - $generatednumber = Carbon::createFromFormat('Y-m-d H:i:s', $booking->created_at)->format('Ym').'-'.sprintf("%05d", $monthlycount); - + // Generate EI and EDO only if not exist $invoice = Invoice::where('booking_id', $id)->first(); - $invoice->ei = 'EI-'.$generatednumber; - $invoice->edo = 'EDO-'.$generatednumber; - $invoice->save(); + var_dump($invoice->ei); + + if (!$invoice->ei && !$invoice->edo) { + + + + $monthlycount = Invoice::where('ei', 'like', 'EI-'.Carbon::createFromFormat('Y-m-d H:i:s', $booking->created_at)->format('Ym').'%')->count() + 1; + $generatednumber = Carbon::createFromFormat('Y-m-d H:i:s', $booking->created_at)->format('Ym').'-'.sprintf("%05d", $monthlycount); + $invoice->ei = 'EI-'.$generatednumber; + $invoice->edo = 'EDO-'.$generatednumber; + + // Skip to next count if already exist + while (Invoice::where('ei', $invoice->ei)->exists() || Invoice::where('edo', $invoice->edo)->exists()) { + $monthlycount = $monthlycount + 1; + $generatednumber = Carbon::createFromFormat('Y-m-d H:i:s', $booking->created_at)->format('Ym').'-'.sprintf("%05d", $monthlycount); + $invoice->ei = 'EI-'.$generatednumber; + $invoice->edo = 'EDO-'.$generatednumber; + } + $invoice->save(); + } if(!$status) { return response()->json(['message' => 'Unable to Update Status'], 500); From 6a67231aa22f3191eba6e0d88b77ce80bb1ce2e6 Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Sat, 26 Sep 2020 18:49:28 +0800 Subject: [PATCH 18/18] supplier do recalculate --- app/Http/Controllers/InvoiceController.php | 27 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index a4c07886..6e0d8c83 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -470,13 +470,30 @@ class InvoiceController extends Controller $booking = Booking::where('id', $id)->first(); $invoice = Invoice::where('booking_id', $booking['id'])->first(); - $lines = InvoiceDetails::where('invoice_id', $invoice->id)->get(); + $supplierbooking = SupplierBooking::where('booking_id', $id)->first(); + $lines = DB::table('invoices') + ->join('invoice_details', function ($join) use ($id) { + $join->where('invoices.booking_id', '=', $id); + $join->on('invoice_details.invoice_id', '=', 'invoices.id'); + }) + ->join('supplier_bookings', 'invoices.booking_id', '=', 'supplier_bookings.booking_id') + ->select( + 'order', + 'stock_code', + 'description', + 'quantity', + DB::raw('ROUND((invoice_details.unit_price_rmb / supplier_bookings.rate), 2) as unit_price_rm'), + DB::raw('ROUND((invoice_details.quantity * ROUND((invoice_details.unit_price_rmb / supplier_bookings.rate), 2)), 2) as total'), + // subtotal + // adjustment + // total + )->get(); $supplierbooking = SupplierBooking::where('booking_id', $id)->first(); $supplier = SettingSupplier::where('id', $supplierbooking->supplier_id)->first(); - $subtotal = InvoiceDetails::where('invoice_id', $invoice->id)->sum('total'); - $adjustment = $invoice->adjustment; - $billing_charges = $booking->billing_charge; - $total = $subtotal + $adjustment + $billing_charges; + $subtotal = $lines->sum('total'); + $billing_charges = null; + $total = $supplierbooking->amount_after_tax; + $adjustment = $total - $subtotal; $data = [ 'title' => 'Delivery Order',