Modifiche all'oggetto articolo
git-svn-id: svn://10.65.10.50/trunk@4464 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
f1dabe4378
commit
4cb017d7da
639
mg/mglib02.cpp
639
mg/mglib02.cpp
@ -1,61 +1,224 @@
|
||||
#include "mglib02.h"
|
||||
#include "../cg/cglib.h"
|
||||
|
||||
bool TArticolo::load_um()
|
||||
{
|
||||
if (_um)
|
||||
return TRUE;
|
||||
void TMultiple_rectype::load_rows_file(int logicnum)
|
||||
{
|
||||
const int index = log2ind(logicnum);
|
||||
TRectype & rec = get_body_record(logicnum);
|
||||
|
||||
const char * codice = (const char *) _codice;
|
||||
|
||||
if (!*codice)
|
||||
return FALSE;
|
||||
|
||||
TRectype rec(LF_UMART);
|
||||
|
||||
_um == new TRecord_array(LF_UMART, UMART_NRIGA);
|
||||
rec.put(UMART_CODART, codice);
|
||||
_um->destroy_rows();
|
||||
_um->read(rec);
|
||||
return TRUE;
|
||||
set_body_key(rec);
|
||||
TRecord_array * r = new TRecord_array(logicnum, (TString &) _numfields[index]);
|
||||
_files.add( r, index);
|
||||
}
|
||||
|
||||
bool TArticolo::load_codcorr()
|
||||
int TMultiple_rectype::find(int logicnum, const char * fieldname, const char * s, int from, bool reverse) const
|
||||
{
|
||||
const TRecord_array & recarray = body(logicnum);
|
||||
const int last = recarray.last_row();
|
||||
const int len = s ? strlen(s) : 0;
|
||||
|
||||
if (reverse)
|
||||
{
|
||||
if (from > 0)
|
||||
{
|
||||
if (len == 0)
|
||||
return from - 1;
|
||||
for (int i = recarray.pred_row(from); i > 0; i = recarray.pred_row(i))
|
||||
if (recarray[i].get(fieldname) == s)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (last > from)
|
||||
{
|
||||
if (len == 0)
|
||||
return from + 1;
|
||||
for (int i = recarray.succ_row(from); i <= last; i = recarray.succ_row(i))
|
||||
if (recarray[i].get(fieldname) == s)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int TMultiple_rectype::write_rewrite(TBaseisamfile & f, bool re) const
|
||||
{
|
||||
int err = NOERR;
|
||||
|
||||
if (_nuovo && re) // E' nuovo di zecca! quindi ...
|
||||
re = FALSE; // ... non fare la rewrite
|
||||
|
||||
if (re)
|
||||
{
|
||||
for (int i = _nfiles - 1; err == NOERR && i >= 0 ; i--)
|
||||
{
|
||||
TRecord_array * r = (TRecord_array *) _files.objptr(i);
|
||||
if (r)
|
||||
err = r->write(re);
|
||||
}
|
||||
// rewrite:
|
||||
if (err == NOERR)
|
||||
{
|
||||
err = TRectype::rewrite(f);
|
||||
if (err != NOERR)
|
||||
err = TRectype::write(f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// write:
|
||||
if (_nuovo)
|
||||
{
|
||||
do
|
||||
{
|
||||
err = TRectype::write(f);
|
||||
if (err == _isreinsert) // usa il flag _nuovo per decidere se
|
||||
((TMultiple_rectype *)this)->renum();
|
||||
} while (err == _isreinsert);
|
||||
((TMultiple_rectype *)this)->_nuovo = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = TRectype::write(f);
|
||||
if (err != NOERR)
|
||||
err = TRectype::rewrite(f);
|
||||
}
|
||||
for (int i = _nfiles - 1; err == NOERR && i >= 0 ; i--)
|
||||
{
|
||||
TRecord_array * r = (TRecord_array *)_files.objptr(i);
|
||||
if (r)
|
||||
err = r->write(re);
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
void TMultiple_rectype::remove_body(int logicnum)
|
||||
{
|
||||
const int index = log2ind(logicnum);
|
||||
|
||||
if (_files.objptr(index) != NULL)
|
||||
_files.remove(index);
|
||||
}
|
||||
|
||||
int TMultiple_rectype::log2ind(int logicnum) const
|
||||
{
|
||||
if (logicnum == 0)
|
||||
return 0;
|
||||
for (int i = _nfiles - 1; i >= 0 ; i--)
|
||||
if (_logicnums[i] == logicnum)
|
||||
return i;
|
||||
NFCHECK("Can't find file %d in multiple record", logicnum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
TRecord_array & TMultiple_rectype::body(int logicnum) const
|
||||
{
|
||||
const int index = log2ind(logicnum);
|
||||
|
||||
if (_files.objptr(index) == NULL)
|
||||
((TMultiple_rectype *) this)->load_rows_file(logicnum);
|
||||
return (TRecord_array &) _files[index];
|
||||
}
|
||||
|
||||
void TMultiple_rectype::renum_key(const char * kfield,const char * val)
|
||||
{
|
||||
if (_codcorr)
|
||||
return TRUE;
|
||||
|
||||
const char * codice = (const char *) _codice;
|
||||
|
||||
if (!*codice)
|
||||
return FALSE;
|
||||
TRectype rec(LF_CODCORR);
|
||||
|
||||
_codcorr == new TRecord_array(LF_CODCORR, CODCORR_NRIGA);
|
||||
rec.put(CODCORR_CODART, codice);
|
||||
_codcorr->destroy_rows();
|
||||
_codcorr->read(rec);
|
||||
return TRUE;
|
||||
TRectype::renum_key(kfield, val); // Aggiorna testata
|
||||
for (int i = _nfiles - 1; i >= 0 ; i--)
|
||||
body(_logicnums[i]).renum_key(kfield, val); // Aggiorna righe
|
||||
}
|
||||
|
||||
bool TArticolo::load_deslin()
|
||||
|
||||
TRectype & TMultiple_rectype::operator =(const TRectype & r)
|
||||
{
|
||||
if (_deslin)
|
||||
return TRUE;
|
||||
|
||||
const char * codice = (const char *) _codice;
|
||||
|
||||
if (* codice)
|
||||
return FALSE;
|
||||
|
||||
TRectype rec(LF_DESLIN);
|
||||
|
||||
_deslin == new TRecord_array(LF_DESLIN, DESLIN_NRIGA);
|
||||
rec.put(DESLIN_CODART, codice);
|
||||
_deslin->destroy_rows();
|
||||
_deslin->read(rec);
|
||||
return TRUE;
|
||||
TRectype::operator=(r);
|
||||
reset_fields(*this);
|
||||
set_fields(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
TRectype & TMultiple_rectype::operator =(const char * r)
|
||||
{
|
||||
TRectype::operator=(r);
|
||||
reset_fields(*this);
|
||||
set_fields(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void TMultiple_rectype::zero(char c)
|
||||
{
|
||||
reset_fields(*this);
|
||||
TAuto_variable_rectype::zero(c);
|
||||
for (int i = _nfiles - 1; i >= 0 ; i--)
|
||||
if (_files.objptr(i) != NULL)
|
||||
_files.remove(i);
|
||||
}
|
||||
|
||||
|
||||
int TMultiple_rectype::read(TRectype & rec, word op, word lockop)
|
||||
{
|
||||
TLocalisamfile f(num());
|
||||
|
||||
*this = rec;
|
||||
|
||||
int err = TRectype::read(f, op, lockop);
|
||||
|
||||
for (int i = _nfiles - 1; i >= 0 ; i--)
|
||||
if (_files.objptr(i) != NULL)
|
||||
_files.remove(i);
|
||||
_nuovo = err != NOERR;
|
||||
return err;
|
||||
}
|
||||
|
||||
int TMultiple_rectype::remove(TBaseisamfile & f) const
|
||||
{
|
||||
int err = NOERR;
|
||||
|
||||
for (int i = _nfiles - 1; err == NOERR && i >= 0 ; i--)
|
||||
{
|
||||
TRecord_array & r = body(_logicnums[i]);
|
||||
r.remove();
|
||||
}
|
||||
if (err == NOERR)
|
||||
err = TRectype::remove(f);
|
||||
return err;
|
||||
}
|
||||
|
||||
// @doc INTERNAL
|
||||
TMultiple_rectype::TMultiple_rectype(int hfn)
|
||||
: TAuto_variable_rectype(hfn), _nuovo(TRUE), _nfiles(0)
|
||||
{
|
||||
}
|
||||
|
||||
// @ cmember costruttore dal file
|
||||
void TMultiple_rectype::add_file(int logicnum, const char * numfield)
|
||||
{
|
||||
CHECK(_nfiles < maxfiles, "Too many files added");
|
||||
_logicnums[_nfiles] = logicnum;
|
||||
_numfields.add(numfield, _nfiles++);
|
||||
}
|
||||
|
||||
TMultiple_rectype::TMultiple_rectype(const TBaseisamfile* file)
|
||||
:TAuto_variable_rectype(file), _nuovo(TRUE), _nfiles(0)
|
||||
{
|
||||
}
|
||||
|
||||
// @ cmember costruttore dal record
|
||||
TMultiple_rectype::TMultiple_rectype(const TRectype & rec)
|
||||
:TAuto_variable_rectype(rec), _nuovo(TRUE), _nfiles(0)
|
||||
{
|
||||
}
|
||||
|
||||
// @mfunc costruttore di copia
|
||||
TMultiple_rectype::TMultiple_rectype(const TMultiple_rectype& r)
|
||||
:TAuto_variable_rectype(r), _files(r._files)
|
||||
{
|
||||
// copia..
|
||||
_nuovo=r._nuovo;
|
||||
_nfiles=r._nfiles; // file delle righe
|
||||
_numfields=r._numfields;
|
||||
}
|
||||
|
||||
HIDDEN TString16 _mg_null_str;
|
||||
|
||||
@ -76,35 +239,26 @@ const TString & TArticolo::get_str(const char* fieldname) const
|
||||
{
|
||||
case LF_UMART:
|
||||
{
|
||||
if (((TArticolo *) this)->load_um())
|
||||
{
|
||||
if (index == 0)
|
||||
index = find_um(op1);
|
||||
if (index > 0 && op2)
|
||||
return _um->row(index).get(op2);
|
||||
}
|
||||
if (index == 0)
|
||||
index = find_um(op1);
|
||||
if (index > 0 && op2)
|
||||
return um().row(index).get(op2);
|
||||
}
|
||||
break;
|
||||
case LF_CODCORR:
|
||||
{
|
||||
if (((TArticolo *) this)->load_codcorr())
|
||||
{
|
||||
if (index == 0)
|
||||
index = find_codcorr(op1);
|
||||
if (index > 0 && op2)
|
||||
return _codcorr->row(index).get(op2);
|
||||
}
|
||||
if (index == 0)
|
||||
index = find_codcorr(op1);
|
||||
if (index > 0 && op2)
|
||||
return codcorr().row(index).get(op2);
|
||||
}
|
||||
break;
|
||||
case LF_DESLIN:
|
||||
{
|
||||
if (((TArticolo *) this)->load_deslin())
|
||||
{
|
||||
if (index == 0)
|
||||
index = find_deslin(op1);
|
||||
if (index > 0 && op2)
|
||||
return _deslin->row(index).get(op2);
|
||||
}
|
||||
if (index == 0)
|
||||
index = find_deslin(op1);
|
||||
if (index > 0 && op2)
|
||||
return deslin().row(index).get(op2);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -113,46 +267,35 @@ const TString & TArticolo::get_str(const char* fieldname) const
|
||||
return _mg_null_str;
|
||||
}
|
||||
|
||||
int TArticolo::find(const TRecord_array & array, const char * fieldname, const char * s,
|
||||
int from) const
|
||||
void TArticolo::set_body_key(TRectype & rowrec)
|
||||
{
|
||||
const int last = array.last_row();
|
||||
if (from > last)
|
||||
{
|
||||
const int len = s ? strlen(s) : 0;
|
||||
if (len == 0)
|
||||
return from + 1;
|
||||
for (int i = array.succ_row(from); i <= last; i = _um->succ_row(i))
|
||||
if (_um->row(i).get(UMART_UM) == s)
|
||||
return i;
|
||||
const int logicnum = rowrec.num();
|
||||
const char * codice = (const char *) _codice;
|
||||
|
||||
switch (logicnum)
|
||||
{
|
||||
case LF_UMART:
|
||||
rowrec.put(UMART_CODART, codice);
|
||||
break;
|
||||
case LF_DESLIN:
|
||||
rowrec.put(DESLIN_CODART, codice);
|
||||
break;
|
||||
case LF_CODCORR:
|
||||
rowrec.put(CODCORR_CODART, codice);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int TArticolo::read(const char * cod)
|
||||
int TArticolo::read(const char * cod, word op, word lockop)
|
||||
{
|
||||
if (strcmp(cod, (const char *) _codice) == 0)
|
||||
if (op == _isequal && lockop == _nolock &&strcmp(cod, (const char *) _codice) == 0)
|
||||
return NOERR;
|
||||
if (_um)
|
||||
{
|
||||
delete _um;
|
||||
_um = NULL;
|
||||
}
|
||||
if (_codcorr)
|
||||
{
|
||||
delete _codcorr;
|
||||
_codcorr = NULL;
|
||||
}
|
||||
if (_deslin)
|
||||
{
|
||||
delete _deslin;
|
||||
_deslin == NULL;
|
||||
}
|
||||
|
||||
TLocalisamfile anamag(LF_ANAMAG);
|
||||
|
||||
*_codice = cod;
|
||||
const int err = TRectype::read(anamag);
|
||||
*_codice = cod;
|
||||
|
||||
const int err = TMultiple_rectype::read(op , lockop);
|
||||
|
||||
if (err != NOERR)
|
||||
zero();
|
||||
return err;
|
||||
@ -171,8 +314,7 @@ const TString & TArticolo::descrizione(const char* lingua) const
|
||||
}
|
||||
|
||||
TArticolo::TArticolo(const char* codice)
|
||||
: TRectype(LF_ANAMAG), _um(NULL), _codcorr(NULL),
|
||||
_deslin(NULL)
|
||||
: TMultiple_rectype(LF_ANAMAG)
|
||||
|
||||
{
|
||||
_codice = new TRecfield(*this, ANAMAG_CODART);
|
||||
@ -181,8 +323,7 @@ TArticolo::TArticolo(const char* codice)
|
||||
}
|
||||
|
||||
TArticolo::TArticolo(const TRectype& rec)
|
||||
: TRectype(rec), _um(NULL), _codcorr(NULL),
|
||||
_deslin(NULL)
|
||||
: TMultiple_rectype(rec)
|
||||
{
|
||||
_codice = new TRecfield(*this, ANAMAG_CODART);
|
||||
}
|
||||
@ -190,73 +331,6 @@ TArticolo::TArticolo(const TRectype& rec)
|
||||
TArticolo::~TArticolo()
|
||||
{
|
||||
delete _codice;
|
||||
if (_um)
|
||||
delete _um;
|
||||
if (_codcorr)
|
||||
delete _codcorr;
|
||||
if (_deslin)
|
||||
delete _deslin;
|
||||
}
|
||||
|
||||
int TArticolo_giacenza::read(const char * cod)
|
||||
{
|
||||
if (strcmp(cod, codice()) == 0)
|
||||
return NOERR;
|
||||
if (_mag)
|
||||
{
|
||||
delete _mag;
|
||||
_mag = NULL;
|
||||
}
|
||||
if (_storico)
|
||||
{
|
||||
delete _storico;
|
||||
_storico = NULL;
|
||||
}
|
||||
return TArticolo::read(cod);
|
||||
}
|
||||
|
||||
|
||||
bool TArticolo_giacenza::load_mag(const char * annoes)
|
||||
{
|
||||
if (_mag)
|
||||
{
|
||||
if (_mag->key().get(MAG_ANNOES) == annoes)
|
||||
return TRUE;
|
||||
delete _mag;
|
||||
}
|
||||
|
||||
const char * cod = (const char *) codice();
|
||||
|
||||
if (!*cod)
|
||||
return FALSE;
|
||||
|
||||
TRectype rec(LF_MAG);
|
||||
|
||||
rec.put(MAG_ANNOES, annoes);
|
||||
rec.put(MAG_CODART, cod);
|
||||
_mag == new TRecord_array(rec, MAG_NRIGA);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool TArticolo_giacenza::load_storico(const char * annoesrif)
|
||||
{
|
||||
if (_storico)
|
||||
{
|
||||
if (_storico->key().get(STOMAG_ANNOESRIF) == annoesrif)
|
||||
return TRUE;
|
||||
delete _storico;
|
||||
}
|
||||
|
||||
const char * cod = (const char *) codice();
|
||||
|
||||
if (!*cod)
|
||||
return FALSE;
|
||||
TRectype rec(LF_STOMAG);
|
||||
|
||||
rec.put(STOMAG_CODART, cod);
|
||||
rec.put(STOMAG_ANNOESRIF, annoesrif);
|
||||
_mag == new TRecord_array(rec, STOMAG_NRIGA);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
const TString & TArticolo_giacenza::get_str(const char* fieldname) const
|
||||
@ -279,22 +353,16 @@ const TString & TArticolo_giacenza::get_str(const char* fieldname) const
|
||||
switch (logicnum)
|
||||
{
|
||||
case LF_MAG:
|
||||
if (((TArticolo_giacenza *) this)->load_mag(op1))
|
||||
{
|
||||
if (index == 0)
|
||||
index = find_mag(op1, op2, op3);
|
||||
if (index > 0 && op3)
|
||||
return _mag->row(index).get(op4);
|
||||
}
|
||||
if (index == 0)
|
||||
index = find_mag(op1, op2, op3);
|
||||
if (index > 0 && op3)
|
||||
return mag(op1).row(index).get(op4);
|
||||
break;
|
||||
case LF_STOMAG:
|
||||
if (((TArticolo_giacenza *) this)->load_storico(op1))
|
||||
{
|
||||
if (index = 0)
|
||||
index = find_storico(op1, op2);
|
||||
if (index > 0)
|
||||
return _storico->row(index).get(op4);
|
||||
}
|
||||
if (index = 0)
|
||||
index = find_storico(op1, op2);
|
||||
if (index > 0)
|
||||
return storico(op1).row(index).get(op4);
|
||||
break;
|
||||
default:
|
||||
return TArticolo::get_str(fieldname);
|
||||
@ -303,10 +371,52 @@ const TString & TArticolo_giacenza::get_str(const char* fieldname) const
|
||||
return _mg_null_str;
|
||||
}
|
||||
|
||||
void TArticolo_giacenza::set_body_key(TRectype & rowrec)
|
||||
{
|
||||
const int logicnum = rowrec.num();
|
||||
const char * cod = (const char *) codice();
|
||||
|
||||
switch (logicnum)
|
||||
{
|
||||
case LF_STOMAG:
|
||||
rowrec.put(STOMAG_CODART, cod);
|
||||
rowrec.put(STOMAG_ANNOESRIF, _anno_sto);
|
||||
break;
|
||||
case LF_MAG:
|
||||
rowrec.put(MAG_ANNOES, _anno_mag);
|
||||
rowrec.put(MAG_CODART, cod);
|
||||
break;
|
||||
default:
|
||||
TArticolo::set_body_key(rowrec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void TArticolo_giacenza::set_anno_mag (const char * anno)
|
||||
{
|
||||
if (_anno_mag != anno)
|
||||
remove_body(LF_MAG);
|
||||
_anno_mag = anno;
|
||||
}
|
||||
|
||||
void TArticolo_giacenza::set_anno_sto (const char * anno)
|
||||
{
|
||||
if (_anno_sto != anno)
|
||||
remove_body(LF_STOMAG);
|
||||
_anno_sto = anno;
|
||||
}
|
||||
|
||||
void TArticolo_giacenza::zero(char c)
|
||||
{
|
||||
reset_anno_sto();
|
||||
reset_anno_mag();
|
||||
TArticolo::zero(c);
|
||||
}
|
||||
|
||||
int TArticolo_giacenza::find_mag(const char * annoes, const char * codmag, const char * livello, int from) const
|
||||
{
|
||||
((TArticolo_giacenza *) this)->load_mag(annoes);
|
||||
const int last = _mag->last_row();
|
||||
{
|
||||
TRecord_array & rmag = mag(annoes);
|
||||
const int last = rmag.last_row();
|
||||
|
||||
if (from <= last)
|
||||
{
|
||||
@ -316,9 +426,9 @@ int TArticolo_giacenza::find_mag(const char * annoes, const char * codmag, const
|
||||
if (codmag_len == 0 && livello_len == 0)
|
||||
return from + 1;
|
||||
|
||||
for (int i = _mag->succ_row(from); i <= last; i = _mag->succ_row(i))
|
||||
for (int i = rmag.succ_row(from); i <= last; i = rmag.succ_row(i))
|
||||
{
|
||||
const TRectype & rec = _mag->row(i);
|
||||
const TRectype & rec = rmag.row(i);
|
||||
|
||||
if (codmag_len == 0 || rec.get(MAG_CODMAG).compare(codmag, codmag_len) == 0)
|
||||
if (livello_len == 0 || rec.get(MAG_LIVELLO).compare(livello, livello_len) == 0)
|
||||
@ -328,79 +438,100 @@ 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
|
||||
{
|
||||
((TArticolo_giacenza *) this)->set_anno_sto(annoesrif);
|
||||
return find(LF_STOMAG, STOMAG_ANNOES, annoes, from);
|
||||
}
|
||||
|
||||
TRecord_array & TArticolo_giacenza::mag(const char * annoes) const
|
||||
{
|
||||
((TArticolo_giacenza *) this)->set_anno_mag(annoes);
|
||||
return body(LF_MAG);
|
||||
}
|
||||
|
||||
TRecord_array & TArticolo_giacenza::storico(const char * annoesrif) const
|
||||
{
|
||||
((TArticolo_giacenza *) this)->set_anno_sto(annoesrif);
|
||||
return body(LF_STOMAG);
|
||||
}
|
||||
|
||||
HIDDEN int last_esercizio = -1;
|
||||
|
||||
real TArticolo_giacenza::ultimo_costo(const char * annoes) const
|
||||
{
|
||||
int index = find_storico(annoes, annoes);
|
||||
|
||||
if (index < 0)
|
||||
if (last_esercizio != atoi(annoes))
|
||||
{
|
||||
const real costo = get_real(ANAMAG_ULTCOS1);
|
||||
return costo == ZERO ? costo_standard(annoes) : costo;
|
||||
}
|
||||
return ZERO;
|
||||
// else
|
||||
// {
|
||||
// const real costo = _storico->row(index).get_real(STOMAG_ULTCOS1);
|
||||
// return costo == ZERO ? costo_standard(annoes) : costo;
|
||||
else
|
||||
{
|
||||
const int index = find_storico(annoes, annoes);
|
||||
const real costo = storico(annoes).row(index).get_real(STOMAG_ULTCOS1);
|
||||
return costo == ZERO ? costo_standard(annoes) : costo;
|
||||
}
|
||||
}
|
||||
|
||||
real TArticolo_giacenza::media_costi(const char * annoes) const
|
||||
{
|
||||
int index = find_storico(annoes, annoes);
|
||||
|
||||
if (index < 0)
|
||||
if (last_esercizio != atoi(annoes))
|
||||
{
|
||||
real costo = get_real(ANAMAG_ULTCOS1);
|
||||
|
||||
costo = (costo + get_real(ANAMAG_ULTCOS2)) / 2.0;
|
||||
return costo == ZERO ? costo_standard(annoes) : costo;
|
||||
}
|
||||
return ZERO;
|
||||
// else
|
||||
// {
|
||||
// TRectype & rec = _storico->row(index);
|
||||
// real costo = rec.get_real(STOMAG_ULTCOS1);
|
||||
//
|
||||
// costo = (costo + rec.get_real(STOMAG_ULTCOS2)) / 2.0;
|
||||
// return costo == ZERO ? costo_standard(annoes) : costo;
|
||||
// }
|
||||
else
|
||||
{
|
||||
const int index = find_storico(annoes, annoes);
|
||||
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 == ZERO ? costo_standard(annoes) : costo;
|
||||
}
|
||||
}
|
||||
|
||||
real TArticolo_giacenza::prezzo_listino(const char * annoes, const char * catven, const char * codlist) const
|
||||
{
|
||||
int index = find_storico(annoes, annoes);
|
||||
|
||||
if (index < 0)
|
||||
if (last_esercizio != atoi(annoes))
|
||||
{
|
||||
static TString16 f;
|
||||
if (f.empty())
|
||||
f.format("#%d->%s", LF_UMART, UMART_PREZZO);
|
||||
return get_real(f); // da terminare
|
||||
}
|
||||
return ZERO;
|
||||
// else
|
||||
// return _storico->row(index).get_real(STOMAG_VALVEN);
|
||||
else
|
||||
{
|
||||
const int index = find_storico(annoes, annoes);
|
||||
|
||||
return storico(annoes).row(index).get_real(STOMAG_PRZLIST);
|
||||
}
|
||||
}
|
||||
|
||||
real TArticolo_giacenza::costo_standard(const char * annoes) const
|
||||
{
|
||||
int index = find_storico(annoes, annoes);
|
||||
|
||||
if (index < 0)
|
||||
if (last_esercizio != atoi(annoes))
|
||||
return get_real(ANAMAG_COSTSTD);
|
||||
return ZERO;
|
||||
// else
|
||||
// return _storico->row(index).get_real(STOMAG_COSTSTD);
|
||||
else
|
||||
{
|
||||
const int index = find_storico(annoes, annoes);
|
||||
return storico(annoes).row(index).get_real(STOMAG_COSTSTD);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
real TArticolo_giacenza::costo_medio(const char * annoes, const char * codmag, const char * livello) const
|
||||
{
|
||||
real acq;
|
||||
real valacq;
|
||||
real valacq;
|
||||
TRecord_array & rmag = mag(annoes);
|
||||
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
||||
{
|
||||
const TRectype & rec = _mag->row(i);
|
||||
const TRectype & rec = rmag.row(i);
|
||||
|
||||
acq += rec.get_real(MAG_ACQ);
|
||||
valacq += rec.get_real(MAG_VALACQ);
|
||||
@ -416,9 +547,10 @@ real TArticolo_giacenza::LIFO_annuale(const char * annoes, const char * codmag,
|
||||
real acq;
|
||||
real valacq;
|
||||
real giacenza;
|
||||
TRecord_array & rmag = mag(annoes);
|
||||
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
||||
{
|
||||
const TRectype & rec = _mag->row(i);
|
||||
const TRectype & rec = rmag.row(i);
|
||||
|
||||
rim += rec.get_real(MAG_RIM);
|
||||
valrim += rec.get_real(MAG_VALRIM);
|
||||
@ -448,9 +580,10 @@ real TArticolo_giacenza::FIFO_annuale(const char * annoes, const char * codmag,
|
||||
real acq;
|
||||
real valacq;
|
||||
real giacenza;
|
||||
TRecord_array & rmag = mag(annoes);
|
||||
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
||||
{
|
||||
const TRectype & rec = _mag->row(i);
|
||||
const TRectype & rec = rmag.row(i);
|
||||
|
||||
rim += rec.get_real(MAG_RIM);
|
||||
valrim += rec.get_real(MAG_VALRIM);
|
||||
@ -481,9 +614,10 @@ real TArticolo_giacenza::LIFO(const char * annoes, const char * codmag, const ch
|
||||
real acq;
|
||||
real valacq;
|
||||
real giacenza;
|
||||
TRecord_array & rmag = mag(annoes);
|
||||
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
||||
{
|
||||
const TRectype & rec = _mag->row(i);
|
||||
const TRectype & rec = rmag.row(i);
|
||||
|
||||
rim += rec.get_real(MAG_RIM);
|
||||
valrim += rec.get_real(MAG_VALRIM);
|
||||
@ -504,13 +638,13 @@ real TArticolo_giacenza::LIFO(const char * annoes, const char * codmag, const ch
|
||||
if (giacenza > rim)
|
||||
return ((giacenza - rim) * (acq == ZERO ? costo_standard(annoes) : valacq / acq) + valrim) / giacenza;
|
||||
|
||||
((TArticolo_giacenza *) this)->load_storico(annoes);
|
||||
const int last = _storico->last_row();
|
||||
TRecord_array & rstorico = storico(annoes);
|
||||
const int last = rstorico.last_row();
|
||||
|
||||
rim = giacenza;
|
||||
for (i = _storico->first_row(); i <= last; i = _storico->succ_row(i))
|
||||
for (i = rstorico.first_row(); i <= last; i = rstorico.succ_row(i))
|
||||
{
|
||||
const TRectype & rec = _storico->row(i);
|
||||
const TRectype & rec = rstorico.row(i);
|
||||
const real qta = rec.get(STOMAG_QUANT);
|
||||
|
||||
if (qta > giacenza)
|
||||
@ -535,9 +669,10 @@ real TArticolo_giacenza::FIFO(const char * annoes, const char * codmag, const ch
|
||||
real acq;
|
||||
real valacq;
|
||||
real giacenza;
|
||||
TRecord_array & rmag = mag(annoes);
|
||||
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
||||
{
|
||||
const TRectype & rec = _mag->row(i);
|
||||
const TRectype & rec = rmag.row(i);
|
||||
|
||||
rim += rec.get_real(MAG_RIM);
|
||||
valrim += rec.get_real(MAG_VALRIM);
|
||||
@ -558,16 +693,16 @@ real TArticolo_giacenza::FIFO(const char * annoes, const char * codmag, const ch
|
||||
if (giacenza <= acq)
|
||||
return valacq / acq;
|
||||
|
||||
((TArticolo_giacenza *) this)->load_storico(annoes);
|
||||
TRecord_array & rstorico = storico(annoes);
|
||||
|
||||
const int last = _storico->last_row();
|
||||
const int last = rstorico.last_row();
|
||||
|
||||
real res = giacenza - acq;
|
||||
rim = ZERO;
|
||||
valrim = ZERO;
|
||||
for (i = last; i > 0; i--)
|
||||
{
|
||||
const TRectype & rec = _storico->row(i);
|
||||
const TRectype & rec = rstorico.row(i);
|
||||
const real qta = rec.get(STOMAG_QUANT);
|
||||
|
||||
if (qta > res)
|
||||
@ -585,10 +720,38 @@ real TArticolo_giacenza::FIFO(const char * annoes, const char * codmag, const ch
|
||||
return ((giacenza - acq) * (valrim / rim) + valacq) / giacenza;
|
||||
}
|
||||
|
||||
TArticolo_giacenza::~TArticolo_giacenza()
|
||||
real TArticolo_giacenza::FIFO_ragionieristico(const char * annoes, const char * codmag, const char * livello,
|
||||
bool giacenza_effettiva, bool valorizza_componenti) const
|
||||
{
|
||||
if (_mag)
|
||||
delete _mag;
|
||||
return ZERO;
|
||||
}
|
||||
|
||||
real TArticolo_giacenza::LIFO_ragionieristico(const char * annoes, const char * codmag, const char * livello,
|
||||
bool giacenza_effettiva, bool valorizza_componenti) const
|
||||
{
|
||||
return ZERO;
|
||||
}
|
||||
|
||||
TArticolo_giacenza::TArticolo_giacenza(const char* codice)
|
||||
: TArticolo(codice)
|
||||
{
|
||||
if (last_esercizio < 0 )
|
||||
{
|
||||
TEsercizi_contabili e;
|
||||
|
||||
last_esercizio = e.last();
|
||||
}
|
||||
}
|
||||
|
||||
TArticolo_giacenza::TArticolo_giacenza(const TRectype& rec)
|
||||
: TArticolo(rec)
|
||||
{
|
||||
if (last_esercizio < 0 )
|
||||
{
|
||||
TEsercizi_contabili e;
|
||||
|
||||
last_esercizio = e.last();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
174
mg/mglib02.h
174
mg/mglib02.h
@ -12,6 +12,14 @@
|
||||
#include <recarray.h>
|
||||
#endif
|
||||
|
||||
#ifndef __VARREC_H
|
||||
#include <varrec.h>
|
||||
#endif
|
||||
|
||||
#ifndef __MSKSHEET_H
|
||||
#include <msksheet.h>
|
||||
#endif
|
||||
|
||||
#ifndef __ANAMAG_H
|
||||
#include "anamag.h"
|
||||
#endif
|
||||
@ -35,51 +43,139 @@
|
||||
#ifndef __STOMAG_H
|
||||
#include "stomag.h"
|
||||
#endif
|
||||
class TMultiple_rectype ;
|
||||
//**************************************
|
||||
// classe per il controllo dei record composti da una testata e N file di righe
|
||||
// è implementato come un TRectype che contiene anche un TRecord_array
|
||||
//
|
||||
class TMultiple_rectype : public TAuto_variable_rectype
|
||||
{
|
||||
enum { maxfiles = 20};
|
||||
// @ cmember Array di TRecord array per le righe
|
||||
TArray _files; //
|
||||
// @ cmember flag indicatore di record nuovo
|
||||
bool _nuovo;
|
||||
// @ cmember numero di file righe
|
||||
short _nfiles;
|
||||
// @ cmember file delle righe
|
||||
int _logicnums[maxfiles];
|
||||
// @ cmember Array di nomi di campo "numeratore" delle righe
|
||||
TString_array _numfields;
|
||||
|
||||
|
||||
protected:
|
||||
const TArray & files() const { return _files;}
|
||||
// @ cmember funzione per costruire la chiave delle righe
|
||||
virtual void set_body_key(TRectype & rowrec) pure;
|
||||
// @ cmember renumber la chiave del corpo
|
||||
virtual long renum(long numdoc = -1) { return -1; }
|
||||
virtual TRectype & get_body_record(int logicnum = 0) { return *(new TRectype(logicnum ? logicnum : _logicnums[0])); }
|
||||
virtual void load_rows_file(int logicnum);
|
||||
// @cmember Ritorna l'indice di <p _files> del numero logico passato
|
||||
int log2ind(int logicnum) const;
|
||||
virtual int find(int logicnum, const char * fieldname, const char * s, int from = 0, bool reverse = FALSE) const ;
|
||||
virtual int write_rewrite(TBaseisamfile& f, bool re = FALSE) const;
|
||||
void remove_body(int logicnum);
|
||||
|
||||
public:
|
||||
//***********************
|
||||
// struttura
|
||||
// @ cmember restituisce il record di testata
|
||||
const TAuto_variable_rectype& head() const { return *this; } // Ritorna la testata del documento
|
||||
// @ cmember restituisce il record di testata
|
||||
TAuto_variable_rectype& head() { return *this; } // Ritorna la testata del documento
|
||||
|
||||
|
||||
// @ cmember restituisce il record array del corpo
|
||||
TRecord_array & body(int logicnum = 0) const;
|
||||
// @ cmember restituisce il numero di record nel corpo
|
||||
int rows(int logicnum = 0) const { return body(logicnum).rows(); }
|
||||
|
||||
// @ cmember restituisce il record n-esimo del del corpo
|
||||
virtual const TRecord_array & operator[](int logicnum) const { return (const TRecord_array &)((TMultiple_rectype *)this)->body(logicnum); }
|
||||
// @ cmember restituisce il record n-esimo del del corpo
|
||||
virtual TRecord_array & operator[](int logicnum) { return (TRecord_array &)body(logicnum); }
|
||||
|
||||
bool destroy_row(int n, bool pack = FALSE, int logicnum = 0) { return body(logicnum).destroy_row(n, pack); }
|
||||
void destroy_rows(int logicnum = 0) { body(logicnum).destroy_rows(); }
|
||||
|
||||
//***********************
|
||||
// record e I/O
|
||||
virtual void dirty_fields() {}
|
||||
virtual void set_fields(TAuto_variable_rectype & rec) {}
|
||||
virtual void reset_fields(TAuto_variable_rectype & rec) { rec.remove_field(); }
|
||||
|
||||
virtual void renum_key(const char * kfield,const char * val);
|
||||
virtual TRectype & operator =(const TRectype & r);
|
||||
virtual TRectype & operator =(const char * r);
|
||||
virtual void zero(char c = '\0');
|
||||
|
||||
virtual int read(TRectype & rec, word op = _isequal, word lockop = _nolock);
|
||||
virtual int read(word op = _isequal, word lockop = _nolock) { return read(*this, op, lockop); }
|
||||
int read(TBaseisamfile & f, word op = _isequal, word lockop = _nolock) { return read(f.curr(), op, lockop); }
|
||||
|
||||
virtual int write(TBaseisamfile& f) const;
|
||||
virtual int rewrite(TBaseisamfile& f) const;
|
||||
virtual int remove(TBaseisamfile& f) const;
|
||||
|
||||
int write() const { TBaseisamfile f(num()); return write(f);}
|
||||
int rewrite() const { TBaseisamfile f(num()); return rewrite(f);}
|
||||
int remove() const { TBaseisamfile f(num()); return remove(f);}
|
||||
|
||||
|
||||
void add_file(int logicnum, const char * numfield);
|
||||
//**************************
|
||||
// @ cmember costruttore dal numero del file
|
||||
TMultiple_rectype(int hfn);
|
||||
// @ cmember costruttore dal file
|
||||
TMultiple_rectype(const TBaseisamfile* file);
|
||||
// @ cmember costruttore dal record
|
||||
TMultiple_rectype(const TRectype & rec);
|
||||
// @ cmember costruttore di copia
|
||||
TMultiple_rectype(const TMultiple_rectype& r);
|
||||
virtual ~TMultiple_rectype() {}
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
valorizz_ultcos , valorizz_mediacos , valorizz_przlist ,
|
||||
valorizz_coststd , valorizz_costmedio ,
|
||||
valorizz_FIFOa , valorizz_LIFOa ,
|
||||
valorizz_FIFO , valorizz_LIFO
|
||||
valorizz_ultcos , valorizz_mediacos , valorizz_przlist ,
|
||||
valorizz_coststd , valorizz_costmedio ,
|
||||
valorizz_FIFOa , valorizz_LIFOa ,
|
||||
valorizz_FIFO , valorizz_LIFO,
|
||||
valorizz_FIFOr , valorizz_LIFOr
|
||||
} TTipo_valorizz;
|
||||
|
||||
char * TNome_valorizz[]= {
|
||||
"Ultimo costo", "Media ultimi costi", "Prezzo di listino",
|
||||
"Costo standard", "Costo medio" ,
|
||||
"FIFO annuale","LIFO annuale",
|
||||
"FIFO","LIFO"
|
||||
"Ultimo costo", "Media ultimi costi", "Prezzo di listino",
|
||||
"Costo standard", "Costo medio" ,
|
||||
"FIFO annuale", "LIFO annuale",
|
||||
"FIFO", "LIFO",
|
||||
"FIFO Ragionieristico", "LIFO Ragionieristico"
|
||||
} ;
|
||||
|
||||
class TArticolo : public TRectype
|
||||
class TArticolo : public TMultiple_rectype
|
||||
{
|
||||
TRecfield * _codice;
|
||||
TRecord_array * _um;
|
||||
TRecord_array * _codcorr;
|
||||
TRecord_array * _deslin;
|
||||
|
||||
protected:
|
||||
bool load_um();
|
||||
bool load_codcorr();
|
||||
bool load_deslin();
|
||||
virtual const TString & get_str(const char* fieldname) const ;
|
||||
int find(const TRecord_array & array, const char * fieldname, const char * s,
|
||||
int from = 0) const ;
|
||||
virtual void set_body_key(TRectype & rowrec);
|
||||
|
||||
public:
|
||||
|
||||
virtual int read(const char* cod);
|
||||
virtual int read(const char * cod, word op = _isequal, word lockop = _nolock);
|
||||
virtual int read(TRectype & rec, word op = _isequal, word lockop = _nolock) { return read( rec.get(ANAMAG_CODART), op, lockop); }
|
||||
|
||||
TObject* dup() const { return new TArticolo(codice()); }
|
||||
|
||||
const TString& codice() const { return (const char *) *_codice;}
|
||||
const TString& descrizione(const char * lingua = NULL) const;
|
||||
|
||||
int find_um(const char * um, int from = 0) const { return find(*_um, UMART_UM, um, from); }
|
||||
int find_deslin(const char * deslin, int from = 0) const { ((TArticolo *) this)->load_deslin(); return find(*_deslin, DESLIN_CODLIN, deslin, from); }
|
||||
int find_codcorr(const char * codcorr, int from = 0) const { ((TArticolo *) this)->load_codcorr(); return find(*_codcorr, CODCORR_CODARTALT, codcorr, from); }
|
||||
TRectype & um_row(int i) const { ((TArticolo *) this)->load_um(); return (TRectype &) _um->row(i); }
|
||||
TRectype & deslin_row(int i) const { ((TArticolo *) this)->load_deslin(); return (TRectype &) _deslin->row(i); }
|
||||
TRectype & codcorr_row(int i) const { ((TArticolo *) this)->load_codcorr(); return (TRectype &) _codcorr->row(i); }
|
||||
int find_um(const char * um, int from = 0) const { return find(LF_UMART, UMART_UM, um, from); }
|
||||
int find_deslin(const char * deslin, int from = 0) const { return find(LF_DESLIN, DESLIN_CODLIN, deslin, from); }
|
||||
int find_codcorr(const char * codcorr, int from = 0) const { return find(LF_CODCORR, CODCORR_CODARTALT, codcorr, from); }
|
||||
TRecord_array & um() const { return body(LF_UMART); }
|
||||
TRecord_array & deslin() const { return body(LF_DESLIN); }
|
||||
TRecord_array & codcorr() const { return body(LF_CODCORR); }
|
||||
|
||||
TArticolo(const char* codice = NULL);
|
||||
TArticolo(const TRectype& rec);
|
||||
@ -88,24 +184,26 @@ public:
|
||||
|
||||
class TArticolo_giacenza : public TArticolo
|
||||
{
|
||||
TRecord_array * _mag;
|
||||
TRecord_array * _storico;
|
||||
TString16 _anno_mag;
|
||||
TString16 _anno_sto;
|
||||
|
||||
protected:
|
||||
bool load_mag(const char * annoes);
|
||||
bool load_storico(const char * annoesrif);
|
||||
virtual const TString & get_str(const char* fieldname) const ;
|
||||
virtual void set_body_key(TRectype & rowrec);
|
||||
void set_anno_mag (const char * anno = NULL);
|
||||
void set_anno_sto (const char * anno = NULL);
|
||||
void reset_anno_mag () { set_anno_mag();}
|
||||
void reset_anno_sto () { set_anno_sto();}
|
||||
|
||||
public:
|
||||
|
||||
virtual int read(const char* cod);
|
||||
|
||||
TObject* dup() const { return new TArticolo_giacenza(codice()); }
|
||||
virtual void zero(char c = '\0');
|
||||
|
||||
int find_mag(const char * annoes, const char * codmag = NULL, const char * livello = NULL, int from = 0) const ;
|
||||
int find_storico(const char * annoesrif, const char * annoes = NULL, int from = 0) const { ((TArticolo_giacenza *) this)->load_storico(annoesrif); return find(*_storico, STOMAG_ANNOES, annoes, from); }
|
||||
TRectype & mag_row(const char * annoes, int i) const { ((TArticolo_giacenza *) this)->load_mag(annoes); return (TRectype &) _mag->row(i); }
|
||||
TRectype & storico_row(const char * annoesrif, int i) const { ((TArticolo_giacenza *) this)->load_storico(annoesrif); return (TRectype &) _storico->row(i); }
|
||||
int find_storico(const char * annoesrif, const char * annoes = NULL, int from = 0) const;
|
||||
TRecord_array & mag(const char * annoes) const;
|
||||
TRecord_array & storico(const char * annoesrif) const;
|
||||
|
||||
real ultimo_costo(const char * annoes) const;
|
||||
real media_costi(const char * annoes) const;
|
||||
@ -120,10 +218,14 @@ public:
|
||||
bool giacenza_effettiva = TRUE, bool valorizza_componenti = TRUE) const;
|
||||
real FIFO(const char * annoes, const char * codmag, const char * livello,
|
||||
bool giacenza_effettiva = TRUE, bool valorizza_componenti = TRUE) const;
|
||||
real LIFO_ragionieristico(const char * annoes, const char * codmag, const char * livello,
|
||||
bool giacenza_effettiva = TRUE, bool valorizza_componenti = TRUE) const;
|
||||
real FIFO_ragionieristico(const char * annoes, const char * codmag, const char * livello,
|
||||
bool giacenza_effettiva = TRUE, bool valorizza_componenti = TRUE) const;
|
||||
|
||||
TArticolo_giacenza(const char* codice = NULL) : TArticolo(codice), _mag(NULL), _storico(NULL) {}
|
||||
TArticolo_giacenza(const TRectype& rec) : TArticolo(rec), _mag(NULL), _storico(NULL) {}
|
||||
virtual ~TArticolo_giacenza();
|
||||
TArticolo_giacenza(const char* codice = NULL);
|
||||
TArticolo_giacenza(const TRectype& rec);
|
||||
virtual ~TArticolo_giacenza() {}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
10
mg/stomag.h
10
mg/stomag.h
@ -1,5 +1,5 @@
|
||||
#ifndef __STOMAG_H
|
||||
#define __STOMAG_H
|
||||
#ifndef __STOMAG_H
|
||||
#define __STOMAG_H
|
||||
|
||||
#define STOMAG_ANNOESRIF "ANNOESRIF"
|
||||
#define STOMAG_CODART "CODART"
|
||||
@ -9,4 +9,10 @@
|
||||
#define STOMAG_VALORE "VALORE"
|
||||
#define STOMAG_NRIGA "NRIGA"
|
||||
|
||||
#define STOMAG_ULTCOS1 "ULTCOS1"
|
||||
#define STOMAG_ULTCOS2 "ULTCOS2"
|
||||
#define STOMAG_COSTSTD "COSTSTD"
|
||||
#define STOMAG_COSTOMEDIO "COSTOMEDIO"
|
||||
#define STOMAG_PRZLIST "PRZLIST"
|
||||
#define STOMAG_CODLISTINO "CODLISTINO"
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user