Passed
Push — master ( c19d9e...2cc707 )
by Vítězslav
24:55
created

FakturaVydana::zrusVazbuZdd()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 1
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
    use Stitky;
20
    use Firma;
21
    use Sum;
22
    use SubItems;
23
24
    /**
25
     * Evidence užitá objektem.
26
     *
27
     * @var string
28
     */
29
    public $evidence = 'faktura-vydana';
30
31
    /**
32
     * Provede spárování platby s dokladem
33
     *
34
     * @link https://demo.flexibee.eu/devdoc/parovani-plateb Párování plateb
35
     * 
36
     * @param $doklad Banka|PokladniPohyb|InterniDoklad S jakým dokladem spárovat ?
37
     * @param $zbytek string ne|zauctovat|ignorovat|castecnaUhrada|castecnaUhradaNeboZauctovat|castecnaUhradaNeboIgnorovat
38
     * 
39
     * @return boolean success
40
     */
41
    public function sparujPlatbu($doklad, $zbytek = 'ignorovat')
42
    {
43
        $sparovani                       = ['uhrazovanaFak' => $this];
44
        $sparovani['uhrazovanaFak@type'] = $this->evidence;
45
        $sparovani['zbytek']             = $zbytek;
46
        $doklad->insertToFlexiBee(['id' => $doklad, 'sparovani' => $sparovani]);
47
        return $doklad->lastResponseCode == 201;
48
    }
49
50
    /**
51
     *  Hotovostní platba faktury.
52
     *
53
     * @link https://demo.flexibee.eu/devdoc/hotovostni-uhrada/ Hotovostní úhrada
54
     * @link https://demo.flexibee.eu/c/demo/pokladna Pokladny
55
     * @link https://demo.flexibee.eu/c/demo/typ-pokladni-pohyb Typy dokladů
56
     * @param float $value částka k úhradě
57
     * @param array $uhrada pole nepoviných vlastností úhrady s těmito možnými položkami:
58
     *        string|Pokladna  'pokladna' identifikátor pokladny
59
     *        string  'typDokl' kod typu pokladniho dokladu
60
     *        boolean 'kurzKDatuUhrady'
61
     *        string  'uhrazujiciDokl' Pokud uvedeno není, vždy se vytvoří nový
62
     *                                pokladní doklad.
63
     *        string  'rada' dokladová řada pro vytvářený pokladní doklad.
64
     *                      Např.:code:POKLADNA+
65
     *        string  'datumUhrady' sql formát. Výchozí: dnes
66
     * 
67
     * @return boolean výsledek pokusu o provedení úhrady
68
     */
69
    public function hotovostniUhrada($value, $uhrada = [])
70
    {
71
        if (!isset($uhrada['pokladna'])) {
72
            $uhrada['pokladna'] = 'code:POKLADNA KČ';
73
        }
74
75
        if (!isset($uhrada['typDokl'])) {
76
            $uhrada['typDokl'] = 'code:STANDARD';
77
        }
78
79
        if (!isset($uhrada['kurzKDatuUhrady'])) {
80
            $uhrada['kurzKDatuUhrady'] = false;
81
        }
82
83
        if (!isset($uhrada['datumUhrady'])) {
84
            $uhrada['datumUhrady'] = date('Y-m-d');
85
        }
86
87
        $uhrada['castka'] = $value;
88
89
        $this->setDataValue('hotovostni-uhrada', $uhrada);
90
        $this->insertToFlexiBee();
91
        return $this->lastResponseCode == 201;
92
    }
93
94
    /**
95
     * Odpočet zálohy (vystavení daňového dokladu k platbě)
96
     * 
97
     * @link https://demo.flexibee.eu/devdoc/odpocet-zaloh Odpočet záloh a ZDD
98
     * @param FakturaVydana $invoice zálohová faktura
99
     * @param array $odpocet Vlastnosti odpočtu
100
     * 
101
     * @return boolean success
102
     */
103
    public function odpocetZalohy($invoice, $odpocet = [])
104
    {
105
        if (!isset($odpocet['castkaMen'])) {
106
            $odpocet['castkaMen'] = $invoice->getDataValue('sumCelkem');
107
        }
108
        $odpocet['doklad'] = $invoice;
109
110
        $this->setDataValue('odpocty-zaloh', ['odpocet' => $odpocet]);
111
        $this->insertToFlexiBee();
112
        return $this->lastResponseCode == 201;
113
    }
114
115
    /**
116
     * Odpočet ZDD
117
     *
118
     * @link https://demo.flexibee.eu/devdoc/odpocet-zaloh Odpočet záloh a ZDD
119
     * @param FakturaVydana $invoice zálohová faktura
120
     * @param array $odpocet Vlastnosti odpočtu
121
     * 
122
     * @return boolean success
123
     */
124
    public function odpocetZDD($invoice, $odpocet = [])
