From b59ea856595a0e2fdfc74a321882ac2b3b155a86 Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Fri, 7 Aug 2026 10:22:44 +0530 Subject: [PATCH] FIX_REPORT_DATES --- app/Libraries/AbhiMisReportService.php | 4 ++-- app/Libraries/IciciMisReportService.php | 10 ++++++---- app/Libraries/MediAssistMisReportService.php | 7 ++++--- app/Libraries/VidalMisReportService.php | 6 ++---- app/Models/ClaimDumpFileModel.php | 20 +++++++++++++++----- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/app/Libraries/AbhiMisReportService.php b/app/Libraries/AbhiMisReportService.php index bddac2c2..fa2da8a2 100644 --- a/app/Libraries/AbhiMisReportService.php +++ b/app/Libraries/AbhiMisReportService.php @@ -82,8 +82,8 @@ class AbhiMisReportService $data = [ 'meta' => [ 'policy_id' => $policyId, - 'last_refresh' => $this->dumpFileModel->getGeneratedAtForPolicy($policyId), - 'generated_at' => date('d-M-Y'), + 'last_refresh' => $this->dumpFileModel->getGeneratedAtForPolicy($policyId, 'd-M-Y') ?: date('d-M-Y'), + 'generated_at' => $this->dumpFileModel->getGeneratedAtForPolicy($policyId, 'd-M-Y') ?: date('d-M-Y'), 'quote_type' => 'IPD + OPD', 'client_name' => trim((string) ($policy['client_name'] ?? '')), 'tpa_name' => trim((string) ($policy['tpa_name'] ?? 'Aditya Birla Health Insurance Co. Limited')), diff --git a/app/Libraries/IciciMisReportService.php b/app/Libraries/IciciMisReportService.php index 5cbf11ac..ab7f5174 100644 --- a/app/Libraries/IciciMisReportService.php +++ b/app/Libraries/IciciMisReportService.php @@ -125,15 +125,17 @@ class IciciMisReportService $startDate = $this->formatDate($policy['policy_start_date'] ?? $exposure['policy_start_date'] ?? null); $endDate = $this->formatDate($policy['policy_end_date'] ?? $exposure['policy_end_date'] ?? null); - $uploadAt = $this->dumpFileModel->getGeneratedAtForPolicy($policyId) ?: date('d/m/Y g:i:s A'); + $dumpTs = $this->dumpFileModel->getLatestClaimDumpTimestamp($policyId) ?: time(); + $uploadAt = date('d/m/Y g:i:s A', $dumpTs); + $reportMonth = date('F-Y', $dumpTs); $data = [ 'meta' => [ 'policy_id' => $policyId, 'client_name' => trim((string) ($policy['client_name'] ?? '')), - 'report_month' => date('F-Y'), + 'report_month' => $reportMonth, 'data_upload' => $uploadAt, - 'generated_at' => date('d-M-Y'), + 'generated_at' => date('d-M-Y', $dumpTs), 'tpa_name' => trim((string) ($policy['tpa_name'] ?? 'ICICI Lombard')), ], 'header' => [ @@ -153,7 +155,7 @@ class IciciMisReportService 'claim_cost' => $claimCost, 'gross_incurred_cost' => $grossInc, 'loss_ratio' => $lossRatio, - 'as_on' => date('m/d/Y'), + 'as_on' => date('m/d/Y', $dumpTs), ], 'claims_summary' => $claimsSummary, 'iltc_summary' => $iltcSummary, diff --git a/app/Libraries/MediAssistMisReportService.php b/app/Libraries/MediAssistMisReportService.php index 72466b71..b6d0f2e1 100644 --- a/app/Libraries/MediAssistMisReportService.php +++ b/app/Libraries/MediAssistMisReportService.php @@ -127,8 +127,9 @@ class MediAssistMisReportService $policyEndRaw = $policy['policy_end_date'] ?? $exposure['policy_end_date'] ?? null; $startDate = $this->formatDateLong($policyStartRaw); $endDate = $this->formatDateLong($policyEndRaw); - $reportAsOn = $this->formatDateShort($this->dumpFileModel->getGeneratedAtForPolicy($policyId) ?: date('Y-m-d')); - $uploadAt = $this->dumpFileModel->getGeneratedAtForPolicy($policyId) ?: date('d/m/Y g:i:s A'); + $dumpTs = $this->dumpFileModel->getLatestClaimDumpTimestamp($policyId) ?: time(); + $reportAsOn = date('d M Y', $dumpTs); + $uploadAt = date('d/m/Y g:i:s A', $dumpTs); $runDays = $this->policyRunDays($policyStartRaw, $policyEndRaw); $statusAgg = $this->aggregateStatus($dumpRows); @@ -161,7 +162,7 @@ class MediAssistMisReportService 'report_as_on' => $reportAsOn, 'units' => 'Actuals', 'version' => self::VERSION, - 'generated_at' => date('d-M-Y'), + 'generated_at' => date('d-M-Y', $dumpTs), 'generated_by' => '', 'upload_at' => $uploadAt, ], diff --git a/app/Libraries/VidalMisReportService.php b/app/Libraries/VidalMisReportService.php index 50a96b89..c9ab43bf 100644 --- a/app/Libraries/VidalMisReportService.php +++ b/app/Libraries/VidalMisReportService.php @@ -182,10 +182,8 @@ class VidalMisReportService ?? $exposure['policy_end_date'] ?? ($firstDump['policy_end_date'] ?? null); - $generatedAt = $this->dumpFileModel->getGeneratedAtForPolicy($policyId); - $generatedAtDisplay = $generatedAt - ? $this->formatDateTimeDisplay($generatedAt) - : date('d-M-Y H:i'); + $generatedAtTs = $this->dumpFileModel->getLatestClaimDumpTimestamp($policyId) ?: time(); + $generatedAtDisplay = date('d-M-Y', $generatedAtTs); $corporateName = trim((string) ( $firstDump['corporate_name'] diff --git a/app/Models/ClaimDumpFileModel.php b/app/Models/ClaimDumpFileModel.php index c13d2f9f..667442ca 100644 --- a/app/Models/ClaimDumpFileModel.php +++ b/app/Models/ClaimDumpFileModel.php @@ -58,10 +58,9 @@ class ClaimDumpFileModel extends Model } /** - * Latest claim_dump_date for a policy, formatted as dd-mm-yyyy. - * Returns null when no dump file has a claim_dump_date. + * Latest claim_dump_date timestamp for a policy (active rows only). */ - public function getGeneratedAtForPolicy(int $policyId): ?string + public function getLatestClaimDumpTimestamp(int $policyId): ?int { if ($policyId <= 0) { return null; @@ -82,10 +81,21 @@ class ClaimDumpFileModel extends Model } $ts = strtotime($raw); - if ($ts === false) { + + return $ts === false ? null : $ts; + } + + /** + * Latest claim_dump_date for a policy, formatted. + * Returns null when no dump file has a claim_dump_date. + */ + public function getGeneratedAtForPolicy(int $policyId, string $format = 'd-m-Y'): ?string + { + $ts = $this->getLatestClaimDumpTimestamp($policyId); + if ($ts === null) { return null; } - return date('d-m-Y', $ts); + return date($format, $ts); } }