some updates
This commit is contained in:
@@ -6,13 +6,9 @@ import com.fasterxml.jackson.databind.JsonDeserializer
|
||||
import com.fasterxml.jackson.databind.JsonNode
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
||||
import com.restapi.domain.*
|
||||
import com.restapi.domain.Product
|
||||
import com.restapi.domain.PurchaseOrder
|
||||
import com.restapi.domain.Quotation
|
||||
import com.restapi.domain.Session.currentUser
|
||||
import com.restapi.domain.Session.database
|
||||
import com.restapi.domain.Session.findDataModelByEntityAndUniqId
|
||||
import com.restapi.domain.Vendor
|
||||
import com.restapi.integ.Scripting
|
||||
import io.ebean.CallableSql
|
||||
import io.ebean.RawSqlBuilder
|
||||
@@ -373,12 +369,13 @@ object Entities {
|
||||
false
|
||||
}
|
||||
}
|
||||
data class Filters(val common :CommonFilters, val custom :CustomFilters)
|
||||
data class SequenceNumber(val number:String)
|
||||
data class BatchPos(val pos :List<PurchaseOrder>)
|
||||
|
||||
data class Filters(val common: CommonFilters, val custom: CustomFilters)
|
||||
data class SequenceNumber(val number: String)
|
||||
data class BatchPos(val pos: List<PurchaseOrder>)
|
||||
object PurchaseOrderCtrl {
|
||||
|
||||
fun getNextNum(ctx: Context){
|
||||
fun getNextNum(ctx: Context) {
|
||||
val prefix = "PO/"
|
||||
val cnt = database.find(PurchaseOrder::class.java)
|
||||
.findCount()
|
||||
@@ -387,39 +384,45 @@ object PurchaseOrderCtrl {
|
||||
val seq = SequenceNumber(prefix + cnt)
|
||||
ctx.json(seq).status(HttpStatus.OK)
|
||||
}
|
||||
fun get(ctx :Context){
|
||||
|
||||
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).status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
data class PF(val common: CommonFilters, val poFilters: POFilters)
|
||||
fun getAll(ctx :Context){
|
||||
|
||||
fun getAll(ctx: Context) {
|
||||
val filters = ctx.bodyAsClass<PF>()
|
||||
val pos = searchPos(filters.common, filters.poFilters)
|
||||
ctx.json(pos).status(HttpStatus.OK)
|
||||
}
|
||||
fun create(ctx :Context){
|
||||
|
||||
fun create(ctx: Context) {
|
||||
val po = ctx.bodyAsClass<PurchaseOrder>()
|
||||
database.save(po)
|
||||
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 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){
|
||||
|
||||
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
|
||||
@@ -427,14 +430,16 @@ object PurchaseOrderCtrl {
|
||||
ctx.json(po).status(HttpStatus.CREATED)
|
||||
//reject all other pos pertaining to the same tx ??
|
||||
}
|
||||
fun reject(ctx :Context){
|
||||
|
||||
fun reject(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.REJECTED
|
||||
po.save()
|
||||
ctx.json(po).status(HttpStatus.CREATED)
|
||||
}
|
||||
fun quoteReference(ctx :Context){
|
||||
|
||||
fun quoteReference(ctx: Context) {
|
||||
//gets the quote reference on which this po is based on
|
||||
val id = ctx.pathParam("id")
|
||||
val quote = database.find(Quotation::class.java)
|
||||
@@ -451,7 +456,7 @@ data class ProductSearch(
|
||||
)
|
||||
|
||||
object ProductCtrl {
|
||||
fun get(ctx :Context){
|
||||
fun get(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val product = database.find(Product::class.java)
|
||||
.where()
|
||||
@@ -462,14 +467,16 @@ object ProductCtrl {
|
||||
println(product)
|
||||
ctx.json(product).status(HttpStatus.OK)
|
||||
}
|
||||
fun getAll(ctx: Context){
|
||||
|
||||
fun getAll(ctx: Context) {
|
||||
val productList = Session.database.find(Product::class.java)
|
||||
.findList()
|
||||
.sortedBy { it.hsnCode }
|
||||
.sortedBy { it.name }
|
||||
|
||||
ctx.json(productList)
|
||||
}
|
||||
fun create(ctx :Context){
|
||||
|
||||
fun create(ctx: Context) {
|
||||
val product = ctx.bodyAsClass<Product>()
|
||||
database.save(product)
|
||||
ctx.json(product).status(HttpStatus.CREATED)
|
||||
@@ -477,21 +484,62 @@ object ProductCtrl {
|
||||
|
||||
fun delete(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val product = database.delete(Product::class.java, id)
|
||||
database.delete(Product::class.java, id)
|
||||
}
|
||||
|
||||
fun patch(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
|
||||
val patchValues = ctx.bodyAsClass<Map<String, Any>>()
|
||||
database.beginTransaction().use {
|
||||
patchValues.entries.forEach { en ->
|
||||
val key = en.key
|
||||
val value = en.value
|
||||
database.sqlUpdate("update products set $key = ? where id = ?").apply {
|
||||
setParameter(1, value)
|
||||
setParameter(2, id)
|
||||
execute()
|
||||
}
|
||||
}
|
||||
it.commit()
|
||||
}
|
||||
}
|
||||
|
||||
fun update(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
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()
|
||||
|
||||
}
|
||||
|
||||
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
val patchValues = mapOf("name" to 1)
|
||||
val id = 1;
|
||||
database.beginTransaction().use {
|
||||
patchValues.entries.forEach { en ->
|
||||
val key = en.key
|
||||
val value = en.value
|
||||
|
||||
database.sqlUpdate("update product set $key = ? where sys_pk = ?").apply {
|
||||
setParameter(1, value)
|
||||
setParameter(2, id)
|
||||
|
||||
execute()
|
||||
}
|
||||
}
|
||||
it.commit()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object QuotationCtrl {
|
||||
fun getNextNum(ctx: Context){
|
||||
fun getNextNum(ctx: Context) {
|
||||
val prefix = "QUOTE/"
|
||||
val cnt = database.find(Quotation::class.java)
|
||||
.findCount()
|
||||
@@ -500,33 +548,37 @@ object QuotationCtrl {
|
||||
val seq = SequenceNumber(prefix + cnt)
|
||||
ctx.json(seq).status(HttpStatus.OK)
|
||||
}
|
||||
fun get(ctx :Context){
|
||||
|
||||
fun get(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
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")
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(quote)
|
||||
}
|
||||
|
||||
data class QF(val common: CommonFilters, val quoteFilters: QuoteFilters)
|
||||
fun getAll(ctx :Context){
|
||||
|
||||
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){
|
||||
fun create(ctx: Context) {
|
||||
val quote = ctx.bodyAsClass<Quotation>()
|
||||
database.save(quote)
|
||||
ctx.json(quote).status(HttpStatus.CREATED)
|
||||
}
|
||||
fun createBatch(ctx :Context){
|
||||
|
||||
fun createBatch(ctx: Context) {
|
||||
val quotes = ctx.bodyAsClass<List<Quotation>>()
|
||||
val txn = database.beginTransaction()
|
||||
val txn = database.beginTransaction()
|
||||
try {
|
||||
txn.isBatchMode = true
|
||||
for(quote in quotes) database.save(quote)
|
||||
for (quote in quotes) database.save(quote)
|
||||
txn.commit()
|
||||
ctx.status(HttpStatus.CREATED).result("Quotes Created")
|
||||
} catch(e :Exception){
|
||||
} catch (e: Exception) {
|
||||
txn.rollback()
|
||||
ctx.status(HttpStatus.INTERNAL_SERVER_ERROR).result("Quotes Creation failed" + e.message)
|
||||
} finally {
|
||||
@@ -534,134 +586,146 @@ object QuotationCtrl {
|
||||
}
|
||||
ctx.result("Quotes batch created").status(HttpStatus.CREATED)
|
||||
}
|
||||
fun delete(ctx :Context){
|
||||
|
||||
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")
|
||||
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){
|
||||
|
||||
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"))
|
||||
|
||||
fun reqForQuote(ctx: Context) {
|
||||
val reqForQuoteNum = ctx.pathParam(("rfqNum"))
|
||||
val rfq = database.find(RequestForQuote::class.java)
|
||||
.where()
|
||||
.eq("reqForQuoteNum", reqForQuoteNum)
|
||||
?: throw NotFoundResponse("request for quote not found for this quotation")
|
||||
.where()
|
||||
.eq("reqForQuoteNum", reqForQuoteNum)
|
||||
?: throw NotFoundResponse("request for quote not found for this quotation")
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(rfq)
|
||||
}
|
||||
}
|
||||
object Document {
|
||||
fun get(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
|
||||
object DocumentCtrl {
|
||||
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>()
|
||||
|
||||
fun create(ctx: Context) {
|
||||
val doc = ctx.bodyAsClass<Document>()
|
||||
database.save(doc)
|
||||
ctx.status(HttpStatus.CREATED)
|
||||
ctx.json(doc)
|
||||
}
|
||||
fun print(ctx :Context){
|
||||
|
||||
fun print(ctx: Context) {
|
||||
//would be handled in the frontend ??
|
||||
}
|
||||
fun delete(ctx :Context){
|
||||
|
||||
fun delete(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val doc = database.find(Document::class.java, id) ?: throw NotFoundResponse("no doc found with id $id")
|
||||
val doc = database.find(Document::class.java, id) ?: throw NotFoundResponse("no doc found with id $id")
|
||||
//doc.delete()
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.result("document deleted with id $id")
|
||||
}
|
||||
fun getWithRefId(ctx :Context){
|
||||
|
||||
fun getWithRefId(ctx: Context) {
|
||||
//fetches a particular doc (po, quote) with ref id
|
||||
val refId = ctx.pathParam("refId")
|
||||
val doc = database.find(Document::class.java)
|
||||
.where()
|
||||
.eq("refId", refId)
|
||||
.eq("typeOfDoc", DocType.valueOf(ctx.pathParam("type")))
|
||||
.eq("refIdOfDoc", refId)
|
||||
?: throw NotFoundResponse("no doc found for refId $refId")
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(doc)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object VendorCtrl {
|
||||
fun get(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
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")
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(vendor)
|
||||
}
|
||||
data class VF(val common : CommonFilters, val vendorFilters: VendorFilters)
|
||||
fun getAll(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)
|
||||
logger.info("filters = {}", filters)
|
||||
val pos = searchVendors(filters.common, filters.vendorFilters)
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(pos)
|
||||
}
|
||||
fun createBatch(ctx: Context){
|
||||
|
||||
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()
|
||||
}
|
||||
database.saveAll(vendors)
|
||||
}
|
||||
fun create(ctx :Context){
|
||||
|
||||
fun create(ctx: Context) {
|
||||
val vendor = ctx.bodyAsClass<Vendor>()
|
||||
database.save(vendor)
|
||||
ctx.status(HttpStatus.CREATED)
|
||||
ctx.json(vendor)
|
||||
}
|
||||
fun update(ctx :Context){
|
||||
|
||||
fun update(ctx: Context) {
|
||||
|
||||
}
|
||||
fun delete(ctx :Context){
|
||||
|
||||
}
|
||||
fun getQuotes(ctx :Context){
|
||||
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")
|
||||
database.delete(vendor)
|
||||
ctx.status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
fun getQuotes(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val quotes = database.find(Quotation::class.java)
|
||||
.where()
|
||||
.eq("vendor", id)
|
||||
.eq("vendor", database.find(Vendor::class.java, id) ?: throw NotFoundResponse("vendor not found for $id"))
|
||||
.findList()
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(quotes)
|
||||
ctx.json(quotes).status(HttpStatus.OK)
|
||||
}
|
||||
fun getPos(ctx :Context){
|
||||
val id = ctx.pathParam("id")
|
||||
|
||||
fun getPos(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val pos = database.find(PurchaseOrder::class.java)
|
||||
.where()
|
||||
.eq("vendor", id)
|
||||
.eq("vendor", database.find(Vendor::class.java, id) ?: throw NotFoundResponse("vendor not found for $id"))
|
||||
.findList()
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.json(pos)
|
||||
ctx.json(pos).status(HttpStatus.OK)
|
||||
}
|
||||
fun rate(ctx :Context){
|
||||
|
||||
fun rate(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val rating = ctx.pathParam("rating").toDouble()
|
||||
val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("vendor not found for id $id")
|
||||
//could place some rating validation checks
|
||||
vendor.rating = rating
|
||||
vendor.save()
|
||||
ctx.status(HttpStatus.OK)
|
||||
ctx.result("rating changed")
|
||||
val rating1 = ctx.pathParam("rating").toDouble()
|
||||
|
||||
database.find(Vendor::class.java, id)?.let {
|
||||
it.rating = rating1
|
||||
it.save()
|
||||
} ?: throw NotFoundResponse("vendor not found for id $id")
|
||||
|
||||
|
||||
ctx.result("rating changed").status(HttpStatus.OK)
|
||||
}
|
||||
}
|
||||
|
||||
object RequestForQuote {
|
||||
fun create(ctx: Context) {
|
||||
val rfq = ctx.bodyAsClass<ReqForQuote>()
|
||||
|
||||
Reference in New Issue
Block a user