save file changes

This commit is contained in:
gowthaman.b 2024-03-19 17:31:19 +05:30
parent 141d8961e4
commit fc361e3133

View File

@ -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<String> = 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<Vendor>) {
val wb = HSSFWorkbook()
val sh = wb.createSheet()
val headers: List<String> =
listOf(
"No.",
"Name",
"MSME",
"GST Number",
"Address",
"Rating",
"Contact Name",
"Contact Email",
"Contact Mobile"
)
val headers: List<String> = 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<Invoice>) {
val sh = wb.createSheet()
val headers: List<String> = 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)