年報表SQL

This commit is contained in:
b110212000 2021-09-11 17:16:44 +08:00
parent 23104dc3a9
commit 883d3d21eb
4 changed files with 199 additions and 29 deletions

View File

@ -655,7 +655,7 @@ namespace SolarPower.Controllers
region = new CellRangeAddress(27, 29, 1, 6);
sheet.AddMergedRegion(region);
cell = row.CreateCell(1);
cell.SetCellValue($"{bill.Result.PowerName}-太陽光電售電收入 \r計算期間:{bill.Result.StartAt}-{bill.Result.EndAt} \r售電收入 = ( 度數 {bill.Result.Kwh} * 費率{bill.Result.PowerRate}) * 1.05 = {Math.Round(bill.Result.Kwh * bill.Result.PowerRate * 1.05,2) } 元");
cell.SetCellValue($"{bill.Result.PowerName}-太陽光電售電收入 \r計算期間:{bill.Result.StartAt}-{bill.Result.EndAt} \r售電收入 = ( 度數 {bill.Result.Kwh} * 費率{bill.Result.PowerRate}) * 1.05 = {Math.Round(bill.Result.Kwh * bill.Result.PowerRate * 1.05) } 元");
cell.CellStyle = style14bodyleftnoborder;
cell = row.CreateCell(6);
cell.CellStyle = style14bodyrightnoborder;

View File

