Adiciona suporte a cônjuge.
authorThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Sun, 6 Sep 2015 03:32:23 +0000 (00:32 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Mon, 7 Sep 2015 22:02:44 +0000 (19:02 -0300)
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
lib/conjuge.c [new file with mode: 0644]
lib/conjuge.h [new file with mode: 0644]
lib/declaracao.c
lib/declaracao.h
lib/gera.c
src/declara.c

index f0fc33a..542c585 100644 (file)
@@ -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 (file)
index 0000000..a0631b2
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ *  Copyright (C) 2015  Thadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
+ *
+ *  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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#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 (file)
index 0000000..72ec340
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ *  Copyright (C) 2015  Thadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
+ *
+ *  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 <stdio.h>
+
+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
index b1cfb55..7eef34c 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <string.h>
 #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);
 }
index be91d96..eaff855 100644 (file)
@@ -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;
index e16f49c..3ae5e3d 100644 (file)
@@ -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) \
index 7677e22..6f6a741 100644 (file)
@@ -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();