Removed previous pending day count logic and added non planned production quantity
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
This commit is contained in:
@@ -33,13 +33,10 @@ class SendProductionReport extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
// ini_set('max_execution_time', 0); // disable limit
|
|
||||||
// set_time_limit(0);
|
|
||||||
|
|
||||||
$scheduleType = $this->argument('schedule_type');
|
$scheduleType = $this->argument('schedule_type');
|
||||||
$plantId = (int) $this->argument('plant'); // cast to int for safety
|
$plantId = (int) $this->argument('plant');
|
||||||
|
|
||||||
// Fetch mail rules based on schedule type
|
|
||||||
$mailRules = \App\Models\AlertMailRule::where('module', 'ProductionQuantities')
|
$mailRules = \App\Models\AlertMailRule::where('module', 'ProductionQuantities')
|
||||||
->where('rule_name', 'ProductionMail')
|
->where('rule_name', 'ProductionMail')
|
||||||
->where('schedule_type', $scheduleType)
|
->where('schedule_type', $scheduleType)
|
||||||
@@ -190,53 +187,11 @@ class SendProductionReport extends Command
|
|||||||
|
|
||||||
$dailyTarget = round($dailyTarget, 2);
|
$dailyTarget = round($dailyTarget, 2);
|
||||||
|
|
||||||
$leaveDatesString = ProductionPlan::where('plant_id', $plant->id)
|
// $leaveDatesString = ProductionPlan::where('plant_id', $plant->id)
|
||||||
->where('line_id', $line->id)
|
// ->where('line_id', $line->id)
|
||||||
->whereMonth('created_at', $month)
|
// ->whereMonth('created_at', $month)
|
||||||
->whereYear('created_at', $year)
|
// ->whereYear('created_at', $year)
|
||||||
->value('leave_dates');
|
// ->value('leave_dates');
|
||||||
|
|
||||||
$leaveDates = $leaveDatesString ? explode(',', $leaveDatesString) : [];
|
|
||||||
|
|
||||||
$monthStart = $startDate->copy()->startOfMonth();
|
|
||||||
$yesterday = $startDate->copy()->subDay();
|
|
||||||
|
|
||||||
$completedDays = 0;
|
|
||||||
$currentDate = $monthStart->copy();
|
|
||||||
|
|
||||||
while ($currentDate->lte($yesterday)) {
|
|
||||||
|
|
||||||
if (!in_array($currentDate->format('Y-m-d'), $leaveDates)) {
|
|
||||||
$completedDays++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$currentDate->addDay();
|
|
||||||
}
|
|
||||||
|
|
||||||
$expectedTillYesterday = $dailyTarget * $completedDays;
|
|
||||||
|
|
||||||
if (strtolower($line->type) == 'fg line') {
|
|
||||||
|
|
||||||
$producedTillYesterday = \App\Models\QualityValidation::where('plant_id', $plant->id)
|
|
||||||
->where('line_id', $line->id)
|
|
||||||
->whereMonth('created_at', $month)
|
|
||||||
->whereYear('created_at', $year)
|
|
||||||
->where('created_at', '<', $startDate)
|
|
||||||
->count();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$producedTillYesterday = ProductionQuantity::where('plant_id', $plant->id)
|
|
||||||
->where('line_id', $line->id)
|
|
||||||
->whereMonth('created_at', $month)
|
|
||||||
->whereYear('created_at', $year)
|
|
||||||
->where('created_at', '<', $startDate)
|
|
||||||
->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
$previousRemaining = max(0, $expectedTillYesterday - $producedTillYesterday);
|
|
||||||
|
|
||||||
$totalTargetQuantity = round($dailyTarget + $previousRemaining, 2);
|
|
||||||
|
|
||||||
$itemIds = ProductionPlan::where('plant_id', $plant->id)
|
$itemIds = ProductionPlan::where('plant_id', $plant->id)
|
||||||
->where('line_id', $line->id)
|
->where('line_id', $line->id)
|
||||||
@@ -245,15 +200,70 @@ class SendProductionReport extends Command
|
|||||||
->distinct()
|
->distinct()
|
||||||
->pluck('item_id');
|
->pluck('item_id');
|
||||||
|
|
||||||
$totalHourlyQuantity = Item::whereIn('id', $itemIds)
|
// $leaveDates = $leaveDatesString ? explode(',', $leaveDatesString) : [];
|
||||||
->sum('hourly_quantity');
|
|
||||||
|
|
||||||
$capacityQuan = $totalHourlyQuantity * 22.5;
|
// $monthStart = $startDate->copy()->startOfMonth();
|
||||||
|
// $monthStart = $startDate->copy()->startOfMonth()->setTime(8, 0, 0);
|
||||||
|
|
||||||
|
// $yesterday = $startDate->copy()->subDay()->setTime(8, 0, 0);
|
||||||
|
|
||||||
|
// $completedDays = 0;
|
||||||
|
// $currentDate = $monthStart->copy();
|
||||||
|
|
||||||
|
// while ($currentDate->lte($yesterday)) {
|
||||||
|
|
||||||
|
// if (!in_array($currentDate->format('Y-m-d'), $leaveDates)) {
|
||||||
|
// $completedDays++;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $currentDate->addDay();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $expectedTillYesterday = $dailyTarget * $completedDays;
|
||||||
|
|
||||||
|
// if (strtolower($line->type) == 'fg line') {
|
||||||
|
|
||||||
|
// $producedTillYesterday = \App\Models\QualityValidation::where('plant_id', $plant->id)
|
||||||
|
// ->where('line_id', $line->id)
|
||||||
|
// ->whereIn('item_id', $itemIds)
|
||||||
|
// ->whereMonth('created_at', $month)
|
||||||
|
// ->whereYear('created_at', $year)
|
||||||
|
// ->where('created_at', '<', $startDate)
|
||||||
|
// ->count();
|
||||||
|
|
||||||
|
// } else {
|
||||||
|
|
||||||
|
// $producedTillYesterday = ProductionQuantity::where('plant_id', $plant->id)
|
||||||
|
// ->where('line_id', $line->id)
|
||||||
|
// ->whereIn('item_id', $itemIds)
|
||||||
|
// ->whereMonth('created_at', $month)
|
||||||
|
// ->whereYear('created_at', $year)
|
||||||
|
// ->where('created_at', '<', $startDate)
|
||||||
|
// ->count();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $previousRemaining = max(0, $expectedTillYesterday - $producedTillYesterday);
|
||||||
|
|
||||||
|
// $totalTargetQuantity = round($dailyTarget + $previousRemaining, 2);
|
||||||
|
|
||||||
|
$totalTargetQuantity = round($dailyTarget, 2);
|
||||||
|
|
||||||
|
// $totalHourlyQuantity = Item::whereIn('id', $itemIds)
|
||||||
|
// ->sum('hourly_quantity');
|
||||||
|
|
||||||
|
// $capacityQuan = $totalHourlyQuantity * 22.5;
|
||||||
|
|
||||||
if (strtolower($line->type) == 'fg line') {
|
if (strtolower($line->type) == 'fg line') {
|
||||||
|
|
||||||
$productionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id)
|
$productionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id)
|
||||||
->where('line_id', $line->id)
|
->where('line_id', $line->id)
|
||||||
|
->whereIn('item_id', $itemIds)
|
||||||
|
->whereBetween('created_at', [$startDate, $endDate])
|
||||||
|
->count();
|
||||||
|
|
||||||
|
$nonPlannedproductionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id)
|
||||||
|
->where('line_id', $line->id)
|
||||||
|
->whereNotIn('item_id', $itemIds)
|
||||||
->whereBetween('created_at', [$startDate, $endDate])
|
->whereBetween('created_at', [$startDate, $endDate])
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
@@ -286,6 +296,7 @@ class SendProductionReport extends Command
|
|||||||
|
|
||||||
$dayproductionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id)
|
$dayproductionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id)
|
||||||
->where('line_id', $line->id)
|
->where('line_id', $line->id)
|
||||||
|
->whereIn('item_id', $itemIds)
|
||||||
->whereBetween('created_at', [
|
->whereBetween('created_at', [
|
||||||
$startDate->copy()->setTime(8, 0, 0),
|
$startDate->copy()->setTime(8, 0, 0),
|
||||||
$startDate->copy()->setTime(19, 30, 0),
|
$startDate->copy()->setTime(19, 30, 0),
|
||||||
@@ -294,6 +305,7 @@ class SendProductionReport extends Command
|
|||||||
|
|
||||||
$nightproductionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id)
|
$nightproductionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id)
|
||||||
->where('line_id', $line->id)
|
->where('line_id', $line->id)
|
||||||
|
->whereIn('item_id', $itemIds)
|
||||||
->whereBetween('created_at', [
|
->whereBetween('created_at', [
|
||||||
$startDate->copy()->setTime(19, 30, 0),
|
$startDate->copy()->setTime(19, 30, 0),
|
||||||
$endDate->copy()->setTime(8, 0, 0),
|
$endDate->copy()->setTime(8, 0, 0),
|
||||||
@@ -331,7 +343,7 @@ class SendProductionReport extends Command
|
|||||||
'plant' => $plant->name,
|
'plant' => $plant->name,
|
||||||
'type' => $line->type,
|
'type' => $line->type,
|
||||||
'line' => $line->name,
|
'line' => $line->name,
|
||||||
'capacityQuantity' => floor($capacityQuan),
|
// 'capacityQuantity' => floor($capacityQuan),
|
||||||
'dayShiftPlanQuantity' => floor($dayShiftPlanQuan),
|
'dayShiftPlanQuantity' => floor($dayShiftPlanQuan),
|
||||||
'dayShiftActualQuantity' => floor($dayproductionQuantity),
|
'dayShiftActualQuantity' => floor($dayproductionQuantity),
|
||||||
'dayShiftEfficiency' => floor($dayShiftEfficiency) . '%',
|
'dayShiftEfficiency' => floor($dayShiftEfficiency) . '%',
|
||||||
@@ -342,6 +354,7 @@ class SendProductionReport extends Command
|
|||||||
'productionQuantity' => $productionQuantity,
|
'productionQuantity' => $productionQuantity,
|
||||||
'uom' => $line->uom,
|
'uom' => $line->uom,
|
||||||
'efficiency' => $efficiency . '%',
|
'efficiency' => $efficiency . '%',
|
||||||
|
'nonPlannedQuantity' => $nonPlannedproductionQuantity,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user