Refactor SendInvoiceDataReport and InvoiceDataMail to dynamically set date range for daily reports and improve email content formatting
This commit is contained in:
@@ -79,10 +79,26 @@ class SendInvoiceDataReport extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
if (strtolower($scheduleType) == 'daily') {
|
||||
$startDate = now()->subDay()->setTime(10, 0, 0);//8:00
|
||||
$endDate = now()->setTime(10, 0, 0);//8
|
||||
} else {
|
||||
// if (strtolower($scheduleType) == 'daily') {
|
||||
// $startDate = now()->subDay()->setTime(10, 0, 0);//8:00
|
||||
// $endDate = now()->setTime(10, 0, 0);//8
|
||||
// }
|
||||
if (strtolower($scheduleType) == 'daily')
|
||||
{
|
||||
$firstRecord = \App\Models\InvoiceDataValidation::orderBy('document_date', 'asc')->first();
|
||||
$lastRecord = \App\Models\InvoiceDataValidation::orderBy('document_date', 'desc')->first();
|
||||
|
||||
if ($firstRecord && $lastRecord) {
|
||||
$startDate = \Carbon\Carbon::parse($firstRecord->document_date)->startOfDay();
|
||||
$endDate = \Carbon\Carbon::parse($lastRecord->document_date)->endOfDay();
|
||||
}
|
||||
else
|
||||
{
|
||||
$startDate = now()->startOfDay();
|
||||
$endDate = now()->endOfDay();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
}
|
||||
@@ -278,13 +294,14 @@ class SendInvoiceDataReport extends Command
|
||||
// }
|
||||
foreach ($pendingInvoices as $inv)
|
||||
{
|
||||
$documentDate = \Carbon\Carbon::parse($inv->document_date);
|
||||
// $documentDate = \Carbon\Carbon::parse($inv->document_date);
|
||||
// $now = \Carbon\Carbon::now();
|
||||
|
||||
if ($documentDate->lt($startDate)) {
|
||||
$statusColor = 'status-pending-red';
|
||||
} else {
|
||||
$statusColor = 'status-pending-yellow';
|
||||
}
|
||||
$endDate = now()->copy()->subDay()->setTime(10, 0, 0);
|
||||
|
||||
//$hoursDiff = $documentDate->diffInHours($now);
|
||||
|
||||
$statusColor = $endDate <= $inv->document_date ? 'status-pending-yellow' : 'status-pending-red';
|
||||
|
||||
$tableData[] = [
|
||||
'no' => $no++,
|
||||
|
||||
@@ -44,9 +44,18 @@ 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"';
|
||||
|
||||
if ($this->scheduleType == 'Daily') {
|
||||
$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: $fromDate to $toDate. <br><br>Please arrange to despatch the same immediately.";
|
||||
$firstRecord = \App\Models\InvoiceDataValidation::orderBy('document_date', 'asc')->first();
|
||||
//$lastRecord = \App\Models\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 = 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user