export budget, timeBudget and budgetType (#2812)

This commit is contained in:
Kevin Papst
2021-10-04 16:57:45 +02:00
committed by GitHub
parent d25653b6ed
commit 9453947309
9 changed files with 54 additions and 29 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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")
*/

View File

@@ -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]);
}
}

View File

@@ -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'],

View File

@@ -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'],

View File

@@ -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());
}
}

View File

@@ -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());
}
}