X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=lib%2Fcalcula.c;h=71b94b45c32e2db9275e10b3e8d179d411df16f9;hb=520ca52421b0629d7b5b0d598ac628b7826b7faa;hp=42b33b644e0a1ae1cc6e14a67e0bb16736f31369;hpb=9e1a54499282baa48c3d7022dd4d381b6431f2bb;p=cascardo%2Fdeclara.git diff --git a/lib/calcula.c b/lib/calcula.c index 42b33b6..71b94b4 100644 --- a/lib/calcula.c +++ b/lib/calcula.c @@ -22,25 +22,35 @@ #include "declaracao.h" #include "cmd.h" #include "rendimento.h" -#include "dependente.h" #include "totais.h" +#include "util.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; + if (dec->verbose) { + printf("Dedução:\n"); + printf("\tDependentes: "FMT_R"\n", R(totais_get(dec, "DEPENDENTES"))); + printf("\tINSS: "FMT_R"\n", R(totais_get(dec, "INSS"))); + printf("\tPagamentos: "FMT_R"\n", R(totais_get(dec, "PAGAMENTOS"))); + printf("\tReembolsos: -"FMT_R"\n", R(totais_get(dec, "REEMBOLSOS"))); } - return dependentes + + return totais_get(dec, "DEPENDENTES") + totais_get(dec, "INSS") + - totais_get(dec, "PAGAMENTOS"); + totais_get(dec, "PAGAMENTOS") - + totais_get(dec, "REEMBOLSOS"); } static void total_pago(struct declaracao *dec) @@ -52,6 +62,10 @@ static void total_pago(struct declaracao *dec) dec->pago += rendimento->imposto; dec->retido += rendimento->imposto; } + if (dec->verbose) { + printf("Total pago e retido: "FMT_R" "FMT_R"\n", + R(dec->pago), R(dec->retido)); + } } struct taxtable { @@ -73,11 +87,15 @@ static const long long simples2015 = 1588089; static const long long obrigatoriedade2015 = 2681655; -static long long imposto(struct taxtable *tt, long long tr) +static long long imposto(struct taxtable *tt, long long tr, int verbose) { int i; for (i = 0; tr >= tt[i].base; i++); i--; + if (verbose) { + printf("Aplicando aliquota de %d%%, deduzindo " FMT_R"\n", + tt[i].aliquota / 10, R(tt[i].deducao)); + } return tr * tt[i].aliquota / 10000 - tt[i].deducao; } @@ -93,8 +111,11 @@ static long long imposto_simples(struct declaracao *dec) td = simples2015; totais_add(dec, "DESCONTO", td); tr -= td; - totais_add(dec, "BASE", tr); - return imposto(tt, tr); + totais_add(dec, "BASESIMPLES", tr); + if (dec->verbose) { + printf("Desconto simplificado é "FMT_R"\n", R(td)); + } + return imposto(tt, tr, dec->verbose); } static long long imposto_completa(struct declaracao *dec) @@ -107,8 +128,13 @@ static long long imposto_completa(struct declaracao *dec) tt = table2015; tr = totais_get(dec, "RENDPJ"); td = total_deducao(dec); + totais_add(dec, "DEDUCOES", td); tr -= td; - return imposto(tt, tr); + totais_add(dec, "BASECOMPLETA", tr); + if (dec->verbose) { + printf("Desconto completa é "FMT_R"\n", R(td)); + } + return imposto(tt, tr, dec->verbose); } int calcula(struct declaracao *dec) @@ -117,15 +143,30 @@ int calcula(struct declaracao *dec) if (dec->ano != 2015) { return -EINVAL; } - if (totais_get(dec, "RENDPJ") > obrigatoriedade2015) + if (totais_get(dec, "RENDPJ") > obrigatoriedade2015) { + if (dec->verbose) { + printf("Declaracao obrigatoria pois rendimento e" + "maior que mínimo para declaracao: " + FMT_R" > "FMT_R"\n", + R(totais_get(dec, "RENDPJ")), + R(obrigatoriedade2015)); + } dec->obrigatoria = 1; + } i_simples = imposto_simples(dec); i_completa = imposto_completa(dec); total_pago(dec); - if (i_simples > i_completa) { + if (dec->verbose) { + printf("Imposto simplificada e completa: "FMT_R" "FMT_R"\n", + R(i_simples), R(i_completa)); + } + if (dec->tipo != FORCA_SIMPLES && + (i_simples > i_completa || dec->tipo == FORCA_COMPLETA)) { + totais_add(dec, "BASE", totais_get(dec, "BASECOMPLETA")); dec->tipo = COMPLETA; dec->devido = i_completa; } else { + totais_add(dec, "BASE", totais_get(dec, "BASESIMPLES")); dec->tipo = SIMPLES; dec->devido = i_simples; }