Suporta indenizações isentas, como FGTS e aviso prévio.
[cascardo/declara.git] / lib / isento.c
index c655f48..8bab86c 100644 (file)
@@ -31,15 +31,50 @@ static int isento_totais_update(struct declaracao *dec, struct isento *isento)
 {
        int r = 0;
        switch (isento->codigo) {
+       case 82:
+               r = totais_add(dec, "DOACOES", isento->valor);
+               r += totais_add(dec, "ISENTOS", isento->valor);
+               if (isento->dependente) {
+                       r += totais_add(dec, "ISENTOSDEP", isento->valor);
+               } else {
+                       r += totais_add(dec, "ISENTOSTIT", isento->valor);
+               }
+               break;
+       case 93:
+               r = totais_add(dec, "INDENIZACOES", isento->valor);
+               r += totais_add(dec, "ISENTOS", isento->valor);
+               if (isento->dependente) {
+                       r += totais_add(dec, "ISENTOSDEP", isento->valor);
+               } else {
+                       r += totais_add(dec, "ISENTOSTIT", isento->valor);
+               }
+               break;
        case 96:
                r = totais_add(dec, "PLR", isento->valor);
                r += totais_add(dec, "EXCLUSIVOS", isento->valor);
-               r += totais_add(dec, "EXCLUSIVOSTIT", isento->valor);
+               if (isento->dependente) {
+                       r += totais_add(dec, "EXCLUSIVOSDEP", isento->valor);
+               } else {
+                       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);
+               if (isento->dependente) {
+                       r += totais_add(dec, "ISENTOSDEP", isento->valor);
+               } else {
+                       r += totais_add(dec, "ISENTOSTIT", isento->valor);
+               }
+               break;
+       case 99:
+               r = totais_add(dec, "APLICACOES", isento->valor);
+               r += totais_add(dec, "EXCLUSIVOS", isento->valor);
+               if (isento->dependente) {
+                       r += totais_add(dec, "EXCLUSIVOSDEP", isento->valor);
+               } else {
+                       r += totais_add(dec, "EXCLUSIVOSTIT", isento->valor);
+               }
                break;
        }
        return r;
@@ -67,7 +102,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;
@@ -86,6 +121,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;
 }
 
@@ -93,11 +137,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);
@@ -116,8 +164,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 = {