Compare commits
7 Commits
b5c28dd288
...
471c043218
| Author | SHA1 | Date | |
|---|---|---|---|
| 471c043218 | |||
| d8ab337fde | |||
| d23ac5261d | |||
| 976aebec5b | |||
| a3f7614979 | |||
| 8745db2127 | |||
| 438daacdc6 |
10
api.http
10
api.http
@ -93,16 +93,16 @@ Authorization: {{auth-token}}
|
|||||||
DELETE http://localhost:9001/api/vehicle/KA01HD6667
|
DELETE http://localhost:9001/api/vehicle/KA01HD6667
|
||||||
Authorization: {{auth-token}}
|
Authorization: {{auth-token}}
|
||||||
|
|
||||||
### get po for id
|
### get products
|
||||||
GET http://localhost:9001/api/vendor/product
|
GET http://localhost:9001/api/vendor/product
|
||||||
Authorization: {{auth-token}}
|
Authorization: {{auth-token}}
|
||||||
|
|
||||||
### get product for id
|
### create excel for products
|
||||||
GET http://localhost:9001/api/vendor/product/7
|
POST http://localhost:9001/api/vendor/product/product-excel
|
||||||
Authorization: {{auth-token}}
|
Authorization: {{auth-token}}
|
||||||
|
|
||||||
### get row
|
### get
|
||||||
GET http://localhost:9001/api/vendor/product/7
|
GET http://localhost:9001/api/vendor/product/product-import
|
||||||
Authorization: Bearer {{auth-token}}
|
Authorization: Bearer {{auth-token}}
|
||||||
|
|
||||||
### create product
|
### create product
|
||||||
|
|||||||
@ -36,10 +36,9 @@ dependencies {
|
|||||||
implementation("org.yaml:snakeyaml:2.2")
|
implementation("org.yaml:snakeyaml:2.2")
|
||||||
implementation("io.minio:minio:8.5.7")
|
implementation("io.minio:minio:8.5.7")
|
||||||
implementation("org.apache.httpcomponents:httpclient:4.5.14")
|
implementation("org.apache.httpcomponents:httpclient:4.5.14")
|
||||||
implementation("org.apache.poi:poi:5.0.0")
|
implementation("org.apache.poi:poi:5.2.3")
|
||||||
implementation("org.apache.poi:poi-ooxml:5.0.0")
|
implementation("org.apache.poi:poi-ooxml:5.2.3")
|
||||||
implementation("com.google.code.gson:gson:2.8.8")
|
implementation("com.google.code.gson:gson:2.8.8")
|
||||||
|
|
||||||
api ("net.cactusthorn.config:config-core:0.81")
|
api ("net.cactusthorn.config:config-core:0.81")
|
||||||
api ("net.cactusthorn.config:config-yaml:0.81")
|
api ("net.cactusthorn.config:config-yaml:0.81")
|
||||||
kapt("net.cactusthorn.config:config-compiler:0.81")
|
kapt("net.cactusthorn.config:config-compiler:0.81")
|
||||||
|
|||||||
@ -6,6 +6,8 @@ import com.restapi.config.AppConfig.Companion.appConfig
|
|||||||
import com.restapi.config.Auth.validateAuthToken
|
import com.restapi.config.Auth.validateAuthToken
|
||||||
import com.restapi.controllers.*
|
import com.restapi.controllers.*
|
||||||
import com.restapi.domain.DataNotFoundException
|
import com.restapi.domain.DataNotFoundException
|
||||||
|
import com.restapi.domain.Product
|
||||||
|
import com.restapi.domain.Session.a
|
||||||
import com.restapi.domain.Session.currentTenant
|
import com.restapi.domain.Session.currentTenant
|
||||||
import com.restapi.domain.Session.currentUser
|
import com.restapi.domain.Session.currentUser
|
||||||
import com.restapi.domain.Session.objectMapper
|
import com.restapi.domain.Session.objectMapper
|
||||||
@ -23,6 +25,7 @@ import io.javalin.http.util.RateLimitUtil
|
|||||||
import io.javalin.json.JavalinJackson
|
import io.javalin.json.JavalinJackson
|
||||||
import org.jose4j.jwt.consumer.InvalidJwtException
|
import org.jose4j.jwt.consumer.InvalidJwtException
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import java.io.InputStream
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -138,13 +141,30 @@ fun main(args: Array<String>) {
|
|||||||
get("/rfq/{rfqNum}", QuotationCtrl::reqForQuote, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_QUOTE_VIEW"))))
|
get("/rfq/{rfqNum}", QuotationCtrl::reqForQuote, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_QUOTE_VIEW"))))
|
||||||
delete("/{id}", QuotationCtrl::delete, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_ADMIN"))))
|
delete("/{id}", QuotationCtrl::delete, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_ADMIN"))))
|
||||||
}
|
}
|
||||||
path("/product"){
|
path("/product") {
|
||||||
post("", ProductCtrl::create, Roles(Role.Explicit(listOf("ROLE_PRODUCT_CREATE", "ROLE_ADMIN", "ROLE_VENDOR_CREATE"))))
|
post("", ProductCtrl::create, Roles(Role.Explicit(listOf("ROLE_PRODUCT_CREATE", "ROLE_ADMIN"))))
|
||||||
//get("/{hsnCode}", ProductCtrl::get, Roles(Role.Explicit(listOf("ROLE_PRODUCT_VIEW", "ROLE_ADMIN"))))
|
//get("/{hsnCode}", ProductCtrl::get, Roles(Role.Explicit(listOf("ROLE_PRODUCT_VIEW", "ROLE_ADMIN"))))
|
||||||
put("/{id}", ProductCtrl::update, Roles(Role.Explicit(listOf("ROLE_PRODUCT_UPDATE", "ROLE_ADMIN"))))
|
put(
|
||||||
|
"/{id}",
|
||||||
|
ProductCtrl::update,
|
||||||
|
Roles(Role.Explicit(listOf("ROLE_PRODUCT_UPDATE", "ROLE_ADMIN")))
|
||||||
|
)
|
||||||
//patch("/{id}", ProductCtrl::patch, Roles(Role.Explicit(listOf("ROLE_PRODUCT_UPDATE", "ROLE_ADMIN"))))
|
//patch("/{id}", ProductCtrl::patch, Roles(Role.Explicit(listOf("ROLE_PRODUCT_UPDATE", "ROLE_ADMIN"))))
|
||||||
delete("/{id}", ProductCtrl::delete, Roles(Role.Explicit(listOf("ROLE_PRODUCT_DELETE", "ROLE_ADMIN"))))
|
delete(
|
||||||
|
"/{id}",
|
||||||
|
ProductCtrl::delete,
|
||||||
|
Roles(Role.Explicit(listOf("ROLE_PRODUCT_DELETE", "ROLE_ADMIN")))
|
||||||
|
)
|
||||||
get("", ProductCtrl::getAll, Roles(Role.Explicit(listOf("ROLE_PRODUCT_VIEW", "ROLE_ADMIN"))))
|
get("", ProductCtrl::getAll, Roles(Role.Explicit(listOf("ROLE_PRODUCT_VIEW", "ROLE_ADMIN"))))
|
||||||
|
post("/product-excel", ProductCtrl::prodExcel)
|
||||||
|
get("/product-import") { ctx -> //ctx.json(ExcelRead())}
|
||||||
|
val fileItem = ctx.uploadedFiles("file")
|
||||||
|
if (fileItem != null) {
|
||||||
|
ctx.result("Data imported successfully!")
|
||||||
|
} else {
|
||||||
|
ctx.result("No file uploaded")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
path("/doc"){
|
path("/doc"){
|
||||||
post("", Document::create, Roles(Role.Explicit(listOf("ROLE_DOC_CREATE", "ROLE_ADMIN"))))
|
post("", Document::create, Roles(Role.Explicit(listOf("ROLE_DOC_CREATE", "ROLE_ADMIN"))))
|
||||||
|
|||||||
@ -17,7 +17,11 @@ import com.restapi.integ.Scripting
|
|||||||
import io.ebean.CallableSql
|
import io.ebean.CallableSql
|
||||||
import io.ebean.RawSqlBuilder
|
import io.ebean.RawSqlBuilder
|
||||||
import io.javalin.http.*
|
import io.javalin.http.*
|
||||||
|
import org.apache.poi.ss.usermodel.WorkbookFactory
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.io.InputStream
|
||||||
import java.sql.Types
|
import java.sql.Types
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
@ -436,7 +440,6 @@ object PurchaseOrderCtrl {
|
|||||||
|
|
||||||
data class ProductSearch(
|
data class ProductSearch(
|
||||||
var isSort: String? = null
|
var isSort: String? = null
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
object ProductCtrl {
|
object ProductCtrl {
|
||||||
@ -449,7 +452,7 @@ object ProductCtrl {
|
|||||||
fun getAll(ctx: Context){
|
fun getAll(ctx: Context){
|
||||||
val productList = Session.database.find(Product::class.java)
|
val productList = Session.database.find(Product::class.java)
|
||||||
.findList()
|
.findList()
|
||||||
.sortedBy { it.hsnCode }
|
//.sortedBy { it.hsnCode }
|
||||||
|
|
||||||
ctx.json(productList)
|
ctx.json(productList)
|
||||||
}
|
}
|
||||||
@ -469,9 +472,41 @@ object ProductCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun update(ctx: Context) {
|
fun update(ctx: Context) {
|
||||||
val id = ctx.pathParam("id")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
fun prodExcel(it: Context) {
|
||||||
|
val product = database.find(Product::class.java).findList()
|
||||||
|
it.result(CreateExcel(product)).contentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||||
|
.header("Content-Disposition", "attachment; filename=\"product.xlsx\"")
|
||||||
|
}
|
||||||
|
|
||||||
|
data class ProductList(
|
||||||
|
val name: String,
|
||||||
|
val description: String,
|
||||||
|
val hsnCode: String,
|
||||||
|
val uom: String?,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun excelToDb(it: Context){
|
||||||
|
val inputStream = FileInputStream("C:\\Users\\vinay\\IdeaProjects\\readymixerp_modules_api_git\\Untitled 1.xlsx")
|
||||||
|
val workbook = WorkbookFactory.create(inputStream)
|
||||||
|
val workSheet = workbook.getSheetAt(0)
|
||||||
|
|
||||||
|
val dataList = mutableListOf<ProductList>()
|
||||||
|
|
||||||
|
for (row in workSheet) {
|
||||||
|
val cell1Value = row.getCell(0).stringCellValue
|
||||||
|
val cell2Value = row.getCell(1).stringCellValue
|
||||||
|
val cell3Value = row.getCell(2).stringCellValue
|
||||||
|
val cell4Value = row.getCell(3).stringCellValue
|
||||||
|
|
||||||
|
val data = ProductList(cell1Value, cell2Value, cell3Value, cell4Value)
|
||||||
|
dataList.add(data)
|
||||||
|
|
||||||
|
}
|
||||||
|
database.saveAll(dataList)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object QuotationCtrl {
|
object QuotationCtrl {
|
||||||
@ -678,4 +713,4 @@ object RequestForQuote {
|
|||||||
//shuld we compare the new body fields with preexisting ones and prepare a sql query to update those fields??
|
//shuld we compare the new body fields with preexisting ones and prepare a sql query to update those fields??
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
package com.restapi.controllers
|
package com.restapi.controllers
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
|
||||||
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.restapi.domain.*
|
import com.restapi.domain.*
|
||||||
import com.restapi.domain.Document
|
import com.restapi.domain.Document
|
||||||
@ -11,15 +14,10 @@ import com.restapi.domain.Session.database
|
|||||||
import com.restapi.domain.Vendor
|
import com.restapi.domain.Vendor
|
||||||
import org.apache.poi.hssf.usermodel.DVConstraint
|
import org.apache.poi.hssf.usermodel.DVConstraint
|
||||||
import org.apache.poi.hssf.usermodel.HSSFDataValidation
|
import org.apache.poi.hssf.usermodel.HSSFDataValidation
|
||||||
import org.apache.poi.ss.usermodel.Cell
|
import org.apache.poi.ss.usermodel.*
|
||||||
import org.apache.poi.ss.usermodel.CellType
|
|
||||||
import org.apache.poi.ss.usermodel.DateUtil
|
|
||||||
import org.apache.poi.ss.usermodel.Workbook
|
|
||||||
import org.apache.poi.ss.usermodel.WorkbookFactory
|
|
||||||
import org.apache.poi.ss.util.CellRangeAddressList
|
import org.apache.poi.ss.util.CellRangeAddressList
|
||||||
import java.io.File
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook
|
||||||
import java.io.FileInputStream
|
import java.io.*
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
@ -416,4 +414,141 @@ fun ImportFromExcel(fileType: FileType, filePath : String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class validateExcel(
|
||||||
|
val name: String,
|
||||||
|
val description: String,
|
||||||
|
val hsnCode: String,
|
||||||
|
val ok: Boolean,
|
||||||
|
val err: String,
|
||||||
|
)
|
||||||
|
|
||||||
|
val app_common_om = jacksonObjectMapper().apply {
|
||||||
|
registerModule(JavaTimeModule())
|
||||||
|
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ExcelRead(): String{
|
||||||
|
val inputStream = FileInputStream("C:\\Users\\vinay\\IdeaProjects\\readymixerp_modules_api_git\\Untitled 1.xlsx")
|
||||||
|
val workbook = WorkbookFactory.create(inputStream)
|
||||||
|
val workSheet = workbook.getSheetAt(0)
|
||||||
|
var h = true
|
||||||
|
//Header check
|
||||||
|
if(workSheet.getRow(0).getCell(0).stringCellValue.equals("Name")) {
|
||||||
|
if (workSheet.getRow(0).getCell(1).stringCellValue.equals("Description")) {
|
||||||
|
if (workSheet.getRow(0).getCell(2).stringCellValue.equals("HSN")) {
|
||||||
|
if (workSheet.getRow(0).getCell(3).stringCellValue.equals("UOM")) {
|
||||||
|
h = false
|
||||||
|
}else return "Header UOM mismatch"
|
||||||
|
}else return "Header-HSN mismatch"
|
||||||
|
}else return "Header-Desc mismatch"
|
||||||
|
}else return "Header-Name mismatch"
|
||||||
|
|
||||||
|
val resp = arrayListOf<validateExcel>()
|
||||||
|
|
||||||
|
if(h==false) {
|
||||||
|
workSheet.rowIterator().forEach { row ->
|
||||||
|
|
||||||
|
if (row == null) return@forEach
|
||||||
|
|
||||||
|
if (h) {
|
||||||
|
|
||||||
|
val pName = row.getCell(0).run {
|
||||||
|
when {
|
||||||
|
this == null -> ""
|
||||||
|
this.cellType == CellType.STRING -> this.stringCellValue
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val pDesc = row.getCell(1).run {
|
||||||
|
when {
|
||||||
|
this == null -> ""
|
||||||
|
this.cellType == CellType.STRING -> this.stringCellValue
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val pHsn = row.getCell(2).run {
|
||||||
|
when {
|
||||||
|
this == null -> ""
|
||||||
|
this.cellType == CellType.STRING -> this.stringCellValue
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pName.isEmpty() && pDesc.isEmpty() && pHsn.isEmpty()) {
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
if (pName.isEmpty()) {
|
||||||
|
resp.add(
|
||||||
|
validateExcel(
|
||||||
|
name = pName,
|
||||||
|
description = pDesc,
|
||||||
|
hsnCode = pHsn,
|
||||||
|
ok = false,
|
||||||
|
err = "Product name is required"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
if (pDesc.isEmpty()) {
|
||||||
|
resp.add(
|
||||||
|
validateExcel(
|
||||||
|
name = pName,
|
||||||
|
description = pDesc,
|
||||||
|
hsnCode = pHsn,
|
||||||
|
ok = false,
|
||||||
|
err = "Product description is required"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
if (pHsn.isEmpty()) {
|
||||||
|
resp.add(
|
||||||
|
validateExcel(
|
||||||
|
name = pName,
|
||||||
|
description = pDesc,
|
||||||
|
hsnCode = pHsn,
|
||||||
|
ok = false,
|
||||||
|
err = "Product HSN is required"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
}
|
||||||
|
h = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return app_common_om.writeValueAsString(resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun CreateExcel(productList: List<Product>): InputStream {
|
||||||
|
val wb = XSSFWorkbook()
|
||||||
|
val sh = wb.createSheet()
|
||||||
|
val rows: Row = sh.createRow(0)
|
||||||
|
rows.createCell(0).setCellValue("Name")
|
||||||
|
rows.createCell(1).setCellValue("Description")
|
||||||
|
rows.createCell(2).setCellValue("HSN")
|
||||||
|
rows.createCell(3).setCellValue("UOM")
|
||||||
|
|
||||||
|
var rowNum = 1
|
||||||
|
for (product in productList) {
|
||||||
|
val row: Row = sh.createRow(rowNum++)
|
||||||
|
|
||||||
|
row.createCell(0).setCellValue(product.name)
|
||||||
|
row.createCell(1).setCellValue(product.description)
|
||||||
|
row.createCell(2).setCellValue(product.hsnCode)
|
||||||
|
|
||||||
|
val uomCell: Cell = row.createCell(3)
|
||||||
|
uomCell.setCellValue(product.uom?.name ?: "")
|
||||||
|
}
|
||||||
|
|
||||||
|
val baos = ByteArrayOutputStream()
|
||||||
|
wb.write(baos)
|
||||||
|
wb.close()
|
||||||
|
|
||||||
|
return ByteArrayInputStream(baos.toByteArray())
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -141,4 +141,13 @@ fun searchRFQ(commonFilters: CommonFilters, rfqFilters: RFQFilters) : List<ReqFo
|
|||||||
applyVendorHelper(q, commonFilters.vendor)
|
applyVendorHelper(q, commonFilters.vendor)
|
||||||
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
|
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
|
||||||
return q.findList()
|
return q.findList()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun searchProduct(commonFilters: CommonFilters, productFilters: ProductFilters): List<Product> {
|
||||||
|
val p = database.find(Product::class.java)
|
||||||
|
.where()
|
||||||
|
.ilike("hsnCode", productFilters.hsnLike)
|
||||||
|
.ilike("Pname", productFilters.nameLike)
|
||||||
|
applySortHelper(p, commonFilters.sortBy, commonFilters.sortAsc)
|
||||||
|
return p.findList()
|
||||||
}
|
}
|
||||||
@ -9,6 +9,7 @@ import io.ebean.annotation.*
|
|||||||
import io.ebean.annotation.Index
|
import io.ebean.annotation.Index
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
|
import java.util.*
|
||||||
import javax.persistence.*
|
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())
|
||||||
@ -274,6 +275,7 @@ open class PurchaseOrder :BaseTenantModel() {
|
|||||||
enum class UOM {
|
enum class UOM {
|
||||||
NOS, LTR, MTR, ALL
|
NOS, LTR, MTR, ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
open class Product :BaseTenantModel() {
|
open class Product :BaseTenantModel() {
|
||||||
var id: Long? = null
|
var id: Long? = null
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user