-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Upominka.php
179 lines (158 loc) · 4.28 KB
/
Upominka.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
declare(strict_types=1);
/**
* This file is part of the AbraFlexi Reminder package
*
* https://github.com/VitexSoftware/abraflexi-reminder
*
* (c) Vítězslav Dvořák <http://vitexsoftware.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace AbraFlexi\Reminder;
/**
* Description of Remind.
*
* @author vitex
*/
class Upominka extends \AbraFlexi\RW
{
public \AbraFlexi\Adresar $firmer;
/**
* Invoice.
*/
public \AbraFlexi\FakturaVydana $invoicer;
public static string $styles = <<<'EOD'
table.greyGridTable {
border: 2px solid #FFFFFF;
width: 100%;
text-align: center;
border-collapse: collapse;
}
table.greyGridTable td, table.greyGridTable th {
border: 1px solid #FFFFFF;
padding: 3px 4px;
}
table.greyGridTable tbody td {
font-size: 13px;
}
table.greyGridTable td:nth-child(even) {
background: #EBEBEB;
}
table.greyGridTable thead {
background: #FFFFFF;
border-bottom: 4px solid #333333;
}
table.greyGridTable thead th {
font-size: 15px;
font-weight: bold;
color: #333333;
text-align: center;
border-left: 2px solid #333333;
}
table.greyGridTable thead th:first-child {
border-left: none;
}
table.greyGridTable tfoot {
font-size: 14px;
font-weight: bold;
color: #333333;
border-top: 4px solid #333333;
}
table.greyGridTable tfoot td {
font-size: 14px;
}
EOD;
/**
* AbraFlexi Remind template helper.
*
* @param string $init
* @param array $options
*/
public function __construct($init = null, $options = [])
{
$this->evidence = 'sablona-upominky';
parent::__construct($init, $options);
$this->invoicer = new \AbraFlexi\FakturaVydana();
$this->firmer = new \AbraFlexi\Adresar();
}
/**
* Load.
*
* @param string $template prvniUpominka|druhaUpominka|pokusOSmir|inventarizace
*/
public function loadTemplate($template): void
{
$this->takeData(current($this->getColumnsFromAbraFlexi(
'*',
['typSablonyK' => 'typSablony.'.$template],
)));
}
/**
* Obtain all debts sums indexed by currency.
*/
public static function getSums(array $debts): array
{
$sumsCelkem = [];
foreach ($debts as $debt) {
$currency = \AbraFlexi\Functions::uncode((string) $debt['mena']);
if ($currency === 'CZK') {
$amount = $debt['zbyvaUhradit'];
} else {
$amount = $debt['zbyvaUhraditMen'];
}
if (!\array_key_exists($currency, $sumsCelkem)) {
$sumsCelkem[$currency] = $amount;
} else {
$sumsCelkem[$currency] += $amount;
}
}
return $sumsCelkem;
}
/**
* Block of QR Payment.
*
* @param array $debts
*
* @return \Ease\Html\DivTag
*/
public static function qrPayments($debts)
{
$invoicer = new \AbraFlexi\FakturaVydana();
$qrDiv = new \Ease\Html\DivTag();
$qrDiv->addItem(new \Ease\Html\H3Tag(_('QR Invoices')));
foreach ($debts as $invoiceId => $invoiceInfo) {
$currency = \AbraFlexi\Functions::uncode((string) $invoiceInfo['mena']);
if ($currency === 'CZK') {
$amount = $invoiceInfo['zbyvaUhradit'];
} else {
$amount = $invoiceInfo['zbyvaUhraditMen'];
}
$invoicer->setMyKey((int) $invoiceInfo['id']);
$invoicer->setEvidence($invoiceInfo['evidence']);
$qrDiv->addItem(new \Ease\Html\DivTag($invoiceId.' <strong>'.$amount.'</strong> '.$currency));
try {
$qrCode = $invoicer->getQrCodeBase64(200);
$qrDiv->addItem(new \Ease\Html\ImgTag(
$qrCode,
_('QR Payment'),
['width' => 200, 'height' => 200, 'title' => $invoiceId],
));
} catch (\AbraFlexi\Exception $exc) {
}
}
return $qrDiv;
}
/**
* Format Czech Currency.
*
* @param float $price
*
* @return string
*/
public static function formatCurrency($price)
{
return number_format($price, 2, ',', ' ');
}
}