1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
order_tax.php
См. документацию.
1<?php
2
4
6{
7 public static function CheckFields($ACTION, &$arFields)
8 {
9 global $DB;
10
11 if ((is_set($arFields, "ORDER_ID") || $ACTION=="ADD") && intval($arFields["ORDER_ID"])<=0)
12 {
13 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGOT_EMPTY_ORDER_ID"), "ERROR_NO_ORDER_ID");
14 return false;
15 }
16 if ((is_set($arFields, "TAX_NAME") || $ACTION=="ADD") && $arFields["TAX_NAME"] == '')
17 {
18 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGOT_EMPTY_TAX_NAME"), "ERROR_NO_TAX_NAME");
19 return false;
20 }
21 if ((is_set($arFields, "IS_PERCENT") || $ACTION=="ADD") && $arFields["IS_PERCENT"]!="Y" && $arFields["IS_PERCENT"]!="N")
22 {
23 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGOT_EMPTY_TAX_VALUE"), "ERROR_NO_IS_PERCENT");
24 return false;
25 }
26 if ((is_set($arFields, "IS_IN_PRICE") || $ACTION=="ADD") && $arFields["IS_IN_PRICE"]!="Y" && $arFields["IS_IN_PRICE"]!="N")
27 {
28 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGOT_EMPTY_IN_PRICE"), "ERROR_NO_IS_IN_PRICE");
29 return false;
30 }
31
32 if (is_set($arFields, "VALUE") || $ACTION=="ADD")
33 {
34 $arFields["VALUE"] = str_replace(",", ".", $arFields["VALUE"]);
35 $arFields["VALUE"] = DoubleVal($arFields["VALUE"]);
36 if ($arFields["VALUE"] <= 0)
37 {
38 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGOT_EMPTY_SUM"), "ERROR_NO_VALUE");
39 return false;
40 }
41 }
42 if (is_set($arFields, "VALUE_MONEY") || $ACTION=="ADD")
43 {
44 $arFields["VALUE_MONEY"] = str_replace(",", ".", $arFields["VALUE_MONEY"]);
45 $arFields["VALUE_MONEY"] = DoubleVal($arFields["VALUE_MONEY"]);
46 }
47 if ((is_set($arFields, "VALUE_MONEY") || $ACTION=="ADD") && $arFields["VALUE_MONEY"]<=0)
48 {
49 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGOT_EMPTY_SUM_MONEY"), "ERROR_NO_VALUE_MONEY");
50 return false;
51 }
52
53 if (is_set($arFields, "ORDER_ID"))
54 {
55 if (!static::isOrderExists($arFields["ORDER_ID"]))
56 {
57 $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $arFields["ORDER_ID"], GetMessage("SKGOT_NO_ORDER")), "ERROR_NO_ORDER");
58 return false;
59 }
60 }
61
62 if ((is_set($arFields, "CODE") || $ACTION=="ADD") && $arFields["CODE"] == '')
63 $arFields["CODE"] = false;
64
65 return true;
66 }
67
68 protected static function isOrderExists($id)
69 {
70 return !empty(CSaleOrder::GetByID($id));
71 }
72
73 public static function Update($ID, $arFields)
74 {
75 global $DB;
76 $ID = intval($ID);
77
78 if (!static::CheckFields("UPDATE", $arFields)) return false;
79
80 $strUpdate = $DB->PrepareUpdate(static::getTableName(), $arFields);
81 $strSql = "UPDATE ".static::getTableName()." SET ".
82 " ".$strUpdate." ".
83 "WHERE ID = ".$ID." ";
84 $DB->Query($strSql);
85
86 return $ID;
87 }
88
89 public static function Delete($ID)
90 {
91 global $DB;
92 $ID = intval($ID);
93 return $DB->Query("DELETE FROM ".static::getTableName()." WHERE ID = ".$ID."", true);
94 }
95
96 public static function DeleteEx($ORDER_ID)
97 {
98 global $DB;
99 $ORDER_ID = intval($ORDER_ID);
100 return $DB->Query("DELETE FROM ".static::getTableName()." WHERE ORDER_ID = ".$ORDER_ID."", true);
101 }
102
103 public static function GetByID($ID)
104 {
105 global $DB;
106
107 $ID = intval($ID);
108 $strSql =
109 "SELECT ID, ORDER_ID, TAX_NAME, VALUE, VALUE_MONEY, APPLY_ORDER, CODE, IS_PERCENT, IS_IN_PRICE ".
110 "FROM ".static::getTableName()." ".
111 "WHERE ID = ".$ID."";
112 $db_res = $DB->Query($strSql);
113
114 if ($res = $db_res->Fetch())
115 {
116 return $res;
117 }
118 return False;
119 }
120
121 // The function does not handle fixed-rate taxes. Only with interest!
122 // any tax returns for the price
123 // the second argument ($ arTaxList [] ["TAX_VAL"]) returns the value of the tax for that price
124 public static function CountTaxes($Price, &$arTaxList, $DefCurrency)
125 {
126 //1. Untwist stack tax included in the price for the determination of the initial price
127 $part_sum = 0.00;
128 $tax_koeff = 1.00;
129 $minus = 0.00;
130 $cnt = count($arTaxList);
131 for ($i = 0; $i < $cnt; $i++)
132 {
133 if ($i == 0)
134 $prevOrder = intval($arTaxList[$i]["APPLY_ORDER"]);
135
136 if ($prevOrder != intval($arTaxList[$i]["APPLY_ORDER"]))
137 {
138 $tax_koeff += $part_sum;
139 $part_sum = 0.00;
140 $prevOrder = intval($arTaxList[$i]["APPLY_ORDER"]);
141 }
142
143 $val = $tax_koeff * DoubleVal($arTaxList[$i]["VALUE"]) / 100.00;
144 $part_sum += $val;
145
146 if ($arTaxList[$i]["IS_IN_PRICE"] != "Y")
147 $minus += $val;
148 }
149 $tax_koeff += $part_sum;
150 $item_price = $Price/($tax_koeff-$minus);
151
152 //2. collect taxes
153 $part_sum = 0.00;
154 $tax_koeff = 1.00;
155 $plus = 0.00;
156 $total_tax = 0.00;
157 $cnt = count($arTaxList);
158 for ($i = 0; $i < $cnt; $i++)
159 {
160 if ($i==0)
161 $prevOrder = intval($arTaxList[$i]["APPLY_ORDER"]);
162
163 if ($prevOrder <> intval($arTaxList[$i]["APPLY_ORDER"]))
164 {
165 $tax_koeff += $part_sum;
166 $part_sum = 0.00;
167 $prevOrder = intval($arTaxList[$i]["APPLY_ORDER"]);
168 }
169
170 $val = $tax_koeff * DoubleVal($arTaxList[$i]["VALUE"]) / 100.00;
171 $tax_val = $val*$item_price;
172 $part_sum += $val;
173 $total_tax += $tax_val;
174
175 $arTaxList[$i]["TAX_VAL"] = $tax_val;
176 }
177 return $total_tax;
178 }
179
183 protected static function getTableName()
184 {
185 return 'b_sale_order_tax';
186 }
187}
$db_res
Определения options_user_settings.php:8
Определения order_tax.php:6
static Delete($ID)
Определения order_tax.php:89
static GetByID($ID)
Определения order_tax.php:103
static CheckFields($ACTION, &$arFields)
Определения order_tax.php:7
static DeleteEx($ORDER_ID)
Определения order_tax.php:96
static isOrderExists($id)
Определения order_tax.php:68
static CountTaxes($Price, &$arTaxList, $DefCurrency)
Определения order_tax.php:124
static Update($ID, $arFields)
Определения order_tax.php:73
static getTableName()
Определения order_tax.php:183
$arFields
Определения dblapprove.php:5
$res
Определения filter_act.php:7
if($ajaxMode) $ID
Определения get_user.php:27
global $DB
Определения cron_frame.php:29
$ACTION
Определения csv_new_setup.php:27
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
is_set($a, $k=false)
Определения tools.php:2133
GetMessage($name, $aReplace=null)
Определения tools.php:3397
for( $i=0, $max=count( $arBasketIDs);$i< $max;$i++) if($arOrder['DELIVERY_VAT_RATE'] > 0) if(is_array( $arBasketOrder) &&!empty( $arBasketOrder)) if(floatval($arOrder["DISCOUNT_VALUE"]) > 0) $arTaxList
Определения factura.php:640
$i
Определения factura.php:643
$item_price
Определения factura.php:672
</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
$ORDER_ID
Определения html.php:2
$val
Определения options.php:1793
$GLOBALS['_____370096793']
Определения update_client.php:1