Mudanças no cálculo das deduções.
[cascardo/declara.git] / lib / calcula.c
index 8507a50..d222f96 100644 (file)
@@ -28,6 +28,7 @@
 
 static const long long dependente[ANO(MAX_ANOS)] = {
        [ANO(2015)] = 215652,
+       [ANO(2016)] = 227508,
 };
 
 long long deducao_dependente(struct declaracao *dec)
@@ -52,8 +53,8 @@ static long long total_deducao(struct declaracao *dec)
        }
        return totais_get(dec, "DEPENDENTES") +
               totais_get(dec, "INSS") +
-              totais_get(dec, "PAGAMENTOS") -
-              totais_get(dec, "REEMBOLSOS");
+              totais_get(dec, "MEDICAS") +
+              totais_get(dec, "PREVIDENCIA");
 }
 
 static void total_pago(struct declaracao *dec)
@@ -86,16 +87,28 @@ static struct taxtable table2015[] = {
        { 9999999999999LL, 0, 0, },
 };
 
+static struct taxtable table2016[] = {
+       {       0,    0,       0, },
+       { 2249914,  750,  168743, },
+       { 3347773, 1500,  419826, },
+       { 4447675, 2250,  753402, },
+       { 5537355, 2750, 1030270, },
+       { 9999999999999LL, 0, 0, },
+};
+
 static struct taxtable *table[ANO(MAX_ANOS)] = {
        [ANO(2015)] = table2015,
+       [ANO(2016)] = table2016,
 };
 
 static const long long simples[ANO(MAX_ANOS)] = {
        [ANO(2015)] = 1588089,
+       [ANO(2016)] = 1675434,
 };
 
 static const long long obrigatoriedade[ANO(MAX_ANOS)] = {
        [ANO(2015)] = 2681655,
+       [ANO(2016)] = 2812391,
 };
 
 static long long imposto(struct taxtable *tt, long long tr, int verbose)
@@ -122,6 +135,8 @@ static long long imposto_simples(struct declaracao *dec)
                td = simples[ANO(dec->ano)];
        totais_add(dec, "DESCONTO", td);
        tr -= td;
+       if (tr < 0)
+               tr = 0;
        totais_add(dec, "BASESIMPLES", tr);
        if (dec->verbose) {
                printf("Desconto simplificado é "FMT_R"\n", R(td));
@@ -138,6 +153,8 @@ static long long imposto_completa(struct declaracao *dec)
        td = total_deducao(dec);
        totais_add(dec, "DEDUCOES", td);
        tr -= td;
+       if (tr < 0)
+               tr = 0;
        totais_add(dec, "BASECOMPLETA", tr);
        if (dec->verbose) {
                printf("Desconto completa é "FMT_R"\n", R(td));