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 long long total_deducao(struct declaracao *dec)
30 struct rendimento *rendimento;
32 for (i = 0; rendimento = list_get(dec->rendimento, i); i++) {
33 td += rendimento->previdencia;
38 static void total_pago(struct declaracao *dec)
40 struct rendimento *rendimento;
42 dec->pago = dec->retido = 0;
43 for (i = 0; rendimento = list_get(dec->rendimento, i); i++) {
44 dec->pago += rendimento->imposto;
45 dec->retido += rendimento->imposto;
55 static struct taxtable table2015[] = {
57 { 2145324, 750, 160899, },
58 { 3215148, 1500, 402035, },
59 { 4286917, 2250, 723554, },
60 { 5356572, 2750, 991383, },
61 { 9999999999999LL, 0, 0, },
64 static const long long simples2015 = 1588089;
66 static const long long obrigatoriedade2015 = 2681655;
68 static long long imposto(struct taxtable *tt, long long tr)
71 for (i = 0; tr >= tt[i].base; i++);
73 return tr * tt[i].aliquota / 10000 - tt[i].deducao;
76 static long long imposto_simples(struct declaracao *dec)
81 tr = totais_get(dec, "RENDPJ");
82 if (tr / 5 < simples2015)
87 return imposto(tt, tr);
90 static long long imposto_completa(struct declaracao *dec)
94 if (dec->ano != 2015) {
98 tr = totais_get(dec, "RENDPJ");
99 td = total_deducao(dec);
101 return imposto(tt, tr);
104 int calcula(struct declaracao *dec)
106 long long i_simples, i_completa;
107 if (dec->ano != 2015) {
110 if (totais_get(dec, "RENDPJ") > obrigatoriedade2015)
111 dec->obrigatoria = 1;
112 i_simples = imposto_simples(dec);
113 i_completa = imposto_completa(dec);
115 if (i_simples > i_completa) {
116 dec->tipo = COMPLETA;
117 dec->devido = i_completa;
120 dec->devido = i_simples;
122 if (dec->pago > dec->devido)
123 dec->restituicao = dec->pago - dec->devido;
125 dec->pagar = dec->devido - dec->pago;
129 static int run_calcula(struct declaracao *dec, char **args, int argc)
134 static struct cmd cmd_calcula = {
139 int calcula_cmd_init(void)
141 cmd_add(&cmd_calcula);