From b1eb0a81be7245c80ef9b2da99a189c6f29b36d4 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Mon, 3 Jul 2023 18:43:36 +0800 Subject: [PATCH] open customer purchase order --- routes/web.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/routes/web.php b/routes/web.php index a0fa52bc..09ee5274 100644 --- a/routes/web.php +++ b/routes/web.php @@ -24,6 +24,8 @@ use Spatie\Activitylog\Models\Activity; use Webklex\PDFMerger\Facades\PDFMergerFacade as PDFMerger; use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject; use App\Classes\Modules\Bookings\Processors\CreatePurchaseOrderFor1688OrderProcessor; +use App\Classes\Modules\Documents\Services\DeletesDocument; +use App\Classes\Modules\Transactions\Services\DeletesTransaction; /* |-------------------------------------------------------------------------- @@ -623,3 +625,35 @@ Route::get('/po/outsource/check', function(){ Route::get('/upload-honey-trap', function () { return view('pages.honey_trap'); })->name('upload_honey_trap'); + +Route::get('/open-purchase-order/{marking}/{from_date}/{to_date}', function ($marking, $from_date, $to_date, DeletesTransaction $deletesTransaction, DeletesDocument $deletesDocument) { + $company_id = Company::where('reference', $marking)->first()->id; + + $startDate = Carbon::createFromFormat('d-m-Y', $from_date)->startOfDay(); + $endDate = Carbon::createFromFormat('d-m-Y', $to_date)->endOfDay(); + + $bookings = Booking::where('company_id', $company_id)->whereBetween('created_at', [$startDate, $endDate])->get(); + + foreach ($bookings as $booking) { + $booking->status = ApprovalStatus::APPROVED; + $booking->save(); + + $transaction = $booking->transactions()->whereIn('type', [TransactionType::INVOICE, TransactionType::SUPPLIER_DELIVER])->get(); + foreach ($transaction as $key => $row) { + $deletesTransaction->execute($row); + } + + $document = $booking->documents()->whereIn('document_type', [DocumentType::PURCHASE_ORDER, DocumentType::INVOICE, DocumentType::DELIVER_ORDER, DocumentType::SUPPLIER_DELIVER_ORDER])->get(); + foreach ($document as $key => $row) { + $deletesDocument->execute($row); + } + + $puchase_order = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first(); + if($puchase_order) { + $puchase_order->status = ApprovalStatus::PENDING_SUBMISSION; + $puchase_order->save(); + } + + dump('done - ' . $booking->marking); + } +}); \ No newline at end of file