Definição de pmhash_new não estava declarada.
[cascardo/declara.git] / calcula.c
index 80f6c6d..44a3bf9 100644 (file)
--- a/calcula.c
+++ b/calcula.c
  */
 
 #include "calcula.h"
+#include <errno.h>
+#include <stdio.h>
 #include "declaracao.h"
 #include "cmd.h"
 #include "rendimento.h"
-#include <errno.h>
-#include <stdio.h>
-
-static void total_rendimento(struct declaracao *dec)
-{
-       long long tr = 0;
-       struct rendimento *rendimento;
-       int i;
-       for (i = 0; rendimento = list_get(dec->rendimento, i); i++) {
-               tr += rendimento->rendimento;
-       }
-       dec->totalrendimento = tr;
-}
+#include "totais.h"
 
 static long long total_deducao(struct declaracao *dec)
 {
@@ -88,8 +78,7 @@ static long long imposto_simples(struct declaracao *dec)
        struct taxtable *tt;
        long long tr, td;
        tt = table2015;
-       tr = dec->totalrendimento;
-       dec->totalrendimento = tr;
+       tr = totais_get(dec, "RENDPJ");
        if (tr / 5 < simples2015)
                td = tr / 5;
        else
@@ -106,7 +95,7 @@ static long long imposto_completa(struct declaracao *dec)
                return -EINVAL;
        }
        tt = table2015;
-       tr = dec->totalrendimento;
+       tr = totais_get(dec, "RENDPJ");
        td = total_deducao(dec);
        tr -= td;
        return imposto(tt, tr);
@@ -118,8 +107,7 @@ int calcula(struct declaracao *dec)
        if (dec->ano != 2015) {
                return -EINVAL;
        }
-       total_rendimento(dec);
-       if (dec->totalrendimento > obrigatoriedade2015)
+       if (totais_get(dec, "RENDPJ") > obrigatoriedade2015)
                dec->obrigatoria = 1;
        i_simples = imposto_simples(dec);
        i_completa = imposto_completa(dec);