diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index 70fffdbf..3d46195b 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -96,6 +96,10 @@ namespace QuotationMaker.Controllers XSSFRow row; ICell cell = null; + double saHeight = 0.0; + + + row = (XSSFRow)sheet.GetRow(1); //估價單名稱與報價日期 row.Cells[0].SetCellValue(row.Cells[0].StringCellValue.Replace("{quotation_date}", objDetail.quotation_date)); @@ -200,6 +204,187 @@ namespace QuotationMaker.Controllers } } + int saRowIndex = 16; + + //紀錄範例列位置 + //目前編輯列 + int editRowIndex = 7; + + //空白編輯列 + int blankIndex = 7; + //小計列位置 + int subTotalIndex = 8; + //AC列位置 + int acIndex = 9; + //此項目總金額位置 + int sutTotalAcIndex = 10; + //優惠總價為置 + int specTotalIndex = 12; + + //主項目編號 + int itemNumber = 0; + //開始產生項目價格列 + foreach (quotationMainItemDetail objMain in objDetail.quotationMainItemDetails) + { + itemNumber++; + + //目前開始要填資料的位置 + int editIndex = editRowIndex; + //目前主項目的個數(子項目加主項目) + int rowCount = 0; + + CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, editRowIndex, editRowIndex + 1); + blankIndex++; + subTotalIndex++; + acIndex++; + sutTotalAcIndex++; + specTotalIndex++; + saRowIndex++; + + foreach (quotationSubItem objSub in objMain.quotationSubItems) { + CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, editRowIndex, editRowIndex + 1); + editRowIndex++; + blankIndex++; + subTotalIndex++; + acIndex++; + sutTotalAcIndex++; + specTotalIndex ++; + saRowIndex++; + + rowCount++; + } + + //項目編號合併並填入編號 + sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(editIndex, editIndex + rowCount, 0, 0)); + sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(editIndex, editIndex, 1, 6)); + + row = (XSSFRow)sheet.GetRow(editIndex); + row.Cells[0].SetCellValue(itemNumber); + row.Cells[1].SetCellValue(objMain.quotationMainItem_name); + + int acTotal = 0; + + //合併子項目row + foreach (quotationSubItem objSub in objMain.quotationSubItems) + { + string descript = objSub.quotationSubItem_descript; + + if (objSub.quotationSubItem_hasAC == "N" && objMain.quotationMainItem_ac > 0) + { + descript = descript + " (此項不加AC)"; + } + + editIndex++; + row = (XSSFRow)sheet.GetRow(editIndex); + row.Height = -1; + row.Cells[1].SetCellValue(objSub.quotationSubItem_name); + row.Cells[2].SetCellValue(descript); + row.Cells[3].SetCellValue("NTD " + objSub.quotationSubItem_price.ToString("###,###")); + row.Cells[4].SetCellValue(objSub.quotationSubItem_number.ToString("###,###")); + row.Cells[5].SetCellValue(objSub.quotationSubItem_unitType); + row.Cells[6].SetCellValue(objSub.quotationSubItem_subTotal); + + if (objSub.quotationSubItem_hasAC == "Y") { + acTotal += (int)Math.Round((objSub.quotationSubItem_price * objSub.quotationSubItem_number) * (objMain.quotationMainItem_ac / 100)); + } + } + editIndex++; + editRowIndex++; + + sheet.ShiftRows(editIndex, sheet.LastRowNum, 3); + + blankIndex+=3; + subTotalIndex+=3; + acIndex+=3; + sutTotalAcIndex+=3; + specTotalIndex+=3; + saRowIndex += 3; + + //複製小計欄 + CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, subTotalIndex, editIndex); + + row = (XSSFRow)sheet.GetRow(editIndex); + row.Cells[6].SetCellValue("NTD " + (objMain.quotationMainItem_subTotal - acTotal).ToString("###,###")); + + + rowCount++; + + editIndex++; + editRowIndex++; + //複製AC欄 + CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, acIndex, editIndex); + + row = (XSSFRow)sheet.GetRow(editIndex); + row.Cells[6].SetCellValue("NTD " + acTotal.ToString("###,###")); + row.Cells[0].SetCellValue(row.Cells[0].StringCellValue.Replace("{quotationMainItem_ac}", objMain.quotationMainItem_ac.ToString())); + + rowCount++; + + editIndex++; + editRowIndex++; + //複製此項目總金額欄 + CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, sutTotalAcIndex, editIndex); + row = (XSSFRow)sheet.GetRow(editIndex); + row.Cells[6].SetCellValue("NTD " + (objMain.quotationMainItem_subTotal).ToString("###,###")); + + rowCount++; + editRowIndex++; + //break; + } + + //刪除不需要的優惠價格欄 + if (objDetail.quotation_specTotal == 0) { + + row = (XSSFRow)sheet.GetRow(specTotalIndex); + if (row != null) + { + sheet.RemoveRow(row); + sheet.ShiftRows(specTotalIndex + 1, sheet.LastRowNum, -1); + saRowIndex--; + } + } + + //刪除sutTotalAc + row = (XSSFRow)sheet.GetRow(sutTotalAcIndex); + if (row != null) + { + sheet.RemoveRow(row); + sheet.ShiftRows(sutTotalAcIndex + 1, sheet.LastRowNum, -1); + saRowIndex--; + } + + row = (XSSFRow)sheet.GetRow(acIndex); + if (row != null) + { + sheet.RemoveRow(row); + sheet.ShiftRows(acIndex + 1, sheet.LastRowNum, -1); + saRowIndex--; + } + + row = (XSSFRow)sheet.GetRow(subTotalIndex); + if (row != null) + { + sheet.RemoveRow(row); + sheet.ShiftRows(subTotalIndex + 1, sheet.LastRowNum, -1); + saRowIndex--; + } + + row = (XSSFRow)sheet.GetRow(blankIndex); + if (row != null) + { + sheet.RemoveRow(row); + sheet.ShiftRows(blankIndex + 1, sheet.LastRowNum, -1); + saRowIndex--; + } + + row = (XSSFRow)sheet.GetRow(saRowIndex); + row.Height = 8190; + + row = (XSSFRow)sheet.GetRow(saRowIndex + 1); + row.Height = 8190; + + row = (XSSFRow)sheet.GetRow(saRowIndex + 2); + row.Height = 4000; MemoryStream ms = new MemoryStream(); workbook.Write(ms); diff --git a/wwwroot/logo/bremen_temp.xlsx b/wwwroot/logo/bremen_temp.xlsx index be2982b7..15ee8eb8 100644 Binary files a/wwwroot/logo/bremen_temp.xlsx and b/wwwroot/logo/bremen_temp.xlsx differ diff --git a/wwwroot/logo/journeys_temp.xlsx b/wwwroot/logo/journeys_temp.xlsx index 059ef472..e7c255c0 100644 Binary files a/wwwroot/logo/journeys_temp.xlsx and b/wwwroot/logo/journeys_temp.xlsx differ