From 1958bb9d09a4ae079cf0e6dd86707e2ff8a7b547 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Thu, 25 Jan 2018 21:42:18 +0100 Subject: [PATCH] added order number to projects #107 (#108) --- config/packages/kimai.yaml | 1 - src/Controller/InvoiceController.php | 4 +- src/Entity/Project.php | 43 +++++++++++++------ src/Form/ProjectEditForm.php | 13 +++--- src/Invoice/RandomNumberGenerator.php | 43 ------------------- src/Model/InvoiceModel.php | 24 ++++++----- .../invoice/{ => renderer}/print.html.twig | 9 +++- .../{ => renderer}/timesheet.html.twig | 8 ++++ tests/Voter/TimesheetVoterTest.php | 2 +- translations/messages.de.xliff | 8 ++-- translations/messages.en.xliff | 8 ++-- 11 files changed, 76 insertions(+), 87 deletions(-) delete mode 100644 src/Invoice/RandomNumberGenerator.php rename templates/invoice/{ => renderer}/print.html.twig (90%) rename templates/invoice/{ => renderer}/timesheet.html.twig (89%) diff --git a/config/packages/kimai.yaml b/config/packages/kimai.yaml index d99d7e4c..84a75493 100644 --- a/config/packages/kimai.yaml +++ b/config/packages/kimai.yaml @@ -10,7 +10,6 @@ kimai: short: 'App\Invoice\ShortInvoiceCalculator' number_generator: default: 'App\Invoice\DateNumberGenerator' - #random: 'App\Invoice\RandomNumberGenerator' twig: globals: diff --git a/src/Controller/InvoiceController.php b/src/Controller/InvoiceController.php index e23ed9c3..1fe2face 100644 --- a/src/Controller/InvoiceController.php +++ b/src/Controller/InvoiceController.php @@ -226,7 +226,7 @@ class InvoiceController extends AbstractController */ public function invoiceAction(InvoiceModel $model) { - return $this->render('invoice/print.html.twig', [ + return $this->render('invoice/renderer/print.html.twig', [ 'model' => $model, ]); } @@ -237,7 +237,7 @@ class InvoiceController extends AbstractController */ public function timesheetAction(InvoiceModel $model) { - return $this->render('invoice/timesheet.html.twig', [ + return $this->render('invoice/renderer/timesheet.html.twig', [ 'model' => $model, ]); } diff --git a/src/Entity/Project.php b/src/Entity/Project.php index 8d237161..d42367a3 100644 --- a/src/Entity/Project.php +++ b/src/Entity/Project.php @@ -52,6 +52,14 @@ class Project */ private $name; + /** + * @var string + * + * @ORM\Column(name="order_number", type="text", length=20, nullable=true) + * @Assert\Length(max=20) + */ + private $orderNumber; + /** * @var string * @@ -68,7 +76,7 @@ class Project private $visible = true; /** - * @var string + * @var float * * @ORM\Column(name="budget", type="decimal", precision=10, scale=2, nullable=false) * @Assert\NotNull() @@ -114,13 +122,11 @@ class Project * Set name * * @param string $name - * * @return Project */ public function setName($name) { $this->name = $name; - return $this; } @@ -138,13 +144,11 @@ class Project * Set comment * * @param string $comment - * * @return Project */ public function setComment($comment) { $this->comment = $comment; - return $this; } @@ -162,13 +166,11 @@ class Project * Set visible * * @param boolean $visible - * * @return Project */ public function setVisible($visible) { $this->visible = $visible; - return $this; } @@ -185,21 +187,19 @@ class Project /** * Set budget * - * @param string $budget - * + * @param float $budget * @return Project */ public function setBudget($budget) { $this->budget = $budget; - return $this; } /** * Get budget * - * @return string + * @return float */ public function getBudget() { @@ -208,12 +208,11 @@ class Project /** * @param Activity[] $activities - * @return $this + * @return Project */ public function setActivities($activities) { $this->activities = $activities; - return $this; } @@ -225,6 +224,24 @@ class Project return $this->activities; } + /** + * @return string + */ + public function getOrderNumber(): ?string + { + return $this->orderNumber; + } + + /** + * @param string $orderNumber + * @return Project + */ + public function setOrderNumber($orderNumber) + { + $this->orderNumber = $orderNumber; + return $this; + } + /** * @return string */ diff --git a/src/Form/ProjectEditForm.php b/src/Form/ProjectEditForm.php index 5fab9de6..d512bf91 100644 --- a/src/Form/ProjectEditForm.php +++ b/src/Form/ProjectEditForm.php @@ -45,29 +45,30 @@ class ProjectEditForm extends AbstractType } $builder - // string - length 255 ->add('name', TextType::class, [ 'label' => 'label.name', ]) - // text ->add('comment', TextareaType::class, [ 'label' => 'label.comment', + 'required' => false, + ]) + ->add('orderNumber', TextType::class, [ + 'label' => 'label.order_number', + 'required' => false, ]) - // customer ->add('customer', CustomerType::class, [ 'label' => 'label.customer', 'query_builder' => function (CustomerRepository $repo) use ($customer) { return $repo->builderForEntityType($customer); }, ]) - // boolean ->add('visible', VisibilityType::class, [ 'label' => 'label.visible', ]) - // string ->add('budget', MoneyType::class, [ 'label' => 'label.budget', - 'currency' => $builder->getOption('currency'), + 'currency' => $customer ? $customer->getCurrency() : $builder->getOption('currency'), + 'required' => false, ]) ; } diff --git a/src/Invoice/RandomNumberGenerator.php b/src/Invoice/RandomNumberGenerator.php deleted file mode 100644 index fb91be08..00000000 --- a/src/Invoice/RandomNumberGenerator.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace App\Invoice; - -use App\Model\InvoiceModel; - -/** - * Class RandomNumberGenerator is meant for testing purpose only. - * - * @author Kevin Papst - */ -class RandomNumberGenerator implements NumberGeneratorInterface -{ - /** - * @var InvoiceModel - */ - protected $model; - - /** - * @param InvoiceModel $model - */ - public function setModel(InvoiceModel $model) - { - $this->model = $model; - } - - /** - * @return string - */ - public function getInvoiceNumber(): string - { - return rand(1000000, 9999999); - } -} diff --git a/src/Model/InvoiceModel.php b/src/Model/InvoiceModel.php index 1bb4ac19..740cd7d4 100644 --- a/src/Model/InvoiceModel.php +++ b/src/Model/InvoiceModel.php @@ -77,6 +77,8 @@ class InvoiceModel } /** + * Do not use this method for rendering the invoice, use InvoiceModel::getCalculator()->getEntries() instead. + * * @return Timesheet[] */ public function getEntries(): array @@ -146,17 +148,6 @@ class InvoiceModel return new \DateTime(); } - /** - * @param CalculatorInterface $calculator - * @return InvoiceModel - */ - public function setCalculator(CalculatorInterface $calculator) - { - $this->calculator = $calculator; - $this->calculator->setModel($this); - return $this; - } - /** * @param NumberGeneratorInterface $generator * @return InvoiceModel @@ -176,6 +167,17 @@ class InvoiceModel return $this->generator; } + /** + * @param CalculatorInterface $calculator + * @return InvoiceModel + */ + public function setCalculator(CalculatorInterface $calculator) + { + $this->calculator = $calculator; + $this->calculator->setModel($this); + return $this; + } + /** * @return CalculatorInterface */ diff --git a/templates/invoice/print.html.twig b/templates/invoice/renderer/print.html.twig similarity index 90% rename from templates/invoice/print.html.twig rename to templates/invoice/renderer/print.html.twig index 36515197..73105d94 100644 --- a/templates/invoice/print.html.twig +++ b/templates/invoice/renderer/print.html.twig @@ -36,8 +36,13 @@ {{ 'invoice.number'|trans }}: {{ model.numberGenerator.invoiceNumber }}

