diff --git a/app/Controllers/Opd.php b/app/Controllers/Opd.php index e068c04..0d94725 100644 --- a/app/Controllers/Opd.php +++ b/app/Controllers/Opd.php @@ -1474,6 +1474,7 @@ class Opd extends BaseController $feeId = (int) $this->request->getPost('fee_id'); $pid = (int) $this->request->getPost('pid'); $appointmentDate = (string) $this->request->getPost('datepicker_appointment'); + $appointmentTime = (string) $this->request->getPost('appointment_time'); $abhaAddress = trim((string) $this->request->getPost('abha_address')); if ($docId <= 0 || $feeId <= 0 || $pid <= 0 || $appointmentDate === '') { @@ -1528,6 +1529,9 @@ class Opd extends BaseController $userId = $user->id ?? ''; $userNameInfo = $userLabel . ' [' . date('d-m-Y H:i:s') . '] ' . $userId; + // Combine appointment date and time into datetime + $appointmentDateTime = str_to_MysqlDateTime($appointmentDate, $appointmentTime); + $insert = [ 'p_id' => $pid, 'P_name' => strtoupper((string) $personInfo[0]->p_fname), @@ -1539,7 +1543,7 @@ class Opd extends BaseController 'opd_fee_desc' => $docFee[0]->doc_fee_desc, 'doc_name' => $docInfo[0]->p_fname, 'opd_fee_type' => $docFee[0]->doc_fee_type, - 'apointment_date' => str_to_MysqlDate($appointmentDate), + 'apointment_date' => $appointmentDateTime, 'doc_spec' => $docInfo[0]->SpecName, 'prepared_by' => $userNameInfo, ]; @@ -2382,7 +2386,21 @@ class Opd extends BaseController $lastVisitText = 'Last Visit : ' . $lastVisitDate; } - $bookTime = (string) ($opd->apointment_date ?? ''); + $bookTime = ''; + if (!empty($opd->apointment_date)) { + $dateTime = $opd->apointment_date; + // Format datetime to "dd/mm/yyyy HH:MM" format + if (preg_match('/^\d{4}-\d{2}-\d{2}/', $dateTime)) { + try { + $dt = new \DateTime($dateTime); + $bookTime = $dt->format('d/m/Y H:i'); + } catch (\Exception $e) { + $bookTime = (string) $dateTime; + } + } else { + $bookTime = (string) $dateTime; + } + } $rxMeds = is_array($data['rx_medicines'] ?? null) ? $data['rx_medicines'] : []; diff --git a/app/Controllers/Opdcase.php b/app/Controllers/Opdcase.php index d7662e2..043f7f6 100644 --- a/app/Controllers/Opdcase.php +++ b/app/Controllers/Opdcase.php @@ -111,6 +111,7 @@ class Opdcase extends BaseController $pid = (int) $this->request->getPost('pid'); $insuranceId = (int) $this->request->getPost('insurance_id'); $appointmentDate = (string) $this->request->getPost('datepicker_appointment'); + $appointmentTime = (string) $this->request->getPost('appointment_time'); if ($docId <= 0 || $feeId <= 0 || $pid <= 0 || $insuranceId <= 0 || $appointmentDate === '') { return $this->response->setJSON([ @@ -158,6 +159,9 @@ class Opdcase extends BaseController $opdFeeAmount = $insurance[0]->opd_fee ?? 0; $opdFeeDesc = $insurance[0]->opd_desc ?? ''; + // Combine appointment date and time into datetime + $appointmentDateTime = str_to_MysqlDateTime($appointmentDate, $appointmentTime); + $insert = [ 'p_id' => $pid, 'P_name' => strtoupper((string) $personInfo[0]->p_fname), @@ -169,7 +173,7 @@ class Opdcase extends BaseController 'opd_fee_desc' => $opdFeeDesc, 'doc_name' => $docInfo[0]->p_fname, 'doc_spec' => $docInfo[0]->SpecName, - 'apointment_date' => str_to_MysqlDate($appointmentDate), + 'apointment_date' => $appointmentDateTime, 'opd_fee_type' => '1', 'prepared_by' => $userNameInfo, ]; diff --git a/app/Database/Migrations/2026-04-28-000103_ChangeOpdAppointmentDateToDATETIME.php b/app/Database/Migrations/2026-04-28-000103_ChangeOpdAppointmentDateToDATETIME.php new file mode 100644 index 0000000..9836f11 --- /dev/null +++ b/app/Database/Migrations/2026-04-28-000103_ChangeOpdAppointmentDateToDATETIME.php @@ -0,0 +1,42 @@ +db->disableForeignKeyChecks(); + + $this->forge->modifyColumn('opd_master', [ + 'apointment_date' => [ + 'type' => 'DATETIME', + 'null' => true, + 'default' => null, + 'comment' => 'Appointment date and time' + ] + ]); + + $this->db->enableForeignKeyChecks(); + } + + public function down() + { + // Revert the column back to DATE type + $this->db->disableForeignKeyChecks(); + + $this->forge->modifyColumn('opd_master', [ + 'apointment_date' => [ + 'type' => 'DATE', + 'null' => true, + 'default' => null, + 'comment' => 'Appointment date' + ] + ]); + + $this->db->enableForeignKeyChecks(); + } +} diff --git a/app/Helpers/common_helper.php b/app/Helpers/common_helper.php index 6335994..6807647 100644 --- a/app/Helpers/common_helper.php +++ b/app/Helpers/common_helper.php @@ -18,6 +18,27 @@ function str_to_MysqlDate(string $strDate): string return '1900-01-01'; } +function str_to_MysqlDateTime(string $strDate, string $strTime = ''): string +{ + $mysqlDate = str_to_MysqlDate($strDate); + + // Validate and format time (HH:MM) + $strTime = trim($strTime); + if ($strTime === '') { + $strTime = '00:00:00'; + } elseif (preg_match('/^\d{2}:\d{2}$/', $strTime) === 1) { + $strTime = $strTime . ':00'; + } elseif (!preg_match('/^\d{2}:\d{2}:\d{2}$/', $strTime)) { + $strTime = '00:00:00'; + } + + if ($mysqlDate === '1900-01-01') { + return '1900-01-01 00:00:00'; + } + + return $mysqlDate . ' ' . $strTime; +} + function MysqlDate_to_str(?string $strDate): string { if ($strDate === null || $strDate === '') { diff --git a/app/Views/billing/opd_app_insurance_V.php b/app/Views/billing/opd_app_insurance_V.php index efca647..900be94 100644 --- a/app/Views/billing/opd_app_insurance_V.php +++ b/app/Views/billing/opd_app_insurance_V.php @@ -29,6 +29,11 @@ +