From 53f0a7bfdfd6dc33a93fde02383439edb28031c1 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 29 Nov 2025 17:37:16 +0530 Subject: [PATCH 1/2] Refactor InvoiceDataMail class for improved readability and consistency and __construct arg passing $tableData instead of $tableData = [] --- app/Mail/InvoiceDataMail.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/Mail/InvoiceDataMail.php b/app/Mail/InvoiceDataMail.php index d6b61b4..764d7fa 100644 --- a/app/Mail/InvoiceDataMail.php +++ b/app/Mail/InvoiceDataMail.php @@ -2,13 +2,13 @@ namespace App\Mail; +use App\Models\InvoiceDataValidation; +use DateTime; use Illuminate\Bus\Queueable; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailables\Content; use Illuminate\Mail\Mailables\Envelope; use Illuminate\Queue\SerializesModels; -use DateTime; class InvoiceDataMail extends Mailable { @@ -23,7 +23,7 @@ class InvoiceDataMail extends Mailable /** * Create a new message instance. */ - public function __construct($scheduleType, $tableData = [], $mailSubject) + public function __construct($scheduleType, $tableData, $mailSubject) { $this->scheduleType = $scheduleType; $this->tableData = $tableData ?? []; @@ -48,17 +48,17 @@ class InvoiceDataMail extends Mailable $greeting = 'Dear Sir/Madam,

We are sending here with list of "Despatch pending sale invoice & STO invoice as on date"'; if ($this->scheduleType == 'Daily') { - $firstRecord = \App\Models\InvoiceDataValidation::orderBy('document_date', 'asc')->first(); - //$lastRecord = \App\Models\InvoiceDataValidation::orderBy('document_date', 'desc')->first(); + $firstRecord = InvoiceDataValidation::orderBy('document_date', 'asc')->first(); + // $lastRecord = InvoiceDataValidation::orderBy('document_date', 'desc')->first(); if ($firstRecord) { $startDate = \Carbon\Carbon::parse($firstRecord->document_date)->startOfDay(); - //$endDate = \Carbon\Carbon::parse($lastRecord->document_date)->endOfDay(); + // $endDate = \Carbon\Carbon::parse($lastRecord->document_date)->endOfDay(); } $endDate = now()->setTime(10, 0, 0); // $fromDate = (new DateTime('yesterday 10:00'))->format('d/m/Y H:i') . ':000';//08:00 - // $toDate = (new DateTime('today 09:59'))->format('d/m/Y H:i') . ':999';//07:59 + // $toDate = (new DateTime('today 09:59')) ->format('d/m/Y H:i') . ':999';//07:59 $reportPeriod = "from: $startDate to $endDate\".

Please arrange to despatch the same immediately."; $greeting .= $reportPeriod; } @@ -74,17 +74,17 @@ class InvoiceDataMail extends Mailable 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'); + $toMinute = $now->format('d/m/Y H:i:s'); $greeting .= "from: $fromMinute to $toMinute.

Please arrange to despatch the same immediately."; } return new Content( view: 'mail.invoice_data_report', with: [ - 'company' => "CRI Digital Manufacturing Solutions", + 'company' => 'CRI Digital Manufacturing Solutions', 'greeting' => $greeting, 'tableData' => $this->tableData, - 'wishes' => "Thanks & Regards,
CRI Digital Manufacturing Solutions" + 'wishes' => 'Thanks & Regards,
CRI Digital Manufacturing Solutions', ], ); } From ff8aa8b5361b68123f961bcfbd32ea3b4e1889ce Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 29 Nov 2025 17:54:12 +0530 Subject: [PATCH 2/2] Update startDate logic in InvoiceDataMail content method to handle null document_date --- app/Mail/InvoiceDataMail.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Mail/InvoiceDataMail.php b/app/Mail/InvoiceDataMail.php index 764d7fa..4fc64d7 100644 --- a/app/Mail/InvoiceDataMail.php +++ b/app/Mail/InvoiceDataMail.php @@ -51,9 +51,12 @@ class InvoiceDataMail extends Mailable $firstRecord = InvoiceDataValidation::orderBy('document_date', 'asc')->first(); // $lastRecord = InvoiceDataValidation::orderBy('document_date', 'desc')->first(); - if ($firstRecord) { + $startDate = null; + if ($firstRecord && $firstRecord->document_date != null && $firstRecord->document_date != '') { $startDate = \Carbon\Carbon::parse($firstRecord->document_date)->startOfDay(); // $endDate = \Carbon\Carbon::parse($lastRecord->document_date)->endOfDay(); + } else { + $startDate = now()->subDay()->setTime(10, 0, 0); } $endDate = now()->setTime(10, 0, 0);