toXml method

void toXml(
  1. XmlBuilder builder,
  2. int id
)

Converts the InvoiceLine instance into XML format using the XmlBuilder.

The method generates the XML representation of the invoice line, including the item details, price, tax, and other related information. This is typically used for generating XML-based invoices.

id is the unique identifier for this invoice line.

Implementation

void toXml(XmlBuilder builder, int id) {
  builder.element('cbc:ID', nest: id);
  builder.element('cbc:InvoicedQuantity',
      attributes: {'unitCode': 'PCE'}, nest: quantity);
  builder.element('cbc:LineExtensionAmount',
      attributes: {'currencyID': 'SAR'}, nest: total);

  builder.element('cac:TaxTotal', nest: () {
    builder.element('cbc:TaxAmount',
        attributes: {'currencyID': 'SAR'}, nest: tax.amount);
    builder.element('cbc:RoundingAmount',
        attributes: {'currencyID': 'SAR'},
        nest: (num.parse(tax.taxableAmount) + num.parse(tax.amount))
            .toStringAsFixed(2));
  });

  builder.element('cac:Item', nest: () {
    builder.element('cbc:Name', nest: name);
    builder.element('cac:ClassifiedTaxCategory', nest: () {
      builder.element('cbc:ID', nest: 'S');
      builder.element('cbc:Percent', nest: tax.percent);
      builder.element('cac:TaxScheme', nest: () {
        builder.element('cbc:ID', nest: 'VAT');
      });
    });
  });

  builder.element('cac:Price', nest: () {
    builder.element('cbc:PriceAmount',
        nest: price, attributes: {'currencyID': tax.currency});
  });
}