UNPKG

tecnospeed-nfe

Version:

Emit NFe through TecnoSpeed API

145 lines (125 loc) 2.89 kB
'use strict' const _ = require('lodash') const TX2 = require('./tx2') class Item extends TX2 { constructor(settings = {}) { super() this.settings = settings } /** * @returns {String} */ getTotal() { return Number.parseFloat(this.getCost()).toFixed(2) } /** * @returns {Number} */ getCost() { return this.getQuantity() * this.getUnitCost() } /** * @returns {Number} */ getUnitCost() { return this.settings.unitCost } /** * @param {Number} unitCost * @returns {Item} */ setUnitCost(unitCost) { this.settings.unitCost = unitCost return this } /** * @returns {Number} */ getSequence() { return this.settings.sequence } /** * @param {Number} sequence * @returns {Item} */ setSequence(sequence) { this.settings.sequence = sequence return this } /** * @returns {String} */ getName() { return this.settings.name } /** * @param {String} name * @returns {Item} */ setName(name) { this.settings.name = name return this } /** * @returns {Number} */ getQuantity() { return this.settings.quantity } /** * @param {Number} quantity * @returns {Item} */ setQuantity(quantity) { this.settings.quantity = quantity return this } /** * @returns {Order} * @param {Object} accounting */ setAccounting(accounting) { this.settings.accounting = accounting return this } /** * @returns {Object} */ getAccounting() { return this.settings.accounting } getAccountingParam(param, defaultValue = '0.00') { return _.get(this.getAccounting(), param) || this.getAccounting()[param] || defaultValue } /** * @returns {String} */ toTX2() { const tx2 = [] tx2.push(' ') tx2.push('INCLUIRITEM') tx2.push('xProd_I04=' + `${this.getQuantity()}X ${this.getName()}`) tx2.push('vProd_I11=' + this.getTotal()) tx2.push('nItem_H02=1') tx2.push('cEAN_I03=SEM GTIN') tx2.push('cProd_I02=' + this.getAccountingParam('cprod').replace(/[^a-zA-Z0-9]+/ig, '')) tx2.push('NCM_I05=' + this.getAccountingParam('ncm').replace(/[^a-zA-Z0-9]+/ig, '')) tx2.push('CEST_I05c=' + this.getAccountingParam('cest').replace(/[^a-zA-Z0-9]+/ig, '')) tx2.push('cBenef_I05f=' + this.getAccountingParam('cbnef').replace(/[^a-zA-Z0-9]+/ig, '')) tx2.push('CFOP_I08=' + this.getAccountingParam('cfop').replace(/[^a-zA-Z0-9]+/ig, '')) tx2.push('uCom_I09=UN') tx2.push('qCom_I10=0.00') tx2.push('vUnCom_I10a=0.00') tx2.push('cEANTrib_I12=SEM GTIN') tx2.push('uTrib_I13=UN') tx2.push('qTrib_I14=0.00') tx2.push('vUnTrib_I14a=0.00') tx2.push('indTot_I17b=1') tx2.push('orig_N11=0') tx2.push('CSOSN_N12a=102') tx2.push('SALVARITEM') tx2.push(' ') return tx2.join('\n') } } module.exports = Item