move around classes
This commit is contained in:
parent
ed1e7546a7
commit
ce622a118f
49
src/main/kotlin/com/restapi/controllers/DocumentCtrl.kt
Normal file
49
src/main/kotlin/com/restapi/controllers/DocumentCtrl.kt
Normal file
@ -0,0 +1,49 @@
|
||||
package com.restapi.controllers
|
||||
|
||||
import com.restapi.domain.DocType
|
||||
import com.restapi.domain.Document
|
||||
import com.restapi.domain.Session
|
||||
import io.javalin.http.Context
|
||||
import io.javalin.http.HttpStatus
|
||||
import io.javalin.http.NotFoundResponse
|
||||
import io.javalin.http.bodyAsClass
|
||||
|
||||
object DocumentCtrl {
|
||||
fun get(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val doc = Session.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>()
|
||||
Session.database.save(doc)
|
||||
ctx.status(HttpStatus.CREATED)
|
||||
ctx.json(doc)
|
||||
}
|
||||
|
||||
fun print(ctx: Context) {
|
||||
//would be handled in the frontend ??
|
||||
}
|
||||
|
||||
fun delete(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val doc = Session.database.find(Document::class.java, id) ?: throw NotFoundResponse("no document found with id $id")
|
||||
Session.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")
|
||||
val doc = Session.database.find(Document::class.java)
|
||||
.where()
|
||||
.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)
|
||||
}
|
||||
|
||||
}
|
||||
@ -14,7 +14,6 @@ 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
|
||||
@ -374,322 +373,3 @@ object Entities {
|
||||
|
||||
data class SequenceNumber(val number: String)
|
||||
|
||||
object ProductCtrl {
|
||||
fun get(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val product = database.find(Product::class.java)
|
||||
.where()
|
||||
.eq("sys_pk", id.toLong())
|
||||
.findOne()
|
||||
?: throw NotFoundResponse("Product not found for $id")
|
||||
ctx.json(product).status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
data class PF(val common: CommonFilters, val productFilters: ProductFilters)
|
||||
data class GetPrice(val productId: Long, val vendor: Any)
|
||||
fun getPrice(ctx: Context){
|
||||
val gp = ctx.bodyAsClass<GetPrice>()
|
||||
val vendor = database.find(Vendor::class.java, gp.vendor) ?: throw BadRequestResponse("vendor not found for ${gp.vendor}")
|
||||
val product = database.find(Product::class.java, gp.productId) ?: throw BadRequestResponse("product not found for ${gp.productId}")
|
||||
val poProduct = database.find(PurchaseOrder::class.java)
|
||||
.where()
|
||||
.eq("vendor", vendor)
|
||||
.findList()
|
||||
.flatMap {
|
||||
it.products
|
||||
}
|
||||
.firstOrNull {
|
||||
it.productId == product.sysPk
|
||||
}
|
||||
|
||||
ctx.json(
|
||||
poProduct ?: throw BadRequestResponse("price not found for this vendor and product")
|
||||
)
|
||||
|
||||
}
|
||||
fun getAll(ctx: Context) {
|
||||
val filters = ctx.bodyAsClass<PF>()
|
||||
val prods = searchProducts(filters.common, filters.productFilters)
|
||||
val excel = ctx.queryParam("excel")
|
||||
if (excel != null) {
|
||||
exportProds(prods)
|
||||
val inputStream = FileInputStream("./excel/Products.xls")
|
||||
ctx.result(inputStream).status(HttpStatus.OK)
|
||||
|
||||
} else {
|
||||
ctx.json(prods).status(HttpStatus.OK)
|
||||
}
|
||||
}
|
||||
|
||||
fun create(ctx: Context) {
|
||||
val product = ctx.bodyAsClass<Product>()
|
||||
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>>()
|
||||
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").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)
|
||||
}
|
||||
|
||||
|
||||
@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 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>()
|
||||
database.save(doc)
|
||||
ctx.status(HttpStatus.CREATED)
|
||||
ctx.json(doc)
|
||||
}
|
||||
|
||||
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")
|
||||
val doc = database.find(Document::class.java)
|
||||
.where()
|
||||
.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 {
|
||||
val logger = LoggerFactory.getLogger("Vendor")
|
||||
fun get(ctx: Context) {
|
||||
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)
|
||||
}
|
||||
|
||||
data class VF(val common: CommonFilters, val vendorFilters: VendorFilters)
|
||||
|
||||
fun getAll(ctx: Context) {
|
||||
val filters = ctx.bodyAsClass<VF>()
|
||||
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) {
|
||||
val vendors = ctx.bodyAsClass<List<Vendor>>()
|
||||
database.saveAll(vendors)
|
||||
}
|
||||
|
||||
fun create(ctx: Context) {
|
||||
val vendor = ctx.bodyAsClass<Vendor>()
|
||||
database.save(vendor)
|
||||
ctx.status(HttpStatus.CREATED)
|
||||
ctx.json(vendor)
|
||||
}
|
||||
|
||||
fun update(ctx: Context) {
|
||||
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")
|
||||
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", database.find(Vendor::class.java, id) ?: throw NotFoundResponse("vendor not found for $id"))
|
||||
.findList()
|
||||
ctx.json(quotes).status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
fun getPos(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val pos = database.find(PurchaseOrder::class.java)
|
||||
.where()
|
||||
.eq("vendor", database.find(Vendor::class.java, id) ?: throw NotFoundResponse("vendor not found for $id"))
|
||||
.findList()
|
||||
ctx.json(pos).status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
fun rate(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
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 PaymentCtrl {
|
||||
fun create(ctx: Context) {
|
||||
val pmt = ctx.bodyAsClass(Payment::class.java)
|
||||
//update the status of invoices pertaining to payment.vendor
|
||||
val vendors: List<Long>? = pmt.vendor?.let { listOf(it.sysPk) }
|
||||
val invoices = searchInvoices(
|
||||
CommonFilters(sortBy = "date", sortAsc = true, vendor = vendors),
|
||||
InvoiceFilters(status = InvoiceStatus.PAID_FULL)
|
||||
)
|
||||
// println(invoices)
|
||||
//pmt.invoicesAffected = mutableMapOf()
|
||||
var totalAmount = pmt.amount
|
||||
var totalDeduct = 0.0
|
||||
for (invoice in invoices) {
|
||||
val deduct = Math.min(totalAmount, invoice.totalAmount)
|
||||
invoice.totalAmount -= deduct
|
||||
totalDeduct += deduct
|
||||
totalAmount -= deduct
|
||||
if (invoice.totalAmount <= 0.0) {
|
||||
invoice.status = InvoiceStatus.PAID_FULL
|
||||
} else {
|
||||
invoice.status = InvoiceStatus.PAID_SOME
|
||||
}
|
||||
//println(invoice)
|
||||
database.update(invoice)
|
||||
pmt.invoicesAffected?.put(invoice.sysPk, deduct)
|
||||
println(pmt.invoicesAffected)
|
||||
if (totalAmount <= 0.0) break
|
||||
}
|
||||
pmt.amountDeducted = totalDeduct
|
||||
pmt.excessAmount = pmt.amount - pmt.amountDeducted!!
|
||||
database.save(pmt)
|
||||
ctx.json(pmt).status(HttpStatus.CREATED)
|
||||
}
|
||||
|
||||
fun delete(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val pmt = database.find(Payment::class.java, id)
|
||||
?: throw NotFoundResponse("No payment found for this id $id")
|
||||
val invoiceDeductMap = pmt.invoicesAffected
|
||||
for (entry in invoiceDeductMap?.entries!!.iterator()) {
|
||||
val inv = database.find(Invoice::class.java, entry.key)
|
||||
?: throw NotFoundResponse("No invoice found for $entry.key")
|
||||
inv.totalAmount += entry.value
|
||||
inv.status = InvoiceStatus.PAID_SOME
|
||||
database.update(inv)
|
||||
}
|
||||
database.delete(pmt)
|
||||
ctx.json(pmt).status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
fun get(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val pmt = database.find(Payment::class.java, id)
|
||||
?: throw NotFoundResponse("No payment found for this id $id")
|
||||
ctx.json(pmt).status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
data class PMTF(val common: CommonFilters, val paymentFilters: PaymentFilters)
|
||||
|
||||
fun getAll(ctx: Context) {
|
||||
val filters = ctx.bodyAsClass<PMTF>()
|
||||
val payments = searchPayments(filters.common, filters.paymentFilters)
|
||||
// println(payments)
|
||||
val excel = ctx.queryParam("excel")
|
||||
if (excel !== null) {
|
||||
exportPayments(payments)
|
||||
val inputStream = FileInputStream("./excel/Payments.xls")
|
||||
ctx.result(inputStream).status(HttpStatus.OK)
|
||||
} else {
|
||||
ctx.json(payments).status(HttpStatus.OK)
|
||||
}
|
||||
}
|
||||
|
||||
fun update(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val pmt =
|
||||
database.find(Payment::class.java, id) ?: throw NotFoundResponse("payment not found for $id")
|
||||
val updatedPayment = ctx.bodyAsClass<Payment>()
|
||||
pmt.patchValues(updatedPayment)
|
||||
pmt.update()
|
||||
ctx.json(pmt).status(HttpStatus.OK)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
96
src/main/kotlin/com/restapi/controllers/PaymentCtrl.kt
Normal file
96
src/main/kotlin/com/restapi/controllers/PaymentCtrl.kt
Normal file
@ -0,0 +1,96 @@
|
||||
package com.restapi.controllers
|
||||
|
||||
import com.restapi.domain.Invoice
|
||||
import com.restapi.domain.InvoiceStatus
|
||||
import com.restapi.domain.Payment
|
||||
import com.restapi.domain.Session
|
||||
import io.javalin.http.Context
|
||||
import io.javalin.http.HttpStatus
|
||||
import io.javalin.http.NotFoundResponse
|
||||
import io.javalin.http.bodyAsClass
|
||||
import java.io.FileInputStream
|
||||
|
||||
object PaymentCtrl {
|
||||
fun create(ctx: Context) {
|
||||
val pmt = ctx.bodyAsClass(Payment::class.java)
|
||||
//update the status of invoices pertaining to payment.vendor
|
||||
val vendors: List<Long>? = pmt.vendor?.let { listOf(it.sysPk) }
|
||||
val invoices = searchInvoices(
|
||||
CommonFilters(sortBy = "date", sortAsc = true, vendor = vendors),
|
||||
InvoiceFilters(status = InvoiceStatus.PAID_FULL)
|
||||
)
|
||||
// println(invoices)
|
||||
//pmt.invoicesAffected = mutableMapOf()
|
||||
var totalAmount = pmt.amount
|
||||
var totalDeduct = 0.0
|
||||
for (invoice in invoices) {
|
||||
val deduct = Math.min(totalAmount, invoice.totalAmount)
|
||||
invoice.totalAmount -= deduct
|
||||
totalDeduct += deduct
|
||||
totalAmount -= deduct
|
||||
if (invoice.totalAmount <= 0.0) {
|
||||
invoice.status = InvoiceStatus.PAID_FULL
|
||||
} else {
|
||||
invoice.status = InvoiceStatus.PAID_SOME
|
||||
}
|
||||
//println(invoice)
|
||||
Session.database.update(invoice)
|
||||
pmt.invoicesAffected?.put(invoice.sysPk, deduct)
|
||||
println(pmt.invoicesAffected)
|
||||
if (totalAmount <= 0.0) break
|
||||
}
|
||||
pmt.amountDeducted = totalDeduct
|
||||
pmt.excessAmount = pmt.amount - pmt.amountDeducted!!
|
||||
Session.database.save(pmt)
|
||||
ctx.json(pmt).status(HttpStatus.CREATED)
|
||||
}
|
||||
|
||||
fun delete(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val pmt = Session.database.find(Payment::class.java, id)
|
||||
?: throw NotFoundResponse("No payment found for this id $id")
|
||||
val invoiceDeductMap = pmt.invoicesAffected
|
||||
for (entry in invoiceDeductMap?.entries!!.iterator()) {
|
||||
val inv = Session.database.find(Invoice::class.java, entry.key)
|
||||
?: throw NotFoundResponse("No invoice found for $entry.key")
|
||||
inv.totalAmount += entry.value
|
||||
inv.status = InvoiceStatus.PAID_SOME
|
||||
Session.database.update(inv)
|
||||
}
|
||||
Session.database.delete(pmt)
|
||||
ctx.json(pmt).status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
fun get(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val pmt = Session.database.find(Payment::class.java, id)
|
||||
?: throw NotFoundResponse("No payment found for this id $id")
|
||||
ctx.json(pmt).status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
data class PMTF(val common: CommonFilters, val paymentFilters: PaymentFilters)
|
||||
|
||||
fun getAll(ctx: Context) {
|
||||
val filters = ctx.bodyAsClass<PMTF>()
|
||||
val payments = searchPayments(filters.common, filters.paymentFilters)
|
||||
// println(payments)
|
||||
val excel = ctx.queryParam("excel")
|
||||
if (excel !== null) {
|
||||
exportPayments(payments)
|
||||
val inputStream = FileInputStream("./excel/Payments.xls")
|
||||
ctx.result(inputStream).status(HttpStatus.OK)
|
||||
} else {
|
||||
ctx.json(payments).status(HttpStatus.OK)
|
||||
}
|
||||
}
|
||||
|
||||
fun update(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val pmt =
|
||||
Session.database.find(Payment::class.java, id) ?: throw NotFoundResponse("payment not found for $id")
|
||||
val updatedPayment = ctx.bodyAsClass<Payment>()
|
||||
pmt.patchValues(updatedPayment)
|
||||
pmt.update()
|
||||
ctx.json(pmt).status(HttpStatus.OK)
|
||||
}
|
||||
}
|
||||
118
src/main/kotlin/com/restapi/controllers/ProductCtrl.kt
Normal file
118
src/main/kotlin/com/restapi/controllers/ProductCtrl.kt
Normal file
@ -0,0 +1,118 @@
|
||||
package com.restapi.controllers
|
||||
|
||||
import com.restapi.domain.Product
|
||||
import com.restapi.domain.PurchaseOrder
|
||||
import com.restapi.domain.Session
|
||||
import com.restapi.domain.Vendor
|
||||
import io.javalin.http.*
|
||||
import java.io.FileInputStream
|
||||
|
||||
object ProductCtrl {
|
||||
fun get(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val product = Session.database.find(Product::class.java)
|
||||
.where()
|
||||
.eq("sys_pk", id.toLong())
|
||||
.findOne()
|
||||
?: throw NotFoundResponse("Product not found for $id")
|
||||
ctx.json(product).status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
data class PF(val common: CommonFilters, val productFilters: ProductFilters)
|
||||
data class GetPrice(val productId: Long, val vendor: Any)
|
||||
fun getPrice(ctx: Context){
|
||||
val gp = ctx.bodyAsClass<GetPrice>()
|
||||
val vendor = Session.database.find(Vendor::class.java, gp.vendor) ?: throw BadRequestResponse("vendor not found for ${gp.vendor}")
|
||||
val product = Session.database.find(Product::class.java, gp.productId) ?: throw BadRequestResponse("product not found for ${gp.productId}")
|
||||
val poProduct = Session.database.find(PurchaseOrder::class.java)
|
||||
.where()
|
||||
.eq("vendor", vendor)
|
||||
.findList()
|
||||
.flatMap {
|
||||
it.products
|
||||
}
|
||||
.firstOrNull {
|
||||
it.productId == product.sysPk
|
||||
}
|
||||
|
||||
ctx.json(
|
||||
poProduct ?: throw BadRequestResponse("price not found for this vendor and product")
|
||||
)
|
||||
|
||||
}
|
||||
fun getAll(ctx: Context) {
|
||||
val filters = ctx.bodyAsClass<PF>()
|
||||
val prods = searchProducts(filters.common, filters.productFilters)
|
||||
val excel = ctx.queryParam("excel")
|
||||
if (excel != null) {
|
||||
exportProds(prods)
|
||||
val inputStream = FileInputStream("./excel/Products.xls")
|
||||
ctx.result(inputStream).status(HttpStatus.OK)
|
||||
|
||||
} else {
|
||||
ctx.json(prods).status(HttpStatus.OK)
|
||||
}
|
||||
}
|
||||
|
||||
fun create(ctx: Context) {
|
||||
val product = ctx.bodyAsClass<Product>()
|
||||
Session.database.save(product)
|
||||
ctx.json(product).status(HttpStatus.CREATED)
|
||||
}
|
||||
|
||||
fun delete(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val prod = Session.database.find(Product::class.java, id) ?: throw NotFoundResponse("no product found with id $id")
|
||||
Session.database.delete(prod)
|
||||
ctx.status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
fun patch(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val patchValues = ctx.bodyAsClass<Map<String, Any>>()
|
||||
Session.database.beginTransaction().use {
|
||||
patchValues.entries.forEach { en ->
|
||||
val key = en.key
|
||||
val value = en.value
|
||||
Session.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").toLong()
|
||||
val product = Session.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)
|
||||
}
|
||||
|
||||
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
val patchValues = mapOf("name" to 1)
|
||||
val id = 1;
|
||||
Session.database.beginTransaction().use {
|
||||
patchValues.entries.forEach { en ->
|
||||
val key = en.key
|
||||
val value = en.value
|
||||
|
||||
Session.database.sqlUpdate("update product set $key = ? where sys_pk = ?").apply {
|
||||
setParameter(1, value)
|
||||
setParameter(2, id)
|
||||
|
||||
execute()
|
||||
}
|
||||
}
|
||||
it.commit()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
96
src/main/kotlin/com/restapi/controllers/VendorCtrl.kt
Normal file
96
src/main/kotlin/com/restapi/controllers/VendorCtrl.kt
Normal file
@ -0,0 +1,96 @@
|
||||
package com.restapi.controllers
|
||||
|
||||
import com.restapi.domain.PurchaseOrder
|
||||
import com.restapi.domain.Quotation
|
||||
import com.restapi.domain.Session
|
||||
import com.restapi.domain.Vendor
|
||||
import io.javalin.http.Context
|
||||
import io.javalin.http.HttpStatus
|
||||
import io.javalin.http.NotFoundResponse
|
||||
import io.javalin.http.bodyAsClass
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.io.FileInputStream
|
||||
|
||||
object VendorCtrl {
|
||||
val logger = LoggerFactory.getLogger("Vendor")
|
||||
fun get(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val vendor = Session.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) {
|
||||
val filters = ctx.bodyAsClass<VF>()
|
||||
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) {
|
||||
val vendors = ctx.bodyAsClass<List<Vendor>>()
|
||||
Session.database.saveAll(vendors)
|
||||
}
|
||||
|
||||
fun create(ctx: Context) {
|
||||
val vendor = ctx.bodyAsClass<Vendor>()
|
||||
Session.database.save(vendor)
|
||||
ctx.status(HttpStatus.CREATED)
|
||||
ctx.json(vendor)
|
||||
}
|
||||
|
||||
fun update(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val vendor = Session.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 = Session.database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id")
|
||||
Session.database.delete(vendor)
|
||||
ctx.status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
fun getQuotes(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val quotes = Session.database.find(Quotation::class.java)
|
||||
.where()
|
||||
.eq("vendor", Session.database.find(Vendor::class.java, id) ?: throw NotFoundResponse("vendor not found for $id"))
|
||||
.findList()
|
||||
ctx.json(quotes).status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
fun getPos(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val pos = Session.database.find(PurchaseOrder::class.java)
|
||||
.where()
|
||||
.eq("vendor", Session.database.find(Vendor::class.java, id) ?: throw NotFoundResponse("vendor not found for $id"))
|
||||
.findList()
|
||||
ctx.json(pos).status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
fun rate(ctx: Context) {
|
||||
val id = ctx.pathParam("id")
|
||||
val rating1 = ctx.pathParam("rating").toDouble()
|
||||
|
||||
Session.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)
|
||||
}
|
||||
}
|
||||
123
src/main/kotlin/com/restapi/domain/Fleets.kt
Normal file
123
src/main/kotlin/com/restapi/domain/Fleets.kt
Normal file
@ -0,0 +1,123 @@
|
||||
package com.restapi.domain
|
||||
|
||||
import io.ebean.annotation.DbArray
|
||||
import io.ebean.annotation.DbJsonB
|
||||
import java.time.LocalDate
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.ManyToOne
|
||||
|
||||
data class FR(val renewal: String, val date: LocalDate)
|
||||
|
||||
@Entity
|
||||
open class Fleet : BaseTenantModel() {
|
||||
fun patchValues(updated: Fleet) {
|
||||
this.name = updated.name
|
||||
this.type = updated.type
|
||||
this.regNumber = updated.regNumber
|
||||
this.model = updated.model
|
||||
this.make = updated.make
|
||||
this.driver = updated.driver
|
||||
this.driverContact = updated.driverContact
|
||||
this.mileage = updated.mileage
|
||||
this.cost = updated.cost
|
||||
this.insuranceRenewalDate = updated.insuranceRenewalDate
|
||||
this.pollutionRenewalDate = updated.pollutionRenewalDate
|
||||
this.fitnessRenewalDate = updated.fitnessRenewalDate
|
||||
this.renewals = updated.renewals
|
||||
this.regDate = updated.regDate
|
||||
}
|
||||
|
||||
var name: String = ""
|
||||
var type: String = ""
|
||||
var regNumber: String = ""
|
||||
var regDate: LocalDate? = null
|
||||
var model: String = ""
|
||||
var make: String = ""
|
||||
var driver: String = ""
|
||||
var driverContact: String = ""
|
||||
var mileage: Double = 0.0
|
||||
var cost: Double = 0.0
|
||||
var insuranceRenewalDate: LocalDate? = null
|
||||
var pollutionRenewalDate: LocalDate? = null
|
||||
var fitnessRenewalDate: LocalDate? = null
|
||||
|
||||
@DbJsonB
|
||||
var renewals: List<FR>? = null
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class FleetType : BaseTenantModel() {
|
||||
fun patchValues(updated: FleetType) {
|
||||
this.name = updated.name
|
||||
this.personIncharge = updated.personIncharge
|
||||
}
|
||||
|
||||
var name: String = ""
|
||||
var personIncharge: String = ""
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Vehicle : BaseTenantModel() {
|
||||
fun patchValues(updated: Vehicle) {
|
||||
this.name = updated.name
|
||||
}
|
||||
|
||||
var name: String = ""
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Renewal : BaseTenantModel() {
|
||||
fun patchValues(updated: Renewal) {
|
||||
this.name = updated.name
|
||||
}
|
||||
|
||||
var name: String = ""
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Reminder : BaseTenantModel() {
|
||||
fun patchValues(updated: Reminder) {
|
||||
this.type = updated.type
|
||||
this.nextRenewalDate = updated.nextRenewalDate
|
||||
this.lastRenewalDate = updated.lastRenewalDate
|
||||
this.frequency = updated.frequency
|
||||
this.documents = updated.documents
|
||||
}
|
||||
|
||||
var type: String = "Other"
|
||||
var nextRenewalDate: LocalDate? = null
|
||||
var lastRenewalDate: LocalDate? = null
|
||||
var amount: Double = 0.0
|
||||
var frequency: Int = 1
|
||||
|
||||
@DbArray
|
||||
var documents: List<String>? = arrayListOf()
|
||||
|
||||
@ManyToOne
|
||||
var fleet: Fleet? = null
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class ReminderLog : BaseTenantModel() {
|
||||
fun patchValues(updated: ReminderLog) {
|
||||
this.fleet = updated.fleet
|
||||
this.reminderDate = updated.reminderDate
|
||||
this.reminderType = updated.reminderType
|
||||
this.actedUpon = updated.actedUpon
|
||||
this.documents = updated.documents
|
||||
this.amount = updated.amount
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
var reminder: Reminder? = null
|
||||
var reminderType: String = "Other"
|
||||
var reminderDate: LocalDate? = null
|
||||
|
||||
@ManyToOne
|
||||
var fleet: Fleet? = null
|
||||
var actedUpon: Boolean = false
|
||||
var amount: Double = 0.0
|
||||
|
||||
@DbArray
|
||||
var documents: List<String>? = null
|
||||
}
|
||||
71
src/main/kotlin/com/restapi/domain/Inventories.kt
Normal file
71
src/main/kotlin/com/restapi/domain/Inventories.kt
Normal file
@ -0,0 +1,71 @@
|
||||
package com.restapi.domain
|
||||
|
||||
import io.ebean.annotation.DbJsonB
|
||||
import java.time.LocalDate
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.EnumType
|
||||
import javax.persistence.Enumerated
|
||||
import javax.persistence.ManyToOne
|
||||
|
||||
@Entity
|
||||
open class IncomingInventory : BaseTenantModel() {
|
||||
fun patchValues(updated: IncomingInventory) {
|
||||
this.date = updated.date
|
||||
this.vendorBillNum = updated.vendorBillNum
|
||||
this.vendorBillAmount = updated.vendorBillAmount
|
||||
this.vehicle = updated.vehicle
|
||||
this.products = updated.products
|
||||
this.vendor = updated.vendor
|
||||
this.loading = updated.loading
|
||||
this.unloading = updated.unloading
|
||||
this.unloadingPlantId = updated.unloadingPlantId
|
||||
}
|
||||
|
||||
var mrn: String? = null
|
||||
var date: LocalDate? = null
|
||||
var vendorBillNum: String? = null
|
||||
var unloadingPlantId: String? = null
|
||||
var vendorBillAmount: Double = 0.0
|
||||
var vehicle: String = ""
|
||||
var loading: String? = ""
|
||||
var unloading: String? = ""
|
||||
|
||||
@DbJsonB
|
||||
var products: List<POProducts>? = null
|
||||
|
||||
@ManyToOne
|
||||
var vendor: Vendor? = null
|
||||
}
|
||||
|
||||
enum class OutMode {
|
||||
PERSON, VEHICLE, ALL
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class OutgoingInventory : BaseTenantModel() {
|
||||
fun patchValues(updated: OutgoingInventory) {
|
||||
this.date = updated.date
|
||||
this.products = updated.products
|
||||
this.purpose = updated.purpose
|
||||
this.outMode = updated.outMode
|
||||
this.person = updated.person
|
||||
this.vehicle = updated.vehicle
|
||||
|
||||
}
|
||||
|
||||
var mdn: String? = null
|
||||
var date: LocalDate? = null
|
||||
|
||||
@DbJsonB
|
||||
var products: List<POProducts>? = null
|
||||
var purpose: String? = null
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
var outMode: OutMode? = null
|
||||
|
||||
var person: String? = null
|
||||
|
||||
var jobCard: String? = null
|
||||
|
||||
var vehicle: String? = null
|
||||
}
|
||||
42
src/main/kotlin/com/restapi/domain/Products.kt
Normal file
42
src/main/kotlin/com/restapi/domain/Products.kt
Normal file
@ -0,0 +1,42 @@
|
||||
package com.restapi.domain
|
||||
|
||||
import javax.persistence.Column
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.EnumType
|
||||
import javax.persistence.Enumerated
|
||||
|
||||
enum class UOM {
|
||||
KG, CFT, TON, LTR, NUMBER, MTR, BOX, CUM, PACKET, ALL, NOS;
|
||||
}
|
||||
|
||||
enum class TypeOfProduct {
|
||||
RAW_MATERIAL
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Product : BaseTenantModel() {
|
||||
fun patchValues(updatedProduct: Product) {
|
||||
this.name = updatedProduct.name
|
||||
this.description = updatedProduct.description
|
||||
this.hsnCode = updatedProduct.hsnCode
|
||||
this.uom = updatedProduct.uom
|
||||
this.gstPct = updatedProduct.gstPct
|
||||
this.code = updatedProduct.code
|
||||
}
|
||||
|
||||
@Column(name = "id")
|
||||
var code: String? = null
|
||||
var name: String = ""
|
||||
var description: String = ""
|
||||
var hsnCode: String = ""
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
var uom: UOM? = null
|
||||
|
||||
var gstPct: Double? = 0.0
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
var type: TypeOfProduct? = null
|
||||
|
||||
|
||||
}
|
||||
192
src/main/kotlin/com/restapi/domain/Vendors.kt
Normal file
192
src/main/kotlin/com/restapi/domain/Vendors.kt
Normal file
@ -0,0 +1,192 @@
|
||||
package com.restapi.domain
|
||||
|
||||
import io.ebean.annotation.DbArray
|
||||
import io.ebean.annotation.DbJsonB
|
||||
import java.time.LocalDate
|
||||
import java.util.*
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.EnumType
|
||||
import javax.persistence.Enumerated
|
||||
import javax.persistence.ManyToOne
|
||||
|
||||
|
||||
enum class AddressType {
|
||||
BILLING, SHIPPING
|
||||
}
|
||||
|
||||
data class ContactPerson(
|
||||
val id: String = UUID.randomUUID().toString(),
|
||||
val name: String = "", val email: String = "", val mobile: String = ""
|
||||
)
|
||||
|
||||
data class Address(
|
||||
val id: String = UUID.randomUUID().toString(),
|
||||
val type: AddressType = AddressType.BILLING,
|
||||
val address: String = "",
|
||||
val pincode: String = ""
|
||||
)
|
||||
|
||||
@Entity
|
||||
open class Vendor : BaseTenantModel() {
|
||||
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
|
||||
this.outstanding = updatedVendor.outstanding
|
||||
this.asOnWhichDate = updatedVendor.asOnWhichDate
|
||||
this.addressList = updatedVendor.addressList
|
||||
}
|
||||
|
||||
var name: String = ""
|
||||
var msme: String = ""
|
||||
var gstNumber: String = ""
|
||||
var address: String = ""
|
||||
var rating: Double = 0.0
|
||||
var outstanding: Double? = 0.0
|
||||
var asOnWhichDate: LocalDate? = null
|
||||
|
||||
@DbJsonB
|
||||
var addressList: List<Address>? = mutableListOf()
|
||||
|
||||
@DbJsonB
|
||||
var contacts: List<ContactPerson> = mutableListOf()
|
||||
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class PurchaseOrder : BaseTenantModel() {
|
||||
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()
|
||||
|
||||
@ManyToOne
|
||||
var vendor: Vendor? = null
|
||||
var referenceQuotation: String? = ""
|
||||
var totalAmount: Double = 0.0
|
||||
var poNum: String = ""
|
||||
var poDate: LocalDate? = null
|
||||
var validTill: LocalDate? = null
|
||||
|
||||
@DbArray
|
||||
var tnc: List<String>? = arrayListOf()
|
||||
|
||||
@DbArray
|
||||
var documents: List<String>? = arrayListOf()
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Quotation : BaseTenantModel() {
|
||||
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
|
||||
var products: MutableList<POProducts> = mutableListOf()
|
||||
|
||||
@ManyToOne
|
||||
var vendor: Vendor? = null
|
||||
var totalAmount: Double = 0.0
|
||||
|
||||
var reqForQuoteNum: String? = ""
|
||||
var quoteNum: String = ""
|
||||
var vendorQuoteNum: String? = ""
|
||||
var quoteDate: LocalDate? = null
|
||||
var validTill: LocalDate? = null
|
||||
|
||||
@DbArray
|
||||
var tnc: List<String>? = arrayListOf()
|
||||
|
||||
@DbArray
|
||||
var documents: List<String>? = arrayListOf()
|
||||
|
||||
var taxesIncluded: Boolean? = null
|
||||
}
|
||||
|
||||
enum class RFQStatus {
|
||||
DELIVERED, PO, QUOTE, CANCELLED
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class ReqForQuote : BaseTenantModel() {
|
||||
@DbArray
|
||||
var potentialVendors: List<Long>? = null
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
var status: RFQStatus? = null
|
||||
|
||||
@DbJsonB
|
||||
var products: List<POProducts>? = null
|
||||
var reqForQuoteNum: String? = null
|
||||
var openTill: LocalDate? = null
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Invoice : BaseTenantModel() {
|
||||
fun patchValues(updated: Invoice) {
|
||||
this.date = updated.date
|
||||
this.number = updated.number
|
||||
this.totalAmount = updated.totalAmount
|
||||
this.poNum = updated.poNum
|
||||
this.products = updated.products
|
||||
this.vendor = updated.vendor
|
||||
this.status = updated.status
|
||||
}
|
||||
|
||||
var number: String = ""
|
||||
var date: LocalDate? = null
|
||||
var totalAmount: Double = 0.0
|
||||
var poNum: String? = null
|
||||
|
||||
@DbJsonB
|
||||
var products: List<POProducts>? = null
|
||||
|
||||
@ManyToOne
|
||||
var vendor: Vendor? = null
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
var status: InvoiceStatus? = null
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Payment : BaseTenantModel() {
|
||||
fun patchValues(updated: Payment) {
|
||||
this.refNumber = updated.refNumber
|
||||
this.amount = updated.amount
|
||||
this.date = updated.date
|
||||
this.remark = updated.remark
|
||||
this.vendor = updated.vendor
|
||||
}
|
||||
|
||||
var refNumber: String = ""
|
||||
var amount: Double = 0.0
|
||||
var date: LocalDate? = null
|
||||
var remark: String? = null
|
||||
var amountDeducted: Double? = null
|
||||
var excessAmount: Double? = null
|
||||
|
||||
@DbJsonB
|
||||
var invoicesAffected: MutableMap<Long, Double>? = mutableMapOf()
|
||||
|
||||
@ManyToOne
|
||||
var vendor: Vendor? = null
|
||||
}
|
||||
@ -252,153 +252,6 @@ class SafeStringDeserializer : JsonDeserializer<String>() {
|
||||
}
|
||||
}
|
||||
|
||||
enum class AddressType {
|
||||
BILLING, SHIPPING
|
||||
}
|
||||
|
||||
data class ContactPerson(
|
||||
val id: String = UUID.randomUUID().toString(),
|
||||
val name: String = "", val email: String = "", val mobile: String = ""
|
||||
)
|
||||
|
||||
data class Address(
|
||||
val id: String = UUID.randomUUID().toString(),
|
||||
val type: AddressType = AddressType.BILLING,
|
||||
val address: String = "",
|
||||
val pincode: String = ""
|
||||
)
|
||||
|
||||
@Entity
|
||||
open class Vendor : BaseTenantModel() {
|
||||
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
|
||||
this.outstanding = updatedVendor.outstanding
|
||||
this.asOnWhichDate = updatedVendor.asOnWhichDate
|
||||
this.addressList = updatedVendor.addressList
|
||||
}
|
||||
|
||||
var name: String = ""
|
||||
var msme: String = ""
|
||||
var gstNumber: String = ""
|
||||
var address: String = ""
|
||||
var rating: Double = 0.0
|
||||
var outstanding: Double? = 0.0
|
||||
var asOnWhichDate: LocalDate? = null
|
||||
|
||||
@DbJsonB
|
||||
var addressList: List<Address>? = mutableListOf()
|
||||
|
||||
@DbJsonB
|
||||
var contacts: List<ContactPerson> = mutableListOf()
|
||||
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class PurchaseOrder : BaseTenantModel() {
|
||||
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()
|
||||
|
||||
@ManyToOne
|
||||
var vendor: Vendor? = null
|
||||
var referenceQuotation: String? = ""
|
||||
var totalAmount: Double = 0.0
|
||||
var poNum: String = ""
|
||||
var poDate: LocalDate? = null
|
||||
var validTill: LocalDate? = null
|
||||
|
||||
@DbArray
|
||||
var tnc: List<String>? = arrayListOf()
|
||||
|
||||
@DbArray
|
||||
var documents: List<String>? = arrayListOf()
|
||||
}
|
||||
|
||||
enum class UOM {
|
||||
KG, CFT, TON, LTR, NUMBER, MTR, BOX, CUM, PACKET, ALL, NOS;
|
||||
}
|
||||
|
||||
enum class TypeOfProduct {
|
||||
RAW_MATERIAL
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Product : BaseTenantModel() {
|
||||
fun patchValues(updatedProduct: Product) {
|
||||
this.name = updatedProduct.name
|
||||
this.description = updatedProduct.description
|
||||
this.hsnCode = updatedProduct.hsnCode
|
||||
this.uom = updatedProduct.uom
|
||||
this.gstPct = updatedProduct.gstPct
|
||||
this.code = updatedProduct.code
|
||||
}
|
||||
|
||||
@Column(name = "id")
|
||||
var code: String? = null
|
||||
var name: String = ""
|
||||
var description: String = ""
|
||||
var hsnCode: String = ""
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
var uom: UOM? = null
|
||||
|
||||
var gstPct: Double? = 0.0
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
var type: TypeOfProduct? = null
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Quotation : BaseTenantModel() {
|
||||
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
|
||||
var products: MutableList<POProducts> = mutableListOf()
|
||||
|
||||
@ManyToOne
|
||||
var vendor: Vendor? = null
|
||||
var totalAmount: Double = 0.0
|
||||
|
||||
var reqForQuoteNum: String? = ""
|
||||
var quoteNum: String = ""
|
||||
var vendorQuoteNum: String? = ""
|
||||
var quoteDate: LocalDate? = null
|
||||
var validTill: LocalDate? = null
|
||||
|
||||
@DbArray
|
||||
var tnc: List<String>? = arrayListOf()
|
||||
|
||||
@DbArray
|
||||
var documents: List<String>? = arrayListOf()
|
||||
|
||||
var taxesIncluded: Boolean? = null
|
||||
}
|
||||
|
||||
enum class DocType {
|
||||
PO, QUOTE, INVOICE, ALL
|
||||
@ -418,256 +271,11 @@ open class Document : BaseTenantModel() {
|
||||
var docDate: LocalDate? = null
|
||||
}
|
||||
|
||||
enum class RFQStatus {
|
||||
DELIVERED, PO, QUOTE, CANCELLED
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class ReqForQuote : BaseTenantModel() {
|
||||
@DbArray
|
||||
var potentialVendors: List<Long>? = null
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
var status: RFQStatus? = null
|
||||
|
||||
@DbJsonB
|
||||
var products: List<POProducts>? = null
|
||||
var reqForQuoteNum: String? = null
|
||||
var openTill: LocalDate? = null
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class IncomingInventory : BaseTenantModel() {
|
||||
fun patchValues(updated: IncomingInventory) {
|
||||
this.date = updated.date
|
||||
this.vendorBillNum = updated.vendorBillNum
|
||||
this.vendorBillAmount = updated.vendorBillAmount
|
||||
this.vehicle = updated.vehicle
|
||||
this.products = updated.products
|
||||
this.vendor = updated.vendor
|
||||
this.loading = updated.loading
|
||||
this.unloading = updated.unloading
|
||||
this.unloadingPlantId = updated.unloadingPlantId
|
||||
}
|
||||
|
||||
var mrn: String? = null
|
||||
var date: LocalDate? = null
|
||||
var vendorBillNum: String? = null
|
||||
var unloadingPlantId: String? = null
|
||||
var vendorBillAmount: Double = 0.0
|
||||
var vehicle: String = ""
|
||||
var loading: String? = ""
|
||||
var unloading: String? = ""
|
||||
|
||||
@DbJsonB
|
||||
var products: List<POProducts>? = null
|
||||
|
||||
@ManyToOne
|
||||
var vendor: Vendor? = null
|
||||
}
|
||||
|
||||
|
||||
enum class OutMode {
|
||||
PERSON, VEHICLE, ALL
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class OutgoingInventory : BaseTenantModel() {
|
||||
fun patchValues(updated: OutgoingInventory) {
|
||||
this.date = updated.date
|
||||
this.products = updated.products
|
||||
this.purpose = updated.purpose
|
||||
this.outMode = updated.outMode
|
||||
this.person = updated.person
|
||||
this.vehicle = updated.vehicle
|
||||
|
||||
}
|
||||
|
||||
var mdn: String? = null
|
||||
var date: LocalDate? = null
|
||||
|
||||
@DbJsonB
|
||||
var products: List<POProducts>? = null
|
||||
var purpose: String? = null
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
var outMode: OutMode? = null
|
||||
|
||||
var person: String? = null
|
||||
var vehicle: String? = null
|
||||
}
|
||||
|
||||
enum class InvoiceStatus {
|
||||
PAID_FULL, PAID_SOME, PAID_NONE, ALL
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Invoice : BaseTenantModel() {
|
||||
fun patchValues(updated: Invoice) {
|
||||
this.date = updated.date
|
||||
this.number = updated.number
|
||||
this.totalAmount = updated.totalAmount
|
||||
this.poNum = updated.poNum
|
||||
this.products = updated.products
|
||||
this.vendor = updated.vendor
|
||||
this.status = updated.status
|
||||
}
|
||||
|
||||
var number: String = ""
|
||||
var date: LocalDate? = null
|
||||
var totalAmount: Double = 0.0
|
||||
var poNum: String? = null
|
||||
|
||||
@DbJsonB
|
||||
var products: List<POProducts>? = null
|
||||
|
||||
@ManyToOne
|
||||
var vendor: Vendor? = null
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
var status: InvoiceStatus? = null
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Payment : BaseTenantModel() {
|
||||
fun patchValues(updated: Payment) {
|
||||
this.refNumber = updated.refNumber
|
||||
this.amount = updated.amount
|
||||
this.date = updated.date
|
||||
this.remark = updated.remark
|
||||
this.vendor = updated.vendor
|
||||
}
|
||||
|
||||
var refNumber: String = ""
|
||||
var amount: Double = 0.0
|
||||
var date: LocalDate? = null
|
||||
var remark: String? = null
|
||||
var amountDeducted: Double? = null
|
||||
var excessAmount: Double? = null
|
||||
|
||||
@DbJsonB
|
||||
var invoicesAffected: MutableMap<Long, Double>? = mutableMapOf()
|
||||
|
||||
@ManyToOne
|
||||
var vendor: Vendor? = null
|
||||
}
|
||||
|
||||
|
||||
data class FR(val renewal: String, val date: LocalDate)
|
||||
|
||||
@Entity
|
||||
open class Fleet : BaseTenantModel() {
|
||||
fun patchValues(updated: Fleet) {
|
||||
this.name = updated.name
|
||||
this.type = updated.type
|
||||
this.regNumber = updated.regNumber
|
||||
this.model = updated.model
|
||||
this.make = updated.make
|
||||
this.driver = updated.driver
|
||||
this.driverContact = updated.driverContact
|
||||
this.mileage = updated.mileage
|
||||
this.cost = updated.cost
|
||||
this.insuranceRenewalDate = updated.insuranceRenewalDate
|
||||
this.pollutionRenewalDate = updated.pollutionRenewalDate
|
||||
this.fitnessRenewalDate = updated.fitnessRenewalDate
|
||||
this.renewals = updated.renewals
|
||||
this.regDate = updated.regDate
|
||||
}
|
||||
|
||||
var name: String = ""
|
||||
var type: String = ""
|
||||
var regNumber: String = ""
|
||||
var regDate: LocalDate? = null
|
||||
var model: String = ""
|
||||
var make: String = ""
|
||||
var driver: String = ""
|
||||
var driverContact: String = ""
|
||||
var mileage: Double = 0.0
|
||||
var cost: Double = 0.0
|
||||
var insuranceRenewalDate: LocalDate? = null
|
||||
var pollutionRenewalDate: LocalDate? = null
|
||||
var fitnessRenewalDate: LocalDate? = null
|
||||
|
||||
@DbJsonB
|
||||
var renewals: List<FR>? = null
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class FleetType : BaseTenantModel() {
|
||||
fun patchValues(updated: FleetType) {
|
||||
this.name = updated.name
|
||||
this.personIncharge = updated.personIncharge
|
||||
}
|
||||
|
||||
var name: String = ""
|
||||
var personIncharge: String = ""
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Vehicle : BaseTenantModel() {
|
||||
fun patchValues(updated: Vehicle) {
|
||||
this.name = updated.name
|
||||
}
|
||||
|
||||
var name: String = ""
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Renewal : BaseTenantModel() {
|
||||
fun patchValues(updated: Renewal) {
|
||||
this.name = updated.name
|
||||
}
|
||||
|
||||
var name: String = ""
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class Reminder : BaseTenantModel() {
|
||||
fun patchValues(updated: Reminder) {
|
||||
this.type = updated.type
|
||||
this.nextRenewalDate = updated.nextRenewalDate
|
||||
this.lastRenewalDate = updated.lastRenewalDate
|
||||
this.frequency = updated.frequency
|
||||
this.documents = updated.documents
|
||||
}
|
||||
|
||||
var type: String = "Other"
|
||||
var nextRenewalDate: LocalDate? = null
|
||||
var lastRenewalDate: LocalDate? = null
|
||||
var amount: Double = 0.0
|
||||
var frequency: Int = 1
|
||||
|
||||
@DbArray
|
||||
var documents: List<String>? = arrayListOf()
|
||||
|
||||
@ManyToOne
|
||||
var fleet: Fleet? = null
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class ReminderLog : BaseTenantModel() {
|
||||
fun patchValues(updated: ReminderLog) {
|
||||
this.fleet = updated.fleet
|
||||
this.reminderDate = updated.reminderDate
|
||||
this.reminderType = updated.reminderType
|
||||
this.actedUpon = updated.actedUpon
|
||||
this.documents = updated.documents
|
||||
this.amount = updated.amount
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
var reminder: Reminder? = null
|
||||
var reminderType: String = "Other"
|
||||
var reminderDate: LocalDate? = null
|
||||
|
||||
@ManyToOne
|
||||
var fleet: Fleet? = null
|
||||
var actedUpon: Boolean = false
|
||||
var amount: Double = 0.0
|
||||
|
||||
@DbArray
|
||||
var documents: List<String>? = null
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Index(name = "plantid_idx", columnNames = ["plant_id"], unique = true)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user