diff --git a/FrontendWebApi/ApiControllers/TenantBillController.cs b/FrontendWebApi/ApiControllers/TenantBillController.cs index f3954be..50dda76 100644 --- a/FrontendWebApi/ApiControllers/TenantBillController.cs +++ b/FrontendWebApi/ApiControllers/TenantBillController.cs @@ -401,7 +401,7 @@ namespace FrontendWebApi.ApiControllers List tenantBill = new List(); try { - string sqlString = $@"select * from {TenantBilltable} WHERE tenant_guid= '{tb.tenant_guid}' and a.deleted = 0"; + string sqlString = $@"select * from {TenantBilltable} WHERE tenant_guid= '{tb.tenant_guid}' and deleted = 0"; tenantBill = await backendRepository.GetAllAsync(sqlString); if (tenantBill.Count > 1) @@ -445,7 +445,7 @@ namespace FrontendWebApi.ApiControllers try { - string sqlString = $@"select * from {TenantBilltable} WHERE tenant_guid= '{tb.tenant_guid}' and a.deleted = 0"; + string sqlString = $@"select * from {TenantBilltable} WHERE tenant_guid= '{tb.tenant_guid}' and deleted = 0"; tenantBill = await backendRepository.GetAllAsync(sqlString); foreach (TenantBill t in tenantBill) @@ -507,21 +507,31 @@ namespace FrontendWebApi.ApiControllers { string sqlString = $@"SELECT - a.tenant_name, - MIN(NULLIF(a.start_timestamp, '')) AS start_timestamp, - MAX(NULLIF(a.end_timestamp, '')) AS end_timestamp, - 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 = 'E4' THEN bill ELSE 0 END) AS elec_bill, - SUM(CASE WHEN a.device_name_tag = 'W1' THEN bill ELSE 0 END) AS water_bill, - SUM(bill) AS total_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;"; + tenant_name, + start_timestamp, + end_timestamp, + bill_perKWH, + 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 + FROM ( + SELECT + a.tenant_name, + MIN(NULLIF(a.start_timestamp, '')) AS start_timestamp, + MAX(NULLIF(a.end_timestamp, '')) AS end_timestamp, + 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 + 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"; outputBill = await backendRepository.GetAllAsync(sqlString); string filePath = CreateOutputForm(outputBill); @@ -660,6 +670,7 @@ namespace FrontendWebApi.ApiControllers $" 水費總計: {item.water_bill}元 " + $" " + $" " + + $"

總計(費用):各電/水量加總 * 單價

" + $" " + $"
" + $"
" +