Modificati algoritmi di calcolo magazzino

git-svn-id: svn://10.65.10.50/trunk@4794 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
alex 1997-07-02 10:53:23 +00:00
parent 560063a128
commit 90faa88bdd
2 changed files with 41 additions and 18 deletions

View File

@ -300,10 +300,27 @@ int TArticolo_giacenza::find_mag(const char * annoes, const char * codmag, const
return -1;
}
int TArticolo_giacenza::find_storico(const char * annoesrif, const char * annoes, int from) const
int TArticolo_giacenza::find_storico(const char * annoesrif, const char * annoes, const char * codmag, int from) const
{
((TArticolo_giacenza *) this)->set_anno_sto(annoesrif);
return find(LF_STOMAG, STOMAG_ANNOES, annoes, from);
TRecord_array & rsto = storico(annoesrif);
const int last = rsto.last_row();
if (from <= last)
{
const int codmag_len = codmag ? strlen(codmag) : 0;
if (codmag_len == 0)
return from + 1;
for (int i = rsto.succ_row(from); i <= last; i = rsto.succ_row(i))
{
const TRectype & rec = rsto.row(i);
if (rec.get(STOMAG_CODMAG).compare(codmag, codmag_len) == 0)
return i;
}
}
return -1;
}
TRecord_array & TArticolo_giacenza::mag(const char * annoes) const
@ -505,10 +522,10 @@ real TArticolo_giacenza::LIFO(const char * annoes, const char * codmag, const ch
return ((giacenza - rim) * (acq == ZERO ? costo_standard(annoes) : valacq / acq) + valrim) / giacenza;
TRecord_array & rstorico = storico(annoes);
const int last = rstorico.last_row();
// const int last = rstorico.last_row();
rim = giacenza;
for (i = rstorico.first_row(); i <= last; i = rstorico.succ_row(i))
for (i = find_storico(annoes, "", codmag); i > 0; i = find_storico(annoes, "", codmag, i))
{
const TRectype & rec = rstorico.row(i);
const real qta = rec.get(STOMAG_QUANT);
@ -565,22 +582,27 @@ real TArticolo_giacenza::FIFO(const char * annoes, const char * codmag, const ch
real res = giacenza - acq;
rim = ZERO;
valrim = ZERO;
valrim = ZERO;
TFixed_string cmag(codmag);
int codmag_len = codmag ? strlen(cmag) : 0;
for (i = last; i > 0; i--)
{
const TRectype & rec = rstorico.row(i);
const real qta = rec.get(STOMAG_QUANT);
if (qta > res)
{
rim += res;
valrim += (rec.get_real(STOMAG_VALORE) / qta) * res;
}
else
if (codmag_len == 0 || rec.get(STOMAG_CODMAG).compare(codmag, codmag_len) == 0)
{
rim += qta;
valrim += rec.get_real(STOMAG_VALORE);
res -= qta;
const real qta = rec.get(STOMAG_QUANT);
if (qta > res)
{
rim += res;
valrim += (rec.get_real(STOMAG_VALORE) / qta) * res;
}
else
{
rim += qta;
valrim += rec.get_real(STOMAG_VALORE);
res -= qta;
}
}
}
return ((giacenza - acq) * (valrim / rim) + valacq) / giacenza;
@ -1175,7 +1197,7 @@ int TMov_mag::update_balances()
mag.write();
}
// modifica questo record (e lo sblocca)
update_balances(mag.curr(),line_mov, +1);
update_balances(mag.curr(), line_mov, +1);
/*// ottimizzazione :(cerca di sfruttare la lettura fatta per un eventuale saldo vecchio)
// ciò causa la modifica dell'oggetto TMov_mag (il metodo non è più const)
if (_annoes == get("ANNOES")

View File

@ -4,6 +4,7 @@
#define STOMAG_ANNOESRIF "ANNOESRIF"
#define STOMAG_CODART "CODART"
#define STOMAG_ANNOES "ANNOES"
#define STOMAG_CODMAG "CODMAG"
// #define STOMAG_UM "UM"
#define STOMAG_QUANT "QUANT"
#define STOMAG_VALORE "VALORE"