Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
orderstatus.php
1<?php
2
4
11
12Loc::loadMessages(__FILE__);
13
15{
16 public static function getEdit(Order $order, \CUser $user, $showCancel, $showSaveButton)
17 {
18 $registry = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER);
20 $orderClass = $registry->getOrderClassName();
21
22 $data = self::prepareData($order);
23 $orderLocked = $orderClass::isLocked($order->getId());
24
25 $allowCancel = false;
26
27 if($showCancel)
28 {
30 $orderStatusClass = $registry->getOrderStatusClassName();
31
32 $allowedStatusesCancel = $orderStatusClass::getStatusesUserCanDoOperations($user->GetID(), array('cancel'));
33 if (is_array($allowedStatusesCancel))
34 {
35 $allowCancel = in_array($order->getField("STATUS_ID"), $allowedStatusesCancel);
36 }
37 }
38
39 $orderSiteId = $order->getSiteId();
40 $result = '
41 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table">
42 <tbody>
43 <tr>
44 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage("SALE_ORDER_STATUS_CREATED").':</td>
45 <td class="adm-detail-content-cell-r">
46 <div>'.
47 $data["DATE_INSERT"].
48 '&nbsp;'.static::renderCreatorLink($data).'
49 </div>
50 </td>
51 </tr>
52 <tr>
53 <td class="adm-detail-content-cell-l">'.Loc::getMessage("SALE_ORDER_STATUS_LAST_MODIF").':</td>
54 <td class="adm-detail-content-cell-r"><div>'. $data["DATE_UPDATE"].'</div></td>
55 </tr>
56 <tr>
57 <td class="adm-detail-content-cell-l">'.Loc::getMessage("SALE_ORDER_STATUS_SITE").':</td>
58 <td class="adm-detail-content-cell-r"><div>'.
59 htmlspecialcharsbx(
60 \Bitrix\Sale\Helpers\Admin\OrderEdit::getSiteName($orderSiteId)
61 ).
62 '</div></td>
63 </tr>';
64
65 if(!empty($data["AFFILIATE_NAME"]))
66 {
67 $data['AFFILIATE_NAME'] = htmlspecialcharsbx($data["AFFILIATE_NAME"]);
68
69 if(intval($data['AFFILIATE_ID']) > 0)
70 {
71 $data["AFFILIATE_NAME"] = '<a href="/bitrix/admin/sale_affiliate_edit.php?lang='.LANGUAGE_ID.'&ID='.$data['AFFILIATE_ID'].'">'.
72 $data["AFFILIATE_NAME"].
73 '</a>';
74 }
75
76 $result .= '
77 <tr>
78 <td class="adm-detail-content-cell-l">'.Loc::getMessage("SALE_ORDER_STATUS_AFFILIATE").':</td>
79 <td class="adm-detail-content-cell-r"><div>'.$data["AFFILIATE_NAME"].'</div></td>
80 </tr>';
81 }
82
83 if($data['SOURCE_NAME'] <> '')
84 {
85 $result .= '<tr>'.
86 '<td class="adm-detail-content-cell-l">'.Loc::getMessage("SALE_ORDER_STATUS_SOURCE").':</td>'.
87 '<td class="adm-detail-content-cell-r">'.htmlspecialcharsbx($data['SOURCE_NAME']).'</td>'.
88 '</tr>';
89 }
90
91 $attr = array(
92 "class" => "adm-bus-select",
93 "id" => "STATUS_ID"
94 );
95
96 if($orderLocked)
97 $attr["disabled"] = "disabled";
98
99 $result .= '<tr>
100 <td class="adm-detail-content-cell-l">'.Loc::getMessage("SALE_ORDER_STATUS").':</td>
101 <td class="adm-detail-content-cell-r">'.
102 \Bitrix\Sale\Helpers\Admin\OrderEdit::makeSelectHtml(
103 "STATUS_ID",
104 self::getStatusesList($user->GetID(), $data["STATUS_ID"]),
105 $data["STATUS_ID"],
106 false,
107 $attr
108 );
109
110 if($showSaveButton && !$orderLocked)
111 {
112 $result .= '
113 &nbsp;
114 <span id="save_status_button" class="adm-btn" onclick="BX.Sale.Admin.OrderEditPage.onSaveStatusButton(\''.$order->getId().'\',\'STATUS_ID\');">
115 '.Loc::getMessage("SALE_ORDER_STATUS_SAVE").'
116 </span>
117 <span id="save_status_result_ok" class="adm-sale-green-check-mark" style="display:none;" title="'.Loc::getMessage('SALE_ORDER_STATUS_CHANGED_SUCCESS').'"></span>
118 ';
119 }
120
121 $result .= '</td>
122 </tr>';
123
124 if (\Bitrix\Sale\Helpers\Order::isAllowGuestView($order))
125 {
126 $result .='<tr><td class="adm-detail-content-cell-l">'.Loc::getMessage("SALE_ORDER_GUEST_VIEW").':</td><td class="adm-detail-content-cell-r">';
127
128 $publicLink = \Bitrix\Sale\Helpers\Order::getPublicLink($order);
129 if (empty($publicLink))
130 {
131 $result .= Loc::getMessage("SALE_ORDER_WRONG_GUEST_PATH", array("#LANGUAGE_ID#" => LANGUAGE_ID));
132 }
133 else
134 {
135 $result .= "<a href='{$publicLink}' target='_blank'>".
136 Loc::getMessage("SALE_ORDER_GUEST_PATH", array('#ID#' => $order->getId(),"#ACCOUNT_NUMBER#" => $order->getField('ACCOUNT_NUMBER'))).
137 "</a>";
138 }
139
140 $result .='</td></tr>';
141 }
142
143 if($showCancel && $allowCancel)
144 $result .= self::getCancelBlockHtml($order, $data, $orderLocked);
145
146 $result .= '</tbody>
147 </table>
148 ';
149
150 return $result;
151 }
152
153 protected static function getCancelBlockHtml(Order $order, array $data, $orderLocked = false)
154 {
155 $isCanceled = $order->getField('CANCELED') === "Y";
156
157 if($isCanceled)
158 {
159 $text = '
160 <div class="adm-s-select-popup-element-selected" id="sale-adm-status-cancel-blocktext">
161 <div class="adm-s-select-popup-element-selected-bad">
162 <span>'.Loc::getMessage("SALE_ORDER_STATUS_CANCELED").'</span>
163 '.$order->getField('DATE_CANCELED').
164 static::renderUserCanceledLink([
165 'EMP_CANCELED_ID'=>$order->getField("EMP_CANCELED_ID"),
166 'EMP_CANCELED_NAME'=>$data["EMP_CANCELED_NAME"]
167 ]).'
168 </div>
169 </div>';
170 }
171 else
172 {
173 $text = '
174 <div class="adm-s-select-popup-element-selected" style="text-align:center;" id="sale-adm-status-cancel-blocktext">
175 <a href="javascript:void(0);" onclick="'.static::getJsObjName().'.toggleCancelDialog();">
176 '.Loc::getMessage("SALE_ORDER_STATUS_CANCELING").'
177 </a>
178 </div>';
179 }
180
181 $reasonCanceled = trim((string)$order->getField("REASON_CANCELED"));
182
183 if(!\CSaleYMHandler::isOrderFromYandex($order->getId()))
184 {
185 $reasonHtml = '
186 <div class="adm-s-select-popup-modal-title">'.Loc::getMessage("SALE_ORDER_STATUS_COMMENT").'</div>
187 <textarea style="width:400px;min-height:100px;" name="FORM_REASON_CANCELED" id="FORM_REASON_CANCELED"'.($isCanceled ? ' disabled' : '' ).'>'.($reasonCanceled <> '' ? htmlspecialcharsbx($reasonCanceled) : '').'</textarea>
188 ';
189 }
190 else
191 {
192 $reasonHtml = '
193 <div class="adm-s-select-popup-modal-title">'.Loc::getMessage("SALE_ORDER_STATUS_CANCELING_REASON").'</div>
194 <select name="FORM_REASON_CANCELED" style="max-width: 400px;" id="FORM_REASON_CANCELED" class="adm-bus-select"'.($isCanceled ? ' disabled' : '' ).'>';
195
196 foreach (\CSaleYMHandler::getOrderSubstatuses() as $statusId => $statusName)
197 $reasonHtml .= '<option value="'.$statusId.'"'.($statusId == $reasonCanceled ? " selected" : "").'>'.htmlspecialcharsbx($statusName).'</option>';
198
199 $reasonHtml .= '</select>';
200 }
201
202 return '
203 <tr id="sale-adm-status-cancel-row">
204 <td class="adm-detail-content-cell-l">&nbsp;</td>
205 <td class="adm-detail-content-cell-r">
206 <div class="adm-s-select-popup-box">
207 <div class="adm-s-select-popup-container">'.
208 ($orderLocked ? '' : '<div class="adm-s-select-popup-element-selected-control" onclick="'.static::getJsObjName().'.toggleCancelDialog();"></div>').
209 $text.
210 '</div>
211 <div class="adm-s-select-popup-modal /*active*/" id="sale-adm-status-cancel-dialog">
212 <div class="adm-s-select-popup-modal-content">
213 '.$reasonHtml.'
214 <div class="adm-s-select-popup-modal-desc">'.Loc::getMessage("SALE_ORDER_STATUS_USER_CAN_VIEW").'</div>
215 <span class="adm-btn" id="sale-adm-status-cancel-dialog-btn" onclick="'.static::getJsObjName().'.onCancelStatusButton(\''.$order->getId().'\',\''.$data["CANCELED"].'\');">
216 '.($data["CANCELED"] == "N" ? Loc::getMessage("SALE_ORDER_STATUS_CANCEL") : Loc::getMessage("SALE_ORDER_STATUS_CANCEL_CANCEL")).'
217 </span>
218 <span class="adm-s-select-popup-modal-close" onclick="'.static::getJsObjName().'.toggleCancelDialog();">'.Loc::getMessage("SALE_ORDER_STATUS_TOGGLE").'</span>
219 </div>
220 </div>
221 </div>
222 </td>
223 </tr>';
224 }
225
226 public static function getUserInfo($userId)
227 {
228 static $users = array();
229
230 $userId = intval($userId);
231 if ($userId <= 0)
232 return array( "ID"=>0, "NAME" => "", "LOGIN"=>"");
233
234 if (isset($users[$userId]))
235 return $users[$userId];
236
237 $dbRes = \CUser::GetList("id", "asc", array("ID" => $userId), array("FIELDS" => array("ID", "NAME", "LOGIN")));
238 $user = $dbRes->Fetch();
239
240 if ($user)
241 $users[$userId] = $user;
242 else
243 $user = array( "ID"=>0, "NAME" => "", "LOGIN"=>"");
244
245 return $user;
246 }
247
248 protected static function prepareData(Order $order)
249 {
250 static $result = null;
251
252 if($result === null)
253 {
254 $creator = static::getUserInfo($order->getField("CREATED_BY"));
255
256 if($order->getField("CREATED_BY") <> '')
257 $creatorName = OrderEdit::getUserName($order->getField("CREATED_BY"), $order->getSiteId());
258 else
259 $creatorName = "";
260
261 if($order->getField("EMP_CANCELED_ID") <> '')
262 $cancelerName = OrderEdit::getUserName($order->getField("EMP_CANCELED_ID"), $order->getSiteId());
263 else
264 $cancelerName = "";
265
266 $sourceName = "";
267
268 if($order->getField('XML_ID') <> '')
269 {
270 $dbRes = OrderTable::getList(array(
271 'filter' => array(
272 'ORDER_ID' => $order->getId()
273 ),
274 'select' => array('SOURCE_NAME' => 'TRADING_PLATFORM.NAME')
275 ));
276
277 if($tpOrder = $dbRes->fetch())
278 $sourceName = $tpOrder['SOURCE_NAME'];
279 }
280
281 $result = array(
282 "DATE_INSERT" => ($order->getDateInsert() instanceof Date) ? $order->getDateInsert()->toString() : '',
283 "DATE_UPDATE" => ($order->getField('DATE_UPDATE') instanceof Date) ? $order->getField('DATE_UPDATE')->toString() : '',
284 "CREATOR_USER_NAME" => $creatorName,
285 "CREATOR_USER_ID" => $creator["ID"],
286 "STATUS_ID" => $order->getField('STATUS_ID'),
287 "CANCELED" => $order->getField("CANCELED"),
288 "EMP_CANCELED_NAME" => $cancelerName,
289 "SOURCE_NAME" => $sourceName
290 );
291
292 if(intval($order->getField('AFFILIATE_ID')) > 0)
293 {
294 $result["AFFILIATE_ID"] = intval($order->getField('AFFILIATE_ID'));
295
296 $dbAffiliate = \CSaleAffiliate::GetList(
297 array(),
298 array("ID" => $result["AFFILIATE_ID"]),
299 false,
300 false,
301 array("ID", "USER_ID")
302 );
303
304 if($arAffiliate = $dbAffiliate->Fetch())
305 {
306 $result["AFFILIATE_ID"] = $arAffiliate["ID"];
307 $result["AFFILIATE_NAME"] = OrderEdit::getUserName($arAffiliate["USER_ID"], $order->getSiteId());
308 }
309 else
310 {
311 $result["AFFILIATE_ID"] = 0;
312 $result["AFFILIATE_NAME"] = "-";
313 }
314 }
315 }
316
317 return $result;
318 }
319
320 public static function getScripts(Order $order, $userId)
321 {
322 $langPhrases = array("SALE_ORDER_STATUS_SAVE", "SALE_ORDER_STATUS_CANCEL", "SALE_ORDER_STATUS_CHANGE_ERROR",
323 "SALE_ORDER_STATUS_CANCEL_ERROR", "SALE_ORDER_STATUS_CANCEL_CANCEL", "SALE_ORDER_STATUS_CHANGED_SUCCESS",
324 "SALE_ORDER_STATUS_CANCELED", "SALE_ORDER_STATUS_CANCELING");
325
326 $result = '
327 <script type="text/javascript">
328 BX.ready(function(){
329 BX.Sale.Admin.OrderEditPage.registerFieldsUpdaters({
330 STATUS_ID: {
331 callback: BX.Sale.Admin.OrderEditPage.setStatus,
332 context: this
333 }
334 });
335 BX.Sale.Admin.OrderEditPage.statusesNames = '.\CUtil::PhpToJSObject(self::getStatusesList($userId, $order->getField('STATUS_ID'))).';
336 BX.Sale.Admin.OrderEditPage.callFieldsUpdaters('.\CUtil::PhpToJSObject(self::prepareData($order)).');';
337
338 foreach($langPhrases as $phrase)
339 $result .= ' BX.message({'.$phrase.': "'.\CUtil::JSEscape(Loc::getMessage($phrase)).'"});';
340
341 $result .= '}); </script>';
342 return $result;
343 }
344
345 public static function getStatusesList($userId, $orderStatus = false)
346 {
347 if($orderStatus === false)
348 $orderStatus = \Bitrix\Sale\OrderStatus::getInitialStatus();
349
350 $result = \Bitrix\Sale\OrderStatus::getAllowedUserStatuses($userId, $orderStatus);
351
352 if(empty($result[$orderStatus]))
353 {
354 $dbRes = \Bitrix\Sale\Internals\StatusTable::getList(array(
355 'select' => array('ID', 'NAME' => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME'),
356 'filter' => array(
357 '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => LANGUAGE_ID,
358 '=ID' => $orderStatus
359 )
360 ));
361
362 if($status = $dbRes->fetch())
363 $result = array($orderStatus => $status['NAME']) + $result;
364 }
365
366 return $result;
367 }
368
369 public static function getEditSimple($userId, $fieldName, $status)
370 {
371 return '
372 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
373 <tbody>
374 <tr>
375 <td class="adm-detail-content-cell-l" width="40%">'.
376 Loc::getMessage("SALE_ORDER_STATUS").':'.
377 '</td>
378 <td class="adm-detail-content-cell-r">'.
379 \Bitrix\Sale\Helpers\Admin\OrderEdit::makeSelectHtml(
380 $fieldName,
381 self::getStatusesList($userId, $status),
382 $status,
383 false,
384 array(
385 "class" => "adm-bus-select",
386 "id" => "STATUS_ID"
387 )
388 ).
389 '</td>
390 </tr>
391 </tbody>
392 </table>';
393 }
394
395 protected static function renderCreatorLink($data)
396 {
397 return '<a href="/bitrix/admin/user_edit.php?lang='.LANGUAGE_ID.'&ID='. $data["CREATOR_USER_ID"].'">'.htmlspecialcharsbx($data["CREATOR_USER_NAME"]).'</a>';
398 }
399
400 protected static function renderUserCanceledLink($data)
401 {
402 return '<a href="/bitrix/admin/user_edit.php?lang='.LANGUAGE_ID.'&ID='.$data["EMP_CANCELED_ID"].'">'.htmlspecialcharsbx($data["EMP_CANCELED_NAME"]).'</a>';
403 }
404
405 protected static function getJsObjName()
406 {
407 return 'BX.Sale.Admin.OrderEditPage';
408 }
409}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getCancelBlockHtml(Order $order, array $data, $orderLocked=false)