diff --git a/.docs/README.md b/.docs/README.md deleted file mode 100644 index 8cc4316..0000000 --- a/.docs/README.md +++ /dev/null @@ -1,189 +0,0 @@ -# Contributte / Invoice - -## Content - -- [Benchmark](#benchmark) -- [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) - -## Benchmark - -Average output is ~9ms for pdf and ~ 1ms for svg - -## Preview with minimal setup - -```php -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()); -``` - -## Entities - -We have following entities: Company (seller), Customer, Account (bank account), Payment Info, Currency, Timestamps, Order and Item. - -### Company - seller - -```php -use Contributte\Invoice\Data\Company; - -$company = new Company('Contributte', 'Prague', 'U haldy', '110 00', 'Czech Republic', 'CZ08304431', '08304431'); -``` - -### Customer - -```php -use Contributte\Invoice\Data\Customer; - -$customer = new Customer('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA', 'CZ08304431', '08304431'); -``` - -### Account - bank account - -```php -use Contributte\Invoice\Data\Account; - -$account = new Account('CZ4808000000002353462013'); -``` - -### Payment info - -```php -use Contributte\Invoice\Data\Account; -use Contributte\Invoice\Data\PaymentInformation; - -$payment = new PaymentInformation( - [new Account('CZ4808000000002353462013')], -); -``` - -### Order - -```php -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 -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')); -``` - -## Data providers -In most applications we need only one seller and one or more same accounts. We use for them prepared data providers - -```php -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(); -``` - -## Generating invoices - -```php -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() { - // declare $template and $order - - $this->sendResponse(new InvoicePdfResponse($template, $order)); - } - -} -``` - -## Neon configuration - -```neon -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 -``` - -## Templates - -## Paraiso -Single page: - - -Multiple pages: - - -Greyscale: - - -## Turoiso -Single page: - - -Greyscale: - diff --git a/README.md b/README.md index 729bccc..844d46d 100755 --- a/README.md +++ b/README.md @@ -18,7 +18,16 @@ Website 🚀 contributte.org | Contact 👨🏻💻 f3l1x.io | Twitter 🐦 @contributte
-## Usage +Simple invoice generator for PHP applications with PDF and SVG rendering, prepared data objects, Nette integration, and ready-to-use invoice templates. + +## Versions + +| State | Version | Branch | PHP | +|-------------|---------------|----------|---------| +| dev | `~5.1.0` | `master` | `>=8.2` | +| stable | `~5.0.0` | `master` | `>=8.2` | + +## Installation To install latest version of `contributte/invoice` use [Composer](https://getcomposer.org). @@ -26,22 +35,201 @@ To install latest version of `contributte/invoice` use [Composer](https://getcom composer require contributte/invoice ``` -## Documentation +## Content -For details on how to use this package, check out our [documentation](.docs). +- [Benchmark](#benchmark) +- [Preview with minimal setup](#preview-with-minimal-setup) +- [Entities](#entities) +- [Data providers](#data-providers) +- [Generating invoices](#generating-invoices) +- [Neon configuration](#neon-configuration) +- [Templates](#templates) -## Versions +## Benchmark -| State | Version | Branch | PHP | -|-------------|---------------|----------|---------| -| dev | `~5.1.0` | `master` | `>=8.2` | -| stable | `~5.0.0` | `master` | `>=8.2` | +Average output is ~9ms for pdf and ~1ms for svg. + +## Preview with minimal setup + +```php +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()); +``` + +## Entities + +We have following entities: Company (seller), Customer, Account (bank account), Payment Info, Currency, Timestamps, Order and Item. + +### Company - seller + +```php +use Contributte\Invoice\Data\Company; + +$company = new Company('Contributte', 'Prague', 'U haldy', '110 00', 'Czech Republic', 'CZ08304431', '08304431'); +``` + +### Customer + +```php +use Contributte\Invoice\Data\Customer; + +$customer = new Customer('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA', 'CZ08304431', '08304431'); +``` + +### Account - bank account + +```php +use Contributte\Invoice\Data\Account; + +$account = new Account('CZ4808000000002353462013'); +``` + +### Payment info + +```php +use Contributte\Invoice\Data\Account; +use Contributte\Invoice\Data\PaymentInformation; + +$payment = new PaymentInformation( + [new Account('CZ4808000000002353462013')], +); +``` + +### Order + +```php +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 +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')); +``` + +## Data providers + +In most applications we need only one seller and one or more same accounts. We use for them prepared data providers. + +```php +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(); +``` + +## Generating invoices + +```php +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() { + // declare $template and $order + + $this->sendResponse(new InvoicePdfResponse($template, $order)); + } + +} +``` + +## Neon configuration + +```neon +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 +``` + +## Templates + +### Paraiso + +Single page: + + +Multiple pages: + + +Greyscale: + + +### Turoiso + +Single page: + + +Greyscale: + ## Development See [how to contribute](https://contributte.org/contributing.html) to this package. -This package is currently maintaining by these authors. +This package is currently maintained by these authors.