#include "cmd.h"
#include "list.h"
#include "util.h"
+#include "totais.h"
void rendimento_free(void *pointer)
{
free(rendimento);
}
+static int rendimento_cmp(void *p1, void *p2)
+{
+ struct rendimento *r1 = p1;
+ struct rendimento *r2 = p2;
+ /* O rendimento maior vem primeiro. */
+ if (r1->rendimento > r2->rendimento)
+ return -1;
+ else if (r1->rendimento < r2->rendimento)
+ return 1;
+ return 0;
+}
+
static struct rendimento * rendimento_new(char **args)
{
struct rendimento *rendimento;
rendimento = rendimento_new(args);
if (!rendimento)
return -ENOMEM;
- r = list_add(&dec->rendimento, rendimento);
+ r = list_insert_ordered(&dec->rendimento, rendimento, rendimento_cmp);
if (r < 0) {
rendimento_free(rendimento);
return r;
}
+ r = totais_add(dec, "RENDPJ", rendimento->rendimento);
+ r += totais_add(dec, "RENDPJTIT", rendimento->rendimento);
+ r += totais_add(dec, "INSS", rendimento->previdencia);
+ if (r) {
+ rendimento_free(rendimento);
+ return r;
+ }
return 0;
}
cmd_add(&cmd_rendimento);
return 0;
}
+
+char * rendimento_cnpj_ordenado(struct declaracao *dec, int i)
+{
+ struct rendimento *rendimento;
+ rendimento = list_get(dec->rendimento, i);
+ if (!rendimento)
+ return "";
+ return rendimento->cnpj;
+}