diff --git a/src/main/kotlin/com/restapi/controllers/Excel.kt b/src/main/kotlin/com/restapi/controllers/Excel.kt index 3ea741a..14548ca 100644 --- a/src/main/kotlin/com/restapi/controllers/Excel.kt +++ b/src/main/kotlin/com/restapi/controllers/Excel.kt @@ -1,6 +1,8 @@ package com.restapi.controllers import com.restapi.domain.* +import com.restapi.domain.Session.currentUserPlants +import com.restapi.domain.Session.database import org.apache.poi.hssf.usermodel.DVConstraint import org.apache.poi.hssf.usermodel.HSSFDataValidation import org.apache.poi.hssf.usermodel.HSSFSheet @@ -13,6 +15,7 @@ import java.text.SimpleDateFormat import java.time.LocalDate import java.time.ZoneId import java.util.* +import java.util.concurrent.ConcurrentHashMap fun createHeaderRow(cols: List, sh: HSSFSheet, wb: Workbook) { val boldFont = wb.createFont() @@ -288,17 +291,20 @@ fun exportPos(pos: List) { "Open Till", "Reference Quotation Number", "Vendor Name", - "Vendor Address", "Product Id", "Product Name", "Unit Price", "Quantity", + "Loading Site", + "Unloading Plant", "Total Amount", "Terms and Conditions" ) createHeaderRow(headers, sh, wb) var rowCnt = 1 + val vmap = ConcurrentHashMap() + val plants = currentUserPlants() for (po in pos) { val prodCnt = po.products.size @@ -309,8 +315,11 @@ fun exportPos(pos: List) { row.createCell(i++).setCellValue(po.poDate) row.createCell(i++).setCellValue(po.validTill) row.createCell(i++).setCellValue(po.referenceQuotation) - row.createCell(i++).setCellValue(po.vendor?.name) - row.createCell(i++).setCellValue(po.vendor?.address) + val vendorId = po.vendor!!.sysPk + val vendor = vmap.computeIfAbsent(vendorId) { + database.find(Vendor::class.java, vendorId)!! + } + row.createCell(i++).setCellValue(vendor.name) //6 would be repeated row.createCell(i++).setCellValue(po.products[j].productId.toString()) @@ -318,8 +327,24 @@ fun exportPos(pos: List) { row.createCell(i++).setCellValue(po.products[j].unitPrice) row.createCell(i++).setCellValue(po.products[j].quantity) + if (po.allLoadingSite) { + + row.createCell(i++).setCellValue("All Site") + } else { + row.createCell(i++).setCellValue(po.loadingSiteId?.toString()) + + } + + if (po.allUnloadingSite) { + row.createCell(i++).setCellValue("All Plants") + + } else { + row.createCell(i++) + .setCellValue(po.unloadingPlantId) + } + row.createCell(i++).setCellValue(po.totalAmount) - row.createCell(i++).setCellValue(po.tnc?.joinToString(";")) + row.createCell(i).setCellValue(po.tnc?.joinToString(";")) } } saveExcelFileLocally("Pos.xls", wb) @@ -338,6 +363,7 @@ fun exportIncomingInventory(tickets: List) { "Vehicle No", "Loading Site", "Unloading Site", + "PO Num", "Product Name", "Unit Price", "Quantity", @@ -361,9 +387,16 @@ fun exportIncomingInventory(tickets: List) { row.createCell(i++).setCellValue(ticket.unloading) //6 would be repeated - row.createCell(i++).setCellValue(ticket.products!![j].productName) - row.createCell(i++).setCellValue(ticket.products!![j].unitPrice) - row.createCell(i++).setCellValue(ticket.products!![j].quantity) + val prod = ticket.products!![j] + val po = if(prod.poId != null && prod.poId > 0){ + database.find(PurchaseOrder::class.java, prod.poId)?.poNum + } else { + "" + } + row.createCell(i++).setCellValue(po) + row.createCell(i++).setCellValue(prod.productName) + row.createCell(i++).setCellValue(prod.unitPrice) + row.createCell(i).setCellValue(prod.quantity) } }