Contributte Invoice
# Contributte / Invoice
# Content
- Benchmark
- Setup
- Preview with minimal setup
- Entities
- Customizing
- Translation
- Generating invoices
- Generating preview
- Neon configuration
- Examples
# Benchmark
Average output is ~20ms
# Setup
$company = new Contributte\Invoice\Data\Company('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA', '0123456789', 'CZ0123456789');
$invoice = new Contributte\Invoice\Invoice($company);
1
2
2
# Preview with minimal setup
$invoice = new Contributte\Invoice\Invoice(Contributte\Invoice\Preview\PreviewFactory::createCompany());
$invoice->send(Contributte\Invoice\Preview\PreviewFactory::createCustomer(), Contributte\Invoice\Preview\PreviewFactory::createOrder());
1
2
3
2
3
# Entities
We have following entities: Company (seller), Customer, Account (bank account), Payment Info, Order and Item.
# Company - seller
$company = new Contributte\Invoice\Data\Company('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA', '0123456789', 'CZ0123456789');
1
# Customer
$customer = new Contributte\Invoice\Data\Customer('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA');
1
# Account - bank account
$account = new Contributte\Invoice\Data\Account('1111', 'CZ4808000000002353462015', 'GIGACZPX');
1
# Payment info
$payment = new Contributte\Invoice\Data\PaymentInformation('Kč', '0123456789', '1234', 0.21);
1
# Order
$order = new Contributte\Invoice\Data\Order('20160001', new \DateTime('+ 14 days'), $account, $payment);
1
# Item
$order->addItem('Logitech G700s Rechargeable Gaming Mouse', 4, 1790);
1
# Customizing
Customize numbers, money or date
use Contributte\Invoice\IFormatter;
class CustomFormatter implements IFormatter {
}
1
2
3
4
5
2
3
4
5
Customize colors, fonts:
$template = new Contributte\Invoice\Templates\DefaultTemplate();
$template->setEven(new Contributte\Invoice\Renderers\Color(0, 0, 0));
$template->setFont(new Contributte\Invoice\Renderers\Color(0, 0, 0));
$template->setEven(new Contributte\Invoice\Renderers\Color(0, 0, 0));
$template->setOdd(new Contributte\Invoice\Renderers\Color(0, 0, 0));
$invoice = new Contributte\Invoice\Invoice($company, $template);
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# Translation
First, create class that implements ITranslator
class Translator implements Contributte\Invoice\ITranslator {
private static $translations = [
'subscriber' => 'Subscriber',
'vat' => 'VAT number',
'vaTin' => 'VATIN',
'date' => 'Date',
'invoice' => 'Invoice',
'invoiceNumber' => 'Invoice number',
'taxPay' => '',
'notTax' => 'VAT unregistered',
'paymentData' => 'Payment information',
'page' => 'Page',
'from' => '/',
'totalPrice' => 'Total price',
'item' => 'Item',
'count' => 'Quantity',
'pricePerItem' => 'Price per item',
'total' => 'Total',
'accountNumber' => 'Account number',
'swift' => 'Swift',
'iban' => 'Iban',
'varSymbol' => 'Variable symbol',
'constSymbol' => 'Constant symbol',
'tax' => 'TAX',
'subtotal' => 'Subtotal',
'dueDate' => 'Due date',
];
public function translate(string $message): string {
return self::$translations[$message];
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
and pass it to the invoice and template
$invoice = new Contributte\Invoice\Invoice($company, new Contributte\Invoice\Templates\DefaultTemplate(new Translator()));
1
# Generating invoices
$invoice = new Contributte\Invoice\Invoice($company);
header('Content-Type: application/pdf; charset=utf-8');
echo $invoice->create($customer, $order);
1
2
3
4
2
3
4
method Invoice::send()
automatically sets content-type header
$invoice = new Contributte\Invoice\Invoice($company);
$invoice->send($customer, $order);
1
2
3
2
3
if you use nette, recommended way is
class CustomPresenter {
public function actionPreview() {
$invoice = new Contributte\Invoice\Invoice($company);
$this->sendResponse($invoice->createResponse($customer, $order));
}
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# Generating preview
$invoice->send(Contributte\Invoice\Preview\PreviewFactory::createCustomer(), Contributte\Invoice\Preview\PreviewFactory::createOrder());
1
# Neon configuration
extensions:
invoice: Contributte\Invoice\DI\InvoiceExtension
invoice:
lang: en
company:
name: string
town: string
address: string
zip: string|int
country: string
## Optional below
tin: string|int
vaTin: string|int
isTax: bool
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Examples
First page:
Second page: