diff --git a/SolarPower/Controllers/ElectricitySoldRecordController.cs b/SolarPower/Controllers/ElectricitySoldRecordController.cs index 787fce7..c9d55cf 100644 --- a/SolarPower/Controllers/ElectricitySoldRecordController.cs +++ b/SolarPower/Controllers/ElectricitySoldRecordController.cs @@ -94,7 +94,8 @@ namespace SolarPower.Controllers Kwh = post.Kwh, Money = post.Money, PowerstationId = post.PowerstationId, - StartAt = post.StartAt + StartAt = post.StartAt, + Month = post.Month }; List properties = new List() { @@ -103,7 +104,8 @@ namespace SolarPower.Controllers "Kwh", "Money", "PowerstationId", - "StartAt" + "StartAt", + "Month" }; await electricitySoldRecordRepository.AddAsync(record, properties); @@ -119,7 +121,8 @@ namespace SolarPower.Controllers UpdatedBy = myUser.Id, Kwh = post.Kwh, Money = post.Money, - StartAt = post.StartAt + StartAt = post.StartAt, + Month = post.Month }; List properties = new List() { @@ -128,7 +131,8 @@ namespace SolarPower.Controllers "UpdatedBy", "Kwh", "Money", - "StartAt" + "StartAt", + "Month" }; await electricitySoldRecordRepository.Update(record, properties); apiResult.Code = "0000"; diff --git a/SolarPower/DBSchema/solar_power_schema.sql b/SolarPower/DBSchema/solar_power_schema.sql index 8f74a13..4e04265 100644 --- a/SolarPower/DBSchema/solar_power_schema.sql +++ b/SolarPower/DBSchema/solar_power_schema.sql @@ -2198,6 +2198,10 @@ ALTER TABLE `power_station` ALTER TABLE `operation_firm` ADD COLUMN `TaxIDNumber` VARCHAR(8) NULL DEFAULT NULL COMMENT '統一編號' AFTER `Email`, ADD COLUMN `Remark` VARCHAR(255) NULL DEFAULT NULL COMMENT '備註' AFTER `TaxIDNumber`; +-- 售電紀錄-歸屬月份 20210911 +ALTER TABLE `electricity_sold_record` + ADD COLUMN `Month` VARCHAR(10) NULL DEFAULT NULL COMMENT '歸屬月份' AFTER `Deleted`; + /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; /*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */; diff --git a/SolarPower/Models/ElectricitySoldRecord.cs b/SolarPower/Models/ElectricitySoldRecord.cs index 85a54b1..1815c69 100644 --- a/SolarPower/Models/ElectricitySoldRecord.cs +++ b/SolarPower/Models/ElectricitySoldRecord.cs @@ -15,6 +15,7 @@ namespace SolarPower.Models public int Kwh { get; set; }//購電度數 public float Money { get; set; }//售出金額 public int Deleted { get; set; } + public string Month { get; set; }// 歸屬月份 } public class ElectricitySoldRecordTable : ElectricitySoldRecord diff --git a/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs b/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs index 3329af4..5573c76 100644 --- a/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs +++ b/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs @@ -26,7 +26,6 @@ namespace SolarPower.Repository.Implement ids.Add(Convert.ToInt32(id.Value)); } - switch (post.SearchType) { case 0: @@ -34,28 +33,33 @@ namespace SolarPower.Repository.Implement post.Time = post.Time.Replace("-", "~"); post.Time = post.Time.Replace("/", "-"); var time = post.Time.Split("~"); + var time1 = Convert.ToDateTime(time[0]).ToString("yyyy-MM"); + var time2 = Convert.ToDateTime(time[1]).ToString("yyyy-MM"); + sql = @$"SELECT es.*,ps.Name AS PowerStationName FROM electricity_sold_record es LEFT JOIN power_station ps ON es.PowerstationId = ps.Id - WHERE es.StartAt BETWEEN '{time[0]}' AND '{time[1]}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; + WHERE es.Month BETWEEN '{time1}' AND '{time2}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; break; case 1: post.Time = post.Time.Replace(" ", ""); post.Time = post.Time.Replace("-", "~"); post.Time = post.Time.Replace("/", "-"); - var time1 = post.Time.Split("~"); + var timea = post.Time.Split("~"); + var timeb = Convert.ToDateTime(timea[0]).ToString("yyyy-MM"); + var timec = Convert.ToDateTime(timea[1]).ToString("yyyy-MM"); sql = @$"SELECT es.*,ps.Name AS PowerStationName FROM electricity_sold_record es LEFT JOIN power_station ps ON es.PowerstationId = ps.Id - WHERE es.StartAt BETWEEN '{time1[0]}' AND '{time1[1]}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; + WHERE es.Month BETWEEN '{timeb}' AND '{timec}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; break; case 2: sql = @$"SELECT es.*,ps.Name AS PowerStationName FROM electricity_sold_record es LEFT JOIN power_station ps ON es.PowerstationId = ps.Id - WHERE DATE_FORMAT(es.StartAt , '%Y-%m') = '{post.Time}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; + WHERE DATE_FORMAT(STR_TO_DATE(es.Month , '%Y-%m'),'%Y-%m') = '{post.Time}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; break; case 3: sql = @$"SELECT es.*,ps.Name AS PowerStationName FROM electricity_sold_record es LEFT JOIN power_station ps ON es.PowerstationId = ps.Id - WHERE DATE_FORMAT(es.StartAt , '%Y') = '{post.Time}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; + WHERE DATE_FORMAT(STR_TO_DATE(es.Month , '%Y'),'%Y') = '{post.Time}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; break; } using (IDbConnection conn = this._databaseHelper.GetConnection()) diff --git a/SolarPower/Repository/Implement/StationReportRepository.cs b/SolarPower/Repository/Implement/StationReportRepository.cs index 195fde2..879237c 100644 --- a/SolarPower/Repository/Implement/StationReportRepository.cs +++ b/SolarPower/Repository/Implement/StationReportRepository.cs @@ -218,7 +218,7 @@ namespace SolarPower.Repository.Implement conn.Open(); try { - string sql = @$"SELECT LeaseRate,Landowner from {post.SiteDB}.land_building WHERE PowerStationId = {post.PowerstationId}"; + string sql = @$"SELECT LeaseRate,Landowner from {post.SiteDB}.land_building WHERE PowerStationId = {post.PowerstationId} and Deleted = 0"; result = (await conn.QueryAsync(sql)).ToList(); } catch (Exception exception) diff --git a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml index 91f1886..5d341a2 100644 --- a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml +++ b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml @@ -174,6 +174,7 @@ 編號 電站名稱 + 歸屬月份 開始日期 結束日期 購電度數 @@ -228,6 +229,11 @@ + +
+ + +
@@ -496,7 +502,8 @@ EndAt: $("#EndTime_modal").val(), Kwh: $("#BuyKwh_modal").val(), Money: $("#Money_modal").val(), - PowerstationId: $("#PowerStationId_modal").val() + PowerstationId: $("#PowerStationId_modal").val(), + Month: $('#Month_modal').val() } $.post(url, send_data, function (rel) { @@ -528,6 +535,8 @@ "data": "id" }, { "data": "powerStationName" + },{ + "data": "month" }, { "data": "startAt" }, { @@ -611,7 +620,7 @@ $("#Record-modal .modal-title").html("台電售電紀錄 - 編輯"); selected_id = $(this).parents('tr').attr('data-id'); var powerstationName = $(this).parents('tr').attr('powerstation-Name'); - //取得單一運維基本資料 + //取得單一售電紀錄基本資料 var url = "/ElectricitySoldRecord/GetOnePowerStation/"; var send_data = { Id: selected_id @@ -628,6 +637,7 @@ $("#BuyKwh_modal").val(rel.data.kwh); $("#EndTime_modal").val(rel.data.endAt); $("#Money_modal").val(rel.data.money); + $("#Month_modal").val(rel.data.month); $("#Record-modal").modal(); }, 'json'); }); @@ -688,6 +698,9 @@ Money_modal: { required: true, }, + Month_modal: { + required: true, + } }, });