125
    {
126
        if (!isset($odpocet['castkaZaklMen'])) {
127
            $odpocet['castkaZaklMen'] = $invoice->getDataValue('sumZklZakl');
128
        }
129
        if (!isset($odpocet['castkaSnizMen'])) {
130
            $odpocet['castkaSnizMen'] = $invoice->getDataValue('sumZklSniz');
131
        }
132
        if (!isset($odpocet['castkaSniz2Men'])) {
133
            $odpocet['castkaSniz2Men'] = $invoice->getDataValue('sumZklSniz2');
134
        }
135
        if (!isset($odpocet['castkaOsvMen'])) {
136
            $odpocet['castkaOsvMen'] = $invoice->getDataValue('sumOsv');
137
        }
138
        if (!isset($odpocet['id'])) {
139
            $odpocet['id'] = 'ext:odpocet1';
140
        }
141
        $odpocet['doklad'] = $invoice;
142
143
        $this->setDataValue('odpocty-zaloh', ['odpocet' => $odpocet]);
144
        $this->insertToFlexiBee();
145
        return $this->lastResponseCode == 201;
146
    }
147
148
    /**
149
     * add link to advance tax document
150
     * 
151
     * @link https://www.flexibee.eu/api/dokumentace/ref/vazby-zdd/ vazby-zdd
152
     * 
153
     * @param Banka|PokladniPohyb $income Income payment document
154
     * 
155
     * @return boolean success
156
     */
157
    public function vytvorVazbuZDD($income)
158
    {
159
        $classHelper = explode('\\', get_class($income));
160
        $bondRequest = [
161
            'id' => $this->getRecordIdent(),
162
            'vytvor-vazbu-zdd' => [
163
                'uhrada' => $income->getRecordIdent(),
164
                'uhrada@type' => strtolower(end($classHelper))
165
            ]
166
        ];
167
        $this->insertToFlexiBee($bondRequest);
168
        return $this->lastResponseCode == 201;
169
    }
170
171
    /**
172
     * Remove Advance tax document bondig
173
     * 
174
     * @link https://www.flexibee.eu/api/dokumentace/ref/vazby-zdd/ vazby-zdd
175
     * 
176
     * @param int|string $id Invoice record identifier
177
     * 
178
     * @return boolean operation success
179
     */
180
    public function zrusVazbuZdd($id = null)
181
    {
182
        $unbondRequest = [
183
            'id' => is_null($id) ? $this->getRecordIent() : $id,
0 ignored issues
show
Bug introduced by
The method getRecordIent() does not exist on FlexiPeeHP\FakturaVydana. Did you maybe mean getRecordIdent()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

183
            'id' => is_null($id) ? $this->/** @scrutinizer ignore-call */ getRecordIent() : $id,

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
184
            'zrus-vazbu-zdd'
185
        ];
186
187
        $this->insertToFlexiBee($unbondRequest);
188
        return $this->lastResponseCode == 201;
189
    }
190
191
    /**
192
     * 
193
     * @param int $size requested of image
194
     * 
195
     * @return string binary PNG body
196
     */
197
    public function getQrCodeImage($size = 140)
198
    {
199
        $this->performRequest($this->getRecordID().'/qrcode.png?size='.$size,
200
            'GET', 'png');
201
        if ($this->lastResponseCode == 200) {
202
            return $this->lastCurlResponse;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->lastCurlResponse also could return the type boolean which is incompatible with the documented return type string.
Loading history...
203
        }
204
    }
205
206
    /**
207
     * Get base64 encoded QrCode image
208
     * 
209
     * @param int $size requested of image
210
     * 
211
     * @return string IMG SRC code
212
     */
213
    public function getQrCodeBase64($size = 140)
214
    {
215
        return 'data: image/png;base64,'.base64_encode($this->getQrCodeImage($size));
216
    }
217
218
    /**
219
     * Get Number of days overdue
220
     * 
221
     * @param string $dueDate FlexiBee date
222
     * 
223
     * @return int
224
     */
225
    static public function overdueDays($dueDate)
226
    {
227
        $dateDiff = date_diff(is_object($dueDate) ? $dueDate : FlexiBeeRO::flexiDateToDateTime($dueDate),
0 ignored issues
show
Bug introduced by
It seems like is_object($dueDate) ? $d...ateToDateTime($dueDate) can also be of type false; however, parameter $object of date_diff() does only seem to accept DateTime, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

227
        $dateDiff = date_diff(/** @scrutinizer ignore-type */ is_object($dueDate) ? $dueDate : FlexiBeeRO::flexiDateToDateTime($dueDate),
Loading history...
introduced by
The condition is_object($dueDate) is always false.
Loading history...
228
            new \DateTime());
229
        if ($dateDiff->invert == 1) {
230
            $ddif = $dateDiff->days * -1;
231
        } else {
232
            $ddif = $dateDiff->days;
233
        }
234
235
        return $ddif;
236
    }
237
238
    /**
239
     * Add Data to invoice subItem
240
     *
241
     * @see Relations
242
     *
243
     * @param array   $data pole dat
244
     * @param string  $relationPath path evidence (relation) pro vkládaná data
245
     * @param boolean $removeAll
246
     *
247
     * @return boolean Operation success
248
     */
249
    public function addArrayToBranch($data, $relationPath = 'polozkyFaktury',
250
                                     $removeAll = false)
251
    {
252
        return parent::addArrayToBranch($data, $relationPath, $removeAll);
253
    }
254
}
255