From 6a6d939cc6bc010ef81d5e69d8832b731f5cff9a Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Sat, 19 Mar 2016 11:58:55 -0300 Subject: [PATCH] =?utf8?q?Permite=20expandir=20c=C3=A1lculo=20para=20outro?= =?utf8?q?s=20anos.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Introduz macros para indexar arranjos com o ano do exercício da declaração, e altera as variáveis utilizadas para os valores de 2015 para arranjos, de tal forma a permitir expansão para outros anos. --- lib/ano.h | 28 ++++++++++++++++++++++++++++ lib/calcula.c | 40 ++++++++++++++++++++++++---------------- 2 files changed, 52 insertions(+), 16 deletions(-) create mode 100644 lib/ano.h diff --git a/lib/ano.h b/lib/ano.h new file mode 100644 index 0000000..7cc9969 --- /dev/null +++ b/lib/ano.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2016 Thadeu Lima de Souza Cascardo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _ANO_H +#define _ANO_H + +#define PRIMEIRO_ANO 2015 +#define ULTIMO_ANO 2015 +#define MAX_ANOS (ULTIMO_ANO + 1) +#define ANO(ano) (ano - PRIMEIRO_ANO) +#define ANO_VALIDO(ano) (ANO(ano) >= 0 && ANO(ano) < ANO(MAX_ANOS)) + +#endif diff --git a/lib/calcula.c b/lib/calcula.c index 71b94b4..8507a50 100644 --- a/lib/calcula.c +++ b/lib/calcula.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Thadeu Lima de Souza Cascardo + * Copyright (C) 2015-2016 Thadeu Lima de Souza Cascardo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,13 +24,16 @@ #include "rendimento.h" #include "totais.h" #include "util.h" +#include "ano.h" -static const long long dependente2015 = 215652; +static const long long dependente[ANO(MAX_ANOS)] = { + [ANO(2015)] = 215652, +}; long long deducao_dependente(struct declaracao *dec) { - if (dec->ano == 2015) - return dependente2015; + if (ANO_VALIDO(dec->ano)) + return dependente[ANO(dec->ano)]; return 0; } @@ -83,9 +86,17 @@ static struct taxtable table2015[] = { { 9999999999999LL, 0, 0, }, }; -static const long long simples2015 = 1588089; +static struct taxtable *table[ANO(MAX_ANOS)] = { + [ANO(2015)] = table2015, +}; -static const long long obrigatoriedade2015 = 2681655; +static const long long simples[ANO(MAX_ANOS)] = { + [ANO(2015)] = 1588089, +}; + +static const long long obrigatoriedade[ANO(MAX_ANOS)] = { + [ANO(2015)] = 2681655, +}; static long long imposto(struct taxtable *tt, long long tr, int verbose) { @@ -103,12 +114,12 @@ static long long imposto_simples(struct declaracao *dec) { struct taxtable *tt; long long tr, td; - tt = table2015; + tt = table[ANO(dec->ano)]; tr = totais_get(dec, "RENDPJ"); - if (tr / 5 < simples2015) + if (tr / 5 < simples[ANO(dec->ano)]) td = tr / 5; else - td = simples2015; + td = simples[ANO(dec->ano)]; totais_add(dec, "DESCONTO", td); tr -= td; totais_add(dec, "BASESIMPLES", tr); @@ -122,10 +133,7 @@ static long long imposto_completa(struct declaracao *dec) { struct taxtable *tt; long long tr, td; - if (dec->ano != 2015) { - return -EINVAL; - } - tt = table2015; + tt = table[ANO(dec->ano)]; tr = totais_get(dec, "RENDPJ"); td = total_deducao(dec); totais_add(dec, "DEDUCOES", td); @@ -140,16 +148,16 @@ static long long imposto_completa(struct declaracao *dec) int calcula(struct declaracao *dec) { long long i_simples, i_completa; - if (dec->ano != 2015) { + if (!ANO_VALIDO(dec->ano)) { return -EINVAL; } - if (totais_get(dec, "RENDPJ") > obrigatoriedade2015) { + if (totais_get(dec, "RENDPJ") > obrigatoriedade[ANO(dec->ano)]) { if (dec->verbose) { printf("Declaracao obrigatoria pois rendimento e" "maior que mínimo para declaracao: " FMT_R" > "FMT_R"\n", R(totais_get(dec, "RENDPJ")), - R(obrigatoriedade2015)); + R(obrigatoriedade[ANO(dec->ano)])); } dec->obrigatoria = 1; } -- 2.20.1