Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adaamz authored and f3l1x committed Jun 30, 2020
1 parent 54e4f66 commit 43a40bf
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 44 deletions.
10 changes: 10 additions & 0 deletions src/Calculators/FloatCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class FloatCalculator implements ICalculator
*/
public function add($op1, $op2)
{
assert(!is_string($op1) && !is_string($op2), 'Strings are not supported in FloatCalculator');

return $op1 + $op2;
}

Expand All @@ -22,6 +24,8 @@ public function add($op1, $op2)
*/
public function mul($op1, $op2)
{
assert(!is_string($op1) && !is_string($op2), 'Strings are not supported in FloatCalculator');

return $op1 * $op2;
}

Expand All @@ -32,6 +36,8 @@ public function mul($op1, $op2)
*/
public function div($op1, $op2)
{
assert(!is_string($op1) && !is_string($op2), 'Strings are not supported in FloatCalculator');

return $op1 / $op2;
}

Expand All @@ -42,6 +48,8 @@ public function div($op1, $op2)
*/
public function sub($op1, $op2)
{
assert(!is_string($op1) && !is_string($op2), 'Strings are not supported in FloatCalculator');

return $op1 - $op2;
}

Expand All @@ -51,6 +59,8 @@ public function sub($op1, $op2)
*/
public function comp($op1, $op2): int
{
assert(!is_string($op1) && !is_string($op2), 'Strings are not supported in FloatCalculator');

return $op1 <=> $op2;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Data/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ public function getTotalPrice(ICalculator $calculator, bool $useTax = false)
return $calculator->add($this->totalPrice, 0);
}

$tax = $calculator->add($this->tax, 1.0);

if (!$useTax) {
return $calculator->mul($this->price, $this->count);
} else {
$total = $calculator->mul($this->price, $this->count);

assert($this->tax !== null);
$tax = $calculator->add($this->tax, 1.0);

return $calculator->mul($total, $tax);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Data/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class Order
/** @var string */
private $number;

/** @var DateTime */
/** @var DateTime|null */
private $dueDate;

/** @var Account */
/** @var Account|null */
private $account;

/** @var PaymentInformation */
Expand Down
11 changes: 7 additions & 4 deletions src/Renderers/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ public function __construct(string $orientation = 'P', string $unit = 'mm', stri
}
}

function SetFontPath($fontPath)
public function SetFontPath(string $fontPath): void
{
$this->fontpath = $fontPath;
}

