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.
20 #include "declaracao.h"
22 #include "rendimento.h"
26 static void total_rendimento(struct declaracao *dec)
29 struct rendimento *rendimento;
31 for (i = 0; rendimento = list_get(dec->rendimento, i); i++) {
32 tr += rendimento->rendimento;
34 dec->totalrendimento = tr;
37 static long long total_deducao(struct declaracao *dec)
40 struct rendimento *rendimento;
42 for (i = 0; rendimento = list_get(dec->rendimento, i); i++) {
43 td += rendimento->previdencia;
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 = dec->totalrendimento;
92 dec->totalrendimento = tr;
93 if (tr / 5 < simples2015)
98 return imposto(tt, tr);
101 static long long imposto_completa(struct declaracao *dec)
105 if (dec->ano != 2015) {
109 tr = dec->totalrendimento;
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 total_rendimento(dec);
122 if (dec->totalrendimento > obrigatoriedade2015)
123 dec->obrigatoria = 1;
124 i_simples = imposto_simples(dec);
125 i_completa = imposto_completa(dec);
127 if (i_simples > i_completa) {
128 dec->tipo = COMPLETA;
129 dec->devido = i_completa;
132 dec->devido = i_simples;
134 if (dec->pago > dec->devido)
135 dec->restituicao = dec->pago - dec->devido;
137 dec->pagar = dec->devido - dec->pago;
141 static int run_calcula(struct declaracao *dec, char **args, int argc)
146 static struct cmd cmd_calcula = {
151 int calcula_cmd_init(void)
153 cmd_add(&cmd_calcula);