From 9453947309d3c3feb6e5fcd81571955da58562b9 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Mon, 4 Oct 2021 16:57:45 +0200 Subject: [PATCH] export budget, timeBudget and budgetType (#2812) --- src/Entity/Activity.php | 2 +- src/Entity/BudgetTrait.php | 12 ++++++-- src/Entity/Customer.php | 2 +- src/Entity/Project.php | 2 +- tests/Entity/ActivityTest.php | 5 +++- tests/Entity/CustomerTest.php | 3 ++ tests/Entity/ProjectTest.php | 3 ++ .../AnnotatedObjectExporterTest.php | 26 ++++++++++------- .../EntityWithMetaFieldsExporterTest.php | 28 +++++++++++-------- 9 files changed, 54 insertions(+), 29 deletions(-) diff --git a/src/Entity/Activity.php b/src/Entity/Activity.php index d71b5d64..4b4c9f9e 100644 --- a/src/Entity/Activity.php +++ b/src/Entity/Activity.php @@ -47,7 +47,7 @@ use Symfony\Component\Validator\Constraints as Assert; * } * ) * - * @Exporter\Order({"id", "name", "project", "budget", "timeBudget", "color", "visible", "comment"}) + * @Exporter\Order({"id", "name", "project", "budget", "timeBudget", "budgetType", "color", "visible", "comment"}) * @Exporter\Expose("project", label="label.project", exp="object.getProject() === null ? null : object.getProject().getName()") */ class Activity implements EntityWithMetaFields, EntityWithBudget diff --git a/src/Entity/BudgetTrait.php b/src/Entity/BudgetTrait.php index d92807db..055f5598 100644 --- a/src/Entity/BudgetTrait.php +++ b/src/Entity/BudgetTrait.php @@ -9,6 +9,7 @@ namespace App\Entity; +use App\Export\Annotation as Exporter; use Doctrine\ORM\Mapping as ORM; use JMS\Serializer\Annotation as Serializer; use Symfony\Component\Validator\Constraints as Assert; @@ -23,7 +24,7 @@ trait BudgetTrait * @Serializer\Expose() * @Serializer\Groups({"Activity_Entity", "Project_Entity", "Customer_Entity"}) * - * @ Exporter\Expose(label="label.budget") + * @Exporter\Expose(label="label.budget", type="float") * * @ORM\Column(name="budget", type="float", nullable=false) * @Assert\Range(min=0.00, max=900000000000.00) @@ -38,7 +39,7 @@ trait BudgetTrait * @Serializer\Expose() * @Serializer\Groups({"Activity_Entity", "Project_Entity", "Customer_Entity"}) * - * @ Exporter\Expose(label="label.timeBudget", type="duration") + * @Exporter\Expose(label="label.timeBudget", type="duration") * * @ORM\Column(name="time_budget", type="integer", nullable=false) * @Assert\Range(min=0, max=2145600000) @@ -55,7 +56,7 @@ trait BudgetTrait * @Serializer\Expose() * @Serializer\Groups({"Activity_Entity", "Project_Entity", "Customer_Entity"}) * - * @ Exporter\Expose(label="label.timeBudget", type="duration") + * @Exporter\Expose(label="label.budgetType") * * @ORM\Column(name="budget_type", type="string", length=10, nullable=true) */ @@ -99,6 +100,11 @@ trait BudgetTrait $this->budgetType = $budgetType; } + public function setIsMonthlyBudget(): void + { + $this->setBudgetType('month'); + } + public function getBudgetType(): ?string { return $this->budgetType; diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index f23b813e..90575946 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -27,7 +27,7 @@ use Symfony\Component\Validator\Constraints as Assert; * * @Serializer\ExclusionPolicy("all") * - * @Exporter\Order({"id", "name", "company", "number", "vatId", "address", "contact","email", "phone", "mobile", "fax", "homepage", "country", "currency", "timezone", "budget", "timeBudget", "color", "visible", "teams", "comment"}) + * @Exporter\Order({"id", "name", "company", "number", "vatId", "address", "contact","email", "phone", "mobile", "fax", "homepage", "country", "currency", "timezone", "budget", "timeBudget", "budgetType", "color", "visible", "teams", "comment"}) * @ Exporter\Expose("teams", label="label.team", exp="object.getTeams().toArray()", type="array") */ class Customer implements EntityWithMetaFields, EntityWithBudget diff --git a/src/Entity/Project.php b/src/Entity/Project.php index 0fb3b69f..8820ebdd 100644 --- a/src/Entity/Project.php +++ b/src/Entity/Project.php @@ -48,7 +48,7 @@ use Symfony\Component\Validator\Constraints as Assert; * } * ) * - * @Exporter\Order({"id", "name", "customer", "orderNumber", "orderDate", "start", "end", "budget", "timeBudget", "color", "visible", "teams", "comment"}) + * @Exporter\Order({"id", "name", "customer", "orderNumber", "orderDate", "start", "end", "budget", "timeBudget", "budgetType", "color", "visible", "teams", "comment"}) * @Exporter\Expose("customer", label="label.customer", exp="object.getCustomer() === null ? null : object.getCustomer().getName()") * @ Exporter\Expose("teams", label="label.team", exp="object.getTeams().toArray()", type="array") */ diff --git a/tests/Entity/ActivityTest.php b/tests/Entity/ActivityTest.php index 0d2b8784..2e36d3e9 100644 --- a/tests/Entity/ActivityTest.php +++ b/tests/Entity/ActivityTest.php @@ -135,6 +135,9 @@ class ActivityTest extends AbstractEntityTest ['label.id', 'integer'], ['label.name', 'string'], ['label.project', 'string'], + ['label.budget', 'float'], + ['label.timeBudget', 'duration'], + ['label.budgetType', 'string'], ['label.color', 'string'], ['label.visible', 'boolean'], ['label.comment', 'string'], @@ -151,7 +154,7 @@ class ActivityTest extends AbstractEntityTest foreach ($expected as $item) { $column = $columns[$i++]; self::assertEquals($item[0], $column->getLabel()); - self::assertEquals($item[1], $column->getType()); + self::assertEquals($item[1], $column->getType(), 'Wrong type for field: ' . $item[0]); } } diff --git a/tests/Entity/CustomerTest.php b/tests/Entity/CustomerTest.php index d3ea83ea..6a12cad7 100644 --- a/tests/Entity/CustomerTest.php +++ b/tests/Entity/CustomerTest.php @@ -188,6 +188,9 @@ class CustomerTest extends AbstractEntityTest ['label.country', 'string'], ['label.currency', 'string'], ['label.timezone', 'string'], + ['label.budget', 'float'], + ['label.timeBudget', 'duration'], + ['label.budgetType', 'string'], ['label.color', 'string'], ['label.visible', 'boolean'], ['label.comment', 'string'], diff --git a/tests/Entity/ProjectTest.php b/tests/Entity/ProjectTest.php index 0a2644a1..bacc2087 100644 --- a/tests/Entity/ProjectTest.php +++ b/tests/Entity/ProjectTest.php @@ -163,6 +163,9 @@ class ProjectTest extends AbstractEntityTest ['label.orderDate', 'datetime'], ['label.project_start', 'datetime'], ['label.project_end', 'datetime'], + ['label.budget', 'float'], + ['label.timeBudget', 'duration'], + ['label.budgetType', 'string'], ['label.color', 'string'], ['label.visible', 'boolean'], ['label.comment', 'string'], diff --git a/tests/Export/Spreadsheet/AnnotatedObjectExporterTest.php b/tests/Export/Spreadsheet/AnnotatedObjectExporterTest.php index 457703c7..dc4aa234 100644 --- a/tests/Export/Spreadsheet/AnnotatedObjectExporterTest.php +++ b/tests/Export/Spreadsheet/AnnotatedObjectExporterTest.php @@ -35,6 +35,8 @@ class AnnotatedObjectExporterTest extends TestCase $project->setOrderNumber('1234567890'); $project->setBudget(123456.7890); $project->setTimeBudget(1234567890); + $project->setBudgetType(); + $project->setIsMonthlyBudget(); $project->setColor('#ababab'); $project->setVisible(false); @@ -42,15 +44,19 @@ class AnnotatedObjectExporterTest extends TestCase $spreadsheet = $sut->export(Project::class, [$project]); $worksheet = $spreadsheet->getActiveSheet(); - self::assertNull($worksheet->getCellByColumnAndRow(1, 2)->getValue()); - self::assertEquals('test project', $worksheet->getCellByColumnAndRow(2, 2)->getValue()); - self::assertEquals('A customer', $worksheet->getCellByColumnAndRow(3, 2)->getValue()); - self::assertEquals(1234567890, $worksheet->getCellByColumnAndRow(4, 2)->getValue()); - self::assertEquals('', $worksheet->getCellByColumnAndRow(5, 2)->getValue()); - self::assertEquals('', $worksheet->getCellByColumnAndRow(6, 2)->getValue()); - self::assertEquals('', $worksheet->getCellByColumnAndRow(7, 2)->getValue()); - self::assertEquals('#ababab', $worksheet->getCellByColumnAndRow(8, 2)->getValue()); - self::assertFalse($worksheet->getCellByColumnAndRow(9, 2)->getValue()); - self::assertEquals('Lorem Ipsum', $worksheet->getCellByColumnAndRow(10, 2)->getValue()); + $i = 0; + self::assertNull($worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('test project', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('A customer', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals(1234567890, $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals(123456.7890, $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('=1234567890/86400', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('month', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('#ababab', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertFalse($worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('Lorem Ipsum', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); } } diff --git a/tests/Export/Spreadsheet/EntityWithMetaFieldsExporterTest.php b/tests/Export/Spreadsheet/EntityWithMetaFieldsExporterTest.php index 426bfa25..ea5da53c 100644 --- a/tests/Export/Spreadsheet/EntityWithMetaFieldsExporterTest.php +++ b/tests/Export/Spreadsheet/EntityWithMetaFieldsExporterTest.php @@ -58,17 +58,21 @@ class EntityWithMetaFieldsExporterTest extends TestCase $spreadsheet = $sut->export(Project::class, [$project], new ProjectMetaDisplayEvent(new ProjectQuery(), ProjectMetaDisplayEvent::EXPORT)); $worksheet = $spreadsheet->getActiveSheet(); - self::assertNull($worksheet->getCellByColumnAndRow(1, 2)->getValue()); - self::assertEquals('test project', $worksheet->getCellByColumnAndRow(2, 2)->getValue()); - self::assertEquals('A customer', $worksheet->getCellByColumnAndRow(3, 2)->getValue()); - self::assertEquals(1234567890, $worksheet->getCellByColumnAndRow(4, 2)->getValue()); - self::assertEquals('', $worksheet->getCellByColumnAndRow(5, 2)->getValue()); - self::assertEquals('', $worksheet->getCellByColumnAndRow(6, 2)->getValue()); - self::assertEquals('', $worksheet->getCellByColumnAndRow(7, 2)->getValue()); - self::assertEquals('#ababab', $worksheet->getCellByColumnAndRow(8, 2)->getValue()); - self::assertFalse($worksheet->getCellByColumnAndRow(9, 2)->getValue()); - self::assertEquals('Lorem Ipsum', $worksheet->getCellByColumnAndRow(10, 2)->getValue()); - self::assertEquals('some magic', $worksheet->getCellByColumnAndRow(11, 2)->getValue()); - self::assertEquals('is happening', $worksheet->getCellByColumnAndRow(12, 2)->getValue()); + $i = 0; + self::assertNull($worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('test project', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('A customer', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals(1234567890, $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals(123456.7890, $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('=1234567890/86400', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('#ababab', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertFalse($worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('Lorem Ipsum', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('some magic', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); + self::assertEquals('is happening', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue()); } }