Calcula e gera desconto simplificado e base de cálculo.
[cascardo/declara.git] / gera.c
diff --git a/gera.c b/gera.c
index 76529fa..ce8c432 100644 (file)
--- a/gera.c
+++ b/gera.c
@@ -111,11 +111,16 @@ static void gera_header(struct declaracao *dec, FILE *f)
        fprintf(f, "%-11.11s", ""); /* CPF procurador */
        fprintf(f, "%03d", dec->obrigatoria); /* criterio obrigatoriedade */
        fprintf(f, "%013lld", totais_get(dec, "RENDPJ")); /* Total tributavel */
-       fprintf(f, "%-14.14s", ""); /* TODO: CNPJ previdencia */
-       fprintf(f, "%-14.14s", ""); /* TODO: CNPJ previdencia 2 */
-       fprintf(f, "%013lld", 0); /* TODO: Total isentos */
-       fprintf(f, "%013lld", 0); /* TODO: Total exclusivo */
-       fprintf(f, "%013lld", 0); /* TODO: Total pagamentos */
+       /* CNPJ previdencia */
+       fprintf(f, "%-14.14s", pagamento_cnpj_ordenado(dec, 36, 0));
+       /* CNPJ previdencia 2 */
+       fprintf(f, "%-14.14s", pagamento_cnpj_ordenado(dec, 36, 1));
+       /* Total isentos */
+       fprintf(f, "%013lld", totais_get(dec, "ISENTOS"));
+       /* Total exclusivo */
+       fprintf(f, "%013lld", totais_get(dec, "EXCLUSIVOS"));
+       /* Total pagamentos */
+       fprintf(f, "%013lld", totais_get(dec, "PAGAMENTOS"));
        fprintf(f, "%-13.13s", dec->contacorrente); /* numero conta */
        fprintf(f, "%-2.2s", dec->dvconta); /* DV conta */
        fprintf(f, "0"); /* TODO: revalidar DV conta */
@@ -186,8 +191,9 @@ static void gera_contribuinte(struct declaracao *dec, FILE *f)
        fprintf(f, "%-2.2s", dec->dvconta); /* DV conta */
        fprintf(f, "N"); /* TODO: débito automático */
        fprintf(f, "0"); /* TODO: débito primeira quota */
-       fprintf(f, "%-14.14s", ""); /* TODO: CNPJ principal fonte */
-       fprintf(f, "%-10.10s", dec->recibo); /* Recibo última declaração ano anterior */
+       /* CNPJ principal fonte */
+       fprintf(f, "%-14.14s", rendimento_cnpj_ordenado(dec, 0));
+       fprintf(f, "%-10.10s", dec->recibo ?: ""); /* Recibo última declaração ano anterior */
        fprintf(f, "A"); /* Declaração de Ajuste */
        fprintf(f, "%-11.11s", ""); /* TODO: CPF procurador */
        fprintf(f, "%-10.10s", "0000000000"); /* FIXME: controle */
@@ -200,10 +206,13 @@ static void gera_simples(struct declaracao *dec, FILE *f)
        fprintf(f, "%s", dec->cpf); /* CPF: 11 dígitos */
        fprintf(f, "%013lld", 0); /* TODO: carnê leão */
        fprintf(f, "%013lld", 0); /* TODO: lucros e dividendos */
-       fprintf(f, "%013lld", 0); /* TODO: isentos */
-       fprintf(f, "%013lld", 0); /* TODO: rendimentos tributação exclusiva */
-       fprintf(f, "%013lld", 0); /* TODO: 13o. */
-       fprintf(f, "%013lld", dec->retido); /* retido na fonte */
+       /* rendimentos isentos */
+       fprintf(f, "%013lld", totais_get(dec, "ISENTOS"));
+       /* rendimentos tributação exclusiva, exceto décimo terceiro */
+       fprintf(f, "%013lld", totais_get(dec, "EXCLUSIVOS_SEM_13o"));
+       /* 13o. */
+       fprintf(f, "%013lld", totais_get(dec, "DECIMOTERCEIRO"));
+       fprintf(f, "%013lld", 0); /* TODO: retido na fonte (Lei 11.033) */
        fprintf(f, "%013lld", 0); /* TODO: 13o. dependentes */
        fprintf(f, "%013lld", 0); /* TODO: lucros dependentes */
        fprintf(f, "%013lld", 0); /* TODO: isentos dependentes */
@@ -217,10 +226,10 @@ static void gera_simples(struct declaracao *dec, FILE *f)
        fprintf(f, "%013lld", 0); /* TODO: carnê-leão PF? */
        fprintf(f, "%013lld", 0); /* TODO: carnê-leão dependentes */
        fprintf(f, "%013lld", 0); /* TODO: dedução dependentes */
-       fprintf(f, "%013lld", 0); /* TODO: previdência */
-       fprintf(f, "%013lld", 0); /* TODO: previdência dependentes */
-       fprintf(f, "%013lld", 0); /* TODO: pensão */
-       fprintf(f, "%013lld", 0); /* TODO: pensão dependentes */
+       fprintf(f, "%013lld", 0); /* TODO: previdência RRA */
+       fprintf(f, "%013lld", 0); /* TODO: previdência RRA dependentes */
+       fprintf(f, "%013lld", 0); /* TODO: pensão RRA */
+       fprintf(f, "%013lld", 0); /* TODO: pensão RRA dependentes */
        fprintf(f, "%013lld", 0); /* TODO: imposto pago exterior */
        fprintf(f, "%013lld", 0); /* TODO: imposto devido sem rendimento exterior */
        fprintf(f, "%013lld", 0); /* TODO: limite imposto pago exterior */
@@ -233,8 +242,10 @@ static void gera_totais_simples(struct declaracao *dec, FILE *f)
        fprintf(f, "18");
        fprintf(f, "%s", dec->cpf); /* CPF: 11 dígitos */
        fprintf(f, "%013lld", totais_get(dec, "RENDPJ")); /* TODO: rendimentos tributáveis */
-       fprintf(f, "%013lld", 0); /* TODO: desconto simplificado */
-       fprintf(f, "%013lld", 0); /* TODO: base cálculo */
+       /* desconto simplificado */
+       fprintf(f, "%013lld", totais_get(dec, "DESCONTO"));
+        /* base de cálculo */
+       fprintf(f, "%013lld", totais_get(dec, "BASE"));
        fprintf(f, "%013lld", dec->devido); /* imposto devido */
        fprintf(f, "%013lld", dec->retido); /* imposto retido */
        fprintf(f, "%013lld", 0); /* TODO: imposto complementar */