| @@ -381,6 +381,10 @@ open class ReportService( | |||||
| val monthStyle = workbook.createDataFormat().getFormat("mmm, yyyy") | val monthStyle = workbook.createDataFormat().getFormat("mmm, yyyy") | ||||
| val dateStyle = workbook.createDataFormat().getFormat("dd/mm/yyyy") | val dateStyle = workbook.createDataFormat().getFormat("dd/mm/yyyy") | ||||
| val boldStyle = workbook.createCellStyle() | |||||
| val boldFont = workbook.createFont() | |||||
| boldFont.bold = true | |||||
| boldStyle.setFont(boldFont) | |||||
| val daysOfMonth = (1..month.lengthOfMonth()).map { day -> | val daysOfMonth = (1..month.lengthOfMonth()).map { day -> | ||||
| val date = month.withDayOfMonth(day) | val date = month.withDayOfMonth(day) | ||||
| val formattedDate = date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) | val formattedDate = date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) | ||||
| @@ -390,8 +394,6 @@ open class ReportService( | |||||
| val sheet: Sheet = workbook.getSheetAt(0) | val sheet: Sheet = workbook.getSheetAt(0) | ||||
| val boldFont = sheet.workbook.createFont() | |||||
| boldFont.bold = true | |||||
| // sheet.forceFormulaRecalculation = true; //Calculate formulas | // sheet.forceFormulaRecalculation = true; //Calculate formulas | ||||
| 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 | ||||
| @@ -403,22 +405,27 @@ open class ReportService( | |||||
| var dayInt = 0 | var dayInt = 0 | ||||
| var tempCell: Cell | var tempCell: Cell | ||||
| tempCell = sheet.getRow(rowIndex).createCell(columnIndex) | |||||
| tempCell.setCellValue(FORMATTED_TODAY) | |||||
| sheet.getRow(rowIndex).createCell(columnIndex).apply { | |||||
| setCellValue(FORMATTED_TODAY) | |||||
| } | |||||
| rowIndex = 2 | rowIndex = 2 | ||||
| tempCell = sheet.getRow(rowIndex).createCell(columnIndex) | |||||
| tempCell.setCellValue(month) | |||||
| tempCell.cellStyle.dataFormat = monthStyle | |||||
| sheet.getRow(rowIndex).getCell(columnIndex).apply { | |||||
| setCellValue(month) | |||||
| // cellStyle.setFont(boldStyle) | |||||
| cellStyle.dataFormat = monthStyle | |||||
| } | |||||
| rowIndex = 3 | rowIndex = 3 | ||||
| tempCell. sheet.getRow(rowIndex).createCell(columnIndex) | |||||
| tempCell.setCellValue(staff.name) | |||||
| sheet.getRow(rowIndex).createCell(columnIndex).apply { | |||||
| setCellValue(staff.name) | |||||
| } | |||||
| rowIndex = 4 | rowIndex = 4 | ||||
| tempCell.sheet.getRow(rowIndex).createCell(columnIndex) | |||||
| tempCell.setCellValue(staff.team.name) | |||||
| sheet.getRow(rowIndex).createCell(columnIndex).apply { | |||||
| setCellValue(staff.team.name) | |||||
| } | |||||
| rowIndex = 5 | rowIndex = 5 | ||||
| tempCell = sheet.getRow(rowIndex).createCell(columnIndex) | tempCell = sheet.getRow(rowIndex).createCell(columnIndex) | ||||
| @@ -430,6 +437,7 @@ open class ReportService( | |||||
| val ThinBorderBottom: MutableMap<String?, Any?> = mutableMapOf() | val ThinBorderBottom: MutableMap<String?, Any?> = mutableMapOf() | ||||
| ThinBorderBottom["borderBottom"] = BorderStyle.THIN | ThinBorderBottom["borderBottom"] = BorderStyle.THIN | ||||
| ThinBorderBottom["wrapText"] = true | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| rowIndex = 7 | rowIndex = 7 | ||||
| daysOfMonth.forEach { dayInfo -> | daysOfMonth.forEach { dayInfo -> | ||||
| @@ -437,12 +445,12 @@ open class ReportService( | |||||
| rowSize++ | rowSize++ | ||||
| tempCell = sheet.getRow(rowIndex).createCell(0) | tempCell = sheet.getRow(rowIndex).createCell(0) | ||||
| tempCell.setCellValue(dayInfo.date) | tempCell.setCellValue(dayInfo.date) | ||||
| tempCell.cellStyle = boldStyle | |||||
| tempCell.cellStyle.dataFormat = dateStyle | tempCell.cellStyle.dataFormat = dateStyle | ||||
| tempCell.cellStyle.setFont(boldFont) | |||||
| // cellStyle.alignment = HorizontalAlignment.LEFT | // cellStyle.alignment = HorizontalAlignment.LEFT | ||||
| tempCell = sheet.getRow(rowIndex).createCell(1) | tempCell = sheet.getRow(rowIndex).createCell(1) | ||||
| tempCell.setCellValue(dayInfo.weekday) | tempCell.setCellValue(dayInfo.weekday) | ||||
| tempCell.cellStyle.setFont(boldFont) | |||||
| tempCell.cellStyle = boldStyle | |||||
| // cellStyle.alignment = HorizontalAlignment.LEFT | // cellStyle.alignment = HorizontalAlignment.LEFT | ||||
| } | } | ||||
| @@ -450,7 +458,7 @@ open class ReportService( | |||||
| tempCell = sheet.getRow(rowIndex).createCell(0) | tempCell = sheet.getRow(rowIndex).createCell(0) | ||||
| sheet.addMergedRegion(CellRangeAddress(rowIndex,rowIndex , 0, 1)) | sheet.addMergedRegion(CellRangeAddress(rowIndex,rowIndex , 0, 1)) | ||||
| tempCell.setCellValue("Sub-total") | tempCell.setCellValue("Sub-total") | ||||
| tempCell.cellStyle.setFont(boldFont) | |||||
| tempCell.cellStyle = boldStyle | |||||
| CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) | CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) | ||||
| CellUtil.setCellStyleProperties(tempCell, DoubleBorderBottom) | CellUtil.setCellStyleProperties(tempCell, DoubleBorderBottom) | ||||
| tempCell = sheet.getRow(rowIndex).createCell(1) | tempCell = sheet.getRow(rowIndex).createCell(1) | ||||
| @@ -459,6 +467,7 @@ open class ReportService( | |||||
| rowIndex += 1 | rowIndex += 1 | ||||
| tempCell = sheet.getRow(rowIndex).createCell(0) | tempCell = sheet.getRow(rowIndex).createCell(0) | ||||
| tempCell.setCellValue("Total Normal Hours [A]") | tempCell.setCellValue("Total Normal Hours [A]") | ||||
| tempCell.cellStyle = boldStyle | |||||
| CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) | CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) | ||||
| var normalConsumed = 0.0 | var normalConsumed = 0.0 | ||||
| @@ -479,8 +488,8 @@ open class ReportService( | |||||
| rowIndex += 1 | rowIndex += 1 | ||||
| tempCell = sheet.getRow(rowIndex).createCell(0) | tempCell = sheet.getRow(rowIndex).createCell(0) | ||||
| tempCell.setCellValue("Total Other Hours [B]") | tempCell.setCellValue("Total Other Hours [B]") | ||||
| tempCell.cellStyle = boldStyle | |||||
| CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) | CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) | ||||
| tempCell.cellStyle.setFont(boldFont) | |||||
| tempCell = sheet.getRow(rowIndex).createCell(2) | tempCell = sheet.getRow(rowIndex).createCell(2) | ||||
| tempCell.setCellValue(otConsumed) | tempCell.setCellValue(otConsumed) | ||||
| tempCell.cellStyle.dataFormat = accountingStyle | tempCell.cellStyle.dataFormat = accountingStyle | ||||
| @@ -492,6 +501,7 @@ open class ReportService( | |||||
| rowIndex += 1 | rowIndex += 1 | ||||
| tempCell = sheet.getRow(rowIndex).createCell(0) | tempCell = sheet.getRow(rowIndex).createCell(0) | ||||
| tempCell.setCellValue("Total Leave Hours") | tempCell.setCellValue("Total Leave Hours") | ||||
| tempCell.cellStyle = boldStyle | |||||
| CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) | CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) | ||||
| sheet.addMergedRegion(CellRangeAddress(rowIndex,rowIndex , 0, 1)) | sheet.addMergedRegion(CellRangeAddress(rowIndex,rowIndex , 0, 1)) | ||||
| if (leaves.isNotEmpty()) { | if (leaves.isNotEmpty()) { | ||||
| @@ -507,7 +517,7 @@ open class ReportService( | |||||
| rowIndex += 1 | rowIndex += 1 | ||||
| tempCell = sheet.getRow(rowIndex).createCell(0) | tempCell = sheet.getRow(rowIndex).createCell(0) | ||||
| tempCell.setCellValue("Total Spent Manhours [A+B]") | tempCell.setCellValue("Total Spent Manhours [A+B]") | ||||
| tempCell.cellStyle.setFont(boldFont) | |||||
| tempCell.cellStyle = boldStyle | |||||
| CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) | CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) | ||||
| CellUtil.setCellStyleProperties(tempCell, DoubleBorderBottom) | CellUtil.setCellStyleProperties(tempCell, DoubleBorderBottom) | ||||
| tempCell = sheet.getRow(rowIndex).createCell(1) | tempCell = sheet.getRow(rowIndex).createCell(1) | ||||
| @@ -526,9 +536,13 @@ open class ReportService( | |||||
| projectList.forEachIndexed { index, title -> | projectList.forEachIndexed { index, title -> | ||||
| tempCell = sheet.getRow(7).createCell(columnIndex + index) | tempCell = sheet.getRow(7).createCell(columnIndex + index) | ||||
| tempCell.setCellValue(title) | tempCell.setCellValue(title) | ||||
| CellUtil.setAlignment(tempCell, HorizontalAlignment.RIGHT) | |||||
| tempCell.cellStyle = boldStyle | |||||
| CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) | |||||
| CellUtil.setVerticalAlignment(tempCell, VerticalAlignment.CENTER) | |||||
| CellUtil.setCellStyleProperties(tempCell, ThinBorderBottom) | CellUtil.setCellStyleProperties(tempCell, ThinBorderBottom) | ||||
| columnSize++ | |||||
| } | } | ||||
| println(columnSize) | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| if (timesheets.isNotEmpty()) { | if (timesheets.isNotEmpty()) { | ||||
| projectList.forEach { _ -> | projectList.forEach { _ -> | ||||
| @@ -564,11 +578,16 @@ open class ReportService( | |||||
| ///////////////////////////////////////////////////////// Leave Hours //////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////// Leave Hours //////////////////////////////////////////////////////////////////// | ||||
| tempCell = sheet.getRow(rowIndex).createCell(columnIndex) | tempCell = sheet.getRow(rowIndex).createCell(columnIndex) | ||||
| tempCell.setCellValue("Leave Hours") | tempCell.setCellValue("Leave Hours") | ||||
| tempCell.cellStyle = boldStyle | |||||
| CellUtil.setVerticalAlignment(tempCell, VerticalAlignment.CENTER) | |||||
| CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) | |||||
| CellUtil.setCellStyleProperties(tempCell, ThinBorderBottom) | CellUtil.setCellStyleProperties(tempCell, ThinBorderBottom) | ||||
| columnIndex += 1 | columnIndex += 1 | ||||
| tempCell = sheet.getRow(rowIndex).createCell(columnIndex) | tempCell = sheet.getRow(rowIndex).createCell(columnIndex) | ||||
| tempCell.setCellValue("Daily Manhour Spent\n(Excluding Leave Hours)") | tempCell.setCellValue("Daily Manhour Spent\n(Excluding Leave Hours)") | ||||
| tempCell.cellStyle = boldStyle | |||||
| CellUtil.setAlignment(tempCell, HorizontalAlignment.LEFT) | |||||
| CellUtil.setCellStyleProperties(tempCell, ThinBorderBottom) | CellUtil.setCellStyleProperties(tempCell, ThinBorderBottom) | ||||
| sheet.addMergedRegion(CellRangeAddress(6,6 , 2, columnIndex)) | sheet.addMergedRegion(CellRangeAddress(6,6 , 2, columnIndex)) | ||||
| @@ -583,18 +602,18 @@ open class ReportService( | |||||
| } | } | ||||
| // cal subtotal | // cal subtotal | ||||
| println(rowIndex) | println(rowIndex) | ||||
| for (i in 0 until columnSize - 2) { // minus last col | |||||
| tempCell = sheet.getRow(rowIndex).createCell(2 + i) | |||||
| for (i in 0 ..columnSize ) { // minus last col | |||||
| println(sheet.getRow(rowIndex).getCell(2 + i)) | |||||
| tempCell = sheet.getRow(rowIndex).getCell(2 + i) ?: sheet.getRow(rowIndex).createCell(2 + i) | |||||
| tempCell.cellFormula = "SUM(${getColumnAlphabet(2 + i)}9:${getColumnAlphabet(2 + i)}${rowIndex})" | tempCell.cellFormula = "SUM(${getColumnAlphabet(2 + i)}9:${getColumnAlphabet(2 + i)}${rowIndex})" | ||||
| tempCell.cellStyle = boldStyle | |||||
| tempCell.cellStyle.dataFormat = accountingStyle | tempCell.cellStyle.dataFormat = accountingStyle | ||||
| tempCell.cellStyle.setFont(boldFont) | |||||
| CellUtil.setCellStyleProperties(tempCell, DoubleBorderBottom) | CellUtil.setCellStyleProperties(tempCell, DoubleBorderBottom) | ||||
| } | } | ||||
| } | } | ||||
| return workbook | return workbook | ||||
| } | } | ||||
| @Throws(IOException::class) | @Throws(IOException::class) | ||||
| private fun createSalaryList( | private fun createSalaryList( | ||||
| salarys: List<Salary>, | salarys: List<Salary>, | ||||