diff --git a/src/main/java/com/ffii/tsms/modules/project/service/InvoiceService.kt b/src/main/java/com/ffii/tsms/modules/project/service/InvoiceService.kt index b1993e4..ea4754a 100644 --- a/src/main/java/com/ffii/tsms/modules/project/service/InvoiceService.kt +++ b/src/main/java/com/ffii/tsms/modules/project/service/InvoiceService.kt @@ -380,6 +380,8 @@ open class InvoiceService( return invoiceRepository.findInvoiceInfoByPaidAmountIsNotNull() } + + @Transactional(rollbackFor = [Exception::class]) open fun importIssueInvoice(workbook: Workbook?): InvoiceResponse { @@ -416,7 +418,17 @@ open class InvoiceService( // println(ExcelUtils.getCell(sheet, i, 0)) // println("sheet.physicalNumberOfRows ${sheet.physicalNumberOfRows}") // println("sheet.lastRowNum ${sheet.lastRowNum}") - val sheetInvoice = ExcelUtils.getCell(sheet, i, 0).toString() + val sheetInvoiceCell = ExcelUtils.getCell(sheet, i, 0) + val sheetInvoice = when (sheetInvoiceCell.cellType) { + CellType.STRING -> sheetInvoiceCell.stringCellValue + CellType.NUMERIC -> { + val numericValue = sheetInvoiceCell.numericCellValue + numericValue.toInt().toString() // Return as integer string + + } + CellType.BLANK -> "" // Return empty string for blank cells + else -> "Unsupported cell type" + } val sheetProjectCode = ExcelUtils.getCell(sheet, i, 1).stringCellValue checkInvoiceNo(sheetInvoice, invoices, invoicesResult, true) checkProjectCode(sheetProjectCode, projects, newProjectCodes) @@ -455,7 +467,16 @@ open class InvoiceService( // val paymentMilestoneId = getMilestonePaymentId(ExcelUtils.getCell(sheet, i, 1).stringCellValue, ExcelUtils.getCell(sheet, i, 5).stringCellValue) // val milestonePayment = milestonePaymentRepository.findById(paymentMilestoneId).orElseThrow() val invoice = Invoice().apply { - invoiceNo = ExcelUtils.getCell(sheet, i, 0).toString() + invoiceNo = when (ExcelUtils.getCell(sheet, i, 0).cellType) { + CellType.STRING -> ExcelUtils.getCell(sheet, i, 0).stringCellValue + CellType.NUMERIC -> { + val numericValue = ExcelUtils.getCell(sheet, i, 0).numericCellValue + numericValue.toInt().toString() // Return as integer string + + } + CellType.BLANK -> "" // Return empty string for blank cells + else -> "Unsupported cell type" + } projectCode = ExcelUtils.getCell(sheet, i, 1).stringCellValue // projectName = ExcelUtils.getCell(sheet, i, 2).stringCellValue // team = ExcelUtils.getCell(sheet, i, 3).stringCellValue @@ -513,7 +534,17 @@ open class InvoiceService( if(ExcelUtils.getCell(sheet, i, 0).cellType == CellType.BLANK){ break } - val sheetInvoice = ExcelUtils.getCell(sheet, i, 0).toString() + val sheetInvoiceCell = ExcelUtils.getCell(sheet, i, 0) + val sheetInvoice = when (sheetInvoiceCell.cellType) { + CellType.STRING -> sheetInvoiceCell.stringCellValue + CellType.NUMERIC -> { + val numericValue = sheetInvoiceCell.numericCellValue + numericValue.toInt().toString() // Return as integer string + + } + CellType.BLANK -> "" // Return empty string for blank cells + else -> "Unsupported cell type" + } val sheetProjectCode = ExcelUtils.getCell(sheet, i, 1).stringCellValue checkInvoiceNo(sheetInvoice, invoices, invoicesResult, false) checkProjectCode(sheetProjectCode, projects, newProjectCodes)