util.c util.h \
contribuinte.c contribuinte.h \
rendimento.c rendimento.h \
+ isento.c isento.h \
pagamento.c pagamento.h \
bem.c bem.h
#include <string.h>
#include "list.h"
#include "rendimento.h"
+#include "isento.h"
#include "pagamento.h"
#include "bem.h"
#include "pmhash.h"
dec->rendimento = list_new();
if (!dec->rendimento)
goto out_rendimento;
+ dec->isentos = list_new();
+ if (!dec->isentos)
+ goto out_isentos;
dec->pagamentos = list_new();
if (!dec->pagamentos)
goto out_pagamentos;
out_bens:
list_free(dec->pagamentos, pagamento_free);
out_pagamentos:
+ list_free(dec->isentos, isento_free);
+out_isentos:
list_free(dec->rendimento, rendimento_free);
out_rendimento:
free(dec);
if (dec->dvconta)
free(dec->dvconta);
list_free(dec->rendimento, rendimento_free);
+ list_free(dec->isentos, isento_free);
list_free(dec->pagamentos, pagamento_free);
list_free(dec->bens, bem_free);
pmhash_del(dec->totais);
char *cpf;
char *nome;
struct list *rendimento;
+ struct list *isentos;
struct list *pagamentos;
struct list *bens;
struct contribuinte contribuinte;
#include "declaracao.h"
#include "cmd.h"
#include "rendimento.h"
+#include "isento.h"
#include "pagamento.h"
#include "bem.h"
#include "totais.h"
fprintf(f, "T");
}
+static void gera_isento(struct declaracao *dec, FILE *f, int codigo)
+{
+ struct isento *i;
+ i = isento_get(dec, codigo, dec->linhas[codigo]);
+ fprintf(f, "%02d", codigo);
+ fprintf(f, "%-11.11s", dec->cpf); /* Titular, TODO: dependente */
+ fprintf(f, "%05d", dec->linhas[codigo] + 1); /* Chave */
+ fprintf(f, "%c", 'T'); /* FIXME: dependente */
+ fprintf(f, "%-14.14s", i->cnpj);
+ fprintf(f, "%-60.60s", i->nome);
+ fprintf(f, "%013lld", i->valor);
+ fprintf(f, "%-11.11s", dec->cpf);
+}
+
+static void gera_plr(struct declaracao *dec, FILE *f)
+{
+ gera_isento(dec, f, 96);
+}
+
+static void gera_poupanca(struct declaracao *dec, FILE *f)
+{
+ gera_isento(dec, f, 98);
+}
+
static void gera_bem(struct declaracao *dec, FILE *f)
{
struct bem *b;
int r;
int i;
struct rendimento *rendimento;
+ struct isento *isento;
struct pagamento *pagamento;
struct bem *bem;
for (i = 0; (bem = list_get(dec->bens, i)); i++) {
W(gera_bem, dec, f);
}
+
+ /* Rendimentos isentos e com tributação exclusiva */
+ /* Registros 82 a 89, e 92 a 99 */
+#define IW(fn, codigo) \
+ for (i = 0; ; i++) { \
+ isento = isento_get(dec, codigo, i); \
+ if (!isento) \
+ break; \
+ W(fn, dec, f); \
+ }
+ IW(gera_plr, 96);
+ IW(gera_poupanca, 98);
+
W(gera_trailler, dec, f);
W(gera_reciboheader, dec, f);
W(gera_recibodetalhe, dec, f);
W(gera_recibotrailler, dec, f);
+
fclose(f);
return 0;
out:
--- /dev/null
+/*
+ * 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 "isento.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include "cmd.h"
+#include "list.h"
+#include "util.h"
+#include "totais.h"
+
+static int isento_totais_update(struct declaracao *dec, struct isento *isento)
+{
+ int r = 0;
+ switch (isento->codigo) {
+ case 96:
+ r = totais_add(dec, "PLR", isento->valor);
+ r += totais_add(dec, "EXCLUSIVOS", isento->valor);
+ r += totais_add(dec, "EXCLUSIVOSTIT", isento->valor);
+ break;
+ case 98:
+ r = totais_add(dec, "POUPANCA", isento->valor);
+ r += totais_add(dec, "ISENTOS", isento->valor);
+ r += totais_add(dec, "ISENTOSTIT", isento->valor);
+ break;
+ }
+ return r;
+}
+
+void isento_free(void *pointer)
+{
+ struct isento *isento = pointer;
+ if (isento->cnpj)
+ free(isento->cnpj);
+ if (isento->nome)
+ free(isento->nome);
+ free(isento);
+}
+
+static int isento_cmp(void *p1, void *p2)
+{
+ struct isento *r1 = p1;
+ struct isento *r2 = p2;
+ /* O rendimento maior vem primeiro. */
+ if (r1->valor > r2->valor)
+ return -1;
+ else if (r1->valor < r2->valor)
+ return 1;
+ return 0;
+}
+
+static struct isento * isento_new(char **args)
+{
+ struct isento *isento;
+ int r = 0;
+ isento = malloc(sizeof(*isento));
+ isento->cnpj = strdup(args[2]);
+ isento->nome = strdup(args[3]);
+ /* TODO: consertar set_int para funcionar como set_llong */
+ r += set_int(args, 2, &isento->codigo);
+ r += set_llong(args[4], &isento->valor);
+ if (!isento->cnpj || !isento->nome) {
+ isento_free(isento);
+ return NULL;
+ }
+ if (r < 0 || isento->codigo < 0 ||
+ isento->valor < 0) {
+ isento_free(isento);
+ return NULL;
+ }
+ return isento;
+}
+
+static int run_isento(struct declaracao *dec, char **args, int argc)
+{
+ struct isento *isento;
+ int r;
+ if (argc != 5)
+ return -EINVAL;
+ isento = isento_new(args);
+ if (!isento)
+ return -ENOMEM;
+ r = list_insert_ordered(&dec->isentos, isento, isento_cmp);
+ if (r < 0) {
+ isento_free(isento);
+ return r;
+ }
+ r = isento_totais_update(dec, isento);
+ if (r) {
+ isento_free(isento);
+ return r;
+ }
+ return 0;
+}
+
+void isento_salva(struct declaracao *dec, FILE *f)
+{
+ int i;
+ struct isento *j;
+ for (i = 0; j = list_get(dec->isentos, i); i++)
+ fprintf(f, "isento %d \"%s\" \"%s\" %lld\n",
+ j->codigo, j->cnpj, j->nome, j->valor);
+}
+
+static struct cmd cmd_isento = {
+ .name = "isento",
+ .run = run_isento,
+};
+
+int isento_cmd_init(void)
+{
+ cmd_add(&cmd_isento);
+ return 0;
+}
+
+struct isento * isento_get(struct declaracao *dec, int codigo, int n)
+{
+ struct isento *isento;
+ int i;
+ int j = 0;
+ for (i = 0; (isento = list_get(dec->isentos, i)); i++) {
+ if (isento->codigo == codigo && j++ == n)
+ break;
+ }
+ return isento;
+}
--- /dev/null
+/*
+ * 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 _ISENTO_H
+#define _ISENTO_H
+
+#include <stdio.h>
+#include "declaracao.h"
+
+struct isento {
+ int codigo;
+ char *cnpj;
+ char *nome;
+ long long valor;
+};
+
+void isento_salva(struct declaracao *dec, FILE *f);
+void isento_free(void *pointer);
+
+int isento_cmd_init(void);
+
+struct isento * isento_get(struct declaracao *dec, int codigo, int n);
+
+#endif
#include "base.h"
#include "contribuinte.h"
#include "rendimento.h"
+#include "isento.h"
#include "pagamento.h"
#include "calcula.h"
#include "gera.h"
base_cmd_init();
contribuinte_cmd_init();
rendimento_cmd_init();
+ isento_cmd_init();
pagamento_cmd_init();
bem_cmd_init();
calcula_cmd_init();