group(function () { Route::group(['as' => 'last_mile_delivery.'], function () { Route::get('/', function () { return view('pages.accounts.signup'); })->name('login'); Route::get('/dashboard', function () { return view('pages.delivery.dashboard'); })->name('dashboard'); Route::get('/orders/export', 'Delivery\ExportDeliveryOrdersToExcelController@lineClear')->name('order.export'); }); }); Route::group(['prefix'=> '/last_mile_delivery', 'as' => 'last_mile_delivery.'], function () { Route::get('/', function () { return view('pages.accounts.signup'); })->name('login'); Route::get('/dashboard', function () { return view('pages.delivery.dashboard'); })->name('dashboard'); Route::get('/orders/export', 'Delivery\ExportDeliveryOrdersToExcelController@lineClear')->name('order.export'); }); Route::group(['prefix'=> '/air_shipment', 'as' => 'air_shipment.'], function () { // Route::get('/', function () { // return view('pages.accounts.signup'); // })->name('login'); Route::get('/quotation', function () { return view('pages.airShipment.quotation'); })->name('quotation'); }); Route::get('', function () { return view('pages.accounts.login'); })->name('login'); Route::get('/signup', function () { return view('pages.accounts.sign_up'); })->name('signup'); Route::group(['prefix' => 'swagger'], function () { Route::get('/', function () { return view('swagger.index'); }); Route::get('/json', function () { return view('swagger.json'); }); }); Route::get('/business/claim/{hash}', function ($hash) { return view('pages.accounts.claim_business', ['id' => Crypt::decryptString($hash)]); })->name('company.claim'); Route::get('/account/email/verification/{token}', function ($token) { return view('pages.accounts.email_verified', ['token' => $token]); })->name('account.email.verification'); Route::get('/account/password/reset/{token}', function ($token) { return view('pages.accounts.reset_password', ['token' => $token]); })->name('account.password.reset'); Route::get('/dashboard', function () { return view('pages.dashboard'); })->name('dashboard'); Route::get('/customers', function () { return view('pages.admin.customers'); })->name('customers'); Route::get('/orders', function () { return view('pages.orders.index'); })->name('orders'); Route::get('/orders-table', function () { return view('pages.orders.table'); })->name('ordersTable'); Route::get('/order/show/{order_number}', function ($orderNumber) { return view('pages.orders.profile', ['id' => $orderNumber]); })->name('order.show'); Route::get('/address', function () { return view('pages.addresses.index'); })->name('address'); Route::get('/warehouse-list', function () { return view('pages.warehouse_list'); })->name('warehouse.list'); Route::get('/delivery-list', function () { return view('pages.delivery_list'); })->name('delivery.list'); Route::get('/unclaimed-packinglist', function () { return view('pages.unclaimed_packinglist'); })->name('unclaimed-packinglist.list'); Route::get('/containers', function () { return view('pages.containers'); })->name('containers'); Route::get('/container/show/{reference}', function ($reference) { $container = Container::where('reference', $reference)->first(); return view('pages.templates.warehouseFlow', ['id' => $container->id]); })->name('container.show'); Route::get('/customer/{marking}', function ($marking) { $connection = CompanyConnection::where('invitee_reference', $marking)->first(); $id = $connection->invitee->company->id; return view('pages.customers.profile', ['id' => $id]); })->name('customer.profile'); Route::get('/customer/{marking}/details', function ($marking) { $connection = CompanyConnection::where('invitee_reference', $marking)->first(); $id = $connection->invitee->company->id; return view('pages.customers.profile_details', ['id' => $id]); })->name('customer.profile.details'); Route::get('/customer/{marking}/payment-and-billing', function ($marking) { $connection = CompanyConnection::where('invitee_reference', $marking)->first(); $company_module_id = $connection->invitee->id; return view('pages.customers.paymentsBilling', ['company_module_id' => $company_module_id]); })->name('customer.payment-and-billing'); Route::get('/orders/refresh', function(Request $request){ $packingLists = PackingList::where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->has('containers')->get(); dd($packingLists); $packingLists->each(function (PackingList $packingList) { $packingList->containers()->detach(); }); FetchWarehouseReceiveListFromVTPortalJob::withChain([ new FetchLoadedContainersFromVTPortalJob, new FetchOrdersFromYDPortalJob ])->dispatch(); return redirect('orders'); })->name('orders.refresh'); Route::get('/containers/refresh', function(){ dd((App()->make(FetchLoadedContainersFromVTPortalProcessor::class))->execute()); // FetchLoadedContainersFromVTPortalJob::dispatch(); // FetchContainersStatusUpdateFromVTPortalJob::dispatch(); return redirect('orders'); })->name('containers.refresh'); Route::get('/deliveries/refresh', function(){ FetchDeliveryListFromVTPortalJob::dispatch(); return redirect('orders'); })->name('deliveries.refresh'); Route::get('/order/{id}/download', 'Orders\DownloadOrderQrPdfController@download')->name('order.qr.download'); Route::get('/report/customclearance/{orderid}', 'Reports\CustomcClearanceReportController@download')->name('report.customclearance'); Route::group(['prefix' => 'template', 'as' => 'template.'], function () { Route::get('/payment-and-billing', function () { return view('pages.templates.paymentsBilling'); })->name('payment-and-billing'); Route::get('/shipping-queue', function () { return view('pages.templates.shippingQueue'); })->name('shipping-queue'); }); Route::get('/yiwu', function () { $orders = Order::whereHas('OrderRoles', function($query){ return $query->where('role_id', OrderRoleTypes::ORIGIN_WAREHOUSE)->where('company_module_id', 2358); })->get(); foreach ($orders as $order){ echo ''. $order->reference.' - '.$order->created_at.'
'; } }); Route::get('/guangzhou', function () { $orders = Order::whereHas('OrderRoles', function($query){ return $query->where('role_id', OrderRoleTypes::ORIGIN_WAREHOUSE)->where('company_module_id', 3); })->whereHas('addresses', function($query){ return $query->where('status', ApprovalStatus::APPROVED)->whereIn('state_id', [5, 13, 14]); })->get(); foreach ($orders as $order){ echo ''. $order->reference.' - '.$order->created_at.'
'; } }); Route::get('/debug', function (){ $orders = Order::all(); $issues = []; foreach ($orders as $order){ $received = $order->parcels()->warehouseReceiveList()->sum('quantity'); $shipping = $order->parcels()->shippingList()->sum('quantity'); if( $received < $shipping){ $issues[] = [ 'order' => $order->reference, 'received' => $received, 'shipping' => $shipping ]; } } dd($issues); }); Route::group(['prefix' => 'yd', 'as' => 'yd.'], function () { Route::get('/packingLists', function (Request $request){ $start = $request->input('start_date') ? Carbon::parse($request->input('start_date')): null; $end = $request->input('end_date') ? Carbon::parse($request->input('end_date')): null; (App()->make(FetchPackingListsFromYdPortalProcessor::class))->execute($start, $end); }); Route::get('/containers', function (){ (App()->make(FetchContainersFromYdPortalProcessor::class))->execute(); (App()->make(FetchContainersUpdatesFromYdPortalProcessor::class))->execute(); }); Route::get('/deliveries', function (){ (App()->make(FetchDeliveryUpdatesFromYdPortalProcessor::class))->execute(); }); }); Route::get('/yd', function (Request $request){ // $start = $request->input('start_date') ? Carbon::parse($request->input('start_date')): null; // $end = $request->input('end_date') ? Carbon::parse($request->input('end_date')): null; // (App()->make(FetchOrderListsFromYdPortalProcessor::class))->execute($start, $end); // (App()->make(\App\Classes\Modules\PackingLists\Processors\FetchPackingListsFromYdPortalProcessor::class))->execute($start, $end); // (App()->make(\App\Classes\Modules\PackingLists\Processors\FetchContainersFromYdPortalProcessor::class))->execute(); // (App()->make(\App\Classes\Modules\PackingLists\Processors\FetchContainersUpdatesFromYdPortalProcessor::class))->execute(); // (App()->make(FetchDeliveryUpdatesFromYdPortalProcessor::class))->execute(); // (App()->make(FetchPackingListFromVTPortalProcessor::class))->execute(); })->name('yd.refresh'); Route::get('/container/{reference}/refresh/', function (string $reference){ $container = Container::where('reference', $reference)->first(); $supplier = in_array($container->owner_id, [3, 4]) ? 'VT' : 'YD'; $arrivalDates = PackingList::whereIn('reference', $container->packingLists->pluck('reference'))->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->get()->map(function($packingList){ return $packingList->transports()->first()->drop_date; })->sortBy(function($date){ return $date; }); $startDate = $arrivalDates->first()->subDay()->format('d-m-Y'); $endDate = $arrivalDates->last()->addDay()->format('d-m-Y'); if($supplier === 'VT'){ return (App()->make(FetchLoadedContainersFromVTPortalProcessor::class))->execute(Carbon::parse($endDate), Carbon::parse($endDate)->addDays(5)); } if($supplier === 'YD'){ return redirect(route('yd.refresh').'?start_date='.$startDate.'&end_date='.$endDate); } })->name('container.refresh'); Route::get('/min_cbm', function (){ $companies = CompanyModule::where('type', BusinessType::IMPORTER)->whereHas('orders', function ($query){ return $query->whereHas('packingLists')->whereDoesntHave('packingLists', function($query){ return $query->whereHas('packages', function($query){ return $query->selectRaw('sum((width/100) * (height/100) * (length/100) * quantity) as cbm')->where('type', PackingListType::SHIPPING_PACKING_LIST)->where('status', '!=', 5)->having('cbm', '>', 0.3); }); }); })->limit(1)->get(); $i = 0; foreach ($companies as $company) { $marking = $company->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference; echo ''.$i++.'. '.$marking.'
'; } }); Route::get('/warehouse', function () { return view('pages.warehouse'); })->name('warehouse'); Route::get('/warehouse/{id}/show', function ($id) { // $connection = CompanyConnection::where('invitee_reference', '2417MEN')->first(); // $id = $connection->invitee->company->id; return view('pages.templates.warehouseDetails', ['id' => $id]); })->name('warehouse.show'); Route::get('/export/customer-latest-order-date/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@export'); Route::get('/export/packing-list/{id}', 'Exports\ExportContainerPackingListController@export')->name('container.packaging_list.export'); Route::get('/export/pending-arrangement-delivery-list', 'Exports\ExportPendingArrangementPackingListController@export')->name('packaging_list.pending_arrangement.export'); Route::get('/export/on-hold-packing-list', 'Exports\ExportPendingArrangementPackingListController@onHold')->name('packaging_list.on_hold.export'); Route::get('/export/arrived-parcel', 'Exports\ExportArrivedParcelController@export')->name('packing_list.arrived_parcel.export'); Route::get('/export/parcel-summary', 'Exports\ExportArrivedParcelController@summary'); Route::get('/export/parcel-postcode', 'Exports\ExportParcelPostcodesController@export'); Route::get('/export/{year}/customer-total-order', 'Exports\ExportCustomersToExcelController@totalOrders'); Route::get('/export/packing-list-warehouse/guangzhou2-to-johor', 'Exports\ExportArrivedParcelController@guangZhou2ToJohor'); Route::get('/settings', function () { return view('pages.settings'); })->name('settings'); Route::get('/settings', function () { return view('pages.settings'); })->name('settings'); Route::get('/customer/{company_module_id}/summary', 'Exports\ExportCompanyModuleSummaryController@export')->name('customer.summary.export'); Route::get('/export-customer-order/{marking}', 'Exports\ExportCompanyModuleSummaryController@exportorderSummaryByMarking')->name('customer.orderSummary.export'); Route::get('/customer/summary/monthly', function () { // $containers = Container::whereMonth('loading_date', '>=', ((float)Carbon::now()->format('m') - 2))->whereYear('loading_date', (float)Carbon::now()->format('Y'))->get(); $containers = Container::whereMonth('loading_date', '>=', 9)->whereYear('loading_date', 2022)->get(); $marking = '769SMC'; $connection = CompanyConnection::where('invitee_reference', $marking)->first(); $companyModuleId = $connection->invitee->id; foreach ($containers as $container){ $packingLists = $container->packingLists()->get()->filter(function ($packingList) use ($companyModuleId){ return $packingList->owner->company_module_id === $companyModuleId; }); if (!count($packingLists)) continue; echo ''; foreach ($packingLists as $packingList){ if($packingList->packingLists->first()){ $packingList = $packingList->packingLists->first(); } $packages = $packingList->packages; foreach ($packages as $package){ echo ''; } } echo '
Date Full Marking Container Description Ctns L (cm) H (cm) W (cm) CBM
'.$container->loading_date->format('d-m-Y').' MS/CIEF/769SMC/'.$packingList->owner->owner->reference.' '.$container->reference.' '.$package->description.' '.$package->quantity.' '.$package->length.' '.$package->height.' '.$package->width.' '.((($package->length / 100) * ($package->height / 100) * ($package->width / 100)) * $package->quantity).'
'; } }); Route::get('/customers/active/{active_start}/{active_end}/{inactive_start?}/{inactive_end?}/{with_cbm?}', function ($active_start, $active_end, $inactive_start=null, $inactive_end=null, $with_cbm = false) { $activeCompanies = CompanyModule::where('type', BusinessType::IMPORTER)->whereHas('orderPackingLists', function($query) use($inactive_start, $inactive_end) { return $query->where('packing_lists.type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($inactive_start, $inactive_end) { return $query->where('drop_date', '>=', Carbon::parse($inactive_start))->where('drop_date', '<=', Carbon::parse($inactive_end)->addDay()); }); })->pluck('id'); $companies = CompanyModule::where('type', BusinessType::IMPORTER)->whereHas('orderPackingLists', function($query) use($active_start, $active_end) { return $query->where('packing_lists.type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($active_start, $active_end) { return $query->whereDate('drop_date', '>=', Carbon::parse($active_start))->whereDate('drop_date', '<=', Carbon::parse($active_end)->addDay()); }); })->whereNotIn('id', $activeCompanies)->get(); echo '

List of customers active between '. Carbon::parse($active_start)->format('d/m/Y'). ' - '. Carbon::parse($active_end)->format('d/m/Y').' & inactive between '. Carbon::parse($inactive_start)->format('d/m/Y'). ' - '. Carbon::parse($inactive_end)->format('d/m/Y').'

'; echo ''; foreach ($companies as $key => $company){ $connection = $company->inviters()->withPivot('invitee_reference')->first(); $marking = $connection ? $connection->pivot->invitee_reference:''; $packingList = collect(); $totalCbm = 0; if($with_cbm){ $packingList = $company->orderPackingLists()->where('packing_lists.type', PackingListType::SHIPPING_PACKING_LIST)->get(); $totalCbm = $packingList->flatMap(function ($packingList) { return $packingList->packages; })->sum(function($package){ return (( (float) $package->width / 100) * ( (float) $package->length / 100) * ( (float) $package->height / 100)) * $package->quantity; }); } echo ''; } echo '
# marking Number of Orders CBM
'.$key.' '.$marking.' '. $packingList->count() .' '. $totalCbm .'
'; }); Route::get('/online_payment/redirect', 'Billplz\CallbackBillplzController@callback')->name('online_payment.redirect'); Route::get('/order/{id}', function ($id) { return view('pages.orders.profile', ['id' => $id]); })->name('order.details'); Route::get('/payment-and-billing', function () { return view('pages.paymentAndBilling'); })->name('admin.payment-and-billing'); Route::get('/notifications/list', 'Notifications\ListNotificationsController@list')->name('notifications.list'); Route::get('billplz/bills/{bill_no}', function($bill_no){ return redirect(env('BILLPLZ_BASE_URL').'/bills/'.$bill_no); })->name('billplz.bill'); Route::get('/export/null-debtor/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@nullDebtor')->name('newDebtor.export'); Route::get('/export/payment-transactions/{section}/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@paymentTransactions')->name('paymentTransactions.export'); Route::get('/delayed_container/customers', function(){ $containers = Container::whereHas('transports', function($query){ return $query->whereHas('Schedules', function($query){ return $query->where('etd', '>', Carbon::parse('15-10-2022')); }); })->get(); $orders = $containers->map(function($container){ return $container->orders; })->flatten()->unique(function($order){ return $order->company_module_id; }); $companies = CompanyModule::whereIn('id', $orders->pluck('company_module_id'))->get(); foreach ($companies as $company){ $marking = $company->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference; echo ''.$marking.'
'; } }); Route::get('/container/billing/{month}/{year}', function($month, $year){ $containers = Container::whereDate('loading_date', '>=', Carbon::parse('01-'.$month.'-'.$year))->whereDate('loading_date', '<', Carbon::parse('01-'.$month.'-'.$year)->addMonth())->get(); $totalBillable = 0; $billed = 0; $totalBilled = 0; $totalPaid = 0; $basePrice = 315; $bigParcelDiscount = -15; $yiwuCost = 15; $discount = -20; $yiwuDiscount = -45; $outstationStates = [8, 3, 16, 10]; foreach($containers as $container) { $containerTotalBillable = 0; $containerBilled = 0; $containerTotalBilled = 0; $containerTotalPaid = 0; $containerCost = 0; $packingLists = $container->packingLists; $totalBillable += count($packingLists); $containerTotalBillable += count($packingLists); echo '

'.$container->reference.' ('.$container->loading_date->format('d-m-Y').')

'; foreach ($packingLists as $packingList) { $invoice = $packingList->transactions() ->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) ->first(); $warehouseList = PackingList::where('reference', $packingList->reference)->where('type', 1)->first(); if($warehouseList){ $packing_list_drop_date = $warehouseList->transports->first()->drop_date; } else { echo '<------------- can\'t find arrival date -------------->'; } $order = $packingList->owner; $address = $order->addresses()->where('status', ApprovalStatus::APPROVED)->first(); $warehouseId = $order->orderRoles()->where('role_id', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->company_module_id; $cbm = round($packingList->packages->where('type', '!=', PackageType::OVER_WEIGHT)->sum(function($package) { return ($package->width / 100) * ($package->height / 100) *($package->length / 100) * ($package->quantity); }), 2); $over_weight_cbm = round($packingList->packages->where('type', PackageType::OVER_WEIGHT)->sum(function($package) { return ($package->width / 100) * ($package->height / 100) *($package->length / 100) * ($package->quantity); }), 2); $price = $basePrice; if($warehouseId === 2358){ $price += $yiwuCost; if($packing_list_drop_date >= Carbon::parse('19-9-2022')){ $price += $yiwuDiscount; } } else { if($cbm >= 2 && in_array($address->state_id, [4, 15])){ $price += $bigParcelDiscount; } if($packing_list_drop_date >= Carbon::parse('19-9-2022')){ $price += $discount; } } if(in_array($address->state_id,$outstationStates)) { $price += 50; } $cbm = max($cbm, 0.3); $cost = $price * ($cbm + $over_weight_cbm); $containerCost += $cost; if(in_array($address->state_id, [13, 14])) { echo 'East Malaysia - '; } echo 'estimated cost: [QTY: '.($cbm + $over_weight_cbm).' | Unit Price: '.$price.' | Total: '.$cost.']'; echo '
'; if(!$invoice) { echo '

'.$packingList->reference .' Warning: no billing

'; continue; } $payments = $invoice->transactions() ->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) ->get(); $billed += 1; $containerBilled += 1; $totalBilled += $invoice->amount; $containerTotalBilled += $invoice->amount; $totalPaid += $payments->sum('amount'); $containerTotalPaid += $payments->sum('amount'); echo '

'.$packingList->reference .' | Amount: '.$invoice->amount.' | Paid: '.$payments->sum('amount').' | Invoice Date: '.$invoice->created_at->format('d-m-Y'). (($invoice->amount - $payments->sum('amount')) < 0.01 ? '' : '('.$invoice->created_at->diffForHumans().')').''; echo '

'; } echo '

Container Invoices: '.$containerBilled.'/'.$containerTotalBillable.'

'; echo '

Billed Total: '.$containerTotalBilled.'

'; echo '

Total Paid: '.$containerTotalPaid.'

'; echo '

Outstanding: '.($totalBilled - $containerTotalPaid).'

'; echo '

Estimated Cost: '.$containerCost.'

'; echo '


'; } echo '

Total Invoices: '.$billed.'/'.$totalBillable.'

'; echo '

Billed Total: '.$totalBilled.'

'; echo '

Total Paid: '.$totalPaid.'

'; echo '

Outstanding: '.($totalBilled - $totalPaid).'

'; }); Route::get('/yd/fix', function(){ $packingLists = PackingList::where('type', PackingListType::SHIPPING_PACKING_LIST)->where('status', ApprovalStatus::APPROVED)->where('claimant_id', 2307)->get(); $i = 0; echo count($packingLists).'

'; foreach ($packingLists as $packingList){ try { (App()->make(UpdateDoFromYDPortalProcessor::class))->execute($packingList); echo 'success'.'
'; } catch (Exception $exception){ echo ''.$packingList->reference.''; } } }); Route::get('/billplz/fix', function(){ $payments = Transaction::where('type', TransactionType::PAYMENT)->where('payment_method', PaymentMethodType::PAYMENT_GATEWAY)->get(); echo '

fixed orders

'; foreach ($payments as $payment){ $response = Http::withBasicAuth(config('billplz.api_key').':', '')->get(config('billplz.base_url').'/api/v3/bills/'.$payment->payment_reference); if($response->successful()){ $data = $response->json(); $invoice = $payment->owner; if(!$invoice){ continue; } $packingList = $invoice->owner; $order = $packingList->owner; $orderNumber = $order->reference; if(!$data['paid'] && $payment->status === ApprovalStatus::APPROVED) { echo '
Fraude: '.$orderNumber.'
'; continue; } if($data['paid']){ if($payment->status !== ApprovalStatus::APPROVED){ echo ''.$orderNumber.'
'; } $payment->status = ApprovalStatus::APPROVED; $payment->save(); $invoice->status = ApprovalStatus::COMPLETED; $invoice->save(); $packingList = $payment->owner->owner; if(app()->environment('production')){ try { (App()->make(UpdateDoFromVTPortalProcessor::class))->execute($packingList); (App()->make(UpdateDoFromYDPortalProcessor::class))->execute($packingList); } catch (Exception $exception){ echo '
Malformed Address: '.$orderNumber.'
'; } } } }else{ echo "billplz error"; } } }); Route::get('/invoices/fix/{company_module_id}', function($company_module_id) { $orders = Order::whereIn('company_module_id', json_decode($company_module_id))->get(); foreach ($orders as $order){ $invoices = $order->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->get(); foreach ($invoices as $invoice){ $invoice->documents()->delete(); $transaction_invoice_pdf = LaravelMpdf::loadView('pages.pdfs.shipping_invoice', ['invoice_transaction' => $invoice]); $document_object = new DocumentObject( DocumentType::SHIPPING_INVOICE, [chunk_split('data:application/pdf;base64,'.base64_encode($transaction_invoice_pdf->output()))], '', ApprovalStatus::COMPLETED, 'shipping_invoice' ); /** @var Document $document */ $document = (App()->make(CreatesDocument::class))->execute($invoice, $document_object); (App()->make(CreatesFiles::class))->execute($document, $document_object); dump($document); } } }); Route::get('/invoices/combine/{ids}', function($ids){ $ids = json_decode($ids); $transactions = Transaction::whereIn('id', $ids)->get(); $pdf = LaravelMpdf::loadView('pages.pdfs.shipping_invoices_combined', ['invoice_transactions' => $transactions]); return $pdf->download('combined_invoice_.pdf'); })->name('invoice.combined_summary'); // Route::get('/generate/invoices', function(){ // $packingLists = (App()->make(ListsPackingLists::class))->execute(['does_not_have_transaction_type' => 1, 'type' => 2]); // foreach ($packingLists as $packingList){ // $order = $packingList->owner; // if(!($order instanceof Order)) { // echo 'failed to generate...
'; // continue; // } // $companyModule = $order->companyModule; // $billingAddress = $companyModule->addresses()->where('type', \App\Classes\ValueObjects\Constants\AddressType::BILLING)->first(); // $deliveryAddress = $order->addresses()->where('status', ApprovalStatus::APPROVED)->first(); // $postCodes = \App\Models\SegmentConstant::whereIn('reference', ['CENTER_POSTCODE', 'OUTSTATION_POSTCODE'])->get()->pluck('value')->flatten(); // if(!!$billingAddress && in_array($deliveryAddress->postcode, $postCodes->toArray())){ // try { // (App()->make(CreateInvoiceTransactionProcessor::class))->execute($packingList); // echo 'Invoice Generated...
'; // } catch (Exception $exception){ // echo 'failed to generate...
'; // } // } // echo 'failed to generate...
'; // } // })->name('generate.invoices'); Route::get('/invoices/approve', function(Request $request){ // whereDoesntHave $invoices = Transaction::where('type', TransactionType::SHIPPING_INVOICE)->where('status', ApprovalStatus::PENDING_SUBMISSION)->get(); foreach ($invoices as $invoice) { $packingList = $invoice->owner; $order = $packingList->owner; if ($request->input('exclude')){ if(in_array($order->reference, json_decode($request->input('exclude')))){ continue; } } try { (App()->make(ApproveShippingInvoiceTransactionProcessor::class))->execute($packingList); echo 'Invoice Approved...
'; } catch (Exception $exception){ echo 'failed to approve...
'; } } })->name('invoices.approve'); Route::get('/invoices/show-duplicated', function(Request $request){ $transactionWithMultipleInvoice = DB::table('transactions') ->where('type', TransactionType::SHIPPING_INVOICE) ->where('status', '!=' , ApprovalStatus::COMPLETED) ->where('deleted_at', null) ->select('owner_id', DB::raw('count(*) as count')) ->groupBy('owner_id') ->having('count', '>', 1) ->get(); // delete invoice type suspended echo ''; echo ""; echo ""; echo ""; echo ""; $duplicatedOrderId = []; foreach($transactionWithMultipleInvoice as $invoice) { $duplicatedOrderId[] = $invoice->owner_id; echo ""; echo ""; echo ""; echo ""; } echo '
owner_idcount
$invoice->owner_id$invoice->count
'; $duplicatedInvoice = Transaction::whereIn('owner_id', $duplicatedOrderId)->orderByDesc('owner_id')->get(); // dd($duplicatedInvoice); echo '
'; echo ''; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; foreach($duplicatedInvoice as $invoice) { $order = $invoice->owner->owner; echo ""; echo ''; echo ""; echo ""; echo ""; echo ""; } echo '
Order ReferenceStatusInvoice Owner IDInvoice Owner ID
'. $order->reference.' - ' . $order->created_at . '".ApprovalStatus::APPROVAL_STATUS_ID[$invoice->status]."$invoice->owner_id$invoice->amount
'; }); Route::get('/invoices/delete-duplicated', function(Request $request){ $duplicatedInvoices = DB::table('transactions') ->where('type', TransactionType::SHIPPING_INVOICE) ->where('status', '!=' , ApprovalStatus::COMPLETED) ->where('deleted_at', null) ->select('owner_id', DB::raw('count(*) as count')) ->groupBy('owner_id') ->having('count', '>', 1) ->get(); $duplicatedInvoices = Transaction::whereIn('owner_id', $duplicatedInvoices->pluck('owner_id'))->get()->groupBy('owner_id'); foreach($duplicatedInvoices as $invoice) { $packingList = $invoice->first()->owner; $order = $packingList->owner; $paidInvoice = $packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', ApprovalStatus::COMPLETED)->get(); $unpaidInvoices = $packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->orderBy('id', 'desc')->get(); if (count($paidInvoice)) { $packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', '!=', ApprovalStatus::COMPLETED)->delete(); continue; } // delete duplicated invoices $unpaidInvoicesIds = $unpaidInvoices->pluck('id')->toArray(); array_shift($unpaidInvoicesIds); Transaction::whereIn('id', $unpaidInvoicesIds)->delete(); // delete expired invoices $packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', '!=', ApprovalStatus::EXPIRED)->delete(); // delete suspended invoices $suspendedInvoices = $packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', '!=', ApprovalStatus::SUSPENDED)->orderBy('id', 'desc')->get(); $suspendedInvoicesIds = $suspendedInvoices->pluck('id')->toArray(); array_shift($suspendedInvoicesIds); Transaction::whereIn('id', $suspendedInvoicesIds)->delete(); } });