diff --git a/src/main/kotlin/com/restapi/controllers/Entities.kt b/src/main/kotlin/com/restapi/controllers/Entities.kt index fa3e11b..b0837e8 100644 --- a/src/main/kotlin/com/restapi/controllers/Entities.kt +++ b/src/main/kotlin/com/restapi/controllers/Entities.kt @@ -851,11 +851,20 @@ object IncomingInventoryCtrl { fun getNextNum(ctx: Context) { 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) + .where() + .eq("unloadingPlantId", plantId) .findCount() + 1) .toString() .padStart(6, '0') - val seq = SequenceNumber(prefix + cnt) + val seq = SequenceNumber(inventoryPrefix + cnt) ctx.json(seq).status(HttpStatus.OK) } } diff --git a/src/main/kotlin/com/restapi/domain/models.kt b/src/main/kotlin/com/restapi/domain/models.kt index 4d65e75..163e563 100644 --- a/src/main/kotlin/com/restapi/domain/models.kt +++ b/src/main/kotlin/com/restapi/domain/models.kt @@ -434,11 +434,13 @@ open class IncomingInventory : BaseTenantModel() { 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? = "" @@ -659,4 +661,6 @@ open class ReminderLog : BaseTenantModel() { open class Plant : BaseModel() { var plantId: String = "" var plantName: String = "" + @DbJsonB + var prefixes: Map? = emptyMap() } \ No newline at end of file diff --git a/src/main/resources/dbmigration/1.28.sql b/src/main/resources/dbmigration/1.28.sql new file mode 100644 index 0000000..b85bfc2 --- /dev/null +++ b/src/main/resources/dbmigration/1.28.sql @@ -0,0 +1,2 @@ +-- apply alter tables +alter table incoming_inventory add column if not exists unloading_plant_id varchar(255); diff --git a/src/main/resources/dbmigration/1.29.sql b/src/main/resources/dbmigration/1.29.sql new file mode 100644 index 0000000..151db0e --- /dev/null +++ b/src/main/resources/dbmigration/1.29.sql @@ -0,0 +1,2 @@ +-- apply alter tables +alter table plant add column if not exists prefixes jsonb; diff --git a/src/main/resources/dbmigration/model/1.28.model.xml b/src/main/resources/dbmigration/model/1.28.model.xml new file mode 100644 index 0000000..9c4ac34 --- /dev/null +++ b/src/main/resources/dbmigration/model/1.28.model.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/dbmigration/model/1.29.model.xml b/src/main/resources/dbmigration/model/1.29.model.xml new file mode 100644 index 0000000..4f5b569 --- /dev/null +++ b/src/main/resources/dbmigration/model/1.29.model.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file