diff --git a/src/main/kotlin/com/restapi/Main.kt b/src/main/kotlin/com/restapi/Main.kt index 2561ef8..d88b700 100644 --- a/src/main/kotlin/com/restapi/Main.kt +++ b/src/main/kotlin/com/restapi/Main.kt @@ -125,7 +125,8 @@ fun main(args: Array) { put("/{id}", VendorCtrl::update, Roles(Role.Explicit("ROLE_VENDOR_CREATE"))) } path("/incoming") { - get("/plants", IncomingInventoryCtrl::plantsForUser, + get( + "/plants", IncomingInventoryCtrl::plantsForUser, Roles( Role.Explicit("ROLE_INVENTORY_CREATE"), Role.Explicit("ROLE_VENDOR_VIEW"), @@ -133,11 +134,13 @@ fun main(args: Array) { Role.Explicit("ROLE_INVENTORY_VIEW") ) ) - put("/plants/{id}", IncomingInventoryCtrl::updatePlant, + put( + "/plants/{id}", IncomingInventoryCtrl::updatePlant, Roles( Role.Explicit("ROLE_INVENTORY_CREATE"), Role.Explicit("ROLE_VENDOR_CREATE") - )) + ) + ) post("", IncomingInventoryCtrl::create, Roles(Role.Explicit("ROLE_INVENTORY_CREATE"))) get("/next", IncomingInventoryCtrl::getNextNum, Roles(Role.Explicit("ROLE_INVENTORY_CREATE"))) get( @@ -274,6 +277,7 @@ fun main(args: Array) { put("/{id}", ProductCtrl::update, Roles(Role.Explicit("ROLE_PRODUCT_CREATE"))) delete("/{id}", ProductCtrl::delete, Roles(Role.Explicit("ROLE_PRODUCT_CREATE"))) patch("/{id}", ProductCtrl::patch, Roles(Role.Explicit("ROLE_PRODUCT_CREATE"))) + post("/getPrice", ProductCtrl::getPrice, Roles(Role.Explicit("ROLE_PRODUCT_VIEW"))) post("/getAll", ProductCtrl::getAll, Roles(Role.Explicit("ROLE_PRODUCT_VIEW"))) get("/{id}", ProductCtrl::get, Roles(Role.Explicit("ROLE_PRODUCT_VIEW"))) } diff --git a/src/main/kotlin/com/restapi/controllers/Entities.kt b/src/main/kotlin/com/restapi/controllers/Entities.kt index 6098aee..cf8ad6d 100644 --- a/src/main/kotlin/com/restapi/controllers/Entities.kt +++ b/src/main/kotlin/com/restapi/controllers/Entities.kt @@ -10,6 +10,7 @@ import com.restapi.domain.Session.currentUser import com.restapi.domain.Session.database import com.restapi.domain.Session.findDataModelByEntityAndUniqId import com.restapi.integ.Scripting +import com.restapi.integ.logger import io.ebean.CallableSql import io.ebean.RawSqlBuilder import io.javalin.http.* @@ -379,8 +380,8 @@ object PurchaseOrderCtrl { fun getNextNum(ctx: Context) { val prefix = "PO/" - val cnt = database.find(PurchaseOrder::class.java) - .findCount() + val cnt = (database.find(PurchaseOrder::class.java) + .findCount() + 1) .toString() .padStart(6, '0') val seq = SequenceNumber(prefix + cnt) @@ -499,7 +500,27 @@ object ProductCtrl { } data class PF(val common: CommonFilters, val productFilters: ProductFilters) + data class GetPrice(val productId: Long, val vendor: Any) + fun getPrice(ctx: Context){ + val gp = ctx.bodyAsClass() + val vendor = database.find(Vendor::class.java, gp.vendor) ?: throw BadRequestResponse("vendor not found for ${gp.vendor}") + val product = database.find(Product::class.java, gp.productId) ?: throw BadRequestResponse("product not found for ${gp.productId}") + val poProduct = database.find(PurchaseOrder::class.java) + .where() + .eq("vendor", vendor) + .findList() + .flatMap { + it.products + } + .firstOrNull { + it.productId == product.sysPk + } + ctx.json( + poProduct ?: throw BadRequestResponse("price not found for this vendor and product") + ) + + } fun getAll(ctx: Context) { val filters = ctx.bodyAsClass() val prods = searchProducts(filters.common, filters.productFilters) diff --git a/src/main/kotlin/com/restapi/controllers/Excel.kt b/src/main/kotlin/com/restapi/controllers/Excel.kt index fb4698d..2b0475b 100644 --- a/src/main/kotlin/com/restapi/controllers/Excel.kt +++ b/src/main/kotlin/com/restapi/controllers/Excel.kt @@ -209,7 +209,7 @@ fun exportQuotations(quotes: List) { row.createCell(i++).setCellValue(quote.quoteDate) row.createCell(i++).setCellValue(quote.validTill) //6 would be repeated - row.createCell(i++).setCellValue(quote.products[j].productId) + row.createCell(i++).setCellValue(quote.products[j].productId.toString()) row.createCell(i++).setCellValue(quote.products[j].productName) row.createCell(i++).setCellValue(quote.products[j].unitPrice) row.createCell(i++).setCellValue(quote.products[j].quantity) @@ -269,7 +269,7 @@ fun exportProds(prods: List) { for (prod in prods) { val row = sh.createRow(rowCnt++) var i = 0 - row.createCell(i++).setCellValue(prod.id.toString()) + row.createCell(i++).setCellValue(prod.code.toString()) row.createCell(i++).setCellValue(prod.name) row.createCell(i++).setCellValue(prod.description) row.createCell(i++).setCellValue(prod.hsnCode) @@ -313,7 +313,7 @@ fun exportPos(pos: List) { row.createCell(i++).setCellValue(po.vendor?.address) //6 would be repeated - row.createCell(i++).setCellValue(po.products[j].productId) + row.createCell(i++).setCellValue(po.products[j].productId.toString()) row.createCell(i++).setCellValue(po.products[j].productName) row.createCell(i++).setCellValue(po.products[j].unitPrice) row.createCell(i++).setCellValue(po.products[j].quantity) @@ -356,7 +356,7 @@ fun exportIncomingInventory(tickets: List) { row.createCell(i++).setCellValue(ticket.vendorBillAmount) //6 would be repeated - row.createCell(i++).setCellValue(ticket.products!![j].productId) + row.createCell(i++).setCellValue(ticket.products!![j].productId.toString()) row.createCell(i++).setCellValue(ticket.products!![j].productName) row.createCell(i++).setCellValue(ticket.products!![j].unitPrice) row.createCell(i++).setCellValue(ticket.products!![j].quantity) @@ -395,7 +395,7 @@ fun exportOutgoingInventory(tickets: List) { row.createCell(i++).setCellValue(ticket.purpose) //6 would be repeated - row.createCell(i++).setCellValue(ticket.products!![j].productId) + row.createCell(i++).setCellValue(ticket.products!![j].productId.toString()) row.createCell(i++).setCellValue(ticket.products!![j].productName) row.createCell(i++).setCellValue(ticket.products!![j].unitPrice) row.createCell(i++).setCellValue(ticket.products!![j].quantity) @@ -460,7 +460,7 @@ fun exportInvoices(invoices: List) { row.createCell(i++).setCellValue(invoice.vendor?.address) //6 would be repeated - row.createCell(i++).setCellValue(invoice.products?.get(j)?.productId ?: "NA") + row.createCell(i++).setCellValue(invoice.products?.get(j)?.productId?.toString() ?: "NA") row.createCell(i++).setCellValue(invoice.products?.get(j)?.productName ?: "NA") invoice.products?.get(j)?.let { row.createCell(i++).setCellValue(it.unitPrice) } invoice.products?.get(j)?.let { row.createCell(i++).setCellValue(it.quantity) } @@ -546,7 +546,7 @@ fun ImportFromExcel(fileType: FileType, filePath: String) { val prodQuantity = doubleFromCellHelper(row.getCell(8)) val prodUnitPrice = doubleFromCellHelper(row.getCell(9)) val totalQuoteAmount = doubleFromCellHelper(row.getCell(10)) - val prod = POProducts("", prodName, prodUnitPrice, prodQuantity) + val prod = POProducts(0, prodName, prodUnitPrice, prodQuantity) if (quotesMap.containsKey(quoteNumber)) { //duplicated row @@ -597,7 +597,7 @@ fun ImportFromExcel(fileType: FileType, filePath: String) { //tncs, docs val prod = POProducts( - productId = "", + productId = 0, productName = prodName, unitPrice = 0.0, quantity = prodQuantity, @@ -658,7 +658,7 @@ fun ImportFromExcel(fileType: FileType, filePath: String) { //new prod object val prod = Product() - prod.id = prodId + prod.code = prodId prod.name = prodName prod.description = prodDesc prod.hsnCode = prodHsnCode diff --git a/src/main/kotlin/com/restapi/domain/models.kt b/src/main/kotlin/com/restapi/domain/models.kt index 0ca7e78..3e0a446 100644 --- a/src/main/kotlin/com/restapi/domain/models.kt +++ b/src/main/kotlin/com/restapi/domain/models.kt @@ -14,7 +14,7 @@ import javax.persistence.* data class Comments(val text: String = "", val by: String = "", val at: LocalDateTime = LocalDateTime.now()) data class POProducts( - val productId: String = "", + val productId: Long = 0, val productName: String = "", val unitPrice: Double = 0.0, val quantity: Double = 0.0, @@ -344,7 +344,8 @@ open class Product : BaseTenantModel() { this.gstPct = updatedProduct.gstPct } - var id: String? = null + @Column(name = "id") + var code: String? = null var name: String = "" var description: String = "" var hsnCode: String = "" diff --git a/src/main/resources/dbmigration/model/1.3.model.xml b/src/main/resources/dbmigration/model/1.3.model.xml index 7461c11..4541ddd 100644 --- a/src/main/resources/dbmigration/model/1.3.model.xml +++ b/src/main/resources/dbmigration/model/1.3.model.xml @@ -8,7 +8,7 @@ - +