From 141d8961e45024b078f949b41785eeccce029833 Mon Sep 17 00:00:00 2001 From: arsalan Date: Mon, 18 Mar 2024 16:07:01 +0530 Subject: [PATCH] add fleet --- excel/Fleets.xls | Bin 0 -> 5120 bytes excel/ReminderLogs.xls | Bin 0 -> 4608 bytes src/main/kotlin/com/restapi/Main.kt | 59 +++++ .../com/restapi/controllers/Entities.kt | 246 +++++++++++++++++- .../kotlin/com/restapi/controllers/Excel.kt | 45 ++++ .../kotlin/com/restapi/controllers/Filters.kt | 32 ++- src/main/kotlin/com/restapi/domain/models.kt | 56 +++- src/main/resources/dbmigration/1.16.sql | 67 +++++ src/main/resources/dbmigration/1.17.sql | 30 +++ src/main/resources/dbmigration/1.18.sql | 2 + src/main/resources/dbmigration/1.19.sql | 62 +++++ src/main/resources/dbmigration/1.20.sql | 2 + src/main/resources/dbmigration/1.21.sql | 6 + src/main/resources/dbmigration/1.22.sql | 2 + .../dbmigration/model/1.16.model.xml | 63 +++++ .../dbmigration/model/1.17.model.xml | 27 ++ .../dbmigration/model/1.18.model.xml | 8 + .../dbmigration/model/1.19.model.xml | 55 ++++ .../dbmigration/model/1.20.model.xml | 8 + .../dbmigration/model/1.21.model.xml | 8 + .../dbmigration/model/1.22.model.xml | 8 + 21 files changed, 772 insertions(+), 14 deletions(-) create mode 100644 excel/Fleets.xls create mode 100644 excel/ReminderLogs.xls create mode 100644 src/main/resources/dbmigration/1.16.sql create mode 100644 src/main/resources/dbmigration/1.17.sql create mode 100644 src/main/resources/dbmigration/1.18.sql create mode 100644 src/main/resources/dbmigration/1.19.sql create mode 100644 src/main/resources/dbmigration/1.20.sql create mode 100644 src/main/resources/dbmigration/1.21.sql create mode 100644 src/main/resources/dbmigration/1.22.sql create mode 100644 src/main/resources/dbmigration/model/1.16.model.xml create mode 100644 src/main/resources/dbmigration/model/1.17.model.xml create mode 100644 src/main/resources/dbmigration/model/1.18.model.xml create mode 100644 src/main/resources/dbmigration/model/1.19.model.xml create mode 100644 src/main/resources/dbmigration/model/1.20.model.xml create mode 100644 src/main/resources/dbmigration/model/1.21.model.xml create mode 100644 src/main/resources/dbmigration/model/1.22.model.xml diff --git a/excel/Fleets.xls b/excel/Fleets.xls new file mode 100644 index 0000000000000000000000000000000000000000..ab6abe7e17aa086348b0bb54ad433eb978566098 GIT binary patch literal 5120 zcmeHLOKe+36rK06owQAyPiaeN(pM*G9mfrJLIffziBSIJs!b^qGIe)Kr4p<7jK_oYADV$_wT$1Y za@1pL31va8b1DCDI;H}KKir!Au}=>c>b4GRgJ;2BQ1fb5{FvXTRpY7-WtRErM`Nqq z+IKzv-8KI&4bSdvfTfM02LPV=5YPlre~|9p8Q_`aJrzHPe^N?~4k_HSZGd}MFSzW5RHC3S`OL8h>hS;#Co|4MpP ze8?Ewo988e51Ll&Cu(r(Bkz>_L#f@=mZ-@Yt;VH?Kkt1A7K}-rGbhCEEy*L2w<0&x zr_$zo(Il~Rzl441mA82$kOC@I$Y&P*k%~>aU*YJnyFiDd6X}ce#(R4c>4CAR|2)uR zpTe@>5cwL^zA)`(U#vE9utGRvzR6IcrVohdrXM%DQ*Tq-lQta1kxM9*CPB>cJ@Uk; z$OB`Z7&#Y#Kk4X18VqrqSDf5*w7ONysWgc>HTLImrm;@dMB4KjE;?03H$Gk=d;k~2 z{Z)j1YoF6=Dzue$J91Si^=k>!QBGS9^;~_?|KeBdujfiOvfoS3UK`op&3c2|uAKb& z9Mtphn_uDU2lmj%_t3}o&^I^KGr$pl-b8?7H{qSP<-B9ss;y|1Shg2~Qg#$=DLacH zDOFKPd9)ZPy(AaMHC#uV@_iIkPv=~BHE|uUPy@dY3@Pp7IB?!=qHd{fgDQN-n>W)1A%vPK|nWqwruQ zv$VRrk{d;f;gKYc$s)6CvV=>gNv*+>amE)YpGSEJU2LFy0_6`Vuc17NIb}?u-(79$ zvz8m7ZOEunhfPKyI)O~mMND*y-1tY3XA!&b_HUPazYUzX-v9ZVso9I;Y0<|-KPdTY zqA9}0PyN^;cuS~PQL}CP5zp&l{f6WlDuUj#0Dq>68*%u{v@`CPhI$4y=+$H_r6X-G z<~A8s@!9*7F~X_|I(AX7;}uh{!>sPo(c^kMOz$oo=da!lt6!tLEiDrd>{(gRGeXsEY)IS} zS_(j7)M{al4fM>2m8oxn_4F_-J55VuU~EeU6F<#h!uJY;3E#sK{pvPkV6S8_s~FW1Zef!16Jy=u2frogJx3XquL>=3Ed0LEZ7VB2ByG8yDk~lmCVq*~ zI<$)^BxB-N3i}QT6VIxa$mEpUR+t`~_zoe&7MA`x{?VxXURIBo9qJPfR!uPTQaAeH TK0)G^XW|C_6QRAd`3u?axh=+C literal 0 HcmV?d00001 diff --git a/excel/ReminderLogs.xls b/excel/ReminderLogs.xls new file mode 100644 index 0000000000000000000000000000000000000000..0db512fe3dc847d3d4cd24c4e9e6d81f5122f47c GIT binary patch literal 4608 zcmeHKO=w(I6h80Gn`B~}$t0<*rZ#;}EX_??r`qC=l{HW z&pr3fk3S5qox3=4RW`M0NyyExPkP$uR@+=MA~tZ+ZiZn<7U!7mwExfw%*qmeO>yN# z@iEqAg|s$p2^Mo&m+;XIo*bCSPcnI(?U<9xq@Ce`lU=(l=-~t{6?Bvkhi`wvBY~EbnfhX-c1IYO z82*NjQD+41aCEYdWycC*W0U3F^mshajXDRhEjUCm1>DzWz3S`jA})3aXDk+ZVzR>q zP?$L+DW17bnNCYa@M+1*q)3?#@@^bagpMnon~u=z<5|R09xs*Qp&&UqOvQGsyt|>2 zcRS>dNI|eq?T$?39ljV;o4aCh!{JjhAy2kBjJ0E*k*d1g&|A||CGuB@AE(juMEDdxB*6h8B(wP>!zA98Tve3!c}U{0LX5 zh2NK!j?O+DxTu=Qb!q4&%8L|EkFP9ysI@a^ms)-km+aBH_g2gE=T~sS&U$AT{i;`Y zU#K)aT)s2&O|R;nSYGl`g-?15i}N)PD#!drt6uTvJ(%-bwHla57n{D+xvTra~OG}o64V&Z~CwFt^#M}-(~X-H;pd>wltmr{aP<~qp#xTXYCx+ zs+oc9>tFow(@S$N7t2b|D}6%yca;)ACT@qYz^JkE4mhh${9brZrQg^7oMd6W3gFL{ zf>nrCaII*ptQ9Re0S>I%e2JL1i-|vF^G(8e^hdxN5YlL3GmQtdopwW4#k^od3}&Gy zQ`cZNFlrer0gP*8Fb5dF&0s9%%nV}GAJElJAYOhI-%h3(z6}aCPYgd1@q_&DrKHUS za+G4(J(wpkrxxSDw?$gqkxr{NBnI^LMyoa=HT=&bt9E47*rHYD#4qSe2zXqM%Sn08 g9+Iz^7E)ptwF8iia)Y17M%CMV!l?dEch6SfAA#|(*8l(j literal 0 HcmV?d00001 diff --git a/src/main/kotlin/com/restapi/Main.kt b/src/main/kotlin/com/restapi/Main.kt index a567f37..74f0a96 100644 --- a/src/main/kotlin/com/restapi/Main.kt +++ b/src/main/kotlin/com/restapi/Main.kt @@ -6,6 +6,7 @@ import com.restapi.config.AppConfig.Companion.appConfig import com.restapi.config.Auth.validateAuthToken import com.restapi.controllers.* import com.restapi.domain.DataNotFoundException +import com.restapi.domain.ReminderLog import com.restapi.domain.Session.currentTenant import com.restapi.domain.Session.currentUser import com.restapi.domain.Session.objectMapper @@ -190,6 +191,7 @@ fun main(args: Array) { delete("/{id}", PaymentCtrl::delete, Roles(Role.Explicit("ROLE_PAYMENT_CREATE"))) } path("/fleet") { + post("", FleetCtrl::create, Roles(Role.Explicit("ROLE_FLEET_CREATE"))) get( "/{id}", @@ -219,6 +221,63 @@ fun main(args: Array) { ) delete("/{id}", RenewalCtrl::delete, Roles(Role.Explicit("ROLE_FLEET_CREATE"))) } + path("/reminder") { + post("", ReminderCtrl::create, Roles(Role.Explicit("ROLE_REMINDER_CREATE"))) + get( + "/{id}", + ReminderCtrl::get, + Roles(Role.Explicit("ROLE_REMINDER_VIEW", "ROLE_REMINDER_CREATE")) + ) + put("/{id}", ReminderCtrl::update, Roles(Role.Explicit("ROLE_REMINDER_CREATE"))) + post( + "/getAll", + ReminderLogCtrl::getAll, + Roles(Role.Explicit("ROLE_REMINDER_CREATE", "ROLE_REMINDER_VIEW")) + ) + post( + "/done", + ReminderLogCtrl::done, + Roles(Role.Explicit("ROLE_REMAINDER_CREATE")) + ) + get( + "/getAll/{id}", + ReminderCtrl::getAllByFleetId, + Roles(Role.Explicit("ROLE_REMINDER_CREATE", "ROLE_REMINDER_VIEW")) + ) + delete( + "/{id}", + ReminderCtrl::delete, + Roles(Role.Explicit("ROLE_REMINDER_CREATE")) + ) + } + path("/vehicle") { + post("", VehicleCtrl::create, Roles(Role.Explicit("ROLE_FLEET_CREATE"))) + get( + "/{id}", + VehicleCtrl::get, + Roles(Role.Explicit("ROLE_FLEET_VIEW", "ROLE_FLEET_CREATE")) + ) + put("/{id}", VehicleCtrl::update, Roles(Role.Explicit("ROLE_FLEET_CREATE"))) + post( + "/getAll", + VehicleCtrl::getAll, + Roles(Role.Explicit("ROLE_FLEET_CREATE", "ROLE_FLEET_VIEW")) + ) + } + path("/fleetType") { + post("", FleetTypeCtrl::create, Roles(Role.Explicit("ROLE_FLEET_CREATE"))) + get( + "/{id}", + FleetTypeCtrl::get, + Roles(Role.Explicit("ROLE_FLEET_VIEW", "ROLE_FLEET_CREATE")) + ) + put("/{id}", FleetTypeCtrl::update, Roles(Role.Explicit("ROLE_FLEET_CREATE"))) + post( + "/getAll", + FleetTypeCtrl::getAll, + Roles(Role.Explicit("ROLE_FLEET_CREATE", "ROLE_FLEET_VIEW")) + ) + } path("/po") { get("/next", PurchaseOrderCtrl::getNextNum, Roles(Role.Explicit("ROLE_PO_CREATE"))) post("", PurchaseOrderCtrl::create, Roles(Role.Explicit("ROLE_PO_CREATE"))) diff --git a/src/main/kotlin/com/restapi/controllers/Entities.kt b/src/main/kotlin/com/restapi/controllers/Entities.kt index f667626..f613686 100644 --- a/src/main/kotlin/com/restapi/controllers/Entities.kt +++ b/src/main/kotlin/com/restapi/controllers/Entities.kt @@ -1047,19 +1047,22 @@ object FleetCtrl { database.save(fleet) ctx.json(fleet).status(HttpStatus.CREATED) } + fun get(ctx: Context) { val id = ctx.pathParam("id").toLong() val fleet = database.find(Fleet::class.java, id) ?: throw NotFoundResponse("No fleet found with id $id") ctx.json(fleet).status(HttpStatus.OK) } + data class FLTF(val common: CommonFilters, val fleetFilters: FleetFilters) + fun getAll(ctx: Context) { val filters = ctx.bodyAsClass() val fleets = searchFleets(filters.common, filters.fleetFilters) val excel = ctx.queryParam("excel") if (excel !== null) { - // exportFleets(fleets) + exportFleets(fleets) val inputStream = FileInputStream("./excel/Fleets.xls") ctx.result(inputStream).status(HttpStatus.OK) } else { @@ -1067,36 +1070,116 @@ object FleetCtrl { } } + fun update(ctx: Context) { val id = ctx.pathParam("id").toLong() val fleet = database.find(Fleet::class.java, id) ?: throw NotFoundResponse("fleet not found for $id") - val updatedFleet= ctx.bodyAsClass() + val updatedFleet = ctx.bodyAsClass() fleet.patchValues(updatedFleet) fleet.update() ctx.json(fleet).status(HttpStatus.OK) } + fun delete(ctx: Context) { } } -object RenewalCtrl{ +object VehicleCtrl { + fun create(ctx: Context) { + val vehicle = ctx.bodyAsClass() + database.save(vehicle) + ctx.json(vehicle).status(HttpStatus.CREATED) + } + + fun get(ctx: Context) { + val id = ctx.pathParam("id").toLong() + val vehicle = database.find(Vehicle::class.java, id) + ?: throw NotFoundResponse("No vehicle found with id $id") + ctx.json(vehicle).status(HttpStatus.OK) + } + + fun getAll(ctx: Context) { + val vehicles = database.find(Vehicle::class.java).findList() + val excel = ctx.queryParam("excel") + if (excel !== null) { + // exportVehicles(vehicles) + val inputStream = FileInputStream("./excel/Vehicles.xls") + ctx.result(inputStream).status(HttpStatus.OK) + } else { + ctx.json(vehicles).status(HttpStatus.OK) + } + + } + + fun update(ctx: Context) { + val id = ctx.pathParam("id").toLong() + val vehicle = + database.find(Vehicle::class.java, id) ?: throw NotFoundResponse("vehicle not found for $id") + val updatedVehicle = ctx.bodyAsClass() + vehicle.patchValues(updatedVehicle) + vehicle.update() + ctx.json(vehicle).status(HttpStatus.OK) + } +} + +object FleetTypeCtrl { + fun create(ctx: Context) { + val fleetType = ctx.bodyAsClass() + database.save(fleetType) + ctx.json(fleetType).status(HttpStatus.CREATED) + } + + fun get(ctx: Context) { + val id = ctx.pathParam("id").toLong() + val fleetType = database.find(FleetType::class.java, id) + ?: throw NotFoundResponse("No fleetType found with id $id") + ctx.json(fleetType).status(HttpStatus.OK) + } + + fun getAll(ctx: Context) { + val fleetTypes = database.find(FleetType::class.java).findList() + val excel = ctx.queryParam("excel") + if (excel !== null) { + // exportFleetTypes(fleetTypes) + val inputStream = FileInputStream("./excel/FleetTypes.xls") + ctx.result(inputStream).status(HttpStatus.OK) + } else { + ctx.json(fleetTypes).status(HttpStatus.OK) + } + + } + + fun update(ctx: Context) { + val id = ctx.pathParam("id").toLong() + val fleetType = + database.find(FleetType::class.java, id) ?: throw NotFoundResponse("fleetType not found for $id") + val updatedFleetType = ctx.bodyAsClass() + fleetType.patchValues(updatedFleetType) + fleetType.update() + ctx.json(fleetType).status(HttpStatus.OK) + } +} + +object RenewalCtrl { fun create(ctx: Context) { val renewal = ctx.bodyAsClass() database.save(renewal) ctx.json(renewal).status(HttpStatus.CREATED) } + fun get(ctx: Context) { val id = ctx.pathParam("id").toLong() val renewal = database.find(Renewal::class.java, id) ?: throw NotFoundResponse("No renewal found with id $id") ctx.json(renewal).status(HttpStatus.OK) } + //data class RNLF(val common: CommonFilters, val renewalFilters: RenewalFilters) fun getAll(ctx: Context) { - // val filters = ctx.bodyAsClass() - // val renewals = searchRenewals(filters.common, filters.renewalFilters) + // val filters = ctx.bodyAsClass() + // val renewals = searchRenewals(filters.common, filters.renewalFilters) val renewals = database.find(Renewal::class.java).findList() val excel = ctx.queryParam("excel") if (excel !== null) { @@ -1108,15 +1191,166 @@ object RenewalCtrl{ } } + fun update(ctx: Context) { val id = ctx.pathParam("id").toLong() val renewal = database.find(Renewal::class.java, id) ?: throw NotFoundResponse("renewal not found for $id") - val updatedRenewal= ctx.bodyAsClass() + val updatedRenewal = ctx.bodyAsClass() renewal.patchValues(updatedRenewal) renewal.update() ctx.json(renewal).status(HttpStatus.OK) } + + fun delete(ctx: Context) { + + } +} + +object ReminderCtrl { + fun create(ctx: Context) { + val renewal = ctx.bodyAsClass() + database.save(renewal) + val entry = ReminderLog() + entry.apply { + reminder = renewal + reminderDate = renewal.nextRenewalDate + reminderType = renewal.type + fleet = renewal.fleet + amount = 0.0 + actedUpon = false + } + ReminderLogCtrl.create(entry) + ctx.json(renewal).status(HttpStatus.CREATED) + } + + fun getAllByFleetId(ctx: Context) { + val fleetId = ctx.pathParam("id").toLong() + val history = database.find(Reminder::class.java) + .where() + .eq("fleet_sys_pk", fleetId) + .findList() + ctx.json(history).status(HttpStatus.OK) + } + + fun get(ctx: Context) { + val id = ctx.pathParam("id").toLong() + val renewal = database.find(Reminder::class.java, id) + ?: throw NotFoundResponse("No renewal found with id $id") + ctx.json(renewal).status(HttpStatus.OK) + } + + //data class RNLF(val common: CommonFilters, val renewalFilters: ReminderFilters) + fun getAll(ctx: Context) { + // val filters = ctx.bodyAsClass() + // val renewals = searchReminders(filters.common, filters.renewalFilters) + val renewals = database.find(Reminder::class.java).findList() + val excel = ctx.queryParam("excel") + if (excel !== null) { + // exportReminders(renewals) + val inputStream = FileInputStream("./excel/Reminders.xls") + ctx.result(inputStream).status(HttpStatus.OK) + } else { + ctx.json(renewals).status(HttpStatus.OK) + } + + } + + fun update(ctx: Context) { + val id = ctx.pathParam("id").toLong() + val renewal = + database.find(Reminder::class.java, id) ?: throw NotFoundResponse("renewal not found for $id") + val updatedReminder = ctx.bodyAsClass() + renewal.patchValues(updatedReminder) + renewal.update() + ctx.json(renewal).status(HttpStatus.OK) + } + + fun delete(ctx: Context) { + + } +} + +object ReminderLogCtrl { + fun create(entry: ReminderLog) { + // val renewal = ctx.bodyAsClass() + + database.save(entry) + return + //ctx.json(renewal).status(HttpStatus.CREATED) + } + + data class Done( + val logId: Long, + val reminderId: Long, + val renewalDate: LocalDate, + val nextRenewalDate: LocalDate, + val amount: Double, + val documents: List? + ) + + fun done(ctx: Context) { + val req = ctx.bodyAsClass() + val reminder = + database.find(Reminder::class.java, req.reminderId) ?: throw NotFoundResponse("No Reminder found") + //update reminder + reminder.apply { + lastRenewalDate = req.renewalDate + nextRenewalDate = req.nextRenewalDate + } + reminder.update() + val entry = database.find(ReminderLog::class.java, req.logId) ?: throw NotFoundResponse("Log not found") + entry.apply { + actedUpon = true + documents = req.documents + amount = req.amount + } + entry.update() + ctx.json(entry).status(HttpStatus.OK) + } + + fun getAllByFleetId(ctx: Context) { + val fleetId = ctx.pathParam("id").toLong() + val history = database.find(ReminderLog::class.java) + .where() + .eq("fleet_sys_pk", fleetId) + .findList() + ctx.json(history).status(HttpStatus.OK) + } + + fun get(ctx: Context) { + val id = ctx.pathParam("id").toLong() + val renewal = database.find(ReminderLog::class.java, id) + ?: throw NotFoundResponse("No renewal found with id $id") + ctx.json(renewal).status(HttpStatus.OK) + } + + data class LOGF(val common: CommonFilters, val reminderLogFilters: ReminderLogFilters) + + fun getAll(ctx: Context) { + val filters = ctx.bodyAsClass() + val entries = searchReminderLogs(filters.common, filters.reminderLogFilters) + val excel = ctx.queryParam("excel") + if (excel !== null) { + exportReminderLogs(entries) + val inputStream = FileInputStream("./excel/ReminderLogs.xls") + ctx.result(inputStream).status(HttpStatus.OK) + } else { + ctx.json(entries).status(HttpStatus.OK) + } + + } + + fun update(ctx: Context) { + val id = ctx.pathParam("id").toLong() + val renewal = + database.find(ReminderLog::class.java, id) ?: throw NotFoundResponse("renewal not found for $id") + val updatedReminderLog = ctx.bodyAsClass() + renewal.patchValues(updatedReminderLog) + renewal.update() + ctx.json(renewal).status(HttpStatus.OK) + } + fun delete(ctx: Context) { } diff --git a/src/main/kotlin/com/restapi/controllers/Excel.kt b/src/main/kotlin/com/restapi/controllers/Excel.kt index a33dfc6..f8ffa98 100644 --- a/src/main/kotlin/com/restapi/controllers/Excel.kt +++ b/src/main/kotlin/com/restapi/controllers/Excel.kt @@ -495,6 +495,51 @@ fun exportInvoices(invoices: List) { saveExcelFileLocally("Invoices.xls", wb) } +fun exportFleets(fleets: List) { + val wb = HSSFWorkbook() + val sh = wb.createSheet() + + val headers: List = listOf("Type", "Reg. Number", "Reg. Date", "Model", "Make", "Driver", "Mileage") + createHeaderRow(headers, sh, wb) + + var rowCnt = 1 + + for (flt in fleets) { + val row = sh.createRow(rowCnt++) + var i = 0 + row.createCell(i++).setCellValue(flt.type) + row.createCell(i++).setCellValue(flt.regNumber) + row.createCell(i++).setCellValue(flt.regDate) + row.createCell(i++).setCellValue(flt.model) + row.createCell(i++).setCellValue(flt.make) + row.createCell(i++).setCellValue(flt.driver) + row.createCell(i++).setCellValue(flt.mileage) + } + saveExcelFileLocally("Fleets.xls", wb) +} + +fun exportReminderLogs(logs: List) { + val wb = HSSFWorkbook() + val sh = wb.createSheet() + + val headers: List = listOf("Type", "Amount", "Frequency", "Reminder Date", "Acted Upon", "Vehicle") + createHeaderRow(headers, sh, wb) + + var rowCnt = 1 + + for (log in logs) { + val row = sh.createRow(rowCnt++) + var i = 0 + row.createCell(i++).setCellValue(log.reminderType) + row.createCell(i++).setCellValue(log.amount) + row.createCell(i++).setCellValue(log.reminder?.frequency.toString()) + row.createCell(i++).setCellValue(log.reminderDate) + row.createCell(i++).setCellValue(log.actedUpon) + row.createCell(i++).setCellValue(log.reminder?.fleet?.regNumber) + } + saveExcelFileLocally("ReminderLogs.xls", wb) +} + fun main() { //ImportFromExcel(FileType.QUOTES, "C:\\Users\\arsalan\\Downloads\\Book.xlsx") TemplateExcelFile(FileType.PRODS) diff --git a/src/main/kotlin/com/restapi/controllers/Filters.kt b/src/main/kotlin/com/restapi/controllers/Filters.kt index 6ba893a..d340e03 100644 --- a/src/main/kotlin/com/restapi/controllers/Filters.kt +++ b/src/main/kotlin/com/restapi/controllers/Filters.kt @@ -97,10 +97,17 @@ data class PaymentFilters( val amountLessThan: Double = Double.MAX_VALUE ) : CustomFilters + + data class FleetFilters( val fleetNameLike: String = IGNORE ):CustomFilters +data class ReminderLogFilters( + val reminderType: String = IGNORE, + val actedUpon: Boolean? = null, + val fleetId: Long? = null +) fun applyVendorHelper(q: io.ebean.ExpressionList, vids: List?) { if (vids.isNullOrEmpty()) return // q.apply { @@ -275,16 +282,29 @@ fun searchFleets(filters: CommonFilters, fleetFilters: FleetFilters) : List= ? and insurance_renewal_date <= ?)" + - "or (pollution_renewal_date >= ? and pollution_renewal_date <= ?)" + - "or (fitness_renewal_date >= ? and fitness_renewal_date <= ?)", - filters.from, filters.to, filters.from, filters.to, filters.from, filters.to - ) +// q.raw("(insurance_renewal_date >= ? and insurance_renewal_date <= ?)" + +// "or (pollution_renewal_date >= ? and pollution_renewal_date <= ?)" + +// "or (fitness_renewal_date >= ? and fitness_renewal_date <= ?)", +// filters.from, filters.to, filters.from, filters.to, filters.from, filters.to +// ) // applyFromToHelper(q, filters.from, filters.to, "insuranceRenewalDate") // applyFromToHelper(q, filters.from, filters.to, "pollutionRenewalDate") // applyFromToHelper(q, filters.from, filters.to, "fitnessRenewalDate") return q.findList() } +fun searchReminderLogs(filters: CommonFilters, reminderLogFilters: ReminderLogFilters) : List { + val q = database.find(ReminderLog::class.java) + .where() + .ilike("reminder_type", reminderLogFilters.reminderType) + if(reminderLogFilters.actedUpon != null){ + q.eq("acted_upon", reminderLogFilters.actedUpon) + } + if(reminderLogFilters.fleetId != null){ + q.eq("fleet_sys_pk", reminderLogFilters.fleetId) + } + return q.findList() +} + +//if date is null then fromtoheper drops that/// -//if date is null then fromtoheper drops that/// \ No newline at end of file diff --git a/src/main/kotlin/com/restapi/domain/models.kt b/src/main/kotlin/com/restapi/domain/models.kt index 9121804..dde69e4 100644 --- a/src/main/kotlin/com/restapi/domain/models.kt +++ b/src/main/kotlin/com/restapi/domain/models.kt @@ -521,7 +521,8 @@ open class Payment : BaseTenantModel() { } -data class FleetRenewal(val renewal : String, val date : LocalDate) +data class FR(val renewal: String, val date: LocalDate) + @Entity open class Fleet : BaseTenantModel() { fun patchValues(updated: Fleet) { @@ -538,11 +539,13 @@ open class Fleet : BaseTenantModel() { this.pollutionRenewalDate = updated.pollutionRenewalDate this.fitnessRenewalDate = updated.fitnessRenewalDate this.renewals = updated.renewals + this.regDate = updated.regDate } var name: String = "" var type: String = "" var regNumber: String = "" + var regDate: LocalDate?=null var model: String = "" var make: String = "" var driver: String = "" @@ -552,8 +555,9 @@ open class Fleet : BaseTenantModel() { var insuranceRenewalDate: LocalDate? = null var pollutionRenewalDate: LocalDate? = null var fitnessRenewalDate: LocalDate? = null + @DbJsonB - var renewals: List?=null + var renewals: List? = null } @Entity @@ -583,4 +587,52 @@ open class Renewal : BaseTenantModel() { } var name: String = "" +} + +@Entity +open class Reminder : BaseTenantModel() { + fun patchValues(updated: Reminder) { + this.type = updated.type + this.nextRenewalDate = updated.nextRenewalDate + this.lastRenewalDate = updated.lastRenewalDate + this.frequency = updated.frequency + this.documents = updated.documents + } + + var type: String = "Other" + var nextRenewalDate: LocalDate? = null + var lastRenewalDate: LocalDate? = null + var amount: Double = 0.0 + var frequency: Int = 1 + + @DbArray + var documents: List? = arrayListOf() + + @ManyToOne + var fleet: Fleet? = null +} + +@Entity +open class ReminderLog : BaseTenantModel() { + fun patchValues(updated: ReminderLog) { + this.fleet = updated.fleet + this.reminderDate = updated.reminderDate + this.reminderType = updated.reminderType + this.actedUpon = updated.actedUpon + this.documents = updated.documents + this.amount = updated.amount + } + + @ManyToOne + var reminder: Reminder? = null + var reminderType: String = "Other" + var reminderDate: LocalDate? = null + + @ManyToOne + var fleet: Fleet? = null + var actedUpon: Boolean = false + var amount: Double = 0.0 + + @DbArray + var documents: List? = null } \ No newline at end of file diff --git a/src/main/resources/dbmigration/1.16.sql b/src/main/resources/dbmigration/1.16.sql new file mode 100644 index 0000000..3f5008e --- /dev/null +++ b/src/main/resources/dbmigration/1.16.sql @@ -0,0 +1,67 @@ +-- apply changes +create table fleet_type ( + 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, + 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, + name varchar(255) not null, + person_incharge varchar(255) not null, + created_by varchar(255) not null, + modified_by varchar(255) not null, + constraint ck_fleet_type_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')), + constraint pk_fleet_type primary key (sys_pk) +); + +create table renewal ( + 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, + 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, + name varchar(255) not null, + created_by varchar(255) not null, + modified_by varchar(255) not null, + constraint ck_renewal_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')), + constraint pk_renewal primary key (sys_pk) +); + +create table vehicle ( + 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, + 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, + name varchar(255) not null, + created_by varchar(255) not null, + modified_by varchar(255) not null, + constraint ck_vehicle_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')), + constraint pk_vehicle primary key (sys_pk) +); + +-- apply alter tables +alter table fleet add column if not exists renewals jsonb; diff --git a/src/main/resources/dbmigration/1.17.sql b/src/main/resources/dbmigration/1.17.sql new file mode 100644 index 0000000..cb735df --- /dev/null +++ b/src/main/resources/dbmigration/1.17.sql @@ -0,0 +1,30 @@ +-- apply changes +create table fleet_renewal ( + 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, + last_date date, + frequency integer not null, + fleet_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, + name varchar(255) not null, + created_by varchar(255) not null, + modified_by varchar(255) not null, + constraint ck_fleet_renewal_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')), + constraint pk_fleet_renewal primary key (sys_pk) +); + +-- foreign keys and indices +create index ix_fleet_renewal_fleet_sys_pk on fleet_renewal (fleet_sys_pk); +alter table fleet_renewal add constraint fk_fleet_renewal_fleet_sys_pk foreign key (fleet_sys_pk) references fleet (sys_pk) on delete restrict on update restrict; + diff --git a/src/main/resources/dbmigration/1.18.sql b/src/main/resources/dbmigration/1.18.sql new file mode 100644 index 0000000..d1bdf29 --- /dev/null +++ b/src/main/resources/dbmigration/1.18.sql @@ -0,0 +1,2 @@ +-- apply alter tables +alter table fleet_renewal add column if not exists documents varchar[]; diff --git a/src/main/resources/dbmigration/1.19.sql b/src/main/resources/dbmigration/1.19.sql new file mode 100644 index 0000000..c99a3ac --- /dev/null +++ b/src/main/resources/dbmigration/1.19.sql @@ -0,0 +1,62 @@ +-- drop dependencies +alter table if exists fleet_renewal drop constraint if exists fk_fleet_renewal_fleet_sys_pk; +-- apply changes +create table reminder ( + 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, + next_renewal_date date, + last_renewal_date date, + amount float not null, + frequency integer not null, + fleet_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, + type varchar(255) not null, + documents varchar[], + created_by varchar(255) not null, + modified_by varchar(255) not null, + constraint ck_reminder_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')), + constraint pk_reminder primary key (sys_pk) +); + +create table reminder_log ( + 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, + reminder_date date, + fleet_sys_pk bigint, + acted_upon boolean default false not null, + amount float not null, + 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, + reminder_type varchar(255) not null, + created_by varchar(255) not null, + modified_by varchar(255) not null, + constraint ck_reminder_log_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')), + constraint pk_reminder_log primary key (sys_pk) +); + +-- foreign keys and indices +create index ix_reminder_fleet_sys_pk on reminder (fleet_sys_pk); +alter table reminder add constraint fk_reminder_fleet_sys_pk foreign key (fleet_sys_pk) references fleet (sys_pk) on delete restrict on update restrict; + +create index ix_reminder_log_fleet_sys_pk on reminder_log (fleet_sys_pk); +alter table reminder_log add constraint fk_reminder_log_fleet_sys_pk foreign key (fleet_sys_pk) references fleet (sys_pk) on delete restrict on update restrict; + diff --git a/src/main/resources/dbmigration/1.20.sql b/src/main/resources/dbmigration/1.20.sql new file mode 100644 index 0000000..4fc97d9 --- /dev/null +++ b/src/main/resources/dbmigration/1.20.sql @@ -0,0 +1,2 @@ +-- apply alter tables +alter table reminder_log add column if not exists documents varchar[]; diff --git a/src/main/resources/dbmigration/1.21.sql b/src/main/resources/dbmigration/1.21.sql new file mode 100644 index 0000000..8e937a7 --- /dev/null +++ b/src/main/resources/dbmigration/1.21.sql @@ -0,0 +1,6 @@ +-- apply alter tables +alter table reminder_log add column if not exists reminder_sys_pk bigint; +-- foreign keys and indices +create index ix_reminder_log_reminder_sys_pk on reminder_log (reminder_sys_pk); +alter table reminder_log add constraint fk_reminder_log_reminder_sys_pk foreign key (reminder_sys_pk) references reminder (sys_pk) on delete restrict on update restrict; + diff --git a/src/main/resources/dbmigration/1.22.sql b/src/main/resources/dbmigration/1.22.sql new file mode 100644 index 0000000..a15d661 --- /dev/null +++ b/src/main/resources/dbmigration/1.22.sql @@ -0,0 +1,2 @@ +-- apply alter tables +alter table fleet add column if not exists reg_date date; diff --git a/src/main/resources/dbmigration/model/1.16.model.xml b/src/main/resources/dbmigration/model/1.16.model.xml new file mode 100644 index 0000000..4aedf15 --- /dev/null +++ b/src/main/resources/dbmigration/model/1.16.model.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/dbmigration/model/1.17.model.xml b/src/main/resources/dbmigration/model/1.17.model.xml new file mode 100644 index 0000000..7abd315 --- /dev/null +++ b/src/main/resources/dbmigration/model/1.17.model.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/dbmigration/model/1.18.model.xml b/src/main/resources/dbmigration/model/1.18.model.xml new file mode 100644 index 0000000..b1cf368 --- /dev/null +++ b/src/main/resources/dbmigration/model/1.18.model.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/dbmigration/model/1.19.model.xml b/src/main/resources/dbmigration/model/1.19.model.xml new file mode 100644 index 0000000..6402e0f --- /dev/null +++ b/src/main/resources/dbmigration/model/1.19.model.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/dbmigration/model/1.20.model.xml b/src/main/resources/dbmigration/model/1.20.model.xml new file mode 100644 index 0000000..ee8793f --- /dev/null +++ b/src/main/resources/dbmigration/model/1.20.model.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/dbmigration/model/1.21.model.xml b/src/main/resources/dbmigration/model/1.21.model.xml new file mode 100644 index 0000000..caa874c --- /dev/null +++ b/src/main/resources/dbmigration/model/1.21.model.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/dbmigration/model/1.22.model.xml b/src/main/resources/dbmigration/model/1.22.model.xml new file mode 100644 index 0000000..305c38c --- /dev/null +++ b/src/main/resources/dbmigration/model/1.22.model.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file