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");
47 static void total_pago(struct declaracao *dec)
49 struct rendimento *rendimento;
51 dec->pago = dec->retido = 0;
52 for (i = 0; rendimento = list_get(dec->rendimento, i); i++) {
53 dec->pago += rendimento->imposto;
54 dec->retido += rendimento->imposto;
64 static struct taxtable table2015[] = {
66 { 2145324, 750, 160899, },
67 { 3215148, 1500, 402035, },
68 { 4286917, 2250, 723554, },
69 { 5356572, 2750, 991383, },
70 { 9999999999999LL, 0, 0, },
73 static const long long simples2015 = 1588089;
75 static const long long obrigatoriedade2015 = 2681655;
77 static long long imposto(struct taxtable *tt, long long tr)
80 for (i = 0; tr >= tt[i].base; i++);
82 return tr * tt[i].aliquota / 10000 - tt[i].deducao;
85 static long long imposto_simples(struct declaracao *dec)
90 tr = totais_get(dec, "RENDPJ");
91 if (tr / 5 < simples2015)
95 totais_add(dec, "DESCONTO", td);
97 totais_add(dec, "BASE", tr);
98 return imposto(tt, tr);
101 static long long imposto_completa(struct declaracao *dec)
105 if (dec->ano != 2015) {
109 tr = totais_get(dec, "RENDPJ");
110 td = total_deducao(dec);
112 return imposto(tt, tr);
115 int calcula(struct declaracao *dec)
117 long long i_simples, i_completa;
118 if (dec->ano != 2015) {
121 if (totais_get(dec, "RENDPJ") > obrigatoriedade2015)
122 dec->obrigatoria = 1;
123 i_simples = imposto_simples(dec);
124 i_completa = imposto_completa(dec);
126 if (i_simples > i_completa) {
127 dec->tipo = COMPLETA;
128 dec->devido = i_completa;
131 dec->devido = i_simples;
133 if (dec->pago > dec->devido)
134 dec->restituicao = dec->pago - dec->devido;
136 dec->pagar = dec->devido - dec->pago;
140 static int run_calcula(struct declaracao *dec, char **args, int argc)
142 totais_add(dec, "EXCLUSIVOS_SEM_13o",
143 totais_get(dec, "EXCLUSIVOS") -
144 totais_get(dec, "DECIMOTERCEIRO"));
148 static struct cmd cmd_calcula = {
153 int calcula_cmd_init(void)
155 cmd_add(&cmd_calcula);