Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
orderpayment.php
1<?php
2
4
5use Bitrix\Main\Entity\EntityError;
18use Bitrix\Main\Page\Asset;
23use Bitrix\Sale;
24use Bitrix\Main;
26
27Loc::loadMessages(__FILE__);
28
30{
32 private static $order = null;
33 private static $defaultFields = null;
34
35 private static function prepareData($item, $error = false)
36 {
39 global $USER, $APPLICATION;
40 static $users = array();
41 static $userCompanyList = array();
42
43 $registry = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER);
45 $orderClass = $registry->getOrderClassName();
46
47 if (is_null(self::$order))
48 self::$order = $item->getCollection()->getOrder();
49
50 $fields = ($error) ? self::$defaultFields : $item->getFieldValues();
51
52 $fields['EMP_PAID_ID_NAME'] = '';
53 $fields['EMP_PAID_ID_LAST_NAME'] = '';
54
55 $empPaidId = (int)($fields['EMP_PAID_ID'] ?? 0);
56 if ($empPaidId > 0)
57 {
58 if (!array_key_exists($item->getField('EMP_PAID_ID'), $users))
59 $users[$empPaidId] = $USER->GetByID($empPaidId)->Fetch();
60 $fields['EMP_PAID_ID_NAME'] = $users[$empPaidId]['NAME'];
61 $fields['EMP_PAID_ID_LAST_NAME'] = $users[$empPaidId]['LAST_NAME'];
62 }
63
64 $fields['ORDER_ID'] = self::$order->getId();
65 $fields['SUM'] = $item->getSum();
66 $fields['ORDER_PRICE'] = self::$order->getPrice();
67 $fields['ORDER_PAYMENT_SUM'] = $item->getCollection()->getSum();
68 $fields['CURRENCY'] = self::$order->getCurrency();
69 $fields['PERSON_TYPE_ID'] = self::$order->getPersonTypeId();
70 $fields['SITE_ID'] = self::$order->getSiteId();
71 $fields['STATUS_ID'] = self::$order->getField('STATUS_ID');
72 $fields['ORDER_LOCKED'] = $orderClass::isLocked($fields['ORDER_ID']);
73
74 $saleModulePermissions = $APPLICATION->GetGroupRight("sale");
75
76 if($saleModulePermissions == "P")
77 {
78 if (empty($userCompanyList))
79 {
80 $userCompanyList = Company\Manager::getUserCompanyList($USER->GetID());
81 }
82
83 $isUserResponsible = false;
84
85 if (self::$order->getField('RESPONSIBLE_ID') == $USER->GetID()
86 || ($fields['RESPONSIBLE_ID'] == $USER->GetID()))
87 {
88 $isUserResponsible = true;
89 }
90
91 $isAllowCompany = in_array($item->getField('COMPANY_ID'), $userCompanyList) || in_array(self::$order->getField('COMPANY_ID'), $userCompanyList);
92
93
94 if (!$isUserResponsible && !$isAllowCompany)
95 {
96 foreach ($fields as $fieldName => $fieldValue)
97 {
98 if (in_array($fieldName, static::getDisallowFields()))
99 {
100 unset($fields[$fieldName]);
101 }
102 }
103 }
104
105 $fields['IS_USER_RESPONSIBLE'] = $isUserResponsible;
106 $fields['IS_ALLOW_COMPANY'] = $isAllowCompany;
107 }
108
109 $fields['PAY_SYSTEM_LIST'] = self::getPaySystemList($item);
110
111 $fields['CHECK'] = CheckManager::getCheckInfo($item);
112
113 $paySystemId = (int)($fields['PAY_SYSTEM_ID'] ?? 0);
114 $fields['CAN_PRINT_CHECK'] = $fields['PAY_SYSTEM_LIST'][$paySystemId]['CAN_PRINT_CHECK'] ?? 'N';
115 if (Sale\Cashbox\Manager::isEnabledPaySystemPrint())
116 {
117 $fields['CAN_PRINT_CHECK'] = 'N';
118 }
119
120 $dbRes = CashboxTable::getList(array('filter' => array('=ACTIVE' => 'Y', '=ENABLED' => 'Y')));
121 $fields['HAS_ENABLED_CASHBOX'] = ($dbRes->fetch()) ? 'Y' : 'N';
122
123 $service = $item->getPaySystem();
124 $fields['HAS_PREVIEW'] = $service && $service->isAffordPdf();
125
126 return $fields;
127 }
128
129
130 private static function getDisallowFields()
131 {
132 return array(
133 'EMP_PAID_ID_NAME',
134 'EMP_PAID_ID_LAST_NAME',
135 );
136 }
137
143 public static function getPaySystemParams($paySystemId)
144 {
145 static $result = array();
146
147 if (!isset($result[$paySystemId]))
148 {
149 $data = array();
150 if ($paySystemId > 0)
151 {
152 $data = PaySystemActionTable::getRow(array(
153 'select' => array('NAME', 'LOGOTIP', 'HAVE_RESULT', 'RESULT_FILE', 'ACTION_FILE'),
154 'filter' => array('ID' => $paySystemId),
155 ));
156 }
157
158 $result[$paySystemId] = $data;
159
160 $logotip = (int)($data["LOGOTIP"] ?? 0);
161 if($logotip > 0)
162 {
163 $tmp = \CFile::ResizeImageGet($logotip, array('width' => 100, 'height' => 60));
164 $result[$paySystemId]["LOGOTIP_PATH"] = $tmp['src'];
165 $tmp = \CFile::ResizeImageGet($logotip, array('width' => 80, 'height' => 50));
166 $result[$paySystemId]["LOGOTIP_SHORT_PATH"] = $tmp['src'];
167 }
168 else
169 {
170 $result[$paySystemId]["LOGOTIP_PATH"] = '/bitrix/images/sale/nopaysystem.gif';
171 $result[$paySystemId]["LOGOTIP_SHORT_PATH"] = '/bitrix/images/sale/nopaysystem.gif';
172 }
173 }
174
175 return $result[$paySystemId];
176 }
177
183 public static function modifyData($payment, $data)
184 {
187 if (is_null(self::$order))
188 self::$order = $payment->getCollection()->getOrder();
189
190 if (!$data['ERROR'])
191 $data['ERROR'] = 'Y';
192 $data['ID'] = $data['PAYMENT_ID'];
193 $data['CURRENCY'] = self::$order->getCurrency();
194 $data['PERSON_TYPE_ID'] = self::$order->getPersonTypeId();
195 $data['SITE_ID'] = self::$order->getSiteId();
196
197 return $data;
198 }
199
207 public static function getEdit($payment, $index = 1, $dataForRecovery = array())
208 {
209 global $USER, $APPLICATION;
210
211 $saleModulePermissions = $APPLICATION->GetGroupRight("sale");
212
213 $data = self::prepareData($payment, !empty($dataForRecovery));
214
215 $data['COMPANIES'] = Company\Manager::getListWithRestrictions($payment, Company\Restrictions\Manager::MODE_MANAGER);
216
217 $userCompanyId = null;
218 if($saleModulePermissions == "P")
219 {
220 $userCompanyList = Company\Manager::getUserCompanyList($USER->GetID());
221 if (!empty($userCompanyList) && is_array($userCompanyList) && count($userCompanyList) == 1)
222 {
223 $userCompanyId = reset($userCompanyList);
224 }
225
226 if ($payment->getId() == 0)
227 {
228 if (intval($userCompanyId) > 0)
229 {
230 $payment->setField('COMPANY_ID', $userCompanyId);
231 }
232 $payment->setField('RESPONSIBLE_ID', $USER->GetID());
233 }
234 }
235
236 $result = self::getEditTemplate($data, $index, $dataForRecovery);
237
238 return $result;
239 }
240
248 public static function getView($payment, $index = 1, $form='')
249 {
250 $data = self::prepareData($payment);
251 return self::getViewTemplate($data, $index, $form);
252 }
253
258 public static function getScripts()
259 {
260 Asset::getInstance()->addJs("/bitrix/js/sale/admin/order_payment.js");
261 $imgPathList = self::getImgPathList();
262 $message = array(
263 'PAYMENT_PAID_NO' => Loc::getMessage('SALE_ORDER_PAYMENT_STATUS_NO'),
264 'PAYMENT_PAID_YES' => Loc::getMessage('SALE_ORDER_PAYMENT_STATUS_YES'),
265 'PAYMENT_PAID_RETURN' => Loc::getMessage('SALE_ORDER_PAYMENT_RETURN'),
266 'PAYMENT_PAID_CANCEL' => Loc::getMessage('SALE_ORDER_PAYMENT_CANCEL'),
267 'PAYMENT_RETURN_COMMENT' => Loc::getMessage('SALE_ORDER_PAYMENT_RETURN_COMMENT'),
268 'PAYMENT_RETURN_NUM' => Loc::getMessage('SALE_ORDER_PAYMENT_RETURN_NUM'),
269 'PAYMENT_RETURN_DATE' => Loc::getMessage('SALE_ORDER_PAYMENT_RETURN_DATE'),
270 'PAYMENT_OPERATION_TITLE' => Loc::getMessage('SALE_ORDER_PAYMENT_OPERATION_TITLE'),
271 'PAYMENT_OPERATION_RETURN' => Loc::getMessage('SALE_ORDER_PAYMENT_OPERATION_RETURN'),
272 'PAYMENT_RETURN_DATE_ALT' => Loc::getMessage('SALE_ORDER_PAYMENT_RETURN_DATE_ALT'),
273 'PAYMENT_WINDOW_RETURN_TITLE' => Loc::getMessage('SALE_ORDER_PAYMENT_WINDOW_RETURN_TITLE'),
274 'PAYMENT_WINDOW_CANCEL_TITLE' => Loc::getMessage('SALE_ORDER_PAYMENT_WINDOW_CANCEL_TITLE'),
275 'PAYMENT_WINDOW_RETURN_BUTTON_SAVE' => Loc::getMessage('SALE_ORDER_PAYMENT_WINDOW_RETURN_BUTTON_SAVE'),
276 'PAYMENT_RETURN_NUM_DOC' => Loc::getMessage('SALE_ORDER_PAYMENT_RETURN_NUM_DOC'),
277 'PAYMENT_RETURN_SUM' => Loc::getMessage('SALE_ORDER_PAYMENT_RETURN_SUM'),
278 'PAYMENT_OPERATION_CANCEL' => Loc::getMessage('SALE_ORDER_PAYMENT_OPERATION_CANCEL'),
279 'PAYMENT_TOGGLE_DOWN' => Loc::getMessage('SALE_ORDER_PAYMENT_TOGGLE_DOWN'),
280 'PAYMENT_TOGGLE_UP' => Loc::getMessage('SALE_ORDER_PAYMENT_TOGGLE_UP'),
281 'PAYMENT_PAY_VOUCHER_NUM' => Loc::getMessage('SALE_ORDER_PAYMENT_PAY_VOUCHER_NUM'),
282 'PAYMENT_PAY_VOUCHER_DATE' => Loc::getMessage('SALE_ORDER_PAYMENT_PAY_VOUCHER_DATE'),
283 'PAYMENT_WINDOW_VOUCHER_TITLE' => Loc::getMessage('SALE_ORDER_PAYMENT_WINDOW_VOUCHER_TITLE'),
284 'PAYMENT_USE_INNER_BUDGET' => Loc::getMessage('SALE_ORDER_PAYMENT_USE_INNER_BUDGET'),
285 'PAYMENT_ORDER_STATUS' => Loc::getMessage('SALE_ORDER_PAYMENT_ORDER_STATUS'),
286 'PAYMENT_CONFIRM_DELETE' => Loc::getMessage('SALE_ORDER_PAYMENT_CONFIRM_DELETE'),
287 'PAYMENT_CASHBOX_CHECK_ADD_WINDOW_TITLE' => Loc::getMessage('PAYMENT_CASHBOX_CHECK_ADD_WINDOW_TITLE')
288 );
289 return '<script type="text/javascript">
290 BX.message('.\CUtil::PhpToJSObject($message).');
291 logoList = '.\CUtil::PhpToJSObject($imgPathList).';
292
293 BX.ready(function(){
294 if(BX.Sale.Admin.OrderEditPage && BX.Sale.Admin.OrderEditPage.registerFieldsUpdaters)
295 BX.Sale.Admin.OrderEditPage.registerFieldsUpdaters( BX.Sale.Admin.OrderPayment.prototype.getCreateOrderFieldsUpdaters() );
296 });
297
298 </script>';
299 }
300
301 private static function getEditTemplate($data, $index, $post = array())
302 {
303 global $USER, $APPLICATION;
304
305 $saleModulePermissions = $APPLICATION->GetGroupRight("sale");
306
307 $paid = ($post) ? htmlspecialcharsbx($post['PAID']) : $data['PAID'];
308 $id = ($post) ? (int)$post['PAYMENT_ID'] : ($data['ID'] ?? 0);
309 $priceCod = ($post) ? htmlspecialcharsbx($post['PRICE_COD']) : ($data['PRICE_COD'] ?? 0);
310 $paidString = ($paid == 'Y') ? 'YES' : 'NO';
311 if (!$post)
312 {
313 if ($data['SUM'] > 0)
314 $sum = $data['SUM'];
315 else
316 $sum = ($data['ORDER_PRICE'] - $data['ORDER_PAYMENT_SUM'] <= 0) ? 0 : $data['ORDER_PRICE'] - $data['ORDER_PAYMENT_SUM'];
317 }
318 else
319 {
320 $sum = $post['SUM'];
321 }
322
323 $psData = self::getPaySystemParams(
324 (isset($post['PAY_SYSTEM_ID'])) ? $post['PAY_SYSTEM_ID'] : ($data['PAY_SYSTEM_ID'] ?? 0)
325 );
326
327 if (isset($psData["LOGOTIP_PATH"]))
328 $data['PAY_SYSTEM_LOGOTIP'] = $psData["LOGOTIP_PATH"];
329
330 $allowedOrderStatusesPayment = OrderStatus::getStatusesUserCanDoOperations($USER->GetID(), array('payment'));
331 $isAllowPayment = in_array($data["STATUS_ID"], $allowedOrderStatusesPayment);
332 $triangle = ($isAllowPayment) ? '<span class="triangle"> &#9662;</span>' : '';
333 $class = ($paid != 'Y') ? 'notpay' : '';
334 $class .= (!$isAllowPayment) ? ' not_active' : '';
335
336 $paymentStatus = '<span><span id="BUTTON_PAID_'.$index.'" class="'.$class.'">'.Loc::getMessage('SALE_ORDER_PAYMENT_STATUS_'.$paidString).'</span>'.$triangle.'</span>';
337
338 $note = BeginNote();
339 $note .= Loc::getMessage('SALE_ORDER_PAYMENT_RETURN_ALERT');
340 $note .= EndNote();
341
342 $hiddenPaySystemInnerId = '';
343 if ($index == 1)
344 $hiddenPaySystemInnerId = '<input type="hidden" value="'.PaySystem\Manager::getInnerPaySystemId().'" id="PAYMENT_INNER_BUDGET_ID">';
345
346 $notPaidBlock = ($paid == 'N' && !empty($data['EMP_PAID_ID'])) ? '' : 'style="display:none;"';
347
348 $return = isset($post['IS_RETURN']) && $post['IS_RETURN'] === 'Y' ? '' : 'style="display:none;"';
349
350 $option = '<option value="Y">'.Loc::getMessage('SALE_ORDER_PAYMENT_RETURN_ACCOUNT').'</option>';
351
352 if (isset($data['PAY_SYSTEM_ID']) && $data['PAY_SYSTEM_ID'] != PaySystem\Manager::getInnerPaySystemId())
353 {
355 $service = PaySystem\Manager::getObjectById($data['PAY_SYSTEM_ID']);
356 if ($service && $service->isRefundable())
357 $option .= '<option value="P">'.htmlspecialcharsbx($service->getField('NAME')).'</option>';
358 }
359
360 $payReturnNum = $post['PAY_RETURN_NUM'] ?? $data['PAY_RETURN_NUM'] ?? '';
361 $payReturnDate = $post['PAY_RETURN_DATE'] ?? $data['PAY_RETURN_DATE'] ?? '';
362 $payReturnComment = $post['PAY_RETURN_COMMENT'] ?? $data['PAY_RETURN_COMMENT'] ?? '';
363
364 $returnInformation = '
365 <tr '.$return.' class="return">
366 <td class="adm-detail-content-cell-l fwb">'.Loc::getMessage('SALE_ORDER_PAYMENT_RETURN_TO').':</td>
367 <td class="adm-detail-content-cell-r">
368 <select name="PAYMENT['.$index.'][OPERATION_ID]" id="OPERATION_ID_'.$index.'" class="adm-bus-select">
369 '.$option.'
370 </select>
371 </td>
372 </tr>
373 <tr '.$return.' class="return">
374 <td colspan="2" style="text-align: center">'.$note.'</td>
375 </tr>
376 <tr '.$notPaidBlock.' class="not_paid">
377 <td class="adm-detail-content-cell-l" width="40%"><br>'.Loc::getMessage('SALE_ORDER_PAYMENT_PAY_RETURN_NUM').':</td>
378 <td class="adm-detail-content-cell-r tal">
379 <br>
380 <input type="text" class="adm-bus-input" name="PAYMENT['.$index.'][PAY_RETURN_NUM]" id="PAYMENT_RETURN_NUM_'.$index.'" value="'.htmlspecialcharsbx($payReturnNum).'" maxlength="20">
381 </td>
382 </tr>
383 <tr '.$notPaidBlock.' class="not_paid">
384 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PAY_RETURN_DATE').':</td>
385 <td class="adm-detail-content-cell-r tal">
386 <div class="adm-input-wrap adm-calendar-second" style="display: inline-block;">
387 <input type="text" class="adm-input adm-calendar-to" name="PAYMENT['.$index.'][PAY_RETURN_DATE]" id="PAYMENT_RETURN_DATE_'.$index.'" size="15" value="'.htmlspecialcharsbx($payReturnDate).'">
388 <span class="adm-calendar-icon" title="'.Loc::getMessage('SALE_ORDER_PAYMENT_CHOOSE_DATE').'" onclick="BX.calendar({node:this, field:\'PAYMENT_RETURN_DATE_'.$index.'\', form: \'\', bTime: false, bHideTime: false});"></span>
389 </div>
390 </td>
391 </tr>
392 <tr '.$notPaidBlock.' class="not_paid">
393 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_RETURN_COMMENT').':</td>
394 <td class="adm-detail-content-cell-r tal">
395 <div class="adm-input-wrap adm-calendar-second" style="display: inline-block;">
396 <textarea name="PAYMENT['.$index.'][PAY_RETURN_COMMENT]" id="PAYMENT_RETURN_COMMENTS_'.$index.'">'.htmlspecialcharsbx($payReturnComment).'</textarea>
397 </div>
398 </td>
399 </tr>';
400
401 $lang = Main\Application::getInstance()->getContext()->getLanguage();
402
403 if ($id > 0)
404 {
405 $dateBill = new Date($data['DATE_BILL']);
406 $title = Loc::getMessage('SALE_ORDER_PAYMENT_BLOCK_EDIT_PAYMENT_TITLE', array('#ID#' => $data['ID'], '#DATE_BILL#' => $dateBill));
407 }
408 else
409 {
410 $title = Loc::getMessage('SALE_ORDER_PAYMENT_BLOCK_NEW_PAYMENT_TITLE');
411 }
412
413 $disabled = isset($data['PAID']) && $data['PAID'] === 'Y' ? 'readonly' : '';
414
415 $companyList = $data['COMPANIES'];
416 $companies = '';
417
418 if (!empty($companyList))
419 {
420 if ($saleModulePermissions == "P")
421 {
422 $userCompanyId = null;
423 $userCompanyList = Company\Manager::getUserCompanyList($USER->GetID());
424 if (is_array($userCompanyList) && count($userCompanyList) == 1)
425 {
426 $userCompanyId = reset($userCompanyList);
427 $companyName = $data['COMPANIES'][$userCompanyId]["NAME"]." [".$data['COMPANIES'][$userCompanyId]["ID"]."]";
428 $companies = htmlspecialcharsbx($companyName);
429 }
430 else
431 {
432 foreach ($data['COMPANIES'] as $companyId => $companyData)
433 {
434 $foundCompany = false;
435
436 if (!empty($userCompanyList) && is_array($userCompanyList))
437 {
438 foreach ($userCompanyList as $userCompanyId)
439 {
440 if ($userCompanyId == $companyId)
441 {
442 $foundCompany = true;
443 break;
444 }
445 }
446 }
447
448 if (!$foundCompany)
449 {
450 unset($data['COMPANIES'][$companyId]);
451 }
452 }
453
454 if (count($data['COMPANIES']) == 1)
455 {
456 $company = reset($data['COMPANIES']);
457 $companies = htmlspecialcharsbx($company["NAME"]." [".$company["ID"]."]");
458 }
459 }
460 }
461
462 if (empty($companies))
463 {
464 $companies = OrderEdit::makeSelectHtmlWithRestricted(
465 'PAYMENT['.$index.'][COMPANY_ID]',
466 $companyList,
467 isset($post["COMPANY_ID"]) ? $post["COMPANY_ID"] : $data["COMPANY_ID"],
468 true,
469 array(
470 "class" => "adm-bus-select",
471 "id" => "PAYMENT_COMPANY_ID_".$index
472 )
473 );
474 }
475 }
476 else
477 {
478 if ($saleModulePermissions >= "W")
479 {
480 $companies = str_replace("#URL#", "/bitrix/admin/sale_company_edit.php?lang=".$lang, Loc::getMessage('SALE_ORDER_PAYMENT_ADD_COMPANY'));
481 }
482 }
483
484 $checkLink = '';
485 $checkLink .= '<tr><td class="tac" id="PAYMENT_CHECK_LIST_ID_'.($data['ID'] ?? 0).'">';
486 if (!empty($data['CHECK']))
487 {
488 $checkLink .= static::buildCheckHtml($data['CHECK']);
489 }
490 $checkLink .= '</td></tr>';
491 if ($data['CAN_PRINT_CHECK'] == 'Y' && $data['HAS_ENABLED_CASHBOX'] === 'Y')
492 {
493 $checkLink .= '<tr><td class="adm-detail-content-cell-r tac"><a href="javascript:void(0);" onclick="BX.Sale.Admin.OrderPayment.prototype.showCreateCheckWindow('.$data['ID'].');">'.Loc::getMessage('SALE_ORDER_PAYMENT_CHECK_ADD').'</a></td></tr>';
494 }
495
496 $isReturn = $post['IS_RETURN'] ?? 'N';
497 $paySystemId = $post['PAY_SYSTEM_ID'] ?? $data['PAY_SYSTEM_ID'] ?? 0;
498 $payVoucherNum = $post['PAY_VOUCHER_NUM'] ?? $data['PAY_VOUCHER_NUM'] ?? '';
499 $payVoucherDate = $post['PAY_VOUCHER_DATE'] ?? $data['PAY_VOUCHER_DATE'] ?? '';
500
501 $data['DATE_PAID'] ??= '';
502 $data['EMP_PAID_ID'] ??= '';
503 $data['EMP_PAID_ID_NAME'] ??= '';
504 $data['EMP_PAID_ID_LAST_NAME'] ??= '';
505
506 $result = '<div>
507 <div class="adm-bus-pay" id="payment_container_'.$index.'">
508 <input type="hidden" name="PAYMENT['.$index.'][PAYMENT_ID]" id="payment_id_'.$index.'" value="'.$id.'">
509 <input type="hidden" name="PAYMENT['.$index.'][INDEX]" value="'.$index.'" class="index">
510 <input type="hidden" name="PAYMENT['.$index.'][PAID]" id="PAYMENT_PAID_'.$index.'" value="'.(empty($paid) ? 'N' : $paid).'">
511 <input type="hidden" name="PAYMENT['.$index.'][IS_RETURN]" id="PAYMENT_IS_RETURN_'.$index.'" value="'.(htmlspecialcharsbx($isReturn)).'">
512 <input type="hidden" name="PAYMENT['.$index.'][IS_RETURN_CHANGED]" id="PAYMENT_IS_RETURN_CHANGED_'.$index.'" value="N">
513 '.$hiddenPaySystemInnerId.'
514 <div class="adm-bus-component-content-container">
515 <div class="adm-bus-pay-section">
516 <div class="adm-bus-pay-section-title-container">
517 <div class="adm-bus-pay-section-title">'.$title.'</div>
518 <div class="adm-bus-pay-section-action-block">'.
519 ((!isset($data['ID']) || $data['ID'] <= 0) ? '<div class="adm-bus-pay-section-action" id="SECTION_'.$index.'_DELETE">'.Loc::getMessage('SALE_ORDER_PAYMENT_DELETE').'</div>' : '')
520 .'</div>
521 </div>
522 <div class="adm-bus-pay-section-content" id="SECTION_'.$index.'">
523 <div class="adm-bus-pay-section-sidebar">
524 <div style="background: url(\''.$data['PAY_SYSTEM_LOGOTIP'].'\')" class="adm-shipment-block-logo" id="LOGOTIP_'.$index.'"></div>
525 </div>
526 <div class="adm-bus-pay-section-right">
527 <div class="adm-bus-table-container caption border">
528 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_PAYMENT_METHOD').'</div>
529 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
530 <tbody>
531 <tr>
532 <td class="adm-detail-content-cell-l fwb" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PAY_SYSTEM').':</td>
533 <td class="adm-detail-content-cell-r">'.
534 OrderEdit::makeSelectHtmlWithRestricted(
535 'PAYMENT['.$index.'][PAY_SYSTEM_ID]',
536 $data['PAY_SYSTEM_LIST'],
537 $paySystemId,
538 false,
539 array(
540 "class" => "adm-bus-select",
541 "id" => "PAY_SYSTEM_ID_".$index
542 )
543 )
544 .'</td>
545 </tr>
546 </tbody>
547 </table>
548 </div>
549 <div class="adm-bus-table-container caption border">
550 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_PAYMENT_SUM').'</div>
551 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
552 <tbody>
553 <tr>
554 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PAYABLE_SUM').':</td>
555 <td class="adm-detail-content-cell-r tal">'
556 . \CCurrencyLang::getPriceControl(
557 '<input type="text" class="adm-bus-input-price" name="PAYMENT['.$index.'][SUM]" id="PAYMENT_SUM_'.$index.'" value="'.round($sum, 2).'" '.$disabled.'>',
558 $data['CURRENCY']
559 )
560 . '<br></td>
561 </tr>
562 <tr '.($priceCod > 0 ?: 'style="display: none"').'>
563 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PAYABLE_PRICE_COD').':</td>
564 <td class="adm-detail-content-cell-r tal">'
565 . \CCurrencyLang::getPriceControl(
566 '<input type="text" class="adm-bus-input-price" name="PAYMENT['.$index.'][PRICE_COD]" id="PAYMENT_PRICE_COD_'.$index.'" value="'.round($priceCod, 2).'" readonly>',
567 $data['CURRENCY']
568 )
569 . '<br></td>
570 </tr>
571 </tbody>
572 </table>
573 </div>
574 <div class="adm-bus-table-container caption border" style="padding-top:10px;">
575 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_PAYMENT_STATUS').'</div>
576 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table alternation edit-table" id="PAYMENT_BLOCK_STATUS_'.$index.'">
577 <tbody>
578 <tr>
579 <td class="adm-detail-content-cell-l vat payment-status" width="40%">
580 '.$paymentStatus.'
581 </td>
582 <td class="adm-detail-content-cell-r tal" id="PAYMENT_CHANGE_USER_INFO_'.$index.'">
583 '.$data['DATE_PAID'].'
584 <a href="/bitrix/admin/user_edit.php?lang='.$lang.'&ID='.$data['EMP_PAID_ID'].'">'.htmlspecialcharsbx($data['EMP_PAID_ID_NAME']).' '.htmlspecialcharsbx($data['EMP_PAID_ID_LAST_NAME']).'</a>
585 </td>
586 </tr>
587 </tbody>
588 </table>
589 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table" id="PAYMENT_BLOCK_STATUS_INFO_'.$index.'">
590 <tbody>
591 <tr>
592 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PAY_VOUCHER_NUM').':</td>
593 <td class="adm-detail-content-cell-r tal">
594 <input type="text" class="adm-bus-input" id="PAYMENT_NUM" name="PAYMENT['.$index.'][PAY_VOUCHER_NUM]" value="'.htmlspecialcharsbx($payVoucherNum).'" maxlength="20">
595 </td>
596 </tr>
597 <tr>
598 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PAY_VOUCHER_DATE').':</td>
599 <td class="adm-detail-content-cell-r tal">
600 <div class="adm-input-wrap adm-calendar-second" style="display: inline-block;">
601 <input type="text" class="adm-input adm-calendar-to" id="PAYMENT_DATE_'.$index.'" name="PAYMENT['.$index.'][PAY_VOUCHER_DATE]" size="15" value="'.htmlspecialcharsbx($payVoucherDate).'">
602 <span class="adm-calendar-icon" title="'.Loc::getMessage('SALE_ORDER_PAYMENT_CHOOSE_DATE').'" onclick="BX.calendar({node:this, field:\'PAYMENT_DATE_'.$index.'\', form: \'\', bTime: false, bHideTime: false});"></span>
603 </div>
604 </td>
605 </tr>
606 '.$returnInformation.'
607 </tbody>
608 </table>
609 </div>';
610 if ($data['CAN_PRINT_CHECK'] == 'Y' && $data['ID'] > 0)
611 {
612 $result .= '<div class="adm-bus-table-container caption border" style="padding-top:10px;">
613 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_PAYMENT_CHECK_LINK_TITLE').'</div>
614 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table">
615 <tbody>
616 '.$checkLink.'
617 </tbody>
618 </table>
619 </div>';
620 }
621
622 if (isset($data['PS_STATUS']) && !empty($data['PS_STATUS']))
623 {
624 $result .= '<div class="adm-bus-table-container caption border">
625 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_STATUS_TITLE').'</div>
626 <a href="javascript:void(0);" id="PS_INFO_'.$index.'">'.Loc::getMessage('SALE_ORDER_PAYMENT_TOGGLE_DOWN').'</a>
627 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table" style="display: none">
628 <tbody>
629 <tr>
630 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_STATUS').':</td>
631 <td class="adm-detail-content-cell-r tal">'.$data['PS_STATUS'].'</td>
632 </tr>
633 <tr>
634 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_STATUS_CODE').':</td>
635 <td class="adm-detail-content-cell-r tal">'.$data['PS_STATUS_CODE'].'</td>
636 </tr>
637 <tr>
638 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_STATUS_DESCRIPTION').':</td>
639 <td class="adm-detail-content-cell-r tal">'.$data['PS_STATUS_DESCRIPTION'].'</td>
640 </tr>
641 <tr>
642 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_CURRENCY').':</td>
643 <td class="adm-detail-content-cell-r tal">'.$data['PS_CURRENCY'].'</td>
644 </tr>
645 <tr>
646 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_STATUS_MESSAGE').':</td>
647 <td class="adm-detail-content-cell-r tal">'.$data['PS_STATUS_MESSAGE'].'</td>
648 </tr>
649 <tr>
650 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_SUM').':</td>
651 <td class="adm-detail-content-cell-r tal">'.$data['PS_SUM'].'</td>
652 </tr>
653 <tr>
654 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_DATE').':</td>
655 <td class="adm-detail-content-cell-r tal">'.$data['PS_RESPONSE_DATE'].'</td>
656 </tr>
657 </tbody>
658 </table>
659 </div>';
660 }
661 if ($companies !== '')
662 {
663 $result .= '<div class="adm-bus-table-container caption border">
664 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_PAYMENT_BLOCK_COMPANY').'</div>
665 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
666 <tbody>
667 <tr>
668 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_COMPANY_BY').':</td>
669 <td class="adm-detail-content-cell-r">'.$companies.'</td>
670 </tr>
671 </tbody>
672 </table>
673 </div>';
674 }
675 $result .= '</div><div class="clb"></div></div></div></div></div></div>';
676
677 $refundablePs = array();
678 if (isset($data['ID']) && $data['ID'] > 0)
679 {
680 $innerService = PaySystem\Manager::getObjectById(PaySystem\Manager::getInnerPaySystemId());
681 $refundablePs[Payment::RETURN_INNER] = $innerService->getField('NAME');
682 if ($data['PAY_SYSTEM_ID'] != $innerService->getField('ID'))
683 {
684 $service = PaySystem\Manager::getObjectById($data['PAY_SYSTEM_ID']);
685 if ($service && $service->isRefundable())
686 $refundablePs[Payment::RETURN_PS] = $service->getField('NAME');
687 }
688 }
689
690 $params = array(
691 'index' => $index,
692 'functionOnSave' => 'saveInHiddenFields',
693 'isPaid' => isset($data['PAID']) && $data['PAID'] === 'Y',
694 'viewForm' => false,
695 'isAvailableChangeStatus' => $isAllowPayment,
696 'psToReturn' => $refundablePs
697 );
698 $result .= self::initJsPayment($params);
699 return $result;
700 }
701
702 private static function getViewTemplate($data, $index, $form)
703 {
704 global $USER;
705
706 $isUserResponsible = null;
707 $isAllowCompany = null;
708 $link = Link::getInstance();
709
710 if (array_key_exists('IS_USER_RESPONSIBLE', $data))
711 {
712 $isUserResponsible = $data['IS_USER_RESPONSIBLE'];
713 }
714
715 if (array_key_exists('IS_ALLOW_COMPANY', $data))
716 {
717 $isAllowCompany = $data['IS_ALLOW_COMPANY'];
718 }
719
720 $psData = self::getPaySystemParams($data['PAY_SYSTEM_ID']);
721
722 if ($isAllowCompany === false)
723 {
724 $data['PAY_VOUCHER_NUM'] = '';
725 $data['PAY_VOUCHER_DATE'] = '';
726 $data['PAY_RETURN_NUM'] = '';
727 $data['PAY_RETURN_DATE'] = '';
728 $data['PS_STATUS'] = '';
729 }
730 else
731 {
732 if (isset($psData["LOGOTIP_PATH"]))
733 {
734 $data['PAY_SYSTEM_LOGOTIP'] = $psData["LOGOTIP_PATH"];
735 $data['PAY_SYSTEM_LOGOTIP_SHORT'] = $psData["LOGOTIP_SHORT_PATH"];
736 }
737 }
738
739 $psResult = '';
740 if ($psData['HAVE_RESULT'] == 'Y' && $form != 'edit')
741 {
742 $psResult .= '&nbsp;&nbsp;&nbsp;<span style="border-bottom: 1px dashed #658d0f; color: #658d0f; cursor: pointer" id="ps_update_'.$index.'">'.Loc::getMessage('SALE_ORDER_PAYMENT_PAY_SYSTEM_CHECK').'</span>';
743 }
744
745 $lang = Main\Application::getInstance()->getContext()->getLanguage();
746 $paidString = ($data['PAID'] == 'Y') ? 'YES' : 'NO';
747
748 $allowedOrderStatusesPayment = OrderStatus::getStatusesUserCanDoOperations($USER->GetID(), array('payment'));
749 $isAllowPayment = in_array($data["STATUS_ID"], $allowedOrderStatusesPayment);
750
751 $isActive = ($form != 'edit' && $form != 'archive') && !$data['ORDER_LOCKED'] && $isAllowPayment;
752 $triangle = ($isActive) ? '<span class="triangle"> &#9662;</span>' : '';
753
754 if ($data['PAID'] == 'Y')
755 $class = (!$isActive) ? 'class="not_active"' : '';
756 else
757 $class = (!$isActive) ? 'class="notpay not_active"' : 'class="notpay"';
758 $paymentStatus = '<span><span id="BUTTON_PAID_'.$index.'" '.$class.'>'.Loc::getMessage('SALE_ORDER_PAYMENT_STATUS_'.$paidString).'</span>'.$triangle.'</span>';
759
760 $res = CompanyTable::getList(array(
761 'select' => array('NAME'),
762 'filter' => array('ID' => $data['COMPANY_ID'])
763 ));
764 $company = $res->fetch();
765
766 $paymentStatusBlockVoucherNum = '';
767 if ($data['PAY_VOUCHER_NUM'] <> '')
768 {
769 $paymentStatusBlockVoucherNum = '<tr>
770 <td class="adm-detail-content-cell-l" width="40%"><br>'.Loc::getMessage('SALE_ORDER_PAYMENT_PAY_VOUCHER_NUM').':</td>
771 <td class="adm-detail-content-cell-r tal">
772 <br>
773 '.htmlspecialcharsbx($data['PAY_VOUCHER_NUM']).'
774 </td>
775 </tr>';
776 }
777
778 $paymentStatusBlockVoucherDate = '';
779 if ($data['PAY_VOUCHER_DATE'] <> '')
780 {
781 $paymentStatusBlockVoucherDate = '<tr>
782 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PAY_VOUCHER_DATE').':</td>
783 <td class="adm-detail-content-cell-r tal">
784 <div class="adm-input-wrap adm-calendar-second" style="display: inline-block;">'.htmlspecialcharsbx($data['PAY_VOUCHER_DATE']).'</div>
785 </td>
786 </tr>';
787 }
788
789 $paymentStatusBlockReturnNum = '';
790 if ($data['PAY_RETURN_NUM'] <> '')
791 {
792 $paymentStatusBlockReturnNum = '<tr>
793 <td class="adm-detail-content-cell-l" width="40%"><br>'.Loc::getMessage('SALE_ORDER_PAYMENT_PAY_RETURN_NUM').':</td>
794 <td class="adm-detail-content-cell-r tal">
795 <br>'.htmlspecialcharsbx($data['PAY_RETURN_NUM']).'</td>
796 </tr>';
797 }
798
799 $paymentStatusBlockReturnDate = '';
800 if ($data['PAY_RETURN_DATE'] <> '')
801 {
802 $paymentStatusBlockReturnDate = '<tr>
803 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PAY_RETURN_DATE').':</td>
804 <td class="adm-detail-content-cell-r tal">
805 <div class="adm-input-wrap adm-calendar-second" style="display: inline-block;">'.htmlspecialcharsbx($data['PAY_RETURN_DATE']).'</div>
806 </td>
807 </tr>';
808 }
809
810 $dateBill = new Date($data['DATE_BILL']);
811
812 $allowedOrderStatusesEdit = OrderStatus::getStatusesUserCanDoOperations($USER->GetID(), array('update'));
813 $isAllowEdit = in_array($data["STATUS_ID"], $allowedOrderStatusesEdit) && $form != 'archive';
814 $sectionEdit = '';
815 $href = $link
816 ->create()
817 ->setPageByType(Registry::SALE_ORDER_PAYMENT_EDIT)
818 ->setFilterParams(false)
819 ->fill()
820 ->setField('order_id', $data['ORDER_ID'])
821 ->setField('payment_id', $data['ID'])
822 ->setField('backurl', $_SERVER['REQUEST_URI'])
823 ->build();
824
825 if ($isAllowEdit && !$data['ORDER_LOCKED'])
826 $sectionEdit = '<div class="adm-bus-pay-section-action" id="SECTION_'.$index.'_EDIT"><a href="'.$href.'">'.Loc::getMessage('SALE_ORDER_PAYMENT_EDIT').'</a></div>';
827
828 $allowedOrderStatusesDelete = OrderStatus::getStatusesUserCanDoOperations($USER->GetID(), array('delete'));
829 $isAllowDelete = in_array($data["STATUS_ID"], $allowedOrderStatusesDelete) && $form != 'archive';
830 $sectionDelete = '';
831 if ($isAllowDelete && !$data['ORDER_LOCKED'])
832 $sectionDelete = '<div class="adm-bus-pay-section-action" id="SECTION_'.$index.'_DELETE">'.Loc::getMessage('SALE_ORDER_PAYMENT_DELETE').'</div>';
833
834 $checkLink = '<tr><td class="tac" id="PAYMENT_CHECK_LIST_ID_'.$data['ID'].'">';
835 if (!empty($data['CHECK']))
836 {
837 $checkLink .= static::buildCheckHtml($data['CHECK']);
838 }
839 $checkLink .= "</td></tr>";
840
841 if($form != 'archive' && $data['CAN_PRINT_CHECK'] == 'Y' && $data['HAS_ENABLED_CASHBOX'] === 'Y')
842 {
843 $checkLink .= '<tr><td class="adm-detail-content-cell-r tac"><a href="javascript:void(0);" onclick="BX.Sale.Admin.OrderPayment.prototype.showCreateCheckWindow('.$data['ID'].');">'.Loc::getMessage('SALE_ORDER_PAYMENT_CHECK_ADD').'</a></td></tr>';
844 }
845
846 if ($isAllowCompany === false && $isUserResponsible === false)
847 {
848 $psName = Loc::getMessage('SALE_ORDER_PAYMENT_HIDDEN');
849 }
850 else
851 {
852 $psName = htmlspecialcharsbx($data['PAY_SYSTEM_NAME']).' ['.$data['PAY_SYSTEM_ID'].'] '.$psResult;
853 if ($data['HAS_PREVIEW'])
854 {
855 $psName .= " (<a target='_blank' href='/bitrix/admin/sale_payment_doc_preview.php?PAYMENT_ID={$data['ID']}&ORDER_ID={$data['ORDER_ID']}'>".Loc::getMessage('SALE_ORDER_PAYMENT_DOC_PREVIEW')."</a>)";
856 }
857 }
858
859 $result = '
860 <div>
861 <div class="adm-bus-pay" id="payment_container_'.$index.'">
862 <input type="hidden" name="PAYMENT['.$index.'][PAYMENT_ID]" id="PAYMENT_ID_'.$index.'" value="'.$data['ID'].'">
863 <div class="adm-bus-component-content-container">
864 <div class="adm-bus-pay-section">
865 <div class="adm-bus-pay-section-title-container">
866 <div class="adm-bus-pay-section-title" id="payment_'.$data['ID'].'">'.$tabTitle = Loc::getMessage('SALE_ORDER_PAYMENT_BLOCK_EDIT_PAYMENT_TITLE', array('#ID#' => $data['ID'], '#DATE_BILL#' => $dateBill)).'</div>
867 <div class="adm-bus-pay-section-action-block">
868 '.$sectionDelete.$sectionEdit.'
869 <div class="adm-bus-pay-section-action" id="SECTION_'.$index.'_TOGGLE">'.Loc::getMessage('SALE_ORDER_PAYMENT_TOGGLE_DOWN').'</div>
870 </div>
871 </div>
872 <div class="adm-bus-pay-section-content" id="SECTION_'.$index.'" style="display:none">
873 <div class="adm-bus-pay-section-sidebar">
874 <div style="background: url(\''.$data['PAY_SYSTEM_LOGOTIP'].'\')" class="adm-shipment-block-logo" id="LOGOTIP_'.$index.'"></div>
875 </div>
876 <div class="adm-bus-pay-section-right">
877 <div class="adm-bus-table-container caption border">
878 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_PAYMENT_METHOD').'</div>
879 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
880 <tbody>
881 <tr>
882 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PAY_SYSTEM').':</td>
883 <td class="adm-detail-content-cell-r">'.$psName.'</td>
884 </tr>
885 </tbody>
886 </table>
887 </div>
888 <div class="adm-bus-table-container caption border">
889 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_PAYMENT_SUM').'</div>
890 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
891 <tbody>
892 <tr>
893 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PAYABLE_SUM').':</td>
894 <td class="adm-detail-content-cell-r tal">'.SaleFormatCurrency($data['SUM'], $data['CURRENCY']).'<br></td>
895 </tr>
896 <tr '.($data['PRICE_COD'] > 0 ?: 'style="display: none"').'>
897 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PAYABLE_PRICE_COD').':</td>
898 <td class="adm-detail-content-cell-r tal" id="PAYMENT_PRICE_COD_'.$index.'">'.SaleFormatCurrency($data['PRICE_COD'], $data['CURRENCY']).'</td>
899 </tr>
900 </tbody>
901 </table>
902 </div>
903 <div class="adm-bus-table-container caption border" style="padding-top:10px;">
904 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_PAYMENT_STATUS').'</div>
905 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table alternation edit-table" id="PAYMENT_BLOCK_STATUS_'.$index.'">
906 <tbody>
907 <tr>
908 <td class="adm-detail-content-cell-l vat payment-status" width="40%">
909 '.$paymentStatus.'
910 </td>
911 <td class="adm-detail-content-cell-r tal" id="PAYMENT_CHANGE_USER_INFO_'.$index.'">
912 '.$data['DATE_PAID'].'
913 <a href="/bitrix/admin/user_edit.php?lang='.$lang.'&ID='.$data['EMP_PAID_ID'].'">'.htmlspecialcharsbx($data['EMP_PAID_ID_NAME']).' '.htmlspecialcharsbx($data['EMP_PAID_ID_LAST_NAME']).'</a>
914 </td>
915 </tr>
916 </tbody>
917 </table>
918 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table">
919 <tbody>
920 '.$paymentStatusBlockVoucherNum.$paymentStatusBlockVoucherDate.$paymentStatusBlockReturnNum.$paymentStatusBlockReturnDate.'
921 </tbody>
922 </table>
923 </div>';
924 if ($checkLink)
925 {
926 $result .= '<div class="adm-bus-table-container caption border" style="padding-top:10px;">
927 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_PAYMENT_CHECK_LINK_TITLE').'</div>
928 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table">
929 <tbody>
930 '.$checkLink.'
931 </tbody>
932 </table>
933 </div>';
934 }
935
936 if (isset($data['PS_STATUS']) && !empty($data['PS_STATUS']))
937 {
938 $result .= '<div class="adm-bus-table-container caption border">
939 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_STATUS_TITLE').'</div>
940 <a href="javascript:void(0);" id="PS_INFO_'.$index.'">'.Loc::getMessage('SALE_ORDER_PAYMENT_TOGGLE_UP').'</a>
941 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table">
942 <tbody>
943 <tr>
944 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_STATUS').':</td>
945 <td class="adm-detail-content-cell-r tal">'.htmlspecialcharsbx($data['PS_STATUS']).'</td>
946 </tr>
947 <tr>
948 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_STATUS_CODE').':</td>
949 <td class="adm-detail-content-cell-r tal">'.htmlspecialcharsbx($data['PS_STATUS_CODE']).'</td>
950 </tr>
951 <tr>
952 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_STATUS_DESCRIPTION').':</td>
953 <td class="adm-detail-content-cell-r tal">'.htmlspecialcharsbx($data['PS_STATUS_DESCRIPTION']).'</td>
954 </tr>
955 <tr>
956 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_CURRENCY').':</td>
957 <td class="adm-detail-content-cell-r tal">'.htmlspecialcharsbx($data['PS_CURRENCY']).'</td>
958 </tr>
959 <tr>
960 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_STATUS_MESSAGE').':</td>
961 <td class="adm-detail-content-cell-r tal">'.htmlspecialcharsbx($data['PS_STATUS_MESSAGE']).'</td>
962 </tr>
963 <tr>
964 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_SUM').':</td>
965 <td class="adm-detail-content-cell-r tal">'.htmlspecialcharsbx($data['PS_SUM']).'</td>
966 </tr>
967 <tr>
968 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_PS_DATE').':</td>
969 <td class="adm-detail-content-cell-r tal">'.htmlspecialcharsbx($data['PS_RESPONSE_DATE']).'</td>
970 </tr>
971 </tbody>
972 </table>
973 </div>';
974 }
975 $result .= '<div class="adm-bus-table-container caption border">
976 <div class="adm-bus-table-caption-title" style="background: #eef5f5;">'.Loc::getMessage('SALE_ORDER_PAYMENT_BLOCK_COMPANY').'</div>
977 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
978 <tbody>
979 <tr>
980 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_PAYMENT_COMPANY_BY').':</td>
981 <td class="adm-detail-content-cell-r">'.
982 ($isAllowCompany === false && $isUserResponsible === false ? Loc::getMessage('SALE_ORDER_PAYMENT_HIDDEN') :
983 (isset($company['NAME']) && !empty($company['NAME']) ? htmlspecialcharsbx($company['NAME']).' ['.$data['COMPANY_ID'].']' : Loc::getMessage('SALE_ORDER_PAYMENT_NO_COMPANY')))
984
985 .'</td>
986 </tr>
987 </tbody>
988 </table>
989 </div>
990 </div>
991 <div class="clb"></div>
992 </div>
993 '.self::getShortViewTemplate($data, $index, $form).'
994 </div>
995 </div>
996 </div>
997 </div>';
998
999 $innerService = PaySystem\Manager::getObjectById(PaySystem\Manager::getInnerPaySystemId());
1000 if ($innerService)
1001 {
1002 $refundablePs = array(Payment::RETURN_INNER => $innerService->getField('NAME'));
1003
1004 if ($data['PAY_SYSTEM_ID'] != $innerService->getField('ID'))
1005 {
1006 $service = PaySystem\Manager::getObjectById($data['PAY_SYSTEM_ID']);
1007 if ($service && $service->isRefundable())
1008 $refundablePs[Payment::RETURN_PS] = $service->getField('NAME');
1009 }
1010 }
1011 else
1012 {
1013 $refundablePs = array();
1014 }
1015
1016 $params = array(
1017 'index' => $index,
1018 'functionOnSave' => 'sendAjax',
1019 'viewForm' => true,
1020 'isPaid' => ($data['PAID'] == 'Y'),
1021 'isAvailableChangeStatus' => $isActive,
1022 'psToReturn' => $refundablePs
1023 );
1024 $result .= self::initJsPayment($params);
1025 return $result;
1026 }
1027
1028 private static function getShortViewTemplate($data, $index, $form)
1029 {
1030 global $USER;
1031 $lang = Main\Application::getInstance()->getContext()->getLanguage();
1032 $paidString = ($data['PAID'] == 'Y') ? 'YES' : 'NO';
1033
1034 $registry = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER);
1035
1036 $isUserResponsible = null;
1037 $isAllowCompany = null;
1038
1039 if (array_key_exists('IS_USER_RESPONSIBLE', $data))
1040 {
1041 $isUserResponsible = $data['IS_USER_RESPONSIBLE'];
1042 }
1043
1044 if (array_key_exists('IS_ALLOW_COMPANY', $data))
1045 {
1046 $isAllowCompany = $data['IS_ALLOW_COMPANY'];
1047 }
1048
1050 $orderStatusClass = $registry->getOrderStatusClassName();
1051
1052 $allowedOrderStatusesPayment = $orderStatusClass::getStatusesUserCanDoOperations($USER->GetID(), array('payment'));
1053 $isAllowPayment = in_array($data["STATUS_ID"], $allowedOrderStatusesPayment);
1054
1055 $isActive = ($form != 'edit' && $form != 'archive') && !$data['ORDER_LOCKED'] && $isAllowPayment;
1056 $triangle = ($isActive) ? '<span class="triangle"> &#9662;</span>' : '';
1057
1058 if ($data['PAID'] == 'Y')
1059 $class = (!$isActive) ? 'class="not_active"' : '';
1060 else
1061 $class = (!$isActive) ? 'class="notpay not_active"' : 'class="notpay"';
1062 $paymentStatus = '<span><span id="BUTTON_PAID_'.$index.'_SHORT" '.$class.'>'.Loc::getMessage('SALE_ORDER_PAYMENT_STATUS_'.$paidString).'</span>'.$triangle.'</span>';
1063
1064 $checkLink = '';
1065 if (($data['CAN_PRINT_CHECK'] == 'Y' && $form != 'archive' && $data['HAS_ENABLED_CASHBOX'] === 'Y') || !empty($data['CHECK']))
1066 {
1067 $checkLink = '<td width="80px">'.Loc::getMessage('SALE_ORDER_PAYMENT_CHECK_LINK_TITLE').':</td><td>';
1068 $checkLink .= '<div id="PAYMENT_CHECK_LIST_ID_SHORT_VIEW'.$data['ID'].'">';
1069 if (!empty($data['CHECK']))
1070 {
1071 $checkLink .= static::buildCheckHtml($data['CHECK']);
1072 }
1073 $checkLink .= "</div>";
1074 if ($form != 'archive' && $data['CAN_PRINT_CHECK'] == 'Y' && $data['HAS_ENABLED_CASHBOX'] === 'Y')
1075 {
1076 $checkLink .= '<div><a href="javascript:void(0);" onclick="BX.Sale.Admin.OrderPayment.prototype.showCreateCheckWindow('.$data['ID'].');">'.Loc::getMessage('SALE_ORDER_PAYMENT_CHECK_ADD').'</a></div>';
1077 }
1078 $checkLink .='</td>';
1079 }
1080
1081 if ($isAllowCompany === false && $isUserResponsible === false)
1082 {
1083 $psName = Loc::getMessage('SALE_ORDER_PAYMENT_HIDDEN');
1084 }
1085 else
1086 {
1087 $psName = htmlspecialcharsbx($data['PAY_SYSTEM_NAME']);
1088
1089 if ($data['HAS_PREVIEW'])
1090 {
1091 $psName .= " (<a target='_blank' href='/bitrix/admin/sale_payment_doc_preview.php?PAYMENT_ID={$data['ID']}&ORDER_ID={$data['ORDER_ID']}'>".Loc::getMessage('SALE_ORDER_PAYMENT_DOC_PREVIEW')."</a>)";
1092 }
1093 }
1094
1095 $result = '
1096 <div class="adm-bus-section-container-section-content" style="padding: 10px;" id="SECTION_SHORT_'.$index.'">
1097 <table class="adm-bus-section-container-section-status" id="PAYMENT_BLOCK_STATUS_'.$index.'">
1098 <tr>
1099 <td>
1100 <div style="background: url(\''.$data['PAY_SYSTEM_LOGOTIP_SHORT'].'\');" class="adm-shipment-block-short-logo" id="LOGOTIP_SHORT_'.$index.'"></div>
1101 </td>
1102 <td class="adm-bus-section-container-section-status-service">'.Loc::getMessage('SALE_ORDER_PAYMENT_PAY_SYSTEM').': '.$psName.'</td>
1103 <td class="adm-bus-section-container-section-status-summ">'.Loc::getMessage('SALE_ORDER_PAYMENT_PAYABLE_SUM').': '.SaleFormatCurrency($data['SUM'], $data['CURRENCY']).'</td>
1104 <td class="adm-bus-section-container-section-status-status payment-status">'.Loc::getMessage('SALE_ORDER_PAYMENT_STATUS').': '.$paymentStatus.'</td>
1105 '.$checkLink.'
1106 <td class="adm-bus-section-container-section-status-others" id="PAYMENT_CHANGE_USER_INFO_'.$index.'">'.$data['DATE_PAID'].'
1107 <a href="/bitrix/admin/user_edit.php?lang='.$lang.'&ID='.$data['EMP_PAID_ID'].'">'.htmlspecialcharsbx($data['EMP_PAID_ID_NAME']).' '.htmlspecialcharsbx($data['EMP_PAID_ID_LAST_NAME']).'</a>
1108 </td>
1109 </tr>
1110 </table>
1111 </div>';
1112
1113 return $result;
1114 }
1115
1116 private static function initJsPayment($params)
1117 {
1118 return "<script>
1119 BX.ready( function(){
1120 var obPayment_".$params['index']." = new BX.Sale.Admin.OrderPayment(".\CUtil::PhpToJSObject($params).");
1121 });
1122 </script>";
1123 }
1124
1130 public static function buildCheckHtml($checkList)
1131 {
1132 $result = '';
1133 foreach ($checkList as $check)
1134 {
1135 $result .= '<div>';
1136
1137 if ($check['LINK'] <> '')
1138 {
1139 $result .= '<a href="'.$check['LINK'].'" target="_blank">'.Loc::getMessage('SALE_ORDER_PAYMENT_CHECK_LINK', array('#CHECK_ID#' => $check['ID'])).'</a>';
1140 }
1141 else
1142 {
1143 $result .='<tspan>'.Loc::getMessage('SALE_ORDER_PAYMENT_CHECK_LINK', array('#CHECK_ID#' => $check['ID']));
1144 if ($check['STATUS'] === 'P')
1145 {
1146 $result .= ' (<a href="javascript:void(0);" onclick="BX.Sale.Admin.OrderPayment.prototype.sendQueryCheckStatus('.$check['ID'].');">'.Loc::getMessage('SALE_ORDER_PAYMENT_CHECK_CHECK_STATUS').'</a>)';
1147 }
1148 $result .= '</tspan>';
1149 }
1150
1151 $result .= '</div>';
1152 }
1153
1154 return $result;
1155 }
1156
1161 public static function getPaySystemList(Payment $payment)
1162 {
1163 $result = array();
1164
1165 $result[] = array(
1166 'ID' => '0',
1167 'NAME' => Loc::getMessage('SALE_ORDER_PAYMENT_NO_PAYSYSTEM')
1168 );
1169
1170 if (self::$order === null)
1171 {
1173 $collection = $payment->getCollection();
1174
1176 self::$order = $collection->getOrder();
1177 }
1178
1179 $paySystems = PaySystem\Manager::getListWithRestrictions($payment, Restrictions\Manager::MODE_MANAGER);
1180
1181 foreach ($paySystems as $paySystem)
1182 {
1183 $params = array(
1184 'ID' => $paySystem['ID'],
1185 'NAME' => "[".$paySystem["ID"]."] ".$paySystem["NAME"],
1186 'CAN_PRINT_CHECK' => $paySystem['CAN_PRINT_CHECK']
1187 );
1188
1189 if (isset($paySystem['RESTRICTED']))
1190 $params['RESTRICTED'] = $paySystem['RESTRICTED'];
1191
1192 $result[$paySystem['ID']] = $params;
1193 }
1194
1195 return $result;
1196 }
1197
1198 private static function getImgPathList()
1199 {
1200 $dbRes = PaySystem\Manager::getList(
1201 array(
1202 'select' => array('ID', 'LOGOTIP')
1203 )
1204 );
1205 $paySystems = $dbRes->fetchAll();
1206
1207 $logotypes = array('/bitrix/images/sale/nopaysystem.gif');
1208 foreach ($paySystems as $paySystem)
1209 {
1210 if (empty($paySystem['LOGOTIP']))
1211 {
1212 $logotypes[$paySystem['ID']] = $logotypes[0];
1213 }
1214 else
1215 {
1216 $image = \CFile::ResizeImageGet($paySystem["LOGOTIP"], array('width' => 100, 'height' => 60));
1217 $logotypes[$paySystem['ID']] = $image['src'];
1218 }
1219 }
1220
1221 return $logotypes;
1222 }
1223
1228 public static function createButtonAddPayment($params=[])
1229 {
1230 return '<input type="button" class="adm-order-block-add-button" value="'.Loc::getMessage('SALE_ORDER_PAYMENT_BUTTON_ADD').'" onclick="BX.Sale.Admin.GeneralPayment.addNewPayment(this,'.\CUtil::PhpToJSObject($params).')">';
1231 }
1232
1242 public static function updateData(Sale\Order &$order, $payments, $canSetPaid = false)
1243 {
1244 global $USER, $APPLICATION;
1245
1246 $saleModulePermissions = $APPLICATION->GetGroupRight("sale");
1247
1248 $result = new Result();
1249 $data['PAYMENT'] = array();
1250
1251 if (!$order)
1252 throw new UserMessageException('Order does not exist');
1253
1254 foreach ($payments as $payment)
1255 {
1256 $paymentId = intval($payment['PAYMENT_ID']);
1257 $isNew = ($paymentId <= 0);
1258 $paymentCollection = $order->getPaymentCollection();
1259
1261 if ($isNew)
1262 {
1263 $paymentItem = $paymentCollection->createItem();
1264 }
1265 else
1266 {
1267 $paymentItem = $paymentCollection->getItemById($paymentId);
1268
1269 if (!$paymentItem)
1270 throw new UserMessageException('Payment does not exist');
1271 }
1272
1273 self::$defaultFields = $paymentItem->getFieldValues();
1274
1275 $isReturn = (isset($payment['IS_RETURN']) && ($payment['IS_RETURN'] == 'Y' || $payment['IS_RETURN'] == 'P'));
1276
1277 $psService = null;
1278 if ($payment['PAY_SYSTEM_ID'] > 0)
1279 $psService = PaySystem\Manager::getObjectById($payment['PAY_SYSTEM_ID']);
1280
1281 $paymentFields = array(
1282 'PAY_SYSTEM_ID' => $payment['PAY_SYSTEM_ID'],
1283 'COMPANY_ID' => (isset($payment['COMPANY_ID']) && intval($payment['COMPANY_ID']) > 0) ? intval($payment['COMPANY_ID']) : 0,
1284 'PAY_VOUCHER_NUM' => $payment['PAY_VOUCHER_NUM'],
1285 'PAY_RETURN_NUM' => $payment['PAY_RETURN_NUM'],
1286 'PAY_RETURN_COMMENT' => $payment['PAY_RETURN_COMMENT'],
1287 'COMMENTS' => $payment['COMMENTS'] ?? null,
1288 'PAY_SYSTEM_NAME' => ($psService) ? $psService->getField('NAME') : ''
1289 );
1290
1291 if ($isNew && $saleModulePermissions == "P")
1292 {
1293 if (empty($payment['COMPANY_ID']))
1294 {
1295 $paymentFields['COMPANY_ID'] = $order->getField('COMPANY_ID');
1296 }
1297 if (empty($payment['RESPONSIBLE_ID']))
1298 {
1299 $paymentFields['RESPONSIBLE_ID'] = $order->getField('RESPONSIBLE_ID');
1300 $paymentFields['EMP_RESPONSIBLE_ID'] = $USER->GetID();
1301 $paymentFields['DATE_RESPONSIBLE_ID'] = new DateTime();
1302 }
1303
1304 }
1305
1306 if (!$paymentItem->isPaid())
1307 $paymentFields['SUM'] = (float)str_replace(',', '.', $payment['SUM']);
1308
1309 if ($payment['PRICE_COD'])
1310 $paymentFields['PRICE_COD'] = $payment['PRICE_COD'];
1311
1312 if ($isNew)
1313 $paymentFields['DATE_BILL'] = new DateTime();
1314
1315 if (!empty($payment['PAY_RETURN_DATE']))
1316 {
1317 try
1318 {
1319 $paymentFields['PAY_RETURN_DATE'] = new Date($payment['PAY_RETURN_DATE']);
1320 }
1321 catch (Main\ObjectException $exception)
1322 {
1323 $result->addError(
1324 new EntityError(Loc::getMessage('SALE_ORDER_PAYMENT_ERROR_RETURN_DATE_FORMAT'))
1325 );
1326 }
1327 }
1328
1329 if (!empty($payment['PAY_VOUCHER_DATE']))
1330 {
1331 try
1332 {
1333 $paymentFields['PAY_VOUCHER_DATE'] = new Date($payment['PAY_VOUCHER_DATE']);
1334 }
1335 catch (Main\ObjectException $exception)
1336 {
1337 $result->addError(
1338 new EntityError(Loc::getMessage('SALE_ORDER_PAYMENT_ERROR_VOUCHER_DATE_FORMAT'))
1339 );
1340 }
1341 }
1342
1343 if (isset($payment['RESPONSIBLE_ID']))
1344 {
1345 $paymentFields['RESPONSIBLE_ID'] = !empty($payment['RESPONSIBLE_ID']) ? $payment['RESPONSIBLE_ID'] : $USER->GetID();
1346 if ($payment['RESPONSIBLE_ID'] != $paymentItem->getField('RESPONSIBLE_ID'))
1347 {
1348 $paymentFields['DATE_RESPONSIBLE_ID'] = new DateTime();
1349 if (!$isNew)
1350 $paymentFields['EMP_RESPONSIBLE_ID'] = $USER->GetID();
1351 }
1352 }
1353
1354 if ($result->isSuccess())
1355 {
1356 $setResult = $paymentItem->setFields($paymentFields);
1357 if (!$setResult->isSuccess())
1358 $result->addErrors($setResult->getErrors());
1359
1360 if ($isReturn && $payment['OPERATION_ID'])
1361 {
1362 $setResult = $paymentItem->setReturn($payment['OPERATION_ID']);
1363 if (!$setResult->isSuccess())
1364 $result->addErrors($setResult->getErrors());
1365 }
1366
1367 $isReturnChanged = $payment['IS_RETURN_CHANGED'] === 'Y';
1368
1369 if (!$canSetPaid && !$isReturnChanged)
1370 {
1371 $setResult = $paymentItem->setPaid($payment['PAID']);
1372 if (!$setResult->isSuccess())
1373 $result->addErrors($setResult->getErrors());
1374 }
1375
1376 if (isset($payment['ORDER_STATUS_ID']) && $payment['ORDER_STATUS_ID'])
1377 {
1378 $order->setField('STATUS_ID', $payment['ORDER_STATUS_ID']);
1379 }
1380 }
1381
1382 $verify = $paymentItem->verify();
1383 if (!$verify->isSuccess())
1384 {
1385 $result->addErrors($verify->getErrors());
1386 }
1387
1388 $data['PAYMENT'][] = $paymentItem;
1389 }
1390
1391 $result->setData($data);
1392
1393 return $result;
1394 }
1395}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getView($payment, $index=1, $form='')
static getEdit($payment, $index=1, $dataForRecovery=array())
static getStatusesUserCanDoOperations($userId, array $operations)