add excel templates fix apis
This commit is contained in:
@@ -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??
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user