2 * Copyright (C) 2015 Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "declaracao.h"
24 #include "rendimento.h"
28 static const long long dependente2015 = 215652;
30 long long deducao_dependente(struct declaracao *dec)
33 return dependente2015;
37 /* Alguns totais precisam ser limitados. Portanto, um total de decuções
38 * precisa ser ajustado para tais limites. Esta função considerará tais
39 * limites no futuro. */
40 static long long total_deducao(struct declaracao *dec)
45 printf("\tDependentes: "FMT_R"\n", R(totais_get(dec, "DEPENDENTES")));
46 printf("\tINSS: "FMT_R"\n", R(totais_get(dec, "INSS")));
47 printf("\tPagamentos: "FMT_R"\n", R(totais_get(dec, "PAGAMENTOS")));
48 printf("\tReembolsos: -"FMT_R"\n", R(totais_get(dec, "REEMBOLSOS")));
50 return totais_get(dec, "DEPENDENTES") +
51 totais_get(dec, "INSS") +
52 totais_get(dec, "PAGAMENTOS") -
53 totais_get(dec, "REEMBOLSOS");
56 static void total_pago(struct declaracao *dec)
58 struct rendimento *rendimento;
60 dec->pago = dec->retido = 0;
61 for (i = 0; rendimento = list_get(dec->rendimento, i); i++) {
62 dec->pago += rendimento->imposto;
63 dec->retido += rendimento->imposto;
66 printf("Total pago e retido: "FMT_R" "FMT_R"\n",
67 R(dec->pago), R(dec->retido));
77 static struct taxtable table2015[] = {
79 { 2145324, 750, 160899, },
80 { 3215148, 1500, 402035, },
81 { 4286917, 2250, 723554, },
82 { 5356572, 2750, 991383, },
83 { 9999999999999LL, 0, 0, },
86 static const long long simples2015 = 1588089;
88 static const long long obrigatoriedade2015 = 2681655;
90 static long long imposto(struct taxtable *tt, long long tr, int verbose)
93 for (i = 0; tr >= tt[i].base; i++);
96 printf("Aplicando aliquota de %d%%, deduzindo " FMT_R"\n",
97 tt[i].aliquota / 10, R(tt[i].deducao));
99 return tr * tt[i].aliquota / 10000 - tt[i].deducao;
102 static long long imposto_simples(struct declaracao *dec)
107 tr = totais_get(dec, "RENDPJ");
108 if (tr / 5 < simples2015)
112 totais_add(dec, "DESCONTO", td);
114 totais_add(dec, "BASESIMPLES", tr);
116 printf("Desconto simplificado é "FMT_R"\n", R(td));
118 return imposto(tt, tr, dec->verbose);
121 static long long imposto_completa(struct declaracao *dec)
125 if (dec->ano != 2015) {
129 tr = totais_get(dec, "RENDPJ");
130 td = total_deducao(dec);
131 totais_add(dec, "DEDUCOES", td);
133 totais_add(dec, "BASECOMPLETA", tr);
135 printf("Desconto completa é "FMT_R"\n", R(td));
137 return imposto(tt, tr, dec->verbose);
140 int calcula(struct declaracao *dec)
142 long long i_simples, i_completa;
143 if (dec->ano != 2015) {
146 if (totais_get(dec, "RENDPJ") > obrigatoriedade2015) {
148 printf("Declaracao obrigatoria pois rendimento e"
149 "maior que mínimo para declaracao: "
151 R(totais_get(dec, "RENDPJ")),
152 R(obrigatoriedade2015));
154 dec->obrigatoria = 1;
156 i_simples = imposto_simples(dec);
157 i_completa = imposto_completa(dec);
160 printf("Imposto simplificada e completa: "FMT_R" "FMT_R"\n",
161 R(i_simples), R(i_completa));
163 if (dec->tipo != FORCA_SIMPLES &&
164 (i_simples > i_completa || dec->tipo == FORCA_COMPLETA)) {
165 totais_add(dec, "BASE", totais_get(dec, "BASECOMPLETA"));
166 dec->tipo = COMPLETA;
167 dec->devido = i_completa;
169 totais_add(dec, "BASE", totais_get(dec, "BASESIMPLES"));
171 dec->devido = i_simples;
173 if (dec->pago > dec->devido)
174 dec->restituicao = dec->pago - dec->devido;
176 dec->pagar = dec->devido - dec->pago;
180 static int run_calcula(struct declaracao *dec, char **args, int argc)
182 totais_add(dec, "EXCLUSIVOS_SEM_13o",
183 totais_get(dec, "EXCLUSIVOS") -
184 totais_get(dec, "DECIMOTERCEIRO"));
188 static struct cmd cmd_calcula = {
193 int calcula_cmd_init(void)
195 cmd_add(&cmd_calcula);