From d475d3828b96f837868d1e0e67e1c2e1d009174f Mon Sep 17 00:00:00 2001 From: arsalan Date: Fri, 1 Mar 2024 18:12:17 +0530 Subject: [PATCH] Add inventory --- api.http | 5 + src/main/kotlin/com/restapi/Main.kt | 90 +++++++++++-- .../com/restapi/controllers/Entities.kt | 121 ++++++++++++++++-- .../kotlin/com/restapi/controllers/Excel.kt | 79 ++++++++++++ .../kotlin/com/restapi/controllers/Filters.kt | 57 ++++++++- .../kotlin/com/restapi/domain/migration.kt | 2 +- src/main/kotlin/com/restapi/domain/models.kt | 68 +++++++++- .../dbmigration/1.10__dropsFor_1.7.sql | 2 + .../dbmigration/1.11__dropsFor_1.8.sql | 3 + src/main/resources/dbmigration/1.6.sql | 64 +++++++++ src/main/resources/dbmigration/1.7.sql | 2 + src/main/resources/dbmigration/1.8.sql | 4 + .../dbmigration/1.9__dropsFor_1.5.sql | 2 + .../model/1.10__dropsFor_1.7.model.xml | 6 + .../model/1.11__dropsFor_1.8.model.xml | 7 + .../resources/dbmigration/model/1.6.model.xml | 58 +++++++++ .../resources/dbmigration/model/1.7.model.xml | 11 ++ .../resources/dbmigration/model/1.8.model.xml | 16 +++ .../model/1.9__dropsFor_1.5.model.xml | 6 + 19 files changed, 578 insertions(+), 25 deletions(-) create mode 100644 src/main/resources/dbmigration/1.10__dropsFor_1.7.sql create mode 100644 src/main/resources/dbmigration/1.11__dropsFor_1.8.sql create mode 100644 src/main/resources/dbmigration/1.6.sql create mode 100644 src/main/resources/dbmigration/1.7.sql create mode 100644 src/main/resources/dbmigration/1.8.sql create mode 100644 src/main/resources/dbmigration/1.9__dropsFor_1.5.sql create mode 100644 src/main/resources/dbmigration/model/1.10__dropsFor_1.7.model.xml create mode 100644 src/main/resources/dbmigration/model/1.11__dropsFor_1.8.model.xml create mode 100644 src/main/resources/dbmigration/model/1.6.model.xml create mode 100644 src/main/resources/dbmigration/model/1.7.model.xml create mode 100644 src/main/resources/dbmigration/model/1.8.model.xml create mode 100644 src/main/resources/dbmigration/model/1.9__dropsFor_1.5.model.xml diff --git a/api.http b/api.http index 88f5c2d..1e9aa29 100644 --- a/api.http +++ b/api.http @@ -380,3 +380,8 @@ Authorization: {{auth-token}} GET http://localhost:9001/api/vendor/quote/next Content-Type: application/json Authorization: {{auth-token}} + +### GET NEXT INCOMING SEW NUMBER +GET http://localhost:9001/api/vendor/incoming/next +Content-Type: application/json +Authorization: {{auth-token}} diff --git a/src/main/kotlin/com/restapi/Main.kt b/src/main/kotlin/com/restapi/Main.kt index 0b7dfef..0710df2 100644 --- a/src/main/kotlin/com/restapi/Main.kt +++ b/src/main/kotlin/com/restapi/Main.kt @@ -115,18 +115,64 @@ fun main(args: Array) { post("", VendorCtrl::create, Roles(Role.Explicit("ROLE_VENDOR_CREATE"))) post("/batch", VendorCtrl::createBatch, Roles(Role.Explicit("ROLE_VENDOR_CREATE"))) get("/{id}", VendorCtrl::get, Roles(Role.Explicit("ROLE_VENDOR_VIEW", "ROLE_VENDOR_CREATE"))) - post("/getAll", VendorCtrl::getAll, Roles(Role.Explicit("ROLE_VENDOR_VIEW", "ROLE_VENDOR_CREATE"))) - get("quotes/{id}", VendorCtrl::getQuotes, Roles(Role.Explicit("ROLE_QUOTE_VIEW", "ROLE_QUOTE_CREATE", "ROLE_VENDOR_VIEW"))) + post( + "/getAll", + VendorCtrl::getAll, + Roles(Role.Explicit("ROLE_VENDOR_VIEW", "ROLE_VENDOR_CREATE")) + ) + get( + "quotes/{id}", + VendorCtrl::getQuotes, + Roles(Role.Explicit("ROLE_QUOTE_VIEW", "ROLE_QUOTE_CREATE", "ROLE_VENDOR_VIEW")) + ) get("pos/{id}", VendorCtrl::getPos, Roles(Role.Explicit("ROLE_PO_VIEW", "ROLE_PO_CREATE`"))) put("/rate/{id}/{rating}", VendorCtrl::rate, Roles(Role.Explicit("ROLE_VENDOR_CREATE"))) put("/{id}", VendorCtrl::update, Roles(Role.Explicit("ROLE_VENDOR_CREATE"))) } + path("/incoming") { + post("", IncomingInventoryCtrl::create, Roles(Role.Explicit("ROLE_INVENTORY_CREATE"))) + get("/next", IncomingInventoryCtrl::getNextNum, Roles(Role.Explicit("ROLE_INVENTORY_CREATE"))) + get( + "/{id}", + IncomingInventoryCtrl::get, + Roles(Role.Explicit("ROLE_INVENTORY_VIEW", "ROLE_INVENTORY_CREATE")) + ) + put("/{id}", IncomingInventoryCtrl::update, Roles(Role.Explicit("ROLE_INVENTORY_CREATE"))) + post( + "/getAll", + IncomingInventoryCtrl::getAll, + Roles(Role.Explicit("ROLE_INVENTORY_CREATE", "ROLE_INVENTORY_VIEW")) + ) + } + path("/outgoing") { + post("", OutgoingInventoryCtrl::create, Roles(Role.Explicit("ROLE_INVENTORY_CREATE"))) + get("/next", OutgoingInventoryCtrl::getNextNum, Roles(Role.Explicit("ROLE_INVENTORY_CREATE"))) + get( + "/{id}", + OutgoingInventoryCtrl::get, + Roles(Role.Explicit("ROLE_INVENTORY_VIEW", "ROLE_INVENTORY_CREATE")) + ) + put("/{id}", OutgoingInventoryCtrl::update, Roles(Role.Explicit("ROLE_INVENTORY_CREATE"))) + post( + "/getAll", + OutgoingInventoryCtrl::getAll, + Roles(Role.Explicit("ROLE_INVENTORY_CREATE", "ROLE_INVENTORY_VIEW")) + ) + } path("/po") { get("/next", PurchaseOrderCtrl::getNextNum, Roles(Role.Explicit("ROLE_PO_CREATE"))) post("", PurchaseOrderCtrl::create, Roles(Role.Explicit("ROLE_PO_CREATE"))) post("/batch", PurchaseOrderCtrl::createBatch, Roles(Role.Explicit("ROLE_PO_CREATE"))) - post("/getAll", PurchaseOrderCtrl::getAll, Roles(Role.Explicit("ROLE_PO_CREATE", "ROLE_PO_VIEW", "ROLE_VENDOR_CREATE"))) - get("/{id}", PurchaseOrderCtrl::get, Roles(Role.Explicit("ROLE_PO_CREATE", "ROLE_PO_VIEW", "ROLE_QUOTE_CREATE"))) + post( + "/getAll", + PurchaseOrderCtrl::getAll, + Roles(Role.Explicit("ROLE_PO_CREATE", "ROLE_PO_VIEW", "ROLE_VENDOR_CREATE")) + ) + get( + "/{id}", + PurchaseOrderCtrl::get, + Roles(Role.Explicit("ROLE_PO_CREATE", "ROLE_PO_VIEW", "ROLE_QUOTE_CREATE")) + ) put("/{id}", PurchaseOrderCtrl::update, Roles(Role.Explicit("ROLE_PO_CREATE"))) put("/approve/{id}", PurchaseOrderCtrl::approve, Roles(Role.Explicit())) put("/reject/{id}", PurchaseOrderCtrl::reject, Roles(Role.Explicit())) @@ -136,7 +182,11 @@ fun main(args: Array) { get("/next", QuotationCtrl::getNextNum, Roles(Role.Explicit("ROLE_QUOTE_CREATE"))) post("", QuotationCtrl::create, Roles(Role.Explicit("ROLE_QUOTE_CREATE"))) post("/batch", QuotationCtrl::createBatch, Roles(Role.Explicit("ROLE_QUOTE_CREATE"))) - post("/getAll", QuotationCtrl::getAll, Roles(Role.Explicit("ROLE_QUOTE_CREATE", "ROLE_QUOTE_VIEW"))) + post( + "/getAll", + QuotationCtrl::getAll, + Roles(Role.Explicit("ROLE_QUOTE_CREATE", "ROLE_QUOTE_VIEW")) + ) get("/{id}", QuotationCtrl::get, Roles(Role.Explicit("ROLE_QUOTE_VIEW", "ROLE_QUOTE_CREATE"))) put("/{id}", QuotationCtrl::update, Roles(Role.Explicit("ROLE_QUOTE_CREATE"))) delete("/{id}", QuotationCtrl::delete, Roles(Role.Explicit("ROLE_QUOTE_CREATE"))) @@ -152,15 +202,35 @@ fun main(args: Array) { path("/doc") { post("", DocumentCtrl::create, Roles(Role.Explicit("ROLE_DOC_CREATE"))) //why type and refid are clubbed ?? - get("/{type}/{refId}", DocumentCtrl::getWithRefId, Roles(Role.Explicit("ROLE_DOC_VIEW", "ROLE_PRODUCT_CREATE"))) + get( + "/{type}/{refId}", + DocumentCtrl::getWithRefId, + Roles(Role.Explicit("ROLE_DOC_VIEW", "ROLE_PRODUCT_CREATE")) + ) get("/{id}", DocumentCtrl::get, Roles(Role.Explicit("ROLE_DOC_VIEW", "ROLE_PRODUCT_CREATE"))) - get("/print/{id}", DocumentCtrl::print, Roles(Role.Explicit("ROLE_DOC_CREATE", "ROLE_DOC_VIEW"))) + get( + "/print/{id}", + DocumentCtrl::print, + Roles(Role.Explicit("ROLE_DOC_CREATE", "ROLE_DOC_VIEW")) + ) delete("/{id}", DocumentCtrl::delete, Roles(Role.Explicit("ROLE_DOC_CREATE"))) } path("/reqForQuote") { - post("", RequestForQuote::create, Roles(Role.Explicit("ROLE_QUOTE_CREATE", "ROLE_PO_CREATE", "ROLE_RFQ_CREATE"))) - get("/{id}", RequestForQuote::get, Roles(Role.Explicit("ROLE_RFQ_CREATE", "ROLE_RFQ_VIEW", "ROLE_QUOTE_VIEW", "ROLE_PO_VIEW"))) - put("/{id}", RequestForQuote::update, Roles(Role.Explicit("ROLE_QUOTE_CREATE", "ROLE_PO_CREATE", "ROLE_RFQ_CREATE"))) + post( + "", + RequestForQuote::create, + Roles(Role.Explicit("ROLE_QUOTE_CREATE", "ROLE_PO_CREATE", "ROLE_RFQ_CREATE")) + ) + get( + "/{id}", + RequestForQuote::get, + Roles(Role.Explicit("ROLE_RFQ_CREATE", "ROLE_RFQ_VIEW", "ROLE_QUOTE_VIEW", "ROLE_PO_VIEW")) + ) + put( + "/{id}", + RequestForQuote::update, + Roles(Role.Explicit("ROLE_QUOTE_CREATE", "ROLE_PO_CREATE", "ROLE_RFQ_CREATE")) + ) } } post("/script/database/{name}", Entities::executeStoredProcedure, Roles(adminRole, Role.DbOps)) diff --git a/src/main/kotlin/com/restapi/controllers/Entities.kt b/src/main/kotlin/com/restapi/controllers/Entities.kt index 84388b2..b22c399 100644 --- a/src/main/kotlin/com/restapi/controllers/Entities.kt +++ b/src/main/kotlin/com/restapi/controllers/Entities.kt @@ -397,12 +397,12 @@ object PurchaseOrderCtrl { fun getAll(ctx: Context) { val filters = ctx.bodyAsClass() val pos = searchPos(filters.common, filters.poFilters) - val excel = ctx.queryParam("excel") - if(excel != null){ + val excel = ctx.queryParam("excel") + if (excel != null) { exportPos(pos) val inputStream = FileInputStream("./excel/Pos.xls") ctx.result(inputStream).status(HttpStatus.OK) - }else{ + } else { ctx.json(pos).status(HttpStatus.OK) } } @@ -410,7 +410,7 @@ object PurchaseOrderCtrl { fun create(ctx: Context) { val po = ctx.bodyAsClass() val prods = po.products - if(prods.isEmpty()){ + if (prods.isEmpty()) { ctx.json(mapOf("error" to "empty product list")).status(HttpStatus.BAD_REQUEST) return } @@ -496,17 +496,19 @@ object ProductCtrl { ?: throw NotFoundResponse("Product not found for $id") ctx.json(product).status(HttpStatus.OK) } -data class PF(val common: CommonFilters, val productFilters: ProductFilters) + + data class PF(val common: CommonFilters, val productFilters: ProductFilters) + fun getAll(ctx: Context) { val filters = ctx.bodyAsClass() val prods = searchProducts(filters.common, filters.productFilters) val excel = ctx.queryParam("excel") - if(excel != null){ + if (excel != null) { exportProds(prods) val inputStream = FileInputStream("./excel/Products.xls") ctx.result(inputStream).status(HttpStatus.OK) - }else{ + } else { ctx.json(prods).status(HttpStatus.OK) } } @@ -611,7 +613,7 @@ object QuotationCtrl { val quote = ctx.bodyAsClass() //validation val prods = quote.products - if(prods.isEmpty()){ + if (prods.isEmpty()) { ctx.json(mapOf("error" to "empty product list")).status(HttpStatus.BAD_REQUEST) return } @@ -800,4 +802,105 @@ object RequestForQuote { //shuld we compare the new body fields with preexisting ones and prepare a sql query to update those fields?? } -} \ No newline at end of file +} + +object IncomingInventoryCtrl { + fun create(ctx: Context) { + val ticket = ctx.bodyAsClass() + database.save(ticket) + ctx.json(ticket).status(HttpStatus.CREATED) + } + + fun update(ctx: Context) { + val id = ctx.pathParam("id").toLong() + val ticket = + database.find(IncomingInventory::class.java, id) ?: throw NotFoundResponse("quote not found for $id") + val updatedTicket = ctx.bodyAsClass() + ticket.patchValues(updatedTicket) + ticket.update() + ctx.json(ticket).status(HttpStatus.OK) + } + + fun get(ctx: Context) { + val id = ctx.pathParam("id").toLong() + val ticket = database.find(IncomingInventory::class.java, id) + ?: throw NotFoundResponse("No incoming inventory ticket found with id $id") + ctx.json(ticket).status(HttpStatus.OK) + } + + data class IIF(val common: CommonFilters, val incomingInventoryFilters: IncomingInventoryFilters) + + fun getAll(ctx: Context) { + val filters = ctx.bodyAsClass() + val tickets = searchIncomingInventory(filters.common, filters.incomingInventoryFilters) + val excel = ctx.queryParam("excel") + if (excel !== null) { + exportIncomingInventory(tickets) + val inputStream = FileInputStream("./excel/IncomingInventory.xls") + ctx.result(inputStream).status(HttpStatus.OK) + } else { + ctx.json(tickets).status(HttpStatus.OK) + } + } + + fun getNextNum(ctx: Context) { + val prefix = "MRN/" + val cnt = database.find(IncomingInventory::class.java) + .findCount() + .toString() + .padStart(6, '0') + val seq = SequenceNumber(prefix + cnt) + ctx.json(seq).status(HttpStatus.OK) + } +} + +object OutgoingInventoryCtrl { + fun create(ctx: Context) { + val ticket = ctx.bodyAsClass() + database.save(ticket) + ctx.json(ticket).status(HttpStatus.CREATED) + } + + fun update(ctx: Context) { + val id = ctx.pathParam("id").toLong() + val ticket = + database.find(OutgoingInventory::class.java, id) ?: throw NotFoundResponse("quote not found for $id") + val updatedTicket = ctx.bodyAsClass() + ticket.patchValues(updatedTicket) + ticket.update() + ctx.json(ticket).status(HttpStatus.OK) + } + + fun get(ctx: Context) { + val id = ctx.pathParam("id").toLong() + val ticket = database.find(OutgoingInventory::class.java, id) + ?: throw NotFoundResponse("No incoming inventory ticket found with id $id") + ctx.json(ticket).status(HttpStatus.OK) + } + + data class OIF(val common: CommonFilters, val outgoingInventoryFilters: OutgoingInventoryFilters) + + fun getAll(ctx: Context) { + val filters = ctx.bodyAsClass() + val tickets = searchOutgoingInventory(filters.common, filters.outgoingInventoryFilters) + val excel = ctx.queryParam("excel") + if (excel !== null) { + exportOutgoingInventory(tickets) + val inputStream = FileInputStream("./excel/OutgoingInventory.xls") + ctx.result(inputStream).status(HttpStatus.OK) + } else { + ctx.json(tickets).status(HttpStatus.OK) + } + } + + fun getNextNum(ctx: Context) { + println("inside next num") + val prefix = "MDN/" + val cnt = database.find(OutgoingInventory::class.java) + .findCount() + .toString() + .padStart(6, '0') + val seq = SequenceNumber(prefix + cnt) + ctx.json(seq).status(HttpStatus.OK) + } +} diff --git a/src/main/kotlin/com/restapi/controllers/Excel.kt b/src/main/kotlin/com/restapi/controllers/Excel.kt index 292e051..b518e40 100644 --- a/src/main/kotlin/com/restapi/controllers/Excel.kt +++ b/src/main/kotlin/com/restapi/controllers/Excel.kt @@ -338,6 +338,85 @@ fun exportPos(pos: List) { saveExcelFileLocally("Pos.xls", wb) } +fun exportIncomingInventory(tickets : List) { + val wb = HSSFWorkbook() + val sh = wb.createSheet() + + val headers: List = listOf( + "MRN", + "Date", + "Vendor Name", + "Vendor Bill Number", + "Vendor Bill Amount", + "Product Id", + "Product Name", + "Unit Price", + "Quantity", + ) + createHeaderRow(headers, sh, wb) + + var rowCnt = 1 + for (ticket in tickets) { + val prodCnt = ticket.products?.size + + for (j in 0..) { + val wb = HSSFWorkbook() + val sh = wb.createSheet() + + val headers: List = listOf( + "MDN", + "Date", + "Out Mode", + "Purpose", + "Product Id", + "Product Name", + "Unit Price", + "Quantity", + ) + createHeaderRow(headers, sh, wb) + + var rowCnt = 1 + for (ticket in tickets) { + val prodCnt = ticket.products?.size + + for (j in 0.. applyVendorHelper(q: io.ebean.ExpressionList, vids: List?) { if (vids.isNullOrEmpty()) return // q.apply { @@ -123,18 +138,19 @@ fun searchVendors(commonFilters: CommonFilters, vendorFilters: VendorFilters): L return q.findList() } -fun searchProducts(commonFilters: CommonFilters, productFilters: ProductFilters) : List { +fun searchProducts(commonFilters: CommonFilters, productFilters: ProductFilters): List { val q = database.find(Product::class.java) .where() .ilike("name", "%" + productFilters.nameLike + "%") .ilike("hsnCode", "%" + productFilters.hsnLike + "%") - if(productFilters.uom != UOM.ALL){ + if (productFilters.uom != UOM.ALL) { q.eq("uom", productFilters.uom) } applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc) return q.findList() } + fun searchDocs(commonFilters: CommonFilters, documentFilters: DocumentFilters): List { val q = database.find(Document::class.java) .where() @@ -173,5 +189,40 @@ fun searchRFQ(commonFilters: CommonFilters, rfqFilters: RFQFilters): List { + val q = database.find(IncomingInventory::class.java) + .where() + .ge("vendorBillAmount", incomingInventoryFilters.vendorBillAmountExceeds) + .le("vendorBillAmount", incomingInventoryFilters.vendorBillAmountLessThan) + .ilike("mrn", "%" + incomingInventoryFilters.mrnLike + "%") + .ilike("vehicle", "%" + incomingInventoryFilters.vehicleLike + "%") + applyFromToHelper(q, commonFilters.from, commonFilters.to, "date") + applyVendorHelper(q, commonFilters.vendor) + applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc) + return q.findList() +} + +fun searchOutgoingInventory( + commonFilters: CommonFilters, + outgoingInventoryFilters: OutgoingInventoryFilters +): List { + val q = database.find(OutgoingInventory::class.java) + .where() + .ilike("mdn", "%" + outgoingInventoryFilters.mdnLike + "%") + .ilike("purpose", "%" + outgoingInventoryFilters.purposeLike + "%") + // .ilike("person", "%" + outgoingInventoryFilters.personLike + "%") + //.ilike("vehicle", "%" + outgoingInventoryFilters.vehicleLike + "%") + if (outgoingInventoryFilters.outMode != OutMode.ALL) { + q.eq("outMode", outgoingInventoryFilters.outMode) + } + applyFromToHelper(q, commonFilters.from, commonFilters.to, "date") + applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc) + return q.findList() } \ No newline at end of file diff --git a/src/main/kotlin/com/restapi/domain/migration.kt b/src/main/kotlin/com/restapi/domain/migration.kt index f3806de..b3362e6 100644 --- a/src/main/kotlin/com/restapi/domain/migration.kt +++ b/src/main/kotlin/com/restapi/domain/migration.kt @@ -8,7 +8,7 @@ object DBMigration { private fun create(){ val dbMigration: DbMigration = DbMigration.create() dbMigration.setPlatform(Platform.POSTGRES) - + //dbMigration.setGeneratePendingDrop("1.8") dbMigration.generateMigration() } diff --git a/src/main/kotlin/com/restapi/domain/models.kt b/src/main/kotlin/com/restapi/domain/models.kt index 209295f..83860d8 100644 --- a/src/main/kotlin/com/restapi/domain/models.kt +++ b/src/main/kotlin/com/restapi/domain/models.kt @@ -305,6 +305,10 @@ enum class UOM { NOS, LTR, MTR, ALL } +enum class TypeOfProduct { + RAW_MATERIAL +} + @Entity open class Product : BaseTenantModel() { fun patchValues(updatedProduct: Product) { @@ -321,6 +325,11 @@ open class Product : BaseTenantModel() { @Enumerated(EnumType.STRING) var uom: UOM? = null + + @Enumerated(EnumType.STRING) + var type: TypeOfProduct? = null + + } @Entity @@ -355,6 +364,8 @@ open class Quotation : BaseTenantModel() { @DbArray var documents: List? = arrayListOf() + + var taxesIncluded: Boolean ?= null } enum class DocType { @@ -387,10 +398,63 @@ open class ReqForQuote : BaseTenantModel() { @Enumerated(EnumType.STRING) var status: RFQStatus? = null - // @DbArray -// var docs :List? = null @DbJsonB var products: List? = 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 + } + + var mrn: String? = null + var date: LocalDate? = null + var vendorBillNum: String? = null + var vendorBillAmount: Double = 0.0 + var vehicle: String = "" + + @DbJsonB + var products: List? = 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? = null + var purpose: String? = null + + @Enumerated(EnumType.STRING) + var outMode: OutMode? = null + + var person: String? = null + var vehicle: String? = null } \ No newline at end of file diff --git a/src/main/resources/dbmigration/1.10__dropsFor_1.7.sql b/src/main/resources/dbmigration/1.10__dropsFor_1.7.sql new file mode 100644 index 0000000..7bb2646 --- /dev/null +++ b/src/main/resources/dbmigration/1.10__dropsFor_1.7.sql @@ -0,0 +1,2 @@ +-- apply alter tables +alter table incoming_inventory drop column vendor_bil_num; diff --git a/src/main/resources/dbmigration/1.11__dropsFor_1.8.sql b/src/main/resources/dbmigration/1.11__dropsFor_1.8.sql new file mode 100644 index 0000000..f1e840c --- /dev/null +++ b/src/main/resources/dbmigration/1.11__dropsFor_1.8.sql @@ -0,0 +1,3 @@ +-- apply alter tables +alter table incoming_inventory drop column mdn; +alter table outgoing_inventory drop column mrn; diff --git a/src/main/resources/dbmigration/1.6.sql b/src/main/resources/dbmigration/1.6.sql new file mode 100644 index 0000000..a2a1b46 --- /dev/null +++ b/src/main/resources/dbmigration/1.6.sql @@ -0,0 +1,64 @@ +-- apply changes +create table incoming_inventory ( + sys_pk bigint generated by default as identity not null, + deleted_on timestamp, + current_approval_level integer default 0 not null, + required_approval_levels integer default 0 not null, + date date, + vendor_bill_amount float not null, + vendor_sys_pk bigint, + deleted boolean default false not null, + version integer default 1 not null, + created_at timestamp default 'now()' not null, + modified_at timestamp default 'now()' not null, + deleted_by varchar(255), + approval_status varchar(8) default 'APPROVED' not null, + tags varchar[] default '{}' not null, + comments jsonb default '[]' not null, + tenant_id varchar(255) not null, + mdn varchar(255) not null, + vendor_bil_num varchar(255) not null, + vehicle varchar(255) not null, + products jsonb, + created_by varchar(255) not null, + modified_by varchar(255) not null, + constraint ck_incoming_inventory_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')), + constraint pk_incoming_inventory primary key (sys_pk) +); + +create table outgoing_inventory ( + sys_pk bigint generated by default as identity not null, + deleted_on timestamp, + current_approval_level integer default 0 not null, + required_approval_levels integer default 0 not null, + date date, + deleted boolean default false not null, + version integer default 1 not null, + created_at timestamp default 'now()' not null, + modified_at timestamp default 'now()' not null, + deleted_by varchar(255), + approval_status varchar(8) default 'APPROVED' not null, + tags varchar[] default '{}' not null, + comments jsonb default '[]' not null, + tenant_id varchar(255) not null, + mrn varchar(255) not null, + purpose varchar(255), + out_mode varchar(7), + person varchar(255), + vehicle varchar(255), + created_by varchar(255) not null, + modified_by varchar(255) not null, + constraint ck_outgoing_inventory_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')), + constraint ck_outgoing_inventory_out_mode check ( out_mode in ('PERSON','VEHICLE','ALL')), + constraint pk_outgoing_inventory primary key (sys_pk) +); + +-- apply alter tables +alter table product add column if not exists type varchar(12); +alter table quotation add column if not exists taxes_included boolean; +-- apply post alter +alter table product add constraint ck_product_type check ( type in ('RAW_MATERIAL')); +-- foreign keys and indices +create index ix_incoming_inventory_vendor_sys_pk on incoming_inventory (vendor_sys_pk); +alter table incoming_inventory add constraint fk_incoming_inventory_vendor_sys_pk foreign key (vendor_sys_pk) references vendor (sys_pk) on delete restrict on update restrict; + diff --git a/src/main/resources/dbmigration/1.7.sql b/src/main/resources/dbmigration/1.7.sql new file mode 100644 index 0000000..7c3df62 --- /dev/null +++ b/src/main/resources/dbmigration/1.7.sql @@ -0,0 +1,2 @@ +-- apply alter tables +alter table incoming_inventory add column if not exists vendor_bill_num varchar(255); diff --git a/src/main/resources/dbmigration/1.8.sql b/src/main/resources/dbmigration/1.8.sql new file mode 100644 index 0000000..1028a42 --- /dev/null +++ b/src/main/resources/dbmigration/1.8.sql @@ -0,0 +1,4 @@ +-- apply alter tables +alter table incoming_inventory add column if not exists mrn varchar(255); +alter table outgoing_inventory add column if not exists mdn varchar(255); +alter table outgoing_inventory add column if not exists products jsonb; diff --git a/src/main/resources/dbmigration/1.9__dropsFor_1.5.sql b/src/main/resources/dbmigration/1.9__dropsFor_1.5.sql new file mode 100644 index 0000000..bb4df97 --- /dev/null +++ b/src/main/resources/dbmigration/1.9__dropsFor_1.5.sql @@ -0,0 +1,2 @@ +-- apply alter tables +alter table document drop column ref_id; diff --git a/src/main/resources/dbmigration/model/1.10__dropsFor_1.7.model.xml b/src/main/resources/dbmigration/model/1.10__dropsFor_1.7.model.xml new file mode 100644 index 0000000..9f340d4 --- /dev/null +++ b/src/main/resources/dbmigration/model/1.10__dropsFor_1.7.model.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/resources/dbmigration/model/1.11__dropsFor_1.8.model.xml b/src/main/resources/dbmigration/model/1.11__dropsFor_1.8.model.xml new file mode 100644 index 0000000..3641709 --- /dev/null +++ b/src/main/resources/dbmigration/model/1.11__dropsFor_1.8.model.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/resources/dbmigration/model/1.6.model.xml b/src/main/resources/dbmigration/model/1.6.model.xml new file mode 100644 index 0000000..bf11a71 --- /dev/null +++ b/src/main/resources/dbmigration/model/1.6.model.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/dbmigration/model/1.7.model.xml b/src/main/resources/dbmigration/model/1.7.model.xml new file mode 100644 index 0000000..d6a6659 --- /dev/null +++ b/src/main/resources/dbmigration/model/1.7.model.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/dbmigration/model/1.8.model.xml b/src/main/resources/dbmigration/model/1.8.model.xml new file mode 100644 index 0000000..205ce77 --- /dev/null +++ b/src/main/resources/dbmigration/model/1.8.model.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/dbmigration/model/1.9__dropsFor_1.5.model.xml b/src/main/resources/dbmigration/model/1.9__dropsFor_1.5.model.xml new file mode 100644 index 0000000..40c91db --- /dev/null +++ b/src/main/resources/dbmigration/model/1.9__dropsFor_1.5.model.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file