Merge branch 'development' of https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0 into development

This commit is contained in:
ahmedsophyudden
2022-04-25 08:42:15 +08:00
4 changed files with 122 additions and 65 deletions
@@ -14,6 +14,7 @@ use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use App\Classes\Exceptions\MalformedRequestException;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\DocumentType;
class DownloadBookingDocumentLogic
{
@@ -26,9 +27,9 @@ class DownloadBookingDocumentLogic
*/
public function execute(Request $request)
{
Auth::login(User::findOrFail(1));
$zip_file = $request->input('type').'.zip';
$document_type = str_replace(' ', '', $request->input('type'));
$zip_file = $document_type.'.zip';
$attachment = storage_path().'/app/documents/collections/' . $zip_file;
$zip = new ZipArchive();
@@ -36,19 +37,40 @@ class DownloadBookingDocumentLogic
$bookings = Booking::where('status', ApprovalStatus::COMPLETED)
->whereDate('created_at', '>=', Carbon::parse($request->input('startDate')))
->whereDate('created_at', '<=', Carbon::parse($request->input('endDate')))->whereHas('transactions', function ($query) use ($request){
->whereDate('created_at', '<=', Carbon::parse($request->input('endDate')))
->whereHas('transactions', function ($query) use ($request){
return $query->where('type', TransactionType::PAYMENT)->whereHas('transactions', function ($query) use ($request){
return $query->where('type', TransactionType::BILL)->where('issuer', $request->input('supplier'));
});
})->get();
if (!count($bookings)) throw new MalformedRequestException('No available file to download');
foreach ($bookings as $booking) {
$file = $booking->documents()->where('document_type', $request->input('type'))->first()->files()->first();
$zip->addFile(Storage::disk('documents')->path($file->file->file_info->original->file), $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf');
}
if ($document_type == 'INVOICEPODO' || $document_type == 'INVOICEPODOSDO') {
$invoice_file = $booking->documents()->where('document_type', DocumentType::INVOICE)->first()->files()->first();
$purchase_file = $booking->documents()->where('document_type', DocumentType::PURCHASE_ORDER)->first()->files()->first();
$deliver_file = $booking->documents()->where('document_type', DocumentType::DELIVER_ORDER)->first()->files()->first();
if ($document_type == 'INVOICEPODOSDO') {
$supplier_deliver_order_file = $booking->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->first()->files()->first();
}
$zip->addFile(Storage::disk('documents')->path($invoice_file->file->file_info->original->file), 'invoice-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf');
$zip->addFile(Storage::disk('documents')->path($purchase_file->file->file_info->original->file), 'purchase-order-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf');
$zip->addFile(Storage::disk('documents')->path($deliver_file->file->file_info->original->file), 'deliver-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf');
$zip->addFile(Storage::disk('documents')->path($supplier_deliver_order_file->file->file_info->original->file), 'supplier-deliver-order-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf');
}
else {
$file = $booking->documents()->where('document_type', $document_type)->first()->files()->first();
$zip->addFile(Storage::disk('documents')->path($file->file->file_info->original->file), $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf');
}
}
$zip->close();
while (ob_get_level()) {
ob_end_clean();
@@ -0,0 +1,69 @@
<?php
namespace App\Classes\Modules\Transactions\Processors;
use App\Classes\Modules\Documents\Services\CreatesDocument;
use App\Classes\Modules\Documents\Services\CreatesFiles;
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\DocumentType;
use App\Models\Booking;
use Meneses\LaravelMpdf\Facades\LaravelMpdf;
class CreateInvoiceTransactionProcessor
{
/** @var CreatesDocument */
private $createsDocument;
/** @var CreatesFiles */
private $createsFile;
/**
* CreateInvoiceTransactionProcessor constructor.
* @param CreatesDocument $createsDocument
* @param CreatesFiles $createsFile
*/
public function __construct(CreatesDocument $createsDocument, CreatesFiles $createsFile)
{
$this->createsDocument = $createsDocument;
$this->createsFile = $createsFile;
}
/**
* @param Booking $booking
* @return void
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute($transaction, $po_order_transaction, $supplier, $document_type)
{
$lowercaseDocumentType = strtolower($document_type);
if ($document_type !== DocumentType::SUPPLIER_DELIVER_ORDER) {
$order_pdf = LaravelMpdf::loadView('pages.pdfs.' . $lowercaseDocumentType, ['invoice_transaction' => $transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]);
$document_object = new DocumentObject(
$document_type,
[chunk_split('data:application/pdf;base64,' . base64_encode($order_pdf->output()))],
'',
ApprovalStatus::COMPLETED,
$lowercaseDocumentType . 's'
);
}
else {
$order_pdf = LaravelMpdf::loadView('pages.pdfs.supplier_deliver_order', ['supplier_deliver_order_transaction' => $transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]);
$document_object = new DocumentObject(
$document_type,
[chunk_split('data:application/pdf;base64,'.base64_encode($order_pdf->output()))],
'',
ApprovalStatus::COMPLETED,
$lowercaseDocumentType . 's'
);
}
$document = $this->createsDocument->execute($po_order_transaction->booking, $document_object);
$this->createsFile->execute($document, $document_object);
}
}
@@ -55,15 +55,12 @@ class CreateInvoiceTransactionProcessor
/** @var FetchesCompany */
private $fetchesCompany;
/** @var CreatesDocument */
private $createsDocument;
/** @var CreatesFiles */
private $createsFile;
/** @var UpdatesBookingStatus */
private $updatesBookingStatus;
/** @var CreateInvoiceDocumentProcessor */
private $invoiceDocumentProcessor;
/**
* CreateInvoiceTransactionProcessor constructor.
* @param ListsTransactions $listsTransactions
@@ -75,11 +72,10 @@ class CreateInvoiceTransactionProcessor
* @param FetchesServiceConfigurations $fetchesServiceConfigurations
* @param CalculatesBookingCurrencyAverageRate $calculatesBookingCurrencyAverageRate
* @param FetchesCompany $fetchesCompany
* @param CreatesDocument $createsDocument
* @param CreatesFiles $createsFile
* @param UpdatesBookingStatus $updatesBookingStatus
* @param CreateInvoiceDocumentProcessor $invoiceDocumentProcessor
*/
public function __construct(ListsTransactions $listsTransactions, CreatesTransaction $createsTransaction, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CalculatesBookingPaidAmount $calculatesBookingPaidAmount, CalculatesBookingPayableAmount $calculatesBookingPayableAmount, CalculatesBookingTransferredAmount $calculatesBookingTransferredAmount, FetchesServiceConfigurations $fetchesServiceConfigurations, CalculatesBookingCurrencyAverageRate $calculatesBookingCurrencyAverageRate, FetchesCompany $fetchesCompany, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesBookingStatus $updatesBookingStatus)
public function __construct(ListsTransactions $listsTransactions, CreatesTransaction $createsTransaction, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CalculatesBookingPaidAmount $calculatesBookingPaidAmount, CalculatesBookingPayableAmount $calculatesBookingPayableAmount, CalculatesBookingTransferredAmount $calculatesBookingTransferredAmount, FetchesServiceConfigurations $fetchesServiceConfigurations, CalculatesBookingCurrencyAverageRate $calculatesBookingCurrencyAverageRate, FetchesCompany $fetchesCompany, UpdatesBookingStatus $updatesBookingStatus, CreateInvoiceTransactionProcessor $invoiceDocumentProcessor)
{
$this->listsTransactions = $listsTransactions;
$this->createsTransaction = $createsTransaction;
@@ -90,9 +86,8 @@ class CreateInvoiceTransactionProcessor
$this->fetchesServiceConfigurations = $fetchesServiceConfigurations;
$this->calculatesBookingCurrencyAverageRate = $calculatesBookingCurrencyAverageRate;
$this->fetchesCompany = $fetchesCompany;
$this->createsDocument = $createsDocument;
$this->createsFile = $createsFile;
$this->updatesBookingStatus = $updatesBookingStatus;
$this->invoiceDocumentProcessor = $invoiceDocumentProcessor;
}
@@ -101,7 +96,7 @@ class CreateInvoiceTransactionProcessor
* @return void
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Booking $booking)
public function execute(Booking $booking)
{
if ($booking->status === ApprovalStatus::COMPLETED) {
@@ -116,7 +111,7 @@ class CreateInvoiceTransactionProcessor
return;
}
// confirm that all payments has been transferred
if($this->calculatesBookingTransferredAmount->execute($booking) !== $this->calculatesBookingPaidAmount->execute($booking)){
if ($this->calculatesBookingTransferredAmount->execute($booking) !== $this->calculatesBookingPaidAmount->execute($booking)) {
return;
}
@@ -127,7 +122,7 @@ class CreateInvoiceTransactionProcessor
$constants = SegmentConstant::where('reference', SegmentConstants::SERVICE_TYPE)->where('detail->id', $booking->service->id)->first();
if($constants->detail->is_billable && !$po_order_transaction) {
if ($constants->detail->is_billable && !$po_order_transaction) {
return;
}
@@ -170,42 +165,14 @@ class CreateInvoiceTransactionProcessor
$supplier = $this->fetchesCompany->execute(['id' => $transaction->receiver]);
$purchase_order_pdf = LaravelMpdf::loadView('pages.pdfs.purchase_order', ['invoice_transaction' => $invoice_transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]);
$document_object = new DocumentObject(
DocumentType::PURCHASE_ORDER,
[chunk_split('data:application/pdf;base64,'.base64_encode($purchase_order_pdf->output()))],
'',
ApprovalStatus::COMPLETED,
'purchase_orders'
);
/** @var Document $document */
$document = $this->createsDocument->execute($po_order_transaction->booking, $document_object);
$this->createsFile->execute($document, $document_object);
// purchase order
$this->invoiceDocumentProcessor->execute($invoice_transaction, $po_order_transaction, $supplier, DocumentType::PURCHASE_ORDER);
$deliver_order_pdf = LaravelMpdf::loadView('pages.pdfs.deliver_order', ['invoice_transaction' => $invoice_transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]);
$document_object = new DocumentObject(
DocumentType::DELIVER_ORDER,
[chunk_split('data:application/pdf;base64,'.base64_encode($deliver_order_pdf->output()))],
'',
ApprovalStatus::COMPLETED,
'delivery_orders'
);
// deliver order
$this->invoiceDocumentProcessor->execute($invoice_transaction, $po_order_transaction, $supplier, DocumentType::DELIVER_ORDER);
/** @var Document $document */
$document = $this->createsDocument->execute($po_order_transaction->booking, $document_object);
$this->createsFile->execute($document, $document_object);
$invoice_pdf = LaravelMpdf::loadView('pages.pdfs.invoice', ['invoice_transaction' => $invoice_transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]);
$document_object = new DocumentObject(
DocumentType::INVOICE,
[chunk_split('data:application/pdf;base64,'.base64_encode($invoice_pdf->output()))],
'',
ApprovalStatus::COMPLETED,
'invoices'
);
$document = $this->createsDocument->execute($po_order_transaction->booking, $document_object);
$this->createsFile->execute($document, $document_object);
// invoice
$this->invoiceDocumentProcessor->execute($invoice_transaction, $po_order_transaction, $supplier, DocumentType::INVOICE);
$billNumber = $this->generatesTransactionBillNumber->execute('SPDO-');
@@ -233,16 +200,8 @@ class CreateInvoiceTransactionProcessor
);
$supplier_deliver_order_transaction = $this->createsTransaction->execute($po_order_transaction->booking, $transaction_object);
$supplier_order_pdf = LaravelMpdf::loadView('pages.pdfs.supplier_deliver_order', ['supplier_deliver_order_transaction' => $supplier_deliver_order_transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]);
$document_object = new DocumentObject(
DocumentType::SUPPLIER_DELIVER_ORDER,
[chunk_split('data:application/pdf;base64,'.base64_encode($supplier_order_pdf->output()))],
'',
ApprovalStatus::COMPLETED,
'supplier_delivery_orders'
);
$document = $this->createsDocument->execute($po_order_transaction->booking, $document_object);
$this->createsFile->execute($document, $document_object);
// supply deliver order
$this->invoiceDocumentProcessor->execute($supplier_deliver_order_transaction, $po_order_transaction, $supplier, DocumentType::SUPPLIER_DELIVER_ORDER);
$this->updatesBookingStatus->execute($booking, ApprovalStatus::COMPLETED);
}
@@ -84,7 +84,14 @@ export default {
type: 'INVOICE',
supplier: null
},
documents: ['INVOICE', 'PURCHASE_ORDER', 'DELIVER_ORDER', 'SUPPLIER_DELIVER_ORDER'],
documents: [
'INVOICE',
'PURCHASE_ORDER',
'DELIVER_ORDER',
'SUPPLIER_DELIVER_ORDER',
'INVOICE + PO + DO',
'INVOICE + PO + DO + SDO'
],
selectedDocumentStatus: false
}
},