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);
}
}