use timesheet description in invoices (#1079)

This commit is contained in:
Kevin Papst
2019-09-04 10:54:21 +02:00
committed by GitHub
parent 93ab3d5666
commit 49e1a1c410
15 changed files with 51 additions and 95 deletions

View File

@@ -47,11 +47,12 @@ abstract class AbstractMergedCalculator extends AbstractCalculator
$invoiceItem->setEnd($entry->getEnd());
}
if (null !== $this->model->getQuery()->getActivity()) {
$invoiceItem->setActivity($this->model->getQuery()->getActivity());
$invoiceItem->setDescription($this->model->getQuery()->getActivity()->getName());
} elseif (null !== $this->model->getQuery()->getProject()) {
$invoiceItem->setDescription($this->model->getQuery()->getProject()->getName());
if (!empty($entry->getDescription())) {
$description = '';
if (!empty($invoiceItem->getDescription())) {
$description = $invoiceItem->getDescription() . PHP_EOL;
}
$invoiceItem->setDescription($description . $entry->getDescription());
}
if (null === $invoiceItem->getActivity()) {

View File

@@ -47,8 +47,14 @@ abstract class AbstractSumInvoiceCalculator extends AbstractMergedCalculator imp
}
$timesheet = $invoiceItems[$id];
$this->mergeTimesheets($timesheet, $entry);
$this->mergeSumTimesheet($timesheet, $entry);
}
return array_values($invoiceItems);
}
protected function mergeSumTimesheet(InvoiceItem $invoiceItem, Timesheet $entry)
{
// allows to set values per calculator after merging the timesheet
}
}

View File

@@ -11,6 +11,7 @@ namespace App\Invoice\Calculator;
use App\Entity\Timesheet;
use App\Invoice\CalculatorInterface;
use App\Invoice\InvoiceItem;
/**
* A calculator that sums up the timesheet records by activity.
@@ -26,6 +27,12 @@ class ActivityInvoiceCalculator extends AbstractSumInvoiceCalculator implements
return (string) $timesheet->getActivity()->getId();
}
protected function mergeSumTimesheet(InvoiceItem $invoiceItem, Timesheet $entry)
{
$invoiceItem->setActivity($entry->getActivity());
$invoiceItem->setDescription($entry->getActivity()->getName());
}
/**
* @return string
*/

View File

@@ -11,6 +11,7 @@ namespace App\Invoice\Calculator;
use App\Entity\Timesheet;
use App\Invoice\CalculatorInterface;
use App\Invoice\InvoiceItem;
/**
* A calculator that sums up the timesheet records by project.
@@ -26,6 +27,12 @@ class ProjectInvoiceCalculator extends AbstractSumInvoiceCalculator implements C
return (string) $timesheet->getProject()->getId();
}
protected function mergeSumTimesheet(InvoiceItem $invoiceItem, Timesheet $entry)
{
$invoiceItem->setProject($entry->getProject());
$invoiceItem->setDescription($entry->getProject()->getName());
}
/**
* @return string
*/

View File

@@ -9,37 +9,21 @@
namespace App\Invoice\Calculator;
use App\Entity\Timesheet;
use App\Invoice\CalculatorInterface;
use App\Invoice\InvoiceItem;
/**
* A calculator that sums up the timesheet records by user.
*/
class UserInvoiceCalculator extends AbstractMergedCalculator implements CalculatorInterface
class UserInvoiceCalculator extends AbstractSumInvoiceCalculator implements CalculatorInterface
{
/**
* @return InvoiceItem[]
*/
public function getEntries()
protected function calculateSumIdentifier(Timesheet $timesheet): string
{
$entries = $this->model->getEntries();
if (empty($entries)) {
return [];
if (null === $timesheet->getUser()->getId()) {
throw new \Exception('Cannot handle un-persisted user');
}
/** @var InvoiceItem[] $invoiceItems */
$invoiceItems = [];
foreach ($entries as $entry) {
$id = $entry->getUser()->getId();
if (!isset($invoiceItems[$id])) {
$invoiceItems[$id] = new InvoiceItem();
}
$invoiceItem = $invoiceItems[$id];
$this->mergeTimesheets($invoiceItem, $entry);
}
return array_values($invoiceItems);
return (string) $timesheet->getUser()->getId();
}
/**