This commit is contained in:
Kai 2021-08-11 16:13:58 +08:00
commit d26c9cc810
10 changed files with 369 additions and 39 deletions

View File

@ -1,10 +1,14 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using SolarPower.Models; using SolarPower.Models;
using SolarPower.Models.PowerStation; using SolarPower.Models.PowerStation;
using SolarPower.Repository.Interface; using SolarPower.Repository.Interface;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -114,6 +118,7 @@ namespace SolarPower.Controllers
foreach (ElectricitySoldRecordTable a in electricitySoldRecordTable) foreach (ElectricitySoldRecordTable a in electricitySoldRecordTable)
{ {
a.Function = @" a.Function = @"
<button type='button' class='btn btn-success btn-pills waves-effect waves-themed bill-btn'></button>
<button type='button' class='btn btn-primary btn-pills waves-effect waves-themed edit-btn'></button> <button type='button' class='btn btn-primary btn-pills waves-effect waves-themed edit-btn'></button>
<button type='button' class='btn btn-danger btn-pills waves-effect waves-themed del-btn'></button>"; <button type='button' class='btn btn-danger btn-pills waves-effect waves-themed del-btn'></button>";
a.CreatedDay = Convert.ToDateTime(a.CreatedAt).ToString("yyyy-MM-dd"); a.CreatedDay = Convert.ToDateTime(a.CreatedAt).ToString("yyyy-MM-dd");
@ -181,5 +186,279 @@ namespace SolarPower.Controllers
return apiResult; return apiResult;
} }
public FileResult BillExcel (int post)
{
var workbook = new XSSFWorkbook();
#region excel設定
IFont font26 = workbook.CreateFont();
font26.FontName = "新細明體";
font26.FontHeightInPoints = 26;
font26.IsBold = true;
ICellStyle style26 = workbook.CreateCellStyle();
style26.SetFont(font26);
style26.Alignment = HorizontalAlignment.Center;
style26.VerticalAlignment = VerticalAlignment.Center;
//IFont font12Times = workbook.CreateFont();
//font12Times.FontName = "Times New Roman";
//font12Times.FontHeightInPoints = 12;
//IFont font18 = workbook.CreateFont();
//font18.FontName = "新細明體";
//font18.FontHeightInPoints = 18;
//font18.IsBold = true;
//ICellStyle styleTitle18 = workbook.CreateCellStyle();
//styleTitle18.SetFont(font18);
//styleTitle18.Alignment = HorizontalAlignment.Center;
//styleTitle18.VerticalAlignment = VerticalAlignment.Center;
//ICellStyle styleLeft12 = workbook.CreateCellStyle();
//styleLeft12.SetFont(font12);
//styleLeft12.Alignment = HorizontalAlignment.Left;
//styleLeft12.VerticalAlignment = VerticalAlignment.Center;
//ICellStyle styleLine12 = workbook.CreateCellStyle();
//styleLine12.SetFont(font12);
//styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
//styleLine12.VerticalAlignment = VerticalAlignment.Center;
//styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
//styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
//styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
//styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
//ICellStyle stylein12 = workbook.CreateCellStyle();
//stylein12.SetFont(font12Times);
//stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
//stylein12.VerticalAlignment = VerticalAlignment.Center;
//stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
//stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
//stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
//stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
//stylein12.WrapText = true;
IFont font14 = workbook.CreateFont();
font14.FontName = "新細明體";
font14.FontHeightInPoints = 14;
font14.IsBold = true;
ICellStyle style14 = workbook.CreateCellStyle();
style14.SetFont(font14);
style14.Alignment = HorizontalAlignment.Left;
style14.VerticalAlignment = VerticalAlignment.Center;
ICellStyle buttomLine14 = workbook.CreateCellStyle();
buttomLine14.BorderBottom = BorderStyle.Medium;
IFont fontBlue14 = workbook.CreateFont();
fontBlue14.FontName = "新細明體";
fontBlue14.FontHeightInPoints = 14;
fontBlue14.IsBold = true;
fontBlue14.Color = NPOI.HSSF.Util.HSSFColor.Indigo.Index;
ICellStyle buttomLineBlue14 = workbook.CreateCellStyle();
buttomLineBlue14.SetFont(fontBlue14);
buttomLineBlue14.BorderBottom = BorderStyle.Medium;
ICellStyle style14upleft = workbook.CreateCellStyle();
style14upleft.SetFont(font14);
style14upleft.Alignment = HorizontalAlignment.Center;
style14upleft.VerticalAlignment = VerticalAlignment.Center;
style14upleft.BorderTop = BorderStyle.Medium;
style14upleft.BorderLeft = BorderStyle.Medium;
style14upleft.BorderRight = BorderStyle.Thin;
style14upleft.BorderBottom = BorderStyle.Thin;
ICellStyle style14up = workbook.CreateCellStyle();
style14up.SetFont(font14);
style14up.Alignment = HorizontalAlignment.Center;
style14up.VerticalAlignment = VerticalAlignment.Center;
style14up.BorderTop = BorderStyle.Medium;
style14up.BorderLeft = BorderStyle.Thin;
style14up.BorderRight = BorderStyle.Thin;
style14up.BorderBottom = BorderStyle.Thin;
#endregion
var bill = electricitySoldRecordRepository.GetBill(post);
var sheet = workbook.CreateSheet("附件一-開立發票申請表");
IRow row;
ICell cell;
sheet.SetColumnWidth(0, 1 * 160 * 4);
sheet.SetColumnWidth(1, 4 * 160 * 8);
sheet.SetColumnWidth(2, 6 * 160 * 8);
sheet.SetColumnWidth(3, 4 * 160 * 8);
sheet.SetColumnWidth(4, 6 * 160 * 8);
sheet.SetColumnWidth(5, 6 * 160 * 8);
sheet.SetColumnWidth(6, 6 * 160 * 8);
CellRangeAddress region;
row = sheet.CreateRow(1);
cell = row.CreateCell(1);
region = new CellRangeAddress(1, 1, 1, 6);
sheet.AddMergedRegion(region);
cell.SetCellValue(bill.Result.Name);
cell.CellStyle = style26;
row = sheet.CreateRow(2);
cell = row.CreateCell(1);
region = new CellRangeAddress(2, 2, 1, 6);
sheet.AddMergedRegion(region);
cell.SetCellValue("開立統一發票申請表");
cell.CellStyle = style26;
row = sheet.CreateRow(4);
cell = row.CreateCell(5);
cell.SetCellValue("單據編號:");
cell.CellStyle = style14;
cell = row.CreateCell(6);
cell.SetCellValue("");
cell.CellStyle = buttomLine14;
row = sheet.CreateRow(5); //第5行
cell = row.CreateCell(1);
cell.SetCellValue("申 請 人 ");
cell.CellStyle = style14;
cell = row.CreateCell(2);
cell.SetCellValue("");
cell.CellStyle = buttomLine14;
cell = row.CreateCell(3);
cell.SetCellValue("分 機:");
cell.CellStyle = style14;
cell = row.CreateCell(4);
cell.SetCellValue("");
cell.CellStyle = buttomLine14;
row = sheet.CreateRow(6); //第6行
cell = row.CreateCell(1);
cell.SetCellValue("成本中心 ");
cell.CellStyle = style14;
cell = row.CreateCell(2);
cell.SetCellValue("");
cell.CellStyle = buttomLine14;
cell = row.CreateCell(3);
cell.SetCellValue("行動電話 ");
cell.CellStyle = style14;
cell = row.CreateCell(4);
cell.SetCellValue("");
cell.CellStyle = buttomLine14;
row = sheet.CreateRow(7); //第7行
cell = row.CreateCell(1);
cell.SetCellValue("領取方式 ");
cell.CellStyle = style14;
cell = row.CreateCell(2);
region = new CellRangeAddress(7, 7, 2, 3);
sheet.AddMergedRegion(region);
cell.SetCellValue("□ 親自領取 □ 郵寄領取");
cell.CellStyle = style14;
row = sheet.CreateRow(9); //第9行
region = new CellRangeAddress(9, 9, 1, 2);
sheet.AddMergedRegion(region);
cell = row.CreateCell(1);
cell.SetCellValue("統一發票開立基本資料");
cell.CellStyle = style14;
row = sheet.CreateRow(10); //第10行
cell = row.CreateCell(1);
cell.SetCellValue("開立方式:");
cell.CellStyle = style14;
region = new CellRangeAddress(10, 10, 2, 6);
sheet.AddMergedRegion(region);
cell = row.CreateCell(2);
cell.SetCellValue("□一次性開立 □ 週期性開立 (自 年 月至 年 月),請檢附合約影本。");
cell.CellStyle = style14;
row = sheet.CreateRow(12); //第12行
cell = row.CreateCell(1);
cell.SetCellValue("買 受 人 ");
cell.CellStyle = style14;
region = new CellRangeAddress(12, 12, 2, 3);
sheet.AddMergedRegion(region);
cell = row.CreateCell(2);
cell.SetCellValue("台灣電力股份有限公司桃園區營業處");
cell.CellStyle = buttomLineBlue14;
row = sheet.CreateRow(13); //第13行
cell = row.CreateCell(1);
cell.SetCellValue("統一編號 ");
cell.CellStyle = style14;
cell = row.CreateCell(2);
cell.SetCellValue("02488533");
cell.CellStyle = buttomLineBlue14;
row = sheet.CreateRow(14); //第14行
cell = row.CreateCell(1);
cell.SetCellValue("地  址:");
cell.CellStyle = style14;
region = new CellRangeAddress(14, 14, 2, 4);
sheet.AddMergedRegion(region);
cell = row.CreateCell(2);
cell.SetCellValue("330桃園市觀音區中山路一段280巷90號(屋頂)");
cell.CellStyle = buttomLineBlue14;
row = sheet.CreateRow(16); //第16行
region = new CellRangeAddress(16, 16, 1, 2);
sheet.AddMergedRegion(region);
cell = row.CreateCell(1);
cell.SetCellValue("統一發票開立內容:");
cell.CellStyle = style14;
row = sheet.CreateRow(17); //第17行
cell = row.CreateCell(1);
cell.SetCellValue("項次");
cell.CellStyle = style14upleft;
cell = row.CreateCell(2);
cell.SetCellValue("品名");
cell.CellStyle = style14up;
cell = row.CreateCell(3);
cell.SetCellValue("數量");
cell.CellStyle = style14up;
cell = row.CreateCell(4);
cell.SetCellValue("發票開立金額(含稅)");
cell.CellStyle = style14up;
cell = row.CreateCell(5);
region = new CellRangeAddress(17, 17, 5, 6);
sheet.AddMergedRegion(region);
cell.SetCellValue("備註(Memo)");
cell.CellStyle = style14up;
cell = row.CreateCell(6);
cell.CellStyle = style14up;
var ms = new NpoiMemoryStream
{
AllowClose = false
};
workbook.Write(ms);
ms.Flush();
ms.Seek(0, SeekOrigin.Begin);
return File(ms, "application/vnd.ms-excel", "台電躉售發票" + ".xlsx");
}
} }
} }

