package com.gpc.server.report.invoice; /** *

Title: TsoInvoice_Ithaca

Description: This form prints on the Ithaca POSJet1000 receipt printers. The form * is capable of 43 characters max per line at 17 cpi (default).

Copyright: Copyright (c) 2002

Company: *

* * @author unascribed * @version 1.0 @todo: Accommodate multi-page invoices (> 50 line items) */ import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.Hashtable; import java.util.List; import java.util.Locale; import java.util.StringTokenizer; import java.util.Vector; import org.apache.log4j.Logger; import com.gpc.common.ApplicationContext; import com.gpc.common.Profile; import com.gpc.common.ResourceBundleReader; import com.gpc.common.TsoConstant; import com.gpc.common.constants.refvalues.RefInvoiceNoteType; import com.gpc.common.constants.refvalues.RefTenderType; import com.gpc.common.constants.refvalues.RefTransactionType; import com.gpc.common.exception.ApplicationException; import com.gpc.common.pattern.FwoPattern; import com.gpc.common.pattern.FwoPhonePattern; import com.gpc.common.pattern.PhonePatternFormatException; import com.gpc.common.report.PrintFormat; import com.gpc.server.invoice.print.PrintUtil; import com.gpc.valueobjects.invoice.line.BaseLineItemVO; import com.gpc.valueobjects.invoice.print.PrintableInvoiceLineItemVO; import com.gpc.valueobjects.invoice.print.PrintableInvoicePaymentVO; import com.gpc.valueobjects.invoice.print.PrintableInvoiceRoaVO; import com.gpc.valueobjects.invoice.print.PrintableInvoiceVO; import com.gpc.valueobjects.invoice.print.PrinterVO; import com.gpc.valueobjects.profile.InvoicingProfileVO; import com.gpc.valueobjects.report.GenericReportRequest; import com.sun.media.jai.codec.ImageCodec; import com.sun.media.jai.codec.ImageDecoder; import com.sun.media.jai.codec.SeekableStream; import com.sun.media.jai.codec.TIFFDecodeParam; import com.sun.media.jai.codecimpl.TIFFImage; import java.awt.Color; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; public class TsoInvoice_Ithaca extends TsoInvoice { private static final Logger logger = Logger.getLogger( TsoInvoice_Ithaca.class ); private static final int MAX_LINE_WIDTH = 43; // compressed mode private static final int MAX_LINE_ITEMS = 100; // 2 lines per Line Item x 50 Line Items private final byte ESC = 27; private final byte[] ENABLE_HORIZONTAL_GRAPHICS = new byte[]{ ESC, '*', 10, 0, 0 }; private final byte[] CLEAR_PRINT_BUFFER = new byte[]{24}; // Lot's of localized text... public static final String NAME = "TsoInvoice_Ithaca"; private static final String TSOINVOICE = "TsoInvoice"; private static final String CHARGE_SALE = "PrintableInvoice.ChargeSale"; private static final String CHANGE_DUE = "PrintableInvoice.ChangeDue"; private static final String BOPIS_SALE = "PrintableInvoice.BOPISSale"; private String empText = null; private String invoiceText = null; private String custCopyText = null; private String storeCopyText = null; private String duplicateText = null; private String reprintText = null; private String manualText = null; private String headerDescText = null; private String headerQtyText = null; private String headerNetText = null; private String headerTotText = null; private String subtotalText = null; private String deliveryText = null; private String miscText = null; private String taxText = null; private String totalText = null; private String reasonText = null; private String originalText = null; private String dateText = null; private String amountText = null; private String approvedText = null; private String receivedText = null; private String customerText = null; private String addressText = null; private String cityText = null; private String stateText = null; private String zipText = null; private String phoneText = null; private String receiptText1 = null; private String receiptText2 = null; private String warrantyText1 = null; private String warrantyText2 = null; private String warrantyText3 = null; private String amountReceivedText = null; private String paymentReceivedText = null; private String discountText = null; private String paymentReceivedInvoicesText = null; private String signatureText = null; private String cardAgreementText1 = null; private String cardAgreementText2 = null; private int j; // line counter private int k = 0; // index of current line item being printed private static final String CREDIT_MEMO = NAME + ".CreditMemo"; private static final String NAME_NOT_AVAILABLE = "PrintableInvoice.NameNotAvailable"; private static final String GIFT_CARD_BALANCE = "PrintableInvoice.GiftCardBalance"; // For ROA's private int numLineItems = 0; private int numPayments = 0; private int numROALines = 0; private boolean roaPaymentsPrinted = false; private boolean roaInfoPrinted = false; private boolean roaNotesPrinted = false; private boolean firstRewardNoteLine = true; //Gift card Activation receipt private String giftCardActivationHeader = null; private String cardNumberText = null; private String giftCardActivationFooter1 = null; private String giftCardActivationFooter2 = null; private String giftCardActivationFooter3 = null; public boolean isFileWriteable() { return true; } protected int getMaxLineWidth() { return MAX_LINE_WIDTH; } protected void buildInvoice() throws ApplicationException { logger.info( "buildInvoice" ); // Get and set all the localized text for the form setLocalization(); Vector invoiceLineItems = null; Vector invoicePayments = null; Vector invoiceROALineItems = null; PrintableInvoiceVO piVO = (PrintableInvoiceVO) getPrintableInvoice(); // Determine the number pages needed based on the number of line items // (Currently, only one payment method can be used if it's an ROA // with a credit card or check) if ((piVO.getLineItems() != null) && (piVO.getLineItems().size() > 0)) { invoiceLineItems = piVO.getLineItems(); numLineItems = invoiceLineItems.size(); } if ((piVO.getInvoicePayments() != null) && (piVO.getInvoicePayments().size() > 0)) { invoicePayments = piVO.getInvoicePayments(); numPayments = invoicePayments.size(); } if ((piVO.getInvoiceROAs() != null) && (piVO.getInvoiceROAs().size() > 0)) { invoiceROALineItems = piVO.getInvoiceROAs(); numROALines = invoiceROALineItems.size(); } logger.debug( "Total line items: " + numLineItems + " | Total payment lines: " + numPayments + " | Total INVOICE_ROA: " + numROALines ); // If reprint flag is true, print only one copy of invoice. if (piVO.isReprintFlag()) { printInvoice( piVO, invoicePayments, invoiceROALineItems, invoiceLineItems, TsoInvoice.REPRINT_INVOICE ); if (!piVO.isVoided()) { printGiftCardActivationReceipts(piVO, invoiceLineItems, TsoInvoice.REPRINT_INVOICE); } } else if (piVO.isCoresPendingReturnReport().booleanValue()) { printInvoice( piVO, invoicePayments, invoiceROALineItems, invoiceLineItems, TsoInvoice.CUSTOMER_COPY_INVOICE ); } else { printInvoice( piVO, invoicePayments, invoiceROALineItems, invoiceLineItems, TsoInvoice.CUSTOMER_COPY_INVOICE ); if (canPrintStoreCopyOfInvoice() || canPrintStoreCopyForReturns(invoiceLineItems)) { printInvoice(piVO, invoicePayments, invoiceROALineItems, invoiceLineItems, TsoInvoice.STORE_COPY_INVOICE); } if (!piVO.isVoided()) { printGiftCardActivationReceipts(piVO, invoiceLineItems, TsoInvoice.CUSTOMER_COPY_INVOICE); } } // All pages processed } /** * This method prints the invoice details. * * @param printableInvoice Contains Invoice information. * @param invoicePayments Contains the payment information. * @param invoiceRoaLineItems Contains invoice line items for a ROA invoice. * @param invoiceLineItems Contains normal invoice line items. * @param invoiceCopy Contains the type of Invoice copy. * @throws ApplicationException */ private void printInvoice( PrintableInvoiceVO printableInvoice, Vector invoicePayments, Vector invoiceRoaLineItems, Vector invoiceLineItems, int invoiceCopy ) throws ApplicationException { firstRewardNoteLine = true; // Reset the character size // Max chars per line at 17CPI is 43 appendInvoiceText( (String) commandCodes.get( "INITIALIZE_PRINTER" ) ); appendInvoiceText( (String) commandCodes.get( "CLEAR_PRINT_BUFFER" ) ); appendInvoiceText( (String) commandCodes.get( "CPI_17" ) ); appendInvoiceText( (String) commandCodes.get( "CLEAR_PRINT_BUFFER" ) ); appendInvoiceText( (String) commandCodes.get( "HEIGHT_SINGLE_WIDTH_SINGLE" ) ); appendInvoiceText( (String) commandCodes.get( "CLEAR_PRINT_BUFFER" ) ); appendInvoiceText( (String) commandCodes.get( "INK_BLACK" ) ); // Print the header, customer and general invoice info first printHeaderLines( printableInvoice ); printCustomerLines( printableInvoice ); // Print the appropriate number of lines per page if (!printableInvoice.isROA()) { // Normal invoice for (j = 0, k = 0; j < MAX_LINE_ITEMS && k < numLineItems; j++, k++) { PrintableInvoiceLineItemVO printableInvoiceLineItem = (PrintableInvoiceLineItemVO) printableInvoice.getLineItems().get( k ); printLineItem( printableInvoiceLineItem ); } } else { // Invoice is an ROA j = 0; printROADetail( printableInvoice, invoicePayments, invoiceRoaLineItems, invoiceLineItems ); } // Print the total lines and the footer at the bottom of the page appendInvoiceText( PrintFormat.LINE_BREAK ); printTotalLines( printableInvoice ); printSignature( printableInvoice ); printFooterLines( printableInvoice, invoiceCopy ); // Cut the paper and get ready for the next invoice appendInvoiceText( (String) commandCodes.get( "EMPHASIZE_BEGIN" ) ); appendInvoiceText( (String) commandCodes.get( "CLEAR_PRINT_BUFFER" ) ); appendInvoiceText( (String) commandCodes.get( "MACRO_NAPA" ) ); appendInvoiceText( (String) commandCodes.get( "CLEAR_PRINT_BUFFER" ) ); appendInvoiceText( (String) commandCodes.get( "EMPHASIZE_END" ) ); appendInvoiceText( (String) commandCodes.get( "CLEAR_PRINT_BUFFER" ) ); appendInvoiceText( (String) commandCodes.get( "AUTO_CUT" ) ); appendInvoiceText( PrintFormat.LINE_BREAK ); } private void printSignature( PrintableInvoiceVO printableInvoice ) throws ApplicationException { final byte[] signatureBytes = printableInvoice.getSignatureOnFile(); if ((signatureBytes == null) || (signatureBytes.length == 0)) { if (printableInvoice.isCreditCardUsed()){ appendInvoiceText( PrintFormat.LINE_BREAK + PrintFormat.LINE_BREAK); printCardAgreement(); } return; } try { // The signature is a TIFF image... convert it to a BufferedImage so it can be // scaled to fit the printer and manipulated with the Java2D API. final SeekableStream s = SeekableStream.wrapInputStream( new ByteArrayInputStream( signatureBytes ), true ); final TIFFDecodeParam params = new TIFFDecodeParam(); final ImageDecoder imageDecoder = ImageCodec.createImageDecoder( "tiff", s, params ); final TIFFImage tiffImage = (TIFFImage) imageDecoder.decodeAsRenderedImage(); final BufferedImage image = new BufferedImage( tiffImage.getWidth(), tiffImage.getHeight(), BufferedImage.TYPE_INT_ARGB ); final Graphics2D g2d = image.createGraphics(); g2d.drawRenderedImage( tiffImage, new AffineTransform() ); g2d.dispose(); // Scale the image to fit the printer paper, and draw a line under it. final int IMAGE_WIDTH = 256; final BufferedImage scaledImage = getScaledImage( image, IMAGE_WIDTH ); final Graphics2D scaledG2D = scaledImage.createGraphics(); scaledG2D.setColor( Color.black ); scaledG2D.drawLine( 0, scaledImage.getHeight()-1, IMAGE_WIDTH, scaledImage.getHeight()-1 ); scaledG2D.dispose(); appendInvoiceText( PrintFormat.LINE_BREAK ); appendInvoiceText( signatureText ); appendInvoiceText( PrintFormat.LINE_BREAK ); printImage( scaledImage ); printCardAgreement(); } catch (Throwable ex) { logger.error( "TsoInvoice_Ithaca.printSignature Error occured while printing the scaled image to fit paper : "); } } /** * This method prints the Credit Card agreement message. */ private void printCardAgreement() { appendInvoiceText(PrintFormat.format(cardAgreementText1, MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED)); appendInvoiceText(PrintFormat.format(cardAgreementText2, MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED)); appendInvoiceText(PrintFormat.LINE_BREAK); } private void setLocalization() { if (resourceBundleReader != null) { empText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".EmployeeText", getReportRequest().getLocale() ); invoiceText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".InvoiceText", getReportRequest().getLocale() ); custCopyText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".CustomerCopyText", getReportRequest().getLocale() ); storeCopyText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".StoreCopyText", getReportRequest().getLocale() ); duplicateText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".DuplicateCopyText", getReportRequest().getLocale() ); reprintText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".ReprintText", getReportRequest().getLocale() ); manualText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".ManualText", getReportRequest().getLocale() ); headerDescText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".HeaderDescriptionText", getReportRequest().getLocale() ); headerQtyText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".HeaderQtyText", getReportRequest().getLocale() ); headerNetText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".HeaderNetText", getReportRequest().getLocale() ); headerTotText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".HeaderTotalText", getReportRequest().getLocale() ); subtotalText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".SubtotalText", getReportRequest().getLocale() ); deliveryText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".DeliveryText", getReportRequest().getLocale() ); miscText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".MiscellaneousText", getReportRequest().getLocale() ); taxText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".TaxText", getReportRequest().getLocale() ); totalText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".TotalDueText", getReportRequest().getLocale() ); reasonText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".ReasonText", getReportRequest().getLocale() ); originalText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".OriginalInvoiceText", getReportRequest().getLocale() ); dateText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".DateText", getReportRequest().getLocale() ); amountText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".AmountText", getReportRequest().getLocale() ); approvedText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".ApprovedByText", getReportRequest().getLocale() ); receivedText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".ReceivedByText", getReportRequest().getLocale() ); customerText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".CustNameText", getReportRequest().getLocale() ); addressText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".AddressText", getReportRequest().getLocale() ); cityText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".CityText", getReportRequest().getLocale() ); stateText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".StateText", getReportRequest().getLocale() ); zipText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".ZipText", getReportRequest().getLocale() ); phoneText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".PhoneText", getReportRequest().getLocale() ); receiptText1 = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".ReceiptText1", getReportRequest().getLocale() ); receiptText2 = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".ReceiptText2", getReportRequest().getLocale() ); warrantyText1 = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".WarrantyText1", getReportRequest().getLocale() ); warrantyText2 = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".WarrantyText2", getReportRequest().getLocale() ); warrantyText3 = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".WarrantyText3", getReportRequest().getLocale() ); amountReceivedText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".AmountReceivedText", getReportRequest().getLocale() ); paymentReceivedText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".PaymentReceivedText", getReportRequest().getLocale() ); discountText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".DiscountText", getReportRequest().getLocale() ); paymentReceivedInvoicesText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".PaymentReceivedInvoicesText", getReportRequest().getLocale() ); signatureText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".SignatureText", getReportRequest().getLocale() ); cardAgreementText1 = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".CardAgreementText1", getReportRequest().getLocale() ); cardAgreementText2 = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".CardAgreementText2", getReportRequest().getLocale() ); giftCardActivationHeader = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".giftCardActivationHeader", getReportRequest().getLocale() ); cardNumberText = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".cardNumberText", getReportRequest().getLocale() ); giftCardActivationFooter1 = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".giftCardActivationFooter1", getReportRequest().getLocale() ); giftCardActivationFooter2 = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".giftCardActivationFooter2", getReportRequest().getLocale() ); giftCardActivationFooter3 = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME + ".giftCardActivationFooter3", getReportRequest().getLocale() ); } else { empText = "Emp"; invoiceText = "INVOICE"; custCopyText = "CUSTOMER COPY"; storeCopyText = "STORE COPY"; duplicateText = "DUPLICATE COPY"; reprintText = "Reprint"; manualText = "Manual"; headerDescText = "Description"; headerQtyText = "Qty"; headerNetText = "Net"; headerTotText = "Total"; subtotalText = "Subtotal"; deliveryText = "Delivery"; miscText = "Miscellaneous"; taxText = "Tax"; totalText = "TOTAL DUE"; originalText = "Original Invoice"; reasonText = "Reason"; dateText = "Date"; amountText = "Amount"; approvedText = "Approved By"; receivedText = "Refund Rec'd By"; customerText = "Customer's Name"; addressText = "Address"; cityText = "City"; stateText = "State"; zipText = "ZIP"; phoneText = "Telephone"; receiptText1 = "RECEIPT REQUIRED"; receiptText2 = "FOR RETURNS"; warrantyText1 = "WARRANTY INFORMATION"; warrantyText2 = "AVAILABLE"; warrantyText3 = "ON REQUEST"; amountReceivedText = "Amount Received"; paymentReceivedText = "Payment Received"; discountText = "Discount"; paymentReceivedInvoicesText = "Payment received for the following invoices"; signatureText = "Customer Signature"; cardAgreementText1 = "I agree to pay total amount"; cardAgreementText2 = "according to card issuer agreement."; giftCardActivationHeader = "GIFT CARD ACTIVATION"; cardNumberText = "Card number"; giftCardActivationFooter1 = "Gift Cards cannot be exchanged or refunded"; giftCardActivationFooter2 = "Please see back of card for information"; giftCardActivationFooter3 = "and conditions for use"; } } private void printHeaderLines( PrintableInvoiceVO piVO ) { // Note that the NAPA logo has already been printed at the end of // the previous invoice InvoiceUtil.compressAddressLines( piVO.getStoreAddressVO(), 3 ); FwoPhonePattern phoneNumber = (FwoPhonePattern) FwoPattern.getPhonePatternInstance( getReportRequest().getLocale() ); StringBuffer storeNameSB = new StringBuffer(); storeNameSB.append( (String) commandCodes.get( "EMPHASIZE_BEGIN" ) ); storeNameSB.append( (String) commandCodes.get( "HEIGHT_DOUBLE_WIDTH_DOUBLE" ) ); storeNameSB.append( (String) commandCodes.get( "CPI_24" ) ); storeNameSB.append( PrintFormat.format( piVO.getStoreName(), 28, PrintFormat.CENTER_JUSTIFIED ) ); storeNameSB.append( (String) commandCodes.get( "CPI_17" ) ); storeNameSB.append( (String) commandCodes.get( "HEIGHT_SINGLE_WIDTH_SINGLE" ) ); storeNameSB.append( (String) commandCodes.get( "EMPHASIZE_END" ) ); StringBuffer storePhoneSB = new StringBuffer(); storePhoneSB.append( (String) commandCodes.get( "EMPHASIZE_BEGIN" ) ); storePhoneSB.append( (String) commandCodes.get( "HEIGHT_DOUBLE_WIDTH_DOUBLE" ) ); storePhoneSB.append( (String) commandCodes.get( "CPI_24" ) ); try { storePhoneSB.append( PrintFormat.format( phoneNumber.format( piVO.getStorePhone() ), 28, PrintFormat.CENTER_JUSTIFIED ) ); } catch (PhonePatternFormatException phonePatternFormatException) { storePhoneSB.append( PrintFormat.format( piVO.getStorePhone(), 28, PrintFormat.CENTER_JUSTIFIED ) ); } storePhoneSB.append( (String) commandCodes.get( "CPI_17" ) ); storePhoneSB.append( (String) commandCodes.get( "HEIGHT_SINGLE_WIDTH_SINGLE" ) ); storePhoneSB.append( (String) commandCodes.get( "EMPHASIZE_END" ) ); // Header Line 1 if (piVO.getStoreName() != null) { appendInvoiceText( storeNameSB.toString() ); appendInvoiceText( PrintFormat.LINE_BREAK ); } if (piVO.getStorePhone() != null) { appendInvoiceText( storePhoneSB.toString() ); } // Header Line 2 if (piVO.getStoreAddressVO().getAddress1() != null) { appendInvoiceText( PrintFormat.format( piVO.getStoreAddressVO().getAddress1(), 43, PrintFormat.CENTER_JUSTIFIED ) ); } // Header Line 3 if ((piVO.getStoreAddressVO().getAddress2() != null) && (piVO.getStoreAddressVO().getAddress2().length() > 0)) { appendInvoiceText( PrintFormat.format( piVO.getStoreAddressVO().getAddress2(), 43, PrintFormat.CENTER_JUSTIFIED ) ); } // Header Line 4 if (piVO.getStoreAddressVO().getCityStateZip() != null) { appendInvoiceText( PrintFormat.format( piVO.getStoreAddressVO().getCityStateZip(), 43, PrintFormat.CENTER_JUSTIFIED ) ); } appendInvoiceText( PrintFormat.LINE_BREAK ); } private void printCustomerLines( PrintableInvoiceVO piVO ) { // Employee and Invoice Info InvoiceUtil.compressAddressLines( piVO.getCustomerAddressVO(), 3 ); String modifiedDate = piVO.getInvoiceDate(); appendInvoiceText( PrintFormat.format( empText + "." + PrintFormat.format( piVO.getCounterEmployeeNum(), 6 ) + modifiedDate + PrintFormat.SPACE + piVO.getInvoiceTime() + " (" + PrintFormat.format( piVO.getCurrentAcctDay(), 2, PrintFormat.ZERO_FILL ) + ")", 43, PrintFormat.CENTER_JUSTIFIED ) ); appendInvoiceText( PrintFormat.LINE_BREAK ); appendInvoiceText( PrintFormat.LINE_BREAK + (String) commandCodes.get( "HEIGHT_DOUBLE_WIDTH_DOUBLE" ) ); appendInvoiceText( PrintFormat.format( " " + invoiceText + " " + piVO.getInvoiceNumber(), 43 ) ); appendInvoiceText( (String) commandCodes.get( "HEIGHT_SINGLE_WIDTH_SINGLE" ) + (String) commandCodes.get( "CLEAR_PRINT_BUFFER" ) + (String) commandCodes.get( "INK_BLACK" ) ); // Customer Line 1 appendInvoiceText( PrintFormat.format( piVO.getCustomerNumber(), 6 ) + InvoiceUtil.getSpaces( 2 ) + PrintFormat.format( piVO.getCustomerName(), 35 ) ); // Customer Line 2 if (piVO.getCustomerAddressVO().getAddress1() != null && piVO.getCustomerAddressVO().getAddress1().length() > 0) { appendInvoiceText( InvoiceUtil.getSpaces( 8 ) + PrintFormat.format( piVO.getCustomerAddressVO().getAddress1(), 35 ) ); } // Customer Line 3 if (piVO.getCustomerAddressVO().getAddress2() != null && piVO.getCustomerAddressVO().getAddress2().length() > 0) { appendInvoiceText( InvoiceUtil.getSpaces( 8 ) + PrintFormat.format( piVO.getCustomerAddressVO().getAddress2(), 35 ) ); } // Customer Line 4 if (piVO.getCustomerAddressVO().getCityStateZip() != null) { appendInvoiceText( InvoiceUtil.getSpaces( 8 ) + PrintFormat.format( piVO.getCustomerAddressVO().getCityStateZip(), 35 ) ); } appendInvoiceText( PrintFormat.LINE_BREAK ); appendInvoiceText( PrintFormat.format( headerDescText, 16, PrintFormat.LEFT_JUSTIFIED ) + InvoiceUtil.getSpaces( 4 ) + PrintFormat.format( headerQtyText, 3, PrintFormat.RIGHT_JUSTIFIED ) + InvoiceUtil.getSpaces( 2 ) + PrintFormat.format( headerNetText, 7, PrintFormat.RIGHT_JUSTIFIED ) + PrintFormat.SPACE + PrintFormat.format( headerTotText, 7, PrintFormat.RIGHT_JUSTIFIED ) + InvoiceUtil.getSpaces( 3 ) ); appendInvoiceText( PrintFormat.format( PrintFormat.UNDERLINE_CHAR, 16, PrintFormat.REPEAT_FILL ) + InvoiceUtil.getSpaces( 4 ) + PrintFormat.format( PrintFormat.UNDERLINE_CHAR, 3, PrintFormat.REPEAT_FILL ) + InvoiceUtil.getSpaces( 2 ) + PrintFormat.format( PrintFormat.UNDERLINE_CHAR, 7, PrintFormat.REPEAT_FILL ) + PrintFormat.SPACE + PrintFormat.format( PrintFormat.UNDERLINE_CHAR, 7, PrintFormat.REPEAT_FILL ) + InvoiceUtil.getSpaces( 3 ) ); } protected void printLineItem( PrintableInvoiceLineItemVO piliVO ) { PrintableInvoiceVO piVO = (PrintableInvoiceVO) getPrintableInvoice(); String invoiceNoteFirstLine = null; int noteWidth; // previous line) if (piliVO.getNoteLine() != null) { // invoice_note.text can be 50 characthers. We need to truncate if more than 41 String note = piliVO.getNoteLine().trim(); String invoiceNoteText = piliVO.getInvoiceNoteText(); String refInvoiceNoteText = piliVO.getRefInvoiceNoteText(); noteWidth = note.length(); if (((piliVO.getNoteId() == RefInvoiceNoteType.WLC_AUTHORIZATION_NUMBER || piliVO.getNoteId() == RefInvoiceNoteType.ZERO_QUANTITY_LINE_ITEM) && noteWidth > 43) || (piliVO.getNoteId() == RefInvoiceNoteType.RETURN_MESSAGE)) { appendInvoiceText( PrintFormat.format( refInvoiceNoteText, 43, PrintFormat.CENTER_JUSTIFIED ) ); appendInvoiceText( PrintFormat.format( invoiceNoteText, 43, PrintFormat.CENTER_JUSTIFIED ) ); } else if (piliVO.getNoteId() == RefInvoiceNoteType.WLC_AUTHORIZATION_NUMBER || piliVO.getNoteId() == RefInvoiceNoteType.ZERO_QUANTITY_LINE_ITEM) { appendInvoiceText( PrintFormat.format( note, 43, PrintFormat.CENTER_JUSTIFIED ) ); } else if ((piliVO.getNoteId() == RefInvoiceNoteType.HAZARDOUS_MATERIAL_MESSAGE || piliVO.getNoteId() == RefInvoiceNoteType.NORMAL_MESSAGE) && noteWidth > 41) { invoiceNoteFirstLine = buildInvoiceNoteFirstLine( note ); appendInvoiceText( InvoiceUtil.getSpaces( 2 ) + PrintFormat.format( invoiceNoteFirstLine, 41 ) ); appendInvoiceText( InvoiceUtil.getSpaces( 2 ) + PrintFormat.format( note.substring( invoiceNoteFirstLine.length(), noteWidth ), 41 ) ); } else if( piliVO.getNoteId() == RefInvoiceNoteType.INVENTORY_NOTE){ List splitNotes = InvoiceUtil.splitNoteItem(note, TsoConstant.ITHACA_INV_NOTE_LENGTH); for (String splitNote : splitNotes) { appendInvoiceText(InvoiceUtil.getSpaces(2) + PrintFormat.format(splitNote, TsoConstant.ITHACA_INV_NOTE_LENGTH)); } }else { if (piliVO.getNoteId() == RefInvoiceNoteType.NAPA_REWARD_PROGRAM) { if(firstRewardNoteLine){ appendInvoiceText( PrintFormat.LINE_BREAK ); firstRewardNoteLine =false; } appendInvoiceText( (String) commandCodes.get( "EMPHASIZE_BEGIN" )); } if (noteWidth > 41) { note = note.substring( 0, 41 ); } appendInvoiceText( InvoiceUtil.getSpaces( 2 ) + PrintFormat.format( note, 41 ) ); if (piliVO.getNoteId() == RefInvoiceNoteType.NAPA_REWARD_PROGRAM) { appendInvoiceText( (String) commandCodes.get( "EMPHASIZE_END" )); } } } else { // Line 1 // Negative indicators appear to the right of the Qty only. The Net and Total amounts // are always expressed as positive values regardless. Credit amounts are indicated in // the // total lines. Hashtable hashtable = ((GenericReportRequest) getReportRequest()).getInputParameters(); PrinterVO printerVO = (PrinterVO) hashtable.get( "PRINTER" ); String description = PrintUtil.getDescription( printerVO, piliVO, piliVO.getPartDescription(), 16 ); if (description.length() > 16) { description = description.substring( 0, 16 ); } String quantity = piliVO.getQuantityBilled(); String quantitySpace = " "; if (quantity != null && !quantity.trim().equals( "" )) { if (quantity.charAt( 0 ) == '-') { quantity = quantity.substring( 1 ); quantitySpace = "- "; } if (new BigDecimal( quantity.substring( quantity.indexOf( "." ) + 1 ) ).signum() != 0) { if (quantity.length() > 3) { quantity = quantity.substring( 0, 3 ); } } else { quantity = quantity.substring( 0, quantity.indexOf( "." ) ); } } String unitNetPrice = piliVO.getUnitNetPrice(); if (unitNetPrice != null && !unitNetPrice.trim().equals( "" )) { if (unitNetPrice.charAt( 0 ) == '-') { unitNetPrice = unitNetPrice.substring( 1 ); } //we are doing this because net price is 4 decimal places and we only want to display 2 if (unitNetPrice.indexOf( "." ) != -1) { DecimalFormat decimalFormat = new DecimalFormat("0.00"); unitNetPrice = decimalFormat.format(new BigDecimal(unitNetPrice)); } } String unitTotalPrice = piliVO.getUnitTotalPrice(); String unitTotalPriceSign = " "; if (unitTotalPrice != null && unitTotalPrice.charAt( 0 ) == '-') { unitTotalPrice = unitTotalPrice.substring( 1 ); unitTotalPriceSign = "-"; } // Display unit total price only to 2 decimal place if (unitTotalPrice != null && unitTotalPrice.indexOf( "." ) != -1) { int lastIndex = unitTotalPrice.indexOf( "." ) + 3; unitTotalPrice = unitTotalPrice.substring( 0, lastIndex ); } String taxCode = InvoiceUtil.getSpaces( 2 ); if (piliVO.getTaxableItem() != null && piliVO.getTaxableItem().equalsIgnoreCase( "Y" )) { taxCode = " T"; } appendInvoiceText( PrintFormat.format( description, 16, PrintFormat.LEFT_JUSTIFIED ) + InvoiceUtil.getSpaces( 4 ) + PrintFormat.format( quantity, 3, PrintFormat.RIGHT_JUSTIFIED ) + quantitySpace + PrintFormat.format( unitNetPrice, 7, PrintFormat.RIGHT_JUSTIFIED ) + PrintFormat.SPACE + PrintFormat.format( unitTotalPrice, 7, PrintFormat.RIGHT_JUSTIFIED ) + unitTotalPriceSign + taxCode ); // Line 2 /* * Do not print line abbrev and part number in the second line for core pending return report */ if (!piVO.isCoresPendingReturnReport().booleanValue()) { appendInvoiceText( InvoiceUtil.getSpaces( 2 ) + PrintFormat.format( piliVO.getLineAbbrev(), 3 ) + PrintFormat.SPACE + PrintFormat.format( piliVO.getPartNumber(), 37 ) ); } else if (piliVO.getPartNumber() != null && !piliVO.getPartNumber().equals( "" )) { appendInvoiceText( PrintFormat.LINE_BREAK ); } } if (!piVO.isCoresPendingReturnReport().booleanValue()) { appendInvoiceText( PrintFormat.LINE_BREAK ); } } private void printROADetail( PrintableInvoiceVO piVO, Vector invoicePayments, Vector invoiceROALineItems, Vector invoiceLineItems ) throws ApplicationException { while (j < MAX_LINE_ITEMS) { if (!roaPaymentsPrinted) { printPaymentReceived( piVO ); for (; j < MAX_LINE_ITEMS && k < numPayments; j++, k++) { PrintableInvoicePaymentVO pipVO = (PrintableInvoicePaymentVO) invoicePayments.elementAt( k ); printROAPayments( pipVO, piVO ); } if (piVO.getROADiscount() != null && piVO.getROADiscount().length() > 0) { printDiscountAmount( piVO ); } if (j >= MAX_LINE_ITEMS) { break; } if (k >= numPayments) { roaPaymentsPrinted = true; k = 0; if (invoiceROALineItems != null) { appendInvoiceText( PrintFormat.format( paymentReceivedInvoicesText + ":", MAX_LINE_WIDTH ) ); j++; } } } // end if(!roaPaymentsPrinted) // Print Invoice numbers to which the payments apply (up to MAX_ROAS_PER_LINE) StringBuffer invoiceNumbersToPrint = new StringBuffer( 500 ); StringBuffer invoiceNumbersInOneLine = new StringBuffer( 50 ); StringBuffer tempInvoiceNumbers = null; if (invoiceROALineItems != null) { if (roaPaymentsPrinted && !roaInfoPrinted) { for (; j < MAX_LINE_ITEMS && k < numROALines; j++) { for (int x = 0; j < MAX_LINE_ITEMS && k < numROALines; x++, k++) { PrintableInvoiceRoaVO piROAVO = (PrintableInvoiceRoaVO) invoiceROALineItems.elementAt( k ); tempInvoiceNumbers = new StringBuffer( 50 ); if (k == 0) { tempInvoiceNumbers.append( InvoiceUtil.getSpaces( 2 ) ); tempInvoiceNumbers.append( "(" ); } if (k != numROALines - 1) { tempInvoiceNumbers.append( piROAVO.getInvoicePaid() ).append( ", " ); } else { tempInvoiceNumbers.append( piROAVO.getInvoicePaid() ); } if (invoiceNumbersInOneLine.length() + tempInvoiceNumbers.length() > MAX_LINE_WIDTH) { invoiceNumbersToPrint.append( PrintFormat.format( invoiceNumbersInOneLine, MAX_LINE_WIDTH ) ); tempInvoiceNumbers.insert( 0, InvoiceUtil.getSpaces( 3 ) ); invoiceNumbersInOneLine = new StringBuffer( 50 ); } invoiceNumbersInOneLine.append( tempInvoiceNumbers ); } } invoiceNumbersInOneLine.append( ")" ); invoiceNumbersToPrint.append( PrintFormat.format( invoiceNumbersInOneLine, MAX_LINE_WIDTH ) ); appendInvoiceText( invoiceNumbersToPrint.toString() ); if (j >= MAX_LINE_ITEMS) { break; } if (k >= numROALines) { roaInfoPrinted = true; k = 0; } } // end if (roaPaymentsPrinted && !roaInfoPrinted) if (j >= MAX_LINE_ITEMS) { break; } } // end if(invoiceROALineItems != null) // Any other messages follow ROA detail (should just be notes) if (invoiceLineItems != null) { if (roaPaymentsPrinted && roaInfoPrinted && !roaNotesPrinted) { for (; j < MAX_LINE_ITEMS && k < numLineItems; j++, k++) { PrintableInvoiceLineItemVO piliVO = (PrintableInvoiceLineItemVO) piVO.getLineItems().get( k ); printLineItem( piliVO ); } if (j >= MAX_LINE_ITEMS) { break; } if (k >= numLineItems) { roaNotesPrinted = true; // don't reset j or k here break; } } } // We're done break; } // end while j < MAX_LINE_ITEMS // reset for the 2nd loop roaPaymentsPrinted = false; roaInfoPrinted = false; roaNotesPrinted = false; } /** * This method prints the discount amount on the Invoice form. * * @param printableInvoice Contains invoice information. */ private void printDiscountAmount( PrintableInvoiceVO printableInvoice ) { StringBuffer discount = new StringBuffer( 50 ); discount.append( PrintFormat.format( discountText, 21, PrintFormat.LEFT_JUSTIFIED ) ); discount.append( PrintFormat.format( printableInvoice.getROADiscount(), 11, PrintFormat.RIGHT_JUSTIFIED ) ); discount.append( InvoiceUtil.getSpaces( 11 ) ); appendInvoiceText( discount.toString() ); } /** * This method prints the payment received amount on the invoice form. * * @param printableInvoice Contains invoice information. */ private void printPaymentReceived( PrintableInvoiceVO printableInvoice ) { StringBuffer paymentReceived = new StringBuffer( 50 ); paymentReceived.append( PrintFormat.format( paymentReceivedText, 20, PrintFormat.LEFT_JUSTIFIED ) ); paymentReceived.append( InvoiceUtil.getSpaces( 10 ) ); paymentReceived.append( PrintFormat.format( printableInvoice.getInvoiceTotal(), 10, PrintFormat.RIGHT_JUSTIFIED ) ); paymentReceived.append( InvoiceUtil.getSpaces( 3 ) ); appendInvoiceText( paymentReceived.toString() ); } private void printROAPayments( PrintableInvoicePaymentVO pipVO, PrintableInvoiceVO piVO ) throws ApplicationException { BigDecimal amountReceived; BigDecimal roaDiscount; BigDecimal invoiceTotal; logger.debug( "Tender type is: " + pipVO.getTenderTypeID() ); int tenderTypeId = pipVO.getTenderTypeID(); String tenderTypeDesc = PrintUtil.getTenderTypeDescription( tenderTypeId, getReportRequest().getLocale().getLanguage() ); StringBuffer amountReceivedSb = new StringBuffer( 200 ); if (tenderTypeDesc != null) { if ((piVO.getInvoiceTotal() != null) && (piVO.getInvoiceTotal().length() > 0)) { invoiceTotal = InvoiceUtil.getBigDecimal( piVO.getInvoiceTotal(), getReportRequest().getLocale() ); } else { invoiceTotal = new BigDecimal( 0.00 ); } if ((piVO.getROADiscount() != null) && (piVO.getROADiscount().length() > 0)) { roaDiscount = InvoiceUtil.getBigDecimal( piVO.getROADiscount(), getReportRequest().getLocale() ); } else { roaDiscount = new BigDecimal( 0.00 ); } amountReceived = invoiceTotal.subtract( roaDiscount ); appendInvoiceText( PrintFormat.format( amountReceivedText, 21, PrintFormat.LEFT_JUSTIFIED ) + PrintFormat.format( InvoiceUtil.getFormattedCurrencyAmount( getReportRequest().getLOC(), amountReceived ), 11, PrintFormat.RIGHT_JUSTIFIED ) ); appendInvoiceText( InvoiceUtil.getSpaces( 11 ) ); amountReceivedSb.append( InvoiceUtil.getSpaces( 2 ) ); amountReceivedSb.append( "(" ); switch (pipVO.getTenderTypeID()) { case RefTenderType.CASH: case RefTenderType.COUPON: case RefTenderType.GIFT_CERTIFICATE: amountReceivedSb.append( tenderTypeDesc ); break; case RefTenderType.CHECK: case RefTenderType.ELECTRONIC_FUNDS_TRANSFER: amountReceivedSb.append( tenderTypeDesc ); if (!("".equals( pipVO.getCreditCardCheckNumber() ))) { amountReceivedSb.append( InvoiceUtil.getSpaces( 1 ) ).append( pipVO.getCreditCardCheckNumber() ); } break; case RefTenderType.VISA: case RefTenderType.MASTER_CARD: case RefTenderType.AMERICAN_EXPRESS: case RefTenderType.DISCOVER: case RefTenderType.PIN_DEBIT: case RefTenderType.AMERICAN_EXPRESS_CORPORATE: amountReceivedSb.append( tenderTypeDesc ); if (!("".equals( pipVO.getMaskedCreditCardCheckNumber() ))) { String creditCardMask = pipVO.getMaskedCreditCardCheckNumber() + InvoiceUtil.getSpaces( 1 ) + pipVO.getAuthorizationNumber(); amountReceivedSb.append( InvoiceUtil.getSpaces( 1 ) ).append( creditCardMask ); } break; default: // Other // sb.append(otherText); break; } amountReceivedSb.append( ")" ); logger.debug( "Payment Received = " + invoiceTotal ); logger.debug( "Amount Tendered = " + pipVO.getAmountTendered() ); logger.debug( "Amount Received = " + amountReceived ); logger.debug( "Discount = " + roaDiscount ); } appendInvoiceText( PrintFormat.format( amountReceivedSb.toString(), 40, PrintFormat.LEFT_JUSTIFIED ) + InvoiceUtil.getSpaces( 3 ) ); } private void printTotalLines( PrintableInvoiceVO printableInvoice ) throws ApplicationException { if ((printableInvoice.getInvoiceSubTotal() != null) && (printableInvoice.getInvoiceSubTotal().length() > 0)) { printSubtotal( printableInvoice ); } if ((printableInvoice.getMiscAdjustments() != null) && (printableInvoice.getMiscAdjustments().length() > 0) && !printableInvoice.isROA()) { printMiscCharges( printableInvoice ); } if ((printableInvoice.getDeliveryCharge() != null) && (printableInvoice.getDeliveryCharge().length() > 0) && !printableInvoice.isROA()) { printDelivery( printableInvoice ); } if ((printableInvoice.getInvoiceTaxAmount1() != null) && (printableInvoice.getInvoiceTaxAmount1().length() > 0) && !printableInvoice.isROA()) { printPrimaryTax( printableInvoice ); } if ((printableInvoice.getInvoiceTaxAmount2() != null) && (printableInvoice.getInvoiceTaxAmount2().length() > 0) && !printableInvoice.isROA()) { printSecondaryTax( printableInvoice ); } printTotal( printableInvoice ); } /** * This method prints the subtotal amount on the invoice form. * * @param printableInvoice Contains invoice information. */ private void printSubtotal( PrintableInvoiceVO printableInvoice ) { StringBuffer subtotalStringBuffer = null; String subtotal = printableInvoice.getInvoiceSubTotal(); if (!printableInvoice.isROA()) { if (subtotal != null && !printableInvoice.getInvoiceTotal().equals( "" )) { subtotalStringBuffer = new StringBuffer( 50 ); if (subtotal.charAt( 0 ) == '-') { subtotalStringBuffer.append( InvoiceUtil.getSpaces( 6 ) ); subtotalStringBuffer.append( PrintFormat.format( subtotalText, 25, PrintFormat.LEFT_JUSTIFIED ) ); subtotalStringBuffer.append( PrintFormat.format( subtotal.substring( 1 ), 9, PrintFormat.RIGHT_JUSTIFIED ) ); subtotalStringBuffer.append( PrintFormat.SPACE ); subtotalStringBuffer.append( PrintFormat.format( AMT_MODIFIER, 2 ) ); } else { subtotalStringBuffer.append( InvoiceUtil.getSpaces( 6 ) ); subtotalStringBuffer.append( PrintFormat.format( subtotalText, 25, PrintFormat.LEFT_JUSTIFIED ) ); subtotalStringBuffer.append( PrintFormat.format( subtotal, 9, PrintFormat.RIGHT_JUSTIFIED ) ); subtotalStringBuffer.append( InvoiceUtil.getSpaces( 3 ) ); } } } else { if (printableInvoice.getInvoiceTotal() != null && !printableInvoice.getInvoiceTotal().equals( "" )) { subtotalStringBuffer = new StringBuffer( 50 ); if (printableInvoice.getInvoiceTotal().charAt( 0 ) == '-') { subtotalStringBuffer.append( InvoiceUtil.getSpaces( 6 ) ); subtotalStringBuffer.append( PrintFormat.format( subtotalText, 25, PrintFormat.LEFT_JUSTIFIED ) ); subtotalStringBuffer.append( PrintFormat.format( printableInvoice.getInvoiceTotal().substring( 1 ), 9, PrintFormat.RIGHT_JUSTIFIED ) ); subtotalStringBuffer.append( PrintFormat.SPACE ); subtotalStringBuffer.append( PrintFormat.format( AMT_MODIFIER, 2 ) ); } else { subtotalStringBuffer.append( InvoiceUtil.getSpaces( 6 ) ); subtotalStringBuffer.append( PrintFormat.format( subtotalText, 25, PrintFormat.LEFT_JUSTIFIED ) ); subtotalStringBuffer.append( PrintFormat.format( printableInvoice.getInvoiceTotal(), 9, PrintFormat.RIGHT_JUSTIFIED ) ); subtotalStringBuffer.append( InvoiceUtil.getSpaces( 3 ) ); } } } if (subtotalStringBuffer != null && subtotalStringBuffer.length() > 0) { appendInvoiceText( subtotalStringBuffer.toString() ); } } private void printDelivery( PrintableInvoiceVO piVO ) { String delivery = piVO.getDeliveryCharge(); String space = InvoiceUtil.getSpaces( 3 ); if (delivery.charAt( 0 ) == '-') { delivery = delivery.substring( 1 ); space = PrintFormat.SPACE + AMT_MODIFIER; } appendInvoiceText( InvoiceUtil.getSpaces( 1 ) + PrintFormat.format( deliveryText, 30, PrintFormat.LEFT_JUSTIFIED ) + PrintFormat.format( delivery, 9, PrintFormat.RIGHT_JUSTIFIED ) + space ); } private void printMiscCharges( PrintableInvoiceVO piVO ) { String misc = piVO.getMiscAdjustments(); String space = InvoiceUtil.getSpaces( 3 ); if (misc.charAt( 0 ) == '-') { misc = misc.substring( 1 ); space = PrintFormat.SPACE + AMT_MODIFIER; } appendInvoiceText( InvoiceUtil.getSpaces( 1 ) + PrintFormat.format( miscText, 30, PrintFormat.LEFT_JUSTIFIED ) + PrintFormat.format( misc, 9, PrintFormat.RIGHT_JUSTIFIED ) + space ); } private void printPrimaryTax( PrintableInvoiceVO piVO ) { String primaryTax = piVO.getSalesTaxPercent(); if (primaryTax != null) { if (piVO.getSalesTaxTableName().length() > 21) { primaryTax = piVO.getSalesTaxTableName().substring( 0, 21 ) + " " + primaryTax + "%"; } else { primaryTax = piVO.getSalesTaxTableName() + " " + primaryTax + "%"; } } else { primaryTax = ""; } String space = InvoiceUtil.getSpaces( 3 ); String taxAmount = piVO.getInvoiceTaxAmount1(); if (taxAmount.charAt( 0 ) == '-') { taxAmount = taxAmount.substring( 1 ); space = PrintFormat.SPACE + AMT_MODIFIER; } appendInvoiceText( InvoiceUtil.getSpaces( 1 ) + PrintFormat.format( primaryTax, 30, PrintFormat.LEFT_JUSTIFIED ) + PrintFormat.format( taxAmount, 9, PrintFormat.RIGHT_JUSTIFIED ) + space ); } private void printSecondaryTax( PrintableInvoiceVO piVO ) { String secondaryTax = piVO.getSecondaryTaxPercent(); if (secondaryTax != null) { if (piVO.getSecondaryTaxTableName().length() > 21) { secondaryTax = piVO.getSecondaryTaxTableName().substring( 0, 21 ) + " " + secondaryTax + "%"; } else { secondaryTax = piVO.getSecondaryTaxTableName() + " " + secondaryTax + "%"; } } else { secondaryTax = ""; } String space = InvoiceUtil.getSpaces( 3 ); String taxAmount = piVO.getInvoiceTaxAmount2(); if (taxAmount.charAt( 0 ) == '-') { taxAmount = taxAmount.substring( 1 ); space = PrintFormat.SPACE + AMT_MODIFIER; } appendInvoiceText( InvoiceUtil.getSpaces( 1 ) + PrintFormat.format( secondaryTax, 30, PrintFormat.LEFT_JUSTIFIED ) + PrintFormat.format( taxAmount, 9, PrintFormat.RIGHT_JUSTIFIED ) + space ); } private void printTotal( PrintableInvoiceVO piVO ) throws ApplicationException { // Make room for the expanded chars appendInvoiceText( PrintFormat.LINE_BREAK + PrintFormat.LINE_BREAK + (String) commandCodes.get( "HEIGHT_DOUBLE_WIDTH_DOUBLE" ) ); if (piVO.getInvoiceTotal().charAt( 0 ) != '-') { appendInvoiceText( PrintFormat.format( totalText, 9 ) + PrintFormat.SPACE + PrintFormat.format( piVO.getInvoiceTotal(), 11, PrintFormat.RIGHT_JUSTIFIED ) + PrintFormat.LINE_BREAK ); } else { appendInvoiceText( (String) commandCodes.get( "INK_RED" ) + PrintFormat.format( totalText, 9 ) + PrintFormat.SPACE + PrintFormat.format( piVO.getInvoiceTotal().substring( 1 ) + PrintFormat.SPACE + AMT_MODIFIER, 11, PrintFormat.RIGHT_JUSTIFIED ) + PrintFormat.LINE_BREAK ); } // Reset size and color appendInvoiceText( (String) commandCodes.get( "HEIGHT_SINGLE_WIDTH_SINGLE" ) + (String) commandCodes.get( "CLEAR_PRINT_BUFFER" ) + (String) commandCodes.get( "INK_BLACK" ) ); PrintableInvoicePaymentVO printableInvoicePayment = null; Object object = null; appendInvoiceText( PrintFormat.LINE_BREAK ); if (piVO.getInvoiceTotal().charAt( 0 ) != '-') { if (piVO.getTransactionTypeID() == RefTransactionType.CHARGE_INVOICE) { if(piVO.isBopis().booleanValue()) { appendInvoiceText( PrintFormat.format( resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, BOPIS_SALE, getReportRequest().getLocale() ), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); } else {appendInvoiceText( PrintFormat.format( resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, CHARGE_SALE, getReportRequest().getLocale() ), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); } } else if (piVO.getInvoicePayments() instanceof Vector) { Vector invoicePayments = piVO.getInvoicePayments(); int invoicePaymentsSize = invoicePayments.size(); for (int i = 0; i < invoicePaymentsSize; i++) { object = invoicePayments.get( i ); if (object instanceof PrintableInvoicePaymentVO) { printableInvoicePayment = (PrintableInvoicePaymentVO) object; appendInvoiceText( getPaymentInformation( printableInvoicePayment, getReportRequest().getLocale() ) ); } } if (piVO.getTransactionTypeID() == RefTransactionType.CASH_INVOICE && piVO.getCashBackAmount() != null && piVO.getCashBackAmount().length() != 0) { printChangeDue( piVO ); } } } else { if (piVO.getTransactionTypeID() == RefTransactionType.CASH_INVOICE) { if (piVO.getInvoicePayments() instanceof Vector) { Vector invoicePayments = piVO.getInvoicePayments(); int invoicePaymentsSize = invoicePayments.size(); for (int i = 0; i < invoicePaymentsSize; i++) { object = invoicePayments.get( i ); if (object instanceof PrintableInvoicePaymentVO) { printableInvoicePayment = (PrintableInvoicePaymentVO) object; appendInvoiceText( getPaymentInformation( printableInvoicePayment, getReportRequest().getLocale() ) ); } } if (piVO.getCashBackAmount() != null && piVO.getCashBackAmount().length() != 0) { printChangeDue( piVO ); } } } else if (piVO.getTransactionTypeID() == RefTransactionType.CHARGE_INVOICE) { appendInvoiceText( PrintFormat.format( resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, CREDIT_MEMO, getReportRequest().getLocale() ), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); } } } private void printFooterLines( PrintableInvoiceVO piVO, int invoiceCopy ) throws ApplicationException { appendInvoiceText( PrintFormat.LINE_BREAK ); if (piVO.getMessageText1().length() > 0) { appendInvoiceText( PrintFormat.format( piVO.getMessageText1(), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); } if (piVO.getMessageText2().length() > 0) { appendInvoiceText( PrintFormat.format( piVO.getMessageText2(), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); } if (piVO.getMessageText3().length() > 0) { appendInvoiceText( PrintFormat.format( piVO.getMessageText3(), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); } appendInvoiceText( PrintFormat.LINE_BREAK ); appendInvoiceText( PrintFormat.format( PrintFormat.format( receiptText1, receiptText1.length() ), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); appendInvoiceText( PrintFormat.format( PrintFormat.format( receiptText2, receiptText2.length() ), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); appendInvoiceText( PrintFormat.LINE_BREAK ); appendInvoiceText( PrintFormat.format( PrintFormat.format( warrantyText1, warrantyText1.length() ), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); appendInvoiceText( PrintFormat.format( PrintFormat.format( warrantyText2, warrantyText2.length() ), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); appendInvoiceText( PrintFormat.format( PrintFormat.format( warrantyText3, warrantyText3.length() ), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); appendInvoiceText( (String) commandCodes.get( "EMPHASIZE_BEGIN" ) + PrintFormat.LINE_BREAK ); switch (invoiceCopy) { case TsoInvoice.REPRINT_INVOICE: if (piVO.isManual()) { appendInvoiceText( PrintFormat.format( ("<< " + PrintFormat.format( manualText, manualText.length() ) + " >>"), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); } else { appendInvoiceText( PrintFormat.format( ("<< " + PrintFormat.format( reprintText, reprintText.length() ) + " >>"), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); } break; case TsoInvoice.CUSTOMER_COPY_INVOICE: appendInvoiceText( PrintFormat.format( ("<< " + PrintFormat.format( custCopyText, custCopyText.length() ) + " >>"), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); break; case TsoInvoice.STORE_COPY_INVOICE: appendInvoiceText( PrintFormat.format( ("<< " + PrintFormat.format( storeCopyText, storeCopyText.length() ) + " >>"), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); break; case TsoInvoice.EXTRA_COPY_INVOICE: appendInvoiceText( PrintFormat.format( ("<< " + PrintFormat.format( duplicateText, duplicateText.length() ) + " >>"), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED ) ); break; } if (piVO.getInvoiceTotal().charAt( 0 ) == '-' && invoiceCopy == TsoInvoice.STORE_COPY_INVOICE) { appendInvoiceText( PrintFormat.LINE_BREAK ); printRefundForm(); appendInvoiceText( PrintFormat.LINE_BREAK ); } appendInvoiceText( (String) commandCodes.get( "EMPHASIZE_END" ) + PrintFormat.LINE_BREAK ); } private void printRefundForm() { int textLength, textLength2, textLength3; int underlineLength, underlineLength2, underlineLength3; textLength = reasonText.length(); underlineLength = (MAX_LINE_WIDTH - (textLength + 1)); // Print the refund form in red color appendInvoiceText( (String) commandCodes.get( "INK_RED" ) ); appendInvoiceText( PrintFormat.format( reasonText, textLength ) + PrintFormat.SPACE + PrintFormat.format( PrintFormat.UNDER_SCORE, underlineLength, PrintFormat.REPEAT_FILL ) + PrintFormat.LINE_BREAK ); textLength = originalText.length(); underlineLength = (MAX_LINE_WIDTH - (textLength + 3)); appendInvoiceText( PrintFormat.format( originalText, textLength ) + " # " + PrintFormat.format( PrintFormat.UNDER_SCORE, underlineLength, PrintFormat.REPEAT_FILL ) + PrintFormat.LINE_BREAK ); textLength = dateText.length(); textLength2 = amountText.length(); underlineLength = 14; underlineLength2 = (MAX_LINE_WIDTH - (textLength + 2 + textLength2 + 2 + underlineLength + 1)); appendInvoiceText( PrintFormat.format( dateText, textLength ) + ": " + PrintFormat.format( PrintFormat.UNDER_SCORE, underlineLength, PrintFormat.REPEAT_FILL ) + PrintFormat.SPACE + PrintFormat.format( amountText, textLength2 ) + ": " + PrintFormat.format( PrintFormat.UNDER_SCORE, underlineLength2, PrintFormat.REPEAT_FILL ) + PrintFormat.LINE_BREAK ); textLength = approvedText.length(); underlineLength = (MAX_LINE_WIDTH - (textLength + 2)); appendInvoiceText( PrintFormat.format( approvedText, textLength ) + ": " + PrintFormat.format( PrintFormat.UNDER_SCORE, underlineLength, PrintFormat.REPEAT_FILL ) + PrintFormat.LINE_BREAK ); textLength = receivedText.length(); underlineLength = (MAX_LINE_WIDTH - (textLength + 2)); appendInvoiceText( PrintFormat.format( receivedText, textLength ) + ": " + PrintFormat.format( PrintFormat.UNDER_SCORE, underlineLength, PrintFormat.REPEAT_FILL ) + PrintFormat.LINE_BREAK ); textLength = customerText.length(); underlineLength = (MAX_LINE_WIDTH - (textLength + 2)); appendInvoiceText( PrintFormat.format( customerText, textLength ) + ": " + PrintFormat.format( PrintFormat.UNDER_SCORE, underlineLength, PrintFormat.REPEAT_FILL ) + PrintFormat.LINE_BREAK ); textLength = addressText.length(); underlineLength = (MAX_LINE_WIDTH - (textLength + 2)); appendInvoiceText( PrintFormat.format( addressText, textLength ) + ": " + PrintFormat.format( PrintFormat.UNDER_SCORE, underlineLength, PrintFormat.REPEAT_FILL ) + PrintFormat.LINE_BREAK ); appendInvoiceText( InvoiceUtil.getSpaces( textLength + 2 ) + PrintFormat.format( PrintFormat.UNDER_SCORE, underlineLength, PrintFormat.REPEAT_FILL ) + PrintFormat.LINE_BREAK ); textLength = cityText.length(); textLength2 = stateText.length(); textLength3 = zipText.length(); underlineLength = 11; underlineLength2 = 6; underlineLength3 = (MAX_LINE_WIDTH - (textLength + 2 + textLength2 + 2 + textLength3 + 2 + underlineLength + 1 + underlineLength2 + 1)); appendInvoiceText( PrintFormat.format( cityText, textLength ) + ": " + PrintFormat.format( PrintFormat.UNDER_SCORE, underlineLength, PrintFormat.REPEAT_FILL ) + PrintFormat.SPACE + PrintFormat.format( stateText, textLength2 ) + ": " + PrintFormat.format( PrintFormat.UNDER_SCORE, underlineLength2, PrintFormat.REPEAT_FILL ) + PrintFormat.SPACE + PrintFormat.format( zipText, textLength3 ) + ": " + PrintFormat.format( PrintFormat.UNDER_SCORE, underlineLength3, PrintFormat.REPEAT_FILL ) + PrintFormat.LINE_BREAK ); textLength = phoneText.length(); underlineLength = (MAX_LINE_WIDTH - (textLength + 2)); appendInvoiceText( PrintFormat.format( phoneText, textLength ) + ": " + PrintFormat.format( PrintFormat.UNDER_SCORE, underlineLength, PrintFormat.REPEAT_FILL ) + PrintFormat.LINE_BREAK ); appendInvoiceText( (String) commandCodes.get( "INK_BLACK" ) ); } /** * This method returns the payment line to print on the invoice. * * @param printableInvoicePayment Contains the payment information for a invoice * @param locale locale of the store. * @return Payment line. * @throws ApplicationException */ private static final String getPaymentInformation( PrintableInvoicePaymentVO printableInvoicePayment, Locale locale ) throws ApplicationException { String creditCardMask = null; StringBuffer paymentLine = null; if (printableInvoicePayment == null) { if (resourceBundleReader == null) { return "NO PAYMENT INFORMATION"; } else { return resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, TSOINVOICE + ".NoPaymentInfo", locale ); } } //Adding Card Holder Name if(printableInvoicePayment.getCardHolderName() != null && printableInvoicePayment.getTenderTypeID() == -1) { paymentLine = new StringBuffer( 50 ); String cardHolderName = (printableInvoicePayment.getCardHolderName().equalsIgnoreCase( TsoConstant.NAME_NOT_AVAILABLE)) ? resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, NAME_NOT_AVAILABLE, locale) : printableInvoicePayment.getCardHolderName(); paymentLine.append( PrintFormat.format( cardHolderName, MAX_LINE_WIDTH, PrintFormat.LEFT_JUSTIFIED ) ); return (paymentLine != null) ? paymentLine.toString() : ""; } //Adding Gift Card Balance to Invoice if(printableInvoicePayment.getGiftCardBalanceAmount() != null && printableInvoicePayment.getTenderTypeID() == -1) { paymentLine = new StringBuffer( 50 ); String giftCardBalance = resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, GIFT_CARD_BALANCE, locale) + " " +printableInvoicePayment.getGiftCardBalanceAmount(); paymentLine.append( InvoiceUtil.getSpaces( 6 )); paymentLine.append( PrintFormat.format( giftCardBalance, 36, PrintFormat.LEFT_JUSTIFIED)); return (paymentLine != null) ? paymentLine.toString() : ""; } int tenderTypeId = printableInvoicePayment.getTenderTypeID(); String tenderTypeDesc = PrintUtil.getTenderTypeDescription( tenderTypeId, locale.getLanguage() ); String amountTendered = printableInvoicePayment.getAmountTendered(); if (tenderTypeDesc != null) { switch (tenderTypeId) { // For Invoice Payment Tender Type cash, coupon, or gift certificate // print the Tender Type Description + " " + Amount Tendered on a payment // information line. case RefTenderType.CASH: case RefTenderType.COUPON: case RefTenderType.GIFT_CERTIFICATE: paymentLine = new StringBuffer( 50 ); paymentLine.append( PrintFormat.format( tenderTypeDesc, 29, PrintFormat.RIGHT_JUSTIFIED ) ); break; // For Invoice Payment record Tender Type check // print Tender Type Description + " " + Invoice Payment Check Number + // " " + Amount Tendered on a payment information line. case RefTenderType.ELECTRONIC_FUNDS_TRANSFER: case RefTenderType.CHECK: paymentLine = new StringBuffer( 50 ); if (!("".equals( printableInvoicePayment.getCreditCardCheckNumber() ))) { paymentLine.append( PrintFormat.format( tenderTypeDesc + InvoiceUtil.getSpaces( 1 ) + printableInvoicePayment.getCreditCardCheckNumber(), 29, PrintFormat.RIGHT_JUSTIFIED ) ); } else { paymentLine.append( PrintFormat.format( tenderTypeDesc, 29, PrintFormat.RIGHT_JUSTIFIED ) ); } break; // For Invoice Payment Tender Type belongs to Credit Card or NAPA Gift Card category // print payment information line as per following rule // i. If invoice profile "Print credit card info on invoice" is no // OR Invoice Payment card number is blank // a. Tender Type Description + " " + Amount Tendered // ii. If invoice profile "Print credit card info on invoice" is yes // and Invoice Payment card number is not blank // a. Tender Type Description + " " + leading asterisks + // last four digits of Invoice Payment card number + " " + Invoice Payment // authorization code + " " + Amount Tendered default: if (PrintUtil.isCreditCard( tenderTypeId ) || PrintUtil.isGiftCard( tenderTypeId )) { paymentLine = new StringBuffer( 50 ); if (!("".equals( printableInvoicePayment.getMaskedCreditCardCheckNumber() ))) { creditCardMask = printableInvoicePayment.getMaskedCreditCardCheckNumber() + InvoiceUtil.getSpaces( 1 ) + printableInvoicePayment.getAuthorizationNumber(); int paymentLineLength = tenderTypeDesc.length() + creditCardMask.length() + 1; if (paymentLineLength <= 29) { paymentLine.append( PrintFormat.format( tenderTypeDesc + InvoiceUtil.getSpaces( 1 ) + creditCardMask, 29, PrintFormat.RIGHT_JUSTIFIED ) ); } else { creditCardMask = creditCardMask.substring( paymentLineLength - 29, creditCardMask.length() ); paymentLine.append( PrintFormat.format( tenderTypeDesc + InvoiceUtil.getSpaces( 1 ) + creditCardMask, 29, PrintFormat.RIGHT_JUSTIFIED ) ); } } else { paymentLine.append( PrintFormat.format( tenderTypeDesc, 29, PrintFormat.RIGHT_JUSTIFIED ) ); } } break; } if (paymentLine != null && amountTendered != null && amountTendered.length() > 0) { if (amountTendered.charAt( 0 ) == '-') { paymentLine.append( PrintFormat.format( amountTendered.substring( 1 ), 10, PrintFormat.RIGHT_JUSTIFIED ) ); paymentLine.append( PrintFormat.SPACE ); paymentLine.append( AMT_MODIFIER ); } else { paymentLine.append( PrintFormat.format( amountTendered, 10, PrintFormat.RIGHT_JUSTIFIED ) ); paymentLine.append( InvoiceUtil.getSpaces( 3 ) ); } } } return (paymentLine != null) ? paymentLine.toString() : ""; } /** * This method prints the change due amount. * * @param printableInvoice contains the Invoice information. * @param refund contains true for the return invoice else false. */ private void printChangeDue( PrintableInvoiceVO printableInvoice ) { StringBuffer changeDue = new StringBuffer( 50 ); changeDue.append( PrintFormat.format( resourceBundleReader.getLocalizedText( ResourceBundleReader.UI, CHANGE_DUE, getReportRequest().getLocale() ), 29, PrintFormat.RIGHT_JUSTIFIED ) ); changeDue.append( PrintFormat.format( printableInvoice.getCashBackAmount(), 11, PrintFormat.RIGHT_JUSTIFIED ) ); changeDue.append( InvoiceUtil.getSpaces( 3 ) ); appendInvoiceText( changeDue.toString() ); } /** * This method builds first line of the invoice note with 41 characters. * * @param invoiceNote contains the Invoice Note information. * * @return String - returns first 41 characters of Invoice Note. */ private String buildInvoiceNoteFirstLine( String invoiceNote ) { StringBuffer buildFirstLine = new StringBuffer( 41 ); StringTokenizer token = new StringTokenizer( invoiceNote ); String word = null; while (token.hasMoreElements()) { word = (String) token.nextElement(); if (buildFirstLine.length() + word.length() < 41) { buildFirstLine.append( word ).append( " " ); } else if (buildFirstLine.length() == 0 && word.length() >= 42) { buildFirstLine.append( word.substring( 0, 41 ) ); break; } else { break; } } return buildFirstLine.toString(); } private final byte IMAGE_WHITE = 1; private final byte IMAGE_BLACK = 0; private void printImage( BufferedImage image ) throws Exception { appendToReportStream( CLEAR_PRINT_BUFFER ); appendToReportStream( ENABLE_HORIZONTAL_GRAPHICS ); final int imageWidth = image.getWidth(); final int imageHeight = image.getHeight(); final ByteArrayOutputStream bOut = new ByteArrayOutputStream( 512 ); for (int y = 0; y < imageHeight; y++) { initImageLine( bOut ); for (int x = 0; x < imageWidth; x++) { final int pixel = image.getRGB( x, y ); final int red = (pixel >> 16) & 0xff; final int green = (pixel >> 8) & 0xff; final int blue = pixel & 0xff; byte printValue = IMAGE_WHITE; if (red == 255 || green == 255 || blue == 255) { printValue = IMAGE_BLACK; } addImagePrintValue( bOut, printValue ); } final byte[] lineData = imageLineDone( bOut ); appendToReportStream( lineData ); } } private void initImageLine( ByteArrayOutputStream bOut ) { bOut.reset(); bOut.write( ESC ); bOut.write( 'h' ); bOut.write( 7 ); // 7 = RGB bOut.write( 0 ); // placeholder for data length bOut.write( 0 ); // 0 = raw data (no compression) totalDataLength = 1; currentBitIndex = 0; currentByte = 0; } private byte totalDataLength = 0; private int currentByte = 0; private int currentBitIndex = 0; private void addImagePrintValue( ByteArrayOutputStream bOut, byte printValue ) throws Exception { if (printValue == IMAGE_BLACK) { currentByte |= (0x80 >>> currentBitIndex); } currentBitIndex++; if (currentBitIndex == 8) { bOut.write( currentByte ); totalDataLength++; currentBitIndex = 0; currentByte = 0; } } private byte[] imageLineDone( ByteArrayOutputStream bOut ) throws Exception { if (currentBitIndex > 0) { bOut.write( currentByte ); totalDataLength++; } final byte[] data = bOut.toByteArray(); data[3] = totalDataLength; return data; } public BufferedImage getScaledImage( BufferedImage srcImage, int targetWidth ) throws IOException { final int srcWidth = srcImage.getWidth(); final int srcHeight = srcImage.getHeight(); if (srcWidth <= targetWidth) { return srcImage; } final double scaleRatio = ((double)targetWidth) / ((double)srcWidth); final int targetHeight = (int) (srcHeight * scaleRatio); return getScaledImage( srcImage, targetWidth, targetHeight ); } private BufferedImage getScaledImage( BufferedImage origImage, int targetWidth, int targetHeight ) { int width = origImage.getWidth(); int height = origImage.getHeight(); BufferedImage returnImage = origImage; do { if (width > targetWidth) { width /= 2; if (width < targetWidth) { width = targetWidth; } } if (height > targetHeight) { height /= 2; if (height < targetHeight) { height = targetHeight; } } final BufferedImage tmp = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB ); final Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC ); g2.drawImage( returnImage, 0, 0, width, height, null ); g2.dispose(); returnImage = tmp; } while (width != targetWidth || height != targetHeight); return returnImage; } private void printGiftCardActivationReceipts(PrintableInvoiceVO printableInvoice, Vector invoiceLineItems, int invoiceCopy) { PrintableInvoiceLineItemVO printableInvoiceLineItemVO = null; if (invoiceLineItems != null && numLineItems > 0) { for (int index = 0; index < numLineItems; index++) { printableInvoiceLineItemVO = (PrintableInvoiceLineItemVO) invoiceLineItems .get(index); if (printableInvoiceLineItemVO != null && printableInvoiceLineItemVO.isGiftCardActivated()) { printGiftCardActivationReceipt(printableInvoice, printableInvoiceLineItemVO, invoiceCopy); } } } } private void printGiftCardActivationReceipt(PrintableInvoiceVO printableInvoice, PrintableInvoiceLineItemVO printableInvoiceLineItemVO, int invoiceCopy) { // Reset the character size appendInvoiceText((String) commandCodes.get("INITIALIZE_PRINTER")); appendInvoiceText((String) commandCodes.get("CLEAR_PRINT_BUFFER")); appendInvoiceText((String) commandCodes.get("CPI_17")); appendInvoiceText((String) commandCodes.get("CLEAR_PRINT_BUFFER")); appendInvoiceText((String) commandCodes.get("HEIGHT_SINGLE_WIDTH_SINGLE")); appendInvoiceText((String) commandCodes.get("CLEAR_PRINT_BUFFER")); appendInvoiceText((String) commandCodes.get("INK_BLACK")); // Print the header, customer and general invoice info first printHeaderLines(printableInvoice); String modifiedDate = printableInvoice.getInvoiceDate(); appendInvoiceText( PrintFormat.format( empText + "." + PrintFormat.format( printableInvoice.getCounterEmployeeNum(), 6 ) + modifiedDate + PrintFormat.SPACE + printableInvoice.getInvoiceTime() + " (" + PrintFormat.format( printableInvoice.getCurrentAcctDay(), 2, PrintFormat.ZERO_FILL ) + ")", 42, PrintFormat.CENTER_JUSTIFIED ) ); appendInvoiceText( PrintFormat.LINE_BREAK ); appendInvoiceText( PrintFormat.LINE_BREAK + (String) commandCodes.get( "HEIGHT_DOUBLE_WIDTH_DOUBLE" ) ); appendInvoiceText( PrintFormat.format( " " + invoiceText + " " + printableInvoice.getInvoiceNumber(), 42 ) ); appendInvoiceText( (String) commandCodes.get( "HEIGHT_SINGLE_WIDTH_SINGLE" ) + (String) commandCodes.get( "CLEAR_PRINT_BUFFER" ) + (String) commandCodes.get( "INK_BLACK" ) ); appendInvoiceText(PrintFormat.LINE_BREAK); appendInvoiceText(PrintFormat.LINE_BREAK); appendInvoiceText(PrintFormat.format(giftCardActivationHeader, MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED)); appendInvoiceText(PrintFormat.LINE_BREAK); String unitTotalPrice = printableInvoiceLineItemVO.getUnitTotalPrice(); String unitTotalPriceSign = " "; if (unitTotalPrice != null && unitTotalPrice.charAt(0) == '-') { unitTotalPrice = unitTotalPrice.substring(1); unitTotalPriceSign = "-"; } // Display unit total price only to 2 decimal place if (unitTotalPrice != null && unitTotalPrice.indexOf(".") != -1) { int lastIndex = unitTotalPrice.indexOf(".") + 3; unitTotalPrice = unitTotalPrice.substring(0, lastIndex); } appendInvoiceText(cardNumberText + InvoiceUtil.getSpaces(1) + "XXXX XXXXX XXXXX" + printableInvoiceLineItemVO.getGiftCardNumber().substring(14) + InvoiceUtil.getSpaces(2) + "$" + unitTotalPrice); appendInvoiceText(PrintFormat.LINE_BREAK); appendInvoiceText(PrintFormat.LINE_BREAK); appendInvoiceText(PrintFormat.format(giftCardActivationFooter1, MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED)); appendInvoiceText(PrintFormat.LINE_BREAK); appendInvoiceText(PrintFormat.format(giftCardActivationFooter2, MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED)); appendInvoiceText(PrintFormat.LINE_BREAK); appendInvoiceText(PrintFormat.format(giftCardActivationFooter3, MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED)); appendInvoiceText(PrintFormat.LINE_BREAK); appendInvoiceText(PrintFormat.LINE_BREAK); if (TsoInvoice.REPRINT_INVOICE == invoiceCopy) { if (printableInvoice.isManual()) { appendInvoiceText(PrintFormat.format( ("<< " + PrintFormat.format(manualText, manualText.length()) + " >>"), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED)); } else { appendInvoiceText(PrintFormat.format( ("<< " + PrintFormat.format(reprintText, reprintText.length()) + " >>"), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED)); } } else if (TsoInvoice.CUSTOMER_COPY_INVOICE == invoiceCopy) { appendInvoiceText(PrintFormat.format( ("<< " + PrintFormat.format(custCopyText, custCopyText.length()) + " >>"), MAX_LINE_WIDTH, PrintFormat.CENTER_JUSTIFIED)); } appendInvoiceText(PrintFormat.LINE_BREAK); // Cut the paper and get ready for the next invoice appendInvoiceText((String) commandCodes.get("EMPHASIZE_BEGIN")); appendInvoiceText((String) commandCodes.get("CLEAR_PRINT_BUFFER")); appendInvoiceText((String) commandCodes.get("MACRO_NAPA")); appendInvoiceText((String) commandCodes.get("CLEAR_PRINT_BUFFER")); appendInvoiceText((String) commandCodes.get("EMPHASIZE_END")); appendInvoiceText((String) commandCodes.get("CLEAR_PRINT_BUFFER")); appendInvoiceText((String) commandCodes.get("AUTO_CUT")); appendInvoiceText(PrintFormat.LINE_BREAK); } private boolean canPrintStoreCopyOfInvoice() { final String methodSpec = "TsoInvoice_Ithaca.canPrintStoreCopyOfInvoice - "; logger.debug(methodSpec); boolean canPrintStoreCopyOfInvoice = false; try { final Hashtable hashtable = ((GenericReportRequest) getReportRequest()) .getInputParameters(); final PrinterVO printerVO = (PrinterVO) hashtable.get("PRINTER"); canPrintStoreCopyOfInvoice = printerVO != null && printerVO.getPrintStoreCopyOfInvoice() != null && printerVO.getPrintStoreCopyOfInvoice().booleanValue(); } catch (Exception exception) { logger.error(methodSpec + "Error occured while fetching Device Assignments : PrintStoreCopyOfInvoice settings " + exception); } logger.debug(methodSpec + "canPrintStoreCopyOfInvoice = " + canPrintStoreCopyOfInvoice); return canPrintStoreCopyOfInvoice; } private boolean isAskForItemReturnCustomerInfoChecked() { final String methodSpec = "TsoInvoice_Ithaca.canPrintStoreCopyOfInvoice - "; logger.debug(methodSpec); boolean isAskForItemReturnCustomerInfoChecked = false; try { final Integer location = ((GenericReportRequest) getReportRequest()).getLOC(); final InvoicingProfileVO invoicingProfileVO = ApplicationContext.getInstance() .getProfile(Profile.SERVER, location).getInvoicingProfile(); isAskForItemReturnCustomerInfoChecked = invoicingProfileVO != null && invoicingProfileVO.getAskForItemReturnCustomerInfo() != null && invoicingProfileVO.getAskForItemReturnCustomerInfo().booleanValue(); } catch (Exception exception) { logger.error(methodSpec + "Error occured while fetching Invoicing Profile : AskForItemReturnCustomerInfo settings " + exception); } logger.debug(methodSpec + "isAskForItemReturnCustomerInfoChecked = " + isAskForItemReturnCustomerInfoChecked); return isAskForItemReturnCustomerInfoChecked; } private boolean canPrintStoreCopyForReturns(final Vector invoiceLineItems) { return isAskForItemReturnCustomerInfoChecked() && doesInvoiceContainReturnItem(invoiceLineItems); } private boolean doesInvoiceContainReturnItem(final Vector invoiceLineItems) { final String methodSpec = "TsoInvoice_Ithaca.doesInvoiceContainReturnItem - "; logger.debug(methodSpec); boolean doesInvoiceContainReturnItem = false; if (invoiceLineItems != null) { final int invoiceLineItemsSize = invoiceLineItems.size(); Object object = null; BaseLineItemVO baseLineItemVO = null; for (int index = 0; index < invoiceLineItemsSize; index++) { object = invoiceLineItems.get(index); if (object instanceof BaseLineItemVO) { baseLineItemVO = (BaseLineItemVO) object; if (baseLineItemVO.getQuantityBilled() != null && baseLineItemVO.getQuantityBilled().signum() < 0) { doesInvoiceContainReturnItem = true; break; } } } } logger.debug(methodSpec + "doesInvoiceContainReturnItem = " + doesInvoiceContainReturnItem); return doesInvoiceContainReturnItem; } }