fecr
Version:
Modulo de comprobantes electrónicos para el API del Ministerio de Hacienda de Costa Rica versión 4.3
95 lines (76 loc) • 2.02 kB
JavaScript
"use strict";
class Item {
constructor(item) {
this.number = item.number;
if (item.hsCode) {
this.hsCode = item.hsCode;
}
if (item.code) {
this.code = item.code;
}
if (item.commercialCode) {
this.typeCommercialCode = item.typeCommercialCode ? item.typeCommercialCode : "04";
this.commercialCode = item.commercialCode;
}
this.quantity = item.quantity;
this.unit = item.unit;
if (item.commercialUnit) {
this.commercialUnit = item.commercialUnit;
}
this.description = item.description;
this.unitPrice = item.unitPrice;
this.total = item.total;
this.discounts = item.discounts;
this.subtotal = item.subtotal;
this.taxBase = item.taxBase;
if (item.taxes) {
this.taxes = item.taxes;
}
this.taxNet = item.taxNet ? item.taxNet : 0;
this.netTotal = item.netTotal;
}
generate() {
var obj = {};
obj.NumeroLinea = this.number;
if (this.code) {
obj.Codigo = this.code;
}
if (this.commercialCode) {
obj.CodigoComercial = {
Tipo: this.typeCommercialCode,
Codigo: this.commercialCode
};
}
obj.Cantidad = this.quantity;
obj.UnidadMedida = this.unit;
obj.Detalle = this.description;
obj.PrecioUnitario = this.unitPrice;
obj.MontoTotal = this.total;
if (this.discounts) {
obj.Descuento = [];
this.discounts.forEach((_ref) => {
var {
discountAmount,
discountReason
} = _ref;
obj.Descuento.push({
MontoDescuento: discountAmount,
NaturalezaDescuento: discountReason
});
});
}
obj.SubTotal = this.subtotal;
obj.BaseImponible = this.taxBase;
if (this.taxes) {
var iva = [];
this.taxes.forEach(tax => {
iva.push(tax.generate());
});
obj.Impuesto = iva;
}
obj.ImpuestoNeto = this.taxNet;
obj.MontoTotalLinea = this.netTotal;
return obj;
}
}
module.exports = Item;