new invoice template variables for budgets (#3005)
This commit is contained in:
@@ -9,12 +9,20 @@
|
||||
|
||||
namespace App\Invoice\Hydrator;
|
||||
|
||||
use App\Activity\ActivityStatisticService;
|
||||
use App\Entity\Activity;
|
||||
use App\Invoice\InvoiceModel;
|
||||
use App\Invoice\InvoiceModelHydrator;
|
||||
|
||||
class InvoiceModelActivityHydrator implements InvoiceModelHydrator
|
||||
{
|
||||
private $activityStatistic;
|
||||
|
||||
public function __construct(ActivityStatisticService $activityStatistic)
|
||||
{
|
||||
$this->activityStatistic = $activityStatistic;
|
||||
}
|
||||
|
||||
public function hydrate(InvoiceModel $model): array
|
||||
{
|
||||
if (!$model->getQuery()->hasActivities()) {
|
||||
@@ -24,19 +32,23 @@ class InvoiceModelActivityHydrator implements InvoiceModelHydrator
|
||||
$values = [];
|
||||
$i = 0;
|
||||
|
||||
if (\count($model->getQuery()->getActivities()) === 1) {
|
||||
$values['activity'] = $model->getQuery()->getActivities()[0]->getName();
|
||||
}
|
||||
|
||||
foreach ($model->getQuery()->getActivities() as $activity) {
|
||||
$prefix = '';
|
||||
if ($i > 0) {
|
||||
$prefix = $i . '.';
|
||||
}
|
||||
$values = array_merge($values, $this->getValuesFromActivity($activity, $prefix));
|
||||
$values = array_merge($values, $this->getValuesFromActivity($model, $activity, $prefix));
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
private function getValuesFromActivity(Activity $activity, string $prefix): array
|
||||
private function getValuesFromActivity(InvoiceModel $model, Activity $activity, string $prefix): array
|
||||
{
|
||||
$prefix = 'activity.' . $prefix;
|
||||
|
||||
@@ -46,6 +58,23 @@ class InvoiceModelActivityHydrator implements InvoiceModelHydrator
|
||||
$prefix . 'comment' => $activity->getComment(),
|
||||
];
|
||||
|
||||
$statistic = $this->activityStatistic->getBudgetStatisticModel($activity, $model->getQuery()->getEnd());
|
||||
$formatter = $model->getFormatter();
|
||||
$currency = $model->getCurrency();
|
||||
|
||||
if ($model->getTemplate()->isDecimalDuration()) {
|
||||
$budgetOpenDuration = $formatter->getFormattedDecimalDuration($statistic->getTimeBudgetOpen());
|
||||
} else {
|
||||
$budgetOpenDuration = $formatter->getFormattedDuration($statistic->getTimeBudgetOpen());
|
||||
}
|
||||
|
||||
$values = array_merge($values, [
|
||||
$prefix . 'budget_open' => $formatter->getFormattedMoney($statistic->getBudgetOpen(), $currency),
|
||||
$prefix . 'budget_open_plain' => $statistic->getBudgetOpen(),
|
||||
$prefix . 'time_budget_open' => $budgetOpenDuration,
|
||||
$prefix . 'time_budget_open_plain' => $statistic->getTimeBudgetOpen(),
|
||||
]);
|
||||
|
||||
foreach ($activity->getVisibleMetaFields() as $metaField) {
|
||||
$values = array_merge($values, [
|
||||
$prefix . 'meta.' . $metaField->getName() => $metaField->getValue(),
|
||||
|
||||
@@ -9,11 +9,19 @@
|
||||
|
||||
namespace App\Invoice\Hydrator;
|
||||
|
||||
use App\Customer\CustomerStatisticService;
|
||||
use App\Invoice\InvoiceModel;
|
||||
use App\Invoice\InvoiceModelHydrator;
|
||||
|
||||
class InvoiceModelCustomerHydrator implements InvoiceModelHydrator
|
||||
{
|
||||
private $customerStatistic;
|
||||
|
||||
public function __construct(CustomerStatisticService $customerStatistic)
|
||||
{
|
||||
$this->customerStatistic = $customerStatistic;
|
||||
}
|
||||
|
||||
public function hydrate(InvoiceModel $model): array
|
||||
{
|
||||
$customer = $model->getCustomer();
|
||||
@@ -22,9 +30,6 @@ class InvoiceModelCustomerHydrator implements InvoiceModelHydrator
|
||||
return [];
|
||||
}
|
||||
|
||||
$formatter = $model->getFormatter();
|
||||
$currency = $model->getCurrency();
|
||||
|
||||
$values = [
|
||||
'customer.id' => $customer->getId(),
|
||||
'customer.address' => $customer->getAddress(),
|
||||
@@ -40,12 +45,25 @@ class InvoiceModelCustomerHydrator implements InvoiceModelHydrator
|
||||
'customer.fax' => $customer->getFax(),
|
||||
'customer.phone' => $customer->getPhone(),
|
||||
'customer.mobile' => $customer->getMobile(),
|
||||
// budget
|
||||
// remaining budget?
|
||||
// time-budget
|
||||
// remaining time-budget?
|
||||
];
|
||||
|
||||
$statistic = $this->customerStatistic->getBudgetStatisticModel($customer, $model->getQuery()->getEnd());
|
||||
$currency = $model->getCurrency();
|
||||
$formatter = $model->getFormatter();
|
||||
|
||||
if ($model->getTemplate()->isDecimalDuration()) {
|
||||
$budgetOpenDuration = $formatter->getFormattedDecimalDuration($statistic->getTimeBudgetOpen());
|
||||
} else {
|
||||
$budgetOpenDuration = $formatter->getFormattedDuration($statistic->getTimeBudgetOpen());
|
||||
}
|
||||
|
||||
$values = array_merge($values, [
|
||||
'customer.budget_open' => $formatter->getFormattedMoney($statistic->getBudgetOpen(), $currency),
|
||||
'customer.budget_open_plain' => $statistic->getBudgetOpen(),
|
||||
'customer.time_budget_open' => $budgetOpenDuration,
|
||||
'customer.time_budget_open_plain' => $statistic->getTimeBudgetOpen(),
|
||||
]);
|
||||
|
||||
foreach ($customer->getMetaFields() as $metaField) {
|
||||
$values = array_merge($values, [
|
||||
'customer.meta.' . $metaField->getName() => $metaField->getValue(),
|
||||
|
||||
@@ -10,40 +10,51 @@
|
||||
namespace App\Invoice\Hydrator;
|
||||
|
||||
use App\Entity\Project;
|
||||
use App\Invoice\InvoiceFormatter;
|
||||
use App\Invoice\InvoiceModel;
|
||||
use App\Invoice\InvoiceModelHydrator;
|
||||
use App\Project\ProjectStatisticService;
|
||||
|
||||
class InvoiceModelProjectHydrator implements InvoiceModelHydrator
|
||||
{
|
||||
private $projectStatistic;
|
||||
|
||||
public function __construct(ProjectStatisticService $projectStatistic)
|
||||
{
|
||||
$this->projectStatistic = $projectStatistic;
|
||||
}
|
||||
|
||||
public function hydrate(InvoiceModel $model): array
|
||||
{
|
||||
if (!$model->getQuery()->hasProjects()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$formatter = $model->getFormatter();
|
||||
$currency = $model->getCurrency();
|
||||
|
||||
$values = [];
|
||||
$i = 0;
|
||||
|
||||
if (\count($model->getQuery()->getProjects()) === 1) {
|
||||
$values['project'] = $model->getQuery()->getProjects()[0]->getName();
|
||||
}
|
||||
|
||||
foreach ($model->getQuery()->getProjects() as $project) {
|
||||
$prefix = '';
|
||||
if ($i > 0) {
|
||||
$prefix = $i . '.';
|
||||
}
|
||||
$values = array_merge($values, $this->getValuesFromProject($project, $formatter, $currency, $prefix));
|
||||
$values = array_merge($values, $this->getValuesFromProject($model, $project, $prefix));
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
private function getValuesFromProject(Project $project, InvoiceFormatter $formatter, string $currency, string $prefix): array
|
||||
private function getValuesFromProject(InvoiceModel $model, Project $project, string $prefix): array
|
||||
{
|
||||
$prefix = 'project.' . $prefix;
|
||||
|
||||
$formatter = $model->getFormatter();
|
||||
$currency = $model->getCurrency();
|
||||
|
||||
$values = [
|
||||
$prefix . 'id' => $project->getId(),
|
||||
$prefix . 'name' => $project->getName(),
|
||||
@@ -60,6 +71,21 @@ class InvoiceModelProjectHydrator implements InvoiceModelHydrator
|
||||
$prefix . 'budget_time_minutes' => (int) ($project->getTimeBudget() / 60),
|
||||
];
|
||||
|
||||
$statistic = $this->projectStatistic->getBudgetStatisticModel($project, $model->getQuery()->getEnd());
|
||||
|
||||
if ($model->getTemplate()->isDecimalDuration()) {
|
||||
$budgetOpenDuration = $formatter->getFormattedDecimalDuration($statistic->getTimeBudgetOpen());
|
||||
} else {
|
||||
$budgetOpenDuration = $formatter->getFormattedDuration($statistic->getTimeBudgetOpen());
|
||||
}
|
||||
|
||||
$values = array_merge($values, [
|
||||
$prefix . 'budget_open' => $formatter->getFormattedMoney($statistic->getBudgetOpen(), $currency),
|
||||
$prefix . 'budget_open_plain' => $statistic->getBudgetOpen(),
|
||||
$prefix . 'time_budget_open' => $budgetOpenDuration,
|
||||
$prefix . 'time_budget_open_plain' => $statistic->getTimeBudgetOpen(),
|
||||
]);
|
||||
|
||||
foreach ($project->getVisibleMetaFields() as $metaField) {
|
||||
$values = array_merge($values, [
|
||||
$prefix . 'meta.' . $metaField->getName() => $metaField->getValue(),
|
||||
|
||||
Reference in New Issue
Block a user