Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
orderadditional.php
1<?php
2
4
9
10Loc::loadMessages(__FILE__);
11
13{
14 public static function getEdit($collection, $formName, $formPrefix, array $post = array())
15 {
16 global $APPLICATION, $USER;
17
18 $saleModulePermissions = $APPLICATION->GetGroupRight("sale");
19
20 $userCompanyId = null;
21
22 if($saleModulePermissions == "P")
23 {
24 $userCompanyList = Manager::getUserCompanyList($USER->GetID());
25 if (!empty($userCompanyList) && is_array($userCompanyList) && count($userCompanyList) == 1)
26 {
27 $userCompanyId = reset($userCompanyList);
28 }
29 if ($collection->getId() == 0)
30 {
31 if (intval($userCompanyId) > 0)
32 {
33 $collection->setField('COMPANY_ID', $userCompanyId);
34 }
35
36 $collection->setField('RESPONSIBLE_ID', $USER->GetID());
37 }
38 }
39
40 $data = self::prepareData($collection);
41
42 $lang = Application::getInstance()->getContext()->getLanguage();
43
44 if(get_class($collection) == 'Bitrix\Sale\Order')
45 $orderLocked = \Bitrix\Sale\Order::isLocked($collection->getId());
46 else
47 $orderLocked = false;
48
49 $blockEmpResponsible = '';
50 if (isset($data['EMP_RESPONSIBLE']) && !empty($data['EMP_RESPONSIBLE']))
51 {
52 $blockEmpResponsible = '
53 <tr>
54 <td class="adm-detail-content-cell-l fwb vat" width="40%"></td>
55 <td class="adm-detail-content-cell-r">
56 <div>'.Loc::getMessage('SALE_ORDER_ADDITIONAL_INFO_CHANGE_BY').': <span style="color: #66878F" id="order_additional_info_date_responsible">'.$data['DATE_RESPONSIBLE'].'</span> <a href="" id="order_additional_info_emp_responsible">'.htmlspecialcharsbx($data['EMP_RESPONSIBLE']).'</a></div>
57 </td>
58 </tr>
59 ';
60 }
61
62 $additionalInfo = '';
63
64 if (isset($data['ADDITIONAL_INFO']) && !empty($data['ADDITIONAL_INFO']))
65 {
66 $additionalInfo = '
67 <table class="adm-detail-content-table edit-table" border="0" width="100%" cellpadding="0" cellspacing="0">
68 <tbody>
69 <tr>
70 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_ADDITIONAL_INFO_ADDITIONAL_INFO').':</td>
71 <td class="adm-detail-content-cell-r">'.$data['ADDITIONAL_INFO'].'</td>
72 </tr>
73 </tbody>
74 </table>';
75 }
76
77 $data['COMPANIES'] = Manager::getListWithRestrictions($collection, \Bitrix\Sale\Services\Company\Restrictions\Manager::MODE_MANAGER);
78
79 if (!empty($data['COMPANIES']))
80 {
81 $companies = null;
82 if ($saleModulePermissions == "P")
83 {
84 //&& !empty($data['COMPANIES'][$userCompanyId])
85 if (count($userCompanyList) == 1)
86 {
87 $companyName = $data['COMPANIES'][$userCompanyId]["NAME"]." [".$data['COMPANIES'][$userCompanyId]["ID"]."]";
88 $companies = htmlspecialcharsbx($companyName);
89 }
90 else
91 {
92 foreach ($data['COMPANIES'] as $companyId => $companyData)
93 {
94 $foundCompany = false;
95 foreach ($userCompanyList as $userCompanyId)
96 {
97 if ($userCompanyId == $companyId)
98 {
99 $foundCompany = true;
100 break;
101 }
102 }
103
104 if (!$foundCompany)
105 {
106 unset($data['COMPANIES'][$companyId]);
107 }
108 }
109
110
111 if (count($data['COMPANIES']) == 1)
112 {
113 $company = reset($data['COMPANIES']);// [$userCompanyId]["NAME"]." [".$data['COMPANIES'][$userCompanyId]["ID"]."]";
114 $companies = htmlspecialcharsbx($company["NAME"]." [".$company["ID"]."]");
115 }
116 }
117 }
118
119
120 if (empty($companies) && $formPrefix === 'ORDER')
121 {
123 $formPrefix.'[COMPANY_ID]',
124 $data['COMPANIES'],
125 isset($post["COMPANY_ID"]) ? $post["COMPANY_ID"] : $data["COMPANY_ID"],
126 true,
127 array(
128 "class" => "adm-bus-select",
129 "id" => $formPrefix."_COMPANY_ID"
130 )
131 );
132 }
133 }
134 else
135 {
136 if ($saleModulePermissions >= "W")
137 {
138 $companies = str_replace("#URL#", "/bitrix/admin/sale_company_edit.php?lang=".$lang, Loc::getMessage('SALE_ORDER_SHIPMENT_ADD_COMPANY'));
139 }
140 }
141
142 if (!empty($companies))
143 {
144 $additionalInfo .= '
145 <table border="0" cellspacing="0" cellpadding="0" width="100%" class="adm-detail-content-table edit-table ">
146 <tbody>
147 <tr>
148 <td class="adm-detail-content-cell-l" width="40%">'.Loc::getMessage('SALE_ORDER_ADDITIONAL_INFO_COMPANY').':</td>
149 <td class="adm-detail-content-cell-r">'.$companies.'</td>
150 </tr>
151 </tbody>
152 </table>';
153 }
154
155
156 return '
157 <input type="hidden" name="'.$formPrefix.'[RESPONSIBLE_ID]" id="RESPONSIBLE_ID" value="'.$data['RESPONSIBLE_ID'].'" onChange="BX.Sale.Admin.OrderAdditionalInfo.changePerson();">
158 <div class="adm-bus-moreInfo_part1">
159 <table class="adm-detail-content-table edit-table" border="0" width="100%" cellpadding="0" cellspacing="0">
160 <tbody>
161 <tr>
162 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_ADDITIONAL_INFO_RESPONSIBLE').':</td>
163 <td class="adm-detail-content-cell-r">
164 <div class="adm-s-order-person-choose">'.static::renderResponsibleLink($data).'
165 &nbsp;
166 <a class="adm-s-bus-morelinkqhsw" onclick="BX.Sale.Admin.OrderAdditionalInfo.choosePerson(\''.$formName.'\', \''.LANGUAGE_ID.'\');" href="javascript:void(0);">
167 '.Loc::getMessage('SALE_ORDER_ADDITIONAL_INFO_CHANGE').'
168 </a>
169 </div>
170 </td>
171 </tr>
172 '.$blockEmpResponsible.'
173 </tbody>
174 </table>
175 </div>
176 <div class="adm-bus-moreInfo_part1-5">
177 '.$additionalInfo.'
178 </div>
179 <div class="adm-s-gray-title">'.Loc::getMessage('SALE_ORDER_ADDITIONAL_INFO_COMMENT').'</div>
180
181 <div class="adm-bus-moreInfo_part2">
182 <table class="adm-detail-content-table edit-table" border="0" width="100%" cellpadding="0" cellspacing="0">
183 <tbody>
184 <tr>
185 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_ADDITIONAL_INFO_MANAGER_COMMENT').':</td>
186 <td class="adm-detail-content-cell-r">
187 <div>
188 <textarea style="width:400px;min-height:100px;" name="'.$formPrefix.'[COMMENTS]" id="COMMENTS"'.($orderLocked ? ' disabled' : '').'>'
189 .htmlspecialcharsbx($data['COMMENTS']).
190 '</textarea>
191 </div>
192 </td>
193 </tr>
194 </tbody>
195 </table>
196 </div>';
197 }
198
199 public static function getView($collection, $formName)
200 {
201 $data = self::prepareData($collection);
202 $blockEmpResponsible = '';
203
204 if(get_class($collection) == 'Bitrix\Sale\Order')
205 $orderLocked = \Bitrix\Sale\Order::isLocked($collection->getId());
206 else
207 $orderLocked = false;
208
209 if ($formName == "archive")
210 $orderLocked = true;
211
212 if (isset($data['EMP_RESPONSIBLE']) && !empty($data['EMP_RESPONSIBLE']))
213 {
214 $blockEmpResponsible = '
215 <tr>
216 <td class="adm-detail-content-cell-l vat" width="40%"></td>
217 <td class="adm-detail-content-cell-r">
218 <div>'.Loc::getMessage('SALE_ORDER_ADDITIONAL_INFO_CHANGE_BY').': <span style="color: #66878F" id="order_additional_info_date_responsible">'.$data['DATE_RESPONSIBLE'].'</span> <a href="" id="order_additional_info_emp_responsible">'.htmlspecialcharsbx($data['EMP_RESPONSIBLE']).'</a></div>
219 </td>
220 </tr>
221 ';
222 }
223
224 $additionalInfo = '';
225
226 if (isset($data['ADDITIONAL_INFO']) && !empty($data['ADDITIONAL_INFO']))
227 {
228 $additionalInfo = '
229 <table class="adm-detail-content-table edit-table" border="0" width="100%" cellpadding="0" cellspacing="0">
230 <tbody>
231 <tr>
232 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_ADDITIONAL_INFO_ADDITIONAL_INFO').':</td>
233 <td class="adm-detail-content-cell-r">'.$data['ADDITIONAL_INFO'].'</td>
234 </tr>
235 </tbody>
236 </table>';
237 }
238
239 if (isset($data['COMPANY_ID']) && !empty($data['COMPANY_ID']))
240 {
241 $companyList = OrderEdit::getCompanyList();
242
243 $additionalInfo .= '
244 <table class="adm-detail-content-table edit-table" border="0" width="100%" cellpadding="0" cellspacing="0">
245 <tbody>
246 <tr>
247 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_ADDITIONAL_INFO_COMPANY').':</td>
248 <td class="adm-detail-content-cell-r">'.htmlspecialcharsbx($companyList[$data['COMPANY_ID']]).'</td>
249 </tr>
250 </tbody>
251 </table>';
252 }
253
254 return '
255 <table class="adm-detail-content-table edit-table" border="0" width="100%" cellpadding="0" cellspacing="0">
256 <tbody>
257 <tr>
258 <td class="adm-detail-content-cell-l vat" width="40%">'.Loc::getMessage('SALE_ORDER_ADDITIONAL_INFO_RESPONSIBLE').':</td>
259 <td class="adm-detail-content-cell-r">
260 <div>'.static::renderResponsibleLink($data).'</div>
261 </td>
262 </tr>
263 '.$blockEmpResponsible.'
264 </tbody>
265 </table>
266 '.$additionalInfo.'
267 <table class="adm-detail-content-table edit-table" border="0" width="100%" cellpadding="0" cellspacing="0">
268 <tbody>
269 <tr>
270 <td class="adm-detail-content-cell-l'.($orderLocked ? '' : ' vat').'" width="40%">'.Loc::getMessage('SALE_ORDER_ADDITIONAL_INFO_MANAGER_COMMENT').':</td>
271 <td class="adm-detail-content-cell-r">'.($orderLocked ? '' : '<a href="javascript:void(0);" style="text-decoration: none; border-bottom: 1px dashed" onClick="BX.Sale.Admin.OrderAdditionalInfo.showCommentsDialog(\''.$collection->getField('ID').'\', BX(\'sale-adm-comments-view\'))">'.Loc::getMessage('SALE_ORDER_ADDITIONAL_INFO_COMMENT_TITLE').'</a>').
272 '<p id="sale-adm-comments-view" style="color:gray; max-width:800px; overflow:auto;">'.($data['COMMENTS'] <> '' ? nl2br(htmlspecialcharsbx($data['COMMENTS'])) : '').'</p>
273 </td>
274 </tr>
275 </tbody>
276 </table>';
277 }
278
279 protected static function renderResponsibleLink($data)
280 {
281 $responsible = $data['RESPONSIBLE'] ?? '';
282 $responsibleId = $data['RESPONSIBLE_ID'] ?? 0;
283
284 return '<a href="/bitrix/admin/user_edit.php?lang='.LANGUAGE_ID.'&ID=' . $responsibleId . '" id="order_additional_info_responsible">' . htmlspecialcharsbx($responsible) . '</a>';
285 }
286
287 public static function getScripts()
288 {
289 \Bitrix\Main\Page\Asset::getInstance()->addJs("/bitrix/js/sale/admin/order_additional_info.js");
290 return '<script type="text/javascript">'.
291 'BX.message({
292 SALE_ORDER_ADDITIONAL_INFO_COMMENT_EDIT: "'.\CUtil::jsEscape(Loc::getMessage("SALE_ORDER_ADDITIONAL_INFO_COMMENT_EDIT")).'",
293 SALE_ORDER_ADDITIONAL_INFO_COMMENT_SAVE: "'.\CUtil::jsEscape(Loc::getMessage("SALE_ORDER_ADDITIONAL_INFO_COMMENT_SAVE")).'",
294 SALE_ORDER_ADDITIONAL_INFO_NO_COMMENT: "'.\CUtil::jsEscape(Loc::getMessage("SALE_ORDER_ADDITIONAL_INFO_NO_COMMENT")).'"
295 })'.
296 '</script>';
297 }
298
299 protected static function prepareData($collection)
300 {
301 global $USER;
302 $data = array();
303
304 if (is_null($collection))
305 {
306 $data['COMMENTS'] = '';
307 }
308 else
309 {
310 if (intval($collection->getField('EMP_RESPONSIBLE_ID')) > 0)
311 $data['EMP_RESPONSIBLE'] = \Bitrix\Sale\Helpers\Admin\OrderEdit::getUserName($collection->getField('EMP_RESPONSIBLE_ID'));
312
313 $dateResponsibleId = $collection->getField('DATE_RESPONSIBLE_ID');
314 if (!is_null($dateResponsibleId))
315 $data['DATE_RESPONSIBLE'] = $dateResponsibleId->toString();
316
317 $data['COMMENTS'] = $collection->getField('COMMENTS');
318 }
319
320 if (intval($collection->getField('RESPONSIBLE_ID')) > 0)
321 {
322 $data['RESPONSIBLE'] = \Bitrix\Sale\Helpers\Admin\OrderEdit::getUserName($collection->getField('RESPONSIBLE_ID'));
323 $data['RESPONSIBLE_ID'] = intval($collection->getField('RESPONSIBLE_ID'));
324 }
325 else
326 {
327 $data['RESPONSIBLE_ID'] = '';
328 }
329
330
331 if(in_array("ADDITIONAL_INFO", $collection->getAvailableFields()))
332 if($collection->getField("ADDITIONAL_INFO") <> '')
333 $data["ADDITIONAL_INFO"] = $collection->getField("ADDITIONAL_INFO");
334
335 if(in_array("COMPANY_ID", $collection->getAvailableFields()))
336 {
337 if(strval($collection->getField("COMPANY_ID")) != '')
338 {
339 $data["COMPANY_ID"] = $collection->getField("COMPANY_ID");
340 }
341 }
342
343 return $data;
344 }
345}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getEdit($collection, $formName, $formPrefix, array $post=array())
static makeSelectHtmlWithRestricted($name, array $data, $selected="", $showNotUse=true, $attributes=array())