use timesheet description in invoices (#1079)
This commit is contained in:
@@ -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()) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user