diff --git a/ve/velib04f.cpp b/ve/velib04f.cpp index df529005a..d10a066af 100755 --- a/ve/velib04f.cpp +++ b/ve/velib04f.cpp @@ -288,7 +288,41 @@ bool TContabilizzazione_analitica::search_costo_ricavo(const TRiga_documento& r, default : break; } // end of switch + if (conto.ok()) + { + const TRectype * rdoc = r.find_original_rdoc(); + + if (rdoc != NULL && rdoc->get(RDOC_PROVV).not_empty()) + { + TString80 key(rdoc->get(RDOC_CODNUM)); + + const TCodice_numerazione& num = TDocumento::codice_numerazione(key); + if (num.fattura_emettere_ricevere()) + { + key.format("%3d%3d%6ld", conto.gruppo(), conto.conto(), conto.sottoconto()); + const TRectype* rs = &cache().get("MRE", key); + if (rs->empty()) + { + key.cut(6); + rs = &cache().get("MRE", key); + if (rs->empty()) + { + key.cut(3); + rs = &cache().get("MRE", key); + } + } + if (!rs->empty()) + { + const int gr = rs->get_int("I0"); + const int co = rs->get_int("I1"); + const long so = rs->get_int("I2"); + const char tipo = rs->get_char("S6"); + conto.set(gr, co, so, tipo); + } + } + } + } return conto.ok() && conto.find(); }