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"
27 static const long long dependente2015 = 215652;
29 long long deducao_dependente(struct declaracao *dec)
32 return dependente2015;
36 /* Alguns totais precisam ser limitados. Portanto, um total de decuções
37 * precisa ser ajustado para tais limites. Esta função considerará tais
38 * limites no futuro. */
39 static long long total_deducao(struct declaracao *dec)
42 return totais_get(dec, "DEPENDENTES") +
43 totais_get(dec, "INSS") +
44 totais_get(dec, "PAGAMENTOS") -
45 totais_get(dec, "REEMBOLSOS");
48 static void total_pago(struct declaracao *dec)
50 struct rendimento *rendimento;
52 dec->pago = dec->retido = 0;
53 for (i = 0; rendimento = list_get(dec->rendimento, i); i++) {
54 dec->pago += rendimento->imposto;
55 dec->retido += rendimento->imposto;
65 static struct taxtable table2015[] = {
67 { 2145324, 750, 160899, },
68 { 3215148, 1500, 402035, },
69 { 4286917, 2250, 723554, },
70 { 5356572, 2750, 991383, },
71 { 9999999999999LL, 0, 0, },
74 static const long long simples2015 = 1588089;
76 static const long long obrigatoriedade2015 = 2681655;
78 static long long imposto(struct taxtable *tt, long long tr)
81 for (i = 0; tr >= tt[i].base; i++);
83 return tr * tt[i].aliquota / 10000 - tt[i].deducao;
86 static long long imposto_simples(struct declaracao *dec)
91 tr = totais_get(dec, "RENDPJ");
92 if (tr / 5 < simples2015)
96 totais_add(dec, "DESCONTO", td);
98 totais_add(dec, "BASESIMPLES", tr);
99 return imposto(tt, tr);
102 static long long imposto_completa(struct declaracao *dec)
106 if (dec->ano != 2015) {
110 tr = totais_get(dec, "RENDPJ");
111 td = total_deducao(dec);
112 totais_add(dec, "DEDUCOES", td);
114 totais_add(dec, "BASECOMPLETA", tr);
115 return imposto(tt, tr);
118 int calcula(struct declaracao *dec)
120 long long i_simples, i_completa;
121 if (dec->ano != 2015) {
124 if (totais_get(dec, "RENDPJ") > obrigatoriedade2015)
125 dec->obrigatoria = 1;
126 i_simples = imposto_simples(dec);
127 i_completa = imposto_completa(dec);
129 if (dec->tipo != FORCA_SIMPLES &&
130 (i_simples > i_completa || dec->tipo == FORCA_COMPLETA)) {
131 totais_add(dec, "BASE", totais_get(dec, "BASECOMPLETA"));
132 dec->tipo = COMPLETA;
133 dec->devido = i_completa;
135 totais_add(dec, "BASE", totais_get(dec, "BASESIMPLES"));
137 dec->devido = i_simples;
139 if (dec->pago > dec->devido)
140 dec->restituicao = dec->pago - dec->devido;
142 dec->pagar = dec->devido - dec->pago;
146 static int run_calcula(struct declaracao *dec, char **args, int argc)
148 totais_add(dec, "EXCLUSIVOS_SEM_13o",
149 totais_get(dec, "EXCLUSIVOS") -
150 totais_get(dec, "DECIMOTERCEIRO"));
154 static struct cmd cmd_calcula = {
159 int calcula_cmd_init(void)
161 cmd_add(&cmd_calcula);