Files
pds/app/Mail/InvoiceDataMail.php
dhanabalan ff8aa8b536
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 12s
Gemini PR Review / review (pull_request) Failing after 21s
Laravel Pint / pint (pull_request) Successful in 2m15s
Laravel Larastan / larastan (pull_request) Failing after 3m7s
Update startDate logic in InvoiceDataMail content method to handle null document_date
2025-11-29 17:54:12 +05:30

105 lines
3.4 KiB
PHP

<?php
namespace App\Mail;
use App\Models\InvoiceDataValidation;
use DateTime;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class InvoiceDataMail extends Mailable
{
use Queueable, SerializesModels;
public $scheduleType;
public $tableData;
public $mailSubject;
/**
* Create a new message instance.
*/
public function __construct($scheduleType, $tableData, $mailSubject)
{
$this->scheduleType = $scheduleType;
$this->tableData = $tableData ?? [];
$this->mailSubject = $mailSubject ?? 'Despatch Pending Sale Invoice & STO Invoice as on Date';
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: $this->mailSubject,
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
$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') {
$firstRecord = InvoiceDataValidation::orderBy('document_date', 'asc')->first();
// $lastRecord = InvoiceDataValidation::orderBy('document_date', 'desc')->first();
$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);
// $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
$reportPeriod = "from: $startDate to $endDate\".<br><br>Please arrange to despatch the same immediately.";
$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 .= "from: $reportDate, $fromHour to $toHour. <br><br>Please arrange to despatch the same immediately.";
}
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 .= "from: $fromMinute to $toMinute. <br><br>Please arrange to despatch the same immediately.";
}
return new Content(
view: 'mail.invoice_data_report',
with: [
'company' => 'CRI Digital Manufacturing Solutions',
'greeting' => $greeting,
'tableData' => $this->tableData,
'wishes' => 'Thanks & Regards,<br>CRI Digital Manufacturing Solutions',
],
);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [];
}
}