1997-06-23 14:51:53 +00:00
|
|
|
|
// oggetto TArticolo, multirecord dell'articolo di anagrafica magazzino
|
|
|
|
|
// oggetto TArticolo_giacenza, multirecord dell'articolo di magazzino
|
1997-06-27 12:58:13 +00:00
|
|
|
|
// oggetto TMov_Mag , multirecord del movimento di magazzino
|
1997-06-23 14:51:53 +00:00
|
|
|
|
// funzione di ricostruzione saldi
|
1997-06-06 16:36:35 +00:00
|
|
|
|
#include "mglib.h"
|
|
|
|
|
#include "anamag.h"
|
|
|
|
|
#include "mag.h"
|
1997-06-23 14:51:53 +00:00
|
|
|
|
#include "movmag.h"
|
1997-06-27 12:58:13 +00:00
|
|
|
|
#include "rmovmag.h"
|
1997-06-06 16:36:35 +00:00
|
|
|
|
|
1997-06-18 15:18:06 +00:00
|
|
|
|
// libreria per i movimenti
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
1997-06-18 15:18:06 +00:00
|
|
|
|
char * Nome_valorizz[]= {
|
1997-06-04 14:27:02 +00:00
|
|
|
|
"Ultimo costo", "Media ultimi costi", "Prezzo di listino",
|
|
|
|
|
"Costo standard", "Costo medio" ,
|
|
|
|
|
"FIFO annuale", "LIFO annuale",
|
|
|
|
|
"FIFO", "LIFO",
|
|
|
|
|
"FIFO Ragionieristico", "LIFO Ragionieristico"
|
|
|
|
|
} ;
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
|
1997-06-06 16:36:35 +00:00
|
|
|
|
HIDDEN TString16 _mg_null_str;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const TString & TArticolo::get_str(const char* fieldname) const
|
|
|
|
|
{
|
|
|
|
|
if (*fieldname != '#')
|
|
|
|
|
return TRectype::get_str(fieldname);
|
|
|
|
|
char * fname = (char *) fieldname + 1;
|
|
|
|
|
const int logicnum = atoi(fname);
|
|
|
|
|
const char * op1 = strchr(fname, '_');
|
|
|
|
|
int index = 0;
|
|
|
|
|
if (op1 && *op1 == '#')
|
|
|
|
|
index = atoi(fname + 1);
|
|
|
|
|
const char* op2 = strstr(fname, "->");
|
|
|
|
|
CHECKS(op2, "Can't find '->' in string ", fieldname);
|
|
|
|
|
|
|
|
|
|
switch (logicnum)
|
|
|
|
|
{
|
|
|
|
|
case LF_UMART:
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
if (index == 0)
|
|
|
|
|
index = find_um(op1);
|
|
|
|
|
if (index > 0 && op2)
|
|
|
|
|
return um().row(index).get(op2);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case LF_CODCORR:
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
if (index == 0)
|
|
|
|
|
index = find_codcorr(op1);
|
|
|
|
|
if (index > 0 && op2)
|
|
|
|
|
return codcorr().row(index).get(op2);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case LF_DESLIN:
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
if (index == 0)
|
|
|
|
|
index = find_deslin(op1);
|
|
|
|
|
if (index > 0 && op2)
|
|
|
|
|
return deslin().row(index).get(op2);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return _mg_null_str;
|
|
|
|
|
}
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
void TArticolo::set_body_key(TRectype & rowrec)
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
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;
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-18 15:23:13 +00:00
|
|
|
|
int TArticolo::read(TRectype & rec, word op, word lockop)
|
|
|
|
|
{
|
|
|
|
|
if (op == _isequal && lockop == _nolock &&strcmp(rec.get(ANAMAG_CODART), (const char *) _codice) == 0)
|
1997-05-27 11:12:10 +00:00
|
|
|
|
return NOERR;
|
1997-06-18 15:23:13 +00:00
|
|
|
|
|
|
|
|
|
*_codice = rec.get(ANAMAG_CODART);
|
1997-05-30 15:26:08 +00:00
|
|
|
|
|
1997-06-18 15:23:13 +00:00
|
|
|
|
const int err = TMultiple_rectype::read(rec, op , lockop);
|
1997-05-30 15:26:08 +00:00
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
if (err != NOERR)
|
|
|
|
|
zero();
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-18 15:23:13 +00:00
|
|
|
|
int TArticolo::read(const char * cod, word op, word lockop)
|
|
|
|
|
{
|
|
|
|
|
put(ANAMAG_CODART,cod);
|
|
|
|
|
return read( *this, op, lockop);
|
|
|
|
|
}
|
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
const TString & TArticolo::descrizione(const char* lingua) const
|
|
|
|
|
{
|
|
|
|
|
if (lingua && *lingua)
|
|
|
|
|
{
|
|
|
|
|
TString16 f; f.format("#%d_%s->%s", LF_DESLIN, lingua, DESLIN_DESCR);
|
|
|
|
|
|
|
|
|
|
return get(f);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return get(ANAMAG_DESCR);
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-04 14:27:02 +00:00
|
|
|
|
|
|
|
|
|
void TArticolo::update_ultcosti(real costo,TDate data)
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
TDate data1(get_date(ANAMAG_DULTCOS1));
|
|
|
|
|
if (data>= data1)
|
|
|
|
|
{
|
|
|
|
|
real costo1(get_real(ANAMAG_ULTCOS1));
|
|
|
|
|
put(ANAMAG_DULTCOS1,data);
|
|
|
|
|
put(ANAMAG_ULTCOS1,costo);
|
|
|
|
|
put(ANAMAG_DULTCOS2,data1);
|
|
|
|
|
put(ANAMAG_ULTCOS2,costo1);
|
|
|
|
|
} else {
|
|
|
|
|
if (data>= get_date(ANAMAG_DULTCOS2))
|
|
|
|
|
put(ANAMAG_DULTCOS2,data);
|
|
|
|
|
put(ANAMAG_ULTCOS2,costo);
|
|
|
|
|
}
|
1997-06-04 14:27:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TArticolo::unlock()
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
bool rv;
|
1997-06-04 14:27:02 +00:00
|
|
|
|
if (*(const char *)_codice)
|
1997-06-18 15:18:06 +00:00
|
|
|
|
{
|
|
|
|
|
TLocalisamfile anag(LF_ANAMAG);
|
|
|
|
|
anag.curr()=*this;
|
|
|
|
|
rv=(anag.read(_isequal,_unlock)==NOERR);
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
1997-06-04 14:27:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TArticolo::lock_and_prompt()
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
TString mess;
|
|
|
|
|
mess << "Il record di anagrafica dell'articolo ''"<< codice() << "'' risulta essere gi<67> in uso.\n Interrompo ?";
|
|
|
|
|
TTimed_breakbox bbox((const char *)mess,10);
|
|
|
|
|
do {
|
|
|
|
|
TLocalisamfile anag(LF_ANAMAG);
|
|
|
|
|
anag.curr()=*this;
|
|
|
|
|
if (anag.read(_isequal,_testandlock)==NOERR)
|
|
|
|
|
return TRUE;
|
|
|
|
|
} while (bbox.run()!=K_ESC);
|
|
|
|
|
return FALSE;
|
1997-06-04 14:27:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
TArticolo::TArticolo(const char* codice)
|
1997-05-30 15:26:08 +00:00
|
|
|
|
: TMultiple_rectype(LF_ANAMAG)
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
add_file(LF_UMART,"NRIGA");
|
|
|
|
|
add_file(LF_CODCORR,"NRIGA");
|
|
|
|
|
add_file(LF_DESLIN,"NRIGA");
|
1997-05-27 11:12:10 +00:00
|
|
|
|
_codice = new TRecfield(*this, ANAMAG_CODART);
|
|
|
|
|
if (codice && *codice)
|
|
|
|
|
read(codice);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TArticolo::TArticolo(const TRectype& rec)
|
1997-05-30 15:26:08 +00:00
|
|
|
|
: TMultiple_rectype(rec)
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
|
|
|
|
_codice = new TRecfield(*this, ANAMAG_CODART);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TArticolo::~TArticolo()
|
|
|
|
|
{
|
|
|
|
|
delete _codice;
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-06 16:36:35 +00:00
|
|
|
|
// *****************
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
const TString & TArticolo_giacenza::get_str(const char* fieldname) const
|
|
|
|
|
{
|
|
|
|
|
if (*fieldname != '#')
|
|
|
|
|
return TRectype::get_str(fieldname);
|
|
|
|
|
char * fname = (char *) fieldname + 1;
|
|
|
|
|
const int logicnum = atoi(fname);
|
|
|
|
|
const char * op1 = strchr(fname, '_');
|
|
|
|
|
int index = 0;
|
|
|
|
|
if (op1 && *op1 == '#')
|
|
|
|
|
index = atoi(fname + 1);
|
|
|
|
|
fname = (char *) op1 + 1;
|
|
|
|
|
const char * op2 = strchr(fname, '_');
|
|
|
|
|
fname = (char *) op2 + 1;
|
|
|
|
|
const char * op3 = strchr(fname, '_');
|
|
|
|
|
const char * op4 = strstr(fname, "->");
|
|
|
|
|
CHECKS(op4, "Can't find '->' in string ", fieldname);
|
|
|
|
|
|
|
|
|
|
switch (logicnum)
|
|
|
|
|
{
|
|
|
|
|
case LF_MAG:
|
1997-05-30 15:26:08 +00:00
|
|
|
|
if (index == 0)
|
|
|
|
|
index = find_mag(op1, op2, op3);
|
|
|
|
|
if (index > 0 && op3)
|
|
|
|
|
return mag(op1).row(index).get(op4);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
break;
|
|
|
|
|
case LF_STOMAG:
|
1997-05-30 15:26:08 +00:00
|
|
|
|
if (index = 0)
|
|
|
|
|
index = find_storico(op1, op2);
|
|
|
|
|
if (index > 0)
|
|
|
|
|
return storico(op1).row(index).get(op4);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return TArticolo::get_str(fieldname);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return _mg_null_str;
|
|
|
|
|
}
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
int TArticolo_giacenza::find_mag(const char * annoes, const char * codmag, const char * livello, int from) const
|
1997-05-30 15:26:08 +00:00
|
|
|
|
{
|
|
|
|
|
TRecord_array & rmag = mag(annoes);
|
|
|
|
|
const int last = rmag.last_row();
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
if (from <= last)
|
|
|
|
|
{
|
|
|
|
|
const int codmag_len = codmag ? strlen(codmag) : 0;
|
|
|
|
|
const int livello_len = livello ? strlen(livello) : 0;
|
|
|
|
|
|
|
|
|
|
if (codmag_len == 0 && livello_len == 0)
|
|
|
|
|
return from + 1;
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
for (int i = rmag.succ_row(from); i <= last; i = rmag.succ_row(i))
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rmag.row(i);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
1997-07-02 10:53:23 +00:00
|
|
|
|
int TArticolo_giacenza::find_storico(const char * annoesrif, const char * annoes, const char * codmag, int from) const
|
1997-05-30 15:26:08 +00:00
|
|
|
|
{
|
1997-07-02 10:53:23 +00:00
|
|
|
|
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;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
real TArticolo_giacenza::ultimo_costo(const char * annoes) const
|
|
|
|
|
{
|
|
|
|
|
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (last_esercizio == atoi(annoes))
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
|
|
|
|
const real costo = get_real(ANAMAG_ULTCOS1);
|
|
|
|
|
return costo == ZERO ? costo_standard(annoes) : costo;
|
|
|
|
|
}
|
1997-05-30 15:26:08 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const int index = find_storico(annoes, annoes);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (index < 0 ) return ZERO;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const real costo = storico(annoes).row(index).get_real(STOMAG_ULTCOS1);
|
|
|
|
|
return costo == ZERO ? costo_standard(annoes) : costo;
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
real TArticolo_giacenza::media_costi(const char * annoes) const
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (last_esercizio == atoi(annoes))
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
|
|
|
|
real costo = get_real(ANAMAG_ULTCOS1);
|
|
|
|
|
|
|
|
|
|
costo = (costo + get_real(ANAMAG_ULTCOS2)) / 2.0;
|
|
|
|
|
return costo == ZERO ? costo_standard(annoes) : costo;
|
|
|
|
|
}
|
1997-05-30 15:26:08 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const int index = find_storico(annoes, annoes);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (index < 0 ) return ZERO;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-05-28 10:14:39 +00:00
|
|
|
|
real TArticolo_giacenza::prezzo_listino(const char * annoes, const char * catven, const char * codlist) const
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (last_esercizio == atoi(annoes))
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
|
|
|
|
static TString16 f;
|
|
|
|
|
if (f.empty())
|
|
|
|
|
f.format("#%d->%s", LF_UMART, UMART_PREZZO);
|
1997-05-28 10:14:39 +00:00
|
|
|
|
return get_real(f); // da terminare
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
1997-05-30 15:26:08 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const int index = find_storico(annoes, annoes);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (index < 0 ) return ZERO;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
return storico(annoes).row(index).get_real(STOMAG_PRZLIST);
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
real TArticolo_giacenza::costo_standard(const char * annoes) const
|
|
|
|
|
{
|
|
|
|
|
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (last_esercizio == atoi(annoes))
|
1997-05-27 11:12:10 +00:00
|
|
|
|
return get_real(ANAMAG_COSTSTD);
|
1997-05-30 15:26:08 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const int index = find_storico(annoes, annoes);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (index < 0 ) return ZERO;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
return storico(annoes).row(index).get_real(STOMAG_COSTSTD);
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
real TArticolo_giacenza::costo_medio(const char * annoes, const char * codmag, const char * livello) const
|
|
|
|
|
{
|
|
|
|
|
real acq;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
real valacq;
|
|
|
|
|
TRecord_array & rmag = mag(annoes);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rmag.row(i);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
acq += rec.get_real(MAG_ACQ);
|
|
|
|
|
valacq += rec.get_real(MAG_VALACQ);
|
|
|
|
|
}
|
|
|
|
|
return acq == ZERO ? costo_standard(annoes) : valacq / acq;
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-18 15:18:06 +00:00
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
real TArticolo_giacenza::LIFO_annuale(const char * annoes, const char * codmag, const char * livello,
|
|
|
|
|
bool giacenza_effettiva, bool valorizza_componenti) const
|
|
|
|
|
{
|
|
|
|
|
real rim;
|
|
|
|
|
real valrim;
|
|
|
|
|
real acq;
|
|
|
|
|
real valacq;
|
|
|
|
|
real giacenza;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
TRecord_array & rmag = mag(annoes);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rmag.row(i);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
rim += rec.get_real(MAG_RIM);
|
|
|
|
|
valrim += rec.get_real(MAG_VALRIM);
|
|
|
|
|
acq += rec.get_real(MAG_ACQ);
|
|
|
|
|
valacq += rec.get_real(MAG_VALACQ);
|
1997-07-30 13:28:22 +00:00
|
|
|
|
giacenza += giacenza_corretta(rec,giacenza_effettiva,valorizza_componenti);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
if (giacenza <= ZERO)
|
|
|
|
|
return ZERO;
|
|
|
|
|
if (giacenza > rim)
|
|
|
|
|
return ((giacenza - rim) * (acq == ZERO ? costo_standard(annoes) : valacq / acq) + valrim) / giacenza;
|
|
|
|
|
return valrim / rim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
real TArticolo_giacenza::FIFO_annuale(const char * annoes, const char * codmag, const char * livello,
|
|
|
|
|
bool giacenza_effettiva, bool valorizza_componenti) const
|
|
|
|
|
{
|
|
|
|
|
real rim;
|
|
|
|
|
real valrim;
|
|
|
|
|
real acq;
|
|
|
|
|
real valacq;
|
|
|
|
|
real giacenza;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
TRecord_array & rmag = mag(annoes);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rmag.row(i);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
rim += rec.get_real(MAG_RIM);
|
|
|
|
|
valrim += rec.get_real(MAG_VALRIM);
|
|
|
|
|
acq += rec.get_real(MAG_ACQ);
|
|
|
|
|
valacq += rec.get_real(MAG_VALACQ);
|
|
|
|
|
giacenza += rec.get_real(MAG_GIAC);
|
|
|
|
|
if (giacenza_effettiva)
|
|
|
|
|
{
|
|
|
|
|
giacenza += rec.get_real(MAG_INCL);
|
|
|
|
|
giacenza -= rec.get_real(MAG_ACL);
|
|
|
|
|
giacenza += valorizza_componenti ? rec.get_real(MAG_PRODCOMP) : rec.get_real(MAG_PRODFIN);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (giacenza <= ZERO)
|
|
|
|
|
return ZERO;
|
|
|
|
|
|
|
|
|
|
if (giacenza > acq)
|
|
|
|
|
return ((giacenza - acq) * (valrim / rim) + valacq) / giacenza;
|
|
|
|
|
return valacq / acq;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
real TArticolo_giacenza::LIFO(const char * annoes, const char * codmag, const char * livello,
|
|
|
|
|
bool giacenza_effettiva, bool valorizza_componenti) const
|
|
|
|
|
{
|
|
|
|
|
real rim;
|
|
|
|
|
real valrim;
|
|
|
|
|
real acq;
|
|
|
|
|
real valacq;
|
|
|
|
|
real giacenza;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
TRecord_array & rmag = mag(annoes);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rmag.row(i);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
rim += rec.get_real(MAG_RIM);
|
|
|
|
|
valrim += rec.get_real(MAG_VALRIM);
|
|
|
|
|
acq += rec.get_real(MAG_ACQ);
|
|
|
|
|
valacq += rec.get_real(MAG_VALACQ);
|
|
|
|
|
giacenza += rec.get_real(MAG_GIAC);
|
|
|
|
|
if (giacenza_effettiva)
|
|
|
|
|
{
|
|
|
|
|
giacenza += rec.get_real(MAG_INCL);
|
|
|
|
|
giacenza -= rec.get_real(MAG_ACL);
|
|
|
|
|
giacenza += valorizza_componenti ? rec.get_real(MAG_PRODCOMP) : rec.get_real(MAG_PRODFIN);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (giacenza <= ZERO)
|
|
|
|
|
return ZERO;
|
|
|
|
|
if (giacenza > rim)
|
|
|
|
|
return ((giacenza - rim) * (acq == ZERO ? costo_standard(annoes) : valacq / acq) + valrim) / giacenza;
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
TRecord_array & rstorico = storico(annoes);
|
1997-07-02 10:53:23 +00:00
|
|
|
|
// const int last = rstorico.last_row();
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
rim = giacenza;
|
1997-07-02 10:53:23 +00:00
|
|
|
|
for (i = find_storico(annoes, "", codmag); i > 0; i = find_storico(annoes, "", codmag, i))
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rstorico.row(i);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
const real qta = rec.get(STOMAG_QUANT);
|
|
|
|
|
|
|
|
|
|
if (qta > giacenza)
|
|
|
|
|
{
|
|
|
|
|
valrim += (rec.get_real(STOMAG_VALORE) / qta) * giacenza;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
valrim += rec.get_real(STOMAG_VALORE);
|
|
|
|
|
giacenza -= qta;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return valrim / rim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
real TArticolo_giacenza::FIFO(const char * annoes, const char * codmag, const char * livello,
|
|
|
|
|
bool giacenza_effettiva, bool valorizza_componenti) const
|
|
|
|
|
{
|
|
|
|
|
real rim;
|
|
|
|
|
real valrim;
|
|
|
|
|
real acq;
|
|
|
|
|
real valacq;
|
|
|
|
|
real giacenza;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
TRecord_array & rmag = mag(annoes);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rmag.row(i);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
rim += rec.get_real(MAG_RIM);
|
|
|
|
|
valrim += rec.get_real(MAG_VALRIM);
|
|
|
|
|
acq += rec.get_real(MAG_ACQ);
|
|
|
|
|
valacq += rec.get_real(MAG_VALACQ);
|
|
|
|
|
giacenza += rec.get_real(MAG_GIAC);
|
|
|
|
|
if (giacenza_effettiva)
|
|
|
|
|
{
|
|
|
|
|
giacenza += rec.get_real(MAG_INCL);
|
|
|
|
|
giacenza -= rec.get_real(MAG_ACL);
|
|
|
|
|
giacenza += valorizza_componenti ? rec.get_real(MAG_PRODCOMP) : rec.get_real(MAG_PRODFIN);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (giacenza <= ZERO)
|
|
|
|
|
return ZERO;
|
|
|
|
|
if (giacenza <= acq)
|
|
|
|
|
return valacq / acq;
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
TRecord_array & rstorico = storico(annoes);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const int last = rstorico.last_row();
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
real res = giacenza - acq;
|
|
|
|
|
rim = ZERO;
|
1997-07-02 10:53:23 +00:00
|
|
|
|
valrim = ZERO;
|
|
|
|
|
TFixed_string cmag(codmag);
|
|
|
|
|
int codmag_len = codmag ? strlen(cmag) : 0;
|
1997-05-27 11:12:10 +00:00
|
|
|
|
for (i = last; i > 0; i--)
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rstorico.row(i);
|
1997-07-02 10:53:23 +00:00
|
|
|
|
if (codmag_len == 0 || rec.get(STOMAG_CODMAG).compare(codmag, codmag_len) == 0)
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1997-07-02 10:53:23 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ((giacenza - acq) * (valrim / rim) + valacq) / giacenza;
|
|
|
|
|
}
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
real TArticolo_giacenza::FIFO_ragionieristico(const char * annoes, const char * codmag, const char * livello,
|
|
|
|
|
bool giacenza_effettiva, bool valorizza_componenti) const
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
1997-07-30 13:28:22 +00:00
|
|
|
|
|
|
|
|
|
real TArticolo_giacenza::giacenza_corretta(const TRectype & rec ,bool giacenza_effettiva,bool valorizza_componenti) const
|
|
|
|
|
{
|
|
|
|
|
CHECK(rec.num() == LF_MAG, "Il record passato deve essere di LF_MAG");
|
|
|
|
|
real giacenza(rec.get_real(MAG_GIAC));
|
|
|
|
|
if (giacenza_effettiva)
|
|
|
|
|
{
|
|
|
|
|
giacenza += rec.get_real(MAG_INCL);
|
|
|
|
|
giacenza -= rec.get_real(MAG_ACL);
|
|
|
|
|
giacenza += valorizza_componenti ? 0 : (rec.get_real(MAG_PRODFIN)-rec.get_real(MAG_PRODCOMP));
|
|
|
|
|
}
|
|
|
|
|
return giacenza;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
TArticolo_giacenza::TArticolo_giacenza(const char* codice)
|
|
|
|
|
: TArticolo(codice)
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
add_file(LF_MAG,"NRIGA");
|
|
|
|
|
add_file(LF_STOMAG,"NRIGA");
|
1997-05-30 15:26:08 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-06-06 16:36:35 +00:00
|
|
|
|
#include <relapp.h>
|
|
|
|
|
#include <utility.h>
|
|
|
|
|
#include <tabutil.h>
|
|
|
|
|
#include <msksheet.h>
|
|
|
|
|
#include <recarray.h>
|
|
|
|
|
#include <assoc.h>
|
|
|
|
|
#include <checks.h>
|
|
|
|
|
#include <defmask.h>
|
|
|
|
|
#include <varrec.h>
|
1997-06-09 15:30:25 +00:00
|
|
|
|
#include "..\ve\velib.h"
|
1997-06-06 16:36:35 +00:00
|
|
|
|
#include "..\ve\sconti.h"
|
|
|
|
|
#include "..\ve\veconf.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const real CENTO=real(100.0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool TCondizione_vendita:: ricerca(const char * codice, const real & qta)
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
int tiporic;
|
|
|
|
|
switch (_condv.get_char("TIPO")) {
|
|
|
|
|
case 'L':
|
|
|
|
|
tiporic=A_LISTINI;
|
|
|
|
|
break;
|
|
|
|
|
case 'C':
|
|
|
|
|
tiporic=A_CONTRATTI;
|
|
|
|
|
break;
|
|
|
|
|
case 'O':
|
|
|
|
|
tiporic=A_OFFERTE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
1997-06-06 16:36:35 +00:00
|
|
|
|
return cerca(tiporic,codice, qta);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool TCondizione_vendita::cerca( int tiporicerca, const char * codriga , const real & qta)
|
|
|
|
|
{
|
|
|
|
|
if( config_ditta().get_bool( "GES", "ve", tiporicerca ) )
|
|
|
|
|
{
|
|
|
|
|
_condv.setkey( 1 );
|
|
|
|
|
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (_condv.get("COD").empty())
|
|
|
|
|
return FALSE;
|
1997-06-06 16:36:35 +00:00
|
|
|
|
switch( tiporicerca )
|
|
|
|
|
{
|
|
|
|
|
case A_CONTRATTI:
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case A_LISTINI:
|
|
|
|
|
{
|
|
|
|
|
_condv.put("TIPOCF", "");
|
|
|
|
|
_condv.put("CODCF", "");
|
|
|
|
|
if( !config_ditta().get_bool("GESLISCV", "ve"))
|
|
|
|
|
_condv.put("CATVEN", "");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case A_OFFERTE:
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if( _condv.read( ) == NOERR )
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
// si posiziona sulla riga
|
1997-06-06 16:36:35 +00:00
|
|
|
|
const bool gest_scagl = _condv.get_bool("GESTSCAGL");
|
|
|
|
|
const TString16 seqricrighe( _condv.get( "SEQRIC" ) );
|
|
|
|
|
bool found = FALSE;
|
|
|
|
|
|
|
|
|
|
for( int i = 0; !found && i < seqricrighe.len( ); i ++ )
|
|
|
|
|
{
|
|
|
|
|
_rcondv.zero( );
|
|
|
|
|
_rcondv.put( "TIPO", _condv.get( "TIPO"));
|
|
|
|
|
_rcondv.put( "CATVEN", _condv.get( "CATVEN"));
|
|
|
|
|
_rcondv.put( "TIPOCF", _condv.get( "TIPOCF"));
|
|
|
|
|
_rcondv.put( "CODCF", _condv.get( "CODCF"));
|
|
|
|
|
_rcondv.put("COD", _condv.get("COD"));
|
|
|
|
|
if (gest_scagl)
|
|
|
|
|
_rcondv.put("NSCAGL", 1);
|
|
|
|
|
|
|
|
|
|
char ricerca = seqricrighe[ i ];
|
|
|
|
|
_rcondv.put( "TIPORIGA", ricerca );
|
|
|
|
|
switch( ricerca )
|
|
|
|
|
{
|
|
|
|
|
case 'A':
|
|
|
|
|
{
|
|
|
|
|
_rcondv.put( "CODRIGA", codriga);
|
|
|
|
|
if (_rcondv.read() != NOERR &&
|
|
|
|
|
_rcondv.prev() == NOERR &&
|
|
|
|
|
_rcondv.get("TIPORIGA")[0] == 'A')
|
|
|
|
|
{
|
|
|
|
|
const TString cod_found(_rcondv.get("CODRIGA"));
|
|
|
|
|
return cod_found.compare(codriga, cod_found.len()) == 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'R':
|
|
|
|
|
_rcondv.put("CODRIGA", anamag().get( "RAGGFIS"));
|
|
|
|
|
_rcondv.read();
|
|
|
|
|
break;
|
|
|
|
|
case 'S':
|
|
|
|
|
{
|
|
|
|
|
_rcondv.put( "CODRIGA", anamag().get("GRMERC"));
|
|
|
|
|
_rcondv.read( );
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'G':
|
|
|
|
|
{
|
|
|
|
|
_rcondv.put( "CODRIGA", anamag().get("GRMERC").left(3));
|
|
|
|
|
_rcondv.read( );
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
found = _rcondv.good();
|
|
|
|
|
}
|
|
|
|
|
// individua lo scaglione corretto in base alla quantita'
|
|
|
|
|
if (found && gest_scagl)
|
|
|
|
|
{
|
|
|
|
|
TRectype rec(_rcondv.curr());
|
|
|
|
|
int last_scagl = 0;
|
|
|
|
|
int scagl = _rcondv.get_int("NSCAGL");
|
|
|
|
|
real qta_lim(_rcondv.get_real("QLIM"));
|
|
|
|
|
while (_rcondv.good() && scagl > last_scagl && qta_lim > ZERO && qta > qta_lim)
|
|
|
|
|
{
|
|
|
|
|
if (_rcondv.next() == NOERR)
|
|
|
|
|
{
|
|
|
|
|
last_scagl = scagl;
|
|
|
|
|
scagl = _rcondv.get_int("NSCAGL");
|
|
|
|
|
qta_lim =_rcondv.get_real("QLIM");
|
|
|
|
|
rec = _rcondv.curr();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_rcondv.read(rec);
|
|
|
|
|
}
|
1997-06-18 15:18:06 +00:00
|
|
|
|
_prezzo = _rcondv.get_real("PREZZO");
|
1997-06-06 16:36:35 +00:00
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Ricerca fallita
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TCondizione_vendita::put_condv(const char *tipocv,const char *codicecv,const char *catven,const char *tipocf,const char *codcf)
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
_condv.put("TIPO",tipocv);
|
|
|
|
|
_condv.put("CATVEN",catven);
|
|
|
|
|
_condv.put("TIPOCF",tipocf);
|
|
|
|
|
_condv.put("CODCF",codcf);
|
|
|
|
|
_condv.put("COD",codicecv);
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TCondizione_vendita::put_listino(const char * codlist,const char *catven)
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if( !config_ditta().get_bool("GESLISCV", "ve"))
|
|
|
|
|
put_condv("L",codlist,"","","");
|
|
|
|
|
else
|
|
|
|
|
put_condv("L",codlist,catven,"","");
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
void TCondizione_vendita::put_contratto(const char * codcontr,const char *tipocf,const char *codcf)
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
put_condv("C",codcontr,"",tipocf,codcf);
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
void TCondizione_vendita::put_offerta(const char * codoff)
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
put_condv("C",codoff,"","","");
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TCondizione_vendita::TCondizione_vendita(TConfig * ditta,
|
1997-06-18 15:18:06 +00:00
|
|
|
|
TLocalisamfile * anamag, TLocalisamfile * umart)
|
1997-06-06 16:36:35 +00:00
|
|
|
|
: _condv(LF_CONDV), _rcondv(LF_RCONDV),
|
|
|
|
|
_sconti( LF_SCONTI ),
|
|
|
|
|
_anamag(anamag), _umart(umart), _config_ditta(ditta), _ivarid(FALSE)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// *********************
|
|
|
|
|
// movimenti di magazzino
|
|
|
|
|
|
|
|
|
|
// causali
|
|
|
|
|
|
|
|
|
|
int TCausale_magazzino::sgn(TTipo_saldomag tiposaldo)
|
|
|
|
|
{
|
1997-07-07 10:25:09 +00:00
|
|
|
|
static TString80 segni;
|
|
|
|
|
segni=get("S2");
|
1997-06-06 16:36:35 +00:00
|
|
|
|
switch (tiposaldo) {
|
|
|
|
|
case s_giac:
|
1997-07-07 10:25:09 +00:00
|
|
|
|
return atoi(segni.mid(0,2));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
case s_acq:
|
1997-07-07 10:25:09 +00:00
|
|
|
|
return atoi(segni.mid(2,2));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
case s_ent:
|
1997-07-07 10:25:09 +00:00
|
|
|
|
return atoi(segni.mid(4,2));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
case s_ven:
|
1997-07-07 10:25:09 +00:00
|
|
|
|
return atoi(segni.mid(6,2));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
case s_usc:
|
1997-07-07 10:25:09 +00:00
|
|
|
|
return atoi(segni.mid(8,2));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
case s_ordc:
|
1997-07-07 10:25:09 +00:00
|
|
|
|
return atoi(segni.mid(10,2));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
case s_ordf:
|
1997-07-07 10:25:09 +00:00
|
|
|
|
return atoi(segni.mid(12,2));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
case s_incl:
|
1997-07-07 10:25:09 +00:00
|
|
|
|
return atoi(segni.mid(14,2));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
case s_acl:
|
1997-07-07 10:25:09 +00:00
|
|
|
|
return atoi(segni.mid(16,2));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
case s_prodc:
|
1997-07-07 10:25:09 +00:00
|
|
|
|
return atoi(segni.mid(18,2));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
case s_prodf:
|
1997-07-07 10:25:09 +00:00
|
|
|
|
return atoi(segni.mid(20,2));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
case s_rim:
|
1997-07-07 10:25:09 +00:00
|
|
|
|
return atoi(segni.mid(22,2));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
case s_scart:
|
1997-07-07 10:25:09 +00:00
|
|
|
|
return atoi(segni.mid(24,2));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
case s_label:
|
1997-07-07 10:25:09 +00:00
|
|
|
|
return atoi(segni.mid(26,2));
|
1997-08-19 13:10:11 +00:00
|
|
|
|
case s_user1:
|
|
|
|
|
return atoi(segni.mid(28,2));
|
|
|
|
|
case s_user2:
|
|
|
|
|
return atoi(segni.mid(30,2));
|
|
|
|
|
case s_user3:
|
|
|
|
|
return atoi(segni.mid(32,2));
|
|
|
|
|
case s_user4:
|
|
|
|
|
return atoi(segni.mid(34,2));
|
|
|
|
|
case s_user5:
|
|
|
|
|
return atoi(segni.mid(36,2));
|
|
|
|
|
case s_user6:
|
|
|
|
|
return atoi(segni.mid(38,2));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1997-07-07 10:25:09 +00:00
|
|
|
|
bool TCausale_magazzino::is_fiscale()
|
|
|
|
|
{
|
|
|
|
|
return (tipomov()=='S' || tipomov()=='C' );
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-06 16:36:35 +00:00
|
|
|
|
|
|
|
|
|
TCausale_magazzino::TCausale_magazzino(const char * codice):
|
1997-06-27 09:19:02 +00:00
|
|
|
|
TRectype(LF_TABCOM)
|
1997-06-06 16:36:35 +00:00
|
|
|
|
{
|
1997-06-27 09:19:02 +00:00
|
|
|
|
TTable f("%CAU");
|
|
|
|
|
|
|
|
|
|
settab("CAU");
|
|
|
|
|
put("CODTAB", codice);
|
|
|
|
|
if (TRectype::read(f) != NOERR)
|
1997-06-18 15:18:06 +00:00
|
|
|
|
zero();
|
1997-06-27 09:19:02 +00:00
|
|
|
|
}
|
1997-06-06 16:36:35 +00:00
|
|
|
|
|
|
|
|
|
// movimenti
|
1997-06-27 12:58:13 +00:00
|
|
|
|
// dati della linea di movimento di magazzino
|
|
|
|
|
class TLine_movmag : public TObject
|
|
|
|
|
{
|
1997-07-25 10:13:54 +00:00
|
|
|
|
TString16 _codcaus;
|
|
|
|
|
TString16 _um;
|
|
|
|
|
real _quant;
|
|
|
|
|
real _prezzo;
|
1997-06-27 12:58:13 +00:00
|
|
|
|
public:
|
1997-07-25 10:13:54 +00:00
|
|
|
|
const TString16 &codcaus() const {return _codcaus;}
|
|
|
|
|
const TString16 &um() const {return _um;}
|
|
|
|
|
const real &quant() const {return _quant;}
|
|
|
|
|
const real &prezzo() const {return _prezzo;}
|
|
|
|
|
void set(const TString16 cau,const TString16 um,const real q, const real p);
|
1997-06-27 12:58:13 +00:00
|
|
|
|
int operator==(TLine_movmag &);
|
|
|
|
|
|
|
|
|
|
virtual TObject* dup() const {return new TLine_movmag(*this);};
|
|
|
|
|
|
|
|
|
|
TLine_movmag() {};
|
|
|
|
|
TLine_movmag(const TLine_movmag &);
|
|
|
|
|
virtual ~TLine_movmag() {};
|
|
|
|
|
};
|
|
|
|
|
|
1997-07-25 10:13:54 +00:00
|
|
|
|
void TLine_movmag ::set(const TString16 cau,const TString16 um,const real q, const real p)
|
|
|
|
|
{
|
|
|
|
|
_codcaus=cau;
|
|
|
|
|
_um=um;
|
|
|
|
|
_quant=q;
|
|
|
|
|
_prezzo=p;
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-06 16:36:35 +00:00
|
|
|
|
TLine_movmag ::TLine_movmag(const TLine_movmag &l)
|
|
|
|
|
{
|
1997-07-25 10:13:54 +00:00
|
|
|
|
_codcaus=l._codcaus;
|
|
|
|
|
_um=l._um;
|
|
|
|
|
_quant=l._quant;
|
|
|
|
|
_prezzo=l._prezzo;
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TLine_movmag::operator==(TLine_movmag &l)
|
|
|
|
|
{
|
1997-07-25 10:13:54 +00:00
|
|
|
|
return (_codcaus==l._codcaus)&&(_um==l._um)&&(_quant==l._quant)&&(_prezzo==l._prezzo);
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-06-27 12:58:13 +00:00
|
|
|
|
// ********************************
|
|
|
|
|
// TMov_mag
|
|
|
|
|
|
|
|
|
|
TRecord_cache TMov_mag::cache_causali("%CAU");
|
|
|
|
|
|
1997-06-06 16:36:35 +00:00
|
|
|
|
|
1997-06-09 09:38:42 +00:00
|
|
|
|
TMov_mag::TMov_mag() :
|
1997-06-06 16:36:35 +00:00
|
|
|
|
TMultiple_rectype(LF_MOVMAG),
|
|
|
|
|
lines_to_add(), lines_to_subtract()
|
|
|
|
|
{
|
1997-06-09 09:38:42 +00:00
|
|
|
|
add_file(LF_RMOVMAG,"NRIG");
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMov_mag::~TMov_mag()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// valuta il valore della chiave per un nuovo record
|
|
|
|
|
bool TMov_mag::renum()
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
put("NUMREG",get_next_key());
|
1997-06-06 16:36:35 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// copia la chiave dal file principale a quello delle righe
|
|
|
|
|
void TMov_mag::set_body_key(TRectype & rowrec)
|
|
|
|
|
{
|
1997-06-27 09:19:02 +00:00
|
|
|
|
rowrec.put("NUMREG",get("NUMREG"));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-07-28 10:30:36 +00:00
|
|
|
|
void TMov_mag::synchronize_bodies()
|
|
|
|
|
{
|
|
|
|
|
TMultiple_rectype::synchronize_bodies();
|
1997-06-06 16:36:35 +00:00
|
|
|
|
// reset delle strutture per il controlli delle variazioni dei saldi
|
1997-07-28 10:30:36 +00:00
|
|
|
|
if (autoload_enabled())
|
|
|
|
|
{
|
|
|
|
|
_annoes=get("ANNOES");
|
|
|
|
|
lines_to_add.destroy();
|
|
|
|
|
lines_to_subtract.destroy();
|
|
|
|
|
const int nrows = rows();
|
|
|
|
|
for (int i = 1; i<= nrows; i++)
|
|
|
|
|
line_deleted(line2key(i), line2data(i));
|
|
|
|
|
}
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-07-28 10:30:36 +00:00
|
|
|
|
|
1997-06-06 16:36:35 +00:00
|
|
|
|
int TMov_mag::remove(TBaseisamfile& f) const
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
if ((res=TMultiple_rectype::remove(f))==NOERR )
|
|
|
|
|
// effettua la variazione dei saldi
|
1997-07-24 14:49:33 +00:00
|
|
|
|
((TMov_mag *)this)->update_balances();
|
1997-06-06 16:36:35 +00:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-23 14:51:53 +00:00
|
|
|
|
|
|
|
|
|
void TMov_mag::add_automatiche()
|
|
|
|
|
{
|
1997-06-27 09:19:02 +00:00
|
|
|
|
for (int r = rows(); r > 0; r--)
|
|
|
|
|
{
|
|
|
|
|
TRecord_array & b = body();
|
|
|
|
|
TRectype & row = b[r];
|
|
|
|
|
TString16 codcaus(row.get(RMOVMAG_CODCAUS));
|
|
|
|
|
if (codcaus.empty())
|
|
|
|
|
codcaus=get(MOVMAG_CODCAUS);
|
1997-06-27 12:58:13 +00:00
|
|
|
|
TCausale_magazzino & cau=(TCausale_magazzino & )cache_causali.get(codcaus);
|
1997-06-27 09:19:02 +00:00
|
|
|
|
codcaus=cau.caus_collegata();
|
|
|
|
|
if (codcaus.not_empty())
|
1997-06-23 14:51:53 +00:00
|
|
|
|
{
|
|
|
|
|
// deve esserci una riga collegata
|
1997-06-27 09:19:02 +00:00
|
|
|
|
if (!b.exist(r + 1) || b[r + 1].get_char(RMOVMAG_TIPORIGA) != riga_automatica)
|
1997-06-23 14:51:53 +00:00
|
|
|
|
{
|
|
|
|
|
// manca, la inserisco
|
1997-06-27 09:19:02 +00:00
|
|
|
|
TRectype * linea_auto = new TRectype(row);
|
|
|
|
|
const char * codmag = codmag_rauto(r);
|
|
|
|
|
if (codmag != NULL)
|
|
|
|
|
linea_auto->put(RMOVMAG_CODMAG, codmag);
|
|
|
|
|
const char * prezzo = prezzo_rauto(r);
|
|
|
|
|
if (prezzo != NULL)
|
|
|
|
|
linea_auto->put(RMOVMAG_PREZZO, prezzo);
|
|
|
|
|
linea_auto->put(RMOVMAG_NRIG, r+1);
|
|
|
|
|
linea_auto->put(RMOVMAG_TIPORIGA, (char) riga_automatica);
|
|
|
|
|
linea_auto->put(RMOVMAG_CODCAUS, codcaus);
|
|
|
|
|
b.insert_row(linea_auto);
|
1997-06-23 14:51:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // ciclo righe
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-06 16:36:35 +00:00
|
|
|
|
int TMov_mag::write(TBaseisamfile& f) const
|
|
|
|
|
{
|
|
|
|
|
int res;
|
1997-06-23 14:51:53 +00:00
|
|
|
|
((TMov_mag *)this)->add_automatiche();
|
1997-06-27 09:19:02 +00:00
|
|
|
|
// memorizza le variazioni
|
|
|
|
|
|
|
|
|
|
const int nrows = rows();
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= nrows; i++)
|
|
|
|
|
((TMov_mag *)this)->line_inserted(line2key(i), line2data(i));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
if ((res=TMultiple_rectype::write(f))==NOERR )
|
|
|
|
|
// effettua la variazione dei saldi
|
1997-07-24 14:49:33 +00:00
|
|
|
|
((TMov_mag *)this)->update_balances();
|
1997-06-06 16:36:35 +00:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TMov_mag::rewrite(TBaseisamfile& f) const
|
|
|
|
|
{
|
|
|
|
|
int res;
|
1997-06-23 14:51:53 +00:00
|
|
|
|
((TMov_mag *)this)->add_automatiche();
|
1997-06-27 09:19:02 +00:00
|
|
|
|
// memorizza le variazioni
|
|
|
|
|
|
|
|
|
|
const int nrows = rows();
|
|
|
|
|
|
1997-07-07 10:25:09 +00:00
|
|
|
|
for (int i = 1; i <= nrows; i++)
|
1997-06-27 09:19:02 +00:00
|
|
|
|
((TMov_mag *)this)->line_inserted(line2key(i), line2data(i));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
if ((res=TMultiple_rectype::rewrite(f))==NOERR )
|
|
|
|
|
// effettua la variazione dei saldi
|
1997-07-24 14:49:33 +00:00
|
|
|
|
((TMov_mag *)this)->update_balances();
|
1997-06-06 16:36:35 +00:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *TMov_mag::get_next_key()
|
|
|
|
|
{
|
1997-07-24 14:49:33 +00:00
|
|
|
|
static TString16 nextcod;
|
1997-06-06 16:36:35 +00:00
|
|
|
|
TLocalisamfile f(LF_MOVMAG);
|
|
|
|
|
f.last();
|
1997-06-23 14:51:53 +00:00
|
|
|
|
int a=atoi(f.get(MOVMAG_NUMREG))+1;
|
1997-07-24 14:49:33 +00:00
|
|
|
|
return nextcod.format("%d",a);
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//*******
|
|
|
|
|
// gestione delle variazione dei saldi
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
int TMov_mag::force_update_bal()
|
|
|
|
|
{
|
|
|
|
|
int res;
|
1997-06-18 15:18:06 +00:00
|
|
|
|
|
|
|
|
|
// reset delle strutture per il controlli delle variazioni dei saldi
|
1997-06-23 14:51:53 +00:00
|
|
|
|
_annoes=get(MOVMAG_ANNOES);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
lines_to_add.destroy();
|
|
|
|
|
lines_to_subtract.destroy();
|
1997-06-27 09:19:02 +00:00
|
|
|
|
|
1997-06-18 15:18:06 +00:00
|
|
|
|
// memorizza le variazioni
|
1997-06-27 09:19:02 +00:00
|
|
|
|
const int nrows = rows();
|
|
|
|
|
|
|
|
|
|
for (int i= 1; i <= nrows; i++)
|
|
|
|
|
line_inserted(line2key(i), line2data(i));
|
1997-06-18 15:18:06 +00:00
|
|
|
|
res=update_balances();
|
|
|
|
|
return res;
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-07-07 10:25:09 +00:00
|
|
|
|
// restituisce il valore dei dati
|
1997-06-27 12:58:13 +00:00
|
|
|
|
TLine_movmag & TMov_mag::line2data(int nrig) const
|
1997-06-06 16:36:35 +00:00
|
|
|
|
{
|
1997-07-25 10:13:54 +00:00
|
|
|
|
static TLine_movmag line;
|
1997-06-27 09:19:02 +00:00
|
|
|
|
TRecord_array & b = body();
|
|
|
|
|
|
1997-07-25 10:13:54 +00:00
|
|
|
|
line.set(
|
|
|
|
|
b.row(nrig).get(RMOVMAG_CODCAUS).blank() ? get(MOVMAG_CODCAUS)
|
|
|
|
|
: b.row(nrig).get(RMOVMAG_CODCAUS) ,
|
|
|
|
|
b.row(nrig).get(RMOVMAG_UM),
|
|
|
|
|
b.row(nrig).get_real(RMOVMAG_QUANT),
|
|
|
|
|
b.row(nrig).get_real(RMOVMAG_PREZZO));
|
|
|
|
|
return line;
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-06-27 09:19:02 +00:00
|
|
|
|
TToken_string & TMov_mag::line2key(int numriga) const
|
1997-06-06 16:36:35 +00:00
|
|
|
|
{
|
1997-06-27 09:19:02 +00:00
|
|
|
|
static TToken_string _key;
|
|
|
|
|
TRecord_array & b = body();
|
1997-06-06 16:36:35 +00:00
|
|
|
|
TString16 nr;
|
1997-06-27 09:19:02 +00:00
|
|
|
|
|
|
|
|
|
nr << numriga;
|
|
|
|
|
_key.cut(0);
|
|
|
|
|
_key.add(b.row(numriga).get(RMOVMAG_CODART));
|
|
|
|
|
_key.add(b.row(numriga).get(RMOVMAG_CODMAG));
|
|
|
|
|
_key.add(b.row(numriga).get(RMOVMAG_LIVGIAC));
|
|
|
|
|
_key.add(nr);
|
|
|
|
|
return _key;
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TString TMov_mag::key2field(TToken_string &key,const char *fieldname)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp(fieldname,"CODART")==0)
|
|
|
|
|
return key.get(0);
|
|
|
|
|
if (strcmp(fieldname,"CODMAG")==0)
|
|
|
|
|
return key.get(1);
|
|
|
|
|
if (strcmp(fieldname,"LIVGIAC")==0)
|
|
|
|
|
return key.get(2);
|
|
|
|
|
CHECKS(FALSE, "Nome di campo non appartenente al file righe mov ", fieldname);
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-06-23 14:51:53 +00:00
|
|
|
|
int TMov_mag::line_inserted(TToken_string &k,TLine_movmag &r)
|
1997-06-06 16:36:35 +00:00
|
|
|
|
{
|
1997-06-27 12:58:13 +00:00
|
|
|
|
if (_annoes != get("ANNOES")) {
|
1997-06-06 16:36:35 +00:00
|
|
|
|
lines_to_add.add(k,r);
|
|
|
|
|
} else {
|
|
|
|
|
if (lines_to_subtract.is_key(k)&& (TLine_movmag &)lines_to_subtract[k]==r)
|
|
|
|
|
// modifica annullata
|
|
|
|
|
lines_to_subtract.remove(k);
|
|
|
|
|
else
|
|
|
|
|
// linea modificata
|
|
|
|
|
lines_to_add.add(k,r);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-23 14:51:53 +00:00
|
|
|
|
int TMov_mag::line_deleted(TToken_string &k,TLine_movmag &r)
|
1997-06-06 16:36:35 +00:00
|
|
|
|
{
|
1997-06-27 12:58:13 +00:00
|
|
|
|
if (_annoes != get("ANNOES")) {
|
1997-06-06 16:36:35 +00:00
|
|
|
|
lines_to_subtract.add(k,r);
|
|
|
|
|
} else {
|
|
|
|
|
if (lines_to_add.is_key(k)&& r==(TLine_movmag &)lines_to_add[k] )
|
|
|
|
|
// modifica annullata
|
|
|
|
|
lines_to_add.remove(k);
|
|
|
|
|
else
|
|
|
|
|
// linea modificata
|
|
|
|
|
lines_to_subtract.add(k,r);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TMov_mag::unlock_anamag(const char *codart)
|
|
|
|
|
{
|
|
|
|
|
TLocalisamfile anamag(LF_ANAMAG);
|
|
|
|
|
anamag.put("CODART",codart);
|
|
|
|
|
return (anamag.read(_isequal,_unlock)==NOERR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TMov_mag::lock_anamag(const char *codart)
|
|
|
|
|
{
|
|
|
|
|
TLocalisamfile anamag(LF_ANAMAG);
|
|
|
|
|
anamag.put("CODART",codart);
|
|
|
|
|
bool insert_new=TRUE;
|
|
|
|
|
TString mess;
|
|
|
|
|
mess << "Il record di anagrafica dell'articolo ''"<< codart << "'' risulta essere gi<67> in uso.\n Interrompo ?";
|
|
|
|
|
TTimed_breakbox bbox((const char *)mess,10);
|
|
|
|
|
do {
|
|
|
|
|
if (anamag.read(_isequal,_testandlock)==NOERR)
|
|
|
|
|
return TRUE;
|
|
|
|
|
} while (bbox.run()!=K_ESC);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TMov_mag::giac_putkey(TLocalisamfile & mag,TString16 annoes,TToken_string curr_key)
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
mag.zero(' ');
|
|
|
|
|
mag.put("ANNOES",annoes);
|
|
|
|
|
mag.put("CODMAG",key2field(curr_key,"CODMAG"));
|
|
|
|
|
mag.put("CODART",key2field(curr_key,"CODART"));
|
|
|
|
|
mag.put("LIVELLO",key2field(curr_key,"LIVGIAC"));
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// aggiorna tutti i saldi in base alle modifiche fatte.
|
|
|
|
|
// il lock su anagrafica dovrebbe garantire il lock su tutte le
|
|
|
|
|
// giacenze dell'articolo
|
1997-06-18 15:23:13 +00:00
|
|
|
|
int TMov_mag::update_balances()
|
1997-06-06 16:36:35 +00:00
|
|
|
|
{
|
|
|
|
|
bool updated_bal=TRUE;
|
|
|
|
|
TLocalisamfile mag(LF_MAG);
|
|
|
|
|
mag.setkey(2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TString_array keys_to_add,keys_to_remove;
|
|
|
|
|
((TMov_mag *)this)->lines_to_add.get_keys(keys_to_add);
|
|
|
|
|
((TMov_mag *)this)->lines_to_subtract.get_keys(keys_to_remove);
|
|
|
|
|
|
|
|
|
|
// aggiunge i saldi nuovi
|
|
|
|
|
keys_to_add.sort();
|
|
|
|
|
TToken_string * curr_key=(TToken_string *)keys_to_add.first_item();
|
|
|
|
|
|
1997-06-18 15:18:06 +00:00
|
|
|
|
while (curr_key) {
|
1997-06-18 15:23:13 +00:00
|
|
|
|
curr_art.read((const char *)key2field(*curr_key,"CODART"));
|
|
|
|
|
if (curr_art.lock_and_prompt()) {
|
1997-06-18 15:18:06 +00:00
|
|
|
|
TLine_movmag & line_mov=(TLine_movmag &)lines_to_add[*curr_key];
|
1997-07-25 10:13:54 +00:00
|
|
|
|
TCausale_magazzino & causmag=(TCausale_magazzino &)cache_causali.get(line_mov.codcaus());
|
1997-07-07 10:25:09 +00:00
|
|
|
|
|
|
|
|
|
if (causmag.update_ultcos())
|
1997-07-25 10:13:54 +00:00
|
|
|
|
curr_art.update_ultcosti(line_mov.prezzo(),get_date("DATACOMP"));
|
1997-06-18 15:18:06 +00:00
|
|
|
|
// lock gained
|
|
|
|
|
giac_putkey(mag,get("ANNOES"),*curr_key);
|
|
|
|
|
if (mag.read()!=NOERR) {
|
|
|
|
|
// non trovato: aggiungo
|
|
|
|
|
giac_putkey(mag,get("ANNOES"),*curr_key);
|
1997-06-18 15:23:13 +00:00
|
|
|
|
mag.put("NRIGA",1+curr_art.mag(get("ANNOES")).rows());
|
1997-06-18 15:18:06 +00:00
|
|
|
|
mag.write();
|
|
|
|
|
}
|
|
|
|
|
// modifica questo record (e lo sblocca)
|
1997-07-02 10:53:23 +00:00
|
|
|
|
update_balances(mag.curr(), line_mov, +1);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
/*// ottimizzazione :(cerca di sfruttare la lettura fatta per un eventuale saldo vecchio)
|
|
|
|
|
// ci<63> causa la modifica dell'oggetto TMov_mag (il metodo non <20> pi<70> const)
|
|
|
|
|
if (_annoes == get("ANNOES")
|
|
|
|
|
&& lines_to_subtract.is_key(*curr_key)) {
|
1997-06-27 12:58:13 +00:00
|
|
|
|
update_balances(mag.curr(),(TLine_movmag &)lines_to_subtract[*curr_key],-1);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
((TMov_mag *)this)->lines_to_add.remove(*curr_key);
|
|
|
|
|
((TMov_mag *)this)->lines_to_subtract.remove(*curr_key);
|
|
|
|
|
}*/
|
|
|
|
|
mag.rewrite();
|
|
|
|
|
// conclude la TRANSAZIONE prima di sbloccare il record dell'articolo
|
|
|
|
|
TToken_string *rem_key=(TToken_string *)keys_to_remove.first_item();
|
|
|
|
|
while ( rem_key) {
|
|
|
|
|
if (key2field(*rem_key,"CODART")==key2field(*curr_key,"CODART")) {
|
|
|
|
|
giac_putkey(mag,_annoes,*rem_key);
|
|
|
|
|
if (mag.read()==NOERR) {
|
1997-06-27 12:58:13 +00:00
|
|
|
|
update_balances(mag.curr(),(TLine_movmag &)lines_to_subtract[*rem_key],-1);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
mag.rewrite();
|
|
|
|
|
}
|
|
|
|
|
keys_to_remove.remove_item();
|
|
|
|
|
}
|
|
|
|
|
rem_key=(TToken_string *)keys_to_remove.succ_item();
|
|
|
|
|
}
|
1997-06-18 15:23:13 +00:00
|
|
|
|
curr_art.unlock();
|
1997-06-18 15:18:06 +00:00
|
|
|
|
} else {
|
|
|
|
|
updated_bal=FALSE;
|
|
|
|
|
}
|
|
|
|
|
curr_key=(TToken_string *)keys_to_add.succ_item();
|
|
|
|
|
}
|
|
|
|
|
// togli i saldi vecchi
|
1997-06-06 16:36:35 +00:00
|
|
|
|
curr_key=(TToken_string *)keys_to_remove.first_item();
|
|
|
|
|
|
1997-06-18 15:18:06 +00:00
|
|
|
|
while (curr_key) {
|
1997-06-18 15:23:13 +00:00
|
|
|
|
curr_art.read((const char *)key2field(*curr_key,"CODART"));
|
|
|
|
|
if (curr_art.lock_and_prompt()) {
|
1997-06-18 15:18:06 +00:00
|
|
|
|
giac_putkey(mag,_annoes,*curr_key);
|
|
|
|
|
// modifica questo record (e lo sblocca)
|
|
|
|
|
if (mag.read()==NOERR) {
|
1997-06-27 12:58:13 +00:00
|
|
|
|
update_balances(mag.curr(),(TLine_movmag &)lines_to_subtract[*curr_key],-1);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
mag.rewrite();
|
|
|
|
|
}
|
1997-06-18 15:23:13 +00:00
|
|
|
|
curr_art.unlock();
|
1997-06-18 15:18:06 +00:00
|
|
|
|
} else {
|
|
|
|
|
updated_bal=FALSE;
|
|
|
|
|
}
|
|
|
|
|
curr_key=(TToken_string *)keys_to_remove.succ_item();
|
|
|
|
|
}
|
|
|
|
|
if (!updated_bal) {
|
|
|
|
|
// saldi non aggiornati
|
|
|
|
|
warning_box("I saldi di magazzino non sono stati del tutto aggiornati. \nProcedere ad una operazione di ''Ricostruzione saldi''");
|
|
|
|
|
}
|
|
|
|
|
return updated_bal;
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// aggiorna i saldi del record corrente
|
|
|
|
|
// in base alla causale e alla modifica fatta (con segno + o -)
|
1997-06-27 12:58:13 +00:00
|
|
|
|
int TMov_mag::update_balances(TRectype & magrec, const TLine_movmag &l,int rett_sign)
|
1997-06-06 16:36:35 +00:00
|
|
|
|
{
|
1997-07-25 10:13:54 +00:00
|
|
|
|
TCausale_magazzino & caus=(TCausale_magazzino &)cache_causali.get(l.codcaus());
|
1997-06-18 15:18:06 +00:00
|
|
|
|
TLocalisamfile umart(LF_UMART);
|
|
|
|
|
real diff,diff_val;
|
|
|
|
|
umart.setkey(2);
|
|
|
|
|
umart.put(UMART_CODART,magrec.get(MAG_CODART));
|
1997-07-25 10:13:54 +00:00
|
|
|
|
umart.put(UMART_UM , l.um());
|
1997-06-18 15:18:06 +00:00
|
|
|
|
umart.read();
|
|
|
|
|
real fc=umart.get_real("FC");
|
|
|
|
|
|
1997-07-25 10:13:54 +00:00
|
|
|
|
diff=fc*rett_sign*l.quant();
|
|
|
|
|
diff_val=rett_sign*l.quant()*l.prezzo();
|
1997-07-07 10:25:09 +00:00
|
|
|
|
if (caus.update_qta()) {
|
|
|
|
|
update_balance(magrec,"GIAC",diff*caus.sgn(s_giac)); // update ..
|
|
|
|
|
update_balance(magrec,"ACQ",diff*caus.sgn(s_acq)); // update ..
|
|
|
|
|
update_balance(magrec,"ENT",diff*caus.sgn(s_ent));
|
|
|
|
|
update_balance(magrec,"VEN",diff*caus.sgn(s_ven));
|
|
|
|
|
update_balance(magrec,"USC",diff*caus.sgn(s_usc));
|
|
|
|
|
update_balance(magrec,"ORDC",diff*caus.sgn(s_ordc));
|
|
|
|
|
update_balance(magrec,"ORDF",diff*caus.sgn(s_ordf));
|
|
|
|
|
update_balance(magrec,"RIM",diff*caus.sgn(s_rim));
|
|
|
|
|
update_balance(magrec,"SCARTI",diff*caus.sgn(s_scart));
|
|
|
|
|
update_balance(magrec,"INCL",diff*caus.sgn(s_incl));
|
|
|
|
|
update_balance(magrec,"ACL",diff*caus.sgn(s_acl));
|
|
|
|
|
update_balance(magrec,"PRODCOMP",diff*caus.sgn(s_prodc));
|
|
|
|
|
update_balance(magrec,"PRODFIN",diff*caus.sgn(s_prodf));
|
|
|
|
|
update_balance(magrec,"NLABEL",diff*caus.sgn(s_label));
|
1997-08-19 13:10:11 +00:00
|
|
|
|
update_balance(magrec,"USER1",diff*caus.sgn(s_user1));
|
|
|
|
|
update_balance(magrec,"USER2",diff*caus.sgn(s_user2));
|
|
|
|
|
update_balance(magrec,"USER3",diff*caus.sgn(s_user3));
|
|
|
|
|
update_balance(magrec,"USER4",diff*caus.sgn(s_user4));
|
|
|
|
|
update_balance(magrec,"USER5",diff*caus.sgn(s_user5));
|
|
|
|
|
update_balance(magrec,"USER6",diff*caus.sgn(s_user6));
|
1997-07-07 10:25:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (caus.update_val()) {
|
|
|
|
|
update_balance(magrec,"VALACQ",diff_val*caus.sgn(s_acq)); // update ..
|
|
|
|
|
update_balance(magrec,"VALENT",diff_val*caus.sgn(s_ent));
|
|
|
|
|
update_balance(magrec,"VALVEN",diff_val*caus.sgn(s_ven));
|
|
|
|
|
update_balance(magrec,"VALUSC",diff_val*caus.sgn(s_usc));
|
|
|
|
|
update_balance(magrec,"VALORDC",diff_val*caus.sgn(s_ordc));
|
|
|
|
|
update_balance(magrec,"VALORDF",diff_val*caus.sgn(s_ordf));
|
|
|
|
|
update_balance(magrec,"VALRIM",diff_val*caus.sgn(s_rim));
|
|
|
|
|
update_balance(magrec,"VALSCARTI",diff_val*caus.sgn(s_scart));
|
1997-08-19 13:10:11 +00:00
|
|
|
|
update_balance(magrec,"USERVAL1",diff*caus.sgn(s_user1));
|
|
|
|
|
update_balance(magrec,"USERVAL2",diff*caus.sgn(s_user2));
|
|
|
|
|
update_balance(magrec,"USERVAL3",diff*caus.sgn(s_user3));
|
|
|
|
|
update_balance(magrec,"USERVAL4",diff*caus.sgn(s_user4));
|
|
|
|
|
update_balance(magrec,"USERVAL5",diff*caus.sgn(s_user5));
|
|
|
|
|
update_balance(magrec,"USERVAL6",diff*caus.sgn(s_user6));
|
1997-07-07 10:25:09 +00:00
|
|
|
|
}
|
1997-06-18 15:18:06 +00:00
|
|
|
|
return 0;
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TMov_mag::update_balance(TRectype & magrec, const char * fieldname, real diff) const
|
|
|
|
|
{
|
1997-07-25 13:08:30 +00:00
|
|
|
|
magrec.put(fieldname,magrec.get_real(fieldname)+diff);
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIDDEN TEsercizi_contabili _esercizi;
|
|
|
|
|
|
|
|
|
|
int TMov_mag::codice_esercizio(TDate &d)
|
|
|
|
|
{
|
|
|
|
|
return _esercizi.date2esc(d);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//**********************
|
1997-07-28 10:30:36 +00:00
|
|
|
|
bool rebuild_balances(const TString16 annoes, bool reset_giac)
|
1997-06-06 16:36:35 +00:00
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
TArray used_files;
|
|
|
|
|
used_files.add(new TLocalisamfile(LF_RMOVMAG),LF_RMOVMAG);
|
|
|
|
|
used_files.add(new TLocalisamfile(LF_MOVMAG),LF_MOVMAG);
|
1997-06-18 15:23:13 +00:00
|
|
|
|
used_files.add(new TTable("%CAU"),5);
|
1997-06-06 16:36:35 +00:00
|
|
|
|
TMov_mag * m_m= new TMov_mag; // record del movimento di magazzino
|
|
|
|
|
|
1997-06-18 15:18:06 +00:00
|
|
|
|
// relazione con un solo file (LF_MOVMAG) ma col record Head_Body
|
1997-06-06 16:36:35 +00:00
|
|
|
|
TRelation rel(LF_MOVMAG);
|
|
|
|
|
rel.lfile().set_curr(m_m);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
int ok=TRUE;
|
|
|
|
|
TLocalisamfile mag(LF_MAG);
|
|
|
|
|
if (reset_giac) {
|
|
|
|
|
// azzera tutte giacenze (ciclo sulle giacenze)
|
|
|
|
|
mag.put("ANNOES",annoes);
|
|
|
|
|
mag.read(_isgteq);
|
|
|
|
|
while (!mag.eof() && annoes==mag.get("ANNOES"))
|
|
|
|
|
{
|
|
|
|
|
TString currcode(mag.get("CODART"));
|
|
|
|
|
TArticolo articolo(currcode);
|
|
|
|
|
if (articolo.lock_and_prompt())
|
|
|
|
|
{
|
|
|
|
|
while (!mag.eof() && currcode==mag.get("CODART"))
|
|
|
|
|
{
|
1997-07-25 10:13:54 +00:00
|
|
|
|
mag.put("GIAC",0);
|
1997-07-28 10:30:36 +00:00
|
|
|
|
mag.put("RIM",0);mag.put("VALRIM",0);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
mag.put("ACQ",0);mag.put("VALACQ",0);
|
|
|
|
|
mag.put("ENT",0);mag.put("VALENT",0);
|
|
|
|
|
mag.put("VEN",0);mag.put("VALVEN",0);
|
|
|
|
|
mag.put("USC",0);mag.put("VALUSC",0);
|
|
|
|
|
mag.put("ORDF",0);mag.put("VALORDF",0);
|
|
|
|
|
mag.put("ORDC",0);mag.put("VALORDC",0);
|
|
|
|
|
mag.put("SCARTI",0);mag.put("VALSCARTI",0);
|
|
|
|
|
mag.put("PRODCOMP",0);
|
|
|
|
|
mag.put("PRODFIN",0);
|
|
|
|
|
mag.put("INCL",0);
|
|
|
|
|
mag.put("ACL",0);
|
|
|
|
|
mag.put("NLABEL",0);
|
|
|
|
|
mag.rewrite();
|
|
|
|
|
mag.next();
|
|
|
|
|
}
|
|
|
|
|
articolo.unlock();
|
|
|
|
|
} else {
|
|
|
|
|
ok=FALSE;
|
|
|
|
|
mag.next();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// ricostruisce i saldi (ciclo sui movimenti)
|
|
|
|
|
TString filterexpr;
|
|
|
|
|
filterexpr << LF_MOVMAG << "->ANNOES==" << annoes;
|
|
|
|
|
TCursor cur(&rel,filterexpr); // cursore filtrato
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<cur.objects(); i++)
|
|
|
|
|
{
|
|
|
|
|
cur=i;
|
|
|
|
|
TMov_mag & mov_rec=(TMov_mag &)cur.file().curr();
|
|
|
|
|
if (!mov_rec.force_update_bal())
|
|
|
|
|
ok=FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|