diff --git a/Frontend/_reportManagement.html b/Frontend/_reportManagement.html
index 035bd8a..7b3c3c4 100644
--- a/Frontend/_reportManagement.html
+++ b/Frontend/_reportManagement.html
@@ -879,8 +879,12 @@
const ElecEachTotal =
$("li.active [name=reportTypeRadio]").data("type") === "compare";
- if (ElecEachTotal) {
- const [year, month] = $("#elecMonthDate").val().split("-");
+ if (ElecEachTotal) {
+ let preDate = new Date($("#elecMonthDate").val().split("-") + "-01");
+ preDate.setMonth(preDate.getMonth() - 1);
+ const [year, month] = $("#elecMonthDate").val().split("-");
+ const preYear = preDate.getFullYear();
+ const preMonth = (preDate.getMonth() + 1).toString().padStart(2, '0');
datesColumns = [
{
label: "選擇月份
" + `${year}${month}` + "(A)",
@@ -888,16 +892,15 @@
},
{
label:
- "前一月份
" +
- `${year}${month - 1 > 10 ? month - 1 : `0${month - 1}`}` +
+ "前一月份
" +
+ `${preYear}${preMonth}` +
"(B)",
- value: `${year}-${month - 1 > 10 ? month - 1 : `0${month - 1}`}`,
+ value: `${preYear}-${preMonth}`,
},
{
label:
"差異比較
" +
- `${year}${month}(A)-${year}${month - 1 > 10 ? month - 1 : `0${month - 1}`
- }(B)`,
+ `${year}${month}(A)-${preYear}${preMonth}(B)`,
value: "last month different",
},
{
diff --git a/FrontendWebApi/ApiControllers/HydroMeterController.cs b/FrontendWebApi/ApiControllers/HydroMeterController.cs
index c9749ab..d30325a 100644
--- a/FrontendWebApi/ApiControllers/HydroMeterController.cs
+++ b/FrontendWebApi/ApiControllers/HydroMeterController.cs
@@ -1299,6 +1299,7 @@ namespace FrontendWebApi.ApiControllers
var start_month = date.ToString("MM"); // 查詢月
var last_year = previousYear.ToString("yyyy"); // 上個查詢年
var last_month = previousMonth.ToString("MM"); // 上個查詢月
+ var pre_year = previousMonth.ToString("yyyy"); // 上個查詢月(年份)
string sqlWhere = "";
string tag_quantity = await backendRepository.GetOneAsync("select system_value from variable where system_type = 'obixConfig' and system_key = 'tag_quantity' and deleted = 0");
@@ -1329,14 +1330,14 @@ namespace FrontendWebApi.ApiControllers
}
string header_now = start_year + "-" + start_month;
- string header_lastM = start_year + "-" + last_month;
+ string header_lastM = pre_year + "-" + last_month;
string header_lastY = last_year + "-" + start_month;
var sql = $@"
select e.full_name building_name, a.device_number, '{header_now}' searchMT, ifnull(b.kwh_sum, 0) searchM, '{header_lastM}' lastMT, ifnull(c.kwh_sum, 0) lastM, '{header_lastY}' lastYT, ifnull(d.kwh_sum, 0) lastY
from device a
left join (select device_number, sum(kwh_result) kwh_sum from archive_electric_meter_month where year(start_timestamp) = {start_year} and month(start_timestamp) = {start_month} group by device_number) b on a.device_number COLLATE utf8mb4_0900_ai_ci = b.device_number -- month1
-left join (select device_number, sum(kwh_result) kwh_sum from archive_electric_meter_month where year(start_timestamp) = {start_year} and month(start_timestamp) = {last_month} group by device_number) c on a.device_number COLLATE utf8mb4_0900_ai_ci = c.device_number -- month2
+left join (select device_number, sum(kwh_result) kwh_sum from archive_electric_meter_month where year(start_timestamp) = {pre_year} and month(start_timestamp) = {last_month} group by device_number) c on a.device_number COLLATE utf8mb4_0900_ai_ci = c.device_number -- month2
left join (select device_number, sum(kwh_result) kwh_sum from archive_electric_meter_month where year(start_timestamp) = {last_year} and month(start_timestamp) = {start_month} group by device_number) d on a.device_number COLLATE utf8mb4_0900_ai_ci = d.device_number -- last Month
join building e on a.device_building_tag = e.building_tag
where {sqlWhere}