Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
MartkCz committed May 4, 2022
1 parent 662ec19 commit 4ce7a21
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions .docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [Setup](#setup)
- [Preview with minimal setup](#preview-with-minimal-setup)
- [Entities](#entities)
- [Data providers](#data-providers)
- [Generating invoices](#generating-invoices)
- [Neon configuration](#neon-configuration)
- [Templates](#templates)
Expand All @@ -14,23 +15,19 @@

Average output is ~9ms for pdf and ~ 1ms for svg

## Setup

```php
$invoice = new Contributte\Invoice\Invoice();

$dataProvider = new Contributte\Invoice\Provider\DataProvider(
new Company('Contributte', 'Prague', 'U haldy', '110 00', 'Czech Republic', 'CZ08304431', '08304431'),
[new Account('CZ4808000000002353462013')],
);
```

## Preview with minimal setup

```php
use Contributte\Invoice\Preview\PreviewFactory;
use Contributte\Invoice\Templates\ParaisoTemplate;

$template = new ParaisoTemplate();

// pdf
echo $template->renderToPdf(PreviewFactory::createOrder());

$invoice->send(PreviewFactory::createOrder());
// svg
echo $template->renderToSvg(PreviewFactory::createOrder());
```

## Entities
Expand Down Expand Up @@ -109,26 +106,43 @@ $order->addInlineItem('Logitech G700s Rechargeable Gaming Mouse', '$ 1.790,00',
$order->addItem(new Item('Logitech G700s Rechargeable Gaming Mouse', '$ 1.790,00', 4, '$ 7.160,00'));
```

## Generating invoices
## Data providers
In most applications we need only one seller and one or more same accounts. We use for them prepared data providers

```php
header('Content-Type: application/pdf; charset=utf-8');
echo $invoice->create($order);
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();
```

method `Invoice::send()` automatically sets content-type header
## Generating invoices

```php
$invoice->send($order);
header('Content-Type: application/pdf; charset=utf-8');
echo $template->renderToPdf($order);
```

if you use nette, recommended way is

```php
use Contributte\Invoice\Bridge\Nette\Response\InvoicePdfResponse;

class CustomPresenter {

public function actionPreview() {
$this->sendResponse($this->invoice->createResponse($order));
// declare $template and $order

$this->sendResponse(new InvoicePdfResponse($template, $order));
}

}
Expand Down

0 comments on commit 4ce7a21

Please sign in to comment.