mirror of
https://gitlab.com/uldvstar/exchange-2.0.git
synced 2026-08-19 04:24:16 +00:00
Merge branch 'debtor' into 'development'
Invoice + PO + DO See merge request CIEFWorldwideSdnBhd/exchange-2.0!104
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user