Package com.plainsource.commons.text.template.token

Examples of com.plainsource.commons.text.template.token.TokenList


    }

    private TokenList createInvoiceLinesHeader() {

        // Invoice line header
        TokenList invoiceLineHeaderTokens = new TokenList("invoiceLineHeaderTokens", new ArrayList<Tokenizer>());
        invoiceLineHeaderTokens.addToken(new Token(
                TextLabel.INV_ITEM_DESCRIPTION_LABEL.toLowerCase(),
                TextLabel.INV_ITEM_DESCRIPTION_LABEL.toString(locale)));

        // depending on the configuration, adds the unit code as a field of the invoice line header
        if (ubl4JConfigurationBean.isIncludeQuantityUnitInInvoiceLine()) {
            invoiceLineHeaderTokens.addToken(new Token(
                    TextLabel.INV_ITEM_UNIT_LABEL.toLowerCase(),
                    TextLabel.INV_ITEM_UNIT_LABEL.toString(locale)));
        }

        invoiceLineHeaderTokens.addToken(new Token(
                TextLabel.INV_ITEM_QUANTITY_LABEL.toLowerCase(),
                TextLabel.INV_ITEM_QUANTITY_LABEL.toString(locale)));
        invoiceLineHeaderTokens.addToken(new Token(
                TextLabel.INV_ITEM_PRICE_LABEL.toLowerCase(),
                TextLabel.INV_ITEM_PRICE_LABEL.toString(locale)));
        invoiceLineHeaderTokens.addToken(new Token(
                TextLabel.INV_ITEM_SUBTOTAL_LABEL.toLowerCase(),
                TextLabel.INV_ITEM_SUBTOTAL_LABEL.toString(locale)));

        // depending on the configuration, adds the vat rate as a field of the invoice line header
        if (ubl4JConfigurationBean.isIncludeVatRateInInvoiceLine()) {
            invoiceLineHeaderTokens.addToken(new Token(
                    TextLabel.INV_ITEM_VAT_RATE_LABEL.toLowerCase(),
                    TextLabel.INV_ITEM_VAT_RATE_LABEL.toString(locale)));
        }

        invoiceLineHeaderTokens.addToken(new Token(
                TextLabel.INV_ITEM_VAT_LABEL.toLowerCase(),
                TextLabel.INV_ITEM_VAT_LABEL.toString(locale)));
        invoiceLineHeaderTokens.addToken(new Token(
                TextLabel.INV_ITEM_TOTAL_LABEL.toLowerCase(),
                TextLabel.INV_ITEM_TOTAL_LABEL.toString(locale)));
        return invoiceLineHeaderTokens;
    }
View Full Code Here


    private void addInvoiceLinesTokens() {
        template.addToken(createInvoiceLinesHeader());

        // Invoice lines
        TokenList invoiceLineTokens;
        for (InvoiceLineType invoiceLineType : invoiceType.getInvoiceLine()) {
            invoiceLineTokens = new TokenList("invoiceLineTokens", new ArrayList<Tokenizer>());
            if (invoiceLineType.getItem() != null) {
                Iterator<DescriptionType> descriptions = invoiceLineType.getItem().getDescription().iterator();
                StringBuffer sb = new StringBuffer();
                while (descriptions.hasNext()) {
                    sb.append(descriptions.next().getValue());
                }
                invoiceLineTokens.addToken(new Token(
                        TextLabel.INV_ITEM_DESCRIPTION.toLowerCase(), sb.toString()));
            }

            // Item Quantity
            QuantityConverter quantityConverter =
                    convertInvoiceQuantityIfRequired(invoiceLineType.getInvoicedQuantity(),
                            invoiceLineType.getPrice(), locale, ubl4JConfigurationBean);
            if (quantityConverter.getInvoicedQuantityType() != null) {
                NumberWrapper quantity = new NumberWrapper(quantityConverter.getInvoicedQuantityType().getValue());
                quantity.setLocale(locale);

                // Adding the unit code either as a field in the invoice line or as a single token.
                // It is more practical to add the unit code as a single toke when all invoice lines
                // share the same unit code; or when there is only one invoice line
                String unitCode = quantityConverter.getInvoicedQuantityType().getUnitCode();
                if (ubl4JConfigurationBean.isIncludeQuantityUnitInInvoiceLine()) {
                    invoiceLineTokens.addToken(new Token(
                            TextLabel.INV_ITEM_UNIT.toLowerCase(), unitCode));
                } else {
                    template.addToken(new Token(TextLabel.INV_ITEM_UNIT.toLowerCase(), unitCode));
                }
                invoiceLineTokens.addToken(new Token(
                        TextLabel.INV_ITEM_QUANTITY.toLowerCase(), quantity.format()));
            }

            // Item Price
            PriceType price = quantityConverter.getPriceType();
            PriceAmountType priceAmount = null;
            if (price != null) {
                priceAmount = price.getPriceAmount();
                if (priceAmount != null) {
                    invoiceLineTokens.addToken(new Token(
                            TextLabel.INV_ITEM_PRICE.toLowerCase(),
                            new CurrencyDecimal(priceAmount.getValue(), invoiceTypeCurrency, locale).format()));
                }
            }

            BigDecimal lineExtensionAmount = invoiceLineType.getLineExtensionAmount().getValue();
            invoiceLineTokens.addToken(new Token(
                    TextLabel.INV_ITEM_SUBTOTAL.toLowerCase(),
                    new CurrencyDecimal(lineExtensionAmount, invoiceTypeCurrency, locale).format()));

            // Tax rate  (VAT Rate)
            // Adding the VAT rate either as a field in the invoice line or as a single token.
            if (invoiceLineType.getItem().getClassifiedTaxCategory().size() > 0) {
                Token vatRateToken = new Token(TextLabel.INV_ITEM_VAT_RATE.toLowerCase(),
                        getTaxRateAsFormattedNumber(invoiceLineType, locale).format());
                if (ubl4JConfigurationBean.isIncludeVatRateInInvoiceLine()) {
                    invoiceLineTokens.addToken(vatRateToken);
                } else {
                    template.addToken(vatRateToken);
                }
            }

            BigDecimal taxTotal = invoiceLineType.getTaxTotal().get(0).getTaxAmount().getValue();
            invoiceLineTokens.addToken(new Token(TextLabel.INV_ITEM_VAT.toLowerCase(),
                    new CurrencyDecimal(taxTotal, invoiceTypeCurrency, locale).format()));

            BigDecimal total = lineExtensionAmount.add(taxTotal);
            invoiceLineTokens.addToken(new Token(TextLabel.INV_ITEM_TOTAL.toLowerCase(),
                    new CurrencyDecimal(total, invoiceTypeCurrency, locale).format()));
            template.addToken(invoiceLineTokens);
        }
    }
View Full Code Here

TOP

Related Classes of com.plainsource.commons.text.template.token.TokenList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.