27 $id = (int)$order->getId();
33 $accountNumber = static::generateCustom($order);
36 $dbRes = $order::getList([
38 'filter' => [
'=ACCOUNT_NUMBER' => $accountNumber]
42 $accountNumber =
null;
47 $accountNumber = static::generateBySettings($order);
52 $accountNumber = static::generateById($order);
55 $dbRes = $order::getList([
57 'filter' => [
'=ACCOUNT_NUMBER' => $accountNumber]
61 $accountNumber = static::generateForOrder($order);
64 return $accountNumber;
75 private static function generateBySettings(
Sale\
OrderBase $order)
77 $accountNumber = static::getNextNumber($order);
80 $dbRes = $order::getList([
'filter' => [
"=ACCOUNT_NUMBER" => $accountNumber]]);
87 return $accountNumber;
95 private static function generateById(
Sale\OrderBase $order)
97 $accountNumber = $order->getId();
98 for ($i = 1; $i <= 10; $i++)
100 $dbRes = $order::getList([
102 'filter' => [
'=ACCOUNT_NUMBER' => $accountNumber]
106 $accountNumber = $order->getId().
"-".$i;
114 return $accountNumber;
123 private static function generateCustom(
Sale\OrderBase $order)
125 $type = Main\Config\Option::get(
"sale",
"account_number_template",
"");
127 foreach(GetModuleEvents(
"sale",
"OnBeforeOrderAccountNumberSet",
true) as $arEvent)
129 $tmpRes = ExecuteModuleEventEx($arEvent, array($order->getId(), $type));
130 if ($tmpRes !==
false)
147 return static::generate($item);
158 return static::generate($item);
170 $accountNumber =
null;
177 if (!method_exists($collection,
"getOrder"))
183 if (!$order = $collection->getOrder())
188 $accountNumber = $order->getField(
'ACCOUNT_NUMBER').static::ACCOUNT_NUMBER_SEPARATOR;
192 foreach ($collection as $itemCollection)
194 if (strval($itemCollection->getField(
"ACCOUNT_NUMBER")) !=
"")
196 $accountNumberIdList = explode(static::ACCOUNT_NUMBER_SEPARATOR, $itemCollection->getField(
"ACCOUNT_NUMBER"));
198 $itemAccountNumber = trim(end($accountNumberIdList));
200 if ($count <= $itemAccountNumber)
201 $count = $itemAccountNumber + 1;
205 return $accountNumber.$count;
217 private static function getNextNumber(
Sale\OrderBase $order)
219 $accountNumber =
null;
221 $numeratorForOrderSettings = Main\Numerator\Numerator::getOneByType($order::getRegistryType());
223 if ($numeratorForOrderSettings)
225 $numerator = Main\Numerator\Numerator::load(
226 $numeratorForOrderSettings[
'id'],
228 'ORDER_ID' => $order->getId()
233 $accountNumber = $numerator->getNext();
236 return $accountNumber;