· 5 years ago · Mar 09, 2020, 12:26 PM
1public String createERegistrationPDF(int checkinId, String url) throws Exception {
2 try {
3 MyCheckIn checkIn = guestDocumentsDao.getGuestDocumentById(checkinId);
4 List<MyCheckIn> myCheckInList = new ArrayList<>();
5 myCheckInList.add(checkIn);
6 Document pdf = new Document();
7 // StringBuffer pdf = new StringBuffer();
8 // byte[] pdfByte = null;
9 String path = "";
10
11 PdfWriter writer = null;
12 pdf.setPageSize(PageSize.A4);
13
14 Image image1;
15 document_name = "Reports.pdf";
16 //
17 String detailConfirmationNumber;
18 String detailHotelCode = "";
19 String detailHotelName = "";
20 String selectedHotel = "";
21 int detailId;
22 String detailArrivalDate = "";
23 String detailDepartureDate = "";
24 String detailDepartureTime = "";
25 String detailDailyRate = "";
26 String detailRoomType = "";
27 String detailCurrency = "";
28 String detailTotalCharge = "";
29 String detailNOfGuest = "";
30 String detailFirstName = "";
31 String detailLastName = "";
32 String detailCountry = "";
33 String detailCity = "";
34 String detailLanguage = "";
35 String detailTel = "";
36 String detailEmail = "";
37 String detailNationality = "";
38 String detailDateOfBirth = "";
39 String detailMethodOfPayment = "";
40 String detailSignature = " ";
41 String detailPreference = "";
42 String billingInstructions = "";
43 String companyName = "";
44 String passportNumber = "";
45 String additionalFees = null;
46 String signatureFee = "";
47 String comments = "";
48 String detailNightlyRate = "";
49 String hotelConfIdentification = "";
50 String hotelConfCheckinTime = "";
51 String hotelConfCheckoutTime = "";
52 String roomNumber;
53 if (myCheckInList.size() == 1) {
54 MyCheckIn mycheckIn = myCheckInList.get(0);
55 detailHotelCode = mycheckIn.getKioskHotelCode();
56 detailConfirmationNumber = mycheckIn.getConfirmationNumber();
57 detailId = mycheckIn.getId();
58
59 document_name = "Report_" + detailHotelCode + "_" + detailConfirmationNumber + "" + "_" + detailId + ".pdf";
60
61 }
62 if (myCheckInList.size() > 0) {
63 try {
64 writer = PdfWriter.getInstance(pdf,
65 new FileOutputStream(pathSignature + "/guest_docs/kiosk_signature/" + document_name));
66 } catch (FileNotFoundException e1) {
67 System.out.println("problem when write pdf " + e1);
68 } catch (DocumentException e1) {
69 System.out.println("problem DocumentException" + e1);
70 }
71 pdf.open();
72 for (int indexL = 0; indexL < myCheckInList.size(); indexL++)
73 {
74 MyCheckIn myCheckin = myCheckInList.get(indexL);
75 detailConfirmationNumber = myCheckin.getConfirmationNumber();
76 detailLastName = myCheckin.getLastName();
77 detailFirstName = myCheckin.getFirstName();
78 if(myCheckin.getArrivalDate() != null) detailArrivalDate = myCheckin.getArrivalDate().toString();
79 if(myCheckin.getDepartureDate() != null) detailDepartureDate = myCheckin.getDepartureDate().toString();
80 if(myCheckin.getDepartureTime() != null) detailDepartureTime = myCheckin.getDepartureTime().toString();
81
82 if (myCheckin.getDailyRate() != null) {
83 BigDecimal dailyRate = myCheckin.getDailyRate();
84 detailDailyRate = dailyRate.toString();
85 }
86 detailId = myCheckin.getId();
87 detailRoomType = myCheckin.getRoomType();
88 detailCurrency = myCheckin.getCurrency();
89
90 if (myCheckin.getRateTotal() != null) {
91 BigDecimal totalRoomCharges = myCheckin.getRateTotal();
92 detailTotalCharge = totalRoomCharges.toString();
93 }
94 if (myCheckin.getNumberOfGuests() != null) {
95 Integer numberOfGuests = myCheckin.getNumberOfGuests();
96 detailNOfGuest = numberOfGuests.toString();
97 }
98 detailCountry = getCountryString(myCheckin.getCountry());
99
100 detailCity = myCheckin.getCity();
101 detailLanguage = myCheckin.getLanguage();
102 detailTel = myCheckin.getPhone();
103 detailEmail = myCheckin.getEmail();
104 //
105 if (myCheckin.getNationality() != null) {
106 detailNationality = getNationalityString(myCheckin.getNationality());
107 }
108 if(myCheckin.getBirthdate() != null) detailDateOfBirth = myCheckin.getBirthdate().toString();
109 // detailRotanaRewards = myCheckin.getRotanaRewards();
110 // detailFrequentFlyer = myCheckin.getFrequentFlyer();
111 // detailMethodOfPayment = myCheckin.getMethodOfPayment();
112 if (myCheckin.getMethodOfPayment() != null) {
113 detailMethodOfPayment = getMethodOfPaymentString(myCheckin.getMethodOfPayment());
114 }
115 detailSignature = myCheckin.getImageName();
116 detailPreference = myCheckin.getPreference();
117 detailHotelCode = myCheckin.getKioskHotelCode();
118 // SystemDefHotel hotel = hotelDao.findHotelByCode(detailHotelCode);
119 List<SystemDefHotel> hotelList = hotelDao.findHotelByKioskCode(detailHotelCode);
120 SystemDefHotel hotel = null;
121 if(hotelList.size() > 0) hotel = hotelList.get(0);
122 if(hotel != null)
123 {
124 detailHotelName = hotel.getHotelName();
125 selectedHotel = hotel.getHotelName();
126 }
127 billingInstructions = myCheckin.getBillingInstructions();
128 companyName = myCheckin.getCompanyName();
129 passportNumber = myCheckin.getPassportNumber();
130 comments = myCheckin.getComments();
131 additionalFees = myCheckin.getAdditionalFees();
132 signatureFee = myCheckin.getSignatureAddFees();
133 if(myCheckin.getDailyRate() != null) detailNightlyRate = myCheckin.getDailyRate().toString();
134 // hotelConfIdentification = myCheckin.getHotelConfIdentification();
135 // hotelConfCheckinTime = myCheckin.getHotelConfCheckinTime();
136 // hotelConfCheckoutTime = myCheckin.getHotelConfCheckoutTime();
137 roomNumber = myCheckin.getRoomNumber();
138 String printRate = myCheckin.getPrintRate();
139 try {
140 // logo
141
142 File f = new File(pathSignature + "/guest_docs/hotel_logos/" + selectedHotel + ".jpg");
143 //f.setReadable(true);
144 //f.setExecutable(true);
145 //f.setWritable(true);
146 if (f.exists() && !f.isDirectory()) {
147 image1 = Image.getInstance(pathSignature + "/guest_docs/hotel_logos/" + selectedHotel + ".jpg");
148 } else {
149 image1 = Image.getInstance(pathSignature + "/guest_docs/hotel_logos/logo.png");
150 }
151 image1.scalePercent(70f);
152 image1.setAbsolutePosition(400f, 750f);
153 pdf.add(image1);
154 pdf.add(new Paragraph("\n"));
155 // ************* create Title E-registration Card font
156 // ***********
157
158 Font TitleFont = FontFactory.getFont("minerva_modern.ttf");
159
160 BaseFont TitlebaseFont = TitleFont.getBaseFont();
161 Paragraph paraRight = new Paragraph();
162 paraRight.setAlignment(Element.ALIGN_LEFT);
163 paraRight.setFont(new Font(TitlebaseFont, 18, Font.NORMAL, new Color(46, 117, 182)));
164 paraRight.add("e-Registration Card");
165 Paragraph space = new Paragraph();
166 space.add("\n");
167 pdf.add(paraRight);
168 pdf.add(space);
169 paraRight = new Paragraph();
170 paraRight.setFont(new Font(TitlebaseFont, 12, Font.NORMAL, new Color(46, 117, 182)));
171 paraRight.add(selectedHotel);
172 pdf.add(paraRight);
173 pdf.add(space);
174 Font headingFont = FontFactory.getFont("CALIBRIL.TTF", 11);
175 Font calibriFont = FontFactory.getFont("CALIBRI.TTF", 12);
176 // ******** Adding WhitefFont For User ID *********
177 Font whiteFont = FontFactory.getFont("minerva_modern.ttf", 11);
178 // ************** Creating Values Font***************
179 Font valuesFont = FontFactory.getFont("CALIBRI.TTF", 11);
180 whiteFont.setColor(Color.white);
181 PdfPTable table = new PdfPTable(4);
182 float[] columnWidths = { 240f, 300f, 260f, 290f };
183 table.setWidths(columnWidths);
184
185 table.setHorizontalAlignment(Element.ALIGN_LEFT);
186 table.setWidthPercentage(100);
187 PdfPCell headingcell = new PdfPCell(new Paragraph(detailConfirmationNumber, whiteFont));
188 headingcell.setBorder(PdfCell.NO_BORDER);
189 headingcell.setHorizontalAlignment(Element.ALIGN_CENTER);
190 headingcell.setBackgroundColor(new Color(46, 117, 182));
191 headingcell.setMinimumHeight(20f);
192 table.addCell(headingcell);
193 final String upperCaseDetailName = detailLastName != null
194 ? detailLastName.substring(0, 1).toUpperCase()
195 : "";
196 final String lowerCaseDetailName = detailLastName != null
197 ? detailLastName.substring(1).toLowerCase()
198 : "";
199 final String upperCaseFirstName = detailFirstName != null
200 ? detailFirstName.substring(0, 1).toUpperCase()
201 : "";
202 final String lowerCaseFirstName = detailFirstName != null
203 ? detailFirstName.substring(1).toLowerCase()
204 : "";
205 headingcell = new PdfPCell(new Paragraph(
206 upperCaseDetailName + lowerCaseDetailName + ", " + upperCaseFirstName + lowerCaseFirstName,
207 headingFont));
208 headingcell.setBorder(PdfCell.NO_BORDER);
209 headingcell.setMinimumHeight(20f);
210 headingcell.setBackgroundColor(new Color(214, 220, 228));
211 table.addCell(headingcell);
212 PdfPCell emptyCell = new PdfPCell(new Paragraph());
213 emptyCell.setColspan(2);
214 emptyCell.setBorder(PdfCell.NO_BORDER);
215 table.addCell(emptyCell);
216 Color greyBackgroundColor = new Color(216, 216, 216);
217 headingcell = new PdfPCell(new Paragraph("Company Name", calibriFont));
218 headingcell.setMinimumHeight(20f);
219 headingcell.setBackgroundColor(greyBackgroundColor);
220 headingcell.setBorder(PdfCell.NO_BORDER);
221 table.addCell(headingcell);
222 headingcell = new PdfPCell(new Paragraph(companyName, headingFont));
223 headingcell.setColspan(1);
224 headingcell.setBorderColor(greyBackgroundColor);
225 table.addCell(headingcell);
226 headingcell = new PdfPCell(new Paragraph("Passport Num:", calibriFont));
227 headingcell.setMinimumHeight(20f);
228 headingcell.setBackgroundColor(greyBackgroundColor);
229 headingcell.setBorder(PdfCell.NO_BORDER);
230 table.addCell(headingcell);
231 headingcell = new PdfPCell(new Paragraph(passportNumber, headingFont));
232 headingcell.setColspan(1);
233 headingcell.setBorderColor(greyBackgroundColor);
234 table.addCell(headingcell);
235 // emptyCell.setColspan(1);
236 // table.addCell(emptyCell);
237
238 // SimpleDateFormat formatDate = new SimpleDateFormat("dd-MM-yyyy");
239 // Date arrivalDate = formatDate.parse(detailArrivalDate);
240 // Date departureDate = formatDate.parse(detailDepartureDate);
241 // final long DAY_IN_MILLIS = 1000 * 60 * 60 * 24;
242 // int detailRoomNights = (int) ((departureDate.getTime() - arrivalDate.getTime()) / DAY_IN_MILLIS);
243
244 ArrayList<SimpleDateFormat> parserList = new ArrayList<SimpleDateFormat>();
245 parserList.add(new SimpleDateFormat("dd-MMM-yy"));
246 parserList.add(new SimpleDateFormat("MM/dd/yyyy"));
247 parserList.add(new SimpleDateFormat("MM-dd-yyyy"));
248
249 SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
250
251 DateFormatter dateFormatter = new DateFormatter(parserList, formatter);
252
253 String nonFormattedCheckinDate = detailArrivalDate;
254 String nonFormattedCheckoutDate = detailDepartureDate;
255
256 String formattedCheckinDate = "",
257 formattedCheckoutDate = "";
258
259 //Check for yyyy-MM-dd Format for Check-In Date
260 if(nonFormattedCheckinDate.matches("(([0-9]{4})-(0[0-9]|1[012])-([012][0-9]|[3][01]))")) {
261 try {
262 SimpleDateFormat exceptionParser = new SimpleDateFormat("yyyy-MM-dd");
263 Date formattedDate = exceptionParser.parse(nonFormattedCheckinDate);
264 formattedCheckinDate = formatter.format(formattedDate);
265 System.out.println("[INFO] " + nonFormattedCheckinDate + " \t-->\t" + formattedCheckinDate + "\tUsing [yyyy-MM-dd] Format.");
266 } catch (ParseException e) {
267 System.out.println("[ERROR] Unexpected Error Using [yyyy-MM-dd] Format.");
268 }
269
270 } else {
271 formattedCheckinDate = dateFormatter.getUnifiedFormat(nonFormattedCheckinDate);
272 }
273
274 //Check for yyyy-MM-dd Format for Check-Out Date
275 if(nonFormattedCheckoutDate.matches("(([0-9]{4})-(0[0-9]|1[012])-([012][0-9]|[3][01]))")) {
276 try {
277 SimpleDateFormat exceptionParser = new SimpleDateFormat("yyyy-MM-dd");
278 Date formattedDate = exceptionParser.parse(nonFormattedCheckoutDate);
279 formattedCheckoutDate = formatter.format(formattedDate);
280 System.out.println("[INFO] " + nonFormattedCheckoutDate + " \t-->\t" + formattedCheckoutDate + "\tUsing [yyyy-MM-dd] Format.");
281 } catch (ParseException e) {
282 System.out.println("[ERROR] Unexpected Error Using [yyyy-MM-dd] Format.");
283 }
284
285 } else {
286 formattedCheckoutDate = dateFormatter.getUnifiedFormat(nonFormattedCheckoutDate);
287 }
288
289 detailArrivalDate = formattedCheckinDate;
290 detailDepartureDate = formattedCheckoutDate;
291
292 int detailRoomNights = 0;
293
294 try {
295 Date date1 = formatter.parse(detailArrivalDate);
296 Date date2 = formatter.parse(detailDepartureDate);
297 long diff = date2.getTime() - date1.getTime();
298 detailRoomNights = (int) TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
299 System.out.println ("Days: " + TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS));
300 } catch (ParseException e) {
301 e.printStackTrace();
302 }
303
304
305 // **** Initializing left headers in listeName1 ***
306
307 ArrayList<String> listeName1 = new ArrayList<String>();
308
309 // ** Initializing right headers in listeName2*******
310
311 ArrayList<String> listeName2 = new ArrayList<String>();
312 listeName1.add("Arrival Date");
313 listeName1.add("Room Type");
314 listeName1.add("Room Number");
315 listeName1.add("Guests");
316 // if (null != printRate && printRate.equalsIgnoreCase("Y"))
317 listeName1.add("Daily Rate");
318 listeName1.add("Country");
319 listeName1.add("Nationality");
320 listeName1.add("Preferences");
321 listeName1.add("Tel");
322
323 listeName2.add("Payment Type");
324 listeName2.add("Departure Date");
325 listeName2.add("Departure Time");
326 listeName2.add("Room Nights");
327 listeName2.add("Total Room Charge");
328 listeName2.add("City");
329 listeName2.add("Language");
330 listeName2.add("Birthday");
331 listeName2.add("Email");
332 // ******* Initializing left Values in listeValue1 *******
333 ArrayList<String> listeValue1 = new ArrayList<String>();
334
335 listeValue1.add(detailArrivalDate);
336 listeValue1.add(detailRoomType);
337
338 if ((roomNumber != null) && (!roomNumber.equals("")))
339 listeValue1.add(roomNumber);
340 else
341 listeValue1.add("");
342 listeValue1.add(detailNOfGuest);
343 if (null != printRate && (printRate.equalsIgnoreCase("Y") || printRate.equalsIgnoreCase(""))) {
344 if (detailDailyRate != null && !detailDailyRate.equals(""))
345 listeValue1.add(detailDailyRate + ((hotel != null)?" " + hotel.getCurrency():""));
346 else
347 listeValue1.add(detailDailyRate);
348 } else
349 listeValue1.add("0.00");
350 listeValue1.add(detailCountry);
351 listeValue1.add(detailNationality);
352 listeValue1.add(detailPreference);
353
354 if (detailTel != null && detailTel.contains("@"))
355 listeValue1.add("");
356 else
357 listeValue1.add(detailTel);
358
359 // ********** Initializing right Values in listeValue2******
360 ArrayList<String> listeValue2 = new ArrayList<String>();
361
362 listeValue2.add(detailMethodOfPayment);
363 listeValue2.add(detailDepartureDate);
364 listeValue2.add(detailDepartureTime);
365 listeValue2.add("" + detailRoomNights);
366 if (null != printRate && (printRate.equalsIgnoreCase("Y") || printRate.equalsIgnoreCase(""))) {
367 if(detailTotalCharge != null && !detailTotalCharge.equals(""))
368 listeValue2.add(detailTotalCharge + ((hotel != null)?" " + hotel.getCurrency():""));
369 else {
370 listeValue2.add(detailDailyRate);
371 }
372 } else
373 listeValue2.add("0.00");
374 listeValue2.add(detailCity);
375 listeValue2.add(detailLanguage);
376 listeValue2.add(detailDateOfBirth);
377 String lowerCaseEmail = detailEmail != null ? detailEmail.toLowerCase() : "";
378 listeValue2.add(lowerCaseEmail);
379
380 for (int i = 0; i < listeName1.size(); i++) {
381
382 String listnameCurr = listeName1.get(i);
383 String listValue1Curr = listeValue1.get(i);
384 if (listnameCurr == null || listValue1Curr == null)
385 System.out.println("listnameCurr" + listnameCurr + " - " + listValue1Curr);
386
387 Paragraph phrase = new Paragraph(listnameCurr, calibriFont);
388 PdfPCell name1 = new PdfPCell(phrase);
389 name1.setMinimumHeight(20f);
390 name1.setBackgroundColor(greyBackgroundColor);
391 name1.setBorderColor(Color.WHITE);
392 PdfPCell value1 = new PdfPCell(new Paragraph(listValue1Curr, headingFont));
393 value1.setBorderColor(greyBackgroundColor);
394 PdfPCell name2 = new PdfPCell(new Paragraph(listeName2.get(i), calibriFont));
395 name2.setBackgroundColor(greyBackgroundColor);
396 name2.setBorderColor(Color.WHITE);
397 PdfPCell value2 = new PdfPCell(new Paragraph(listeValue2.get(i), headingFont));
398 value2.setBorderColor(greyBackgroundColor);
399 table.addCell(name1);
400 table.addCell(value1);
401 table.addCell(name2);
402 table.addCell(value2);
403
404 }
405 // only if exist
406 if (additionalFees != null && !additionalFees.isEmpty()) {
407 PdfPCell FeeCell = new PdfPCell(new Paragraph("Additional Fees", calibriFont));
408 FeeCell.setBorder(PdfCell.NO_BORDER);
409 FeeCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
410 FeeCell.setBackgroundColor(greyBackgroundColor);
411 table.addCell(FeeCell);
412 emptyCell = new PdfPCell(new Paragraph(additionalFees, headingFont));
413 emptyCell.setFixedHeight(36f);
414 emptyCell.setBorderColor(greyBackgroundColor);
415 emptyCell.setColspan(1);
416 table.addCell(emptyCell);
417 headingcell = new PdfPCell(new Paragraph("Signature", calibriFont));
418 headingcell.setMinimumHeight(20f);
419 headingcell.setBackgroundColor(greyBackgroundColor);
420 headingcell.setBorder(PdfCell.NO_BORDER);
421 table.addCell(headingcell);
422
423 // headingcell = new PdfPCell(new Paragraph(signatureFee, headingFont));
424 // headingcell.setColspan(1);
425 // headingcell.setBorderColor(greyBackgroundColor);
426 // table.addCell(headingcell);
427 emptyCell = new PdfPCell(createImageCell(pathSigFee + "/" + signatureFee));
428 // emptyCell.setFixedHeight(50f);
429 // emptyCell.setBorderColor(greyBorderColor);
430 // emptyCell.setBackgroundColor(whiteBackgroundColor);
431 // emptyCell.setColspan(3);
432 // emptyCell.setBorderColorBottom(greenColor);
433 // emptyCell.setBorder(Rectangle.BOTTOM);
434 // emptyCell.setUseBorderPadding(true);
435 // emptyCell.setBorderWidthBottom(3);
436 headingcell.setColspan(1);
437 headingcell.setBorderColor(greyBackgroundColor);
438 table.addCell(emptyCell);
439 }
440 // ****** Adding Billing Instruction Row*************
441 PdfPCell BillingCell = new PdfPCell(new Paragraph("Billing Instructions", calibriFont));
442 BillingCell.setBorder(PdfCell.NO_BORDER);
443 BillingCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
444 BillingCell.setBackgroundColor(greyBackgroundColor);
445 table.addCell(BillingCell);
446 emptyCell = new PdfPCell(new Paragraph(billingInstructions, headingFont));
447 emptyCell.setFixedHeight(36f);
448 emptyCell.setBorderColor(greyBackgroundColor);
449 emptyCell.setColspan(1);
450 table.addCell(emptyCell);
451 headingcell = new PdfPCell(new Paragraph("Comments:", calibriFont));
452 headingcell.setMinimumHeight(20f);
453 headingcell.setBackgroundColor(greyBackgroundColor);
454 headingcell.setBorder(PdfCell.NO_BORDER);
455 table.addCell(headingcell);
456 headingcell = new PdfPCell(new Paragraph(comments, headingFont));
457 headingcell.setColspan(1);
458 headingcell.setBorderColor(greyBackgroundColor);
459 table.addCell(headingcell);
460
461 // **************Adding the table to the Document*********
462 pdf.add(table);
463 // ajout de Terms
464 // ****************Adding the Terms and conditions********
465 // ******** Title Terms and Conditions**********************
466 Paragraph paraTermsTitle = new Paragraph("Terms & Conditions");
467 Font paraTermsTitleFont = FontFactory.getFont("CALIBRIB.TTF", 14);
468 paraTermsTitle.setFont(paraTermsTitleFont);
469 pdf.add(paraTermsTitle);
470 // ******************* Terms and conditions content*********
471 Font paraTermsFont = FontFactory.getFont("CALIBRIL.TTF", 8);
472 Paragraph paraTerms = new Paragraph(12);
473 paraTerms.setSpacingAfter(5);
474 paraTerms.setSpacingBefore(5);
475
476 paraTerms.setAlignment(Element.ALIGN_LEFT);
477 paraTerms.setFont(paraTermsFont);
478
479 OnlineCheckinConfiguration onlineCheckinConfiguration = guestDocumentsDao.getOnlineCheckinConfigurationWithTerms(myCheckin.getKioskHotelCode(),"E");
480 if(onlineCheckinConfiguration!=null){
481 String termCond = onlineCheckinConfiguration.getTermCondition();
482 String checkoutTimeFrom=onlineCheckinConfiguration.getConfCheckinTimeFrom();
483 String checkoutTimeTo= onlineCheckinConfiguration.getConfCheckoutTimeTo();
484 // replace dynamic field by values on termCondition text
485 if(termCond!=null&&!termCond.isEmpty()){
486 //replace double %
487 String doublePourc="%%";
488 if(termCond.contains(doublePourc)){
489 termCond=termCond.replaceAll(doublePourc,"%");
490 }
491 // replace %@ values
492 String dynamicValue="%@";
493 if(termCond.contains(dynamicValue)){
494 int firstOcc = termCond.indexOf(dynamicValue);
495 int lastOcc= termCond.lastIndexOf(dynamicValue);
496 if(firstOcc>=0 &&lastOcc>=0){// exist
497 if(checkoutTimeFrom!=null&&checkoutTimeTo!=null){
498 termCond=termCond.replaceFirst(dynamicValue,checkoutTimeTo);// replace first
499 termCond=termCond.replaceFirst(dynamicValue,checkoutTimeFrom);//replace second
500 }
501 }
502 }
503 }
504 paraTerms.add(StringEscapeUtils.unescapeJava(termCond));
505 }
506 pdf.add(paraTerms);
507 // paraTerms.add("[]The hotel is not responsible for any loss of money or valubles left in the room."
508 // + "\n");
509 // paraTerms.add(
510 // "[]By accepting these terms and conditions you are confirming that all details presented are correct and you agree to be held personally liable to pay the full amount of the charges prior to departure from the hotel. In the event that arrangements have been agreed with the hotel for a person, company, travel agent or another association to pay any of the charges incurred, you agree that your liability for the charges incurred will not be waived and to be held personally liable in the event the amount is not paid in full."
511 // + "\n");
512 // paraTerms.add(
513 // "[]Departure date extensions are subject to hotel availability and changes in rate may be applied. Departure date extensions must be agreed with the hotel in advance."
514 // + "\n");
515 // paraTerms.add("[]Extra bed charges will be applied as per the hotels policy" + "\n");
516 // paraTerms.add("[]Early departure date charges may be applied." + "\n");
517 // pdf.add(paraTerms);
518 // paraTerms = new Paragraph(12);
519 // paraTerms.setSpacingAfter(3);
520 // paraTerms.setFont(paraTermsFont);
521 // paraTerms.add("HOTEL DEPARTURE POLICY" + "\n");
522 //
523 // paraTerms.add("The official hotel departure time is 12 noon." + "\n");
524 // paraTerms.add(
525 // "Late departures can be requested through the Front Desk, subject to hotel availability."
526 // + "\n");
527 // paraTerms.add("Additional charges will apply as follows:" + "\n");
528 // paraTerms.add("Up to 18:00 hrs : 50% of room rate" + "\n");
529 // paraTerms.add("After 18:00 hrs : 100% of room rate" + "\n");
530 // paraTerms.add(
531 // "[]Rotana Rewards Select Members may extend their check-out to 14:00 hrs, subject to availability."
532 // + "\n");
533 // paraTerms.add(
534 // "[]Rotana Rewards Exclusive Members may extend their check-out to 18:00 hrs, conditions apply.");
535 // pdf.add(paraTerms);
536
537 // ***********Add Nightly Rate terms****************
538 detailNightlyRate = onlineCheckinConfiguration.getConfNightlyRate();
539 if ((detailNightlyRate != null) && (!detailNightlyRate.equals(""))) {
540
541 paraTerms = new Paragraph(12);
542 paraTerms.setSpacingAfter(5);
543 paraTerms.setFont(paraTermsFont);
544 // paraTerms.add("[]Room rates are subject to " + detailNightlyRate);
545 paraTerms.add("[]" + detailNightlyRate);
546 pdf.add(paraTerms);
547
548 }
549 // ************* Add Arrival Time Term*************
550 // if (!hotelConfCheckinTime.equals("")) {
551 // paraTerms = new Paragraph(12);
552 // paraTerms.setSpacingAfter(5);
553 // paraTerms.setFont(paraTermsFont);
554 // paraTerms.add("Arrival Time" + "\n");
555 // paraTerms.add("Hotel Check-In time is from
556 // "+hotelConfCheckinTime
557 // );
558 // pdf.add(paraTerms);
559 // }
560 //
561 // ***********Add Departure Time Term********
562 // hotelConfCheckoutTime = onlineCheckinConfiguration.getConfCheckoutTimeTo();
563 // if ((hotelConfCheckoutTime != null) && (!hotelConfCheckoutTime.equals(""))) {
564 //
565 // paraTerms = new Paragraph(10);
566 // paraTerms.setSpacingAfter(3);
567 // paraTerms.setFont(paraTermsFont);
568 // paraTerms.add("Departure Time" + "\n");
569 // paraTerms.add("Hotel Check-Out time is " + hotelConfCheckoutTime);
570 // pdf.add(paraTerms);
571 //
572 // }
573 // **************Add Hotel Arrival policy********
574
575 hotelConfCheckinTime = onlineCheckinConfiguration.getConfCheckinTimeFrom();
576 paraTerms = new Paragraph(12);
577 paraTerms.setSpacingAfter(5);
578 paraTerms.setFont(paraTermsFont);
579 paraTerms.add("HOTEL ARRIVAL POLICY" + "\n");
580 if ((null != hotelConfCheckinTime) && (!hotelConfCheckinTime.equals("")))
581 paraTerms.add("The official hotel check-in time is " + hotelConfCheckinTime + ".");
582 if ((null != hotelConfCheckinTime) && (!hotelConfCheckinTime.equals("")))
583 paraTerms.add("The Online Check-In Desk is only available from " + hotelConfCheckinTime + ".");
584
585 paraTerms.add(
586 "To guarantee an earlier Check-In please book your reservation one night prior."
587 // + " However, Check-In between 09.00 to "
588 // + hotelConfCheckinTime
589 // + " is possible without charge, subject to availability at time of arrival."
590 + "\n");
591
592 // **********Add hotel identification **********
593 hotelConfIdentification = onlineCheckinConfiguration.getConfIdentification();
594 if ((hotelConfIdentification != null) && (!hotelConfIdentification.equals(""))) {
595 paraTerms.add(
596 "[]As per local government requirements all occupants will be required to present a valid "
597 + hotelConfIdentification + " on arrival. \n");
598
599 // }
600 }
601
602 pdf.add(paraTerms);
603
604 // ** Adding WaterMarker
605 // :p****
606 Paragraph paraRight1 = new Paragraph();
607 paraRight1.setAlignment(Element.ALIGN_LEFT);
608 paraRight1.add(new Chunk(" \n \n \n"));
609 // pdf.add(paraRight1);
610
611 Image waterMarker = Image.getInstance(pathSignature + "/guest_docs/hotel_logos/watermark2.png");
612 waterMarker.scalePercent(44f);
613 waterMarker.setAbsolutePosition(40, 50);
614 waterMarker.setAlignment(Element.ALIGN_LEFT);
615 pdf.add(waterMarker);
616 // ******Adding Signature & its
617 // timeStamp(timeSignature)*******
618 if (detailSignature != null && !detailSignature.isEmpty() && !detailSignature.equals(" ")) {
619 // ********** if signature exists ******
620
621 try {
622 // Image imageSignature = Image.getInstance(pathSignature + "/guest_docs/kiosk_signature/" + detailSignature);
623 String middlePath = "/tsl/midd_data/portal/img/kiosk_signature/";
624 String os = System.getProperty("os.name").toLowerCase();
625
626
627 // url = url.replaceFirst("https", "http");
628 String imagePath = myCheckin.getImageName().toLowerCase();
629 if(imagePath.indexOf("/") >= 0)
630 imagePath = imagePath.substring(imagePath.lastIndexOf("/") + 1, imagePath.length());
631
632 // String fullImagePath = url + middlePath + "/" + imagePath;
633 String fullImagePath = middlePath + imagePath;
634
635 if(!((os.indexOf("mac") >= 0) || (os.indexOf("nux") >= 0))) {
636 middlePath = "/tsl/midd_data/portal/rotana/guest_docs/kiosk_signature/";
637 fullImagePath = middlePath + imagePath;
638 }
639
640 float defaultImageWidth = 300f;//Tested from a real signature image
641 float defaultImageHeight = 69f;//Tested from a real signature image
642
643 Image imageSignature = Image.getInstance(fullImagePath);
644 String timeSignature = detailSignature.substring(detailSignature.indexOf("signature_") + 10, detailSignature.length() - 4);
645 SimpleDateFormat formatD = new SimpleDateFormat("yyyyMMddHHmmss", Locale.ENGLISH);
646 Date signDate = formatD.parse(timeSignature);
647 formatD.applyPattern("dd-MMM-yyyy KK:mm:ss aaa");
648 String signDateString = formatD.format(signDate);
649 // imageSignature.scalePercent(50f);
650 if(imageSignature.getWidth() > defaultImageWidth || imageSignature.getHeight() > defaultImageHeight) {
651 float widthScalePercent = (float) (100f / (imageSignature.getWidth() / defaultImageWidth));
652 float heightScalePercent = (float) (100f / (imageSignature.getHeight() / defaultImageHeight));
653 imageSignature.scalePercent(widthScalePercent, heightScalePercent);
654 }
655 // imageSignature.setAbsolutePosition(260, 120);
656 imageSignature.setAbsolutePosition(50, 30);
657 imageSignature.setAlignment(Element.ALIGN_LEFT);
658 pdf.add(imageSignature);
659 Paragraph signTime = new Paragraph();
660 // PdfContentByte canvas = pdf.getDirectContent();
661 signTime.setAlignment(Element.ALIGN_LEFT);
662 signTime.add(new Chunk(signDateString));
663 PdfContentByte canvas = writer.getDirectContent();
664 ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, signTime, 50, 30, 0);
665 } catch (Exception e) {
666 e.printStackTrace();
667 }
668 // pdf.add(signTime);
669 }
670
671 pdf.newPage();
672
673 } catch (Exception e1) {
674 e1.printStackTrace();
675 if (pdf != null && pdf.isOpen()) {
676 pdf.close();
677 }
678 FacesMessage msg = new FacesMessage("", "The PDF file can not be created");
679 FacesContext.getCurrentInstance().addMessage(null, msg);
680 throw e1;
681 }
682 }
683 pdf.close();
684 path = pathSignature + "/guest_docs/kiosk_signature/" + document_name;
685 } else {
686 path = "";
687 FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_FATAL, " Error", "no data selected");
688 FacesContext.getCurrentInstance().addMessage(null, msg);
689 }
690 return path;
691 } catch(Exception e2) {
692 e2.printStackTrace();
693 throw e2;
694 }
695 }