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