Skip to content

Commit

Permalink
remove Currency
Browse files Browse the repository at this point in the history
  • Loading branch information
MartkCz committed May 4, 2022
1 parent b5d3a44 commit 5ed4592
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 97 deletions.
21 changes: 0 additions & 21 deletions src/DI/InvoiceExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Contributte\Invoice\Data\Account;
use Contributte\Invoice\Data\Company;
use Contributte\Invoice\Data\Currency;
use Contributte\Invoice\Invoice;
use Contributte\Invoice\Provider\InvoiceDataProvider;
use Nette\DI\CompilerExtension;
Expand All @@ -31,10 +30,6 @@ public function getConfigSchema(): Schema
'accounts' => Expect::arrayOf(Expect::structure([
'iban' => Expect::string(),
])),
'currency' => Expect::structure([
'currency' => Expect::string()->required(),
'template' => Expect::string()->default(':currency:price'),
]),
]);
}

Expand All @@ -46,7 +41,6 @@ public function loadConfiguration(): void
->setFactory(InvoiceDataProvider::class, [
$this->getCompany(),
$this->getAccounts(),
$this->getCurrency(),
]);

$builder->addDefinition($this->prefix('invoice'))
Expand Down Expand Up @@ -93,19 +87,4 @@ private function getAccounts(): array
return $accounts;
}

private function getCurrency(): ?Statement
{
/** @var stdClass $config */
$config = $this->getConfig();

/** @var stdClass $currency */
$currency = $config->currency;

if (!$currency->currency) {
return null;
}

return new Statement(Currency::class, [$currency->currency, $currency->template]);
}

}
28 changes: 0 additions & 28 deletions src/Data/Currency.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Data/ICurrency.php

This file was deleted.

2 changes: 0 additions & 2 deletions src/Data/IOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public function getCustomer(): ICustomer;

public function getPayment(): IPaymentInformation;

public function getCurrency(): ICurrency;

/**
* @return IItem[]
*/
Expand Down
9 changes: 0 additions & 9 deletions src/Data/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ class Order implements IOrder
/** @var IItem[] */
private array $items = [];

private ICurrency $currency;

public function __construct(
private string $number,
private string $totalPrice,
private ICompany $company,
private ICustomer $customer,
private IPaymentInformation $payment,
private ITimestamps $timestamps,
?ICurrency $currency = null,
)
{
$this->currency = $currency ?? new Currency('$');
}

public function addItem(IItem $item): IItem
Expand Down Expand Up @@ -71,9 +67,4 @@ public function getItems(): array
return $this->items;
}

