17 private const CHECK_CURRENCY_RUB =
'RUB';
23 parent::__construct();
26 $this->fields[
'CURRENCY'] = self::CHECK_CURRENCY_RUB;
35 $isNew = (int)$this->fields[
'ID'] === 0;
37 $result = parent::save();
38 if (!$result->isSuccess())
45 $r = Internals\CashboxCheckCorrectionTable::add([
46 'CHECK_ID' => $this->fields[
'ID'],
47 'CORRECTION_TYPE' => $this->correction[
'CORRECTION_TYPE'],
48 'DOCUMENT_NUMBER' => $this->correction[
'DOCUMENT_NUMBER'],
49 'DOCUMENT_DATE' => $this->correction[
'DOCUMENT_DATE'],
50 'DESCRIPTION' => $this->correction[
'DESCRIPTION'],
51 'CORRECTION_PAYMENT' => $this->correction[
'CORRECTION_PAYMENT'],
52 'CORRECTION_VAT' => $this->correction[
'CORRECTION_VAT'],
57 $result->addErrors($r->getErrors());
67 'type' => static::getType(),
68 'unique_id' => $this->
getField(
'ID'),
70 'calculated_sign' => static::getCalculatedSign()
76 $result[
'correction_info'] = [
77 'type' => $data[
'CORRECTION_TYPE'],
78 'document_number' => $data[
'DOCUMENT_NUMBER'],
79 'document_date' => $data[
'DOCUMENT_DATE'],
80 'description' => $data[
'DESCRIPTION'],
81 'total_sum' => $data[
'TOTAL_SUM'],
84 if (isset($data[
'PAYMENTS']))
86 $result[
'payments'] = [];
88 foreach ($data[
'PAYMENTS'] as $payment)
90 $result[
'payments'][] = [
91 'type' => $payment[
'TYPE'],
92 'sum' => $payment[
'SUM'],
97 if (isset($data[
'VATS']))
101 foreach ($data[
'VATS'] as $vat)
103 $result[
'vats'][] = [
104 'type' => $vat[
'TYPE'],
105 'sum' => $vat[
'SUM'],
117 'CORRECTION_TYPE' => $this->correction[
'CORRECTION_TYPE'],
118 'DOCUMENT_NUMBER' => $this->correction[
'DOCUMENT_NUMBER'],
119 'DOCUMENT_DATE' => $this->correction[
'DOCUMENT_DATE'],
120 'DESCRIPTION' => $this->correction[
'DESCRIPTION'],
121 'PAYMENTS' => $this->correction[
'CORRECTION_PAYMENT'],
125 if ($this->correction[
'CORRECTION_VAT'])
127 $result[
'VATS'] = [];
129 foreach ($this->correction[
'CORRECTION_VAT'] as $vat)
131 $result[
'VATS'][] = [
133 'SUM' => $vat[
'SUM'],
138 if ($this->correction[
'CORRECTION_PAYMENT'])
140 foreach ($this->correction[
'CORRECTION_PAYMENT'] as $payment)
142 $result[
'TOTAL_SUM'] += $payment[
'SUM'];
154 if (!$cashbox || !$cashbox->isCorrection())
156 throw new Main\SystemException(
'Cashbox '.$cashbox::getName().
' is not supported correction check');
170 if (!$this->isCorrectionFieldAvailable($name))
175 if ($name ===
'DOCUMENT_DATE')
180 $this->correction[$name] = $value;
189 foreach (
$fields as $name => $value)
193 if ($name ===
'CORRECTION_PAYMENT')
195 $this->fields[
'SUM'] = $this->calculateSumByPayments($value);
200 private function calculateSumByPayments(array $payments)
204 foreach ($payments as $item)
206 $result += $item[
'SUM'];
220 if ($this->correction)
227 $dbRes = Internals\CashboxCheckCorrectionTable::getList([
228 'select' => static::getAvailableCorrectionFields(),
230 '=CHECK_ID' => $this->
getField(
'ID')
233 if ($data = $dbRes->fetch())
245 private function getAvailableCorrectionFields()
253 return !in_array($name, [
'CHECK',
'ID',
'CHECK_ID']);
262 private function isCorrectionFieldAvailable($name)
264 $fields = $this->getAvailableCorrectionFields();
266 return in_array($name,
$fields);
274 return static::SUPPORTED_ENTITY_TYPE_NONE;
getVatIdByVatRate($vatRate)
setAvailableCashbox(array $cashboxList)
setCorrectionField($name, $value)
setCorrectionFields($fields)
static getSupportedEntityType()
const CORRECTION_TYPE_INSTRUCTION
const CORRECTION_TYPE_SELF
const REGISTRY_TYPE_ORDER