- {{ 'invoice.due_days'|trans }}: {{ model.dueDate|date(kimai_context.date_1) }}
- {% if model.customer.number is not empty %}{{ 'label.customer_number'|trans }}: {{ model.customer.number }}
{% endif %} + {{ 'invoice.due_days'|trans }}: {{ model.dueDate|date(kimai_context.date_1) }} + {% if model.customer.number is not empty %} +
{{ 'label.customer_number'|trans }}: {{ model.customer.number }} + {% endif %} + {% if model.query.project is not empty and model.query.project.orderNumber is not empty %} +
{{ 'label.order_number'|trans }}: {{ model.query.project.orderNumber }} + {% endif %}

diff --git a/templates/invoice/timesheet.html.twig b/templates/invoice/renderer/timesheet.html.twig similarity index 89% rename from templates/invoice/timesheet.html.twig rename to templates/invoice/renderer/timesheet.html.twig index b3b6fb2d..137cc6e6 100644 --- a/templates/invoice/timesheet.html.twig +++ b/templates/invoice/renderer/timesheet.html.twig @@ -32,6 +32,14 @@ {{ model.customer.name }} / {{ model.customer.contact }} + {% if model.query.project is not empty and model.query.project.orderNumber is not empty %} + + {{ 'label.order_number'|trans }} + + {{ model.query.project.orderNumber }} + + + {% endif %} diff --git a/tests/Voter/TimesheetVoterTest.php b/tests/Voter/TimesheetVoterTest.php index 669eb1c8..b44afca3 100644 --- a/tests/Voter/TimesheetVoterTest.php +++ b/tests/Voter/TimesheetVoterTest.php @@ -30,7 +30,7 @@ class TimesheetVoterTest extends TestCase /** * @dataProvider getTestData */ - public function testCustomerIsDisallowed($user, $allow, $subject, $attributes, $result) + public function testCustomerIsDisallowed(User $user, $allow, $subject, $attributes, $result) { $token = new UsernamePasswordToken($user, 'foo', 'bar', $user->getRoles()); diff --git a/translations/messages.de.xliff b/translations/messages.de.xliff index d13d4a40..53bb6256 100644 --- a/translations/messages.de.xliff +++ b/translations/messages.de.xliff @@ -687,10 +687,6 @@ invoice_number_generator.default Datum (Standard) - - invoice_number_generator.random - Zufallszahl (nur zum Testen) - label.invoice_calculator Zahlungsberechnung @@ -711,6 +707,10 @@ invoice.signature_customer Leistungsbestätigung: Datum / Name Kunde / Unterschrift + + label.order_number + Bestellnummer +