@facturacr/atv-sdk
Version:
Librería (SDK) de Javascript/NodeJS para acceder al API de Administración Tributaria Virtual (ATV) del Ministerio de Hacienda.
105 lines • 3.79 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Document = void 0;
class Document {
constructor(props) {
this.props = props;
}
get clave() {
return this.props.clave.value;
}
get fullConsecutive() {
return this.props.fullConsecutive.value;
}
get activityCode() {
return this.props.activityCode;
}
get issueDate() {
return this.props.issueDate;
}
get emitter() {
return this.props.emitter;
}
get receiver() {
return this.props.receiver;
}
get orderLines() {
return this.props.orderLines;
}
get conditionSale() {
return this.props.conditionSale;
}
get deadlineCredit() {
return this.props.deadlineCredit;
}
get paymentMethod() {
return this.props.paymentMethod;
}
get others() {
return this.props.others;
}
get summaryInvoice() {
if (this.props.summaryInvoice) {
return this.props.summaryInvoice;
}
const orderLineSumResult = this.sumOrderLines();
const servicesLineSumResult = this.sumServicesLines();
const merchandiseLineSumResult = this.sumMerchandiseLines();
const summary = {
currency: {
code: 'CRC',
exchangeRate: '585.69'
},
totalExemptServices: 0,
totalEncumberedServices: servicesLineSumResult.totalAmount,
totalExonerated: 0,
totalTaxedServices: servicesLineSumResult.totalTaxes,
totalTaxes: orderLineSumResult.totalTaxes,
totalDiscounts: 0,
totalEncumberedMerchandise: merchandiseLineSumResult.totalAmount,
totalTaxed: orderLineSumResult.totalTaxes,
totalExemptMerchandise: 0,
totalExempt: 0,
totalNetSale: orderLineSumResult.totalAmount,
totalEncumbered: orderLineSumResult.totalAmount
};
const totalSale = summary.totalEncumbered + summary.totalExempt + summary.totalExonerated;
return Object.assign(Object.assign({}, summary), { totalSale, totalNetSale: totalSale - summary.totalDiscounts, totalVoucher: summary.totalNetSale + summary.totalTaxed });
}
get referenceInformation() {
return this.props.referenceInformation;
}
isAService(orderLine) {
const servicesMeasurementUnits = ['Sp', 'St', 'Spe'];
return servicesMeasurementUnits.includes(orderLine.measureUnit);
}
sumServicesLines() {
return this.orderLines.filter(this.isAService).reduce((previousValue, currentValue) => {
return {
totalAmount: previousValue.totalAmount + currentValue.totalAmount,
totalTaxes: previousValue.totalTaxes + currentValue.tax.amount
};
}, { totalAmount: 0, totalTaxes: 0 });
}
sumMerchandiseLines() {
return this.orderLines.filter((ol) => !this.isAService(ol)).reduce((previousValue, currentValue) => {
return {
totalAmount: previousValue.totalAmount + currentValue.totalAmount,
totalTaxes: previousValue.totalTaxes + currentValue.tax.amount
};
}, { totalAmount: 0, totalTaxes: 0 });
}
sumOrderLines() {
return this.orderLines.reduce((previousValue, currentValue) => {
return {
totalAmount: previousValue.totalAmount + currentValue.totalAmount,
totalTaxes: previousValue.totalTaxes + currentValue.tax.amount
};
}, { totalAmount: 0, totalTaxes: 0 });
}
static create(props) {
return new Document(props);
}
}
exports.Document = Document;
//# sourceMappingURL=Document.js.map