Contributte Invoice
# Contributte / Invoice
# Content
- Benchmark
- Setup
- Preview with minimal setup
- Entities
- Data providers
- Generating invoices
- Neon configuration
- Templates
# Benchmark
Average output is ~9ms for pdf and ~ 1ms for svg
# Preview with minimal setup
use Contributte\Invoice\Preview\PreviewFactory;
use Contributte\Invoice\Templates\ParaisoTemplate;
$template = new ParaisoTemplate();
// pdf
echo $template->renderToPdf(PreviewFactory::createOrder());
// svg
echo $template->renderToSvg(PreviewFactory::createOrder());
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# Entities
We have following entities: Company (seller), Customer, Account (bank account), Payment Info, Currency, Timestamps, Order and Item.
# Company - seller
use Contributte\Invoice\Data\Company;
$company = new Company('Contributte', 'Prague', 'U haldy', '110 00', 'Czech Republic', 'CZ08304431', '08304431');
1
2
3
2
3
# Customer
use Contributte\Invoice\Data\Customer;
$customer = new Customer('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA', 'CZ08304431', '08304431');
1
2
3
2
3
# Account - bank account
use Contributte\Invoice\Data\Account;
$account = new Account('CZ4808000000002353462013');
1
2
3
2
3
# Payment info
use Contributte\Invoice\Data\Account;
use Contributte\Invoice\Data\PaymentInformation;
$payment = new PaymentInformation(
[new Account('CZ4808000000002353462013')],
);
1
2
3
4
5
6
2
3
4
5
6
# Order
use Contributte\Invoice\Data\Account;
use Contributte\Invoice\Data\Company;
use Contributte\Invoice\Data\Customer;
use Contributte\Invoice\Data\Order;
use Contributte\Invoice\Data\PaymentInformation;
use Contributte\Invoice\Data\Timestamps;
$order = new Order(
date('Y') . '0001',
'$ 15.000,00',
new Company('Contributte', 'Prague', 'U haldy', '110 00', 'Czech Republic', 'CZ08304431', '08304431'),
new Customer('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA', 'CZ08304431', '08304431'),
new PaymentInformation(
[new Account('CZ4808000000002353462013')],
),
new Timestamps(
(new DateTime())->format('Y-m-d'),
(new DateTime('+ 1 week'))->format('Y-m-d'),
),
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Item
use Contributte\Invoice\Data\Item;
$order->addInlineItem('Logitech G700s Rechargeable Gaming Mouse', '$ 1.790,00', 4, '$ 7.160,00');
// or
$order->addItem(new Item('Logitech G700s Rechargeable Gaming Mouse', '$ 1.790,00', 4, '$ 7.160,00'));
1
2
3
4
5
6
7
2
3
4
5
6
7
# Data providers
In most applications we need only one seller and one or more same accounts. We use for them prepared data providers
use Contributte\Invoice\Data\Account;
use Contributte\Invoice\Data\Company;
use Contributte\Invoice\Provider\InvoiceAccountsProvider;
use Contributte\Invoice\Provider\InvoiceCompanyProvider;
$companyProvider = new InvoiceCompanyProvider(new Company(...));
$companyProvider->getCompany();
$accountsProvider = new InvoiceAccountsProvider([
new Account(...),
]);
$accountsProvider->getAccounts();
$accountsProvider->getAccount();
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# Generating invoices
header('Content-Type: application/pdf; charset=utf-8');
echo $template->renderToPdf($order);
1
2
2
if you use nette, recommended way is
use Contributte\Invoice\Bridge\Nette\Response\InvoicePdfResponse;
class CustomPresenter {
public function actionPreview() {
// declare $template and $order
$this->sendResponse(new InvoicePdfResponse($template, $order));
}
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# Neon configuration
extensions:
invoice: Contributte\Invoice\DI\InvoiceExtension
invoice:
company:
name: string
town: string
address: string
zip: string
country: string
## Optional below
vatNumber: string
id: string
accounts:
-
iban: string
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Templates
# Paraiso
Single page:
Multiple pages:
Greyscale:
# Turoiso
Single page:
Greyscale: