Skip to content

Commit

Permalink
Ajuste sincronismo
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfl2007 committed Sep 16, 2024
1 parent 0de2f04 commit 9a08a56
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/cron-jobs/cron-jobs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class CronJobsService {
});
}

async onModuleLoad() {
async onModuleLoad() {
const THIS_CLASS_WITH_METHOD = 'CronJobsService.onModuleLoad';

this.jobsConfig.push(
Expand Down Expand Up @@ -309,11 +309,8 @@ export class CronJobsService {
}
this.logger.log('Tarefa iniciada', METHOD);
const startDate = new Date();
// const sex = subDays(today, 7);
// const qui = subDays(today, 1);

const sex = new Date('2024-07-12');
const qui = new Date('2024-09-06');
const sex = subDays(today, 7);
const qui = subDays(today, 1);

await this.cnabService.saveTransacoesJae(sex, qui, 0, 'Van');
const listCnab = await this.cnabService.generateRemessa({
Expand Down Expand Up @@ -390,7 +387,7 @@ export class CronJobsService {

private async syncTransacaoViewOrdem(method = 'syncTransacaoViewOrdem') {
try {
const startDate = subDays(new Date(), 15);
const startDate = subDays(new Date(), 30);
const today = new Date();
this.logger.log(`Sincronizando TransacaoViews entre ${formatDateYMD(startDate)} e ${formatDateYMD(today)}`, method);
await this.cnabService.syncTransacaoViewOrdemPgto({ dataOrdem_between: [startDate, today] });
Expand Down
13 changes: 10 additions & 3 deletions src/transacao-view/transacao-view.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,14 @@ export class TransacaoViewRepository {
SELECT
DISTINCT ON (tv.id)
tv.id AS tv_id,
ita.id AS ita_id,
(select ia.id from item_transacao_agrupado ia
where ia."idOrdemPagamento" = ita."idOrdemPagamento"
and ia."idOperadora" = ita."idOperadora"
and ia."dataOrdem" = ita."dataOrdem"
and ia."createdAt" =(select max(itt."createdAt") from item_transacao_agrupado itt
where ia."idOrdemPagamento" = itt."idOrdemPagamento"
and ia."idOperadora" = itt."idOperadora"
and ia."dataOrdem" = itt."dataOrdem") ) as ita_id,
tv."datetimeTransacao",
tv."datetimeProcessamento",
ita."dataOrdem"
Expand All @@ -94,8 +101,8 @@ export class TransacaoViewRepository {
AND tv."idOperadora" = ita."idOperadora"
AND tv."operadoraCpfCnpj" = cf."cpfCnpj"
AND tv."datetimeTransacao"::DATE BETWEEN
(ita."dataOrdem"::DATE - (CASE WHEN ita."nomeConsorcio" = 'VLT' THEN INTERVAL '2 DAYS' ELSE INTERVAL '8 DAYS' END)) -- VENCIMENTO - 2 SE VLT; SENÃO QUINTA PGTO
AND (DATE(ita."dataOrdem") - INTERVAL '2 DAYS') -- VENCIMENTO - 2 (OU QUARTA PGTO SE NÃO for VLT)
(ita."dataCaptura"::DATE - (CASE WHEN ita."nomeConsorcio" = 'VLT' THEN INTERVAL '2 DAYS' ELSE INTERVAL '8 DAYS' END)) -- VENCIMENTO - 2 SE VLT; SENÃO QUINTA PGTO
AND (DATE(ita."dataCaptura") - INTERVAL '2 DAYS') -- VENCIMENTO - 2 (OU QUARTA PGTO SE NÃO for VLT)
WHERE (1=1) ${where.length ? `AND ${where.join(' AND ')}` : ''}
ORDER BY tv.id ASC, ita.id DESC
) associados
Expand Down

0 comments on commit 9a08a56

Please sign in to comment.