select sum(payments.amount_paid),count(payments.id) , tenants.id as tenant_id, tenants.tenant_name, properties.unit_no, tenants.rental_rate, bills.issue_date,  users.name, locations.location_name,projects.project_name, bill_types.bill_type_name, bills.bill_type_id
									from payments 
									inner join bills on payments.bill_id = bills.id
									inner join bill_types on bills.bill_type_id = bill_types.id
									inner join tenants on bills.tenant_id = tenants.id 
									inner join properties on tenants.property_id = properties.id
									inner join locations on properties.location_id = locations.id
									inner join projects on locations.project_id = projects.id
									inner join users on payments.created_by =  users.id
									where bills.bill_type_id in (1,0)  and locations.id = 5 
									and projects.id = 2 and (  YEAR(payments.created_at)  = 2023 ) group by tenants.id  
ORDER BY `bills`.`bill_type_id`  DESC



select bills.issue_date, payments.created_at from payments inner join bills on payments.bill_id = bills.id 
										where  bills.bill_type_id in (1,0) and YEAR(bills.issue_date) >= '2023'  group by YEAR(bills.issue_date)
										


select YEAR(bills.issue_date) as year, count(YEAR(bills.issue_date)) from payments 
inner join bills on payments.bill_id = bills.id 
inner join tenants on bills.tenant_id = tenants.id 
inner join properties on tenants.property_id = properties.id 
inner join locations on properties.location_id = locations.id
inner join projects on locations.project_id = projects.id 
where bills.bill_type_id in (1,0) and 
bills.issue_date > '2023-09-30' and 
(payments.created_at between '2023-09-01' and '2023-09-30') 
and locations.id = 5 and projects.id = 2
group by YEAR(bills.issue_date)