Created
June 13, 2016 22:22
-
-
Save FraGoTe/7148976e3161bd8cd00f2c4cb2d67bf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(DocumentoElectronico) { | |
var _archivos = require('../../classes/Archivos') | |
DocumentoElectronico._obtenerRucColegio = function (cb) | |
{ | |
var knex = DocumentoElectronico.app.getKnex(); | |
return knex.schema.then(function(){ | |
return knex('colegio') | |
.select('RUC'); | |
}); | |
} | |
DocumentoElectronico._obtenerCodigoSunat = function (tipoDocumento) | |
{ | |
var codigoSunat = ''; | |
/* | |
01 Factura Electrónica | |
03 Boleta de venta | |
07 Nota de Crédito | |
08 Nota de Debito | |
*/ | |
switch (tipoDocumento) { | |
case 'FA': | |
codigoSunat = '01' | |
break; | |
case 'BV': | |
codigoSunat = '03' | |
break; | |
case 'NC': | |
codigoSunat = '07' | |
break; | |
case 'ND': | |
codigoSunat = '08' | |
break; | |
} | |
return codigoSunat; | |
} | |
DocumentoElectronico._obtenerNombreDocumento = function ( | |
tipoDocumento, prefijoDocumento, numeroDocumento, fechaRegistro | |
) { | |
var nombreDocumento = '' | |
console.log('RUC COLEGIOOOOOO -------'); | |
var ruc = this._obtenerRucColegio().map(function(row) { return row; }); | |
console.log(ruc); | |
console.log('RUC COLEGIOOOOOO22 -------'); | |
this._obtenerRucColegio().map(function(row) { ruc = row; }); | |
console.log(ruc); | |
console.log('RUC COLEGIOOOOOO333333 -------'); | |
this._obtenerRucColegio().done(function(row) { ruc = row; }); | |
console.log(ruc); | |
switch (tipoDocumento) { | |
case 'FA': | |
case 'BV': | |
case 'NC': | |
case 'ND': | |
nombreDocumento = | |
// this._obtenerRucColegio(function(RUC) { | |
// return RUC; | |
//}) + '-' + | |
this._obtenerCodigoSunat(tipoDocumento) + '-' + | |
prefijoDocumento + '-' + | |
numeroDocumento | |
break; | |
case 'RC': | |
case 'RA': | |
nombreDocumento = | |
//this._obtenerRucColegio() + '-' + | |
this._obtenerCodigoSunat(tipoDocumento) + '-' + | |
fecha + '-' + | |
numeroDocumento | |
break; | |
} | |
return nombreDocumento; | |
} | |
DocumentoElectronico.generarDocumento = function( | |
tipoDocumento, prefijoDocumento, numeroDocumento, | |
fechaRegistro, cb | |
) { | |
var nombreDocumento = this._obtenerNombreDocumento( | |
tipoDocumento, prefijoDocumento, numeroDocumento, fechaRegistro | |
); | |
console.log(nombreDocumento); | |
console.log(tipoDocumento); | |
console.log(prefijoDocumento); | |
console.log(numeroDocumento); | |
cb(null, { 'nombreDocumento': nombreDocumento}); | |
} | |
DocumentoElectronico.remoteMethod('generarDocumento', { | |
http: {path: '/generar-documento', verb: 'get'}, | |
accepts: [ | |
{ arg: 'tipoDocumento', type: 'string'}, | |
{ arg: 'prefijoDocumento', type: 'string'}, | |
{ arg: 'numeroDocumento', type: 'string'}, | |
{ arg: 'fechaRegistro', type: 'date'}, /*, | |
{ arg: 'tipoDocumento', type: 'string'}, | |
{ arg: 'tipoDocumento', type: 'string'}*/ | |
], | |
returns: {arg: 'generarDocumento', type: 'string'} | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment