support multiple invoice repositories (#1084)
This commit is contained in:
@@ -11,10 +11,21 @@ namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Invoice\InvoiceItem;
|
||||
use App\Invoice\InvoiceItemInterface;
|
||||
|
||||
abstract class AbstractMergedCalculator extends AbstractCalculator
|
||||
{
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
|
||||
protected function mergeInvoiceItems(InvoiceItem $invoiceItem, InvoiceItemInterface $entry)
|
||||
{
|
||||
$invoiceItem->setAmount($invoiceItem->getAmount() + 1);
|
||||
$invoiceItem->setUser($entry->getUser());
|
||||
|
||||
@@ -9,16 +9,16 @@
|
||||
|
||||
namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Invoice\CalculatorInterface;
|
||||
use App\Invoice\InvoiceItem;
|
||||
use App\Invoice\InvoiceItemInterface;
|
||||
|
||||
/**
|
||||
* An abstract calculator that sums up the timesheet records.
|
||||
* An abstract calculator that sums up the invoice item records.
|
||||
*/
|
||||
abstract class AbstractSumInvoiceCalculator extends AbstractMergedCalculator implements CalculatorInterface
|
||||
{
|
||||
abstract protected function calculateSumIdentifier(Timesheet $timesheet): string;
|
||||
abstract protected function calculateSumIdentifier(InvoiceItemInterface $invoiceItem): string;
|
||||
|
||||
/**
|
||||
* @return InvoiceItem[]
|
||||
@@ -45,15 +45,15 @@ abstract class AbstractSumInvoiceCalculator extends AbstractMergedCalculator imp
|
||||
if (!isset($invoiceItems[$id])) {
|
||||
$invoiceItems[$id] = new InvoiceItem();
|
||||
}
|
||||
$timesheet = $invoiceItems[$id];
|
||||
$this->mergeTimesheets($timesheet, $entry);
|
||||
$this->mergeSumTimesheet($timesheet, $entry);
|
||||
$invoiceItem = $invoiceItems[$id];
|
||||
$this->mergeInvoiceItems($invoiceItem, $entry);
|
||||
$this->mergeSumTimesheet($invoiceItem, $entry);
|
||||
}
|
||||
|
||||
return array_values($invoiceItems);
|
||||
}
|
||||
|
||||
protected function mergeSumTimesheet(InvoiceItem $invoiceItem, Timesheet $entry)
|
||||
protected function mergeSumTimesheet(InvoiceItem $invoiceItem, InvoiceItemInterface $entry)
|
||||
{
|
||||
// allows to set values per calculator after merging the timesheet
|
||||
}
|
||||
|
||||
@@ -9,25 +9,25 @@
|
||||
|
||||
namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Invoice\CalculatorInterface;
|
||||
use App\Invoice\InvoiceItem;
|
||||
use App\Invoice\InvoiceItemInterface;
|
||||
|
||||
/**
|
||||
* A calculator that sums up the timesheet records by activity.
|
||||
* A calculator that sums up the invoice item records by activity.
|
||||
*/
|
||||
class ActivityInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
{
|
||||
protected function calculateSumIdentifier(Timesheet $timesheet): string
|
||||
protected function calculateSumIdentifier(InvoiceItemInterface $invoiceItem): string
|
||||
{
|
||||
if (null === $timesheet->getActivity()->getId()) {
|
||||
if (null === $invoiceItem->getActivity()->getId()) {
|
||||
throw new \Exception('Cannot handle un-persisted activities');
|
||||
}
|
||||
|
||||
return (string) $timesheet->getActivity()->getId();
|
||||
return (string) $invoiceItem->getActivity()->getId();
|
||||
}
|
||||
|
||||
protected function mergeSumTimesheet(InvoiceItem $invoiceItem, Timesheet $entry)
|
||||
protected function mergeSumTimesheet(InvoiceItem $invoiceItem, InvoiceItemInterface $entry)
|
||||
{
|
||||
$invoiceItem->setActivity($entry->getActivity());
|
||||
$invoiceItem->setDescription($entry->getActivity()->getName());
|
||||
|
||||
@@ -9,21 +9,21 @@
|
||||
|
||||
namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Invoice\CalculatorInterface;
|
||||
use App\Invoice\InvoiceItemInterface;
|
||||
|
||||
/**
|
||||
* A calculator that sums up the timesheet records for each day.
|
||||
* A calculator that sums up the invoice item records for each day.
|
||||
*/
|
||||
class DateInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
{
|
||||
protected function calculateSumIdentifier(Timesheet $timesheet): string
|
||||
protected function calculateSumIdentifier(InvoiceItemInterface $invoiceItem): string
|
||||
{
|
||||
if (null === $timesheet->getBegin()) {
|
||||
throw new \Exception('Cannot handle timesheets without start date');
|
||||
if (null === $invoiceItem->getBegin()) {
|
||||
throw new \Exception('Cannot handle invoice items without start date');
|
||||
}
|
||||
|
||||
return $timesheet->getBegin()->format('Y-m-d');
|
||||
return $invoiceItem->getBegin()->format('Y-m-d');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,7 +29,7 @@ class DefaultCalculator extends AbstractMergedCalculator implements CalculatorIn
|
||||
|
||||
foreach ($this->model->getEntries() as $entry) {
|
||||
$item = new InvoiceItem();
|
||||
$this->mergeTimesheets($item, $entry);
|
||||
$this->mergeInvoiceItems($item, $entry);
|
||||
foreach ($entry->getVisibleMetaFields() as $field) {
|
||||
$item->addAdditionalField($field->getName(), $field->getValue());
|
||||
}
|
||||
|
||||
@@ -9,25 +9,25 @@
|
||||
|
||||
namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Invoice\CalculatorInterface;
|
||||
use App\Invoice\InvoiceItem;
|
||||
use App\Invoice\InvoiceItemInterface;
|
||||
|
||||
/**
|
||||
* A calculator that sums up the timesheet records by project.
|
||||
* A calculator that sums up the invoice item records by project.
|
||||
*/
|
||||
class ProjectInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
{
|
||||
protected function calculateSumIdentifier(Timesheet $timesheet): string
|
||||
protected function calculateSumIdentifier(InvoiceItemInterface $invoiceItem): string
|
||||
{
|
||||
if (null === $timesheet->getProject()->getId()) {
|
||||
if (null === $invoiceItem->getProject()->getId()) {
|
||||
throw new \Exception('Cannot handle un-persisted projects');
|
||||
}
|
||||
|
||||
return (string) $timesheet->getProject()->getId();
|
||||
return (string) $invoiceItem->getProject()->getId();
|
||||
}
|
||||
|
||||
protected function mergeSumTimesheet(InvoiceItem $invoiceItem, Timesheet $entry)
|
||||
protected function mergeSumTimesheet(InvoiceItem $invoiceItem, InvoiceItemInterface $entry)
|
||||
{
|
||||
$invoiceItem->setProject($entry->getProject());
|
||||
$invoiceItem->setDescription($entry->getProject()->getName());
|
||||
|
||||
@@ -9,12 +9,11 @@
|
||||
|
||||
namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Invoice\CalculatorInterface;
|
||||
use App\Invoice\InvoiceItem;
|
||||
|
||||
/**
|
||||
* A calculator that sums up all timesheet records from the model and returns only one
|
||||
* 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
|
||||
@@ -40,7 +39,7 @@ class ShortInvoiceCalculator extends AbstractMergedCalculator implements Calcula
|
||||
if (!in_array($key, $keys)) {
|
||||
$keys[] = $key;
|
||||
}
|
||||
$this->mergeTimesheets($invoiceItem, $entry);
|
||||
$this->mergeInvoiceItems($invoiceItem, $entry);
|
||||
}
|
||||
|
||||
if (count($keys) > 1) {
|
||||
|
||||
@@ -9,21 +9,21 @@
|
||||
|
||||
namespace App\Invoice\Calculator;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Invoice\CalculatorInterface;
|
||||
use App\Invoice\InvoiceItemInterface;
|
||||
|
||||
/**
|
||||
* A calculator that sums up the timesheet records by user.
|
||||
* A calculator that sums up the invoice item records by user.
|
||||
*/
|
||||
class UserInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
|
||||
{
|
||||
protected function calculateSumIdentifier(Timesheet $timesheet): string
|
||||
protected function calculateSumIdentifier(InvoiceItemInterface $invoiceItem): string
|
||||
{
|
||||
if (null === $timesheet->getUser()->getId()) {
|
||||
if (null === $invoiceItem->getUser()->getId()) {
|
||||
throw new \Exception('Cannot handle un-persisted user');
|
||||
}
|
||||
|
||||
return (string) $timesheet->getUser()->getId();
|
||||
return (string) $invoiceItem->getUser()->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user