52 return Internals\OrderTable::getMap();
60 return Internals\OrderTable::getUfId();
71 if (!$this->printedChecks
78 return $this->printedChecks;
89 $dbRes = Cashbox\CheckManager::getList([
91 '=ORDER_ID' => $this->getId()
95 while ($data = $dbRes->fetch())
97 $result[] = Cashbox\CheckManager::create($data);
111 $this->printedChecks[] = $check;
131 public function onShipmentCollectionModify($action,
Shipment $shipment, $name =
null, $oldValue =
null, $value =
null)
140 $entityMarker = $registry->getEntityMarkerClassName();
144 if ((
int)$this->getField(
'DELIVERY_ID') === $shipment->
getDeliveryId())
146 $foundShipment =
false;
149 foreach ($this->getShipmentCollection()->getNotSystemItems() as $entityShipment)
151 if ((
int)$entityShipment->getField(
'DELIVERY_ID') > 0)
153 $foundShipment =
true;
154 $this->setFieldNoDemand(
'DELIVERY_ID', $entityShipment->getField(
'DELIVERY_ID'));
159 if (!$foundShipment && !$shipment->
isSystem())
161 $systemShipment = $this->getShipmentCollection()->getSystemShipment();
163 if ((
int)$systemShipment->getField(
'DELIVERY_ID') > 0)
165 $this->setFieldNoDemand(
'DELIVERY_ID', $systemShipment->getField(
'DELIVERY_ID'));
172 if ($shipment->getId() === 0)
188 if ($name ===
"ALLOW_DELIVERY")
192 $result->addError(
new ResultError(
Loc::getMessage(
'SALE_ORDER_ALLOW_DELIVERY_ORDER_CANCELED'),
'SALE_ORDER_ALLOW_DELIVERY_ORDER_CANCELED'));
199 $eventManager = Main\EventManager::getInstance();
210 $result->addErrors($r->getErrors());
221 if (!$r->isSuccess())
223 $result->addErrors($r->getErrors());
226 if ($r->hasWarnings())
228 $result->addWarnings($r->getWarnings());
229 $entityMarker::addMarker($this, $shipment, $r);
239 if (!$r->isSuccess())
241 $result->addErrors($r->getErrors());
244 if ($r->hasWarnings())
246 $result->addWarnings($r->getWarnings());
247 $entityMarker::addMarker($this, $shipment, $r);
255 if (!$result->isSuccess())
263 if ($oldValue ===
"N")
267 $orderStatus = $optionClassName::get(
'sale',
'status_on_allow_delivery',
'');
271 $orderStatus = $optionClassName::get(
'sale',
'status_on_allow_delivery_one_of',
'');
275 if ($orderStatus !==
null && $this->
getField(
'STATUS_ID') != static::getFinalStatus())
277 if ((
string)$orderStatus !=
'')
279 $r = $this->
setField(
'STATUS_ID', $orderStatus);
280 if (!$r->isSuccess())
282 $result->addErrors($r->getErrors());
285 if ($r->hasWarnings())
287 $result->addWarnings($r->getWarnings());
288 $entityMarker::addMarker($this, $this, $r);
298 $r = $shipment->
setField(
"DEDUCTED",
"Y");
299 if (!$r->isSuccess())
301 $result->addErrors($r->getErrors());
304 if ($r->hasWarnings())
306 $result->addWarnings($r->getWarnings());
307 $entityMarker::addMarker($this, $shipment, $r);
319 && $this->
getField(
'ALLOW_DELIVERY') ===
'N'
327 elseif ($name ===
"DEDUCTED")
331 $result->addError(
new ResultError(
Loc::getMessage(
'SALE_ORDER_SHIPMENT_ORDER_CANCELED'),
'SALE_ORDER_SHIPMENT_ORDER_CANCELED'));
344 if (!$r->isSuccess())
346 $result->addErrors($r->getErrors());
349 if ($r->hasWarnings())
351 $result->addWarnings($r->getWarnings());
352 $entityMarker::addMarker($this, $shipment, $r);
362 if (!$r->isSuccess())
364 $result->addErrors($r->getErrors());
367 if ($r->hasWarnings())
369 $result->addWarnings($r->getWarnings());
370 $entityMarker::addMarker($this, $shipment, $r);
382 $r = $shipment->tryShip();
383 if (!$r->isSuccess())
385 $result->addErrors($r->getErrors());
388 if ($r->hasWarnings())
390 $result->addWarnings($r->getWarnings());
391 $entityMarker::addMarker($this, $shipment, $r);
399 elseif ($oldValue ===
'Y')
402 if (!$r->isSuccess())
404 $result->addErrors($r->getErrors());
407 if ($r->hasWarnings())
409 $result->addWarnings($r->getWarnings());
410 $entityMarker::addMarker($this, $shipment, $r);
423 if (!$r->isSuccess())
425 $result->addErrors($r->getErrors());
428 if ($r->hasWarnings())
430 $result->addWarnings($r->getWarnings());
431 $entityMarker::addMarker($this, $shipment, $r);
440 if (!$result->isSuccess())
447 $allowSetStatus =
false;
449 if ($oldValue ===
"N")
453 $orderStatus = $optionClassName::get(
'sale',
'status_on_shipped_shipment',
'');
457 $orderStatus = $optionClassName::get(
'sale',
'status_on_shipped_shipment_one_of',
'');
459 $allowSetStatus = ($this->
getField(
'STATUS_ID') != static::getFinalStatus());
464 $originalValues = $fields->getOriginalValues();
465 if (!empty($originalValues[
'STATUS_ID']))
467 $orderStatus = $originalValues[
'STATUS_ID'];
468 $allowSetStatus =
true;
473 (
string)$orderStatus !==
''
477 $r = $this->
setField(
'STATUS_ID', $orderStatus);
478 if (!$r->isSuccess())
480 $result->addErrors($r->getErrors());
482 elseif ($r->hasWarnings())
484 $result->addWarnings($r->getWarnings());
485 $entityMarker::addMarker($this, $this, $r);
495 if (strval($shipment->getField(
'DATE_DEDUCTED')) !=
'')
497 $this->
setFieldNoDemand(
'DATE_DEDUCTED', $shipment->getField(
'DATE_DEDUCTED'));
499 if (strval($shipment->getField(
'EMP_DEDUCTED_ID')) !=
'')
501 $this->
setFieldNoDemand(
'EMP_DEDUCTED_ID', $shipment->getField(
'EMP_DEDUCTED_ID'));
505 elseif ($name ==
"MARKED")
510 $r = $this->
setField(
'MARKED',
'Y');
511 if (!$r->isSuccess())
513 $result->addErrors($r->getErrors());
517 elseif ($name ==
"REASON_MARKED")
519 $r = $this->setReasonMarked($value);
520 if (!$r->isSuccess())
522 $result->addErrors($r->getErrors());
525 elseif ($name ==
"BASE_PRICE_DELIVERY")
529 $result->addError(
new ResultError(
Loc::getMessage(
'SALE_ORDER_PRICE_DELIVERY_ORDER_CANCELED'),
'SALE_ORDER_PRICE_DELIVERY_ORDER_CANCELED'));
534 $discount->setCalculateShipments($shipment);
536 elseif ($name ==
"PRICE_DELIVERY")
540 $result->addError(
new ResultError(
Loc::getMessage(
'SALE_ORDER_PRICE_DELIVERY_ORDER_CANCELED'),
'SALE_ORDER_PRICE_DELIVERY_ORDER_CANCELED'));
544 $deliveryPrice = ($this->
isNew()) ? $value : $this->
getField(
"PRICE_DELIVERY") - $oldValue + $value;
553 $this->
getField(
"PRICE") - $oldValue + $value
556 if (!$r->isSuccess())
558 $result->addErrors($r->getErrors());
562 elseif ($name ==
"DELIVERY_ID")
564 if ($shipment->
isSystem() || intval($shipment->getField(
'DELIVERY_ID')) <= 0 )
574 elseif ($name ==
"TRACKING_NUMBER")
581 $this->
setFieldNoDemand(
'TRACKING_NUMBER', $shipment->getField(
'TRACKING_NUMBER'));
584 if ($value != $oldValue)
586 $fields = $this->fields->getChangedValues();
587 if (!empty($fields) && !array_key_exists(
"UPDATED_1C", $fields))
589 parent::setField(
"UPDATED_1C",
"N");
601 $entity->getId() === 0
602 && $entity->getField(
'TRADING_PLATFORM_ID') > 0
605 $this->propertyCollection = $this->loadPropertyCollection();
610 if ($name ===
'TRADING_PLATFORM_ID')
612 $this->propertyCollection = $this->loadPropertyCollection();
629 parent::resetData($select);
639 $price = parent::getBasePrice();
659 $r = parent::setBasket($basket);
660 if (!$r->isSuccess())
662 $result->addErrors($r->getErrors());
667 if (!$r->isSuccess())
669 $result->addErrors($r->getErrors());
675 $r = $this->refreshData();
676 if (!$r->isSuccess())
678 $result->addErrors($r->getErrors());
686 $r = $this->doFinalAction($hasMeaningfulFields);
687 if (!$r->isSuccess())
689 $result->addErrors($r->getErrors());
705 public function appendBasket(
BasketBase $basket)
709 $isStartField = $this->isStartField();
711 $r = parent::appendBasket($basket);
712 if (!$r->isSuccess())
714 $result->addErrors($r->getErrors());
719 $result = $this->getShipmentCollection()->resetCollection();
720 if (!$r->isSuccess())
722 $result->addErrors($r->getErrors());
726 if (!$this->isMathActionOnly())
729 $r = $this->refreshData();
730 if (!$r->isSuccess())
732 $result->addErrors($r->getErrors());
741 $r = $this->doFinalAction($hasMeaningfulFields);
742 if (!$r->isSuccess())
744 $result->addErrors($r->getErrors());
760 if (empty($this->shipmentCollection))
765 return $this->shipmentCollection;
778 if (empty($this->tradeBindingCollection))
780 $this->tradeBindingCollection = $this->loadTradeBindingCollection();
783 return $this->tradeBindingCollection;
793 if (empty($this->paymentCollection))
798 return $this->paymentCollection;
808 public function loadShipmentCollection()
813 $shipmentCollectionClassName = $registry->getShipmentCollectionClassName();
814 return $shipmentCollectionClassName::load($this);
823 public function loadPaymentCollection()
828 $paymentCollectionClassName = $registry->getPaymentCollectionClassName();
829 return $paymentCollectionClassName::load($this);
838 protected function loadTradeBindingCollection()
845 return $tradeBindingCollection::load($this);
854 protected static function deleteEntitiesNoDemand($orderId)
856 $r = parent::deleteEntitiesNoDemand($orderId);
857 if (!$r->isSuccess())
863 $shipmentClassName = $registry->getShipmentClassName();
864 $shipmentClassName::deleteNoDemand($orderId);
865 if (!$r->isSuccess())
869 $paymentClassName = $registry->getPaymentClassName();
870 $paymentClassName::deleteNoDemand($orderId);
871 if (!$r->isSuccess())
886 protected static function deleteEntities(OrderBase $order)
888 parent::deleteEntities($order);
891 foreach ($order->getShipmentCollection() as $shipment)
897 foreach ($order->getPaymentCollection() as $payment)
925 public function onPaymentCollectionModify($action,
Payment $payment, $name =
null, $oldValue =
null, $value =
null)
936 if (intval($entityPayment->getField(
'PAY_SYSTEM_ID')) > 0
937 && intval($entityPayment->getField(
'PAY_SYSTEM_ID')) != $payment->
getPaymentSystemId())
939 $this->setFieldNoDemand(
'PAY_SYSTEM_ID', $entityPayment->getField(
'PAY_SYSTEM_ID'));
947 if ($payment->getId() === 0)
958 if (($name ==
"CURRENCY") && ($value != $this->
getField(
"CURRENCY")))
960 throw new Main\NotImplementedException();
963 if ($name ==
"SUM" || $name ==
"PAID")
967 $result->addError(
new ResultError(
Loc::getMessage(
'SALE_ORDER_PAID_ORDER_CANCELED'),
'SALE_ORDER_PAID_ORDER_CANCELED'));
978 $r = $this->syncOrderAndPayments($payment);
979 if (!$r->isSuccess())
981 $result->addErrors($r->getErrors());
983 elseif ($r->hasWarnings())
985 $result->addWarnings($r->getWarnings());
988 elseif ($name ==
"PAY_SYSTEM_ID")
990 $this->
setFieldNoDemand(
'PAY_SYSTEM_ID', $payment->getField(
'PAY_SYSTEM_ID'));
994 elseif ($name ==
"DATE_PAID")
998 elseif ($name ==
"PAY_VOUCHER_NUM")
1000 $this->
setFieldNoDemand(
'PAY_VOUCHER_NUM', $payment->getField(
'PAY_VOUCHER_NUM'));
1002 elseif ($name ==
"PAY_VOUCHER_DATE")
1004 $this->
setFieldNoDemand(
'PAY_VOUCHER_DATE', $payment->getField(
'PAY_VOUCHER_DATE'));
1006 elseif ($name ==
"EMP_PAID_ID")
1008 $this->
setFieldNoDemand(
'EMP_PAYED_ID', $payment->getField(
'EMP_PAID_ID'));
1010 elseif ($name ==
"MARKED")
1015 $r = $this->
setField(
'MARKED',
'Y');
1016 if (!$r->isSuccess())
1018 $result->addErrors($r->getErrors());
1022 elseif ($name ==
"REASON_MARKED")
1024 $r = $this->setReasonMarked($value);
1025 if (!$r->isSuccess())
1027 $result->addErrors($r->getErrors());
1031 if ($value != $oldValue)
1033 $fields = $this->fields->getChangedValues();
1034 if (!empty($fields) && !array_key_exists(
"UPDATED_1C", $fields) && $name !=
'UPDATED_1C')
1036 parent::setField(
"UPDATED_1C",
"N");
1057 $result = parent::onFieldModify($name, $oldValue, $value);
1059 if ($name ==
"PRICE")
1062 if (!$r->isSuccess())
1064 return $result->addErrors($r->getErrors());
1068 if (!$r->isSuccess())
1070 return $result->addErrors($r->getErrors());
1073 $r = $this->syncOrderAndPayments();
1074 if (!$r->isSuccess())
1076 $result->addErrors($r->getErrors());
1079 elseif($name ==
"MARKED")
1083 if (is_object($USER))
1085 $this->
setField(
'EMP_MARKED_ID', $USER->GetID());
1091 if (!$r->isSuccess())
1093 return $result->addErrors($r->getErrors());
1113 if (!$r->isSuccess())
1115 return $result->addErrors($r->getErrors());
1119 if (!$r->isSuccess())
1121 return $result->addErrors($r->getErrors());
1144 if (!$r->isSuccess())
1146 return $result->addErrors($r->getErrors());
1150 if (!$r->isSuccess())
1152 return $result->addErrors($r->getErrors());
1182 $r = parent::onBasketModify($action, $basketItem, $name, $oldValue, $value);
1183 if (!$r->isSuccess())
1185 $result->addErrors($r->getErrors());
1193 if ($basketItem->
getField(
'ORDER_ID'))
1198 return $this->
getShipmentCollection()->onBasketModify($action, $basketItem, $name, $oldValue, $value);
1205 if ($name ===
"QUANTITY")
1207 $r = parent::onBasketModify($action, $basketItem, $name, $oldValue, $value);
1208 if (!$r->isSuccess())
1210 $result->addErrors($r->getErrors());
1214 $r = $this->
getShipmentCollection()->onBasketModify($action, $basketItem, $name, $oldValue, $value);
1215 if (!$r->isSuccess())
1217 $result->addErrors($r->getErrors());
1220 elseif ($r->hasWarnings())
1222 $result->addWarnings($r->getWarnings());
1227 elseif ($name ===
"PRICE")
1229 $r = parent::onBasketModify($action, $basketItem, $name, $oldValue, $value);
1230 if (!$r->isSuccess())
1232 $result->addErrors($r->getErrors());
1238 return $this->
getShipmentCollection()->onBasketModify($action, $basketItem, $name, $oldValue, $value);
1241 elseif ($name ===
'WEIGHT')
1243 return $this->
getShipmentCollection()->onBasketModify($action, $basketItem, $name, $oldValue, $value);
1247 $r = parent::onBasketModify($action, $basketItem, $name, $oldValue, $value);
1248 if (!$r->isSuccess())
1250 $result->addErrors($r->getErrors());
1266 if (!$r->isSuccess())
1268 $result->addErrors($r->getErrors());
1277 public function onAfterBasketRefresh()
1282 foreach ($this->getShipmentCollection() as $shipment)
1285 $shipment->isShipped()
1286 || !$shipment->needReservation()
1293 $r = $shipment->tryReserve();
1294 if (!$r->isSuccess())
1296 $result->addErrors($r->getErrors());
1315 private function syncOrderAndPayments(Payment $payment =
null)
1317 $result =
new Result();
1319 $oldPaid = $this->
getField(
'PAYED');
1325 $finalSumPaid = $sumPaid;
1336 $r = $this->syncOrderPaymentPaid($payment);
1337 if ($r->isSuccess())
1339 $paidResult = $r->getData();
1340 if (isset($paidResult[
'SUM_PAID']))
1342 $finalSumPaid = $paidResult[
'SUM_PAID'];
1347 return $result->addErrors($r->getErrors());
1355 $r = $this->syncOrderPaid();
1356 if (!$r->isSuccess())
1358 return $result->addErrors($r->getErrors());
1361 $paidResult = $r->getData();
1362 if (isset($paidResult[
'SUM_PAID']))
1364 $finalSumPaid = $paidResult[
'SUM_PAID'];
1380 Internals\EventsPool::addEvent(
1388 Internals\EventsPool::addEvent(
1397 if ($finalSumPaid > 0 && $finalSumPaid > $this->
getPrice())
1399 if (!$payment || $payment->
isPaid())
1409 $r = $this->onAfterSyncPaid($oldPaid);
1410 if (!$r->isSuccess())
1412 $result->addErrors($r->getErrors());
1414 elseif ($r->hasWarnings())
1416 $result->addWarnings($r->getWarnings());
1426 private function syncOrderPaymentPaid(Payment $payment)
1428 $result =
new Result();
1430 if ($payment->isPaid())
1437 $userBudget = Internals\UserBudgetPool::getUserBudgetByOrder($this);
1439 $debitSum = $payment->getSum();
1441 $maxPaid = $payment->getSum() + $sumPaid - $this->
getSumPaid();
1443 if ($maxPaid >= $payment->getSum())
1449 $debitSum = $maxPaid;
1450 $finalSumPaid = $sumPaid;
1453 if ($debitSum > 0 && $payment->isInner())
1457 $result->addError(
new ResultError(
Loc::getMessage(
'SALE_ORDER_PAYMENT_CANCELLED_PAID'),
'SALE_ORDER_PAYMENT_NOT_ENOUGH_USER_BUDGET_SYNCPAID') );
1464 $result->setData(array(
'SUM_PAID' => $finalSumPaid));
1472 private function syncOrderPaid()
1474 $result =
new Result();
1482 $userBudget = Internals\UserBudgetPool::getUserBudgetByOrder($this);
1488 if ($debitSum > $bePaid)
1490 $debitSum = $bePaid;
1493 if ($debitSum >= $userBudget)
1495 $debitSum = $userBudget;
1498 if ($userBudget >= $debitSum && $debitSum > 0)
1502 $finalSumPaid = $this->
getSumPaid() + $debitSum;
1503 $result->setData([
'SUM_PAID' => $finalSumPaid]);
1520 return $optionClassName::get(
'sale',
'status_on_paid',
'');
1533 return $optionClassName::get(
'sale',
'status_on_half_paid',
'');
1547 private function onAfterSyncPaid($oldPaid =
null)
1551 $paymentCollection = $this->getPaymentCollection();
1553 $shipmentCollection = $this->getShipmentCollection();
1555 $orderStatus =
null;
1557 $allowSetStatus =
false;
1559 if ($oldPaid ==
"N")
1561 if ($this->isPaid())
1563 $orderStatus = $this->getStatusOnPaid();
1565 elseif ($paymentCollection->hasPaidPayment())
1567 $orderStatus = $this->getStatusOnPartialPaid();
1570 $allowSetStatus = ($this->getField(
'STATUS_ID') != static::getFinalStatus());
1573 if ($orderStatus !==
null && $allowSetStatus)
1575 if (strval($orderStatus) !=
'')
1577 $r = $this->
setField(
'STATUS_ID', $orderStatus);
1578 if (!$r->isSuccess())
1580 $result->addErrors($r->getErrors());
1582 elseif ($r->hasWarnings())
1584 $result->addWarnings($r->getWarnings());
1589 $entityMarker = $registry->getEntityMarkerClassName();
1590 $entityMarker::addMarker($this, $this, $r);
1613 if ($oldPaid ==
"N" && $this->
isPaid())
1617 elseif ($oldPaid ==
"Y" && !$this->
isPaid())
1625 if (!$r->isSuccess())
1627 $result->addErrors($r->getErrors());
1629 elseif ($r->hasWarnings())
1631 $result->addWarnings($r->getWarnings());
1636 $allowDelivery =
null;
1642 $allowDelivery =
true;
1646 $allowDelivery =
false;
1651 if ($oldPaid ==
"N" && $this->
isPaid())
1653 $allowDelivery =
true;
1655 elseif ($oldPaid ==
"Y" && !$this->
isPaid())
1657 $allowDelivery =
false;
1661 if ($allowDelivery !==
null)
1672 if (!$r->isSuccess())
1674 $result->addErrors($r->getErrors());
1691 $result = parent::refreshInternal();
1692 if (!$result->isSuccess())
1711 $r = parent::applyDiscount($data);
1712 if (!$r->isSuccess())
1717 if (isset($data[
'SHIPMENT']) && intval($data[
'SHIPMENT']) > 0
1718 && (isset($data[
'PRICE_DELIVERY']) && floatval($data[
'PRICE_DELIVERY']) >= 0
1719 || isset($data[
'DISCOUNT_PRICE']) && floatval($data[
'DISCOUNT_PRICE']) >= 0))
1723 if (!$shipment->isCustomPrice())
1725 $data[
'PRICE_DELIVERY'] = (float)$data[
'PRICE_DELIVERY'];
1726 $data[
'DISCOUNT_PRICE'] = (float)$data[
'DISCOUNT_PRICE'];
1727 if ($data[
'PRICE_DELIVERY'] >= 0 && $data[
'PRICE_DELIVERY'] != $shipment->getPrice())
1730 $shipment->setField(
'PRICE_DELIVERY', $data[
'PRICE_DELIVERY']);
1733 if ($data[
'DISCOUNT_PRICE'] != $shipment->getField(
'DISCOUNT_PRICE'))
1736 $shipment->setField(
'DISCOUNT_PRICE', $data[
'DISCOUNT_PRICE']);
1765 return static::updateInternal($id, array(
1767 'LOCKED_BY' => (is_object($USER) ? $USER->GetID():
false)
1791 if(!$order = static::load($id))
1797 $userRights = \CMain::getUserRight(
"sale", $USER->getUserGroupArray(),
"Y",
"Y");
1799 if (($userRights >=
"W") || ($order->getField(
"LOCKED_BY") == $USER->getID()))
1801 return static::updateInternal($id, array(
1802 'DATE_LOCK' =>
null,
1816 public static function isLocked($id)
1819 $r = static::getLockedStatus($id);
1820 if ($r->isSuccess())
1822 $lockResultData = $r->getData();
1824 if (array_key_exists(
'LOCK_STATUS', $lockResultData)
1825 && $lockResultData[
'LOCK_STATUS'] == static::SALE_ORDER_LOCK_STATUS_RED)
1845 $res = static::getList(array(
1846 'filter' => array(
'=ID' => $id),
1854 if ($data = $res->fetch())
1856 $result->addData(array(
1857 'LOCKED_BY' => $data[
'LOCKED_BY'],
1858 'LOCK_STATUS' => $data[
'LOCK_STATUS'],
1859 'DATE_LOCK' => $data[
'DATE_LOCK'],
1876 $result = parent::verify();
1879 if (!$r->isSuccess())
1881 $result->addErrors($r->getErrors());
1885 if (!$r->isSuccess())
1887 $result->addErrors($r->getErrors());
1899 $providerInstance =
null;
1901 if (is_array($mapping) && isset($mapping[
'PROVIDER_KEY']))
1903 switch ($mapping[
'PROVIDER_KEY'])
1907 $providerInstance = $this;
1910 $providerInstance = $this->
getField(
'USER_ID');
1913 $providerInstance = $this->
getField(
'COMPANY_ID');
1918 return $providerInstance;
1927 public static function getList(array $parameters = array())
1929 return Internals\OrderTable::getList($parameters);
1938 protected function cloneEntities(\SplObjectStorage $cloneEntity)
1941 parent::cloneEntities($cloneEntity);
1943 $orderClone = $cloneEntity[$this];
1945 $orderClone->shipmentCollection = $this->getShipmentCollection()->createClone($cloneEntity);
1947 $orderClone->paymentCollection = $this->getPaymentCollection()->createClone($cloneEntity);
1949 $orderClone->tradeBindingCollection = $this->getTradeBindingCollection()->createClone($cloneEntity);
1957 if (parent::isChanged())
1981 parent::clearChanged();
1995 public function getDeliveryIdList() : array
2000 foreach ($this->getShipmentCollection()->getNotSystemItems() as $shipment)
2002 if ($shipment->getDeliveryId() > 0)
2004 $result[] = $shipment->getDeliveryId();
2014 public function getPaySystemIdList() : array
2021 if ($payment->getPaymentSystemId() > 0)
2023 $result[] = $payment->getPaymentSystemId();
2035 $vatInfo = parent::calculateVat();
2040 $rate = $shipment->getVatRate();
2043 $vatInfo[
'VAT_SUM'] += $shipment->getVatSum();
2044 $vatInfo[
'VAT_RATE'] = max($vatInfo[
'VAT_RATE'], $rate);
2056 $result = parent::saveEntities();
2059 if (!$r->isSuccess())
2061 $result->addWarnings($r->getErrors());
2065 if (!$r->isSuccess())
2067 $result->addWarnings($r->getErrors());
2071 Internals\UserBudgetPool::onUserBudgetSave($this->
getUserId());
2074 if (!$r->isSuccess())
2076 $result->addWarnings($r->getErrors());
2079 $res = Cashbox\Internals\Pool::generateChecks($this->
getInternalId());
2080 if (!$res->isSuccess())
2082 $result->addWarnings($res->getErrors());
2084 $warningResult =
new Result();
2085 $warningResult->addWarnings($res->getErrors());
2089 $entityMarker = $registry->getEntityMarkerClassName();
2090 $entityMarker::addMarker($this, $this, $warningResult);
2091 static::updateInternal($this->getId(), array(
'MARKED' =>
'Y'));
2102 $price = parent::calculatePrice();
2115 protected function onBeforeSave()
2120 $entityMarker = $registry->getEntityMarkerClassName();
2122 $result = Internals\Catalog\Provider::save($this);
2123 if ($result->hasWarnings())
2125 $entityMarker::addMarker($this, $this, $result);
2126 if ($this->getId() > 0)
2128 static::updateInternal($this->getId(), [
'MARKED' =>
'Y']);
2132 $entityMarker::refreshMarkers($this);
2142 $result = parent::onAfterSave();
2143 if (!$result->isSuccess())
2148 global $CACHE_MANAGER;
2150 if (defined(
"CACHED_b_sale_order")
2155 && $this->
getField(
"UPDATED_1C") !=
"Y"
2160 $CACHE_MANAGER->Read(CACHED_b_sale_order,
"sale_orders");
2161 $CACHE_MANAGER->SetImmediate(
"sale_orders",
true);
2174 public function save()
2176 $result = parent::save();
2181 $orderHistory = $registry->getOrderHistoryClassName();
2182 $orderHistory::collectEntityFields(
'ORDER', $this->getId(), $this->getId());
2185 $entityMarker = $registry->getEntityMarkerClassName();
2186 if ($entityMarker::hasErrors($this))
2188 $entityMarker::saveMarkers($this);
2189 static::updateInternal(
2193 'REASON_MARKED' => $this->getField(
'REASON_MARKED')
2209 protected function add()
2211 $result = parent::add();
2216 $orderHistory = $registry->getOrderHistoryClassName();
2217 $orderHistory::addAction(
'ORDER', $result->getId(),
'ORDER_ADDED', $result->getId(), $this);
2226 protected function update()
2228 $result = parent::update();
2232 $orderHistory = $registry->getOrderHistoryClassName();
2234 if (!$result->isSuccess())
2236 $orderHistory::addAction(
2239 'ORDER_UPDATE_ERROR',
2242 array(
"ERROR" => $result->getErrorMessages())
2247 $orderHistory::addAction(
2265 protected function callEventOnSaleOrderEntitySaved()
2267 parent::callEventOnSaleOrderEntitySaved();
2269 $changeMeaningfulFields = array(
2282 $logFields = array();
2287 $originalValues = $fields->getOriginalValues();
2289 foreach($originalValues as $originalFieldName => $originalFieldValue)
2291 if (in_array($originalFieldName, $changeMeaningfulFields) && $this->
getField($originalFieldName) != $originalFieldValue)
2293 $logFields[$originalFieldName] = $this->
getField($originalFieldName);
2294 $logFields[
'OLD_'.$originalFieldName] = $originalFieldValue;
2301 $orderHistory = $registry->getOrderHistoryClassName();
2302 $orderHistory::addLog(
2309 $orderHistory::SALE_ORDER_HISTORY_LOG_LEVEL_1
2324 $orderHistory = $registry->getOrderHistoryClassName();
2325 $orderHistory::addLog(
2328 'ORDER_EVENT_ON_ORDER_SAVED',
2332 $orderHistory::SALE_ORDER_HISTORY_LOG_LEVEL_1
2335 parent::callEventOnSaleOrderSaved();
2345 return Internals\OrderTable::add($data);
2356 return Internals\OrderTable::update($primary, $data);
2366 return Internals\OrderTable::delete($primary);
2373 protected static function deleteExternalEntities($orderId)
2375 parent::deleteExternalEntities($orderId);
2379 TradingPlatform\OrderTable::deleteByOrderId($orderId);
2380 Internals\OrderProcessingTable::deleteByOrderId($orderId);
2383 $entityMarker = $registry->getEntityMarkerClassName();
2384 $entityMarker::deleteByOrderId($orderId);
2387 $orderHistory = $registry->getOrderHistoryClassName();
2388 $orderHistory::deleteByOrderId($orderId);
2398 protected function addChangesToHistory($name, $oldValue =
null, $value =
null)
2400 if ($this->getId() > 0)
2402 $historyFields = array();
2403 if ($name ==
"PRICE")
2405 $historyFields[
'CURRENCY'] = $this->getCurrency();
2407 if ($name ==
"RESPONSIBLE_ID")
2409 $historyFields[$name] = $value;
2412 $historyFields[
'OLD_'.$name] = $oldValue;
2417 $orderHistory = $registry->getOrderHistoryClassName();
2418 $orderHistory::addField(
2439 return $this->getDeliveryIdList();
2449 return $this->getPaySystemIdList();
2459 $result = parent::toArray();