diff --git a/app/Config/Routes.php b/app/Config/Routes.php index cb0438c..9446a07 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -652,6 +652,8 @@ $routes->get('Report/report_total_payment_app_show/(:segment)/(:segment)/(:segme $routes->get('Report/report_total_payment_app_show/(:segment)/(:segment)/(:segment)/(:num)', 'Report::report_total_payment_app_show/$1/$2/$3/$4'); $routes->get('Report/report_total_payment_app_show/(:segment)/(:segment)/(:segment)/(:segment)', 'Report::report_total_payment_app_show/$1/$2/$3/$4'); $routes->get('Report/report_total_payment_app_show/(:segment)/(:segment)/(:segment)/(:segment)/(:num)', 'Report::report_total_payment_app_show/$1/$2/$3/$4/$5'); +$routes->get('Report/report_total_payment_total_amount_show/(:segment)/(:segment)/(:segment)', 'Report::report_total_payment_total_amount_show/$1/$2/$3'); +$routes->get('Report/report_total_payment_total_amount_show/(:segment)/(:segment)/(:segment)/(:num)', 'Report::report_total_payment_total_amount_show/$1/$2/$3/$4'); $routes->get('Report/billing_operations_report', 'Report::billing_operations_report'); $routes->get('Report/billing_operations_report_data/(:segment)/(:segment)', 'Report::billing_operations_report_data/$1/$2'); diff --git a/app/Controllers/Report.php b/app/Controllers/Report.php index c26b05f..bf70775 100644 --- a/app/Controllers/Report.php +++ b/app/Controllers/Report.php @@ -2,6 +2,8 @@ namespace App\Controllers; +use Mpdf\Mpdf; + class Report extends BaseController { public function index() @@ -103,6 +105,151 @@ class Report extends BaseController return $this->response->setBody(''); } + if ($output === 2) { + $mpdfTempDir = WRITEPATH . 'cache' . DIRECTORY_SEPARATOR . 'mpdf'; + if (! is_dir($mpdfTempDir)) { + mkdir($mpdfTempDir, 0755, true); + } + + $mpdf = new Mpdf([ + 'tempDir' => $mpdfTempDir, + 'format' => 'A4-L', + 'margin_top' => 8, + 'margin_bottom' => 8, + 'margin_left' => 8, + 'margin_right' => 8, + ]); + + $pdfHtml = '' + . '

Collection Report

' + . $content; + + $mpdf->WriteHTML($pdfHtml); + + $fileName = 'Collection_Report_' . date('Ymd_His') . '.pdf'; + + return $this->response + ->setHeader('Content-Type', 'application/pdf') + ->setHeader('Content-Disposition', 'inline; filename="' . $fileName . '"') + ->setBody($mpdf->Output($fileName, 'S')); + } + + return $this->response->setBody($content); + } + + public function report_total_payment_total_amount_show( + string $dateRange, + string $employeeIds, + string $payModeId, + int $output = 0 + ) { + [$minRange, $maxRange] = $this->parseDateRange($dateRange); + + $builder = $this->db->table('payment_history p'); + $builder->select('p.update_by_id as user_id') + ->select('COALESCE(u.username, p.update_by) as user_name', false) + ->select('SUM(CASE WHEN p.credit_debit = 0 AND p.payof_type = 1 THEN p.amount ELSE 0 END) as opd_amount', false) + ->select('SUM(CASE WHEN p.credit_debit = 0 AND p.payof_type = 2 THEN p.amount ELSE 0 END) as charge_amount', false) + ->select('SUM(CASE WHEN p.credit_debit = 0 AND p.payof_type = 4 THEN p.amount ELSE 0 END) as ipd_amount', false) + ->select('SUM(CASE WHEN p.credit_debit = 0 AND p.payof_type = 3 THEN p.amount ELSE 0 END) as org_amount', false) + ->select('SUM(CASE WHEN p.credit_debit = 1 THEN p.amount ELSE 0 END) as return_amount', false) + ->select('SUM(CASE WHEN p.credit_debit = 0 THEN p.amount ELSE 0 END) - SUM(CASE WHEN p.credit_debit = 1 THEN p.amount ELSE 0 END) as total_amount', false) + ->join('users u', 'u.id = p.update_by_id', 'left') + ->where('p.payment_date >=', $minRange) + ->where('p.payment_date <=', $maxRange); + + $empList = $this->normalizeIdList($employeeIds); + if (! empty($empList)) { + $builder->whereIn('p.update_by_id', $empList); + } + + $payMode = (int) $payModeId; + if ($payMode < 1) { + $builder->whereIn('p.payment_mode', [1, 2]); + } else { + $builder->where('p.payment_mode', $payMode); + } + + $rows = $builder + ->groupBy(['p.update_by_id', 'u.username']) + ->orderBy('u.username', 'ASC') + ->orderBy('p.update_by_id', 'ASC') + ->get() + ->getResult(); + + $totals = [ + 'opd_amount' => 0.0, + 'charge_amount' => 0.0, + 'ipd_amount' => 0.0, + 'org_amount' => 0.0, + 'return_amount' => 0.0, + 'total_amount' => 0.0, + ]; + + foreach ($rows as $row) { + $totals['opd_amount'] += (float) ($row->opd_amount ?? 0); + $totals['charge_amount'] += (float) ($row->charge_amount ?? 0); + $totals['ipd_amount'] += (float) ($row->ipd_amount ?? 0); + $totals['org_amount'] += (float) ($row->org_amount ?? 0); + $totals['return_amount'] += (float) ($row->return_amount ?? 0); + $totals['total_amount'] += (float) ($row->total_amount ?? 0); + } + + $content = view('report/collection_report_total_table', [ + 'rows' => $rows, + 'totals' => $totals, + 'min_range' => $minRange, + 'max_range' => $maxRange, + ]); + + if ($output === 1) { + ExportExcel($content, 'Collection_Report_Total_' . date('YmdHis')); + return $this->response->setBody(''); + } + + if ($output === 2) { + $mpdfTempDir = WRITEPATH . 'cache' . DIRECTORY_SEPARATOR . 'mpdf'; + if (! is_dir($mpdfTempDir)) { + mkdir($mpdfTempDir, 0755, true); + } + + $mpdf = new Mpdf([ + 'tempDir' => $mpdfTempDir, + 'format' => 'A4-L', + 'margin_top' => 8, + 'margin_bottom' => 8, + 'margin_left' => 8, + 'margin_right' => 8, + ]); + + $pdfHtml = '' + . '

Collection Report - Total Amount

' + . $content; + + $mpdf->WriteHTML($pdfHtml); + + $fileName = 'Collection_Report_Total_' . date('Ymd_His') . '.pdf'; + + return $this->response + ->setHeader('Content-Type', 'application/pdf') + ->setHeader('Content-Disposition', 'inline; filename="' . $fileName . '"') + ->setBody($mpdf->Output($fileName, 'S')); + } + return $this->response->setBody($content); } @@ -327,6 +474,42 @@ class Report extends BaseController return $this->response->setBody(''); } + if ($output === 2) { + $mpdfTempDir = WRITEPATH . 'cache' . DIRECTORY_SEPARATOR . 'mpdf'; + if (! is_dir($mpdfTempDir)) { + mkdir($mpdfTempDir, 0755, true); + } + + $mpdf = new Mpdf([ + 'tempDir' => $mpdfTempDir, + 'format' => 'A4-L', + 'margin_top' => 8, + 'margin_bottom' => 8, + 'margin_left' => 8, + 'margin_right' => 8, + ]); + + $pdfHtml = '' + . '

Billing Operations Report

' + . $content; + + $mpdf->WriteHTML($pdfHtml); + + $fileName = 'Billing_Operations_Report_' . date('Ymd_His') . '.pdf'; + + return $this->response + ->setHeader('Content-Type', 'application/pdf') + ->setHeader('Content-Disposition', 'inline; filename="' . $fileName . '"') + ->setBody($mpdf->Output($fileName, 'S')); + } + return $this->response->setBody($content); } @@ -465,6 +648,42 @@ class Report extends BaseController return $this->response->setBody(''); } + if ($output === 2) { + $mpdfTempDir = WRITEPATH . 'cache' . DIRECTORY_SEPARATOR . 'mpdf'; + if (! is_dir($mpdfTempDir)) { + mkdir($mpdfTempDir, 0755, true); + } + + $mpdf = new Mpdf([ + 'tempDir' => $mpdfTempDir, + 'format' => 'A4', + 'margin_top' => 8, + 'margin_bottom' => 8, + 'margin_left' => 8, + 'margin_right' => 8, + ]); + + $pdfHtml = '' + . '

Document Issue Report

' + . $content; + + $mpdf->WriteHTML($pdfHtml); + + $fileName = 'Document_Issue_Report_' . date('Ymd_His') . '.pdf'; + + return $this->response + ->setHeader('Content-Type', 'application/pdf') + ->setHeader('Content-Disposition', 'inline; filename="' . $fileName . '"') + ->setBody($mpdf->Output($fileName, 'S')); + } + return $this->response->setBody($content); } @@ -476,12 +695,18 @@ class Report extends BaseController ) { [$minRange, $maxRange] = $this->parseDateRange($dateRange); + $netAmountExpr = "ROUND(IF(m.invoice_status=1, (t.item_amount - (t.item_amount * m.discount_amount / NULLIF(m.total_amount, 0))), 0), 2)"; + $builder = $this->db->table('invoice_master m'); $builder->select('y.group_desc, t.item_name') ->select('COUNT(t.id) as no_test', false) ->select('SUM(t.item_qty) as no_qty', false) - ->select('SUM(ROUND(IF(m.invoice_status=1, (t.item_amount - (t.item_amount * m.discount_amount / m.total_amount)), 0), 2)) as total_amount', false) + ->select('SUM(' . $netAmountExpr . ') as total_amount', false) ->select('SUM(IF(m.invoice_status=1, t.item_amount, 0)) as total_act_amount', false) + ->select('SUM(CASE WHEN m.ipd_id = 0 AND IFNULL(m.insurance_case_id, 0) = 0 THEN ' . $netAmountExpr . ' ELSE 0 END) as direct_patient_amount', false) + ->select('SUM(CASE WHEN m.ipd_id > 0 AND IFNULL(m.insurance_case_id, 0) = 0 THEN ' . $netAmountExpr . ' ELSE 0 END) as ipd_direct_amount', false) + ->select('SUM(CASE WHEN m.ipd_id > 0 AND IFNULL(m.insurance_case_id, 0) > 0 THEN ' . $netAmountExpr . ' ELSE 0 END) as ipd_tpa_amount', false) + ->select('SUM(CASE WHEN m.ipd_id = 0 AND IFNULL(m.insurance_case_id, 0) > 0 THEN ' . $netAmountExpr . ' ELSE 0 END) as org_credit_amount', false) ->join('invoice_item t', 'm.id = t.inv_master_id', 'inner') ->join('hc_item_type y', 't.item_type = y.itype_id', 'inner') ->where('y.is_ipd_opd IN (0, 1)', null, false) @@ -530,6 +755,45 @@ class Report extends BaseController return $this->response->setBody(''); } + if ($output === 2) { + $mpdfTempDir = WRITEPATH . 'cache' . DIRECTORY_SEPARATOR . 'mpdf'; + if (! is_dir($mpdfTempDir)) { + mkdir($mpdfTempDir, 0755, true); + } + + $mpdf = new Mpdf([ + 'tempDir' => $mpdfTempDir, + 'format' => 'A4-L', + 'margin_top' => 8, + 'margin_bottom' => 8, + 'margin_left' => 8, + 'margin_right' => 8, + ]); + + $pdfHtml = '' + . '

Diagnosis Report

' + . $content; + + $mpdf->WriteHTML($pdfHtml); + + $fileName = 'Diagnosis_Report_' . date('Ymd_His') . '.pdf'; + + return $this->response + ->setHeader('Content-Type', 'application/pdf') + ->setHeader('Content-Disposition', 'inline; filename="' . $fileName . '"') + ->setBody($mpdf->Output($fileName, 'S')); + } + return $this->response->setBody($content); } diff --git a/app/Views/report/billing_operations_report.php b/app/Views/report/billing_operations_report.php index 2bd7a6d..51f321d 100644 --- a/app/Views/report/billing_operations_report.php +++ b/app/Views/report/billing_operations_report.php @@ -24,9 +24,12 @@ $doctors = $doctors ?? []; -
- - +
+
+ + + +
@@ -85,6 +88,11 @@ $doctors = $doctors ?? []; window.open(buildUrl(true), '_blank'); }); + document.getElementById('billing_pdf').addEventListener('click', function() { + var url = buildUrl(false) + '/2'; + window.open(url, '_blank'); + }); + $('.select2').select2({ theme: 'bootstrap4', width: '100%' diff --git a/app/Views/report/collection_report.php b/app/Views/report/collection_report.php index 020c4b3..5baef5b 100644 --- a/app/Views/report/collection_report.php +++ b/app/Views/report/collection_report.php @@ -36,9 +36,17 @@ $payModes = $pay_modes ?? []; -
- - +
+
+ + + +
+
+ + + +
@@ -78,7 +86,7 @@ $payModes = $pay_modes ?? []; document.getElementById('report_start').value = toInputValue(start); document.getElementById('report_end').value = toInputValue(end); - function buildQuery() { + function buildBaseQuery() { var startVal = toRangeValue(document.getElementById('report_start').value, toInputValue(start)); var endVal = toRangeValue(document.getElementById('report_end').value, toInputValue(end)); var dateRange = startVal + 'S' + endVal; @@ -93,17 +101,50 @@ $payModes = $pay_modes ?? []; var empList = empValues.length ? empValues.join('S') : '0'; var payMode = document.getElementById('paymode_id').value || '0'; - return '/' - + encodeURIComponent(dateRange) + '/' + empList + '/' + payMode; + return { + dateRange: encodeURIComponent(dateRange), + empList: empList, + payMode: payMode, + }; + } + + function buildDetailQuery() { + var q = buildBaseQuery(); + return '/' + q.dateRange + '/' + q.empList + '/' + q.payMode; + } + + function buildTotalQuery() { + var q = buildBaseQuery(); + return '/' + q.dateRange + '/' + q.empList + '/' + q.payMode; } document.getElementById('show_report').addEventListener('click', function() { - var url = buildQuery(); + var url = buildDetailQuery(); load_form_div(url, 'report_result'); }); + document.getElementById('show_total_amount').addEventListener('click', function() { + var totalUrl = buildTotalQuery(); + load_form_div(totalUrl, 'report_result'); + }); + document.getElementById('export_report').addEventListener('click', function() { - var url = buildQuery() + '/1'; + var url = buildDetailQuery() + '/0/1'; + window.open(url, '_blank'); + }); + + document.getElementById('pdf_report').addEventListener('click', function() { + var url = buildDetailQuery() + '/0/2'; + window.open(url, '_blank'); + }); + + document.getElementById('total_export_report').addEventListener('click', function() { + var url = buildTotalQuery() + '/1'; + window.open(url, '_blank'); + }); + + document.getElementById('total_pdf_report').addEventListener('click', function() { + var url = buildTotalQuery() + '/2'; window.open(url, '_blank'); }); diff --git a/app/Views/report/collection_report_total_table.php b/app/Views/report/collection_report_total_table.php new file mode 100644 index 0000000..d405700 --- /dev/null +++ b/app/Views/report/collection_report_total_table.php @@ -0,0 +1,67 @@ + 0, + 'charge_amount' => 0, + 'ipd_amount' => 0, + 'org_amount' => 0, + 'return_amount' => 0, + 'total_amount' => 0, +]; +$minRange = $min_range ?? ''; +$maxRange = $max_range ?? ''; +?> + +

Date Range: to

+ + +
No records found for the selected filters.
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
User IDOPD AmountCharge AmountIPD AmountORG AmountReturn AmountTotal
+ user_name ?? '')); + $userId = (int) ($row->user_id ?? 0); + $userLabel = $userName !== '' ? $userName : 'Unknown'; + if ($userId > 0) { + $userLabel .= '[' . $userId . ']'; + } + ?> + + opd_amount ?? 0), 2)) ?>charge_amount ?? 0), 2)) ?>ipd_amount ?? 0), 2)) ?>org_amount ?? 0), 2)) ?>return_amount ?? 0), 2)) ?>total_amount ?? 0), 2)) ?>
Total
+ diff --git a/app/Views/report/diagnosis_report.php b/app/Views/report/diagnosis_report.php index eaf7273..546c684 100644 --- a/app/Views/report/diagnosis_report.php +++ b/app/Views/report/diagnosis_report.php @@ -35,9 +35,12 @@ $itemTypes = $item_types ?? []; -
- - +
+
+ + + +
@@ -107,6 +110,11 @@ $itemTypes = $item_types ?? []; window.open(url, '_blank'); }); + document.getElementById('pdf_report').addEventListener('click', function() { + var url = buildQuery() + '/2'; + window.open(url, '_blank'); + }); + // Initialize Select2 $('.select2').select2({ theme: 'bootstrap4', diff --git a/app/Views/report/diagnosis_report_table.php b/app/Views/report/diagnosis_report_table.php index eeaeba9..4e94514 100644 --- a/app/Views/report/diagnosis_report_table.php +++ b/app/Views/report/diagnosis_report_table.php @@ -3,10 +3,27 @@ $rows = $rows ?? []; $minRange = $min_range ?? ''; $maxRange = $max_range ?? ''; $invoiceTypeLabel = $invoice_type_label ?? 'All Types'; + +$formatIndianDateTime = static function ($value): string { + $value = trim((string) $value); + if ($value === '') { + return ''; + } + + $timestamp = strtotime($value); + if ($timestamp === false) { + return $value; + } + + return date('d-m-Y H:i:s', $timestamp); +}; + +$minRangeDisplay = $formatIndianDateTime($minRange); +$maxRangeDisplay = $formatIndianDateTime($maxRange); ?>
-

