Removed unwanted logic from target plan page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 14s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 17s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 14s
Laravel Pint / pint (pull_request) Successful in 4m38s
Laravel Larastan / larastan (pull_request) Failing after 6m9s

This commit is contained in:
dhanabalan
2026-10-12 15:06:32 +05:30
parent 95f27b5851
commit 0c6b5ef257

View File

@@ -463,12 +463,12 @@ class ProductionTargetPlan extends Component
$this->leaveDates = [];
if (!$plantId || !$lineId || !$month || !$year) {
// $this->records = [];
// $this->dates = [];
// $this->leaveDates = [];
return;
}
$startDate = Carbon::create($year, $month, 1)->startOfDay();
$endDate = $startDate->copy()->addMonth();
$dates = $this->getMonthDates($month, $year);
$this->dates = $dates;
@@ -478,8 +478,10 @@ class ProductionTargetPlan extends Component
->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)
// ->whereMonth('production_plans.created_at', $month)
// ->whereYear('production_plans.created_at', $year)
->where('production_plans.created_at', '>=', $startDate)
->where('production_plans.created_at', '<', $endDate)
->select(
'production_plans.item_id',
'production_plans.plant_id',
@@ -492,7 +494,6 @@ class ProductionTargetPlan extends Component
'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();
@@ -505,7 +506,7 @@ class ProductionTargetPlan extends Component
$this->leaveDates = $leaveDates;
$start = microtime(true);
$leaveDateLookup = array_fill_keys($leaveDates, true);
$producedData = QualityValidation::selectRaw("
quality_validations.plant_id,
@@ -522,8 +523,10 @@ class ProductionTargetPlan extends Component
)
->where('quality_validations.plant_id', $plantId)
->where('quality_validations.line_id', $lineId)
->whereMonth('quality_validations.created_at', $month)
->whereYear('quality_validations.created_at', $year)
// ->whereMonth('quality_validations.created_at', $month)
// ->whereYear('quality_validations.created_at', $year)
->where('quality_validations.created_at', '>=', $startDate)
->where('quality_validations.created_at', '<', $endDate)
->groupBy(
'quality_validations.plant_id',
'quality_validations.line_id',
@@ -542,32 +545,18 @@ class ProductionTargetPlan extends Component
$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'] = [];
@@ -575,61 +564,22 @@ class ProductionTargetPlan extends Component
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] = '-';
// if (in_array($date, $leaveDates)) {
if (isset($leaveDateLookup[$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
);
$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
);
$pendingQty = max(0,$todayTarget - $producedQty);
}
$records[] = $row;
@@ -666,12 +616,12 @@ class ProductionTargetPlan extends Component
$this->leaveDates = [];
if (!$plantId || !$lineId || !$month || !$year || !$category) {
// $this->records = [];
// $this->dates = [];
// $this->leaveDates = [];
return;
}
$startDate = Carbon::create($year, $month, 1)->startOfDay();
$endDate = $startDate->copy()->addMonth();
$dates = $this->getMonthDates($month, $year);
$this->dates = $dates;
@@ -682,8 +632,10 @@ class ProductionTargetPlan extends Component
->where('production_plans.plant_id', $plantId)
->where('production_plans.line_id', $lineId)
->where('items.category', $category)
->whereMonth('production_plans.created_at', $month)
->whereYear('production_plans.created_at', $year)
// ->whereMonth('production_plans.created_at', $month)
// ->whereYear('production_plans.created_at', $year)
->where('production_plans.created_at', '>=', $startDate)
->where('production_plans.created_at', '<', $endDate)
->select(
'production_plans.item_id',
'production_plans.plant_id',
@@ -726,8 +678,10 @@ class ProductionTargetPlan extends Component
->where('items.category', $category)
->where('quality_validations.plant_id', $plantId)
->where('quality_validations.line_id', $lineId)
->whereMonth('quality_validations.created_at', $month)
->whereYear('quality_validations.created_at', $year)
->where('quality_validations.created_at', '>=', $startDate)
->where('quality_validations.created_at', '<', $endDate)
// ->whereMonth('quality_validations.created_at', $month)
// ->whereYear('quality_validations.created_at', $year)
->groupBy(
'quality_validations.plant_id',
'quality_validations.line_id',
@@ -758,7 +712,7 @@ class ProductionTargetPlan extends Component
$dailyHourlyQuantity = (float) ($row['hourly_quantity'] ?? 0);
$row['category'] = $row['category'] ?? '-';
$row['daily_hourly_quantity'] = [];
// $row['daily_hourly_quantity'] = [];
$row['daily_target_dynamic'] = [];
$row['produced_quantity'] = [];
@@ -767,7 +721,7 @@ class ProductionTargetPlan extends Component
foreach ($dates as $date) {
if (in_array($date, $leaveDates)) {
$row['daily_hourly_quantity'][$date] = '-';
// $row['daily_hourly_quantity'][$date] = '-';
$row['daily_target_dynamic'][$date] = '-';
$row['produced_quantity'][$date] = '-';
@@ -783,7 +737,7 @@ class ProductionTargetPlan extends Component
$row['daily_target_dynamic'][$date] = $todayTarget;
$row['produced_quantity'][$date] = $producedQty;
$row['daily_hourly_quantity'][$date] = $dailyHourlyQuantity * 22.5;
// $row['daily_hourly_quantity'][$date] = $dailyHourlyQuantity * 22.5;
$pendingQty = max(
0,
@@ -804,8 +758,10 @@ class ProductionTargetPlan extends Component
$this->monthlyActualQuantity = QualityValidation::where('plant_id', $plantId)
->where('line_id', $lineId)
->whereYear('created_at', $year)
->whereMonth('created_at', $month)
->where('created_at', '>=', $startDate)
->where('created_at', '<', $endDate)
// ->whereYear('created_at', $year)
// ->whereMonth('created_at', $month)
->count();
$this->efficiency = $this->monthlyRecords > 0