Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
2.1 kB
1
Indexable
Never
for (let i = 0; i < docs.length; i++) {

      if (docs[i].status === null) {
        const doc = docs[i];
        const nfModeloToNumber = await getNfNumberByDoc(doc);
        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}
            and modelo7 = ${nfModeloToNumber.modelo} and tipo7 = ${nfModeloToNumber.tipo}`)
        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 doc = docs[i];
        const nfModeloToNumber = await getNfNumberByDoc(doc);

        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}
          and modelo7 = ${nfModeloToNumber.modelo} and tipo7 = ${nfModeloToNumber.tipo}`)
        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)
        }
      }



    }