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