From 561c0d9fc38a1f7f17b075676de5a24e9cb37c01 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Fri, 7 Aug 2026 15:23:57 +0530 Subject: [PATCH] Add package checkbox for IPD pharmacy bill inclusion --- app/Config/Routes.php | 1 + app/Controllers/Billing/Ipd.php | 62 +++++++++++++++++++ app/Views/billing/ipd/panel_package.php | 81 ++++++++++++++++++++++++- 3 files changed, 142 insertions(+), 2 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index cd2c667..be384ea 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -459,6 +459,7 @@ $routes->group('billing', function($routes) { $routes->post('ipd/nursing-charge/delete/(:num)/(:num)', 'Billing\\Ipd::deleteNursingCharge/$1/$2'); $routes->post('ipd/charge/package/(:num)', 'Billing\\Ipd::updateIpdChargePackage/$1'); $routes->post('ipd/package/add/(:num)', 'Billing\\Ipd::addIpdPackage/$1'); + $routes->post('ipd/medical-bill/credit-type/(:num)', 'Billing\\Ipd::updateMedicalBillCreditType/$1'); $routes->get('ipd/panel/(:num)/ayushman/search', 'Billing\Ipd::searchAyushmanPackages/$1'); $routes->post('ipd/panel/(:num)/ayushman/map/(:num)', 'Billing\Ipd::saveAyushmanPackageMapping/$1/$2'); $routes->post('ipd/panel/(:num)/ayushman/checklist', 'Billing\Ipd::saveAyushmanChecklist/$1'); diff --git a/app/Controllers/Billing/Ipd.php b/app/Controllers/Billing/Ipd.php index 8e6e6fb..67a705c 100644 --- a/app/Controllers/Billing/Ipd.php +++ b/app/Controllers/Billing/Ipd.php @@ -517,6 +517,7 @@ class Ipd extends BaseController if ($tab === 'package') { $panelData['ipd_packages'] = $this->ipdModel->getIpdPackages($ipdId); + $panelData['medical_bills'] = $this->ipdModel->getMedicalBills($ipdId); $caseMeta = $this->ipdModel->getIpdCaseMeta($ipdId); $insCompId = (int) ($caseMeta['insurance_id'] ?? 0); if ($insCompId <= 0) { @@ -1975,6 +1976,67 @@ class Ipd extends BaseController return $this->response->setJSON(['ok' => $result === 1]); } + public function updateMedicalBillCreditType(int $invoiceId) + { + $permission = $this->requireAnyPermission([ + 'billing.access', + 'billing.ipd.invoice', + ]); + if ($permission) { + return $permission; + } + + if (! $this->request->isAJAX()) { + return $this->response->setStatusCode(400)->setJSON(['ok' => false, 'error' => 'Invalid request']); + } + + if ($invoiceId <= 0 || ! $this->db->tableExists('invoice_med_master')) { + return $this->response->setStatusCode(404)->setJSON(['ok' => false, 'error' => 'Medical bill not found']); + } + + $fields = $this->db->getFieldNames('invoice_med_master') ?? []; + if (! in_array('ipd_credit_type', $fields, true)) { + return $this->response->setStatusCode(422)->setJSON(['ok' => false, 'error' => 'Medical bill credit type column not available']); + } + + $invoice = $this->db->table('invoice_med_master') + ->select('id,ipd_id') + ->where('id', $invoiceId) + ->get(1) + ->getRowArray(); + + if (empty($invoice)) { + return $this->response->setStatusCode(404)->setJSON(['ok' => false, 'error' => 'Medical bill not found']); + } + + $creditType = (int) ($this->request->getPost('ipd_credit_type') ?? 0) === 1 ? 1 : 0; + $update = [ + 'ipd_credit_type' => $creditType, + ]; + + if (in_array('ipd_credit', $fields, true)) { + $update['ipd_credit'] = 1; + } + + if (in_array('ipd_credit_type_update', $fields, true)) { + $user = function_exists('auth') ? auth()->user() : null; + $userId = (int) ($user->id ?? 0); + $userName = (string) ($user->username ?? $user->email ?? 'user'); + $update['ipd_credit_type_update'] = $userName . '[' . $userId . '] D:' . date('d-m-Y h:i:s'); + } + + $this->db->table('invoice_med_master') + ->where('id', $invoiceId) + ->update($update); + + return $this->response->setJSON([ + 'ok' => true, + 'invoice_id' => $invoiceId, + 'ipd_id' => (int) ($invoice['ipd_id'] ?? 0), + 'ipd_credit_type' => $creditType, + ]); + } + public function loadPaymentModal(int $ipdId) { $permission = $this->requireAnyPermission([ diff --git a/app/Views/billing/ipd/panel_package.php b/app/Views/billing/ipd/panel_package.php index 50e3ffa..d8df374 100644 --- a/app/Views/billing/ipd/panel_package.php +++ b/app/Views/billing/ipd/panel_package.php @@ -129,7 +129,7 @@ $ayushmanChecklistItems = $ayushman_checklist_items ?? [];
- +
@@ -161,7 +161,7 @@ $ayushmanChecklistItems = $ayushman_checklist_items ?? [];
- +
@@ -321,6 +321,63 @@ $ayushmanChecklistItems = $ayushman_checklist_items ?? [];
+
+
+ Pharmacy Bills Package Mapping + Unchecked = In Package, Checked = Include in Bill +
+
+
+ + + + + + + + + + + + + + + ipd_credit_type ?? 1) === 1 ? 'checked' : ''; ?> + + + + + + + + + + + + + + +
#Invoice CodeDateAmountInclude in Bill
+ inv_med_code ?? $medicalBill->id ?? '') ?> + payment_status ?? 0) > 0) : ?> + Paid + + Pending + + inv_date ?? '')) ?>net_amount ?? 0), 2)) ?> +
+ + /> +
+
No pharmacy bills found for this IPD.
+
+
+
+