#include <errno.h>
#include <stdio.h>
-static long long total_rendimento(struct declaracao *dec)
+static void total_rendimento(struct declaracao *dec)
{
long long tr = 0;
struct rendimento *rendimento;
for (i = 0; rendimento = list_get(dec->rendimento, i); i++) {
tr += rendimento->rendimento;
}
- return tr;
+ dec->totalrendimento = tr;
}
static long long total_deducao(struct declaracao *dec)
return td;
}
-static long long total_pago(struct declaracao *dec)
+static void total_pago(struct declaracao *dec)
{
- long long tt = 0;
struct rendimento *rendimento;
int i;
+ dec->pago = dec->retido = 0;
for (i = 0; rendimento = list_get(dec->rendimento, i); i++) {
- tt += rendimento->imposto;
+ dec->pago += rendimento->imposto;
+ dec->retido += rendimento->imposto;
}
- return tt;
}
struct taxtable {
{
struct taxtable *tt;
long long tr, td;
- if (dec->ano != 2015) {
- return -EINVAL;
- }
tt = table2015;
- tr = total_rendimento(dec);
+ tr = dec->totalrendimento;
+ dec->totalrendimento = tr;
if (tr / 5 < simples2015)
td = tr / 5;
else
return -EINVAL;
}
tt = table2015;
- tr = total_rendimento(dec);
+ tr = dec->totalrendimento;
td = total_deducao(dec);
tr -= td;
return imposto(tt, tr);
}
-void calcula(struct declaracao *dec)
+int calcula(struct declaracao *dec)
{
long long i_simples, i_completa;
+ if (dec->ano != 2015) {
+ return -EINVAL;
+ }
+ total_rendimento(dec);
i_simples = imposto_simples(dec);
i_completa = imposto_completa(dec);
- dec->pago = total_pago(dec);
+ total_pago(dec);
if (i_simples > i_completa) {
dec->tipo = COMPLETA;
dec->devido = i_completa;
dec->tipo = SIMPLES;
dec->devido = i_simples;
}
- dec->restituicao = dec->pago - dec->devido;
+ if (dec->pago > dec->devido)
+ dec->restituicao = dec->pago - dec->devido;
+ else
+ dec->pagar = dec->devido - dec->pago;
+ return 0;
}
static int run_calcula(struct declaracao *dec, char **args, int argc)
{
- calcula(dec);
- return 0;
+ return calcula(dec);
}
static struct cmd cmd_calcula = {