Passed
Push — master ( ef71b6...431342 )
by Vítězslav
02:53
created

FakturaVydana::overdueDays()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 3
eloc 7
nc 2
nop 1
crap 12
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 ?
0 ignored issues
show
Bug introduced by
The type FlexiPeeHP\InterniDoklad was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
62 1
     * @param $zbytek string ne|zauctovat|ignorovat|castecnaUhrada|castecnaUhradaNeboZauctovat|castecnaUhradaNeboIgnorovat
63
     * 
64 1
     * @return Banka|PokladniPohyb|InterniDoklad Matched document
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
        return $doklad->insertToFlexiBee(['id' => $doklad, 'sparovani' => $sparovani]);
72
    }
73
74
    /**
75
     *  Hotovostní platba faktury.
76
     *
77
     * @link https://demo.flexibee.eu/devdoc/hotovostni-uhrada/ Hotovostní úhrada
78
     * @link https://demo.flexibee.eu/c/demo/pokladna Pokladny
79
     * @link https://demo.flexibee.eu/c/demo/typ-pokladni-pohyb Typy dokladů
80
     * @param float $value částka k úhradě
81
     * @param array $uhrada pole nepoviných vlastností úhrady s těmito možnými položkami:
82
     *        string|Pokladna  'pokladna' identifikátor pokladny
83
     *        string  'typDokl' kod typu pokladniho dokladu
84
     *        boolean 'kurzKDatuUhrady'
85
     *        string  'uhrazujiciDokl' Pokud uvedeno není, vždy se vytvoří nový
86
     *                                pokladní doklad.
87
     *        string  'rada' dokladová řada pro vytvářený pokladní doklad.
88
     *                      Např.:code:POKLADNA+
89 1
     *        string  'datumUhrady' sql formát. Výchozí: dnes
90
     * @return array výsledek pokusu o provedení úhrady
91 1
     */
92 1
    public function hotovostniUhrada($value, $uhrada = [])
93 1
    {
94
        if (!isset($uhrada['pokladna'])) {
95 1
            $uhrada['pokladna'] = 'code:POKLADNA KČ';
96 1
        }
97 1
98
        if (!isset($uhrada['typDokl'])) {
99 1
            $uhrada['typDokl'] = 'code:STANDARD';
100 1
        }
101 1
102
        if (!isset($uhrada['kurzKDatuUhrady'])) {
103 1
            $uhrada['kurzKDatuUhrady'] = false;
104 1
        }
105 1
106
        if (!isset($uhrada['datumUhrady'])) {
107 1
            $uhrada['datumUhrady'] = date('Y-m-d');
108
        }
109 1
110 1
        $uhrada['castka'] = $value;
111
112
        $this->setDataValue('hotovostni-uhrada', $uhrada);
113
        return $this->insertToFlexiBee();
114
    }
115
116
    /**
117
     * Odpočet zálohy (vystavení daňového dokladu k platbě)
118
     * 
119
     * @link https://demo.flexibee.eu/devdoc/odpocet-zaloh Odpočet záloh a ZDD
120
     * @param FakturaVydana $invoice zálohová faktura
121
     * @param array $odpocet Vlastnosti odpočtu
122
     * @return array
123
     */
124
    public function odpocetZalohy($invoice, $odpocet = [])
125
    {
126
        if (!isset($odpocet['castkaMen'])) {
127
            $odpocet['castkaMen'] = $invoice->getDataValue('sumCelkem');
128
        }
129
        $odpocet['doklad'] = $invoice;
130
131
        $this->setDataValue('odpocty-zaloh', ['odpocet' => $odpocet]);
132
        return $this->insertToFlexiBee();
133
    }
134
135
    /**
136
     * Odpočet ZDD
137
     *
138
     * @link https://demo.flexibee.eu/devdoc/odpocet-zaloh Odpočet záloh a ZDD
139
     * @param FakturaVydana $invoice zálohová faktura
140
     * @param array $odpocet Vlastnosti odpočtu
141
     * @return array
142
     */
143
    public function odpocetZDD($invoice, $odpocet = [])
144
    {
145
        if (!isset($odpocet['castkaZaklMen'])) {
146
            $odpocet['castkaZaklMen'] = $invoice->getDataValue('sumZklZakl');
147
        }
148
        if (!isset($odpocet['castkaSnizMen'])) {
149
            $odpocet['castkaSnizMen'] = $invoice->getDataValue('sumZklSniz');
150
        }
151
        if (!isset($odpocet['castkaSniz2Men'])) {
152
            $odpocet['castkaSniz2Men'] = $invoice->getDataValue('sumZklSniz2');
153
        }
154
        if (!isset($odpocet['castkaOsvMen'])) {
155
            $odpocet['castkaOsvMen'] = $invoice->getDataValue('sumOsv');
156
        }
157
        if (!isset($odpocet['id'])) {
158
            $odpocet['id'] = 'ext:odpocet1';
159
        }
160
        $odpocet['doklad'] = $invoice;
161
162
        $this->setDataValue('odpocty-zaloh', ['odpocet' => $odpocet]);
163
        return $this->insertToFlexiBee();
164
    }
