From eef42d9736a44e6384ef74b230e42d4413ce12ec Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Wed, 8 Jul 2026 11:29:21 +0530 Subject: [PATCH] changed logic in pallet print controller --- .../Controllers/PalletPrintController.php | 54 +++++++++++++++---- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/PalletPrintController.php b/app/Http/Controllers/PalletPrintController.php index 3dfa365..cdb9c3a 100644 --- a/app/Http/Controllers/PalletPrintController.php +++ b/app/Http/Controllers/PalletPrintController.php @@ -167,6 +167,16 @@ class PalletPrintController extends Controller ->where('wire_packing_number', $pallet) ->value('customer_po_master_id'); + $masterIds = WireMasterPacking::where('plant_id', $plant) + ->where('wire_packing_number', $pallet) + ->pluck('customer_po_master_id'); + + $customerPo = CustomerPoMaster::whereIn('id', $masterIds) + ->value('customer_po'); + + $customerPoMasterIds = CustomerPoMaster::where('customer_po', $customerPo) + ->pluck('id'); + $items = WireMasterPacking::with('item') ->where('plant_id', $plant) ->where('wire_packing_number', $pallet) @@ -185,8 +195,18 @@ class PalletPrintController extends Controller $customerCode = $customer->customer_po ?? ''; $customerName = $customer->customer_name ?? ''; + // $totalBoxes = WireMasterPacking::where('plant_id', $plant) + // ->where('customer_po_master_id', $customerPoMasterId) + // ->select('wire_packing_number') + // ->groupBy('wire_packing_number') + // ->havingRaw( + // 'COUNT(*) = COUNT(CASE WHEN wire_packing_status = ? THEN 1 END)', + // ['Completed'] + // ) + // ->count(); + $totalBoxes = WireMasterPacking::where('plant_id', $plant) - ->where('customer_po_master_id', $customerPoMasterId) + ->whereIn('customer_po_master_id', $customerPoMasterIds) ->select('wire_packing_number') ->groupBy('wire_packing_number') ->havingRaw( @@ -195,17 +215,29 @@ class PalletPrintController extends Controller ) ->count(); + // $completedPallets = WireMasterPacking::where('plant_id', $plant) + // ->where('customer_po_master_id', $customerPoMasterId) + // ->select('wire_packing_number') + // ->groupBy('wire_packing_number') + // ->havingRaw( + // 'COUNT(*) = COUNT(CASE WHEN wire_packing_status = ? THEN 1 END)', + // ['Completed'] + // ) + // ->orderBy('wire_packing_number') + // ->pluck('wire_packing_number') + // ->values(); + $completedPallets = WireMasterPacking::where('plant_id', $plant) - ->where('customer_po_master_id', $customerPoMasterId) - ->select('wire_packing_number') - ->groupBy('wire_packing_number') - ->havingRaw( - 'COUNT(*) = COUNT(CASE WHEN wire_packing_status = ? THEN 1 END)', - ['Completed'] - ) - ->orderBy('wire_packing_number') - ->pluck('wire_packing_number') - ->values(); + ->whereIn('customer_po_master_id', $customerPoMasterIds) + ->select('wire_packing_number') + ->groupBy('wire_packing_number') + ->havingRaw( + 'COUNT(*) = COUNT(CASE WHEN wire_packing_status = ? THEN 1 END)', + ['Completed'] + ) + ->orderBy('wire_packing_number') + ->pluck('wire_packing_number') + ->values(); $index = $completedPallets->search($pallet);