|
@@ -7,15 +7,13 @@ import com.ffii.tsms.modules.data.entity.CustomerType |
|
|
import com.ffii.tsms.modules.data.entity.CustomerRepository |
|
|
import com.ffii.tsms.modules.data.entity.CustomerRepository |
|
|
import com.ffii.tsms.modules.data.entity.CustomerTypeRepository |
|
|
import com.ffii.tsms.modules.data.entity.CustomerTypeRepository |
|
|
import com.ffii.tsms.modules.data.web.models.FinancialSummaryByClient |
|
|
import com.ffii.tsms.modules.data.web.models.FinancialSummaryByClient |
|
|
|
|
|
import com.ffii.tsms.modules.data.web.models.FinancialSummaryByProject |
|
|
import com.ffii.tsms.modules.data.web.models.SaveCustomerResponse |
|
|
import com.ffii.tsms.modules.data.web.models.SaveCustomerResponse |
|
|
import com.ffii.tsms.modules.project.entity.Invoice |
|
|
import com.ffii.tsms.modules.project.entity.Invoice |
|
|
import com.ffii.tsms.modules.project.entity.Project |
|
|
import com.ffii.tsms.modules.project.entity.Project |
|
|
import com.ffii.tsms.modules.project.web.models.SaveCustomerRequest |
|
|
import com.ffii.tsms.modules.project.web.models.SaveCustomerRequest |
|
|
import com.ffii.tsms.modules.timesheet.entity.Timesheet |
|
|
import com.ffii.tsms.modules.timesheet.entity.Timesheet |
|
|
import org.apache.poi.ss.usermodel.BorderStyle |
|
|
|
|
|
import org.apache.poi.ss.usermodel.HorizontalAlignment |
|
|
|
|
|
import org.apache.poi.ss.usermodel.Sheet |
|
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook |
|
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.* |
|
|
import org.apache.poi.ss.util.CellRangeAddress |
|
|
import org.apache.poi.ss.util.CellRangeAddress |
|
|
import org.apache.poi.ss.util.CellUtil |
|
|
import org.apache.poi.ss.util.CellUtil |
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook |
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook |
|
@@ -42,7 +40,7 @@ open class DashboardService( |
|
|
private val FORMATTED_TODAY = LocalDate.now().format(DATE_FORMATTER) |
|
|
private val FORMATTED_TODAY = LocalDate.now().format(DATE_FORMATTER) |
|
|
|
|
|
|
|
|
private val FINANCIAL_SUMMARY_FOR_CLIENT = "templates/report/[Dashboard] Financial Summary for client.xlsx" |
|
|
private val FINANCIAL_SUMMARY_FOR_CLIENT = "templates/report/[Dashboard] Financial Summary for client.xlsx" |
|
|
private val FINANCIAL_SUMMARY_FOR_PROJET = "templates/report/[Dashboard] Financial Summary for project.xlsx" |
|
|
|
|
|
|
|
|
private val FINANCIAL_SUMMARY_FOR_PROJECT = "templates/report/[Dashboard] Financial Summary for project.xlsx" |
|
|
|
|
|
|
|
|
fun CustomerSubsidiary(args: Map<String, Any>): List<Map<String, Any>> { |
|
|
fun CustomerSubsidiary(args: Map<String, Any>): List<Map<String, Any>> { |
|
|
val sql = StringBuilder("select" |
|
|
val sql = StringBuilder("select" |
|
@@ -2163,9 +2161,9 @@ open class DashboardService( |
|
|
fontName = "Times New Roman" |
|
|
fontName = "Times New Roman" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
val normalFontStyle = workbook.createCellStyle().apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// val normalFontStyle = workbook.createCellStyle().apply { |
|
|
|
|
|
// setFont(normalFont) |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
var rowIndex = 1 // Assuming the location is in (1,2), which is the report date field |
|
|
var rowIndex = 1 // Assuming the location is in (1,2), which is the report date field |
|
|
var columnIndex = 1 |
|
|
var columnIndex = 1 |
|
@@ -2178,19 +2176,25 @@ open class DashboardService( |
|
|
sheet.createRow(rowIndex++).apply { |
|
|
sheet.createRow(rowIndex++).apply { |
|
|
createCell(0).apply { |
|
|
createCell(0).apply { |
|
|
setCellValue(financialSummaryByClient.customerCode) |
|
|
setCellValue(financialSummaryByClient.customerCode) |
|
|
cellStyle = normalFontStyle |
|
|
|
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
} |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.LEFT) |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.LEFT) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
createCell(1).apply { |
|
|
createCell(1).apply { |
|
|
setCellValue(financialSummaryByClient.customerName) |
|
|
setCellValue(financialSummaryByClient.customerName) |
|
|
cellStyle = normalFontStyle |
|
|
|
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
dataFormat = accountingStyle |
|
|
|
|
|
} |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.LEFT) |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.LEFT) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
createCell(2).apply { |
|
|
createCell(2).apply { |
|
|
setCellValue(financialSummaryByClient.projectNo) |
|
|
setCellValue(financialSummaryByClient.projectNo) |
|
|
cellStyle = normalFontStyle.apply { |
|
|
|
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
dataFormat = accountingStyle |
|
|
dataFormat = accountingStyle |
|
|
} |
|
|
} |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.LEFT) |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.LEFT) |
|
@@ -2198,13 +2202,16 @@ open class DashboardService( |
|
|
|
|
|
|
|
|
createCell(3).apply { |
|
|
createCell(3).apply { |
|
|
cellFormula = "IF(E${rowIndex}>=1,\"Positive\",\"Negative\")" |
|
|
cellFormula = "IF(E${rowIndex}>=1,\"Positive\",\"Negative\")" |
|
|
cellStyle = normalFontStyle |
|
|
|
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
} |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.CENTER) |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.CENTER) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
createCell(4).apply { |
|
|
createCell(4).apply { |
|
|
cellFormula = "IFERROR(IF(K${rowIndex}=1, 0, K${rowIndex}/J${rowIndex}),0)" |
|
|
|
|
|
cellStyle = normalFontStyle.apply { |
|
|
|
|
|
|
|
|
cellFormula = "IFERROR(IF(K${rowIndex}=0, 0, K${rowIndex}/J${rowIndex}),0)" |
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
dataFormat = accountingStyle |
|
|
dataFormat = accountingStyle |
|
|
} |
|
|
} |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
@@ -2212,13 +2219,16 @@ open class DashboardService( |
|
|
|
|
|
|
|
|
createCell(5).apply { |
|
|
createCell(5).apply { |
|
|
cellFormula = "IF(G${rowIndex}>=1,\"Positive\",\"Negative\")" |
|
|
cellFormula = "IF(G${rowIndex}>=1,\"Positive\",\"Negative\")" |
|
|
cellStyle = normalFontStyle |
|
|
|
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
} |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.CENTER) |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.CENTER) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
createCell(6).apply { |
|
|
createCell(6).apply { |
|
|
cellFormula = "IFERROR(H${rowIndex}/J${rowIndex},0)" |
|
|
cellFormula = "IFERROR(H${rowIndex}/J${rowIndex},0)" |
|
|
cellStyle = normalFontStyle.apply { |
|
|
|
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
dataFormat = accountingStyle |
|
|
dataFormat = accountingStyle |
|
|
} |
|
|
} |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
@@ -2226,7 +2236,8 @@ open class DashboardService( |
|
|
|
|
|
|
|
|
createCell(7).apply { |
|
|
createCell(7).apply { |
|
|
setCellValue(financialSummaryByClient.totalFee) |
|
|
setCellValue(financialSummaryByClient.totalFee) |
|
|
cellStyle = normalFontStyle.apply { |
|
|
|
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
dataFormat = accountingStyle |
|
|
dataFormat = accountingStyle |
|
|
} |
|
|
} |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
@@ -2234,7 +2245,8 @@ open class DashboardService( |
|
|
|
|
|
|
|
|
createCell(8).apply { |
|
|
createCell(8).apply { |
|
|
cellFormula = "H${rowIndex}*80%" |
|
|
cellFormula = "H${rowIndex}*80%" |
|
|
cellStyle = normalFontStyle.apply { |
|
|
|
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
dataFormat = accountingStyle |
|
|
dataFormat = accountingStyle |
|
|
} |
|
|
} |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
@@ -2242,7 +2254,8 @@ open class DashboardService( |
|
|
|
|
|
|
|
|
createCell(9).apply { |
|
|
createCell(9).apply { |
|
|
setCellValue(financialSummaryByClient.cumulativeExpenditure) |
|
|
setCellValue(financialSummaryByClient.cumulativeExpenditure) |
|
|
cellStyle = normalFontStyle.apply { |
|
|
|
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
dataFormat = accountingStyle |
|
|
dataFormat = accountingStyle |
|
|
} |
|
|
} |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
@@ -2250,7 +2263,8 @@ open class DashboardService( |
|
|
|
|
|
|
|
|
createCell(10).apply { |
|
|
createCell(10).apply { |
|
|
setCellValue(financialSummaryByClient.totalInvoiced) |
|
|
setCellValue(financialSummaryByClient.totalInvoiced) |
|
|
cellStyle = normalFontStyle.apply { |
|
|
|
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
dataFormat = accountingStyle |
|
|
dataFormat = accountingStyle |
|
|
} |
|
|
} |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
@@ -2258,7 +2272,8 @@ open class DashboardService( |
|
|
|
|
|
|
|
|
createCell(11).apply { |
|
|
createCell(11).apply { |
|
|
cellFormula = "IF(H${rowIndex}-K${rowIndex}<0,0,H${rowIndex}-K${rowIndex})" |
|
|
cellFormula = "IF(H${rowIndex}-K${rowIndex}<0,0,H${rowIndex}-K${rowIndex})" |
|
|
cellStyle = normalFontStyle.apply { |
|
|
|
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
dataFormat = accountingStyle |
|
|
dataFormat = accountingStyle |
|
|
} |
|
|
} |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
@@ -2266,7 +2281,185 @@ open class DashboardService( |
|
|
|
|
|
|
|
|
createCell(12).apply { |
|
|
createCell(12).apply { |
|
|
setCellValue(financialSummaryByClient.totalReceived) |
|
|
setCellValue(financialSummaryByClient.totalReceived) |
|
|
cellStyle = normalFontStyle.apply { |
|
|
|
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
dataFormat = accountingStyle |
|
|
|
|
|
} |
|
|
|
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return workbook |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Throws(IOException::class) |
|
|
|
|
|
fun exportFinancialSummaryByProjectExcel( |
|
|
|
|
|
financialSummaryByProjects: List<FinancialSummaryByProject>, |
|
|
|
|
|
): ByteArray { |
|
|
|
|
|
// Generate the Excel report with query results |
|
|
|
|
|
val workbook: Workbook = |
|
|
|
|
|
createFinancialSummaryByProjectExcel(financialSummaryByProjects, FINANCIAL_SUMMARY_FOR_PROJECT) |
|
|
|
|
|
|
|
|
|
|
|
// Write the workbook to a ByteArrayOutputStream |
|
|
|
|
|
val outputStream: ByteArrayOutputStream = ByteArrayOutputStream() |
|
|
|
|
|
workbook.write(outputStream) |
|
|
|
|
|
workbook.close() |
|
|
|
|
|
|
|
|
|
|
|
return outputStream.toByteArray() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Throws(IOException::class) |
|
|
|
|
|
private fun createFinancialSummaryByProjectExcel( |
|
|
|
|
|
financialSummaryByProjects: List<FinancialSummaryByProject>, |
|
|
|
|
|
templatePath: String, |
|
|
|
|
|
): Workbook { |
|
|
|
|
|
// please create a new function for each report template |
|
|
|
|
|
val resource = ClassPathResource(templatePath) |
|
|
|
|
|
val templateInputStream = resource.inputStream |
|
|
|
|
|
val workbook: Workbook = XSSFWorkbook(templateInputStream) |
|
|
|
|
|
|
|
|
|
|
|
val sheet: Sheet = workbook.getSheetAt(0) |
|
|
|
|
|
|
|
|
|
|
|
// accounting style + comma style |
|
|
|
|
|
val accountingStyle = workbook.createDataFormat().getFormat("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)") |
|
|
|
|
|
|
|
|
|
|
|
// normal font |
|
|
|
|
|
val normalFont = workbook.createFont().apply { |
|
|
|
|
|
fontName = "Times New Roman" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// val normalFontStyle = workbook.createCellStyle().apply { |
|
|
|
|
|
// setFont(normalFont) |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
var rowIndex = 1 // Assuming the location is in (1,2), which is the report date field |
|
|
|
|
|
var columnIndex = 1 |
|
|
|
|
|
sheet.getRow(rowIndex).createCell(columnIndex).apply { |
|
|
|
|
|
setCellValue(FORMATTED_TODAY) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rowIndex = 4 |
|
|
|
|
|
financialSummaryByProjects.forEach { financialSummaryByProject: FinancialSummaryByProject -> |
|
|
|
|
|
sheet.createRow(rowIndex++).apply { |
|
|
|
|
|
createCell(0).apply { |
|
|
|
|
|
setCellValue(financialSummaryByProject.projectCode) |
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
} |
|
|
|
|
|
CellUtil.setAlignment(this, HorizontalAlignment.LEFT) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createCell(1).apply { |
|
|
|
|
|
setCellValue(financialSummaryByProject.projectName) |
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
dataFormat = accountingStyle |
|
|
|
|
|
} |
|
|
|
|
|
CellUtil.setAlignment(this, HorizontalAlignment.LEFT) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createCell(2).apply { |
|
|
|
|
|
setCellValue(financialSummaryByProject.customerName) |
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
dataFormat = accountingStyle |
|
|
|
|
|
} |
|
|
|
|
|
CellUtil.setAlignment(this, HorizontalAlignment.LEFT) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createCell(3).apply { |
|
|
|
|
|
setCellValue(financialSummaryByProject.subsidiaryName ?: "N/A") |
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
dataFormat = accountingStyle |
|
|
|
|
|
} |
|
|
|
|
|
CellUtil.setAlignment(this, HorizontalAlignment.LEFT) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createCell(4).apply { |
|
|
|
|
|
cellFormula = "IF(F${rowIndex}>=1,\"Positive\",\"Negative\")" |
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
} |
|
|
|
|
|
CellUtil.setAlignment(this, HorizontalAlignment.CENTER) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createCell(5).apply { |
|
|
|
|
|
cellFormula = "IFERROR(IF(L${rowIndex}=0, 0, K${rowIndex}/J${rowIndex}),0)" |
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
dataFormat = accountingStyle |
|
|
|
|
|
} |
|
|
|
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createCell(6).apply { |
|
|
|
|
|
cellFormula = "IF(H${rowIndex}>=1,\"Positive\",\"Negative\")" |
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
} |
|
|
|
|
|
CellUtil.setAlignment(this, HorizontalAlignment.CENTER) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createCell(7).apply { |
|
|
|
|
|
cellFormula = "IFERROR(I${rowIndex}/K${rowIndex},0)" |
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
dataFormat = accountingStyle |
|
|
|
|
|
} |
|
|
|
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createCell(8).apply { |
|
|
|
|
|
setCellValue(financialSummaryByProject.totalFee) |
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
dataFormat = accountingStyle |
|
|
|
|
|
} |
|
|
|
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createCell(9).apply { |
|
|
|
|
|
cellFormula = "I${rowIndex}*80%" |
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
dataFormat = accountingStyle |
|
|
|
|
|
} |
|
|
|
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createCell(10).apply { |
|
|
|
|
|
setCellValue(financialSummaryByProject.cumulativeExpenditure) |
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
dataFormat = accountingStyle |
|
|
|
|
|
} |
|
|
|
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createCell(11).apply { |
|
|
|
|
|
setCellValue(financialSummaryByProject.totalInvoiced) |
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
dataFormat = accountingStyle |
|
|
|
|
|
} |
|
|
|
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createCell(12).apply { |
|
|
|
|
|
cellFormula = "IF(I${rowIndex}-L${rowIndex}<0,0,I${rowIndex}-L${rowIndex})" |
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
|
|
|
dataFormat = accountingStyle |
|
|
|
|
|
} |
|
|
|
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createCell(13).apply { |
|
|
|
|
|
setCellValue(financialSummaryByProject.totalReceived) |
|
|
|
|
|
cellStyle.apply { |
|
|
|
|
|
setFont(normalFont) |
|
|
dataFormat = accountingStyle |
|
|
dataFormat = accountingStyle |
|
|
} |
|
|
} |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|
CellUtil.setAlignment(this, HorizontalAlignment.RIGHT) |
|
|