From 278063e7fab86145ed2ff0de20147a7337a38c86 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Sun, 6 Sep 2015 00:37:38 -0300 Subject: [PATCH] =?utf8?q?Totaliza=20dedu=C3=A7=C3=B5es=20por=20dependente?= =?utf8?q?s.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit O total de deduções por dependentes está presente na linha de totais. Implementa uma função para obter o limite da dedução anual por dependente e totaliza em um total DEPENDENTES. --- lib/calcula.c | 15 ++++++++------- lib/calcula.h | 4 ++++ lib/dependente.c | 3 +++ lib/gera.c | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/calcula.c b/lib/calcula.c index 42b33b6..68ad6f1 100644 --- a/lib/calcula.c +++ b/lib/calcula.c @@ -22,23 +22,24 @@ #include "declaracao.h" #include "cmd.h" #include "rendimento.h" -#include "dependente.h" #include "totais.h" static const long long dependente2015 = 215652; +long long deducao_dependente(struct declaracao *dec) +{ + if (dec->ano == 2015) + return dependente2015; + return 0; +} + /* Alguns totais precisam ser limitados. Portanto, um total de decuções * precisa ser ajustado para tais limites. Esta função considerará tais * limites no futuro. */ static long long total_deducao(struct declaracao *dec) { int i; - long long dependentes = 0; - struct dependente *dependente; - for (i = 0; (dependente = list_get(dec->dependentes, i)); i++) { - dependentes += dependente2015; - } - return dependentes + + return totais_get(dec, "DEPENDENTES") + totais_get(dec, "INSS") + totais_get(dec, "PAGAMENTOS"); } diff --git a/lib/calcula.h b/lib/calcula.h index cc40110..97aa5ec 100644 --- a/lib/calcula.h +++ b/lib/calcula.h @@ -19,6 +19,10 @@ #ifndef _CALCULA_H #define _CALCULA_H +#include "declaracao.h" + int calcula_cmd_init(void); +long long deducao_dependente(struct declaracao *dec); + #endif diff --git a/lib/dependente.c b/lib/dependente.c index 20dfa98..5a789c1 100644 --- a/lib/dependente.c +++ b/lib/dependente.c @@ -25,6 +25,8 @@ #include "cmd.h" #include "list.h" #include "util.h" +#include "totais.h" +#include "calcula.h" void dependente_free(void *pointer) { @@ -73,6 +75,7 @@ static int run_dependente(struct declaracao *dec, char **args, int argc) dependente_free(dependente); return r; } + r = totais_add(dec, "DEPENDENTES", deducao_dependente(dec)); return 0; } diff --git a/lib/gera.c b/lib/gera.c index 7f0b4c8..c48be18 100644 --- a/lib/gera.c +++ b/lib/gera.c @@ -227,7 +227,7 @@ static void gera_simples(struct declaracao *dec, FILE *f) fprintf(f, "%013lld", 0); /* TODO: rendimentos PF ext. depend. */ fprintf(f, "%013lld", 0); /* TODO: carnê-leão PF? */ fprintf(f, "%013lld", 0); /* TODO: carnê-leão dependentes */ - fprintf(f, "%013lld", 0); /* TODO: dedução dependentes */ + fprintf(f, "%013lld", totais_get(dec, "DEPENDENTES")); /* TODO: dedução dependentes */ fprintf(f, "%013lld", 0); /* TODO: previdência RRA */ fprintf(f, "%013lld", 0); /* TODO: previdência RRA dependentes */ fprintf(f, "%013lld", 0); /* TODO: pensão RRA */ -- 2.20.1