Add refer doctor filter to diagnosis report
This commit is contained in:
parent
bb066399f9
commit
b4ae081d28
|
|
@ -698,8 +698,16 @@ class Report extends BaseController
|
|||
->get()
|
||||
->getResult();
|
||||
|
||||
$referDoctors = $this->db->table('doctor_master')
|
||||
->select('id, p_fname')
|
||||
->where('active', 1)
|
||||
->orderBy('p_fname', 'ASC')
|
||||
->get()
|
||||
->getResult();
|
||||
|
||||
return view('report/diagnosis_report', [
|
||||
'item_types' => $itemTypes,
|
||||
'refer_doctors' => $referDoctors,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -870,9 +878,27 @@ class Report extends BaseController
|
|||
int $output = 0
|
||||
) {
|
||||
[$minRange, $maxRange] = $this->parseDateRange($dateRange);
|
||||
$referDoctorId = (int) ($this->request->getGet('refer_doctor_id') ?? 0);
|
||||
$referDoctorLabel = 'All Refer Doctors';
|
||||
|
||||
$netAmountExpr = "ROUND(IF(m.invoice_status=1, (t.item_amount - (t.item_amount * m.discount_amount / NULLIF(m.total_amount, 0))), 0), 2)";
|
||||
|
||||
$invoiceFields = $this->db->getFieldNames('invoice_master') ?? [];
|
||||
$referByIdCol = $this->resolveExistingColumn($invoiceFields, ['refer_by_id', 'doctor_id', 'doc_id']);
|
||||
$referByNameCol = $this->resolveExistingColumn($invoiceFields, ['refer_by_other', 'doc_name', 'doctor_name']);
|
||||
|
||||
if ($referDoctorId > 0 && $this->db->tableExists('doctor_master')) {
|
||||
$doctorRow = $this->db->table('doctor_master')
|
||||
->select('p_fname')
|
||||
->where('id', $referDoctorId)
|
||||
->get()
|
||||
->getRow();
|
||||
|
||||
if ($doctorRow !== null && trim((string) ($doctorRow->p_fname ?? '')) !== '') {
|
||||
$referDoctorLabel = (string) $doctorRow->p_fname;
|
||||
}
|
||||
}
|
||||
|
||||
$builder = $this->db->table('invoice_master m');
|
||||
$builder->select('y.group_desc, t.item_name')
|
||||
->select('COUNT(t.id) as no_test', false)
|
||||
|
|
@ -890,6 +916,14 @@ class Report extends BaseController
|
|||
->where('m.inv_date >=', $minRange)
|
||||
->where('m.inv_date <=', $maxRange);
|
||||
|
||||
if ($referDoctorId > 0) {
|
||||
if ($referByIdCol !== null) {
|
||||
$builder->where('m.' . $referByIdCol, $referDoctorId);
|
||||
} elseif ($referByNameCol !== null && $referDoctorLabel !== 'All Refer Doctors') {
|
||||
$builder->where('m.' . $referByNameCol, $referDoctorLabel);
|
||||
}
|
||||
}
|
||||
|
||||
// Invoice type filter
|
||||
$invoiceTypeInt = (int) $invoiceType;
|
||||
if ($invoiceTypeInt === 1) {
|
||||
|
|
@ -922,6 +956,7 @@ class Report extends BaseController
|
|||
'min_range' => $minRange,
|
||||
'max_range' => $maxRange,
|
||||
'invoice_type_label' => $invoiceTypeLabel,
|
||||
'refer_doctor_label' => $referDoctorLabel,
|
||||
];
|
||||
|
||||
$content = view('report/diagnosis_report_table', $data);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
$itemTypes = $item_types ?? [];
|
||||
$referDoctors = $refer_doctors ?? [];
|
||||
?>
|
||||
<section class="content">
|
||||
<div class="card">
|
||||
|
|
@ -15,7 +16,7 @@ $itemTypes = $item_types ?? [];
|
|||
<input type="datetime-local" class="form-control" id="report_end">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">Invoice Type</label>
|
||||
<select class="form-control" id="invoice_type" name="invoice_type">
|
||||
<option value="0">All Types</option>
|
||||
|
|
@ -24,7 +25,16 @@ $itemTypes = $item_types ?? [];
|
|||
<option value="3">Organization</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Refer Doctor</label>
|
||||
<select class="form-control select2" id="refer_doctor_id" name="refer_doctor_id" data-placeholder="Select Refer Doctor">
|
||||
<option value="0">All Refer Doctors</option>
|
||||
<?php foreach ($referDoctors as $row) : ?>
|
||||
<option value="<?= esc($row->id ?? '') ?>"><?= esc($row->p_fname ?? '') ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Diagnosis Head</label>
|
||||
<select class="form-control select2" id="diagnosis_id" name="diagnosis_id" multiple data-placeholder="Select Diagnosis">
|
||||
<option value="0">All Diagnosis</option>
|
||||
|
|
@ -86,6 +96,7 @@ $itemTypes = $item_types ?? [];
|
|||
var dateRange = startVal + 'S' + endVal;
|
||||
|
||||
var invoiceType = document.getElementById('invoice_type').value || '0';
|
||||
var referDoctorId = document.getElementById('refer_doctor_id').value || '0';
|
||||
|
||||
var diagnosisSelect = document.getElementById('diagnosis_id');
|
||||
var diagnosisValues = Array.prototype.filter.call(diagnosisSelect.options, function(option) {
|
||||
|
|
@ -97,7 +108,8 @@ $itemTypes = $item_types ?? [];
|
|||
var diagnosisList = diagnosisValues.length ? diagnosisValues.join('S') : '0';
|
||||
|
||||
return '<?= base_url('Report/diagnosis_report_data') ?>/'
|
||||
+ encodeURIComponent(dateRange) + '/' + invoiceType + '/' + diagnosisList;
|
||||
+ encodeURIComponent(dateRange) + '/' + invoiceType + '/' + diagnosisList
|
||||
+ '?refer_doctor_id=' + encodeURIComponent(referDoctorId);
|
||||
}
|
||||
|
||||
document.getElementById('show_report').addEventListener('click', function() {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ $rows = $rows ?? [];
|
|||
$minRange = $min_range ?? '';
|
||||
$maxRange = $max_range ?? '';
|
||||
$invoiceTypeLabel = $invoice_type_label ?? 'All Types';
|
||||
$referDoctorLabel = $refer_doctor_label ?? 'All Refer Doctors';
|
||||
|
||||
$formatIndianDateTime = static function ($value): string {
|
||||
$value = trim((string) $value);
|
||||
|
|
@ -25,6 +26,7 @@ $maxRangeDisplay = $formatIndianDateTime($maxRange);
|
|||
<div class="mb-3">
|
||||
<p><strong>Date Range:</strong> <?= esc($minRangeDisplay) ?> to <?= esc($maxRangeDisplay) ?></p>
|
||||
<p><strong>Invoice Type:</strong> <?= esc($invoiceTypeLabel) ?></p>
|
||||
<p><strong>Refer Doctor:</strong> <?= esc($referDoctorLabel) ?></p>
|
||||
</div>
|
||||
|
||||
<?php if (empty($rows)) : ?>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user