add excel templates fix apis
This commit is contained in:
@@ -6,8 +6,6 @@ import com.restapi.config.AppConfig.Companion.appConfig
|
||||
import com.restapi.config.Auth.validateAuthToken
|
||||
import com.restapi.controllers.*
|
||||
import com.restapi.domain.DataNotFoundException
|
||||
import com.restapi.domain.Product
|
||||
import com.restapi.domain.Session
|
||||
import com.restapi.domain.Session.currentTenant
|
||||
import com.restapi.domain.Session.currentUser
|
||||
import com.restapi.domain.Session.objectMapper
|
||||
@@ -114,25 +112,31 @@ fun main(args: Array<String>) {
|
||||
|
||||
path("/vendor"){
|
||||
path("/"){
|
||||
post("", Vendor::create, Roles(Role.Explicit(listOf("ROLE_VENDOR_CREATE", "ROLE_ADMIN"))))
|
||||
get("", Vendor::get, Roles(Role.Explicit(listOf("ROLE_VENDOR_VIEW", "ROLE_VENDOR_CREATE", "ROLE_ADMIN"))))
|
||||
get("quotes/{id}", Vendor::getQuotes, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_QUOTE_VIEW", "ROLE_QUOTE_CREATE", "ROLE_VENDOR_VIEW"))))
|
||||
get("pos/{id}", Vendor::getPos, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_PO_VIEW", "ROLE_PO_CREATE`"))))
|
||||
put("/rate/{id}/{rating}", Vendor::rate, Roles(Role.Explicit(listOf("ROLE_VENDOR_CREATE"))))
|
||||
post("", VendorCtrl::create, Roles(Role.Explicit(listOf("ROLE_VENDOR_CREATE", "ROLE_ADMIN"))))
|
||||
post("/batch", VendorCtrl::createBatch, Roles(Role.Explicit(listOf("ROLE_VENDOR_CREATE", "ROLE_ADMIN"))))
|
||||
get("/{id}", VendorCtrl::get, Roles(Role.Explicit(listOf("ROLE_VENDOR_VIEW", "ROLE_VENDOR_CREATE", "ROLE_ADMIN"))))
|
||||
post("/getAll", VendorCtrl::getAll, Roles(Role.Explicit(listOf("ROLE_VENDOR_VIEW", "ROLE_VENDOR_CREATE"))))
|
||||
get("quotes/{id}", VendorCtrl::getQuotes, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_QUOTE_VIEW", "ROLE_QUOTE_CREATE", "ROLE_VENDOR_VIEW"))))
|
||||
get("pos/{id}", VendorCtrl::getPos, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_PO_VIEW", "ROLE_PO_CREATE`"))))
|
||||
put("/rate/{id}/{rating}", VendorCtrl::rate, Roles(Role.Explicit(listOf("ROLE_VENDOR_CREATE"))))
|
||||
}
|
||||
path("/po"){
|
||||
post("", PurchaseOrder::create, Roles(Role.Explicit(listOf("ROLE_PO_CREATE", "ROLE_ADMIN"))))
|
||||
get("/{id}", PurchaseOrder::get, Roles(Role.Explicit(listOf("ROLE_PO_CREATE", "ROLE_PO_VIEW", "ROLE_QUOTE_CREATE"))))
|
||||
put("/approve/{id}", PurchaseOrder::approve, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_APPROVE"))))
|
||||
put("/reject/{id}", PurchaseOrder::reject, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_APPROVE"))))
|
||||
get("/refQuote/{id}", PurchaseOrder::quoteReference, Roles(Role.Explicit(listOf("ROLE_PO_CREATE", "ROLE_PO_VIEW"))))
|
||||
post("", PurchaseOrderCtrl::create, Roles(Role.Explicit(listOf("ROLE_PO_CREATE", "ROLE_ADMIN"))))
|
||||
post("/batch", PurchaseOrderCtrl::createBatch, Roles(Role.Explicit(listOf("ROLE_PO_CREATE", "ROLE_VENDOR_CREATE", "ROLE_ADMIN"))))
|
||||
post("/getAll", PurchaseOrderCtrl::getAll, Roles(Role.Explicit(listOf("ROLE_PO_CREATE", "ROLE_PO_CREATE", "ROLE_VENDOR_CREATE", "ROLE_ADMIN"))))
|
||||
get("/{id}", PurchaseOrderCtrl::get, Roles(Role.Explicit(listOf("ROLE_PO_CREATE", "ROLE_PO_VIEW", "ROLE_QUOTE_CREATE"))))
|
||||
put("/approve/{id}", PurchaseOrderCtrl::approve, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_APPROVE"))))
|
||||
put("/reject/{id}", PurchaseOrderCtrl::reject, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_APPROVE"))))
|
||||
get("/refQuote/{id}", PurchaseOrderCtrl::quoteReference, Roles(Role.Explicit(listOf("ROLE_PO_CREATE", "ROLE_PO_VIEW"))))
|
||||
}
|
||||
path("/quote"){
|
||||
post("", Quotation::create, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_ADMIN"))))
|
||||
get("/{id}", Quotation::get, Roles(Role.Explicit(listOf("ROLE_QUOTE_VIEW", "ROLE_ADMIN", "ROLE_PO_CREATE", "ROLE_QUOTE_CREATE"))))
|
||||
get("/po/{id}", Quotation::generatePO, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_PO_CRETE"))))
|
||||
get("/rfq/{rfqNum}", Quotation::reqForQuote, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_QUOTE_VIEW"))))
|
||||
delete("/{id}", Quotation::delete, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_ADMIN"))))
|
||||
post("", QuotationCtrl::create, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_ADMIN"))))
|
||||
post("/batch", QuotationCtrl::createBatch, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_ADMIN", "ROLE_VENDOR_CREATE"))))
|
||||
post("/getAll", QuotationCtrl::getAll, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_ADMIN", "ROLE_VENDOR_CREATE"))))
|
||||
get("/{id}", QuotationCtrl::get, Roles(Role.Explicit(listOf("ROLE_QUOTE_VIEW", "ROLE_ADMIN", "ROLE_PO_CREATE", "ROLE_QUOTE_CREATE"))))
|
||||
get("/po/{id}", QuotationCtrl::generatePO, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_PO_CRETE"))))
|
||||
get("/rfq/{rfqNum}", QuotationCtrl::reqForQuote, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_QUOTE_VIEW"))))
|
||||
delete("/{id}", QuotationCtrl::delete, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_ADMIN"))))
|
||||
}
|
||||
path("/product"){
|
||||
post("", ProductCtrl::create, Roles(Role.Explicit(listOf("ROLE_PRODUCT_CREATE", "ROLE_ADMIN"))))
|
||||
|
||||
@@ -374,30 +374,46 @@ object Entities {
|
||||
}
|
||||
}
|
||||
data class Filters(val common :CommonFilters, val custom :CustomFilters)
|
||||
object PurchaseOrder {
|
||||
data class BatchPos(val pos :List<PurchaseOrder>)
|
||||
object PurchaseOrderCtrl {
|
||||
fun get(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("po not found for $id")
|
||||
|
||||
ctx.json(po)
|
||||
ctx.json(po).status(HttpStatus.OK)
|
||||
}
|
||||
data class PF(val common: CommonFilters, val poFilters: POFilters)
|
||||
fun getAll(ctx :Context){
|
||||
val filters = ctx.bodyAsClass<Filters>()
|
||||
val poFilters :POFilters? = filters.custom as? POFilters
|
||||
val pos = searchPos(filters.common, poFilters)
|
||||
ctx.json(pos)
|
||||
val filters = ctx.bodyAsClass<PF>()
|
||||
val pos = searchPos(filters.common, filters.poFilters)
|
||||
ctx.json(pos).status(HttpStatus.OK)
|
||||
}
|
||||
fun create(ctx :Context){
|
||||
val po = ctx.bodyAsClass<PurchaseOrder>()
|
||||
database.save(po)
|
||||
ctx.result("po created")
|
||||
ctx.json(po).status(HttpStatus.CREATED)
|
||||
}
|
||||
fun createBatch(ctx :Context){
|
||||
val pos = ctx.bodyAsClass<List<PurchaseOrder>>()
|
||||
val txn = database.beginTransaction()
|
||||
try {
|
||||
txn.isBatchMode = true
|
||||
for(po in pos) database.save(po)
|
||||
txn.commit()
|
||||
ctx.status(HttpStatus.CREATED).result("POS Created")
|
||||
} catch(e :Exception){
|
||||
txn.rollback()
|
||||
ctx.status(HttpStatus.INTERNAL_SERVER_ERROR).result("Pos Creation failed" + e.message)
|
||||
} finally {
|
||||
txn.end()
|
||||
}
|
||||
ctx.result("pos batch created").status(HttpStatus.CREATED)
|
||||
}
|
||||
fun approve(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("po not found for $id")
|
||||
po.approvalStatus = ApprovalStatus.APPROVED
|
||||
po.save()
|
||||
ctx.result("po with id $id approved")
|
||||
ctx.json(po).status(HttpStatus.CREATED)
|
||||
//reject all other pos pertaining to the same tx ??
|
||||
}
|
||||
fun reject(ctx :Context){
|
||||
@@ -405,7 +421,7 @@ object PurchaseOrder {
|
||||
val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("po not found for $id")
|
||||
po.approvalStatus = ApprovalStatus.REJECTED
|
||||
po.save()
|
||||
ctx.result("po with id $id rejected")
|
||||
ctx.json(po).status(HttpStatus.CREATED)
|
||||
}
|
||||
fun quoteReference(ctx :Context){
|
||||
//gets the quote reference on which this po is based on
|
||||
@@ -457,12 +473,20 @@ object ProductCtrl {
|
||||
}
|
||||
}
|
||||
|
||||
object Quotation {
|
||||
object QuotationCtrl {
|
||||
fun get(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
val quote = database.find(Quotation::class.java, id) ?: throw NotFoundResponse("quote not found for $id")
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(quote)
|
||||
}
|
||||
data class QF(val common: CommonFilters, val quoteFilters: QuoteFilters)
|
||||
fun getAll(ctx :Context){
|
||||
val filters = ctx.bodyAsClass<QF>()
|
||||
val quotes = searchQuotes(filters.common, filters.quoteFilters)
|
||||
ctx.json(quotes).status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
fun create(ctx :Context){
|
||||
val quote = ctx.bodyAsClass<Quotation>()
|
||||
//we have to check if the quotation created date is below the expiry of rfq
|
||||
@@ -475,25 +499,44 @@ object Quotation {
|
||||
if(quote.quoteDate!! <= rfq.openTill) {
|
||||
//valid
|
||||
database.save(quote)
|
||||
ctx.result("quote created")
|
||||
ctx.status(HttpStatus.CREATED)
|
||||
ctx.json(quote)
|
||||
}else {
|
||||
ctx.status(HttpStatus.BAD_REQUEST)
|
||||
ctx.result("request for quote closed")
|
||||
}
|
||||
}else {
|
||||
throw NotFoundResponse("request for quote not found for this quotation")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
fun createBatch(ctx :Context){
|
||||
val quotes = ctx.bodyAsClass<List<Quotation>>()
|
||||
val txn = database.beginTransaction()
|
||||
try {
|
||||
txn.isBatchMode = true
|
||||
for(quote in quotes) database.save(quote)
|
||||
txn.commit()
|
||||
ctx.status(HttpStatus.CREATED).result("Quotes Created")
|
||||
} catch(e :Exception){
|
||||
txn.rollback()
|
||||
ctx.status(HttpStatus.INTERNAL_SERVER_ERROR).result("Quotes Creation failed" + e.message)
|
||||
} finally {
|
||||
txn.end()
|
||||
}
|
||||
ctx.result("Quotes batch created").status(HttpStatus.CREATED)
|
||||
}
|
||||
fun delete(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
val quote = database.find(Quotation::class.java, id) ?: throw NotFoundResponse("quote not found for id $id")
|
||||
quote.delete()
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.result("quote with $id deleted")
|
||||
}
|
||||
fun generatePO(ctx :Context){
|
||||
//user should be redirected to a po form submission with prefilled values
|
||||
//create a PO object with values from the quote and then send it as body to vendor/po/create ??
|
||||
|
||||
}
|
||||
fun reqForQuote(ctx :Context){
|
||||
val reqForQuoteNum = ctx.pathParam(("rfqNum"))
|
||||
@@ -501,6 +544,7 @@ object Quotation {
|
||||
.where()
|
||||
.eq("reqForQuoteNum", reqForQuoteNum)
|
||||
?: throw NotFoundResponse("request for quote not found for this quotation")
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(rfq)
|
||||
}
|
||||
}
|
||||
@@ -508,12 +552,14 @@ object Document {
|
||||
fun get(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
val doc = database.find(Document::class.java, id) ?: throw NotFoundResponse("no doc found with id $id")
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(doc)
|
||||
}
|
||||
fun create(ctx :Context){
|
||||
val doc = ctx.bodyAsClass<Document>()
|
||||
database.save(doc)
|
||||
ctx.result("doc created")
|
||||
ctx.status(HttpStatus.CREATED)
|
||||
ctx.json(doc)
|
||||
}
|
||||
fun print(ctx :Context){
|
||||
//would be handled in the frontend ??
|
||||
@@ -522,7 +568,8 @@ object Document {
|
||||
val id = ctx.pathParam("id")
|
||||
val doc = database.find(Document::class.java, id) ?: throw NotFoundResponse("no doc found with id $id")
|
||||
//doc.delete()
|
||||
ctx.result("document deleted")
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.result("document deleted with id $id")
|
||||
}
|
||||
fun getWithRefId(ctx :Context){
|
||||
//fetches a particular doc (po, quote) with ref id
|
||||
@@ -531,20 +578,47 @@ object Document {
|
||||
.where()
|
||||
.eq("refId", refId)
|
||||
?: throw NotFoundResponse("no doc found for refId $refId")
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(doc)
|
||||
}
|
||||
|
||||
}
|
||||
object Vendor {
|
||||
object VendorCtrl {
|
||||
fun get(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id")
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(vendor)
|
||||
}
|
||||
fun create(ctx :Context){
|
||||
data class VF(val common : CommonFilters, val vendorFilters: VendorFilters)
|
||||
fun getAll(ctx :Context){
|
||||
val filters = ctx.bodyAsClass<VF>()
|
||||
println(filters.common)
|
||||
println(filters.vendorFilters)
|
||||
val pos = searchVendors(filters.common, filters.vendorFilters)
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(pos)
|
||||
}
|
||||
fun createBatch(ctx: Context){
|
||||
val vendors = ctx.bodyAsClass<List<Vendor>>()
|
||||
val txn = database.beginTransaction()
|
||||
try {
|
||||
txn.isBatchMode = true
|
||||
for(v in vendors) database.save(v)
|
||||
txn.commit()
|
||||
ctx.status(HttpStatus.CREATED).result("Vendors Created")
|
||||
} catch(e :Exception){
|
||||
txn.rollback()
|
||||
ctx.status(HttpStatus.INTERNAL_SERVER_ERROR).result("Vendor Creation failed" + e.message)
|
||||
} finally {
|
||||
txn.end()
|
||||
}
|
||||
}
|
||||
fun create(ctx :Context){
|
||||
val vendor = ctx.bodyAsClass<Vendor>()
|
||||
database.save(vendor)
|
||||
ctx.result("vendor created")
|
||||
ctx.status(HttpStatus.CREATED)
|
||||
ctx.json(vendor)
|
||||
}
|
||||
fun update(ctx :Context){
|
||||
|
||||
@@ -558,6 +632,7 @@ object Vendor {
|
||||
.where()
|
||||
.eq("vendor", id)
|
||||
.findList()
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(quotes)
|
||||
}
|
||||
fun getPos(ctx :Context){
|
||||
@@ -566,6 +641,7 @@ object Vendor {
|
||||
.where()
|
||||
.eq("vendor", id)
|
||||
.findList()
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(pos)
|
||||
}
|
||||
fun rate(ctx :Context){
|
||||
@@ -575,24 +651,29 @@ object Vendor {
|
||||
//could place some rating validation checks
|
||||
vendor.rating = rating
|
||||
vendor.save()
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.result("rating changed")
|
||||
}
|
||||
}
|
||||
object RequestForQuote {
|
||||
fun create(ctx :Context) {
|
||||
fun create(ctx: Context) {
|
||||
val rfq = ctx.bodyAsClass<ReqForQuote>()
|
||||
database.save(rfq)
|
||||
//ctx.result("request for quote created")
|
||||
//ctx.json(rfq)
|
||||
//ctx.status(HttpStatus.CREATED)
|
||||
//ctx.json("asss")
|
||||
ctx.status(HttpStatus.CREATED)
|
||||
ctx.json("asss")
|
||||
}
|
||||
fun get(ctx :Context){
|
||||
|
||||
fun get(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val rfq = database.find(ReqForQuote::class.java, id) ?: throw NotFoundResponse("request for quote not found for id $id")
|
||||
val rfq = database.find(ReqForQuote::class.java, id)
|
||||
?: throw NotFoundResponse("request for quote not found for id $id")
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(rfq)
|
||||
}
|
||||
fun update(ctx :Context){
|
||||
|
||||
fun update(ctx: Context) {
|
||||
//shuld we compare the new body fields with preexisting ones and prepare a sql query to update those fields??
|
||||
|
||||
}
|
||||
|
||||
@@ -4,29 +4,39 @@ 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.ss.util.CellRangeAddressList
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
|
||||
|
||||
import java.io.FileOutputStream
|
||||
import java.text.SimpleDateFormat
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneId
|
||||
import java.util.*
|
||||
|
||||
fun createHeaderRow(cols :List<String>, sh :HSSFSheet) {
|
||||
fun createHeaderRow(cols :List<String>, sh :HSSFSheet, wb: Workbook) {
|
||||
val boldFont = wb.createFont()
|
||||
boldFont.bold = true
|
||||
val style = wb.createCellStyle()
|
||||
style.setFont(boldFont)
|
||||
style.locked = true
|
||||
|
||||
sh.createRow(0).apply {
|
||||
cols.forEachIndexed{index, value ->
|
||||
createCell(index).setCellValue(value)
|
||||
val cell = createCell(index)
|
||||
cell.setCellValue(value)
|
||||
cell.setCellStyle(style)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,19 +78,7 @@ fun doubleFromCellHelper(cell: Cell): Double {
|
||||
}
|
||||
return double?:0.0
|
||||
}
|
||||
fun enumFromCellHelper(cell: Cell, enumFor: EnumFor) :String{
|
||||
var string = ""
|
||||
val cellValue = cell.stringCellValue
|
||||
when(enumFor){
|
||||
EnumFor.UOM -> {
|
||||
string = "uom"
|
||||
}
|
||||
EnumFor.DocType -> {
|
||||
string = "doc"
|
||||
}
|
||||
}
|
||||
return string
|
||||
}
|
||||
|
||||
fun longIntFromCellHelper(cell : Cell) :Long {
|
||||
val long = when(cell.cellType){
|
||||
CellType.NUMERIC -> cell.numericCellValue.toLong()
|
||||
@@ -95,12 +93,59 @@ enum class FileType {
|
||||
enum class EnumFor {
|
||||
UOM, DocType
|
||||
}
|
||||
fun saveExcelFileLocally(fileName :String, wb: Workbook){
|
||||
val out = FileOutputStream(fileName)
|
||||
wb.use {
|
||||
it.write(out)
|
||||
}
|
||||
out.close()
|
||||
}
|
||||
fun TemplateExcelFile(fileType: FileType){
|
||||
when(fileType){
|
||||
FileType.QUOTES -> {
|
||||
val headers : List<String> = listOf("Quotation Number", "Date", "Open Till", "Product Id", "Product Name", "Product Unit Price", "Quantity", "Vendor Name", "Vendor Address", "RFQ Number", "Total Amount", "Terms and Conditions")
|
||||
val wb = HSSFWorkbook()
|
||||
val sh = wb.createSheet()
|
||||
createHeaderRow(headers, sh, wb)
|
||||
saveExcelFileLocally("Quotes_Template.xls", wb)
|
||||
}
|
||||
FileType.POS -> {
|
||||
val headers : List<String> = listOf("Number", "Date", "Open Till", "Reference Quotation Number", "Vendor Name", "Vendor Address", "Product Id", "Product Name", "Unit Price", "Quantity", "Total Amount", "Terms and Conditions")
|
||||
val wb = HSSFWorkbook()
|
||||
val sh = wb.createSheet()
|
||||
createHeaderRow(headers, sh, wb)
|
||||
saveExcelFileLocally("Purchase_Order_Template.xls", wb)
|
||||
}
|
||||
FileType.VENDORS -> {
|
||||
val headers : List<String> = listOf("Name", "MSME", "GST Number", "Address", "Rating", "Contact Name", "Contact Email", "Contact Mobile")
|
||||
val wb = HSSFWorkbook()
|
||||
val sh = wb.createSheet()
|
||||
createHeaderRow(headers, sh, wb)
|
||||
saveExcelFileLocally("Vendors_Template.xls", wb)
|
||||
}
|
||||
FileType.PRODS -> {
|
||||
val headers : List<String> = listOf("Id", "Name", "Description", "HSN Code", "UOM")
|
||||
val wb = HSSFWorkbook()
|
||||
val sh = wb.createSheet()
|
||||
createHeaderRow(headers, sh, wb)
|
||||
val r0 = CellRangeAddressList(0, 1000, 4, 4)
|
||||
val dv0 = HSSFDataValidation(r0, DVConstraint.createExplicitListConstraint(arrayOf("LTR", "MTR", "NOS", "ALL"))).apply {
|
||||
suppressDropDownArrow = true
|
||||
}
|
||||
sh.addValidationData(dv0)
|
||||
saveExcelFileLocally("Products_Template.xls", wb)
|
||||
}
|
||||
FileType.DOCS -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
fun ExportQuotations(quotes :List<Quotation>) {
|
||||
val wb = HSSFWorkbook()
|
||||
val sh = wb.createSheet()
|
||||
|
||||
val headers : List<String> = listOf("Quotation Number", "Date", "Open Till", "Product Id", "Product Name", "Product Unit Price", "Quantity", "Vendor Name", "Vendor Address", "RFQ Number", "Total AMount", "Terms and Conditions")
|
||||
createHeaderRow(headers, sh)
|
||||
createHeaderRow(headers, sh, wb)
|
||||
val totalCols = headers.size
|
||||
var rowCnt = 1
|
||||
for(quote in quotes){
|
||||
@@ -134,7 +179,7 @@ fun ExportVendors(vendors :List<Vendor>){
|
||||
val sh = wb.createSheet()
|
||||
|
||||
val headers : List<String> = listOf("Name", "MSME", "GST Number", "Address", "Rating", "Contact Name", "Contact Email", "Contact Mobile")
|
||||
createHeaderRow(headers, sh)
|
||||
createHeaderRow(headers, sh, wb)
|
||||
|
||||
val totalCols = headers.size
|
||||
var rowCnt = 1
|
||||
@@ -160,7 +205,7 @@ fun ExportProds(prods :List<Product>){
|
||||
val sh = wb.createSheet()
|
||||
|
||||
val headers : List<String> = listOf("Id", "Name", "Description", "HSN Code", "UOM")
|
||||
createHeaderRow(headers, sh)
|
||||
createHeaderRow(headers, sh, wb)
|
||||
|
||||
val totalCols = headers.size
|
||||
var rowCnt = 1
|
||||
@@ -180,7 +225,7 @@ fun ExportPos(pos :List<PurchaseOrder>){
|
||||
val sh = wb.createSheet()
|
||||
|
||||
val headers : List<String> = listOf("Number", "Date", "Open Till", "Reference Quotation Number", "Vendor Name", "Vendor Address", "Product Id", "Product Name", "Unit Price", "Quantity", "Total Amount", "Terms and Conditions")
|
||||
createHeaderRow(headers, sh)
|
||||
createHeaderRow(headers, sh, wb)
|
||||
|
||||
val totalCols = headers.size
|
||||
var rowCnt = 1
|
||||
@@ -204,12 +249,13 @@ fun ExportPos(pos :List<PurchaseOrder>){
|
||||
row.createCell(i++).setCellValue(po.products[j].quantity)
|
||||
|
||||
row.createCell(i++).setCellValue(po.totalAmount)
|
||||
row.createCell(i++).setCellValue(po.tnc.joinToString(";"))
|
||||
row.createCell(i++).setCellValue(po.tnc?.joinToString(";"))
|
||||
}
|
||||
}
|
||||
}
|
||||
fun main() {
|
||||
ImportFromExcel(FileType.QUOTES, "C:\\Users\\arsalan\\Downloads\\Book.xlsx")
|
||||
//ImportFromExcel(FileType.QUOTES, "C:\\Users\\arsalan\\Downloads\\Book.xlsx")
|
||||
TemplateExcelFile(FileType.PRODS)
|
||||
}
|
||||
|
||||
fun ImportFromExcel(fileType: FileType, filePath : String) {
|
||||
@@ -218,7 +264,7 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
|
||||
|
||||
when(fileType){
|
||||
FileType.QUOTES -> {
|
||||
//Quote Number, ProductName, Product Quantity, Product Uom, Total Amount, RFQ Number, Quote Date, Valid Till, TNC[], Documents[]
|
||||
//Quote Number, ProductName, Product Quantity, Total Amount, RFQ Number, Quote Date, Valid Till, TNC[], Documents[]
|
||||
val quotesMap : MutableMap<String, Quotation> = mutableMapOf()
|
||||
val quotesList : List<Quotation> = mutableListOf()
|
||||
sh.rowIterator().forEach { row ->
|
||||
@@ -226,8 +272,8 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
|
||||
//reached eof
|
||||
return@forEach
|
||||
}
|
||||
val quoteNum = stringFromCellHelper(row.getCell(0))
|
||||
val quoteDate = dateFromCellHelper(row.getCell(1))
|
||||
val quoteNumber = stringFromCellHelper(row.getCell(0))
|
||||
val quoteDt = dateFromCellHelper(row.getCell(1))
|
||||
val rfqNum = stringFromCellHelper(row.getCell(2))
|
||||
val quoteValidTill = dateFromCellHelper(row.getCell(3))
|
||||
val vendorName = stringFromCellHelper(row.getCell(4))
|
||||
@@ -236,35 +282,38 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
|
||||
val prodName = stringFromCellHelper(row.getCell(7))
|
||||
val prodQuantity = doubleFromCellHelper(row.getCell(8))
|
||||
val prodUnitPrice = doubleFromCellHelper(row.getCell(9))
|
||||
val prodUom = enumFromCellHelper(row.getCell(10), EnumFor.UOM)
|
||||
val totalQuoteAmount = doubleFromCellHelper(row.getCell(11))
|
||||
val totalQuoteAmount = doubleFromCellHelper(row.getCell(10))
|
||||
val prod = POProducts("", prodName, prodUnitPrice, prodQuantity)
|
||||
|
||||
if (quotesMap.containsKey(quoteNum)) {
|
||||
if (quotesMap.containsKey(quoteNumber)) {
|
||||
//duplicated row
|
||||
quotesMap.get(quoteNum)?.products?.add(prod)
|
||||
quotesMap.get(quoteNumber)?.products?.add(prod)
|
||||
}else {
|
||||
val vendor = Vendor()
|
||||
vendor.name = vendorName
|
||||
vendor.address = vendorAddress
|
||||
vendor.gstNumber = vendorGstNum
|
||||
val v = Vendor()
|
||||
v.apply {
|
||||
name = vendorName
|
||||
address = vendorAddress
|
||||
gstNumber = vendorGstNum
|
||||
}
|
||||
val quote = Quotation()
|
||||
quote.quoteNum = quoteNum
|
||||
quote.quoteDate = quoteDate
|
||||
quote.reqForQuoteNum = rfqNum
|
||||
quote.validTill = quoteValidTill
|
||||
quote.products = mutableListOf<POProducts>(prod)
|
||||
quote.vendor = vendor
|
||||
quote.totalAmount = totalQuoteAmount
|
||||
quotesMap.put(quoteNum, quote)
|
||||
quote.apply {
|
||||
quoteNum = quoteNumber
|
||||
quoteDate = quoteDt
|
||||
reqForQuoteNum = rfqNum
|
||||
validTill = quoteValidTill
|
||||
products = mutableListOf(prod)
|
||||
vendor = v
|
||||
totalAmount = totalQuoteAmount
|
||||
}
|
||||
quotesMap.put(quoteNumber, quote)
|
||||
}
|
||||
}
|
||||
//docs, tncs
|
||||
// println("$quotesMap")
|
||||
|
||||
quotesMap.forEach { (k, v) ->
|
||||
println("$v")
|
||||
}
|
||||
// quotesMap.forEach { (k, v) ->
|
||||
// println("$v")
|
||||
// }
|
||||
}
|
||||
FileType.POS -> {
|
||||
//poNum, poDate, validTill, refQuoteNum, prodName, prodQuantity, totalAmount, products, vendorName, vendorGst, vendorAddress, tnc[]. docs[]
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
package com.restapi.controllers
|
||||
|
||||
import com.restapi.domain.DocType
|
||||
import com.restapi.domain.PurchaseOrder
|
||||
import com.restapi.domain.*
|
||||
import com.restapi.domain.Quotation
|
||||
import com.restapi.domain.ReqForQuote
|
||||
import com.restapi.domain.UOM
|
||||
import java.time.LocalDate
|
||||
import com.restapi.domain.Session.database
|
||||
import java.time.LocalDate
|
||||
|
||||
//constants
|
||||
const val IGNORE = "%"
|
||||
val baseDate :LocalDate = LocalDate.MIN
|
||||
val maxDate :LocalDate = LocalDate.MAX
|
||||
val baseDate :LocalDate = LocalDate.of(1500, 1,1, )
|
||||
val maxDate :LocalDate = LocalDate.of(3000, 1 ,1)
|
||||
const val RATING_MAX = 10.0
|
||||
const val RATING_MIN = 0.0
|
||||
//common filters would be used by most of the handlers
|
||||
@@ -50,8 +47,8 @@ data class RFQFilters (
|
||||
)
|
||||
data class QuoteFilters (
|
||||
val quoteNumLike :String = IGNORE,
|
||||
val validBefore :LocalDate = baseDate,
|
||||
val validAfter :LocalDate = maxDate,
|
||||
val validBefore :LocalDate = maxDate,
|
||||
val validAfter :LocalDate = baseDate,
|
||||
val totalAmountExceeds :Long = Long.MIN_VALUE,
|
||||
val totalAmountLessThan :Long = Long.MAX_VALUE,
|
||||
) :CustomFilters
|
||||
@@ -91,12 +88,8 @@ fun searchQuotes(commonFilters: CommonFilters, quoteFilters: QuoteFilters) : Lis
|
||||
.le("validTill", quoteFilters.validBefore)
|
||||
.ge("totalAmount", quoteFilters.totalAmountExceeds)
|
||||
.le("totalAmount", quoteFilters.totalAmountLessThan)
|
||||
.ilike("quoteNum", quoteFilters.quoteNumLike )
|
||||
.apply {
|
||||
if(!commonFilters.vendor?.isEmpty()!!){
|
||||
commonFilters.vendor.let { this.`in`("vendor", it) }
|
||||
}
|
||||
}
|
||||
.ilike("quoteNum", "%" + quoteFilters.quoteNumLike + "%")
|
||||
applyVendorHelper(q, commonFilters.vendor)
|
||||
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
|
||||
return q.findList()
|
||||
}
|
||||
@@ -105,10 +98,10 @@ fun searchVendors(commonFilters: CommonFilters, vendorFilters: VendorFilters) :
|
||||
.where()
|
||||
.ge("rating", vendorFilters.ratingExceeds)
|
||||
.le("rating", vendorFilters.ratingLessThan)
|
||||
.ilike("name", vendorFilters.nameLike)
|
||||
.ilike("msme", vendorFilters.msmeLike)
|
||||
.ilike("gstNum", vendorFilters.gstNumLike)
|
||||
.ilike("address", vendorFilters.addressLike)
|
||||
.ilike("name", "%" + vendorFilters.nameLike + "%")
|
||||
.ilike("msme", "%" + vendorFilters.msmeLike + "%")
|
||||
.ilike("gstNumber", "%" + vendorFilters.gstNumLike + "%")
|
||||
.ilike("address", "%" + vendorFilters.addressLike + "%")
|
||||
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
|
||||
return q.findList()
|
||||
}
|
||||
@@ -120,7 +113,7 @@ fun searchDocs(commonFilters: CommonFilters, documentFilters: DocumentFilters) :
|
||||
this.eq("docType", documentFilters.typeOfDoc)
|
||||
}
|
||||
}
|
||||
.ilike("name", documentFilters.nameLike )
|
||||
.ilike("name", "%" + documentFilters.nameLike + "%")
|
||||
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
|
||||
applyVendorHelper(q, commonFilters.vendor)
|
||||
return q.findList()
|
||||
@@ -133,8 +126,8 @@ fun searchPos(commonFilters: CommonFilters, poFilters: POFilters?) : List<Purcha
|
||||
.le("totalAmount", poFilters.totalAmountLessThan)
|
||||
.ge("validTill", poFilters.validAfter)
|
||||
.le("validTill", poFilters.validBefore)
|
||||
.ilike("poNum", poFilters.poNumLike )
|
||||
.ilike("referenceQuotation", poFilters.refQuotation )
|
||||
.ilike("poNum", "%" + poFilters.poNumLike + "%")
|
||||
.ilike("referenceQuotation", "%" + poFilters.refQuotation + "%")
|
||||
applyVendorHelper(q, commonFilters.vendor)
|
||||
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
|
||||
return q.findList()
|
||||
@@ -144,7 +137,7 @@ fun searchRFQ(commonFilters: CommonFilters, rfqFilters: RFQFilters) : List<ReqFo
|
||||
.where()
|
||||
.ge("validTill", rfqFilters.validAfter)
|
||||
.le("validTill", rfqFilters.validBefore)
|
||||
.ilike("reqForQuoteNum", rfqFilters.reqForQuoteNumLike)
|
||||
.ilike("reqForQuoteNum", "%" + rfqFilters.reqForQuoteNumLike + "%")
|
||||
applyVendorHelper(q, commonFilters.vendor)
|
||||
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
|
||||
return q.findList()
|
||||
|
||||
@@ -243,7 +243,7 @@ class SafeStringDeserializer : JsonDeserializer<String>() {
|
||||
}
|
||||
}
|
||||
|
||||
data class ContactPerson(val name: String, val email: String, val mobile: String)
|
||||
data class ContactPerson(val name: String = "", val email: String = "", val mobile: String = "")
|
||||
@Entity
|
||||
open class Vendor :BaseTenantModel() {
|
||||
var name :String = ""
|
||||
@@ -260,15 +260,15 @@ open class PurchaseOrder :BaseTenantModel() {
|
||||
var products :MutableList<POProducts> = mutableListOf()
|
||||
@ManyToOne
|
||||
var vendor :Vendor? = null
|
||||
var referenceQuotation :String = ""
|
||||
var referenceQuotation :String? = ""
|
||||
var totalAmount :Double = 0.0
|
||||
var poNum: String = ""
|
||||
var poDate: LocalDate? = null
|
||||
var validTill: LocalDate? = null
|
||||
@DbArray
|
||||
var tnc: List<String> = arrayListOf()
|
||||
var tnc: List<String>? = arrayListOf()
|
||||
@DbArray
|
||||
var documents: MutableList<Long> = arrayListOf()
|
||||
var documents: MutableList<Long>? = arrayListOf()
|
||||
}
|
||||
|
||||
enum class UOM {
|
||||
@@ -292,7 +292,7 @@ open class Quotation :BaseTenantModel() {
|
||||
var vendor :Vendor? = null
|
||||
var totalAmount :Double = 0.0
|
||||
|
||||
var reqForQuoteNum: String = ""
|
||||
var reqForQuoteNum: String? = ""
|
||||
var quoteNum: String = ""
|
||||
var quoteDate: LocalDate? = null
|
||||
var validTill: LocalDate? = null
|
||||
|
||||
Reference in New Issue
Block a user