diff --git a/FrontendWebApi/ApiControllers/TenantBillController.cs b/FrontendWebApi/ApiControllers/TenantBillController.cs index 2c8f285..79e31c1 100644 --- a/FrontendWebApi/ApiControllers/TenantBillController.cs +++ b/FrontendWebApi/ApiControllers/TenantBillController.cs @@ -514,9 +514,9 @@ namespace FrontendWebApi.ApiControllers bill_perRCV, elec_result, water_result, - bill_perKWH * elec_result AS elec_bill, - bill_perRCV * water_result AS water_bill, - ROUND(bill_perKWH * elec_result + bill_perRCV * water_result) AS total_bill + elec_bill, + water_bill, + (elec_bill + water_bill) AS total_bill FROM ( SELECT a.tenant_name, @@ -525,13 +525,15 @@ namespace FrontendWebApi.ApiControllers bill_perKWH, bill_perRCV, SUM(CASE WHEN a.device_name_tag = 'E4' THEN result ELSE 0 END) AS elec_result, - SUM(CASE WHEN a.device_name_tag = 'W1' THEN result ELSE 0 END) AS water_result + SUM(CASE WHEN a.device_name_tag = 'W1' THEN result ELSE 0 END) AS water_result, + ROUND(bill_perKWH * SUM(CASE WHEN a.device_name_tag = 'E4' THEN result ELSE 0 END)) AS elec_bill, + ROUND(bill_perRCV * SUM(CASE WHEN a.device_name_tag = 'W1' THEN result ELSE 0 END)) AS water_bill FROM archive_electric_meter_tenant_bill a JOIN archive_electric_meter_tenant_list b ON a.tenant_guid = b.tenant_guid JOIN device c ON a.device_number = c.device_number WHERE {building_tag} GROUP BY a.tenant_name - ) subquery_alias"; + ) AS subquery_alias;"; outputBill = await backendRepository.GetAllAsync(sqlString); string filePath = CreateOutputForm(outputBill);