UNPKG

tecnospeed-nfe

Version:

Emit NFe through TecnoSpeed API

101 lines (83 loc) 1.53 kB
'use strict' const Address = require('./address') const TX2 = require('./tx2') class Customer extends TX2 { constructor(settings = {}) { super() this.settings = settings } /** * @param {String} document * @returns {Customer} */ setDocument(document) { this.settings.document = document return this } /** * @returns {String} */ getDocument() { return this.settings.document } /** * @param {String} type * @returns {Customer} */ setType(type) { this.settings.type = type return this } /** * @returns {String} */ getType() { return this.settings.type } /** * @param {String} name * @returns {Customer} */ setName(name) { this.settings.name = name return this } /** * @returns {String} */ getName() { return this.settings.name } /** * @param {Address} address * @returns {Customer} */ setAddress(address) { this.settings.address = address return this } /** * @returns {Address} */ getAddress() { return this.settings.address } /** * @returns {String} */ toTX2() { if (!this.getType()) { return '' } const tx2 = [] tx2.push('xNome_E04=' + this.getName()) if (this.getType().toUpperCase() === 'PF') { tx2.push('CPF_E03=' + this.getDocument()) } if (this.getType().toUpperCase() === 'PJ') { tx2.push('CNPJ_E02=' + this.getDocument()) } return tx2.join('\n') } } module.exports = Customer