--- /dev/null
+/*
+ * Copyright (C) 2015 Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
+ *
+ * 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 "gera.h"
+#include "declaracao.h"
+#include "cmd.h"
+#include "rendimento.h"
+#include <errno.h>
+#include <stdio.h>
+
+static int gera_header(struct declaracao *dec, FILE *f)
+{
+ fprintf(f, "IRPF ");
+ fprintf(f, "%04d", dec->ano); /* Exercício */
+ fprintf(f, "%04d", dec->ano - 1); /* Ano base */
+ fprintf(f, "2500"); /* Código */
+ fprintf(f, "%s", dec->retifica ? "1" : "0"); /* Retificadora */
+ fprintf(f, "%s", dec->cpf); /* CPF: 11 dígitos */
+ fprintf(f, " "); /* Filler */
+ fprintf(f, "1"); /* Tipo NI: Pessoa Física (1) */
+ fprintf(f, "100"); /* Versão IRPF */
+ fprintf(f, "%-60.60s", dec->nome);
+ fprintf(f, "%s", dec->contribuinte.uf);
+ fprintf(f, "%s", "0000000000"); /* FIXME: hash */
+ fprintf(f, "1"); /* TODO: certificavel */
+ fprintf(f, "%s", dec->contribuinte.dn);
+ fprintf(f, "%s", dec->tipo == COMPLETA ? "S" : "N");
+ fprintf(f, "0"); /* TODO: resultado imposto */
+ fprintf(f, "S"); /* TODO: gerada? */
+ fprintf(f, "%-10.10s", dec->retifica ?: ""); /* recibo retificada ex. atual */
+ fprintf(f, "2"); /* TODO: PGD */
+ fprintf(f, "LINUX "); /* TODO: SO */
+ fprintf(f, "3.16.0-"); /* TODO: versao SO */
+ fprintf(f, "1.7.0_75 "); /* TODO: versao JVM */
+ fprintf(f, "%-10.10s", dec->retifica ? : ""); /* TODO: recibo da última declaração transmitida (recibo ou retifica?) */
+ fprintf(f, "%04d", dec->contribuinte.cd_municipio);
+ fprintf(f, " "); /* TODO: CPF conjuge */
+ fprintf(f, "0"); /* TODO: obrigatoria entrega */
+ fprintf(f, "0000000000000"); /* TODO: imposto devido, carne-leao, complementar dos dependentes */
+ fprintf(f, "%-10.10s", dec->recibo); /* recibo ex. anterior */
+ fprintf(f, "2"); /* TODO: indicador seguranca */
+ fprintf(f, "00"); /* TODO: indicador imposto pago */
+ fprintf(f, "0"); /* TODO: indicador imposto antecipado */
+ fprintf(f, "0"); /* TODO: mudanca endereco */
+ fprintf(f, "%s", dec->contribuinte.cep);
+ fprintf(f, "0"); /* TODO: debito 1a quota */
+ fprintf(f, "000"); /* TODO: no banco */
+ fprintf(f, "0000"); /* TODO: agencia */
+ fprintf(f, " "); /* TODO: filler */
+ fprintf(f, "00000000"); /* transito julgado, gravado apenas se espolio */
+ fprintf(f, "0000000000000"); /* TODO: imposto a pagar */
+ fprintf(f, " "); /* RRA1 */
+ fprintf(f, "%-11.11s", ""); /* CPF RRA1 */
+ fprintf(f, " "); /* RRA2 */
+ fprintf(f, "%-11.11s", ""); /* CPF RRA2 */
+ fprintf(f, " "); /* RRA3 */
+ fprintf(f, "%-11.11s", ""); /* CPF RRA3 */
+ fprintf(f, " "); /* RRA4 */
+ fprintf(f, "%-11.11s", ""); /* CPF RRA4 */
+ fprintf(f, "0000000000000"); /* TODO: Doacao ECA */
+ fprintf(f, "%-14.14s", ""); /* TODO: CNPJ maior */
+ fprintf(f, "%-14.14s", ""); /* TODO: CNPJ maior 2 */
+ fprintf(f, "%-14.14s", ""); /* TODO: CNPJ maior 3 */
+ fprintf(f, "%-14.14s", ""); /* TODO: CNPJ maior 4 */
+ fprintf(f, "%-11.11s", ""); /* CPF Dependente 1 */
+ fprintf(f, "%-8.8s", ""); /* DN Dependente 1 */
+ fprintf(f, "%-11.11s", ""); /* CPF Dependente 2 */
+ fprintf(f, "%-8.8s", ""); /* DN Dependente 2 */
+ fprintf(f, "%-11.11s", ""); /* CPF Dependente 3 */
+ fprintf(f, "%-8.8s", ""); /* DN Dependente 3 */
+ fprintf(f, "%-11.11s", ""); /* CPF Dependente 4 */
+ fprintf(f, "%-8.8s", ""); /* DN Dependente 4 */
+ fprintf(f, "%-11.11s", ""); /* CPF Dependente 5 */
+ fprintf(f, "%-8.8s", ""); /* DN Dependente 5 */
+ fprintf(f, "%-11.11s", ""); /* CPF Dependente 6 */
+ fprintf(f, "%-8.8s", ""); /* DN Dependente 6 */
+ fprintf(f, "%-14.14s", ""); /* TODO: medico maior */
+ fprintf(f, "%-14.14s", ""); /* TODO: medico maior 2 */
+ fprintf(f, "%-11.11s", ""); /* CPF pensao */
+ fprintf(f, "%-11.11s", ""); /* CPF inventariante */
+ fprintf(f, "%-40.40s", dec->contribuinte.municipio);
+ fprintf(f, "%-60.60s", dec->nome);
+ fprintf(f, "%-11.11s", ""); /* CPF empregada */
+ fprintf(f, "000000000000"); /* FIXME: MAC */
+ fprintf(f, "%08d", 0); /* Data saída */
+ fprintf(f, "%-11.11s", ""); /* CPF procurador */
+ fprintf(f, "000"); /* TODO: criterio obrigatoriedade */
+ fprintf(f, "%013lld", dec->totalrendimento); /* 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 */
+ fprintf(f, "%-13.13s", ""); /* TODO: numero conta */
+ fprintf(f, "%-2.2s", ""); /* TODO: DV conta */
+ fprintf(f, "0"); /* TODO: revalidar DV conta */
+
+ /* Mudanças de 2015 */
+
+ fprintf(f, "%02d", dec->contribuinte.natureza_ocupacao); /* TODO: natureza ocupacao */
+ fprintf(f, "%-11.11s", ""); /* CPF domestica */
+ fprintf(f, "%-11.11s", ""); /* NI domestica */
+ fprintf(f, "%-11.11s", ""); /* CPF domestica 2 */
+ fprintf(f, "%-11.11s", ""); /* NI domestica 2 */
+ fprintf(f, "%-11.11s", ""); /* CPF domestica 3 */
+ fprintf(f, "%-11.11s", ""); /* NI domestica 3 */
+ fprintf(f, "1"); /* Declaracao iniciada */
+ fprintf(f, "1"); /* Utilizou PGD */
+ fprintf(f, "0"); /* Utilizou APP */
+ fprintf(f, "0"); /* Utilizou online */
+ fprintf(f, "0"); /* Utilizou rascunho */
+ fprintf(f, "0"); /* Utilizou pre preenchida */
+ fprintf(f, "0"); /* Utilizou fontes */
+ fprintf(f, "0"); /* Utilizou plano saude */
+ fprintf(f, "0"); /* Utilizou recuperar */
+ fprintf(f, "1"); /* Declaracao iniciada */
+
+ /* Fim das mudanças de 2015 */
+
+ fprintf(f, " "); /* Teste PGD, FILLER2 */
+ fprintf(f, "0000000000"); /* FIXME: controle */
+ fprintf(f, "\r\n");
+}
+
+static int gera_contribuinte(struct declaracao *dec, FILE *f)
+{
+ fprintf(f, "16");
+ fprintf(f, "%s", dec->cpf);
+ fprintf(f, "%-60.60s", dec->nome);
+ fprintf(f, "%-15.15s", dec->contribuinte.tipo_logradouro);
+ fprintf(f, "%-40.40s", dec->contribuinte.logradouro);
+ fprintf(f, "%-6.6s", dec->contribuinte.numero);
+ fprintf(f, "%-21.21s", dec->contribuinte.complemento);
+ fprintf(f, "%-19.19s", dec->contribuinte.bairro);
+ fprintf(f, "%-9.9s", dec->contribuinte.cep);
+ fprintf(f, "%04d", dec->contribuinte.cd_municipio);
+ fprintf(f, "%-40.40s", dec->contribuinte.municipio);
+ fprintf(f, "%-2.2s", dec->contribuinte.uf);
+ fprintf(f, " "); /* TODO: código exterior */
+ fprintf(f, "105"); /* TODO: código país */
+ fprintf(f, "%-100.100s", ""); /* TODO: FILLER3 */
+ fprintf(f, "%-4.4s", ""); /* TODO: FILLER1 */
+ fprintf(f, "%-8.8s", ""); /* TODO: FILLER2 */
+ fprintf(f, "%-4.4s", dec->contribuinte.ddd);
+ fprintf(f, "%-9.9s", dec->contribuinte.telefone);
+ fprintf(f, "%-8.8s", dec->contribuinte.dn);
+ fprintf(f, "%-13.13s", dec->contribuinte.titulo_eleitor);
+ fprintf(f, "%03d", dec->contribuinte.ocupacao_principal);
+ fprintf(f, "%02d", dec->contribuinte.natureza_ocupacao);
+ fprintf(f, "0"); /* TODO: qnt quotas */
+ fprintf(f, "%s", dec->tipo == COMPLETA ? "S" : "N");
+ fprintf(f, "%s", dec->retifica ? "S" : "N");
+ fprintf(f, "S"); /* GERADO */
+ fprintf(f, "N"); /* TODO: mudança de endereço */
+ fprintf(f, "%-12.12s", dec->retifica ? : ""); /* Recibo declaração original */
+ fprintf(f, "%-3.3s", "000"); /* TODO: banco */
+ fprintf(f, "%-4.4s", "0000"); /* TODO: agência */
+ fprintf(f, "N"); /* TODO: deficiência */
+ fprintf(f, "0"); /* FILLER: pré-preenchida */
+ fprintf(f, "%-13.13s", ""); /* TODO: conta */
+ fprintf(f, "%-2.2s", ""); /* TODO: 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 */
+ fprintf(f, "A"); /* Declaração de Ajuste */
+ fprintf(f, "%-11.11s", ""); /* TODO: CPF procurador */
+ fprintf(f, "%-10.10s", "0000000000"); /* FIXME: controle */
+ fprintf(f, "\r\n");
+}
+
+static int gera(struct declaracao *dec, char *filename)
+{
+ FILE *f;
+ f = fopen(filename, "w");
+ if (!f)
+ return -errno;
+ gera_header(dec, f);
+ gera_contribuinte(dec, f);
+ fclose(f);
+ return 0;
+}
+
+static int run_gera(struct declaracao *dec, char **args, int argc)
+{
+ if (argc != 2)
+ return -EINVAL;
+ return gera(dec, args[1]);
+}
+
+static struct cmd cmd_gera = {
+ .name = "gera",
+ .run = run_gera,
+};
+
+int gera_cmd_init(void)
+{
+ cmd_add(&cmd_gera);
+ return 0;
+}