Added logic for fg line concept in production mail alert
This commit is contained in:
@@ -127,15 +127,75 @@ class SendProductionReport extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
// $startDate = now()->setTime(8, 0, 0);
|
||||
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
if (strtolower($scheduleType) == 'daily')
|
||||
{
|
||||
$startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
$endDate = now()->setTime(8, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
}
|
||||
|
||||
$PlanstartDate = now()->setTime(8, 0, 0);
|
||||
$planendDate = now()->copy()->addDay()->setTime(7, 59, 0);
|
||||
|
||||
$tableData = [];
|
||||
$no = 1;
|
||||
|
||||
foreach ($plants as $plant) {
|
||||
// foreach ($plants as $plant) {
|
||||
// $lines = Line::where('plant_id', $plant->id)->get();
|
||||
|
||||
// foreach ($lines as $line) {
|
||||
// $targetQuantity = ProductionPlan::where('plant_id', $plant->id)
|
||||
// ->where('line_id', $line->id)
|
||||
// ->whereBetween('created_at', [$PlanstartDate, $planendDate])
|
||||
// ->sum('plan_quantity');
|
||||
|
||||
// $productionQuantity = ProductionQuantity::where('plant_id', $plant->id)
|
||||
// ->where('line_id', $line->id)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->count();
|
||||
|
||||
// $tableData[] = [
|
||||
// 'no' => $no++,
|
||||
// 'plant' => $plant->name,
|
||||
// 'line' => $line->name,
|
||||
// 'targetQuantity' => $targetQuantity,
|
||||
// 'productionQuantity' => $productionQuantity,
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
|
||||
// $fgTableData = []; // store FG Line related data
|
||||
|
||||
// foreach ($plants as $plant) {
|
||||
// // ✅ Only get FG Lines
|
||||
// $fgLines = Line::where('plant_id', $plant->id)
|
||||
// ->where('type', 'FG Line')
|
||||
// ->get();
|
||||
|
||||
// foreach ($fgLines as $line) {
|
||||
// $validationCount = \App\Models\QualityValidation::where('plant_id', $plant->id)
|
||||
// ->where('line_id', $line->id)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->count();
|
||||
|
||||
// $fgTableData[] = [
|
||||
// 'no' => $no++,
|
||||
// 'plant' => $plant->name,
|
||||
// 'line' => $line->name,
|
||||
// 'targetQuantity' => $targetQuantity,
|
||||
// 'productionQuantity' => $validationCount,
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
|
||||
foreach ($plants as $plant)
|
||||
{
|
||||
$lines = Line::where('plant_id', $plant->id)->get();
|
||||
|
||||
foreach ($lines as $line) {
|
||||
@@ -144,10 +204,17 @@ class SendProductionReport extends Command
|
||||
->whereBetween('created_at', [$PlanstartDate, $planendDate])
|
||||
->sum('plan_quantity');
|
||||
|
||||
$productionQuantity = ProductionQuantity::where('plant_id', $plant->id)
|
||||
->where('line_id', $line->id)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->count();
|
||||
if (strtolower($line->type) === 'fg line') {
|
||||
$productionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id)
|
||||
->where('line_id', $line->id)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->count();
|
||||
} else {
|
||||
$productionQuantity = ProductionQuantity::where('plant_id', $plant->id)
|
||||
->where('line_id', $line->id)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->count();
|
||||
}
|
||||
|
||||
$tableData[] = [
|
||||
'no' => $no++,
|
||||
@@ -159,8 +226,11 @@ class SendProductionReport extends Command
|
||||
}
|
||||
}
|
||||
|
||||
// Optional: show table in console
|
||||
$this->table(['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'], $tableData);
|
||||
|
||||
|
||||
///$this->table(['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'], $fgTableData);
|
||||
|
||||
$this->table(['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'], $tableData);
|
||||
|
||||
if (!empty($emails)) {
|
||||
foreach ($emails as $email) {
|
||||
|
||||
Reference in New Issue
Block a user