Skip to content

Commit

Permalink
change bool to state on payment on invoce state
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKasp committed Aug 12, 2021
1 parent 61a8f40 commit 1d37271
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 43 deletions.
8 changes: 4 additions & 4 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
Expand All @@ -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;
```

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/Entity/InvoiceSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function let(
new ArrayCollection([$lineItem->getWrappedObject()]),
new ArrayCollection([$taxItem->getWrappedObject()]),
$channel,
true,
InvoiceInterface::PAYMENT_STATE_COMPLETED,
$shopBillingData
);
}
Expand Down
4 changes: 2 additions & 2 deletions spec/Factory/InvoiceFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion spec/Generator/InvoiceGeneratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
17 changes: 6 additions & 11 deletions src/Entity/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class Invoice implements InvoiceInterface
/** @var ChannelInterface */
protected $channel;

/** @var bool */
protected $isPaid;
/** @var string */
protected $paymentState;

/** @var InvoiceShopBillingDataInterface */
protected $shopBillingData;
Expand All @@ -71,7 +71,7 @@ public function __construct(
Collection $lineItems,
Collection $taxItems,
ChannelInterface $channel,
bool $isPaid,
string $paymentState,
InvoiceShopBillingDataInterface $shopBillingData
) {
$this->id = $id;
Expand All @@ -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 */
Expand Down Expand Up @@ -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;
}
}
8 changes: 5 additions & 3 deletions src/Entity/InvoiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions src/Factory/InvoiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function createForData(
Collection $lineItems,
Collection $taxItems,
ChannelInterface $channel,
bool $isPaid,
string $paymentState,
InvoiceShopBillingDataInterface $shopBillingData = null
): InvoiceInterface {
return new Invoice(
Expand All @@ -51,7 +51,7 @@ public function createForData(
$lineItems,
$taxItems,
$channel,
$isPaid,
$paymentState,
$shopBillingData ?? new InvoiceShopBillingData()
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/InvoiceFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function createForData(
Collection $lineItems,
Collection $taxItems,
ChannelInterface $channel,
bool $isPaid,
string $paymentState,
InvoiceShopBillingDataInterface $shopBillingData = null
): InvoiceInterface;
}
6 changes: 3 additions & 3 deletions src/Generator/InvoiceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -97,7 +97,7 @@ public function generateForOrder(OrderInterface $order, \DateTimeInterface $date
)),
$this->taxItemsConverter->convert($order),
$channel,
$isPaid,
$paymentState,
$this->invoiceShopBillingDataConverter->convert($channel)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\InvoicingPlugin\Migrations;
Expand All @@ -19,17 +10,22 @@
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210811092457 extends AbstractMigration
final class Version20210812125029 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add payment_state to invoice';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->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');
}
}
2 changes: 1 addition & 1 deletion src/Resources/config/doctrine/Invoice.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<field name="currencyCode" column="currency_code" length="3" />
<field name="localeCode" column="locale_code" />
<field name="total" column="total" type="integer" />
<field name="isPaid" column="is_paid" type="boolean" />
<field name="paymentState" column="payment_state" type="string" />

<one-to-one field="billingData" target-entity="Sylius\InvoicingPlugin\Entity\BillingDataInterface">
<cascade>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/Invoice/Download/pdf.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<td colspan="5"></td>
<td colspan="2" class="bold">{{ 'sylius_invoicing_plugin.ui.payment.paid'|trans }}:</td>
<td>
{% 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 }}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/Invoice/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
<div class="ui segment" {{ sylius_test_html_attribute('invoice-is-paid') }}>
<strong>{{ 'sylius_invoicing_plugin.ui.payment.paid'|trans }}: </strong>
<span>
{% 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 }}
Expand Down

0 comments on commit 1d37271

Please sign in to comment.