Refactor SendInvoiceDataReport and InvoiceDataMail to dynamically set date range for daily reports and improve email content formatting

This commit is contained in:
dhanabalan
2025-11-06 09:51:19 +05:30
parent 7c1946d879
commit 570ce9473d
3 changed files with 41 additions and 15 deletions

View File

@@ -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++,