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

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


        PartyType partyType = supplierParty ? invoiceType.getAccountingSupplierParty().getParty() :
                invoiceType.getAccountingCustomerParty().getParty();

        if (supplierParty) {
            template.addToken(new Token(TextLabel.SUPPLIER_NAME_LABEL.toLowerCase(),
                    TextLabel.SUPPLIER_NAME_LABEL.toString(locale)));
        } else {
            template.addToken(new Token(TextLabel.CUSTOMER_NAME_LABEL.toLowerCase(),
                    TextLabel.CUSTOMER_NAME_LABEL.toString(locale)));
        }

        if (partyType != null) {
            addPartyNameAndIDTokens(partyType, supplierParty);
            // Address
            AddressType address = partyType.getPostalAddress();
            if (address != null) {
                if (supplierParty) {
                    template.addToken(new Token(TextLabel.SUPPLIER_ADDRESS.toLowerCase(),
                            InvoiceTypeParser.parseAddressType(address)));
                } else {
                    template.addToken(new Token(TextLabel.CUSTOMER_ADDRESS.toLowerCase(),
                            InvoiceTypeParser.parseAddressType(address)));
                }
            }
            // Contact
            ContactType contactType = partyType.getContact();
            if (contactType != null) {
                addContactTokens(contactType, supplierParty);
            }

            // Website
            if (supplierParty) {
                template.addToken(new Token(
                        TextLabel.SUPPLIER_WEBSITE_URL_LABEL.toLowerCase(),
                        TextLabel.SUPPLIER_WEBSITE_URL_LABEL.toString(locale)));
                WebsiteURIType websiteURIType = partyType.getWebsiteURI();
                if (websiteURIType != null) {
                    template.addToken(new Token(
                            TextLabel.SUPPLIER_WEBSITE_URL.toLowerCase(),
                            InvoiceTypeParser.parseWebsiteURIType(websiteURIType)));
                }
            } else {
                template.addToken(new Token(
                        TextLabel.CUSTOMER_WEBSITE_URL_LABEL.toLowerCase(),
                        TextLabel.CUSTOMER_WEBSITE_URL_LABEL.toString(locale)));
                template.addToken(new Token(TextLabel.CUSTOMER_WEBSITE_URL.toLowerCase(),
                        InvoiceTypeParser.parseWebsiteURIType(partyType.getWebsiteURI())));
            }
            // Logo
            if (supplierParty) {
                template.addToken(new Token(TextLabel.SUPPLIER_LOGO.toLowerCase(),
                        InvoiceTypeParser.parseLogoReferenceID(partyType.getLogoReferenceID())));
            }
            // VAT
            if (supplierParty) {
                template.addToken(new Token(TextLabel.SUPPLIER_VAT_LABEL.toLowerCase(),
                        TextLabel.SUPPLIER_VAT_LABEL.toString(locale)));
                template.addToken(new Token(TextLabel.SUPPLIER_VAT.toLowerCase(),
                        InvoiceTypeParser.parsePartyTaxSchemeType(partyType.getPartyTaxScheme())));
            } else {
                template.addToken(new Token(TextLabel.CUSTOMER_VAT_LABEL.toLowerCase(),
                        TextLabel.CUSTOMER_VAT_LABEL.toString(locale)));
                template.addToken(new Token(TextLabel.CUSTOMER_VAT.toLowerCase(),
                        InvoiceTypeParser.parsePartyTaxSchemeType(partyType.getPartyTaxScheme())));
            }

            // Bank
            if (invoiceType.getPaymentMeans().size() > 0) {
View Full Code Here


            }
        }
    }

    private void addReferenceTokens() {
        template.addToken(new Token(
                TextLabel.ORDER_ID_LABEL.toLowerCase(), TextLabel.ORDER_ID_LABEL.toString(locale)));
        template.addToken(new Token(TextLabel.ORDER_ID.toLowerCase(),
                InvoiceTypeParser.parseOrderReferenceID(invoiceType.getOrderReference())));
    }
View Full Code Here

    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

                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

            template.addToken(invoiceLineTokens);
        }
    }

    private void addInvoiceIDTokens() {
        template.addToken(new Token(
                TextLabel.INV_ID_LABEL.toLowerCase(), TextLabel.INV_ID_LABEL.toString(locale)));
        template.addToken(new Token(TextLabel.INV_ID.toLowerCase(), invoiceType.getID().getValue()));
    }
View Full Code Here

                TextLabel.INV_ID_LABEL.toLowerCase(), TextLabel.INV_ID_LABEL.toString(locale)));
        template.addToken(new Token(TextLabel.INV_ID.toLowerCase(), invoiceType.getID().getValue()));
    }

    private void addInvoiceIssueDateTokens() {
        template.addToken(new Token(TextLabel.INV_ISSUE_DATE_LABEL.toLowerCase(),
                TextLabel.INV_ISSUE_DATE_LABEL.toString(locale)));
        template.addToken(new Token(TextLabel.INV_ISSUE_DATE.toLowerCase(),
                new LocalDateWrapper(invoiceType.getIssueDate().getValue()).format()));
    }
View Full Code Here

        template.addToken(new Token(TextLabel.INV_ISSUE_DATE.toLowerCase(),
                new LocalDateWrapper(invoiceType.getIssueDate().getValue()).format()));
    }

    private void addInvoiceLabelToken() {
        template.addToken(new Token(
                TextLabel.INV_NAME_LABEL.toLowerCase(), TextLabel.INV_NAME_LABEL.toString(locale)));
    }
View Full Code Here

TOP

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

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.