Skip to content

Commit

Permalink
v4
Browse files Browse the repository at this point in the history
  • Loading branch information
MartkCz committed May 4, 2022
1 parent a86be99 commit 22b351b
Show file tree
Hide file tree
Showing 77 changed files with 1,293 additions and 2,064 deletions.
170 changes: 64 additions & 106 deletions .docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,159 +6,121 @@
- [Setup](#setup)
- [Preview with minimal setup](#preview-with-minimal-setup)
- [Entities](#entities)
- [Customizing](#customizing)
- [Translation](#translation)
- [Generating invoices](#generating-invoices)
- [Generating preview](#generating-preview)
- [Neon configuration](#neon-configuration)
- [Examples](#examples)
- [Templates](#templates)

## Benchmark

Average output is ~20ms
Average output is ~5ms

## Setup

```php
$company = new Contributte\Invoice\Data\Company('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA', '0123456789', 'CZ0123456789');
$invoice = new Contributte\Invoice\Invoice($company);
```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')],
new Currency('Kč', ':price :currency'), // change default format $ 1000 to 1000 Kč
);
```

## Preview with minimal setup

```php
$invoice = new Contributte\Invoice\Invoice(Contributte\Invoice\Preview\PreviewFactory::createCompany());
use Contributte\Invoice\Preview\PreviewFactory;

$invoice->send(Contributte\Invoice\Preview\PreviewFactory::createCustomer(), Contributte\Invoice\Preview\PreviewFactory::createOrder());
$invoice->send(PreviewFactory::createOrder());
```

## Entities

We have following entities: Company (seller), Customer, Account (bank account), Payment Info, Order and Item.
We have following entities: Company (seller), Customer, Account (bank account), Payment Info, Currency, Timestamps, Order and Item.

### Company - seller

```php
$company = new Contributte\Invoice\Data\Company('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA', '0123456789', 'CZ0123456789');
use Contributte\Invoice\Data\Company;

$company = new Company('Contributte', 'Prague', 'U haldy', '110 00', 'Czech Republic', 'CZ08304431', '08304431');
```

### Customer

```php
$customer = new Contributte\Invoice\Data\Customer('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA');
use Contributte\Invoice\Data\Customer;

$customer = new Customer('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA', 'CZ08304431', '08304431');
```

### Account - bank account

```php
$account = new Contributte\Invoice\Data\Account('1111', 'CZ4808000000002353462015', 'GIGACZPX');
use Contributte\Invoice\Data\Account;

$account = new Account('CZ4808000000002353462013');
```

### Payment info

```php
$payment = new Contributte\Invoice\Data\PaymentInformation('Kč', '0123456789', '1234', 0.21);
use Contributte\Invoice\Data\Account;
use Contributte\Invoice\Data\PaymentInformation;

$payment = new PaymentInformation(
[new Account('CZ4808000000002353462013')],
);
```

### Order

```php
$order = new Contributte\Invoice\Data\Order('20160001', new \DateTime('+ 14 days'), $account, $payment);
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'),
),
);
```

### Item

```php
$order->addItem('Logitech G700s Rechargeable Gaming Mouse', 4, 1790);
```

## Customizing

Customize numbers, money or date

```php
use Contributte\Invoice\IFormatter;

class CustomFormatter implements IFormatter {

}
```

Customize colors, fonts:

```php
$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);
```

## Translation

First, create class that implements ITranslator

```php
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];
}
use Contributte\Invoice\Data\Item;

}
```
$order->addInlineItem('Logitech G700s Rechargeable Gaming Mouse', '1.790,00', 4, '7.160,00');

and pass it to the invoice and template
// or

```php
$invoice = new Contributte\Invoice\Invoice($company, new Contributte\Invoice\Templates\DefaultTemplate(new Translator()));
$order->addItem(new Item('Logitech G700s Rechargeable Gaming Mouse', '1.790,00', 4, '7.160,00'));
```

## Generating invoices

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

header('Content-Type: application/pdf; charset=utf-8');
echo $invoice->create($customer, $order);
echo $invoice->create($order);
```

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

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

$invoice->send($customer, $order);
$invoice->send($order);
```

if you use nette, recommended way is
Expand All @@ -167,20 +129,12 @@ if you use nette, recommended way is
class CustomPresenter {

public function actionPreview() {
$invoice = new Contributte\Invoice\Invoice($company);

$this->sendResponse($invoice->createResponse($customer, $order));
$this->sendResponse($this->invoice->createResponse($order));
}

}
```

## Generating preview

```php
$invoice->send(Contributte\Invoice\Preview\PreviewFactory::createCustomer(), Contributte\Invoice\Preview\PreviewFactory::createOrder());
```

## Neon configuration

```neon
Expand All @@ -201,10 +155,14 @@ invoice:
isTax: bool
```

## Examples
## Templates

## Paraiso
Single page:
![single page](/img/paraiso.png?raw=true)

First page:
![first page](http://i.imgbox.com/pwFByZ1L.jpg)
Multiple pages:
![multiple pages](/img/paraiso-paginator.png?raw=true)

Second page:
![second page](http://i.imgbox.com/ebrwXldf.jpg)
Greyscale:
![greyscale](/img/paraiso-greyscale.png?raw=true)
Binary file added .docs/img/paraiso-greyscale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .docs/img/paraiso-paginator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .docs/img/paraiso.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

vendor
composer.lock

## workspace
workspace
27 changes: 0 additions & 27 deletions assets/OpenSans-Regular.php

This file was deleted.

Binary file removed assets/OpenSans-Regular.ttf
Binary file not shown.
Binary file removed assets/OpenSans-Regular.z
Binary file not shown.
26 changes: 0 additions & 26 deletions assets/OpenSans-Semibold.php

This file was deleted.

Binary file removed assets/OpenSans-Semibold.ttf
Binary file not shown.
Binary file removed assets/OpenSans-Semibold.z
Binary file not shown.
Loading

0 comments on commit 22b351b

Please sign in to comment.