Newer
Older
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
<?php
/**
* This file contains QUI\ERP\Utils\User
*/
namespace QUI\ERP\Utils;
use QUI;
use QUI\Interfaces\Users\User as UserInterface;
/**
* Class User Utils
*
* @package QUI\ERP\Utils
* @author www.pcsg.de (Henning Leutz)
*/
class User
{
/**
* netto flag
*/
const IS_NETTO_USER = 1;
/**
* brutto flag
*/
const IS_BRUTTO_USER = 2;
/**
* Return the brutto netto status
* is the user a netto or brutto user
*
* @param UserInterface $User
* @return bool
*/
public static function getBruttoNettoUserStatus(UserInterface $User)
{
if (QUI::getUsers()->isSystemUser($User)) {
return self::IS_NETTO_USER;
}
$nettoStatus = $User->getAttribute('quiqqer.erp.isNettoUser');
if (is_numeric($nettoStatus)) {
$nettoStatus = (int)$nettoStatus;
}
switch ($nettoStatus) {
case self::IS_NETTO_USER:
case self::IS_BRUTTO_USER:
return $nettoStatus;
}
$euVatId = $User->getAttribute('quiqqer.erp.euVatId');
$taxId = $User->getAttribute('quiqqer.erp.taxId');
if (!empty($euVatId) || !empty($taxId)) {
return self::IS_NETTO_USER;
}

Henning Leutz
committed
try {
$Package = QUI::getPackage('quiqqer/tax');
} catch (QUI\Exception $Exception) {
return self::IS_BRUTTO_USER;
}
try {
$Config = $Package->getConfig();
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
return self::IS_NETTO_USER;
}
// @todo quiqqer.erp.isNettoUser beachten, die eigenschaft ist besser, gab es damals noch nicht
// verifizierung als unternehm einbauen
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
try {
$Address = self::getUserERPAddress($User);
if (is_object($Address)
&& $Address
&& $Address->getAttribute('company')
) {
if ($Config->getValue('shop', 'companyForceBruttoPrice')) {
return self::IS_BRUTTO_USER;
}
return self::IS_NETTO_USER;
}
if (is_array($Address)
&& isset($Address['company'])
&& $Address['company'] == 1
) {
if ($Config->getValue('shop', 'companyForceBruttoPrice')) {
return self::IS_BRUTTO_USER;
}
return self::IS_NETTO_USER;
}
} catch (QUI\Exception $Exception) {
// no address found
}
$isNetto = $Config->getValue('shop', 'isNetto');
if ($isNetto) {
return self::IS_NETTO_USER;
}
try {
$Tax = QUI\ERP\Tax\Utils::getTaxByUser($User);
if ($Tax->getValue() == 0) {
return self::IS_NETTO_USER;
}
} catch (QUI\Exception $Exception) {
return self::IS_NETTO_USER;
}
return self::IS_BRUTTO_USER;
}
/**
* Is the user a netto user?
*
* @param UserInterface $User
* @return bool
*/
public static function isNettoUser(UserInterface $User)
{
return self::getBruttoNettoUserStatus($User) === self::IS_NETTO_USER;
}
/**
* Return the area of the user
* if user is in no area, the default one of the shop would be used
*
* @param UserInterface $User
* @return bool|QUI\ERP\Areas\Area
*/
public static function getUserArea(UserInterface $User)
{
$Country = $User->getCountry();
$Area = QUI\ERP\Areas\Utils::getAreaByCountry($Country);
if ($Area) {
return $Area;
}
return QUI\ERP\Defaults::getArea();
}
/**
* Return the user ERP address (Rechnungsaddresse, Accounting Address)
*
* @param UserInterface $User
* @return false|QUI\Users\Address
* @throws QUI\Exception
*/
public static function getUserERPAddress(UserInterface $User)
{
if (!QUI::getUsers()->isUser($User)) {
'quiqqer/erp',
'exception.no.user'
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
}
/* @var $User QUI\Users\User */
if (!$User->getAttribute('quiqqer.erp.address')) {
return $User->getStandardAddress();
}
$erpAddress = $User->getAttribute('quiqqer.erp.address');
try {
return $User->getAddress($erpAddress);
} catch (QUI\Exception $Exception) {
}
return $User->getStandardAddress();
}
/**
* Return the area of the shop
*
* @return QUI\ERP\Areas\Area
* @throws QUI\Exception
* @deprecated use QUI\ERP\Defaults::getShopArea()
*/
public static function getShopArea()
{
return QUI\ERP\Defaults::getArea();
}
/**
* Filter unwanted user attributes
* Therefore we can use the attributes in the ERP stack
*
* @param $attributes
* @return array
*/
public static function filterCustomerAttributes($attributes = [])
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
{
if (!is_array($attributes)) {
return [];
}
$needle = [
'uuid',
'id',
'email',
'lang',
'usergroup',
'username',
'active',
'regdate',
'lastvisit',
'lastedit',
'firstname',
'lastname',
'usertitle',
'company',
'birthday',
'avatar',
'quiqqer.erp.euVatId',
'quiqqer.erp.taxId',
'quiqqer.erp.address',
'quiqqer.erp.isNettoUser'
];
$needle = array_flip($needle);
$result = [];
foreach ($attributes as $key => $value) {
if (isset($needle[$key])) {
$result[$key] = $value;
}
}
return $result;
}