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

9
.gitignore vendored
View File

@ -43,4 +43,11 @@ bin/
application.yaml
initial-data.sql
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("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("/{id}", VendorCtrl::update, Roles(Role.Explicit("ROLE_VENDOR_CREATE")))
}
path("/po") {
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("/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")))
put("/{id}", PurchaseOrderCtrl::update, Roles(Role.Explicit("ROLE_PO_CREATE")))
put("/approve/{id}", PurchaseOrderCtrl::approve, Roles(Role.Explicit()))
put("/reject/{id}", PurchaseOrderCtrl::reject, Roles(Role.Explicit()))
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("/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")))
put("/{id}", QuotationCtrl::update, Roles(Role.Explicit("ROLE_QUOTE_CREATE")))
delete("/{id}", QuotationCtrl::delete, Roles(Role.Explicit("ROLE_QUOTE_CREATE")))
}
path("/product") {

View File

@ -14,6 +14,7 @@ import io.ebean.CallableSql
import io.ebean.RawSqlBuilder
import io.javalin.http.*
import org.slf4j.LoggerFactory
import java.io.FileInputStream
import java.sql.Types
import java.time.LocalDate
import java.time.LocalDateTime
@ -396,7 +397,14 @@ object PurchaseOrderCtrl {
fun getAll(ctx: Context) {
val filters = ctx.bodyAsClass<PF>()
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) {
@ -450,13 +458,16 @@ object PurchaseOrderCtrl {
?: throw NotFoundResponse("reference quotation not found for po $id")
ctx.json(quote)
}
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 updatedPo = ctx.bodyAsClass<PurchaseOrder>()
po.patchValues(updatedPo)
po.update()
ctx.json(po).status(HttpStatus.OK)
}
fun delete(ctx: Context) {
val id = ctx.pathParam("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)
.findList()
.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) {
@ -496,12 +514,14 @@ object ProductCtrl {
database.save(product)
ctx.json(product).status(HttpStatus.CREATED)
}
fun delete(ctx: Context) {
val id = ctx.pathParam("id")
val prod = database.find(Product::class.java, id) ?: throw NotFoundResponse("no product found with id $id")
database.delete(prod)
ctx.status(HttpStatus.OK)
}
fun patch(ctx: Context) {
val id = ctx.pathParam("id")
val patchValues = ctx.bodyAsClass<Map<String, Any>>()
@ -520,11 +540,12 @@ object ProductCtrl {
}
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 updatedProduct = ctx.bodyAsClass<Product>()
product.patchValues(updatedProduct)
product.update()
ctx.json(product).status(HttpStatus.OK)
}
@ -573,8 +594,15 @@ object QuotationCtrl {
fun getAll(ctx: Context) {
val filters = ctx.bodyAsClass<QF>()
val excel: String? = ctx.queryParam("excel")
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) {
@ -599,18 +627,21 @@ object QuotationCtrl {
}
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("no quote found with id $id")
database.delete(quote)
ctx.status(HttpStatus.OK)
}
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 updatedQuote = ctx.bodyAsClass<Quotation>()
quote.patchValues(updatedQuote)
quote.update()
ctx.json(quote).status(HttpStatus.OK)
}
}
@ -632,12 +663,14 @@ object DocumentCtrl {
fun print(ctx: Context) {
//would be handled in the frontend ??
}
fun delete(ctx: Context) {
val id = ctx.pathParam("id")
val doc = database.find(Document::class.java, id) ?: throw NotFoundResponse("no document found with id $id")
database.delete(doc)
ctx.status(HttpStatus.OK)
}
fun getWithRefId(ctx: Context) {
//fetches a particular doc (po, quote) with ref id
val refId = ctx.pathParam("refId")
@ -655,8 +688,8 @@ object DocumentCtrl {
object VendorCtrl {
val logger = LoggerFactory.getLogger("Vendor")
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")
val id = ctx.pathParam("id").toLong()
val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id")
ctx.status(HttpStatus.OK)
ctx.json(vendor)
}
@ -666,9 +699,15 @@ object VendorCtrl {
fun getAll(ctx: Context) {
val filters = ctx.bodyAsClass<VF>()
logger.info("filters = {}", filters)
val pos = searchVendors(filters.common, filters.vendorFilters)
ctx.status(HttpStatus.OK)
ctx.json(pos)
val excel: String? = ctx.queryParam("excel")
val vendors = searchVendors(filters.common, filters.vendorFilters)
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) {
@ -684,12 +723,14 @@ object VendorCtrl {
}
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 updatedVendor = ctx.bodyAsClass<Vendor>()
vendor.patchValues(updatedVendor)
vendor.update()
ctx.json(vendor).status(HttpStatus.OK)
}
fun delete(ctx: Context) {
val id = ctx.pathParam("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
import com.google.gson.Gson
import com.restapi.domain.*
import com.restapi.domain.Document
@ -25,7 +26,7 @@ import java.time.LocalDate
import java.time.ZoneId
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()
boldFont.bold = true
val style = wb.createCellStyle()
@ -33,13 +34,14 @@ fun createHeaderRow(cols :List<String>, sh :HSSFSheet, wb: Workbook) {
style.locked = true
sh.createRow(0).apply {
cols.forEachIndexed{index, value ->
cols.forEachIndexed { index, value ->
val cell = createCell(index)
cell.setCellValue(value)
cell.setCellStyle(style)
}
}
}
fun String.parseDate(format: String): Date? {
val locale = Locale.getDefault()
return try {
@ -48,227 +50,310 @@ fun String.parseDate(format: String): Date? {
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.NUMERIC -> {
if (DateUtil.isCellDateFormatted(cell)) {
cell.getDateCellValue()
} else{
} else {
null
}
}
else -> null
}
return date?.toInstant()?.atZone(ZoneId.systemDefault())?.toLocalDate()
}
fun stringFromCellHelper(cell: Cell): String {
val string = when(cell.cellType){
val string = when (cell.cellType) {
CellType.NUMERIC -> cell.numericCellValue.toString()
CellType.STRING -> cell.stringCellValue
else -> ""
}
return string
}
fun doubleFromCellHelper(cell: Cell): Double {
val double = when(cell.cellType){
val double = when (cell.cellType) {
CellType.NUMERIC -> cell.numericCellValue
CellType.STRING -> cell.stringCellValue.toDoubleOrNull()
else -> 0.0
}
return double?:0.0
return double ?: 0.0
}
fun longIntFromCellHelper(cell : Cell) :Long {
val long = when(cell.cellType){
fun longIntFromCellHelper(cell: Cell): Long {
val long = when (cell.cellType) {
CellType.NUMERIC -> cell.numericCellValue.toLong()
CellType.STRING -> cell.stringCellValue.toLong()
else -> 0
}
return long
}
enum class FileType {
QUOTES, POS, VENDORS, PRODS, DOCS
}
enum class EnumFor {
UOM, DocType
}
fun saveExcelFileLocally(fileName :String, wb: Workbook){
val out = FileOutputStream(fileName)
fun saveExcelFileLocally(fileName: String, wb: Workbook) {
val path = "./excel/"
val out = FileOutputStream(path + fileName)
wb.use {
it.write(out)
}
out.close()
}
fun TemplateExcelFile(fileType: FileType){
when(fileType){
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 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 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 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 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 {
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>) {
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")
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)
val totalCols = headers.size
var rowCnt = 1
for(quote in quotes){
for (quote in quotes) {
val prodCnt = quote.products.size
for (j in 0..prodCnt - 1){
for (j in 0..<prodCnt) {
val row = sh.createRow(rowCnt++)
var i = 0;
row.createCell(i++).setCellValue(quote.quoteNum)
row.createCell(i++).setCellValue(quote.quoteDate)
row.createCell(i++).setCellValue(quote.validTill)
//6 would be repeated
row.createCell(i++).setCellValue(quote.products[j].productId)
row.createCell(i++).setCellValue(quote.products[j].productName)
row.createCell(i++).setCellValue(quote.products[j].unitPrice)
row.createCell(i++).setCellValue(quote.products[j].quantity)
var i = 0;
row.createCell(i++).setCellValue(quote.quoteNum)
row.createCell(i++).setCellValue(quote.quoteDate)
row.createCell(i++).setCellValue(quote.validTill)
//6 would be repeated
row.createCell(i++).setCellValue(quote.products[j].productId)
row.createCell(i++).setCellValue(quote.products[j].productName)
row.createCell(i++).setCellValue(quote.products[j].unitPrice)
row.createCell(i++).setCellValue(quote.products[j].quantity)
row.createCell(i++).setCellValue(quote.vendor?.name)
row.createCell(i++).setCellValue(quote.vendor?.address)
row.createCell(i++).setCellValue(quote.vendor?.name)
row.createCell(i++).setCellValue(quote.vendor?.address)
row.createCell(i++).setCellValue(quote.reqForQuoteNum)
row.createCell(i++).setCellValue(quote.totalAmount)
row.createCell(i++).setCellValue(quote.reqForQuoteNum)
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 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)
val totalCols = headers.size
var rowCnt = 1
for (vendor in vendors){
for (vendor in vendors) {
val contactCnt = vendor.contacts.size
for (j in 0..contactCnt - 1){
for (j in 0..<contactCnt) {
val row = sh.createRow(rowCnt++)
var i = 0
row.createCell(i++).setCellValue(vendor.msme)
row.createCell(i++).setCellValue(vendor.gstNumber)
row.createCell(i++).setCellValue(vendor.address)
row.createCell(i++).setCellValue(vendor.rating)
row.createCell(i++).setCellValue(vendor.contacts[j].name)
row.createCell(i++).setCellValue(vendor.contacts[j].email)
row.createCell(i++).setCellValue(vendor.contacts[j].mobile)
row.createCell(i++).setCellValue((rowCnt - 1).toString())
row.createCell(i++).setCellValue(vendor.name)
row.createCell(i++).setCellValue(vendor.msme)
row.createCell(i++).setCellValue(vendor.gstNumber)
row.createCell(i++).setCellValue(vendor.address)
row.createCell(i++).setCellValue(vendor.rating)
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 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)
val totalCols = headers.size
var rowCnt = 1
for (prod in prods){
for (prod in prods) {
val row = sh.createRow(rowCnt++)
var i = 0
row.createCell(i++).setCellValue(prod.id.toString())
row.createCell(i++).setCellValue(prod.name)
row.createCell(i++).setCellValue(prod.description)
row.createCell(i++).setCellValue(prod.hsnCode)
row.createCell(i++).setCellValue(prod.uom?.name)
row.createCell(i++).setCellValue(prod.id.toString())
row.createCell(i++).setCellValue(prod.name)
row.createCell(i++).setCellValue(prod.description)
row.createCell(i++).setCellValue(prod.hsnCode)
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 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)
val totalCols = headers.size
var rowCnt = 1
for(po in pos){
for (po in pos) {
val prodCnt = po.products.size
for (j in 0..prodCnt - 1){
for (j in 0..<prodCnt) {
val row = sh.createRow(rowCnt++)
var i = 0
row.createCell(i++).setCellValue(po.poNum)
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)
var i = 0
row.createCell(i++).setCellValue(po.poNum)
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)
//6 would be repeated
row.createCell(i++).setCellValue(po.products[j].productId)
row.createCell(i++).setCellValue(po.products[j].productName)
row.createCell(i++).setCellValue(po.products[j].unitPrice)
row.createCell(i++).setCellValue(po.products[j].quantity)
//6 would be repeated
row.createCell(i++).setCellValue(po.products[j].productId)
row.createCell(i++).setCellValue(po.products[j].productName)
row.createCell(i++).setCellValue(po.products[j].unitPrice)
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.totalAmount)
row.createCell(i++).setCellValue(po.tnc?.joinToString(";"))
}
}
saveExcelFileLocally("Pos.xls", wb)
}
fun main() {
//ImportFromExcel(FileType.QUOTES, "C:\\Users\\arsalan\\Downloads\\Book.xlsx")
TemplateExcelFile(FileType.PRODS)
}
fun ImportFromExcel(fileType: FileType, filePath : String) {
fun ImportFromExcel(fileType: FileType, filePath: String) {
val wb = WorkbookFactory.create(File(filePath))
val sh = wb.getSheetAt(0)
when(fileType){
when (fileType) {
FileType.QUOTES -> {
//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()
val quotesMap: MutableMap<String, Quotation> = mutableMapOf()
val quotesList: List<Quotation> = mutableListOf()
sh.rowIterator().forEach { row ->
if(row == null){
if (row == null) {
//reached eof
return@forEach
}
@ -288,7 +373,7 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
if (quotesMap.containsKey(quoteNumber)) {
//duplicated row
quotesMap.get(quoteNumber)?.products?.add(prod)
}else {
} else {
val v = Vendor()
v.apply {
name = vendorName
@ -309,17 +394,18 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
}
}
//docs, tncs
// println("$quotesMap")
// println("$quotesMap")
// quotesMap.forEach { (k, v) ->
// println("$v")
// }
}
FileType.POS -> {
//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 ->
if(row == null) return@forEach
if (row == null) return@forEach
val poNum = stringFromCellHelper(row.getCell(0))
val poDate = dateFromCellHelper(row.getCell(1))
val refQuoteNum = stringFromCellHelper(row.getCell(2))
@ -332,11 +418,11 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
val totalPoAmount = doubleFromCellHelper(row.getCell(9))
//tncs, docs
val prod = POProducts("", prodName, 0.0, prodQuantity,"")
if(PoMap.containsKey(poNum)){
val prod = POProducts("", prodName, 0.0, prodQuantity, "")
if (PoMap.containsKey(poNum)) {
//repeated row
PoMap.get(poNum)?.products?.add(prod)
}else{
} else {
val vendor = Vendor()
vendor.name = vendorName
vendor.address = vendorAddress
@ -350,15 +436,16 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
}
}
}
FileType.VENDORS -> {
sh.rowIterator().forEach { row ->
//name, msme, gstNum, addresss, rating, contacts
if(row == null) return@forEach
if (row == null) return@forEach
val name = stringFromCellHelper(row.getCell(0))
val msme = stringFromCellHelper(row.getCell(1))
val gstNum = stringFromCellHelper(row.getCell(2))
val address = stringFromCellHelper(row.getCell(3))
val rating = doubleFromCellHelper(row.getCell(4))
val rating = doubleFromCellHelper(row.getCell(4))
//vendor object
val vendor = Vendor()
@ -369,9 +456,10 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
vendor.rating = rating
}
}
FileType.PRODS -> {
sh.rowIterator().forEach { row ->
if(row == null) return@forEach
if (row == null) return@forEach
//id, name, description, hsnCode, uom
val prodId = longIntFromCellHelper(row.getCell(0))
val prodName = stringFromCellHelper(row.getCell(1))
@ -385,7 +473,7 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
prod.name = prodName
prod.description = prodDesc
prod.hsnCode = prodHsnCode
prod.uom = when(prodUom) {
prod.uom = when (prodUom) {
"nos" -> UOM.NOS
"ltr" -> UOM.LTR
"mtr" -> UOM.MTR
@ -393,6 +481,7 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
}
}
}
FileType.DOCS -> {
sh.rowIterator().forEach { row ->
//Document Name, Document Type, RefID, url
@ -405,7 +494,7 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
//new doc object
val doc = Document()
doc.name = docName
doc.typeOfDoc = when(docType) {
doc.typeOfDoc = when (docType) {
"quote" -> DocType.QUOTE
"po" -> DocType.PO
"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
//require a list of vendor ids to be passed
data class CommonFilters(
val fromDate: LocalDate = baseDate,
val toDate: LocalDate = maxDate,
val from: LocalDate = baseDate,
val to: LocalDate = maxDate,
val vendor: List<Long>? = null,
val sortAsc: Boolean = true,
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> {
val q = database.find(Quotation::class.java)
.where()
.ge("quoteDate", commonFilters.fromDate)
.le("quoteDate", commonFilters.toDate)
.ge("quoteDate", commonFilters.from)
.le("quoteDate", commonFilters.to)
.ge("validTill", quoteFilters.validAfter)
.le("validTill", quoteFilters.validBefore)
.ge("totalAmount", quoteFilters.totalAmountExceeds)
.le("totalAmount", quoteFilters.totalAmountLessThan)
.ilike("quoteNum", "%" + quoteFilters.quoteNumLike + "%")
applyFromToHelper(q, commonFilters.fromDate, commonFilters.toDate, "quoteDate")
applyFromToHelper(q, commonFilters.from, commonFilters.to, "quoteDate")
applyVendorHelper(q, commonFilters.vendor)
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
return q.findList()
@ -123,6 +123,18 @@ fun searchVendors(commonFilters: CommonFilters, vendorFilters: VendorFilters): L
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> {
val q = database.find(Document::class.java)
.where()
@ -147,7 +159,7 @@ fun searchPos(commonFilters: CommonFilters, poFilters: POFilters?): List<Purchas
.le("validTill", poFilters.validBefore)
.ilike("poNum", "%" + poFilters.poNumLike + "%")
.ilike("referenceQuotation", "%" + poFilters.refQuotation + "%")
applyFromToHelper(q, commonFilters.fromDate, commonFilters.toDate, "poDate")
applyFromToHelper(q, commonFilters.from, commonFilters.to, "poDate")
applyVendorHelper(q, commonFilters.vendor)
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
return q.findList()

View File

@ -12,7 +12,13 @@ import java.time.LocalDateTime
import javax.persistence.*
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 {
@ -246,9 +252,15 @@ data class ContactPerson(val name: String = "", val email: String = "", val mobi
@Entity
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 msme: String = ""
var gstNumber: String = ""
@ -261,9 +273,16 @@ open class Vendor : BaseTenantModel() {
@Entity
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
var products: MutableList<POProducts> = mutableListOf()
@ -306,8 +325,16 @@ open class Product : BaseTenantModel() {
@Entity
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