UNPKG

@facturacr/atv-sdk

Version:

Librería (SDK) de Javascript/NodeJS para acceder al API de Administración Tributaria Virtual (ATV) del Ministerio de Hacienda.

114 lines 4.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mapDocumentToAtvFormat = void 0; const mapOrderLinesToAtvFormat = (orderLines) => { const LineaDetalle = orderLines.map((orderLine) => { return { NumeroLinea: orderLine.lineNumber, Codigo: orderLine.code, // CodigoComercial Cantidad: orderLine.quantity, UnidadMedida: orderLine.measureUnit, // UnidadMedidaComercial Detalle: orderLine.detail, PrecioUnitario: orderLine.unitaryPrice, MontoTotal: orderLine.totalAmount, // Descuento SubTotal: orderLine.subTotal, // BaseImponible Impuesto: { Codigo: orderLine.tax.code, CodigoTarifa: orderLine.tax.rateCode, Tarifa: orderLine.tax.rate, Monto: orderLine.tax.amount }, // ImpuestoNeto MontoTotalLinea: orderLine.totalOrderLineAmount }; }); return { LineaDetalle }; }; const mapSummaryInvoice = (summaryInvoice) => { return { CodigoTipoMoneda: { CodigoMoneda: summaryInvoice.currency.code, TipoCambio: summaryInvoice.currency.exchangeRate }, TotalServGravados: summaryInvoice.totalEncumberedServices, TotalServExentos: summaryInvoice.totalExemptServices, TotalMercanciasGravadas: summaryInvoice.totalEncumberedMerchandise, TotalMercanciasExentas: summaryInvoice.totalExemptMerchandise, TotalGravado: summaryInvoice.totalEncumbered, TotalExento: summaryInvoice.totalExempt, TotalExonerado: summaryInvoice.totalExonerated, TotalVenta: summaryInvoice.totalSale, TotalDescuentos: summaryInvoice.totalDiscounts, TotalVentaNeta: summaryInvoice.totalNetSale, TotalImpuesto: summaryInvoice.totalTaxes, TotalComprobante: summaryInvoice.totalVoucher }; }; const mapPerson = (person) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; const atvPerson = { Nombre: person.fullName, Identificacion: { Tipo: person.identifierType, Numero: person.identifierId }, NombreComercial: person.commercialName, Ubicacion: undefined, Telefono: undefined, Fax: undefined, CorreoElectronico: undefined }; atvPerson.Ubicacion = person.location ? { Provincia: (_a = person.location) === null || _a === void 0 ? void 0 : _a.province, Canton: (_c = (_b = person.location) === null || _b === void 0 ? void 0 : _b.canton) === null || _c === void 0 ? void 0 : _c.padStart(2, '0'), Distrito: (_e = (_d = person.location) === null || _d === void 0 ? void 0 : _d.district) === null || _e === void 0 ? void 0 : _e.padStart(2, '0'), Barrio: (_g = (_f = person.location) === null || _f === void 0 ? void 0 : _f.neighborhood) === null || _g === void 0 ? void 0 : _g.padStart(2, '0'), OtrasSenas: (_h = person.location) === null || _h === void 0 ? void 0 : _h.details } : undefined; atvPerson.Telefono = person.phone ? { CodigoPais: (_j = person.phone) === null || _j === void 0 ? void 0 : _j.countryCode, NumTelefono: (_k = person.phone) === null || _k === void 0 ? void 0 : _k.number } : undefined; atvPerson.Fax = person.fax ? { CodigoPais: (_l = person.fax) === null || _l === void 0 ? void 0 : _l.countryCode, NumTelefono: (_m = person.fax) === null || _m === void 0 ? void 0 : _m.number } : undefined; atvPerson.CorreoElectronico = person.email; return atvPerson; }; const mapReferenceInformation = (referenceInfo) => { return { TipoDoc: referenceInfo.docType, Numero: referenceInfo.refNumber, FechaEmision: referenceInfo.issueDate.toISOString(), Codigo: referenceInfo.code, Razon: referenceInfo.reason }; }; const mapDocumentToAtvFormat = (docName, document) => { const key = docName; const doc = { Clave: document.clave, CodigoActividad: document.activityCode.padStart(6, '0'), NumeroConsecutivo: document.fullConsecutive, FechaEmision: document.issueDate.toISOString(), Emisor: mapPerson(document.emitter), Receptor: mapPerson(document.receiver), CondicionVenta: document.conditionSale, PlazoCredito: document.deadlineCredit, MedioPago: document.paymentMethod, DetalleServicio: mapOrderLinesToAtvFormat(document.orderLines), ResumenFactura: mapSummaryInvoice(document.summaryInvoice), Otros: document.others }; doc.InformacionReferencia = document.referenceInformation ? mapReferenceInformation(document.referenceInformation) : undefined; return { [key]: doc }; }; exports.mapDocumentToAtvFormat = mapDocumentToAtvFormat; //# sourceMappingURL=billDocToAtv.js.map