keep track of PO
This commit is contained in:
parent
0d203a880f
commit
1e7db629ae
@ -1,9 +1,8 @@
|
||||
package com.restapi.controllers
|
||||
|
||||
import com.restapi.domain.IncomingInventory
|
||||
import com.restapi.domain.OutgoingInventory
|
||||
import com.restapi.domain.Plant
|
||||
import com.restapi.domain.Session
|
||||
import com.restapi.domain.*
|
||||
import com.restapi.domain.Session.database
|
||||
import com.restapi.integ.logger
|
||||
import io.javalin.http.*
|
||||
import java.io.FileInputStream
|
||||
|
||||
@ -16,8 +15,9 @@ object IncomingInventoryCtrl {
|
||||
|
||||
fun updatePlant(ctx: Context) {
|
||||
val p = ctx.bodyAsClass<Plant>()
|
||||
val plant = Session.database.find(Plant::class.java, ctx.pathParam("id"))
|
||||
plant.patch(p)
|
||||
database.find(Plant::class.java, ctx.pathParam("id"))?.let {
|
||||
it.patch(p)
|
||||
}
|
||||
ctx.json(
|
||||
Session.currentUserPlants()
|
||||
)
|
||||
@ -25,23 +25,61 @@ object IncomingInventoryCtrl {
|
||||
|
||||
fun create(ctx: Context) {
|
||||
val ticket = ctx.bodyAsClass<IncomingInventory>()
|
||||
Session.database.save(ticket)
|
||||
database.save(ticket)
|
||||
keepTrackOfPoQty(ticket)
|
||||
ctx.json(ticket).status(HttpStatus.CREATED)
|
||||
}
|
||||
|
||||
fun update(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val ticket =
|
||||
Session.database.find(IncomingInventory::class.java, id) ?: throw NotFoundResponse("quote not found for $id")
|
||||
database.find(IncomingInventory::class.java, id) ?: throw NotFoundResponse("quote not found for $id")
|
||||
val updatedTicket = ctx.bodyAsClass<IncomingInventory>()
|
||||
ticket.patchValues(updatedTicket)
|
||||
ticket.update()
|
||||
keepTrackOfPoQty(ticket)
|
||||
ctx.json(ticket).status(HttpStatus.OK)
|
||||
}
|
||||
|
||||
private fun keepTrackOfPoQty(ticket: IncomingInventory) {
|
||||
ticket.products?.forEach { incomingProduct ->
|
||||
if (incomingProduct.poId != null) {
|
||||
database.find(PurchaseOrder::class.java, incomingProduct.poId)?.let { po ->
|
||||
logger.warn("found po for ${incomingProduct.poId} => ${po.poNum}")
|
||||
po.products.forEach { poProduct ->
|
||||
if (poProduct.productId == incomingProduct.productId) {
|
||||
logger.warn("for ${ticket.mrn} , product ${poProduct.productId} add to po-qty ${incomingProduct.receivedQty}")
|
||||
//remove existing entry for same mrn and product id
|
||||
poProduct.receivedVoucher.removeIf {
|
||||
it.productId == incomingProduct.productId
|
||||
&& it.plantId == ticket.unloadingPlantId
|
||||
&& it.ticket == ticket.mrn
|
||||
}
|
||||
poProduct.receivedVoucher.add(
|
||||
ReceivedVoucher(
|
||||
ticket = ticket.mrn!!,
|
||||
productName = poProduct.productName,
|
||||
productId = poProduct.productId,
|
||||
qty = incomingProduct.receivedQty,
|
||||
plantId = ticket.unloadingPlantId!!,
|
||||
ticketDate = ticket.date!!
|
||||
)
|
||||
)
|
||||
} else {
|
||||
logger.warn("no match for ${poProduct.productId} and ${incomingProduct.productId}")
|
||||
}
|
||||
}
|
||||
po.update()
|
||||
}
|
||||
} else {
|
||||
logger.warn("poId is missing for $incomingProduct")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun get(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val ticket = Session.database.find(IncomingInventory::class.java, id)
|
||||
val ticket = database.find(IncomingInventory::class.java, id)
|
||||
?: throw NotFoundResponse("No incoming inventory ticket found with id $id")
|
||||
ctx.json(ticket).status(HttpStatus.OK)
|
||||
}
|
||||
@ -64,13 +102,13 @@ object IncomingInventoryCtrl {
|
||||
fun getNextNum(ctx: Context) {
|
||||
val prefix = "MRN/"
|
||||
val plantId = ctx.queryParam("plantId") ?: throw BadRequestResponse("plantId not sent")
|
||||
val plant = Session.database.find(Plant::class.java)
|
||||
val plant = database.find(Plant::class.java)
|
||||
.where()
|
||||
.eq("plantId", plantId)
|
||||
.findOne() ?: throw BadRequestResponse("plant missing for $plantId")
|
||||
val inventoryPrefix = plant.prefixes?.get("INBOUND") ?: prefix
|
||||
|
||||
val cnt = (Session.database.find(IncomingInventory::class.java)
|
||||
val cnt = (database.find(IncomingInventory::class.java)
|
||||
.where()
|
||||
.eq("unloadingPlantId", plantId)
|
||||
.findCount() + 1)
|
||||
@ -84,14 +122,14 @@ object IncomingInventoryCtrl {
|
||||
object OutgoingInventoryCtrl {
|
||||
fun create(ctx: Context) {
|
||||
val ticket = ctx.bodyAsClass<OutgoingInventory>()
|
||||
Session.database.save(ticket)
|
||||
database.save(ticket)
|
||||
ctx.json(ticket).status(HttpStatus.CREATED)
|
||||
}
|
||||
|
||||
fun update(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val ticket =
|
||||
Session.database.find(OutgoingInventory::class.java, id) ?: throw NotFoundResponse("quote not found for $id")
|
||||
database.find(OutgoingInventory::class.java, id) ?: throw NotFoundResponse("quote not found for $id")
|
||||
val updatedTicket = ctx.bodyAsClass<OutgoingInventory>()
|
||||
ticket.patchValues(updatedTicket)
|
||||
ticket.update()
|
||||
@ -100,7 +138,7 @@ object OutgoingInventoryCtrl {
|
||||
|
||||
fun get(ctx: Context) {
|
||||
val id = ctx.pathParam("id").toLong()
|
||||
val ticket = Session.database.find(OutgoingInventory::class.java, id)
|
||||
val ticket = database.find(OutgoingInventory::class.java, id)
|
||||
?: throw NotFoundResponse("No incoming inventory ticket found with id $id")
|
||||
ctx.json(ticket).status(HttpStatus.OK)
|
||||
}
|
||||
@ -123,13 +161,13 @@ object OutgoingInventoryCtrl {
|
||||
fun getNextNum(ctx: Context) {
|
||||
val prefix = "MDN/"
|
||||
val plantId = ctx.queryParam("plantId") ?: throw BadRequestResponse("plantId not sent")
|
||||
val plant = Session.database.find(Plant::class.java)
|
||||
val plant = database.find(Plant::class.java)
|
||||
.where()
|
||||
.eq("plantId", plantId)
|
||||
.findOne() ?: throw BadRequestResponse("plant missing for $plantId")
|
||||
val inventoryPrefix = plant.prefixes?.get("OUTBOUND") ?: prefix
|
||||
|
||||
val cnt = (Session.database.find(OutgoingInventory::class.java)
|
||||
val cnt = (database.find(OutgoingInventory::class.java)
|
||||
.where()
|
||||
.eq("unloadingPlantId", plantId)
|
||||
.findCount() + 1)
|
||||
|
||||
@ -9,15 +9,18 @@ import io.ebean.annotation.*
|
||||
import io.ebean.annotation.Index
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDateTime
|
||||
import java.util.*
|
||||
import javax.persistence.*
|
||||
|
||||
data class Comments(val text: String = "", val by: String = "", val at: LocalDateTime = LocalDateTime.now())
|
||||
data class ReceivedVoucher(val ticket: String, val productName: String, val productId: Long, val qty: Double, val plantId: String, val ticketDate: LocalDate)
|
||||
data class POProducts(
|
||||
val productId: Long = 0,
|
||||
val productName: String = "",
|
||||
val unitPrice: Double = 0.0,
|
||||
val quantity: Double = 0.0,
|
||||
val orderedQty: Double = 0.0,
|
||||
val receivedQty: Double = 0.0,
|
||||
val receivedVoucher: MutableList<ReceivedVoucher> = arrayListOf(),
|
||||
val billQty: Double = 0.0,
|
||||
val gstPct: Double = 0.0,
|
||||
val taxableValue: Double = 0.0,
|
||||
@ -290,13 +293,14 @@ open class Plant : BaseModel() {
|
||||
var prefixes: MutableMap<String, String>? = mutableMapOf()
|
||||
}
|
||||
|
||||
class RefreshHistory {
|
||||
var oldAt: String = ""
|
||||
var oldExpiryAt: String = ""
|
||||
var newAt: String = ""
|
||||
var newExpiryAt: String = ""
|
||||
var createdAt: String = ""
|
||||
}
|
||||
class RefreshHistory {
|
||||
var oldAt: String = ""
|
||||
var oldExpiryAt: String = ""
|
||||
var newAt: String = ""
|
||||
var newExpiryAt: String = ""
|
||||
var createdAt: String = ""
|
||||
}
|
||||
|
||||
@Entity
|
||||
open class AuthTokenCache : BaseModel() {
|
||||
@Column(columnDefinition = "text")
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
</appender>
|
||||
|
||||
<!-- SQL and bind values -->
|
||||
<logger name="io.ebean.SQL" level="DEBUG"/>
|
||||
<logger name="io.ebean.SQL" level="WARN"/>
|
||||
<logger name="org.apache.http.client.protocol.ResponseProcessCookies" level="ERROR"/>
|
||||
|
||||
<!-- Transaction Commit and Rollback events -->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user