@ -195,6 +195,55 @@ namespace SolarPower.Repository.Implement
}
break;
case 3:
sql = @$"
SET @sql = NULL;
SELECT
GROUP_CONCAT(DISTINCT
CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 4), '''')
) INTO @sql
FROM inverter_history_hour where powerstationId = {post.PowerStation};
SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%Y/%m'') report_date, ', @sql,
',b.todayKWH ''dayKWH'', round((b.todayKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', c.KWHKWP ''KWHKWP'', c.PR,
d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'',
c.monthKWH ''monthKWH'', c.money ''monthmoney'', stationName, powerRate ''monthmoneyone'',SolarType,SiteDB
FROM inverter_history_month a left join
( # inv
select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y-%m'') report_date, siteid, sitetype,
round(MONTHKWH, 2) todayKWH,round(KWHKWP, 2) KWHKWP, round(PR, 2) PR, ifnull(round(money, 2),0) money, round(SOLARHOUR, 2) SOLARHOUR
from power_station_history_month
where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y'') = ''{post.Time}''
) b on a.powerStationid = b.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m'') = b.report_date
left join
( # month
select powerStationid, DATE_FORMAT(TIMESTAMP,''%Y'') report_date, sitetype, sum(round(monthKWH, 2)) monthKWH , avg(round(KWHKWP, 2)) KWHKWP
, avg(round(PR, 2)) PR, sum(round(money, 2)) money , sum(round(SOLARHOUR, 2)) SOLARHOUR
from power_station_history_month
where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y'') = ''{post.Time}'' group by DATE_FORMAT(TIMESTAMP,''%Y'')
) c on a.powerStationid = c.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y'') = c.report_date
left join
(
select powerStationID, DATE_FORMAT(TIMESTAMP,''%Y-%m'')report_date, irradiance, Temperature
from sensor_history_month
where powerstationid = {post.PowerStation} and DATE_FORMAT(TIMESTAMP,''%Y'') = ''{post.Time}''
) d on a.powerStationid = d.powerStationid and DATE_FORMAT(a.TIMESTAMP,''%Y-%m'') = d.report_date
join
(
select id, name stationName, powerRate,SolarType,SiteDB from power_station where id = {post.PowerStation}
)z on a.powerstationid = z.id
where DATE_FORMAT(a.TIMESTAMP,''%Y'') = ''{post.Time}''
GROUP BY DATE_FORMAT(a.TIMESTAMP,''%Y-%m'')
order by DATE_FORMAT(a.TIMESTAMP,''%Y-%m'') ');
# select @sql as 'mySelect'; #
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
";
break;
}
a = await conn.QueryAsync<dynamic>(sql);
}

View File

@ -570,9 +570,9 @@
str += "<td>" + (val.cbAkwh * val.cbAeff * days * val.capacity * 0.01).toFixed(2) + "</td>";
str += "<td>" + (val.rate * (val.cbAkwh * val.cbAeff * days * val.capacity * 0.01)).toFixed(2) + "</td>";
str += "<td>" + val.realKWH.toFixed(2) + "</td>";
str += "<td>" + val.realMoney.toFixed(2) + "</td>";
str += "<td>" + Math.round(val.realMoney) + "</td>";
str += "<td>" + val.actualkwh.toFixed(2) + "</td>";
str += "<td>" + val.actualMoney.toFixed(2) + "</td>";
str += "<td>" + Math.round(val.actualMoney) + "</td>";
var cba = val.cbAkwh * val.cbAeff * days * val.capacity * 0.01 / days / val.capacity;
str += "<td>" + cba.toFixed(2) + "</td>";
var real = val.realKWH / days / val.capacity;
@ -590,12 +590,12 @@
}
var stra = "";
stra += "<tr>";
stra += "<td>" + capacity.toFixed(2) + "</td>";
stra += "<td>" + capacity.toFixed(3) + "</td>";
stra += "<td>" + cbAkwh.toFixed(2) + "</td>";
stra += "<td>" + rate.toFixed(2) + "</td>";
stra += "<td>" + capacity.toFixed(2) + "</td>";
stra += "<td>" + capacity.toFixed(3) + "</td>";
stra += "<td>" + rate.toFixed(2) + "</td>";
stra += "<td>" + capacity.toFixed(2) + "</td>";
stra += "<td>" + capacity.toFixed(3) + "</td>";
stra += "<td>" + rate.toFixed(2) + "</td>";
stra += "<td>" + (checkvalue ? 0 : (totalcbAkwh / totaldays / capacity).toFixed(2)) + "</td>";
stra += "<td>" + ((totaldays == 0) ? 0 : (totalrealKWH / totaldays / capacity).toFixed(2)) + "</td>";

View File

@ -209,6 +209,7 @@
<div class="pr-3" id="quickSearchOption">
<button type="button" class="btn btn-primary waves-effect waves-themed ml-1" onclick="Dateform(0)" id="daybtn">日報表</button>
<button type="button" class="btn btn-primary waves-effect waves-themed ml-1" onclick="Dateform(1)" id="monthbtn">月報表</button>
<button type="button" class="btn btn-primary waves-effect waves-themed ml-1" onclick="Dateform(3)" id="year2btn">年報表</button>
<button type="button" class="btn btn-primary waves-effect waves-themed ml-1" onclick="Dateform(2)" id="yearbtn">綜合報表</button>
</div>
</div>
@ -785,7 +786,7 @@
if (inverter[i] == null) {
sta += "<td>" + 0 + "</td>";
} else {
sta += "<td>" + Number(inverter[i]).toFixed(2) + "</td>";
sta += "<td>" + Number(inverter[i]).toFixed(2) + "</td>";
}
});
sta += "<td>" + Number(inverter.hourKWH) + "</td>";
@ -800,8 +801,8 @@
tpr = inverter.pr ? inverter.pr.toFixed(2) : 0;
tkwh = inverter.totKWH ? inverter.totKWH.toFixed(2) : 0;
kWhkwp = inverter.totKWHKWP ? inverter.totKWHKWP.toFixed(2) : 0;
ntd = inverter.totmoney ? inverter.totmoney.toFixed(2) : 0;
ntdone = inverter.totmoney / inverter.totKWH ? (inverter.totmoney / inverter.totKWH).toFixed(2) : 0;
ntd = inverter.totmoney ? Math.round(inverter.totmoney) : 0;
ntdone = inverter.totmoney / inverter.totKWH ? Math.round(inverter.totmoney / inverter.totKWH) : 0;
})
var stc = "<tr>";
stc += "<th>" + '日照小時' + "</th>";
@ -832,7 +833,7 @@
$('#tothead').append(stc);
haveinvertName = [];
}
else {//月報表
else if (form == 1) {//月報表
var avghour = 0;
var avgKWHKWP = 0;
var avgdayKWH = 0;
@ -871,8 +872,7 @@
monthmoney = inverter.monthmoney ? inverter.monthmoney : 0;
monthmoneyone += inverter.monthmoneyone ? inverter.monthmoneyone : 0;
if (inverter.SolarType == 1)
{
if (inverter.SolarType == 1) {
check_hire = true;
sitedb = inverter.SiteDB
}
@ -882,17 +882,19 @@
var stc = "<tr>";
stc += "<th>" + '日小時平均' + "</th>";
stc += "<th>" + '日kWH/kWP平均' + "</th>";
stc += "<th>" + '發電量平均(kWh)' + "</th>";
stc += "<th>" + '發電量(kWh)' + "</th>";
stc += "<th>" + '日照平均(日)' + "</th>";
stc += "<th>" + 'kWH/kWP(日)' + "</th>";
stc += "<th>" + '發電量平均(kWh)(日)' + "</th>";
stc += "<th>" + '發電量(kWh)(月)' + "</th>";
if (showmoney == 1) {
stc += "<th>" + '售電金額(NTD)' + "</th>";
stc += "<th>" + '售電單價(NTD)' + "</th>";
stc += "<th>" + '售電金額(NTD)(月)' + "</th>";
stc += "<th>" + '售電單價(NTD)(月)' + "</th>";
}
stc += "<th>" + '售電天數' + "</th>";
stc += "<th>" + '售電天數(月)' + "</th>";
stc += "</tr>";
var stb = "<tr>";
if (monthday == 0) {
stb += "<td>" + 0 + "</td>";
@ -904,22 +906,20 @@
stb += "<td>" + 0 + "</td>";
stb += "</tr>";
}
else
{
else {
stb += "<td>" + (avghour / monthday).toFixed(2) + "</td>";
stb += "<td>" + (avgKWHKWP / monthday).toFixed(2) + "</td>";
stb += "<td>" + (avgdayKWH / monthday).toFixed(2) + "</td>";
stb += "<td>" + monthKWH + "</td>";
if (showmoney == 1) {
stb += "<td>" + monthmoney + "</td>";
stb += "<td>" + (monthmoneyone / monthday).toFixed(2) + "</td>";
stb += "<td>" + Math.round(monthmoneyone / monthday) + "</td>";
}
stb += "<td>" + monthday + "</td>";
stb += "</tr>";
}
var std = "";
if (check_hire == true && showmoney == 1)
{
if (check_hire == true && showmoney == 1) {
var dataTosent =
{
Sitedb: sitedb,
@ -936,8 +936,8 @@
std += "<tr>";
std += "<td>" + value.landowner + "</td>";
std += "<td>" + value.leaseRate + "%" + "</td>";
std += "<td>" + (monthmoney * value.leaseRate / 100).toFixed(2) + "</td>";
std += "<td>" + (monthmoney * value.leaseRate / 100 * 1.05).toFixed(2) + "</td>";
std += "<td>" + Math.round(monthmoney * value.leaseRate / 100) + "</td>";
std += "<td>" + Math.round(monthmoney * value.leaseRate / 100 * 1.05) + "</td>";
std += "</tr>";
})
$('#HireTableBody').append(std);
@ -953,6 +953,127 @@
haveinvertName = [];
}
else if (form == 3) {
var avghour = 0;
var avgKWHKWP = 0;
var avgdayKWH = 0;
var monthKWH = 0;
var monthmoney = 0;
var monthmoneyone = 0;
var monthday = 0;
var check_hire = false;
var sitedb = "";
$.each(rel.data, function (index, inverter) {
sta += "<tr>";
sta += "<td>" + inverter.report_date + "</td>";
$.each(haveinvertName, function (item, i) {
if (inverter[i] == null) {
sta += "<td>" + 0 + "</td>";
} else {
sta += "<td>" + inverter[i] + "</td>";
}
});
sta += "<td>" + inverter.dayKWH + "</td>";
sta += "<td>" + inverter.dayKWHp + "</td>";
sta += "<td>" + inverter.tothour + "</td>";
sta += "<td>" + inverter.KWHKWP + "</td>";
sta += "<td>" + inverter.PR + "</td>";
sta += "<td>" + inverter.irradiance + "</td>";
sta += "<td>" + inverter.temperature + "</td>";
if (showmoney == 1) {
sta += "<td>" + inverter.soldmoney + "</td>";
}
sta += "</tr>";
avghour += inverter.tothour ? inverter.tothour : 0;
avgKWHKWP += inverter.KWHKWP ? inverter.KWHKWP : 0;
avgdayKWH += inverter.dayKWH ? inverter.dayKWH : 0;
monthKWH = inverter.monthKWH ? inverter.monthKWH : 0;
monthmoney = inverter.monthmoney ? inverter.monthmoney : 0;
monthmoneyone += inverter.monthmoneyone ? inverter.monthmoneyone : 0;
if (inverter.SolarType == 1) {
check_hire = true;
sitedb = inverter.SiteDB
}
})
monthday = rel.data.length;
var stc = "<tr>";
stc += "<th>" + '日照平均(日)' + "</th>";
stc += "<th>" + 'kWH/kWP(日)' + "</th>";
stc += "<th>" + '發電量平均(kWh)(日)' + "</th>";
stc += "<th>" + '發電量(kWh)(月)' + "</th>";
if (showmoney == 1) {
stc += "<th>" + '售電金額(NTD)(月)' + "</th>";
stc += "<th>" + '售電單價(NTD)(月)' + "</th>";
}
stc += "<th>" + '售電天數(月)' + "</th>";
stc += "</tr>";
var stb = "<tr>";
if (monthday == 0) {
stb += "<td>" + 0 + "</td>";
stb += "<td>" + 0 + "</td>";
stb += "<td>" + 0 + "</td>";
stb += "<td>" + 0 + "</td>";
stb += "<td>" + 0 + "</td>";
stb += "<td>" + 0 + "</td>";
stb += "<td>" + 0 + "</td>";
stb += "</tr>";
}
else {
stb += "<td>" + (avghour / monthday).toFixed(2) + "</td>";
stb += "<td>" + (avgKWHKWP / monthday).toFixed(2) + "</td>";
stb += "<td>" + (avgdayKWH / monthday).toFixed(2) + "</td>";
stb += "<td>" + monthKWH + "</td>";
if (showmoney == 1) {
stb += "<td>" + monthmoney + "</td>";
stb += "<td>" + Math.round(monthmoneyone / monthday) + "</td>";
}
stb += "<td>" + monthday + "</td>";
stb += "</tr>";
}
var std = "";
if (check_hire == true && showmoney == 1) {
var dataTosent =
{
Sitedb: sitedb,
PowerstationId: nowpowerstation
}
$('#HireTableBody').empty();
var posturl = "/StationReport/GetHireInfo";
$.post(posturl, dataTosent, function (rel) {
if (rel.code != "0000") {
toast_error(rel.data.msg);
return;
}
$.each(rel.data, function (index, value) {
std += "<tr>";
std += "<td>" + value.landowner + "</td>";
std += "<td>" + value.leaseRate + "%" + "</td>";
std += "<td>" + Math.round(monthmoney * value.leaseRate / 100) + "</td>";
std += "<td>" + Math.round(monthmoney * value.leaseRate / 100 * 1.05) + "</td>";
std += "</tr>";
})
$('#HireTableBody').append(std);
$('#hiretable').show();
})
}
$('#TableBody').append(sta);
$('#totbody').append(stb);
$('#tothead').append(stc);
haveinvertName = [];
}
$('#overviewtable').show();
$('#detailtable').show();
@ -1047,11 +1168,11 @@
StrInfoBody += "<td>" + data.avgIrradiance.toFixed(2) + "</td>";
StrInfoBody += "<td>" + data.avgPR.toFixed(2) + "</td>";
if (showmoney == 1) {
StrInfoBody += "<td>" + data.todayMoney.toFixed(2) + "</td>";
StrInfoBody += "<td>" + Math.round(data.todayMoney) + "</td>";
StrInfoBody += "<td>" + (data.todayMoney * hirerate * 0.01).toFixed(2)+ "</td>";
StrInfoBody += "<td>" + Math.round(data.todayMoney * hirerate * 0.01)+ "</td>";
StrInfoBody += "<td>" + data.todayMoney.toFixed(2) + "</td>";
StrInfoBody += "<td>" + Math.round(data.todayMoney) + "</td>";
}