1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
tax_rate.php
См. документацию.
1
<?php
2
3
IncludeModuleLangFile
(__FILE__);
4
5
use Bitrix\Sale\Location\Admin\LocationHelper as Helper;
6
use
Bitrix\Main\DB
;
7
8
class
CAllSaleTaxRate
9
{
10
const
CONN_ENTITY_NAME
=
'Bitrix\Sale\Tax\RateLocation'
;
11
12
public
static
function
CheckFields
(
$ACTION
, &
$arFields
)
13
{
14
global
$DB
;
15
16
if
((
is_set
(
$arFields
,
"TAX_ID"
) ||
$ACTION
==
"ADD"
) && intval(
$arFields
[
"TAX_ID"
])<=0)
17
{
18
$GLOBALS
[
"APPLICATION"
]->ThrowException(
GetMessage
(
"SKGTR_EMPTY_TAX_ID"
),
"ERROR_NO_TAX_ID"
);
19
return
false
;
20
}
21
22
if
((
is_set
(
$arFields
,
"PERSON_TYPE_ID"
) ||
$ACTION
==
"ADD"
) && intval(
$arFields
[
"PERSON_TYPE_ID"
])<=0)
23
$arFields
[
"PERSON_TYPE_ID"
] =
false
;
24
25
if
(
is_set
(
$arFields
,
"VALUE"
) ||
$ACTION
==
"ADD"
)
26
{
27
$arFields
[
"VALUE"
] = str_replace(
","
,
"."
,
$arFields
[
"VALUE"
]);
28
$arFields
[
"VALUE"
] = DoubleVal(
$arFields
[
"VALUE"
]);
29
}
30
31
if
((
is_set
(
$arFields
,
"IS_PERCENT"
) ||
$ACTION
==
"ADD"
) && (
$arFields
[
"IS_PERCENT"
]!=
"N"
))
32
$arFields
[
"IS_PERCENT"
] =
"Y"
;
33
34
if
(
$arFields
[
"IS_PERCENT"
] ==
"Y"
)
35
{
36
$arFields
[
"CURRENCY"
] =
false
;
37
}
38
elseif
(
$arFields
[
"IS_PERCENT"
] ==
"N"
&& (!
is_set
(
$arFields
,
"CURRENCY"
) ||
$arFields
[
"CURRENCY"
] ==
''
))
39
{
40
return
False;
41
}
42
elseif
(!
is_set
(
$arFields
,
"IS_PERCENT"
) && (
is_set
(
$arFields
,
"CURRENCY"
) &&
$arFields
[
"CURRENCY"
]!==
false
))
43
{
44
return
False;
45
}
46
47
if
(
is_set
(
$arFields
,
"TAX_ID"
))
48
{
49
if
(!($arTax =
CSaleTax::GetByID
(
$arFields
[
"TAX_ID"
])))
50
{
51
$GLOBALS
[
"APPLICATION"
]->ThrowException(str_replace(
"#ID#"
,
$arFields
[
"TAX_ID"
],
GetMessage
(
"SKGTR_NO_TAX"
)),
"ERROR_NO_TAX"
);
52
return
false
;
53
}
54
}
55
56
if
(
is_set
(
$arFields
,
"PERSON_TYPE_ID"
) &&
$arFields
[
"PERSON_TYPE_ID"
] !==
false
)
57
{
58
if
(!\
Bitrix
\Sale\Internals\PersonTypeTable::getRowById(
$arFields
[
"PERSON_TYPE_ID"
]))
59
{
60
$GLOBALS
[
"APPLICATION"
]->ThrowException(str_replace(
"#ID#"
,
$arFields
[
"PERSON_TYPE_ID"
],
GetMessage
(
"SKGTR_NO_PERS_TYPE"
)),
"ERROR_NO_PERSON_TYPE"
);
61
return
false
;
62
}
63
}
64
65
if
((
is_set
(
$arFields
,
"IS_IN_PRICE"
) ||
$ACTION
==
"ADD"
) && (
$arFields
[
"IS_IN_PRICE"
]!=
"Y"
))
66
$arFields
[
"IS_IN_PRICE"
] =
"N"
;
67
if
((
is_set
(
$arFields
,
"ACTIVE"
) ||
$ACTION
==
"ADD"
) && (
$arFields
[
"ACTIVE"
]!=
"N"
))
68
$arFields
[
"ACTIVE"
] =
"Y"
;
69
if
((
is_set
(
$arFields
,
"APPLY_ORDER"
) ||
$ACTION
==
"ADD"
) && intval(
$arFields
[
"APPLY_ORDER"
])<=0)
70
$arFields
[
"APPLY_ORDER"
] =
"100"
;
71
72
return
true
;
73
}
74
75
public
static
function
SetTaxRateLocation
(
$ID
,
$arFields
,
$arOptions
=
array
())
76
{
77
if
(
CSaleLocation::isLocationProMigrated
())
78
{
79
Helper::resetLocationsForEntity(
$ID
,
$arFields
, self::CONN_ENTITY_NAME, !!
$arOptions
[
'EXPECT_LOCATION_CODES'
]);
80
}
81
else
82
{
83
global
$DB
;
84
$ID
= intval(
$ID
);
85
if
(0 >=
$ID
)
86
return
;
87
88
$DB
->Query(
"DELETE FROM b_sale_tax2location WHERE TAX_RATE_ID = "
.
$ID
);
89
if
(is_array(
$arFields
))
90
{
91
$countField =
count
(
$arFields
);
92
for
(
$i
= 0;
$i
< $countField;
$i
++)
93
{
94
$arFields
[
$i
][
"LOCATION_ID"
] = intval(
$arFields
[
$i
][
"LOCATION_ID"
]);
95
if
(
$arFields
[
$i
][
"LOCATION_TYPE"
]!=
"G"
)
$arFields
[
$i
][
"LOCATION_TYPE"
] =
"L"
;
96
if
(
$arFields
[
$i
][
"LOCATION_ID"
]>0)
97
{
98
$strSql =
99
"INSERT INTO b_sale_tax2location(TAX_RATE_ID, LOCATION_CODE, LOCATION_TYPE) "
.
100
"VALUES("
.$ID.
", "
.
$arFields
[
$i
][
"LOCATION_ID"
].
", '"
.
$arFields
[
$i
][
"LOCATION_TYPE"
].
"')"
;
101
$DB
->Query($strSql);
102
}
103
}
104
}
105
}
106
}
107
108
public
static
function
Update
(
$ID
,
$arFields
,
$arOptions
=
array
())
109
{
110
global
$DB
;
111
$ID
= intval(
$ID
);
112
if
(0 >=
$ID
)
113
return
false
;
114
115
if
(!
CSaleTaxRate::CheckFields
(
"UPDATE"
,
$arFields
))
return
false
;
116
117
$strUpdate =
$DB
->PrepareUpdate(
"b_sale_tax_rate"
,
$arFields
);
118
$strSql =
"UPDATE b_sale_tax_rate SET TIMESTAMP_X = "
.$DB->GetNowFunction().
", "
.$strUpdate.
" WHERE ID = "
.
$ID
;
119
$DB
->Query($strSql);
120
121
if
(array_key_exists(
"TAX_LOCATION"
,
$arFields
))
122
CSaleTaxRate::SetTaxRateLocation
(
$ID
,
$arFields
[
"TAX_LOCATION"
],
$arOptions
);
123
124
return
$ID
;
125
}
126
127
public
static
function
Delete
(
$ID
)
128
{
129
global
$DB
;
130
$ID
= intval(
$ID
);
131
if
(0 >=
$ID
)
132
return
false
;
133
$DB
->Query(
"DELETE FROM b_sale_tax2location WHERE TAX_RATE_ID = "
.
$ID
,
true
);
134
return
$DB
->Query(
"DELETE FROM b_sale_tax_rate WHERE ID = "
.
$ID
,
true
);
135
}
136
137
public
static
function
GetByID
(
$ID
)
138
{
139
global
$DB
;
140
141
$ID
= intval(
$ID
);
142
if
(0 >=
$ID
)
143
return
false
;
144
145
$strSql =
146
"SELECT ID, TAX_ID, PERSON_TYPE_ID, VALUE, CURRENCY, IS_PERCENT, IS_IN_PRICE, APPLY_ORDER, "
.$DB->DateToCharFunction(
"TIMESTAMP_X"
,
"FULL"
).
" as TIMESTAMP_X, ACTIVE "
.
147
"FROM b_sale_tax_rate WHERE ID = "
.$ID;
148
$db_res
=
$DB
->Query($strSql);
149
150
if
(
$res
=
$db_res
->Fetch())
151
{
152
return
$res
;
153
}
154
return
false
;
155
}
156
163
public
static
function
GetLocationList
(
$arFilter
=Array())
164
{
165
if
(
CSaleLocation::isLocationProMigrated
())
166
{
167
try
168
{
169
return
CSaleLocation::getDenormalizedLocationList
(self::CONN_ENTITY_NAME,
$arFilter
);
170
}
171
catch
(
Exception
$e)
172
{
173
return
new
DB\ArrayResult
(
array
());
174
}
175
}
176
else
177
{
178
global
$DB
;
179
$arSqlSearch = Array();
180
181
if
(!is_array(
$arFilter
))
182
$filter_keys = Array();
183
else
184
$filter_keys = array_keys(
$arFilter
);
185
186
$countFilterKey =
count
($filter_keys);
187
for
(
$i
=0;
$i
< $countFilterKey;
$i
++)
188
{
189
$val
=
$DB
->ForSql(
$arFilter
[$filter_keys[
$i
]]);
190
if
(
$val
==
''
)
continue
;
191
192
$key
= $filter_keys[
$i
];
193
if
(
$key
[0]==
"!"
)
194
{
195
$key
= mb_substr(
$key
, 1);
196
$bInvert =
true
;
197
}
198
else
199
$bInvert =
false
;
200
201
switch
(mb_strtoupper(
$key
))
202
{
203
case
"TAX_RATE_ID"
:
204
$arSqlSearch[] =
"TR2L.TAX_RATE_ID "
.($bInvert?
"<>"
:
"="
).
" "
.intval(
$val
).
" "
;
205
break
;
206
case
"LOCATION_ID"
:
207
$arSqlSearch[] =
"TR2L.LOCATION_CODE "
.($bInvert?
"<>"
:
"="
).
" "
.intval(
$val
).
" "
;
208
break
;
209
case
"LOCATION_TYPE"
:
210
$arSqlSearch[] =
"TR2L.LOCATION_TYPE "
.($bInvert?
"<>"
:
"="
).
" '"
.
$val
.
"' "
;
211
break
;
212
}
213
}
214
215
$strSqlSearch =
""
;
216
$countSqlSearch =
count
($arSqlSearch);
217
for
(
$i
=0;
$i
< $countSqlSearch;
$i
++)
218
{
219
$strSqlSearch .=
" AND "
;
220
$strSqlSearch .=
" ("
.$arSqlSearch[
$i
].
") "
;
221
}
222
223
$strSql =
224
"SELECT TR2L.TAX_RATE_ID, TR2L.LOCATION_CODE as LOCATION_ID, TR2L.LOCATION_TYPE "
.
225
"FROM b_sale_tax2location TR2L "
.
226
"WHERE 1 = 1 "
.
227
" "
.$strSqlSearch.
" "
;
228
229
$strSql .= $strSqlOrder;
230
$db_res
=
$DB
->Query($strSql);
231
return
$db_res
;
232
233
}
234
}
235
}
$db_res
$db_res
Определения
options_user_settings.php:8
Bitrix\Main\DB\ArrayResult
Определения
arrayresult.php:10
CAllSaleLocation\isLocationProMigrated
static isLocationProMigrated()
Определения
location.php:58
CAllSaleLocation\getDenormalizedLocationList
static getDenormalizedLocationList($entityName, $arFilter=array())
Определения
location.php:745
CAllSaleTax\GetByID
static GetByID($ID)
Определения
tax.php:499
CAllSaleTaxRate
Определения
tax_rate.php:9
CAllSaleTaxRate\Delete
static Delete($ID)
Определения
tax_rate.php:127
CAllSaleTaxRate\Update
static Update($ID, $arFields, $arOptions=array())
Определения
tax_rate.php:108
CAllSaleTaxRate\GetByID
static GetByID($ID)
Определения
tax_rate.php:137
CAllSaleTaxRate\GetLocationList
static GetLocationList($arFilter=Array())
Определения
tax_rate.php:163
CAllSaleTaxRate\CONN_ENTITY_NAME
const CONN_ENTITY_NAME
Определения
tax_rate.php:10
CAllSaleTaxRate\CheckFields
static CheckFields($ACTION, &$arFields)
Определения
tax_rate.php:12
CAllSaleTaxRate\SetTaxRateLocation
static SetTaxRateLocation($ID, $arFields, $arOptions=array())
Определения
tax_rate.php:75
$arFields
$arFields
Определения
dblapprove.php:5
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$res
$res
Определения
filter_act.php:7
$ID
if($ajaxMode) $ID
Определения
get_user.php:27
$DB
global $DB
Определения
cron_frame.php:29
$ACTION
$ACTION
Определения
csv_new_setup.php:27
$arOptions
$arOptions
Определения
structure.php:223
IncludeModuleLangFile
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения
tools.php:3778
is_set
is_set($a, $k=false)
Определения
tools.php:2133
GetMessage
GetMessage($name, $aReplace=null)
Определения
tools.php:3397
Bitrix\Main\DB
Определения
arrayresult.php:2
Bitrix\Main\DI\Exception
Определения
circulardependencyexception.php:3
Bitrix\Main\$GLOBALS
$GLOBALS['____1690880296']
Определения
license.php:1
Bitrix
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$key
if(empty($signedUserToken)) $key
Определения
quickway.php:257
$i
$i
Определения
factura.php:643
count
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения
waybill.php:936
$val
$val
Определения
options.php:1793
$arFilter
$arFilter
Определения
user_search.php:106
bitrix
modules
sale
general
tax_rate.php
Создано системой
1.14.0