handle limit
This commit is contained in:
parent
bb169d6cc8
commit
7b39e64ae5
@ -289,6 +289,10 @@ open class Plant : BaseModel() {
|
|||||||
this.clear()
|
this.clear()
|
||||||
this.putAll(p.print ?: emptyMap())
|
this.putAll(p.print ?: emptyMap())
|
||||||
}
|
}
|
||||||
|
this.limits?.apply {
|
||||||
|
this.clear()
|
||||||
|
this.putAll(p.limits ?: emptyMap())
|
||||||
|
}
|
||||||
this.save()
|
this.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
35
src/main/resources/scripts/expense.kts
Normal file
35
src/main/resources/scripts/expense.kts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import com.restapi.domain.DataModel
|
||||||
|
import com.restapi.domain.EntityModel
|
||||||
|
import io.ebean.Database
|
||||||
|
import org.slf4j.Logger
|
||||||
|
import java.time.LocalDate
|
||||||
|
|
||||||
|
fun execute(d: Map<String, Any>, entityModel: EntityModel?, db: Database, logger: Logger, user: String, tenant: String): Map<String, Any> {
|
||||||
|
println("execute on $d")
|
||||||
|
//check if the limits have exceeded in the given month
|
||||||
|
|
||||||
|
//language=PostgreSQL
|
||||||
|
val q = db.sqlQuery(
|
||||||
|
"""
|
||||||
|
select sum(cast(data->>'amount' as float)) as amount from data_model
|
||||||
|
where entity_name = 'expense'
|
||||||
|
and cast(data->>'date' as timestamp) between :f and :t
|
||||||
|
and data->>'plantId' = :p
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
q.setParameter("f", LocalDate.parse(d["fromDate"] as String))
|
||||||
|
q.setParameter("t", LocalDate.parse(d["toDate"] as String))
|
||||||
|
q.setParameter("p", d["plantId"] as String)
|
||||||
|
val sum = q.findOne()?.getLong("amount") ?: 0
|
||||||
|
|
||||||
|
return mapOf("sum" to sum)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun preSave(d: DataModel, entityModel: EntityModel?, db: Database, logger: Logger, user: String, tenant: String): Boolean {
|
||||||
|
logger.warn("PreSave $d")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun postSave(d: DataModel, entityModel: EntityModel?, db: Database, logger: Logger, user: String, tenant: String) {
|
||||||
|
println("PostSave $d")
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user