View File

@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel; using NPOI.SS.UserModel;
using NPOI.SS.Util; using NPOI.SS.Util;
using NPOI.XSSF.UserModel; using NPOI.XSSF.UserModel;
@ -292,7 +293,7 @@ namespace SolarPower.Controllers
foreach (var head in Formhead.Result.Data.Inv) foreach (var head in Formhead.Result.Data.Inv)
{ {
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(dbody[head] == null ? "0" : dbody[head].ToString()); cell.SetCellValue(dbody[head] == null ? 0 : Convert.ToDouble(dbody[head].ToString()));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
} }
@ -311,12 +312,12 @@ namespace SolarPower.Controllers
cell = row.CreateCell(index); cell = row.CreateCell(index);
if (dbody[bodyname] == null) if (dbody[bodyname] == null)
{ {
cell.SetCellValue("0"); cell.SetCellValue(0);
} }
else else
{ {
var c = dbody[bodyname].ToString(); var c = dbody[bodyname].ToString();
cell.SetCellValue(c); cell.SetCellValue(Convert.ToDouble(c));
} }
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
@ -333,7 +334,7 @@ namespace SolarPower.Controllers
cell.SetCellValue("日照小時:"); cell.SetCellValue("日照小時:");
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
cell = row.CreateCell(1); cell = row.CreateCell(1);
cell.SetCellValue(thour); cell.SetCellValue(Convert.ToDouble(thour));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
RowPosition++; RowPosition++;
@ -343,7 +344,7 @@ namespace SolarPower.Controllers
cell.SetCellValue("kWH/kWP:"); cell.SetCellValue("kWH/kWP:");
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
cell = row.CreateCell(1); cell = row.CreateCell(1);
cell.SetCellValue(kWhkwp); cell.SetCellValue(Convert.ToDouble(kWhkwp));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
RowPosition++; RowPosition++;
@ -353,7 +354,7 @@ namespace SolarPower.Controllers
cell.SetCellValue("PR%:"); cell.SetCellValue("PR%:");
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
cell = row.CreateCell(1); cell = row.CreateCell(1);
cell.SetCellValue(tpr); cell.SetCellValue(Convert.ToDouble(tpr));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
RowPosition++; RowPosition++;
@ -364,7 +365,7 @@ namespace SolarPower.Controllers
cell.SetCellValue("日發電量(kWh):"); cell.SetCellValue("日發電量(kWh):");
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
cell = row.CreateCell(1); cell = row.CreateCell(1);
cell.SetCellValue(tkwh); cell.SetCellValue(Convert.ToDouble(tkwh));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
RowPosition++; RowPosition++;
@ -377,7 +378,7 @@ namespace SolarPower.Controllers
cell.SetCellValue("日售電金額(NTD):"); cell.SetCellValue("日售電金額(NTD):");
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
cell = row.CreateCell(1); cell = row.CreateCell(1);
cell.SetCellValue(ntd); cell.SetCellValue(Convert.ToDouble(ntd));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
RowPosition++; RowPosition++;
@ -387,7 +388,7 @@ namespace SolarPower.Controllers
cell.SetCellValue("日售電單價(NTD):"); cell.SetCellValue("日售電單價(NTD):");
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
cell = row.CreateCell(1); cell = row.CreateCell(1);
cell.SetCellValue(ntdone); cell.SetCellValue(Convert.ToDouble(ntdone));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
} }
@ -470,7 +471,7 @@ namespace SolarPower.Controllers
foreach (var head in Formhead.Result.Data.Inv) foreach (var head in Formhead.Result.Data.Inv)
{ {
cell2 = row2.CreateCell(index2); cell2 = row2.CreateCell(index2);
cell2.SetCellValue(dbody[head] == null ? "0": dbody[head].ToString()); cell2.SetCellValue(dbody[head] == null ? 0 : Convert.ToDouble(dbody[head].ToString()));
cell2.CellStyle = styleLine12; cell2.CellStyle = styleLine12;
index2++; index2++;
} }
@ -492,12 +493,12 @@ namespace SolarPower.Controllers
cell2 = row2.CreateCell(index2); cell2 = row2.CreateCell(index2);
if (dbody[bodyname] == null) if (dbody[bodyname] == null)
{ {
cell2.SetCellValue("0"); cell2.SetCellValue(0);
} }
else else
{ {
var c = dbody[bodyname].ToString(); var c = dbody[bodyname].ToString();
cell2.SetCellValue(c); cell2.SetCellValue(Convert.ToDouble(c));
} }
cell2.CellStyle = styleLine12; cell2.CellStyle = styleLine12;
index2++; index2++;
@ -562,13 +563,13 @@ namespace SolarPower.Controllers
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(monthKWH); cell.SetCellValue(Convert.ToDouble(monthKWH));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
if (Formhead.Result.Data.ShowMoney == 1) if (Formhead.Result.Data.ShowMoney == 1)
{ {
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(monthmoney); cell.SetCellValue(Convert.ToDouble(monthmoney));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
@ -625,11 +626,11 @@ namespace SolarPower.Controllers
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) * Convert.ToDouble(a.LeaseRate) /100,2).ToString()); cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) * Convert.ToDouble(a.LeaseRate) /100,2));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) * Convert.ToDouble(a.LeaseRate) / 100 * 1.05, 2).ToString()); cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) * Convert.ToDouble(a.LeaseRate) / 100 * 1.05, 2));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
} }
@ -843,7 +844,7 @@ namespace SolarPower.Controllers
foreach (var head in Formhead.Result.Data.Inv) foreach (var head in Formhead.Result.Data.Inv)
{ {
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(dbody[head] == null ? "0" : dbody[head].ToString()); cell.SetCellValue(dbody[head] == null ? 0 : Convert.ToDouble(dbody[head].ToString()));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
} }
@ -862,12 +863,12 @@ namespace SolarPower.Controllers
cell = row.CreateCell(index); cell = row.CreateCell(index);
if (dbody[bodyname] == null) if (dbody[bodyname] == null)
{ {
cell.SetCellValue("0"); cell.SetCellValue(0);
} }
else else
{ {
var c = dbody[bodyname].ToString(); var c = dbody[bodyname].ToString();
cell.SetCellValue(c); cell.SetCellValue(Convert.ToDouble(Convert.ToDouble(c)));
} }
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
@ -884,7 +885,7 @@ namespace SolarPower.Controllers
cell.SetCellValue("日照小時:"); cell.SetCellValue("日照小時:");
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
cell = row.CreateCell(1); cell = row.CreateCell(1);
cell.SetCellValue(thour); cell.SetCellValue(Convert.ToDouble(thour));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
RowPosition++; RowPosition++;
@ -894,7 +895,7 @@ namespace SolarPower.Controllers
cell.SetCellValue("kWH/kWP:"); cell.SetCellValue("kWH/kWP:");
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
cell = row.CreateCell(1); cell = row.CreateCell(1);
cell.SetCellValue(kWhkwp); cell.SetCellValue(Convert.ToDouble(kWhkwp));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
RowPosition++; RowPosition++;
@ -904,7 +905,7 @@ namespace SolarPower.Controllers
cell.SetCellValue("PR%:"); cell.SetCellValue("PR%:");
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
cell = row.CreateCell(1); cell = row.CreateCell(1);
cell.SetCellValue(tpr); cell.SetCellValue(Convert.ToDouble(tpr));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
RowPosition++; RowPosition++;
@ -915,7 +916,7 @@ namespace SolarPower.Controllers
cell.SetCellValue("日發電量(kWh):"); cell.SetCellValue("日發電量(kWh):");
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
cell = row.CreateCell(1); cell = row.CreateCell(1);
cell.SetCellValue(tkwh); cell.SetCellValue(Convert.ToDouble(tkwh));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
RowPosition++; RowPosition++;
@ -928,7 +929,7 @@ namespace SolarPower.Controllers
cell.SetCellValue("日售電金額(NTD):"); cell.SetCellValue("日售電金額(NTD):");
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
cell = row.CreateCell(1); cell = row.CreateCell(1);
cell.SetCellValue(ntd); cell.SetCellValue(Convert.ToDouble(ntd));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
RowPosition++; RowPosition++;
@ -938,7 +939,7 @@ namespace SolarPower.Controllers
cell.SetCellValue("日售電單價(NTD):"); cell.SetCellValue("日售電單價(NTD):");
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
cell = row.CreateCell(1); cell = row.CreateCell(1);
cell.SetCellValue(ntdone); cell.SetCellValue(Convert.ToDouble(ntdone));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
} }
@ -1021,7 +1022,7 @@ namespace SolarPower.Controllers
foreach (var head in Formhead.Result.Data.Inv) foreach (var head in Formhead.Result.Data.Inv)
{ {
cell2 = row2.CreateCell(index2); cell2 = row2.CreateCell(index2);
cell2.SetCellValue(dbody[head] == null ? "0" : dbody[head].ToString()); cell2.SetCellValue(dbody[head] == null ? 0 : Convert.ToDouble(dbody[head].ToString()));
cell2.CellStyle = styleLine12; cell2.CellStyle = styleLine12;
index2++; index2++;
} }
@ -1043,12 +1044,12 @@ namespace SolarPower.Controllers
cell2 = row2.CreateCell(index2); cell2 = row2.CreateCell(index2);
if (dbody[bodyname] == null) if (dbody[bodyname] == null)
{ {
cell2.SetCellValue("0"); cell2.SetCellValue(0);
} }
else else
{ {
var c = dbody[bodyname].ToString(); var c = dbody[bodyname].ToString();
cell2.SetCellValue(c); cell2.SetCellValue(Convert.ToDouble(c));
} }
cell2.CellStyle = styleLine12; cell2.CellStyle = styleLine12;
index2++; index2++;
@ -1113,13 +1114,13 @@ namespace SolarPower.Controllers
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(monthKWH); cell.SetCellValue(Convert.ToDouble(monthKWH));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
if (Formhead.Result.Data.ShowMoney == 1) if (Formhead.Result.Data.ShowMoney == 1)
{ {
cell = row.CreateCell(index); cell = row.CreateCell(index);
cell.SetCellValue(monthmoney); cell.SetCellValue(Convert.ToDouble(monthmoney));
cell.CellStyle = styleLine12; cell.CellStyle = styleLine12;
index++; index++;
cell = row.CreateCell(index); cell = row.CreateCell(index);

View File

@ -2113,6 +2113,11 @@ ALTER TABLE `notice_schedule`
ADD COLUMN `UserId` TINYINT(1) UNSIGNED NOT NULL COMMENT '帳號Id' AFTER `Type`, ADD COLUMN `UserId` TINYINT(1) UNSIGNED NOT NULL COMMENT '帳號Id' AFTER `Type`,
ADD COLUMN `EmailType` TINYINT(1) UNSIGNED NULL DEFAULT NULL COMMENT '發送種類' AFTER `UserId`; ADD COLUMN `EmailType` TINYINT(1) UNSIGNED NULL DEFAULT NULL COMMENT '發送種類' AFTER `UserId`;
-- 新增發票相關資訊 20210810
ALTER TABLE `power_station`
ADD COLUMN `GUINumber` VARCHAR(16) NULL DEFAULT NULL COMMENT '統一編號' AFTER `BoERentRatio`,
ADD COLUMN `TPCInvoiceBuyer` VARCHAR(100) NULL DEFAULT NULL COMMENT '台電發票買受人' AFTER `TPCContractNumber`,
ADD COLUMN `TPCInvoiceAddress` VARCHAR(100) NULL DEFAULT NULL COMMENT '台電發票地址' AFTER `TPCInvoiceBuyer`;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */; /*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

View File

@ -35,6 +35,15 @@ namespace SolarPower.Models
public string Time { get; set; } public string Time { get; set; }
public int SearchType { get; set; } public int SearchType { get; set; }
} }
public class BillInfo
{
public double Money { get; set; }
public string GUINumber { get; set; }
public string TPCInvoiceBuyer { get; set; }
public string TPCInvoiceAddress { get; set; }
public string Name { get; set; }
public string Logo { get; set; }
}
} }

View File

@ -363,7 +363,7 @@ namespace SolarPower.Quartz.Jobs
calcPowerStation.TodayWeatherTemp = Convert.ToDouble(Location.WeatherElement[0].ElementValue); calcPowerStation.TodayWeatherTemp = Convert.ToDouble(Location.WeatherElement[0].ElementValue);
weatherObservation.PowerStationId = powerStation.Id; weatherObservation.PowerStationId = powerStation.Id;
weatherObservation.Temp = Convert.ToDouble(Location.WeatherElement[0].ElementValue); weatherObservation.Temp = Convert.ToDouble(Location.WeatherElement[0].ElementValue);
weatherObservation.ObsTime = Convert.ToInt32(Location.Time.ObsTime.Substring(0, 4)) < 1970 ? null : Location.Time.ObsTime; weatherObservation.ObsTime = Convert.ToInt32(Location.Time.ObsTime.Substring(0, 4)) < 1970 ? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : Location.Time.ObsTime;
calcPowerStation.WeathersStationId = powerStation.WeathersStationId; calcPowerStation.WeathersStationId = powerStation.WeathersStationId;
break; break;
} }

View File

@ -566,7 +566,10 @@ namespace SolarPower.Repository.Implement
`BoEDiscountRate` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '', `BoEDiscountRate` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '',
`BoEDeviceRegisterNumber` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '', `BoEDeviceRegisterNumber` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`BoERentRatio` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '(%)', `BoERentRatio` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '(%)',
`GUINumber` varchar(16) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`TPCContractNumber` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '', `TPCContractNumber` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`TPCInvoiceBuyer` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`TPCInvoiceAddress` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`TPCContractAt` timestamp NULL DEFAULT NULL COMMENT '', `TPCContractAt` timestamp NULL DEFAULT NULL COMMENT '',
`TPCSellDeadline` int(10) unsigned DEFAULT '0' COMMENT '()', `TPCSellDeadline` int(10) unsigned DEFAULT '0' COMMENT '()',
`TPCMeterReading` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '', `TPCMeterReading` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '',

View File

@ -73,5 +73,31 @@ namespace SolarPower.Repository.Implement
} }
} }
public async Task<BillInfo> GetBill (int id)
{
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
BillInfo a = new BillInfo();
try
{
var sql = @$"SELECT es.Money,ps.GUINumber,ps.TPCInvoiceBuyer,ps.TPCInvoiceAddress,cp.Name,cp.Logo,ps.Id
FROM electricity_sold_record es
LEFT JOIN power_station ps
ON es.PowerstationId = ps.Id
LEFT JOIN company cp
ON cp.Id = ps.CompanyId
WHERE es.Id = {id}";
a = await conn.QueryFirstOrDefaultAsync<BillInfo>(sql);
}
catch (Exception exception)
{
throw exception;
}
return a;
}
}
} }
} }

View File

@ -9,5 +9,6 @@ namespace SolarPower.Repository.Interface
public interface IElectricitySoldRecordRepository: IRepositoryBase<ElectricitySoldRecord> public interface IElectricitySoldRecordRepository: IRepositoryBase<ElectricitySoldRecord>
{ {
Task<List<ElectricitySoldRecordTable>> RecordTable(ElectricitySoldRecordTablePost post); Task<List<ElectricitySoldRecordTable>> RecordTable(ElectricitySoldRecordTablePost post);
Task<BillInfo> GetBill(int id);
} }
} }

View File

@ -627,9 +627,15 @@
$("#Money_modal").val(rel.data.money); $("#Money_modal").val(rel.data.money);
$("#Record-modal").modal(); $("#Record-modal").modal();
}, 'json'); }, 'json');
}); });
$('#RecordTable').on("click", "button.bill-btn", function () {
selected_id = $(this).parents('tr').attr('data-id');
window.location = "/ElectricitySoldRecord/BillExcel?post=" + selected_id;
})
$('#RecordTable').on("click", "button.del-btn", function () { $('#RecordTable').on("click", "button.del-btn", function () {
selected_id = $(this).parents('tr').attr('data-id'); selected_id = $(this).parents('tr').attr('data-id');
Swal.fire( Swal.fire(

View File

@ -953,16 +953,16 @@
} }
if (send_data.FormType != null && send_data.PowerStation.length != 0 && send_data.FormType != 2) { if (send_data.FormType != null && send_data.PowerStation.length != 0 && send_data.FormType != 2) {
window.location = "/StationReport/ExportExcel?post=" + JSON.stringify(send_data); window.location = "/StationReport/ExportExcel?post=" + JSON.stringify(send_data);
} else { }
else
{
if (send_data.FormType != 2) { if (send_data.FormType != 2) {
toast_warning("請先選擇電站及報表類型"); toast_warning("請先選擇電站及報表類型");
} }
} else
{
if (send_data.PowerStation.length != 0 && send_data.FormType == 2) {
window.location = "/StationReport/ExportExcelmaxtable?post=" + JSON.stringify(send_data); window.location = "/StationReport/ExportExcelmaxtable?post=" + JSON.stringify(send_data);
} else { }
toast_warning("請先選擇電站及報表類型");
} }
} }