diff --git a/app/Config/Routes.php b/app/Config/Routes.php index c3f5219..589f6d3 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -501,6 +501,7 @@ $routes->get('opd_print/opd_Cont_print/(:num)', 'Opd::opd_cont_print/$1'); $routes->get('opd_print/opd_blank_print/(:num)', 'Opd::opd_blank_print/$1'); $routes->get('Opd_prescription/Prescription/(:num)', 'Opd_prescription::Prescription/$1'); +$routes->match(['get', 'post'], 'Opd_prescription/create_opd_queue/(:num)', 'Opd_prescription::create_opd_queue/$1'); $routes->get('Opd_prescription/opd_prescription_print/(:num)/(:num)', 'Opd_prescription::opd_prescription_print/$1/$2'); $routes->get('Opd_prescription/opd_prescription_print/(:num)/(:num)/(:num)', 'Opd_prescription::opd_prescription_print/$1/$2/$3'); $routes->post('Opd_prescription/opd_prescription_save', 'Opd_prescription::opd_prescription_save'); diff --git a/app/Controllers/Opd.php b/app/Controllers/Opd.php index 0bf08cf..47f7ab1 100644 --- a/app/Controllers/Opd.php +++ b/app/Controllers/Opd.php @@ -811,8 +811,17 @@ class Opd extends BaseController $sql = "select o.opd_id,o.opd_code,o.opd_no,o.opd_status, p.id,p.p_code,p.p_fname as P_name,p.p_rname, - o.opd_fee_desc,o.opd_fee_amount,o.payment_status, - if(o.payment_mode=4,'Credit to ECHS',if(o.payment_mode=1,'Cash','Pending')) as opd_type, + o.opd_fee_desc,o.opd_fee_amount,o.payment_status,o.opd_fee_type, + coalesce(o.running_opd,0) as running_opd, + o.confirm_pay_opd, + (case + when (coalesce(o.running_opd,0)=1 or o.opd_fee_type=3 or upper(coalesce(o.opd_fee_desc,'')) like '%RUNNING%') then 'Running' + when o.payment_mode=4 then 'Credit to ECHS' + when o.payment_status=1 and o.payment_mode=0 then 'No Cost' + when o.payment_mode=1 then 'Cash' + when o.payment_mode=2 then 'Bank Card' + else 'Pending' + end) as opd_type, if(pr.id is null, 0, 1) as has_prescription, if( coalesce(trim(pr.pulse),'')<>'' @@ -842,6 +851,15 @@ class Opd extends BaseController foreach ($allRows as $row) { $status = (int) ($row->opd_status ?? 0); $hasPrescription = (int) ($row->has_prescription ?? 0) === 1; + $paymentStatus = (int) ($row->payment_status ?? 0); + $runningOpd = (int) ($row->running_opd ?? 0) === 1; + $opdFeeType = (int) ($row->opd_fee_type ?? 0); + $opdFeeAmount = (float) ($row->opd_fee_amount ?? 0); + $opdFeeDesc = strtoupper(trim((string) ($row->opd_fee_desc ?? ''))); + $isRunningVisit = $runningOpd || $opdFeeType === 3 || str_contains($opdFeeDesc, 'RUNNING'); + $isConfirmedZeroAmount = $isRunningVisit && $opdFeeAmount <= 0; + $isConfirmedForQueue = $paymentStatus === 1 || $isConfirmedZeroAmount || !empty($row->confirm_pay_opd); + $row->is_confirmed_for_queue = $isConfirmedForQueue ? 1 : 0; if ($status === 1 && ! $hasPrescription) { $opdList0[] = $row; diff --git a/app/Controllers/Opd_prescription.php b/app/Controllers/Opd_prescription.php index 205e7c6..cb92e21 100644 --- a/app/Controllers/Opd_prescription.php +++ b/app/Controllers/Opd_prescription.php @@ -6021,6 +6021,24 @@ class Opd_prescription extends BaseController return (int) $this->db->insertID(); } + public function create_opd_queue(int $opdId) + { + if (! $this->canAccessPrescription()) { + return $this->response->setStatusCode(403)->setBody('Access denied'); + } + + if ($opdId <= 0) { + return $this->response->setBody('Invalid OPD ID'); + } + + $sessionId = $this->ensurePrescriptionSession($opdId, 0); + if ($sessionId <= 0) { + return $this->response->setBody('Unable to create queue'); + } + + return $this->response->setBody('Queue Created'); + } + private function isValidAbhaAddress(string $value): bool { $validation = service('validation'); diff --git a/app/Views/billing/opd_appointment_list.php b/app/Views/billing/opd_appointment_list.php index 0559a90..6f71ea3 100644 --- a/app/Views/billing/opd_appointment_list.php +++ b/app/Views/billing/opd_appointment_list.php @@ -120,6 +120,10 @@ } } + function reloadAppointmentList() { + load_form('/Opd/get_appointment_list/= esc((int) ($doc_id ?? 0)) ?>/= esc($opd_date ?? date('Y-m-d')) ?>', 'OPD Appointment List'); + } + function setVitalMessage(type, text) { var $msg = $('#vital_msg'); $msg.removeClass('text-muted text-success text-danger'); @@ -257,7 +261,35 @@ } $.post('/Opd/opd_status/' + opdId + '/' + opdStatus, {}, function() { - load_form('/Opd/get_appointment_list/= esc((int) ($doc_id ?? 0)) ?>/= esc($opd_date ?? date('Y-m-d')) ?>', 'OPD Appointment List'); + reloadAppointmentList(); + }); + }); + + $(document).off('click.opdcreatequeue', '.btn-opd-create-queue').on('click.opdcreatequeue', '.btn-opd-create-queue', function() { + var opdId = parseInt($(this).data('opdid') || '0', 10); + if (!opdId) { + return; + } + + var $btn = $(this); + $btn.prop('disabled', true).text('Queueing...'); + + $.post('/Opd_prescription/create_opd_queue/' + opdId, {}, function(resp) { + var message = (resp || '').toString().trim(); + if (message !== 'Queue Created') { + window.alert(message || 'Unable to create queue'); + $btn.prop('disabled', false).text('Queue'); + return; + } + + reloadAppointmentList(); + }).fail(function(xhr) { + var message = 'Unable to create queue'; + if (xhr && xhr.responseText) { + message = xhr.responseText; + } + window.alert(message); + $btn.prop('disabled', false).text('Queue'); }); }); diff --git a/app/Views/billing/opd_appointment_list_table.php b/app/Views/billing/opd_appointment_list_table.php index 2e7d87e..fe9f7af 100644 --- a/app/Views/billing/opd_appointment_list_table.php +++ b/app/Views/billing/opd_appointment_list_table.php @@ -30,23 +30,38 @@ if ($authUser) {