Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def departureReportExcel(def params){
- UserLoginData userLoginData = UserLoginData.current
- Long fdPropertyId = UserLoginData.getItem("fdPropertyId")?.toString()?.toLong()
- String startDateFilter = params.startDateFilter
- String endDateFilter = params.endDateFilter
- Date startDate = Date.parse("dd/MM/yyyy", startDateFilter)
- Date endDate = Date.parse("dd/MM/yyyy", endDateFilter)
- List<Reservation> reservationList = Reservation.createCriteria().list{
- fdUnit{
- fdProperty{
- eq("id", fdPropertyId)
- }
- }
- eq("companyId", userLoginData.company_id)
- isNotNull("checkOut")
- gte("checkOut", startDate.clearTime())
- lt("checkOut", (endDate + 1).clearTime())
- order("checkOut", "asc")
- ne("canceled", true)
- }
- FdProperty fdProperty = FdProperty.findById(fdPropertyId)
- List<FdUnit> fdUnitList = FdUnit.findAllByFdPropertyAndIsActive(fdProperty, true)
- def serviceTypeList = OfferedService.serviceTypeList
- serviceTypeList.remove(1)
- def reservationGuestList = ReservationGuest.findAllByReservationInList(reservationList)
- def reservationPaymentList = ReservationPayment.findAllByReservationInList(reservationList)
- def reservationPaymentGuestList = ReservationPayment.findAllByReservationGuestInList(reservationGuestList)
- String outputFilePath = "/var/www/front_desk/zipFiles/"
- File outputFileDir = new File(outputFilePath)
- if(!outputFileDir.exists()){
- outputFileDir.mkdirs()
- }
- String cmd = "chmod 777 -R " + outputFilePath
- cmd.execute()
- String fileName = "${fdProperty.name}_${startDate?.format("ddMMyyyy") ?: "noStartDate"}_${endDate?.format("ddMMyyyy") ?: "noEndDate"}_departures.xls"
- Workbook oldWB = Workbook.getWorkbook(new File("/var/www/front_desk/manas_apartmants_template.xls"))
- File excelFile = new File(outputFilePath + fileName)
- WritableWorkbook outputWorkbook = Workbook.createWorkbook(excelFile, oldWB)
- WritableSheet outputSheet = outputWorkbook.getSheet(0)
- outputSheet.setName("Departures")
- outputSheet.getSettings().setVerticalFreeze(1)
- Cell readCell = outputSheet.getCell(0, 0)
- CellFormat nameCellFormat = readCell.getCellFormat()
- WritableCellFormat numberFormat = new WritableCellFormat (NumberFormats.FLOAT)
- numberFormat.setVerticalAlignment(jxl.format.VerticalAlignment.getAlignment(1))
- WritableCellFormat modifiedCellFormat = ExcelCell.getWritableCellFormat(nameCellFormat, null, null, 10, false, -1, 1)
- WritableCellFormat headingNumberCellFormat = ExcelCell.getWritableCellFormat(nameCellFormat, null, null, 10, true, -1, 1)
- headingNumberCellFormat.setAlignment(Alignment.RIGHT)
- WritableCellFormat headingCellFormat = ExcelCell.getWritableCellFormat(nameCellFormat, null, null, 10, true, -1, 1)
- WritableCellFormat dayCellFormat = ExcelCell.getWritableCellFormat(nameCellFormat, null, null, 10, true, 2)
- WritableCellFormat resGuestCellFormat = ExcelCell.getWritableCellFormat(nameCellFormat, Colour.VERY_LIGHT_YELLOW, null, 10, false, -1, 1)
- resGuestCellFormat.setBorder(Border.ALL, BorderLineStyle.THIN)
- WritableCellFormat yellowNumberFormat = new WritableCellFormat (NumberFormats.FLOAT)
- yellowNumberFormat.setVerticalAlignment(jxl.format.VerticalAlignment.getAlignment(1))
- yellowNumberFormat.setBackground(Colour.VERY_LIGHT_YELLOW, Pattern.SOLID)
- yellowNumberFormat.setBorder(Border.ALL, BorderLineStyle.THIN)
- println("DEPARTURE*****************")
- println(new Date())
- outputSheet.setColumnView(0, 10)
- ExcelCell.cellModifications(outputSheet, 0, 0, "Unit", headingCellFormat, "string")
- outputSheet.setColumnView(1, 25)
- ExcelCell.cellModifications(outputSheet, 1, 0, "Full name", headingCellFormat, "string")
- outputSheet.setColumnView(2, 10)
- ExcelCell.cellModifications(outputSheet, 2, 0, "Total", headingNumberCellFormat, "string")
- int i=3
- for(serviceType in serviceTypeList){
- outputSheet.setColumnView(i, 20)
- ExcelCell.cellModifications(outputSheet, i, 0, serviceType.name, headingNumberCellFormat, "string")
- i++
- }
- outputSheet.setColumnView(i, 15)
- ExcelCell.cellModifications(outputSheet, i++, 0, "Arrival", headingCellFormat, "string")
- outputSheet.setColumnView(i, 17)
- ExcelCell.cellModifications(outputSheet, i++, 0, "Reservation number", headingCellFormat, "string")
- outputSheet.setColumnView(i, 15)
- ExcelCell.cellModifications(outputSheet, i++, 0, "Reservation status", headingCellFormat, "string")
- outputSheet.setColumnView(i, 15)
- ExcelCell.cellModifications(outputSheet, i, 0, "Payment status", headingCellFormat, "string")
- int currentRow = 1
- for(Date d = startDate; d <= endDate; d++) {
- List<Reservation> resList = reservationList.findAll{it.checkOut.format("dd/MM/yyyy") == d.format("dd/MM/yyyy")}
- ExcelCell.cellModifications(outputSheet, 0, currentRow, "Departure list on ${d}", dayCellFormat, "string")
- outputSheet.mergeCells(0, currentRow, 9, currentRow)
- currentRow++
- for(res in resList) {
- outputSheet.setRowView(currentRow, 1200)
- double totalPayment = res?.totalPayment?.round(2) ?: 0.00
- def currentStatus = res.currentStatus
- def paymentStatus = res.paymentStatus
- def rgList = reservationGuestList.findAll{it.reservationId == res.id}
- List<ReservationPayment> rpList = reservationPaymentList.findAll{it.reservationId == res.id}
- String unitName = fdUnitList.find({ it -> it.id == res?.fdUnit.id }).name
- ExcelCell.cellModifications(outputSheet, 0, currentRow, "${unitName}", modifiedCellFormat, "string")
- ExcelCell.cellModifications(outputSheet, 1, currentRow, "${res.displayTitle ?: res.accountDisplayTitle ?: res.contactDisplayTitle ?: 'No contact'}", modifiedCellFormat, "string")
- ExcelCell.cellModifications(outputSheet, 2, currentRow, "${totalPayment?:0.00}", numberFormat, "number")
- int j=3
- for(serviceType in serviceTypeList){
- List<ReservationPayment> currentRpList = rpList.findAll{it.offeredService.serviceType == serviceType.id}
- if(currentRpList) {
- ExcelCell.cellModifications(outputSheet, j, currentRow, "${currentRpList.sum{it.netPrice.round(2)?: 0.00}}", numberFormat, "number")
- }
- else {
- ExcelCell.cellModifications(outputSheet, j, currentRow, "${0.00}", numberFormat, "number")
- }
- j++
- }
- ExcelCell.cellModifications(outputSheet, j++, currentRow, "${res.checkIn.format("yyyy-MM-dd")}", modifiedCellFormat, "string")
- ExcelCell.cellModifications(outputSheet, j++, currentRow, "${res.id}", modifiedCellFormat, "string")
- ExcelCell.cellModifications(outputSheet, j++, currentRow, "${currentStatus.name}", modifiedCellFormat, "string")
- ExcelCell.cellModifications(outputSheet, j, currentRow, "${paymentStatus.name}", modifiedCellFormat, "string")
- currentRow++
- if(rgList.size() >= 1) {
- for (resG in rgList) {
- def currentStatusGuest = resG.currentStatus
- def paymentStatusGuest = resG.paymentStatus
- List<ReservationPayment> rpListGuest = reservationPaymentGuestList.findAll{it.reservationGuestId == resG.id}
- ExcelCell.cellModifications(outputSheet, 0, currentRow, "${unitName} - ${resG.id}", resGuestCellFormat, "string")
- ExcelCell.cellModifications(outputSheet, 1, currentRow, "${resG.title}", resGuestCellFormat, "string")
- ExcelCell.cellModifications(outputSheet, 2, currentRow, "${rpListGuest ? rpListGuest.sum{it.netPrice ?: 0.00} : 0.00}", yellowNumberFormat, "number")
- int k=3
- for(serviceType in serviceTypeList){
- List<ReservationPayment> currentRpListGuest = rpListGuest.findAll{it.offeredService.serviceType == serviceType.id}
- if(currentRpListGuest) {
- ExcelCell.cellModifications(outputSheet, k, currentRow, "${currentRpListGuest.sum{it.netPrice.round(2)?: 0.00}}", yellowNumberFormat, "number")
- }
- else {
- ExcelCell.cellModifications(outputSheet, k, currentRow, "${0.00}", yellowNumberFormat, "number")
- }
- k++
- }
- ExcelCell.cellModifications(outputSheet, k++, currentRow, "${resG.checkIn.format("yyyy-MM-dd")}", resGuestCellFormat, "string")
- ExcelCell.cellModifications(outputSheet, k++, currentRow, "${res.id}", resGuestCellFormat, "string")
- ExcelCell.cellModifications(outputSheet, k++, currentRow, "${currentStatusGuest.name}", resGuestCellFormat, "string")
- ExcelCell.cellModifications(outputSheet, k, currentRow, "${paymentStatusGuest.name}", resGuestCellFormat, "string")
- currentRow++
- }
- }
- }
- }
- outputWorkbook.write()
- outputWorkbook.close()
- println(new Date())
- return [status: 0, message: "Exporting successful!", fileName: fileName, outputFilePath: outputFilePath]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement