Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)
This commit is contained in:
@@ -9,43 +9,25 @@
|
||||
|
||||
namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Invoice\CalculatorInterface;
|
||||
use App\Invoice\InvoiceItem;
|
||||
use App\Invoice\InvoiceModel;
|
||||
|
||||
abstract class AbstractCalculator
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $currency;
|
||||
|
||||
/**
|
||||
* @var InvoiceModel
|
||||
*/
|
||||
protected $model;
|
||||
protected InvoiceModel $model;
|
||||
|
||||
/**
|
||||
* @return InvoiceItem[]
|
||||
*/
|
||||
abstract public function getEntries();
|
||||
abstract public function getEntries(): array;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getId(): string;
|
||||
|
||||
/**
|
||||
* @param InvoiceModel $model
|
||||
*/
|
||||
public function setModel(InvoiceModel $model)
|
||||
public function setModel(InvoiceModel $model): void
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getSubtotal(): float
|
||||
{
|
||||
$amount = 0.00;
|
||||
@@ -56,17 +38,11 @@ abstract class AbstractCalculator
|
||||
return round($amount, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getVat(): ?float
|
||||
public function getVat(): float
|
||||
{
|
||||
return $this->model->getTemplate()->getVat();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getTax(): float
|
||||
{
|
||||
$vat = $this->getVat();
|
||||
@@ -79,28 +55,11 @@ abstract class AbstractCalculator
|
||||
return round($this->getSubtotal() * $percent, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getTotal(): float
|
||||
{
|
||||
return $this->getSubtotal() + $this->getTax();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 1.8 will be removed with 2.0
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrency(): string
|
||||
{
|
||||
@trigger_error(
|
||||
sprintf('%s::getCurrency() is deprecated and will be removed with 2.0', CalculatorInterface::class),
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
|
||||
return $this->model->getCurrency();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total amount of worked time in seconds.
|
||||
*
|
||||
|
||||
@@ -9,42 +9,23 @@
|
||||
|
||||
namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Entity\ExportableItem;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Invoice\InvoiceItem;
|
||||
use App\Invoice\InvoiceItemInterface;
|
||||
use App\Invoice\InvoiceItemWithAmountInterface;
|
||||
|
||||
abstract class AbstractMergedCalculator extends AbstractCalculator
|
||||
{
|
||||
public const TYPE_MIXED = 'mixed';
|
||||
public const CATEGORY_MIXED = 'mixed';
|
||||
|
||||
/**
|
||||
* @deprecated since 1.3 - will be removed with 2.0
|
||||
*/
|
||||
protected function mergeTimesheets(InvoiceItem $invoiceItem, Timesheet $entry)
|
||||
{
|
||||
@trigger_error('mergeTimesheets() is deprecated and will be removed with 2.0', E_USER_DEPRECATED);
|
||||
|
||||
$this->mergeInvoiceItems($invoiceItem, $entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InvoiceItem $invoiceItem
|
||||
* @param InvoiceItemInterface $entry
|
||||
* @return void
|
||||
*/
|
||||
protected function mergeInvoiceItems(InvoiceItem $invoiceItem, InvoiceItemInterface $entry) /* : void */
|
||||
protected function mergeInvoiceItems(InvoiceItem $invoiceItem, ExportableItem $entry): void
|
||||
{
|
||||
$duration = $invoiceItem->getDuration();
|
||||
if (null !== $entry->getDuration()) {
|
||||
$duration += $entry->getDuration();
|
||||
}
|
||||
|
||||
$amount = 1;
|
||||
if ($entry instanceof InvoiceItemWithAmountInterface) {
|
||||
$amount = $entry->getAmount();
|
||||
}
|
||||
$amount = $entry->getAmount();
|
||||
|
||||
$type = $entry->getType();
|
||||
$category = $entry->getCategory();
|
||||
@@ -62,11 +43,7 @@ abstract class AbstractMergedCalculator extends AbstractCalculator
|
||||
$invoiceItem->setAmount($invoiceItem->getAmount() + $amount);
|
||||
$invoiceItem->setUser($entry->getUser());
|
||||
$invoiceItem->setRate($invoiceItem->getRate() + $entry->getRate());
|
||||
if (method_exists($entry, 'getInternalRate')) {
|
||||
$invoiceItem->setInternalRate($invoiceItem->getInternalRate() + $entry->getInternalRate());
|
||||
} else {
|
||||
$invoiceItem->setInternalRate($invoiceItem->getInternalRate() + $entry->getRate());
|
||||
}
|
||||
$invoiceItem->setInternalRate($invoiceItem->getInternalRate() + ($entry->getInternalRate() ?? 0.00));
|
||||
$invoiceItem->setDuration($duration);
|
||||
|
||||
if (null !== $entry->getFixedRate()) {
|
||||
|
||||
@@ -9,18 +9,18 @@
|
||||
|
||||
namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Entity\ExportableItem;
|
||||
use App\Invoice\CalculatorInterface;
|
||||
use App\Invoice\InvoiceItem;
|
||||
use App\Invoice\InvoiceItemInterface;
|
||||
|
||||
/**
|
||||
* An abstract calculator that sums up the invoice item records.
|
||||
*/
|
||||
abstract class AbstractSumInvoiceCalculator extends AbstractMergedCalculator implements CalculatorInterface
|
||||
{
|
||||
abstract protected function calculateSumIdentifier(InvoiceItemInterface $invoiceItem): string;
|
||||
abstract protected function calculateSumIdentifier(ExportableItem $invoiceItem): string;
|
||||
|
||||
protected function calculateIdentifier(InvoiceItemInterface $entry): string
|
||||
protected function calculateIdentifier(ExportableItem $entry): string
|
||||
{
|
||||
$prefix = $this->calculateSumIdentifier($entry);
|
||||
|
||||
@@ -34,7 +34,7 @@ abstract class AbstractSumInvoiceCalculator extends AbstractMergedCalculator imp
|
||||
/**
|
||||
* @return InvoiceItem[]
|
||||
*/
|
||||
public function getEntries()
|
||||
public function getEntries(): array
|
||||
{
|
||||
$entries = $this->model->getEntries();
|
||||
if (empty($entries)) {
|
||||
@@ -60,14 +60,10 @@ abstract class AbstractSumInvoiceCalculator extends AbstractMergedCalculator imp
|
||||
|
||||
/**
|
||||
* @param InvoiceItem $invoiceItem
|
||||
* @param InvoiceItemInterface $entry
|
||||
* @param ExportableItem $entry
|
||||
* @return void
|
||||
*/
|
||||
protected function mergeSumInvoiceItem(InvoiceItem $invoiceItem, InvoiceItemInterface $entry) /* : void */
|
||||
protected function mergeSumInvoiceItem(InvoiceItem $invoiceItem, ExportableItem $entry): void
|
||||
{
|
||||
if (method_exists($this, 'mergeSumTimesheet')) {
|
||||
@trigger_error('mergeSumTimesheet() is deprecated and will be removed with 2.0 - use mergeSumInvoiceItem() instead', E_USER_DEPRECATED);
|
||||
$this->mergeSumTimesheet($invoiceItem, $entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,16 +9,16 @@
|
||||
|
||||
namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Entity\ExportableItem;
|
||||
use App\Invoice\CalculatorInterface;
|
||||
use App\Invoice\InvoiceItem;
|
||||
use App\Invoice\InvoiceItemInterface;
|
||||
|
||||
/**
|
||||
* A calculator that sums up the invoice item records by activity.
|
||||
*/
|
||||
class ActivityInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
final class ActivityInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
{
|
||||
protected function calculateSumIdentifier(InvoiceItemInterface $invoiceItem): string
|
||||
protected function calculateSumIdentifier(ExportableItem $invoiceItem): string
|
||||
{
|
||||
if (null === $invoiceItem->getActivity()) {
|
||||
return '__NULL__';
|
||||
@@ -27,7 +27,7 @@ class ActivityInvoiceCalculator extends AbstractSumInvoiceCalculator implements
|
||||
return (string) $invoiceItem->getActivity()->getId();
|
||||
}
|
||||
|
||||
protected function mergeSumInvoiceItem(InvoiceItem $invoiceItem, InvoiceItemInterface $entry)
|
||||
protected function mergeSumInvoiceItem(InvoiceItem $invoiceItem, ExportableItem $entry): void
|
||||
{
|
||||
if (null === $entry->getActivity()) {
|
||||
return;
|
||||
@@ -40,9 +40,6 @@ class ActivityInvoiceCalculator extends AbstractSumInvoiceCalculator implements
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return 'activity';
|
||||
|
||||
@@ -9,15 +9,15 @@
|
||||
|
||||
namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Entity\ExportableItem;
|
||||
use App\Invoice\CalculatorInterface;
|
||||
use App\Invoice\InvoiceItemInterface;
|
||||
|
||||
/**
|
||||
* A calculator that sums up the invoice item records for each day.
|
||||
*/
|
||||
class DateInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
final class DateInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
{
|
||||
protected function calculateSumIdentifier(InvoiceItemInterface $invoiceItem): string
|
||||
protected function calculateSumIdentifier(ExportableItem $invoiceItem): string
|
||||
{
|
||||
if (null === $invoiceItem->getBegin()) {
|
||||
throw new \Exception('Cannot handle invoice items without start date');
|
||||
@@ -26,9 +26,6 @@ class DateInvoiceCalculator extends AbstractSumInvoiceCalculator implements Calc
|
||||
return $invoiceItem->getBegin()->format('Y-m-d');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return 'date';
|
||||
|
||||
@@ -14,23 +14,26 @@ use App\Invoice\InvoiceItem;
|
||||
|
||||
/**
|
||||
* Class DefaultCalculator works on all given entries using:
|
||||
* - the customers currency
|
||||
* - the customer currency
|
||||
* - the invoice template vat rate
|
||||
* - the entries rate
|
||||
*/
|
||||
class DefaultCalculator extends AbstractMergedCalculator implements CalculatorInterface
|
||||
final class DefaultCalculator extends AbstractMergedCalculator implements CalculatorInterface
|
||||
{
|
||||
/**
|
||||
* @return InvoiceItem[]
|
||||
*/
|
||||
public function getEntries()
|
||||
public function getEntries(): array
|
||||
{
|
||||
$entries = [];
|
||||
|
||||
foreach ($this->model->getEntries() as $entry) {
|
||||
$item = new InvoiceItem();
|
||||
$this->mergeInvoiceItems($item, $entry);
|
||||
foreach ($entry->getVisibleMetaFields() as $field) {
|
||||
foreach ($entry->getMetaFields() as $field) {
|
||||
if ($field->getName() === null) {
|
||||
continue;
|
||||
}
|
||||
$item->addAdditionalField($field->getName(), $field->getValue());
|
||||
}
|
||||
$entries[] = $item;
|
||||
@@ -39,9 +42,6 @@ class DefaultCalculator extends AbstractMergedCalculator implements CalculatorIn
|
||||
return $entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return 'default';
|
||||
|
||||
@@ -9,15 +9,15 @@
|
||||
|
||||
namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Entity\ExportableItem;
|
||||
use App\Invoice\CalculatorInterface;
|
||||
use App\Invoice\InvoiceItemInterface;
|
||||
|
||||
/**
|
||||
* A calculator that sums up the invoice item records by price.
|
||||
*/
|
||||
class PriceInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
final class PriceInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
{
|
||||
protected function calculateSumIdentifier(InvoiceItemInterface $invoiceItem): string
|
||||
protected function calculateSumIdentifier(ExportableItem $invoiceItem): string
|
||||
{
|
||||
if (null !== $invoiceItem->getFixedRate()) {
|
||||
return 'fixed_' . $invoiceItem->getFixedRate();
|
||||
@@ -26,9 +26,6 @@ class PriceInvoiceCalculator extends AbstractSumInvoiceCalculator implements Cal
|
||||
return 'hourly_' . $invoiceItem->getHourlyRate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return 'price';
|
||||
|
||||
@@ -9,16 +9,16 @@
|
||||
|
||||
namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Entity\ExportableItem;
|
||||
use App\Invoice\CalculatorInterface;
|
||||
use App\Invoice\InvoiceItem;
|
||||
use App\Invoice\InvoiceItemInterface;
|
||||
|
||||
/**
|
||||
* A calculator that sums up the invoice item records by project.
|
||||
*/
|
||||
class ProjectInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
final class ProjectInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
{
|
||||
protected function calculateSumIdentifier(InvoiceItemInterface $invoiceItem): string
|
||||
protected function calculateSumIdentifier(ExportableItem $invoiceItem): string
|
||||
{
|
||||
if (null === $invoiceItem->getProject()->getId()) {
|
||||
throw new \Exception('Cannot handle un-persisted projects');
|
||||
@@ -27,7 +27,7 @@ class ProjectInvoiceCalculator extends AbstractSumInvoiceCalculator implements C
|
||||
return (string) $invoiceItem->getProject()->getId();
|
||||
}
|
||||
|
||||
protected function mergeSumInvoiceItem(InvoiceItem $invoiceItem, InvoiceItemInterface $entry)
|
||||
protected function mergeSumInvoiceItem(InvoiceItem $invoiceItem, ExportableItem $entry): void
|
||||
{
|
||||
if ($entry->getProject()->getInvoiceText() !== null) {
|
||||
$invoiceItem->setDescription($entry->getProject()->getInvoiceText());
|
||||
@@ -36,9 +36,6 @@ class ProjectInvoiceCalculator extends AbstractSumInvoiceCalculator implements C
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return 'project';
|
||||
|
||||
@@ -16,12 +16,12 @@ use App\Invoice\InvoiceItem;
|
||||
* A calculator that sums up all invoice item records from the model and returns only one
|
||||
* entry for a compact invoice version.
|
||||
*/
|
||||
class ShortInvoiceCalculator extends AbstractMergedCalculator implements CalculatorInterface
|
||||
final class ShortInvoiceCalculator extends AbstractMergedCalculator implements CalculatorInterface
|
||||
{
|
||||
/**
|
||||
* @return InvoiceItem[]
|
||||
*/
|
||||
public function getEntries()
|
||||
public function getEntries(): array
|
||||
{
|
||||
$entries = $this->model->getEntries();
|
||||
if (empty($entries)) {
|
||||
@@ -51,9 +51,6 @@ class ShortInvoiceCalculator extends AbstractMergedCalculator implements Calcula
|
||||
return [$invoiceItem];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return 'short';
|
||||
|
||||
@@ -9,15 +9,15 @@
|
||||
|
||||
namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Entity\ExportableItem;
|
||||
use App\Invoice\CalculatorInterface;
|
||||
use App\Invoice\InvoiceItemInterface;
|
||||
|
||||
/**
|
||||
* A calculator that sums up the invoice item records by user.
|
||||
*/
|
||||
class UserInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
final class UserInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
{
|
||||
protected function calculateSumIdentifier(InvoiceItemInterface $invoiceItem): string
|
||||
protected function calculateSumIdentifier(ExportableItem $invoiceItem): string
|
||||
{
|
||||
if (null === $invoiceItem->getUser()->getId()) {
|
||||
throw new \Exception('Cannot handle un-persisted user');
|
||||
@@ -26,9 +26,6 @@ class UserInvoiceCalculator extends AbstractSumInvoiceCalculator implements Calc
|
||||
return (string) $invoiceItem->getUser()->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return 'user';
|
||||
|
||||
@@ -9,22 +9,19 @@
|
||||
|
||||
namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Entity\ExportableItem;
|
||||
use App\Invoice\CalculatorInterface;
|
||||
use App\Invoice\InvoiceItemInterface;
|
||||
|
||||
/**
|
||||
* A calculator that sums up the invoice item records per week.
|
||||
*/
|
||||
class WeeklyInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
final class WeeklyInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
{
|
||||
protected function calculateSumIdentifier(InvoiceItemInterface $invoiceItem): string
|
||||
protected function calculateSumIdentifier(ExportableItem $invoiceItem): string
|
||||
{
|
||||
return $invoiceItem->getBegin()->format('W');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return 'weekly';
|
||||
|
||||
Reference in New Issue
Block a user