From 4f313b9e72e4f93bfc103dbd6e61dbc6dc13e413 Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Wed, 9 Sep 2020 18:31:22 +0800 Subject: [PATCH] before cief to customer do --- app/Http/Controllers/InvoiceController.php | 162 ++++++------- .../js/pages/admin/booking/completed.vue | 19 ++ .../assets/js/pages/booking/completed.vue | 19 ++ resources/views/pdf/invoice.blade.php | 220 +++++++++++++----- resources/views/pdf/po.blade.php | 87 +++++-- routes/api.php | 7 +- 6 files changed, 333 insertions(+), 181 deletions(-) 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 @@ - + - + Document +
+ +

+ CIEF WORLDWIDE SDN BHD + (1134596-M)
+ Malaysian Global Innovation & Creativity Center
+ Level 1 CWS, Block 3730, Persiaran APEC,
+ 63000 Cyberjaya, Malaysian.
+ Tel: 018-2909252 +

+
+
{{$title}}
+ @if($detail['ei']) +
EI#: {{$detail['ei']}}
+ @endif + @if($detail['edo']) +
EDO#: {{$detail['edo']}}
+ @endif +
Ref#: {{$detail['ref']}}
+
Date: {{$detail['date']}}
+
Page: 1 of 1
+
+
+ +
+ Bill To +
+
+
+ {{$billto['buyer_company']}} +
+
+ {{$billto['address']}} +
+
+ Phone: {{$billto['phone']}} +
+
+ +
+
- - - - + + + + + + + + + + + + @foreach ($lines as $line) + + + + + + + + + @endforeach + + + + + + + + + + + + +
-
- -

- CIEF WORLDWIDE SDN BHD - 1134596-M
- Malaysian Global Innovation & Creativity Center
- Level 1 CWS, Block 3730, Persiaran APEC,
- 63000 Cyberjaya, Malaysian.
- Tel: 018-2909252 -

-
-
-
-
- INVOICE -
- - EI No: - - - EI-1234566777 - -
-
NoStock CodeDescriptionQuantityUnit 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: -

AMK Store
- 19, Jalan Cheras Indah 21, - Taman Cheras Indah, - 56100 Kuala Lumpur -

-
-
-

- Sell To: -

AMK Store
- 19, Jalan Cheras Indah 21, - Taman Cheras Indah, - 56100 Kuala Lumpur -

-
-
- - + \ No newline at end of file diff --git a/resources/views/pdf/po.blade.php b/resources/views/pdf/po.blade.php index e0eac015..44f8a0d5 100644 --- a/resources/views/pdf/po.blade.php +++ b/resources/views/pdf/po.blade.php @@ -13,14 +13,18 @@ padding: 2em; border: 1px solid black; } - .buyer { + .buyer, .header { max-width: 45%; float: left; } - .seller { + .seller, .doc-details { max-width: 45%; float: right; } + .doc-details { + padding: 1em; + border: 1px solid black; + } .buyer-seller-container { } .buyer-company { @@ -52,6 +56,9 @@ width: 100%; } + th { + border-bottom: 1px solid black; + } .clear-fix::after { content: ""; clear: both; @@ -70,21 +77,59 @@ } .buyer-seller-title { font-size: 1.2em; - /* text-decoration-line: underline; */ - /* text-decoration-style: double; */ margin-bottom: 0.2em; } + .subtotal td { + border-top: 1px solid black; + } + .total { + border-top: 1px solid black; + border-bottom: 1px double black; + font-weight: bolder; + } -
-

{{ $title }}

+
+
+

{{ $title }}

+
+
+ @if ($detail['po']) +
+ PO#: {{ $detail['po'] }} +
+ @endif + @if ($detail['do']) +
+ DO#: {{ $detail['do'] }} +
+ @endif +
+ Ref#: {{ $detail['ref'] }} +
+
+ Date: {{ $detail['date'] }} +
+
+ Page: 1 of 1 +
+
+
+ +
+
Buyer
+ @if($buyer['marking_no']) +
+ Marking#: {{$buyer['marking_no']}} +
+ @endif {{ $buyer['buyer_company'] }} @@ -111,24 +156,17 @@
{{ $seller['address'] }}
+ @if($seller['phone'])
Phone: {{ $seller['phone'] }}
-
- Date: {{ $seller['date'] }} -
-
- PO#: {{ $seller['po_number'] }} -
-
- Order#: {{ $seller['order_number'] }} -
+ @endif +



- {{$lines[0]->description}} + @@ -146,6 +185,7 @@ @foreach ($lines as $line) + @@ -154,18 +194,25 @@ @endforeach - - + + - + - +

Billing Detail

@@ -136,6 +174,7 @@
NoStock Code Description Quantity Unit Price (RM)
{{$line->order}}{{$line->stock_code}} {{$line->description}} {{$line->quantity}} {{number_format($line->unit_price_rm, 2)}}
Subtotal {{ number_format($amount, 2) }}
Total{{ number_format($amount, 2) }}{{ number_format($amount, 2) }}
+
+ + + + \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index 7bd70efc..82c0f5d2 100644 --- a/routes/api.php +++ b/routes/api.php @@ -53,8 +53,9 @@ Route::group(['middleware' => 'auth:api'], function () { Route::get('invoice/{id}', 'InvoiceController@show'); Route::post('invoice/{id}', 'InvoiceController@create'); Route::put('invoice/{id}', 'InvoiceController@edit'); - Route::get('invoice/{id}/po', 'InvoiceController@getPO'); - Route::get('invoice/{id}/do', 'InvoiceController@getDO'); + Route::get('invoice/{id}/po', 'InvoiceController@customerToCIEFPO'); + Route::get('invoice/{id}/do', 'InvoiceController@CIEFToCustomerDO'); + Route::get('invoice/{id}/invoice', 'InvoiceController@CIEFToCustomerInvoice'); //Route::get('notification/user', 'NotificationController@getUserMessage'); //Route::post('notification/read-notification/{notification_id}', 'NotificationController@readNotification'); @@ -142,7 +143,7 @@ Route::group(['middleware' => ['role:admin']], function() { // New routes for invoice Route::patch('invoice/{id}/status', 'InvoiceController@updateStatus'); - Route::get('invoice/{id}/supplierdo', 'InvoiceController@getSupplierDO'); + Route::get('invoice/{id}/supplierdo', 'InvoiceController@CIEFToSupplierDO'); Route::post('invoice/{id}/comment', 'InvoiceController@postStatus'); Route::get('admin/complete-orders', 'BookingController@adminShowCompletedOrders');