Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ordershipment.php
1<?php
2
4
19use Bitrix\Main\Page\Asset;
22use Bitrix\Main\Entity\EntityError;
23use Bitrix\Main;
26use Bitrix\Sale;
29
30Loc::loadMessages(__FILE__);
31
33{
34 public static $shipmentObjJs = null;
36 protected static $shipment = null;
37 protected static $defaultFields = null;
38 protected static $backUrl = '';
39
40 public static function getEditTemplate($data, $index, $formType, $post)
41 {
42 global $USER, $APPLICATION;
43
44 $saleModulePermissions = $APPLICATION->GetGroupRight("sale");
45
46 $index++;
47
48 static $items = null;
49 if (is_null($items))
51
52 $data['DELIVERY_ID'] ??= 0;
53
54 if (!isset($items[$data['DELIVERY_ID']]))
55 {
56 $delivery = self::getDeliveryServiceInfoById($data['DELIVERY_ID']);
57 if ($delivery)
58 $items[$delivery['ID']] = $delivery;
59 }
60
61 static $deliveries = null;
62 if (is_null($deliveries))
63 $deliveries = self::makeDeliveryServiceTree($items);
64
65 $deliveryId = 0;
66 $profileId = 0;
67
68 if (isset($post['DELIVERY_ID']))
69 {
70 if (isset($post['PROFILE']))
71 $data['DELIVERY_ID'] = $post['PROFILE'];
72 else
73 $data['DELIVERY_ID'] = $post['DELIVERY_ID'];
74 }
75
76 // default
77 $data['ID'] ??= 0;
78 $data['TRACKING_NUMBER'] ??= null;
79 $data['BASE_PRICE_DELIVERY'] ??= null;
80 $data['CALCULATED_PRICE'] ??= null;
81 $data['CALCULATED_WEIGHT'] ??= null;
82 $data['DEDUCTED'] ??= 'N';
83 $data['ALLOW_DELIVERY'] ??= 'N';
84 $data['DELIVERY_DOC_NUM'] ??= null;
85 $data['DELIVERY_DOC_DATE'] ??= null;
86
87 $profiles = array();
88 if ($data['DELIVERY_ID'])
89 {
90 $deliveryId = $data['DELIVERY_ID'];
91 $service = Services\Manager::getObjectById($deliveryId);
92 if ($service && $service::isProfile())
93 {
94 $profileId = $deliveryId;
95 $deliveryId = $service->getParentService()->getId();
96
97 $profiles = self::getDeliveryServiceProfiles($deliveryId);
98 if (!$profiles)
99 unset($deliveries[$deliveryId]);
100 }
101 else if ($service && $service->canHasProfiles())
102 {
103 unset($deliveries[$deliveryId]);
104 }
105 }
106
107 if (isset($post['ALLOW_DELIVERY']))
108 $data['ALLOW_DELIVERY'] = $post['ALLOW_DELIVERY'];
109
110 $allowedStatusesDelivery = DeliveryStatus::getStatusesUserCanDoOperations($USER->GetID(), array('delivery'));
111 $isAllowDelivery = isset($data["STATUS_ID"]) && in_array($data["STATUS_ID"], $allowedStatusesDelivery);
112
113 $class = ($data['ALLOW_DELIVERY'] == 'Y') ? '' : 'notdelivery';
114 $class .= ($isAllowDelivery) ? '' : ' not_active';
115 $status = ($data['ALLOW_DELIVERY'] == 'Y') ? 'YES' : 'NO';
116 $triangle = ($class === '') ? '<span class="triangle"> &#9662;</span>' : '';
117
118 $allowDelivery = '<span><span id="BUTTON_ALLOW_DELIVERY_'.$index.'" class="'.$class.'">'.Loc::getMessage('SALE_ORDER_SHIPMENT_ALLOW_DELIVERY_'.$status).'</span>'.$triangle.'</span>';
119
120 $allowedStatusesDeduction = DeliveryStatus::getStatusesUserCanDoOperations($USER->GetID(), array('deduction'));
121 $isAllowDeduction = isset($data["STATUS_ID"]) && in_array($data["STATUS_ID"], $allowedStatusesDeduction);
122
123 if (isset($post['DEDUCTED']) && $isAllowDeduction)
124 $data['DEDUCTED'] = $post['DEDUCTED'];
125
126 $class = ($data['DEDUCTED'] == 'Y') ? '' : 'notdeducted';
127 $class .= ($isAllowDeduction) ? '' : ' not_active';
128 $status = ($data['DEDUCTED'] == 'Y') ? 'YES' : 'NO';
129 $triangle = ($class === '') ? '<span class="triangle"> &#9662;</span>' : '';
130
131 $deducted = '<span><span id="BUTTON_DEDUCTED_'.$index.'" class="'.$class.'">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DEDUCTED_'.$status).'</span>'.$triangle.'</span>';
132
133 $lang = Main\Application::getInstance()->getContext()->getLanguage();
134 $map = '';
135 $extraServiceHTML = '';
136 $extraServiceManager = new \Bitrix\Sale\Delivery\ExtraServices\Manager($data['DELIVERY_ID']);
137 $extraServiceManager->setOperationCurrency($data['CURRENCY']);
138 if (isset($post['EXTRA_SERVICES']))
139 {
140 $data['EXTRA_SERVICES'] = $post['EXTRA_SERVICES'];
141 }
142
143 if (isset($post['EXTRA_SERVICES']))
144 {
145 $data['DELIVERY_STORE_ID'] = $post['DELIVERY_STORE_ID'];
146 }
147
148 if (!empty($data['EXTRA_SERVICES']))
149 {
150 $extraServiceManager->setValues($data['EXTRA_SERVICES']);
151 }
152
153 $extraService = $extraServiceManager->getItems();
154 if ($extraService)
155 $extraServiceHTML = self::getExtraServiceEditControl($extraService, $index, false, self::$shipment);
156
157 if ($data['DELIVERY_ID'] > 0)
158 $map = self::getMap($data['DELIVERY_ID'], $index, $data['DELIVERY_STORE_ID']);
159
160 $dataId = (int)($data['ID'] ?? 0);
161 if ($dataId > 0)
162 {
163 $dateInsert = new Date($data['DATE_INSERT']);
164 $title = Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_EDIT_SHIPMENT_TITLE', array("#ID#" => $dataId, '#DATE_INSERT#' => $dateInsert));
165 }
166 else
167 {
168 $title = Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_NEW_SHIPMENT_TITLE');
169 }
170
171 $customPriceDelivery = isset($post['CUSTOM_PRICE_DELIVERY']) ? htmlspecialcharsbx($post['CUSTOM_PRICE_DELIVERY']) : $data['CUSTOM_PRICE_DELIVERY'];
172 $customWeightDelivery = isset($post['CUSTOM_WEIGHT_DELIVERY']) ? htmlspecialcharsbx($post['CUSTOM_WEIGHT_DELIVERY']) : $data['CUSTOM_WEIGHT_DELIVERY'];
173
174 $basePriceDelivery = round(
175 (float)($post['BASE_PRICE_DELIVERY'] ?? $data['BASE_PRICE_DELIVERY'] ?? 0.0),
176 2
177 );
178 $priceDelivery = round(
179 (float)($post['PRICE_DELIVERY'] ?? $data['PRICE_DELIVERY'] ?? 0.0),
180 2
181 );
182
183 $weight = $post['WEIGHT'] ?? $data['WEIGHT'] ?? 0;
184 $weight = roundEx(
185 floatval(
186 $weight/self::getWeightKoef($data['SITE_ID'])
187 ),
188 SALE_WEIGHT_PRECISION
189 );
190
191 $weightMeasureUnits = self::getWeightUnit($data['SITE_ID']);
192
193 $blockProfiles = '';
194 if ($profileId > 0 && $profiles)
195 {
196 $profiles = self::checkProfilesRestriction($profiles, self::$shipment);
197
198 $profilesTemplate = self::getProfileEditControl($profiles, $index, $profileId);
199 $blockProfiles = '
200 <tr id="BLOCK_PROFILES_'.$index.'">
201 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_SERVICE_PROFILE').':</td>
202 <td class="adm-detail-content-cell-r" id="PROFILE_SELECT_'.$index.'">'.$profilesTemplate.'</td>
203 </tr>';
204 }
205 $id = (isset($post['ID'])) ? $post['SHIPMENT_ID'] : $data['ID'];
206
207 $companies = '';
208
209 if (!empty($data['COMPANIES']))
210 {
211 if ($saleModulePermissions == "P")
212 {
213 $userCompanyId = null;
214
215 $userCompanyList = Company\Manager::getUserCompanyList($USER->GetID());
216 if (is_array($userCompanyList) && count($userCompanyList) == 1)
217 {
218 $userCompanyId = reset($userCompanyList);
219 $companyName = $data['COMPANIES'][$userCompanyId]["NAME"]." [".$data['COMPANIES'][$userCompanyId]["ID"]."]";
220 $companies = htmlspecialcharsbx($companyName);
221 }
222 else
223 {
224 foreach ($data['COMPANIES'] as $companyId => $companyData)
225 {
226 $foundCompany = false;
227
228 if (!empty($userCompanyList) && is_array($userCompanyList))
229 {
230 foreach ($userCompanyList as $userCompanyId)
231 {
232 if ($userCompanyId == $companyId)
233 {
234 $foundCompany = true;
235 break;
236 }
237 }
238 }
239
240 if (!$foundCompany)
241 {
242 unset($data['COMPANIES'][$companyId]);
243 }
244 }
245
246 if (count($data['COMPANIES']) == 1)
247 {
248 $company = reset($data['COMPANIES']);
249 $companies = htmlspecialcharsbx($company["NAME"]." [".$company["ID"]."]");
250 }
251 }
252 }
253
254 if (empty($companies))
255 {
257 'SHIPMENT['.$index.'][COMPANY_ID]',
258 $data['COMPANIES'],
259 isset($post["COMPANY_ID"]) ? $post["COMPANY_ID"] : $data["COMPANY_ID"],
260 true,
261 array(
262 "class" => "adm-bus-select",
263 "id" => "SHIPMENT_COMPANY_ID_".$index
264 )
265 );
266 }
267 }
268 else
269 {
270 if ($saleModulePermissions >= "W")
271 {
272 $companies = str_replace("#URL#", "/bitrix/admin/sale_company_edit.php?lang=".$lang, Loc::getMessage('SALE_ORDER_SHIPMENT_ADD_COMPANY'));
273 }
274 }
275
276 if ($data['FFD_105_ENABLED'] === 'Y')
277 {
278 $checkLink = '<tr><td class="tac" id="SHIPMENT_CHECK_LIST_ID_'.$data['ID'].'">';
279
280 if (!empty($data['CHECK']))
281 {
282 $checkLink .= OrderShipment::buildCheckHtml($data['CHECK']);
283 }
284 $checkLink .= '</td></tr>';
285 if ($data['HAS_ENABLED_CASHBOX'] === 'Y' && $data['CAN_PRINT_CHECK'] === 'Y')
286 {
287 $checkLink .= '<tr><td class="adm-detail-content-cell-r tac"><a href="javascript:void(0);" onclick="BX.Sale.Admin.OrderShipment.prototype.showCreateCheckWindow('.$data['ID'].');">'.Loc::getMessage('SALE_ORDER_SHIPMENT_CHECK_ADD').'</a></td></tr>';
288 }
289 }
290
291 if (isset($items[$data['DELIVERY_ID']]['LOGOTIP']['MAIN']))
292 $logo = $items[$data['DELIVERY_ID']]['LOGOTIP']['MAIN'];
293 else
294 $logo = '/bitrix/images/sale/logo-default-d.gif';
295
296 $trackingNumber = htmlspecialcharsbx(isset($post['TRACKING_NUMBER']) ? $post['TRACKING_NUMBER'] : $data['TRACKING_NUMBER']);
297
298 $result = '
299 <div class="adm-bus-pay" id="shipment_container_'.$index.'">
300 <input type="hidden" name="SHIPMENT['.$index.'][SHIPMENT_ID]" id="SHIPMENT_ID_'.$index.'" value="'.$id.'">
301 <input type="hidden" name="SHIPMENT['.$index.'][CUSTOM_PRICE_DELIVERY]" id="CUSTOM_PRICE_DELIVERY_'.$index.'" value="'.$customPriceDelivery.'">
302 <input type="hidden" name="SHIPMENT['.$index.'][CUSTOM_WEIGHT_DELIVERY]" id="CUSTOM_WEIGHT_DELIVERY_'.$index.'" value="'.$customWeightDelivery.'">
303 <input type="hidden" name="SHIPMENT['.$index.'][BASE_PRICE_DELIVERY]" id="BASE_PRICE_DELIVERY_'.$index.'" value="'.$data['BASE_PRICE_DELIVERY'].'">
304 <input type="hidden" name="SHIPMENT['.$index.'][CALCULATED_PRICE]" id="CALCULATED_PRICE_'.$index.'" value="'.(isset($post['CALCULATED_PRICE']) ? htmlspecialcharsbx($post['CALCULATED_PRICE']) : $data['CALCULATED_PRICE']).'">
305 <input type="hidden" name="SHIPMENT['.$index.'][CALCULATED_WEIGHT]" id="CALCULATED_WEIGHT_'.$index.'" value="'.(isset($post['CALCULATED_WEIGHT']) ? htmlspecialcharsbx($post['CALCULATED_WEIGHT']) : $data['CALCULATED_WEIGHT']).'">
306 <input type="hidden" name="SHIPMENT['.$index.'][DEDUCTED]" id="STATUS_DEDUCTED_'.$index.'" value="'.($data['DEDUCTED'] == "" ? "N" : $data['DEDUCTED']).'">
307 <input type="hidden" name="SHIPMENT['.$index.'][ALLOW_DELIVERY]" id="STATUS_ALLOW_DELIVERY_'.$index.'" value="'.($data['ALLOW_DELIVERY'] == "" ? "N" : htmlspecialcharsbx($data['ALLOW_DELIVERY'])).'">
308 <div class="adm-bus-component-content-container">
309 <div class="adm-bus-pay-section">
310 <div class="adm-bus-pay-section-title-container">
311 <div class="adm-bus-pay-section-title">'.$title.'</div>
312 </div>
313 <div class="adm-bus-pay-section-content">
314 <div class="adm-bus-pay-section-sidebar">
315 <div style="background: url(\''.$logo.'\')" id="delivery_service_logo_'.$index.'" class="adm-shipment-block-logo"></div>
316 <div id="section_map_'.$index.'">'.$map.'</div>
317 </div>
318 <div class="adm-bus-pay-section-right">
319 <div class="adm-bus-table-container caption border">
320 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_SERVICE').'</div>
321 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
322 <tbody>
323 <tr id="BLOCK_DELIVERY_SERVICE_'.$index.'">
324 <td class="adm-detail-content-cell-l fwb" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_SERVICE').':</td>
325 <td class="adm-detail-content-cell-r">
326 '.self::getDeliverySelectHtml($deliveries, $deliveryId, $index).'
327 </td>
328 </tr>
329 '.$blockProfiles.'
330 </tbody>
331 </table>
332 </div>
333 <div class="adm-bus-table-container caption border">
334 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_BLOCK_PRICE').'</div>
335 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
336 <tbody>
337 <tr style="display: none;">
338 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_SUM_PRICE').':</td>
339 <td class="adm-detail-content-cell-r tal">'
340 .\CCurrencyLang::getPriceControl(
341 '<span id="BASE_PRICE_DELIVERY_T_'.$index.'">'.$basePriceDelivery.'</span>',
342 $data['CURRENCY']
343 )
344 . '<br></td>
345 </tr>
346 <tr id="sale-order-shipment-discounts-row-'.$index.'" style="display: none;">
347 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DISCOUNT').':</td>
348 <td class="adm-detail-content-cell-r tal" id="sale-order-shipment-discounts-container-'.$index.'"></td>
349 </tr>
350 <tr>
351 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_SUM_DISCOUNT_PRICE').':</td>
352 <td class="adm-detail-content-cell-r tal">'
353 .\CCurrencyLang::getPriceControl(
354 '<input type="text" class="adm-bus-input-price" name="SHIPMENT['.$index.'][PRICE_DELIVERY]" id="PRICE_DELIVERY_'.$index.'" value="'.$priceDelivery.'">',
355 $data['CURRENCY']
356 )
357 .'</td>
358 </tr>
359 </tbody>
360 </table>
361 </div>
362 <div class="adm-bus-table-container caption border">
363 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_BLOCK_WEIGHT').'</div>
364 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
365 <tbody>
366 <tr>
367 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_WEIGHT').':</td>
368 <td class="adm-detail-content-cell-r tal">
369 <input type="text" class="adm-bus-input-price" name="SHIPMENT['.$index.'][WEIGHT]" id="WEIGHT_DELIVERY_'.$index.'" value="'.$weight.'"> '.$weightMeasureUnits.'
370 <span id="UPDATE_DELIVERY_INFO_'.$index.'" class="new_delivery_price_button">'.Loc::getMessage('SALE_ORDER_SHIPMENT_RECALCULATE_DELIVERY_PRICE').'</span>
371 </td>
372 </tr>
373 </tbody>
374 </table>
375 </div>';
376
377
378 if ($companies)
379 {
380 $result .= '<div class="adm-bus-table-container caption border">
381 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_SHIPMENT').'</div>
382 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
383 <tbody>
384 <tr>
385 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_OFFICE').':</td>
386 <td class="adm-detail-content-cell-r">'.$companies.'</td>
387 </tr>
388 </tbody>
389 </table>
390 </div>';
391 }
392 if ($data['FFD_105_ENABLED'] === 'Y' && $data['ID'] > 0)
393 {
394 $result .= '<div class="adm-bus-table-container caption border" style="padding-top:10px;">
395 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_CHECK_LINK_TITLE').'</div>
396 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table">
397 <tbody>
398 '.$checkLink.'
399 </tbody>
400 </table>
401 </div>';
402 }
403
404 $result .= '<div class="adm-bus-table-container caption border">
405 <div class="adm-bus-moreInfo_part1">
406 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_STATUS').'</div>
407 <table class="adm-detail-content-table edit-table" border="0" width="100%" cellpadding="0" cellspacing="0">
408 <tbody>
409 <tr>
410 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_ALLOW_DELIVERY').':</td>
411 <td class="adm-detail-content-cell-r delivery-status">'.$allowDelivery.'</td>
412 </tr>
413 '.((!empty($data['EMP_ALLOW_DELIVERY_ID'])) ? '
414 <tr>
415 <td class="adm-detail-content-cell-l vat" width="40%"></td>
416 <td class="adm-detail-content-cell-r">
417 <div>'.Loc::getMessage('SALE_ORDER_SHIPMENT_MODIFY_BY').': <span style="color: #66878F" id="order_additional_info_date_responsible">'.htmlspecialcharsbx($data['DATE_ALLOW_DELIVERY']).'</span> <a href="/bitrix/admin/user_edit.php?lang='.$lang.'&ID='.$data['EMP_ALLOW_DELIVERY_ID'].'" id="order_additional_info_emp_responsible">'.htmlspecialcharsbx($data['EMP_ALLOW_DELIVERY_ID_LAST_NAME']).' '.htmlspecialcharsbx($data['EMP_ALLOW_DELIVERY_ID_NAME']).'</a></div>
418 </td>
419 </tr>
420 ' : '').'
421 <tr>
422 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DEDUCTED').':</td>
423 <td class="adm-detail-content-cell-r deducted-status">'.$deducted.'</td>
424 </tr>
425 '.((!empty($data['EMP_DEDUCTED_ID'])) ? '
426 <tr>
427 <td class="adm-detail-content-cell-l fwb vat" width="40%"></td>
428 <td class="adm-detail-content-cell-r">
429 <div>'.Loc::getMessage('SALE_ORDER_SHIPMENT_MODIFY_BY').': <span style="color: #66878F" id="order_additional_info_date_responsible">'.htmlspecialcharsbx($data['DATE_DEDUCTED']).'</span> <a href="/bitrix/admin/user_edit.php?lang='.$lang.'&ID='.$data['EMP_DEDUCTED_ID'].'" id="order_additional_info_emp_responsible">'.htmlspecialcharsbx($data['EMP_DEDUCTED_ID_LAST_NAME']).' '.htmlspecialcharsbx($data['EMP_DEDUCTED_ID_NAME']).'</a></div>
430 </td>
431 </tr>
432 ' : '').'
433 </tbody>
434 </table>
435 </div>
436 </div>
437 <div class="adm-bus-table-container caption border">
438 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_DELIVERY_INFO').'</div>
439 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
440 <tbody>
441 <tr>
442 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_TRACKING_NUMBER').':</td>
443 <td class="adm-detail-content-cell-r tal"><input type="text" class="adm-bus-input" name="SHIPMENT['.$index.'][TRACKING_NUMBER]" value="'.$trackingNumber.'"><br></td>
444 </tr>'.(
445 $data['HAS_TRACKING'] && $trackingNumber <> '' && intval($data['ID'] > 0)
446 ?
447 '<tr>
448 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_TRACKING_STATUS').':</td>
449 <td class="adm-detail-content-cell-r tal">'.
450 '<span id="sale-order-shipment-tracking-status-'.$index.'">'.(intval($data['TRACKING_STATUS']) >= 0 ? \Bitrix\Sale\Delivery\Tracking\Manager::getStatusName($data['TRACKING_STATUS']) : '-').'</span>'.
451 '&nbsp;&nbsp;&nbsp;[<span onclick="BX.Sale.Admin.GeneralShipment.refreshTrackingStatus(\''.$index.'\', \''.$data['ID'].'\', true);" style="border-bottom: 1px dashed #2675d7; cursor: pointer; color: #2675d7;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_TRACKING_STATUS_REFRESH').'</span>]<br></td>
452 </tr>
453 <tr>
454 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_TRACKING_DESCRIPTION').':</td>
455 <td class="adm-detail-content-cell-r tal" id="sale-order-shipment-tracking-description-'.$index.'">'.($data['TRACKING_DESCRIPTION'] <> '' ? $data['TRACKING_DESCRIPTION'] : '-').'<br></td>
456 </tr>
457 <tr>
458 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_TRACKING_LAST_CHANGE').':</td>
459 <td class="adm-detail-content-cell-r tal" id="sale-order-shipment-tracking-last-change-'.$index.'">'.($data['TRACKING_LAST_CHANGE'] <> '' ? $data['TRACKING_LAST_CHANGE'] : '-').'<br></td>
460 </tr>'.(!empty($data['TRACKING_URL']) ?
461 '<tr>
462 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_TRACKING_URL').':</td>
463 <td class="adm-detail-content-cell-r tal" id="sale-order-shipment-tracking-url-'.$index.'"><a href="'.$data['TRACKING_URL'].'">'.$data['TRACKING_URL'].'</a><br></td>
464 <tr>' : '')
465 :
466 ''
467 ).'<tr>
468 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_DOC_NUM').':</td>
469 <td class="adm-detail-content-cell-r tal"><input type="text" class="adm-bus-input" name="SHIPMENT['.$index.'][DELIVERY_DOC_NUM]" value="'.htmlspecialcharsbx(isset($post['DELIVERY_DOC_NUM']) ? $post['DELIVERY_DOC_NUM'] : $data['DELIVERY_DOC_NUM']).'"><br></td>
470 </tr>
471 <tr>
472 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_DOC_DATE').':</td>
473 <td class="adm-detail-content-cell-r tal">
474 <div class="adm-input-wrap adm-calendar-second" style="display: inline-block;">
475 <input type="text" class="adm-input adm-calendar-to" id="DELIVERY_DOC_DATE" name="SHIPMENT['.$index.'][DELIVERY_DOC_DATE]" size="15" value="'.htmlspecialcharsbx(isset($post['DELIVERY_DOC_DATE']) ? $post['DELIVERY_DOC_DATE'] : $data['DELIVERY_DOC_DATE']).'">
476 <span class="adm-calendar-icon" title="'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_CHOOSE_DATE').'" onclick="BX.calendar({node:this, field:\'DELIVERY_DOC_DATE\', form: \'\', bTime: false, bHideTime: false});"></span>
477 </div>
478 </td>
479 </tr>
480 </tbody>
481 </table>
482 <div id="DELIVERY_INFO_'.$index.'">'.$extraServiceHTML.'
483 </div>
484 </div>';
485
486 if(!empty($data['DELIVERY_REQUEST_NAME']) || !empty($data['DELIVERY_REQUEST_ERROR_DESCRIPTION']))
487 {
488 $result .= '<div class="adm-bus-table-container caption border">
489 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DEL_REQ_INFO').'</div>
490 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
491 <tbody>';
492
493 if(!empty($data['DELIVERY_REQUEST_NAME']))
494 {
495 $result .='<tr>
496 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DEL_REQ').':</td>
497 <td class="adm-detail-content-cell-r"><a href="'.$data['DELIVERY_REQUEST_LINK'].'"">'.$data['DELIVERY_REQUEST_NAME'].'</a></td>
498 </tr>';
499 }
500
501 if(!empty($data['DELIVERY_REQUEST_ERROR_DESCRIPTION']))
502 {
503 $result .= '<tr>
504 <td valign="top" class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DEL_REQ_ERROR').':</td>
505 <td class="adm-detail-content-cell-r">'.$data['DELIVERY_REQUEST_ERROR_DESCRIPTION'].'</td>
506 </tr>';
507 }
508
509 $result .= '
510 </tbody>
511 </table>
512 </div>';
513 }
514
515 if(is_array($data['DELIVERY_ADDITIONAL_INFO_EDIT']) && !empty($data['DELIVERY_ADDITIONAL_INFO_EDIT']))
516 {
517 $result .= '<div class="adm-bus-table-container caption border">
518 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_DELIVERY_ADDITIONAL').'</div>
519 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
520 <tbody><tr>';
521
522 foreach($data['DELIVERY_ADDITIONAL_INFO_EDIT'] as $name => $params)
523 {
524 $result .='
525 <td class="adm-detail-content-cell-l" width="40%">'.$params['LABEL'].':</td>
526 <td class="adm-detail-content-cell-r" width="60%">
527 '.\Bitrix\Sale\Internals\Input\Manager::getEditHtml('SHIPMENT['.$index.'][ADDITIONAL]['.$name.']', $params).'
528 </td>';
529 }
530
531 $result .= ' </tr></tbody>
532 </table>
533 </div>';
534 }
535
536 $result .= '</div>
537 <div class="clb"></div>
538 </div>
539 </div>
540 </div>
541 </div>';
542
543 $srcList = self::getImgDeliveryServiceList($items);
544
545 $params = array(
546 'index' => $index,
547 'id' => (int)$data['ID'],
548 'isAjax' => false,
549 'canAllow' => $isAllowDelivery,
550 'canDeduct' => $isAllowDeduction,
551 'canChangeStatus' => false,
552 'src_list' => $srcList,
553 'active' => true,
554 'discounts' => $data["DISCOUNTS"] ?? [],
555 'discountsMode' => ($formType == "edit" ? "view" : "edit"),
556 'templateType' => 'edit',
557 'weightKoef' => self::getWeightKoef($data['SITE_ID']),
558 'weightUnit' => self::getWeightUnit($data['SITE_ID'])
559 );
560
561 if ($customPriceDelivery == 'Y')
562 $params['calculated_price'] = $data['CALCULATED_PRICE'];
563
564 if ($customWeightDelivery == 'Y')
565 $params['calculated_weight'] = $data['CALCULATED_WEIGHT'];
566
567 $result .= self::initJsShipment($params);
568 return $result;
569 }
570
571 public static function getWeightUnit($siteId)
572 {
573 return htmlspecialcharsbx(Option::get('sale', 'weight_unit', "", $siteId));
574 }
575
576 public static function getWeightKoef($siteId)
577 {
578 $weightKoef = floatval(Option::get('sale', 'weight_koef', 1, $siteId));
579
580 if($weightKoef <= 0)
581 {
582 $weightKoef = 1;
583 }
584
585 return $weightKoef;
586 }
587
588 public static function getImgDeliveryServiceList($items)
589 {
590 $srcList = array();
591 foreach ($items as $item)
592 $srcList[$item['ID']] = $item['LOGOTIP'];
593 return $srcList;
594 }
595
596 public static function getDeliveryServiceProfiles($parentId)
597 {
598 return Services\Manager::getByParentId($parentId);
599 }
600
601 public static function initJsShipment($params)
602 {
603 self::$shipmentObjJs = 'obShipment_'.$params['index'];
604
605 return "<script>
606 BX.ready(function() {
607 var ".self::$shipmentObjJs." = new BX.Sale.Admin.OrderShipment(".\CUtil::PhpToJSObject($params).");
608 if (BX.Sale.Admin.ShipmentBasketObj)
609 BX.Sale.Admin.ShipmentBasketObj.shipment = ".self::$shipmentObjJs.";
610 });
611 </script>";
612 }
613
614 private static function getDeliveryServiceInfoById($id)
615 {
616 $service = null;
617
618 if ($id > 0)
619 {
620 $resService = \Bitrix\Sale\Delivery\Services\Table::getList(array(
621 'filter' => array('ID' => $id),
622 'order' => array('SORT' => 'ASC', 'NAME' => 'ASC'),
623 'select' => array("ID", "NAME", "DESCRIPTION", "LOGOTIP", "CLASS_NAME", "PARENT_ID", "CONFIG")
624 ));
625 $service = $resService->fetch();
626 }
627
628 return $service;
629 }
630
631 public static function getDeliveryServiceList($shipment = null)
632 {
633 static $result = null;
634 $logoPath ='/bitrix/images/sale/logo-default-d.gif';
635
636 if($result === null)
637 {
638 if ($shipment != null)
639 self::$shipment = $shipment;
640
641 $result = array(
642 array(
643 'ID' => 0,
644 'PARENT_ID' => 0,
645 'NAME' => Loc::getMessage('SALE_ORDER_PAYMENT_NO_DELIVERY_SERVICE'),
646 'LOGOTIP' => array(
647 'MAIN' => $logoPath,
648 'SHORT' => $logoPath
649 )
650 )
651 );
652
653 $deliveryList = Services\Manager::getRestrictedList(
654 self::$shipment,
655 Restrictions\Manager::MODE_MANAGER,
656 array(
657 Services\Manager::SKIP_CHILDREN_PARENT_CHECK,
658 Services\Manager::SKIP_PROFILE_PARENT_CHECK
659 )
660 );
661
662 foreach ($deliveryList as $delivery)
663 {
664 $service = Services\Manager::getObjectById($delivery['ID']);
665
666 if(!$service)
667 continue;
668
669 if($shipment && !$service->isCompatible($shipment))
670 continue;
671
672 if ($service->canHasProfiles())
673 {
674 $profiles = $service->getProfilesList();
675 if (empty($profiles))
676 continue;
677 }
678
679 $logo = $service->getLogotip();
680
681 if (!empty($logo))
682 {
683 $mainLogo = self::getMainImgPath($logo);
684 $shortLogo = self::getShortImgPath($logo);
685 $delivery['LOGOTIP'] = array(
686 'MAIN' => $mainLogo['src'],
687 'SHORT' => $shortLogo['src']
688 );
689 }
690 else
691 {
692 $delivery['LOGOTIP'] = array(
693 'MAIN' => $logoPath,
694 'SHORT' => $logoPath
695 );
696 }
697 $result[$delivery['ID']] = $delivery;
698 }
699 }
700
701 return $result;
702 }
703
704 private static function getMainImgPath($logotip)
705 {
706 return \CFile::ResizeImageGet(
707 $logotip,
708 array('width'=>100, 'height'=>60)
709 );
710 }
711
712 private static function getShortImgPath($logotip)
713 {
714 return \CFile::ResizeImageGet(
715 $logotip,
716 array('width'=>80, 'height'=>50)
717 );
718 }
719
720 public static function getExtraServiceEditControl($extraService, $index, $view = false, Shipment $shipment = null)
721 {
722 ob_start();
723 echo '<table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table" id="BLOCK_EXTRA_SERVICE_'.$index.'">';
724 echo '<tbody>';
725
730 foreach ($extraService as $itemId => $item)
731 {
732 if (!$item->canManagerEditValue())
733 continue;
734
735 echo '<tr><td class="adm-detail-content-cell-l" width="40%">'.htmlspecialcharsbx($item->getName()).':</td>';
736 echo '<td class="adm-detail-content-cell-r tal">';
737
738 if ($view)
739 echo $item->getViewControl();
740 else
741 echo $item->getEditControl('SHIPMENT['.$index.'][EXTRA_SERVICES]['.$itemId.']');
742
743 $order = self::$shipment->getCollection()->getOrder();
744 $currency = $order->getCurrency();
745 $price = $item->getPriceShipment($shipment);
746
747 if($price)
748 echo ' ('.SaleFormatCurrency(floatval($price), $currency).')';
749
750 echo '</td></tr>';
751 }
752 echo '</tbody></table>';
753
754 $result = ob_get_contents();
755 ob_end_clean();
756
757 return $result;
758 }
759
767 public static function getEdit($shipment, $index = 0, $formType = '', $dataForRecovery = array())
768 {
769 global $USER, $APPLICATION;
770
771 self::$shipment = $shipment;
772 $data = self::prepareData(!empty($dataForRecovery));
773 $data['COMPANIES'] = Company\Manager::getListWithRestrictions($shipment, \Bitrix\Sale\Services\Company\Restrictions\Manager::MODE_MANAGER);
774
775 $saleModulePermissions = $APPLICATION->GetGroupRight("sale");
776
777 $userCompanyId = null;
778
779 if($saleModulePermissions == "P")
780 {
781 $userCompanyList = Company\Manager::getUserCompanyList($USER->GetID());
782 if (!empty($userCompanyList) && is_array($userCompanyList) && count($userCompanyList) == 1)
783 {
784 $userCompanyId = reset($userCompanyList);
785 }
786
787 if (self::$shipment->getId() == 0)
788 {
789 if (intval($userCompanyId) > 0)
790 {
791 self::$shipment->setField('COMPANY_ID', $userCompanyId);
792 }
793
794 self::$shipment->setField('RESPONSIBLE_ID', $USER->GetID());
795 }
796 }
797 $result = self::getEditTemplate($data, $index, $formType, $dataForRecovery);
798
799 return $result;
800 }
801
802 public static function modifyData($data)
803 {
804 $order = self::$shipment->getCollection()->getOrder();
805
806 foreach ($data as &$item)
807 {
808 $item['ID'] = $item['SHIPMENT_ID'];
809 if ($item['PROFILE'] && $item['PROFILE'] > 0)
810 {
811 $item['DELIVERY_ID'] = $item['PROFILE'];
812 unset($item['PROFILE']);
813 }
814 $item['CURRENCY'] = $order->getCurrency();
815 }
816 unset($item);
817
818 return array('SHIPMENT' => $data);
819 }
820
821 public static function getStoresList($deliveryId, $storeId)
822 {
823 $result = array();
824
825 if(!\Bitrix\Main\Loader::includeModule('catalog'))
826 return $result;
827
828 $storesIds = \Bitrix\Sale\Delivery\ExtraServices\Manager::getStoresList($deliveryId);
829
830 if(!empty($storesIds))
831 {
832 $dbList = \CCatalogStore::GetList(
833 array("SORT" => "DESC", "ID" => "DESC"),
834 array("ISSUING_CENTER" => "Y", "ID" => $storesIds),
835 false,
836 false,
837 array("ID", "ACTIVE", "SITE_ID", "TITLE", "ADDRESS", "DESCRIPTION", "IMAGE_ID", "PHONE", "SCHEDULE", "LOCATION_ID", "GPS_N", "GPS_S")
838 );
839
840 while ($store = $dbList->Fetch())
841 {
842 if ($store['ACTIVE'] === 'N' && (int)$store["ID"] !== (int)$storeId)
843 continue;
844 $result[$store["ID"]] = $store;
845 }
846 }
847
848 return $result;
849 }
850
851 public static function getMap($deliveryId, $index, $storeId = 0, $formType = "")
852 {
853 global $APPLICATION;
854 $map = '';
855
856 if ($deliveryId <= 0)
857 return $map;
858
859 $stores = self::getStoresList($deliveryId, $storeId);
860 if ($stores)
861 {
862 $params = array(
863 "INPUT_NAME" => 'SHIPMENT['.$index.'][DELIVERY_STORE_ID]',
864 "INPUT_ID" => 'DELIVERY_ST_'.$index,
865 "INDEX" => $index,
866 "DELIVERY_ID" => $deliveryId,
867 "STORES_LIST" => $stores,
868 "MAP" => array(
869 'OPTIONS' => array('ENABLE_DRAGGING'),
870 'CONTROLS' => array('SMALLZOOM', 'SMALL_ZOOM_CONTROL')
871 ),
872 "TITLE" => Loc::getMessage('SALE_ORDER_SHIPMENT_STORE_SELF_DELIVERY'),
873 "SHOW_MAP_TYPE_SETTINGS" => "Y"
874 );
875
876 if ($formType === 'archive' || $formType === 'view')
877 {
878 $params['FORM'] = 'view';
879 }
880
881 if (intval($storeId) > 0)
882 $params["SELECTED_STORE"] = $storeId;
883
884 ob_start();
885 $APPLICATION->IncludeComponent(
886 "bitrix:sale.store.choose",
887 ".default",
888 $params
889 );
890 $map .= '<div style="padding-top: 15px;">';
891 $map .= ob_get_contents();
892 $map .= '</div>';
893 ob_end_clean();
894
895 $map .= '<link rel="stylesheet" type="text/css" href="/bitrix/components/bitrix/sale.store.choose/templates/.default/style.css">';
896 }
897
898 return $map;
899 }
900
901 private static function getDeliverySelectHtml($deliveryServices, $selected, $index)
902 {
903 $result = '<select class="adm-bus-select" name="SHIPMENT['.$index.'][DELIVERY_ID]" id="DELIVERY_'.$index.'">';
904 $result .= self::getTemplate($deliveryServices, $selected);
905 $result .= '</select>';
906
907 return $result;
908 }
909
910 public static function getScripts()
911 {
912 Asset::getInstance()->addJs("/bitrix/js/sale/admin/order_shipment.js");
913 $message = array(
914 'SALE_ORDER_SHIPMENT_DEDUCTED_YES' => Loc::getMessage('SALE_ORDER_SHIPMENT_DEDUCTED_YES'),
915 'SALE_ORDER_SHIPMENT_DEDUCTED_NO' => Loc::getMessage('SALE_ORDER_SHIPMENT_DEDUCTED_NO'),
916 'SALE_ORDER_SHIPMENT_ALLOW_DELIVERY_YES' => Loc::getMessage('SALE_ORDER_SHIPMENT_ALLOW_DELIVERY_YES'),
917 'SALE_ORDER_SHIPMENT_ALLOW_DELIVERY_NO' => Loc::getMessage('SALE_ORDER_SHIPMENT_ALLOW_DELIVERY_NO'),
918 'SALE_ORDER_SHIPMENT_NEW_PRICE_DELIVERY' => Loc::getMessage('SALE_ORDER_SHIPMENT_NEW_PRICE_DELIVERY'),
919 'SALE_ORDER_SHIPMENT_APPLY' => Loc::getMessage('SALE_ORDER_SHIPMENT_APPLY'),
920 'SALE_ORDER_SHIPMENT_CONFIRM_SET_NEW_PRICE' => Loc::getMessage('SALE_ORDER_SHIPMENT_CONFIRM_SET_NEW_PRICE'),
921 'SALE_ORDER_SHIPMENT_BLOCK_SHIPMENT_TOGGLE_UP' => Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_SHIPMENT_TOGGLE_UP'),
922 'SALE_ORDER_SHIPMENT_BLOCK_SHIPMENT_TOGGLE' => Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_SHIPMENT_TOGGLE'),
923 'SALE_ORDER_SHIPMENT_CONFIRM_DELETE_SHIPMENT' => Loc::getMessage('SALE_ORDER_SHIPMENT_CONFIRM_DELETE_SHIPMENT'),
924 'SALE_ORDER_SHIPMENT_PROFILE' => Loc::getMessage('SALE_ORDER_SHIPMENT_PROFILE'),
925 'SALE_ORDER_SHIPMENT_TRACKING_S_EMPTY' => Loc::getMessage('SALE_ORDER_SHIPMENT_TRACKING_S_EMPTY'),
926 'SALE_ORDER_SHIPMENT_CASHBOX_CHECK_ADD_WINDOW_TITLE' => Loc::getMessage('SALE_ORDER_SHIPMENT_CHECK_ADD_WINDOW_TITLE'),
927 'SALE_ORDER_SHIPMENT_CONFIRM_SET_NEW_WEIGHT' => Loc::getMessage('SALE_ORDER_SHIPMENT_CONFIRM_SET_NEW_WEIGHT'),
928 'SALE_ORDER_SHIPMENT_NEW_WEIGHT_DELIVERY' => Loc::getMessage('SALE_ORDER_SHIPMENT_NEW_WEIGHT_DELIVERY'),
929 );
930
931 return "<script>
932 BX.message(".\CUtil::PhpToJSObject($message).");
933 </script>";
934 }
935
936 public static function registerShipmentFieldsUpdaters()
937 {
938 return "<script>
939 BX.ready(function(){
940 BX.Sale.Admin.OrderEditPage.registerFieldsUpdaters( BX.Sale.Admin.GeneralShipment.getFieldsUpdaters() );
941 });
942 </script>";
943
944 }
945
951 public static function checkProfilesRestriction($profiles, $shipment)
952 {
953 foreach ($profiles as $key => $profile)
954 {
955 $profiles[$key]['RESTRICTED'] = Restrictions\Manager::checkService($profile['ID'], $shipment, Restrictions\Manager::MODE_MANAGER);
956 if ($profiles[$key]['RESTRICTED'] === Base\RestrictionManager::SEVERITY_NONE)
957 {
958 $service = Services\Manager::getObjectById($profile['ID']);
959 if ($service && !$service->isCompatible($shipment))
960 {
961 $profiles[$key]['RESTRICTED'] = Base\RestrictionManager::SEVERITY_SOFT;
962 }
963 }
964 }
965
966 return $profiles;
967 }
968
975 public static function getProfileEditControl($profiles, $index = 1, $selectedProfileId = 0)
976 {
977
978 $result = '<select class="adm-bus-select" name="SHIPMENT['.$index.'][PROFILE]" id="PROFILE_'.$index.'">';
979 $availableProfile = '';
980 $unAvailableProfile = '';
981
982 foreach ($profiles as $profile)
983 {
984 if ($profile['ACTIVE'] == 'N')
985 continue;
986
987 $selected = ($profile['ID'] == $selectedProfileId ? 'selected' : '');
988
989 if ($profile['RESTRICTED'] == Restrictions\Manager::SEVERITY_SOFT)
990 $unAvailableProfile .= '<option value="'.$profile['ID'].'" '.$selected.' class="bx-admin-service-restricted">'.htmlspecialcharsbx($profile['NAME']).'</option>';
991 else
992 $availableProfile .= '<option value="'.$profile['ID'].'" '.$selected.'>'.htmlspecialcharsbx($profile['NAME']).'</option>';
993 }
994
995 $result .= $availableProfile.$unAvailableProfile.'</select>';
996 return $result;
997 }
998
1003 public static function makeDeliveryServiceTree($items)
1004 {
1005 $deliveries = array();
1006 $rootId = array();
1007
1008 foreach ($items as $item)
1009 $deliveries[$item['ID']] = $item;
1010
1011 foreach ($deliveries as $id => $delivery)
1012 {
1013 $className = $deliveries[$delivery['PARENT_ID']]['CLASS_NAME'] ?? null;
1014
1015 if (
1016 $className
1017 && is_callable($className . '::canHasProfiles')
1018 && $className::canHasProfiles()
1019 )
1020 {
1021 continue;
1022 }
1023
1024 if (!empty($delivery['PARENT_ID']))
1025 {
1026 $deliveries[$delivery['PARENT_ID']]['SUBMENU'][$id] = & $deliveries[$id];
1027 }
1028 else
1029 {
1030 $rootId[] = $id;
1031 }
1032 }
1033
1034 $result = [];
1035 foreach ($rootId as $id)
1036 {
1037 $className = $deliveries[$id]['CLASS_NAME'] ?? null;
1038 if (
1039 $className
1040 && is_callable($className.'::canHasChildren')
1041 && $className::canHasChildren()
1042 && !isset($deliveries[$id]['SUBMENU'])
1043 )
1044 {
1045 continue;
1046 }
1047
1048 $result[$id] = $deliveries[$id];
1049 }
1050
1051 return $result;
1052 }
1053
1059 public static function getTemplate($deliveries, $selected = '')
1060 {
1061 $result = '';
1062 $restricted = '';
1063 foreach ($deliveries as $service)
1064 {
1065 $serviceCode = '';
1066 if ($service['ID'] > 0)
1067 $serviceCode = '['.$service['ID'].'] ';
1068
1069 if (isset($service['SUBMENU']) && count($service['SUBMENU']) > 0)
1070 {
1071 $result .= '<optgroup label="'.htmlspecialcharsbx($service['NAME']).'" id="parent_'.$service['ID'].'">';
1072 $subRestricted = '';
1073 foreach ($service['SUBMENU'] as $subService)
1074 {
1075 $subServiceCode = '';
1076 if ($subService['ID'] > 0)
1077 $subServiceCode = '['.$subService['ID'].'] ';
1078
1079 if (isset($subService['RESTRICTED']) && $subService['RESTRICTED'])
1080 {
1081 if ($subService['ID'] == $selected)
1082 $subRestricted .= '<option value="'.$subService['ID'].'" class="bx-admin-service-restricted" data-parent-id="'.$subService['PARENT_ID'].'" selected>'.$subServiceCode.htmlspecialcharsbx(TruncateText($subService['NAME'], 40)).'</option>';
1083 else
1084 $subRestricted .= '<option value="'.$subService['ID'].'" class="bx-admin-service-restricted" data-parent-id="'.$subService['PARENT_ID'].'">'.$subServiceCode.htmlspecialcharsbx(TruncateText($subService['NAME'], 40)).'</option>';
1085 }
1086 else
1087 {
1088 if ($subService['ID'] == $selected)
1089 $result .= '<option value="'.$subService['ID'].'" data-parent-id="'.$subService['PARENT_ID'].'" selected>'.$subServiceCode.htmlspecialcharsbx(TruncateText($subService['NAME'], 40)).'</option>';
1090 else
1091 $result .= '<option value="'.$subService['ID'].'" data-parent-id="'.$subService['PARENT_ID'].'">'.$subServiceCode.htmlspecialcharsbx(TruncateText($subService['NAME'], 40)).'</option>';
1092 }
1093 }
1094 $result .= $subRestricted.'</optgroup>';
1095 }
1096 else
1097 {
1098 if (isset($service['RESTRICTED']) && $service['RESTRICTED'])
1099 {
1100 if ($service['ID'] == $selected)
1101 $restricted .= '<option value="'.$service['ID'].'" class="bx-admin-service-restricted" selected>'.$serviceCode.htmlspecialcharsbx(TruncateText($service['NAME'], 40)).'</option>';
1102 else
1103 $restricted .= '<option value="'.$service['ID'].'" class="bx-admin-service-restricted">'.$serviceCode.htmlspecialcharsbx(TruncateText($service['NAME'], 40)).'</option>';
1104 }
1105 else
1106 {
1107 if ($service['ID'] == $selected)
1108 $result .= '<option value="'.$service['ID'].'" selected>'.$serviceCode.htmlspecialcharsbx(TruncateText($service['NAME'], 40)).'</option>';
1109 else
1110 $result .= '<option value="'.$service['ID'].'">'.$serviceCode.htmlspecialcharsbx(TruncateText($service['NAME'], 40)).'</option>';
1111 }
1112 }
1113
1114 }
1115
1116 return $result.$restricted;
1117 }
1118
1126 public static function getView($shipment, $index = 0, $formType = '')
1127 {
1128 self::$shipment = $shipment;
1129 $data = self::prepareData(false, false);
1130
1131 $result = self::getViewTemplate($data, $index, $formType);
1132
1133 return $result;
1134 }
1135
1143 public static function getViewTemplate($data, $index, $formType)
1144 {
1145 global $USER;
1146 $index++;
1147
1148 $isUserResponsible = null;
1149 $isAllowCompany = null;
1150
1151 if (array_key_exists('IS_USER_RESPONSIBLE', $data))
1152 {
1153 $isUserResponsible = $data['IS_USER_RESPONSIBLE'];
1154 }
1155
1156 if (array_key_exists('IS_ALLOW_COMPANY', $data))
1157 {
1158 $isAllowCompany = $data['IS_ALLOW_COMPANY'];
1159 }
1160
1161 if (self::$backUrl !== '')
1163 else
1164 $backUrl = $_SERVER['REQUEST_URI'];
1165
1166 $allowDeliveryString = ($data['ALLOW_DELIVERY'] == 'Y') ? 'YES' : 'NO';
1167 $deductedString = ($data['DEDUCTED'] == 'Y') ? 'YES' : 'NO';
1168
1169 $allowedStatusesDelivery = DeliveryStatus::getStatusesUserCanDoOperations($USER->GetID(), array('delivery'));
1170 $isAllowDelivery = in_array($data["STATUS_ID"], $allowedStatusesDelivery) && $formType != 'archive' && $formType != 'edit';
1171
1172 $isActive = ($formType != 'edit' && $formType != 'archive') && !$data['ORDER_LOCKED'];
1173
1174 $triangle = ($isActive && $isAllowDelivery) ? '<span class="triangle"> &#9662;</span>' : '';
1175
1176 if ($data['ALLOW_DELIVERY'] == 'Y')
1177 $class = ($isActive && $isAllowDelivery) ? '' : 'class="not_active"';
1178 else
1179 $class = ($isActive && $isAllowDelivery) ? 'class="notdelivery"' : 'class="notdelivery not_active"';
1180
1181 $allowDelivery = '<span><span id="BUTTON_ALLOW_DELIVERY_'.$index.'" '.$class.'>'.Loc::getMessage('SALE_ORDER_SHIPMENT_ALLOW_DELIVERY_'.$allowDeliveryString).'</span>'.$triangle.'</span>';
1182
1183 $allowedStatusesDeduction = DeliveryStatus::getStatusesUserCanDoOperations($USER->GetID(), array('deduction'));
1184 $isAllowDeduction = in_array($data["STATUS_ID"], $allowedStatusesDeduction) && $formType != 'archive' && $formType != 'edit';
1185
1186 $triangle = ($isActive && $isAllowDeduction) ? '<span class="triangle"> &#9662;</span>' : '';
1187
1188 if ($data['DEDUCTED'] == 'Y')
1189 $class = ($isActive && $isAllowDeduction) ? '' : 'class="not_active"';
1190 else
1191 $class = ($isActive && $isAllowDeduction) ? 'class="notdeducted"' : 'class="notdeducted not_active"';
1192 $deducted = '<span><span id="BUTTON_DEDUCTED_'.$index.'" '.$class.'>'.Loc::getMessage('SALE_ORDER_SHIPMENT_DEDUCTED_'.$deductedString).'</span>'.$triangle.'</span>';
1193
1194 $map = ($data['DELIVERY_ID'] > 0) ? self::getMap($data['DELIVERY_ID'], $index, $data['DELIVERY_STORE_ID'], 'view') : '';
1195
1196 $lang = Main\Application::getInstance()->getContext()->getLanguage();
1197 $service = null;
1198 $extraServiceHTML = '';
1199 $mainLogoPath = '/bitrix/images/sale/logo-default-d.gif';
1200 $shortLogoPath = '/bitrix/images/sale/logo-default-d.gif';
1201
1202 if (($isAllowCompany !== false || $isUserResponsible !== false) && $data['DELIVERY_ID'] > 0)
1203 {
1204 $service = Services\Manager::getObjectById($data['DELIVERY_ID']);
1205 $extraServiceManager = new \Bitrix\Sale\Delivery\ExtraServices\Manager($data['DELIVERY_ID']);
1206 $extraServiceManager->setOperationCurrency($data['CURRENCY']);
1207 if ($data['EXTRA_SERVICES'])
1208 $extraServiceManager->setValues($data['EXTRA_SERVICES']);
1209
1210 if ($service && $service->getLogotip() > 0)
1211 {
1212 $mainLogo = self::getMainImgPath($service->getLogotip());
1213 $shortLogo = self::getShortImgPath($service->getLogotip());
1214 $mainLogoPath = $mainLogo['src'];
1215 $shortLogoPath = $shortLogo['src'];
1216 }
1217
1218 $extraService = $extraServiceManager->getItems();
1219 if ($extraService)
1220 $extraServiceHTML = self::getExtraServiceEditControl($extraService, $index, true, self::$shipment);
1221 }
1222
1223 $companyList = OrderEdit::getCompanyList();
1224 $shipmentStatusList = OrderShipmentStatus::getShipmentStatusList($data['STATUS_ID']);
1225 $jsShipmentStatus = array();
1226 foreach ($shipmentStatusList as $id => $name)
1227 {
1228 $jsShipmentStatus[] = array(
1229 'ID' => $id,
1230 'NAME' => htmlspecialcharsbx($name)
1231 );
1232 }
1233
1234 $allowedStatusesFrom = DeliveryStatus::getStatusesUserCanDoOperations($USER->GetID(), array('from'));
1235 $canChangeStatus = in_array($data["STATUS_ID"], $allowedStatusesFrom) && $formType != 'archive' && $formType != 'edit';
1236 $triangle = ($isActive && $canChangeStatus) ? '<span class="triangle"> &#9662;</span>' : '';
1237
1238 $class = ($isActive && $canChangeStatus) ? '' : 'class="not_active"';
1239 $shipmentStatus = '<span><span id="BUTTON_SHIPMENT_' . $index . '" '.$class.'>' . htmlspecialcharsbx($shipmentStatusList[$data['STATUS_ID']]) . '</span>'.$triangle.'</span>';
1240
1241 $shippingBlockId = '';
1242 if(($isAllowCompany !== false || $isUserResponsible !== false) && ($isActive || $data['TRACKING_NUMBER'] <> ''))
1243 {
1244 $shippingBlockId = '<tr>
1245 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_TRACKING_NUMBER').':</td>
1246 <td class="adm-detail-content-cell-r tal">
1247 <input type="text" id="TRACKING_NUMBER_'.$index.'_EDIT" name="SHIPMENT['.$index.'][TRACKING_NUMBER]" style="display: none;" value="'.htmlspecialcharsbx($data['TRACKING_NUMBER']).'">
1248 <span id="TRACKING_NUMBER_'.$index.'_VIEW">'.htmlspecialcharsbx($data['TRACKING_NUMBER']).'</span>';
1249 if ($isActive)
1250 $shippingBlockId .= '<div class="bx-adm-edit-pencil" id="TRACKING_NUMBER_PENCIL_'.$index.'"></div>';
1251
1252 if($data['HAS_TRACKING'] && $data['TRACKING_NUMBER'] <> '')
1253 {
1254 $shippingBlockId .= '</td></tr>
1255 <tr>
1256 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_TRACKING_STATUS').':</td>
1257 <td class="adm-detail-content-cell-r tal">'.
1258 '<span id="sale-order-shipment-tracking-status-'.$index.'">'.(intval($data['TRACKING_STATUS']) >= 0 ? \Bitrix\Sale\Delivery\Tracking\Manager::getStatusName($data['TRACKING_STATUS']) : '-').'</span>'.
1259 '&nbsp;&nbsp;&nbsp;[<span onclick="BX.Sale.Admin.GeneralShipment.refreshTrackingStatus(\''.$index.'\', \''.$data['ID'].'\');" style="border-bottom: 1px dashed #2675d7; cursor: pointer; color: #2675d7;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_TRACKING_STATUS_REFRESH').'</span>]<br></td>
1260 </tr>
1261 <tr>
1262 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_TRACKING_DESCRIPTION').':</td>
1263 <td class="adm-detail-content-cell-r tal" id="sale-order-shipment-tracking-description-'.$index.'">'.($data['TRACKING_DESCRIPTION'] <> '' ? $data['TRACKING_DESCRIPTION'] : '-').'<br></td>
1264 <tr>
1265 <tr>
1266 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_TRACKING_LAST_CHANGE').':</td>
1267 <td class="adm-detail-content-cell-r tal" id="sale-order-shipment-tracking-last-change-'.$index.'">'.($data['TRACKING_LAST_CHANGE'] <> '' ? $data['TRACKING_LAST_CHANGE'] : '-').'<br></td>
1268 <tr>';
1269
1270 if(!empty($data['TRACKING_URL']))
1271 {
1272 $shippingBlockId .= '<tr>
1273 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_TRACKING_URL').':</td>
1274 <td class="adm-detail-content-cell-r tal" id="sale-order-shipment-tracking-url-'.$index.'"><a href="'.$data['TRACKING_URL'].'">'.$data['TRACKING_URL'].'</a><br></td>
1275 <tr>';
1276 }
1277 }
1278 }
1279
1280 $shippingBlockDocNum = '';
1281 if (($isAllowCompany !== false || $isUserResponsible !== false) && $data['DELIVERY_DOC_NUM'] <> '')
1282 {
1283 $shippingBlockDocNum = '<tr>
1284 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_DOC_NUM').':</td>
1285 <td class="adm-detail-content-cell-r tal">
1286 ' . htmlspecialcharsbx($data['DELIVERY_DOC_NUM']) . '
1287 </td>
1288 </tr>';
1289 }
1290
1291 $shippingBlockDocDate = '';
1292 if (($isAllowCompany !== false || $isUserResponsible !== false) && $data['DELIVERY_DOC_DATE'] <> '')
1293 {
1294 $shippingBlockDocDate = '<tr>
1295 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_DOC_DATE').':</td>
1296 <td class="adm-detail-content-cell-r tal">
1297 ' . htmlspecialcharsbx($data['DELIVERY_DOC_DATE']) . '
1298 </td>
1299 </tr>';
1300 }
1301
1302 $dateInsert = new Date($data['DATE_INSERT']);
1303
1304 $checkLink = '';
1305 if ($data['FFD_105_ENABLED'] === 'Y')
1306 {
1307 $checkLink .= '<tr><td class="tac" id="SHIPMENT_CHECK_LIST_ID_'.$data['ID'].'">';
1308 if (!empty($data['CHECK']))
1309 {
1310 $checkLink .= OrderShipment::buildCheckHtml($data['CHECK']);
1311 }
1312 $checkLink .= "</td></tr>";
1313 if($formType != 'archive' && $data['HAS_ENABLED_CASHBOX'] === 'Y' && $data['CAN_PRINT_CHECK'] === 'Y')
1314 {
1315 $checkLink .= '<tr><td class="adm-detail-content-cell-r tac"><a href="javascript:void(0);" onclick="BX.Sale.Admin.OrderShipment.prototype.showCreateCheckWindow('.$data['ID'].');">'.Loc::getMessage('SALE_ORDER_SHIPMENT_CHECK_ADD').'</a></td></tr>';
1316 }
1317 }
1318
1319 $sectionDelete = '';
1320 $allowedDeliveryStatusesDelete = DeliveryStatus::getStatusesUserCanDoOperations($USER->GetID(), array('delete'));
1321 if (in_array($data["STATUS_ID"], $allowedDeliveryStatusesDelete) && !$data['ORDER_LOCKED'] && $formType != 'archive')
1322 $sectionDelete = '<div class="adm-bus-pay-section-action" id="SHIPMENT_SECTION_'.$index.'_DELETE">'.Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_SHIPMENT_DELETE').'</div>';
1323
1324 $sectionEdit = '';
1325 $allowedOrderStatusesUpdate = DeliveryStatus::getStatusesUserCanDoOperations($USER->GetID(), array('update'));
1326 if (in_array($data["STATUS_ID"], $allowedOrderStatusesUpdate) && !$data['ORDER_LOCKED'] && $formType != 'archive')
1327 {
1328 $sectionEdit = '<div class="adm-bus-pay-section-action" id="SHIPMENT_SECTION_'.$index.'_EDIT">'.
1329 static::renderShipmentEditLink($data+['backurl'=>$backUrl]).
1330 Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_SHIPMENT_EDIT').'</a></div>';
1331 }
1332
1333 $weightView = roundEx(
1334 floatval(
1335 $data['WEIGHT']/self::getWeightKoef($data['SITE_ID'])
1336 ),
1337 SALE_WEIGHT_PRECISION
1338 )." ".self::getWeightUnit($data['SITE_ID']);
1339
1340 $result = '
1341 <input type="hidden" name="SHIPMENT['.$index.'][DEDUCTED]" id="STATUS_DEDUCTED_'.$index.'" value="'.($data['DEDUCTED'] == "" ? "N" : $data['DEDUCTED']).'">
1342 <input type="hidden" name="SHIPMENT['.$index.'][ALLOW_DELIVERY]" id="STATUS_ALLOW_DELIVERY_'.$index.'" value="'.($data['ALLOW_DELIVERY'] == "" ? "N" : $data['ALLOW_DELIVERY']).'">
1343 <input type="hidden" name="SHIPMENT['.$index.'][STATUS_ID]" id="STATUS_SHIPMENT_'.$index.'" value="'.$data['STATUS_ID'].'">
1344 <div class="adm-bus-pay" id="shipment_container_'.$index.'">
1345 <input type="hidden" name="SHIPMENT['.$index.'][SHIPMENT_ID]" id="SHIPMENT_ID_'.$index.'" value="'.$data['ID'].'">
1346 <div class="adm-bus-component-content-container">
1347 <div class="adm-bus-pay-section">
1348 <div class="adm-bus-pay-section-title-container">
1349 <div class="adm-bus-pay-section-title" id="shipment_'.$data['ID'].'">'.Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_EDIT_SHIPMENT_TITLE', array("#ID#" => $data['ID'], '#DATE_INSERT#' => $dateInsert)).'</div>
1350 <div class="adm-bus-pay-section-action-block">'.$sectionDelete.$sectionEdit.'
1351 <div class="adm-bus-pay-section-action" id="SHIPMENT_SECTION_'.$index.'_TOGGLE">'.Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_SHIPMENT_TOGGLE_UP').'</div>
1352 </div>
1353 </div>
1354 <div class="adm-bus-pay-section-content" id="SHIPMENT_SECTION_'.$index.'" style="display:none;">
1355 <div class="adm-bus-pay-section-sidebar">
1356 <div style="background: url(\''.$mainLogoPath.'\')" id="delivery_service_logo_'.$index.'" class="adm-shipment-block-logo"></div>
1357 '.$map.'
1358 </div>
1359 <div class="adm-bus-pay-section-right">
1360 <div class="adm-bus-table-container caption border">
1361 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_SERVICE').'</div>
1362 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
1363 <tbody>
1364 <tr>
1365 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_SERVICE').':</td>
1366 <td class="adm-detail-content-cell-r">
1367 '.(($isAllowCompany === false && $isUserResponsible === false) ? Loc::getMessage('SALE_ORDER_SHIPMENT_HIDDEN') : htmlspecialcharsbx($data['DELIVERY_NAME']).' ['.$data['DELIVERY_ID'].']'). '
1368 </td>
1369 </tr>
1370 </tbody>
1371 </table>
1372 </div>
1373 <div class="adm-bus-table-container caption border">
1374 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_BLOCK_PRICE').'</div>
1375 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table">
1376 <tbody>
1377 <tr style="display: none;">
1378 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_SUM_PRICE').':</td>
1379 <td class="adm-detail-content-cell-r tal">
1380 '.SaleFormatCurrency(floatval($data['BASE_PRICE_DELIVERY']), $data['CURRENCY']).'
1381 </td>
1382 </tr>
1383 <tr id="sale-order-shipment-discounts-row-'.$index.'" style="display: none;">
1384 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DISCOUNT').':</td>
1385 <td class="adm-detail-content-cell-r tal" id="sale-order-shipment-discounts-container-'.$index.'"></td>
1386 </tr>
1387 <tr>
1388 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_SUM_DISCOUNT_PRICE').':</td>
1389 <td class="adm-detail-content-cell-r tal" id="PRICE_DELIVERY_'.$index.'">'.SaleFormatCurrency(floatval($data['PRICE_DELIVERY']), $data['CURRENCY']).'<br></td>
1390 </tr>
1391 </tbody>
1392 </table>
1393 </div>
1394 <div class="adm-bus-table-container caption border">
1395 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_BLOCK_WEIGHT').'</div>
1396 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table">
1397 <tbody>
1398 <tr>
1399 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_WEIGHT').':</td>
1400 <td class="adm-detail-content-cell-r tal" id="WEIGHT_DELIVERY_'.$index.'">'.$weightView.'<br></td>
1401 </tr>
1402 </tbody>
1403 </table>
1404 </div>
1405 <div class="adm-bus-table-container caption border">
1406 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_SHIPMENT').'</div>
1407 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
1408 <tbody>
1409 <tr>
1410 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_OFFICE').':</td>
1411 <td class="adm-detail-content-cell-r">
1412 '.(($isAllowCompany === false && $isUserResponsible === false) ? Loc::getMessage('SALE_ORDER_SHIPMENT_HIDDEN') : (isset($companyList[$data['COMPANY_ID']]) ? htmlspecialcharsbx($companyList[$data['COMPANY_ID']]) : Loc::getMessage('SALE_ORDER_SHIPMENT_NO_COMPANY'))).'
1413 </td>
1414 </tr>
1415 </tbody>
1416 </table>
1417 </div>';
1418 if ($checkLink)
1419 {
1420 $result .= '<div class="adm-bus-table-container caption border" style="padding-top:10px;">
1421 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_CHECK_LINK_TITLE').'</div>
1422 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table">
1423 <tbody>
1424 '.$checkLink.'
1425 </tbody>
1426 </table>
1427 </div>';
1428 }
1429 $result .= '<div class="adm-bus-table-container caption border">
1430 <div class="adm-bus-moreInfo_part1">
1431 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_STATUS').'</div>
1432 <table class="adm-detail-content-table edit-table" border="0" width="100%" cellpadding="0" cellspacing="0">
1433 <tbody>
1434 <tr>
1435 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_ALLOW_DELIVERY').':</td>
1436 <td class="adm-detail-content-cell-r delivery-status">'.$allowDelivery.'</td>
1437 </tr>
1438 '.((!empty($data['EMP_ALLOW_DELIVERY_ID'])) ? '
1439 <tr>
1440 <td class="adm-detail-content-cell-l vat" width="40%"></td>
1441 <td class="adm-detail-content-cell-r">
1442 <div>'.Loc::getMessage('SALE_ORDER_SHIPMENT_MODIFY_BY').': <span style="color: #66878F" id="order_additional_info_date_responsible">'.htmlspecialcharsbx($data['DATE_ALLOW_DELIVERY']).'</span> <a href="/bitrix/admin/user_edit.php?lang='.$lang.'&ID='.$data['EMP_ALLOW_DELIVERY_ID'].'" id="order_additional_info_emp_responsible">'.htmlspecialcharsbx($data['EMP_ALLOW_DELIVERY_ID_LAST_NAME']).' '.htmlspecialcharsbx($data['EMP_ALLOW_DELIVERY_ID_NAME']).'</a></div>
1443 </td>
1444 </tr>
1445 ' : '').'
1446 <tr>
1447 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DEDUCTED').':</td>
1448 <td class="adm-detail-content-cell-r"><div class="delivery-status">'.$deducted.'</div></td>
1449 </tr>
1450 '.((!empty($data['EMP_DEDUCTED_ID'])) ? '
1451 <tr>
1452 <td class="adm-detail-content-cell-l vat" width="40%"></td>
1453 <td class="adm-detail-content-cell-r">
1454 <div>'.Loc::getMessage('SALE_ORDER_SHIPMENT_MODIFY_BY').': <span style="color: #66878F" id="order_additional_info_date_responsible">'.htmlspecialcharsbx($data['DATE_DEDUCTED']).'</span> <a href="/bitrix/admin/user_edit.php?lang='.$lang.'&ID='.$data['EMP_DEDUCTED_ID'].'" id="order_additional_info_emp_responsible">'.htmlspecialcharsbx($data['EMP_DEDUCTED_ID_LAST_NAME']).' '.htmlspecialcharsbx($data['EMP_DEDUCTED_ID_NAME']).'</a></div>
1455 </td>
1456 </tr>
1457 ' : '').'
1458 <tr>
1459 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_DOC_STATUS').':</td>
1460 <td class="adm-detail-content-cell-r">
1461 <div class="shipment-status">
1462 '.$shipmentStatus.'
1463 </div>
1464 </td>
1465 </tr>
1466 </tbody>
1467 </table>
1468 </div>
1469 </div>';
1470
1471 if (!empty($shippingBlockId) || !empty($shippingBlockDocNum) || !empty($shippingBlockDocDate) || !empty($extraServiceHTML))
1472 {
1473 $result .= '<div class="adm-bus-table-container caption border">
1474 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_DELIVERY_INFO').'</div>
1475 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
1476 <tbody>
1477 ' . $shippingBlockId . $shippingBlockDocNum . $shippingBlockDocDate . '
1478 </tbody>
1479 </table>
1480 <div id="DELIVERY_INFO_' . $index . '">
1481 ' . $extraServiceHTML . '
1482 </div>
1483 </div>';
1484 }
1485
1486 if(!empty($data['DELIVERY_REQUEST_NAME']) || !empty($data['DELIVERY_REQUEST_ERROR_DESCRIPTION']))
1487 {
1488 $result .= '<div class="adm-bus-table-container caption border">
1489 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DEL_REQ_INFO').'</div>
1490 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
1491 <tbody>';
1492
1493 if(!empty($data['DELIVERY_REQUEST_NAME']))
1494 {
1495 $result .= '<tr>
1496 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DEL_REQ').':</td>
1497 <td class="adm-detail-content-cell-r"><a href="'.$data['DELIVERY_REQUEST_LINK'].'"">'.$data['DELIVERY_REQUEST_NAME'].'</a></td>
1498 </tr>';
1499 }
1500
1501 if(!empty($data['DELIVERY_REQUEST_ERROR_DESCRIPTION']))
1502 {
1503 $result .= '<tr>
1504 <td valign="top" class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DEL_REQ_ERROR').':</td>
1505 <td class="adm-detail-content-cell-r">'.$data['DELIVERY_REQUEST_ERROR_DESCRIPTION'].'</td>
1506 </tr>';
1507 }
1508
1509 $result.='
1510 </tbody>
1511 </table>
1512 </div>';
1513 }
1514
1515 if(is_array($data['DELIVERY_ADDITIONAL_INFO_VIEW']) && !empty($data['DELIVERY_ADDITIONAL_INFO_VIEW']))
1516 {
1517 $result .= '<div class="adm-bus-table-container caption border">
1518 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_SHIPMENT_BLOCK_DELIVERY_ADDITIONAL').'</div>
1519 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
1520 <tbody><tr>';
1521
1522 foreach($data['DELIVERY_ADDITIONAL_INFO_VIEW'] as $name => $params)
1523 {
1524 $result .='
1525 <td class="adm-detail-content-cell-l" width="40%">'.$params['LABEL'].':</td>
1526 <td class="adm-detail-content-cell-r" width="60%">
1527 '.\Bitrix\Sale\Internals\Input\Manager::getViewHtml($params).'
1528 </td>';
1529 }
1530
1531 $result .= ' </tr></tbody>
1532 </table>
1533 </div>';
1534 }
1535
1536 $result .= '</div>
1537 <div class="clb"></div>
1538 <div class="adm-s-order-shipment-basket-structure">'.Loc::getMessage('SALE_ORDER_SHIPMENT_BASKET').'</div>';
1539
1540 $shipmentBasket = new OrderBasketShipment(self::$shipment, "BX.Sale.Admin.ShipmentBasketObj_".$index, "shipment_basket_".$index);
1541 $result .= $shipmentBasket->getView($index);
1542
1543 $result .='</div>';
1544
1545 $result .= self::getShortViewTemplate($data, $index, $shortLogoPath, $formType);
1546 $result .= '</div>
1547 </div>
1548 </div>';
1549
1550 $params = array(
1551 'index' => $index,
1552 'canAllow' => $isAllowDelivery,
1553 'canDeduct' => $isAllowDeduction,
1554 'canChangeStatus' => $canChangeStatus,
1555 'id' => (int)$data['ID'],
1556 'extra_service' => array(),
1557 'shipment_statuses' => $jsShipmentStatus,
1558 'isAjax' => true,
1559 'active' => $isActive,
1560 'discounts' => $data["DISCOUNTS"],
1561 'discountsMode' => ($formType == "edit" ? "edit" : "view"),
1562 'templateType' => 'view',
1563 'weightKoef' => self::getWeightKoef($data['SITE_ID']),
1564 'weightUnit' => self::getWeightUnit($data['SITE_ID'])
1565 );
1566
1567 $result .= self::initJsShipment($params);
1568
1569 return $result;
1570 }
1571
1572 protected static function renderShipmentEditLink($data)
1573 {
1574 $backUrl = $data['backurl'];
1575 $href = Link::getInstance()
1576 ->create()
1577 ->setPageByType(Registry::SALE_ORDER_SHIPMENT_EDIT)
1578 ->setFilterParams(false)
1579 ->fill()
1580 ->setField('order_id', $data['ORDER_ID'])
1581 ->setField('shipment_id', $data['ID'])
1582 ->setField('backurl', $backUrl)
1583 ->build();
1584
1585 return '<a href="'.$href.'">';
1586 }
1587
1588 private static function getShortViewTemplate($data, $index, $logo, $formType)
1589 {
1590 global $USER;
1591
1592 $isUserResponsible = null;
1593 $isAllowCompany = null;
1594
1595 if (array_key_exists('IS_USER_RESPONSIBLE', $data))
1596 {
1597 $isUserResponsible = $data['IS_USER_RESPONSIBLE'];
1598 }
1599
1600 if (array_key_exists('IS_ALLOW_COMPANY', $data))
1601 {
1602 $isAllowCompany = $data['IS_ALLOW_COMPANY'];
1603 }
1604
1605 $allowDeliveryString = ($data['ALLOW_DELIVERY'] == 'Y') ? 'YES' : 'NO';
1606 $deductedString = ($data['DEDUCTED'] == 'Y') ? 'YES' : 'NO';
1607
1608 $allowedStatusesDelivery = DeliveryStatus::getStatusesUserCanDoOperations($USER->GetID(), array('delivery'));
1609 $isAllowDelivery = in_array($data["STATUS_ID"], $allowedStatusesDelivery) && $formType != 'archive' && $formType != 'edit';
1610
1611 $isActive = ($formType != 'edit' && $formType != 'archive') && !$data['ORDER_LOCKED'];
1612 $triangle = ($isActive && $isAllowDelivery) ? '<span class="triangle"> &#9662;</span>' : '';
1613
1614 if ($data['ALLOW_DELIVERY'] == 'Y')
1615 $class = ($isActive && $isAllowDelivery) ? '' : 'class="not_active"';
1616 else
1617 $class = ($isActive && $isAllowDelivery) ? 'class="notdelivery"' : 'class="notdelivery not_active"';
1618
1619 $allowDelivery = '<span><span id="BUTTON_ALLOW_DELIVERY_SHORT_'.$index.'" '.$class.'>'.Loc::getMessage('SALE_ORDER_SHIPMENT_ALLOW_DELIVERY_'.$allowDeliveryString).'</span>'.$triangle.'</span>';
1620
1621 $allowedStatusesDeduction = DeliveryStatus::getStatusesUserCanDoOperations($USER->GetID(), array('deduction'));
1622 $isAllowDeduction = in_array($data["STATUS_ID"], $allowedStatusesDeduction) && $formType != 'archive' && $formType != 'edit';
1623
1624 $triangle = ($isActive && $isAllowDeduction) ? '<span class="triangle"> &#9662;</span>' : '';
1625
1626 if ($data['DEDUCTED'] == 'Y')
1627 $class = ($isActive && $isAllowDeduction) ? '' : 'class="not_active"';
1628 else
1629 $class = ($isActive && $isAllowDeduction) ? 'class="notdeducted"' : 'class="notdeducted not_active"';
1630 $deducted = '<span><span id="BUTTON_DEDUCTED_SHORT_'.$index.'" '.$class.'>'.Loc::getMessage('SALE_ORDER_SHIPMENT_DEDUCTED_'.$deductedString).'</span>'.$triangle.'</span>';
1631
1632 $shipmentStatusList = OrderShipmentStatus::getShipmentStatusList($data['STATUS_ID']);
1633
1634 $allowedStatusesFrom = DeliveryStatus::getStatusesUserCanDoOperations($USER->GetID(), array('from'));
1635 $canChangeStatus = in_array($data["STATUS_ID"], $allowedStatusesFrom) && $formType != 'archive' && $formType != 'edit';
1636 $triangle = ($isActive && $canChangeStatus) ? '<span class="triangle"> &#9662;</span>' : '';
1637
1638 $class = ($isActive && $canChangeStatus) ? '' : 'class="not_active"';
1639 $shipmentStatus = '<span><span id="BUTTON_SHIPMENT_SHORT_' . $index . '" '.$class.'>' . htmlspecialcharsbx($shipmentStatusList[$data['STATUS_ID']]) . '</span>'.$triangle.'</span>';
1640
1641 $checkLink = '';
1642 if ($data['FFD_105_ENABLED'] === 'Y' &&
1643 (
1644 ($formType != 'archive' && $data['HAS_ENABLED_CASHBOX'] === 'Y' && $data['CAN_PRINT_CHECK'] === 'Y') ||
1645 !empty($data['CHECK'])
1646 )
1647 )
1648 {
1649 $checkLink = '<td class="adm-detail-content-cell-l vat">'.Loc::getMessage('SALE_ORDER_SHIPMENT_CHECK_LINK_TITLE').':</td><td class="adm-detail-content-cell-l vat">';
1650 $checkLink .= '<div id="SHIPMENT_CHECK_LIST_ID_SHORT_VIEW'.$data['ID'].'">';
1651 if (!empty($data['CHECK']))
1652 {
1653 $checkLink .= OrderShipment::buildCheckHtml($data['CHECK']);
1654 }
1655 $checkLink .= "</div>";
1656 if ($formType != 'archive' && $data['HAS_ENABLED_CASHBOX'] === 'Y' && $data['CAN_PRINT_CHECK'] === 'Y')
1657 {
1658 $checkLink .= '<div><a href="javascript:void(0);" onclick="BX.Sale.Admin.OrderShipment.prototype.showCreateCheckWindow('.$data['ID'].');">'.Loc::getMessage('SALE_ORDER_SHIPMENT_CHECK_ADD').'</a></div>';
1659 }
1660 $checkLink .='</td>';
1661 }
1662
1663 $result = '<div class="adm-bus-pay-section-content" id="SHIPMENT_SECTION_SHORT_'.$index.'">
1664 <table class="adm-detail-content-table edit-table" border="0" width="100%" cellpadding="0" cellspacing="0">
1665 <tbody>
1666 <tr class="adm-shipment-block-short-info">
1667 <td class="adm-detail-content-cell-l vat">
1668 <div style="background: url(\''.$logo.'\')" id="delivery_service_short_logo_'.$index.'" class="adm-shipment-block-short-logo"></div>
1669 </td>
1670 <td class="adm-detail-content-cell-l vat">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_SERVICE').': <span>'.(($isAllowCompany === false && $isUserResponsible === false) ? Loc::getMessage('SALE_ORDER_SHIPMENT_HIDDEN') : htmlspecialcharsbx($data['DELIVERY_NAME'])).'</span></td>
1671 <td class="adm-detail-content-cell-l vat"><div class="delivery-status">'.Loc::getMessage('SALE_ORDER_SHIPMENT_ALLOW_DELIVERY').': '.$allowDelivery.'</div></td>
1672 <td class="adm-detail-content-cell-l vat"><div class="deducted-status">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DEDUCTED').': '.$deducted.'</div></td>
1673 <td class="adm-detail-content-cell-l vat"><div class="shipment-status">'.Loc::getMessage('SALE_ORDER_SHIPMENT_DELIVERY_STATUS').': '.$shipmentStatus.'</div></td>
1674 '.$checkLink.'
1675 </tr>
1676 </tbody>
1677 </table>
1678 <div class="clb"></div>
1679 </div>';
1680
1681
1682 return $result;
1683 }
1684
1685 public static function createNewShipmentButton($params=[])
1686 {
1687 return '<input type="button" class="adm-order-block-add-button" onclick="BX.Sale.Admin.GeneralShipment.createNewShipment(this,'.\CUtil::PhpToJSObject($params).')" value = "'.Loc::getMessage('SALE_ORDER_SHIPMENT_ADD_SHIPMENT').'">';
1688 }
1689
1695 protected static function prepareData($error = false, $needRecalculate = true)
1696 {
1697 global $USER, $APPLICATION;
1698 static $users = array();
1699 static $userCompanyList = array();
1700
1701 $result = array();
1702 if ($error)
1703 {
1704 $fields = self::$defaultFields;
1705 }
1706 else
1707 {
1708 $fields = self::$shipment->getFieldValues();
1709 $fields['DELIVERY_STORE_ID'] = self::$shipment->getStoreId();
1710 $fields["EXTRA_SERVICES"] = self::$shipment->getExtraServices();
1711 $fields["STORE"] = self::$shipment->getStoreId();
1712 }
1713
1715 $order = self::$shipment->getCollection()->getOrder();
1716
1717 $saleModulePermissions = $APPLICATION->GetGroupRight("sale");
1718
1719 if($saleModulePermissions == "P")
1720 {
1721 if (empty($userCompanyList))
1722 {
1723 $userCompanyList = Company\Manager::getUserCompanyList($USER->GetID());
1724 }
1725
1726 $isUserResponsible = false;
1727 if ($order->getField('RESPONSIBLE_ID') == $USER->GetID()
1728 || ($fields['RESPONSIBLE_ID'] == $USER->GetID()))
1729 {
1730 $isUserResponsible = true;
1731 }
1732
1733 $isAllowCompany = in_array(self::$shipment->getField('COMPANY_ID'), $userCompanyList) || in_array($order->getField('COMPANY_ID'), $userCompanyList);
1734
1735 $fields['IS_USER_RESPONSIBLE'] = $isUserResponsible;
1736 $fields['IS_ALLOW_COMPANY'] = $isAllowCompany;
1737
1738 if (!$isUserResponsible && !$isAllowCompany)
1739 {
1740 foreach ($fields as $fieldName => $fieldValue)
1741 {
1742 if (in_array($fieldName, static::getDisallowFields()))
1743 {
1744 unset($fields[$fieldName]);
1745 }
1746 }
1747 }
1748 }
1749
1750 if (!empty($fields['DELIVERY_DOC_DATE']))
1751 {
1752 $date = new Date($fields['DELIVERY_DOC_DATE']);
1753 $fields['DELIVERY_DOC_DATE'] = $date->toString();
1754 }
1755
1756 $empDeductedId = (int)($fields['EMP_DEDUCTED_ID'] ?? 0);
1757 if ($empDeductedId > 0)
1758 {
1759 if (!array_key_exists($empDeductedId, $users))
1760 $users[$empDeductedId] = $USER->GetByID($empDeductedId)->Fetch();
1761 $fields['EMP_DEDUCTED_ID_NAME'] = $users[$empDeductedId]['NAME'];
1762 $fields['EMP_DEDUCTED_ID_LAST_NAME'] = $users[$empDeductedId]['LAST_NAME'];
1763 }
1764
1765 $empAllowDeliveryId = (int)($fields['EMP_ALLOW_DELIVERY_ID'] ?? 0);
1766 if ($empAllowDeliveryId > 0)
1767 {
1768 if (!array_key_exists($empAllowDeliveryId, $users))
1769 $users[$empAllowDeliveryId] = $USER->GetByID($empAllowDeliveryId)->Fetch();
1770 $fields['EMP_ALLOW_DELIVERY_ID_NAME'] = $users[$empAllowDeliveryId]['NAME'];
1771 $fields['EMP_ALLOW_DELIVERY_ID_LAST_NAME'] = $users[$empAllowDeliveryId]['LAST_NAME'];
1772 }
1773
1774 $empCanceledId = (int)($fields['EMP_CANCELED_ID'] ?? 0);
1775 if ($empCanceledId > 0)
1776 {
1777 if (!array_key_exists($empCanceledId, $users))
1778 $users[$empCanceledId] = $USER->GetByID($empCanceledId)->Fetch();
1779 $fields['EMP_CANCELLED_ID_NAME'] = $users[$empCanceledId]['NAME'];
1780 $fields['EMP_CANCELLED_ID_LAST_NAME'] = $users[$empCanceledId]['LAST_NAME'];
1781 }
1782
1783 $empMarkedId = (int)($fields['EMP_MARKED_ID'] ?? 0);
1784 if ($empMarkedId > 0)
1785 {
1786 if (!array_key_exists($empMarkedId, $users))
1787 $users[$empMarkedId] = $USER->GetByID($empMarkedId)->Fetch();
1788 $fields['EMP_MARKED_ID_NAME'] = $users[$empMarkedId]['NAME'];
1789 $fields['EMP_MARKED_ID_LAST_NAME'] = $users[$empMarkedId]['LAST_NAME'];
1790 }
1791 $fields['CURRENCY'] = $order->getCurrency();
1792
1793 if ($needRecalculate)
1794 {
1795 $calcResult = self::calculateDeliveryPrice(self::$shipment);
1796 if ($calcResult->isSuccess())
1797 $fields['CALCULATED_PRICE'] = $calcResult->getPrice();
1798 }
1799
1800 $fields['CALCULATED_WEIGHT'] = self::$shipment->getShipmentItemCollection()->getWeight() / self::getWeightKoef($order->getSiteId());
1801
1802 if (
1803 isset($fields['CUSTOM_PRICE_DELIVERY'])
1804 && $fields['CUSTOM_PRICE_DELIVERY'] === 'Y'
1805 && $fields['ID'] <= 0
1806 )
1807 {
1808 $fields['BASE_PRICE_DELIVERY'] = self::$shipment->getField('BASE_PRICE_DELIVERY');
1809 }
1810
1811 $discounts = OrderEdit::getDiscountsApplyResult($order, $needRecalculate);
1812
1813 if ($order instanceof \Bitrix\Sale\Archive\Order)
1814 {
1815 $shipmentIds = $discounts['SHIPMENTS_ID'];
1816 }
1817 else
1818 {
1819 $shipmentIds = $order->getDiscount()->getShipmentsIds();
1820 }
1821
1822 foreach ($shipmentIds as $shipmentId)
1823 {
1824 if ($shipmentId == self::$shipment->getId())
1825 $fields['DISCOUNTS'] = $discounts;
1826 }
1827
1829 $delivery = self::$shipment->getDelivery();
1830
1831 if(!is_null($delivery))
1832 {
1833 $fields['HAS_TRACKING'] = $delivery->getTrackingClass() <> '' ? true : false;
1834
1835 if($fields['HAS_TRACKING'] && intval($fields['DELIVERY_ID']) > 0)
1836 {
1837 $trackingManager = \Bitrix\Sale\Delivery\Tracking\Manager::getInstance();
1838 $fields['TRACKING_URL'] = $trackingManager->getTrackingUrl($fields['DELIVERY_ID'], $fields['TRACKING_NUMBER']);
1839 }
1840
1841 $fields['DELIVERY_ADDITIONAL_INFO_EDIT'] = $delivery->getAdditionalInfoShipmentEdit(self::$shipment);
1842 $fields['DELIVERY_ADDITIONAL_INFO_VIEW'] = $delivery->getAdditionalInfoShipmentView(self::$shipment);
1843 }
1844
1845 $res = Requests\ShipmentTable::getList(array(
1846 'filter' => array('=SHIPMENT_ID' => self::$shipment->getId()),
1847 'select' => array(
1848 '*',
1849 'REQUEST_DATE' => 'REQUEST.DATE'
1850 )
1851 ));
1852
1853 if($request = $res->fetch())
1854 {
1855 if(intval($request['REQUEST_ID']) > 0)
1856 {
1857 $fields['DELIVERY_REQUEST_NAME'] = Loc::getMessage(
1858 'SALE_ORDER_SHIPMENT_DEL_REQ_NAME',
1859 array(
1860 '#REQUEST_ID#' => $request['REQUEST_ID'],
1861 '#REQUEST_DATE#' => $request['REQUEST_DATE']->format(\Bitrix\Main\Type\Date::getFormat())
1862 ));
1863 $fields['DELIVERY_REQUEST_LINK'] = '/bitrix/admin/sale_delivery_request_view.php?lang='.LANGUAGE_ID.'&ID='.intval($request['REQUEST_ID']);
1864 }
1865
1866 $sanitizer = new \CBXSanitizer;
1867 $sanitizer->SetLevel(\CBXSanitizer::SECURE_LEVEL_MIDDLE);
1868
1869 if($request['ERROR_DESCRIPTION'] <> '')
1870 $fields['DELIVERY_REQUEST_ERROR_DESCRIPTION'] = $sanitizer->SanitizeHtml($request['ERROR_DESCRIPTION']);
1871 }
1872
1873 $fields['FFD_105_ENABLED'] = Cashbox\Manager::isSupportedFFD105() ? 'Y' : 'N';
1874 if ($fields['FFD_105_ENABLED'] === 'Y')
1875 {
1876 $fields['CHECK'] = Cashbox\CheckManager::getCheckInfo(self::$shipment);
1877 }
1878
1879 $dbRes = CashboxTable::getList(array('filter' => array('=ACTIVE' => 'Y', '=ENABLED' => 'Y')));
1880 $fields['HAS_ENABLED_CASHBOX'] = ($dbRes->fetch()) ? 'Y' : 'N';
1881
1882 $fields['CAN_PRINT_CHECK'] = 'Y';
1883 if (Sale\Cashbox\Manager::isEnabledPaySystemPrint())
1884 {
1885 $fields['CAN_PRINT_CHECK'] = 'N';
1886 }
1887
1888 $registry = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER);
1890 $orderClass = $registry->getOrderClassName();
1891
1892 $fields['ORDER_LOCKED'] = $orderClass::isLocked($fields['ORDER_ID'] ?? 0);
1893 $fields['SITE_ID'] = $order->getSiteId();
1894 $fields['CUSTOM_WEIGHT_DELIVERY'] = self::$shipment->isMarkedFieldCustom('WEIGHT') ? 'Y' : 'N';
1895
1896 return $fields;
1897 }
1898
1899 private static function getDisallowFields()
1900 {
1901 return array(
1902 'STORE',
1903 'DELIVERY_STORE_ID',
1904 'EXTRA_SERVICES',
1905 'EMP_DEDUCTED_ID',
1906 'DELIVERY_DOC_DATE',
1907 'EMP_DEDUCTED_ID',
1908 'EMP_ALLOW_DELIVERY_ID',
1909 'EMP_CANCELED_ID',
1910 'EMP_MARKED_ID',
1911 'TRACKING_NUMBER',
1912 'DELIVERY_NAME',
1913 'DELIVERY_ID',
1914 );
1915 }
1916
1923 public static function updateData(Order &$order, array $shipments)
1924 {
1925 global $USER, $APPLICATION;
1926
1927 $saleModulePermissions = $APPLICATION->GetGroupRight("sale");
1928
1929 $result = new Result();
1930 $data = array();
1931 $basketResult = null;
1932
1933 if (!$order)
1934 {
1935 $result->addError(
1936 new EntityError(
1937 Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_ORDER_NOT_FOUND')
1938 )
1939 );
1940 return $result;
1941 }
1942
1943 $shipmentCollection = $order->getShipmentCollection();
1944
1945 $isStartField = $shipmentCollection->isStartField();
1946
1947 foreach ($shipments as $item)
1948 {
1949 $shipmentId = intval($item['SHIPMENT_ID']);
1950 $isNew = ($shipmentId <= 0);
1951 $deliveryService = null;
1952
1953 if ($isNew)
1954 {
1955 self::$shipment = $shipmentCollection->createItem();
1956 }
1957 else
1958 {
1959 self::$shipment = $shipmentCollection->getItemById($shipmentId);
1960 if (!self::$shipment)
1961 {
1962 $result->addError(
1963 new EntityError(
1964 Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_SHIPMENT_NOT_FOUND')
1965 )
1966 );
1967 continue;
1968 }
1969 }
1970
1971 self::$defaultFields = self::$shipment->getFieldValues();
1972
1975 $countItems = count(self::$shipment->getShipmentItemCollection());
1976 $systemShipment = $shipmentCollection->getSystemShipment();
1977 $systemShipmentItemCollection = $systemShipment->getShipmentItemCollection();
1978
1979 $products = array();
1980 if (
1981 !isset($item['PRODUCT'])
1982 && self::$shipment->getId() <= 0
1983 )
1984 {
1985 $basket = $order->getBasket();
1986 if ($basket)
1987 {
1988 $basketItems = $basket->getBasketItems();
1989 foreach ($basketItems as $product)
1990 {
1991 $systemShipmentItem = $systemShipmentItemCollection->getItemByBasketCode($product->getBasketCode());
1992 if ($product->isBundleChild() || !$systemShipmentItem || $systemShipmentItem->getQuantity() <= 0)
1993 continue;
1994
1995 $products[] = array(
1996 'AMOUNT' => $product->getQuantity(),
1997 'BASKET_CODE' => $product->getBasketCode()
1998 );
1999 }
2000 }
2001 }
2002 else
2003 {
2004 $products = $item['PRODUCT'];
2005 }
2006
2007 if ($item['DEDUCTED'] == 'Y')
2008 {
2009 $basketResult = OrderBasketShipment::updateData($order, self::$shipment, $products);
2010 if (!$basketResult->isSuccess())
2011 $result->addErrors($basketResult->getErrors());
2012 }
2013
2014 $extraServices = $item['EXTRA_SERVICES'] ?? [];
2015
2016 $shipmentFields = array(
2017 'COMPANY_ID' => (isset($item['COMPANY_ID']) && intval($item['COMPANY_ID']) > 0) ? intval($item['COMPANY_ID']) : 0,
2018 'DEDUCTED' => $item['DEDUCTED'],
2019 'DELIVERY_DOC_NUM' => $item['DELIVERY_DOC_NUM'],
2020 'TRACKING_NUMBER' => $item['TRACKING_NUMBER'],
2021 'CURRENCY' => $order->getCurrency(),
2022 'COMMENTS' => $item['COMMENTS'] ?? null,
2023 'WEIGHT' => $item['WEIGHT'] * self::getWeightKoef($order->getSiteId())
2024 );
2025
2026 if($item['CUSTOM_WEIGHT_DELIVERY'] === 'Y')
2027 {
2028 self::$shipment->markFieldCustom('WEIGHT');
2029 }
2030 else
2031 {
2032 self::$shipment->unMarkFieldCustom('WEIGHT');
2033 }
2034
2035 if ($isNew)
2036 {
2037 $shipmentFields['STATUS_ID'] = DeliveryStatus::getInitialStatus();
2038 }
2039 elseif (isset($item['STATUS_ID']) && $item['STATUS_ID'] !== self::$defaultFields['STATUS_ID'])
2040 {
2041 $shipmentFields['STATUS_ID'] = $item['STATUS_ID'];
2042 }
2043
2044 if ($isNew && $saleModulePermissions == "P")
2045 {
2046 if (empty($item['COMPANY_ID']))
2047 {
2048 $shipmentFields['COMPANY_ID'] = $order->getField('COMPANY_ID');
2049 }
2050 if (empty($item['RESPONSIBLE_ID']))
2051 {
2052 $shipmentFields['RESPONSIBLE_ID'] = $order->getField('RESPONSIBLE_ID');
2053 $shipmentFields['EMP_RESPONSIBLE_ID'] = $USER->GetID();
2054 $shipmentFields['DATE_RESPONSIBLE_ID'] = new DateTime();
2055 }
2056 }
2057
2058 if ($item['DELIVERY_DOC_DATE'])
2059 {
2060 try
2061 {
2062 $shipmentFields['DELIVERY_DOC_DATE'] = new Date($item['DELIVERY_DOC_DATE']);
2063 }
2064 catch (Main\ObjectException $exception)
2065 {
2066 $result->addError(
2067 new EntityError(
2068 Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_UNCORRECT_FORM_DATE')
2069 )
2070 );
2071 }
2072 }
2073
2074 $shipmentFields['DELIVERY_ID'] = (($item['PROFILE'] ?? 0) > 0) ? $item['PROFILE'] : $item['DELIVERY_ID'];
2075
2076 try
2077 {
2078 if($deliveryService = Services\Manager::getObjectById($shipmentFields['DELIVERY_ID']))
2079 {
2080 if ($deliveryService->isProfile())
2081 $shipmentFields['DELIVERY_NAME'] = $deliveryService->getNameWithParent();
2082 else
2083 $shipmentFields['DELIVERY_NAME'] = $deliveryService->getName();
2084 }
2085 }
2086 catch (Main\ArgumentNullException $e)
2087 {
2088 $result->addError(
2089 new EntityError(
2090 Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_NO_DELIVERY_SERVICE')
2091 )
2092 );
2093 }
2094
2095 $responsibleId = self::$shipment->getField('RESPONSIBLE_ID');
2096 if (($item['RESPONSIBLE_ID'] ?? null) != $responsibleId || empty($responsibleId))
2097 {
2098 if (isset($item['RESPONSIBLE_ID']))
2099 $shipmentFields['RESPONSIBLE_ID'] = $item['RESPONSIBLE_ID'];
2100 else
2101 $shipmentFields['RESPONSIBLE_ID'] = $order->getField('RESPONSIBLE_ID');
2102
2103 if (!empty($shipmentFields['RESPONSIBLE_ID']))
2104 {
2105 $shipmentFields['EMP_RESPONSIBLE_ID'] = $USER->getID();
2106 $shipmentFields['DATE_RESPONSIBLE_ID'] = new DateTime();
2107 }
2108 }
2109
2110 if ($extraServices)
2111 {
2112 self::$shipment->setExtraServices($extraServices);
2113 }
2114
2115 $setFieldsResult = self::$shipment->setFields($shipmentFields);
2116 if (!$setFieldsResult->isSuccess())
2117 {
2118 $result->addErrors($setFieldsResult->getErrors());
2119 }
2120
2121 self::$shipment->setStoreId($item['DELIVERY_STORE_ID'] ?? 0);
2122
2123 if ($item['DEDUCTED'] == 'N')
2124 {
2125 $basketResult = OrderBasketShipment::updateData($order, self::$shipment, $products);
2126 if (!$basketResult->isSuccess())
2127 $result->addErrors($basketResult->getErrors());
2128 }
2129
2130 $fields = array(
2131 'CUSTOM_PRICE_DELIVERY' => $item['CUSTOM_PRICE_DELIVERY'] === 'Y' ? 'Y' : 'N',
2132 'ALLOW_DELIVERY' => $item['ALLOW_DELIVERY'] === 'Y' ? 'Y' : 'N'
2133 );
2134
2135 $deliveryPrice = (float)str_replace(',', '.', $item['PRICE_DELIVERY']);
2136
2137 if ($item['CUSTOM_PRICE_DELIVERY'] == 'Y')
2138 $fields['BASE_PRICE_DELIVERY'] = $deliveryPrice;
2139 else
2140 $fields['BASE_PRICE_DELIVERY'] = (float)str_replace(',', '.', $item['BASE_PRICE_DELIVERY']);
2141
2142 $fields['PRICE_DELIVERY'] = $deliveryPrice;
2143
2144 $setFieldsResult = self::$shipment->setFields($fields);
2145
2146
2147 if (!$setFieldsResult->isSuccess())
2148 {
2149 $result->addErrors($setFieldsResult->getErrors());
2150 }
2151
2152 if($deliveryService && !empty($item['ADDITIONAL']))
2153 {
2154 $modifiedShipment = $deliveryService->processAdditionalInfoShipmentEdit(self::$shipment, $item['ADDITIONAL']);
2155
2156 if($modifiedShipment && get_class($modifiedShipment) == 'Bitrix\Sale\Shipment')
2157 self::$shipment = $modifiedShipment;
2158 }
2159
2160 $data['SHIPMENT'][] = self::$shipment;
2161 }
2162
2163 if ($isStartField)
2164 {
2165 $hasMeaningfulFields = $shipmentCollection->hasMeaningfulField();
2166
2168 $r = $shipmentCollection->doFinalAction($hasMeaningfulFields);
2169 if (!$r->isSuccess())
2170 {
2171 $result->addErrors($r->getErrors());
2172 }
2173 }
2174
2175 $result->setData($data);
2176
2177 return $result;
2178 }
2179
2185 public static function calculateDeliveryPrice(\Bitrix\Sale\Shipment $shipment)
2186 {
2187 $result = new CalculationResult();
2188
2189 if ($shipment->getDeliveryId())
2190 {
2191 $service = Services\Manager::getObjectById($shipment->getDeliveryId());
2192
2193 if ($service && !$service->canHasProfiles())
2194 {
2195 $extraServices = $shipment->getExtraServices();
2196 $extraServicesManager = $service->getExtraServices();
2197 $extraServicesManager->setValues($extraServices);
2198 return $service->calculate($shipment);
2199 }
2200 }
2201
2202 return $result;
2203 }
2204
2209 public static function setShipmentByDefaultValues(&$shipment)
2210 {
2212 $shipmentCollection = $shipment->getCollection();
2213
2214 $systemShipment = $shipmentCollection->getSystemShipment();
2215 $systemShipmentItemCollection = $systemShipment->getShipmentItemCollection();
2217 $shipmentItemCollection = $shipment->getShipmentItemCollection();
2218
2220 foreach ($systemShipmentItemCollection as $systemShipmentItem)
2221 {
2222 if ($systemShipmentItem->getQuantity() <= 0)
2223 continue;
2224
2225 $basketItem = $systemShipmentItem->getBasketItem();
2226 $shipmentItem = $shipmentItemCollection->createItem($basketItem);
2227 $shipmentItem->setField('QUANTITY', $systemShipmentItem->getQuantity());
2228 }
2229
2230 $shipment->setField('CUSTOM_PRICE_DELIVERY', 'N');
2231 $shipment->setField('DELIVERY_ID', $systemShipment->getField('DELIVERY_ID'));
2232 $shipment->setField('COMPANY_ID', $systemShipment->getField('COMPANY_ID'));
2233 $shipment->setField('DELIVERY_NAME', $systemShipment->getField('DELIVERY_NAME'));
2234 $shipment->setExtraServices($systemShipment->getExtraServices());
2235 $shipment->setStoreId($systemShipment->getStoreId());
2236
2237 $price = 0;
2238 $calcResult = self::calculateDeliveryPrice($shipment);
2239 if ($calcResult->isSuccess())
2240 $price = $calcResult->getPrice();
2241 $shipment->setField('BASE_PRICE_DELIVERY', $price);
2242 }
2243
2244 public static function setBackUrl($backUrl)
2245 {
2246 self::$backUrl = $backUrl;
2247 }
2248
2254 public static function buildCheckHtml($checkList)
2255 {
2256 $result = '';
2257 foreach ($checkList as $check)
2258 {
2259 $result .= '<div>';
2260
2261 if ($check['LINK'] <> '')
2262 {
2263 $result .= '<a href="'.$check['LINK'].'" target="_blank">'.Loc::getMessage('SALE_ORDER_SHIPMENT_CHECK_LINK', array('#CHECK_ID#' => $check['ID'])).'</a>';
2264 }
2265 else
2266 {
2267 $result .='<tspan>'.Loc::getMessage('SALE_ORDER_SHIPMENT_CHECK_LINK', array('#CHECK_ID#' => $check['ID']));
2268 if ($check['STATUS'] === 'P')
2269 {
2270 $result .= ' (<a href="javascript:void(0);" onclick="BX.Sale.Admin.OrderShipment.prototype.sendQueryCheckStatus('.$check['ID'].');">'.Loc::getMessage('SALE_ORDER_SHIPMENT_CHECK_CHECK_STATUS').'</a>)';
2271 }
2272 $result .= '</tspan>';
2273 }
2274
2275 $result .= '</div>';
2276 }
2277
2278 return $result;
2279 }
2280}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getMap($deliveryId, $index, $storeId=0, $formType="")
static getProfileEditControl($profiles, $index=1, $selectedProfileId=0)
static getView($shipment, $index=0, $formType='')
static getStoresList($deliveryId, $storeId)
static checkProfilesRestriction($profiles, $shipment)
static getEdit($shipment, $index=0, $formType='', $dataForRecovery=array())
static getEditTemplate($data, $index, $formType, $post)
static getViewTemplate($data, $index, $formType)
static getTemplate($deliveries, $selected='')
static makeSelectHtmlWithRestricted($name, array $data, $selected="", $showNotUse=true, $attributes=array())
static getStatusesUserCanDoOperations($userId, array $operations)