165
166
    /**
167
     * add link to advance tax document
168
     * 
169
     * @param Banka|PokladniPohyb $income Income payment document
170
     * 
171
     * @return boolean success
172
     * 
173
     * @throws Exception
174
     */
175
    public function vytvorVazbuZDD($income)
176
    {
177
        switch (get_class($income)) {
178
            case 'FlexiPeeHP\\Banka':
179
                $modul = 'banka';
180
                break;
181
            case 'FlexiPeeHP\\PokladniPohyb':
182
                $modul = 'pokladna';
183
                break;
184
            default :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
185
                throw new \Ease\Exception(_('Unsupported $income parameter type'));
186
        }
187
188
        $incomeId = $income->getRecordID();
189
        $myId     = $this->getRecordID();
190
191
        $headersBackup = $this->defaultHttpHeaders;
192
193
        $this->defaultHttpHeaders['Accept'] = 'text/html';
194
        $this->setPostFields(http_build_query(['modul' => $modul,
195
            'submit' => 'OK']));
196
        $this->performRequest($myId.'/vytvor-vazbu-zdd/'.$incomeId, 'GET',
197
            'json');
198
199
        $responseArr = explode("\n", $this->lastCurlResponse);
200
        $result      = true;
201
        $message     = '';
202
        foreach ($responseArr as $lineNo => $responseLine) {
203
            if (strstr($responseLine, '<ul class = "flexibee-errors">')) {
204
                $message = trim($responseArr[$lineNo + 1]);
205
                $result  = false;
206
            }
207
            if (strstr($responseLine, '<div class = "alert alert-success">')) {
208
                $message = strip_tags(html_entity_decode(trim($responseArr[$lineNo
209
                            + 1])));
210
                $result  = true;
211
            }
212
        }
213
214
        if ($result === true) {
215
            $this->addStatusMessage(empty($message) ? $this->getDataValue('kod').'/vytvor-vazbu-zdd/'.$income->getRecordCode()
216
                        : $message, 'success');
217
        } else {
218
            $this->addStatusMessage($this->getDataValue('kod').'/vytvor-vazbu-zdd/'.$incomeId,
219
                'warning');
220
        }
221
222
        $this->defaultHttpHeaders = $headersBackup;
223
224
        return $result;
225
    }
226
227
    /**
228
     * 
229
     * @param int $size requested of image
230
     * 
231
     * @return type
0 ignored issues
show
Bug introduced by
The type FlexiPeeHP\type was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
232
     */
233
    public function getQrCodeImage($size = 140)
234
    {
235
        $this->performRequest($this->getRecordID().'/qrcode.png?size='.$size,
236
            'GET', 'png');
237
        if ($this->lastResponseCode == 200) {
238
            return $this->lastCurlResponse;
239
        }
240
    }
241
242
    /**
243
     * Get base64 encoded QrCode image
244
     * 
245
     * @param int $size requested of image
246
     * 
247
     * @return string IMG SRC code
248
     */
249
    public function getQrCodeBase64($size = 140)
250
    {
251
        return 'data: image/png;base64,'.base64_encode($this->getQrCodeImage($size));
252
    }
253
254
    /**
255
     * Get Number of days overdue
256
     * 
257
     * @param string $dueDate FlexiBee date
258
     * 
259
     * @return int
260
     */
261
    static public function overdueDays($dueDate)
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
262
    {
263
        $dateDiff = date_diff(is_object($dueDate) ? $dueDate : FlexiBeeRO::flexiDateToDateTime($dueDate),
0 ignored issues
show
introduced by
The condition is_object($dueDate) is always false.
Loading history...
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

263
        $dateDiff = date_diff(/** @scrutinizer ignore-type */ is_object($dueDate) ? $dueDate : FlexiBeeRO::flexiDateToDateTime($dueDate),
Loading history...
264
            new \DateTime());
265
        if ($dateDiff->invert == 1) {
266
            $ddif = $dateDiff->days * -1;
267
        } else {
268
            $ddif = $dateDiff->days;
269
        }
270
271
        return $ddif;
272
    }
273
}
274