UNPKG

kkmserver-js

Version:
346 lines (340 loc) 13.9 kB
import axios from 'axios'; var Commands = /* @__PURE__ */ ((Commands2) => { Commands2["GetDataKKT"] = "GetDataKKT"; Commands2["RegisterCheck"] = "RegisterCheck"; Commands2["OpenShift"] = "OpenShift"; Commands2["CloseShift"] = "CloseShift"; Commands2["XReport"] = "XReport"; Commands2["GetDataCheck"] = "GetDataCheck"; Commands2["GetRezult"] = "GetRezult"; Commands2["DepositingCash"] = "DepositingCash"; Commands2["PaymentCash"] = "PaymentCash"; return Commands2; })(Commands || {}); var CommandStatus = /* @__PURE__ */ ((CommandStatus2) => { CommandStatus2[CommandStatus2["Ok"] = 0] = "Ok"; CommandStatus2[CommandStatus2["Run"] = 1] = "Run"; CommandStatus2[CommandStatus2["Error"] = 2] = "Error"; CommandStatus2[CommandStatus2["NotFound"] = 3] = "NotFound"; CommandStatus2[CommandStatus2["NotRun"] = 4] = "NotRun"; return CommandStatus2; })(CommandStatus || {}); var ShiftStatus = /* @__PURE__ */ ((ShiftStatus2) => { ShiftStatus2[ShiftStatus2["Closed"] = 1] = "Closed"; ShiftStatus2[ShiftStatus2["Opened"] = 2] = "Opened"; ShiftStatus2[ShiftStatus2["Expired"] = 3] = "Expired"; return ShiftStatus2; })(ShiftStatus || {}); var TypeCheck = /* @__PURE__ */ ((TypeCheck2) => { TypeCheck2[TypeCheck2["Sale"] = 0] = "Sale"; TypeCheck2[TypeCheck2["Refund"] = 1] = "Refund"; TypeCheck2[TypeCheck2["SalesCorrection"] = 2] = "SalesCorrection"; TypeCheck2[TypeCheck2["RefundCorrection"] = 3] = "RefundCorrection"; return TypeCheck2; })(TypeCheck || {}); var TaxVariant = /* @__PURE__ */ ((TaxVariant2) => { TaxVariant2[TaxVariant2["General"] = 0] = "General"; TaxVariant2[TaxVariant2["SimplifiedIncome"] = 1] = "SimplifiedIncome"; TaxVariant2[TaxVariant2["SimplifiedIncomeMinusCost"] = 2] = "SimplifiedIncomeMinusCost"; TaxVariant2[TaxVariant2["UnifiedTaxOnImputedIncome"] = 3] = "UnifiedTaxOnImputedIncome"; TaxVariant2[TaxVariant2["UnifiedAgriculturalTax"] = 4] = "UnifiedAgriculturalTax"; TaxVariant2[TaxVariant2["PatentSystem"] = 5] = "PatentSystem"; return TaxVariant2; })(TaxVariant || {}); var CorrectionType = /* @__PURE__ */ ((CorrectionType2) => { CorrectionType2[CorrectionType2["Self"] = 0] = "Self"; CorrectionType2[CorrectionType2["Prescription"] = 1] = "Prescription"; return CorrectionType2; })(CorrectionType || {}); var SignMethodCalculation = /* @__PURE__ */ ((SignMethodCalculation2) => { SignMethodCalculation2[SignMethodCalculation2["FullPrepayment"] = 1] = "FullPrepayment"; SignMethodCalculation2[SignMethodCalculation2["PartialPrepayment"] = 2] = "PartialPrepayment"; SignMethodCalculation2[SignMethodCalculation2["Advance"] = 3] = "Advance"; SignMethodCalculation2[SignMethodCalculation2["FullPayment"] = 4] = "FullPayment"; SignMethodCalculation2[SignMethodCalculation2["PartialPaymentAndCredit"] = 5] = "PartialPaymentAndCredit"; SignMethodCalculation2[SignMethodCalculation2["TransferCredit"] = 6] = "TransferCredit"; SignMethodCalculation2[SignMethodCalculation2["PaymentCredit"] = 7] = "PaymentCredit"; return SignMethodCalculation2; })(SignMethodCalculation || {}); var SignCalculationObject = /* @__PURE__ */ ((SignCalculationObject2) => { SignCalculationObject2[SignCalculationObject2["Product"] = 1] = "Product"; SignCalculationObject2[SignCalculationObject2["ExciseProduct"] = 2] = "ExciseProduct"; SignCalculationObject2[SignCalculationObject2["Work"] = 3] = "Work"; SignCalculationObject2[SignCalculationObject2["Service"] = 4] = "Service"; SignCalculationObject2[SignCalculationObject2["RateGambling"] = 5] = "RateGambling"; SignCalculationObject2[SignCalculationObject2["WinGambling"] = 6] = "WinGambling"; SignCalculationObject2[SignCalculationObject2["LotteryTicket"] = 7] = "LotteryTicket"; SignCalculationObject2[SignCalculationObject2["LotteryWin"] = 8] = "LotteryWin"; SignCalculationObject2[SignCalculationObject2["ProvideRight"] = 9] = "ProvideRight"; SignCalculationObject2[SignCalculationObject2["Payment"] = 10] = "Payment"; SignCalculationObject2[SignCalculationObject2["AgentReward"] = 11] = "AgentReward"; SignCalculationObject2[SignCalculationObject2["CompositeCalculationObject"] = 12] = "CompositeCalculationObject"; SignCalculationObject2[SignCalculationObject2["OtherCalculationObject"] = 13] = "OtherCalculationObject"; SignCalculationObject2[SignCalculationObject2["PropertyRight"] = 14] = "PropertyRight"; SignCalculationObject2[SignCalculationObject2["NonOperatingIncome"] = 15] = "NonOperatingIncome"; SignCalculationObject2[SignCalculationObject2["InsuranceContributions"] = 16] = "InsuranceContributions"; SignCalculationObject2[SignCalculationObject2["TradeFee"] = 17] = "TradeFee"; SignCalculationObject2[SignCalculationObject2["ResortFee"] = 18] = "ResortFee"; SignCalculationObject2[SignCalculationObject2["Deposit"] = 19] = "Deposit"; SignCalculationObject2[SignCalculationObject2["Expense"] = 20] = "Expense"; SignCalculationObject2[SignCalculationObject2["PensionInsuranceContributionsIP"] = 21] = "PensionInsuranceContributionsIP"; SignCalculationObject2[SignCalculationObject2["PensionInsuranceContributions"] = 22] = "PensionInsuranceContributions"; SignCalculationObject2[SignCalculationObject2["MedicalInsuranceContributionsIP"] = 23] = "MedicalInsuranceContributionsIP"; SignCalculationObject2[SignCalculationObject2["MedicalInsuranceContributions"] = 24] = "MedicalInsuranceContributions"; SignCalculationObject2[SignCalculationObject2["SocialInsuranceContributions"] = 25] = "SocialInsuranceContributions"; SignCalculationObject2[SignCalculationObject2["CasinoPayment"] = 26] = "CasinoPayment"; return SignCalculationObject2; })(SignCalculationObject || {}); var AgentSign = /* @__PURE__ */ ((AgentSign2) => { AgentSign2[AgentSign2["BankPaymentAgent"] = 0] = "BankPaymentAgent"; AgentSign2[AgentSign2["BankPaymentSubagent"] = 1] = "BankPaymentSubagent"; AgentSign2[AgentSign2["PaymentAgent"] = 2] = "PaymentAgent"; AgentSign2[AgentSign2["PaymentSubagent"] = 3] = "PaymentSubagent"; AgentSign2[AgentSign2["Attorney"] = 4] = "Attorney"; AgentSign2[AgentSign2["Commissioner"] = 5] = "Commissioner"; AgentSign2[AgentSign2["Agent"] = 6] = "Agent"; return AgentSign2; })(AgentSign || {}); var __defProp$1 = Object.defineProperty; var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, key + "" , value); class HttpService { constructor(baseURL, options = {}) { __publicField$1(this, "client"); this.client = axios.create({ baseURL, headers: { Accept: "application/json" }, ...options }); } async get(url, options = {}) { const response = await this.client.get(url, options); return response; } async post(url, params = {}, requestParams = {}) { const response = await this.client.post(url, params, requestParams); return response; } async put(url, params = {}) { const response = await this.client.put(url, params); return response; } async delete(url) { const response = await this.client.delete(url); return response; } } var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); class KKMClient { constructor(settings) { __publicField(this, "http"); __publicField(this, "executePath", "Execute"); __publicField(this, "url"); __publicField(this, "innKkm"); __publicField(this, "kktNumber"); __publicField(this, "cashierName"); __publicField(this, "cashierVatin"); __publicField(this, "numDevice"); __publicField(this, "taxVariant"); __publicField(this, "commandTimeout"); __publicField(this, "placeMarket"); __publicField(this, "addressSettle"); __publicField(this, "commandResultTimeout"); this.url = settings.url || "http://localhost:5893/"; this.http = new HttpService(this.url); this.innKkm = settings.innKkm || ""; this.kktNumber = settings.kktNumber || ""; this.cashierName = settings.cashierName || ""; this.cashierVatin = settings.cashierVatin || ""; this.taxVariant = settings.taxVariant; this.numDevice = settings.numDevice; this.commandTimeout = settings.commandTimeout || 60; this.placeMarket = settings.placeMarket; this.addressSettle = settings.addressSettle; this.commandResultTimeout = settings.commandResultTimeout || 1e3; } /** * Генерирует GUID */ generateUUID() { function getRandomHex() { return (Math.random().toString(16) + "000000").slice(2, 10); } return getRandomHex() + "-" + getRandomHex() + "-" + getRandomHex() + "-" + getRandomHex() + "-" + getRandomHex() + getRandomHex() + getRandomHex(); } /** * Получает параметры для чека по умолчанию */ getDefaultCheckParams() { return { InnKkm: this.innKkm, TaxVariant: this.taxVariant, NumDevice: this.numDevice, CashierName: this.cashierName, CashierVatin: this.cashierVatin, Timeout: this.commandTimeout, PlaceMarket: this.placeMarket, AddressSettle: this.addressSettle, IdCommand: this.generateUUID() }; } /** * Отправляет комманду на ККМ * @param {Bodies} commandBody - Идентификатор задания */ async sendCommand(commandBody) { const response = await this.http.post(this.executePath, commandBody); return response?.data; } /** * Проверяет статуса ранее отданной команды * @param {String} uuid - Идентификатор задания */ async getCommandResult(uuid) { try { while (true) { const requestParams = { Command: Commands.GetRezult, IdCommand: uuid }; const response = await this.http.post(this.executePath, requestParams); if (response.data?.Rezult) { if (response.data.Rezult.Status === CommandStatus.Run) { await new Promise((resolve) => setTimeout(resolve, this.commandResultTimeout)); } else { return response?.data; } } } ; } catch (error) { return Promise.reject(error); } } } class CommandBodies extends KKMClient { constructor(kkmClient) { if (kkmClient) { super({ url: kkmClient.url, innKkm: kkmClient.innKkm, kktNumber: kkmClient.kktNumber, cashierName: kkmClient.cashierName, cashierVatin: kkmClient.cashierVatin, numDevice: kkmClient.numDevice, taxVariant: kkmClient.taxVariant, commandTimeout: kkmClient.commandTimeout, placeMarket: kkmClient.placeMarket, addressSettle: kkmClient.addressSettle }); } else { throw new Error("\u041D\u0435 \u043F\u0435\u0440\u0435\u0434\u0430\u043D \u044D\u043A\u0437\u0435\u043C\u043F\u043B\u044F\u0440 KKMClient"); } } /** * Тело получения текущего состояние ККТ */ getDataKKTBody(body) { return { Command: Commands.GetDataKKT, InnKkm: this.innKkm, TaxVariant: this.taxVariant, NumDevice: this.numDevice, IdCommand: this.generateUUID(), ...body }; } /** * Тело открытия смены * @param {OpenShiftBody} body - Тело запроса */ openShiftBody(body) { return { Command: Commands.OpenShift, NotPrint: false, IdDevice: "", ...this.getDefaultCheckParams(), ...body }; } /** * Тело закрытия смены * @param {CloseShiftBody} body - Тело запроса */ closeShiftBody(body) { return { Command: Commands.CloseShift, NotPrint: false, IdDevice: "", ...this.getDefaultCheckParams(), ...body }; } /** * Тело печати X отчета * @param {XReportBody} body - Тело запроса */ xReportBody(body) { return { Command: Commands.XReport, ...this.getDefaultCheckParams(), ...body }; } /** * Тело получения данных чека * @param {GetDataCheckBody} body - Тело запроса */ getDataCheckBody(body) { return { Command: Commands.GetDataCheck, InnKkm: this.innKkm, TaxVariant: this.taxVariant, NumDevice: this.numDevice, IdCommand: this.generateUUID(), ...body }; } /** * Тело печати чека * @param {RegisterCheckBody} body - Тело запроса */ registerCheckBody(body) { return { Command: Commands.RegisterCheck, IsFiscalCheck: true, NotPrint: false, NumberCopies: 0, ...this.getDefaultCheckParams(), ...body }; } /** * Тело печати чека изъятия денежных средств * @param {PaymentCashBody} body - Тело запроса */ paymentCashBody(body) { return { Command: Commands.PaymentCash, ...this.getDefaultCheckParams(), ...body }; } /** * Тело печати чека внесения денежных средств * @param {DepositingCashBody} body - Тело запроса */ depositingCashBody(body) { return { Command: Commands.DepositingCash, ...this.getDefaultCheckParams(), ...body }; } } export { AgentSign, CommandBodies, CommandStatus, Commands, CorrectionType, KKMClient, ShiftStatus, SignCalculationObject, SignMethodCalculation, TaxVariant, TypeCheck }; //# sourceMappingURL=kkmserver-js.mjs.map