Refactor invoice report generation to include quantity metrics and enhance email content structure
This commit is contained in:
@@ -33,77 +33,6 @@ class SendProductionReport extends Command
|
||||
* Execute the console command.
|
||||
*/
|
||||
|
||||
// public function handle()
|
||||
// {
|
||||
// $scheduleType = $this->argument('schedule_type');
|
||||
// $plantId = $this->argument('plant');
|
||||
|
||||
// $mailRules = \App\Models\AlertMailRule::where('module', 'ProductionQuantities')
|
||||
// ->where('rule_name', 'ProductionMail')
|
||||
// ->where('plant', $plantId)
|
||||
// ->where('schedule_type', $scheduleType)
|
||||
// ->get();
|
||||
|
||||
// $emails = $mailRules->pluck('email')->unique()->toArray();
|
||||
|
||||
// $plant = Plant::find($plantId);
|
||||
|
||||
// if (!$plant) {
|
||||
// $this->error("Invalid plant ID: $plantId");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// $lines = Line::where('plant_id', $plantId)->get();
|
||||
|
||||
// $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, 00);
|
||||
|
||||
// $tableData = [];
|
||||
// $no = 1;
|
||||
|
||||
// foreach ($lines as $line) {
|
||||
// $lineId = $line->id;
|
||||
// $lineName = $line->name;
|
||||
|
||||
// $targetQuantity = ProductionPlan::where('plant_id', $plantId)
|
||||
// ->where('line_id', $lineId)
|
||||
// ->whereBetween('created_at', [$PlanstartDate, $planendDate])
|
||||
// ->sum('plan_quantity');
|
||||
|
||||
// $productionQuantity = ProductionQuantity::where('plant_id', $plantId)
|
||||
// ->where('line_id', $lineId)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->count();
|
||||
|
||||
// $tableData[] = [
|
||||
// 'no' => $no++,
|
||||
// 'plant' => $plant->name,
|
||||
// 'line' => $lineName,
|
||||
// 'targetQuantity' => $targetQuantity,
|
||||
// 'productionQuantity' => $productionQuantity,
|
||||
// ];
|
||||
// }
|
||||
|
||||
// // $this->table(
|
||||
// // ['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'],
|
||||
// // $tableData
|
||||
// // );
|
||||
|
||||
// if (!empty($emails)) {
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new ProductionMail($tableData));
|
||||
// }
|
||||
// } else {
|
||||
// $this->info('No recipients found for ProductionMailAlert.');
|
||||
// }
|
||||
|
||||
// $this->info("Production report sent to " . count($emails) . " recipient(s).");
|
||||
|
||||
// }
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$scheduleType = $this->argument('schedule_type');
|
||||
@@ -146,55 +75,6 @@ class SendProductionReport extends Command
|
||||
$tableData = [];
|
||||
$no = 1;
|
||||
|
||||
// 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)
|
||||
@@ -232,20 +112,38 @@ class SendProductionReport extends Command
|
||||
|
||||
|
||||
|
||||
///$this->table(['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'], $fgTableData);
|
||||
//$this->table(['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'], $fgTableData);
|
||||
|
||||
$this->table(['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'], $tableData);
|
||||
// $this->table(['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'], $tableData);
|
||||
|
||||
// if (!empty($emails)) {
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new ProductionMail($tableData));
|
||||
// }
|
||||
// } else {
|
||||
// $this->info('No recipients found for ProductionMailAlert.');
|
||||
// }
|
||||
|
||||
// $this->info("Production report sent to " . count($emails) . " recipient(s).");
|
||||
// Preview in console
|
||||
$mail = new ProductionMail($scheduleType, $tableData);
|
||||
$contentVars = $mail->content()->with;
|
||||
|
||||
$this->info($contentVars['greeting'] ?? 'Production Report');
|
||||
$this->table(
|
||||
['No', 'Plant', 'Line', 'Type', 'Target Quantity', 'Production Quantity'],
|
||||
$tableData
|
||||
);
|
||||
$this->info($contentVars['wishes'] ?? '');
|
||||
|
||||
// Send mails
|
||||
if (!empty($emails)) {
|
||||
foreach ($emails as $email) {
|
||||
Mail::to($email)->send(new ProductionMail($tableData));
|
||||
Mail::to($email)->send(new ProductionMail($scheduleType, $tableData));
|
||||
}
|
||||
$this->info("Production report sent to " . count($emails) . " recipient(s).");
|
||||
} else {
|
||||
$this->info('No recipients found for ProductionMailAlert.');
|
||||
$this->warn('No recipients found for ProductionMailAlert.');
|
||||
}
|
||||
|
||||
$this->info("Production report sent to " . count($emails) . " recipient(s).");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user