/* IPD Revenue Report */




SET @d1 = '2022-02-07 00:00:00'; /* date range 1 */
SET @d2 = '2022-02-17 00:00:00'; /* date range 2 */

SELECT
	si.service_item_name as ch_nm,
	s_sub.sub_cate_name as ch_s_nm,
	s_cat.name as ch_c_nm,
	pc_dtls.service_charge_date as ch_dt,
	pc_dtls.net_amount as ch_nt
FROM
	patient_service_charge_details as pc_dtls
INNER JOIN service_items si ON pc_dtls.service_id = si.id
INNER JOIN service_sub_categories s_sub ON s_sub.id = si.service_sub_category
INNER JOIN service_category s_cat ON s_cat.id = s_sub.category_id
WHERE (
		CASE
			WHEN (@d1 != '' AND @d2 != '') THEN (pc_dtls.service_charge_date BETWEEN @d1 AND @d2)
		END)