diff --git a/mg/mglib02.cpp b/mg/mglib02.cpp index 1ed35c49f..6694214cb 100755 --- a/mg/mglib02.cpp +++ b/mg/mglib02.cpp @@ -854,12 +854,17 @@ real TArticolo_giacenza::ultimo_costo(int annoes) const } else { - const int index = find_storico(annoes); - - if (index >= 0 ) + const int nextes = esercizi().next(annoes); + + if (nextes > 0) { - const real costo = storico(annoes).row(index).get_real(STOMAG_ULTCOS1); - return costo.is_zero() ? costo_standard(annoes) : costo; + const int index = find_storico(nextes); + + if (index >= 0 ) + { + const real costo = storico(nextes).row(index).get_real(STOMAG_ULTCOS1); + return costo.is_zero() ? costo_standard(annoes) : costo; + } } } return ZERO; @@ -875,18 +880,23 @@ real TArticolo_giacenza::media_costi(int annoes) const } else { - const int index = find_storico(annoes); - - if (index >= 0 ) + const int nextes = esercizi().next(annoes); + + if (nextes > 0) { - const TRectype & rec = storico(annoes).row(index); - real costo = rec.get_real(STOMAG_ULTCOS1); - - costo = (costo + rec.get_real(STOMAG_ULTCOS2)) / 2.0; - return costo.is_zero() ? costo_standard(annoes) : costo; + const int index = find_storico(nextes); + + if (index >= 0 ) + { + const TRectype & rec = storico(nextes).row(index); + real costo = rec.get_real(STOMAG_ULTCOS1); + + costo = (costo + rec.get_real(STOMAG_ULTCOS2)) / 2.0; + return costo.is_zero() ? costo_standard(annoes) : costo; + } } } - return ZERO; + return ZERO; } real TArticolo_giacenza::prezzo_listino(int annoes, const char * catven, const char * codlist) const @@ -909,11 +919,16 @@ real TArticolo_giacenza::prezzo_listino(int annoes, const char * catven, const c } else { - const int index = find_storico(annoes); + const int nextes = esercizi().next(annoes); + + if (nextes > 0) + { + const int index = find_storico(nextes); - if (index >= 0 ) - return storico(annoes).row(index).get_real(STOMAG_PRZLIST); - } + if (index >= 0 ) + return storico(nextes).row(index).get_real(STOMAG_PRZLIST); + } + } return ZERO; } @@ -923,10 +938,14 @@ real TArticolo_giacenza::costo_standard(int annoes) const return get_real(ANAMAG_COSTSTD); else { - const int index = find_storico(annoes); - - if (index >= 0 ) - return storico(annoes).row(index).get_real(STOMAG_COSTSTD); + const int nextes = esercizi().next(annoes); + if (nextes > 0) + { + const int index = find_storico(nextes); + + if (index >= 0 ) + return storico(nextes).row(index).get_real(STOMAG_COSTSTD); + } } return ZERO; }