From 687bc57d97d703decd2a41f224a3de0b41f5881d Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Sun, 6 Sep 2015 00:32:23 -0300 Subject: [PATCH] =?utf8?q?Adiciona=20suporte=20a=20c=C3=B4njuge.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Dados da declaração do cônjuge estão na linha 9. Futuramente, seria interessante implementar a importação dos dados da declaração do cônjuge. --- lib/Makefile.am | 3 +- lib/conjuge.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/conjuge.h | 43 ++++++++++++++++++++++ lib/declaracao.c | 2 ++ lib/declaracao.h | 2 ++ lib/gera.c | 16 +++++++++ src/declara.c | 2 ++ 7 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 lib/conjuge.c create mode 100644 lib/conjuge.h diff --git a/lib/Makefile.am b/lib/Makefile.am index f0fc33a..542c585 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -14,4 +14,5 @@ libreceita_la_SOURCES = declaracao.c declaracao.h \ isento.c isento.h \ pagamento.c pagamento.h \ bem.c bem.h \ - dependente.c dependente.h + dependente.c dependente.h \ + conjuge.c conjuge.h diff --git a/lib/conjuge.c b/lib/conjuge.c new file mode 100644 index 0000000..a0631b2 --- /dev/null +++ b/lib/conjuge.c @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2015 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. + */ + +#include "conjuge.h" +#include +#include +#include +#include +#include +#include "declaracao.h" +#include "cmd.h" +#include "util.h" + +void conjuge_free(struct declaracao *dec) +{ + if (dec->conjuge.cpf) + free(dec->conjuge.cpf); +} + +static int conjuge_parse(struct declaracao *dec, char **args) +{ + int r = 0; + + dec->conjuge.cpf = strdup(args[1]); + + r += set_llong(args[2], &dec->conjuge.base); + r += set_llong(args[3], &dec->conjuge.imposto); + r += set_llong(args[4], &dec->conjuge.isento); + r += set_llong(args[5], &dec->conjuge.exclusivo); + r += set_llong(args[6], &dec->conjuge.rendpj_exigibilidade_suspensa); + r += set_llong(args[7], &dec->conjuge.total); + r += set_int(args + 7, 2, &dec->conjuge.entregou); + + if (!dec->conjuge.cpf) { + conjuge_free(dec); + return -ENOMEM; + } + if (r < 0 || dec->conjuge.base < 0 || dec->conjuge.imposto < 0 || + dec->conjuge.isento < 0 || dec->conjuge.exclusivo < 0 || + dec->conjuge.rendpj_exigibilidade_suspensa < 0 || + dec->conjuge.total < 0 || dec->conjuge.entregou < 0) { + conjuge_free(dec); + return -EINVAL; + } + return 0; +} + +static int run_conjuge(struct declaracao *dec, char **args, int argc) +{ + struct conjuge *conjuge; + int r; + if (argc != 9) + return -EINVAL; + r = conjuge_parse(dec, args); + if (r < 0) + return r; + return 0; +} + +void conjuge_salva(struct declaracao *dec, FILE *f) +{ + fprintf(f, "conjuge \"%s\" %lld %lld %lld %lld %lld %lld %lld %lld %d\n", + dec->conjuge.cpf, dec->conjuge.base, + dec->conjuge.imposto, dec->conjuge.isento, + dec->conjuge.exclusivo, + dec->conjuge.rendpj_exigibilidade_suspensa, + dec->conjuge.total, dec->conjuge.entregou); +} + +static struct cmd cmd_conjuge = { + .name = "conjuge", + .run = run_conjuge, +}; + +int conjuge_cmd_init(void) +{ + cmd_add(&cmd_conjuge); + return 0; +} diff --git a/lib/conjuge.h b/lib/conjuge.h new file mode 100644 index 0000000..72ec340 --- /dev/null +++ b/lib/conjuge.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2015 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 _CONJUGE_H +#define _CONJUGE_H + +#include + +struct declaracao; + +struct conjuge { + char *cpf; + long long base; + long long imposto; + long long isento; + long long exclusivo; + long long rendpj_exigibilidade_suspensa; + long long total; + int entregou; +}; + +void conjuge_free(struct declaracao *dec); + +void conjuge_salva(struct declaracao *dec, FILE *f); + +int conjuge_cmd_init(void); + +#endif diff --git a/lib/declaracao.c b/lib/declaracao.c index b1cfb55..7eef34c 100644 --- a/lib/declaracao.c +++ b/lib/declaracao.c @@ -20,6 +20,7 @@ #include #include #include "list.h" +#include "conjuge.h" #include "sistema.h" #include "rendimento.h" #include "isento.h" @@ -98,6 +99,7 @@ void declaracao_free(struct declaracao *dec) list_free(dec->bens, bem_free); list_free(dec->dependentes, dependente_free); pmhash_del(dec->totais); + conjuge_free(dec); sistema_free(dec); free(dec); } diff --git a/lib/declaracao.h b/lib/declaracao.h index be91d96..eaff855 100644 --- a/lib/declaracao.h +++ b/lib/declaracao.h @@ -21,6 +21,7 @@ #include "list.h" #include "contribuinte.h" +#include "conjuge.h" #include "sistema.h" enum { @@ -38,6 +39,7 @@ struct declaracao { struct list *bens; struct list *dependentes; struct contribuinte contribuinte; + struct conjuge conjuge; struct sistema sistema; long long pago; long long retido; diff --git a/lib/gera.c b/lib/gera.c index e16f49c..3ae5e3d 100644 --- a/lib/gera.c +++ b/lib/gera.c @@ -377,6 +377,20 @@ static void gera_exclusivos(struct declaracao *dec, FILE *f) fprintf(f, "%013lld", totais_get(dec, "PLR")); } +static void gera_conjuge(struct declaracao *dec, FILE *f) +{ + fprintf(f, "29"); + fprintf(f, "%-11.11s", dec->cpf); + fprintf(f, "%-11.11s", dec->conjuge.cpf); + fprintf(f, "%013lld", dec->conjuge.base); + fprintf(f, "%013lld", dec->conjuge.imposto); + fprintf(f, "%013lld", dec->conjuge.isento); + fprintf(f, "%013lld", dec->conjuge.exclusivo); + fprintf(f, "%013lld", dec->conjuge.rendpj_exigibilidade_suspensa); + fprintf(f, "%013lld", dec->conjuge.total); + fprintf(f, "%c", dec->conjuge.entregou ? 'S' : 'N'); +} + static void gera_trailler(struct declaracao *dec, FILE *f) { int i; @@ -675,6 +689,8 @@ static int gera(struct declaracao *dec, char *filename) W(gera_bem); } + W(gera_conjuge); + /* Rendimentos isentos e com tributação exclusiva */ /* Registros 82 a 89, e 92 a 99 */ #define IW(fn, codigo) \ diff --git a/src/declara.c b/src/declara.c index 7677e22..6f6a741 100644 --- a/src/declara.c +++ b/src/declara.c @@ -27,6 +27,7 @@ #include "cmd.h" #include "base.h" #include "contribuinte.h" +#include "conjuge.h" #include "rendimento.h" #include "isento.h" #include "pagamento.h" @@ -93,6 +94,7 @@ int main(int argc, char **argv) cmd_init(); base_cmd_init(); contribuinte_cmd_init(); + conjuge_cmd_init(); rendimento_cmd_init(); isento_cmd_init(); pagamento_cmd_init(); -- 2.20.1