handle prefixes

This commit is contained in:
gowthaman 2024-04-30 11:08:21 +05:30
parent d17ea1da6a
commit fb4f1a0995
6 changed files with 34 additions and 1 deletions

View File

@ -851,11 +851,20 @@ 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 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 = (database.find(IncomingInventory::class.java) val cnt = (database.find(IncomingInventory::class.java)
.where()
.eq("unloadingPlantId", plantId)
.findCount() + 1) .findCount() + 1)
.toString() .toString()
.padStart(6, '0') .padStart(6, '0')
val seq = SequenceNumber(prefix + cnt) val seq = SequenceNumber(inventoryPrefix + cnt)
ctx.json(seq).status(HttpStatus.OK) ctx.json(seq).status(HttpStatus.OK)
} }
} }

View File

@ -434,11 +434,13 @@ open class IncomingInventory : BaseTenantModel() {
this.vendor = updated.vendor this.vendor = updated.vendor
this.loading = updated.loading this.loading = updated.loading
this.unloading = updated.unloading this.unloading = updated.unloading
this.unloadingPlantId = updated.unloadingPlantId
} }
var mrn: String? = null var mrn: String? = null
var date: LocalDate? = null var date: LocalDate? = null
var vendorBillNum: String? = null var vendorBillNum: String? = null
var unloadingPlantId: String? = null
var vendorBillAmount: Double = 0.0 var vendorBillAmount: Double = 0.0
var vehicle: String = "" var vehicle: String = ""
var loading: String? = "" var loading: String? = ""
@ -659,4 +661,6 @@ open class ReminderLog : BaseTenantModel() {
open class Plant : BaseModel() { open class Plant : BaseModel() {
var plantId: String = "" var plantId: String = ""
var plantName: String = "" var plantName: String = ""
@DbJsonB
var prefixes: Map<String,String>? = emptyMap()
} }

View File

@ -0,0 +1,2 @@
-- apply alter tables
alter table incoming_inventory add column if not exists unloading_plant_id varchar(255);

View File

@ -0,0 +1,2 @@
-- apply alter tables
alter table plant add column if not exists prefixes jsonb;

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<migration xmlns="http://ebean-orm.github.io/xml/ns/dbmigration">
<changeSet type="apply">
<addColumn tableName="incoming_inventory">
<column name="unloading_plant_id" type="varchar"/>
</addColumn>
</changeSet>
</migration>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<migration xmlns="http://ebean-orm.github.io/xml/ns/dbmigration">
<changeSet type="apply">
<addColumn tableName="plant">
<column name="prefixes" type="jsonb"/>
</addColumn>
</changeSet>
</migration>