mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-19 12:24:09 +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;
|
||||
|
||||
Reference in New Issue
Block a user