public function getCurrency(): ICurrency
{
return $this->currency;
}

}
23 changes: 11 additions & 12 deletions src/Preview/PreviewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Contributte\Invoice\Data\Account;
use Contributte\Invoice\Data\Company;
use Contributte\Invoice\Data\Currency;
use Contributte\Invoice\Data\Customer;
use Contributte\Invoice\Data\International\Czech\CzechAccount;
use Contributte\Invoice\Data\International\Czech\CzechPaymentInformation;
Expand All @@ -22,7 +21,7 @@ public static function createOrder(?int $itemCount = null): IOrder
{
$order = new Order(
date('Y') . '0001',
'15.000,00',
'$ 15.000,00',
new Company('Contributte', 'Prague', 'U haldy', '110 00', 'Czech Republic', 'CZ08304431', '08304431'),
new Customer('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA', 'CZ08304431', '08304431'),
new PaymentInformation(
Expand All @@ -43,7 +42,7 @@ public static function createCzechOrder(?int $itemCount = null): IOrder
{
$order = new Order(
date('Y') . '0001',
'15.000,00',
'15.000,00',
new Company('Contributte', 'Prague', 'U haldy', '110 00', 'Czech Republic', 'CZ08304431', '08304431'),
new Customer('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA', 'CZ08304431', '08304431'),
new CzechPaymentInformation(
Expand All @@ -56,23 +55,23 @@ public static function createCzechOrder(?int $itemCount = null): IOrder
(new DateTime())->format('Y-m-d'),
(new DateTime('+ 1 week'))->format('Y-m-d'),
),
new Currency('', ':price :currency'),
);

self::addItems($order, $itemCount);
self::addItems($order, $itemCount, ':value Kč');

return $order;
}

private static function addItems(IOrder $order, ?int $itemCount = null): void
private static function addItems(IOrder $order, ?int $itemCount = null, string $format = '$ :value'): void
{
$format = fn (string $money) => str_replace(':value', $money, $format);
$items = [
new Item('Logitech G700s Rechargeable Gaming Mouse', '1.790,00', 4, '7.160,00'),
new Item('ASUS Z380KL 8" - 16GB, LTE', '6.490,00', 1, '6.490,00'),
new Item('Philips 48PFS6909 - 121cm', '13.990,00', 1, '13.990,00'),
new Item('HP Deskjet 3545 Advantage', '1.799,00', 1, '1.799,00'),
new Item('LG 105UC9V - 266cm', '11.599,00', 1, '11.599,00'),
new Item('Samsung Galaxy S21 Ultra 5G, 12GB/128GB', '31.490,00', 1, '31.490,00'),
new Item('Logitech G700s Rechargeable Gaming Mouse', $format('1.790,00'), 4, $format('7.160,00')),
new Item('ASUS Z380KL 8" - 16GB, LTE', $format('6.490,00'), 1, $format('6.490,00')),
new Item('Philips 48PFS6909 - 121cm', $format('13.990,00'), 1, $format('13.990,00')),
new Item('HP Deskjet 3545 Advantage', $format('1.799,00'), 1, $format('1.799,00')),
new Item('LG 105UC9V - 266cm', $format('11.599,00'), 1, $format('11.599,00')),
new Item('Samsung Galaxy S21 Ultra 5G, 12GB/128GB', $format('31.490,00'), 1, $format('31.490,00')),
];
$count = count($items);

Expand Down
7 changes: 0 additions & 7 deletions src/Provider/InvoiceDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Contributte\Invoice\Data\IAccount;
use Contributte\Invoice\Data\ICompany;
use Contributte\Invoice\Data\ICurrency;

final class InvoiceDataProvider
{
Expand All @@ -15,7 +14,6 @@ final class InvoiceDataProvider
public function __construct(
private ICompany $company,
private array $accounts = [],
private ?ICurrency $currency = null,
)
{
}
Expand All @@ -33,9 +31,4 @@ public function getAccounts(): array
return $this->accounts;
}

public function getCurrency(): ?ICurrency
{
return $this->currency;
}

}
15 changes: 7 additions & 8 deletions src/Templates/templates/paraiso.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use Contributte\Invoice\Templates\Template\ParaisoTemplateObject;
use WebChemistry\SvgPdf\Utility\TemplateUtility;

/** @var $template ParaisoTemplateObject */
$formatMoney = $template->formatMoneyCallback();
$order = $template->getOrder();
$payment = $order->getPayment();

Expand Down Expand Up @@ -66,7 +65,7 @@ echo '<?xml version="1.0" encoding="UTF-8"?>';

<!-- Total Due -->
<text font-size="67" x="1678" y="878" fill="<?= $this->colors['totalDue'] ?>" text-anchor="start"><?= TemplateUtility::escape($template->translate('Total price')) ?>:</text>
<text font-size="67" x="1678" y="959" fill="<?= $this->colors['primary'] ?>" font-weight="bold" text-anchor="start"><?= TemplateUtility::escape($formatMoney($order->getTotalPrice())) ?></text>
<text font-size="67" x="1678" y="959" fill="<?= $this->colors['primary'] ?>" font-weight="bold" text-anchor="start"><?= TemplateUtility::escape($order->getTotalPrice()) ?></text>
<!-- / Total Due -->

<rect x="0" y="1133" width="2480" height="5" fill="<?= $this->colors['primary'] ?>" />
Expand All @@ -89,7 +88,7 @@ echo '<?xml version="1.0" encoding="UTF-8"?>';
<foreignObject x="1031" y="<?= $y ?>" width="400" height="200" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility">
<p xmlns="http://www.w3.org/1999/xhtml" style="font-size:42px;color:#5f6f73;text-align:center;"><?= TemplateUtility::escape($item->getQuantity()) ?></p>
</foreignObject>
<text font-size="42" x="1031" y="<?= $y ?>" fill="#5f6f73" text-anchor="middle" data-pdf-width="400"><?= TemplateUtility::escape($formatMoney($item->getUnitPrice())) ?></text>
<text font-size="42" x="1031" y="<?= $y ?>" fill="#5f6f73" text-anchor="middle" data-pdf-width="400"><?= TemplateUtility::escape($item->getUnitPrice()) ?></text>
</switch>

<switch>
Expand All @@ -103,7 +102,7 @@ echo '<?xml version="1.0" encoding="UTF-8"?>';
<foreignObject x="1974" y="<?= $y ?>" width="400" height="200" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility">
<p xmlns="http://www.w3.org/1999/xhtml" style="font-size:42px;text-align:center;color:#5f6f73"><?= TemplateUtility::escape($item->getTotalPrice()) ?></p>
</foreignObject>
<text font-size="42" x="1974" y="<?= $y ?>" fill="#5f6f73" text-anchor="middle" data-pdf-width="400"><?= TemplateUtility::escape($formatMoney($item->getTotalPrice())) ?></text>
<text font-size="42" x="1974" y="<?= $y ?>" fill="#5f6f73" text-anchor="middle" data-pdf-width="400"><?= TemplateUtility::escape($item->getTotalPrice()) ?></text>
</switch>

<?php $y->increment(); endforeach; ?>
Expand All @@ -119,18 +118,18 @@ echo '<?xml version="1.0" encoding="UTF-8"?>';

<?php if ($payment instanceof IPriceWithTax): ?>
<text font-size="42" x="1593" y="<?= $y; ?>" fill="#5f6f73">Sub Total:</text>
<text font-size="42" x="2250" y="<?= $y->postIncrement(); ?>" text-anchor="end" fill="#5f6f73"><?= TemplateUtility::escape($formatMoney($payment->getPriceBeforeTax())) ?></text>
<text font-size="42" x="2250" y="<?= $y->postIncrement(); ?>" text-anchor="end" fill="#5f6f73"><?= TemplateUtility::escape($payment->getPriceBeforeTax()) ?></text>

<text font-size="42" x="1593" y="<?= $y; ?>" fill="#5f6f73">Tax:</text>
<text font-size="42" x="2250" y="<?= $y->postIncrement(); ?>" text-anchor="end" fill="#5f6f73"><?= TemplateUtility::escape($formatMoney($payment->getTax())) ?></text>
<text font-size="42" x="2250" y="<?= $y->postIncrement(); ?>" text-anchor="end" fill="#5f6f73"><?= TemplateUtility::escape($payment->getTax()) ?></text>
<?php endif; ?>

<?php if ($order instanceof IDiscount): ?>
<text font-size="42" x="1593" y="<?= $y; ?>" fill="#5f6f73"><?= TemplateUtility::escape($template->translate('Discount')) ?>:</text>
<text font-size="42" x="2250" y="<?= $y->postIncrement(); ?>" text-anchor="end" fill="#5f6f73"><?= TemplateUtility::escape($formatMoney($order->getDiscount())) ?></text>
<text font-size="42" x="2250" y="<?= $y->postIncrement(); ?>" text-anchor="end" fill="#5f6f73"><?= TemplateUtility::escape($order->getDiscount()) ?></text>
<?php endif; ?>

<text font-size="42" x="1593" y="<?= $y; ?>" font-weight="bold" fill="#5f6f73">Total</text>
<text font-size="42" x="1593" y="<?= $y; ?>" font-weight="bold" fill="#5f6f73"><?= TemplateUtility::escape($template->translate('Total')) ?></text>
<text font-size="42" x="2250" y="<?= $y; ?>" font-weight="bold" text-anchor="end" fill="#5f6f73">$ 4500.00</text>

<?php $paymentY = TemplateUtility::multiplier($adjust, 42 + 30); ?>
Expand Down

0 comments on commit 5ed4592

Please sign in to comment.