add vendor module

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

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")