Com esta opção, alguns resultados intermediários são exibidos,
permitindo verificações e detecção de erros.
+static int run_verbose(struct declaracao *dec, char **args, int argc)
+{
+ if (argc != 1)
+ return -EINVAL;
+ dec->verbose = 1;
+ return 0;
+}
+
static void salva(struct declaracao *dec, FILE *f)
{
fprintf(f, "ano %d\n", dec->ano);
static void salva(struct declaracao *dec, FILE *f)
{
fprintf(f, "ano %d\n", dec->ano);
+static struct cmd cmd_verbose = {
+ .name = "verbose",
+ .run = run_verbose,
+};
+
static struct cmd cmd_simples = {
.name = "simples",
.run = run_simples,
static struct cmd cmd_simples = {
.name = "simples",
.run = run_simples,
cmd_add(&cmd_contacorrente);
cmd_add(&cmd_dvconta);
cmd_add(&cmd_contacorrente);
cmd_add(&cmd_dvconta);
cmd_add(&cmd_simples);
cmd_add(&cmd_completa);
cmd_add(&cmd_simples);
cmd_add(&cmd_completa);
#include "cmd.h"
#include "rendimento.h"
#include "totais.h"
#include "cmd.h"
#include "rendimento.h"
#include "totais.h"
static const long long dependente2015 = 215652;
static const long long dependente2015 = 215652;
static long long total_deducao(struct declaracao *dec)
{
int i;
static long long total_deducao(struct declaracao *dec)
{
int i;
+ if (dec->verbose) {
+ printf("Dedução:\n");
+ printf("\tDependentes: "FMT_R"\n", R(totais_get(dec, "DEPENDENTES")));
+ printf("\tINSS: "FMT_R"\n", R(totais_get(dec, "INSS")));
+ printf("\tPagamentos: "FMT_R"\n", R(totais_get(dec, "PAGAMENTOS")));
+ printf("\tReembolsos: -"FMT_R"\n", R(totais_get(dec, "REEMBOLSOS")));
+ }
return totais_get(dec, "DEPENDENTES") +
totais_get(dec, "INSS") +
totais_get(dec, "PAGAMENTOS") -
return totais_get(dec, "DEPENDENTES") +
totais_get(dec, "INSS") +
totais_get(dec, "PAGAMENTOS") -
dec->pago += rendimento->imposto;
dec->retido += rendimento->imposto;
}
dec->pago += rendimento->imposto;
dec->retido += rendimento->imposto;
}
+ if (dec->verbose) {
+ printf("Total pago e retido: "FMT_R" "FMT_R"\n",
+ R(dec->pago), R(dec->retido));
+ }
static const long long obrigatoriedade2015 = 2681655;
static const long long obrigatoriedade2015 = 2681655;
-static long long imposto(struct taxtable *tt, long long tr)
+static long long imposto(struct taxtable *tt, long long tr, int verbose)
{
int i;
for (i = 0; tr >= tt[i].base; i++);
i--;
{
int i;
for (i = 0; tr >= tt[i].base; i++);
i--;
+ if (verbose) {
+ printf("Aplicando aliquota de %d%%, deduzindo " FMT_R"\n",
+ tt[i].aliquota / 10, R(tt[i].deducao));
+ }
return tr * tt[i].aliquota / 10000 - tt[i].deducao;
}
return tr * tt[i].aliquota / 10000 - tt[i].deducao;
}
totais_add(dec, "DESCONTO", td);
tr -= td;
totais_add(dec, "BASESIMPLES", tr);
totais_add(dec, "DESCONTO", td);
tr -= td;
totais_add(dec, "BASESIMPLES", tr);
- return imposto(tt, tr);
+ if (dec->verbose) {
+ printf("Desconto simplificado é "FMT_R"\n", R(td));
+ }
+ return imposto(tt, tr, dec->verbose);
}
static long long imposto_completa(struct declaracao *dec)
}
static long long imposto_completa(struct declaracao *dec)
totais_add(dec, "DEDUCOES", td);
tr -= td;
totais_add(dec, "BASECOMPLETA", tr);
totais_add(dec, "DEDUCOES", td);
tr -= td;
totais_add(dec, "BASECOMPLETA", tr);
- return imposto(tt, tr);
+ if (dec->verbose) {
+ printf("Desconto completa é "FMT_R"\n", R(td));
+ }
+ return imposto(tt, tr, dec->verbose);
}
int calcula(struct declaracao *dec)
}
int calcula(struct declaracao *dec)
if (dec->ano != 2015) {
return -EINVAL;
}
if (dec->ano != 2015) {
return -EINVAL;
}
- if (totais_get(dec, "RENDPJ") > obrigatoriedade2015)
+ if (totais_get(dec, "RENDPJ") > obrigatoriedade2015) {
+ if (dec->verbose) {
+ printf("Declaracao obrigatoria pois rendimento e"
+ "maior que mínimo para declaracao: "
+ FMT_R" > "FMT_R"\n",
+ R(totais_get(dec, "RENDPJ")),
+ R(obrigatoriedade2015));
+ }
i_simples = imposto_simples(dec);
i_completa = imposto_completa(dec);
total_pago(dec);
i_simples = imposto_simples(dec);
i_completa = imposto_completa(dec);
total_pago(dec);
+ if (dec->verbose) {
+ printf("Imposto simplificada e completa: "FMT_R" "FMT_R"\n",
+ R(i_simples), R(i_completa));
+ }
if (dec->tipo != FORCA_SIMPLES &&
(i_simples > i_completa || dec->tipo == FORCA_COMPLETA)) {
totais_add(dec, "BASE", totais_get(dec, "BASECOMPLETA"));
if (dec->tipo != FORCA_SIMPLES &&
(i_simples > i_completa || dec->tipo == FORCA_COMPLETA)) {
totais_add(dec, "BASE", totais_get(dec, "BASECOMPLETA"));
struct pmhash *totais;
unsigned long hash;
unsigned long rhash;
struct pmhash *totais;
unsigned long hash;
unsigned long rhash;
};
struct declaracao * declaracao_new(int ano);
};
struct declaracao * declaracao_new(int ano);
#include <string.h>
#include <errno.h>
#include "pmhash.h"
#include <string.h>
#include <errno.h>
#include "pmhash.h"
int totais_add(struct declaracao *dec, char *key, long long val)
{
int totais_add(struct declaracao *dec, char *key, long long val)
{
+ if (dec->verbose) {
+ printf("Somando "FMT_R" a %s: "FMT_R" -> "FMT_R"\n",
+ R(val), key, R(*p), R(*p + val));
+ }
*p += val;
return 0;
out_hash:
*p += val;
return 0;
out_hash: