From 56656264c0b1cd189b3fcceb4c5ac2288af0702d Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 6 Jul 2026 12:28:51 +0530 Subject: [PATCH] corrected logic pallet print controller --- .../Controllers/PalletPrintController.php | 59 +++++-------------- 1 file changed, 14 insertions(+), 45 deletions(-) diff --git a/app/Http/Controllers/PalletPrintController.php b/app/Http/Controllers/PalletPrintController.php index 0a7b1ca..c71fb4c 100644 --- a/app/Http/Controllers/PalletPrintController.php +++ b/app/Http/Controllers/PalletPrintController.php @@ -163,16 +163,11 @@ class PalletPrintController extends Controller public function print(Request $request, $pallet, $plant) { - $customerPo = $request->query('customer'); + // $customerPo = $request->query('customer'); - $itemId = WireMasterPacking::where('plant_id', $plant) + $customerPoMasterId = WireMasterPacking::where('plant_id', $plant) ->where('wire_packing_number', $pallet) - ->value('item_id'); - - $customerPoIds = CustomerPoMaster::where('plant_id', $plant) - ->where('customer_po', $customerPo) - ->where('item_id', $itemId) - ->pluck('id'); + ->value('customer_po_master_id'); $items = WireMasterPacking::with('item') ->where('plant_id', $plant) @@ -187,49 +182,23 @@ class PalletPrintController extends Controller ]; }); - $masterBox = WireMasterPacking::where('plant_id', $plant) - ->where('wire_packing_number', $pallet) - ->value('customer_po_master_id'); - - $customer = CustomerPoMaster::find($masterBox); + $customer = CustomerPoMaster::find($customerPoMasterId); $customerCode = $customer->customer_po ?? ''; $customerName = $customer->customer_name ?? ''; - // $totalBoxes = WireMasterPacking::where('plant_id', $plant) - // ->where('customer_po_master_id', $customerId) - // ->distinct('wire_packing_number') - // ->count('wire_packing_number'); - - // $totalBoxes = WireMasterPacking::where('plant_id', $plant) - // ->whereIn('customer_po_master_id', $customerPoIds) - // ->distinct('wire_packing_number') - // ->count('wire_packing_number'); - - $totalBoxes = WireMasterPacking::where('plant_id', $plant) - ->whereIn('customer_po_master_id', $customerPoIds) - ->select('wire_packing_number') - ->groupBy('wire_packing_number') - ->havingRaw( - 'COUNT(*) = COUNT(CASE WHEN wire_packing_status = ? THEN 1 END)', - ['Completed'] - ) - ->count(); - - // $completedPallets = WireMasterPacking::where('plant_id', $plant) - // ->where('customer_po_master_id', $customerId) - // ->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(); + $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(); $completedPallets = WireMasterPacking::where('plant_id', $plant) - ->whereIn('customer_po_master_id', $customerPoIds) + ->where('customer_po_master_id', $customerPoMasterId) ->select('wire_packing_number') ->groupBy('wire_packing_number') ->havingRaw(