58 if ($this->internalId === 0)
60 if ($this->getId() > 0)
62 $this->internalId = $this->getId();
66 static::$idShipment++;
67 $this->internalId = static::$idShipment;
80 "BASE_PRICE_DELIVERY",
83 "DATE_ALLOW_DELIVERY",
84 "EMP_ALLOW_DELIVERY_ID",
88 "REASON_UNDO_DEDUCTED",
106 "DATE_RESPONSIBLE_ID",
107 "EMP_RESPONSIBLE_ID",
110 "CUSTOM_PRICE_DELIVERY",
113 "VERSION_1C",
"ID_1C",
115 "TRACKING_LAST_CHECK",
116 "TRACKING_DESCRIPTION",
127 return [
'PRICE_DELIVERY' =>
'PRICE_DELIVERY',
'WEIGHT' =>
'WEIGHT'];
136 if (isset($values[
'DEDUCTED']))
138 if ($this->getField(
'DEDUCTED') ===
'Y')
140 if ($values[
'DEDUCTED'] ===
'N')
142 $values = [
'DEDUCTED' => $values[
'DEDUCTED']] + $values;
147 if ($values[
'DEDUCTED'] ===
'Y')
150 unset($values[
'DEDUCTED']);
151 $values[
'DEDUCTED'] =
'Y';
164 return array(
'BASE_PRICE_DELIVERY',
'DELIVERY_ID');
177 $result = $this->
setField(
"DELIVERY_ID", $service->getId());
178 if ($result->isSuccess())
180 $this->
setField(
"DELIVERY_NAME", $service->getName());
195 'CURRENCY' =>
$collection->getOrder()->getCurrency(),
197 'DELIVERY_ID' => $emptyService[
'ID'],
198 'DELIVERY_NAME' => $emptyService[
'NAME'],
199 'ALLOW_DELIVERY' =>
'N',
201 'CUSTOM_PRICE_DELIVERY' =>
'N',
205 'XML_ID' => static::generateXmlId(),
212 $deliveryStatusClassName = $registry->getDeliveryStatusClassName();
213 $fields[
'STATUS_ID'] = $deliveryStatusClassName::getInitialStatus();
215 $shipment = static::createShipmentObject();
216 $shipment->setFieldsNoDemand(
$fields);
221 $shipment->setDeliveryService(
$service);
232 return uniqid(
'bx_');
243 $shipmentClassName = $registry->getShipmentClassName();
245 return new $shipmentClassName(
$fields);
267 if ($condition === ReserveCondition::ON_CREATE)
272 if ($condition === ReserveCondition::ON_PAY
273 || $condition === ReserveCondition::ON_FULL_PAY)
276 if ($condition === ReserveCondition::ON_FULL_PAY)
281 return $order->getPaymentCollection()->hasPaidPayment();
291 $condition === ReserveCondition::ON_ALLOW_DELIVERY
295 $condition === ReserveCondition::ON_SHIP
311 private function transferItem2SystemShipment(
ShipmentItem $sourceItem, $quantity)
314 if ($this !== $sourceItemCollection->getShipment())
319 $quantity = floatval($quantity);
322 $systemShipment = $this->
getCollection()->getSystemShipment();
328 $order = $basketItem->getCollection()->getOrder();
338 $systemShipmentItemCollection = $systemShipment->getShipmentItemCollection();
340 $systemShipmentItem = $systemShipmentItemCollection->getItemByBasketCode($shipmentItemCode);
341 if (is_null($systemShipmentItem))
343 $systemShipmentItem = $systemShipmentItemCollection->createItem($basketItem);
346 $newSystemShipmentItemQuantity = $systemShipmentItem->getQuantity() + $quantity;
347 if ($newSystemShipmentItemQuantity < 0)
349 $result =
new Result();
353 [
"#NAME#",
"#QUANTITY#"],
354 [$sourceItem->
getBasketItem()->getField(
"NAME"), abs($quantity)],
355 Loc::getMessage(
'SALE_SHIPMENT_QUANTITY_MISMATCH')
357 'SALE_SHIPMENT_QUANTITY_MISMATCH'
363 $systemShipmentItem->setFieldNoDemand(
'QUANTITY', $newSystemShipmentItemQuantity);
364 if ($newSystemShipmentItemQuantity <= 1e-10)
366 $systemShipmentItem->delete();
369 $affectedQuantity = 0;
375 $affectedQuantity = $quantity;
376 $originalQuantity = $sourceItem->
getQuantity() + $quantity;
385 if ($systemShipmentItem->getReservedQuantity() > 0)
387 $affectedQuantity = $quantity;
388 if ($systemShipmentItem->getReservedQuantity() < -$affectedQuantity)
390 $affectedQuantity = -1 * $systemShipmentItem->getReservedQuantity();
395 if ($affectedQuantity != 0)
397 $sourceItem->getFields()->set(
399 $sourceItem->getField(
'RESERVED_QUANTITY') - $affectedQuantity
402 $systemShipmentItem->getFields()->set(
404 $systemShipmentItem->getField(
'RESERVED_QUANTITY') + $affectedQuantity
409 ($systemShipmentItem->getField(
"RESERVED_QUANTITY") > 0) ?
"Y" :
"N"
412 $shipmentItemForPool = $sourceItem;
413 $sourceShipmentItemForPool = $systemShipmentItem;
417 $shipmentItemForPool = $systemShipmentItem;
418 $sourceShipmentItemForPool = $sourceItem;
424 $poolItems = Internals\ItemsPool::get(
$order->getInternalId(), $productId);
425 if (!empty($poolItems))
427 foreach ($poolItems as $poolIndex => $poolItem)
429 if ($poolItem->getInternalIndex() === $shipmentItemForPool->getInternalIndex())
435 $sourceShipmentItemForPool
436 && $poolItem instanceof ShipmentItem
437 && $poolItem->getInternalIndex() === $sourceShipmentItemForPool->getInternalIndex()
440 $reserveQuantity = $sourceShipmentItemForPool->getReservedQuantity();
441 if (abs($reserveQuantity) <= 1e-6)
443 Internals\ItemsPool::delete(
$order->getInternalId(), $productId, $poolIndex);
451 Internals\ItemsPool::add(
$order->getInternalId(), $productId, $shipmentItemForPool);
455 $tryReserveResult =
null;
461 if ($systemShipment->needReservation())
463 $tryReserveResult = Internals\Catalog\Provider::tryReserveShipmentItem($systemShipmentItem);
467 $tryReserveResult = Internals\Catalog\Provider::tryUnreserveShipmentItem($systemShipmentItem);
475 && $sourceItemCollection->getShipment()->needReservation()
478 $tryReserveResult = Internals\Catalog\Provider::tryReserveShipmentItem($sourceItem);
484 if ($tryReserveResult ===
null)
489 if ($tryReserveResult !==
null && ($tryReserveResult->isSuccess() && ($tryReserveResultData = $tryReserveResult->getData())))
491 if (array_key_exists(
'CAN_RESERVE', $tryReserveResultData))
493 $canReserve = $tryReserveResultData[
'CAN_RESERVE'];
499 && $systemShipment->needReservation()
505 !Internals\ActionEntity::isTypeExists(
511 Internals\ActionEntity::add(
515 'METHOD' =>
'Bitrix\Sale\ShipmentCollection::updateReservedFlag',
516 'PARAMS' => [$systemShipment->getCollection()]
532 public static function updateReservedFlag(Shipment $shipment)
534 $shipmentReserved =
true;
536 $shipmentItemList = $shipment->getShipmentItemCollection()->getShippableItems();
538 if ($shipmentItemList->count() === 0)
540 $shipmentReserved =
false;
544 foreach ($shipmentItemList as $shipmentItem)
546 if ($shipmentItem->getQuantity() - $shipmentItem->getReservedQuantity())
548 $shipmentReserved =
false;
553 $shipmentReservedValue = $shipmentReserved ?
"Y" :
"N";
554 $currentValue = $shipment->getField(
'RESERVED');
555 if ($shipment->getField(
'RESERVED') != $shipmentReservedValue)
559 if (!empty($eventsList))
563 'ENTITY' => $shipment,
564 'VALUE' => $shipmentReservedValue,
571 $result =
new Result();
573 foreach(
$event->getResults() as $eventResult)
575 if($eventResult->getType() === Main\EventResult::ERROR)
577 $errorMsg =
new ResultError(Main\Localization\Loc::getMessage(
'SALE_EVENT_ON_BEFORE_SHIPMENT_RESERVE_ERROR'),
'SALE_EVENT_ON_BEFORE_SHIPMENT_RESERVE_ERROR');
579 $eventResultData = $eventResult->getParameters();
580 if ($eventResultData)
582 if (isset($eventResultData) && $eventResultData instanceof ResultError)
594 if (!$result->isSuccess())
601 $shipment->setFieldNoDemand(
'RESERVED', $shipmentReserved ?
"Y" :
"N");
604 'ENTITY' => $shipment,
605 'VALUE' => $shipmentReservedValue,
606 'OLD_VALUE' => $currentValue,
631 &&
$name !=
'RESERVED_QUANTITY'
637 if (
$name ===
"QUANTITY")
639 $result = $this->transferItem2SystemShipment($shipmentItem, $oldValue - $value);
641 if (!$this->isMarkedFieldCustom(
'WEIGHT'))
645 $this->getShipmentItemCollection()->
getWeight()
665 'METHOD' =>
'Bitrix\Sale\ShipmentCollection::updateReservedFlag',
666 'PARAMS' => [$this->getCollection()]
688 $shipmentDataList = static::getList(
690 "filter" => [
"=ORDER_ID" =>
$orderId],
695 while ($shipment = $shipmentDataList->fetch())
697 $res = static::deleteInternal($shipment[
'ID']);
699 if (
$res -> isSuccess())
705 $result->addErrors(
$res->getErrors());
723 public function delete()
728 return $result->addError(
730 Loc::getMessage(
'SALE_SHIPMENT_EXIST_SHIPPED'),
731 'SALE_SHIPMENT_EXIST_SHIPPED'
738 $this->
setField(
'BASE_PRICE_DELIVERY', 0);
740 if ($this->getFields()->isMarkedCustom(
'PRICE_DELIVERY'))
742 $this->
setField(
'PRICE_DELIVERY', 0);
751 $this->getShipmentItemCollection()->clearCollection();
753 return parent::delete();
772 $value = (string)$value;
773 if (mb_strlen($value) > 255)
775 $value = mb_substr($value, 0, 255);
779 return parent::normalizeValue(
$name, $value);
799 if (
$name ===
'CUSTOM_PRICE_DELIVERY')
803 $this->markFieldCustom(
'PRICE_DELIVERY');
807 $this->unmarkFieldCustom(
'PRICE_DELIVERY');
811 return parent::setField(
$name, $value);
823 $result = parent::checkValueBeforeSet(
$name, $value);
825 if (
$name ===
"DELIVERY_ID")
827 if (intval($value) > 0 && !
Delivery\
Services\Manager::isServiceExist($value))
831 Loc::getMessage(
'SALE_SHIPMENT_WRONG_DELIVERY_SERVICE'),
832 'SALE_SHIPMENT_WRONG_DELIVERY_SERVICE'
839 $dbRes = static::getList([
841 'filter' => [
'=ACCOUNT_NUMBER' => $value]
848 Loc::getMessage(
'SALE_SHIPMENT_ACCOUNT_NUMBER_EXISTS')
868 if (
$name ===
'CUSTOM_PRICE_DELIVERY')
872 $this->markFieldCustom(
'PRICE_DELIVERY');
876 $this->unmarkFieldCustom(
'PRICE_DELIVERY');
880 parent::setFieldNoDemand(
$name, $value);
891 if (intval($id) <= 0)
898 $shipmentDataList = static::getList(static::getParametersForLoad($id));
899 while ($shipmentData = $shipmentDataList->fetch())
901 $shipments[] = static::createShipmentObject($shipmentData);
916 'DATE_INSERT' =>
'ASC',
932 public function save()
934 $this->checkCallingContext();
938 $id = $this->getId();
939 $this->isNew = ($this->getId() === 0);
941 $this->callEventOnBeforeEntitySaved();
962 if (!$r->isSuccess())
964 $result->addErrors($r->getErrors());
972 $controller = Internals\CustomFieldsController::getInstance();
973 $controller->save($this);
982 $this->callEventOnEntitySaved();
984 $this->callDelayedEvents();
988 if (!$r->isSuccess())
990 $result->addErrors($r->getErrors());
999 $orderHistory = $registry->getOrderHistoryClassName();
1000 $orderHistory::collectEntityFields(
'SHIPMENT', $this->
getParentOrderId(), $id);
1008 if (!
$res->isSuccess())
1010 $result->addWarnings(
$res->getErrors());
1015 $this->isNew =
false;
1023 private function checkCallingContext()
1027 if (!
$order->isSaveRunning())
1029 trigger_error(
"Incorrect call to the save process. Use method save() on \Bitrix\Sale\Order entity", E_USER_WARNING);
1041 private function add()
1043 $result =
new Result();
1050 if (!$r->isSuccess())
1053 $orderHistory = $registry->getOrderHistoryClassName();
1055 $orderHistory::addAction(
1058 'SHIPMENT_ADD_ERROR',
1061 [
"ERROR" => $r->getErrorMessages()]
1064 $result->addErrors($r->getErrors());
1070 $result->setId($id);
1072 $this->setAccountNumber($id);
1077 $orderHistory = $registry->getOrderHistoryClassName();
1079 $orderHistory::addAction(
1095 private function update()
1097 $result =
new Result();
1103 $r = static::updateInternal($this->
getId(), $this->
getFields()->getChangedValues());
1104 if (!$r->isSuccess())
1107 $orderHistory = $registry->getOrderHistoryClassName();
1109 $orderHistory::addAction(
1112 'SHIPMENT_UPDATE_ERROR',
1115 [
"ERROR" => $r->getErrorMessages()]
1118 $result->addErrors($r->getErrors());
1139 private function callDelayedEvents()
1145 foreach ($eventList as $eventName => $eventData)
1153 $notifyClassName = $registry->getNotifyClassName();
1154 $notifyClassName::callNotify($this, $eventName);
1164 private function callEventOnBeforeEntitySaved()
1167 $event =
new Main\Event(
'sale',
'OnBeforeSaleShipmentEntitySaved', [
1169 'VALUES' => $this->fields->getOriginalValues()
1178 private function callEventOnEntitySaved()
1181 $event =
new Main\Event(
'sale',
'OnSaleShipmentEntitySaved', [
1183 'VALUES' => $this->fields->getOriginalValues(),
1184 'IS_NEW' => $this->isNew,
1197 $this->getFields()->
isChanged(
'DEDUCTED')
1233 public function getShipmentItemCollection()
1235 if (empty($this->shipmentItemCollection))
1240 $itemCollectionClassName = $registry->getShipmentItemCollectionClassName();
1241 $this->shipmentItemCollection = $itemCollectionClassName::load($this);
1267 $shipment = static::create(
$collection, $deliveryService);
1268 $shipment->markSystem();
1270 if ($deliveryService ===
null)
1272 $shipment->setFieldNoDemand(
'DELIVERY_ID',
Delivery\
Services\Manager::getEmptyDeliveryServiceId());
1283 return (
float)$this->getField(
'PRICE_DELIVERY');
1292 return $this->isMarkedFieldCustom(
'PRICE_DELIVERY');
1298 $name ===
'BASE_PRICE_DELIVERY'
1299 ||
$name ===
'PRICE_DELIVERY'
1300 ||
$name ===
'DISCOUNT_PRICE'
1309 return (
string)$this->getField(
'CURRENCY');
1317 return (
int)$this->getField(
'DELIVERY_ID');
1325 return (
string)$this->getField(
'DELIVERY_NAME');
1343 if ($this->service ===
null)
1372 return $this->getField(
'SYSTEM') ===
'Y';
1378 return $this->getField(
'CANCELED') ===
'Y';
1386 return $this->getField(
'DEDUCTED') ===
'Y';
1394 return $this->getField(
'DATE_DEDUCTED');
1402 return $this->getField(
'EMP_DEDUCTED_ID');
1410 return (
string)$this->getField(
'REASON_UNDO_DEDUCTED');
1418 return $this->getField(
'MARKED') ===
"Y";
1427 public function isReserved()
1430 foreach ($this->getShipmentItemCollection() as $shipmentItem)
1432 if ($shipmentItem->getReservedQuantity() !== $shipmentItem->getQuantity())
1446 return $this->getField(
'ALLOW_DELIVERY') ===
"Y";
1454 return $this->getShipmentItemCollection()->isEmpty();
1462 return $this->getField(
'DATE_ALLOW_DELIVERY');
1470 return (
int)$this->getField(
'EMP_ALLOW_DELIVERY_ID');
1478 return (
int)$this->getField(
'COMPANY_ID');
1489 return Internals\Catalog\Provider::tryReserveShipment($this);
1499 return Internals\Catalog\Provider::tryUnreserveShipment($this);
1507 public function tryShip()
1512 $r = Internals\Catalog\Provider::tryShipShipment($this);
1513 if ($r->isSuccess())
1515 $resultList = $r->getData();
1517 if (!empty($resultList) && is_array($resultList))
1520 foreach ($resultList as $resultDat)
1522 if (!$resultDat->isSuccess())
1524 $result->addErrors( $resultDat->getErrors() );
1531 $result->addErrors( $r->getErrors() );
1534 if ($r->hasWarnings())
1536 $result->addWarnings( $r->getWarnings() );
1548 return $this->tryShip();
1556 if ($this->fields->isChanged(
'DEDUCTED'))
1558 if ($this->getField(
'DEDUCTED') ===
"Y")
1562 elseif ($this->getField(
'DEDUCTED') ===
"N" && $this->getId() != 0)
1578 if ($result->isSuccess())
1593 return $this->
setField(
'ALLOW_DELIVERY',
"Y");
1603 return $this->
setField(
'ALLOW_DELIVERY',
"N");
1622 if (!$r->isSuccess())
1624 return $result->addErrors($r->getErrors());
1629 return $this->syncQuantityAfterModify($basketItem);
1649 public function onBasketModify(
$action,
BasketItem $basketItem,
$name =
null, $oldValue =
null, $value =
null)
1660 return $this->getShipmentItemCollection()->onBasketModify(
$action, $basketItem,
$name, $oldValue, $value);
1664 if (
$name ===
"QUANTITY")
1668 return $this->syncQuantityAfterModify($basketItem, $value, $oldValue);
1675 if ($r->isSuccess())
1680 if ($deliveryCalculate->isSuccess())
1682 $this->
setField(
'BASE_PRICE_DELIVERY', $deliveryCalculate->getPrice());
1686 $result->addWarnings($deliveryCalculate->getErrors());
1692 $result->addErrors($r->getErrors());
1697 if (!$this->isMarkedFieldCustom(
'WEIGHT'))
1699 if ($this->getShipmentItemCollection()->isExistBasketItem($basketItem))
1709 if ($this->getShipmentItemCollection()->isExistBasketItem($basketItem))
1712 if ($r->isSuccess())
1714 $this->
setField(
'BASE_PRICE_DELIVERY', $r->getPrice());
1718 $result->addErrors($r->getErrors());
1744 $result =
new Result();
1746 if (
$name ===
'DELIVERY_ID')
1751 $this->service ===
null
1752 || $this->service->getId() !== (
int)$value
1756 $service = Delivery\Services\Manager::getObjectById($value);
1761 $this->
setField(
'DELIVERY_NAME', $this->service->getName());
1769 if ($oldValue !=
"Y")
1771 $this->
setField(
'DATE_MARKED',
new Main\Type\DateTime());
1773 if (is_object(
$USER))
1780 $this->
setField(
'REASON_MARKED',
'');
1785 $this->
setField(
'DATE_ALLOW_DELIVERY',
new Main\Type\DateTime());
1787 if (is_object(
$USER))
1792 if ($oldValue ===
'N')
1794 $shipmentStatus = Main\Config\Option::get(
'sale',
'shipment_status_on_allow_delivery',
'');
1798 $deliveryStatusClassName = $registry->getDeliveryStatusClassName();
1801 $shipmentStatus !==
''
1802 && $this->getField(
'STATUS_ID') != $deliveryStatusClassName::getFinalStatus()
1805 $r = $this->setStatus($shipmentStatus);
1806 if (!$r->isSuccess())
1808 $result->addErrors($r->getErrors());
1813 Internals\EventsPool::addEvent(
1818 'VALUES' => $this->fields->getOriginalValues()
1824 $this->
setField(
'DATE_DEDUCTED',
new Main\Type\DateTime());
1826 if (is_object(
$USER))
1831 if ($oldValue ===
'N')
1833 $shipmentStatus = Main\Config\Option::get(
'sale',
'shipment_status_on_shipped',
'');
1837 $deliveryStatusClassName = $registry->getDeliveryStatusClassName();
1839 if (strval($shipmentStatus) !=
'' && $this->getField(
'STATUS_ID') != $deliveryStatusClassName::getFinalStatus())
1841 $r = $this->setStatus($shipmentStatus);
1842 if (!$r->isSuccess())
1844 $result->addErrors($r->getErrors());
1852 foreach ($this->getShipmentItemCollection() as $shipmentItem)
1854 $r = $shipmentItem->checkMarkingCodeOnDeducted();
1855 if (!$r->isSuccess())
1857 $result->addErrors($r->getErrors());
1862 Internals\EventsPool::addEvent(
1867 'VALUES' => $this->fields->getOriginalValues()
1871 Cashbox\Internals\Pool::addDoc($this->
getOrder()->getInternalId(), $this);
1881 'OLD_VALUE' => $oldValue,
1886 Internals\EventsPool::addEvent(
1892 'OLD_VALUE' => $oldValue,
1896 Internals\EventsPool::addEvent(
1902 'OLD_VALUE' => $oldValue,
1908 $this->
setField(
'DATE_RESPONSIBLE_ID',
new Main\Type\DateTime());
1914 Internals\EventsPool::addEvent(
1919 'VALUES' => $this->
getFields()->getOriginalValues(),
1925 $r = parent::onFieldModify(
$name, $oldValue, $value);
1926 if (!$r->isSuccess())
1928 return $result->addErrors($r->getErrors());
1932 $name ===
'BASE_PRICE_DELIVERY'
1933 && !$this->isMarkedFieldCustom(
'PRICE_DELIVERY')
1936 $value -= $this->getField(
'DISCOUNT_PRICE');
1938 $r = $this->
setField(
'PRICE_DELIVERY', $value);
1939 if (!$r->isSuccess())
1941 $result->addErrors($r->getErrors());
1945 if ($r->hasWarnings())
1947 $result->addWarnings($r->getWarnings());
1950 $result->addData($r->getData());
1952 if ($result->isSuccess())
1973 protected function syncQuantityAfterModify(BasketItem $basketItem, $value =
null, $oldValue =
null)
1975 $result =
new Result();
1984 if ($shipmentItem !==
null)
1986 $shipmentItem->setFieldNoDemand(
'QUANTITY', 0);
1992 if ($shipmentItem ===
null)
1997 $deltaQuantity =
$value - $oldValue;
1999 if ($deltaQuantity > 0)
2001 $shipmentItem->setFieldNoDemand(
2003 $shipmentItem->getField(
"QUANTITY") + $deltaQuantity
2011 Internals\Catalog\Provider::tryReserveShipmentItem($shipmentItem);
2016 if (floatval($shipmentItem->getField(
"QUANTITY")) <= 0)
2018 return new Result();
2026 array(
"#NAME#",
"#QUANTITY#",
"#DELTA_QUANTITY#"),
2027 array($basketItem->getField(
"NAME"), $shipmentItem->getField(
"QUANTITY"), abs($deltaQuantity)),
2028 Loc::getMessage(
'SALE_SHIPMENT_SYSTEM_QUANTITY_ERROR')
2030 'SALE_SHIPMENT_SYSTEM_QUANTITY_ERROR'
2038 $shipmentItem->setFieldNoDemand(
2040 $shipmentItem->getField(
"QUANTITY") + $deltaQuantity
2048 Internals\Catalog\Provider::tryReserveShipmentItem($shipmentItem);
2062 $params = $this->getField(
'PARAMS');
2072 $params = $this->getField(
'PARAMS');
2073 $params[
"SERVICE_PARAMS"] = $serviceParams;
2082 if ($this->extraServices ===
null)
2098 || !empty(array_diff_assoc(
$extraServices, $currentExtraServices))
2101 $this->areExtraServicesChanged =
true;
2112 return Delivery\ExtraServices\Manager::getObjectsForShipment(
2132 if ($this->storeId ===
null)
2147 $this->isStoreIdChanged =
true;
2166 return (
float)$this->getField(
'WEIGHT');
2175 return $this->
setField(
'WEIGHT', $weight);
2205 $this->
setField(
'BASE_PRICE_DELIVERY', 0);
2216 public function getBasketItemQuantity(
BasketItem $basketItem)
2230 protected function addChangesToHistory(
$name, $oldValue =
null, $value =
null)
2232 if ($this->getId() > 0 && !$this->
isSystem())
2241 $orderHistory = $registry->getOrderHistoryClassName();
2242 $orderHistory::addField(
2261 public function isExistBasketItem(BasketItem $basketItem)
2266 throw new Main\ObjectNotFoundException(
'Entity "ShipmentItemCollection" not found');
2278 public function verify()
2280 $result =
new Result();
2286 Loc::getMessage(
"SALE_SHIPMENT_DELIVERY_SERVICE_EMPTY"),
2287 'SALE_SHIPMENT_DELIVERY_SERVICE_EMPTY'
2298 $r = $shipmentItem->verify();
2299 if (!$r->isSuccess())
2301 $result->addErrors($r->getErrors());
2316 public function setAccountNumber($id)
2318 $result =
new Result();
2323 $result->addError(
new ResultError(Loc::getMessage(
'SALE_PAYMENT_GENERATE_ACCOUNT_NUMBER_ORDER_NUMBER_WRONG_ID'),
'SALE_PAYMENT_GENERATE_ACCOUNT_NUMBER_ORDER_NUMBER_WRONG_ID'));
2327 $value = Internals\AccountNumberGenerator::generateForShipment($this);
2332 $r = static::updateInternal($id,
array(
"ACCOUNT_NUMBER" => $value));
2333 $res = $r->isSuccess(
true);
2335 catch (Main\DB\SqlQueryException $exception)
2354 $providerInstance =
null;
2356 if (is_array($mapping) && isset($mapping[
'PROVIDER_KEY']))
2358 switch ($mapping[
'PROVIDER_KEY'])
2360 case 'SHIPMENT': $providerInstance = $this;
break;
2361 case 'COMPANY' : $providerInstance = $this->getField(
'COMPANY_ID');
break;
2366 $providerInstance =
$order->getBusinessValueProviderInstance($mapping);
2371 return $providerInstance;
2382 return $order->getPersonTypeId();
2397 return Internals\ShipmentTable::getList($parameters);
2410 public function createClone(\SplObjectStorage $cloneEntity)
2412 if ($this->
isClone() && $cloneEntity->contains($this))
2414 return $cloneEntity[$this];
2418 $shipmentClone = parent::createClone($cloneEntity);
2437 if (!$cloneEntity->contains(
$service))
2442 if ($cloneEntity->contains(
$service))
2444 $shipmentClone->service = $cloneEntity[
$service];
2448 return $shipmentClone;
2459 protected function setStatus(
$status)
2463 $result =
new Result();
2467 $deliveryStatusClassName = $registry->getDeliveryStatusClassName();
2469 if (is_object(
$USER) &&
$USER->isAuthorized())
2471 $statusesList = $deliveryStatusClassName::getAllowedUserStatuses(
$USER->getID(), $this->getField(
'STATUS_ID'));
2482 if (!$r->isSuccess())
2484 $result->addErrors($r->getErrors());
2500 $errorsList = static::getAutoFixErrorsList();
2501 if (is_array($errorsList) && in_array($value, $errorsList))
2503 $className = static::getClassName();
2525 $errorsList = static::getAutoFixErrorsList();
2526 if (is_array($errorsList) && in_array($value, $errorsList))
2547 return array_keys(static::getAutoFixRules());
2561 if (!$r->isSuccess())
2563 $result->addErrors($r->getErrors());
2565 elseif ($r->hasWarnings())
2567 $result->addWarnings($r->getWarnings());
2579 $codeList = static::getAutoFixRules();
2581 if (!empty($codeList[
$code]))
2583 return $codeList[
$code];
2598 $r = $entity->tryReserve();
2599 if (!$r->isSuccess())
2601 $result->addErrors($r->getErrors());
2603 elseif ($r->hasWarnings())
2605 $result->addWarnings($r->getWarnings());
2621 $r = $entity->setField(
'DEDUCTED',
'Y');
2622 if (!$r->isSuccess())
2624 if (!$r->isSuccess())
2626 $result->addErrors($r->getErrors());
2630 $r = $entity->tryShip();
2631 if (!$r->isSuccess())
2633 if (!$r->isSuccess())
2635 $result->addErrors($r->getErrors());
2648 'PROVIDER_BASKET_ITEM_WRONG_AVAILABLE_QUANTITY' => [
'\Bitrix\Sale\Shipment',
"fixReserveErrors"],
2649 'SALE_PROVIDER_RESERVE_SHIPMENT_ITEM_WRONG_AVAILABLE_QUANTITY' => [
'\Bitrix\Sale\Shipment',
"fixReserveErrors"],
2650 'PROVIDER_UNRESERVE_SHIPMENT_ITEM_WRONG_AVAILABLE_QUANTITY' => [
'\Bitrix\Sale\Shipment',
"fixReserveErrors"],
2651 'SALE_PROVIDER_RESERVE_SHIPMENT_ITEM_QUANTITY_NOT_ENOUGH' => [
'\Bitrix\Sale\Shipment',
"fixReserveErrors"],
2653 'SALE_PROVIDER_SHIPMENT_SHIPPED_LESS_QUANTITY' => [
'\Bitrix\Sale\Shipment',
"fixShipErrors"],
2654 'SALE_PROVIDER_SHIPMENT_SHIPPED_MORE_QUANTITY' => [
'\Bitrix\Sale\Shipment',
"fixShipErrors"],
2655 'DDCT_DEDUCTION_QUANTITY_STORE_ERROR' => [
'\Bitrix\Sale\Shipment',
"fixShipErrors"],
2656 'SALE_PROVIDER_SHIPMENT_QUANTITY_NOT_ENOUGH' => [
'\Bitrix\Sale\Shipment',
"fixShipErrors"],
2657 'DDCT_DEDUCTION_QUANTITY_ERROR' => [
'\Bitrix\Sale\Shipment',
"fixShipErrors"],
2682 if (parent::isChanged())
2688 $this->getShipmentItemCollection()->
isChanged()
2690 || $this->isStoreIdChanged
2691 || $this->areExtraServicesChanged
2698 public function clearChanged()
2700 parent::clearChanged();
2707 $shipmentItem->clearChanged();
2727 if (!
Main\Loader::includeModule(
'catalog'))
2738 $dbRes = VatTable::getById($vatId);
2739 $vatInfo =
$dbRes->fetch();
2742 $vatRate = $vatInfo[
'RATE'] / 100;
2757 $price = $this->
getPrice() * $vatRate / (1 + $vatRate);
2769 return Internals\ShipmentTable::add(
$data);
2780 return Internals\ShipmentTable::update($primary,
$data);
2825 $this->markFieldCustom(
'PRICE_DELIVERY');
2828 $r = $this->
setField(
'BASE_PRICE_DELIVERY', $value);
2829 if (!$r->isSuccess())
2831 $result->addErrors($r->getErrors());
2844 return 'SaleShipment';
2854 $result = parent::toArray();
2856 $result[
'ITEMS'] = $this->getShipmentItemCollection()->toArray();
2864 if(empty($this->propertyCollection))
2866 $this->propertyCollection = $this->loadPropertyCollection();
2876 $propertyCollectionClassName = $registry->getShipmentPropertyValueCollectionClassName();
2878 return $propertyCollectionClassName::load($this);