Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.7 kB
1
Indexable
Never
for (let i = 0; i < docs.length; i++) {
      if (docs[i].status === null) {
        const result: any = await this
          .knex.schema.raw(`select codigo7 as codigo, data7 as emissao, trim(leading 0 from serie7) as serie, subserie7 as subSerie, 'I' as status, '${docs[i].modelo}' as modelo, '${docs[i].data ? docs[i].data : ''}' as data, sql_rowid, pronfe7 as chave, 'I' as downStatus from de28${empresa} where codigo7 = ${docs[i].codigo}`)
        const resultArray = JSON.parse(JSON.stringify(result))

        if (docs[i]?.data === null) {
          const data = await this.knex.schema.raw(`select` + "`data`" + ` from downloads where chave = '${resultArray[0][0].chave}';`).debug(false);
          const dataResult = JSON.parse(JSON.stringify(data))
          resultArray[0][0].data = dataResult[0][0].data;
        }

        docs[i] = resultArray[0][0];
      }
      if (docs[i].status === 'I') {
        const result: any = await this
          .knex.schema.raw(`select codigo7 as codigo, emissao7 as emissao, trim(leading 0 from serie7) as serie, subserie7 as subSerie, 'I' as status, '${docs[i].modelo}' as modelo, '${docs[i].data ? docs[i].data : ''}' as data, sql_rowid, pronfe7 as chave, 'I' as downStatus from de28${empresa} where codigo7 = ${docs[i].codigo}`)
        const dataResult = JSON.parse(JSON.stringify(result))

        const isDentroDoPeriodo = Number.parseInt(dataResult[0][0].emissao) >= Number.parseInt(getDocumentosDto.dataInicio) && Number.parseInt(dataResult[0][0].emissao) <= Number.parseInt(getDocumentosDto.dataFim)
        if (isDentroDoPeriodo === false) {
          docs.splice(i, 1)
        }
      }