Refactor invoice report generation to include quantity metrics and enhance email content structure

This commit is contained in:
dhanabalan
2025-08-26 18:08:06 +05:30
parent e57962f023
commit 19e1f12f5d
5 changed files with 195 additions and 392 deletions

View File

@@ -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,