-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CreditMemo] Add tax items to credit memo
- Loading branch information
Showing
20 changed files
with
449 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20200113091731 extends AbstractMigration | ||
{ | ||
public function up(Schema $schema): void | ||
{ | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('ALTER TABLE sylius_refund_credit_memo ADD tax_items LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:json)\''); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('ALTER TABLE sylius_refund_credit_memo DROP tax_items'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\RefundPlugin\Entity; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Sylius\RefundPlugin\Entity\TaxItemInterface; | ||
|
||
final class TaxItemSpec extends ObjectBehavior | ||
{ | ||
function let(): void | ||
{ | ||
$this->beConstructedWith('VAT', 100); | ||
} | ||
|
||
function it_implements_tax_item_interface(): void | ||
{ | ||
$this->shouldImplement(TaxItemInterface::class); | ||
} | ||
|
||
function it_has_a_label(): void | ||
{ | ||
$this->getLabel()->shouldReturn('VAT'); | ||
} | ||
|
||
function it_has_an_amount(): void | ||
{ | ||
$this->getAmount()->shouldReturn(100); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\RefundPlugin\Generator; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Component\Core\Model\AdjustmentInterface; | ||
use Sylius\Component\Core\Model\OrderItemUnitInterface; | ||
use Sylius\Component\Resource\Repository\RepositoryInterface; | ||
use Sylius\RefundPlugin\Entity\TaxItem; | ||
use Sylius\RefundPlugin\Generator\TaxItemsGeneratorInterface; | ||
use Sylius\RefundPlugin\Model\OrderItemUnitRefund; | ||
|
||
final class TaxItemsGeneratorSpec extends ObjectBehavior | ||
{ | ||
function let(RepositoryInterface $orderItemUnitRepository): void | ||
{ | ||
$this->beConstructedWith($orderItemUnitRepository); | ||
} | ||
|
||
function it_implements_tax_items_generator_interface(): void | ||
{ | ||
$this->shouldImplement(TaxItemsGeneratorInterface::class); | ||
} | ||
|
||
function it_generates_tax_items( | ||
RepositoryInterface $orderItemUnitRepository, | ||
OrderItemUnitInterface $firstOrderItemUnit, | ||
OrderItemUnitInterface $secondOrderItemUnit, | ||
AdjustmentInterface $firstAdjustment, | ||
AdjustmentInterface $secondAdjustment | ||
): void { | ||
$firstUnitRefund = new OrderItemUnitRefund(1, 500); | ||
$secondUnitRefund = new OrderItemUnitRefund(3, 200); | ||
|
||
$orderItemUnitRepository->find(1)->willReturn($firstOrderItemUnit); | ||
$firstOrderItemUnit->getTotal()->willReturn(500); | ||
$firstOrderItemUnit->getTaxTotal()->willReturn(50); | ||
$firstOrderItemUnit | ||
->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT) | ||
->willReturn(new ArrayCollection([$firstAdjustment->getWrappedObject()])) | ||
; | ||
$firstAdjustment->getLabel()->willReturn('VAT'); | ||
|
||
$orderItemUnitRepository->find(3)->willReturn($secondOrderItemUnit); | ||
$secondOrderItemUnit->getTotal()->willReturn(200); | ||
$secondOrderItemUnit->getTaxTotal()->willReturn(20); | ||
$secondOrderItemUnit | ||
->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT) | ||
->willReturn(new ArrayCollection([$secondAdjustment->getWrappedObject()])) | ||
; | ||
$secondAdjustment->getLabel()->willReturn('VAT'); | ||
|
||
$this->generate([$firstUnitRefund, $secondUnitRefund])->shouldBeLike([new TaxItem('VAT', 70)]); | ||
} | ||
|
||
function it_generates_tax_items_with_partial_amount( | ||
RepositoryInterface $orderItemUnitRepository, | ||
OrderItemUnitInterface $orderItemUnit, | ||
AdjustmentInterface $adjustment | ||
): void { | ||
$unitRefund = new OrderItemUnitRefund(1, 250); | ||
|
||
$orderItemUnitRepository->find(1)->willReturn($orderItemUnit); | ||
$orderItemUnit->getTotal()->willReturn(500); | ||
$orderItemUnit->getTaxTotal()->willReturn(50); | ||
$orderItemUnit | ||
->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT) | ||
->willReturn(new ArrayCollection([$adjustment->getWrappedObject()])) | ||
; | ||
$adjustment->getLabel()->willReturn('VAT'); | ||
|
||
$this->generate([$unitRefund])->shouldBeLike([new TaxItem('VAT', 25)]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\RefundPlugin\Entity; | ||
|
||
/** @final */ | ||
class TaxItem implements TaxItemInterface | ||
{ | ||
/** @var string */ | ||
protected $label; | ||
|
||
/** @var int */ | ||
protected $amount; | ||
|
||
public function __construct(string $label, int $amount) | ||
{ | ||
$this->label = $label; | ||
$this->amount = $amount; | ||
} | ||
|
||
public function getLabel(): string | ||
{ | ||
return $this->label; | ||
} | ||
|
||
public function getAmount(): int | ||
{ | ||
return $this->amount; | ||
} | ||
|
||
public function serialize(): string | ||
{ | ||
$serialized = json_encode(['label' => $this->label, 'amount' => $this->amount]); | ||
|
||
if ($serialized === false) { | ||
throw new \Exception('Tax item cannot be serialized.'); | ||
} | ||
|
||
return $serialized; | ||
} | ||
|
||
public static function unserialize(string $serialized): self | ||
{ | ||
$data = json_decode($serialized, true); | ||
|
||
return new self($data['label'], $data['amount']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\RefundPlugin\Entity; | ||
|
||
interface TaxItemInterface | ||
{ | ||
public function getLabel(): string; | ||
|
||
public function getAmount(): int; | ||
|
||
public function serialize(): string; | ||
} |
Oops, something went wrong.