26 $addResult = Internals\CashboxZReportTable::add(
28 'CASHBOX_ID' => $cashboxId,
35 return $addResult->getId();
44 $dbRes = Internals\CashboxZReportTable::getList(
46 'select' => array(
'*'),
47 'filter' => array(
'CASHBOX_ID' => $cashboxId),
48 'order' => array(
'ID' =>
'DESC'),
53 return $dbRes->fetch();
60 public static function getPrintableZReport($cashboxId)
62 $lastZReport = static::getLastZReport($cashboxId);
65 $nowTs = $now->getTimestamp();
67 if ($lastZReport && ($lastZReport[
'STATUS'] ===
'N' || $lastZReport[
'STATUS'] ===
'P'))
69 if ($lastZReport[
'STATUS'] ===
'N')
71 Internals\CashboxZReportTable::update($lastZReport[
'ID'], array(
'STATUS' =>
'P',
'DATE_PRINT_START' =>
new DateTime()));
72 return $lastZReport[
'ID'];
77 $datePrintStart = $lastZReport[
'DATE_PRINT_START'];
78 $datePrintStartTs = $datePrintStart->getTimestamp();
80 $p = $nowTs - $datePrintStartTs;
81 if ($p > static::MIN_TIME_RESENDING_REPORT && $p < static::MAX_TIME_RESENDING_REPORT)
83 return $lastZReport[
'ID'];
85 elseif ($p >= static::MAX_TIME_RESENDING_REPORT)
87 Internals\CashboxZReportTable::update($lastZReport[
'ID'], array(
'STATUS' =>
'E',
'DATE_PRINT_END' =>
new DateTime()));
94 $prevPrintDate =
new DateTime();
95 $prevPrintDate->setTime($cashbox[
'SETTINGS'][
'Z_REPORT'][
'TIME'][
'H'], $cashbox[
'SETTINGS'][
'Z_REPORT'][
'TIME'][
'M']);
96 if ($prevPrintDate->getTimestamp() > $nowTs)
97 $prevPrintDate->add(
"-1d");
101 $datePrintStart = $lastZReport[
'DATE_PRINT_START'];
103 $datePrintStart =
new DateTime(
'2017-01-01 00:00:00',
'Y-m-d H:i:s');
105 $datePrintStartTs = $datePrintStart->getTimestamp();
107 if ($prevPrintDate->getTimestamp() - $datePrintStartTs > static::MIN_TIME_RESENDING_REPORT)
111 'select' => array(
'CNT'),
113 'CASHBOX_ID' => $cashboxId,
114 '>=DATE_PRINT_START' => $datePrintStart,
115 '<DATE_PRINT_START' => $prevPrintDate,
118 new ExpressionField(
'CNT',
'COUNT(*)')
122 $checksCount = $dbChecksCount->fetch();
123 if ($checksCount && $checksCount[
'CNT'] > 0)
125 $reportId = static::addZReport($cashboxId);
126 Internals\CashboxZReportTable::update($reportId, array(
'STATUS' =>
'P',
'DATE_PRINT_START' =>
new DateTime()));
150 $report = Internals\CashboxZReportTable::getRowById($reportId);
153 $result->addError(
new Error(
Loc::getMessage(
'SALE_CASHBOX_ERROR_REPORT_NOT_FOUND', array(
'#REPORT_ID#' => $reportId))));
157 if ($report[
'STATUS'] ===
'Y')
160 if (isset($data[
'ERROR']))
162 $errorMessage =
Loc::getMessage(
'SALE_CASHBOX_ERROR_REPORT_PRINT', array(
'#REPORT_ID#' => $reportId));
163 if ($data[
'ERROR'][
'MESSAGE'])
164 $errorMessage .=
': '.$data[
'ERROR'][
'MESSAGE'];
168 if ($report[
'CNT_FAIL_PRINT'] >= 3)
170 $data[
'ERROR'][
'TYPE'] = Errors\Error::TYPE;
174 $result->addError(
new Errors\
Warning($errorMessage));
175 Internals\CashboxZReportTable::update($reportId, array(
'CNT_FAIL_PRINT' => $report[
'CNT_FAIL_PRINT']+1));
180 if ($data[
'ERROR'][
'TYPE'] === Errors\Error::TYPE)
182 $updatedFields = array(
'STATUS' =>
'E',
'DATE_PRINT_END' =>
new DateTime());
183 if ((
int)$report[
'CNT_FAIL_PRINT'] === 0)
184 $updatedFields[
'CNT_FAIL_PRINT'] = 1;
186 Internals\CashboxZReportTable::update($reportId, $updatedFields);
196 $result->addError($error);
200 $updateResult = Internals\CashboxZReportTable::update(
205 'CASH_SUM' => $data[
'CASH_SUM'],
206 'CASHLESS_SUM' => $data[
'CASHLESS_SUM'],
207 'CUMULATIVE_SUM' => $data[
'CUMULATIVE_SUM'],
208 'RETURNED_SUM' => $data[
'RETURNED_SUM'],
209 'LINK_PARAMS' => $data[
'LINK_PARAMS']
213 if (!$updateResult->isSuccess())
214 $result->addErrors($updateResult->getErrors());
static loadLanguageFile($file, $language=null, $normalize=true)
static getMessage($code, $replace=null, $language=null)