Skip to content

Commit

Permalink
refactor credit memo show page
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKasp authored and GSadee committed Mar 16, 2021
1 parent 0db1f05 commit f1499ab
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 1 deletion.
2 changes: 2 additions & 0 deletions features/viewing_details_of_credit_memo.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Feature: Viewing details of a credit memo
And it should contain a tax item "20%" with amount "3.50" in "USD" currency
And it should contain a tax item "15%" with amount "1.50" in "USD" currency
And its total should be "42.00" in "USD" currency
And its net total should be "36.00"
And its tax total should be "6.00"

@ui @application
Scenario: Viewing details of a credit memo issued for a partial refund
Expand Down
24 changes: 24 additions & 0 deletions src/Entity/CreditMemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,28 @@ public function getTo(): ?ShopBillingDataInterface
{
return $this->to;
}

public function getNetValueTotal(): int
{
$sum = 0;

/** @var LineItemInterface $lineItem */
foreach ($this->getLineItems() as $lineItem) {
$sum = $sum + $lineItem->netValue();
}

return $sum;
}

public function getTaxTotal(): int
{
$sum = 0;

/** @var LineItemInterface $lineItem */
foreach ($this->getLineItems() as $lineItem) {
$sum = $sum + $lineItem->taxAmount();
}

return $sum;
}
}
4 changes: 4 additions & 0 deletions src/Entity/CreditMemoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ public function getIssuedAt(): \DateTimeImmutable;
public function getFrom(): CustomerBillingDataInterface;

public function getTo(): ?ShopBillingDataInterface;

public function getNetValueTotal(): int;

public function getTaxTotal(): int;
}
2 changes: 2 additions & 0 deletions src/Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sylius_refund:
issued_for_order: Issued for order
issued_from: Issued from
manage_credit_memos: Manage credit memos
net_total: Net total
net_value: Net value
no: No.
order_number: Order number
Expand All @@ -28,6 +29,7 @@ sylius_refund:
seller: Seller
tax_amount: Tax amount
tax_rate: Tax rate %
tax_total: Tax total
unit_net_price: Unit net price

sylius:
Expand Down
25 changes: 24 additions & 1 deletion src/Resources/views/Order/Admin/CreditMemo/details.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,19 @@
</tbody>
<tfoot>
<tr>
<th colspan="7" class="right aligned">
<th colspan="3" class="right aligned">
<strong>{{ 'sylius_refund.ui.net_total'|trans }}</strong>:
</th>
<th id="credit-memo-net-value-total" class="right aligned">
{{ '%0.2f'|format(credit_memo.getNetValueTotal()/100) }}
</th>
<th colspan="1" class="right aligned">
<strong>{{ 'sylius_refund.ui.tax_total'|trans }}</strong>:
</th>
<th id="credit-memo-tax-total" class="right aligned">
{{ '%0.2f'|format(credit_memo.getTaxTotal()/100) }}
</th>
<th colspan="1" class="right aligned">
<strong>{{ 'sylius.ui.total'|trans }}</strong>:
</th>
<th id="credit-memo-total" class="right aligned">
Expand All @@ -122,6 +134,17 @@
{{ credit_memo.currencyCode }}
</th>
</tr>
<tr>
<th colspan="7" class="right aligned">
<strong>{{ 'sylius_refund.ui.tax_rate'|trans }}</strong>
</th>
<th class="right aligned">
<strong>{{ 'sylius_refund.ui.tax_amount'|trans }}</strong>
</th>
<th class="left aligned">
<strong>{{ 'sylius.ui.currency'|trans }}</strong>
</th>
</tr>
{% for item in credit_memo.taxItems %}
<tr class="tax-item">
<th colspan="7" class="right aligned">
Expand Down
16 changes: 16 additions & 0 deletions tests/Behat/Context/Application/CreditMemoContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ public function creditMemoTotalShouldBe(int $total, string $currencyCode): void
Assert::same($this->creditMemo->getCurrencyCode(), $currencyCode);
}

/**
* @Given /^its net total should be ("[^"]+")$/
*/
public function itsNetTotalShouldBe(int $total): void
{
Assert::same($this->creditMemo->getNetValueTotal(), $total);
}

/**
* @Given /^its tax total should be ("[^"]+")$/
*/
public function itsTaxTotalShouldBe(int $total): void
{
Assert::same($this->creditMemo->getTaxTotal(), $total);
}

/**
* @Then it should be commented with :comment
*/
Expand Down
18 changes: 18 additions & 0 deletions tests/Behat/Context/Ui/CreditMemoContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,24 @@ public function itsTotalShouldBeInCurrency(string $total, string $currencyCode):
Assert::same($this->creditMemoDetailsPage->getTotalCurrencyCode(), $currencyCode);
}

/**
* @Then its net total should be :total
*/
public function itsNetTotalShouldBe(string $total): void
{
Assert::same($this->creditMemoDetailsPage->getNetTotal(), $total);

}

/**
* @Then its tax total should be :total
*/
public function itsTaxTotalShouldBe(string $total): void
{
Assert::same($this->creditMemoDetailsPage->getTaxTotal(), $total);

}

/**
* @Then it should be commented with :comment
*/
Expand Down
12 changes: 12 additions & 0 deletions tests/Behat/Page/Admin/CreditMemoDetailsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,24 @@ public function isCreditMemoInPosition(string $creditMemo, int $position): bool
]) !== null;
}

public function getNetTotal(): string
{
return $this->getElement('net_total')->getText();
}

public function getTaxTotal(): string
{
return $this->getElement('tax_total')->getText();
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'credit_memo_in_given_position' => 'table tbody tr:nth-child(%position%) td:contains("%creditMemo%")',
'net_total' => '#credit-memo-net-value-total',
'table' => 'table',
'tax_item_amount' => 'tr.tax-item:contains("%label%") .tax-item-amount',
'tax_total' => '#credit-memo-tax-total',
'total' => '#credit-memo-total',
'total_currency_code' => '#credit-memo-total-currency-code',
]);
Expand Down
4 changes: 4 additions & 0 deletions tests/Behat/Page/Admin/CreditMemoDetailsPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ public function getFromAddress(): string;
public function getToAddress(): string;

public function isCreditMemoInPosition(string $creditMemo, int $position): bool;

public function getNetTotal(): string;

public function getTaxTotal(): string;
}

0 comments on commit f1499ab

Please sign in to comment.