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 3b1f974..3af2ad7 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 @@ -17,6 +17,7 @@ import com.ffii.tsms.modules.project.web.models.EditInvoiceResponse import com.ffii.tsms.modules.project.web.models.InvoiceResponse import net.sf.jasperreports.engine.JasperCompileManager import net.sf.jasperreports.engine.JasperReport +import org.apache.poi.ss.usermodel.Cell import org.apache.poi.ss.usermodel.CellType import org.apache.poi.ss.usermodel.Sheet import org.apache.poi.ss.usermodel.Workbook @@ -250,6 +251,9 @@ open class InvoiceService( val duplicateValues = HashSet() for (i in startingRow..sheet.lastRowNum) { + if(ExcelUtils.getCell(sheet, i, 0).cellType == CellType.BLANK){ + break + } val row = sheet.getRow(i) val cell = row?.getCell(columnIndex) if (cell != null && cell.cellType == CellType.STRING) { @@ -405,6 +409,12 @@ open class InvoiceService( // Check the import invoice with the data in DB for (i in 2..sheet.lastRowNum){ + if(ExcelUtils.getCell(sheet, i, 0).cellType == CellType.BLANK){ + break + } +// 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 sheetProjectCode = ExcelUtils.getCell(sheet, i, 1).stringCellValue checkInvoiceNo(sheetInvoice, invoices, invoicesResult, true) @@ -437,6 +447,9 @@ open class InvoiceService( } for (i in 2..sheet.lastRowNum){ + if(ExcelUtils.getCell(sheet, i, 0).cellType == CellType.BLANK){ + break + } // Beria cannot provide Payment Milestone when importing the invoice, so it cannot be checked and import to DB // val paymentMilestoneId = getMilestonePaymentId(ExcelUtils.getCell(sheet, i, 1).stringCellValue, ExcelUtils.getCell(sheet, i, 5).stringCellValue) // val milestonePayment = milestonePaymentRepository.findById(paymentMilestoneId).orElseThrow() @@ -496,6 +509,9 @@ open class InvoiceService( val duplicateItemsInInvoice = checkDuplicateItemInImportedInvoice(sheet,2,0) for (i in 2..sheet.lastRowNum){ + if(ExcelUtils.getCell(sheet, i, 0).cellType == CellType.BLANK){ + break + } val sheetInvoice = ExcelUtils.getCell(sheet, i, 0).toString() val sheetProjectCode = ExcelUtils.getCell(sheet, i, 1).stringCellValue checkInvoiceNo(sheetInvoice, invoices, invoicesResult, false) @@ -538,6 +554,9 @@ open class InvoiceService( } for (i in 2..sheet.lastRowNum){ + if(ExcelUtils.getCell(sheet, i, 0).cellType == CellType.BLANK){ + break + } val invoice = getInvoiceByInvoiceNo(ExcelUtils.getCell(sheet, i, 0).toString()) invoice.paidAmount = ExcelUtils.getCell(sheet, i, 3).numericCellValue.toBigDecimal() invoice.receiptDate = ExcelUtils.getCell(sheet, i, 2).dateCellValue.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()