diff --git a/app/Controllers/Medical.php b/app/Controllers/Medical.php index a07ea29..24f666b 100644 --- a/app/Controllers/Medical.php +++ b/app/Controllers/Medical.php @@ -15979,11 +15979,15 @@ class Medical extends BaseController $shelf = trim((string)($this->request->getGet('shelf') ?? '')); $q = trim((string)($this->request->getGet('q') ?? '')); + if ($rack === '' && $shelf === '' && $q === '') { + return $this->response->setJSON(['status' => 1, 'items' => []]); + } + $builder = $this->db->table('purchase_invoice_item p'); $builder->select(' p.id AS batch_id, p.item_code, - m.item_name, + COALESCE(NULLIF(m.item_name, ""), p.Item_name, "Medicine") AS item_name, m.formulation, p.packing, p.batch_no, @@ -15994,11 +15998,15 @@ class Medical extends BaseController p.selling_unit_rate, IFNULL(NULLIF(p.rack_no, ""), m.rack_no) AS rack_no, IFNULL(NULLIF(p.shelf_no, ""), m.shelf_no) AS shelf_no, - (p.total_unit - p.total_sale_unit + p.total_return_unit - p.total_lost_unit) AS system_qty + (IFNULL(p.total_unit, 0) - IFNULL(p.total_sale_unit, 0) + IFNULL(p.total_return_unit, 0) - IFNULL(p.total_lost_unit, 0)) AS system_qty ', false); - $builder->join('med_product_master m', 'm.id = p.item_code'); + $builder->join('med_product_master m', 'm.id = p.item_code', 'left'); $builder->where('p.item_code >', 0); + if ($this->db->fieldExists('remove_item', 'purchase_invoice_item')) { + $builder->where('p.remove_item', 0); + } + if ($rack !== '') { $builder->groupStart(); $builder->where('p.rack_no', $rack); @@ -16016,7 +16024,18 @@ class Medical extends BaseController if ($q !== '') { $builder->groupStart(); $builder->like('m.item_name', $q); + $builder->orLike('p.Item_name', $q); $builder->orLike('p.batch_no', $q); + if ($this->db->fieldExists('genericname', 'med_product_master')) { + $builder->orLike('m.genericname', $q); + } + if (is_numeric($q)) { + $builder->orWhere('p.item_code', (int)$q); + $builder->orWhere('p.id', (int)$q); + } + if ($this->db->fieldExists('barcode', 'purchase_invoice_item')) { + $builder->orLike('p.barcode', $q); + } $builder->groupEnd(); } diff --git a/app/Views/medical/mobile_store.php b/app/Views/medical/mobile_store.php index 417963e..cf518e5 100644 --- a/app/Views/medical/mobile_store.php +++ b/app/Views/medical/mobile_store.php @@ -337,19 +337,24 @@
- + +
- +
- - +
@@ -360,7 +365,7 @@
- Select a rack or click Load to start shelf counting. + Select a rack or type medicine/batch name to start shelf counting.
@@ -384,13 +389,6 @@ - - - @@ -899,13 +897,81 @@ } loadRacksDatalist(); + function clearAuditSearch() { + jQuery('#audit_search_q').val('').focus(); + jQuery('#btn_clear_audit_q').hide(); + loadAuditItems(); + } + + function clearAuditRack() { + jQuery('#audit_rack_input').val(''); + jQuery('#audit_shelf_input').val(''); + loadAuditItems(); + } + + var auditSearchTimer = null; + jQuery('#audit_search_q').on('input', function() { + clearTimeout(auditSearchTimer); + var q = jQuery(this).val().trim(); + if (q.length > 0) { + jQuery('#btn_clear_audit_q').show(); + } else { + jQuery('#btn_clear_audit_q').hide(); + } + + var rack = jQuery('#audit_rack_input').val().trim(); + var shelf = jQuery('#audit_shelf_input').val().trim(); + + if (q.length === 0 && rack === '' && shelf === '') { + jQuery('#audit_items_container').html( + '
' + + '' + + 'Select a rack or type medicine/batch name to start shelf counting.' + + '
' + ); + return; + } + + auditSearchTimer = setTimeout(loadAuditItems, 300); + }); + + jQuery('#audit_rack_input, #audit_shelf_input').on('change input', function() { + clearTimeout(auditSearchTimer); + auditSearchTimer = setTimeout(loadAuditItems, 350); + }); + + jQuery('#audit_search_q, #audit_rack_input, #audit_shelf_input').on('keydown', function(e) { + if (e.key === 'Enter') { + e.preventDefault(); + clearTimeout(auditSearchTimer); + loadAuditItems(); + } + }); + function loadAuditItems() { var rack = jQuery('#audit_rack_input').val().trim(); var shelf = jQuery('#audit_shelf_input').val().trim(); var q = jQuery('#audit_search_q').val().trim(); + if (q.length > 0) { + jQuery('#btn_clear_audit_q').show(); + } else { + jQuery('#btn_clear_audit_q').hide(); + } + var container = jQuery('#audit_items_container'); - container.html('
Loading shelf batches...
'); + + if (q === '' && rack === '' && shelf === '') { + container.html( + '
' + + '' + + 'Select a rack or type medicine/batch name to start shelf counting.' + + '
' + ); + return; + } + + container.html('
Searching shelf batches...
'); jQuery.ajax({ url: baseUrl + 'Medical/mobile_audit_items', @@ -914,7 +980,10 @@ dataType: 'json', success: function(res) { if (!res.items || res.items.length === 0) { - container.html('
No batches found in this rack / shelf.
'); + var notFoundMsg = q + ? ('No medicines or batches found matching "' + escapeHtml(q) + '"' + (rack ? ' in rack ' + escapeHtml(rack) : '') + '.') + : ('No batches found in rack "' + escapeHtml(rack) + '"' + (shelf ? ' / shelf ' + escapeHtml(shelf) : '') + '.'); + container.html('
' + notFoundMsg + '
'); return; }