|
|
@@ -8,6 +8,7 @@ import com.ffii.tsms.modules.data.entity.Team |
|
|
|
import com.ffii.tsms.modules.project.entity.Invoice |
|
|
|
import com.ffii.tsms.modules.project.entity.Milestone |
|
|
|
import com.ffii.tsms.modules.project.entity.Project |
|
|
|
import com.ffii.tsms.modules.report.web.model.costAndExpenseRequest |
|
|
|
import com.ffii.tsms.modules.timesheet.entity.Leave |
|
|
|
import com.ffii.tsms.modules.timesheet.entity.Timesheet |
|
|
|
import com.ffii.tsms.modules.timesheet.entity.projections.MonthlyLeave |
|
|
@@ -32,6 +33,7 @@ import java.time.LocalDate |
|
|
|
import java.time.YearMonth |
|
|
|
import java.time.format.DateTimeFormatter |
|
|
|
import java.util.* |
|
|
|
import kotlin.jvm.optionals.getOrElse |
|
|
|
|
|
|
|
|
|
|
|
data class DayInfo(val date: String?, val weekday: String?) |
|
|
@@ -1933,7 +1935,7 @@ open class ReportService( |
|
|
|
|
|
|
|
val gradeCell = row.getCell(1) ?: row.createCell(1) |
|
|
|
gradeCell.apply { |
|
|
|
setCellValue("G${staff.getValue("grade")}") |
|
|
|
setCellValue("${staff.getValue("grade")}") |
|
|
|
} |
|
|
|
CellUtil.setAlignment(gradeCell, HorizontalAlignment.CENTER); |
|
|
|
|
|
|
@@ -2106,7 +2108,7 @@ open class ReportService( |
|
|
|
return workbook |
|
|
|
} |
|
|
|
|
|
|
|
fun getCostAndExpense(status: String): List<Map<String,Any?>>{ |
|
|
|
fun getCostAndExpense(clientId: Long?, teamId: Long?): List<Map<String,Any?>>{ |
|
|
|
val sql = StringBuilder( |
|
|
|
" with cte_timesheet as ( " |
|
|
|
+ " Select p.code, s.name as staff, IFNULL(t.normalConsumed, 0) as normalConsumed, IFNULL(t.otConsumed , 0) as otConsumed, s2.salaryPoint, s2.hourlyRate, t.staffId," |
|
|
@@ -2131,17 +2133,25 @@ open class ReportService( |
|
|
|
+ " left join team t2 on t2.id = s.teamId" |
|
|
|
+ " where ISNULL(p.code) = False" |
|
|
|
) |
|
|
|
if(status != "All"){ |
|
|
|
if(clientId != null){ |
|
|
|
sql.append( |
|
|
|
" and p.status = :status" |
|
|
|
" and c.id = :clientId " |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
if(teamId != null){ |
|
|
|
sql.append( |
|
|
|
" and p.teamLead = :teamId " |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
sql.append( |
|
|
|
" group by p.code, p.description , c.name, teamLead, p.expectedTotalFee , hourlyRate" + " order by p.code" |
|
|
|
) |
|
|
|
|
|
|
|
val args = mapOf( |
|
|
|
"status" to status |
|
|
|
"clientId" to clientId, |
|
|
|
"teamId" to teamId |
|
|
|
) |
|
|
|
|
|
|
|
val otFactor = BigDecimal(1).toDouble() |
|
|
@@ -2179,6 +2189,8 @@ open class ReportService( |
|
|
|
fun createCostAndExpenseWorkbook( |
|
|
|
templatePath: String, |
|
|
|
costAndExpenseList: List<Map<String, Any?>>, |
|
|
|
teamId: Long?, |
|
|
|
clientId: Long? |
|
|
|
): Workbook{ |
|
|
|
val resource = ClassPathResource(templatePath) |
|
|
|
val templateInputStream = resource.inputStream |
|
|
@@ -2188,9 +2200,35 @@ open class ReportService( |
|
|
|
var rowNum = 0 |
|
|
|
rowNum = 1 |
|
|
|
val row1: Row = sheet.getRow(rowNum) |
|
|
|
val row1Cell = row1.getCell(1) |
|
|
|
val row1Cell = row1.getCell(2) |
|
|
|
row1Cell.setCellValue(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd")).toString()) |
|
|
|
|
|
|
|
rowNum = 2 |
|
|
|
val row2: Row = sheet.getRow(rowNum) |
|
|
|
val row2Cell = row2.getCell(2) |
|
|
|
if(teamId == null){ |
|
|
|
row2Cell.setCellValue("All") |
|
|
|
}else{ |
|
|
|
val sql = StringBuilder( |
|
|
|
" select t.id, t.code, t.name, concat(t.code, \" - \" ,t.name) as teamLead from team t where t.id = :teamId " |
|
|
|
) |
|
|
|
val team = jdbcDao.queryForMap(sql.toString(), mapOf("teamId" to teamId)).get() |
|
|
|
row2Cell.setCellValue(team["teamLead"] as String) |
|
|
|
} |
|
|
|
|
|
|
|
rowNum = 3 |
|
|
|
val row3: Row = sheet.getRow(rowNum) |
|
|
|
val row3Cell = row3.getCell(2) |
|
|
|
if(clientId == null){ |
|
|
|
row3Cell.setCellValue("All") |
|
|
|
}else{ |
|
|
|
val sql = StringBuilder( |
|
|
|
" select c.id, c.name from customer c where c.id = :clientId " |
|
|
|
) |
|
|
|
val client = jdbcDao.queryForMap(sql.toString(), mapOf("clientId" to clientId)).get() |
|
|
|
row3Cell.setCellValue(client["name"] as String) |
|
|
|
} |
|
|
|
|
|
|
|
rowNum = 6 |
|
|
|
for(item in costAndExpenseList){ |
|
|
|
val index = costAndExpenseList.indexOf(item) |
|
|
@@ -2239,7 +2277,7 @@ open class ReportService( |
|
|
|
|
|
|
|
val cell8 = row.getCell(8) ?: row.createCell(8) |
|
|
|
cell8.apply { |
|
|
|
cellFormula = "H${rowNum+1}/G${rowNum+1}" |
|
|
|
cellFormula = "H${rowNum+1}/F${rowNum+1}" |
|
|
|
} |
|
|
|
sheet.setRowBreak(rowNum++); |
|
|
|
} |
|
|
@@ -2247,10 +2285,11 @@ open class ReportService( |
|
|
|
return workbook |
|
|
|
} |
|
|
|
|
|
|
|
fun genCostAndExpenseReport(): ByteArray{ |
|
|
|
val costAndExpenseList = getCostAndExpense("All") |
|
|
|
fun genCostAndExpenseReport(request: costAndExpenseRequest): ByteArray{ |
|
|
|
|
|
|
|
val costAndExpenseList = getCostAndExpense(request.clientId, request.teamId) |
|
|
|
|
|
|
|
val workbook: Workbook = createCostAndExpenseWorkbook(COSTANDEXPENSE_REPORT, costAndExpenseList) |
|
|
|
val workbook: Workbook = createCostAndExpenseWorkbook(COSTANDEXPENSE_REPORT, costAndExpenseList, request.clientId, request.teamId) |
|
|
|
|
|
|
|
val outputStream: ByteArrayOutputStream = ByteArrayOutputStream() |
|
|
|
workbook.write(outputStream) |
|
|
|