mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-19 04:14:04 +00:00
customer do and po
This commit is contained in:
@@ -14,6 +14,7 @@ use App\Booking;
|
||||
use App\Invoice;
|
||||
use App\InvoiceDetails;
|
||||
use App\InvoiceStatuses;
|
||||
use PDF;
|
||||
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
@@ -309,17 +310,87 @@ class InvoiceController extends Controller
|
||||
|
||||
// Generate PO
|
||||
|
||||
$booking = Booking::where('id', $id)->first();
|
||||
$invoice = Invoice::where('booking_id', $booking['id'])->first();
|
||||
$lines = InvoiceDetails::where('invoice_id', $invoice->id)->get();
|
||||
|
||||
$data = [
|
||||
'title' => 'Purchase Order',
|
||||
'buyer' => [
|
||||
'buyer_company' => $invoice->buyer_company,
|
||||
'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
|
||||
];
|
||||
$pdf = PDF::loadView('pdf/po', $data);
|
||||
|
||||
|
||||
// Send
|
||||
return response()->json(['message' => 'successful'], 200);
|
||||
return $pdf->download('po.pdf');
|
||||
|
||||
}
|
||||
|
||||
public function getDO($id)
|
||||
public function getDO(Request $request, $id)
|
||||
{
|
||||
// Ensure Invoice Exist and Completed
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
$data = [
|
||||
'title' => 'Delivery Order',
|
||||
'buyer' => [
|
||||
'buyer_company' => 'CIEF Worldwide Sdn Bhd',
|
||||
'reg_no' => '',
|
||||
'address' => 'Malaysia Global Innovation & Creativity Centre, Level
|
||||
1 CWS, Block 3730, Persiaran APEC 63000
|
||||
Cyberjaya.',
|
||||
'gst' => '',
|
||||
'phone' => '018 2909252'
|
||||
],
|
||||
'seller' => [
|
||||
'seller_company' => $invoice->buyer_company,
|
||||
'address' => $invoice->address,
|
||||
'phone' => $invoice->contact_no,
|
||||
'date' => $invoice->updated_at,
|
||||
'po_number' => $invoice->po_number,
|
||||
'order_number' => $booking->order_no
|
||||
],
|
||||
'lines' => $lines,
|
||||
'amount' => $invoice->amount
|
||||
];
|
||||
$pdf = PDF::loadView('pdf/po', $data);
|
||||
|
||||
|
||||
// Send
|
||||
return $pdf->download('do.pdf');
|
||||
|
||||
}
|
||||
|
||||
@@ -358,9 +429,9 @@ class InvoiceController extends Controller
|
||||
}
|
||||
|
||||
private function invoiceStatus($booking_id) {
|
||||
$invoice = Invoice::where('booking_id', $booking_id).first();
|
||||
$invoice = Invoice::where('booking_id', $booking_id)->first();
|
||||
if (!$invoice) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
$currentstatus = InvoiceStatuses::where('invoice_id', $invoice['id'])->latest('created_at')->first()->status;
|
||||
return $currentstatus;
|
||||
|
||||
@@ -223,13 +223,35 @@ export default {
|
||||
},
|
||||
onDownloadPO () {
|
||||
const url = '/api/invoice/' + this.booking_details.id + '/po'
|
||||
axios
|
||||
.get(url)
|
||||
.then(resp => console.log(resp))
|
||||
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', 'po.pdf')
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
})
|
||||
.catch(err => console.error(JSON.stringify(err)))
|
||||
},
|
||||
onDownloadDO () {
|
||||
alert('Downloading DO')
|
||||
const url = '/api/invoice/' + this.booking_details.id + '/do'
|
||||
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', 'po.pdf')
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
})
|
||||
.catch(err => console.error(JSON.stringify(err)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Hi</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to ItSolutionStuff.com - {{ $title }}</h1>
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
||||
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
|
||||
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
|
||||
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
|
||||
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
|
||||
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,164 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: Helvetica, "Times-Roman", Courier;
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
}
|
||||
.details {
|
||||
float: right;
|
||||
max-width: 30%;
|
||||
padding: 2em;
|
||||
border: 1px solid black;
|
||||
}
|
||||
.buyer {
|
||||
max-width: 45%;
|
||||
float: left;
|
||||
}
|
||||
.seller {
|
||||
max-width: 45%;
|
||||
float: right;
|
||||
}
|
||||
.buyer-seller-container {
|
||||
}
|
||||
.buyer-company {
|
||||
display: block;
|
||||
font-size: 16px;
|
||||
font-weight: bolder;
|
||||
}
|
||||
.reg {
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
}
|
||||
.address {
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
.gst {
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
}
|
||||
.contact-no {
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
}
|
||||
.seller {
|
||||
width: 45%;
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
|
||||
}
|
||||
.clear-fix::after {
|
||||
content: "";
|
||||
clear: both;
|
||||
display: table;
|
||||
}
|
||||
td {
|
||||
padding: 0.4em;
|
||||
text-align: center;
|
||||
}
|
||||
td.description, th.description {
|
||||
text-align: left;
|
||||
}
|
||||
td, th {
|
||||
margin-top: 0.6em;
|
||||
margin-right: 0.6em;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h1>{{ $title }}</h1>
|
||||
</div>
|
||||
<div class="buyer-seller-container clear-fix">
|
||||
<div class="buyer">
|
||||
<span class="buyer-company">
|
||||
{{ $buyer['buyer_company'] }}
|
||||
</span>
|
||||
<span class="reg">
|
||||
X-123456
|
||||
</span>
|
||||
<span class="address">
|
||||
{{ $buyer['address'] }}
|
||||
</span>
|
||||
<!-- <span class="gst">
|
||||
GST: 12345678
|
||||
</span> -->
|
||||
<span class="contact-no">
|
||||
Phone: {{ $buyer['phone'] }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="seller">
|
||||
<span class="buyer-company">
|
||||
{{ $seller['seller_company'] }}
|
||||
</span>
|
||||
<div class="address">
|
||||
{{ $seller['address'] }}
|
||||
</div>
|
||||
<div class="contact-no">
|
||||
Phone: {{ $seller['phone'] }}
|
||||
</div>
|
||||
<div class="contact-no">
|
||||
Date: {{ $seller['date'] }}
|
||||
</div>
|
||||
<div class="contact-no">
|
||||
PO#: {{ $seller['po_number'] }}
|
||||
</div>
|
||||
<div class="contact-no">
|
||||
Order#: {{ $seller['order_number'] }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<table>
|
||||
<caption>
|
||||
<h3>Billing Detail</h3>
|
||||
</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>No</th>
|
||||
<th class="description">Description</th>
|
||||
<th>Quantity</th>
|
||||
<th>Unit Price (RM)</th>
|
||||
<th>Total Amount</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($lines as $line)
|
||||
<tr>
|
||||
<td>{{$line->order}}</td>
|
||||
<td class="description">{{$line->description}}</td>
|
||||
<td>{{$line->quantity}}</td>
|
||||
<td>{{number_format($line->unit_price_rm, 2)}}</td>
|
||||
<td>{{number_format($line->total, 2)}}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="3"></td>
|
||||
<td>Subtotal</td>
|
||||
<td>{{ number_format($amount, 2) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3"></td>
|
||||
<td>GST</td>
|
||||
<td>0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3"></td>
|
||||
<td>Total</td>
|
||||
<td>{{ number_format($amount, 2) }}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user