-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
AntikCz
committed
Mar 2, 2016
0 parents
commit ec6e3af
Showing
16 changed files
with
1,876 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
vendor | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
Oops, something went wrong.