1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
tax.php
См. документацию.
1<?php
2
4
6{
7 public static function DoProcessOrderBasket(&$arOrder, $arOptions, &$arErrors)
8 {
9 if ((!array_key_exists("TAX_LOCATION", $arOrder) || intval($arOrder["TAX_LOCATION"]) <= 0) && (!$arOrder["USE_VAT"] || $arOrder["USE_VAT"]!="Y"))
10 return;
11
12 $arOrder["TAX_LOCATION"] = \CSaleLocation::tryTranslateIDToCode($arOrder["TAX_LOCATION"]);
13
14 static::calculateTax($arOrder, $arOptions, $arErrors);
15 }
16
23 public static function calculateTax(&$arOrder, $arOptions, &$arErrors = [])
24 {
25 // don't change `$arOrder["USE_VAT"] != "Y"` comparison, may be values: 1, true, etc
26 if (
27 (!array_key_exists("TAX_LOCATION", $arOrder) || trim((string)$arOrder["TAX_LOCATION"]) === "")
28 && (!$arOrder["USE_VAT"] || $arOrder["USE_VAT"] != "Y")
29 )
30 {
31 return;
32 }
33
34 $arOrder["TAX_PRICE"] = 0.0;
35
36 if (!$arOrder["USE_VAT"])
37 {
38 if (!array_key_exists("TAX_EXEMPT", $arOrder))
39 {
40 $arOrder["TAX_EXEMPT"] = array();
41 $arUserGroups = CUser::GetUserGroup($arOrder["USER_ID"]);
42
43 $dbTaxExemptList = CSaleTax::GetExemptList(array("GROUP_ID" => $arUserGroups));
44 while ($TaxExemptList = $dbTaxExemptList->Fetch())
45 {
46 if (!in_array(intval($TaxExemptList["TAX_ID"]), $arOrder["TAX_EXEMPT"]))
47 $arOrder["TAX_EXEMPT"][] = intval($TaxExemptList["TAX_ID"]);
48 }
49 }
50
51 if (!array_key_exists("TAX_LIST", $arOrder))
52 {
53 $arOrder["TAX_LIST"] = array();
54
55 static $proxyOrderTaxList = array();
56
57 $proxyOrderTaxKey = $arOrder["SITE_ID"]."|".$arOrder["PERSON_TYPE_ID"]."|".$arOrder["TAX_LOCATION"];
58
59 if (isset($proxyOrderTaxList[$proxyOrderTaxKey]) && is_array($proxyOrderTaxList[$proxyOrderTaxKey]))
60 {
61 $arOrder["TAX_LIST"] = $proxyOrderTaxList[$proxyOrderTaxKey];
62 }
63 else
64 {
65 $dbTaxRate = CSaleTaxRate::GetList(
66 array("APPLY_ORDER" => "ASC"),
67 array(
68 "LID" => $arOrder["SITE_ID"],
69 "PERSON_TYPE_ID" => $arOrder["PERSON_TYPE_ID"],
70 "ACTIVE" => "Y",
71 "LOCATION_CODE" => $arOrder["TAX_LOCATION"],
72 )
73 );
74 while ($arTaxRate = $dbTaxRate->GetNext())
75 {
76 if (!in_array(intval($arTaxRate["TAX_ID"]), $arOrder["TAX_EXEMPT"]))
77 {
78 if ($arTaxRate["IS_PERCENT"] != "Y")
79 {
80 $arTaxRate["VALUE"] = \Bitrix\Sale\PriceMaths::roundPrecision(CCurrencyRates::ConvertCurrency($arTaxRate["VALUE"], $arTaxRate["CURRENCY"], $arOrder["CURRENCY"]));
81 $arTaxRate["CURRENCY"] = $arOrder["CURRENCY"];
82 }
83 $arOrder["TAX_LIST"][] = $arTaxRate;
84 }
85 }
86
87 $proxyOrderTaxList[$proxyOrderTaxKey] = $arOrder["TAX_LIST"];
88 }
89 }
90 else
91 {
92 if (!empty($arOrder["TAX_LIST"]) && is_array($arOrder["TAX_LIST"]))
93 {
94 foreach ($arOrder["TAX_LIST"] as &$taxValue)
95 {
96 if (isset($taxValue['VALUE_MONEY']))
97 unset($taxValue['VALUE_MONEY']);
98 }
99 unset($taxValue);
100 }
101 }
102
103 if (!empty($arOrder["TAX_LIST"]))
104 {
105 if (!empty($arOrder["BASKET_ITEMS"]) && is_array($arOrder["BASKET_ITEMS"]))
106 {
107 foreach ($arOrder["BASKET_ITEMS"] as $arItem)
108 {
110 $arItem["PRICE"] * $arItem["QUANTITY"],
111 $arOrder["TAX_LIST"],
112 $arOrder["CURRENCY"]
113 );
114
115 foreach ($arOrder["TAX_LIST"] as &$arTax)
116 {
117 $arTax["VALUE_MONEY"] += $arTax["TAX_VAL"];
118 $arTax["VALUE_MONEY_FORMATED"] = SaleFormatCurrency($arTax["VALUE_MONEY"], $arOrder["CURRENCY"]);
119 }
120 unset($arTax);
121 }
122
123 foreach ($arOrder["TAX_LIST"] as $arTax)
124 {
125 if ($arTax["IS_IN_PRICE"] != "Y"
126 || (!empty($arOptions['ENABLE_INCLUSIVE_TAX']) && $arOptions['ENABLE_INCLUSIVE_TAX'] == "Y"))
127 {
128 $arOrder["TAX_PRICE"] += $arTax["VALUE_MONEY"];
129 }
130 }
131 }
132 else
133 {
134 $arOrder["TAX_LIST"] = array();
135 $arOrder["TAX_PRICE"] = 0;
136 }
137
138
139 }
140 }
141 else
142 {
143 if (!array_key_exists("TAX_LIST", $arOrder))
144 {
145 $arOrder["TAX_LIST"][] = array(
146 "NAME" => GetMessage("SOA_VAT"),
147 "IS_PERCENT" => "Y",
148 "VALUE" => $arOrder["VAT_RATE"] * 100,
149 "VALUE_FORMATED" => "(".($arOrder["VAT_RATE"] * 100)."%, ".GetMessage("SOA_VAT_INCLUDED").")",
150 "VALUE_MONEY" => $arOrder["VAT_SUM"],
151 "VALUE_MONEY_FORMATED" => SaleFormatCurrency($arOrder["VAT_SUM"], $arOrder["CURRENCY"]),
152 "APPLY_ORDER" => 100,
153 "IS_IN_PRICE" => "Y",
154 "CODE" => "VAT",
155 'TAX_VAL' => $arOrder['VAT_SUM'],
156 );
157 }
158 }
159
160 $arOrder["TAX_PRICE"] = \Bitrix\Sale\PriceMaths::roundPrecision($arOrder["TAX_PRICE"]);
161 }
162
163 public static function DoProcessOrderDelivery(&$arOrder, $arOptions, &$arErrors)
164 {
165 if ((!array_key_exists("TAX_LOCATION", $arOrder) || intval($arOrder["TAX_LOCATION"]) <= 0) && (!$arOrder["USE_VAT"] || $arOrder["USE_VAT"]!="Y"))
166 return;
167
168 $arOrder["TAX_LOCATION"] = \CSaleLocation::tryTranslateIDToCode($arOrder["TAX_LOCATION"]);
169
170 static::calculateDeliveryTax($arOrder, $arOptions, $arErrors);
171 }
172
179 public static function calculateDeliveryTax(&$arOrder, $arOptions, &$arErrors = [])
180 {
181 // don't change `$arOrder["USE_VAT"] != "Y"` comparison, may be values: 1, true, etc
182 if (
183 (!array_key_exists("TAX_LOCATION", $arOrder) || trim((string)$arOrder["TAX_LOCATION"]) === "")
184 && (empty($arOrder["USE_VAT"]) || $arOrder["USE_VAT"] != "Y")
185 )
186 {
187 return;
188 }
189
190 if (!array_key_exists("COUNT_DELIVERY_TAX", $arOptions))
191 {
192 $arOptions["COUNT_DELIVERY_TAX"] = COption::GetOptionString("sale", "COUNT_DELIVERY_TAX", "N");
193 }
194
195 if ((double)$arOrder["DELIVERY_PRICE"] <= 0 || $arOptions["COUNT_DELIVERY_TAX"] != "Y")
196 {
197 return;
198 }
199
200 if (!$arOrder["USE_VAT"] || $arOrder["USE_VAT"] != "Y")
201 {
202 if (!array_key_exists("TAX_EXEMPT", $arOrder))
203 {
204 $arUserGroups = CUser::GetUserGroup($arOrder["USER_ID"]);
205
206 $dbTaxExemptList = CSaleTax::GetExemptList(array("GROUP_ID" => $arUserGroups));
207 while ($TaxExemptList = $dbTaxExemptList->Fetch())
208 {
209 if (!in_array(intval($TaxExemptList["TAX_ID"]), $arOrder["TAX_EXEMPT"]))
210 $arOrder["TAX_EXEMPT"][] = intval($TaxExemptList["TAX_ID"]);
211 }
212 }
213
214 if (!array_key_exists("TAX_LIST", $arOrder))
215 {
216 $arOrder["TAX_LIST"] = array();
217
218 $dbTaxRate = CSaleTaxRate::GetList(
219 array("APPLY_ORDER" => "ASC"),
220 array(
221 "LID" => $arOrder["SITE_ID"],
222 "PERSON_TYPE_ID" => $arOrder["PERSON_TYPE_ID"],
223 "ACTIVE" => "Y",
224 "LOCATION_CODE" => $arOrder["TAX_LOCATION"],
225 )
226 );
227 while ($arTaxRate = $dbTaxRate->GetNext())
228 {
229 if (is_array($arOrder["TAX_EXEMPT"]) && !in_array(intval($arTaxRate["TAX_ID"]), $arOrder["TAX_EXEMPT"]))
230 {
231 if ($arTaxRate["IS_PERCENT"] != "Y")
232 {
233 $arTaxRate["VALUE"] = \Bitrix\Sale\PriceMaths::roundPrecision(CurrencyRates::ConvertCurrency($arTaxRate["VALUE"], $arTaxRate["CURRENCY"], $arOrder["CURRENCY"]));
234 $arTaxRate["CURRENCY"] = $arOrder["CURRENCY"];
235 }
236 $arOrder["TAX_LIST"][] = $arTaxRate;
237 }
238 }
239 }
240
241 if (count($arOrder["TAX_LIST"]) > 0)
242 {
244 $arOrder["DELIVERY_PRICE"],
245 $arOrder["TAX_LIST"],
246 $arOrder["CURRENCY"]
247 );
248
249 $arOrder["TAX_PRICE"] = 0;
250 foreach ($arOrder["TAX_LIST"] as &$arTax)
251 {
252 $arTax["VALUE_MONEY"] += \Bitrix\Sale\PriceMaths::roundPrecision($arTax["TAX_VAL"]);
253 $arTax['VALUE_MONEY_FORMATED'] = SaleFormatCurrency($arTax["VALUE_MONEY"], $arOrder["CURRENCY"]);
254
255 if ($arTax["IS_IN_PRICE"] != "Y"
256 || (!empty($arOptions['ENABLE_INCLUSIVE_TAX']) && $arOptions['ENABLE_INCLUSIVE_TAX'] == "Y"))
257 {
258 $arOrder["TAX_PRICE"] += $arTax["VALUE_MONEY"];
259 }
260
261 }
262 unset($arTax);
263
264 }
265 }
266 else
267 {
268
269 $deliveryVat = $arOrder["DELIVERY_PRICE"] * $arOrder["VAT_RATE"] / (1 + $arOrder["VAT_RATE"]);
270
271 $arOrder["VAT_SUM"] += $deliveryVat;
272 $arOrder["VAT_DELIVERY"] += $deliveryVat;
273
274 //if (!array_key_exists("TAX_LIST", $arOrder))
275 //{
276 $arOrder["TAX_LIST"][0] = array(
277 "NAME" => GetMessage("SOA_VAT"),
278 "IS_PERCENT" => "Y",
279 "VALUE" => $arOrder["VAT_RATE"] * 100,
280 "VALUE_FORMATED" => "(".($arOrder["VAT_RATE"] * 100)."%, ".GetMessage("SOA_VAT_INCLUDED").")",
281 "VALUE_MONEY" => $arOrder["VAT_SUM"],
282 "VALUE_MONEY_FORMATED" => SaleFormatCurrency($arOrder["VAT_SUM"], $arOrder["CURRENCY"]),
283 "APPLY_ORDER" => 100,
284 "IS_IN_PRICE" => "Y",
285 "CODE" => "VAT"
286 );
287 //}
288 }
289
290 $arOrder["TAX_PRICE"] = \Bitrix\Sale\PriceMaths::roundPrecision($arOrder["TAX_PRICE"]);
291 $arOrder["VAT_SUM"] = \Bitrix\Sale\PriceMaths::roundPrecision($arOrder["VAT_SUM"]);
292 $arOrder["VAT_DELIVERY"] = \Bitrix\Sale\PriceMaths::roundPrecision($arOrder["VAT_DELIVERY"]);
293
294 }
295
296 public static function DoSaveOrderTax($orderId, $taxList, &$arErrors = [])
297 {
298 $duplicateList = array();
299 $idList = array();
300
302 $orderTaxClass = static::getOrderTaxEntityName();
303 $res = $orderTaxClass::GetList(
304 array('ID' => 'ASC'),
305 array("ORDER_ID" => $orderId),
306 false,
307 false,
308 array("ID", "TAX_NAME", "CODE")
309 );
310 while ($data = $res->Fetch())
311 {
312 $hash = $data["TAX_NAME"]."|".$data["CODE"];
313 if (!array_key_exists($hash, $idList))
314 {
315 $idList[$data["TAX_NAME"]."|".$data["CODE"]] = $data["ID"];
316 }
317 else
318 {
319 $duplicateList[$hash] = $data['ID'];
320 }
321 }
322
323 $isChanged = false;
324
325 if (is_array($taxList))
326 {
327 foreach ($taxList as $itemData)
328 {
329 $fields = array(
330 "ORDER_ID" => $orderId,
331 "TAX_NAME" => $itemData["NAME"],
332 "IS_PERCENT" => $itemData["IS_PERCENT"],
333 "VALUE" => $itemData["VALUE"],
334 "VALUE_MONEY" => $itemData["VALUE_MONEY"],
335 "APPLY_ORDER" => $itemData["APPLY_ORDER"],
336 "IS_IN_PRICE" => $itemData["IS_IN_PRICE"],
337 "CODE" => $itemData["CODE"]
338 );
339
340 $hash = $itemData["NAME"]."|".$itemData["CODE"];
341 $isNew = false;
342
343 if (array_key_exists($hash, $idList))
344 {
346 $orderTaxClass = static::getOrderTaxEntityName();
347 $taxId = $orderTaxClass::Update($idList[$hash], $fields);
348 unset($idList[$hash]);
349 }
350 elseif (!array_key_exists($hash, $duplicateList))
351 {
352 $isNew = true;
354 $orderTaxClass = static::getOrderTaxEntityName();
355 $taxId = $orderTaxClass::Add($fields);
356 }
357
358 if ($orderId > 0)
359 {
361 $historyClass = static::getHistoryEntityName();
362 $historyClass::addLog(
363 'TAX',
364 $orderId,
365 $isNew ? 'TAX_ADD' : 'TAX_UPDATE',
366 $taxId,
367 null,
368 array(
369 "NAME" => $itemData["NAME"],
370 "CODE" => $itemData["CODE"]
371 ),
372 $historyClass::SALE_ORDER_HISTORY_LOG_LEVEL_1
373 );
374
375 $isChanged = true;
376 }
377 }
378 }
379
380 foreach ($idList as $code => $id)
381 {
383 $orderTaxClass = static::getOrderTaxEntityName();
384 $orderTaxClass::Delete($id);
385 if ($orderId > 0)
386 {
388 $historyClass = static::getHistoryEntityName();
389 $historyClass::addLog(
390 'TAX',
391 $orderId,
392 'TAX_DELETED',
393 $id,
394 null,
395 array(),
396 $historyClass::SALE_ORDER_HISTORY_LOG_LEVEL_1
397 );
398 }
399 }
400
401 if (!empty($duplicateList))
402 {
403 foreach ($duplicateList as $hash => $id)
404 {
406 $orderTaxClass = static::getOrderTaxEntityName();
407 $orderTaxClass::Delete($id);
408
409
411 $historyClass = static::getHistoryEntityName();
412 $historyClass::addLog(
413 'TAX',
414 $orderId,
415 'TAX_DUPLICATE_DELETED',
416 $id,
417 null,
418 array(),
419 $historyClass::SALE_ORDER_HISTORY_LOG_LEVEL_1
420 );
421 }
422 }
423
424 if ($isChanged)
425 {
427 $historyClass = static::getHistoryEntityName();
428 $historyClass::addAction(
429 'TAX',
430 $orderId,
431 "TAX_SAVED"
432 );
433 }
434 }
435
436 public static function CheckFields($ACTION, &$arFields)
437 {
438 global $DB;
439
440 if ((is_set($arFields, "LID") || $ACTION=="ADD") && $arFields["LID"] == '')
441 {
442 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGT_EMPTY_SITE"), "ERROR_NO_LID");
443 return false;
444 }
445 if ((is_set($arFields, "NAME") || $ACTION=="ADD") && $arFields["NAME"] == '')
446 {
447 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGT_EMPTY_NAME"), "ERROR_NO_NAME");
448 return false;
449 }
450
451 if (is_set($arFields, "LID"))
452 {
453 $dbSite = CSite::GetByID($arFields["LID"]);
454 if (!$dbSite->Fetch())
455 {
456 $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $arFields["LID"], GetMessage("SKGT_NO_SITE")), "ERROR_NO_SITE");
457 return false;
458 }
459 }
460
461 if ((is_set($arFields, "CODE") || $ACTION=="ADD") && $arFields["CODE"] == '')
462 $arFields["CODE"] = false;
463
464 return true;
465 }
466
467 public static function Update($ID, $arFields)
468 {
469 global $DB;
470 $ID = intval($ID);
471
472 if (!CSaleTax::CheckFields("UPDATE", $arFields)) return false;
473
474 $strUpdate = $DB->PrepareUpdate("b_sale_tax", $arFields);
475 $strSql = "UPDATE b_sale_tax SET ".
476 " TIMESTAMP_X = ".$DB->GetNowFunction().", ".
477 " ".$strUpdate." ".
478 "WHERE ID = ".$ID." ";
479 $DB->Query($strSql);
480
481 return $ID;
482 }
483
484 public static function Delete($ID)
485 {
486 global $DB;
487 $ID = intval($ID);
488
489 $db_taxrates = CSaleTaxRate::GetList(Array(), Array("TAX_ID"=>$ID));
490 while ($ar_taxrates = $db_taxrates->Fetch())
491 {
492 CSaleTaxRate::Delete($ar_taxrates["ID"]);
493 }
494
495 $DB->Query("DELETE FROM b_sale_tax_exempt2group WHERE TAX_ID = ".$ID."", true);
496 return $DB->Query("DELETE FROM b_sale_tax WHERE ID = ".$ID."", true);
497 }
498
499 public static function GetByID($ID)
500 {
501 global $DB;
502
503 $ID = intval($ID);
504 $strSql =
505 "SELECT ID, LID, NAME, CODE, DESCRIPTION, ".$DB->DateToCharFunction("TIMESTAMP_X", "FULL")." as TIMESTAMP_X ".
506 "FROM b_sale_tax ".
507 "WHERE ID = ".$ID."";
508 $db_res = $DB->Query($strSql);
509
510 if ($res = $db_res->Fetch())
511 {
512 return $res;
513 }
514 return False;
515 }
516
517 public static function GetList($arOrder=Array("NAME"=>"ASC"), $arFilter=Array())
518 {
519 global $DB;
520 $arSqlSearch = Array();
521
522 if (!is_array($arFilter))
523 {
524 $filter_keys = [];
525 }
526 else
527 {
528 $filter_keys = array_keys($arFilter);
529 }
530
531 $countFiltersKeys = count($filter_keys);
532 for ($i=0; $i<$countFiltersKeys; $i++)
533 {
534 $val = $DB->ForSql($arFilter[$filter_keys[$i]]);
535 if ($val == '') continue;
536
537 $key = $filter_keys[$i];
538 if ($key[0]=="!")
539 {
540 $key = mb_substr($key, 1);
541 $bInvert = true;
542 }
543 else
544 $bInvert = false;
545
546 switch (mb_strtoupper($key))
547 {
548 case "ID":
549 $arSqlSearch[] = "T.ID ".($bInvert?"<>":"=")." ".intval($val)." ";
550 break;
551 case "LID":
552 $arSqlSearch[] = "T.LID ".($bInvert?"<>":"=")." '".$val."' ";
553 break;
554 case "CODE":
555 $arSqlSearch[] = "T.CODE ".($bInvert?"<>":"=")." '".$val."' ";
556 break;
557 }
558 }
559
560 $strSqlSearch = "";
561 $countSqlSearch = count($arSqlSearch);
562 for($i=0; $i<$countSqlSearch; $i++)
563 {
564 $strSqlSearch .= " AND ";
565 $strSqlSearch .= " (".$arSqlSearch[$i].") ";
566 }
567
568 $strSql =
569 "SELECT T.ID, T.LID, T.NAME, T.CODE, T.DESCRIPTION, ".$DB->DateToCharFunction("T.TIMESTAMP_X", "FULL")." as TIMESTAMP_X ".
570 "FROM b_sale_tax T ".
571 "WHERE 1 = 1 ".
572 " ".$strSqlSearch." ";
573
574 $arSqlOrder = Array();
575 foreach ($arOrder as $by=>$order)
576 {
577 $by = mb_strtoupper($by);
578 $order = mb_strtoupper($order);
579 if ($order!="ASC")
580 $order = "DESC";
581
582 if ($by == "ID") $arSqlOrder[] = " T.ID ".$order." ";
583 elseif ($by == "LID") $arSqlOrder[] = " T.LID ".$order." ";
584 elseif ($by == "CODE") $arSqlOrder[] = " T.CODE ".$order." ";
585 elseif ($by == "TIMESTAMP_X") $arSqlOrder[] = " T.TIMESTAMP_X ".$order." ";
586 else
587 {
588 $arSqlOrder[] = " T.NAME ".$order." ";
589 $by = "NAME";
590 }
591 }
592 $strSqlOrder = "";
593
594 $countSqlOrder = count($arSqlOrder);
595 DelDuplicateSort($arSqlOrder); for ($i=0; $i<$countSqlOrder; $i++)
596 {
597 if ($i==0)
598 $strSqlOrder = " ORDER BY ";
599 else
600 $strSqlOrder .= ",";
601
602 $strSqlOrder .= $arSqlOrder[$i];
603 }
604 $strSql .= $strSqlOrder;
605 $db_res = $DB->Query($strSql);
606 return $db_res;
607 }
608
609 public static function GetExemptList($arFilter = array())
610 {
611 global $DB;
612 $arSqlSearch = Array();
613
614 if (!is_array($arFilter))
615 {
616 $filter_keys = [];
617 }
618 else
619 {
620 $filter_keys = array_keys($arFilter);
621 }
622
623 $countFilterKeys = count($filter_keys);
624 for ($i = 0; $i < $countFilterKeys; $i++)
625 {
626 $vals = $arFilter[$filter_keys[$i]];
627 if (!is_array($vals))
628 $vals = array($vals);
629
630 $key = $filter_keys[$i];
631 if ($key[0]=="!")
632 {
633 $key = mb_substr($key, 1);
634 $bInvert = true;
635 }
636 else
637 $bInvert = false;
638
639 $arSqlSearch_tmp = array();
640
641 $countVals = count($vals);
642 for ($j = 0; $j < $countVals; $j++)
643 {
644 $val = $vals[$j];
645
646 switch (mb_strtoupper($key))
647 {
648 case "GROUP_ID":
649 $arSqlSearch_tmp[] = "TE2G.GROUP_ID ".($bInvert?"<>":"=")." ".intval($val)." ";
650 break;
651 case "TAX_ID":
652 $arSqlSearch_tmp[] = "TE2G.TAX_ID ".($bInvert?"<>":"=")." ".intval($val)." ";
653 break;
654 }
655 }
656
657 $strSqlSearch_tmp = "";
658 $countSqlSearchTmp = count($arSqlSearch_tmp);
659 for ($j = 0; $j < $countSqlSearchTmp; $j++)
660 {
661 if ($j > 0)
662 $strSqlSearch_tmp .= ($bInvert ? " AND " : " OR ");
663 $strSqlSearch_tmp .= "(".$arSqlSearch_tmp[$j].")";
664 }
665
666 if ($strSqlSearch_tmp != "")
667 $arSqlSearch[] = "(".$strSqlSearch_tmp.")";
668 }
669
670 $strSqlSearch = "";
671 $countSqlSearch = count($arSqlSearch);
672 for ($i = 0; $i < $countSqlSearch; $i++)
673 {
674 $strSqlSearch .= " AND ";
675 $strSqlSearch .= " (".$arSqlSearch[$i].") ";
676 }
677
678 $strSql =
679 "SELECT TE2G.GROUP_ID, TE2G.TAX_ID ".
680 "FROM b_sale_tax_exempt2group TE2G ".
681 "WHERE 1 = 1 ".
682 " ".$strSqlSearch." ";
683
684 $db_res = $DB->Query($strSql);
685 return $db_res;
686 }
687
688 public static function AddExempt($arFields)
689 {
690 global $DB;
691
692 $arFields["GROUP_ID"] = intval($arFields["GROUP_ID"]);
693 $arFields["TAX_ID"] = intval($arFields["TAX_ID"]);
694
695 if ($arFields["GROUP_ID"]<=0 || $arFields["TAX_ID"]<=0)
696 return False;
697
698 $strSql =
699 "INSERT INTO b_sale_tax_exempt2group(GROUP_ID, TAX_ID) ".
700 "VALUES(".$arFields["GROUP_ID"].", ".$arFields["TAX_ID"].")";
701 $DB->Query($strSql);
702
703 return True;
704 }
705
706 public static function DeleteExempt($arFields)
707 {
708 global $DB;
709
710 $strSql = "DELETE FROM b_sale_tax_exempt2group WHERE ";
711
712 $arSqlSearch = Array();
713
714 if (!is_array($arFields))
715 return False;
716 else
717 $filter_keys = array_keys($arFields);
718
719 $countFilterKeys = count($filter_keys);
720 for ($i=0; $i<$countFilterKeys; $i++)
721 {
722 $val = $arFields[$filter_keys[$i]];
723 if (intval($val)<=0) continue;
724 $key = $filter_keys[$i];
725 $arSqlSearch[] = " ".$key." = ".intval($val)." ";
726 }
727
728 $countSqlSearch = count($arSqlSearch);
729 if ($countSqlSearch<=0)
730 return False;
731
732 $strSqlSearch = "";
733
734 for ($i=0; $i<$countSqlSearch; $i++)
735 {
736 if ($i==0) $strSqlSearch .= " ";
737 else $strSqlSearch .= " AND ";
738 $strSqlSearch .= " (".$arSqlSearch[$i].") ";
739 }
740
741 $strSql .= $strSqlSearch;
742
743 return $DB->Query($strSql, true);
744 }
745
749 protected static function getOrderTaxEntityName()
750 {
751 return CSaleOrderTax::class;
752 }
753
757 protected static function getHistoryEntityName()
758 {
759 return \Bitrix\Sale\OrderHistory::class;
760 }
761}
$hash
Определения ajax_redirector.php:8
$db_res
Определения options_user_settings.php:8
static roundPrecision($value)
Определения pricemaths.php:16
static ConvertCurrency($valSum, $curFrom, $curTo, $valDate="")
Определения currency_rate.php:393
static tryTranslateIDToCode($id)
Определения location.php:281
static CountTaxes($Price, &$arTaxList, $DefCurrency)
Определения order_tax.php:124
Определения tax.php:6
static AddExempt($arFields)
Определения tax.php:688
static GetList($arOrder=Array("NAME"=>"ASC"), $arFilter=Array())
Определения tax.php:517
static GetExemptList($arFilter=array())
Определения tax.php:609
static Delete($ID)
Определения tax.php:484
static GetByID($ID)
Определения tax.php:499
static calculateDeliveryTax(&$arOrder, $arOptions, &$arErrors=[])
Определения tax.php:179
static DoProcessOrderDelivery(&$arOrder, $arOptions, &$arErrors)
Определения tax.php:163
static CheckFields($ACTION, &$arFields)
Определения tax.php:436
static calculateTax(&$arOrder, $arOptions, &$arErrors=[])
Определения tax.php:23
static getOrderTaxEntityName()
Определения tax.php:749
static DeleteExempt($arFields)
Определения tax.php:706
static getHistoryEntityName()
Определения tax.php:757
static Update($ID, $arFields)
Определения tax.php:467
static DoProcessOrderBasket(&$arOrder, $arOptions, &$arErrors)
Определения tax.php:7
static Delete($ID)
Определения tax_rate.php:127
static GetList($arOrder=array("APPLY_ORDER"=>"ASC"), $arFilter=array())
Определения tax_rate.php:29
$arFields
Определения dblapprove.php:5
$data['IS_AVAILABLE']
Определения .description.php:13
$orderId
Определения payment.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
if($ajaxMode) $ID
Определения get_user.php:27
global $DB
Определения cron_frame.php:29
$ACTION
Определения csv_new_setup.php:27
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$arOptions
Определения structure.php:223
DelDuplicateSort(&$arSort)
Определения tools.php:2055
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
is_set($a, $k=false)
Определения tools.php:2133
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$order
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$i
Определения factura.php:643
</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
SaleFormatCurrency($fSum, $strCurrency, $OnlyValue=false, $withoutFormat=false)
Определения include.php:142
$val
Определения options.php:1793
$GLOBALS['_____370096793']
Определения update_client.php:1
$arFilter
Определения user_search.php:106
$fields
Определения yandex_run.php:501