mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
fix duplicated packing list
This commit is contained in:
+39
-8
@@ -894,17 +894,12 @@ Route::get('/invoices/delete-duplicated', function(Request $request){
|
||||
}
|
||||
});
|
||||
|
||||
Route::get('/fix-invoices-drop-date/{orderMarking}', function($orderMarking){
|
||||
// 359360902
|
||||
$dilter = ['does_not_have_transaction_type' => 1, 'type' => 2, 'order_marking_in'=> strval($orderMarking)];
|
||||
dump($dilter);
|
||||
$packingLists = (App()->make(ListsPackingLists::class))->execute($dilter);
|
||||
dd($packingLists->first()->containers->first()->transports->first());
|
||||
});Route::get('/packing-lists/show-duplicated', function(Request $request){
|
||||
Route::get('/packing-lists/show-duplicated', function(Request $request){
|
||||
$results = PackingList::select('reference', 'type', DB::raw('count(*) as total'))
|
||||
->groupBy('reference', 'type')
|
||||
->having('total', '>', 1)
|
||||
->get()->toArray();
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
echo '<table>';
|
||||
echo "<tr>";
|
||||
@@ -923,3 +918,39 @@ Route::get('/fix-invoices-drop-date/{orderMarking}', function($orderMarking){
|
||||
}
|
||||
echo '</table>';
|
||||
});
|
||||
|
||||
Route::get('/packing-lists/delete-duplicated', function(Request $request){
|
||||
$results = PackingList::select('reference', 'type', DB::raw('count(*) as total'))
|
||||
->groupBy('reference', 'type')
|
||||
->having('total', '>', 1)
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
foreach($results as $result) {
|
||||
$duplicatedPackingList = PackingList::where('reference', $result['reference'])->where('type', $result['type'])->orderBy('id', 'desc')->get();
|
||||
|
||||
// if packinglist has paid inivoice
|
||||
$paidPackinglist = PackingList::where('reference', $result['reference'])->where('type', $result['type'])->whereHas('transactions', function($query){
|
||||
return $query->where('type', TransactionType::SHIPPING_INVOICE)->where('status', ApprovalStatus::COMPLETED);
|
||||
})->get();
|
||||
|
||||
if (count($paidPackinglist)) {
|
||||
// delete all the other packing list
|
||||
$paidPackinglistID = $paidPackinglist->first()->id;
|
||||
$duplicatedPackingList = PackingList::where('reference', $result['reference'])->where('type', $result['type'])->where('id', '!=', $paidPackinglistID)->get();
|
||||
// $duplicatedPackingList->delete();
|
||||
foreach ($duplicatedPackingList as $p) {
|
||||
$p->delete();
|
||||
dump('have paid packinglist, deleting id:' . $p->id);
|
||||
}
|
||||
} else {
|
||||
// delete all but left the latest packing list
|
||||
$firstItem = $duplicatedPackingList->shift();
|
||||
// dump('dont have paid packinglist, keep first and delete others');
|
||||
foreach ($duplicatedPackingList as $p) {
|
||||
$p->delete();
|
||||
dump('dont have paid packinglist, keep latest id:' . $firstItem->id . ', and deleting id:' . $p->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user