From ac211098bf0130807c5f9348a26782cadf6db159 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 28 Sep 2026 10:42:15 +0530 Subject: [PATCH 1/2] Added sucess msg after import sucess in class characteristic import --- .../Resources/ClassCharacteristicResource.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/Filament/Resources/ClassCharacteristicResource.php b/app/Filament/Resources/ClassCharacteristicResource.php index 89cf954..63cc226 100644 --- a/app/Filament/Resources/ClassCharacteristicResource.php +++ b/app/Filament/Resources/ClassCharacteristicResource.php @@ -2992,6 +2992,13 @@ class ClassCharacteristicResource extends Resource } } + if ($record) { + Notification::make() + ->title('Import Successful') + ->body("{$insertedCount} records inserted successfully.") + ->success(); + } + $itemCharacteristic = ItemCharacteristic::where('plant_id', $plantId)->where('item_id', $item->id)->first(); if ($itemCharacteristic) { @@ -3137,16 +3144,9 @@ class ClassCharacteristicResource extends Resource 'zmm_operating_temperature' => $itemCharacteristic->zmm_operating_temperature, 'zmm_axial_force' => $itemCharacteristic->zmm_axial_force, ]); - - $updatedCount++; } - } - if ($record) { - Notification::make() - ->title('Import Successful') - ->body("{$insertedCount} records inserted successfully and updated zmm values success for '{$updatedCount}' records.") - ->success(); + $updatedCount++; } } }) From 8d99b08b953adcdc520d36c50a4490bd04ccd430 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 28 Sep 2026 11:30:41 +0530 Subject: [PATCH 2/2] Changed logic for production target plan --- app/Livewire/ProductionTargetPlan.php | 442 ++++++++++++++++++-------- 1 file changed, 311 insertions(+), 131 deletions(-) diff --git a/app/Livewire/ProductionTargetPlan.php b/app/Livewire/ProductionTargetPlan.php index cca36b9..4011798 100644 --- a/app/Livewire/ProductionTargetPlan.php +++ b/app/Livewire/ProductionTargetPlan.php @@ -174,161 +174,161 @@ class ProductionTargetPlan extends Component // } - public function loadProductionData($year, $month, $plantId, $lineId, $category) - { - if (!$plantId || !$lineId || !$month || !$year) { - $this->records = []; - $this->dates = []; - $this->leaveDates = []; - return; - } + // public function loadProductionData($year, $month, $plantId, $lineId, $category) + // { + // if (!$plantId || !$lineId || !$month || !$year) { + // $this->records = []; + // $this->dates = []; + // $this->leaveDates = []; + // return; + // } - $dates = $this->getMonthDates($month, $year); - $this->dates = $dates; + // $dates = $this->getMonthDates($month, $year); + // $this->dates = $dates; - $plans = ProductionPlan::query() - ->join('items', 'items.id', '=', 'production_plans.item_id') - ->join('lines', 'lines.id', '=', 'production_plans.line_id') - ->join('plants', 'plants.id', '=', 'production_plans.plant_id') - ->where('production_plans.plant_id', $plantId) - ->where('production_plans.line_id', $lineId) - ->whereMonth('production_plans.created_at', $month) - ->whereYear('production_plans.created_at', $year) - ->when($category, function ($query) use ($category) { - $query->where('items.category', $category); - }) - ->select( - 'production_plans.item_id', - 'production_plans.plant_id', - 'production_plans.line_id', - 'production_plans.plan_quantity', - 'production_plans.working_days', - 'production_plans.leave_dates', - 'items.code as item_code', - 'items.category as category', - 'items.description as item_description', - 'items.hourly_quantity as hourly_quantity', - 'lines.name as line_name', - // 'lines.line_capacity as line_capacity', - 'plants.name as plant_name' - ) - ->get(); + // $plans = ProductionPlan::query() + // ->join('items', 'items.id', '=', 'production_plans.item_id') + // ->join('lines', 'lines.id', '=', 'production_plans.line_id') + // ->join('plants', 'plants.id', '=', 'production_plans.plant_id') + // ->where('production_plans.plant_id', $plantId) + // ->where('production_plans.line_id', $lineId) + // ->whereMonth('production_plans.created_at', $month) + // ->whereYear('production_plans.created_at', $year) + // ->when($category, function ($query) use ($category) { + // $query->where('items.category', $category); + // }) + // ->select( + // 'production_plans.item_id', + // 'production_plans.plant_id', + // 'production_plans.line_id', + // 'production_plans.plan_quantity', + // 'production_plans.working_days', + // 'production_plans.leave_dates', + // 'items.code as item_code', + // 'items.category as category', + // 'items.description as item_description', + // 'items.hourly_quantity as hourly_quantity', + // 'lines.name as line_name', + // // 'lines.line_capacity as line_capacity', + // 'plants.name as plant_name' + // ) + // ->get(); - $leaveDates = []; + // $leaveDates = []; - if ($plans->isNotEmpty() && $plans[0]->leave_dates) { - $leaveDates = array_map('trim', explode(',', $plans[0]->leave_dates)); - } + // if ($plans->isNotEmpty() && $plans[0]->leave_dates) { + // $leaveDates = array_map('trim', explode(',', $plans[0]->leave_dates)); + // } - $this->leaveDates = $leaveDates; + // $this->leaveDates = $leaveDates; - // $producedData = QualityValidation::selectRaw(" - // plant_id, - // line_id, - // sticker_master_id, - // DATE(created_at) as prod_date, - // COUNT(*) as total_qty - // ") - // ->where('plant_id', $plantId) - // ->where('line_id', $lineId) - // ->whereMonth('created_at', $month) - // ->whereYear('created_at', $year) - // ->when($category, function ($query) use ($category) { - // $query->whereHas('item', function ($q) use ($category) { - // $q->where('category', $category); - // }); - // }) - // ->groupBy('plant_id', 'line_id', 'sticker_master_id', DB::raw('DATE(created_at)')) - // ->get() - // ->groupBy(fn($row) => - // $row->plant_id . '_' . $row->line_id . '_' . $row->item_id - // ) - // ->map(fn($group) => $group->keyBy('prod_date')); + // // $producedData = QualityValidation::selectRaw(" + // // plant_id, + // // line_id, + // // sticker_master_id, + // // DATE(created_at) as prod_date, + // // COUNT(*) as total_qty + // // ") + // // ->where('plant_id', $plantId) + // // ->where('line_id', $lineId) + // // ->whereMonth('created_at', $month) + // // ->whereYear('created_at', $year) + // // ->when($category, function ($query) use ($category) { + // // $query->whereHas('item', function ($q) use ($category) { + // // $q->where('category', $category); + // // }); + // // }) + // // ->groupBy('plant_id', 'line_id', 'sticker_master_id', DB::raw('DATE(created_at)')) + // // ->get() + // // ->groupBy(fn($row) => + // // $row->plant_id . '_' . $row->line_id . '_' . $row->item_id + // // ) + // // ->map(fn($group) => $group->keyBy('prod_date')); - $producedData = QualityValidation::selectRaw(" - quality_validations.plant_id, - quality_validations.line_id, - quality_validations.sticker_master_id, - sticker_masters.item_id, - DATE(quality_validations.created_at) as prod_date, - COUNT(*) as total_qty - ") - ->join('sticker_masters', 'sticker_masters.id', '=', 'quality_validations.sticker_master_id') - ->where('quality_validations.plant_id', $plantId) - ->where('quality_validations.line_id', $lineId) - ->whereMonth('quality_validations.created_at', $month) - ->whereYear('quality_validations.created_at', $year) - ->when($category, function ($query) use ($category) { - $query->whereHas('item', function ($q) use ($category) { - $q->where('category', $category); - }); - }) - ->groupBy( - 'quality_validations.plant_id', - 'quality_validations.line_id', - 'quality_validations.sticker_master_id', - 'sticker_masters.item_id', - DB::raw('DATE(quality_validations.created_at)') - ) - ->get() - ->groupBy(fn($row) => - $row->plant_id . '_' . $row->line_id . '_' . $row->item_id - ) - ->map(fn($group) => $group->keyBy('prod_date')); + // $producedData = QualityValidation::selectRaw(" + // quality_validations.plant_id, + // quality_validations.line_id, + // quality_validations.sticker_master_id, + // sticker_masters.item_id, + // DATE(quality_validations.created_at) as prod_date, + // COUNT(*) as total_qty + // ") + // ->join('sticker_masters', 'sticker_masters.id', '=', 'quality_validations.sticker_master_id') + // ->where('quality_validations.plant_id', $plantId) + // ->where('quality_validations.line_id', $lineId) + // ->whereMonth('quality_validations.created_at', $month) + // ->whereYear('quality_validations.created_at', $year) + // ->when($category, function ($query) use ($category) { + // $query->whereHas('item', function ($q) use ($category) { + // $q->where('category', $category); + // }); + // }) + // ->groupBy( + // 'quality_validations.plant_id', + // 'quality_validations.line_id', + // 'quality_validations.sticker_master_id', + // 'sticker_masters.item_id', + // DB::raw('DATE(quality_validations.created_at)') + // ) + // ->get() + // ->groupBy(fn($row) => + // $row->plant_id . '_' . $row->line_id . '_' . $row->item_id + // ) + // ->map(fn($group) => $group->keyBy('prod_date')); - $records = []; + // $records = []; - foreach ($plans as $plan) { + // foreach ($plans as $plan) { - $row = $plan->toArray(); + // $row = $plan->toArray(); - $remainingQty = (float) $row['plan_quantity']; - $remainingDays = (int) ($row['working_days'] ?? 0); + // $remainingQty = (float) $row['plan_quantity']; + // $remainingDays = (int) ($row['working_days'] ?? 0); - $lineCapacity = (float) ($row['line_capacity'] ?? 0); - $dailyHourlyQuantity = (float) ($row['hourly_quantity'] ?? 0); + // $lineCapacity = (float) ($row['line_capacity'] ?? 0); + // $dailyHourlyQuantity = (float) ($row['hourly_quantity'] ?? 0); - $row['category'] = $row['category'] ?? '-'; - $row['daily_hourly_quantity'] = []; - $row['daily_target_dynamic'] = []; - $row['produced_quantity'] = []; + // $row['category'] = $row['category'] ?? '-'; + // $row['daily_hourly_quantity'] = []; + // $row['daily_target_dynamic'] = []; + // $row['produced_quantity'] = []; - $key = $row['plant_id'].'_'.$row['line_id'].'_'.$row['item_id']; + // $key = $row['plant_id'].'_'.$row['line_id'].'_'.$row['item_id']; - foreach ($dates as $date) { + // foreach ($dates as $date) { - // Skip leave dates fast - if (isset($leaveDates) && in_array($date, $leaveDates)) { - $row['daily_hourly_quantity'][$date] = '-'; - $row['daily_target_dynamic'][$date] = '-'; - $row['produced_quantity'][$date] = '-'; - continue; - } + // // Skip leave dates fast + // if (isset($leaveDates) && in_array($date, $leaveDates)) { + // $row['daily_hourly_quantity'][$date] = '-'; + // $row['daily_target_dynamic'][$date] = '-'; + // $row['produced_quantity'][$date] = '-'; + // continue; + // } - $todayTarget = $remainingDays > 0 - ? round($remainingQty / $remainingDays, 2) - : 0; + // $todayTarget = $remainingDays > 0 + // ? round($remainingQty / $remainingDays, 2) + // : 0; - $producedQty = $producedData[$key][$date]->total_qty ?? 0; + // $producedQty = $producedData[$key][$date]->total_qty ?? 0; - $row['daily_target_dynamic'][$date] = $todayTarget; - $row['produced_quantity'][$date] = $producedQty; - $row['daily_hourly_quantity'][$date] = $dailyHourlyQuantity * 22.5; + // $row['daily_target_dynamic'][$date] = $todayTarget; + // $row['produced_quantity'][$date] = $producedQty; + // $row['daily_hourly_quantity'][$date] = $dailyHourlyQuantity * 22.5; - // Carry forward remaining qty - $remainingQty = max(0, $remainingQty - $producedQty); + // // Carry forward remaining qty + // $remainingQty = max(0, $remainingQty - $producedQty); - if ($remainingDays > 0) { - $remainingDays--; - } - } + // if ($remainingDays > 0) { + // $remainingDays--; + // } + // } - $records[] = $row; - } + // $records[] = $row; + // } - $this->records = $records; - } + // $this->records = $records; + // } // public function loadProductionDataCategory($year, $month, $plantId, $lineId, $category) // { @@ -446,6 +446,186 @@ class ProductionTargetPlan extends Component // } + + public function loadProductionData($year, $month, $plantId, $lineId) + { + if (!$plantId || !$lineId || !$month || !$year) { + $this->records = []; + $this->dates = []; + $this->leaveDates = []; + return; + } + + $dates = $this->getMonthDates($month, $year); + $this->dates = $dates; + + $plans = ProductionPlan::query() + ->join('items', 'items.id', '=', 'production_plans.item_id') + ->join('lines', 'lines.id', '=', 'production_plans.line_id') + ->join('plants', 'plants.id', '=', 'production_plans.plant_id') + ->where('production_plans.plant_id', $plantId) + ->where('production_plans.line_id', $lineId) + ->whereMonth('production_plans.created_at', $month) + ->whereYear('production_plans.created_at', $year) + ->select( + 'production_plans.item_id', + 'production_plans.plant_id', + 'production_plans.line_id', + 'production_plans.plan_quantity', + 'production_plans.working_days', + 'production_plans.leave_dates', + 'items.code as item_code', + 'items.category as category', + 'items.description as item_description', + 'items.hourly_quantity as hourly_quantity', + 'lines.name as line_name', + // 'lines.line_capacity as line_capacity', + 'plants.name as plant_name' + ) + ->get(); + + $leaveDates = []; + + if ($plans->isNotEmpty() && $plans[0]->leave_dates) { + $leaveDates = array_map('trim', explode(',', $plans[0]->leave_dates)); + } + + $this->leaveDates = $leaveDates; + + $producedData = QualityValidation::selectRaw(" + quality_validations.plant_id, + quality_validations.line_id, + quality_validations.sticker_master_id, + sticker_masters.item_id, + DATE(quality_validations.created_at) as prod_date, + COUNT(*) as total_qty + ") + ->join( + 'sticker_masters', + 'sticker_masters.id', + '=', + 'quality_validations.sticker_master_id' + ) + ->where('quality_validations.plant_id', $plantId) + ->where('quality_validations.line_id', $lineId) + ->whereMonth('quality_validations.created_at', $month) + ->whereYear('quality_validations.created_at', $year) + ->groupBy( + 'quality_validations.plant_id', + 'quality_validations.line_id', + 'quality_validations.sticker_master_id', + 'sticker_masters.item_id', + DB::raw('DATE(quality_validations.created_at)') + ) + ->get() + ->groupBy(fn($row) => + $row->plant_id . '_' . $row->line_id . '_' . $row->item_id + ) + ->map(fn($group) => $group->keyBy('prod_date')); + + $records = []; + + foreach ($plans as $plan) { + + $row = $plan->toArray(); + + /* + * Calculate the normal daily target. + * + * Example: + * Plan quantity = 60 + * Working days = 3 + * + * Normal daily target = 60 / 3 = 20 + */ + $workingDays = (int) ($row['working_days'] ?? 0); + + $normalDailyTarget = $workingDays > 0 + ? round((float) $row['plan_quantity'] / $workingDays, 2) + : 0; + + /* + * This stores the uncompleted quantity from the previous + * working day and carries it to the next working day. + */ + $pendingQty = 0; + + $lineCapacity = (float) ($row['line_capacity'] ?? 0); + $dailyHourlyQuantity = (float) ($row['hourly_quantity'] ?? 0); + + $row['category'] = $row['category'] ?? '-'; + $row['daily_hourly_quantity'] = []; + $row['daily_target_dynamic'] = []; + $row['produced_quantity'] = []; + + $key = $row['plant_id'] . '_' . $row['line_id'] . '_' . $row['item_id']; + + foreach ($dates as $date) { + + /* + * Skip leave dates. + * + * Pending quantity is NOT changed here. + * Therefore it will carry forward to the next working day. + */ + if (in_array($date, $leaveDates)) { + + $row['daily_hourly_quantity'][$date] = '-'; + $row['daily_target_dynamic'][$date] = '-'; + $row['produced_quantity'][$date] = '-'; + + continue; + } + + /* + * Today's target: + * + * Normal daily target + * + + * Previous day's pending quantity + */ + $todayTarget = round( + $normalDailyTarget + $pendingQty, + 2 + ); + + /* + * Get actual produced quantity for this item/date. + */ + $producedQty = $producedData[$key][$date]->total_qty ?? 0; + + /* + * Store today's values. + */ + $row['daily_target_dynamic'][$date] = $todayTarget; + $row['produced_quantity'][$date] = $producedQty; + $row['daily_hourly_quantity'][$date] = $dailyHourlyQuantity * 22.5; + + /* + * Calculate today's pending quantity. + * + * Example: + * + * Target = 40 + * Produced = 30 + * + * Pending = 10 + * + * This 10 will be added to tomorrow's target. + */ + $pendingQty = max( + 0, + $todayTarget - $producedQty + ); + } + + $records[] = $row; + } + + $this->records = $records; + } + + public function exportProductionData() { return Excel::download(