16 public static function getEdit(
Order $order, \CUser $user, $showCancel, $showSaveButton)
20 $orderClass = $registry->getOrderClassName();
23 $orderLocked = $orderClass::isLocked($order->getId());
30 $orderStatusClass = $registry->getOrderStatusClassName();
32 $allowedStatusesCancel = $orderStatusClass::getStatusesUserCanDoOperations($user->GetID(), array(
'cancel'));
33 if (is_array($allowedStatusesCancel))
35 $allowCancel = in_array($order->getField(
"STATUS_ID"), $allowedStatusesCancel);
39 $orderSiteId = $order->getSiteId();
41 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table">
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">
48 ' '.static::renderCreatorLink($data).
'
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>
57 <td class="adm-detail-content-cell-l">'.
Loc::getMessage(
"SALE_ORDER_STATUS_SITE").
':</td>
58 <td class="adm-detail-content-cell-r"><div>'.
65 if(!empty($data[
"AFFILIATE_NAME"]))
67 $data[
'AFFILIATE_NAME'] = htmlspecialcharsbx($data[
"AFFILIATE_NAME"]);
69 if(intval($data[
'AFFILIATE_ID']) > 0)
71 $data[
"AFFILIATE_NAME"] =
'<a href="/bitrix/admin/sale_affiliate_edit.php?lang='.LANGUAGE_ID.
'&ID='.$data[
'AFFILIATE_ID'].
'">'.
72 $data[
"AFFILIATE_NAME"].
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>
83 if($data[
'SOURCE_NAME'] <>
'')
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>'.
92 "class" =>
"adm-bus-select",
97 $attr[
"disabled"] =
"disabled";
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(
104 self::getStatusesList($user->GetID(), $data[
"STATUS_ID"]),
110 if($showSaveButton && !$orderLocked)
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").
'
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>
124 if (\
Bitrix\
Sale\Helpers\Order::isAllowGuestView($order))
126 $result .=
'<tr><td class="adm-detail-content-cell-l">'.Loc::getMessage(
"SALE_ORDER_GUEST_VIEW").
':</td><td class="adm-detail-content-cell-r">';
128 $publicLink = \Bitrix\Sale\Helpers\Order::getPublicLink($order);
129 if (empty($publicLink))
131 $result .=
Loc::getMessage(
"SALE_ORDER_WRONG_GUEST_PATH", array(
"#LANGUAGE_ID#" => LANGUAGE_ID));
135 $result .=
"<a href='{$publicLink}' target='_blank'>".
136 Loc::getMessage(
"SALE_ORDER_GUEST_PATH", array(
'#ID#' => $order->getId(),
"#ACCOUNT_NUMBER#" => $order->getField(
'ACCOUNT_NUMBER'))).
140 $result .=
'</td></tr>';
143 if($showCancel && $allowCancel)
155 $isCanceled = $order->getField(
'CANCELED') ===
"Y";
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"]
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();">
181 $reasonCanceled = trim((
string)$order->getField(
"REASON_CANCELED"));
183 if(!\CSaleYMHandler::isOrderFromYandex($order->getId()))
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>
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' :
'' ).
'>';
196 foreach (\CSaleYMHandler::getOrderSubstatuses() as $statusId => $statusName)
197 $reasonHtml .=
'<option value="'.$statusId.
'"'.($statusId == $reasonCanceled ?
" selected" :
"").
'>'.htmlspecialcharsbx($statusName).
'</option>';
199 $reasonHtml .=
'</select>';
203 <tr id="sale-adm-status-cancel-row">
204 <td class="adm-detail-content-cell-l"> </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>').
211 <div class="adm-s-select-popup-modal /*active*/" id="sale-adm-status-cancel-dialog">
212 <div class="adm-s-select-popup-modal-content">
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
")).'
218 <span class="adm-s-select-popup-modal-close
" onclick="'.static::getJsObjName().'.toggleCancelDialog();
">'.Loc::getMessage("SALE_ORDER_STATUS_TOGGLE
").'</span>
226 public static function getUserInfo($userId)
228 static $users = array();
230 $userId = intval($userId);
232 return array( "ID
"=>0, "NAME
" => "", "LOGIN
"=>"");
234 if (isset($users[$userId]))
235 return $users[$userId];
237 $dbRes = \CUser::GetList("id", "asc
", array("ID
" => $userId), array("FIELDS
" => array("ID
", "NAME
", "LOGIN
")));
238 $user = $dbRes->Fetch();
241 $users[$userId] = $user;
243 $user = array( "ID
"=>0, "NAME
" => "", "LOGIN
"=>"");
248 protected static function prepareData(Order $order)
250 static $result = null;
254 $creator = static::getUserInfo($order->getField("CREATED_BY
"));
256 if($order->getField("CREATED_BY
") <> '')
257 $creatorName = OrderEdit::getUserName($order->getField("CREATED_BY
"), $order->getSiteId());
261 if($order->getField("EMP_CANCELED_ID
") <> '')
262 $cancelerName = OrderEdit::getUserName($order->getField("EMP_CANCELED_ID
"), $order->getSiteId());
268 if($order->getField('XML_ID') <> '')
270 $dbRes = OrderTable::getList(array(
272 'ORDER_ID' => $order->getId()
274 'select' => array('SOURCE_NAME' => 'TRADING_PLATFORM.NAME')
277 if($tpOrder = $dbRes->fetch())
278 $sourceName = $tpOrder['SOURCE_NAME'];
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
292 if(intval($order->getField('AFFILIATE_ID')) > 0)
294 $result["AFFILIATE_ID
"] = intval($order->getField('AFFILIATE_ID'));
296 $dbAffiliate = \CSaleAffiliate::GetList(
298 array("ID
" => $result["AFFILIATE_ID
"]),
301 array("ID
", "USER_ID
")
304 if($arAffiliate = $dbAffiliate->Fetch())
306 $result["AFFILIATE_ID
"] = $arAffiliate["ID
"];
307 $result["AFFILIATE_NAME
"] = OrderEdit::getUserName($arAffiliate["USER_ID
"], $order->getSiteId());
311 $result["AFFILIATE_ID
"] = 0;
312 $result["AFFILIATE_NAME
"] = "-
";
320 public static function getScripts(Order $order, $userId)
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
");
327 <script type="text/javascript
">
329 BX.Sale.Admin.OrderEditPage.registerFieldsUpdaters({
331 callback: BX.Sale.Admin.OrderEditPage.setStatus,
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)).');';
338 foreach($langPhrases as $phrase)
339 $result .= ' BX.message({'.$phrase.': "'.\CUtil::JSEscape(Loc::getMessage($phrase)).'"});';
341 $result .= '}); </script>';
345 public static function getStatusesList($userId, $orderStatus = false)
347 if($orderStatus === false)
348 $orderStatus = \Bitrix\Sale\OrderStatus::getInitialStatus();
350 $result = \Bitrix\Sale\OrderStatus::getAllowedUserStatuses($userId, $orderStatus);
352 if(empty($result[$orderStatus]))
354 $dbRes = \Bitrix\Sale\Internals\StatusTable::getList(array(
355 'select' => array('ID', 'NAME' => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME'),
357 '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => LANGUAGE_ID,
358 '=ID' => $orderStatus
362 if($status = $dbRes->fetch())
363 $result = array($orderStatus => $status['NAME']) + $result;
369 public static function getEditSimple($userId, $fieldName, $status)
372 <table border="0
" cellspacing="0
" cellpadding="0
" width="100%
" class="adm-detail-content-table edit-table
">
375 <td class="adm-detail-content-cell-l
" width="40%
">'.
376 Loc::getMessage("SALE_ORDER_STATUS
").':'.
378 <td class="adm-detail-content-cell-r
">'.
379 \Bitrix\Sale\Helpers\Admin\OrderEdit::makeSelectHtml(
381 self::getStatusesList($userId, $status),
385 "class" => "adm-bus-select
",
395 protected static function renderCreatorLink($data)
397 return '<a href="/
bitrix/admin/user_edit.php?lang=
'.LANGUAGE_ID.'&ID=
'. $data["CREATOR_USER_ID"].'">'.htmlspecialcharsbx($data["CREATOR_USER_NAME
"]).'</a>';
400 protected static function renderUserCanceledLink($data)
402 return '<a href="/
bitrix/admin/user_edit.php?lang=
'.LANGUAGE_ID.'&ID=
'.$data["EMP_CANCELED_ID"].'">'.htmlspecialcharsbx($data["EMP_CANCELED_NAME
"]).'</a>';
405 protected static function getJsObjName()
407 return 'BX.Sale.Admin.OrderEditPage';
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)