From 1d37271b2410afe8dfea2f17cce69d6bff1c5938 Mon Sep 17 00:00:00 2001 From: Adam Kasperczak Date: Thu, 12 Aug 2021 15:08:44 +0200 Subject: [PATCH] change bool to state on payment on invoce state --- UPGRADE.md | 8 ++++---- spec/Entity/InvoiceSpec.php | 2 +- spec/Factory/InvoiceFactorySpec.php | 4 ++-- spec/Generator/InvoiceGeneratorSpec.php | 2 +- src/Entity/Invoice.php | 17 ++++++---------- src/Entity/InvoiceInterface.php | 8 +++++--- src/Factory/InvoiceFactory.php | 4 ++-- src/Factory/InvoiceFactoryInterface.php | 2 +- src/Generator/InvoiceGenerator.php | 6 +++--- ...11092457.php => Version20210812125029.php} | 20 ++++++++----------- src/Resources/config/doctrine/Invoice.orm.xml | 2 +- .../views/Invoice/Download/pdf.html.twig | 2 +- src/Resources/views/Invoice/show.html.twig | 2 +- 13 files changed, 36 insertions(+), 43 deletions(-) rename src/Migrations/{Version20210811092457.php => Version20210812125029.php} (65%) diff --git a/UPGRADE.md b/UPGRADE.md index 01e68db8..beeee508 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -2,7 +2,7 @@ Now on invoice admin and shop user can check if related order was paid before invoice generated. -1. `src/Entity/Invoice.php` model has new field (`isPaid`), and updated constructor arguments: +1. `src/Entity/Invoice.php` model has new field (`paymentState`), and updated constructor arguments: ```dif public function __construct( @@ -17,7 +17,7 @@ Now on invoice admin and shop user can check if related order was paid before in Collection $lineItems, Collection $taxItems, ChannelInterface $channel, - + bool $isPaid, + + string $paymentState, InvoiceShopBillingDataInterface $shopBillingData ) { $this->id = $id; @@ -31,7 +31,7 @@ Now on invoice admin and shop user can check if related order was paid before in $this->lineItems = $lineItems; $this->taxItems = $taxItems; $this->channel = $channel; - + $this->isPaid = $isPaid; + + $this->paymentState = $paymentState; $this->shopBillingData = $shopBillingData; ``` @@ -69,7 +69,7 @@ Invoices are now saved on the server during their generation (by default, when t to `InvoiceFileProviderInterface $invoiceFileProvider` 1. `Sylius\InvoicingPlugin\Generator\InvoicePdfFileGenerator` class has additional `InvoiceFileNameGeneratorInterface $invoiceFileNameGenerator` dependency, placed on 4th place, before `string $template` -1. `Sylius\InvoicingPlugin\Ui\Action\DownloadInvoisrc/Resources/views/Invoice/show.html.twigceAction` class 4th dependency has been changed from `InvoicePdfFileGeneratorInterface $invoicePdfFileGenerator` +1. `Sylius\InvoicingPlugin\Ui\Action\DownloadInvoiceAction` class 4th dependency has been changed from `InvoicePdfFileGeneratorInterface $invoicePdfFileGenerator` to `InvoiceFileProviderInterface $invoiceFilePathProvider` 1. `Sylius\InvoicingPlugin\Converter\LineItemsConverter` class has additional `TaxRatePercentageProviderInterface $taxRatePercentageProvider` dependency diff --git a/spec/Entity/InvoiceSpec.php b/spec/Entity/InvoiceSpec.php index 469c5127..8b5e067e 100644 --- a/spec/Entity/InvoiceSpec.php +++ b/spec/Entity/InvoiceSpec.php @@ -48,7 +48,7 @@ function let( new ArrayCollection([$lineItem->getWrappedObject()]), new ArrayCollection([$taxItem->getWrappedObject()]), $channel, - true, + InvoiceInterface::PAYMENT_STATE_COMPLETED, $shopBillingData ); } diff --git a/spec/Factory/InvoiceFactorySpec.php b/spec/Factory/InvoiceFactorySpec.php index d54fab7b..017ba1e4 100644 --- a/spec/Factory/InvoiceFactorySpec.php +++ b/spec/Factory/InvoiceFactorySpec.php @@ -49,7 +49,7 @@ function it_creates_an_invoice_for_given_data( new ArrayCollection(), new ArrayCollection(), $channel, - true, + InvoiceInterface::PAYMENT_STATE_COMPLETED, $invoiceShopBillingData )->shouldReturnAnInstanceOf(InvoiceInterface::class); } @@ -73,7 +73,7 @@ function it_allows_for_nullable_shop_billing_data( new ArrayCollection(), new ArrayCollection(), $channel, - true, + InvoiceInterface::PAYMENT_STATE_COMPLETED, null )->shouldReturnAnInstanceOf(InvoiceInterface::class); } diff --git a/spec/Generator/InvoiceGeneratorSpec.php b/spec/Generator/InvoiceGeneratorSpec.php index 0fe7f39e..45817bb1 100644 --- a/spec/Generator/InvoiceGeneratorSpec.php +++ b/spec/Generator/InvoiceGeneratorSpec.php @@ -112,7 +112,7 @@ function it_generates_an_invoice_for_a_given_order( new ArrayCollection([$unitLineItem->getWrappedObject(), $shippingLineItem->getWrappedObject()]), new ArrayCollection([$taxItem->getWrappedObject()]), $channel, - true, + InvoiceInterface::PAYMENT_STATE_COMPLETED, $invoiceShopBillingData )->willReturn($invoice); diff --git a/src/Entity/Invoice.php b/src/Entity/Invoice.php index 94446999..2588b44a 100644 --- a/src/Entity/Invoice.php +++ b/src/Entity/Invoice.php @@ -53,8 +53,8 @@ class Invoice implements InvoiceInterface /** @var ChannelInterface */ protected $channel; - /** @var bool */ - protected $isPaid; + /** @var string */ + protected $paymentState; /** @var InvoiceShopBillingDataInterface */ protected $shopBillingData; @@ -71,7 +71,7 @@ public function __construct( Collection $lineItems, Collection $taxItems, ChannelInterface $channel, - bool $isPaid, + string $paymentState, InvoiceShopBillingDataInterface $shopBillingData ) { $this->id = $id; @@ -85,7 +85,7 @@ public function __construct( $this->lineItems = $lineItems; $this->taxItems = $taxItems; $this->channel = $channel; - $this->isPaid = $isPaid; + $this->paymentState = $paymentState; $this->shopBillingData = $shopBillingData; /** @var LineItemInterface $lineItem */ @@ -193,13 +193,8 @@ public function shopBillingData(): InvoiceShopBillingDataInterface return $this->shopBillingData; } - public function isPaid(): bool - { - return $this->isPaid; - } - - public function setIsPaid(bool $isPaid): void + public function paymentState(): string { - $this->isPaid = $isPaid; + return $this->paymentState; } } diff --git a/src/Entity/InvoiceInterface.php b/src/Entity/InvoiceInterface.php index 321413f5..b47cbc2e 100644 --- a/src/Entity/InvoiceInterface.php +++ b/src/Entity/InvoiceInterface.php @@ -20,6 +20,10 @@ interface InvoiceInterface extends ResourceInterface { + public const PAYMENT_STATE_COMPLETED = 'Completed'; + + public const PAYMENT_STATE_PENDING = "Pending"; + public function id(): string; public function number(): string; @@ -51,7 +55,5 @@ public function channel(): ChannelInterface; public function shopBillingData(): InvoiceShopBillingDataInterface; - public function isPaid(): bool; - - public function setIsPaid(bool $isPaid): void; + public function paymentState(): string; } diff --git a/src/Factory/InvoiceFactory.php b/src/Factory/InvoiceFactory.php index 4072c34e..cef8e945 100644 --- a/src/Factory/InvoiceFactory.php +++ b/src/Factory/InvoiceFactory.php @@ -36,7 +36,7 @@ public function createForData( Collection $lineItems, Collection $taxItems, ChannelInterface $channel, - bool $isPaid, + string $paymentState, InvoiceShopBillingDataInterface $shopBillingData = null ): InvoiceInterface { return new Invoice( @@ -51,7 +51,7 @@ public function createForData( $lineItems, $taxItems, $channel, - $isPaid, + $paymentState, $shopBillingData ?? new InvoiceShopBillingData() ); } diff --git a/src/Factory/InvoiceFactoryInterface.php b/src/Factory/InvoiceFactoryInterface.php index 668259ee..03678a65 100644 --- a/src/Factory/InvoiceFactoryInterface.php +++ b/src/Factory/InvoiceFactoryInterface.php @@ -34,7 +34,7 @@ public function createForData( Collection $lineItems, Collection $taxItems, ChannelInterface $channel, - bool $isPaid, + string $paymentState, InvoiceShopBillingDataInterface $shopBillingData = null ): InvoiceInterface; } diff --git a/src/Generator/InvoiceGenerator.php b/src/Generator/InvoiceGenerator.php index e2a06c59..b8007007 100644 --- a/src/Generator/InvoiceGenerator.php +++ b/src/Generator/InvoiceGenerator.php @@ -79,8 +79,8 @@ public function generateForOrder(OrderInterface $order, \DateTimeInterface $date /** @var ChannelInterface $channel */ $channel = $order->getChannel(); - /** @var bool $isPaid */ - $isPaid = $order->getPaymentState() === PaymentInterface::STATE_COMPLETED; + $paymentState = $order->getPaymentState() === PaymentInterface::STATE_COMPLETED ? + InvoiceInterface::PAYMENT_STATE_COMPLETED : InvoiceInterface::PAYMENT_STATE_PENDING; return $this->invoiceFactory->createForData( $this->uuidInvoiceIdentifierGenerator->generate(), @@ -97,7 +97,7 @@ public function generateForOrder(OrderInterface $order, \DateTimeInterface $date )), $this->taxItemsConverter->convert($order), $channel, - $isPaid, + $paymentState, $this->invoiceShopBillingDataConverter->convert($channel) ); } diff --git a/src/Migrations/Version20210811092457.php b/src/Migrations/Version20210812125029.php similarity index 65% rename from src/Migrations/Version20210811092457.php rename to src/Migrations/Version20210812125029.php index 544d2fd6..cf4b0d88 100644 --- a/src/Migrations/Version20210811092457.php +++ b/src/Migrations/Version20210812125029.php @@ -1,14 +1,5 @@ addSql('ALTER TABLE sylius_invoicing_plugin_invoice ADD is_paid TINYINT(1) NOT NULL'); + $this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice ADD payment_state VARCHAR(255) NOT NULL'); } public function down(Schema $schema): void { // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice DROP is_paid'); + $this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice DROP payment_state'); } } diff --git a/src/Resources/config/doctrine/Invoice.orm.xml b/src/Resources/config/doctrine/Invoice.orm.xml index afa772ff..c113b0ba 100644 --- a/src/Resources/config/doctrine/Invoice.orm.xml +++ b/src/Resources/config/doctrine/Invoice.orm.xml @@ -9,7 +9,7 @@ - + diff --git a/src/Resources/views/Invoice/Download/pdf.html.twig b/src/Resources/views/Invoice/Download/pdf.html.twig index 4279c012..f381bc95 100644 --- a/src/Resources/views/Invoice/Download/pdf.html.twig +++ b/src/Resources/views/Invoice/Download/pdf.html.twig @@ -129,7 +129,7 @@ {{ 'sylius_invoicing_plugin.ui.payment.paid'|trans }}: - {% if invoice.isPaid() %} + {% if invoice.paymentState() is constant('Sylius\\InvoicingPlugin\\Entity\\InvoiceInterface::PAYMENT_STATE_COMPLETED') %} {{ 'sylius_invoicing_plugin.ui.payment.yes'|trans }} {% else %} {{ 'sylius_invoicing_plugin.ui.payment.no'|trans }} diff --git a/src/Resources/views/Invoice/show.html.twig b/src/Resources/views/Invoice/show.html.twig index c5400a02..1fd7529f 100644 --- a/src/Resources/views/Invoice/show.html.twig +++ b/src/Resources/views/Invoice/show.html.twig @@ -150,7 +150,7 @@
{{ 'sylius_invoicing_plugin.ui.payment.paid'|trans }}: - {% if invoice.isPaid() %} + {% if invoice.paymentState() is constant('Sylius\\InvoicingPlugin\\Entity\\InvoiceInterface::PAYMENT_STATE_COMPLETED') %} {{ 'sylius_invoicing_plugin.ui.payment.yes'|trans }} {% else %} {{ 'sylius_invoicing_plugin.ui.payment.no'|trans }}