home | create | search | help
  1. package hhsystem.landlord;
  2.  
  3. import hhsystem.HolidayHomeAdministration;
  4. import hhsystem.user.Tenant;
  5.  
  6. import java.awt.Color;
  7. import java.io.Byte
  8. import java.text.SimpleDateFormat;
  9. import java.util.Date;
  10. import java.util.HashMap;
  11. import java.util.Locale;
  12. import java.util.Map;
  13.  
  14. import javax.servlet.ServletOutputStream;
  15. import javax.servlet.http.HttpServletRequest;
  16. import javax.servlet.http.HttpServletResponse;
  17.  
  18. import org.apache.struts.action.ActionForm;
  19. import org.apache.struts.action.ActionForward;
  20. import org.apache.struts.action.ActionMapping;
  21. import org.apache.struts.action.ActionMessage;
  22. import org.apache.struts.action.ActionMessages;
  23. import org.apache.struts.actions.LookupDispatchAction;
  24.  
  25. import users.UserManager;
  26.  
  27. import com.lowagie.text.Document;
  28. import com.lowagie.text.DocumentException;
  29. import com.lowagie.text.Element;
  30. import com.lowagie.text.Font;
  31. import com.lowagie.text.Image;
  32. import com.lowagie.text.Paragraph;
  33. import com.lowagie.text.Phrase;
  34. import com.lowagie.text.pdf.PdfPCell;
  35. import com.lowagie.text.pdf.PdfPTable;
  36. import com.lowagie.text.pdf.PdfWriter;
  37.  
  38. import data.events.VetoException;
  39.  
  40. public class EditBookingAction extends LookupDispatchAction {
  41.  
  42.     @SuppressWarnings(\\\\\\\"unchecked\\\\\\\")
  43.     protected Map getKeyMethodMap() {
  44.         Map map = new HashMap();
  45.         map.put(\\\\\\\"hhsystem.save\\\\\\\", \\\\\\\"save\\\\\\\");
  46.         map.put(\\\\\\\"hhsystem.landlord.editbooking.print\\\\\\\", \\\\\\\"print\\\\\\\");
  47.         return map;
  48.     }
  49.    
  50.     /**
  51.      * Simple \\\\\\\"go-back\\\\\\\" Action
  52.      *
  53.      * @param mapping   ActionMapping
  54.      * @param form   the EditBookingForm
  55.      * @param request   HttpServletRequest
  56.      * @param response  HttpServletResponse
  57.      * @return    will forward to Landlords overview
  58.      */
  59.     public ActionForward cancelled(ActionMapping mapping, ActionForm form,
  60.             HttpServletRequest request, HttpServletResponse response) {
  61.         return mapping.findForward(\\\\\\\"exit\\\\\\\");
  62.     }
  63.     /**
  64.      * Does save the {@link BookingStatus} of the selected booking
  65.      * and forwards to the landlords overview.
  66.      *
  67.      * @param mapping   ActionMapping
  68.      * @param form   the EditBookingForm
  69.      * @param request   HttpServletRequest
  70.      * @param response  HttpServletResponse
  71.      * @return      will forward to Landlords overview
  72.      */
  73.     public ActionForward save(ActionMapping mapping, ActionForm form,
  74.             HttpServletRequest request, HttpServletResponse response) {
  75.         EditBookingForm ebf = (EditBookingForm) form;
  76.         String bookingId = ((Booking) request.getSession().getAttribute(
  77.                 \\\\\\\"selectedBooking\\\\\\\")).getName();
  78.         try {
  79.             Booking b = (Booking) HolidayHomeAdministration.getInstance()
  80.                     .getBookingsCatalog().get(bookingId, null, true);
  81.             if (ebf.getBookingStatus().equals(\\\\\\\"BOOKED\\\\\\\")) {
  82.                 b.setBookingStatus(BookingStatus.BOOKED);
  83.             }
  84.             if (ebf.getBookingStatus().equals(\\\\\\\"CANCELLED\\\\\\\")) {
  85.                 b.setBookingStatus(BookingStatus.CANCELLED);
  86.             }
  87.             if (ebf.getBookingStatus().equals(\\\\\\\"RESERVED\\\\\\\")) {
  88.                 b.setBookingStatus(BookingStatus.BOOKED);
  89.             }
  90.         } catch (VetoException e) {
  91.             e.printStackTrace();
  92.         }
  93.         ActionMessages messages = new ActionMessages();
  94.         messages.add(\\\\\\\"message\\\\\\\", new ActionMessage(
  95.                 \\\\\\\"hhsystem.landlord.editbooking.success\\\\\\\"));
  96.         saveMessages(request, messages);
  97.         return mapping.findForward(\\\\\\\"exit\\\\\\\");
  98.     }
  99.    
  100.     /**
  101.      * Creates a PDF, using iText-Lib, with the content of the {@link Booking} and other informational
  102.      * stuff about the {@link HolidayHome} and the {@link Tenant}.
  103.      * After generating the PDF, the output will be written into a {@link ServletOutputStream}.
  104.      *
  105.      * @param mapping   ActionMapping
  106.      * @param form   the EditBookingForm
  107.      * @param request   HttpServletRequest
  108.      * @param response  HttpServletResponse
  109.      * @return      null
  110.      */
  111.    
  112.     public ActionForward print(ActionMapping mapping, ActionForm form,
  113.             HttpServletRequest request, HttpServletResponse response) {
  114.         String bookingId = ((Booking) request.getSession().getAttribute(
  115.                 \\\\\\\"selectedBooking\\\\\\\")).getName();
  116.         Document document = new Document();
  117.         try {
  118.             Booking b = (Booking) HolidayHomeAdministration.getInstance()
  119.                     .getBookingsCatalog().get(bookingId, null, false);
  120.             HolidayHome hh = (HolidayHome) HolidayHomeAdministration
  121.                     .getInstance().getHHCatalog().get(b.getHolidayHomeID(),
  122.                             null, false);
  123.             Landlord l = (Landlord) UserManager.getGlobalUM().getUser(
  124.                     hh.getLandlordId());
  125.             Tenant t = (Tenant) UserManager.getGlobalUM().getUser(
  126.                     b.getTenantID());
  127.             NumberFormat nbf = NumberFormat.getNumberInstance(Locale.GERMANY);
  128.             ByteArrayOutputStream baos = new ByteArrayOutputStream();
  129.             PdfWriter.getInstance(document, baos);
  130.             SimpleDateFormat sdf = new SimpleDateFormat();
  131.             sdf.applyPattern(\\\\\\\"dd.MM.yyyy\\\\\\\");
  132.             document.open();
  133.             Image png = Image.getInstance(request.getSession()
  134.                     .getServletContext().getResource(\\\\\\\"/templates/Logo.png\\\\\\\"));
  135.             png.setAlignment(Image.LEFT);
  136.             png.scalePercent(50);
  137.             Paragraph vermieterAdr = new Paragraph(\\\\\\\"\\\\\\\\n\\\\\\\" + l.getFirstName()
  138.                     + \\\\\\\" \\\\\\\" + l.getLastName() + \\\\\\\"\\\\\\\\n\\\\\\\" + l.getStreetAndNbr() + \\\\\\\"\\\\\\\\n\\\\\\\"
  139.                     + l.getCodeAndCity());
  140.             Paragraph mieterAdr = new Paragraph(\\\\\\\"\\\\\\\\n\\\\\\\" + t.getFirstName() + \\\\\\\" \\\\\\\"
  141.                     + t.getLastName() + \\\\\\\"\\\\\\\\n\\\\\\\" + t.getStreetAndNbr() + \\\\\\\"\\\\\\\\n\\\\\\\"
  142.                     + t.getCodeAndCity());
  143.             Phrase betreff = new Phrase(\\\\\\\"\\\\\\\\nBetreff: Buchung von Ferienhaus \\\\\\\\\\\\\\\"\\\\\\\"
  144.                     + hh.getHouseName() + \\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\", new Font(Font.HELVETICA,
  145.                     Font.DEFAULTSIZE, Font.BOLD));
  146.             Phrase reiseinfos = new Phrase(\\\\\\\"\\\\\\\\n\\\\\\\\n\\\\\\\\n\\\\\\\\nReiseinformationen\\\\\\\",
  147.                     new Font(Font.HELVETICA, Font.DEFAULTSIZE, Font.BOLD));
  148.             Paragraph rechnungsDatum = new Paragraph(\\\\\\\"\\\\\\\\n\\\\\\\"
  149.                     + sdf.format(new Date()));
  150.             Phrase rechnungsNummer = new Phrase(\\\\\\\"\\\\\\\\n\\\\\\\\n\\\\\\\\n\\\\\\\\nRechnungsnummer: \\\\\\\"
  151.                     + b.getId() + \\\\\\\"/2009\\\\\\\", new Font(Font.HELVETICA,
  152.                     Font.DEFAULTSIZE, Font.BOLD));
  153.             Paragraph anreiselb = new Paragraph(\\\\\\\"\\\\\\\\nAnreise:\\\\\\\");
  154.             Paragraph anreise = new Paragraph(\\\\\\\"\\\\\\\\n\\\\\\\"
  155.                     + sdf.format(b.getStartDate()));
  156.             Paragraph abreiselb = new Paragraph(\\\\\\\"Abreise:\\\\\\\");
  157.             Paragraph abreise = new Paragraph(sdf.format(b.getEndDate()));
  158.             Paragraph ferienhauslb = new Paragraph(\\\\\\\"\\\\\\\\nFerienhaus:\\\\\\\");
  159.             Paragraph ferienhaus = new Paragraph(\\\\\\\"\\\\\\\\n\\\\\\\" + hh.getHouseName()
  160.                     + \\\\\\\"\\\\\\\\n\\\\\\\" + hh.getStreetAndNbr() + \\\\\\\"\\\\\\\\n\\\\\\\" + hh.getCodeAndCity());
  161.             Phrase gesamtPreis = new Phrase(\\\\\\\"\\\\\\\\n\\\\\\\\n\\\\\\\\n\\\\\\\\nGesamtpreis: \\\\\\\"
  162.                     + nbf.format(b.getCalculatedPrice()) + \\\\\\\" EUR\\\\\\\", new Font(
  163.                     Font.HELVETICA, Font.DEFAULTSIZE, Font.BOLD));
  164.             Phrase inf;
  165.             Paragraph footer = new Paragraph(
  166.                     \\\\\\\"\\\\\\\\n\\\\\\\\nKeine Ausweisung von Umsatzsteuer wegen Anwendung von § 19  Abs. 1 UstG  (Umsatzsteuerbefreiung für Kleinunternehmer)\\\\\\\");
  167.             PdfPTable table = new PdfPTable(2);
  168.             PdfPCell mieterCell = new PdfPCell(mieterAdr);
  169.             mieterCell.setBorderColor(Color.WHITE);
  170.             mieterCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
  171.             PdfPCell vermieterCell = new PdfPCell(vermieterAdr);
  172.             vermieterCell.setBorderColor(Color.WHITE);
  173.             vermieterCell.setHorizontalAlignment(Element.ALIGN_LEFT);
  174.             PdfPCell betreffCell = new PdfPCell(betreff);
  175.             betreffCell.setBorderColor(Color.WHITE);
  176.             betreffCell.setHorizontalAlignment(Element.ALIGN_LEFT);
  177.             PdfPCell reiseInfoCell = new PdfPCell(reiseinfos);
  178.             reiseInfoCell.setBorderColor(Color.WHITE);
  179.             reiseInfoCell.setHorizontalAlignment(Element.ALIGN_LEFT);
  180.             PdfPCell datumCell = new PdfPCell(rechnungsDatum);
  181.             datumCell.setBorderColor(Color.WHITE);
  182.             datumCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
  183.             PdfPCell nummerCell = new PdfPCell(rechnungsNummer);
  184.             nummerCell.setBorderColor(Color.WHITE);
  185.             nummerCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
  186.             nummerCell.setColspan(2);
  187.             PdfPCell anreiselbCell = new PdfPCell(anreiselb);
  188.             anreiselbCell.setBorderColor(Color.WHITE);
  189.             anreiselbCell.setHorizontalAlignment(Element.ALIGN_LEFT);
  190.             PdfPCell anreiseCell = new PdfPCell(anreise);
  191.             anreiseCell.setBorderColor(Color.WHITE);
  192.             anreiseCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
  193.             PdfPCell abreiselbCell = new PdfPCell(abreiselb);
  194.             abreiselbCell.setBorderColor(Color.WHITE);
  195.             abreiselbCell.setHorizontalAlignment(Element.ALIGN_LEFT);
  196.             PdfPCell abreiseCell = new PdfPCell(abreise);
  197.             abreiseCell.setBorderColor(Color.WHITE);
  198.             abreiseCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
  199.             PdfPCell ferienhauslbCell = new PdfPCell(ferienhauslb);
  200.             ferienhauslbCell.setBorderColor(Color.WHITE);
  201.             ferienhauslbCell.setHorizontalAlignment(Element.ALIGN_LEFT);
  202.             PdfPCell ferienhausCell = new PdfPCell(ferienhaus);
  203.             ferienhausCell.setBorderColor(Color.WHITE);
  204.             ferienhausCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
  205.             PdfPCell gesamtPreisCell = new PdfPCell(gesamtPreis);
  206.             gesamtPreisCell.setBorderColor(Color.WHITE);
  207.             gesamtPreisCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
  208.             gesamtPreisCell.setColspan(2);
  209.             PdfPCell infCell;
  210.             PdfPCell kontoNummerCell;
  211.             PdfPCell blzCell;
  212.            
  213.             if (b.getBankData().getCreditCardNumber().equals(\\\\\\\"\\\\\\\")) {
  214.                 inf = new Phrase(\\\\\\\"\\\\\\\\n\\\\\\\\n\\\\\\\\nÜberweisungsinformationen\\\\\\\", new Font(
  215.                         Font.HELVETICA, Font.DEFAULTSIZE, Font.BOLD));
  216.                 Paragraph kontoNummer = new Paragraph(\\\\\\\"Kontonummer: \\\\\\\"
  217.                         + l.getBankCode());
  218.                 Paragraph blz = new Paragraph(\\\\\\\"Bankleitzahl: \\\\\\\"
  219.                         + l.getAccountNumber());
  220.                 infCell = new PdfPCell(inf);
  221.                 infCell.setBorderColor(Color.WHITE);
  222.                 infCell.setHorizontalAlignment(Element.ALIGN_LEFT);
  223.                 infCell.setColspan(2);
  224.                 kontoNummerCell = new PdfPCell(kontoNummer);
  225.                 kontoNummerCell.setBorderColor(Color.WHITE);
  226.                 kontoNummerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
  227.                 kontoNummerCell.setColspan(2);
  228.                 blzCell = new PdfPCell(blz);
  229.                 blzCell.setBorderColor(Color.WHITE);
  230.                 blzCell.setHorizontalAlignment(Element.ALIGN_LEFT);
  231.                 blzCell.setColspan(2);
  232.                
  233.                 table.addCell(vermieterCell);
  234.                 table.addCell(mieterCell);
  235.                 table.addCell(betreffCell);
  236.                 table.addCell(datumCell);
  237.                 table.addCell(reiseInfoCell);
  238.                 table.addCell(nummerCell);
  239.                 table.addCell(anreiselbCell);
  240.                 table.addCell(anreiseCell);
  241.                 table.addCell(abreiselbCell);
  242.                 table.addCell(abreiseCell);
  243.                 table.addCell(ferienhauslbCell);
  244.                 table.addCell(ferienhausCell);
  245.                 table.addCell(gesamtPreisCell);
  246.                 table.addCell(infCell);
  247.                 table.addCell(kontoNummerCell);
  248.                 table.addCell(blzCell);
  249.             } else {
  250.                 inf = new Phrase(\\\\\\\"Es wurde mit Kreditkarte bezahlt.\\\\\\\");
  251.                
  252.                 infCell = new PdfPCell(inf);
  253.                 infCell.setBorderColor(Color.WHITE);
  254.                 infCell.setHorizontalAlignment(Element.ALIGN_LEFT);
  255.                 infCell.setColspan(2);
  256.                
  257.                 table.addCell(vermieterCell);
  258.                 table.addCell(mieterCell);
  259.                 table.addCell(betreffCell);
  260.                 table.addCell(datumCell);
  261.                 table.addCell(reiseInfoCell);
  262.                 table.addCell(nummerCell);
  263.                 table.addCell(anreiselbCell);
  264.                 table.addCell(anreiseCell);
  265.                 table.addCell(abreiselbCell);
  266.                 table.addCell(abreiseCell);
  267.                 table.addCell(ferienhauslbCell);
  268.                 table.addCell(ferienhausCell);
  269.                 table.addCell(gesamtPreisCell);
  270.                 table.addCell(infCell);
  271.             }
  272.             PdfPCell footerCell = new PdfPCell(footer);
  273.             footerCell.setBorderColor(Color.WHITE);
  274.             footerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
  275.             footerCell.setColspan(2);
  276.             table.addCell(footerCell);
  277.             table.setWidthPercentage(100);
  278.             document.add(png);
  279.             document.add(table);
  280.             document.close();
  281.             response.setContentType(\\\\\\\"application/pdf\\\\\\\");
  282.             response.setContentLength(baos.size());
  283.             ServletOutputStream out = response.getOutputStream();
  284.             baos.writeTo(out);
  285.             out.flush();
  286.             response.flushBuffer();
  287.         } catch (VetoException e) {
  288.             e.printStackTrace();
  289.         } catch (DocumentException de) {
  290.             de.printStackTrace();
  291.         } catch (IOException ioe) {
  292.             ioe.printStackTrace();
  293.         }
  294.         return null;
  295.     }
  296. }
Subscribe to this code! Get Firefox! Valid XHTML Valid CSS Powered By GeSHi 665 pieces of code saved