RadaPokladniPohyb::incrementNextRecordCode()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 19
c 0
b 0
f 0
rs 9.8666
ccs 0
cts 14
cp 0
cc 3
nc 4
nop 1
crap 12
1
<?php
2
/**
3
 * FlexiPeeHP - Objekt řady pokladního pohybu.
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
 * Číselná řada pokladního pohybu
13
 */
14
class RadaPokladniPohyb extends FlexiBeeRW
15
{
16
    /**
17
     * Evidence užitá objektem.
18
     *
19
     * @var string
20
     */
21
    public $evidence = 'rada-pokladni-pohyb';
22
23
    /**
24
     * Obtain code for new Record
25
     *
26
     * @param string $code
27
     * @return string
28
     */
29
    public function getNextRecordCode($code = null)
30
    {
31
        if (is_null($code)) {
32
            $code = $this->getMyKey();
33
        }
34
        $crID = null;
35
        if (is_string($code)) {
36
            $sro = $this->performRequest($this->evidence.'/(kod=\''.$code.'\').json');
37
            if (count($sro[$this->evidence])) {
38
                $crID = current(current($sro[$this->evidence]));
39
            }
40
        } else {
41
            $crID = $code;
42
        }
43
44
        $cr                = $this->performRequest($this->evidence.'/'.$crID.'.json');
45
        $radaPokladniPohyb = current($cr[$this->evidence]);
46
        $crInfo            = end($radaPokladniPohyb['polozkyRady']);
47
48
        $cislo = $crInfo['cisAkt'] + 1;
49
        if ($crInfo['zobrazNuly'] == 'true') {
50
            return $crInfo['prefix'].sprintf('%\'.0'.$crInfo['cisDelka'].'d',
51
                    $cislo).'/'.date('y');
52
        } else {
53
            return $crInfo['prefix'].$cislo.'/'.date('y');
54
        }
55
    }
56
57
    /**
58
     * Zvedne číslo dokladu
59
     *
60
     * @param string $code
61
     * @return int číslo nového dokladu
62
     */
63
    public function incrementNextRecordCode($code = null)
64
    {
65
        if (is_null($code)) {
66
            $code = $this->getMyKey();
67
        }
68
69
        if (is_string($code)) {
70
            $sro  = $this->performRequest($this->evidence.'/(kod=\''.$code.'\').json');
71
            $crID = current(current($sro[$this->evidence]));
72
        } else {
73
            $crID = $code;
74
        }
75
76
        $cr                = $this->performRequest($this->evidence.'/'.$crID.'.json');
77
        $radaPokladniPohyb = current($cr[$this->evidence]);
78
        $crInfo            = end($radaPokladniPohyb['polozkyRady']);
79
80
        $cislo = $crInfo['cisAkt'] + 1;
81
        return $cislo;
82
    }
83
}
84