29 parent::__construct($settings);
35 $fields = array_merge(
44 return parent::prepareFields($fields);
51 $this->formData[
"PAYMENT"] = [
53 'SUM'=>$this->
getOrder()->getPrice(),
55 'PAY_SYSTEM_ID'=>Manager::getInnerPaySystemId()
59 parent::buildPayments();
68 $this->formData[
"SHIPMENT"] = [
74 parent::buildShipments();
84 if (isset($item[
'STATUS_ID']))
86 $statusId = $item[
'STATUS_ID'];
91 $statusId = parent::prepareFieldsStatusId($isNew, $item, $defaultFields);
97 protected function removeShipmentItems(\
Bitrix\
Sale\
Shipment $shipment, $products, $idsFromForm)
101 if(is_array($products))
105 $shipmentItemCollection = $shipment->getShipmentItemCollection();
107 $shipmentItemIds = [];
108 foreach($products as $items)
110 if(!isset($items[
'ORDER_DELIVERY_BASKET_ID']))
113 $shipmentItemProduct = $shipmentItemCollection->getItemById($items[
'ORDER_DELIVERY_BASKET_ID']);
115 if ($shipmentItemProduct ==
null)
118 $shipmentItemIds[] = $shipmentItemProduct->getId();
122 foreach ($shipmentItemCollection as $shipmentItem)
124 if(!in_array($shipmentItem->getId(), $shipmentItemIds))
126 $r = $shipmentItem->delete();
127 if (!$r->isSuccess())
129 $this->errorsContainer->addErrors($r->getErrors());
130 $result->addErrors($r->getErrors());
141 $result =
new Result();
142 $shipmentItemCollection = $shipment->getShipmentItemCollection();
145 if(isset($items[
'ORDER_DELIVERY_BASKET_ID']) && intval($items[
'ORDER_DELIVERY_BASKET_ID']) > 0)
147 if (!$shipmentItem = $shipmentItemCollection->getItemById($items[
'ORDER_DELIVERY_BASKET_ID']))
149 $result->addError(
new Error(
'SALE_ORDER_SHIPMENT_BASKET_ORDER_DELIVERY_ID_NOT_FOUND'));
154 $items[
'BASKET_ID'] = $shipmentItem->getBasketId();
157 return $result->setData([$items]);
164 $basketItem = $shipmentItem->getBasketItem();
166 $basket = $basketItem->getCollection();
168 $order = $basket->getOrder();
170 $allAllowedQuantity = $this->getQuantityBasketItemFromShipmentCollection($basketItem);
172 $deltaQuantity = $params[
'AMOUNT'] - $shipmentItem->getQuantity();
174 if($deltaQuantity < 0)
178 elseif($deltaQuantity > 0)
180 if($allAllowedQuantity >= $params[
'AMOUNT'])
182 $systemShipment =
$order->getShipmentCollection()->getSystemShipment();
183 $systemBasketQuantity = $systemShipment->getBasketItemQuantity($basketItem);
185 if($systemBasketQuantity >= $deltaQuantity)
191 $needQuantity = $deltaQuantity - $systemBasketQuantity;
193 $r = $this->synchronizeQuantityShipmentItems($shipmentItem, $needQuantity);
202 $r->addError(
new \
Bitrix\Main\
Error(
'Attempt to increase the quantity of goods in shipment to a quantity that exceeds not shipped in the order.'));
208 private function getQuantityBasketItemFromShipmentCollection(BasketItem $basketItem)
211 $basket = $basketItem->getCollection();
213 $order = $basket->getOrder();
217 foreach (
$order->getShipmentCollection() as $shipment)
219 if($shipment->isShipped())
222 $allQuantity += $shipment->getBasketItemQuantity($basketItem);
230 $deltaQuantity = $value - $oldValue;
232 if($shipmentItem->
getQuantity() + $deltaQuantity == 0)
234 $r = $shipmentItem->
delete();
247 public function synchronizeQuantityShipmentItems(
ShipmentItem $shipmentItem, $needQuantity)
251 if(intval($needQuantity) <= 0)
259 $parentEntity = $shipmentItemCollection->getShipment();
261 foreach ($parentEntity->getCollection() as $shipment)
264 if($parentEntity->getId() == $shipment->getId())
267 if($shipment->isShipped() || $shipment->isSystem())
270 $basketQuantity = $shipment->getBasketItemQuantity($basketItem);
271 if(empty($basketQuantity))
274 $shipmentItem = $shipment->getShipmentItemCollection()->getItemByBasketCode($basketItem->getBasketCode());
276 if($basketQuantity >= $needQuantity)
284 $needQuantity -= $basketQuantity;
287 if($needQuantity == 0)
291 if($needQuantity != 0)
292 $result->addError(
new Error(
'Not enough unallocated goods in shipments'));
299 if(!isset($this->formData[
"PROPERTIES"]))
304 $r = $this->removePropertyValues();
305 if($r->isSuccess() ==
false)
311 $this->formData[
"PROPERTIES"] = File::getPostWithFiles(
312 $this->formData[
"PROPERTIES"],
313 $this->settingsContainer->getItemValue(
'propsFiles')
316 $propCollection = $this->order->getPropertyCollection();
318 foreach ($this->formData[
"PROPERTIES"] as $id=>$value)
320 if(($propertyValue = $propCollection->getItemByOrderPropertyId($id)))
322 $propertyValue->setValue($value);
334 protected function removePropertyValues()
340 $propCollection = $this->order->getPropertyCollection();
342 foreach($propCollection as $propertyValue)
344 if(is_set($this->formData[
"PROPERTIES"],$propertyValue->getPropertyId()) ==
false)
346 $r = $propertyValue->delete();
347 if (!$r->isSuccess())
349 $result->addErrors($r->getErrors());
361 $orderClass = $this->
getRegistry()->getOrderClassName();
363 return $orderClass::getAvailableFields();