-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsubItems.php
More file actions
86 lines (75 loc) · 1.87 KB
/
subItems.php
File metadata and controls
86 lines (75 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
declare(strict_types=1);
/**
* This file is part of the SpojeNet\AbraFlexi package.
*
* (c) 2019-2024 SpojeNet s.r.o. <http://spoje.net/>
* (c) 2025 SpojeNetIT s.r.o. <http://spojenet.cz/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace AbraFlexi;
/**
* Document SubItems functions.
*
* @author vitex
*
* @no-named-arguments
*/
trait subItems
{
/**
* Subitems - ex. items of invoice.
*
* @return array<mixed> of document items or null
*/
public function getSubItems()
{
return $this->getDataValue($this->getSubmenuName());
}
/**
* @param array<mixed> $subitems
* @return bool
*/
public function setSubitems(array $subitems)
{
return $this->setDataValue($this->getSubmenuName(), $subitems);
}
/**
* Name for SubItem branch.
*
* @return string
*/
public function getSubMenuName()
{
return \array_key_exists('polozkyFaktury', $this->getData()) ? 'polozkyFaktury'
: (\array_key_exists('polozkyDokladu', $this->getData()) ? 'polozkyDokladu'
: null);
}
/**
* SubItem object.
*
* @return array<int, string>
*/
public function getSubObjects()
{
$subEvidence = $this->getEvidence().'-polozka';
$subClass = str_replace(
' ',
'',
ucwords(str_replace('-', ' ', $subEvidence)),
);
if (class_exists($subClass) === false) {
$subClass = 'RW';
}
$subObjects = [];
foreach ($this->getSubItems() as $subItemData) {
$subObjects[$subItemData['id']] = new $subClass(
$subItemData,
['evidence' => $subEvidence],
);
}
return $subObjects;
}
}