added more columns to spreadsheet exports (#2413)
This commit is contained in:
@@ -49,7 +49,6 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
*
|
||||
* @Exporter\Order({"id", "name", "project", "budget", "timeBudget", "color", "visible", "comment"})
|
||||
* @Exporter\Expose("project", label="label.project", exp="object.getProject() === null ? null : object.getProject().getName()")
|
||||
* @ Exporter\Expose("teams", label="label.team", exp="object.getTeams().toArray()", type="array")
|
||||
*/
|
||||
class Activity implements EntityWithMetaFields
|
||||
{
|
||||
@@ -368,7 +367,22 @@ class Activity implements EntityWithMetaFields
|
||||
{
|
||||
if ($this->id) {
|
||||
$this->id = null;
|
||||
$this->meta = new ArrayCollection();
|
||||
}
|
||||
|
||||
$currentTeams = $this->teams;
|
||||
$this->teams = new ArrayCollection();
|
||||
/** @var Team $team */
|
||||
foreach ($currentTeams as $team) {
|
||||
$this->addTeam($team);
|
||||
}
|
||||
|
||||
$currentMeta = $this->meta;
|
||||
$this->meta = new ArrayCollection();
|
||||
/** @var ProjectMeta $meta */
|
||||
foreach ($currentMeta as $meta) {
|
||||
$newMeta = clone $meta;
|
||||
$newMeta->setEntity($this);
|
||||
$this->setMetaField($newMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -632,4 +632,27 @@ class Customer implements EntityWithMetaFields
|
||||
{
|
||||
return $this->getName();
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
if ($this->id) {
|
||||
$this->id = null;
|
||||
}
|
||||
|
||||
$currentTeams = $this->teams;
|
||||
$this->teams = new ArrayCollection();
|
||||
/** @var Team $team */
|
||||
foreach ($currentTeams as $team) {
|
||||
$this->addTeam($team);
|
||||
}
|
||||
|
||||
$currentMeta = $this->meta;
|
||||
$this->meta = new ArrayCollection();
|
||||
/** @var ProjectMeta $meta */
|
||||
foreach ($currentMeta as $meta) {
|
||||
$newMeta = clone $meta;
|
||||
$newMeta->setEntity($this);
|
||||
$this->setMetaField($newMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -531,8 +531,22 @@ class Project implements EntityWithMetaFields
|
||||
{
|
||||
if ($this->id) {
|
||||
$this->id = null;
|
||||
$this->teams = new ArrayCollection();
|
||||
$this->meta = new ArrayCollection();
|
||||
}
|
||||
|
||||
$currentTeams = $this->teams;
|
||||
$this->teams = new ArrayCollection();
|
||||
/** @var Team $team */
|
||||
foreach ($currentTeams as $team) {
|
||||
$this->addTeam($team);
|
||||
}
|
||||
|
||||
$currentMeta = $this->meta;
|
||||
$this->meta = new ArrayCollection();
|
||||
/** @var ProjectMeta $meta */
|
||||
foreach ($currentMeta as $meta) {
|
||||
$newMeta = clone $meta;
|
||||
$newMeta->setEntity($this);
|
||||
$this->setMetaField($newMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,8 +166,6 @@ class Timesheet implements EntityWithMetaFields, ExportItemInterface
|
||||
*/
|
||||
private $user;
|
||||
/**
|
||||
* Activity
|
||||
*
|
||||
* @var Activity
|
||||
*
|
||||
* @Serializer\Expose()
|
||||
@@ -180,8 +178,6 @@ class Timesheet implements EntityWithMetaFields, ExportItemInterface
|
||||
*/
|
||||
private $activity;
|
||||
/**
|
||||
* Project
|
||||
*
|
||||
* @var Project
|
||||
*
|
||||
* @Serializer\Expose()
|
||||
@@ -727,6 +723,13 @@ class Timesheet implements EntityWithMetaFields, ExportItemInterface
|
||||
$timesheet->setMetaField(clone $meta);
|
||||
}
|
||||
|
||||
$timesheet->tags = new ArrayCollection();
|
||||
|
||||
/** @var Tag $tag */
|
||||
foreach ($this->tags as $tag) {
|
||||
$timesheet->addTag($tag);
|
||||
}
|
||||
|
||||
return $timesheet;
|
||||
}
|
||||
|
||||
@@ -734,7 +737,24 @@ class Timesheet implements EntityWithMetaFields, ExportItemInterface
|
||||
{
|
||||
if ($this->id) {
|
||||
$this->id = null;
|
||||
$this->exported = false;
|
||||
}
|
||||
|
||||
$this->exported = false;
|
||||
|
||||
$currentMeta = $this->meta;
|
||||
$this->meta = new ArrayCollection();
|
||||
/** @var TimesheetMeta $meta */
|
||||
foreach ($currentMeta as $meta) {
|
||||
$newMeta = clone $meta;
|
||||
$newMeta->setEntity($this);
|
||||
$this->setMetaField($newMeta);
|
||||
}
|
||||
|
||||
$currentTags = $this->tags;
|
||||
$this->tags = new ArrayCollection();
|
||||
/** @var Tag $tag */
|
||||
foreach ($currentTags as $tag) {
|
||||
$this->addTag($tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +90,11 @@ abstract class AbstractSpreadsheetRenderer
|
||||
'project-meta' => [],
|
||||
'activity-meta' => [],
|
||||
'user-meta' => [],
|
||||
'type' => [],
|
||||
'category' => [],
|
||||
'customer_number' => [],
|
||||
'customer_vat' => [],
|
||||
'order_number' => [],
|
||||
];
|
||||
|
||||
public function __construct(TranslatorInterface $translator, LocaleFormatExtensions $dateExtension, EventDispatcherInterface $dispatcher, AuthorizationCheckerInterface $voter)
|
||||
@@ -503,6 +508,78 @@ abstract class AbstractSpreadsheetRenderer
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($columns['type']) && !isset($columns['type']['render'])) {
|
||||
$columns['type']['render'] = function (Worksheet $sheet, int $row, int $column, ExportItemInterface $entity) {
|
||||
$sheet->setCellValueByColumnAndRow($column, $row, $entity->getType());
|
||||
};
|
||||
}
|
||||
|
||||
if (isset($columns['category']) && !isset($columns['category']['render'])) {
|
||||
$columns['category']['render'] = function (Worksheet $sheet, int $row, int $column, ExportItemInterface $entity) {
|
||||
$sheet->setCellValueByColumnAndRow($column, $row, $entity->getCategory());
|
||||
};
|
||||
}
|
||||
|
||||
if (isset($columns['customer_number'])) {
|
||||
if (!isset($columns['customer_number']['header'])) {
|
||||
$columns['customer_number']['header'] = function (Worksheet $sheet, $row, $column) {
|
||||
$sheet->setCellValueByColumnAndRow($column, $row, $this->translator->trans('label.number'));
|
||||
|
||||
return 1;
|
||||
};
|
||||
}
|
||||
|
||||
if (!isset($columns['customer_number']['render'])) {
|
||||
$columns['customer_number']['render'] = function (Worksheet $sheet, int $row, int $column, ExportItemInterface $entity) {
|
||||
$customerId = '';
|
||||
if (null !== $entity->getProject()) {
|
||||
$customerId = $entity->getProject()->getCustomer()->getNumber();
|
||||
}
|
||||
$sheet->setCellValueByColumnAndRow($column, $row, $customerId);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($columns['customer_vat']) && !isset($columns['customer_vat']['render'])) {
|
||||
if (!isset($columns['customer_vat']['header'])) {
|
||||
$columns['customer_vat']['header'] = function (Worksheet $sheet, $row, $column) {
|
||||
$sheet->setCellValueByColumnAndRow($column, $row, $this->translator->trans('label.vat_id'));
|
||||
|
||||
return 1;
|
||||
};
|
||||
}
|
||||
|
||||
if (!isset($columns['customer_vat']['render'])) {
|
||||
$columns['customer_vat']['render'] = function (Worksheet $sheet, int $row, int $column, ExportItemInterface $entity) {
|
||||
$customerVat = '';
|
||||
if (null !== $entity->getProject()) {
|
||||
$customerVat = $entity->getProject()->getCustomer()->getVatId();
|
||||
}
|
||||
$sheet->setCellValueByColumnAndRow($column, $row, $customerVat);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($columns['order_number']) && !isset($columns['order_number']['render'])) {
|
||||
if (!isset($columns['order_number']['header'])) {
|
||||
$columns['order_number']['header'] = function (Worksheet $sheet, $row, $column) {
|
||||
$sheet->setCellValueByColumnAndRow($column, $row, $this->translator->trans('label.orderNumber'));
|
||||
|
||||
return 1;
|
||||
};
|
||||
}
|
||||
|
||||
if (!isset($columns['order_number']['render'])) {
|
||||
$columns['order_number']['render'] = function (Worksheet $sheet, int $row, int $column, ExportItemInterface $entity) {
|
||||
$orderNumber = '';
|
||||
if (null !== $entity->getProject()) {
|
||||
$orderNumber = $entity->getProject()->getOrderNumber();
|
||||
}
|
||||
$sheet->setCellValueByColumnAndRow($column, $row, $orderNumber);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (!$showRates) {
|
||||
$removes = ['rate', 'fixedRate', 'hourlyRate', 'rate_internal'];
|
||||
foreach ($removes as $removeMe) {
|
||||
|
||||
Reference in New Issue
Block a user