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 @@