Skip to content

Commit

Permalink
minor enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
sombriks committed Mar 25, 2024
1 parent b3f13e4 commit 6aa926f
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @param { import('knex').Knex } knex
* @returns { Promise<void> }
*/
export const up = async (knex) =>
knex.schema.table('planejamento', tb => {
tb.integer('tipo_movimentacao_id').unsigned().notNullable()
.references('tipo_movimentacao.id').defaultTo(2)
})

/**
* @param { import('knex').Knex } knex
* @returns { Promise<void> }
*/
export const down = async (knex) =>
knex.schema.table('planejamento', tb => {
tb.dropColumn("tipo_movimentacao_id")
})
19 changes: 15 additions & 4 deletions service-node-koa/app/services/recorrencia.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { knex } from '../config/db/index.mjs'
import { addMonths, differenceInDays, differenceInMonths, differenceInYears } from 'date-fns'
import { addDays, addMonths, addYears, differenceInDays, differenceInMonths, differenceInYears } from 'date-fns'

export const listRecorrencia = ({ usuario_id = -1, q = '', limit = 10, offset = 0 }) => {
return knex('recorrencia')
Expand Down Expand Up @@ -41,16 +41,16 @@ export const geraLancamentos = async ({ usuario_id, id }) => {
recorrencia_id: recorrencia.id,
conta_id: recorrencia.conta_id,
tipo_movimentacao_id: recorrencia.tipo_movimentacao_id,
vencimento: addMonths(recorrencia.inicial, i).toISOString(),
vencimento: proximoVencimento(recorrencia, i),
valor: recorrencia.valorParcela
})
}
const result = await knex('movimentacao').insert(lancamentos)
return { success: true }
return { success: true, result }
}

const limparParcelas = async (recorrencia) => {
return await knex('movimentacao').del().where({ recorrencia_id: recorrencia.id })
return knex('movimentacao').del().where({ recorrencia_id: recorrencia.id })
}

const calculaParcelas = ({ tipo_recorrencia_id, inicial, final }) => {
Expand All @@ -63,3 +63,14 @@ const calculaParcelas = ({ tipo_recorrencia_id, inicial, final }) => {
return 1 + differenceInDays(final, inicial)
}
}

const proximoVencimento = (recorrencia, i) => {
switch (recorrencia.tipo_recorrencia_id) {
case 1:
return addMonths(recorrencia.inicial, i).toISOString()
case 2:
return addYears(recorrencia.inicial, i).toISOString()
default:
return addDays(recorrencia.inicial, i).toISOString()
}
}
2 changes: 1 addition & 1 deletion web-app-vue/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=1.5">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.1, maximum-scale=1.5">
<title>Redline Finance</title>
</head>
<body>
Expand Down
39 changes: 38 additions & 1 deletion web-app-vue/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6aa926f

Please sign in to comment.