Refactor InvoiceDataMail class for improved readability and consistency and __construct arg passing $tableData instead of $tableData = []
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s

This commit is contained in:
dhanabalan
2025-11-29 17:37:16 +05:30
parent 1aa1937b39
commit 53f0a7bfdf

View File

@@ -2,13 +2,13 @@
namespace App\Mail; namespace App\Mail;
use App\Models\InvoiceDataValidation;
use DateTime;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content; use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope; use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use DateTime;
class InvoiceDataMail extends Mailable class InvoiceDataMail extends Mailable
{ {
@@ -23,7 +23,7 @@ class InvoiceDataMail extends Mailable
/** /**
* Create a new message instance. * Create a new message instance.
*/ */
public function __construct($scheduleType, $tableData = [], $mailSubject) public function __construct($scheduleType, $tableData, $mailSubject)
{ {
$this->scheduleType = $scheduleType; $this->scheduleType = $scheduleType;
$this->tableData = $tableData ?? []; $this->tableData = $tableData ?? [];
@@ -48,8 +48,8 @@ class InvoiceDataMail extends Mailable
$greeting = 'Dear Sir/Madam,<br><br>We are sending here with list of "Despatch pending sale invoice & STO invoice as on date"'; $greeting = 'Dear Sir/Madam,<br><br>We are sending here with list of "Despatch pending sale invoice & STO invoice as on date"';
if ($this->scheduleType == 'Daily') { if ($this->scheduleType == 'Daily') {
$firstRecord = \App\Models\InvoiceDataValidation::orderBy('document_date', 'asc')->first(); $firstRecord = InvoiceDataValidation::orderBy('document_date', 'asc')->first();
//$lastRecord = \App\Models\InvoiceDataValidation::orderBy('document_date', 'desc')->first(); // $lastRecord = InvoiceDataValidation::orderBy('document_date', 'desc')->first();
if ($firstRecord) { if ($firstRecord) {
$startDate = \Carbon\Carbon::parse($firstRecord->document_date)->startOfDay(); $startDate = \Carbon\Carbon::parse($firstRecord->document_date)->startOfDay();
@@ -81,10 +81,10 @@ class InvoiceDataMail extends Mailable
return new Content( return new Content(
view: 'mail.invoice_data_report', view: 'mail.invoice_data_report',
with: [ with: [
'company' => "CRI Digital Manufacturing Solutions", 'company' => 'CRI Digital Manufacturing Solutions',
'greeting' => $greeting, 'greeting' => $greeting,
'tableData' => $this->tableData, 'tableData' => $this->tableData,
'wishes' => "Thanks & Regards,<br>CRI Digital Manufacturing Solutions" 'wishes' => 'Thanks & Regards,<br>CRI Digital Manufacturing Solutions',
], ],
); );
} }