UNPKG

@cafecafe/afip.ts

Version:
263 lines 10.5 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ElectronicBillingService = void 0; const afip_service_1 = require("./afip.service"); const wsdl_path_enum_1 = require("../soap/wsdl-path.enum"); const service_names_enum_1 = require("../soap/service-names.enum"); const enums_1 = require("../enums"); class ElectronicBillingService extends afip_service_1.AfipService { constructor(context) { super(context, { url: enums_1.EndpointsEnum.WSFEV1, url_test: enums_1.EndpointsEnum.WSFEV1_TEST, wsdl: wsdl_path_enum_1.WsdlPathEnum.WSFE, wsdl_test: wsdl_path_enum_1.WsdlPathEnum.WSFE_TEST, serviceName: service_names_enum_1.ServiceNamesEnum.WSFE, v12: true, }); } /** * Asks to web service for servers status * * @return object { AppServer : Web Service status, * DbServer : Database status, AuthServer : Autentication * server status} **/ getServerStatus() { return __awaiter(this, void 0, void 0, function* () { const client = yield this.getClient(); const [output] = yield client.FEDummyAsync({}); return output; }); } /** * Asks to AFIP Servers for sales points availables {@see WS * Specification item 4.11} * * @return array All sales points availables **/ getSalesPoints() { return __awaiter(this, void 0, void 0, function* () { const client = yield this.getClient(); const [output] = yield client.FEParamGetPtosVentaAsync({}); return output; }); } /** * Asks to Afip servers for number of the last voucher created for * certain sales point and voucher type * * @param salesPoint Sales point to ask for last voucher * @param type Voucher type to ask for last voucher * @returns */ getLastVoucher(salesPoint, type) { return __awaiter(this, void 0, void 0, function* () { const client = yield this.getClient(); const [output] = yield client.FECompUltimoAutorizadoAsync({ PtoVta: salesPoint, CbteTipo: type, }); return output.FECompUltimoAutorizadoResult; }); } /** * Create a voucher from AFIP * * Send to AFIP servers request for create a voucher and assign * CAE to them * * @param req data Voucher parameter **/ createVoucher(req) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f; const client = yield this.getClient(); const [output] = yield client.FECAESolicitarAsync({ FeCAEReq: { FeCabReq: { CantReg: req.CbteHasta - req.CbteDesde + 1, PtoVta: req.PtoVta, CbteTipo: req.CbteTipo, }, FeDetReq: { FECAEDetRequest: [ Object.assign(Object.assign({}, req), { Tributos: req.Tributos ? { Tributo: req.Tributos } : undefined, Iva: req.Iva ? { AlicIva: req.Iva } : undefined, CbtesAsoc: req.CbtesAsoc ? { CbteAsoc: req.CbtesAsoc } : undefined, Compradores: req.Compradores ? { Comprador: req.Compradores } : undefined, Opcionales: req.Opcionales ? { Opcional: req.Opcionales } : undefined }), ], }, }, }); const { FECAESolicitarResult } = output; return { response: FECAESolicitarResult, cae: (_c = (_b = (_a = FECAESolicitarResult.FeDetResp) === null || _a === void 0 ? void 0 : _a.FECAEDetResponse) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.CAE, caeFchVto: (_f = (_e = (_d = FECAESolicitarResult.FeDetResp) === null || _d === void 0 ? void 0 : _d.FECAEDetResponse) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.CAEFchVto, }; }); } /** * Create next voucher from AFIP * * This method combines getLastVoucher and createVoucher * for create the next voucher * * @param req data Same to data in Afip.createVoucher except that * don't need CbteDesde and CbteHasta attributes **/ createNextVoucher(req) { return __awaiter(this, void 0, void 0, function* () { const lastVoucher = yield this.getLastVoucher(req.PtoVta, req.CbteTipo); const nextVoucherNumber = lastVoucher.CbteNro + 1; const nextVoucherPayload = Object.assign(Object.assign({}, req), { CbteDesde: nextVoucherNumber, CbteHasta: nextVoucherNumber }); return yield this.createVoucher(nextVoucherPayload); }); } /** * Get voucher information * * Asks to AFIP servers for complete information of voucher * * @param number Number of voucher to get information * @param salesPoint Sales point of voucher to get information * @param type Type of voucher to get information * * @return data with array | null returns array with complete voucher information **/ getVoucherInfo(number, salesPoint, type) { return __awaiter(this, void 0, void 0, function* () { const client = yield this.getClient(); const req = { FeCompConsReq: { CbteNro: number, PtoVta: salesPoint, CbteTipo: type, }, }; try { const [output] = yield client.FECompConsultarAsync(req); return output.FECompConsultarResult; } catch (error) { const err = error; // They send a custom error and we need to parse it if ((err === null || err === void 0 ? void 0 : err.code) === 602) return null; throw error; } }); } /** * Asks to AFIP Servers for voucher types availables **/ getVoucherTypes() { return __awaiter(this, void 0, void 0, function* () { const client = yield this.getClient(); const [output] = yield client.FEParamGetTiposCbteAsync({}); return output.FEParamGetTiposCbteResult; }); } /** * Asks to AFIP Servers for voucher concepts availables * * @return data with array of all voucher concepts availables **/ getConceptTypes() { return __awaiter(this, void 0, void 0, function* () { const client = yield this.getClient(); const [output] = yield client.FEParamGetTiposConceptoAsync({}); return output.FEParamGetTiposConceptoResult; }); } /** * Asks to AFIP Servers for document types availables * * @return data with array of all document types availables **/ getDocumentTypes() { return __awaiter(this, void 0, void 0, function* () { const client = yield this.getClient(); const [output] = yield client.FEParamGetTiposDocAsync({}); return output.FEParamGetTiposDocResult; }); } /** * Asks to AFIP Servers for aliquot availables * * @return data with array of all aliquot availables **/ getAliquotTypes() { return __awaiter(this, void 0, void 0, function* () { const client = yield this.getClient(); const [output] = yield client.FEParamGetTiposIvaAsync({}); return output.FEParamGetTiposIvaResult; }); } /** * Asks to AFIP Servers for currencies availables * * @return data with array of all currencies availables **/ getCurrenciesTypes() { return __awaiter(this, void 0, void 0, function* () { const client = yield this.getClient(); const [output] = yield client.FEParamGetTiposMonedasAsync({}); return output.FEParamGetTiposMonedasResult; }); } /** * Asks to AFIP Servers for voucher optional data available * * @return data with array of all voucher optional data available **/ getOptionsTypes() { return __awaiter(this, void 0, void 0, function* () { const client = yield this.getClient(); const [output] = yield client.FEParamGetTiposOpcionalAsync({}); return output.FEParamGetTiposOpcionalResult; }); } /** * Asks to AFIP Servers for tax availables * * @return data with array of all tax availables **/ getTaxTypes() { return __awaiter(this, void 0, void 0, function* () { const client = yield this.getClient(); const [output] = yield client.FEParamGetTiposTributosAsync({}); return output.FEParamGetTiposTributosResult; }); } /** * Alias for createVoucher method. */ createInvoice(req) { return __awaiter(this, void 0, void 0, function* () { return this.createVoucher(req); }); } /** * Alias for createVoucher method. */ createNextInvoice(req) { return __awaiter(this, void 0, void 0, function* () { return this.createNextVoucher(req); }); } } exports.ElectronicBillingService = ElectronicBillingService; //# sourceMappingURL=electronic-billing.service.js.map