fix(pharmacy): finalize product page panel toggle and GST selector behavior

This commit is contained in:
DevSoftTech Server 2026-05-26 13:07:46 +05:30
parent 032ff4f1ab
commit 298647b80b
3 changed files with 154 additions and 32 deletions

View File

@ -6850,6 +6850,11 @@ class Medical extends BaseController
$categories = $this->db->table('med_product_cat_master')->orderBy('med_cat_desc', 'ASC')->get()->getResult();
}
$gstRates = [];
if ($this->db->tableExists('med_gst_per')) {
$gstRates = $this->db->table('med_gst_per')->orderBy('gst_per', 'ASC')->get()->getResult();
}
$selectedCatIds = [];
if ($productId > 0 && $this->db->tableExists('med_product_cat_assign')) {
$catRows = $this->db->table('med_product_cat_assign')
@ -6865,6 +6870,7 @@ class Medical extends BaseController
'med_formulation' => $formulations,
'med_company' => $companies,
'med_product_cat_master' => $categories,
'med_gst_per' => $gstRates,
'selected_cat_ids' => $selectedCatIds,
]);
}

View File

@ -15,22 +15,23 @@
</div>
</form>
<div id="sub-main-pharmacy" class="mb-3" style="display:none;"></div>
<div id="searchresult" class="table-responsive">
<table id="product_report_list" class="table table-bordered table-striped table-sm align-middle" style="width:100%;">
<thead>
<tr>
<th>Prod. ID</th>
<th>Name</th>
<th>Formulation</th>
<th>Generic Name</th>
<th>Packing Type</th>
<th style="width:110px;">Action</th>
</tr>
</thead>
<tbody></tbody>
</table>
<div id="sub-main-pharmacy" class="mb-3">
<div id="drug-master-list-panel" class="table-responsive">
<table id="product_report_list" class="table table-bordered table-striped table-sm align-middle" style="width:100%;">
<thead>
<tr>
<th>Prod. ID</th>
<th>Name</th>
<th>Formulation</th>
<th>Generic Name</th>
<th>Packing Type</th>
<th style="width:110px;">Action</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<div id="drug-master-sub-panel" style="display:none;"></div>
</div>
</section>
@ -72,17 +73,26 @@
$form.off('submit').on('submit', function (event) {
event.preventDefault();
if (window.showDrugMasterListPanel) {
window.showDrugMasterListPanel();
}
dt.ajax.reload();
});
$('#btnResetSearch').off('click').on('click', function () {
$('#txtsearch').val('');
if (window.showDrugMasterListPanel) {
window.showDrugMasterListPanel();
}
dt.search('').ajax.reload();
});
$('#txtsearch').off('keypress').on('keypress', function (event) {
if (event.which === 13) {
event.preventDefault();
if (window.showDrugMasterListPanel) {
window.showDrugMasterListPanel();
}
dt.ajax.reload();
}
});
@ -98,20 +108,38 @@
})();
// Keep add/edit forms inside the Drug Master shell so the search form stays visible.
window.showDrugMasterListPanel = function () {
var $listPanel = $('#drug-master-list-panel');
var $subPanel = $('#drug-master-sub-panel');
if ($listPanel.length && $subPanel.length) {
$subPanel.hide();
$listPanel.show();
}
};
window.openDrugMasterSubView = function (url, title) {
var $sub = $('#sub-main-pharmacy');
if ($sub.length) {
$sub.show();
load_form_div(url, 'sub-main-pharmacy', title || 'Drug Master :Pharmacy');
var $root = $('#sub-main-pharmacy');
var $listPanel = $('#drug-master-list-panel');
var $subPanel = $('#drug-master-sub-panel');
if ($root.length && $subPanel.length) {
$listPanel.hide();
$subPanel.show();
load_form_div(url, 'drug-master-sub-panel', title || 'Drug Master :Pharmacy');
return;
}
load_form_div(url, 'medical-main', title || 'Drug Master :Pharmacy');
};
window.closeDrugMasterSubView = function () {
var $sub = $('#sub-main-pharmacy');
if ($sub.length) {
$sub.hide().empty();
var $root = $('#sub-main-pharmacy');
var $listPanel = $('#drug-master-list-panel');
var $subPanel = $('#drug-master-sub-panel');
if ($root.length && $subPanel.length) {
$subPanel.hide().empty();
$listPanel.show();
if (window.reloadDrugMasterList) {
window.reloadDrugMasterList();
}

View File

@ -22,6 +22,7 @@ $abdmDrugDisplay = (string) ($product->abdm_drug_display ?? '');
$abdmDrugGeneric = (string) ($product->abdm_drug_generic ?? '');
$abdmDrugPayloadJson = (string) ($product->abdm_drug_payload_json ?? '');
$abdmDrugLastSyncedAt = (string) ($product->abdm_drug_last_synced_at ?? '');
$gstRates = $med_gst_per ?? [];
$flag = static function ($v): string {
return ((int) $v === 1) ? 'checked' : '';
@ -119,11 +120,35 @@ $flag = static function ($v): string {
</div>
<div class="col-md-1">
<label class="form-label">CGST</label>
<input class="form-control" name="input_CGST" id="input_CGST" type="text" value="<?= esc($cgst) ?>">
<select class="form-select" name="input_CGST" id="input_CGST">
<?php if (! empty($gstRates)): ?>
<?php foreach ($gstRates as $rate): ?>
<?php $gstValue = trim((string) ($rate->gst_per ?? '0')); ?>
<?php if ($gstValue === '') { $gstValue = '0'; } ?>
<option value="<?= esc($gstValue) ?>" <?= ((float) $gstValue === (float) $cgst) ? 'selected' : '' ?>><?= esc($gstValue) ?></option>
<?php endforeach; ?>
<?php else: ?>
<?php foreach (['0', '2.5', '5', '6', '9', '12'] as $gstValue): ?>
<option value="<?= esc($gstValue) ?>" <?= ((float) $gstValue === (float) $cgst) ? 'selected' : '' ?>><?= esc($gstValue) ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
<div class="col-md-1">
<label class="form-label">SGST</label>
<input class="form-control" name="input_SGST" id="input_SGST" type="text" value="<?= esc($sgst) ?>">
<select class="form-select" name="input_SGST" id="input_SGST">
<?php if (! empty($gstRates)): ?>
<?php foreach ($gstRates as $rate): ?>
<?php $gstValue = trim((string) ($rate->gst_per ?? '0')); ?>
<?php if ($gstValue === '') { $gstValue = '0'; } ?>
<option value="<?= esc($gstValue) ?>" <?= ((float) $gstValue === (float) $sgst) ? 'selected' : '' ?>><?= esc($gstValue) ?></option>
<?php endforeach; ?>
<?php else: ?>
<?php foreach (['0', '2.5', '5', '6', '9', '12'] as $gstValue): ?>
<option value="<?= esc($gstValue) ?>" <?= ((float) $gstValue === (float) $sgst) ? 'selected' : '' ?>><?= esc($gstValue) ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
<div class="col-md-2">
@ -173,15 +198,40 @@ $flag = static function ($v): string {
<script>
window.openDrugMasterSubView = window.openDrugMasterSubView || function (url, title) {
var target = document.getElementById('sub-main-pharmacy') ? 'sub-main-pharmacy' : 'medical-main';
var listPanel = document.getElementById('drug-master-list-panel');
var subPanel = document.getElementById('drug-master-sub-panel');
var target = 'medical-main';
if (subPanel) {
if (listPanel) {
listPanel.style.display = 'none';
}
subPanel.style.display = '';
target = 'drug-master-sub-panel';
} else if (document.getElementById('sub-main-pharmacy')) {
target = 'sub-main-pharmacy';
}
load_form_div(url, target, title || 'Drug Master :Pharmacy');
};
window.closeDrugMasterSubView = window.closeDrugMasterSubView || function () {
var listPanel = document.getElementById('drug-master-list-panel');
var subPanel = document.getElementById('drug-master-sub-panel');
var sub = document.getElementById('sub-main-pharmacy');
if (subPanel && listPanel) {
subPanel.innerHTML = '';
subPanel.style.display = 'none';
listPanel.style.display = '';
if (typeof window.reloadDrugMasterList === 'function') {
window.reloadDrugMasterList();
}
return;
}
if (sub) {
sub.innerHTML = '';
sub.style.display = 'none';
if (typeof window.reloadDrugMasterList === 'function') {
window.reloadDrugMasterList();
}
@ -220,6 +270,32 @@ window.closeDrugMasterSubView = window.closeDrugMasterSubView || function () {
$('#product-msg').html(html || '');
}
function setTaxSelectValue(selector, value) {
var $el = $(selector);
if (!$el.length) {
return;
}
var normalized = (value === null || value === undefined) ? '' : String(value).trim();
if (normalized === '') {
return;
}
var exists = false;
$el.find('option').each(function () {
if (String($(this).val()) === normalized) {
exists = true;
return false;
}
return true;
});
if (!exists) {
$el.append($('<option>', { value: normalized, text: normalized }));
}
$el.val(normalized).trigger('change');
}
function showSelectedDrugSummary() {
var id = $('#abdm_drug_identifier').val() || '';
var label = $('#abdm_drug_display').val() || '';
@ -853,18 +929,18 @@ window.closeDrugMasterSubView = window.closeDrugMasterSubView || function () {
}
if (cgstVal !== null) {
$('#input_CGST').val(cgstVal.toFixed(2).replace(/\.00$/, ''));
setTaxSelectValue('#input_CGST', cgstVal.toFixed(2).replace(/\.00$/, ''));
}
if (sgstVal !== null) {
$('#input_SGST').val(sgstVal.toFixed(2).replace(/\.00$/, ''));
setTaxSelectValue('#input_SGST', sgstVal.toFixed(2).replace(/\.00$/, ''));
}
if (gstTotal !== null && (cgstVal === null || sgstVal === null)) {
var half = (gstTotal / 2);
if (cgstVal === null) {
$('#input_CGST').val(half.toFixed(2).replace(/\.00$/, ''));
setTaxSelectValue('#input_CGST', half.toFixed(2).replace(/\.00$/, ''));
}
if (sgstVal === null) {
$('#input_SGST').val(half.toFixed(2).replace(/\.00$/, ''));
setTaxSelectValue('#input_SGST', half.toFixed(2).replace(/\.00$/, ''));
}
}
@ -1161,13 +1237,25 @@ window.closeDrugMasterSubView = window.closeDrugMasterSubView || function () {
showSelectedDrugSummary();
$('#btn_update_stock').off('click').on('click', function () {
$.post('<?= base_url('product_master/product_master_update') ?>/' + ($('#product_id').val() || '0'), $('#product-form').serialize(), function (data) {
var currentProductId = parseInt($('#product_id').val() || '0', 10) || 0;
var isAddFlow = currentProductId <= 0;
$.post('<?= base_url('product_master/product_master_update') ?>/' + (currentProductId || '0'), $('#product-form').serialize(), function (data) {
if (!data || typeof data !== 'object') {
showMsg('<div class="alert alert-danger mb-0">Unexpected response.</div>');
return;
}
showMsg(data.show_text || '');
if ((data.is_update_stock || 0) > 0) {
if (isAddFlow) {
if (window.jQuery && $('#txtsearch').length) {
$('#txtsearch').val($('#input_item_name').val() || '');
}
if (typeof window.closeDrugMasterSubView === 'function') {
window.closeDrugMasterSubView();
}
return;
}
openDrugMasterSubView('<?= base_url('Product_master/Product_edit') ?>/' + data.is_update_stock, 'Drug Master : Edit :Pharmacy');
}
}, 'json').fail(function () {