|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Test\FlexiPeeHP; |
|
4
|
|
|
|
|
5
|
|
|
use FlexiPeeHP\FakturaVydana; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Generated by PHPUnit_SkeletonGenerator on 2016-04-27 at 17:32:11. |
|
9
|
|
|
*/ |
|
10
|
|
|
class FakturaVydanaTest extends FlexiBeeRWTest |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var FakturaVydana |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $object; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Gives You new testng invoice |
|
19
|
|
|
* |
|
20
|
|
|
* @param string $code with givew code of internal ID |
|
21
|
|
|
* @param array $overrides with given values |
|
22
|
|
|
* |
|
23
|
|
|
* @return FakturaVydana |
|
24
|
|
|
*/ |
|
25
|
|
|
static public function getNew($code = 'UnitTest', $overrides = []) |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
$helper = new FakturaVydanaTest(); |
|
28
|
|
|
$helper->setUp(); |
|
29
|
|
|
$helper->object->sync(array_merge($helper->getDataForInsert($code), |
|
30
|
|
|
$overrides)); |
|
31
|
|
|
return $helper->object; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Gives You data able to insert into current evidence |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $code custom record code |
|
38
|
|
|
* |
|
39
|
|
|
* @return array |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getDataForInsert($code = 'UnitTest') |
|
42
|
|
|
{ |
|
43
|
|
|
$dataForInsert = parent::getDataForInsert($code); |
|
44
|
|
|
$dataForInsert['typDokl'] = 'code:FAKTURA'; |
|
45
|
|
|
$adresar = new \FlexiPeeHP\Adresar(); |
|
46
|
|
|
$candidates = $adresar->getColumnsFromFlexibee('id'); |
|
|
|
|
|
|
47
|
|
|
$dataForInsert['firma'] = $candidates[array_rand($candidates)]['id']; |
|
48
|
|
|
$dataForInsert['sumZklZakl'] = \Ease\Sand::randomNumber(1000, 9999); |
|
49
|
|
|
$dataForInsert['varSym'] = $dataForInsert['kod'] = time(); |
|
50
|
|
|
$dataForInsert['bezPolozek'] = true; |
|
51
|
|
|
return $dataForInsert; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Sets up the fixture, for example, opens a network connection. |
|
56
|
|
|
* This method is called before a test is executed. |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function setUp(): void |
|
59
|
|
|
{ |
|
60
|
|
|
$this->object = new FakturaVydana(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Tears down the fixture, for example, closes a network connection. |
|
65
|
|
|
* This method is called after a test is executed. |
|
66
|
|
|
*/ |
|
67
|
|
|
protected function tearDown(): void |
|
68
|
|
|
{ |
|
69
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @covers FlexiPeeHP\FakturaVydana::hotovostniUhrada |
|
74
|
|
|
*/ |
|
75
|
|
|
public function testhotovostniUhrada() |
|
76
|
|
|
{ |
|
77
|
|
|
$this->makeInvoice(); |
|
78
|
|
|
$this->object->unsetDataValue('kod'); |
|
79
|
|
|
$this->object->hotovostniUhrada($this->object->getDataValue('sumCelkZakl')); |
|
80
|
|
|
$this->assertEquals(201, $this->object->lastResponseCode, |
|
|
|
|
|
|
81
|
|
|
_('Invoice settle error')); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @covers FlexiPeeHP\FakturaVydana::sparujPlatbu |
|
86
|
|
|
*/ |
|
87
|
|
|
public function testsparujPlatbu() |
|
88
|
|
|
{ |
|
89
|
|
|
$this->makeInvoice(); |
|
90
|
|
|
$doklad = new \FlexiPeeHP\PokladniPohyb(); |
|
91
|
|
|
$value = $this->object->getDataValue('sumCelkZakl'); |
|
92
|
|
|
$dataPohybu = [ |
|
93
|
|
|
'kod' => 'FP'.time(), |
|
94
|
|
|
'typDokl' => 'code:STANDARD', |
|
95
|
|
|
'typPohybuK' => 'typPohybu.prijem', |
|
96
|
|
|
'datVyst' => date("Y-m-d", time() - 60 * 60 * 24), |
|
97
|
|
|
'jakUhrK' => 'jakUhrazeno.rucne1', |
|
98
|
|
|
'pokladna' => 'code:POKLADNA KČ', |
|
99
|
|
|
'generovatSkl' => false, |
|
100
|
|
|
'zdrojProSkl' => false, |
|
101
|
|
|
'firma' => $this->object->getDataValue('firma'), |
|
102
|
|
|
'bezPolozek' => true, |
|
103
|
|
|
'poznam' => $this->poznam, |
|
104
|
|
|
'primUcet' => 'code:013001', |
|
105
|
|
|
'sumZklCelkem' => $value |
|
106
|
|
|
]; |
|
107
|
|
|
$doklad->takeData($dataPohybu); |
|
108
|
|
|
$doklad->insertToFlexiBee(); |
|
109
|
|
|
$doklad->unsetDataValue('kod'); |
|
110
|
|
|
$this->object->sparujPlatbu($doklad); |
|
111
|
|
|
$this->assertEquals(201, $doklad->lastResponseCode, |
|
112
|
|
|
_('Invoice match error')); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Crerate testing invoice |
|
117
|
|
|
* |
|
118
|
|
|
* @param array $invoiceData |
|
119
|
|
|
*/ |
|
120
|
|
|
public function makeInvoice($invoiceData = []) |
|
121
|
|
|
{ |
|
122
|
|
|
if (!isset($invoiceData['kod'])) { |
|
123
|
|
|
$invoiceData['kod'] = 'PeeHP'.time(); |
|
124
|
|
|
} |
|
125
|
|
|
if (!isset($invoiceData['varSym'])) { |
|
126
|
|
|
$invoiceData['varSym'] = \Ease\Sand::randomNumber(1000, 99999); |
|
127
|
|
|
} |
|
128
|
|
|
if (!isset($invoiceData['datVyst'])) { |
|
129
|
|
|
$invoiceData['datVyst'] = date("Y-m-d", time() - 60 * 60 * 24); |
|
130
|
|
|
} |
|
131
|
|
|
if (!isset($invoiceData['typDokl'])) { |
|
132
|
|
|
$invoiceData['typDokl'] = 'code:FAKTURA'; |
|
133
|
|
|
} |
|
134
|
|
|
if (!isset($invoiceData['zdrojProSkl'])) { |
|
135
|
|
|
$invoiceData['zdrojProSkl'] = false; |
|
136
|
|
|
} |
|
137
|
|
|
if (!isset($invoiceData['dobropisovano'])) { |
|
138
|
|
|
$invoiceData['dobropisovano'] = false; |
|
139
|
|
|
} |
|
140
|
|
|
if (!isset($invoiceData['bezPolozek'])) { |
|
141
|
|
|
$invoiceData['bezPolozek'] = false; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
if (!isset($invoiceData['polozky']) && !$invoiceData['bezPolozek']) { |
|
145
|
|
|
$invoiceData['bezPolozek'] = true; |
|
146
|
|
|
if (!array_key_exists('sumCelkZakl', $invoiceData)) { |
|
147
|
|
|
$scale = pow(1000, 2); |
|
148
|
|
|
$price = round(mt_rand(10 * $scale, |
|
149
|
|
|
9000 * $scale) / $scale, 2); |
|
150
|
|
|
// $invoiceData['sumCelkZakl'] = $invoiceData['castkaMen'] = 0; |
|
|
|
|
|
|
151
|
|
|
$invoiceData['sumZklCelkem'] = $price; |
|
152
|
|
|
$invoiceData['sumCelkem'] = $price; |
|
153
|
|
|
$invoiceData['sumOsv'] = $price; |
|
154
|
|
|
} |
|
155
|
|
|
} else { |
|
156
|
|
|
$invoiceData['bezPolozek'] = false; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
if (!isset($invoiceData['firma'])) { |
|
160
|
|
|
$adresar = new \FlexiPeeHP\Adresar(); |
|
161
|
|
|
|
|
162
|
|
|
$adresy = $adresar->getFlexiData(null, |
|
163
|
|
|
['typVztahuK' => 'typVztahu.odberatel']); |
|
164
|
|
|
if (count($adresy)) { |
|
165
|
|
|
$dodavatel = $adresy[array_rand($adresy)]; |
|
166
|
|
|
|
|
167
|
|
|
$invoiceData['firma'] = 'code:'.$dodavatel['kod']; |
|
168
|
|
|
} else { |
|
169
|
|
|
/** |
|
170
|
|
|
* Make Some Address First ... |
|
171
|
|
|
*/ |
|
172
|
|
|
$address = new \FlexiPeeHP\Adresar(); |
|
173
|
|
|
$address->setDataValue('nazev', \Ease\Sand::randomString()); |
|
174
|
|
|
$address->setDataValue('poznam', 'Generated Unit Test Customer'); |
|
175
|
|
|
$address->setDataValue('typVztahuK', 'typVztahu.odberatel'); |
|
176
|
|
|
$address->insertToFlexiBee(); |
|
177
|
|
|
$invoiceData['firma'] = $address; |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
if (!isset($invoiceData['poznam'])) { |
|
182
|
|
|
$invoiceData['poznam'] = $this->poznam; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
$this->object->takeData($invoiceData); |
|
186
|
|
|
$this->object->refresh(); |
|
|
|
|
|
|
187
|
|
|
return $this->object; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Provizorní zkopírování faktury |
|
192
|
|
|
* |
|
193
|
|
|
* @link https://www.flexibee.eu/podpora/Tickets/Ticket/View/28848 Chyba při Provádění akcí přes REST API JSON |
|
194
|
|
|
* @param \FlexiPeeHP\FakturaVydana $invoice |
|
195
|
|
|
* @param array $overide Hodnoty přepisující výchozí v kopii faktury |
|
196
|
|
|
* @return \FlexiPeeHP\FakturaVydana |
|
197
|
|
|
*/ |
|
198
|
|
|
public function invoiceCopy($invoice, $override = []) |
|
199
|
|
|
{ |
|
200
|
|
|
$invoice2 = new \FlexiPeeHP\FakturaVydana($invoice->getData()); |
|
201
|
|
|
$invoice2->debug = true; |
|
202
|
|
|
$invoice2->unsetDataValue('id'); |
|
203
|
|
|
$invoice2->unsetDataValue('kod'); |
|
204
|
|
|
$polozky = $invoice2->getDataValue('polozkyFaktury'); |
|
205
|
|
|
if (is_array($polozky) && count($polozky)) { |
|
206
|
|
|
foreach ($polozky as $pid => $polozka) { |
|
207
|
|
|
unset($polozky[$pid]['id']); |
|
208
|
|
|
unset($polozky[$pid]['doklFak']); |
|
209
|
|
|
unset($polozky[$pid]['doklFak@showAs']); |
|
210
|
|
|
unset($polozky[$pid]['doklFak@ref']); |
|
211
|
|
|
} |
|
212
|
|
|
$invoice2->setDataValue('polozkyFaktury', $polozky); |
|
213
|
|
|
} |
|
214
|
|
|
if (is_null($invoice2->getDataValue('typDokl'))) { |
|
215
|
|
|
$invoice2->setDataValue('typDokl', 'code:FAKTURA'); |
|
216
|
|
|
} |
|
217
|
|
|
$invoice2->unsetDataValue('external-ids'); |
|
218
|
|
|
|
|
219
|
|
|
$today = date('Y-m-d'); |
|
220
|
|
|
|
|
221
|
|
|
$invoice2->setDataValue('duzpPuv', $today); |
|
222
|
|
|
$invoice2->setDataValue('duzpUcto', $today); |
|
223
|
|
|
$invoice2->setDataValue('datUcto', $today); |
|
224
|
|
|
$invoice2->takeData($override); |
|
225
|
|
|
$invoice2->insertToFlexiBee(); |
|
226
|
|
|
|
|
227
|
|
|
return $invoice2; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @covers FlexiPeeHP\FakturaVydana::odpocetZDD |
|
232
|
|
|
*/ |
|
233
|
|
|
public function testodpocetZDD() |
|
234
|
|
|
{ |
|
235
|
|
|
$this->markTestIncomplete('TODO: Write Test'); |
|
|
|
|
|
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* @covers FlexiPeeHP\FakturaVydana::odpocetZalohy |
|
240
|
|
|
*/ |
|
241
|
|
|
public function testodpocetZalohy() |
|
242
|
|
|
{ |
|
243
|
|
|
$itemName = \Ease\Sand::randomString(); |
|
244
|
|
|
|
|
245
|
|
|
$polozka = [ |
|
246
|
|
|
"typCenyDphK" => "typCeny.bezDph", |
|
247
|
|
|
"typSzbDphK" => "typSzbDph.dphZakl", |
|
248
|
|
|
"kopClenKonVykDph" => "true", |
|
249
|
|
|
"typPolozkyK" => "typPolozky.obecny", |
|
250
|
|
|
'zdrojProSkl' => false, |
|
251
|
|
|
'zaloha' => true, |
|
252
|
|
|
'nazev' => $itemName, |
|
253
|
|
|
'szbDph' => 19.0, |
|
254
|
|
|
'cenaMj' => 123, |
|
255
|
|
|
"mnozMj" => "1.0", |
|
256
|
|
|
'poznam' => $this->poznam, |
|
257
|
|
|
]; |
|
258
|
|
|
|
|
259
|
|
|
$this->makeInvoice( |
|
260
|
|
|
[ |
|
261
|
|
|
'typDokl' => 'code:ZÁLOHA', |
|
262
|
|
|
'polozky' => $polozka, |
|
263
|
|
|
'bezPolozek' => false |
|
264
|
|
|
] |
|
265
|
|
|
); |
|
266
|
|
|
|
|
267
|
|
|
|
|
268
|
|
|
$this->object->hotovostniUhrada($this->object->getDataValue('sumCelkem')); |
|
269
|
|
|
|
|
270
|
|
|
$invoice2 = $this->invoiceCopy($this->object, |
|
271
|
|
|
['typDokl' => 'code:FAKTURA']); |
|
272
|
|
|
$id = (int) $invoice2->getLastInsertedId(); |
|
273
|
|
|
$invoice2->loadFromFlexiBee($id); |
|
274
|
|
|
$kod = $invoice2->getDataValue('kod'); |
|
275
|
|
|
$invoice2->dataReset(); |
|
276
|
|
|
$invoice2->setDataValue('id', 'code:'.$kod); |
|
277
|
|
|
|
|
278
|
|
|
$invdata = $this->object->getData(); |
|
279
|
|
|
|
|
280
|
|
|
$this->assertArrayHasKey('id', $invdata); |
|
|
|
|
|
|
281
|
|
|
|
|
282
|
|
|
// $this->object->getDataValue('sumCelkem'); ???? |
|
|
|
|
|
|
283
|
|
|
// $result = $invoice2->odpocetZalohy($this->object); |
|
284
|
|
|
// $this->assertArrayHasKey('success', $result); |
|
285
|
|
|
// $this->assertEquals('true', $result['success'], 'Matching Error'); |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* @covers FlexiPeeHP\FakturaVydana::addArrayToBranch |
|
290
|
|
|
*/ |
|
291
|
|
|
public function testAddArrayToBranch() |
|
292
|
|
|
{ |
|
293
|
|
|
$this->object->setDataValue('typDokl', 'FAKTURA'); |
|
294
|
|
|
$this->object->addArrayToBranch(['nazev' => 'faktura'], 'polozkyDokladu',true); |
|
295
|
|
|
$this->object->setDataValue('typDokl', 'ZALOHA'); |
|
296
|
|
|
$this->object->addArrayToBranch(['nazev' => 'zaloha'], 'polozkyDokladu'); |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
/** |
|
300
|
|
|
* @covers FlexiPeeHP\FakturaVydana::vytvorVazbuZDD |
|
301
|
|
|
*/ |
|
302
|
|
|
public function testVytvorVazbuZDD() |
|
303
|
|
|
{ |
|
304
|
|
|
$vs = \Ease\Sand::randomNumber(); |
|
305
|
|
|
$this->object->setDataValue('typDokl', 'code:ZÁLOHA'); |
|
306
|
|
|
$this->object->setDataValue('varSym', $vs); |
|
307
|
|
|
$this->object->setDataValue('duzpPuv', '2018-02-10T23:47:10.510+01:00'); |
|
308
|
|
|
$this->object->refresh(); |
|
309
|
|
|
$this->object->setDataValue('typDokl', 'code:ZDD'); |
|
310
|
|
|
$this->object->refresh(); |
|
311
|
|
|
$income = new \FlexiPeeHP\Banka(); |
|
312
|
|
|
$income->setDataValue('typDokl', 'code:STANDARD'); |
|
313
|
|
|
$income->setDataValue('kod', $vs); |
|
314
|
|
|
$income->setDataValue('banka', 'code:BANKOVNÍ ÚČET'); |
|
315
|
|
|
$income->setDataValue('varSym', $vs); |
|
316
|
|
|
$income->refresh(); |
|
|
|
|
|
|
317
|
|
|
$this->object->vytvorVazbuZDD($income); |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
/** |
|
321
|
|
|
* @covers FlexiPeeHP\FakturaVydana::overdueDays |
|
322
|
|
|
*/ |
|
323
|
|
|
public function testOverdueDays() |
|
324
|
|
|
{ |
|
325
|
|
|
$datSplat = new \DateTime(); |
|
326
|
|
|
$datSplat->modify('-7 days'); |
|
327
|
|
|
$datVyst = new \DateTime(); |
|
328
|
|
|
$datVyst->modify('-14 days'); |
|
329
|
|
|
$this->assertEquals(0, FakturaVydana::overdueDays(new \DateTime())); |
|
|
|
|
|
|
330
|
|
|
$this->assertEquals(7, FakturaVydana::overdueDays($datSplat)); |
|
331
|
|
|
$this->assertEquals(14, |
|
332
|
|
|
FakturaVydana::overdueDays(\FlexiPeeHP\FlexiBeeRW::dateToFlexiDate($datVyst))); |
|
333
|
|
|
} |
|
334
|
|
|
} |
|
335
|
|
|
|