diff --git a/app/Console/Commands/SendInvoiceDataReport.php b/app/Console/Commands/SendInvoiceDataReport.php index ef07436..f82b58f 100644 --- a/app/Console/Commands/SendInvoiceDataReport.php +++ b/app/Console/Commands/SendInvoiceDataReport.php @@ -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++, diff --git a/app/Mail/InvoiceDataMail.php b/app/Mail/InvoiceDataMail.php index e57edbc..e92e140 100644 --- a/app/Mail/InvoiceDataMail.php +++ b/app/Mail/InvoiceDataMail.php @@ -44,9 +44,18 @@ class InvoiceDataMail extends Mailable $greeting = 'Dear Sir/Madam,

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.

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\".

Please arrange to despatch the same immediately."; $greeting .= $reportPeriod; } diff --git a/resources/views/mail/invoice_data_report.blade.php b/resources/views/mail/invoice_data_report.blade.php index 81cf258..c351957 100644 --- a/resources/views/mail/invoice_data_report.blade.php +++ b/resources/views/mail/invoice_data_report.blade.php @@ -45,14 +45,14 @@ color: #ef4444; font-weight: bold; } */ - /* .status-pending-yellow { + .status-pending-yellow { color: #eab308; font-weight: bold; } .status-pending-red { color: #ef4444; font-weight: bold; - } */ + } .footer { text-align: center; font-size: 13px;