diff --git a/src/main/kotlin/com/restapi/controllers/Excel.kt b/src/main/kotlin/com/restapi/controllers/Excel.kt index f8ffa98..256a216 100644 --- a/src/main/kotlin/com/restapi/controllers/Excel.kt +++ b/src/main/kotlin/com/restapi/controllers/Excel.kt @@ -1,25 +1,13 @@ package com.restapi.controllers -import com.google.gson.Gson import com.restapi.domain.* -import com.restapi.domain.Document -import com.restapi.domain.PurchaseOrder -import com.restapi.domain.Quotation -import com.restapi.domain.Session.currentUser -import org.apache.poi.hssf.usermodel.HSSFSheet -import org.apache.poi.hssf.usermodel.HSSFWorkbook -import com.restapi.domain.Session.database -import com.restapi.domain.Vendor import org.apache.poi.hssf.usermodel.DVConstraint import org.apache.poi.hssf.usermodel.HSSFDataValidation -import org.apache.poi.ss.usermodel.Cell -import org.apache.poi.ss.usermodel.CellType -import org.apache.poi.ss.usermodel.DateUtil -import org.apache.poi.ss.usermodel.Workbook -import org.apache.poi.ss.usermodel.WorkbookFactory +import org.apache.poi.hssf.usermodel.HSSFSheet +import org.apache.poi.hssf.usermodel.HSSFWorkbook +import org.apache.poi.ss.usermodel.* import org.apache.poi.ss.util.CellRangeAddressList import java.io.File -import java.io.FileInputStream import java.io.FileOutputStream import java.text.SimpleDateFormat import java.time.LocalDate @@ -103,8 +91,13 @@ enum class EnumFor { } fun saveExcelFileLocally(fileName: String, wb: Workbook) { - val path = "./excel/" - val out = FileOutputStream(path + fileName) + val path = "./excel" + val file = File(path, fileName) + + if (!file.parentFile.exists()) { + file.parentFile.mkdirs() + } + val out = FileOutputStream(file) wb.use { it.write(out) } @@ -157,14 +150,7 @@ fun TemplateExcelFile(fileType: FileType) { FileType.VENDORS -> { val headers: List = listOf( - "Name", - "MSME", - "GST Number", - "Address", - "Rating", - "Contact Name", - "Contact Email", - "Contact Mobile" + "Name", "MSME", "GST Number", "Address", "Rating", "Contact Name", "Contact Email", "Contact Mobile" ) val wb = HSSFWorkbook() val sh = wb.createSheet() @@ -179,8 +165,7 @@ fun TemplateExcelFile(fileType: FileType) { createHeaderRow(headers, sh, wb) val r0 = CellRangeAddressList(0, 1000, 4, 4) val dv0 = HSSFDataValidation( - r0, - DVConstraint.createExplicitListConstraint(arrayOf("LTR", "MTR", "NOS", "ALL")) + r0, DVConstraint.createExplicitListConstraint(arrayOf("LTR", "MTR", "NOS", "ALL")) ).apply { suppressDropDownArrow = true } @@ -245,18 +230,9 @@ fun exportVendors(vendors: List) { val wb = HSSFWorkbook() val sh = wb.createSheet() - val headers: List = - listOf( - "No.", - "Name", - "MSME", - "GST Number", - "Address", - "Rating", - "Contact Name", - "Contact Email", - "Contact Mobile" - ) + val headers: List = listOf( + "No.", "Name", "MSME", "GST Number", "Address", "Rating", "Contact Name", "Contact Email", "Contact Mobile" + ) createHeaderRow(headers, sh, wb) val totalCols = headers.size @@ -455,17 +431,7 @@ fun exportInvoices(invoices: List) { val sh = wb.createSheet() val headers: List = listOf( - "Number", - "Date", - "Reference PO", - "Status", - "Vendor Name", - "Vendor Address", - "Product Id", - "Product Name", - "Unit Price", - "Quantity", - "Total Amount" + "Number", "Date", "Reference PO", "Status", "Vendor Name", "Vendor Address", "Product Id", "Product Name", "Unit Price", "Quantity", "Total Amount" ) createHeaderRow(headers, sh, wb)