1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* FlexiPeeHP - Objekt vydané faktury. |
4
|
|
|
* |
5
|
|
|
* @author Vítězslav Dvořák <[email protected]> |
6
|
|
|
* @copyright (C) 2015-2017 Spoje.Net |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace FlexiPeeHP; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Faktura vydaná |
13
|
|
|
* |
14
|
|
|
* @link https://demo.flexibee.eu/c/demo/faktura-vydana/properties položky evidence |
15
|
|
|
*/ |
16
|
|
|
class FakturaVydana extends FlexiBeeRW |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Evidence užitá objektem. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
public $evidence = 'faktura-vydana'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Add Data to evidence Branch |
27
|
|
|
* Přidá položky do dokladu a nastaví jim správně flag "ucetni" |
28
|
|
|
* |
29
|
|
|
* @see Relations |
30
|
|
|
* |
31
|
|
|
* @param array $data pole dat |
32
|
|
|
* @param string $relationPath path evidence (relation) pro vkládaná data |
33
|
|
|
* |
34
|
|
|
* @return boolean Description |
35
|
|
|
*/ |
36
|
|
|
public function addArrayToBranch($data, $relationPath = 'polozkyDokladu') |
37
|
|
|
{ |
38
|
|
|
if (($relationPath == 'polozkyDokladu') || ($relationPath == 'polozky-dokladu') |
39
|
|
|
|| ($relationPath == 'polozky-faktury')) { |
40
|
|
|
switch (self::uncode($this->getDataValue('typDokl'))) { |
41
|
|
|
case 'DOBR': |
42
|
|
|
case 'DOBROPIS': |
43
|
|
|
case 'FAKTURA': |
44
|
|
|
$data['ucetni'] = true; |
45
|
|
|
break; |
46
|
|
|
case 'ZÁLOHA': |
47
|
|
|
case 'ZALOHA': |
48
|
|
|
default: |
49
|
|
|
$data['ucetni'] = false; |
50
|
|
|
break; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
return parent::addArrayToBranch($data, $relationPath); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Provede spárování platby s dokladem |
58
|
|
|
* |
59
|
|
|
* @link https://demo.flexibee.eu/devdoc/parovani-plateb Párování plateb |
60
|
|
|
* |
61
|
|
|
* @param $doklad Banka|PokladniPohyb|InterniDoklad S jakým dokladem spárovat ? |
|
|
|
|
62
|
1 |
|
* @param $zbytek string ne|zauctovat|ignorovat|castecnaUhrada|castecnaUhradaNeboZauctovat|castecnaUhradaNeboIgnorovat |
63
|
|
|
* |
64
|
1 |
|
* @return boolean success |
65
|
1 |
|
*/ |
66
|
1 |
|
public function sparujPlatbu($doklad, $zbytek = 'ignorovat') |
67
|
1 |
|
{ |
68
|
1 |
|
$sparovani = ['uhrazovanaFak' => $this]; |
69
|
|
|
$sparovani['uhrazovanaFak@type'] = $this->evidence; |
70
|
|
|
$sparovani['zbytek'] = $zbytek; |
71
|
|
|
$doklad->insertToFlexiBee(['id' => $doklad, 'sparovani' => $sparovani]); |
72
|
|
|
return $doklad->lastResponseCode == 201; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Hotovostní platba faktury. |
77
|
|
|
* |
78
|
|
|
* @link https://demo.flexibee.eu/devdoc/hotovostni-uhrada/ Hotovostní úhrada |
79
|
|
|
* @link https://demo.flexibee.eu/c/demo/pokladna Pokladny |
80
|
|
|
* @link https://demo.flexibee.eu/c/demo/typ-pokladni-pohyb Typy dokladů |
81
|
|
|
* @param float $value částka k úhradě |
82
|
|
|
* @param array $uhrada pole nepoviných vlastností úhrady s těmito možnými položkami: |
83
|
|
|
* string|Pokladna 'pokladna' identifikátor pokladny |
84
|
|
|
* string 'typDokl' kod typu pokladniho dokladu |
85
|
|
|
* boolean 'kurzKDatuUhrady' |
86
|
|
|
* string 'uhrazujiciDokl' Pokud uvedeno není, vždy se vytvoří nový |
87
|
|
|
* pokladní doklad. |
88
|
|
|
* string 'rada' dokladová řada pro vytvářený pokladní doklad. |
89
|
1 |
|
* Např.:code:POKLADNA+ |
90
|
|
|
* string 'datumUhrady' sql formát. Výchozí: dnes |
91
|
1 |
|
* |
92
|
1 |
|
* @return boolean výsledek pokusu o provedení úhrady |
93
|
1 |
|
*/ |
94
|
|
|
public function hotovostniUhrada($value, $uhrada = []) |
95
|
1 |
|
{ |
96
|
1 |
|
if (!isset($uhrada['pokladna'])) { |
97
|
1 |
|
$uhrada['pokladna'] = 'code:POKLADNA KČ'; |
98
|
|
|
} |
99
|
1 |
|
|
100
|
1 |
|
if (!isset($uhrada['typDokl'])) { |
101
|
1 |
|
$uhrada['typDokl'] = 'code:STANDARD'; |
102
|
|
|
} |
103
|
1 |
|
|
104
|
1 |
|
if (!isset($uhrada['kurzKDatuUhrady'])) { |
105
|
1 |
|
$uhrada['kurzKDatuUhrady'] = false; |
106
|
|
|
} |
107
|
1 |
|
|
108
|
|
|
if (!isset($uhrada['datumUhrady'])) { |
109
|
1 |
|
$uhrada['datumUhrady'] = date('Y-m-d'); |
110
|
1 |
|
} |
111
|
|
|
|
112
|
|
|
$uhrada['castka'] = $value; |
113
|
|
|
|
114
|
|
|
$this->setDataValue('hotovostni-uhrada', $uhrada); |
115
|
|
|
$this->insertToFlexiBee(); |
116
|
|
|
return $this->lastResponseCode == 201; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Odpočet zálohy (vystavení daňového dokladu k platbě) |
121
|
|
|
* |
122
|
|
|
* @link https://demo.flexibee.eu/devdoc/odpocet-zaloh Odpočet záloh a ZDD |
123
|
|
|
* @param FakturaVydana $invoice zálohová faktura |
124
|
|
|
* @param array $odpocet Vlastnosti odpočtu |
125
|
|
|
* |
126
|
|
|
* @return boolean success |
127
|
|
|
*/ |
128
|
|
|
public function odpocetZalohy($invoice, $odpocet = []) |
129
|
|
|
{ |
130
|
|
|
if (!isset($odpocet['castkaMen'])) { |
131
|
|
|
$odpocet['castkaMen'] = $invoice->getDataValue('sumCelkem'); |
132
|
|
|
} |
133
|
|
|
$odpocet['doklad'] = $invoice; |
134
|
|
|
|
135
|
|
|
$this->setDataValue('odpocty-zaloh', ['odpocet' => $odpocet]); |
136
|
|
|
$this->insertToFlexiBee(); |
137
|
|
|
return $this->lastResponseCode == 201; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Odpočet ZDD |
142
|
|
|
* |
143
|
|
|
* @link https://demo.flexibee.eu/devdoc/odpocet-zaloh Odpočet záloh a ZDD |
144
|
|
|
* @param FakturaVydana $invoice zálohová faktura |
145
|
|
|
* @param array $odpocet Vlastnosti odpočtu |
146
|
|
|
* |
147
|
|
|
* @return boolean success |
148
|
|
|
*/ |
149
|
|
|
public function odpocetZDD($invoice, $odpocet = []) |
150
|
|
|
{ |
151
|
|
|
if (!isset($odpocet['castkaZaklMen'])) { |
152
|
|
|
$odpocet['castkaZaklMen'] = $invoice->getDataValue('sumZklZakl'); |
153
|
|
|
} |
154
|
|
|
if (!isset($odpocet['castkaSnizMen'])) { |
155
|
|
|
$odpocet['castkaSnizMen'] = $invoice->getDataValue('sumZklSniz'); |
156
|
|
|
} |
157
|
|
|
if (!isset($odpocet['castkaSniz2Men'])) { |
158
|
|
|
$odpocet['castkaSniz2Men'] = $invoice->getDataValue('sumZklSniz2'); |
159
|
|
|
} |
160
|
|
|
if (!isset($odpocet['castkaOsvMen'])) { |
161
|
|
|
$odpocet['castkaOsvMen'] = $invoice->getDataValue('sumOsv'); |
162
|
|
|
} |
163
|
|
|
if (!isset($odpocet['id'])) { |
164
|
|
|
$odpocet['id'] = 'ext:odpocet1'; |
165
|
|
|
} |
166
|
|
|
$odpocet['doklad'] = $invoice; |
167
|
|
|
|
168
|
|
|
$this->setDataValue('odpocty-zaloh', ['odpocet' => $odpocet]); |
169
|
|
|
$this->insertToFlexiBee(); |
170
|
|
|
return $this->lastResponseCode == 201; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* add link to advance tax document |
175
|
|
|
* |
176
|
|
|
* @param Banka|PokladniPohyb $income Income payment document |
177
|
|
|
* |
178
|
|
|
* @return boolean success |
179
|
|
|
* |
180
|
|
|
* @throws Exception |
181
|
|
|
*/ |
182
|
|
|
public function vytvorVazbuZDD($income) |
183
|
|
|
{ |
184
|
|
|
switch (get_class($income)) { |
185
|
|
|
case 'FlexiPeeHP\\Banka': |
186
|
|
|
$modul = 'banka'; |
187
|
|
|
break; |
188
|
|
|
case 'FlexiPeeHP\\PokladniPohyb': |
189
|
|
|
$modul = 'pokladna'; |
190
|
|
|
break; |
191
|
|
|
default : |
|
|
|
|
192
|
|
|
throw new \Ease\Exception(_('Unsupported $income parameter type')); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
$incomeId = $income->getRecordID(); |
196
|
|
|
$myId = $this->getRecordID(); |
197
|
|
|
|
198
|
|
|
$headersBackup = $this->defaultHttpHeaders; |
199
|
|
|
|
200
|
|
|
$this->defaultHttpHeaders['Accept'] = 'text/html'; |
201
|
|
|
$this->setPostFields(http_build_query(['modul' => $modul, |
202
|
|
|
'submit' => 'OK'])); |
203
|
|
|
$this->performRequest($myId.'/vytvor-vazbu-zdd/'.$incomeId, 'GET', |
204
|
|
|
'json'); |
205
|
|
|
|
206
|
|
|
$responseArr = explode("\n", $this->lastCurlResponse); |
207
|
|
|
$result = true; |
208
|
|
|
$message = ''; |
209
|
|
|
foreach ($responseArr as $lineNo => $responseLine) { |
210
|
|
|
if (strstr($responseLine, '<ul class = "flexibee-errors">')) { |
211
|
|
|
$message = trim($responseArr[$lineNo + 1]); |
212
|
|
|
$result = false; |
213
|
|
|
} |
214
|
|
|
if (strstr($responseLine, '<div class = "alert alert-success">')) { |
215
|
|
|
$message = strip_tags(html_entity_decode(trim($responseArr[$lineNo |
216
|
|
|
+ 1]))); |
217
|
|
|
$result = true; |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
if ($result === true) { |
222
|
|
|
$this->addStatusMessage(empty($message) ? $this->getDataValue('kod').'/vytvor-vazbu-zdd/'.$income->getRecordCode() |
223
|
|
|
: $message, 'success'); |
224
|
|
|
} else { |
225
|
|
|
$this->addStatusMessage($this->getDataValue('kod').'/vytvor-vazbu-zdd/'.$incomeId, |
226
|
|
|
'warning'); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
$this->defaultHttpHeaders = $headersBackup; |
230
|
|
|
|
231
|
|
|
return $result; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* |
236
|
|
|
* @param int $size requested of image |
237
|
|
|
* |
238
|
|
|
* @return type |
|
|
|
|
239
|
|
|
*/ |
240
|
|
|
public function getQrCodeImage($size = 140) |
241
|
|
|
{ |
242
|
|
|
$this->performRequest($this->getRecordID().'/qrcode.png?size='.$size, |
243
|
|
|
'GET', 'png'); |
244
|
|
|
if ($this->lastResponseCode == 200) { |
245
|
|
|
return $this->lastCurlResponse; |
246
|
|
|
} |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Get base64 encoded QrCode image |
251
|
|
|
* |
252
|
|
|
* @param int $size requested of image |
253
|
|
|
* |
254
|
|
|
* @return string IMG SRC code |
255
|
|
|
*/ |
256
|
|
|
public function getQrCodeBase64($size = 140) |
257
|
|
|
{ |
258
|
|
|
return 'data: image/png;base64,'.base64_encode($this->getQrCodeImage($size)); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Get Number of days overdue |
263
|
|
|
* |
264
|
|
|
* @param string $dueDate FlexiBee date |
265
|
|
|
* |
266
|
|
|
* @return int |
267
|
|
|
*/ |
268
|
|
|
static public function overdueDays($dueDate) |
|
|
|
|
269
|
|
|
{ |
270
|
|
|
$dateDiff = date_diff(is_object($dueDate) ? $dueDate : FlexiBeeRO::flexiDateToDateTime($dueDate), |
|
|
|
|
271
|
|
|
new \DateTime()); |
272
|
|
|
if ($dateDiff->invert == 1) { |
273
|
|
|
$ddif = $dateDiff->days * -1; |
274
|
|
|
} else { |
275
|
|
|
$ddif = $dateDiff->days; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
return $ddif; |
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths