Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
orderanalysis.php
1<?php
2
4
6use Bitrix\Sale\Company;
16
17Loc::loadMessages(__FILE__);
18
20{
21 public static function getScripts()
22 {
23 return '';
24 }
25
26 private static function sortDocumentsByDate($doc1, $doc2)
27 {
28 $date1 = $doc1->getField($doc1 instanceof Payment ? 'DATE_PAID' : 'DATE_INSERT');
29 $date2 = $doc2->getField($doc2 instanceof Payment ? 'DATE_PAID' : 'DATE_INSERT');
30 return $date1 > $date2 ? 1 : -1;
31 }
32
33 public static function getView(Order $order, OrderBasket $orderBasket, $selectPayment = null, $selectId = null)
34 {
35 global $APPLICATION, $USER;
36 // prepare data
37
38 $orderId = $order->getId();
39 $data = $orderBasket->prepareData();
40 $items = $data['ITEMS'];
41 $documents = array();
42 $documentAllowList = array();
43 static $userCompanyList = array();
44 $isUserResponsible = false;
45 $isAllowCompany = false;
46 $itemNo = 0;
47
48
49
50 $saleModulePermissions = $APPLICATION->GetGroupRight("sale");
51
52 if($saleModulePermissions == "P")
53 {
54 if (empty($userCompanyList))
55 {
56 $userCompanyList = Manager::getUserCompanyList($USER->GetID());
57 }
58
59 if ($order->getField('RESPONSIBLE_ID') == $USER->GetID())
60 {
61 $isUserResponsible = true;
62 }
63
64 if (in_array($order->getField('COMPANY_ID'), $userCompanyList))
65 {
66 $isAllowCompany = true;
67 }
68 }
69
71 foreach ($order->getPaymentCollection() as $payment)
72 {
73 $documents []= $payment;
74
75 $documentAllowList['PAYMENT'][$payment->getId()] = true;
76
77 if ($saleModulePermissions == "P")
78 {
79 $isPaymentUserResponsible = ($isUserResponsible || $payment->getField('RESPONSIBLE_ID') == $USER->GetID());
80 $isPaymentAllowCompany = ($isAllowCompany || in_array($payment->getField('COMPANY_ID'), $userCompanyList));
81 $documentAllowList['PAYMENT'][$payment->getId()] = ($isPaymentUserResponsible || $isPaymentAllowCompany);
82 }
83
84 }
85
87 foreach ($order->getShipmentCollection() as $shipment)
88 {
89 if (! $shipment->isSystem())
90 {
91 if (! $shipment->isCanceled() && $shipment->isShipped())
92 {
94 foreach ($shipment->getShipmentItemCollection() as $shipmentItem)
95 {
96 $basketCode = $shipmentItem->getBasketCode();
97
98 if ($basketCode && isset($items[$basketCode]))
99 {
100 $item = &$items[$basketCode];
101 if ($shippedQuantity = &$item['SHIPPED_QUANTITY'])
102 $shippedQuantity += (float) $shipmentItem->getField('QUANTITY');
103 else
104 $shippedQuantity = (float) $shipmentItem->getField('QUANTITY');
105 }
106 }
107 }
108
109 $documents []= $shipment;
110
111 $documentAllowList['SHIPMENT'][$shipment->getId()] = true;
112
113 if ($saleModulePermissions == "P")
114 {
115 $isShipmentUserResponsible = ($isUserResponsible || $shipment->getField('RESPONSIBLE_ID') == $USER->GetID());
116 $isShipmentAllowCompany = ($isAllowCompany || in_array($shipment->getField('COMPANY_ID'), $userCompanyList));
117 $documentAllowList['SHIPMENT'][$shipment->getId()] = ($isShipmentUserResponsible || $isShipmentAllowCompany);
118 }
119 }
120 }
121
122 unset($item, $shippedQuantity);
123
124 usort($documents, array(__CLASS__, 'sortDocumentsByDate'));
125
126 // render view
127
128 ob_start();
129
130 ?>
131 <div class="adm-s-order-table-ddi">
132 <table class="adm-s-order-table-ddi-table adm-s-bus-ordertable-option" style="width: 100%;">
133 <thead>
134 <tr>
135 <td class="tac"><?=Loc::getMessage('SALE_OANALYSIS_ITEM_NUMBER')?></td>
136 <td><?=Loc::getMessage('SALE_OANALYSIS_ITEM_NAME')?></td>
137 <td class="tac"><?=Loc::getMessage('SALE_OANALYSIS_ITEM_PROPERTIES')?></td>
138 <td class="tac"><?=Loc::getMessage('SALE_OANALYSIS_ITEM_PLANNED')?></td>
139 <td class="tac"><?=Loc::getMessage('SALE_OANALYSIS_ITEM_SHIPPED')?></td>
140 <td class="tac"><?=Loc::getMessage('SALE_OANALYSIS_ITEM_TO_SHIP')?></td>
141 </tr>
142 </thead>
143 <tbody>
144 <?foreach ($items as $item):
145 $properties = '<table style="margin: auto; width: 50%;">';
146 if (isset($item['SKU_PROPS']) && is_array($item['SKU_PROPS']))
147 {
148 foreach ($item['SKU_PROPS'] as $skuProp)
149 {
150 $properties .= '<tr>';
151 $properties .= '<td style="text-align: left; padding-left: 0;">'. htmlspecialcharsbx($skuProp['NAME']).' : '.'</td>';
152
153 if (isset($skuProp['VALUE']['PICT']) && $skuProp['VALUE']['PICT'])
154 $properties .= '<td><span class="color"><img src="'.$skuProp['VALUE']['PICT'].'" alt=""></span></td>';
155 else
156 $properties .= '<td><span>'.htmlspecialcharsbx($skuProp['VALUE']['NAME']).'</span></td>';
157
158 $properties .= '</tr>';
159 }
160 }
161 $properties .= '</table>';
162
163 $quantity = (float)($item['QUANTITY'] ?? 0);
164
165 $shippedQuantity = (float)($item['SHIPPED_QUANTITY'] ?? 0);
166
167 ?>
168 <tr class="bdb-line">
169 <td class="tac"><?=++$itemNo?></td>
170 <td style="text-align: left;"><?=static::renderShipmentItemLink($item)?></td>
171 <td class="tac"><?=$properties;?></td>
172 <td class="tac" style="text-align: right !important;"><?=$quantity.' '.htmlspecialcharsEx($item['MEASURE_TEXT'])?></td>
173 <td class="tac" style="text-align: right !important;;"><?=$shippedQuantity.' '.htmlspecialcharsEx($item['MEASURE_TEXT'])?></td>
174 <td class="tac" style="text-align: right !important;;"><?=($quantity - $shippedQuantity).' '.htmlspecialcharsEx($item['MEASURE_TEXT'])?></td>
175 </tr>
176 <?endforeach?>
177 <tr><td colspan="8" style="padding: 16px; background: #f7fafa; text-align: right;" class="fwb"><?=Loc::getMessage('SALE_OANALYSIS_ITEMS_QUANTITY').': '.count($items)?></td></tr>
178 </tbody>
179 </table>
180 <div class="adm-bus-table-contaier-white caption border" style="margin-top: 25px;">
181 <div class="adm-bus-table-caption-white-title"><?=Loc::getMessage('SALE_OANALYSIS_DOCUMENTS')?>:</div>
182 <div class="adm-bus-orderdocs-threelist-container">
183 <div class="adm-bus-orderdocs-threelist-block-top<?=$selectPayment === null ? ' adm-bus-orderdocs-threelist-block-children-open' : ''?>">
184 <div class="adm-bus-orderdocs-threelist-block-img adm-bus-orderdocs-threelist-block-img-order"></div>
185 <div class="adm-bus-orderdocs-threelist-block-content">
186 <div class="adm-bus-orderdocs-threelist-block-title">
187 <?=static::renderOrderLink(['order'=>$order])?>
188 </div>
189 <?self::renderBottomBlocks($order->getField('DATE_INSERT'), $order->getField('RESPONSIBLE_ID'))?>
190 </div>
191 <div class="clb"></div>
192 </div>
193 <?foreach ($documents as $document): $isPayment = $document instanceof Payment; $documentId = $document->getId()?>
194 <div class="adm-bus-orderdocs-threelist-block-children<?=$selectPayment === $isPayment && $selectId == $documentId ? ' adm-bus-orderdocs-threelist-block-children-open' : ''?>">
195 <div class="adm-bus-orderdocs-threelist-block-img adm-bus-orderdocs-threelist-block-img-doc_<?=$isPayment ? 'payment' : 'shipping'?>"></div>
196 <div class="adm-bus-orderdocs-threelist-block-content">
197 <div class="adm-bus-orderdocs-threelist-block-title">
198 <?if ($isPayment):
199 $isAllowCompany = $documentAllowList['PAYMENT'][$documentId];
200 ?>
201 <?if ($document->isPaid()):?>
202 <span class="adm-bus-orderdocs-docstatus adm-bus-orderdocs-docstatus-paid"><?=Loc::getMessage('SALE_OANALYSIS_PAYMENT_PAID')?></span>
203 <?elseif ($document->isReturn()):?>
204 <span class="adm-bus-orderdocs-docstatus"><?=Loc::getMessage('SALE_OANALYSIS_PAYMENT_RETURN')?></span>
205 <?endif?>
206 <? if ($isAllowCompany):?>
207 <?=static::renderPaymentEditLink(['payment'=>$document])?>
208 <?else:?>
209 <?= Loc::getMessage('SALE_OANALYSIS_HIDDEN');?>
210 <? endif; ?>
211 <?else:/* shipment*/
212 $isAllowCompany = $documentAllowList['SHIPMENT'][$documentId];
213 ?>
214 <?if ($document->isShipped()):?>
215 <span class="adm-bus-orderdocs-docstatus adm-bus-orderdocs-docstatus-shippingallowed"><?=Loc::getMessage('SALE_OANALYSIS_SHIPMENT_SHIPPED')?></span>
216 <?elseif ($document->isCanceled()):?>
217 <span class="adm-bus-orderdocs-docstatus adm-bus-orderdocs-docstatus-canceled"><?=Loc::getMessage('SALE_OANALYSIS_SHIPMENT_CANCELED')?></span>
218 <?elseif ($document->isAllowDelivery()):?>
219 <span class="adm-bus-orderdocs-docstatus adm-bus-orderdocs-docstatus-shippingallowed"><?=Loc::getMessage('SALE_OANALYSIS_SHIPMENT_ALLOWED')?></span>
220 <?endif?>
221 <? if ($isAllowCompany): ?>
222 <?=static::renderShipmentEditLink(['shipment'=>$document])?>
223 <?else:?>
224 <?= Loc::getMessage('SALE_OANALYSIS_HIDDEN');?>
225 <? endif; ?>
226 <?endif?>
227 </div>
228 <?self::renderBottomBlocks($document->getField($isPayment ? 'DATE_BILL' : 'DATE_INSERT'), $document->getField('RESPONSIBLE_ID'))?>
229 </div>
230 <div class="clb"></div>
231 </div>
232 <?if(!$isPayment):?>
233 <?self::printDeliveryRequestBlock($document->getId());?>
234 <?endif;?>
235 <?endforeach?>
236 </div>
237 </div>
238 </div>
239 <?
240
241 $result = ob_get_contents();
242 ob_end_clean();
243 return $result;
244 }
245
246 private static function printDeliveryRequestBlock($shipmentId)
247 {
248 $res = ShipmentTable::getList(
249 array(
250 'filter' => array('=SHIPMENT_ID' => $shipmentId),
251 'select' => array(
252 'REQUEST_ID',
253 'REQUEST_DATE' => 'REQUEST.DATE',
254 )
255 )
256 );
257
258 $shipment = $res->fetch();
259
260 if ($shipment && intval($shipment['REQUEST_ID']) > 0)
261 {
262 ?>
263 <div class="adm-bus-orderdocs-threelist-block-children" style="padding-left: 60px;">
264 <div class="adm-bus-orderdocs-threelist-block-img adm-bus-orderdocs-threelist-block-img-doc_shipping"></div>
265 <div class="adm-bus-orderdocs-threelist-block-content">
266 <div class="adm-bus-orderdocs-threelist-block-title">
267 <?=static::renderDeliveryRequestView(['ID'=>$shipment['REQUEST_ID']])?>
268 </div>
269 <div class="adm-bus-orderdocs-threelist-block-date-block">
270 <?=Loc::getMessage('SALE_OANALYSIS_CREATED_AT')?>: <span class="adm-bus-orderdocs-threelist-block-date"><?=$shipment['REQUEST_DATE']?></span>
271 </div>
272 </div>
273 <div class="clb"></div>
274 </div>
275 <?
276 }
277 }
278
279 private static function renderBottomBlocks($creationDate, $userId)
280 {
281 $userName = '';
282
283 if ($userId && ($user = \CUser::GetByID($userId)->Fetch()))
284 {
285 if ($user['NAME'])
286 $userName = $user['NAME'];
287 if ($user['LAST_NAME'])
288 $userName .= ($userName ? ' ' : '').$user['LAST_NAME'];
289 if (! $userName)
290 $userName = $user['LOGIN'];
291 }
292
293 ?>
294 <div class="adm-bus-orderdocs-threelist-block-date-block">
295 <?=Loc::getMessage('SALE_OANALYSIS_CREATED_AT')?>: <span class="adm-bus-orderdocs-threelist-block-date"><?=$creationDate?></span>
296 </div>
297 <?if ($userName) :?>
298 <div class="adm-bus-orderdocs-threelist-block-responsible-block">
299 <?=Loc::getMessage('SALE_OANALYSIS_RESPONSIBLE')?>:
300 <?=static::renderResponsibleLink(['RESPONSIBLE_ID'=>$userId, 'RESPONSIBLE'=>$userName])?>
301 </div>
302 <?endif;?>
303 <?
304 }
305 protected static function renderShipmentItemLink($item)
306 {
307 if (!isset($item['EDIT_PAGE_URL']))
308 {
309 return htmlspecialcharsEx($item['NAME']);
310 }
311 return
312 '<a class="fwb" href="' . htmlspecialcharsbx($item['EDIT_PAGE_URL']) . '">'
313 . htmlspecialcharsEx($item['NAME'])
314 . '</a>'
315 ;
316 }
317 protected static function renderOrderLink($data)
318 {
320 $order = $data['order'];
321
322 $url = Link::getInstance()
323 ->create()
324 ->setPageByType(Registry::SALE_ORDER_EDIT)
325 ->setFilterParams(false)
326 ->setField('ID', $order->getId())
327 ->fill()
328 ->build();
329
330 return '<a class="adm-bus-orderdocs-threelist-block-title-link fwb" href="'.$url.'">'.
331 Loc::getMessage('SALE_OANALYSIS_ORDER_TITLE', array(
332 '#USER_ID#' => $order->getField('USER_ID'),
333 '#ORDER_ID#' => $order->getId())
334 ).'</a>';
335 }
336 protected static function renderPaymentEditLink($data)
337 {
339 $payment = $data['payment'];
340
341 $url = Link::getInstance()
342 ->create()
343 ->setPageByType(Registry::SALE_ORDER_PAYMENT_EDIT)
344 ->setFilterParams(false)
345 ->setLang(false)
346 ->setField('order_id', $payment->getOrderId())
347 ->setField('payment_id', $payment->getId())
348 ->fill()
349 ->build();
350
351 return '<a href="'.$url.'" class="adm-bus-orderdocs-threelist-block-title-link">'.Loc::getMessage('SALE_OANALYSIS_PAYMENT_TITLE', array(
352 '#SYSTEM_NAME#' => htmlspecialcharsbx($payment->getField('PAY_SYSTEM_NAME')),
353 '#PAYMENT_ID#' => $payment->getId(),
354 '#SUM#' => SaleFormatCurrency($payment->getField('SUM'), $payment->getField('CURRENCY')),
355 )).'</a>';
356 }
357 protected static function renderShipmentEditLink($data)
358 {
360 $shipment = $data['shipment'];
361
362 $url = Link::getInstance()
363 ->create()
364 ->setPageByType(Registry::SALE_ORDER_SHIPMENT_EDIT)
365 ->setFilterParams(false)
366 ->setLang(false)
367 ->setField('order_id', $shipment->getOrder()->getId())
368 ->setField('shipment_id', $shipment->getId())
369 ->fill()
370 ->build();
371
372 return '<a href="'.$url.'" class="adm-bus-orderdocs-threelist-block-title-link'.($shipment->isCanceled() ? "adm-bus-orderdocs-threelist-block-title-link-canceled" : "").'">'.
373 Loc::getMessage('SALE_OANALYSIS_SHIPMENT_TITLE', array(
374 '#SHIPMENT_ID#' => $shipment->getId(),
375 '#ORDER_ID#' => $shipment->getOrder()->getId()
376 )).'</a>';
377 }
378 protected static function renderResponsibleLink($data)
379 {
380 return '<a class="adm-bus-orderdocs-threelist-block-responsible-name" href="/bitrix/admin/user_edit.php?ID='.$data['RESPONSIBLE_ID'].'">'.htmlspecialcharsbx($data['RESPONSIBLE']).'</a>';
381 }
382 protected static function renderDeliveryRequestView($data)
383 {
384 $id = $data['ID'];
385
386 $url = Link::getInstance()
387 ->create()
388 ->setPageByType(Registry::SALE_DELIVERY_REQUEST_VIEW)
389 ->setFilterParams(false)
390 ->setField('ID', $id)
391 ->fill()
392 ->build();
393
394 return '<a href="'.$url.'" class="adm-bus-orderdocs-threelist-block-title-link">'.
395 Loc::getMessage('SALE_OANALYSIS_DELIVERY_REQUEST', array(
396 '#REQUEST_ID#' => $id
397 )).'</a>';
398 }
399}
400
401
402
403
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
if(Main\Loader::includeModule("rest")) endif
Definition rating.php:7
if(!function_exists(__NAMESPACE__.'\\___1034172934'))
Definition license.php:1