diff --git a/app/Controllers/Opd.php b/app/Controllers/Opd.php index 0ea7603..c192c4c 100644 --- a/app/Controllers/Opd.php +++ b/app/Controllers/Opd.php @@ -2197,7 +2197,16 @@ class Opd extends BaseController $opdNo = (string) ($opd->opd_code ?? ''); $opdDate = (string) ($opd->str_apointment_date ?? ''); $expDate = trim((string) ($opd->opd_Exp_Date ?? '')); - $expDateText = $expDate !== '' ? ('Valid Upto : ' . esc($expDate)) : ''; + $isRunningOpdEntry = ((int) ($opd->running_opd ?? 0) === 1) + || ((int) ($opd->opd_fee_type ?? 0) === 3); + if ($isRunningOpdEntry && !empty($data['old_opd'][0] ?? null)) { + $oldExpDate = trim((string) ($data['old_opd'][0]->opd_Exp_Date ?? '')); + $oldStartDate = trim((string) ($data['old_opd'][0]->str_apointment_date ?? '')); + $expDateText = ($oldStartDate !== '' ? 'OPD Start Date : ' . esc($oldStartDate) . '
' : '') + . ($oldExpDate !== '' ? 'Valid Upto : ' . esc($oldExpDate) : ''); + } else { + $expDateText = $expDate !== '' ? ('Valid Upto : ' . esc($expDate)) : ''; + } $specName = trim((string) ($doctor->SpecName ?? $opd->doc_spec ?? '')); $doctorShortDescription = trim((string) ($doctor->doc_sign ?? $opd->doc_sign ?? '')); diff --git a/app/Models/OpdModel.php b/app/Models/OpdModel.php index 9851064..5ee72d6 100644 --- a/app/Models/OpdModel.php +++ b/app/Models/OpdModel.php @@ -66,7 +66,7 @@ class OpdModel $lastOpdRow = $this->db->table('opd_master') ->select('max(opd_id) as last_opd_id') - ->where('apointment_date >=', date('Y-m-d', strtotime('-4 days'))) + ->where('apointment_date >=', $this->resolveRunningLookupDate($docId)) ->where('apointment_date <=', date('Y-m-d')) ->where('running_opd', 0) ->where('opd_fee_type <>', 3) @@ -108,4 +108,15 @@ class OpdModel return $insertId; } + + private function resolveRunningLookupDate(int $docId): string + { + $docRow = $this->db->table('doctor_master') + ->select('opd_valid_no_days') + ->where('id', $docId) + ->get() + ->getRow(); + $validDays = max(4, (int) ($docRow->opd_valid_no_days ?? 5) - 1); + return date('Y-m-d', strtotime('-' . $validDays . ' days')); + } }