package hhsystem.landlord;
import hhsystem.HolidayHomeAdministration;
import hhsystem.user.Tenant;
import java.awt.Color;
import java.io.Byte
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.LookupDispatchAction;
import users.UserManager;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import data.events.VetoException;
public class EditBookingAction extends LookupDispatchAction {
@SuppressWarnings(\\\\\\\"unchecked\\\\\\\")
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put(\\\\\\\"hhsystem.save\\\\\\\", \\\\\\\"save\\\\\\\");
map.put(\\\\\\\"hhsystem.landlord.editbooking.print\\\\\\\", \\\\\\\"print\\\\\\\");
return map;
}
/**
* Simple \\\\\\\"go-back\\\\\\\" Action
*
* @param mapping ActionMapping
* @param form the EditBookingForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return will forward to Landlords overview
*/
public ActionForward cancelled(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
return mapping.findForward(\\\\\\\"exit\\\\\\\");
}
/**
* Does save the {@link BookingStatus} of the selected booking
* and forwards to the landlords overview.
*
* @param mapping ActionMapping
* @param form the EditBookingForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return will forward to Landlords overview
*/
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
EditBookingForm ebf = (EditBookingForm) form;
String bookingId = ((Booking) request.getSession().getAttribute(
\\\\\\\"selectedBooking\\\\\\\")).getName();
try {
Booking b = (Booking) HolidayHomeAdministration.getInstance()
.getBookingsCatalog().get(bookingId, null, true);
if (ebf.getBookingStatus().equals(\\\\\\\"BOOKED\\\\\\\")) {
b.setBookingStatus(BookingStatus.BOOKED);
}
if (ebf.getBookingStatus().equals(\\\\\\\"CANCELLED\\\\\\\")) {
b.setBookingStatus(BookingStatus.CANCELLED);
}
if (ebf.getBookingStatus().equals(\\\\\\\"RESERVED\\\\\\\")) {
b.setBookingStatus(BookingStatus.BOOKED);
}
} catch (VetoException e) {
e.printStackTrace();
}
ActionMessages messages = new ActionMessages();
messages.add(\\\\\\\"message\\\\\\\", new ActionMessage(
\\\\\\\"hhsystem.landlord.editbooking.success\\\\\\\"));
saveMessages(request, messages);
return mapping.findForward(\\\\\\\"exit\\\\\\\");
}
/**
* Creates a PDF, using iText-Lib, with the content of the {@link Booking} and other informational
* stuff about the {@link HolidayHome} and the {@link Tenant}.
* After generating the PDF, the output will be written into a {@link ServletOutputStream}.
*
* @param mapping ActionMapping
* @param form the EditBookingForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return null
*/
public ActionForward print(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String bookingId = ((Booking) request.getSession().getAttribute(
\\\\\\\"selectedBooking\\\\\\\")).getName();
Document document = new Document();
try {
Booking b = (Booking) HolidayHomeAdministration.getInstance()
.getBookingsCatalog().get(bookingId, null, false);
HolidayHome hh = (HolidayHome) HolidayHomeAdministration
.getInstance().getHHCatalog().get(b.getHolidayHomeID(),
null, false);
Landlord l = (Landlord) UserManager.getGlobalUM().getUser(
hh.getLandlordId());
Tenant t = (Tenant) UserManager.getGlobalUM().getUser(
b.getTenantID());
NumberFormat nbf = NumberFormat.getNumberInstance(Locale.GERMANY);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter.getInstance(document, baos);
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern(\\\\\\\"dd.MM.yyyy\\\\\\\");
document.open();
Image png = Image.getInstance(request.getSession()
.getServletContext().getResource(\\\\\\\"/templates/Logo.png\\\\\\\"));
png.setAlignment(Image.LEFT);
png.scalePercent(50);
Paragraph vermieterAdr = new Paragraph(\\\\\\\"\\\\\\\\n\\\\\\\" + l.getFirstName()
+ \\\\\\\" \\\\\\\" + l.getLastName() + \\\\\\\"\\\\\\\\n\\\\\\\" + l.getStreetAndNbr() + \\\\\\\"\\\\\\\\n\\\\\\\"
+ l.getCodeAndCity());
Paragraph mieterAdr = new Paragraph(\\\\\\\"\\\\\\\\n\\\\\\\" + t.getFirstName() + \\\\\\\" \\\\\\\"
+ t.getLastName() + \\\\\\\"\\\\\\\\n\\\\\\\" + t.getStreetAndNbr() + \\\\\\\"\\\\\\\\n\\\\\\\"
+ t.getCodeAndCity());
Phrase betreff = new Phrase(\\\\\\\"\\\\\\\\nBetreff: Buchung von Ferienhaus \\\\\\\\\\\\\\\"\\\\\\\"
+ hh.getHouseName() + \\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\", new Font(Font.HELVETICA,
Font.DEFAULTSIZE, Font.BOLD));
Phrase reiseinfos = new Phrase(\\\\\\\"\\\\\\\\n\\\\\\\\n\\\\\\\\n\\\\\\\\nReiseinformationen\\\\\\\",
new Font(Font.HELVETICA, Font.DEFAULTSIZE, Font.BOLD));
Paragraph rechnungsDatum = new Paragraph(\\\\\\\"\\\\\\\\n\\\\\\\"
+ sdf.format(new Date()));
Phrase rechnungsNummer = new Phrase(\\\\\\\"\\\\\\\\n\\\\\\\\n\\\\\\\\n\\\\\\\\nRechnungsnummer: \\\\\\\"
+ b.getId() + \\\\\\\"/2009\\\\\\\", new Font(Font.HELVETICA,
Font.DEFAULTSIZE, Font.BOLD));
Paragraph anreiselb = new Paragraph(\\\\\\\"\\\\\\\\nAnreise:\\\\\\\");
Paragraph anreise = new Paragraph(\\\\\\\"\\\\\\\\n\\\\\\\"
+ sdf.format(b.getStartDate()));
Paragraph abreiselb = new Paragraph(\\\\\\\"Abreise:\\\\\\\");
Paragraph abreise = new Paragraph(sdf.format(b.getEndDate()));
Paragraph ferienhauslb = new Paragraph(\\\\\\\"\\\\\\\\nFerienhaus:\\\\\\\");
Paragraph ferienhaus = new Paragraph(\\\\\\\"\\\\\\\\n\\\\\\\" + hh.getHouseName()
+ \\\\\\\"\\\\\\\\n\\\\\\\" + hh.getStreetAndNbr() + \\\\\\\"\\\\\\\\n\\\\\\\" + hh.getCodeAndCity());
Phrase gesamtPreis = new Phrase(\\\\\\\"\\\\\\\\n\\\\\\\\n\\\\\\\\n\\\\\\\\nGesamtpreis: \\\\\\\"
+ nbf.format(b.getCalculatedPrice()) + \\\\\\\" EUR\\\\\\\", new Font(
Font.HELVETICA, Font.DEFAULTSIZE, Font.BOLD));
Phrase inf;
Paragraph footer = new Paragraph(
\\\\\\\"\\\\\\\\n\\\\\\\\nKeine Ausweisung von Umsatzsteuer wegen Anwendung von § 19 Abs. 1 UstG (Umsatzsteuerbefreiung für Kleinunternehmer)\\\\\\\");
PdfPTable table = new PdfPTable(2);
PdfPCell mieterCell = new PdfPCell(mieterAdr);
mieterCell.setBorderColor(Color.WHITE);
mieterCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell vermieterCell = new PdfPCell(vermieterAdr);
vermieterCell.setBorderColor(Color.WHITE);
vermieterCell.setHorizontalAlignment(Element.ALIGN_LEFT);
PdfPCell betreffCell = new PdfPCell(betreff);
betreffCell.setBorderColor(Color.WHITE);
betreffCell.setHorizontalAlignment(Element.ALIGN_LEFT);
PdfPCell reiseInfoCell = new PdfPCell(reiseinfos);
reiseInfoCell.setBorderColor(Color.WHITE);
reiseInfoCell.setHorizontalAlignment(Element.ALIGN_LEFT);
PdfPCell datumCell = new PdfPCell(rechnungsDatum);
datumCell.setBorderColor(Color.WHITE);
datumCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell nummerCell = new PdfPCell(rechnungsNummer);
nummerCell.setBorderColor(Color.WHITE);
nummerCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
nummerCell.setColspan(2);
PdfPCell anreiselbCell = new PdfPCell(anreiselb);
anreiselbCell.setBorderColor(Color.WHITE);
anreiselbCell.setHorizontalAlignment(Element.ALIGN_LEFT);
PdfPCell anreiseCell = new PdfPCell(anreise);
anreiseCell.setBorderColor(Color.WHITE);
anreiseCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell abreiselbCell = new PdfPCell(abreiselb);
abreiselbCell.setBorderColor(Color.WHITE);
abreiselbCell.setHorizontalAlignment(Element.ALIGN_LEFT);
PdfPCell abreiseCell = new PdfPCell(abreise);
abreiseCell.setBorderColor(Color.WHITE);
abreiseCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell ferienhauslbCell = new PdfPCell(ferienhauslb);
ferienhauslbCell.setBorderColor(Color.WHITE);
ferienhauslbCell.setHorizontalAlignment(Element.ALIGN_LEFT);
PdfPCell ferienhausCell = new PdfPCell(ferienhaus);
ferienhausCell.setBorderColor(Color.WHITE);
ferienhausCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell gesamtPreisCell = new PdfPCell(gesamtPreis);
gesamtPreisCell.setBorderColor(Color.WHITE);
gesamtPreisCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
gesamtPreisCell.setColspan(2);
PdfPCell infCell;
PdfPCell kontoNummerCell;
PdfPCell blzCell;
if (b.getBankData().getCreditCardNumber().equals(\\\\\\\"\\\\\\\")) {
inf = new Phrase(\\\\\\\"\\\\\\\\n\\\\\\\\n\\\\\\\\nÜberweisungsinformationen\\\\\\\", new Font(
Font.HELVETICA, Font.DEFAULTSIZE, Font.BOLD));
Paragraph kontoNummer = new Paragraph(\\\\\\\"Kontonummer: \\\\\\\"
+ l.getBankCode());
Paragraph blz = new Paragraph(\\\\\\\"Bankleitzahl: \\\\\\\"
+ l.getAccountNumber());
infCell = new PdfPCell(inf);
infCell.setBorderColor(Color.WHITE);
infCell.setHorizontalAlignment(Element.ALIGN_LEFT);
infCell.setColspan(2);
kontoNummerCell = new PdfPCell(kontoNummer);
kontoNummerCell.setBorderColor(Color.WHITE);
kontoNummerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
kontoNummerCell.setColspan(2);
blzCell = new PdfPCell(blz);
blzCell.setBorderColor(Color.WHITE);
blzCell.setHorizontalAlignment(Element.ALIGN_LEFT);
blzCell.setColspan(2);
table.addCell(vermieterCell);
table.addCell(mieterCell);
table.addCell(betreffCell);
table.addCell(datumCell);
table.addCell(reiseInfoCell);
table.addCell(nummerCell);
table.addCell(anreiselbCell);
table.addCell(anreiseCell);
table.addCell(abreiselbCell);
table.addCell(abreiseCell);
table.addCell(ferienhauslbCell);
table.addCell(ferienhausCell);
table.addCell(gesamtPreisCell);
table.addCell(infCell);
table.addCell(kontoNummerCell);
table.addCell(blzCell);
} else {
inf = new Phrase(\\\\\\\"Es wurde mit Kreditkarte bezahlt.\\\\\\\");
infCell = new PdfPCell(inf);
infCell.setBorderColor(Color.WHITE);
infCell.setHorizontalAlignment(Element.ALIGN_LEFT);
infCell.setColspan(2);
table.addCell(vermieterCell);
table.addCell(mieterCell);
table.addCell(betreffCell);
table.addCell(datumCell);
table.addCell(reiseInfoCell);
table.addCell(nummerCell);
table.addCell(anreiselbCell);
table.addCell(anreiseCell);
table.addCell(abreiselbCell);
table.addCell(abreiseCell);
table.addCell(ferienhauslbCell);
table.addCell(ferienhausCell);
table.addCell(gesamtPreisCell);
table.addCell(infCell);
}
PdfPCell footerCell = new PdfPCell(footer);
footerCell.setBorderColor(Color.WHITE);
footerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
footerCell.setColspan(2);
table.addCell(footerCell);
table.setWidthPercentage(100);
document.add(png);
document.add(table);
document.close();
response.setContentType(\\\\\\\"application/pdf\\\\\\\");
response.setContentLength(baos.size());
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
response.flushBuffer();
} catch (VetoException e) {
e.printStackTrace();
} catch (DocumentException de) {
de.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return null;
}
}
-