mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
check duplicated invoice
This commit is contained in:
+59
-2
@@ -778,8 +778,10 @@ Route::get('/invoices/approve', function(Request $request){
|
||||
$packingList = $invoice->owner;
|
||||
$order = $packingList->owner;
|
||||
|
||||
if(in_array($order->reference, json_decode($request->input('exclude')))){
|
||||
continue;
|
||||
if ($request->input('exclude')){
|
||||
if(in_array($order->reference, json_decode($request->input('exclude')))){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -847,3 +849,58 @@ Route::get('/invoices/show-duplicated', function(Request $request){
|
||||
});
|
||||
|
||||
|
||||
|
||||
Route::get('/invoices/delete-duplicated', function(Request $request){
|
||||
$duplicatedInvoiceId = 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()->pluck('owner_id');
|
||||
|
||||
// delete invoice type suspended
|
||||
|
||||
$duplicatedInvoice = Transaction::whereIn('owner_id', $duplicatedInvoiceId)->get();
|
||||
|
||||
foreach($duplicatedInvoice as $invoice) {
|
||||
$packingList = $invoice->owner;
|
||||
$order = $packingList->owner;
|
||||
$order_marking = $order->reference;
|
||||
|
||||
$duplicatedShipingInvoice = $packingList->transactions->where('type', TransactionType::SHIPPING_INVOICE);
|
||||
|
||||
if (sizeof($duplicatedShipingInvoice)) {
|
||||
$paidShippingInvoice = $duplicatedShipingInvoice->where('status', ApprovalStatus::COMPLETED);
|
||||
|
||||
if (sizeof($paidShippingInvoice)) {
|
||||
// if packing list have any paid invoices, delete all the unpaid
|
||||
|
||||
if ($invoice->id != $paidShippingInvoice->id ) {
|
||||
// delete this invoice
|
||||
$invoice->delete();
|
||||
dump('Deleted invoice id -' . $invoice->id);
|
||||
}
|
||||
} else {
|
||||
// if all unpaid, leave the latest one, delete all
|
||||
// if ($invoice->id != $duplicatedShipingInvoice->orderByDesc('created_at')->first()->id ) {
|
||||
if ($invoice->id != $duplicatedShipingInvoice->sortByDesc('created_at')->first()->id ) {
|
||||
// delete this invoice
|
||||
$invoice->delete();
|
||||
dump('Deleted invoice id -' . $invoice->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Route::get('/invoices/suspend-invoices', function(Request $request){
|
||||
// $pendingPayment = Transaction::where('type', TransactionType::SHIPPING_INVOICE)->where('status', ApprovalStatus::APPROVED)->get();
|
||||
$pendingPayment = Transaction::where('type', TransactionType::SHIPPING_INVOICE)->where('status', 5)->get();
|
||||
|
||||
foreach ($pendingPayment as $invoice) {
|
||||
$invoice->status = ApprovalStatus::EXPIRED;
|
||||
$invoice->save();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user