Skip to main content
Version: 2.1

Invoice - InvoiceBuilder

To create an invoice you can use the InvoiceBuilder

InvoiceBuilder

To build an invoice you use the Parthenon\Invoice\InvoiceBuilder.

addItem

ParameterTypeDescription
$namestringThe name of the item
$valueBrick\Money\MoneyThe value of the item
$optionsarrayThe options for the items.

Options

NameTypeDescription
quantityintegerThe quantity of the items
vatfloatThe VAT percentage
typestringThe type of item
descriptionstringThe description for the item

setInvoiceNumberGenerator

Allows you to set an Invoice Number Generator that implements Parthenon\Invoice\InvoiceNumberGeneratorInterface. See Invoice Number Generator

setInvoiceNumber

Set the invoice number.

addVatToTotal

Sometimes you want to add the VAT to the total. Calling this method will make that happen once the invoice is built.

deductVatFromTotal

Sometimes you don't want to add the VAT to the total. Calling this method will make that happen once the invoice is built.

addVatNumber

This takes a string that contains the VAT number.

setBillerAddress

This accepts an instance of Parthenon\Common\Address

setCountryRules

This accepts an instance of Parthenon\Invoice\CountryRules see Multi-Country VAT

setCurrency

This accepts an string that sets the currency.

setDeliveryAddress

This accepts an instance of Parthenon\Common\Address

setPaymentDetails

This accepts an string that contains the payment details

setCreatedAt

This accepts an instance of DateTimeInterface.

build

This method will build the invoice with all the information given to the InvoiceBuilder and will return an Parthenon\Invoice\Invoice instance.

Example


$invoiceBuilder = new InvoiceBuilder();

foreach ($items as $item) {
$options = [];
$options['quantity'] = (isset($item['Quantity'])) ? (int) $item['Quantity'] : 1;
$options['vat'] = (isset($item['VAT %'])) ? (float) $item['VAT %'] : 0.0;
if (isset($item['Goods Type'])) {
$options['type'] = $item['Goods Type'];
}
$invoiceBuilder->addItem($item['Title'], Money::of($item['Value'], 'EUR'), $options);
}
$invoice = $invoiceBuilder->build();