Gera outros totais de declaração simplificada.
[cascardo/declara.git] / declaracao.c
index 2731222..53ff1e4 100644 (file)
@@ -21,6 +21,8 @@
 #include <string.h>
 #include "list.h"
 #include "rendimento.h"
+#include "pagamento.h"
+#include "pmhash.h"
 
 struct declaracao * declaracao_new(int ano)
 {
@@ -31,16 +33,26 @@ struct declaracao * declaracao_new(int ano)
        memset(dec, 0, sizeof(*dec));
        dec->ano = ano;
        dec->rendimento = list_new();
-       if (!dec->rendimento) {
-               free(dec);
-               return NULL;
-       }
-       dec->totalrendimento = 0;
+       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)
@@ -51,6 +63,18 @@ void declaracao_free(struct declaracao *dec)
                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);
 }