%PDF- %PDF-
Server IP : 37.220.80.31 / Your IP : 18.191.14.50 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 : |
<?php namespace Bitrix\Sale\Cashbox; use Bitrix\Main; use Bitrix\Sale\Registry; /** * Class CorrectionCheck * @package Bitrix\Sale\Cashbox */ abstract class CorrectionCheck extends AbstractCheck { public const CORRECTION_TYPE_SELF = 'self'; public const CORRECTION_TYPE_INSTRUCTION = 'instruction'; private const CHECK_CURRENCY_RUB = 'RUB'; protected $correction = []; public function __construct() { parent::__construct(); $this->fields['ENTITY_REGISTRY_TYPE'] = Registry::REGISTRY_TYPE_ORDER; $this->fields['CURRENCY'] = self::CHECK_CURRENCY_RUB; } /** * @return Main\ORM\Data\AddResult|Main\ORM\Data\UpdateResult * @throws \Exception */ public function save() { $isNew = (int)$this->fields['ID'] === 0; $result = parent::save(); if (!$result->isSuccess()) { return $result; } if ($isNew) { Internals\CashboxCheckCorrectionTable::add([ 'CHECK_ID' => $this->fields['ID'], 'CORRECTION_TYPE' => $this->correction['TYPE'], 'DOCUMENT_NUMBER' => $this->correction['DOCUMENT_NUMBER'], 'DOCUMENT_DATE' => $this->correction['DOCUMENT_DATE'], 'DESCRIPTION' => $this->correction['DESCRIPTION'], 'CORRECTION_PAYMENT' => $this->correction['CORRECTION_PAYMENT'], 'CORRECTION_VAT' => $this->correction['CORRECTION_VAT'], ]); } return $result; } public function getDataForCheck() { $result = [ 'type' => static::getType(), 'unique_id' => $this->getField('ID'), 'date_create' => new Main\Type\DateTime(), 'calculated_sign' => static::getCalculatedSign() ]; $data = static::extractData(); if ($data) { $result['correction_info'] = [ 'type' => $data['CORRECTION_TYPE'], 'document_number' => $data['DOCUMENT_NUMBER'], 'document_date' => $data['DOCUMENT_DATE'], 'description' => $data['DESCRIPTION'], 'total_sum' => $data['TOTAL_SUM'], ]; if (isset($data['PAYMENTS'])) { $result['payments'] = []; foreach ($data['PAYMENTS'] as $payment) { $result['payments'][] = [ 'type' => $payment['TYPE'], 'sum' => $payment['SUM'], ]; } }; if (isset($data['VATS'])) { $result['vats'] = []; foreach ($data['VATS'] as $vat) { $result['vats'][] = [ 'type' => $vat['TYPE'], 'sum' => $vat['SUM'], ]; } } } return $result; } protected function extractDataInternal() { $result = [ 'CORRECTION_TYPE' => $this->correction['CORRECTION_TYPE'], 'DOCUMENT_NUMBER' => $this->correction['DOCUMENT_NUMBER'], 'DOCUMENT_DATE' => $this->correction['DOCUMENT_DATE'], 'DESCRIPTION' => $this->correction['DESCRIPTION'], 'PAYMENTS' => $this->correction['CORRECTION_PAYMENT'], 'TOTAL_SUM' => 0 ]; if ($this->correction['CORRECTION_VAT']) { $result['VATS'] = []; foreach ($this->correction['CORRECTION_VAT'] as $vat) { $result['VATS'][] = [ 'TYPE' => $this->getVatIdByVatRate($vat['TYPE']), 'SUM' => $vat['SUM'], ]; } } if ($this->correction['CORRECTION_PAYMENT']) { foreach ($this->correction['CORRECTION_PAYMENT'] as $payment) { $result['TOTAL_SUM'] += $payment['SUM']; } } return $result; } public function setAvailableCashbox(array $cashboxList) { foreach ($cashboxList as $item) { $cashbox = Cashbox::create($item); if (!$cashbox || !$cashbox->isCorrection()) { throw new Main\SystemException('Cashbox '.$cashbox::getName().' is not supported correction check'); } } parent::setAvailableCashbox($cashboxList); } /** * @param $name * @param $value * @throws Main\ArgumentException */ public function setCorrectionField($name, $value) { if (!$this->isCorrectionFieldAvailable($name)) { throw new Main\ArgumentException('Incorrect field '.$name); } $this->correction[$name] = $value; } /** * @param $fields * @throws Main\ArgumentException */ public function setCorrectionFields($fields) { foreach ($fields as $name => $value) { $this->setCorrectionField($name, $value); if ($name === 'CORRECTION_PAYMENT') { $this->fields['SUM'] = $this->calculateSumByPayments($value); } } } private function calculateSumByPayments(array $payments) { $result = 0; foreach ($payments as $item) { $result += $item['SUM']; } return $result; } /** * @return array|false * @throws Main\ArgumentException * @throws Main\ObjectPropertyException * @throws Main\SystemException */ public function getCorrectionFields() { if ($this->correction) { return $this->correction; } if ($this->getField('ID') > 0) { $dbRes = Internals\CashboxCheckCorrectionTable::getList([ 'select' => static::getAvailableCorrectionFields(), 'filter' => [ '=CHECK_ID' => $this->getField('ID') ] ]); if ($data = $dbRes->fetch()) { return $data; } } return []; } /** * @return array */ private function getAvailableCorrectionFields() { $fields = array_keys(Internals\CashboxCheckCorrectionTable::getMap()); return array_filter( $fields, function ($name) { return !in_array($name, ['CHECK', 'ID', 'CHECK_ID']); } ); } /** * @param $name * @return bool */ private function isCorrectionFieldAvailable($name) { $fields = $this->getAvailableCorrectionFields(); return in_array($name, $fields); } /** * @return string */ public static function getSupportedEntityType() { return static::SUPPORTED_ENTITY_TYPE_NONE; } }