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 long long total_rendimento(struct declaracao *dec)
29 struct rendimento *rendimento;
31 for (i = 0; rendimento = list_get(dec->rendimento, i); i++) {
32 tr += rendimento->rendimento;
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 long long imposto(struct taxtable *tt, long long tr)
79 for (i = 0; tr >= tt[i].base; i++);
81 return tr * tt[i].aliquota / 10000 - tt[i].deducao;
84 static long long imposto_simples(struct declaracao *dec)
89 tr = total_rendimento(dec);
90 dec->totalrendimento = tr;
91 if (tr / 5 < simples2015)
96 return imposto(tt, tr);
99 static long long imposto_completa(struct declaracao *dec)
103 if (dec->ano != 2015) {
107 tr = total_rendimento(dec);
108 td = total_deducao(dec);
109 dec->totalrendimento = tr;
111 return imposto(tt, tr);
114 int calcula(struct declaracao *dec)
116 long long i_simples, i_completa;
117 if (dec->ano != 2015) {
120 i_simples = imposto_simples(dec);
121 i_completa = imposto_completa(dec);
123 if (i_simples > i_completa) {
124 dec->tipo = COMPLETA;
125 dec->devido = i_completa;
128 dec->devido = i_simples;
130 if (dec->pago > dec->devido)
131 dec->restituicao = dec->pago - dec->devido;
133 dec->pagar = dec->devido - dec->pago;
137 static int run_calcula(struct declaracao *dec, char **args, int argc)
142 static struct cmd cmd_calcula = {
147 int calcula_cmd_init(void)
149 cmd_add(&cmd_calcula);