From c352f9f487c401239781dff57d0e838992a49413 Mon Sep 17 00:00:00 2001 From: Mikhail Chechnev Date: Thu, 10 Jan 2019 17:24:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81=D0=B0=20?= =?UTF-8?q?=D1=87=D0=B5=D0=BA=D0=B0=20=D0=B2=20ATOL-=D0=BE=D0=BD=D0=BB?= =?UTF-8?q?=D0=B0=D0=B9=D0=BD,=20=D1=81=D0=BC=D0=B5=D0=BD=D0=B0=20=D1=82?= =?UTF-8?q?=D0=B8=D0=BF=D0=B0=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D1=82=D1=8D=D0=B3=D0=B0=201199=20(=D0=BF=D1=80=D0=B8=D0=B7?= =?UTF-8?q?=D0=BD=D0=B0=D0=BA=20=D1=81=D1=82=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=9D=D0=94=D0=A1),=20=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=BD=D0=B0=D1=8F=20=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=20=D0=B8=D1=81=D1=82=D0=B5=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=81=D0=B5=D1=81=D1=81=D0=B8=D0=B8=20ATOL=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=20=D0=B0=D1=83=D1=82=D0=B5=D0=BD=D1=82=D0=B8=D1=84=D0=B8?= =?UTF-8?q?=D0=BA=D0=B0=D1=86=D0=B8=D0=B8,=20=D0=B4=D0=BE=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=BD=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D1=8C=20=D0=BD=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D1=87=D0=B8=D1=8F=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D0=B2=20=D0=BF=D0=BE=D1=81=D1=8B=D0=BB=D0=BA=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8E=20=D1=87=D0=B5=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/UDO_PKG_EXS_ATOL.pck | 33 ++++++++++++++- modules/parus_atol_v4_ffd1.05.js | 72 +++++++++++++++++++++++++------- 2 files changed, 90 insertions(+), 15 deletions(-) diff --git a/db/UDO_PKG_EXS_ATOL.pck b/db/UDO_PKG_EXS_ATOL.pck index fb1543f..255d433 100644 --- a/db/UDO_PKG_EXS_ATOL.pck +++ b/db/UDO_PKG_EXS_ATOL.pck @@ -7,6 +7,13 @@ create or replace package UDO_PKG_EXS_ATOL as NEXSQUEUE in number -- ); + /* (v4) ( 1.05) */ + procedure V4_FFD105_PROCESS_GET_BILL_INF + ( + NIDENT in number, -- + NEXSQUEUE in number -- + ); + end; / create or replace package body UDO_PKG_EXS_ATOL as @@ -49,6 +56,30 @@ create or replace package body UDO_PKG_EXS_ATOL as /* */ PKG_EXS.PRC_RESP_RESULT_SET(NIDENT => NIDENT, SRESULT => PKG_EXS.SPRC_RESP_RESULT_ERR, SMSG => sqlerrm); end V4_FFD105_PROCESS_REG_BILL_SIR; - + + /* (v4) ( 1.05) */ + procedure V4_FFD105_PROCESS_GET_BILL_INF + ( + NIDENT in number, -- + NEXSQUEUE in number -- + ) + is + REXSQUEUE EXSQUEUE%rowtype; -- + CTMP clob; -- + begin + /* */ + REXSQUEUE := GET_EXSQUEUE_ID(NFLAG_SMART => 0, NRN => NEXSQUEUE); + /* */ + CTMP := BLOB2CLOB(LBDATA => REXSQUEUE.RESP, SCHARSET => 'UTF8'); + if (CTMP is null) then + P_EXCEPTION(0, ' .'); + end if; + /* */ + PKG_EXS.PRC_RESP_RESULT_SET(NIDENT => NIDENT); + exception + when others then + /* */ + PKG_EXS.PRC_RESP_RESULT_SET(NIDENT => NIDENT, SRESULT => PKG_EXS.SPRC_RESP_RESULT_ERR, SMSG => sqlerrm); + end V4_FFD105_PROCESS_GET_BILL_INF; end; / diff --git a/modules/parus_atol_v4_ffd1.05.js b/modules/parus_atol_v4_ffd1.05.js index 1da8fc8..3dbac43 100644 --- a/modules/parus_atol_v4_ffd1.05.js +++ b/modules/parus_atol_v4_ffd1.05.js @@ -115,6 +115,9 @@ const { NFN_TYPE_LOGIN } = require("@models/obj_service_function"); // Глобальные константы //--------------------- +//Код круппы ККТ +const SGROUP_CODE = "v4-online-atol-ru_4179"; + //Словарь - Признак способа расчёта const paymentMethod = { sName: "Признак способа расчёта", @@ -250,6 +253,12 @@ const getPropValueByCode = (props, sCode, sValType = "STR", sValField = "VALUE") return res; }; +//Добавление определённого количетсва часов к дате +const addHours = (dDate, nHours) => { + dDate.setTime(dDate.getTime() + nHours * 60 * 60 * 1000); + return new Date(dDate); +}; + //Конвертация строки в формате ДД.ММ.ГГГГ ЧЧ:МИ:СС в JS Date const strDDMMYYYYHHMISStoDate = sDate => { let res = null; @@ -261,11 +270,6 @@ const strDDMMYYYYHHMISStoDate = sDate => { res = new Date(year, month - 1, day, hh, min, ss); if (isNaN(res.getTime())) { res = null; - } else { - res.addHours = function(nHours) { - this.setTime(this.getTime() + nHours * 60 * 60 * 1000); - return this; - }; } } catch (e) { res = null; @@ -303,7 +307,7 @@ const afterConnect = async prms => { return { blResp: new Buffer(resp.token), sCtx: resp.token, - dCtxExp: strDDMMYYYYHHMISStoDate(resp.timestamp).addHours(24) + dCtxExp: addHours(new Date(), 23) }; } else { throw new Error(`Сервер АТОЛ-Онлайн вернул ошибку: ${resp.error.text}`); @@ -313,8 +317,6 @@ const afterConnect = async prms => { //Обработчик "До" отправки запроса на регистрацию чека (приход, расход, возврат) серверу "АТОЛ-Онлайн" const beforeRegBillSIR = async prms => { try { - //Код круппы ККТ - const sGroupCode = "v4-online-atol-ru_4179"; //Токен доступа let sToken = null; if (prms.service.sCtx) { @@ -324,10 +326,14 @@ const beforeRegBillSIR = async prms => { if (!sToken) return { bUnAuth: true }; //Разберем XML-данные фискального документа let parseRes = null; - try { - parseRes = await parseXML(prms.queue.blMsg.toString()); - } catch (e) { - throw new Error("Ошибка рабора XML"); + if (prms.queue.blMsg) { + try { + parseRes = await parseXML(prms.queue.blMsg.toString()); + } catch (e) { + throw new Error("Ошибка рабора XML"); + } + } else { + throw new Error("В теле сообщения отсутствуют данные фискального документа"); } //Сохраним короткие ссылки на документ и его свойства const doc = parseRes.FISCDOC; @@ -359,7 +365,7 @@ const beforeRegBillSIR = async prms => { payment_method: mapDictionary(paymentMethod, getPropValueByCode(docProps, "1214")), payment_object: mapDictionary(paymentObject, getPropValueByCode(docProps, "1212")), vat: { - type: mapDictionary(receiptItemVat, getPropValueByCode(docProps, "1199")), + type: mapDictionary(receiptItemVat, getPropValueByCode(docProps, "1199", "NUM")), sum: getPropValueByCode(docProps, "1200", "NUM") } } @@ -449,7 +455,7 @@ const beforeRegBillSIR = async prms => { let res = { options: { url: buildURL({ sSrvRoot: prms.service.sSrvRoot, sFnURL: prms.function.sFnURL }) - .replace("", sGroupCode) + .replace("", SGROUP_CODE) .replace("", sOperation), headers: { "Content-type": "application/json; charset=utf-8", @@ -491,6 +497,42 @@ const afterRegBillSIR = async prms => { } }; +//Обработчик "До" отправки запроса на получение информации о чеке серверу "АТОЛ-Онлайн" +const beforeGetBillInfo = async prms => { + //Токен доступа + let sToken = null; + if (prms.service.sCtx) { + sToken = prms.service.sCtx; + } + //Если не достали из контекста токен доступа - значит нет аутентификации на сервере + if (!sToken) return { bUnAuth: true }; + //Забираем идентификатор документа из тела сообщения + let sUUID = null; + if (prms.queue.blMsg) sUUID = prms.queue.blMsg.toString(); + if (!sUUID) throw new Error("В теле сообщения не указан идентификатор документа в АТОЛ-Онлайн"); + //Собираем общий результат работы + let res = { + options: { + url: buildURL({ sSrvRoot: prms.service.sSrvRoot, sFnURL: prms.function.sFnURL }) + .replace("", SGROUP_CODE) + .replace("", sUUID), + headers: { + "Content-type": "application/json; charset=utf-8", + Token: sToken + }, + simple: false + } + }; + //Возврат резульатата + return res; +}; + +//Обработчик "После" отправки запроса на получение информации о чеке серверу "АТОЛ-Онлайн" +const afterGetBillInfo = async prms => { + if (prms.queue.blResp) console.log(prms.queue.blResp.toString()); + else console.log("Сервер не вернул ответ"); +}; + //----------------- // Интерфейс модуля //----------------- @@ -499,3 +541,5 @@ exports.beforeConnect = beforeConnect; exports.afterConnect = afterConnect; exports.beforeRegBillSIR = beforeRegBillSIR; exports.afterRegBillSIR = afterRegBillSIR; +exports.beforeGetBillInfo = beforeGetBillInfo; +exports.afterGetBillInfo = afterGetBillInfo;