diff --git a/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt b/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt index e36173b..537f969 100644 --- a/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt +++ b/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt @@ -12,6 +12,7 @@ import com.ffii.tsms.modules.data.web.models.FinancialSummaryByProject import com.ffii.tsms.modules.project.entity.* import com.ffii.tsms.modules.project.service.InvoiceService import com.ffii.tsms.modules.project.service.ProjectExpenseService +import com.ffii.tsms.modules.report.service.ReportService import com.ffii.tsms.modules.timesheet.entity.TimesheetRepository import com.ffii.tsms.modules.timesheet.service.TimesheetsService import org.apache.poi.ss.usermodel.* @@ -37,7 +38,8 @@ open class DashboardService( private val salaryEffectiveService: SalaryEffectiveService, private val projectExpenseRepository: ProjectExpenseRepository, private val companyHolidayService: CompanyHolidayService, - private val jdbcDao: JdbcDao + private val jdbcDao: JdbcDao, + private val reportService: ReportService ) { private val DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd") private val FORMATTED_TODAY = LocalDate.now().format(DATE_FORMATTER) @@ -1746,7 +1748,7 @@ open class DashboardService( + " coalesce (sum(i.paidAmount),0) as totalReceived," + " coalesce (sum(i.issueAmount) - sum(i.paidAmount),0) as receivable," + " coalesce (round((sum(p.expectedTotalFee) - sum(ifnull(p.subContractFee, 0)))*0.8,2),0) as totalBudget," - + " coalesce(expenditure.expenditure, 0) + + sum(coalesce(pc.expense, 0)) as totalExpenditure," + + " coalesce(expenditure.expenditure, 0) + sum(coalesce(pc.expense, 0)) as totalExpenditure," + " coalesce(round((sum(p.expectedTotalFee) - sum(ifnull(p.subContractFee, 0)))*0.8,2),0) - (coalesce(expenditure.expenditure, 0) + + sum(coalesce(pc.expense, 0))) as expenditureReceivable," // + " (sum(p.expectedTotalFee) - sum(ifnull(p.subContractFee, 0)))*0.8 - coalesce(sum(pc.expense), 0) as expenditureReceivable," // + " coalesce ((sum(p.expectedTotalFee) - sum(ifnull(p.subContractFee, 0)))*0.8 - expenditure.expenditure,0) as expenditureReceivable," @@ -1802,7 +1804,27 @@ open class DashboardService( + " group by expenditure.expenditure" ) - return jdbcDao.queryForList(sql.toString(), args) + var sqlResult = jdbcDao.queryForList(sql.toString(), args) + + val date = LocalDate.now() + val yearMonth: YearMonth = YearMonth.from(date) + + val teamLeadId = -1L; + val startMonth = "1970-01"; + val endMonth = yearMonth.toString(); + + val projectCodes = args["projectIds"]?.let { ids -> projectRepository.findAllById( ids as MutableList).map { project -> project.code } } ?: mutableListOf() + val manhoursSpent = reportService.getManHoursSpentByTeam(teamLeadId, startMonth, endMonth) + val salaryEffectiveMap = reportService.getSalaryEffectiveByTeamLead(teamLeadId) + val updatedTimesheetData = reportService.updateTimesheetDataWithEffectiveSalary(manhoursSpent, salaryEffectiveMap) + val projectsExpenditure = reportService.calculateProjectExpenditures(updatedTimesheetData) + .filter { projectCodes.contains(it.key) } + .map { it.value } + .sumOf { it } + + sqlResult[0]["totalExpenditure"] = projectsExpenditure; + + return sqlResult } fun CashFlowAnticipateIncome(args: Map): List> { val sql = StringBuilder("select" diff --git a/src/main/java/com/ffii/tsms/modules/data/web/DashboardController.kt b/src/main/java/com/ffii/tsms/modules/data/web/DashboardController.kt index f1e4840..21ca143 100644 --- a/src/main/java/com/ffii/tsms/modules/data/web/DashboardController.kt +++ b/src/main/java/com/ffii/tsms/modules/data/web/DashboardController.kt @@ -209,7 +209,7 @@ class DashboardController( fun searchCashFlowReceivableAndExpenditure(request: HttpServletRequest?): List> { val args = mutableMapOf() val projectIdList = request?.getParameter("projectIdList") - val projectIds = projectIdList?.split(",")?.map { it.toInt() }?.toList() + val projectIds = projectIdList?.split(",")?.map { it.toLong() }?.toList() if (projectIds != null) { args["projectIds"] = projectIds }