From: Thadeu Lima de Souza Cascardo Date: Sun, 10 Apr 2016 15:32:51 +0000 (-0300) Subject: Suporta rendimentos isentos e exclusivos de dependentes. X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fdeclara.git;a=commitdiff_plain;h=fd1f6192290c7f2f3b8d0e136776c3aa0a9d0a16 Suporta rendimentos isentos e exclusivos de dependentes. Da mesma forma como implementado para pagamentos, os rendimentos isentos e exclusivos de dependentes são indicados através de um índice de dependentes. --- diff --git a/lib/gera.c b/lib/gera.c index 69c4311..2d02d26 100644 --- a/lib/gera.c +++ b/lib/gera.c @@ -675,13 +675,20 @@ 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, "%-11.11s", dec->cpf); /* Titular */ fprintf(f, "%05d", dec->linhas[codigo] + 1); /* Chave */ - fprintf(f, "%c", 'T'); /* FIXME: dependente */ + /* Titular (T), Dependente (D), Alimentando (A), FIXME Alimentando */ + fprintf(f, "%c", i->dependente ? 'D' : 'T'); fprintf(f, "%-14.14s", i->cnpj); fprintf(f, "%-60.60s", i->nome); fprintf(f, "%013lld", i->valor); - fprintf(f, "%-11.11s", dec->cpf); + if (i->dependente) { + struct dependente *d; + d = list_get(dec->dependentes, i->dependente - 1); + fprintf(f, "%-11.11s", d ? d->cpf : ""); + } else { + fprintf(f, "%-11.11s", dec->cpf); + } } static void gera_doacao(struct declaracao *dec, FILE *f) diff --git a/lib/isento.c b/lib/isento.c index f078804..4e7540e 100644 --- a/lib/isento.c +++ b/lib/isento.c @@ -77,7 +77,7 @@ static int isento_cmp(void *p1, void *p2) return 0; } -static struct isento * isento_new(char **args) +static struct isento * isento_new(char **args, int argc) { struct isento *isento; int r = 0; @@ -96,6 +96,15 @@ static struct isento * isento_new(char **args) isento_free(isento); return NULL; } + if (argc == 6) { + r = set_int(&args[4], 2, &isento->dependente); + } else { + isento->dependente = 0; + } + if (r < 0 || isento->dependente < 0) { + isento_free(isento); + return NULL; + } return isento; } @@ -103,11 +112,15 @@ static int run_isento(struct declaracao *dec, char **args, int argc) { struct isento *isento; int r; - if (argc != 5) + if (argc != 5 && argc != 6) return -EINVAL; - isento = isento_new(args); + isento = isento_new(args, argc); if (!isento) return -ENOMEM; + if (isento->dependente > list_size(dec->dependentes)) { + isento_free(isento); + return -EINVAL; + } r = list_insert_ordered(&dec->isentos, isento, isento_cmp); if (r < 0) { isento_free(isento); @@ -126,8 +139,8 @@ 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); + fprintf(f, "isento %d \"%s\" \"%s\" %lld %d\n", + j->codigo, j->cnpj, j->nome, j->valor, j->dependente); } static struct cmd cmd_isento = { diff --git a/lib/isento.h b/lib/isento.h index 32897ac..0cecf21 100644 --- a/lib/isento.h +++ b/lib/isento.h @@ -27,6 +27,7 @@ struct isento { char *cnpj; char *nome; long long valor; + int dependente; }; void isento_salva(struct declaracao *dec, FILE *f);