gera: imprime espaços quando recibo é nulo
[cascardo/declara.git] / declaracao.c
index eb3c81f..53ff1e4 100644 (file)
 #include "declaracao.h"
 #include <stdlib.h>
 #include <string.h>
+#include "list.h"
+#include "rendimento.h"
+#include "pagamento.h"
+#include "pmhash.h"
 
 struct declaracao * declaracao_new(int ano)
 {
@@ -28,7 +32,27 @@ struct declaracao * declaracao_new(int ano)
                return NULL;
        memset(dec, 0, sizeof(*dec));
        dec->ano = ano;
+       dec->rendimento = list_new();
+       if (!dec->rendimento)
+               goto out_rendimento;
+       dec->pagamentos = list_new();
+       if (!dec->pagamentos)
+               goto out_pagamentos;
+       dec->totais = pmhash_new();
+       if (!dec->totais)
+               goto out_totais;
+       dec->pago = 0;
+       dec->devido = 0;
+       dec->restituicao = 0;
+       dec->tipo = SIMPLES;
        return dec;
+out_totais:
+       list_free(dec->pagamentos, pagamento_free);
+out_pagamentos:
+       list_free(dec->rendimento, rendimento_free);
+out_rendimento:
+       free(dec);
+       return NULL;
 }
 
 void declaracao_free(struct declaracao *dec)
@@ -37,5 +61,20 @@ void declaracao_free(struct declaracao *dec)
                free(dec->cpf);
        if (dec->nome)
                free(dec->nome);
+       if (dec->recibo)
+               free(dec->recibo);
+       if (dec->retifica)
+               free(dec->retifica);
+       if (dec->banco)
+               free(dec->banco);
+       if (dec->agencia)
+               free(dec->agencia);
+       if (dec->contacorrente)
+               free(dec->contacorrente);
+       if (dec->dvconta)
+               free(dec->dvconta);
+       list_free(dec->rendimento, rendimento_free);
+       list_free(dec->pagamentos, pagamento_free);
+       pmhash_del(dec->totais);
        free(dec);
 }