summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
cff2688)
O cabeçalho da declaração contém os CNPJs das pessoas jurídicas que
pagaram os maiores rendimentos. Insere os rendimentos de forma ordenada,
com os maiores rendimentos primeiro, e cria uma função para retornar o
CNPJ de um rendimento dado o seu índice.
fprintf(f, " "); /* RRA4 */
fprintf(f, "%-11.11s", ""); /* CPF RRA4 */
fprintf(f, "0000000000000"); /* TODO: Doacao ECA */
fprintf(f, " "); /* RRA4 */
fprintf(f, "%-11.11s", ""); /* CPF RRA4 */
fprintf(f, "0000000000000"); /* TODO: Doacao ECA */
- fprintf(f, "%-14.14s", ""); /* TODO: CNPJ maior */
- fprintf(f, "%-14.14s", ""); /* TODO: CNPJ maior 2 */
- fprintf(f, "%-14.14s", ""); /* TODO: CNPJ maior 3 */
- fprintf(f, "%-14.14s", ""); /* TODO: CNPJ maior 4 */
+ fprintf(f, "%-14.14s", rendimento_cnpj_ordenado(dec, 0)); /* TODO: CNPJ maior */
+ fprintf(f, "%-14.14s", rendimento_cnpj_ordenado(dec, 1)); /* TODO: CNPJ maior 2 */
+ fprintf(f, "%-14.14s", rendimento_cnpj_ordenado(dec, 2)); /* TODO: CNPJ maior 3 */
+ fprintf(f, "%-14.14s", rendimento_cnpj_ordenado(dec, 3)); /* TODO: CNPJ maior 4 */
fprintf(f, "%-11.11s", ""); /* CPF Dependente 1 */
fprintf(f, "%-8.8s", ""); /* DN Dependente 1 */
fprintf(f, "%-11.11s", ""); /* CPF Dependente 2 */
fprintf(f, "%-11.11s", ""); /* CPF Dependente 1 */
fprintf(f, "%-8.8s", ""); /* DN Dependente 1 */
fprintf(f, "%-11.11s", ""); /* CPF Dependente 2 */
+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;
static struct rendimento * rendimento_new(char **args)
{
struct rendimento *rendimento;
rendimento = rendimento_new(args);
if (!rendimento)
return -ENOMEM;
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;
if (r < 0) {
rendimento_free(rendimento);
return r;
cmd_add(&cmd_rendimento);
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;
+}
int rendimento_cmd_init(void);
int rendimento_cmd_init(void);
+char * rendimento_cnpj_ordenado(struct declaracao *dec, int i);
+