23 PayableShipmentItem::class,
25 function($className, $id) {
31 $pi = $payableItemCollection::getList([
32 'select'=>[
'PAYMENT_ID'],
39 if($piRow = $pi->fetch())
43 $paymentClass = $registry->getPaymentClassName();
45 $r = $paymentClass::getList([
46 'select'=>[
'ORDER_ID'],
47 'filter'=>[
'ID'=>$piRow[
'PAYMENT_ID']]
50 if($row = $r->fetch())
53 $orderClass = $registry->getOrderClassName();
55 $order = $orderClass::load($row[
'ORDER_ID']);
56 $payment = $order->getPaymentCollection()->getItemById($piRow[
'PAYMENT_ID']);
57 $payableItemCollection = $payment->getPayableItemCollection();
59 foreach ($payableItemCollection as $item)
61 if($item->getId() == $id)
69 $this->addError(
new Error(
'payment is not exists', 200640400001));
73 $this->addError(
new Error(
'payment item is not exists', 201240400001));
82 $view = $this->getViewManager()
85 return [
'PAYMENT_ITEM_SHIPMENT'=>$view->prepareFieldInfos(
92 return [
'PAYMENT_ITEM_SHIPMENT'=>$paymentItem->toArray()];
105 public function listAction(
PageNavigation $pageNavigation, array $select = [], array $filter = [], array $order = []):
Page
107 $select = empty($select) ? [
'*'] : $select;
108 $order = empty($order) ? [
'ID' =>
'ASC'] : $order;
115 $paymentItems = $payableItemCollection::getList(
120 'offset' => $pageNavigation->
getOffset(),
121 'limit' => $pageNavigation->
getLimit(),
125 return new Page(
'PAYMENT_ITEMS_SHIPMENT', $paymentItems,
function() use ($filter)
131 return (
int) $payableItemCollection::getList([
141 public function addAction(array $fields): ?array
143 $result =
new Result();
148 $shipmentId = $fields[
'SHIPMENT_ID'];
149 $paymentId = $fields[
'PAYMENT_ID'];
151 unset($fields[
'PAYMENT_ID'], $fields[
'SHIPMENT_ID']);
154 $shipmentClass = $registry->getShipmentClassName();
156 $r = $shipmentClass::getList([
157 'select'=>[
'ORDER_ID'],
158 'filter'=>[
'ID'=>$shipmentId],
161 if($row = $r->fetch())
164 $orderClass = $registry->getOrderClassName();
166 $order = $orderClass::load($row[
'ORDER_ID']);
167 $shipment = $order->getShipmentCollection()->getItemById($shipmentId);
168 if($shipment instanceof \
Bitrix\
Sale\Shipment)
171 $collection = $order->getPaymentCollection();
172 $payment = $collection->getItemById($paymentId);
175 $paymentItems = $payment->getPayableItemCollection()->getShipments();
176 if($this->isExistShipment($paymentItems, $shipment) ==
false)
179 $paymentItem = $payment->getPayableItemCollection()->createItemByShipment($shipment);
180 $result = $paymentItem->setFields($fields);
181 if($result->isSuccess() && $result->hasWarnings() ==
false)
183 $r = $this->save($paymentItem);
186 $result->addErrors($r->getErrors());
192 $result->addError(
new Error(
'Duplicate entry for key [shipmentId, paymentId]', 201250000001));
197 $result->addError(
new Error(
'payment not exists', 201240400002));
203 $result->addError(
new Error(
'shipment not exists', 201240400003));
206 if(!$result->isSuccess())
211 elseif($result->hasWarnings())
213 $this->
addErrors($result->getWarnings());
216 elseif($paymentItem instanceof PayableItem)
218 return [
'PAYMENT_ITEM_SHIPMENT'=>$paymentItem->toArray()];
222 return [
'PAYMENT_ITEM_SHIPMENT'=>$paymentItem];
228 $r = $paymentItem->setFields($fields);
230 if($r->isSuccess() ==
false)
232 $this->addErrors($r->getErrors());
235 elseif($r->hasWarnings())
237 $this->addErrors($r->getWarnings());
242 $r = $this->save($paymentItem);
245 $this->addErrors($r->getErrors());
250 return [
'PAYMENT_ITEM_SHIPMENT'=>$paymentItem->toArray()];
257 $r = $paymentItem->
delete();
259 if($r->isSuccess() ==
false)
261 $this->addErrors($r->getErrors());
264 elseif($r->hasWarnings())
266 $this->addErrors($r->getWarnings());
271 $r = $this->save($paymentItem);
274 $this->addErrors($r->getErrors());
291 $payment = $collectionPaymentItems->getPayment();
293 $collectionPayments = $payment->getCollection();
294 $order = $collectionPayments->getOrder();
299 $result->addErrors($r->getErrors());
301 elseif($r->hasWarnings())
303 $result->addErrors($r->getWarnings());
308 protected function isExistShipment(CollectionFilterIterator $paymentItems, \
Bitrix\
Sale\Shipment $shipment): bool
310 foreach ($paymentItems as $paymentItem)
313 $entityShipment = $paymentItem->getEntityObject();
314 if ($shipment->getInternalIndex() === $entityShipment->getInternalIndex())
327 if ($saleModulePermissions <
"W")
329 $r->addError(
new Error(
'Access Denied', 200040300020));
339 if ($saleModulePermissions ==
"D")
341 $r->addError(
new Error(
'Access Denied', 200040300010));