add vendor module

This commit is contained in:
arsalan 2024-02-21 17:22:45 +05:30
parent 338f86a5f5
commit 9a60105ed3
10 changed files with 299 additions and 120 deletions

7
.gitignore vendored
View File

@ -44,3 +44,10 @@ application.yaml
initial-data.sql initial-data.sql
app.yaml app.yaml
*.env.json *.env.json
### API Logs ###
api.log
api.2024*
### Excel FIles ###
./excel

BIN
excel/Pos.xls Normal file

Binary file not shown.

BIN
excel/Products.xls Normal file

Binary file not shown.

BIN
excel/Quotes.xls Normal file

Binary file not shown.

BIN
excel/VendorList.xls Normal file

Binary file not shown.

View File

@ -119,6 +119,7 @@ fun main(args: Array<String>) {
get("quotes/{id}", VendorCtrl::getQuotes, Roles(Role.Explicit("ROLE_QUOTE_VIEW", "ROLE_QUOTE_CREATE", "ROLE_VENDOR_VIEW"))) get("quotes/{id}", VendorCtrl::getQuotes, Roles(Role.Explicit("ROLE_QUOTE_VIEW", "ROLE_QUOTE_CREATE", "ROLE_VENDOR_VIEW")))
get("pos/{id}", VendorCtrl::getPos, Roles(Role.Explicit("ROLE_PO_VIEW", "ROLE_PO_CREATE`"))) get("pos/{id}", VendorCtrl::getPos, Roles(Role.Explicit("ROLE_PO_VIEW", "ROLE_PO_CREATE`")))
put("/rate/{id}/{rating}", VendorCtrl::rate, Roles(Role.Explicit("ROLE_VENDOR_CREATE"))) put("/rate/{id}/{rating}", VendorCtrl::rate, Roles(Role.Explicit("ROLE_VENDOR_CREATE")))
put("/{id}", VendorCtrl::update, Roles(Role.Explicit("ROLE_VENDOR_CREATE")))
} }
path("/po") { path("/po") {
get("/next", PurchaseOrderCtrl::getNextNum, Roles(Role.Explicit("ROLE_PO_CREATE"))) get("/next", PurchaseOrderCtrl::getNextNum, Roles(Role.Explicit("ROLE_PO_CREATE")))
@ -126,6 +127,7 @@ fun main(args: Array<String>) {
post("/batch", PurchaseOrderCtrl::createBatch, Roles(Role.Explicit("ROLE_PO_CREATE"))) post("/batch", PurchaseOrderCtrl::createBatch, Roles(Role.Explicit("ROLE_PO_CREATE")))
post("/getAll", PurchaseOrderCtrl::getAll, Roles(Role.Explicit("ROLE_PO_CREATE", "ROLE_PO_VIEW", "ROLE_VENDOR_CREATE"))) post("/getAll", PurchaseOrderCtrl::getAll, Roles(Role.Explicit("ROLE_PO_CREATE", "ROLE_PO_VIEW", "ROLE_VENDOR_CREATE")))
get("/{id}", PurchaseOrderCtrl::get, Roles(Role.Explicit("ROLE_PO_CREATE", "ROLE_PO_VIEW", "ROLE_QUOTE_CREATE"))) get("/{id}", PurchaseOrderCtrl::get, Roles(Role.Explicit("ROLE_PO_CREATE", "ROLE_PO_VIEW", "ROLE_QUOTE_CREATE")))
put("/{id}", PurchaseOrderCtrl::update, Roles(Role.Explicit("ROLE_PO_CREATE")))
put("/approve/{id}", PurchaseOrderCtrl::approve, Roles(Role.Explicit())) put("/approve/{id}", PurchaseOrderCtrl::approve, Roles(Role.Explicit()))
put("/reject/{id}", PurchaseOrderCtrl::reject, Roles(Role.Explicit())) put("/reject/{id}", PurchaseOrderCtrl::reject, Roles(Role.Explicit()))
get("/refQuote/{id}", PurchaseOrderCtrl::quoteReference, Roles(Role.Explicit("ROLE_PO_CREATE"))) get("/refQuote/{id}", PurchaseOrderCtrl::quoteReference, Roles(Role.Explicit("ROLE_PO_CREATE")))
@ -136,6 +138,7 @@ fun main(args: Array<String>) {
post("/batch", QuotationCtrl::createBatch, Roles(Role.Explicit("ROLE_QUOTE_CREATE"))) post("/batch", QuotationCtrl::createBatch, Roles(Role.Explicit("ROLE_QUOTE_CREATE")))
post("/getAll", QuotationCtrl::getAll, Roles(Role.Explicit("ROLE_QUOTE_CREATE", "ROLE_QUOTE_VIEW"))) post("/getAll", QuotationCtrl::getAll, Roles(Role.Explicit("ROLE_QUOTE_CREATE", "ROLE_QUOTE_VIEW")))
get("/{id}", QuotationCtrl::get, Roles(Role.Explicit("ROLE_QUOTE_VIEW", "ROLE_QUOTE_CREATE"))) get("/{id}", QuotationCtrl::get, Roles(Role.Explicit("ROLE_QUOTE_VIEW", "ROLE_QUOTE_CREATE")))
put("/{id}", QuotationCtrl::update, Roles(Role.Explicit("ROLE_QUOTE_CREATE")))
delete("/{id}", QuotationCtrl::delete, Roles(Role.Explicit("ROLE_QUOTE_CREATE"))) delete("/{id}", QuotationCtrl::delete, Roles(Role.Explicit("ROLE_QUOTE_CREATE")))
} }
path("/product") { path("/product") {

View File

@ -14,6 +14,7 @@ import io.ebean.CallableSql
import io.ebean.RawSqlBuilder import io.ebean.RawSqlBuilder
import io.javalin.http.* import io.javalin.http.*
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.io.FileInputStream
import java.sql.Types import java.sql.Types
import java.time.LocalDate import java.time.LocalDate
import java.time.LocalDateTime import java.time.LocalDateTime
@ -396,7 +397,14 @@ object PurchaseOrderCtrl {
fun getAll(ctx: Context) { fun getAll(ctx: Context) {
val filters = ctx.bodyAsClass<PF>() val filters = ctx.bodyAsClass<PF>()
val pos = searchPos(filters.common, filters.poFilters) val pos = searchPos(filters.common, filters.poFilters)
ctx.json(pos).status(HttpStatus.OK) val excel = ctx.queryParam("excel")
if(excel != null){
exportPos(pos)
val inputStream = FileInputStream("./excel/Pos.xls")
ctx.result(inputStream).status(HttpStatus.OK)
}else{
ctx.json(pos).status(HttpStatus.OK)
}
} }
fun create(ctx: Context) { fun create(ctx: Context) {
@ -450,13 +458,16 @@ object PurchaseOrderCtrl {
?: throw NotFoundResponse("reference quotation not found for po $id") ?: throw NotFoundResponse("reference quotation not found for po $id")
ctx.json(quote) ctx.json(quote)
} }
fun update(ctx: Context) { fun update(ctx: Context) {
val id = ctx.pathParam("id") val id = ctx.pathParam("id").toLong()
val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("po not found for $id") val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("po not found for $id")
val updatedPo = ctx.bodyAsClass<PurchaseOrder>() val updatedPo = ctx.bodyAsClass<PurchaseOrder>()
po.patchValues(updatedPo) po.patchValues(updatedPo)
po.update() po.update()
ctx.json(po).status(HttpStatus.OK)
} }
fun delete(ctx: Context) { fun delete(ctx: Context) {
val id = ctx.pathParam("id") val id = ctx.pathParam("id")
val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("no po found with id $id") val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("no po found with id $id")
@ -487,8 +498,15 @@ object ProductCtrl {
val productList = Session.database.find(Product::class.java) val productList = Session.database.find(Product::class.java)
.findList() .findList()
.sortedBy { it.name } .sortedBy { it.name }
val excel = ctx.queryParam("excel")
if(excel != null){
exportProds(productList)
val inputStream = FileInputStream("./excel/Products.xls")
ctx.result(inputStream).status(HttpStatus.OK)
ctx.json(productList) }else{
ctx.json(productList)
}
} }
fun create(ctx: Context) { fun create(ctx: Context) {
@ -496,12 +514,14 @@ object ProductCtrl {
database.save(product) database.save(product)
ctx.json(product).status(HttpStatus.CREATED) ctx.json(product).status(HttpStatus.CREATED)
} }
fun delete(ctx: Context) { fun delete(ctx: Context) {
val id = ctx.pathParam("id") val id = ctx.pathParam("id")
val prod = database.find(Product::class.java, id) ?: throw NotFoundResponse("no product found with id $id") val prod = database.find(Product::class.java, id) ?: throw NotFoundResponse("no product found with id $id")
database.delete(prod) database.delete(prod)
ctx.status(HttpStatus.OK) ctx.status(HttpStatus.OK)
} }
fun patch(ctx: Context) { fun patch(ctx: Context) {
val id = ctx.pathParam("id") val id = ctx.pathParam("id")
val patchValues = ctx.bodyAsClass<Map<String, Any>>() val patchValues = ctx.bodyAsClass<Map<String, Any>>()
@ -520,11 +540,12 @@ object ProductCtrl {
} }
fun update(ctx: Context) { fun update(ctx: Context) {
val id = ctx.pathParam("id") val id = ctx.pathParam("id").toLong()
val product = database.find(Product::class.java, id) ?: throw NotFoundResponse("product not found for $id") val product = database.find(Product::class.java, id) ?: throw NotFoundResponse("product not found for $id")
val updatedProduct = ctx.bodyAsClass<Product>() val updatedProduct = ctx.bodyAsClass<Product>()
product.patchValues(updatedProduct) product.patchValues(updatedProduct)
product.update() product.update()
ctx.json(product).status(HttpStatus.OK)
} }
@ -573,8 +594,15 @@ object QuotationCtrl {
fun getAll(ctx: Context) { fun getAll(ctx: Context) {
val filters = ctx.bodyAsClass<QF>() val filters = ctx.bodyAsClass<QF>()
val excel: String? = ctx.queryParam("excel")
val quotes = searchQuotes(filters.common, filters.quoteFilters) val quotes = searchQuotes(filters.common, filters.quoteFilters)
ctx.json(quotes).status(HttpStatus.OK) if (excel != null) {
exportQuotations(quotes)
val inputStream = FileInputStream("./excel/Quotes.xls")
ctx.result(inputStream).status(HttpStatus.OK)
} else {
ctx.json(quotes).status(HttpStatus.OK)
}
} }
fun create(ctx: Context) { fun create(ctx: Context) {
@ -599,18 +627,21 @@ object QuotationCtrl {
} }
ctx.result("Quotes batch created").status(HttpStatus.CREATED) ctx.result("Quotes batch created").status(HttpStatus.CREATED)
} }
fun delete(ctx: Context) { fun delete(ctx: Context) {
val id = ctx.pathParam("id") val id = ctx.pathParam("id")
val quote = database.find(Quotation::class.java, id) ?: throw NotFoundResponse("no quote found with id $id") val quote = database.find(Quotation::class.java, id) ?: throw NotFoundResponse("no quote found with id $id")
database.delete(quote) database.delete(quote)
ctx.status(HttpStatus.OK) ctx.status(HttpStatus.OK)
} }
fun update(ctx: Context) { fun update(ctx: Context) {
val id = ctx.pathParam("id") val id = ctx.pathParam("id").toLong()
val quote = database.find(Quotation::class.java, id) ?: throw NotFoundResponse("quote not found for $id") val quote = database.find(Quotation::class.java, id) ?: throw NotFoundResponse("quote not found for $id")
val updatedQuote = ctx.bodyAsClass<Quotation>() val updatedQuote = ctx.bodyAsClass<Quotation>()
quote.patchValues(updatedQuote) quote.patchValues(updatedQuote)
quote.update() quote.update()
ctx.json(quote).status(HttpStatus.OK)
} }
} }
@ -632,12 +663,14 @@ object DocumentCtrl {
fun print(ctx: Context) { fun print(ctx: Context) {
//would be handled in the frontend ?? //would be handled in the frontend ??
} }
fun delete(ctx: Context) { fun delete(ctx: Context) {
val id = ctx.pathParam("id") val id = ctx.pathParam("id")
val doc = database.find(Document::class.java, id) ?: throw NotFoundResponse("no document found with id $id") val doc = database.find(Document::class.java, id) ?: throw NotFoundResponse("no document found with id $id")
database.delete(doc) database.delete(doc)
ctx.status(HttpStatus.OK) ctx.status(HttpStatus.OK)
} }
fun getWithRefId(ctx: Context) { fun getWithRefId(ctx: Context) {
//fetches a particular doc (po, quote) with ref id //fetches a particular doc (po, quote) with ref id
val refId = ctx.pathParam("refId") val refId = ctx.pathParam("refId")
@ -655,8 +688,8 @@ object DocumentCtrl {
object VendorCtrl { object VendorCtrl {
val logger = LoggerFactory.getLogger("Vendor") val logger = LoggerFactory.getLogger("Vendor")
fun get(ctx: Context) { fun get(ctx: Context) {
val id = ctx.pathParam("id") val id = ctx.pathParam("id").toLong()
val vendor =database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id") val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id")
ctx.status(HttpStatus.OK) ctx.status(HttpStatus.OK)
ctx.json(vendor) ctx.json(vendor)
} }
@ -666,9 +699,15 @@ object VendorCtrl {
fun getAll(ctx: Context) { fun getAll(ctx: Context) {
val filters = ctx.bodyAsClass<VF>() val filters = ctx.bodyAsClass<VF>()
logger.info("filters = {}", filters) logger.info("filters = {}", filters)
val pos = searchVendors(filters.common, filters.vendorFilters) val excel: String? = ctx.queryParam("excel")
ctx.status(HttpStatus.OK) val vendors = searchVendors(filters.common, filters.vendorFilters)
ctx.json(pos) if (excel !== null) {
exportVendors(vendors)
val inputStream = FileInputStream("./excel/VendorList.xls")
ctx.result(inputStream).status(HttpStatus.OK)
} else {
ctx.json(vendors).status(HttpStatus.OK)
}
} }
fun createBatch(ctx: Context) { fun createBatch(ctx: Context) {
@ -684,12 +723,14 @@ object VendorCtrl {
} }
fun update(ctx: Context) { fun update(ctx: Context) {
val id = ctx.pathParam("id") val id = ctx.pathParam("id").toLong()
val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("vendor not found for $id") val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("vendor not found for $id")
val updatedVendor = ctx.bodyAsClass<Vendor>() val updatedVendor = ctx.bodyAsClass<Vendor>()
vendor.patchValues(updatedVendor) vendor.patchValues(updatedVendor)
vendor.update() vendor.update()
ctx.json(vendor).status(HttpStatus.OK)
} }
fun delete(ctx: Context) { fun delete(ctx: Context) {
val id = ctx.pathParam("id") val id = ctx.pathParam("id")
val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id") val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id")

View File

@ -1,4 +1,5 @@
package com.restapi.controllers package com.restapi.controllers
import com.google.gson.Gson import com.google.gson.Gson
import com.restapi.domain.* import com.restapi.domain.*
import com.restapi.domain.Document import com.restapi.domain.Document
@ -25,7 +26,7 @@ import java.time.LocalDate
import java.time.ZoneId import java.time.ZoneId
import java.util.* import java.util.*
fun createHeaderRow(cols :List<String>, sh :HSSFSheet, wb: Workbook) { fun createHeaderRow(cols: List<String>, sh: HSSFSheet, wb: Workbook) {
val boldFont = wb.createFont() val boldFont = wb.createFont()
boldFont.bold = true boldFont.bold = true
val style = wb.createCellStyle() val style = wb.createCellStyle()
@ -33,13 +34,14 @@ fun createHeaderRow(cols :List<String>, sh :HSSFSheet, wb: Workbook) {
style.locked = true style.locked = true
sh.createRow(0).apply { sh.createRow(0).apply {
cols.forEachIndexed{index, value -> cols.forEachIndexed { index, value ->
val cell = createCell(index) val cell = createCell(index)
cell.setCellValue(value) cell.setCellValue(value)
cell.setCellStyle(style) cell.setCellStyle(style)
} }
} }
} }
fun String.parseDate(format: String): Date? { fun String.parseDate(format: String): Date? {
val locale = Locale.getDefault() val locale = Locale.getDefault()
return try { return try {
@ -48,227 +50,310 @@ fun String.parseDate(format: String): Date? {
null null
} }
} }
fun dateFromCellHelper(cell: Cell): LocalDate?{
val date = when(cell.cellType){ fun dateFromCellHelper(cell: Cell): LocalDate? {
val date = when (cell.cellType) {
CellType.STRING -> cell.stringCellValue.parseDate("yyyy-MM-dd") CellType.STRING -> cell.stringCellValue.parseDate("yyyy-MM-dd")
CellType.NUMERIC -> { CellType.NUMERIC -> {
if (DateUtil.isCellDateFormatted(cell)) { if (DateUtil.isCellDateFormatted(cell)) {
cell.getDateCellValue() cell.getDateCellValue()
} else{ } else {
null null
} }
} }
else -> null else -> null
} }
return date?.toInstant()?.atZone(ZoneId.systemDefault())?.toLocalDate() return date?.toInstant()?.atZone(ZoneId.systemDefault())?.toLocalDate()
} }
fun stringFromCellHelper(cell: Cell): String { fun stringFromCellHelper(cell: Cell): String {
val string = when(cell.cellType){ val string = when (cell.cellType) {
CellType.NUMERIC -> cell.numericCellValue.toString() CellType.NUMERIC -> cell.numericCellValue.toString()
CellType.STRING -> cell.stringCellValue CellType.STRING -> cell.stringCellValue
else -> "" else -> ""
} }
return string return string
} }
fun doubleFromCellHelper(cell: Cell): Double { fun doubleFromCellHelper(cell: Cell): Double {
val double = when(cell.cellType){ val double = when (cell.cellType) {
CellType.NUMERIC -> cell.numericCellValue CellType.NUMERIC -> cell.numericCellValue
CellType.STRING -> cell.stringCellValue.toDoubleOrNull() CellType.STRING -> cell.stringCellValue.toDoubleOrNull()
else -> 0.0 else -> 0.0
} }
return double?:0.0 return double ?: 0.0
} }
fun longIntFromCellHelper(cell : Cell) :Long { fun longIntFromCellHelper(cell: Cell): Long {
val long = when(cell.cellType){ val long = when (cell.cellType) {
CellType.NUMERIC -> cell.numericCellValue.toLong() CellType.NUMERIC -> cell.numericCellValue.toLong()
CellType.STRING -> cell.stringCellValue.toLong() CellType.STRING -> cell.stringCellValue.toLong()
else -> 0 else -> 0
} }
return long return long
} }
enum class FileType { enum class FileType {
QUOTES, POS, VENDORS, PRODS, DOCS QUOTES, POS, VENDORS, PRODS, DOCS
} }
enum class EnumFor { enum class EnumFor {
UOM, DocType UOM, DocType
} }
fun saveExcelFileLocally(fileName :String, wb: Workbook){ fun saveExcelFileLocally(fileName: String, wb: Workbook) {
val out = FileOutputStream(fileName) val path = "./excel/"
val out = FileOutputStream(path + fileName)
wb.use { wb.use {
it.write(out) it.write(out)
} }
out.close() out.close()
} }
fun TemplateExcelFile(fileType: FileType){
when(fileType){ fun TemplateExcelFile(fileType: FileType) {
when (fileType) {
FileType.QUOTES -> { 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 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 wb = HSSFWorkbook()
val sh = wb.createSheet() val sh = wb.createSheet()
createHeaderRow(headers, sh, wb) createHeaderRow(headers, sh, wb)
saveExcelFileLocally("Quotes_Template.xls", wb) saveExcelFileLocally("Quotes_Template.xls", wb)
} }
FileType.POS -> { 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 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 wb = HSSFWorkbook()
val sh = wb.createSheet() val sh = wb.createSheet()
createHeaderRow(headers, sh, wb) createHeaderRow(headers, sh, wb)
saveExcelFileLocally("Purchase_Order_Template.xls", wb) saveExcelFileLocally("Purchase_Order_Template.xls", wb)
} }
FileType.VENDORS -> { FileType.VENDORS -> {
val headers : List<String> = listOf("Name", "MSME", "GST Number", "Address", "Rating", "Contact Name", "Contact Email", "Contact Mobile") val headers: List<String> = listOf(
"Name",
"MSME",
"GST Number",
"Address",
"Rating",
"Contact Name",
"Contact Email",
"Contact Mobile"
)
val wb = HSSFWorkbook() val wb = HSSFWorkbook()
val sh = wb.createSheet() val sh = wb.createSheet()
createHeaderRow(headers, sh, wb) createHeaderRow(headers, sh, wb)
saveExcelFileLocally("Vendors_Template.xls", wb) saveExcelFileLocally("Vendors_Template.xls", wb)
} }
FileType.PRODS -> { FileType.PRODS -> {
val headers : List<String> = listOf("Id", "Name", "Description", "HSN Code", "UOM") val headers: List<String> = listOf("Id", "Name", "Description", "HSN Code", "UOM")
val wb = HSSFWorkbook() val wb = HSSFWorkbook()
val sh = wb.createSheet() val sh = wb.createSheet()
createHeaderRow(headers, sh, wb) createHeaderRow(headers, sh, wb)
val r0 = CellRangeAddressList(0, 1000, 4, 4) val r0 = CellRangeAddressList(0, 1000, 4, 4)
val dv0 = HSSFDataValidation(r0, DVConstraint.createExplicitListConstraint(arrayOf("LTR", "MTR", "NOS", "ALL"))).apply { val dv0 = HSSFDataValidation(
r0,
DVConstraint.createExplicitListConstraint(arrayOf("LTR", "MTR", "NOS", "ALL"))
).apply {
suppressDropDownArrow = true suppressDropDownArrow = true
} }
sh.addValidationData(dv0) sh.addValidationData(dv0)
saveExcelFileLocally("Products_Template.xls", wb) saveExcelFileLocally("Products_Template.xls", wb)
} }
FileType.DOCS -> { FileType.DOCS -> {
} }
} }
} }
fun ExportQuotations(quotes :List<Quotation>) {
fun exportQuotations(quotes: List<Quotation>) {
val wb = HSSFWorkbook() val wb = HSSFWorkbook()
val sh = wb.createSheet() 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") 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, wb) createHeaderRow(headers, sh, wb)
val totalCols = headers.size
var rowCnt = 1 var rowCnt = 1
for(quote in quotes){ for (quote in quotes) {
val prodCnt = quote.products.size val prodCnt = quote.products.size
for (j in 0..prodCnt - 1){ for (j in 0..<prodCnt) {
val row = sh.createRow(rowCnt++) val row = sh.createRow(rowCnt++)
var i = 0; var i = 0;
row.createCell(i++).setCellValue(quote.quoteNum) row.createCell(i++).setCellValue(quote.quoteNum)
row.createCell(i++).setCellValue(quote.quoteDate) row.createCell(i++).setCellValue(quote.quoteDate)
row.createCell(i++).setCellValue(quote.validTill) row.createCell(i++).setCellValue(quote.validTill)
//6 would be repeated //6 would be repeated
row.createCell(i++).setCellValue(quote.products[j].productId) row.createCell(i++).setCellValue(quote.products[j].productId)
row.createCell(i++).setCellValue(quote.products[j].productName) row.createCell(i++).setCellValue(quote.products[j].productName)
row.createCell(i++).setCellValue(quote.products[j].unitPrice) row.createCell(i++).setCellValue(quote.products[j].unitPrice)
row.createCell(i++).setCellValue(quote.products[j].quantity) row.createCell(i++).setCellValue(quote.products[j].quantity)
row.createCell(i++).setCellValue(quote.vendor?.name) row.createCell(i++).setCellValue(quote.vendor?.name)
row.createCell(i++).setCellValue(quote.vendor?.address) row.createCell(i++).setCellValue(quote.vendor?.address)
row.createCell(i++).setCellValue(quote.reqForQuoteNum) row.createCell(i++).setCellValue(quote.reqForQuoteNum)
row.createCell(i++).setCellValue(quote.totalAmount) row.createCell(i++).setCellValue(quote.totalAmount)
row.createCell(i++).setCellValue(quote.tnc?.joinToString(";")) row.createCell(i++).setCellValue(quote.tnc?.joinToString(";"))
} }
} }
saveExcelFileLocally("Quotes.xls", wb)
} }
fun ExportVendors(vendors :List<Vendor>){ fun exportVendors(vendors: List<Vendor>) {
val wb = HSSFWorkbook() val wb = HSSFWorkbook()
val sh = wb.createSheet() val sh = wb.createSheet()
val headers : List<String> = listOf("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) createHeaderRow(headers, sh, wb)
val totalCols = headers.size val totalCols = headers.size
var rowCnt = 1 var rowCnt = 1
for (vendor in vendors){ for (vendor in vendors) {
val contactCnt = vendor.contacts.size val contactCnt = vendor.contacts.size
for (j in 0..contactCnt - 1){ for (j in 0..<contactCnt) {
val row = sh.createRow(rowCnt++) val row = sh.createRow(rowCnt++)
var i = 0 var i = 0
row.createCell(i++).setCellValue(vendor.msme) row.createCell(i++).setCellValue((rowCnt - 1).toString())
row.createCell(i++).setCellValue(vendor.gstNumber) row.createCell(i++).setCellValue(vendor.name)
row.createCell(i++).setCellValue(vendor.address) row.createCell(i++).setCellValue(vendor.msme)
row.createCell(i++).setCellValue(vendor.rating) row.createCell(i++).setCellValue(vendor.gstNumber)
row.createCell(i++).setCellValue(vendor.contacts[j].name) row.createCell(i++).setCellValue(vendor.address)
row.createCell(i++).setCellValue(vendor.contacts[j].email) row.createCell(i++).setCellValue(vendor.rating)
row.createCell(i++).setCellValue(vendor.contacts[j].mobile) row.createCell(i++).setCellValue(vendor.contacts[j].name)
row.createCell(i++).setCellValue(vendor.contacts[j].email)
row.createCell(i++).setCellValue(vendor.contacts[j].mobile)
} }
} }
saveExcelFileLocally("VendorList.xls", wb)
} }
fun ExportProds(prods :List<Product>){ fun exportProds(prods: List<Product>) {
val wb = HSSFWorkbook() val wb = HSSFWorkbook()
val sh = wb.createSheet() val sh = wb.createSheet()
val headers : List<String> = listOf("Id", "Name", "Description", "HSN Code", "UOM") val headers: List<String> = listOf("Id", "Name", "Description", "HSN Code", "UOM")
createHeaderRow(headers, sh, wb) createHeaderRow(headers, sh, wb)
val totalCols = headers.size
var rowCnt = 1 var rowCnt = 1
for (prod in prods){ for (prod in prods) {
val row = sh.createRow(rowCnt++) val row = sh.createRow(rowCnt++)
var i = 0 var i = 0
row.createCell(i++).setCellValue(prod.id.toString()) row.createCell(i++).setCellValue(prod.id.toString())
row.createCell(i++).setCellValue(prod.name) row.createCell(i++).setCellValue(prod.name)
row.createCell(i++).setCellValue(prod.description) row.createCell(i++).setCellValue(prod.description)
row.createCell(i++).setCellValue(prod.hsnCode) row.createCell(i++).setCellValue(prod.hsnCode)
row.createCell(i++).setCellValue(prod.uom?.name) row.createCell(i++).setCellValue(prod.uom?.name)
} }
saveExcelFileLocally("Products.xls", wb)
} }
fun ExportPos(pos :List<PurchaseOrder>){
fun exportPos(pos: List<PurchaseOrder>) {
val wb = HSSFWorkbook() val wb = HSSFWorkbook()
val sh = wb.createSheet() 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") 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, wb) createHeaderRow(headers, sh, wb)
val totalCols = headers.size
var rowCnt = 1 var rowCnt = 1
for(po in pos){ for (po in pos) {
val prodCnt = po.products.size val prodCnt = po.products.size
for (j in 0..prodCnt - 1){ for (j in 0..<prodCnt) {
val row = sh.createRow(rowCnt++) val row = sh.createRow(rowCnt++)
var i = 0 var i = 0
row.createCell(i++).setCellValue(po.poNum) row.createCell(i++).setCellValue(po.poNum)
row.createCell(i++).setCellValue(po.poDate) row.createCell(i++).setCellValue(po.poDate)
row.createCell(i++).setCellValue(po.validTill) row.createCell(i++).setCellValue(po.validTill)
row.createCell(i++).setCellValue(po.referenceQuotation) row.createCell(i++).setCellValue(po.referenceQuotation)
row.createCell(i++).setCellValue(po.vendor?.name) row.createCell(i++).setCellValue(po.vendor?.name)
row.createCell(i++).setCellValue(po.vendor?.address) row.createCell(i++).setCellValue(po.vendor?.address)
//6 would be repeated //6 would be repeated
row.createCell(i++).setCellValue(po.products[j].productId) row.createCell(i++).setCellValue(po.products[j].productId)
row.createCell(i++).setCellValue(po.products[j].productName) row.createCell(i++).setCellValue(po.products[j].productName)
row.createCell(i++).setCellValue(po.products[j].unitPrice) row.createCell(i++).setCellValue(po.products[j].unitPrice)
row.createCell(i++).setCellValue(po.products[j].quantity) row.createCell(i++).setCellValue(po.products[j].quantity)
row.createCell(i++).setCellValue(po.totalAmount) row.createCell(i++).setCellValue(po.totalAmount)
row.createCell(i++).setCellValue(po.tnc?.joinToString(";")) row.createCell(i++).setCellValue(po.tnc?.joinToString(";"))
} }
} }
saveExcelFileLocally("Pos.xls", wb)
} }
fun main() { fun main() {
//ImportFromExcel(FileType.QUOTES, "C:\\Users\\arsalan\\Downloads\\Book.xlsx") //ImportFromExcel(FileType.QUOTES, "C:\\Users\\arsalan\\Downloads\\Book.xlsx")
TemplateExcelFile(FileType.PRODS) TemplateExcelFile(FileType.PRODS)
} }
fun ImportFromExcel(fileType: FileType, filePath : String) { fun ImportFromExcel(fileType: FileType, filePath: String) {
val wb = WorkbookFactory.create(File(filePath)) val wb = WorkbookFactory.create(File(filePath))
val sh = wb.getSheetAt(0) val sh = wb.getSheetAt(0)
when(fileType){ when (fileType) {
FileType.QUOTES -> { FileType.QUOTES -> {
//Quote Number, ProductName, Product Quantity, 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 quotesMap: MutableMap<String, Quotation> = mutableMapOf()
val quotesList : List<Quotation> = mutableListOf() val quotesList: List<Quotation> = mutableListOf()
sh.rowIterator().forEach { row -> sh.rowIterator().forEach { row ->
if(row == null){ if (row == null) {
//reached eof //reached eof
return@forEach return@forEach
} }
@ -288,7 +373,7 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
if (quotesMap.containsKey(quoteNumber)) { if (quotesMap.containsKey(quoteNumber)) {
//duplicated row //duplicated row
quotesMap.get(quoteNumber)?.products?.add(prod) quotesMap.get(quoteNumber)?.products?.add(prod)
}else { } else {
val v = Vendor() val v = Vendor()
v.apply { v.apply {
name = vendorName name = vendorName
@ -309,17 +394,18 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
} }
} }
//docs, tncs //docs, tncs
// println("$quotesMap") // println("$quotesMap")
// quotesMap.forEach { (k, v) -> // quotesMap.forEach { (k, v) ->
// println("$v") // println("$v")
// } // }
} }
FileType.POS -> { FileType.POS -> {
//poNum, poDate, validTill, refQuoteNum, prodName, prodQuantity, totalAmount, products, vendorName, vendorGst, vendorAddress, tnc[]. docs[] //poNum, poDate, validTill, refQuoteNum, prodName, prodQuantity, totalAmount, products, vendorName, vendorGst, vendorAddress, tnc[]. docs[]
val PoMap : MutableMap<String, PurchaseOrder> = mutableMapOf() val PoMap: MutableMap<String, PurchaseOrder> = mutableMapOf()
sh.rowIterator().forEach { row -> sh.rowIterator().forEach { row ->
if(row == null) return@forEach if (row == null) return@forEach
val poNum = stringFromCellHelper(row.getCell(0)) val poNum = stringFromCellHelper(row.getCell(0))
val poDate = dateFromCellHelper(row.getCell(1)) val poDate = dateFromCellHelper(row.getCell(1))
val refQuoteNum = stringFromCellHelper(row.getCell(2)) val refQuoteNum = stringFromCellHelper(row.getCell(2))
@ -332,11 +418,11 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
val totalPoAmount = doubleFromCellHelper(row.getCell(9)) val totalPoAmount = doubleFromCellHelper(row.getCell(9))
//tncs, docs //tncs, docs
val prod = POProducts("", prodName, 0.0, prodQuantity,"") val prod = POProducts("", prodName, 0.0, prodQuantity, "")
if(PoMap.containsKey(poNum)){ if (PoMap.containsKey(poNum)) {
//repeated row //repeated row
PoMap.get(poNum)?.products?.add(prod) PoMap.get(poNum)?.products?.add(prod)
}else{ } else {
val vendor = Vendor() val vendor = Vendor()
vendor.name = vendorName vendor.name = vendorName
vendor.address = vendorAddress vendor.address = vendorAddress
@ -350,15 +436,16 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
} }
} }
} }
FileType.VENDORS -> { FileType.VENDORS -> {
sh.rowIterator().forEach { row -> sh.rowIterator().forEach { row ->
//name, msme, gstNum, addresss, rating, contacts //name, msme, gstNum, addresss, rating, contacts
if(row == null) return@forEach if (row == null) return@forEach
val name = stringFromCellHelper(row.getCell(0)) val name = stringFromCellHelper(row.getCell(0))
val msme = stringFromCellHelper(row.getCell(1)) val msme = stringFromCellHelper(row.getCell(1))
val gstNum = stringFromCellHelper(row.getCell(2)) val gstNum = stringFromCellHelper(row.getCell(2))
val address = stringFromCellHelper(row.getCell(3)) val address = stringFromCellHelper(row.getCell(3))
val rating = doubleFromCellHelper(row.getCell(4)) val rating = doubleFromCellHelper(row.getCell(4))
//vendor object //vendor object
val vendor = Vendor() val vendor = Vendor()
@ -369,9 +456,10 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
vendor.rating = rating vendor.rating = rating
} }
} }
FileType.PRODS -> { FileType.PRODS -> {
sh.rowIterator().forEach { row -> sh.rowIterator().forEach { row ->
if(row == null) return@forEach if (row == null) return@forEach
//id, name, description, hsnCode, uom //id, name, description, hsnCode, uom
val prodId = longIntFromCellHelper(row.getCell(0)) val prodId = longIntFromCellHelper(row.getCell(0))
val prodName = stringFromCellHelper(row.getCell(1)) val prodName = stringFromCellHelper(row.getCell(1))
@ -385,7 +473,7 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
prod.name = prodName prod.name = prodName
prod.description = prodDesc prod.description = prodDesc
prod.hsnCode = prodHsnCode prod.hsnCode = prodHsnCode
prod.uom = when(prodUom) { prod.uom = when (prodUom) {
"nos" -> UOM.NOS "nos" -> UOM.NOS
"ltr" -> UOM.LTR "ltr" -> UOM.LTR
"mtr" -> UOM.MTR "mtr" -> UOM.MTR
@ -393,6 +481,7 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
} }
} }
} }
FileType.DOCS -> { FileType.DOCS -> {
sh.rowIterator().forEach { row -> sh.rowIterator().forEach { row ->
//Document Name, Document Type, RefID, url //Document Name, Document Type, RefID, url
@ -405,7 +494,7 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
//new doc object //new doc object
val doc = Document() val doc = Document()
doc.name = docName doc.name = docName
doc.typeOfDoc = when(docType) { doc.typeOfDoc = when (docType) {
"quote" -> DocType.QUOTE "quote" -> DocType.QUOTE
"po" -> DocType.PO "po" -> DocType.PO
"invoice" -> DocType.INVOICE "invoice" -> DocType.INVOICE

View File

@ -14,8 +14,8 @@ const val RATING_MIN = 0.0
//common filters would be used by most of the handlers //common filters would be used by most of the handlers
//require a list of vendor ids to be passed //require a list of vendor ids to be passed
data class CommonFilters( data class CommonFilters(
val fromDate: LocalDate = baseDate, val from: LocalDate = baseDate,
val toDate: LocalDate = maxDate, val to: LocalDate = maxDate,
val vendor: List<Long>? = null, val vendor: List<Long>? = null,
val sortAsc: Boolean = true, val sortAsc: Boolean = true,
val sortBy: String = IGNORE val sortBy: String = IGNORE
@ -97,14 +97,14 @@ fun <T> applyCommonFilters(q: io.ebean.ExpressionList<T>, commonFilters: CommonF
fun searchQuotes(commonFilters: CommonFilters, quoteFilters: QuoteFilters): List<Quotation> { fun searchQuotes(commonFilters: CommonFilters, quoteFilters: QuoteFilters): List<Quotation> {
val q = database.find(Quotation::class.java) val q = database.find(Quotation::class.java)
.where() .where()
.ge("quoteDate", commonFilters.fromDate) .ge("quoteDate", commonFilters.from)
.le("quoteDate", commonFilters.toDate) .le("quoteDate", commonFilters.to)
.ge("validTill", quoteFilters.validAfter) .ge("validTill", quoteFilters.validAfter)
.le("validTill", quoteFilters.validBefore) .le("validTill", quoteFilters.validBefore)
.ge("totalAmount", quoteFilters.totalAmountExceeds) .ge("totalAmount", quoteFilters.totalAmountExceeds)
.le("totalAmount", quoteFilters.totalAmountLessThan) .le("totalAmount", quoteFilters.totalAmountLessThan)
.ilike("quoteNum", "%" + quoteFilters.quoteNumLike + "%") .ilike("quoteNum", "%" + quoteFilters.quoteNumLike + "%")
applyFromToHelper(q, commonFilters.fromDate, commonFilters.toDate, "quoteDate") applyFromToHelper(q, commonFilters.from, commonFilters.to, "quoteDate")
applyVendorHelper(q, commonFilters.vendor) applyVendorHelper(q, commonFilters.vendor)
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc) applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
return q.findList() return q.findList()
@ -123,6 +123,18 @@ fun searchVendors(commonFilters: CommonFilters, vendorFilters: VendorFilters): L
return q.findList() return q.findList()
} }
fun searchProducts(commonFilters: CommonFilters, productFilters: ProductFilters) : List<Product> {
val q = database.find(Product::class.java)
.where()
.ilike("name", "%" + productFilters.nameLike + "%")
.ilike("hsnCode", "%" + productFilters.hsnLike + "%")
if(productFilters.uom != UOM.ALL){
q.eq("uom", productFilters.uom)
}
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
return q.findList()
}
fun searchDocs(commonFilters: CommonFilters, documentFilters: DocumentFilters): List<Document> { fun searchDocs(commonFilters: CommonFilters, documentFilters: DocumentFilters): List<Document> {
val q = database.find(Document::class.java) val q = database.find(Document::class.java)
.where() .where()
@ -147,7 +159,7 @@ fun searchPos(commonFilters: CommonFilters, poFilters: POFilters?): List<Purchas
.le("validTill", poFilters.validBefore) .le("validTill", poFilters.validBefore)
.ilike("poNum", "%" + poFilters.poNumLike + "%") .ilike("poNum", "%" + poFilters.poNumLike + "%")
.ilike("referenceQuotation", "%" + poFilters.refQuotation + "%") .ilike("referenceQuotation", "%" + poFilters.refQuotation + "%")
applyFromToHelper(q, commonFilters.fromDate, commonFilters.toDate, "poDate") applyFromToHelper(q, commonFilters.from, commonFilters.to, "poDate")
applyVendorHelper(q, commonFilters.vendor) applyVendorHelper(q, commonFilters.vendor)
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc) applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
return q.findList() return q.findList()

View File

@ -12,7 +12,13 @@ import java.time.LocalDateTime
import javax.persistence.* import javax.persistence.*
data class Comments(val text: String = "", val by: String = "", val at: LocalDateTime = LocalDateTime.now()) data class Comments(val text: String = "", val by: String = "", val at: LocalDateTime = LocalDateTime.now())
data class POProducts(val productId: String = "", val productName: String = "", val unitPrice: Double = 0.0, val quantity: Double = 0.0, val description: String = "") data class POProducts(
val productId: String = "",
val productName: String = "",
val unitPrice: Double = 0.0,
val quantity: Double = 0.0,
val description: String = ""
)
enum class ApprovalStatus { enum class ApprovalStatus {
@ -246,9 +252,15 @@ data class ContactPerson(val name: String = "", val email: String = "", val mobi
@Entity @Entity
open class Vendor : BaseTenantModel() { open class Vendor : BaseTenantModel() {
fun patchValues(updatedVendor : Vendor) { fun patchValues(updatedVendor: Vendor) {
this.name = updatedVendor.name
this.msme = updatedVendor.msme
this.gstNumber = updatedVendor.gstNumber
this.address = updatedVendor.address
this.rating = updatedVendor.rating
this.contacts = updatedVendor.contacts
} }
var name: String = "" var name: String = ""
var msme: String = "" var msme: String = ""
var gstNumber: String = "" var gstNumber: String = ""
@ -261,9 +273,16 @@ open class Vendor : BaseTenantModel() {
@Entity @Entity
open class PurchaseOrder : BaseTenantModel() { open class PurchaseOrder : BaseTenantModel() {
fun patchValues(updatedPo : PurchaseOrder){ fun patchValues(updatedPo: PurchaseOrder) {
this.poDate = updatedPo.poDate
this.validTill = updatedPo.validTill
this.tnc = updatedPo.tnc
this.products = updatedPo.products
this.vendor = updatedPo.vendor
this.documents = updatedPo.documents
this.totalAmount = updatedPo.totalAmount
} }
@DbJsonB @DbJsonB
var products: MutableList<POProducts> = mutableListOf() var products: MutableList<POProducts> = mutableListOf()
@ -306,8 +325,16 @@ open class Product : BaseTenantModel() {
@Entity @Entity
open class Quotation : BaseTenantModel() { open class Quotation : BaseTenantModel() {
fun patchValues(updatedQuote : Quotation) { fun patchValues(updatedQuote: Quotation) {
this.quoteDate = updatedQuote.quoteDate
this.vendorQuoteNum = updatedQuote.vendorQuoteNum
this.validTill = updatedQuote.validTill
this.reqForQuoteNum = updatedQuote.reqForQuoteNum
this.tnc = updatedQuote.tnc
this.products = updatedQuote.products
this.vendor = updatedQuote.vendor
this.documents = updatedQuote.documents
this.totalAmount = updatedQuote.totalAmount
} }
@DbJsonB @DbJsonB