function Polygon($points, $style = 'D')
/**
* @param float[] $points
*/
public function Polygon(array $points, string $style = 'D'): void
{
//Draw a polygon
if ($style == 'F') {
if ($style === 'F') {
$op = 'f';
} elseif ($style == 'FD' || $style == 'DF') {
} elseif ($style === 'FD' || $style === 'DF') {
$op = 'b';
} else {
$op = 's';
Expand Down
72 changes: 36 additions & 36 deletions src/Templates/DefaultTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,53 +149,53 @@ protected function buildTotal(int $offset): void
$renderer = $this->renderer;
$half = ($renderer->width() - 553) / 2;

$renderer->rect(553, $offset, $renderer->width() - 553, 29, function (Settings $settings) {
$renderer->rect(553, $offset, $renderer->width() - 553, 29, function (Settings $settings): void {
$settings->setFillDrawColor($this->even);
});
$renderer->polygon([
553 + $half, $offset + 29,
573 + $half, $offset,
$renderer->width(), $offset,
$renderer->width(), $offset + 29,
], function (Settings $settings) {
], function (Settings $settings): void {
$settings->setFillDrawColor($this->primary);
});
$renderer->cell(553, $offset, $half, 29.0, Strings::upper($this->translator->translate('totalPrice')) . ':', function (Settings $settings) {
$renderer->cell(553, $offset, $half, 29.0, Strings::upper($this->translator->translate('totalPrice')) . ':', static function (Settings $settings): void {
$settings->fontFamily = 'sans';
$settings->fontStyle = $settings::FONT_STYLE_BOLD;
$settings->align = $settings::ALIGN_CENTER;
});
$renderer->cell(553 + $half, $offset, $half - 4, 29.0, $this->formatter->formatMoney($this->order->getTotalPrice($this->calculator, $this->company->hasTax()), $this->order->getPayment()->getCurrency()), function (Settings $settings) {
$renderer->cell(553 + $half, $offset, $half - 4, 29.0, $this->formatter->formatMoney($this->order->getTotalPrice($this->calculator, $this->company->hasTax()), $this->order->getPayment()->getCurrency()), static function (Settings $settings): void {
$settings->fontFamily = 'sans';
$settings->fontStyle = $settings::FONT_STYLE_BOLD;
$settings->fontColor = Color::white();
});
}

/**
* @param Item[] $items
*/
protected function buildItems(int $offset, array $items): int
{
$renderer = $this->renderer;

/**
* @var Item $item
*/
foreach ($items as $i => $item) {
$renderer->rect(0, $offset, $renderer->width(), 29, function (Settings $settings) use ($i) {
$renderer->rect(0, $offset, $renderer->width(), 29, function (Settings $settings) use ($i): void {
$settings->setFillDrawColor($i % 2 === 1 ? $this->even : $this->odd);
});
$renderer->rect(0, $offset + 30, $renderer->width(), 0.1, function (Settings $settings) {
$renderer->rect(0, $offset + 30, $renderer->width(), 0.1, function (Settings $settings): void {
$settings->setFillDrawColor($this->even->darken(10));
});

// Data
$renderer->cell(33, $offset, 360, 29.0, $item->getName(), function (Settings $settings) {
$renderer->cell(33, $offset, 360, 29.0, $item->getName(), function (Settings $settings): void {
$settings->fontFamily = 'sans';
$settings->fontColor = $this->font;
$settings->fontStyle = $settings::FONT_STYLE_NONE;
$settings->align = $settings::ALIGN_LEFT;
$settings->fontSize = 5;
});
$renderer->cell(353, $offset, 80, 29.0, $this->formatter->formatNumber($item->getCount()), function (Settings $settings) {
$renderer->cell(353, $offset, 80, 29.0, $this->formatter->formatNumber($item->getCount()), static function (Settings $settings): void {
$settings->align = $settings::ALIGN_CENTER;
});

Expand All @@ -205,7 +205,7 @@ protected function buildItems(int $offset, array $items): int
$renderer->cell(593, $offset, 70, 29.0, $item->getTax() * 100 . '%');
}

$renderer->cell(670, $offset, 123, 29.0, $this->formatter->formatMoney($item->getTotalPrice($this->calculator, $this->company->hasTax()), $this->order->getPayment()->getCurrency()), function (Settings $settings) {
$renderer->cell(670, $offset, 123, 29.0, $this->formatter->formatMoney($item->getTotalPrice($this->calculator, $this->company->hasTax()), $this->order->getPayment()->getCurrency()), static function (Settings $settings): void {
$settings->fontFamily = 'sans';
$settings->fontStyle = $settings::FONT_STYLE_BOLD;
});
Expand All @@ -220,7 +220,7 @@ protected function buildMain(): void
{
$renderer = $this->renderer;

$renderer->rect(0, 307, $renderer->width(), 29, function (Settings $settings) {
$renderer->rect(0, 307, $renderer->width(), 29, function (Settings $settings): void {
$settings->setFillDrawColor($this->even);
});
$renderer->polygon([
Expand All @@ -233,12 +233,12 @@ protected function buildMain(): void
});
$renderer->rect(0, 336, $renderer->width(), 1);

$renderer->cell(33, 307, 360, 29.0, Strings::upper($this->translator->translate('item')), function (Settings $settings) {
$renderer->cell(33, 307, 360, 29.0, Strings::upper($this->translator->translate('item')), function (Settings $settings): void {
$settings->fontColor = $this->primary;
$settings->fontStyle = $settings::FONT_STYLE_BOLD;
$settings->fontSize = 9;
});
$renderer->cell(353, 307, 80, 29.0, Strings::upper($this->translator->translate('count')), function (Settings $settings) {
$renderer->cell(353, 307, 80, 29.0, Strings::upper($this->translator->translate('count')), static function (Settings $settings): void {
$settings->align = $settings::ALIGN_CENTER;
});

Expand All @@ -248,7 +248,7 @@ protected function buildMain(): void
$renderer->cell(593, 307, 70, 29.0, Strings::upper($this->translator->translate('tax')));
}

$renderer->cell($renderer->width() - 80, 307, 60, 29.0, Strings::upper($this->translator->translate('total')), function (Settings $settings) {
$renderer->cell($renderer->width() - 80, 307, 60, 29.0, Strings::upper($this->translator->translate('total')), function (Settings $settings): void {
$settings->fontColor = $this->even;
});
}
Expand All @@ -262,7 +262,7 @@ protected function buildHeader(): void
0, 100,
245, 100,
312, 0,
], function (Settings $settings) {
], function (Settings $settings): void {
$settings->setFillDrawColor($this->font);
});

Expand All @@ -271,7 +271,7 @@ protected function buildHeader(): void
245, 100,
$renderer->width(), 100,
$renderer->height(), 0,
], function (Settings $settings) {
], function (Settings $settings): void {
$settings->setFillDrawColor($this->primary);
});

Expand All @@ -288,7 +288,7 @@ protected function buildHeader(): void
188, 120,
205, 125,
222, 100,
], function (Settings $settings) {
], function (Settings $settings): void {
$settings->setFillDrawColor($this->primary->darken(15));
});

Expand All @@ -297,12 +297,12 @@ protected function buildHeader(): void
217, 106,
242, 106,
247, 100,
], function (Settings $settings) {
], function (Settings $settings): void {
$settings->setFillDrawColor($this->primary);
});

$y = 36;
$renderer->cell(112, $y, 1, null, $this->company->getZip() . ' ' . $this->company->getTown(), function (Settings $settings) {
$renderer->cell(112, $y, 1, null, $this->company->getZip() . ' ' . $this->company->getTown(), static function (Settings $settings): void {
$settings->align = $settings::ALIGN_RIGHT;
$settings->fontSize = 6;
$settings->fontFamily = 'sans';
Expand All @@ -319,14 +319,14 @@ protected function buildHeader(): void

$multiplier = 0;
if ($this->company->getTin()) {
$renderer->cell(130, $y, 1, null, Strings::upper($this->translator->translate('vat')) . ': ' . $this->company->getTin(), function (Settings $settings) {
$renderer->cell(130, $y, 1, null, Strings::upper($this->translator->translate('vat')) . ': ' . $this->company->getTin(), static function (Settings $settings): void {
$settings->align = $settings::ALIGN_LEFT;
});
$multiplier++;
}

if ($this->company->getVaTin()) {
$renderer->cell(130, $y + ($multiplier * 12), 1, null, Strings::upper($this->translator->translate('vaTin')) . ': ' . $this->company->getVaTin(), function (Settings $settings) {
$renderer->cell(130, $y + ($multiplier * 12), 1, null, Strings::upper($this->translator->translate('vaTin')) . ': ' . $this->company->getVaTin(), static function (Settings $settings): void {
$settings->align = $settings::ALIGN_LEFT;
});
$multiplier++;
Expand All @@ -335,17 +335,17 @@ protected function buildHeader(): void
$renderer->cell(130, $y + ($multiplier * 12), 1, null,
$this->company->hasTax() ? $this->translator->translate('taxPay') : $this->translator->translate('notTax'));

$renderer->cell(543, 25, 1, null, $this->company->getName(), function (Settings $settings) {
$renderer->cell(543, 25, 1, null, $this->company->getName(), static function (Settings $settings): void {
$settings->align = $settings::ALIGN_CENTER;
$settings->fontSize = 8;
});

$renderer->cell(525, 45, 1, null, $this->translator->translate('date') . ': ' . $this->formatter->formatDate($this->order->getCreated()), function (Settings $settings) {
$renderer->cell(525, 45, 1, null, $this->translator->translate('date') . ': ' . $this->formatter->formatDate($this->order->getCreated()), static function (Settings $settings): void {
$settings->align = $settings::ALIGN_RIGHT;
$settings->fontSize = 6;
});
$renderer->cell(525, 57, 1, null, $this->translator->translate('invoiceNumber') . ': ' . $this->order->getNumber());
$renderer->cell(537, 52, 1, null, Strings::upper($this->translator->translate('invoice')), function (Settings $settings) {
$renderer->cell(537, 52, 1, null, Strings::upper($this->translator->translate('invoice')), static function (Settings $settings): void {
$settings->align = $settings::ALIGN_LEFT;
$settings->fontSize = 18;
$settings->fontStyle = $settings::FONT_STYLE_BOLD;
Expand All @@ -357,15 +357,15 @@ protected function buildLeftPane(): void
$renderer = $this->renderer;
$text = Strings::upper($this->translator->translate('subscriber'));

$renderer->cell(33, 175, 1, null, $text, function (Settings $settings) {
$renderer->cell(33, 175, 1, null, $text, function (Settings $settings): void {
$settings->fontSize = 16;
$settings->fontColor = $this->primary;
$settings->fontStyle = $settings::FONT_STYLE_BOLD;
});

$x = $renderer->textWidth($text) + 76;

$x = max($x, $renderer->textWidth($this->customer->getName(), function (Settings $settings) {
$x = max($x, $renderer->textWidth($this->customer->getName(), static function (Settings $settings): void {
$settings->fontSize = 7;
}) + 76);

Expand All @@ -379,13 +379,13 @@ protected function buildLeftPane(): void
$settings->setFillDrawColor($this->primary);
});

$renderer->cell(33, 210, 1, null, $this->customer->getName(), function (Settings $settings) {
$renderer->cell(33, 210, 1, null, $this->customer->getName(), function (Settings $settings): void {
$settings->fontSize = 10;
$settings->fontColor = $this->font;
});

$multiplier = 0;
$renderer->cell(33, 228, 1, null, $this->customer->getZip() . ', ' . $this->customer->getTown(), function (Settings $settings) {
$renderer->cell(33, 228, 1, null, $this->customer->getZip() . ', ' . $this->customer->getTown(), static function (Settings $settings): void {
$settings->fontSize = 6;
$settings->fontStyle = $settings::FONT_STYLE_NONE;
});
Expand Down Expand Up @@ -415,7 +415,7 @@ protected function buildRightPane(): void
{
$renderer = $this->renderer;

$renderer->cell(450, 145, 1, null, Strings::upper($this->translator->translate('paymentData')), function (Settings $settings) {
$renderer->cell(450, 145, 1, null, Strings::upper($this->translator->translate('paymentData')), function (Settings $settings): void {
$settings->fontColor = $this->primary;
$settings->align = $settings::ALIGN_LEFT;
$settings->fontStyle = $settings::FONT_STYLE_BOLD;
Expand All @@ -430,17 +430,17 @@ protected function buildRightPane(): void
$renderer->width(), 160,
]);

$iconCb = function (Settings $settings) {
$iconCb = function (Settings $settings): void {
$settings->fontStyle = $settings::FONT_STYLE_NONE;
$settings->fontColor = $this->primary;
$settings->fontSize = 9;
$settings->fontFamily = 'icons';
};
$sectionCb = function (Settings $settings) {
$sectionCb = static function (Settings $settings): void {
$settings->fontSize = 6;
$settings->fontFamily = 'sans';
};
$textCb = function (Settings $settings) {
$textCb = function (Settings $settings): void {
$settings->fontColor = $this->font;
};

Expand Down Expand Up @@ -495,11 +495,11 @@ protected function buildFooter(Paginator $paginator): void
{
$renderer = $this->renderer;

$renderer->rect(0, $renderer->height() - 20, $renderer->width(), 20, function (Settings $settings) {
$renderer->rect(0, $renderer->height() - 20, $renderer->width(), 20, function (Settings $settings): void {
$settings->setFillDrawColor($this->font);
});

$renderer->cell(0, -10, $renderer->width() - 10, null, $this->translator->translate('page') . ' ' . $paginator->getCurrentPage() . ' / ' . $paginator->getTotalPages(), function (Settings $settings) {
$renderer->cell(0, -10, $renderer->width() - 10, null, $this->translator->translate('page') . ' ' . $paginator->getCurrentPage() . ' / ' . $paginator->getTotalPages(), static function (Settings $settings): void {
$settings->fontColor = Color::white();
$settings->fontFamily = 'sans';
$settings->align = $settings::ALIGN_RIGHT;
Expand Down

0 comments on commit 43a40bf

Please sign in to comment.