some changes

This commit is contained in:
gowthaman 2024-05-08 07:39:40 +05:30
parent dac0fcb85b
commit c80a347bef
5 changed files with 43 additions and 17 deletions

View File

@ -125,7 +125,8 @@ fun main(args: Array<String>) {
put("/{id}", VendorCtrl::update, Roles(Role.Explicit("ROLE_VENDOR_CREATE"))) put("/{id}", VendorCtrl::update, Roles(Role.Explicit("ROLE_VENDOR_CREATE")))
} }
path("/incoming") { path("/incoming") {
get("/plants", IncomingInventoryCtrl::plantsForUser, get(
"/plants", IncomingInventoryCtrl::plantsForUser,
Roles( Roles(
Role.Explicit("ROLE_INVENTORY_CREATE"), Role.Explicit("ROLE_INVENTORY_CREATE"),
Role.Explicit("ROLE_VENDOR_VIEW"), Role.Explicit("ROLE_VENDOR_VIEW"),
@ -133,11 +134,13 @@ fun main(args: Array<String>) {
Role.Explicit("ROLE_INVENTORY_VIEW") Role.Explicit("ROLE_INVENTORY_VIEW")
) )
) )
put("/plants/{id}", IncomingInventoryCtrl::updatePlant, put(
"/plants/{id}", IncomingInventoryCtrl::updatePlant,
Roles( Roles(
Role.Explicit("ROLE_INVENTORY_CREATE"), Role.Explicit("ROLE_INVENTORY_CREATE"),
Role.Explicit("ROLE_VENDOR_CREATE") Role.Explicit("ROLE_VENDOR_CREATE")
)) )
)
post("", IncomingInventoryCtrl::create, Roles(Role.Explicit("ROLE_INVENTORY_CREATE"))) post("", IncomingInventoryCtrl::create, Roles(Role.Explicit("ROLE_INVENTORY_CREATE")))
get("/next", IncomingInventoryCtrl::getNextNum, Roles(Role.Explicit("ROLE_INVENTORY_CREATE"))) get("/next", IncomingInventoryCtrl::getNextNum, Roles(Role.Explicit("ROLE_INVENTORY_CREATE")))
get( get(
@ -274,6 +277,7 @@ fun main(args: Array<String>) {
put("/{id}", ProductCtrl::update, Roles(Role.Explicit("ROLE_PRODUCT_CREATE"))) put("/{id}", ProductCtrl::update, Roles(Role.Explicit("ROLE_PRODUCT_CREATE")))
delete("/{id}", ProductCtrl::delete, 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"))) 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"))) post("/getAll", ProductCtrl::getAll, Roles(Role.Explicit("ROLE_PRODUCT_VIEW")))
get("/{id}", ProductCtrl::get, Roles(Role.Explicit("ROLE_PRODUCT_VIEW"))) get("/{id}", ProductCtrl::get, Roles(Role.Explicit("ROLE_PRODUCT_VIEW")))
} }

View File

@ -10,6 +10,7 @@ import com.restapi.domain.Session.currentUser
import com.restapi.domain.Session.database import com.restapi.domain.Session.database
import com.restapi.domain.Session.findDataModelByEntityAndUniqId import com.restapi.domain.Session.findDataModelByEntityAndUniqId
import com.restapi.integ.Scripting import com.restapi.integ.Scripting
import com.restapi.integ.logger
import io.ebean.CallableSql import io.ebean.CallableSql
import io.ebean.RawSqlBuilder import io.ebean.RawSqlBuilder
import io.javalin.http.* import io.javalin.http.*
@ -379,8 +380,8 @@ object PurchaseOrderCtrl {
fun getNextNum(ctx: Context) { fun getNextNum(ctx: Context) {
val prefix = "PO/" val prefix = "PO/"
val cnt = database.find(PurchaseOrder::class.java) val cnt = (database.find(PurchaseOrder::class.java)
.findCount() .findCount() + 1)
.toString() .toString()
.padStart(6, '0') .padStart(6, '0')
val seq = SequenceNumber(prefix + cnt) val seq = SequenceNumber(prefix + cnt)
@ -499,7 +500,27 @@ object ProductCtrl {
} }
data class PF(val common: CommonFilters, val productFilters: ProductFilters) 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<GetPrice>()
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) { fun getAll(ctx: Context) {
val filters = ctx.bodyAsClass<PF>() val filters = ctx.bodyAsClass<PF>()
val prods = searchProducts(filters.common, filters.productFilters) val prods = searchProducts(filters.common, filters.productFilters)

View File

@ -209,7 +209,7 @@ fun exportQuotations(quotes: List<Quotation>) {
row.createCell(i++).setCellValue(quote.quoteDate) row.createCell(i++).setCellValue(quote.quoteDate)
row.createCell(i++).setCellValue(quote.validTill) row.createCell(i++).setCellValue(quote.validTill)
//6 would be repeated //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].productName)
row.createCell(i++).setCellValue(quote.products[j].unitPrice) row.createCell(i++).setCellValue(quote.products[j].unitPrice)
row.createCell(i++).setCellValue(quote.products[j].quantity) row.createCell(i++).setCellValue(quote.products[j].quantity)
@ -269,7 +269,7 @@ fun exportProds(prods: List<Product>) {
for (prod in prods) { for (prod in prods) {
val row = sh.createRow(rowCnt++) val row = sh.createRow(rowCnt++)
var i = 0 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.name)
row.createCell(i++).setCellValue(prod.description) row.createCell(i++).setCellValue(prod.description)
row.createCell(i++).setCellValue(prod.hsnCode) row.createCell(i++).setCellValue(prod.hsnCode)
@ -313,7 +313,7 @@ fun exportPos(pos: List<PurchaseOrder>) {
row.createCell(i++).setCellValue(po.vendor?.address) row.createCell(i++).setCellValue(po.vendor?.address)
//6 would be repeated //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].productName)
row.createCell(i++).setCellValue(po.products[j].unitPrice) row.createCell(i++).setCellValue(po.products[j].unitPrice)
row.createCell(i++).setCellValue(po.products[j].quantity) row.createCell(i++).setCellValue(po.products[j].quantity)
@ -356,7 +356,7 @@ fun exportIncomingInventory(tickets: List<IncomingInventory>) {
row.createCell(i++).setCellValue(ticket.vendorBillAmount) row.createCell(i++).setCellValue(ticket.vendorBillAmount)
//6 would be repeated //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].productName)
row.createCell(i++).setCellValue(ticket.products!![j].unitPrice) row.createCell(i++).setCellValue(ticket.products!![j].unitPrice)
row.createCell(i++).setCellValue(ticket.products!![j].quantity) row.createCell(i++).setCellValue(ticket.products!![j].quantity)
@ -395,7 +395,7 @@ fun exportOutgoingInventory(tickets: List<OutgoingInventory>) {
row.createCell(i++).setCellValue(ticket.purpose) row.createCell(i++).setCellValue(ticket.purpose)
//6 would be repeated //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].productName)
row.createCell(i++).setCellValue(ticket.products!![j].unitPrice) row.createCell(i++).setCellValue(ticket.products!![j].unitPrice)
row.createCell(i++).setCellValue(ticket.products!![j].quantity) row.createCell(i++).setCellValue(ticket.products!![j].quantity)
@ -460,7 +460,7 @@ fun exportInvoices(invoices: List<Invoice>) {
row.createCell(i++).setCellValue(invoice.vendor?.address) row.createCell(i++).setCellValue(invoice.vendor?.address)
//6 would be repeated //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") 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.unitPrice) }
invoice.products?.get(j)?.let { row.createCell(i++).setCellValue(it.quantity) } 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 prodQuantity = doubleFromCellHelper(row.getCell(8))
val prodUnitPrice = doubleFromCellHelper(row.getCell(9)) val prodUnitPrice = doubleFromCellHelper(row.getCell(9))
val totalQuoteAmount = doubleFromCellHelper(row.getCell(10)) val totalQuoteAmount = doubleFromCellHelper(row.getCell(10))
val prod = POProducts("", prodName, prodUnitPrice, prodQuantity) val prod = POProducts(0, prodName, prodUnitPrice, prodQuantity)
if (quotesMap.containsKey(quoteNumber)) { if (quotesMap.containsKey(quoteNumber)) {
//duplicated row //duplicated row
@ -597,7 +597,7 @@ fun ImportFromExcel(fileType: FileType, filePath: String) {
//tncs, docs //tncs, docs
val prod = POProducts( val prod = POProducts(
productId = "", productId = 0,
productName = prodName, productName = prodName,
unitPrice = 0.0, unitPrice = 0.0,
quantity = prodQuantity, quantity = prodQuantity,
@ -658,7 +658,7 @@ fun ImportFromExcel(fileType: FileType, filePath: String) {
//new prod object //new prod object
val prod = Product() val prod = Product()
prod.id = prodId prod.code = prodId
prod.name = prodName prod.name = prodName
prod.description = prodDesc prod.description = prodDesc
prod.hsnCode = prodHsnCode prod.hsnCode = prodHsnCode

View File

@ -14,7 +14,7 @@ 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 POProducts( data class POProducts(
val productId: String = "", 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,
@ -344,7 +344,8 @@ open class Product : BaseTenantModel() {
this.gstPct = updatedProduct.gstPct this.gstPct = updatedProduct.gstPct
} }
var id: String? = null @Column(name = "id")
var code: String? = null
var name: String = "" var name: String = ""
var description: String = "" var description: String = ""
var hsnCode: String = "" var hsnCode: String = ""

View File

@ -8,7 +8,7 @@
</addColumn> </addColumn>
<alterColumn columnName="uom" tableName="product" checkConstraint="check ( uom in ('NOS','LTR','MTR','ALL'))" checkConstraintName="ck_product_uom"/> <alterColumn columnName="uom" tableName="product" checkConstraint="check ( uom in ('NOS','LTR','MTR','ALL'))" checkConstraintName="ck_product_uom"/>
<addColumn tableName="product"> <addColumn tableName="product">
<column name="id" type="bigint"/> <column name="code" type="bigint"/>
</addColumn> </addColumn>
<alterColumn columnName="reference_quotation" tableName="purchase_order" currentType="varchar" notnull="false" currentNotnull="true"/> <alterColumn columnName="reference_quotation" tableName="purchase_order" currentType="varchar" notnull="false" currentNotnull="true"/>
<alterColumn columnName="total_amount" tableName="purchase_order" type="double" currentType="integer" currentNotnull="true"/> <alterColumn columnName="total_amount" tableName="purchase_order" type="double" currentType="integer" currentNotnull="true"/>