Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AntikCz committed Mar 2, 2016
0 parents commit ec6e3af
Show file tree
Hide file tree
Showing 16 changed files with 1,876 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor
composer.lock
91 changes: 91 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# PHP Invoice

## Installation

```
composer require webchemistry/invoice
```

## Usage

### Company data

```php
$company = new \WebChemistry\Invoice\Data\Company();

$company->setAddress('address');
$company->setCountry('country');
$company->setFooter('footer');
$company->setName('name');
$company->setTown('town');
$company->setZip('77777');
$company->setTin('1111');
$company->setVaTin('CZ1111');
$company->setLogo(__DIR__ . '/logo.png'); // Recommended height is 106px
$company->setIsTax(TRUE);
```

### Customer data

```php
$customer = new \WebChemistry\Invoice\Data\Customer();

$customer->setAddress('address');
$customer->setCountry('country');
$customer->setTin('2222');
$customer->setVaTin('CZ2222');
$customer->setTown('town');
$customer->setName('name');
$customer->setZip('77777');
```

### Payment data

```php
$payment->setAccountNumber('1111');
$payment->setConstantSymbol('2222');
$payment->setVariableSymbol('3333');
$payment->setCurrency('Kč');
$payment->setIBan('4444');
$payment->setSwift('5555');
$payment->setMaturityDate(new \DateTime('+ 7 days'));
$payment->setInvoiceNumber(20160001);
```

Adding items

```php
$item = new \WebChemistry\Invoice\Data\Item();
$item->setName('item');
$item->setCount(rand(1,3));
$item->setPrice(rand(999, 100000));

$payment->addItem($item);
```

### Customizing template

```php
$template = new WebChemistry\Invoice\Data\Template();

// ...
```

## Generating invoices

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

$images = $invoice->create($customer, $payment);
foreach ($images as $page => $invoice) {
$invoice->save(__DIR__ . "/invoice-$page.jpg");
}
```

## Previews

First page:
![first page](http://i.imgbox.com/aykrwnkq.jpg)

Second page:
![second page](http://i.imgbox.com/7fvkelxr.jpg)
Binary file added assets/OpenSans-Regular.ttf
Binary file not shown.
Binary file added assets/OpenSans-Semibold.ttf
Binary file not shown.
Binary file added assets/pe.ttf
Binary file not shown.
13 changes: 13 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "webchemistry/invoice",
"type": "library",
"desc": "Generates invoices",
"tags": ["webchemistry", "invoice"],
"require": {
"nette/utils": "^2.3",
"intervention/image": "^2.3"
},
"autoload": {
"classmap": ["src/"]
}
}
68 changes: 68 additions & 0 deletions src/Components/Paginator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace WebChemistry\Invoice\Components;

use WebChemistry\Invoice\Data\Item;

class Paginator {

/** @var int */
public static $maxItems = 9;

/** @var Item[] */
private $items;

/** @var int */
protected $currentPage;

/**
* @param array $items
* @return self
*/
public function setItems(array $items) {
$this->items = $items;

return $this;
}

/**
* @return int
*/
public function getTotalPages() {
return (int) ceil(count($this->items) / 9);
}

/**
* @return Item[]
*/
public function getItems() {
$page = $this->currentPage - 1;

return array_slice($this->items, $page * 9, $page * 9 + 9);
}

/**
* @return bool
*/
public function isLastPage() {
return $this->currentPage === $this->getTotalPages();
}

/**
* @return int
*/
public function getCurrentPage() {
return $this->currentPage;
}

/**
* @param int $currentPage
* @return Paginator
*/
public function setCurrentPage($currentPage) {
$this->currentPage = (int) $currentPage;

return $this;
}

}
171 changes: 171 additions & 0 deletions src/Data/AbstractData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<?php

namespace WebChemistry\Invoice\Data;

use Nette\Object;
use WebChemistry\Invoice\Exception;

abstract class AbstractData extends Object {

/** @var string */
protected $name;

/** @var string */
protected $town;

/** @var string */
protected $address;

/** @var string */
protected $zip;

/** @var string */
protected $country;

/** @var string */
protected $tin;

/** @var string */
protected $vaTin;

/** @var array */
private $important = ['name', 'town', 'address', 'zip', 'country'];

/**
* @throws Exception
*/
public function check() {
foreach ($this->important as $item) {
if (!$this->$item) {
throw new Exception("Parameter '$item' must be set.");
}
}
if ($this->vaTin && !$this->tin) {
throw new Exception("Parameter 'ic' must be set.");
}
}

/**
* @return string
*/
public function getName() {
return $this->name;
}

/**
* @param string $name
* @return self
*/
public function setName($name) {
$this->name = (string) $name;

return $this;
}

/**
* @return string
*/
public function getTown() {
return $this->town;
}

/**
* @param string $town
* @return self
*/
public function setTown($town) {
$this->town = (string) $town;

return $this;
}

/**
* @return string
*/
public function getAddress() {
return $this->address;
}

/**
* @param string $address
* @return self
*/
public function setAddress($address) {
$this->address = (string) $address;

return $this;
}

/**
* @return string
*/
public function getZip() {
return $this->zip;
}

/**
* @param string $zip
* @return self
*/
public function setZip($zip) {
$this->zip = (string) $zip;

return $this;
}

/**
* @return string
*/
public function getCountry() {
return $this->country;
}

/**
* @param string $country
* @return self
*/
public function setCountry($country) {
$this->country = (string) $country;

return $this;
}

/**
* @return string
*/
public function getTin() {
return $this->tin;
}

/**
* @param string $tin
* @throws Exception
* @return self
*/
public function setTin($tin) {
if (!is_numeric($tin)) {
throw new Exception(sprintf('Ic must be numeric, %s given.', gettype($tin)));
}
$this->tin = $tin;

return $this;
}

/**
* @return string
*/
public function getVaTin() {
return $this->vaTin;
}

/**
* @param string $vaTin
* @return self
*/
public function setVaTin($vaTin) {
$this->vaTin = (string) $vaTin;

return $this;
}

}
Loading

0 comments on commit ec6e3af

Please sign in to comment.