improved invoice handling for fixed rates (#1058)

This commit is contained in:
Kevin Papst
2019-08-24 00:02:16 +02:00
committed by GitHub
parent 46e5650882
commit ceeec7b8a6
40 changed files with 581 additions and 131 deletions

View File

@@ -10,7 +10,7 @@
namespace App\Invoice\Renderer;
use App\Entity\InvoiceDocument;
use App\Model\InvoiceModel;
use App\Invoice\InvoiceModel;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;

View File

@@ -10,8 +10,8 @@
namespace App\Invoice\Renderer;
use App\Entity\InvoiceDocument;
use App\Invoice\InvoiceModel;
use App\Invoice\RendererInterface;
use App\Model\InvoiceModel;
use PhpOffice\PhpWord\Escaper\Xml;
use PhpOffice\PhpWord\Exception\Exception as OfficeException;
use PhpOffice\PhpWord\Settings;

View File

@@ -10,9 +10,9 @@
namespace App\Invoice\Renderer;
use App\Entity\InvoiceDocument;
use App\Entity\Timesheet;
use App\Entity\UserPreference;
use App\Model\InvoiceModel;
use App\Invoice\InvoiceItem;
use App\Invoice\InvoiceModel;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
@@ -176,40 +176,36 @@ trait RendererTrait
return $values;
}
/**
* @param Timesheet $timesheet
* @return array
*/
protected function timesheetToArray(Timesheet $timesheet)
protected function timesheetToArray(InvoiceItem $invoiceItem): array
{
$rate = $timesheet->getRate();
$hourlyRate = $timesheet->getHourlyRate();
$amount = $this->getFormattedDuration($timesheet->getDuration());
$description = $timesheet->getDescription();
$rate = $invoiceItem->getRate();
$hourlyRate = $invoiceItem->getHourlyRate();
$amount = $this->getFormattedDuration($invoiceItem->getDuration());
$description = $invoiceItem->getDescription();
if (null !== $timesheet->getFixedRate()) {
$rate = $timesheet->getFixedRate();
$hourlyRate = $timesheet->getFixedRate();
$amount = 1; // FIXME fixed rates
if (null !== $invoiceItem->getFixedRate()) {
$rate = $invoiceItem->getFixedRate();
$hourlyRate = $invoiceItem->getFixedRate();
$amount = $invoiceItem->getAmount();
}
if (empty($description)) {
$description = $timesheet->getActivity()->getName();
$description = $invoiceItem->getActivity()->getName();
}
$user = $timesheet->getUser();
$user = $invoiceItem->getUser();
if (empty($hourlyRate)) {
$hourlyRate = $user->getPreferenceValue(UserPreference::HOURLY_RATE);
}
$activity = $timesheet->getActivity();
$project = $timesheet->getProject();
$activity = $invoiceItem->getActivity();
$project = $invoiceItem->getProject();
$customer = $project->getCustomer();
$currency = $customer->getCurrency();
$begin = $timesheet->getBegin();
$end = $timesheet->getEnd();
$begin = $invoiceItem->getBegin();
$end = $invoiceItem->getEnd();
$values = [
'entry.row' => '',
@@ -218,9 +214,9 @@ trait RendererTrait
'entry.rate' => $this->getFormattedMoney($hourlyRate, $currency),
'entry.total' => $this->getFormattedMoney($rate, $currency),
'entry.currency' => $currency,
'entry.duration' => $timesheet->getDuration(),
'entry.duration_decimal' => $this->getFormattedDecimalDuration($timesheet->getDuration()),
'entry.duration_minutes' => number_format($timesheet->getDuration() / 60),
'entry.duration' => $invoiceItem->getDuration(),
'entry.duration_decimal' => $this->getFormattedDecimalDuration($invoiceItem->getDuration()),
'entry.duration_minutes' => number_format($invoiceItem->getDuration() / 60),
'entry.begin' => $this->getFormattedDateTime($begin),
'entry.begin_time' => $this->getFormattedTime($begin),
'entry.begin_timestamp' => $begin->getTimestamp(),
@@ -240,9 +236,9 @@ trait RendererTrait
'entry.customer_id' => $customer->getId(),
];
foreach ($timesheet->getVisibleMetaFields() as $metaField) {
foreach ($invoiceItem->getAdditionalFields() as $name => $value) {
$values = array_merge($values, [
'entry.meta.' . $metaField->getName() => $metaField->getValue(),
'entry.meta.' . $name => $value,
]);
}

View File

@@ -10,8 +10,8 @@
namespace App\Invoice\Renderer;
use App\Entity\InvoiceDocument;
use App\Invoice\InvoiceModel;
use App\Invoice\RendererInterface;
use App\Model\InvoiceModel;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;