diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 179518eb..8e83c699 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -16,6 +16,8 @@ use App\InvoiceDetails; use App\InvoiceStatuses; use App\SupplierBooking; use App\SettingSupplier; +use App\Marking; +use App\User; use PDF; class InvoiceController extends Controller @@ -301,7 +303,7 @@ class InvoiceController extends Controller } - public function getPO(Request $request, $id) + public function customerToCIEFPO(Request $request, $id) { // Booking Exist and Belongs to User or is Admin if ($request->user()->role === 'member') { @@ -320,30 +322,34 @@ 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(); + $marking = User::find($booking->user_id)->marking; $data = [ 'title' => 'Purchase 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' => $invoice->buyer_company, 'reg_no' => $invoice->reg_no, 'address' => $invoice->address, 'gst' => '', - 'phone' => $invoice->contact_no + 'phone' => $invoice->contact_no, + 'marking_no' => $marking ], 'seller' => [ - 'seller_company' => 'CIEF Worldwide Sdn Bhd', + 'seller_company' => 'CIEF Worldwide Sdn Bhd (1134596-M)', 'address' => 'Malaysia Global Innovation & Creativity Centre, Level 1 CWS, Block 3730, Persiaran APEC 63000 Cyberjaya.', 'phone' => '018 2909252', - 'date' => $invoice->updated_at, - 'po_number' => $invoice->po_number, - 'order_number' => $booking->order_no ], 'lines' => $lines, 'amount' => $invoice->amount ]; - PDF::setOptions(['dpi' => 150, 'defaultFont' => 'courier']); $pdf = PDF::loadView('pdf/po', $data); @@ -352,74 +358,7 @@ class InvoiceController extends Controller } - public function showpo() { - - $booking = Booking::where('id', 2018)->first(); - $invoice = Invoice::where('booking_id', $booking['id'])->first(); - $lines = InvoiceDetails::where('invoice_id', $invoice->id)->get(); - - $data = [ - 'title' => 'Delivery Order', - 'buyer' => [ - 'buyer_company' => $invoice->buyer_company, - 'reg_no' => $invoice->reg_no, - 'address' => $invoice->address, - 'gst' => '', - 'phone' => $invoice->contact_no - ], - 'seller' => [ - 'seller_company' => 'CIEF Worldwide Sdn Bhd', - 'address' => 'Malaysia Global Innovation & Creativity Centre, - Level 1 CWS, Block 3730, - Persiaran APEC 63000 Cyberjaya.', - 'phone' => '018 2909252', - 'date' => $invoice->updated_at, - 'po_number' => $invoice->po_number, - 'order_number' => $booking->order_no - ], - 'lines' => $lines, - 'amount' => $invoice->amount - ]; - - // Send - return view('pdf/po', $data); - - } - - public function showdo() { - - $booking = Booking::where('id', 2018)->first(); - $invoice = Invoice::where('booking_id', $booking['id'])->first(); - $lines = InvoiceDetails::where('invoice_id', $invoice->id)->get(); - - $data = [ - 'title' => 'Delivery Order', - 'buyer' => [ - 'buyer_company' => $invoice->buyer_company, - 'reg_no' => $invoice->reg_no, - 'address' => $invoice->address, - 'gst' => '', - 'phone' => $invoice->contact_no - ], - 'seller' => [ - 'seller_company' => 'CIEF Worldwide Sdn Bhd', - 'address' => 'Malaysia Global Innovation & Creativity Centre, Level - 1 CWS, Block 3730, Persiaran APEC 63000 Cyberjaya.', - 'phone' => '018 2909252', - 'date' => $invoice->updated_at, - 'po_number' => $invoice->po_number, - 'order_number' => $booking->order_no - ], - 'lines' => $lines, - 'amount' => $invoice->amount - ]; - - // Send - return view('pdf/do', $data); - - } - - public function getDO(Request $request, $id) + public function CIEFToSupplierDO(Request $request, $id) { // Booking Exist and Belongs to User or is Admin if ($request->user()->role === 'member') { @@ -438,25 +377,31 @@ 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(); + $supplier = SettingSupplier::where('id', $supplierbooking->supplier_id)->first(); $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' => $invoice->buyer_company, - 'reg_no' => $invoice->reg_no, - 'address' => $invoice->address, + 'buyer_company' => 'CIEF Worldwide Sdn Bhd (1134596-M)', + 'reg_no' => '', + 'address' => 'Malaysia Global Innovation & Creativity Centre, Level + 1 CWS, Block 3730, Persiaran APEC 63000 + Cyberjaya.', 'gst' => '', - 'phone' => $invoice->contact_no + 'phone' => '018 2909252', + 'marking_no' => '' ], 'seller' => [ - 'seller_company' => 'CIEF Worldwide Sdn Bhd', - 'address' => 'Malaysia Global Innovation & Creativity Centre, Level - 1 CWS, Block 3730, Persiaran APEC 63000 - Cyberjaya.', - 'phone' => '018 2909252', - 'date' => $invoice->updated_at, - 'po_number' => $invoice->po_number, - 'order_number' => $booking->order_no + 'seller_company' => $supplier->company_name, + 'address' => '', + 'phone' => '', ], 'lines' => $lines, 'amount' => $invoice->amount @@ -469,7 +414,39 @@ class InvoiceController extends Controller } - public function getSupplierDO($id) + public function CIEFToCustomerInvoice($id) + { + $booking = Booking::where('id', $id)->first(); + $invoice = Invoice::where('booking_id', $booking['id'])->first(); + $lines = InvoiceDetails::where('invoice_id', $invoice->id)->get(); + + $data = [ + 'title' => 'INVOICE', + 'detail' => [ + 'date' => Carbon::createFromFormat('Y-m-d H:i:s', $booking->created_at)->format('d-m-Y'), + 'ei' => 'EI-202009-000001', + 'edo' => '', + 'ref' => $booking->id + ], + 'billto' => [ + 'buyer_company' => $invoice->buyer_company, + 'reg_no' => $invoice->reg_no, + 'address' => $invoice->address, + 'gst' => '', + 'phone' => $invoice->contact_no, + 'marking_no' => '' + ], + 'lines' => $lines, + 'amount' => $invoice->amount + ]; + + $pdf = PDF::loadView('pdf/invoice', $data); + + // Send + return $pdf->download('invoice.pdf'); + } + + public function CIEFToCustomerDO($id) { // Generate PO @@ -508,15 +485,6 @@ class InvoiceController extends Controller return $pdf->download('do.pdf'); } - // private invoiceExist($id) - // { - - // } - - // private invoiceStatus($id) { - - // } - private function isUser($booking_id, $user_id) { $booking = Booking::where([ diff --git a/resources/assets/js/pages/admin/booking/completed.vue b/resources/assets/js/pages/admin/booking/completed.vue index 74af3821..c7c5518b 100644 --- a/resources/assets/js/pages/admin/booking/completed.vue +++ b/resources/assets/js/pages/admin/booking/completed.vue @@ -78,6 +78,9 @@ + @@ -473,6 +476,22 @@ export default { link.click() }) .catch(err => console.error(JSON.stringify(err))) + }, + onDownloadInvoice () { + const url = '/api/invoice/' + this.booking_details.id + '/invoice' + axios({ + url: url, + method: 'GET', + responseType: 'blob' // important + }).then(resp => { + const url = window.URL.createObjectURL(new Blob([resp.data])) + const link = document.createElement('a') + link.href = url + link.setAttribute('download', 'invoice.pdf') + document.body.appendChild(link) + link.click() + }) + .catch(err => console.error(JSON.stringify(err))) } }, directives: { diff --git a/resources/assets/js/pages/booking/completed.vue b/resources/assets/js/pages/booking/completed.vue index db496a33..2f768bf0 100644 --- a/resources/assets/js/pages/booking/completed.vue +++ b/resources/assets/js/pages/booking/completed.vue @@ -58,6 +58,9 @@ + @@ -252,6 +255,22 @@ export default { link.click() }) .catch(err => console.error(JSON.stringify(err))) + }, + onDownloadInvoice () { + const url = '/api/invoice/' + this.booking_details.id + '/invoice' + axios({ + url: url, + method: 'GET', + responseType: 'blob' // important + }).then(resp => { + const url = window.URL.createObjectURL(new Blob([resp.data])) + const link = document.createElement('a') + link.href = url + link.setAttribute('download', 'invoice.pdf') + document.body.appendChild(link) + link.click() + }) + .catch(err => console.error(JSON.stringify(err))) } } } diff --git a/resources/views/pdf/invoice.blade.php b/resources/views/pdf/invoice.blade.php index 927a1ae3..d26a7954 100644 --- a/resources/views/pdf/invoice.blade.php +++ b/resources/views/pdf/invoice.blade.php @@ -1,71 +1,169 @@ - +
-
+
+ CIEF WORLDWIDE SDN BHD
+ (1134596-M)
+ Malaysian Global Innovation & Creativity Center
+ Level 1 CWS, Block 3730, Persiaran APEC,
+ 63000 Cyberjaya, Malaysian.
+ Tel: 018-2909252
+
|
-
-
-
-
- CIEF WORLDWIDE SDN BHD
- 1134596-M |
-
-
-
-
- INVOICE
-
-
- EI No:
-
-
- EI-1234566777
-
- |
- ||||
| No | +Stock Code | +Description | +Quantity | +Unit Price (RM) | +Total Amount (RM) | +
|---|---|---|---|---|---|
| {{$line->order}} | +{{$line->stock_code}} | +{{$line->description}} | +{{$line->quantity}} | +{{number_format($line->unit_price_rm, 2)}} | +{{number_format($line->total, 2)}} | +
| + | Subtotal | +{{ number_format($amount, 2) }} | +|||
| + | Total | +{{ number_format($amount, 2) }} | +|||
- Marking No: - 1234567 -
-- Bill To: -
- Sell To: -
| No | +Stock Code | Description | Quantity | Unit Price (RM) | @@ -146,6 +185,7 @@ @foreach ($lines as $line)|||||
|---|---|---|---|---|---|---|---|---|---|
| {{$line->order}} | +{{$line->stock_code}} | {{$line->description}} | {{$line->quantity}} | {{number_format($line->unit_price_rm, 2)}} | @@ -154,18 +194,25 @@ @endforeach|||||
| + | |||||||||
| Subtotal | {{ number_format($amount, 2) }} | ||||||||
| + | Total | -{{ number_format($amount, 2) }} | +{{ number_format($amount, 2) }} | ||||||