Created
September 6, 2017 20:38
-
-
Save viniazvd/54e758f46f9150c2089cc1b4099af0c6 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
services.registra_adiantamento = (adiantamento, itens, purchasing_id, valorTotalItens, deposito) => { | |
const queryCodigoBlueform = repositorys.queryCodigoBlueform() | |
return new Promise((resolve, reject) => { | |
db.query(queryCodigoBlueform, (err, results) => { | |
if (err) reject(new Error(err)) | |
const codigoBlueform = results[0].codigoblueform + 1 | |
const codigoAdiantamento = results[0].codigoadiantamento + 1 | |
let { data, contaOrcamentariaSelected, aprovadorSelected, departamento, moedaSelected, unidadeSelected, pagamentoSelected, evento } = adiantamento | |
const dataRegistro = `${data} 00:00:00` | |
if (aprovadorSelected === null) aprovadorSelected = 'Sem aprovador' | |
const dadosMoeda = moedaSelected.split('-') | |
const moeda = dadosMoeda[0] | |
const cotacaoMoeda = dadosMoeda[1] | |
let idusuario = purchasing_id | |
let { cpfoucnpj, nome, tipoconta, banco, agencia, conta, cpfcnpjvalor } = deposito | |
let status = 0 | |
const queryAdiantamento = repositorys.queryAdiantamento(dataRegistro, idusuario, codigoBlueform, contaOrcamentariaSelected, aprovadorSelected, departamento, unidadeSelected, evento, moeda, cotacaoMoeda, pagamentoSelected, tipoconta, cpfoucnpj, cpfcnpjvalor, nome, banco, agencia, conta, status,valorTotalItens, codigoAdiantamento) | |
db.query(queryAdiantamento, (err, results) => { | |
if (err) reject(new Error(err)) | |
let itensAdiantamento = itens.map( item => { | |
let queryItens = repositorys.queryItens(dataRegistro, item.descricao, item.valor, codigoAdiantamento) | |
db.query(queryItens, (err, results) => { | |
if (err) reject(new Error(err)) | |
return resolve(results) | |
}) | |
}) | |
}) | |
}) | |
}) | |
} | |
module.exports = services |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment