diff --git a/service-node-koa/app/services/dashboard.mjs b/service-node-koa/app/services/dashboard.mjs index 7f1f590..f3167c3 100644 --- a/service-node-koa/app/services/dashboard.mjs +++ b/service-node-koa/app/services/dashboard.mjs @@ -17,13 +17,7 @@ export const getDashboard = async ({ usuario_id, inicio, fim }) => { receitaConta: await receitaConta({ usuario_id, inicio, fim }), receitaCategoria: await receitaCategoria({ usuario_id, inicio, fim }), composicaoDespesas: await composicaoDespesas({ usuario_id, inicio, fim }), - composicaoReceitas: [ - { - label: 'Conta 1', - color: 'lightblue', - data: [{ label: 'Salário', value: 18000, color: 'lightgreen' }] - } - ], + composicaoReceitas: await composicaoReceitas({ usuario_id, inicio, fim }), saldos: { // Saldos relativos ao período anteriorGeral: 0, @@ -163,3 +157,23 @@ async function composicaoDespesas({ usuario_id, inicio, fim }){ } return contas.filter(c => c.data.length) } + +async function composicaoReceitas({ usuario_id, inicio, fim }){ + const contas = await knex("conta").where({usuario_id}) + for await (const conta of contas) { + const conta_id = conta.id + conta.color = conta.cor + conta.data = await knex.raw(` + with data_frame as (select categoria.*, movimentacao.* + from movimentacao + left join categoria on categoria.id = movimentacao.categoria_id + where conta_id = :conta_id + and vencimento between :inicio and :fim + and tipo_movimentacao_id = 1) + select descricao as label, cor as color, sum(valor) as value + from data_frame + group by descricao, cor + `,{conta_id, inicio, fim}) + } + return contas.filter(c => c.data.length) +} diff --git a/web-app-vue/src/App.vue b/web-app-vue/src/App.vue index cfc049f..c8bf934 100644 --- a/web-app-vue/src/App.vue +++ b/web-app-vue/src/App.vue @@ -24,7 +24,7 @@ const show = ref(false) - + diff --git a/web-app-vue/src/components/dashboard/controles-dashboard.vue b/web-app-vue/src/components/dashboard/controles-dashboard.vue index 292ad2b..85db4d3 100644 --- a/web-app-vue/src/components/dashboard/controles-dashboard.vue +++ b/web-app-vue/src/components/dashboard/controles-dashboard.vue @@ -17,7 +17,9 @@ :config="receitaDespesaBarConfig" :dataset="receitaDespesaTotalPeriodo" > +
+
+
+

Despesas por categoria

+
+

Receitas por categoria

+
+

Composição de receitas

-
-

{{ conta.label }}

+
+

{{ conta.descricao }}

{ - const total = dashboardState.store.dashboard.receitaDespesaTotalPeriodo.reduce((acc, e) => { + const total = dashboardState.store.dashboard.receitaDespesaTotalPeriodo?.reduce((acc, e) => { acc += e.value return acc - }, 0) + }, 0) || 0 return { style: { ...sparkBarConfig.style, @@ -216,7 +222,7 @@ const receitaDespesaBarConfig = computed(() => { }) const receitaDespesaTotalPeriodo = computed(() => { - return dashboardState.store.dashboard.receitaDespesaTotalPeriodo.map((r) => ({ + return dashboardState.store.dashboard.receitaDespesaTotalPeriodo?.map((r) => ({ ...r, name: r.label, prefix: 'R$ ' @@ -224,7 +230,7 @@ const receitaDespesaTotalPeriodo = computed(() => { }) const receitaDespesaEfetivadaPeriodo = computed(() => { - return dashboardState.store.dashboard.receitaDespesaEfetivadaPeriodo.map((r) => ({ + return dashboardState.store.dashboard.receitaDespesaEfetivadaPeriodo?.map((r) => ({ ...r, name: r.label, prefix: 'R$ ' diff --git a/web-app-vue/src/services/router.js b/web-app-vue/src/services/router.js index dd4cddc..aaf8e5d 100644 --- a/web-app-vue/src/services/router.js +++ b/web-app-vue/src/services/router.js @@ -15,7 +15,7 @@ export const routes = [ { component: AuthPage, path: '/auth' }, { path: '/', redirect: '/dashboard' }, { component: DashboardPage, path: '/dashboard', label: 'Dashboard', icon: 'mdi-chart-bar' }, - { component: NovaMovimentacaoPage, path: '/nova-movimentacao', label: 'Nova movimentação', icon: 'mdi-currency-usd' }, + { component: NovaMovimentacaoPage, path: '/nova-movimentacao', label: 'Novo lançamento', icon: 'mdi-currency-usd' }, { component: ContasPage, path: '/contas', label: 'Contas', icon: 'mdi-card-account-details' }, { component: CategoriasPage, path: '/categorias', label: 'Categorias', icon: 'mdi-playlist-check' }, { component: HistoricoPage, path: '/historico', label: 'Histórico', icon: 'mdi-clipboard-text-search-outline' }, diff --git a/web-app-vue/src/stores/dashboardStore.js b/web-app-vue/src/stores/dashboardStore.js index a380259..986a926 100644 --- a/web-app-vue/src/stores/dashboardStore.js +++ b/web-app-vue/src/stores/dashboardStore.js @@ -9,95 +9,15 @@ export const useDashboardStore = defineStore('dashboard-store', () => { const store = reactive({ dashboard: getRedLine()?.dashboard || { - receitaDespesaTotalPeriodo: [ - // Receita x Despesa - simple-bar - { label: 'Receita Total', value: 18000, color: 'lightgreen' }, - { label: 'Despesa Total', value: 14500, color: 'red' } - ], - receitaDespesaEfetivadaPeriodo: [ - // Receita x Despesa - simple-bar - { label: 'Receita Efetivada', value: 18000, color: 'lightgreen' }, - { label: 'Despesa Efetivada', value: 1500, color: 'red' } - ], - despesaConta: [ - // Despesas por conta - pie - { label: 'Banco', value: 5800.55, color: 'lightyellow' }, - { label: 'Cartão', value: 2600.02, color: 'orange' }, - { label: 'Carteira', value: 1500, color: 'darkgreen' } - ], - despesaCategoria: [ - // Despesas por categoria - pie - { label: 'Moradia', value: 4000, color: 'gray' }, - { label: 'Alimentação', value: 5000, color: 'red' }, - { label: 'Internet', value: 600, color: 'green' }, - { label: 'Empréstimos', value: 3000, color: 'brown' }, - { label: 'Transporte', value: 1500, color: 'blue' } - ], - receitaConta: [ - // Receitas por conta - { label: 'Banco', value: 18000, color: 'lightyellow' } - ], - receitaCategoria: [ - // Receitas categoria - { label: 'Salário', value: 18000, color: 'lightgreen' } - ], - composicaoDespesas: [ - { - label: 'Banco', - color: 'red', - data: [ - { label: 'Moradia', value: 4000, color: 'gray' }, - { label: 'Internet', value: 600, color: 'green' } - ] - }, - { - label: 'Cartão', - color: 'cyan', - data: [{ label: 'Empréstimos', value: 3000, color: 'brown' }] - }, - { - label: 'Carteira', - color: 'violet', - data: [ - { label: 'Transporte', value: 1500, color: 'blue' }, - { label: 'Alimentação', value: 5000, color: 'red' }, - { label: 'Outros', value: 700, color: 'blue' } - ] - } - ], - composicaoReceitas: [ - { - label: 'Conta 1', - color: 'lightblue', - data: [{ label: 'Salário', value: 18000, color: 'lightgreen' }] - } - ], - saldos: { - // Saldos relativos ao período - anteriorGeral: 0, - anterior1Ano: -10, - anterior6Meses: 0, - anterior1Mes: 0, - periodo: 0, - projetado1Mes: 0, - projetado6Meses: 10, - projetado1Ano: 0 - }, - vencimentos: { - quitadas: 7, - aVencer: 3, - emAtraso: 0 - }, - limites: [], - planejamentos: [] + receitaDespesaTotalPeriodo: [], + receitaDespesaEfetivadaPeriodo: [] } }) const sincronizarDashboard = async (inicio, fim) => { const { id } = uState.userData - const result = await getDashboard({ id, inicio, fim }) + const result = await getDashboard({ id, inicio, fim }) store.dashboard = result - console.log(id, inicio, fim) } return { store, sincronizarDashboard }