Test Failed
Push — master ( 8f94bb...4b74ee )
by Vítězslav
16:50
created

FakturaVydana::vytvorVazbuZDD()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 12
ccs 0
cts 9
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
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
     * @param array  $data pole dat
30
     * @param string $relationPath path evidence (relation) pro vkládaná data
31
     * @see Relations
32
     */
33
    public function addArrayToBranch($data, $relationPath)
34
    {
35
        if (($relationPath == 'polozky-dokladu') || ($relationPath == 'polozky-faktury')) {
36
            switch ($this->getDataValue('typDokl')) {
37
                case 'code:DOBR':
38
                case 'code:DOBROPIS':
39
                case 'code:FAKTURA':
40
                    $data['ucetni'] = true;
41
                    break;
42
                case 'code:ZÁLOHA':
43
                case 'code:ZALOHA':
44
                default:
45
                    $data['ucetni'] = false;
46
                    break;
47
            }
48
        }
49
        return parent::addArrayToBranch($data, $relationPath);
50
    }
51
52
    /**
53
     * Provede spárování platby s dokladem
54
     *
55
     * @link https://demo.flexibee.eu/devdoc/parovani-plateb Párování plateb
56
     * @param $doklad Banka|PokladniPohyb|InterniDoklad S jakým dokladem spárovat ?
57
     * @param $zbytek string ne|zauctovat|ignorovat|castecnaUhrada|castecnaUhradaNeboZauctovat|castecnaUhradaNeboIgnorovat
58
     */
59 1
    public function sparujPlatbu($doklad, $zbytek = 'ignorovat')
60
    {
61 1
        $sparovani                       = ['uhrazovanaFak' => $this];
62 1
        $sparovani['uhrazovanaFak@type'] = $this->evidence;
63 1
        $sparovani['zbytek']             = $zbytek;
64 1
        $doklad->setDataValue('sparovani', $sparovani);
65 1
        return $doklad->insertToFlexiBee();
66
    }
67
68
    /**
69
     *  Hotovostní platba faktury.
70
     *
71
     * @link https://demo.flexibee.eu/devdoc/hotovostni-uhrada/ Hotovostní úhrada
72
     * @link https://demo.flexibee.eu/c/demo/pokladna Pokladny
73
     * @link https://demo.flexibee.eu/c/demo/typ-pokladni-pohyb Typy dokladů
74
     * @param float $value částka k úhradě
75
     * @param array $uhrada pole nepoviných vlastností úhrady s těmito možnými položkami:
76
     *        string|Pokladna  'pokladna' identifikátor pokladny
77
     *        string  'typDokl' kod typu pokladniho dokladu
78
     *        boolean 'kurzKDatuUhrady'
79
     *        string  'uhrazujiciDokl' Pokud uvedeno není, vždy se vytvoří nový
80
     *                                pokladní doklad.
81
     *        string  'rada' dokladová řada pro vytvářený pokladní doklad.
82
     *                      Např.:code:POKLADNA+
83
     *        string  'datumUhrady' sql formát. Výchozí: dnes
84
     * @return array výsledek pokusu o provedení úhrady
85
     */
86 1
    public function hotovostniUhrada($value, $uhrada = [])
87
    {
88 1
        if (!isset($uhrada['pokladna'])) {
89 1
            $uhrada['pokladna'] = 'code:POKLADNA KČ';
90 1
        }
91
92 1
        if (!isset($uhrada['typDokl'])) {
93 1
            $uhrada['typDokl'] = 'code:STANDARD';
94 1
        }
95
96 1
        if (!isset($uhrada['kurzKDatuUhrady'])) {
97 1
            $uhrada['kurzKDatuUhrady'] = false;
98 1
        }
99
100 1
        if (!isset($uhrada['datumUhrady'])) {
101 1
            $uhrada['datumUhrady'] = date('Y-m-d');
102 1
        }
103
104 1
        $uhrada['castka'] = $value;
105
106 1
        $this->setDataValue('hotovostni-uhrada', $uhrada);
107 1
        return $this->insertToFlexiBee();
108
    }
109
110
    /**
111
     * Odpočet zálohy (vystavení daňového dokladu k platbě)
112
     * 
113
     * @link https://demo.flexibee.eu/devdoc/odpocet-zaloh Odpočet záloh a ZDD
114
     * @param FakturaVydana $invoice zálohová faktura
115
     * @param array $odpocet Vlastnosti odpočtu
116
     * @return array
117
     */
118
    public function odpocetZalohy($invoice, $odpocet = [])
119
    {
120
        if (!isset($odpocet['castkaMen'])) {
121
            $odpocet['castkaMen'] = $invoice->getDataValue('sumCelkem');
122
        }
123
        $odpocet['doklad'] = $invoice;
124
125
        $this->setDataValue('odpocty-zaloh', ['odpocet' => $odpocet]);
126
        return $this->insertToFlexiBee();
127
    }
128
129
    /**
130
     * Odpočet ZDD
131
     *
132
     * @link https://demo.flexibee.eu/devdoc/odpocet-zaloh Odpočet záloh a ZDD
133
     * @param FakturaVydana $invoice zálohová faktura
134
     * @param array $odpocet Vlastnosti odpočtu
135
     * @return array
136
     */
137
    public function odpocetZDD($invoice, $odpocet = [])
138
    {
139
        if (!isset($odpocet['castkaZaklMen'])) {
140
            $odpocet['castkaZaklMen'] = $invoice->getDataValue('sumZklZakl');
141
        }
142
        if (!isset($odpocet['castkaSnizMen'])) {
143
            $odpocet['castkaSnizMen'] = $invoice->getDataValue('sumZklSniz');
144
        }
145
        if (!isset($odpocet['castkaSniz2Men'])) {
146
            $odpocet['castkaSniz2Men'] = $invoice->getDataValue('sumZklSniz2');
147
        }
148
        if (!isset($odpocet['castkaOsvMen'])) {
149
            $odpocet['castkaOsvMen'] = $invoice->getDataValue('sumOsv');
150
        }
151
        if (!isset($odpocet['id'])) {
152
            $odpocet['id'] = 'ext:odpocet1';
153
        }
154
        $odpocet['doklad'] = $invoice;
155
156
        $this->setDataValue('odpocty-zaloh', ['odpocet' => $odpocet]);
157
        return $this->insertToFlexiBee();
158
    }
159
160
    public function vytvorVazbuZDD($modul = 'banka' /* pokladna */)
161
    {
162
        $headersBackup                            = $this->defaultHttpHeaders;
163
        $this->defaultHttpHeaders['Accept']       = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
164
        $this->defaultHttpHeaders['Content-Type'] = 'application/x-www-form-urlencoded';
165
        $this->setPostFields(['module' => $modul, 'submit' => 'OK']);
0 ignored issues
show
Documentation introduced by
array('module' => $modul, 'submit' => 'OK') is of type array<string,string,{"mo...ng","submit":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
166
        $this->performRequest($this->myKey().'/vytvor-vazbu-zdd/'.$idBanky,
0 ignored issues
show
Bug introduced by
The variable $idBanky does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The method myKey() does not seem to exist on object<FlexiPeeHP\FakturaVydana>.

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...
167
            'POST', 'html');
168
        $this->defaultHttpHeaders                 = $headersBackup;
169
170
        return $this->lastResponseCode == 201;
171
    }
172
}