Date Range: to

+

Date Range: to

Invoice Type:

@@ -17,11 +34,14 @@ $invoiceTypeLabel = $invoice_type_label ?? 'All Types'; # - Diagnosis Group Test Name No. of Qty Amount Cost Amt + Direct Patient Amt + IPD Direct Amt + IPD TPA Amt + Org Credit Amt @@ -30,9 +50,17 @@ $invoiceTypeLabel = $invoice_type_label ?? 'All Types'; $diagnosisHeadTotal = 0.0; $diagnosisActHeadTotal = 0.0; $diagnosisQtyTotal = 0.0; + $diagnosisDirectPatientTotal = 0.0; + $diagnosisIpdDirectTotal = 0.0; + $diagnosisIpdTpaTotal = 0.0; + $diagnosisOrgCreditTotal = 0.0; $grandTotal = 0.0; $grandActTotal = 0.0; $grandQtyTotal = 0.0; + $grandDirectPatientTotal = 0.0; + $grandIpdDirectTotal = 0.0; + $grandIpdTpaTotal = 0.0; + $grandOrgCreditTotal = 0.0; $rowCount = count($rows); $rowNum = 0; @@ -43,6 +71,10 @@ $invoiceTypeLabel = $invoice_type_label ?? 'All Types'; $noQty = (float) ($row->no_qty ?? 0); $totalAmount = (float) ($row->total_amount ?? 0); $totalActAmount = (float) ($row->total_act_amount ?? 0); + $directPatientAmount = (float) ($row->direct_patient_amount ?? 0); + $ipdDirectAmount = (float) ($row->ipd_direct_amount ?? 0); + $ipdTpaAmount = (float) ($row->ipd_tpa_amount ?? 0); + $orgCreditAmount = (float) ($row->org_credit_amount ?? 0); // Diagnosis group header if ($groupDesc !== $diagnosisHead) { @@ -50,19 +82,27 @@ $invoiceTypeLabel = $invoice_type_label ?? 'All Types'; if ($diagnosisHead !== '') { echo ''; echo ''; - echo 'Total of ' . esc($diagnosisHead) . ''; + echo 'Total of ' . esc($diagnosisHead) . ''; echo '' . number_format($diagnosisQtyTotal, 0) . ''; echo '' . number_format($diagnosisHeadTotal, 2) . ''; echo '' . number_format($diagnosisActHeadTotal, 2) . ''; + echo '' . number_format($diagnosisDirectPatientTotal, 2) . ''; + echo '' . number_format($diagnosisIpdDirectTotal, 2) . ''; + echo '' . number_format($diagnosisIpdTpaTotal, 2) . ''; + echo '' . number_format($diagnosisOrgCreditTotal, 2) . ''; echo ''; $diagnosisHeadTotal = 0.0; $diagnosisActHeadTotal = 0.0; $diagnosisQtyTotal = 0.0; + $diagnosisDirectPatientTotal = 0.0; + $diagnosisIpdDirectTotal = 0.0; + $diagnosisIpdTpaTotal = 0.0; + $diagnosisOrgCreditTotal = 0.0; } echo ''; - echo '' . esc($groupDesc) . ''; + echo '' . esc($groupDesc) . ''; echo ''; $diagnosisHead = $groupDesc; } @@ -71,40 +111,59 @@ $invoiceTypeLabel = $invoice_type_label ?? 'All Types'; $rowNum++; echo ''; echo '' . $rowNum . ''; - echo ''; echo '' . esc($itemName) . ''; echo '' . number_format($noQty, 0) . ''; echo '' . number_format($totalAmount, 2) . ''; echo '' . number_format($totalActAmount, 2) . ''; + echo '' . number_format($directPatientAmount, 2) . ''; + echo '' . number_format($ipdDirectAmount, 2) . ''; + echo '' . number_format($ipdTpaAmount, 2) . ''; + echo '' . number_format($orgCreditAmount, 2) . ''; echo ''; // Update totals $diagnosisHeadTotal += $totalAmount; $diagnosisActHeadTotal += $totalActAmount; $diagnosisQtyTotal += $noQty; + $diagnosisDirectPatientTotal += $directPatientAmount; + $diagnosisIpdDirectTotal += $ipdDirectAmount; + $diagnosisIpdTpaTotal += $ipdTpaAmount; + $diagnosisOrgCreditTotal += $orgCreditAmount; $grandTotal += $totalAmount; $grandActTotal += $totalActAmount; $grandQtyTotal += $noQty; + $grandDirectPatientTotal += $directPatientAmount; + $grandIpdDirectTotal += $ipdDirectAmount; + $grandIpdTpaTotal += $ipdTpaAmount; + $grandOrgCreditTotal += $orgCreditAmount; } // Show last group total if ($diagnosisHead !== '' && $rowCount > 0) { echo ''; echo ''; - echo 'Total of ' . esc($diagnosisHead) . ''; + echo 'Total of ' . esc($diagnosisHead) . ''; echo '' . number_format($diagnosisQtyTotal, 0) . ''; echo '' . number_format($diagnosisHeadTotal, 2) . ''; echo '' . number_format($diagnosisActHeadTotal, 2) . ''; + echo '' . number_format($diagnosisDirectPatientTotal, 2) . ''; + echo '' . number_format($diagnosisIpdDirectTotal, 2) . ''; + echo '' . number_format($diagnosisIpdTpaTotal, 2) . ''; + echo '' . number_format($diagnosisOrgCreditTotal, 2) . ''; echo ''; } ?> - Grand Total + Grand Total + + + + diff --git a/app/Views/report/document_list.php b/app/Views/report/document_list.php index 49af032..c9e3add 100644 --- a/app/Views/report/document_list.php +++ b/app/Views/report/document_list.php @@ -29,9 +29,10 @@ $doclist = $doclist ?? [];
-
+
+
@@ -81,5 +82,10 @@ $doclist = $doclist ?? []; document.getElementById('showreportexport').addEventListener('click', function() { window.open(buildUrl(true), '_blank'); }); + + document.getElementById('showreportpdf').addEventListener('click', function() { + var pdfUrl = buildUrl(false) + '/2'; + window.open(pdfUrl, '_blank'); + }); })();