From ce97d88bcab4ddbd96abd640eb616f7b2d4b518c Mon Sep 17 00:00:00 2001 From: b110212000 Date: Thu, 12 Aug 2021 10:34:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BC=E7=A5=A8=E5=90=AB=E5=9C=96=E7=89=87(?= =?UTF-8?q?=E5=AE=8C=E6=88=90)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricitySoldRecordController.cs | 310 +++++++++++++++++- SolarPower/Models/ElectricitySoldRecord.cs | 6 +- .../ElectricitySoldRecordRepository.cs | 3 +- 3 files changed, 311 insertions(+), 8 deletions(-) diff --git a/SolarPower/Controllers/ElectricitySoldRecordController.cs b/SolarPower/Controllers/ElectricitySoldRecordController.cs index a8092fb..2ed6abd 100644 --- a/SolarPower/Controllers/ElectricitySoldRecordController.cs +++ b/SolarPower/Controllers/ElectricitySoldRecordController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; +using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.SS.Util; using NPOI.XSSF.UserModel; @@ -233,11 +234,16 @@ namespace SolarPower.Controllers //stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; //stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; //stylein12.WrapText = true; + IFont font14NoBold = workbook.CreateFont(); + font14NoBold.FontName = "新細明體"; + font14NoBold.FontHeightInPoints = 14; + font14NoBold.IsBold = false; IFont font14 = workbook.CreateFont(); font14.FontName = "新細明體"; font14.FontHeightInPoints = 14; font14.IsBold = true; + ICellStyle style14 = workbook.CreateCellStyle(); style14.SetFont(font14); style14.Alignment = HorizontalAlignment.Left; @@ -251,6 +257,7 @@ namespace SolarPower.Controllers 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; @@ -273,7 +280,65 @@ namespace SolarPower.Controllers style14up.BorderRight = BorderStyle.Thin; style14up.BorderBottom = BorderStyle.Thin; + ICellStyle style14upright = workbook.CreateCellStyle(); + style14upright.SetFont(font14); + style14upright.Alignment = HorizontalAlignment.Center; + style14upright.VerticalAlignment = VerticalAlignment.Center; + style14upright.BorderTop = BorderStyle.Medium; + style14upright.BorderLeft = BorderStyle.Thin; + style14upright.BorderRight = BorderStyle.Medium; + style14upright.BorderBottom = BorderStyle.Thin; + ICellStyle style14bodyleft = workbook.CreateCellStyle(); + style14bodyleft.SetFont(font14NoBold); + style14bodyleft.Alignment = HorizontalAlignment.Center; + style14bodyleft.VerticalAlignment = VerticalAlignment.Center; + style14bodyleft.BorderTop = BorderStyle.Thin; + style14bodyleft.BorderLeft = BorderStyle.Medium; + style14bodyleft.BorderRight = BorderStyle.Thin; + style14bodyleft.BorderBottom = BorderStyle.Thin; + + ICellStyle style14body = workbook.CreateCellStyle(); + style14body.SetFont(font14NoBold); + style14body.Alignment = HorizontalAlignment.Center; + style14body.VerticalAlignment = VerticalAlignment.Center; + style14body.BorderTop = BorderStyle.Thin; + style14body.BorderLeft = BorderStyle.Thin; + style14body.BorderRight = BorderStyle.Thin; + style14body.BorderBottom = BorderStyle.Thin; + + ICellStyle style14bodyright = workbook.CreateCellStyle(); + style14bodyright.SetFont(font14NoBold); + style14bodyright.Alignment = HorizontalAlignment.Center; + style14bodyright.VerticalAlignment = VerticalAlignment.Center; + style14bodyright.BorderTop = BorderStyle.Thin; + style14bodyright.BorderLeft = BorderStyle.Thin; + style14bodyright.BorderRight = BorderStyle.Medium; + style14bodyright.BorderBottom = BorderStyle.Thin; + + ICellStyle style14bodyrightnoborder = workbook.CreateCellStyle(); + style14bodyrightnoborder.SetFont(font14); + style14bodyrightnoborder.Alignment = HorizontalAlignment.Left; + style14bodyrightnoborder.VerticalAlignment = VerticalAlignment.Center; + style14bodyrightnoborder.BorderTop = BorderStyle.None; + style14bodyrightnoborder.BorderBottom = BorderStyle.None; + style14bodyrightnoborder.BorderLeft = BorderStyle.None; + style14bodyrightnoborder.BorderRight = BorderStyle.Medium; + + ICellStyle style14bodyleftnoborder = workbook.CreateCellStyle(); + style14bodyleftnoborder.SetFont(font14); + style14bodyleftnoborder.Alignment = HorizontalAlignment.Left; + style14bodyleftnoborder.VerticalAlignment = VerticalAlignment.Center; + style14bodyleftnoborder.BorderLeft = BorderStyle.Medium; + style14bodyleftnoborder.WrapText = true; + + ICellStyle style14bodyleftrigrtbottom = workbook.CreateCellStyle(); + style14bodyleftrigrtbottom.SetFont(font14); + style14bodyleftrigrtbottom.Alignment = HorizontalAlignment.Left; + style14bodyleftrigrtbottom.VerticalAlignment = VerticalAlignment.Center; + style14bodyleftrigrtbottom.BorderRight = BorderStyle.Medium; + style14bodyleftrigrtbottom.BorderBottom = BorderStyle.Medium; + style14bodyleftrigrtbottom.BorderLeft = BorderStyle.Medium; #endregion var bill = electricitySoldRecordRepository.GetBill(post); @@ -286,8 +351,8 @@ namespace SolarPower.Controllers 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); + sheet.SetColumnWidth(5, 5 * 160 * 8); + sheet.SetColumnWidth(6, 5 * 160 * 8); CellRangeAddress region; row = sheet.CreateRow(1); @@ -297,6 +362,14 @@ namespace SolarPower.Controllers cell.SetCellValue(bill.Result.Name); cell.CellStyle = style26; + if(bill.Result.Logo != null) + { + byte[] bytes = System.IO.File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "company_logo", bill.Result.Logo)); + XSSFDrawing patriarch = (XSSFDrawing)sheet.CreateDrawingPatriarch(); + XSSFClientAnchor regionr = (XSSFClientAnchor)patriarch.CreateAnchor(0, 0, 2, 2, 1, 1, 2, 3); + patriarch.CreatePicture(regionr, workbook.AddPicture(bytes, XSSFWorkbook.PICTURE_TYPE_JPEG)); + } + row = sheet.CreateRow(2); cell = row.CreateCell(1); region = new CellRangeAddress(2, 2, 1, 6); @@ -384,7 +457,7 @@ namespace SolarPower.Controllers region = new CellRangeAddress(12, 12, 2, 3); sheet.AddMergedRegion(region); cell = row.CreateCell(2); - cell.SetCellValue("台灣電力股份有限公司桃園區營業處"); + cell.SetCellValue(bill.Result.TPCInvoiceBuyer); cell.CellStyle = buttomLineBlue14; row = sheet.CreateRow(13); //第13行 @@ -393,7 +466,7 @@ namespace SolarPower.Controllers cell.CellStyle = style14; cell = row.CreateCell(2); - cell.SetCellValue("02488533"); + cell.SetCellValue(bill.Result.GUINumber); cell.CellStyle = buttomLineBlue14; @@ -405,7 +478,7 @@ namespace SolarPower.Controllers region = new CellRangeAddress(14, 14, 2, 4); sheet.AddMergedRegion(region); cell = row.CreateCell(2); - cell.SetCellValue("330桃園市觀音區中山路一段280巷90號(屋頂)"); + cell.SetCellValue(bill.Result.TPCInvoiceAddress); cell.CellStyle = buttomLineBlue14; row = sheet.CreateRow(16); //第16行 @@ -439,15 +512,240 @@ namespace SolarPower.Controllers cell.CellStyle = style14up; cell = row.CreateCell(6); - cell.CellStyle = style14up; + cell.CellStyle = style14upright; + + row = sheet.CreateRow(18); //第18行 + cell = row.CreateCell(1); + cell.SetCellValue(1); + cell.CellStyle = style14bodyleft; + + cell = row.CreateCell(2); + cell.SetCellValue("太陽光電售電"); + cell.CellStyle = style14body; + + cell = row.CreateCell(3); + cell.SetCellValue(1); + cell.CellStyle = style14body; + + cell = row.CreateCell(4); + cell.SetCellValue(bill.Result.Money); + + ICellStyle style0 = workbook.CreateCellStyle(); + IDataFormat dataformat = workbook.CreateDataFormat(); + style0.DataFormat = dataformat.GetFormat("$#,##0"); + style0.SetFont(font14NoBold); + style0.Alignment = HorizontalAlignment.Center; + style0.VerticalAlignment = VerticalAlignment.Center; + style0.BorderTop = BorderStyle.Thin; + style0.BorderLeft = BorderStyle.Thin; + style0.BorderRight = BorderStyle.Thin; + style0.BorderBottom = BorderStyle.Thin; + cell.CellStyle = style0; + + cell = row.CreateCell(5); + region = new CellRangeAddress(18, 18, 5, 6); + sheet.AddMergedRegion(region); + cell.CellStyle = style14body; + + cell = row.CreateCell(6); + cell.CellStyle = style14bodyright; + + + for(var index = 19;index < 26;index++) + { + row = sheet.CreateRow(index); //第19行 + cell = row.CreateCell(1); + if(index != 25){ + cell.SetCellValue(index - 17); + } + else{ + cell.SetCellValue("合計"); + } + cell.CellStyle = style14bodyleft; + + cell = row.CreateCell(2); + cell.CellStyle = style14body; + + cell = row.CreateCell(3); + cell.CellStyle = style14body; + + cell = row.CreateCell(4); + if (index == 25){ + cell.CellStyle = style0; + cell.SetCellValue(bill.Result.Money); + } + else{ + cell.CellStyle = style14body; + } + + + cell = row.CreateCell(5); + region = new CellRangeAddress(index, index, 5, 6); + sheet.AddMergedRegion(region); + cell.CellStyle = style14body; + + cell = row.CreateCell(6); + cell.CellStyle = style14bodyright; + } //第19-25行 + + row = sheet.CreateRow(26); //第26行 + region = new CellRangeAddress(26, 26, 1, 6); + sheet.AddMergedRegion(region); + cell = row.CreateCell(1); + cell.SetCellValue("說明(請略述發票開立性質及金額計算):"); + cell.CellStyle = style14bodyleftnoborder; + + cell = row.CreateCell(6); + cell.CellStyle = style14bodyrightnoborder; + row = sheet.CreateRow(27); //第27行 + region = new CellRangeAddress(27, 29, 1, 6); + sheet.AddMergedRegion(region); + cell = row.CreateCell(1); + cell.SetCellValue($"計算期間:{bill.Result.StartAt}-{bill.Result.EndAt} \r售電收入 = ( 度數 {bill.Result.Kwh} * 費率{Math.Round(bill.Result.Money / 1.05 / bill.Result.Kwh,2)}) * 1.05 = {bill.Result.Money} 元"); + cell.CellStyle = style14bodyleftnoborder; + cell = row.CreateCell(6); + cell.CellStyle = style14bodyrightnoborder; + row = sheet.CreateRow(28); //第28行 + cell = row.CreateCell(1); + cell.CellStyle = style14bodyleftnoborder; + cell = row.CreateCell(6); + cell.CellStyle = style14bodyrightnoborder; + row = sheet.CreateRow(29); //第29行 + cell = row.CreateCell(1); + cell.CellStyle = style14bodyleftnoborder; + cell = row.CreateCell(6); + cell.CellStyle = style14bodyrightnoborder; + row = sheet.CreateRow(30); //第30行 + cell = row.CreateCell(1); + cell.CellStyle = style14bodyleftnoborder; + cell = row.CreateCell(6); + cell.CellStyle = style14bodyrightnoborder; + row = sheet.CreateRow(31); //第31行 + cell = row.CreateCell(1); + cell.SetCellValue("入帳會計科目:"); + cell.CellStyle = style14bodyleftnoborder; + cell = row.CreateCell(2); + cell.SetCellValue("售電收入"); + cell.CellStyle = style14; + cell = row.CreateCell(6); + cell.CellStyle = style14bodyrightnoborder; + + row = sheet.CreateRow(32); //第32行 + cell = row.CreateCell(1); + cell.SetCellValue("入帳成本中心:"); + cell.CellStyle = style14bodyleftnoborder; + + cell = row.CreateCell(6); + cell.CellStyle = style14bodyrightnoborder; + + row = sheet.CreateRow(33); //第32行 + cell = row.CreateCell(1); + cell.CellStyle = style14bodyleftnoborder; + + cell = row.CreateCell(6); + cell.CellStyle = style14bodyrightnoborder; + + row = sheet.CreateRow(34); //第34行 + cell = row.CreateCell(1); + cell.SetCellValue("備註:"); + cell.CellStyle = style14bodyleftnoborder; + + cell = row.CreateCell(6); + cell.CellStyle = style14bodyrightnoborder; + + row = sheet.CreateRow(35); //第35行 + cell = row.CreateCell(1); + region = new CellRangeAddress(35, 35, 1, 6); + sheet.AddMergedRegion(region); + cell.SetCellValue(" 1.請申請人提醒客戶付款期限為收到發票後30天內,以匯款方式給付於旭天能源指定之帳戶。"); + cell.CellStyle = style14bodyleftnoborder; + + cell = row.CreateCell(6); + cell.CellStyle = style14bodyrightnoborder; + + row = sheet.CreateRow(36); //第36行 + cell = row.CreateCell(1); + region = new CellRangeAddress(36, 36, 1, 6); + sheet.AddMergedRegion(region); + cell.SetCellValue(" 2.申請人應於收到客戶匯款時,填具收入繳存單交予出納,並請於收入繳存單上註明發票號碼。"); + cell.CellStyle = style14bodyleftnoborder; + + cell = row.CreateCell(6); + cell.CellStyle = style14bodyrightnoborder; + + row = sheet.CreateRow(37); //第37行 + cell = row.CreateCell(1); + region = new CellRangeAddress(37, 37, 1, 6); + sheet.AddMergedRegion(region); + cell.SetCellValue(" 3. 發票如需作廢或更改者,應於次月五日前通知會計部,逾期恕不受理。"); + cell.CellStyle = style14bodyleftnoborder; + + cell = row.CreateCell(6); + cell.CellStyle = style14bodyrightnoborder; + + row = sheet.CreateRow(38); //第38行 + cell = row.CreateCell(1); + region = new CellRangeAddress(38, 38, 1, 6); + sheet.AddMergedRegion(region); + cell.SetCellValue(" 4. 發票內容確認無誤後,請於發票領取人簽收欄內簽名。"); + cell.CellStyle = style14bodyleftnoborder; + + cell = row.CreateCell(6); + cell.CellStyle = style14bodyrightnoborder; + + row = sheet.CreateRow(39); //第39行 + cell = row.CreateCell(1); + region = new CellRangeAddress(39, 39, 1, 6); + sheet.AddMergedRegion(region); + cell.SetCellValue(" 5. 申請人填具申請表單,至少須經L3主管(含)或以上之主管核准。"); + cell.CellStyle = style14bodyleftnoborder; + + cell = row.CreateCell(6); + cell.CellStyle = style14bodyrightnoborder; + + row = sheet.CreateRow(40); //第39行 + cell = row.CreateCell(1); + region = new CellRangeAddress(40, 40, 1, 6); + sheet.AddMergedRegion(region); + cell.SetCellValue(" 6. 若對上述內容有任何問題,請電會計部-旭天:Yuchi Lin #15220"); + cell.CellStyle = style14bodyleftrigrtbottom; + + for(int a = 2; a < 7; a++) + { + cell = row.CreateCell(a); + cell.CellStyle = style14bodyleftrigrtbottom; + } + + row = sheet.CreateRow(43); //第5行 + cell = row.CreateCell(1); + cell.SetCellValue("申 請 人 :"); + cell.CellStyle = style14; + + cell = row.CreateCell(2); + cell.CellStyle = buttomLine14; + + cell = row.CreateCell(3); + cell.SetCellValue("部門主管: "); + cell.CellStyle = style14; + + cell = row.CreateCell(4); + cell.CellStyle = buttomLine14; + + row = sheet.CreateRow(45); //第5行 + cell = row.CreateCell(5); + cell.SetCellValue("發票領取人簽收:"); + cell.CellStyle = style14; + + cell = row.CreateCell(6); + cell.CellStyle = buttomLine14; var ms = new NpoiMemoryStream { diff --git a/SolarPower/Models/ElectricitySoldRecord.cs b/SolarPower/Models/ElectricitySoldRecord.cs index c8b9cb4..903e59b 100644 --- a/SolarPower/Models/ElectricitySoldRecord.cs +++ b/SolarPower/Models/ElectricitySoldRecord.cs @@ -43,7 +43,11 @@ namespace SolarPower.Models public string TPCInvoiceAddress { get; set; } public string Name { get; set; } public string Logo { get; set; } - + private string startAt; + public string StartAt { get { return Convert.ToDateTime(startAt).ToString("yyyy/MM/dd"); } set { startAt = value; } } + private string endAt; + public string EndAt { get { return Convert.ToDateTime(endAt).ToString("yyyy/MM/dd"); } set { endAt = value; } } + public int Kwh { get; set; } } } diff --git a/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs b/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs index 8739af1..421f606 100644 --- a/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs +++ b/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs @@ -81,7 +81,8 @@ namespace SolarPower.Repository.Implement BillInfo a = new BillInfo(); try { - var sql = @$"SELECT es.Money,ps.GUINumber,ps.TPCInvoiceBuyer,ps.TPCInvoiceAddress,cp.Name,cp.Logo,ps.Id + var sql = @$"SELECT es.Money,ps.GUINumber,ps.TPCInvoiceBuyer,ps.TPCInvoiceAddress,cp.Name,cp.Logo,ps.Id, + es.StartAt,es.EndAt,es.Kwh FROM electricity_sold_record es LEFT JOIN power_station ps ON es.PowerstationId = ps.Id