fix duplicate packages

This commit is contained in:
Omair Saleh
2023-08-22 15:24:38 +08:00
parent c5a49bbc44
commit fcc4da1a56
+2 -21
View File
@@ -1143,26 +1143,8 @@ Route::get('/final-duplicated-invoice-debug', function(){
Route::get('/duplicate-package-clean-up', function(){
$duplicateGroups = \App\Models\Package::select('packing_list_id', 'description', 'width', 'height', 'weight', 'quantity')
->selectRaw('MIN(created_at) AS min_created_at')
->groupBy('packing_list_id', 'description', 'width', 'height', 'weight', 'quantity')
->havingRaw('COUNT(*) > 1')
->get();
foreach ($duplicateGroups as $group) {
$deletableGroups = \App\Models\Package::where('packing_list_id', $group->packing_list_id)
->where('description', $group->description)
->where('width', $group->width)
->where('height', $group->height)
->where('weight', $group->weight)
->where('quantity', $group->quantity)
->where('created_at', '>', $group->min_created_at)
->get();
}
// Fetching duplicate rows based on given columns
$duplicates = DB::table('packages')
->select('packing_list_id', 'description', 'width', 'height', 'weight', 'quantity', DB::raw('COUNT(*) as count'))
$duplicates = Package::select('packing_list_id', 'description', 'width', 'height', 'weight', 'quantity', DB::raw('COUNT(*) as count'))
->groupBy('packing_list_id', 'description', 'width', 'height', 'weight', 'quantity')
->havingRaw('COUNT(*) > 1')
->get();
@@ -1174,8 +1156,7 @@ Route::get('/duplicate-package-clean-up', function(){
$totalGroups++;
// Fetch all rows of the current group and order by created_at
$rows = Package::where('packages')
->where('packing_list_id', $duplicate->packing_list_id)
$rows = Package::where('packing_list_id', $duplicate->packing_list_id)
->where('description', $duplicate->description)
->where('width', $duplicate->width)
->where('height', $duplicate->height)