// classpim.cpp // funzione per classificare i PIM e sommare tutto cio' che contengono #include "classpim.h" #include bool classify_pim(TRectype& pimr, real& imp, real& iva, tiporec& t) { static int last_checked = -1; // parse CODTAB of pim record TString ctab = pimr.get("CODTAB"); const int tipocr = atoi(ctab.mid(15,1)); // tipo costo_ricavo const int tipodet = atoi(ctab.mid(20,1)); // tipo detraibilita' const int corrisp = (int)pimr.get_long("I0"); // netto = 1, lordo = 2 const int tipomov = (int)pimr.get_long("I1"); // 1 = vendita, 2 = acquisto const bool vola = pimr.get_bool("B2"); const bool rimb = pimr.get_bool("B3"); const bool ricl = pimr.get_bool("B4"); TString tipoiva = pimr.get("S5"); // cominciamo cosi' imp = ZERO; iva = ZERO; for (int i = last_checked + 1; i <= MAX_TIPOREC; i++) { tiporec tocheck = (tiporec)i; bool found = FALSE; switch(tocheck) { case acq_norm: //found = tipomov == 2 && tipoiva != "NS"; found = tipomov == 2; found &= (tipodet == 0 /* || tipodet == 1 || tipodet == 3 || tipodet == 5 || tipodet == 9 */); if (found) { imp = pimr.get_real("R0") - pimr.get_real("R9"); iva = pimr.get_real("R1") - pimr.get_real("R10"); } break; case vend_norm: //found = tipomov == 1 /* && corrisp == 1 */ && tipoiva != "NS"; found = tipomov == 1 /* && corrisp == 1 */; if (found) { imp = pimr.get_real("R0"); iva = pimr.get_real("R1"); } break; case acq_simp: if (tipomov == 2) { imp = pimr.get_real("R11"); iva = pimr.get_real("R12"); } found = !imp.is_zero() || !iva.is_zero(); break; case vend_simp: if (tipomov == 1 /* && corrisp == 1 */) { imp = pimr.get_real("R11"); iva = pimr.get_real("R12"); } found = !imp.is_zero() || !iva.is_zero(); break; case bolle_doganali: //if (tipomov == 2 && tipoiva != "NS") if (tipomov == 2) { imp = pimr.get_real("R9"); iva = pimr.get_real("R10"); } found = !imp.is_zero() || !iva.is_zero(); break; case base_ventilazione: found = (tipomov == 2 && tipodet != 9 && tipocr == 1); found &= (tipoiva != "NS" && tipoiva != "NI" && tipoiva != "ES"); found &= (ricl ? TRUE : tipodet == 3); if (found) { imp = pimr.get_real("R0"); iva = pimr.get_real("R1"); } found &= !imp.is_zero() || !iva.is_zero(); break; case acq_beni_riv: /* found = (tipomov == 2 && tipodet != 9 && (tipocr == 1 || (tipocr == 5 && tipodet == 3))); found &= tipoiva != "NS" && tipoiva != "NI" && tipoiva != "ES"; found &= (ricl ? TRUE : tipodet == 3); */ found = (tipomov == 2 && (tipocr == 1 || tipocr == 5)); if (found) { imp = pimr.get_real("R0"); iva = pimr.get_real("R1"); } found &= (!imp.is_zero() || !iva.is_zero()); break; case corr_norm: found = tipomov == 1 && corrisp == 2 && tipoiva != "NS"; if (found) { imp = pimr.get_real("R0"); iva = pimr.get_real("R1"); found &= (!imp.is_zero() || !iva.is_zero()); } break; case corr_simp: if (tipomov == 1 && corrisp == 2) { imp = pimr.get_real("R11"); iva = pimr.get_real("R12"); } found = !imp.is_zero() || !iva.is_zero(); break; case acq_beni_ammort: //found = tipomov == 2 && tipocr == 2 && // tipodet == 0 && tipoiva != "NS"; found = tipomov == 2 && tipocr == 2 && tipodet == 0; if (found) { imp = pimr.get_real("R0"); iva = pimr.get_real("R1"); found &= (!imp.is_zero() || !iva.is_zero()); } break; case acq_beni_ammort_nd: //found = tipomov == 2 && tipocr ==2 && // tipodet != 0 && tipoiva != "NS"; found = tipomov == 2 && tipocr ==2 && tipodet != 0; if (found) { imp = pimr.get_real("R0"); iva = pimr.get_real("R1"); found &= (!imp.is_zero() || !iva.is_zero()); } break; case acq_beni_leasing: //found = tipomov == 2 && tipocr == 8 && tipoiva != "NS"; found = tipomov == 2 && tipocr == 8; if (found) { imp = pimr.get_real("R0"); iva = pimr.get_real("R1"); found &= (!imp.is_zero() || !iva.is_zero()); } break; case acq_amm_ultdetr: //found = tipomov == 2 && tipocr == 3 && tipoiva != "NS"; found = tipomov == 2 && tipocr == 3; if (found) { imp = pimr.get_real("R0"); iva = pimr.get_real("R1"); found &= (!imp.is_zero() || !iva.is_zero()); } break; case acq_ind_op_es: found = tipomov == 2 && tipodet == 1 && tipoiva != "NS"; if (found) { imp = pimr.get_real("R0"); iva = pimr.get_real("R1"); found &= (!imp.is_zero() || !iva.is_zero()); } break; case acq_ind_pass_int: found = tipomov == 2 && tipodet == 3 && tipoiva != "NS"; if (found) { imp = pimr.get_real("R0"); iva = pimr.get_real("R1"); found &= (!imp.is_zero() || !iva.is_zero()); } break; case acq_ind_art_19: found = tipomov == 2 && tipodet == 9 && tipoiva != "NS"; if (found) { imp = pimr.get_real("R0"); iva = pimr.get_real("R1"); found &= (!imp.is_zero() || !iva.is_zero()); } break; case cess_amm: //found = tipomov == 1 && tipocr == 4 && tipoiva != "NS"; found = tipomov == 1 && tipocr == 4; if (found) { imp = pimr.get_real("R0"); iva = pimr.get_real("R1"); found &= (!imp.is_zero() || !iva.is_zero()); } break; case vend_rimborso: found = tipomov == 1 && rimb && tipoiva != "NS"; if (found) { imp = pimr.get_real("R0"); iva = pimr.get_real("R1"); found &= (!imp.is_zero() || !iva.is_zero()); } break; case acq_rimborso: found = tipomov == 2 && rimb && tipoiva != "NS"; if (found) { imp = pimr.get_real("R0"); iva = pimr.get_real("R1"); found &= (!imp.is_zero() || !iva.is_zero()); } break; } if (i == MAX_TIPOREC) last_checked = -1; else if (found) { t = tocheck; last_checked = i; break; } } return last_checked != -1; }