+static void calculo_instrucao(struct declaracao *dec)
+{
+ int i, j;
+ struct dependente *d;
+ struct pagamento *p;
+ long long instrucao_titular = 0;
+ /* Instrução do titular */
+ for (i = 0; (p = list_get(dec->pagamentos, i)); i++) {
+ if (p->dependente == 0 && pagamento_instrucao(p)) {
+ instrucao_titular += (p->pagamento - p->reembolso);
+ }
+ }
+ if (instrucao_titular > instrucao[ANO(dec->ano)]) {
+ totais_add(dec, "INSTRUCAO", instrucao[ANO(dec->ano)]);
+ } else {
+ totais_add(dec, "INSTRUCAO", instrucao_titular);
+ }
+ /* Dependentes com instrução */
+ for (i = 0; (d = list_get(dec->dependentes, i)); i++) {
+ long long instrucao_dependente = 0;
+ for (j = 0; (p = list_get(dec->pagamentos, j)); j++) {
+ if (p->dependente == (i + 1) && pagamento_instrucao(p)) {
+ instrucao_dependente += (p->pagamento - p->reembolso);
+ }
+ }
+ if (instrucao_dependente) {
+ /* Conta número de dependentes com instrução. */
+ totais_add(dec, "DEPSINSTRUCAO", 1);
+ if (dec->verbose) {
+ printf("Dependente %s (%d) tem instrução\n", d->nome, i);
+ }
+ }
+ if (instrucao_dependente > instrucao[ANO(dec->ano)]) {
+ totais_add(dec, "INSTRUCAO", instrucao[ANO(dec->ano)]);
+ } else {
+ totais_add(dec, "INSTRUCAO", instrucao_dependente);
+ }
+ }
+}
+