Refactor invoice report generation to include quantity metrics and enhance email content structure
This commit is contained in:
@@ -30,252 +30,11 @@ class SendInvoiceReport extends Command
|
||||
* Execute the console command.
|
||||
*/
|
||||
|
||||
// public function handle()
|
||||
// {
|
||||
|
||||
// $schedule = $this->argument('schedule_type');
|
||||
// $plantid = $this->argument('plant');
|
||||
|
||||
// $mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceValidation')->get()->groupBy('rule_name');
|
||||
|
||||
// $startDate = now()->setTime(8, 0, 0);
|
||||
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
// $plants = InvoiceValidation::select('plant_id')->distinct()->pluck('plant_id');
|
||||
|
||||
// $serialTableData = [];
|
||||
// $materialTableData = [];
|
||||
// $bundleTableData = [];
|
||||
// $noSerial = 1;
|
||||
// $noMaterial = 1;
|
||||
// $noBundle = 1;
|
||||
|
||||
// foreach ($plants as $plantId) {
|
||||
// $plant = Plant::find($plantId);
|
||||
// $plantName = $plant ? $plant->name : $plantId;
|
||||
|
||||
// //..Serial Invoice
|
||||
|
||||
// $totalSerialCount = InvoiceValidation::where('plant_id', $plantId)
|
||||
// ->whereNull('quantity')
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->distinct('invoice_number')
|
||||
// ->count('invoice_number');
|
||||
|
||||
// $scannedSerialCount = InvoiceValidation::select('invoice_number')
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->whereNull('quantity')
|
||||
// ->whereBetween('updated_at', [$startDate, $endDate])
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw(
|
||||
// "COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)"
|
||||
// )
|
||||
// ->count();
|
||||
|
||||
// $serialTableData[] = [
|
||||
// 'no' => $noSerial++,
|
||||
// 'plant' => $plantName,
|
||||
// 'totalInvoice' => $totalSerialCount,
|
||||
// 'scannedInvoice' => $scannedSerialCount,
|
||||
// ];
|
||||
|
||||
// //..Individual Invoice
|
||||
|
||||
// $TotalMatCount = InvoiceValidation::where('plant_id', $plantId)
|
||||
// ->where('quantity', 1)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->distinct('invoice_number')
|
||||
// ->count('invoice_number');
|
||||
|
||||
// $scannedMatCount = InvoiceValidation::select('invoice_number')
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->where('quantity', 1)
|
||||
// ->whereBetween('updated_at', [$startDate, $endDate])
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw(
|
||||
// "COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)"
|
||||
// )
|
||||
// ->count();
|
||||
|
||||
// $materialTableData[] = [
|
||||
// 'no' => $noMaterial++,
|
||||
// 'plant' => $plantName,
|
||||
// 'totalInvoice' => $TotalMatCount,
|
||||
// 'scannedInvoice' => $scannedMatCount,
|
||||
// ];
|
||||
|
||||
// //..BUndle Invoice
|
||||
|
||||
// $totalBundleCount = InvoiceValidation::where('plant_id', $plantId)
|
||||
// ->where('quantity', '>', 1)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->distinct('invoice_number')
|
||||
// ->count('invoice_number');
|
||||
|
||||
// $scannedBundleCount = InvoiceValidation::select('invoice_number')
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->where('quantity', '>', 1)
|
||||
// ->whereBetween('updated_at', [$startDate, $endDate])
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw(
|
||||
// "COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)"
|
||||
// )
|
||||
// ->count();
|
||||
|
||||
// $bundleTableData[] = [
|
||||
// 'no' => $noBundle++,
|
||||
// 'plant' => $plantName,
|
||||
// 'totalInvoice' => $totalBundleCount,
|
||||
// 'scannedInvoice' => $scannedBundleCount,
|
||||
// ];
|
||||
// }
|
||||
|
||||
// // Send to SerialInvoiceMail recipients
|
||||
// if ($mailRules->has('SerialInvoiceMail')) {
|
||||
// $emails = $mailRules['SerialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new test($serialTableData, [], []));
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Send to MaterialInvoiceMail recipients (material + bundle table)
|
||||
// if ($mailRules->has('MaterialInvoiceMail')) {
|
||||
// $emails = $mailRules['MaterialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new test([], $materialTableData, $bundleTableData));
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Send to InvoiceMail recipients (all three tables)
|
||||
// if ($mailRules->has('InvoiceMail')) {
|
||||
// $emails = $mailRules['InvoiceMail']->pluck('email')->unique()->toArray();
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new test($serialTableData, $materialTableData, $bundleTableData));
|
||||
// }
|
||||
// }
|
||||
// //$this->info(json_encode($materialTableData));
|
||||
// }
|
||||
|
||||
// public function handle()
|
||||
// {
|
||||
// $schedule = $this->argument('schedule_type');
|
||||
// $plantId = $this->argument('plant');
|
||||
|
||||
// $mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceValidation')->get()->groupBy('rule_name');
|
||||
|
||||
// $startDate = now()->setTime(8, 0, 0);
|
||||
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
|
||||
// $serialTableData = [];
|
||||
// $materialTableData = [];
|
||||
// $bundleTableData = [];
|
||||
|
||||
// $plant = Plant::find($plantId);
|
||||
// $plantName = $plant ? $plant->name : $plantId;
|
||||
|
||||
// // Serial Invoice
|
||||
// $totalSerialCount = InvoiceValidation::where('plant_id', $plantId)
|
||||
// ->whereNull('quantity')
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->distinct('invoice_number')
|
||||
// ->count('invoice_number');
|
||||
|
||||
// $scannedSerialCount = InvoiceValidation::select('invoice_number')
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->whereNull('quantity')
|
||||
// ->whereBetween('updated_at', [$startDate, $endDate])
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw(
|
||||
// "COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)"
|
||||
// )
|
||||
// ->count();
|
||||
|
||||
// $serialTableData[] = [
|
||||
// 'no' => 1,
|
||||
// 'plant' => $plantName,
|
||||
// 'totalInvoice' => $totalSerialCount,
|
||||
// 'scannedInvoice' => $scannedSerialCount,
|
||||
// ];
|
||||
|
||||
// // Individual Material Invoice
|
||||
// $TotalMatCount = InvoiceValidation::where('plant_id', $plantId)
|
||||
// ->where('quantity', 1)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->distinct('invoice_number')
|
||||
// ->count('invoice_number');
|
||||
|
||||
// $scannedMatCount = InvoiceValidation::select('invoice_number')
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->where('quantity', 1)
|
||||
// ->whereBetween('updated_at', [$startDate, $endDate])
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw(
|
||||
// "COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)"
|
||||
// )
|
||||
// ->count();
|
||||
|
||||
// $materialTableData[] = [
|
||||
// 'no' => 1,
|
||||
// 'plant' => $plantName,
|
||||
// 'totalInvoice' => $TotalMatCount,
|
||||
// 'scannedInvoice' => $scannedMatCount,
|
||||
// ];
|
||||
|
||||
// // Bundle Invoice
|
||||
// $totalBundleCount = InvoiceValidation::where('plant_id', $plantId)
|
||||
// ->where('quantity', '>', 1)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->distinct('invoice_number')
|
||||
// ->count('invoice_number');
|
||||
|
||||
// $scannedBundleCount = InvoiceValidation::select('invoice_number')
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->where('quantity', '>', 1)
|
||||
// ->whereBetween('updated_at', [$startDate, $endDate])
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw(
|
||||
// "COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)"
|
||||
// )
|
||||
// ->count();
|
||||
|
||||
// $bundleTableData[] = [
|
||||
// 'no' => 1,
|
||||
// 'plant' => $plantName,
|
||||
// 'totalInvoice' => $totalBundleCount,
|
||||
// 'scannedInvoice' => $scannedBundleCount,
|
||||
// ];
|
||||
|
||||
// // Send to SerialInvoiceMail recipients
|
||||
// if ($mailRules->has('SerialInvoiceMail')) {
|
||||
// $emails = $mailRules['SerialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new test($serialTableData, [], []));
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Send to MaterialInvoiceMail recipients (material + bundle table)
|
||||
// if ($mailRules->has('MaterialInvoiceMail')) {
|
||||
// $emails = $mailRules['MaterialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new test([], $materialTableData, $bundleTableData));
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Send to InvoiceMail recipients (all three tables)
|
||||
// if ($mailRules->has('InvoiceMail')) {
|
||||
// $emails = $mailRules['InvoiceMail']->pluck('email')->unique()->toArray();
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new test($serialTableData, $materialTableData, $bundleTableData));
|
||||
// }
|
||||
// }
|
||||
|
||||
// // $this->table(
|
||||
// // ['No', 'Plant', 'Total Invoice', 'Scanned Invoice'],
|
||||
// // $serialTableData
|
||||
// // );
|
||||
// }
|
||||
public function handle()
|
||||
{
|
||||
$schedule = $this->argument('schedule_type');
|
||||
//$scheduleType = $this->argument('scheduleType');
|
||||
$plantIdArg = (int) $this->argument('plant'); // can be 0 for all plants
|
||||
|
||||
$mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceValidation')->get()->groupBy('rule_name');
|
||||
@@ -303,7 +62,8 @@ class SendInvoiceReport extends Command
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
}
|
||||
foreach ($plantIds as $plantId) {
|
||||
foreach ($plantIds as $plantId)
|
||||
{
|
||||
$plant = Plant::find($plantId);
|
||||
$plantName = $plant ? $plant->name : $plantId;
|
||||
|
||||
@@ -322,11 +82,27 @@ class SendInvoiceReport extends Command
|
||||
->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)")
|
||||
->count();
|
||||
|
||||
$serialInvoiceQuan = InvoiceValidation::where('plant_id', $plantId)
|
||||
->where('quantity', null)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->count();
|
||||
|
||||
$scannedInvoiceQuan = InvoiceValidation::where('plant_id', $plantId)
|
||||
->where('scanned_status', 'Scanned')
|
||||
->where(function($query) {
|
||||
$query->whereNull('quantity')
|
||||
->orWhere('quantity', 0);
|
||||
})
|
||||
->whereBetween('updated_at', [$startDate, $endDate])
|
||||
->count();
|
||||
|
||||
$serialTableData[] = [
|
||||
'no' => $no,
|
||||
'plant' => $plantName,
|
||||
'totalInvoice' => $totalSerialCount,
|
||||
'scannedInvoice' => $scannedSerialCount,
|
||||
'totalInvoiceQuan' => $serialInvoiceQuan,
|
||||
'scannedInvoiceQuan' => $scannedInvoiceQuan,
|
||||
];
|
||||
|
||||
// Material Invoice
|
||||
@@ -344,11 +120,25 @@ class SendInvoiceReport extends Command
|
||||
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)")
|
||||
->count();
|
||||
|
||||
$totalMatInvoiceQuan = InvoiceValidation::where('plant_id', $plantId)
|
||||
->where('quantity', 1)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->count();
|
||||
|
||||
$scannedMatInvoiceQuan = InvoiceValidation::where('plant_id', $plantId)
|
||||
->where('quantity', 1)
|
||||
->whereNotNull('serial_number')
|
||||
->where('serial_number','!=', '')
|
||||
->whereBetween('updated_at', [$startDate, $endDate])
|
||||
->count();
|
||||
|
||||
$materialTableData[] = [
|
||||
'no' => $no,
|
||||
'plant' => $plantName,
|
||||
'totalInvoice' => $totalMatCount,
|
||||
'scannedInvoice' => $scannedMatCount,
|
||||
'totalInvoiceQuan' => $totalMatInvoiceQuan,
|
||||
'scannedInvoiceQuan' => $scannedMatInvoiceQuan,
|
||||
];
|
||||
|
||||
// Bundle Invoice
|
||||
@@ -366,29 +156,51 @@ class SendInvoiceReport extends Command
|
||||
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)")
|
||||
->count();
|
||||
|
||||
$totalBundleInvoiceQuan = InvoiceValidation::where('plant_id', $plantId)
|
||||
->where('quantity', null)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->count();
|
||||
|
||||
$scannedBundleInvoiceQuan = InvoiceValidation::where('plant_id', $plantId)
|
||||
->where('scanned_status', 'Scanned')
|
||||
->where(function($query) {
|
||||
$query->whereNull('quantity')
|
||||
->orWhere('quantity', 0);
|
||||
})
|
||||
->whereBetween('updated_at', [$startDate, $endDate])
|
||||
->count();
|
||||
|
||||
$bundleTableData[] = [
|
||||
'no' => $no,
|
||||
'plant' => $plantName,
|
||||
'totalInvoice' => $totalBundleCount,
|
||||
'scannedInvoice' => $scannedBundleCount,
|
||||
'totalInvoiceQuan' => $totalBundleInvoiceQuan,
|
||||
'scannedInvoiceQuan' => $scannedBundleInvoiceQuan,
|
||||
];
|
||||
|
||||
$no++;
|
||||
}
|
||||
|
||||
$mail = new test($serialTableData, $materialTableData, $bundleTableData, $schedule);
|
||||
$contentVars = $mail->content()->with;
|
||||
|
||||
$this->info($contentVars['greeting'] ?? 'Invoice Report');
|
||||
|
||||
// Send to SerialInvoiceMail recipients
|
||||
if ($mailRules->has('SerialInvoiceMail')) {
|
||||
$emails = $mailRules['SerialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||
foreach ($emails as $email) {
|
||||
Mail::to($email)->send(new test($serialTableData, [], []));
|
||||
Mail::to($email)->send(new test($serialTableData, [], [], $schedule));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Send to MaterialInvoiceMail recipients (material + bundle table)
|
||||
if ($mailRules->has('MaterialInvoiceMail')) {
|
||||
$emails = $mailRules['MaterialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||
foreach ($emails as $email) {
|
||||
Mail::to($email)->send(new test([], $materialTableData, $bundleTableData));
|
||||
Mail::to($email)->send(new test([], $materialTableData, $bundleTableData, $schedule));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,19 +208,21 @@ class SendInvoiceReport extends Command
|
||||
if ($mailRules->has('InvoiceMail')) {
|
||||
$emails = $mailRules['InvoiceMail']->pluck('email')->unique()->toArray();
|
||||
foreach ($emails as $email) {
|
||||
Mail::to($email)->send(new test($serialTableData, $materialTableData, $bundleTableData));
|
||||
Mail::to($email)->send(new test($serialTableData, $materialTableData, $bundleTableData, $schedule));
|
||||
}
|
||||
}
|
||||
|
||||
// Show preview in console
|
||||
$this->info('--- Serial Invoice Table ---');
|
||||
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice'], $serialTableData);
|
||||
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice','TotalInvoice Quantity', 'ScannedInvoice Quantity'], $serialTableData);
|
||||
|
||||
$this->info('--- Material Invoice Table ---');
|
||||
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice'], $materialTableData);
|
||||
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice','TotalInvoice Quantity', 'ScannedInvoice Quantity'], $materialTableData);
|
||||
|
||||
$this->info('--- Bundle Invoice Table ---');
|
||||
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice'], $bundleTableData);
|
||||
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice','TotalInvoice Quantity', 'ScannedInvoice Quantity'], $bundleTableData);
|
||||
|
||||
$this->info($contentVars['wishes'] ?? '');
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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).");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use DateTime;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
@@ -14,12 +15,14 @@ class ProductionMail extends Mailable
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public $tableData;
|
||||
public $scheduleType;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct($tableData = [])
|
||||
public function __construct($scheduleType,$tableData = [])
|
||||
{
|
||||
$this->scheduleType = $scheduleType;
|
||||
$this->tableData = $tableData ?? [];
|
||||
}
|
||||
|
||||
@@ -36,19 +39,57 @@ class ProductionMail extends Mailable
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
// public function content(): Content
|
||||
// {
|
||||
// return new Content(
|
||||
// view: 'mail.production_report',
|
||||
// with: [
|
||||
// 'company' => "CRI Digital Manufacturing Solutions",
|
||||
// 'greeting' => "Dear Sir/Madam,<br><br>Kindly find the attached production report status details for the 'Target Quantity' and 'Production Quantity' count,",
|
||||
// // 'greeting' => "Dear Sir/Madam,<br><br>Kindly find the attached production report status details for the 'Target Quantity' and 'Production Quantity' count,<br>" . $reportPeriod,
|
||||
// 'tableData' => $this->tableData,
|
||||
// 'wishes' => "Thanks & Regards,<br>CRI Digital Manufacturing Solutions"
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
$greeting = "Dear Sir/Madam,<br><br>Kindly find the attached production report status details for the 'Target Quantity' and 'Production Quantity' count,";
|
||||
|
||||
if ($this->scheduleType == 'Daily') {
|
||||
$fromDate = (new DateTime('yesterday 08:00'))->format('d/m/Y H:i') . ':000';
|
||||
$toDate = (new DateTime('today 07:59'))->format('d/m/Y H:i') . ':999';
|
||||
$reportPeriod = "The following report presents results from: $fromDate to $toDate.";
|
||||
$greeting .= $reportPeriod;
|
||||
}
|
||||
|
||||
if ($this->scheduleType == 'Hourly') {
|
||||
$now = now();
|
||||
$fromHour = $now->copy()->subHour()->format('H:i:s');
|
||||
$toHour = $now->format('H:i:s');
|
||||
$reportDate = $now->format('d/m/Y');
|
||||
$greeting .= "The following report presents results from: $reportDate, $fromHour to $toHour.";
|
||||
}
|
||||
|
||||
if ($this->scheduleType == 'Live') {
|
||||
$now = now();
|
||||
$fromMinute = $now->copy()->subMinute()->format('d/m/Y H:i:s');
|
||||
$toMinute = $now->format('d/m/Y H:i:s');
|
||||
$greeting .= "The following report presents results from: $fromMinute to $toMinute.";
|
||||
}
|
||||
|
||||
return new Content(
|
||||
view: 'mail.production_report',
|
||||
with: [
|
||||
'company' => "CRI Digital Manufacturing Solutions",
|
||||
'greeting' => "Dear Sir/Madam,<br><br>Kindly find the attached production report status details for the 'Target Quantity' and 'Production Quantity' count,",
|
||||
'greeting' => $greeting,
|
||||
'tableData' => $this->tableData,
|
||||
'wishes' => "Thanks & Regards,<br>CRI Digital Manufacturing Solutions"
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use DateTime;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
@@ -16,16 +17,16 @@ class test extends Mailable
|
||||
public $materialTableData;
|
||||
public $bundleTableData;
|
||||
|
||||
public $schedule;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
// public function __construct($tableData = [])
|
||||
// {
|
||||
// $this->tableData = $tableData ?? [];
|
||||
// }
|
||||
public function __construct($serialTableData, $materialTableData, $bundleTableData)
|
||||
|
||||
public function __construct($serialTableData, $materialTableData, $bundleTableData, $schedule)
|
||||
{
|
||||
$this->schedule = $schedule;
|
||||
$this->serialTableData = $serialTableData;
|
||||
$this->materialTableData = $materialTableData;
|
||||
$this->bundleTableData = $bundleTableData;
|
||||
@@ -44,18 +45,54 @@ class test extends Mailable
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
// public function content(): Content
|
||||
// {
|
||||
// return new Content(
|
||||
// view: 'mail.test_mail',
|
||||
// with: [
|
||||
// 'company' => "CRI Digital Manufacturing Solutions",
|
||||
// 'greeting' => "Dear Sir/Madam,<br><br>Kindly find the attached invoice status details for the 'Total Number of Invoices' and 'Scanned Number of Invoices' count,",
|
||||
// //'tableData' => $this->tableData,
|
||||
// 'serialTableData' => $this->serialTableData,
|
||||
// 'materialTableData' => $this->materialTableData,
|
||||
// 'bundleTableData' => $this->bundleTableData,
|
||||
// 'wishes' => "Thanks & Regards,<br>CRI Digital Manufacturing Solutions"
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
public function content(): Content
|
||||
{
|
||||
$greeting = "Dear Sir/Madam,<br><br>Kindly find the attached invoice status details for the 'Total Number of Invoices' and 'Scanned Number of Invoices' count,";
|
||||
|
||||
if ($this->schedule == 'Daily') {
|
||||
$fromDate = (new DateTime('yesterday 08:00'))->format('d/m/Y H:i') . ':000';
|
||||
$toDate = (new DateTime('today 07:59'))->format('d/m/Y H:i') . ':999';
|
||||
$reportPeriod = "The following report presents results from: $fromDate to $toDate.";
|
||||
//$greeting .= $reportPeriod;
|
||||
$greeting .= "<br><br>$reportPeriod";
|
||||
}
|
||||
|
||||
if ($this->schedule == 'Hourly') {
|
||||
$now = now();
|
||||
$fromHour = $now->copy()->subHour()->format('H:i:s');
|
||||
$toHour = $now->format('H:i:s');
|
||||
$reportDate = $now->format('d/m/Y');
|
||||
$greeting .= "The following report presents results from: $reportDate, $fromHour to $toHour.";
|
||||
}
|
||||
|
||||
if ($this->schedule == 'Live') {
|
||||
$now = now();
|
||||
$fromMinute = $now->copy()->subMinute()->format('d/m/Y H:i:s');
|
||||
$toMinute = $now->format('d/m/Y H:i:s');
|
||||
$greeting .= "The following report presents results from: $fromMinute to $toMinute.";
|
||||
}
|
||||
|
||||
return new Content(
|
||||
view: 'mail.test_mail',
|
||||
// with: [
|
||||
// 'name' => "CRI Digital Manufacturing Solutions<br><br>Dear Sir/Madam,<br><br> Kindly find the attached invoice status details for the 'Total Number Of Invoices' and 'Scanned Number Of Invoices' count,",
|
||||
// 'tableData' => $this->tableData,
|
||||
// 'wishes' => "Thanks & Regards<br><br>CRI Digital Manufacturing Solutions"
|
||||
// ],
|
||||
with: [
|
||||
with: [
|
||||
'company' => "CRI Digital Manufacturing Solutions",
|
||||
'greeting' => "Dear Sir/Madam,<br><br>Kindly find the attached invoice status details for the 'Total Number of Invoices' and 'Scanned Number of Invoices' count,",
|
||||
'greeting' => $greeting,
|
||||
//'greeting' => "Dear Sir/Madam,<br><br>Kindly find the attached invoice status details for the 'Total Number of Invoices' and 'Scanned Number of Invoices' count,",
|
||||
//'tableData' => $this->tableData,
|
||||
'serialTableData' => $this->serialTableData,
|
||||
'materialTableData' => $this->materialTableData,
|
||||
|
||||
@@ -98,6 +98,8 @@
|
||||
<th>Plant</th>
|
||||
<th>Total Number of Invoice</th>
|
||||
<th>Scanned Number of Invoice</th>
|
||||
<th>Total Invoice Quantity</th>
|
||||
<th>Scanned Invoice Quantity</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -107,6 +109,8 @@
|
||||
<td style="white-space: nowrap;">{{ $row['plant'] }}</td>
|
||||
<td>{{ $row['totalInvoice'] }}</td>
|
||||
<td>{{ $row['scannedInvoice'] }}</td>
|
||||
<td>{{ $row['totalInvoiceQuan'] }}</td>
|
||||
<td>{{ $row['scannedInvoiceQuan'] }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
@@ -123,6 +127,8 @@
|
||||
<th>Plant</th>
|
||||
<th>Total Number of Invoice</th>
|
||||
<th>Scanned Number of Invoice</th>
|
||||
<th>Total Invoice Quantity</th>
|
||||
<th>Scanned Invoice Quantity</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -132,6 +138,8 @@
|
||||
<td style="white-space: nowrap;">{{ $row['plant'] }}</td>
|
||||
<td>{{ $row['totalInvoice'] }}</td>
|
||||
<td>{{ $row['scannedInvoice'] }}</td>
|
||||
<td>{{ $row['totalInvoiceQuan'] }}</td>
|
||||
<td>{{ $row['scannedInvoiceQuan'] }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
@@ -148,6 +156,9 @@
|
||||
<th>Plant</th>
|
||||
<th>Total Number of Invoice</th>
|
||||
<th>Scanned Number of Invoice</th>
|
||||
<th>Scanned Number of Invoice</th>
|
||||
<th>Total Invoice Quantity</th>
|
||||
<th>Scanned Invoice Quantity</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -157,6 +168,8 @@
|
||||
<td style="white-space: nowrap;">{{ $row['plant'] }}</td>
|
||||
<td>{{ $row['totalInvoice'] }}</td>
|
||||
<td>{{ $row['scannedInvoice'] }}</td>
|
||||
<td>{{ $row['totalInvoiceQuan'] }}</td>
|
||||
<td>{{ $row['scannedInvoiceQuan'] }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user