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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strtolower($scheduleType) == 'daily') {
|
// if (strtolower($scheduleType) == 'daily') {
|
||||||
$startDate = now()->subDay()->setTime(10, 0, 0);//8:00
|
// $startDate = now()->subDay()->setTime(10, 0, 0);//8:00
|
||||||
$endDate = now()->setTime(10, 0, 0);//8
|
// $endDate = now()->setTime(10, 0, 0);//8
|
||||||
} else {
|
// }
|
||||||
|
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);
|
$startDate = now()->setTime(8, 0, 0);
|
||||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||||
}
|
}
|
||||||
@@ -278,13 +294,14 @@ class SendInvoiceDataReport extends Command
|
|||||||
// }
|
// }
|
||||||
foreach ($pendingInvoices as $inv)
|
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)) {
|
$endDate = now()->copy()->subDay()->setTime(10, 0, 0);
|
||||||
$statusColor = 'status-pending-red';
|
|
||||||
} else {
|
//$hoursDiff = $documentDate->diffInHours($now);
|
||||||
$statusColor = 'status-pending-yellow';
|
|
||||||
}
|
$statusColor = $endDate <= $inv->document_date ? 'status-pending-yellow' : 'status-pending-red';
|
||||||
|
|
||||||
$tableData[] = [
|
$tableData[] = [
|
||||||
'no' => $no++,
|
'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"';
|
$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') {
|
||||||
$fromDate = (new DateTime('yesterday 10:00'))->format('d/m/Y H:i') . ':000';//08:00
|
$firstRecord = \App\Models\InvoiceDataValidation::orderBy('document_date', 'asc')->first();
|
||||||
$toDate = (new DateTime('today 09:59'))->format('d/m/Y H:i') . ':999';//07:59
|
//$lastRecord = \App\Models\InvoiceDataValidation::orderBy('document_date', 'desc')->first();
|
||||||
$reportPeriod = "from: $fromDate to $toDate. <br><br>Please arrange to despatch the same immediately.";
|
|
||||||
|
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;
|
$greeting .= $reportPeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,14 +45,14 @@
|
|||||||
color: #ef4444;
|
color: #ef4444;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
} */
|
} */
|
||||||
/* .status-pending-yellow {
|
.status-pending-yellow {
|
||||||
color: #eab308;
|
color: #eab308;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
.status-pending-red {
|
.status-pending-red {
|
||||||
color: #ef4444;
|
color: #ef4444;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
} */
|
}
|
||||||
.footer {
|
.footer {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
|
|||||||
Reference in New Issue
Block a user