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
Showing
17 changed files
with
508 additions
and
20 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
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
15 changes: 15 additions & 0 deletions
15
module/AjastaInvoice/config/doctrine/Ajasta.Invoice.Entity.InvoiceNumberIncrementer.dcm.xml
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,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-mapping | ||
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping | ||
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> | ||
|
||
<entity name="Ajasta\Invoice\Entity\InvoiceNumberIncrementer" table="invoiceNumberIncrementer"> | ||
<id name="id" type="integer"> | ||
<generator strategy="AUTO"/> | ||
</id> | ||
|
||
<field name="value" type="integer"/> | ||
</entity> | ||
</doctrine-mapping> |
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
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
30 changes: 30 additions & 0 deletions
30
module/AjastaInvoice/src/Ajasta/Invoice/Entity/InvoiceNumberIncrementer.php
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,30 @@ | ||
<?php | ||
namespace Ajasta\Invoice\Entity; | ||
|
||
class InvoiceNumberIncrementer | ||
{ | ||
const ID = 1; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $id = self::ID; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $value = 1; | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
|
||
public function incrementValue() | ||
{ | ||
$this->value++; | ||
} | ||
} |
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,120 @@ | ||
<?php | ||
namespace Ajasta\Invoice; | ||
|
||
use InvalidArgumentException; | ||
use Zend\Stdlib\AbstractOptions; | ||
|
||
class Options extends AbstractOptions | ||
{ | ||
/** | ||
* @var decimal | ||
*/ | ||
protected $defaultVat = '0.0'; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
protected $defaultUnit; | ||
|
||
/** | ||
* @var decimal | ||
*/ | ||
protected $defaultUnitPrice = '0.0'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $invoiceNumberFormat = '%1$s'; | ||
|
||
/** | ||
* @return decimal | ||
*/ | ||
public function getDefaultVat() | ||
{ | ||
return $this->defaultVat; | ||
} | ||
|
||
/** | ||
* @param decimal $defaultVat | ||
*/ | ||
public function setDefaultVat($defaultVat) | ||
{ | ||
if (!is_string($defaultVat) || !preg_match('(^\d+(\.\d+)?$)', $defaultVat)) { | ||
throw new InvalidArgumentException(sprintf( | ||
'Default VAT must be a decimal string value, got %s', | ||
$defaultVat | ||
)); | ||
} | ||
|
||
$this->defaultVat = $defaultVat; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getDefaultUnit() | ||
{ | ||
return $this->defaultUnit; | ||
} | ||
|
||
/** | ||
* @param string|null $defaultUnit | ||
*/ | ||
public function setDefaultUnit($defaultUnit) | ||
{ | ||
if (!in_array($defaultUnit, [null, 'hours', 'days'], true)) { | ||
throw new InvalidArgumentException(sprintf( | ||
'Default unit must be either null, "hours" or "days", got %s', | ||
$defaultUnit | ||
)); | ||
} | ||
|
||
$this->defaultUnit = $defaultUnit; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getDefaultUnitPrice() | ||
{ | ||
return $this->defaultUnitPrice; | ||
} | ||
|
||
/** | ||
* @param decimal $defaultUnitPrice | ||
*/ | ||
public function setDefaultUnitPrice($defaultUnitPrice) | ||
{ | ||
if (!is_string($defaultUnitPrice) || !preg_match('(^\d+(\.\d+)?$)', $defaultUnitPrice)) { | ||
throw new InvalidArgumentException(sprintf( | ||
'Default unit price must be a decimal string value, got %s', | ||
$defaultUnitPrice | ||
)); | ||
} | ||
|
||
$this->defaultUnitPrice = $defaultUnitPrice; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getInvoiceNumberFormat() | ||
{ | ||
return $this->invoiceNumberFormat; | ||
} | ||
|
||
/** | ||
* @param string $invoiceNumberFormat | ||
*/ | ||
public function setInvoiceNumberFormat($invoiceNumberFormat) | ||
{ | ||
if (!is_string($invoiceNumberFormat)) { | ||
throw new InvalidArgumentException(sprintf( | ||
'Invoice number format must be a string, got %s', | ||
is_object($invoiceNumberFormat) ? get_class($invoiceNumberFormat) : gettype($invoiceNumberFormat)) | ||
); | ||
} | ||
|
||
$this->invoiceNumberFormat = $invoiceNumberFormat; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
module/AjastaInvoice/src/Ajasta/Invoice/OptionsFactory.php
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,22 @@ | ||
<?php | ||
namespace Ajasta\Invoice; | ||
|
||
use Zend\ServiceManager\FactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class OptionsFactory implements FactoryInterface | ||
{ | ||
/** | ||
* @return Options | ||
*/ | ||
public function createService(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
$config = $serviceLocator->get('Config'); | ||
|
||
if (!isset($config['ajasta']['invoice'])) { | ||
return new Options(); | ||
} | ||
|
||
return new Options($config['ajasta']['invoice']); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
module/AjastaInvoice/src/Ajasta/Invoice/Service/InvoiceNumberGenerator/FormatGenerator.php
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,33 @@ | ||
<?php | ||
namespace Ajasta\Invoice\Service\InvoiceNumberGenerator; | ||
|
||
use Ajasta\Invoice\Entity\Invoice; | ||
|
||
class FormatGenerator implements GeneratorInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $invoiceNumberFormat; | ||
|
||
/** | ||
* @param string $invoiceNumberFormat | ||
*/ | ||
public function __construct($invoiceNumberFormat) | ||
{ | ||
$this->invoiceNumberFormat = $invoiceNumberFormat; | ||
} | ||
|
||
public function generate(Invoice $invoice, $incrementer) | ||
{ | ||
$issueDate = $invoice->getIssueDate(); | ||
|
||
return sprintf( | ||
$this->invoiceNumberFormat, | ||
$incrementer, | ||
$issueDate->format('Y'), | ||
$issueDate->format('m'), | ||
$issueDate->format('d') | ||
); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
module/AjastaInvoice/src/Ajasta/Invoice/Service/InvoiceNumberGenerator/GeneratorFactory.php
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,16 @@ | ||
<?php | ||
namespace Ajasta\Invoice\Service\InvoiceNumberGenerator; | ||
|
||
use Zend\ServiceManager\FactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class GeneratorFactory implements FactoryInterface | ||
{ | ||
/** | ||
* @return GeneratorInterface | ||
*/ | ||
public function createService(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
return new FormatGenerator($serviceLocator->get('Ajasta\Invoice\Options')->getInvoiceNumberFormat()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...le/AjastaInvoice/src/Ajasta/Invoice/Service/InvoiceNumberGenerator/GeneratorInterface.php
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,16 @@ | ||
<?php | ||
namespace Ajasta\Invoice\Service\InvoiceNumberGenerator; | ||
|
||
use Ajasta\Invoice\Entity\Invoice; | ||
|
||
interface GeneratorInterface | ||
{ | ||
/** | ||
* Generates a new invoice number for an invoice with a given incrememter. | ||
* | ||
* @param Invoice $invoice | ||
* @param int $incrementer | ||
* @return string | ||
*/ | ||
public function generate(Invoice $invoice, $incrementer); | ||
} |
Oops, something went wrong.