| @@ -96,7 +96,7 @@ open class InvoiceService( | |||||
| open fun getMilestonePaymentWithProjectCode(code: List<String>): List<Map<String, Any>> { | open fun getMilestonePaymentWithProjectCode(code: List<String>): List<Map<String, Any>> { | ||||
| val sql = StringBuilder("select " | val sql = StringBuilder("select " | ||||
| + " p.code, mp.* " | |||||
| + " p.code, mp.*, m.taskGroupId " | |||||
| + " from milestone_payment mp " | + " from milestone_payment mp " | ||||
| + " left join milestone m on mp.milestoneId = m.id " | + " left join milestone m on mp.milestoneId = m.id " | ||||
| + " left join project p on p.id = m.projectId " | + " left join project p on p.id = m.projectId " | ||||
| @@ -108,6 +108,20 @@ open class InvoiceService( | |||||
| return jdbcDao.queryForList(sql.toString(), args) | return jdbcDao.queryForList(sql.toString(), args) | ||||
| } | } | ||||
| open fun getMilestonePaymentId(code: String, paymentMilestone: String): Long{ | |||||
| val sql = StringBuilder(" select" | |||||
| + " mp.id as milestonePaymentId" | |||||
| + " from milestone_payment mp" | |||||
| + " left join milestone m on mp.milestoneId = m.id" | |||||
| + " left join project p on p.id = m.projectId" | |||||
| + " where p.deleted = false" | |||||
| + " and p.code = :code" | |||||
| + " and mp.description = :description " | |||||
| ) | |||||
| val args = mapOf("code" to code, "description" to paymentMilestone) | |||||
| return jdbcDao.queryForInt(sql.toString(), args).toLong() | |||||
| } | |||||
| open fun getInvoiceByInvoiceNo(invoiceNo: String): Invoice { | open fun getInvoiceByInvoiceNo(invoiceNo: String): Invoice { | ||||
| return invoiceRepository.findByInvoiceNo(invoiceNo) | return invoiceRepository.findByInvoiceNo(invoiceNo) | ||||
| } | } | ||||
| @@ -227,17 +241,18 @@ open class InvoiceService( | |||||
| /** | /** | ||||
| * @return true when cellValue Object exist in DB | * @return true when cellValue Object exist in DB | ||||
| */ | */ | ||||
| fun checkStringExists(list: List<Map<String, Any>>, cellValue: Map<String, Any>): Boolean { | |||||
| private fun checkStringExists(list: List<Map<String, Any>>, cellValue: Map<String, Any>): Boolean { | |||||
| // println("LIST-------------: $list") | // println("LIST-------------: $list") | ||||
| // println("CELL VALUE-------------: $cellValue") | // println("CELL VALUE-------------: $cellValue") | ||||
| // println(list.contains(cellValue)) | |||||
| // println(list.any { it["code"] == cellValue["code"] && it["description"] == cellValue["description"] }) | |||||
| // return list.contains(cellValue) | |||||
| return list.any { it["code"] == cellValue["code"] && it["description"] == cellValue["description"] } | |||||
| // println(list.any { it["code"] == cellValue["code"] && it["description"] == cellValue["description"] && it["groupTaskId"] == cellValue["stage"]}) | |||||
| return list.any { it["code"] == cellValue["code"] && it["description"] == cellValue["description"] && it["groupTaskId"] == cellValue["stage"]} | |||||
| } | } | ||||
| open fun checkMilestonePayment( | |||||
| open fun checkMilestonePaymentByStageAndDescription( | |||||
| sheet: Sheet, | sheet: Sheet, | ||||
| startingRow: Int, | startingRow: Int, | ||||
| stageColumnIndex: Int, | |||||
| columnIndex: Int, | columnIndex: Int, | ||||
| invoiceColumnIndex: Int, | invoiceColumnIndex: Int, | ||||
| projectCodeColumnIndex: Int, | projectCodeColumnIndex: Int, | ||||
| @@ -250,15 +265,18 @@ open class InvoiceService( | |||||
| val milestonePaymentCell = row?.getCell(columnIndex) | val milestonePaymentCell = row?.getCell(columnIndex) | ||||
| val invoiceNoCell = row?.getCell(invoiceColumnIndex) | val invoiceNoCell = row?.getCell(invoiceColumnIndex) | ||||
| val projectCodeCell = row?.getCell(projectCodeColumnIndex) | val projectCodeCell = row?.getCell(projectCodeColumnIndex) | ||||
| val stageCell = row?.getCell(stageColumnIndex) | |||||
| if (milestonePaymentCell != null && milestonePaymentCell.cellType == CellType.STRING && | if (milestonePaymentCell != null && milestonePaymentCell.cellType == CellType.STRING && | ||||
| invoiceNoCell != null && invoiceNoCell.cellType == CellType.STRING && | invoiceNoCell != null && invoiceNoCell.cellType == CellType.STRING && | ||||
| projectCodeCell != null && projectCodeCell.cellType == CellType.STRING) | |||||
| projectCodeCell != null && projectCodeCell.cellType == CellType.STRING && | |||||
| stageCell != null && stageCell.cellType == CellType.NUMERIC) | |||||
| { | { | ||||
| val milestonePaymentCellValue = milestonePaymentCell.stringCellValue | val milestonePaymentCellValue = milestonePaymentCell.stringCellValue | ||||
| val invoiceNoCellValue = invoiceNoCell.stringCellValue | val invoiceNoCellValue = invoiceNoCell.stringCellValue | ||||
| val projectCodeCellValue = projectCodeCell.stringCellValue | val projectCodeCellValue = projectCodeCell.stringCellValue | ||||
| val stageCellValue = stageCell.numericCellValue.toInt() | |||||
| val cellValue = mapOf("code" to projectCodeCellValue, "description" to milestonePaymentCellValue) | |||||
| val cellValue = mapOf("code" to projectCodeCellValue, "description" to milestonePaymentCellValue, "groupTaskId" to stageCellValue) | |||||
| if(!checkStringExists(paymentMilestoneWithCode, cellValue)) { | if(!checkStringExists(paymentMilestoneWithCode, cellValue)) { | ||||
| if(!nonExistMilestone.contains(mapOf("paymentMilestone" to milestonePaymentCellValue, "invoiceNo" to invoiceNoCellValue))){ | if(!nonExistMilestone.contains(mapOf("paymentMilestone" to milestonePaymentCellValue, "invoiceNo" to invoiceNoCellValue))){ | ||||
| @@ -359,7 +377,7 @@ open class InvoiceService( | |||||
| val milestonepaymentWithCode = getMilestonePaymentWithProjectCode(projectsCodes) | val milestonepaymentWithCode = getMilestonePaymentWithProjectCode(projectsCodes) | ||||
| // println("newProjectCodes == 0") | // println("newProjectCodes == 0") | ||||
| // println(checkMilestonePayment(sheet, 2, 5, 0, 1, milestonepaymentWithCode)) | // println(checkMilestonePayment(sheet, 2, 5, 0, 1, milestonepaymentWithCode)) | ||||
| val paymenMilestones = checkMilestonePayment(sheet, 2, 5, 0, 1, milestonepaymentWithCode) | |||||
| val paymenMilestones = checkMilestonePaymentByStageAndDescription(sheet, 2, 4,5, 0, 1, milestonepaymentWithCode) | |||||
| if (paymenMilestones.isNotEmpty()){ | if (paymenMilestones.isNotEmpty()){ | ||||
| return InvoiceResponse(false, "Imported Invoice's format is incorrect", newProjectCodes, emptyRowList, invoicesResult, duplicateItemsInInvoice, paymenMilestones) | return InvoiceResponse(false, "Imported Invoice's format is incorrect", newProjectCodes, emptyRowList, invoicesResult, duplicateItemsInInvoice, paymenMilestones) | ||||
| } | } | ||||
| @@ -376,6 +394,9 @@ open class InvoiceService( | |||||
| } | } | ||||
| for (i in 2..sheet.lastRowNum){ | for (i in 2..sheet.lastRowNum){ | ||||
| val paymentMilestoneId = getMilestonePaymentId(ExcelUtils.getCell(sheet, i, 1).stringCellValue, ExcelUtils.getCell(sheet, i, 5).stringCellValue) | |||||
| println("paymentMilestoneId--------------: $paymentMilestoneId") | |||||
| val milestonePayment = milestonePaymentRepository.findById(paymentMilestoneId).orElseThrow() | |||||
| val invoice = Invoice().apply { | val invoice = Invoice().apply { | ||||
| invoiceNo = ExcelUtils.getCell(sheet, i, 0).stringCellValue | invoiceNo = ExcelUtils.getCell(sheet, i, 0).stringCellValue | ||||
| projectCode = ExcelUtils.getCell(sheet, i, 1).stringCellValue | projectCode = ExcelUtils.getCell(sheet, i, 1).stringCellValue | ||||
| @@ -390,6 +411,7 @@ open class InvoiceService( | |||||
| invoiceDate = ExcelUtils.getCell(sheet, i, 10).dateCellValue.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() | invoiceDate = ExcelUtils.getCell(sheet, i, 10).dateCellValue.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() | ||||
| dueDate = ExcelUtils.getCell(sheet, i, 11).dateCellValue.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() | dueDate = ExcelUtils.getCell(sheet, i, 11).dateCellValue.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() | ||||
| issueAmount = ExcelUtils.getCell(sheet, i, 12).numericCellValue.toBigDecimal() | issueAmount = ExcelUtils.getCell(sheet, i, 12).numericCellValue.toBigDecimal() | ||||
| this.milestonePayment = milestonePayment | |||||
| } | } | ||||
| saveAndFlush(invoice) | saveAndFlush(invoice) | ||||
| } | } | ||||