diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php
index 47e818a3..3f6e6ec0 100644
--- a/app/Http/Controllers/InvoiceController.php
+++ b/app/Http/Controllers/InvoiceController.php
@@ -397,6 +397,109 @@ class InvoiceController extends Controller
// Generate PO
+ $booking = Booking::where('id', $id)->first();
+ $invoice = Invoice::where('booking_id', $booking['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 = $lines->sum('total');
+ $billing_charges = null;
+ $total = $supplierbooking->amount_after_tax;
+ $adjustment = $total - $subtotal;
+
+ $data = [
+ 'title' => 'Delivery Order',
+ 'detail' => [
+ 'date' => Carbon::createFromFormat('Y-m-d H:i:s', $booking->created_at)->format('d-m-Y'),
+ 'po' => $invoice->po_number,
+ 'do' => '',
+ 'ref' => $booking->id
+ ],
+ 'buyer' => [
+ 'buyer_company' => 'CIEF Worldwide Sdn Bhd',
+ 'reg_no' => '1134596-M',
+ 'address' => 'Malaysia Global Innovation & Creativity Centre, Level
+ 1 CWS, Block 3730, Persiaran APEC 63000
+ Cyberjaya.',
+ 'gst' => '',
+ 'phone' => '018 2909252',
+ 'marking_no' => ''
+ ],
+ 'seller' => [
+ 'seller_company' => $supplier->company_name,
+ 'address' => '',
+ 'phone' => '',
+ ],
+ 'lines' => $lines,
+ 'subtotal' => $subtotal,
+ 'adjustment' => $adjustment,
+ 'billingcharges' => $billing_charges,
+ 'total' => $total
+ ];
+ $defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults();
+ $fontDirs = $defaultConfig['fontDir'];
+ $defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults();
+ $fontData = $defaultFontConfig['fontdata'];
+
+ $mpdf = new \Mpdf\Mpdf([
+ 'fontDir' => array_merge($fontDirs, [
+ __DIR__ . '/custom/font/directory',
+ ]),
+ ]);
+ $mpdf->shrink_tables_to_fit=1;
+ $mpdf->keep_table_proportions = true;
+ $mpdf->SetTitle('Invoice');
+
+ $html = view('pdf/po', $data);
+
+ $mpdf->Bookmark('Start of the document');
+ $mpdf->SetHTMLFooter('
+
+
+ | This is generated by computer. No signature required. |
+ Page {PAGENO} of {nbpg} |
+
+
+ ');
+ $mpdf->setHeader($invoice->po_number);
+ $mpdf->WriteHTML($html);
+
+ return $mpdf;
+ }
+
+ public function customerToCIEFPO(Request $request, $id)
+ {
+ if (!is_numeric($id)) {
+ return response()->json(["message" => "Invalid id. Id needs to be a number"], 400);
+ }
+
+ // Booking Exist and Belongs to User or is Admin
+ if ($request->user()->role === 'member') {
+ if (!$this->isUser($id, $request->user()->id)) {
+ return response()->json(['message' => 'The PO Does not belongs to you.'], 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();
@@ -464,23 +567,6 @@ class InvoiceController extends Controller
$mpdf->setHeader($invoice->po_number);
$mpdf->WriteHTML($html);
- return $mpdf;
- }
-
- public function customerToCIEFPO(Request $request, $id)
- {
- if (!is_numeric($id)) {
- return response()->json(["message" => "Invalid id. Id needs to be a number"], 400);
- }
-
- // Booking Exist and Belongs to User or is Admin
- if ($request->user()->role === 'member') {
- if (!$this->isUser($id, $request->user()->id)) {
- return response()->json(['message' => 'The PO Does not belongs to you.'], 403);
- }
- }
-
- $mpdf = $this->generateSupplierDo($id);
$mpdf->Output();
}
@@ -504,91 +590,7 @@ class InvoiceController extends Controller
// 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();
- $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 = $lines->sum('total');
- $billing_charges = null;
- $total = $supplierbooking->amount_after_tax;
- $adjustment = $total - $subtotal;
-
- $data = [
- 'title' => 'Delivery Order',
- 'detail' => [
- 'date' => Carbon::createFromFormat('Y-m-d H:i:s', $booking->created_at)->format('d-m-Y'),
- 'po' => $invoice->po_number,
- 'do' => '',
- 'ref' => $booking->id
- ],
- 'buyer' => [
- 'buyer_company' => 'CIEF Worldwide Sdn Bhd',
- 'reg_no' => '1134596-M',
- 'address' => 'Malaysia Global Innovation & Creativity Centre, Level
- 1 CWS, Block 3730, Persiaran APEC 63000
- Cyberjaya.',
- 'gst' => '',
- 'phone' => '018 2909252',
- 'marking_no' => ''
- ],
- 'seller' => [
- 'seller_company' => $supplier->company_name,
- 'address' => '',
- 'phone' => '',
- ],
- 'lines' => $lines,
- 'subtotal' => $subtotal,
- 'adjustment' => $adjustment,
- 'billingcharges' => $billing_charges,
- 'total' => $total
- ];
- $defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults();
- $fontDirs = $defaultConfig['fontDir'];
- $defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults();
- $fontData = $defaultFontConfig['fontdata'];
-
- $mpdf = new \Mpdf\Mpdf([
- 'fontDir' => array_merge($fontDirs, [
- __DIR__ . '/custom/font/directory',
- ]),
- ]);
- $mpdf->shrink_tables_to_fit=1;
- $mpdf->keep_table_proportions = true;
- $mpdf->SetTitle('Invoice');
-
- $html = view('pdf/po', $data);
-
- $mpdf->Bookmark('Start of the document');
- $mpdf->SetHTMLFooter('
-
-
- | This is generated by computer. No signature required. |
- Page {PAGENO} of {nbpg} |
-
-
- ');
- $mpdf->setHeader($invoice->po_number);
- $mpdf->WriteHTML($html);
+ $mpdf = $this->generateSupplierDo($id);
$mpdf->Output();