Spostate qui le classi HEad_lines_record
Classi per le finestre di dialogo temporizzate Classi per la causale di magazzino git-svn-id: svn://10.65.10.50/trunk@4404 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
1788e94036
commit
b8791ea102
783
mg/mglib01.cpp
783
mg/mglib01.cpp
@ -7,6 +7,306 @@
|
||||
|
||||
#include "mglib01.h"
|
||||
|
||||
// **************************************
|
||||
// **************************************
|
||||
// **************************************
|
||||
// *** classi per la libreria
|
||||
// ***
|
||||
//*****
|
||||
// THead_lines_record
|
||||
// metodi protected
|
||||
void THead_lines_record::renum_key(const char * kfield,const char * val)
|
||||
{
|
||||
TRectype::renum_key(kfield, val); // Aggiorna testata
|
||||
_rows->renum_key(kfield, val); // Aggiorna righe
|
||||
}
|
||||
|
||||
TRectype & THead_lines_record::row(int index) const // riga del corpo
|
||||
{
|
||||
if (index > _rows->rows() || index < 0)
|
||||
CHECKD(FALSE, "Riga non esistente ", index);
|
||||
return _rows->row(index, FALSE);
|
||||
}
|
||||
|
||||
void THead_lines_record::put_str(const char* fieldname, const char* val)
|
||||
{
|
||||
TString v(val);
|
||||
// cambio
|
||||
//if (strcmp(fieldname, "TIPODOC") == 0 && TRectype::get("TIPODOC") != v)
|
||||
//{
|
||||
// TAuto_variable_rectype::put_str(fieldname, v);
|
||||
// reset_fields(*this);
|
||||
// set_fields(*this);
|
||||
//}
|
||||
//else
|
||||
{
|
||||
TAuto_variable_rectype::put_str(fieldname, v);
|
||||
dirty_fields();
|
||||
}
|
||||
}
|
||||
|
||||
//*****
|
||||
// metodi public
|
||||
THead_lines_record::THead_lines_record(int hfn, int rfn,const char *numfield):
|
||||
TAuto_variable_rectype(hfn),
|
||||
_file(hfn),
|
||||
_rfile(rfn),
|
||||
_numfield(numfield)
|
||||
{
|
||||
_rows= new TRecord_array(rfn,numfield); // inizializza il record array delle righe
|
||||
}
|
||||
|
||||
THead_lines_record::THead_lines_record(const TBaseisamfile* i,int rfn,const char *numfield):
|
||||
TAuto_variable_rectype(i),
|
||||
_numfield(numfield)
|
||||
{
|
||||
_rows= new TRecord_array(rfn,numfield); // inizializza il record array delle righe
|
||||
}
|
||||
|
||||
THead_lines_record::THead_lines_record(const TRectype & r,int rfn,const char *numfield):
|
||||
TAuto_variable_rectype(r),
|
||||
_numfield(numfield)
|
||||
{
|
||||
_rows= new TRecord_array(rfn,numfield); // inizializza il record array delle righe
|
||||
}
|
||||
|
||||
// @doc INTERNAL
|
||||
|
||||
// @mfunc costruttore di copia
|
||||
THead_lines_record::THead_lines_record(const THead_lines_record& r):
|
||||
TAuto_variable_rectype((TAuto_variable_rectype &)r)
|
||||
{
|
||||
// copia..
|
||||
_rows= new TRecord_array(* r._rows); // inizializza il record array delle righe
|
||||
_nuovo=r._nuovo;
|
||||
_file=r._file; // file principale
|
||||
_rfile=r._rfile; // file delle righe
|
||||
_numfield=r._numfield;
|
||||
}
|
||||
|
||||
THead_lines_record::~THead_lines_record()
|
||||
{
|
||||
delete _rows;
|
||||
}
|
||||
|
||||
|
||||
// setta a dirty i campi
|
||||
void THead_lines_record::dirty_fields()
|
||||
{
|
||||
}
|
||||
|
||||
TRectype & THead_lines_record::operator =(const TRectype & r)
|
||||
{
|
||||
TRectype::operator=(r);
|
||||
reset_fields(*this);
|
||||
set_fields(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
TRectype & THead_lines_record::operator =(const char * r)
|
||||
{
|
||||
TRectype::operator=(r);
|
||||
reset_fields(*this);
|
||||
set_fields(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void THead_lines_record::zero(const char * fieldname)
|
||||
{
|
||||
// resetta il record righe solo se .....
|
||||
// if (strcmp(fieldname, "TIPODOC") == 0)
|
||||
reset_fields(*this);
|
||||
TAuto_variable_rectype::zero(fieldname);
|
||||
dirty_fields();
|
||||
}
|
||||
|
||||
void THead_lines_record::zero(char c)
|
||||
{
|
||||
reset_fields(*this);
|
||||
TAuto_variable_rectype::zero(c);
|
||||
}
|
||||
|
||||
|
||||
// settaggio campi variabili
|
||||
void THead_lines_record::set_fields(TAuto_variable_rectype & rec)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int THead_lines_record::read(TBaseisamfile& f, word op, word lockop, TDate& atdate)
|
||||
{
|
||||
TRectype line_key(_rfile);
|
||||
|
||||
copy_linekey(head(),line_key);
|
||||
|
||||
int err = TRectype::read(f,op,lockop,atdate);
|
||||
if (err == NOERR)
|
||||
{
|
||||
_nuovo = FALSE;
|
||||
_rows->read(line_key); //ok
|
||||
}
|
||||
else
|
||||
{
|
||||
// nuovo oggetto: resetta tutto
|
||||
_nuovo = TRUE;
|
||||
destroy_rows();
|
||||
_rows->set_key((TRectype *)(line_key.dup())); // ok
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
/*int THead_lines_record::read(const TRectype& rec)
|
||||
{
|
||||
head() = rec;
|
||||
TRectype line_key(_rows->key());
|
||||
|
||||
copy_linekey(head(),line_key);
|
||||
|
||||
TLocalisamfile afile(_file);
|
||||
int err = TRectype::read(afile);
|
||||
if (err == NOERR)
|
||||
{
|
||||
_nuovo = FALSE;
|
||||
_rows->read(line_key); //ok
|
||||
}
|
||||
else
|
||||
{
|
||||
// nuovo oggetto: resetta tutto
|
||||
_nuovo = TRUE;
|
||||
head() = rec;
|
||||
destroy_rows();
|
||||
_rows->set_key(&line_key); // ok
|
||||
}
|
||||
return err;
|
||||
}
|
||||
*/
|
||||
int THead_lines_record::write(TBaseisamfile& f, TDate& atdate ) const
|
||||
{
|
||||
return write_rewrite(f,FALSE);
|
||||
}
|
||||
int THead_lines_record::rewrite(TBaseisamfile& f, TDate& atdate) const
|
||||
{
|
||||
return write_rewrite(f,TRUE);
|
||||
}
|
||||
|
||||
|
||||
int THead_lines_record::write_rewrite(TBaseisamfile& f,bool re ) const
|
||||
{
|
||||
const bool nuovo = _nuovo; // E' nuovo di zecca!
|
||||
if (nuovo && re) // quindi ...
|
||||
re = FALSE; // ... non fare la rewrite
|
||||
|
||||
int err = NOERR;
|
||||
if (re)
|
||||
{
|
||||
// rewrite:
|
||||
err = _rows->write(re);
|
||||
if (err == NOERR)
|
||||
{
|
||||
err = TRectype::rewrite(f);
|
||||
if (err != NOERR)
|
||||
err = TRectype::write(f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// write:
|
||||
if (nuovo)
|
||||
{
|
||||
//THead_lines_record &myself=*this;
|
||||
//if (numero() <= 0)
|
||||
// myself.renum();
|
||||
do
|
||||
{
|
||||
err = TRectype::write(f);
|
||||
if (err == _isreinsert) // usa il flag _nuovo per decidere se
|
||||
((THead_lines_record *)this)->renum();
|
||||
} while (err == _isreinsert);
|
||||
((THead_lines_record *)this)->_nuovo = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = TRectype::write(f);
|
||||
if (err != NOERR)
|
||||
err = TRectype::rewrite(f);
|
||||
}
|
||||
if (err == NOERR)
|
||||
err = _rows->write(re);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
int THead_lines_record::remove(TBaseisamfile& f, TDate& atdate ) const
|
||||
{
|
||||
int err = _rows->remove();
|
||||
if (err == NOERR)
|
||||
err = TRectype::remove(f,atdate);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
// @doc INTERNAL
|
||||
|
||||
// @mfunc costruttore di copia
|
||||
TTimed_box::TTimed_box(const char * header,const char * message,int seconds,short button_id,int x,int y)
|
||||
: TMask(header,1,x,y)
|
||||
{
|
||||
// costruisce una maschera run time
|
||||
add_memo(FIRST_FIELD, 0, "", 1, 0,-1,-3);
|
||||
set(FIRST_FIELD, message);
|
||||
|
||||
// setta il timer per l'evento
|
||||
_timer_delay=seconds *1000+1;
|
||||
_timer_id=XVT_TIMER_ERROR;
|
||||
_button_id=button_id;
|
||||
}
|
||||
|
||||
void TTimed_box::start_run()
|
||||
{
|
||||
if (_timer_id!=XVT_TIMER_ERROR)
|
||||
xvt_timer_destroy(_timer_id);
|
||||
_timer_id=xvt_timer_create(win(),_timer_delay);
|
||||
TMask::start_run();
|
||||
}
|
||||
|
||||
void TTimed_box::handler(WINDOW win, EVENT* ep)
|
||||
{
|
||||
if (ep->type == E_TIMER && ep->v.timer.id==_timer_id)
|
||||
{
|
||||
send_key(K_SPACE,DLG_OK);
|
||||
}
|
||||
TMask::handler(win, ep);
|
||||
}
|
||||
|
||||
class TTimed_breakbox: public TTimed_box
|
||||
{
|
||||
public:
|
||||
TTimed_breakbox(const char * message,int seconds,int x=40,int y=10);
|
||||
};
|
||||
|
||||
TTimed_breakbox::TTimed_breakbox(const char * message,int seconds,int x,int y)
|
||||
: TTimed_box("Richiesta di interruzione",message,seconds,DLG_OK,x,y)
|
||||
{
|
||||
add_button(DLG_CANCEL, 0, "Interrompi", -22, -1, 12, 2,"",0);
|
||||
add_button(DLG_OK, 0, "Riprova", -12, -1, 12, 2,"",0);
|
||||
}
|
||||
|
||||
|
||||
// **********************************
|
||||
// **********************************
|
||||
// **********************************
|
||||
// **********************************
|
||||
// fine classi per la libreria
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************
|
||||
// classe livelli giacenze
|
||||
@ -15,6 +315,7 @@ TMag_livelli:: TMag_livelli(const char *tabname)
|
||||
TTable _tabformato(tabname);
|
||||
int e;
|
||||
|
||||
_last_level=0;
|
||||
e=_tabformato.first();
|
||||
for (int i=0; i< MANY_MAG_LEV; i++) {
|
||||
_enabled[i]=(e==NOERR);
|
||||
@ -76,14 +377,15 @@ void TMag_livelli::pack_grpcode(TString & pc, const TString &codlev, const int l
|
||||
TString TMag_livelli::unpack_grpcode(const TString & pc, const int levnum)
|
||||
{
|
||||
int start=0;
|
||||
if (!_enabled[levnum-1])
|
||||
return("");
|
||||
for (int i=1; i<levnum; i++)
|
||||
start+= _code_lenght[i-1];
|
||||
if (start>=pc.len())
|
||||
return("");
|
||||
else
|
||||
else {
|
||||
if (levnum != _last_level && !_enabled[levnum-1])
|
||||
return("");
|
||||
return(pc.mid(start,levnum == _last_level ? -1 : _code_lenght[levnum-1]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -435,6 +737,9 @@ void TMetachar::add_tran(int s,unsigned char metasymbol, int nextstate)
|
||||
for (c=MAXSIMBOLS-1;c>=FIRST_NEMPTY_SYMBOL;c--)
|
||||
_au->add_tran(s,c,nextstate);
|
||||
break;
|
||||
default:
|
||||
_au->add_tran(s,metasymbol,nextstate);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -465,53 +770,34 @@ void TMetachar::set_language(const char * language)
|
||||
if (!escaped_char)
|
||||
{
|
||||
// meta-caratteri e literal fuori set
|
||||
s=_au->add_state(label);
|
||||
switch (language[i]) {
|
||||
case '0':// cifra obbligatoria
|
||||
s=_au->add_state(label);
|
||||
add_tran(s,S_DIGIT,s+1);
|
||||
break;
|
||||
case '9':// cifra opzionale
|
||||
s=_au->add_state(label);
|
||||
add_tran(s,EPSILON,s+1);
|
||||
add_tran(s,S_DIGIT,s+1);
|
||||
break;
|
||||
case '#':// cifra o blank opzionale
|
||||
s=_au->add_state(label);
|
||||
add_tran(s,EPSILON,s+1);
|
||||
add_tran(s,S_BLANK,s+1);
|
||||
add_tran(s,'-',s+1);
|
||||
add_tran(s,'+',s+1);
|
||||
case '9':// cifra opzionale
|
||||
add_tran(s,EPSILON,s+1);
|
||||
case '0':// cifra obbligatoria
|
||||
add_tran(s,S_DIGIT,s+1);
|
||||
break;
|
||||
case 'L': // lettera obbligatoria
|
||||
s=_au->add_state(label);
|
||||
add_tran(s,S_LETTER,s+1);
|
||||
break;
|
||||
case '?': // lettera opzionale
|
||||
s=_au->add_state(label);
|
||||
add_tran(s,EPSILON,s+1);
|
||||
case 'L': // lettera obbligatoria
|
||||
add_tran(s,S_LETTER,s+1);
|
||||
break;
|
||||
case 'A': // lettera o numero obbligatorio
|
||||
s=_au->add_state(label);
|
||||
add_tran(s,S_LETTER,s+1);
|
||||
add_tran(s,S_DIGIT,s+1);
|
||||
break;
|
||||
case 'a': // lettera o numero opzionale
|
||||
s=_au->add_state(label);
|
||||
add_tran(s,EPSILON,s+1);
|
||||
case 'A': // lettera o numero obbligatorio
|
||||
add_tran(s,S_LETTER,s+1);
|
||||
add_tran(s,S_DIGIT,s+1);
|
||||
break;
|
||||
case '&': // qualsiasi carattere obbligatorio
|
||||
s=_au->add_state(label);
|
||||
add_tran(s,S_ANY,s+1);
|
||||
break;
|
||||
case 'c': // qualsiasi carattere opzionale
|
||||
s=_au->add_state(label);
|
||||
add_tran(s,EPSILON,s+1);
|
||||
case '&': // qualsiasi carattere obbligatorio
|
||||
add_tran(s,S_ANY,s+1);
|
||||
break;
|
||||
default:
|
||||
s=_au->add_state(label);
|
||||
_au->add_tran(s,language[i],s+1);
|
||||
break;
|
||||
}
|
||||
@ -600,3 +886,438 @@ TMetachar::~TMetachar ()
|
||||
delete _au;
|
||||
}
|
||||
|
||||
|
||||
// **************************************
|
||||
// **************************************
|
||||
// **************************************
|
||||
// *** classi per il magazzino
|
||||
// ***
|
||||
long giac_last_item(const char * annoes, const char *codart)
|
||||
{
|
||||
long r=0;
|
||||
TLocalisamfile mag(LF_MAG);
|
||||
mag.put("ANNOES",annoes);
|
||||
mag.put("CODART",codart);
|
||||
mag.put("NRIGA",1);
|
||||
if (mag.read()==NOERR)
|
||||
{
|
||||
do {
|
||||
r=mag.get_long("NRIGA");
|
||||
} while (mag.next()==NOERR && mag.get("CODART")==codart);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
// *********************
|
||||
// movimenti di magazzino
|
||||
|
||||
// causali
|
||||
|
||||
int TCausale_magazzino::sgn(TTipo_saldomag tiposaldo)
|
||||
{
|
||||
switch (tiposaldo) {
|
||||
case s_giac:
|
||||
return get_int("I0");
|
||||
case s_acq:
|
||||
return get_int("I1");
|
||||
case s_ent:
|
||||
return get_int("I2");
|
||||
case s_ven:
|
||||
return get_int("I3");
|
||||
case s_usc:
|
||||
return get_int("I4");
|
||||
case s_ordc:
|
||||
return get_int("I5");
|
||||
case s_ordf:
|
||||
return get_int("I6");
|
||||
case s_incl:
|
||||
return get_int("I7");
|
||||
case s_acl:
|
||||
return get_int("I8");
|
||||
case s_prodc:
|
||||
return get_int("I9");
|
||||
case s_prodf:
|
||||
return get_int("I10");
|
||||
case s_rim:
|
||||
return get_int("I11");
|
||||
case s_scart:
|
||||
return get_int("I12");
|
||||
case s_label:
|
||||
return get_int("I13");
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TCausale_magazzino::TCausale_magazzino(const char * codice):
|
||||
TRectype(LF_TAB)
|
||||
{
|
||||
TTable f("CAU");
|
||||
f.put("CODTAB",codice);
|
||||
if (f.read() != NOERR)
|
||||
zero();
|
||||
else
|
||||
*this=(TCausale_magazzino &)f.curr();
|
||||
}
|
||||
|
||||
// movimenti
|
||||
TLine_movmag ::TLine_movmag(const TLine_movmag &l)
|
||||
{
|
||||
um=l.um;
|
||||
quant=l.quant;
|
||||
prezzo=l.prezzo;
|
||||
}
|
||||
|
||||
int TLine_movmag::operator==(TLine_movmag &l)
|
||||
{
|
||||
return (um==l.um)&&(quant==l.quant)&&(prezzo==l.prezzo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TMov_mag::TMov_mag() :
|
||||
THead_lines_record(LF_MOVMAG,LF_RMOVMAG,"NRIG"),
|
||||
lines_to_add(), lines_to_subtract()
|
||||
{
|
||||
}
|
||||
|
||||
TMov_mag::~TMov_mag()
|
||||
{
|
||||
}
|
||||
//void TMov_mag::dirty_fields()
|
||||
//{
|
||||
//}
|
||||
|
||||
// rinumerazione automatica: numdoc>=0
|
||||
// (con creazione nuova chiave)
|
||||
long TMov_mag::renum(long numdoc)
|
||||
{
|
||||
if (numdoc <= 0)
|
||||
numdoc = atoi(get_next_key());
|
||||
char num[16]; sprintf(num, "%ld", numdoc);
|
||||
renum_key("NUMREG", num); // Aggiorna testata
|
||||
return numdoc;
|
||||
}
|
||||
|
||||
// copia la chiave dal file principale a quello delle righe
|
||||
void TMov_mag::copy_linekey(const TRectype & headrec, TRectype & linesrec)
|
||||
{
|
||||
// ...qui basta una put tra Rectype....
|
||||
linesrec.put("NUMREG",headrec.get("NUMREG")) ;
|
||||
}
|
||||
|
||||
int TMov_mag::read(TBaseisamfile& f, word op , word lockop, TDate& atdate)
|
||||
{
|
||||
TToken_string l_key;
|
||||
TLine_movmag l_data;
|
||||
|
||||
int res=THead_lines_record::read(f,op,lockop,atdate);
|
||||
// reset delle strutture per il controlli delle variazioni dei saldi
|
||||
_codcaus=get("CODCAUS");
|
||||
_annoes=get("ANNOES");
|
||||
lines_to_add.destroy();
|
||||
lines_to_subtract.destroy();
|
||||
for (int i=0; i<rows(); i++) {
|
||||
l_key=line2key(i+1);
|
||||
l_data=line2data(i+1);
|
||||
delete_line(l_key,l_data);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
int TMov_mag::remove(TBaseisamfile& f, TDate& atdate ) const
|
||||
{
|
||||
int res;
|
||||
if ((res=THead_lines_record::remove(f,atdate))==NOERR )
|
||||
// effettua la variazione dei saldi
|
||||
res=update_balances();
|
||||
return res;
|
||||
}
|
||||
|
||||
int TMov_mag::write(TBaseisamfile& f, TDate& atdate ) const
|
||||
{
|
||||
int res;
|
||||
TToken_string l_key;
|
||||
TLine_movmag l_data;
|
||||
// memorizza le variazioni
|
||||
for (int i=0; i<rows(); i++) {
|
||||
l_key=line2key(i+1);
|
||||
l_data=line2data(i+1);
|
||||
((TMov_mag *)this)->insert_line(l_key,l_data);
|
||||
}
|
||||
if ((res=THead_lines_record::write(f,atdate))==NOERR )
|
||||
// effettua la variazione dei saldi
|
||||
res=update_balances();
|
||||
return res;
|
||||
}
|
||||
|
||||
int TMov_mag::rewrite(TBaseisamfile& f, TDate& atdate ) const
|
||||
{
|
||||
int res;
|
||||
TToken_string l_key;
|
||||
TLine_movmag l_data;
|
||||
// memorizza le variazioni
|
||||
for (int i=0; i<rows(); i++) {
|
||||
l_key=line2key(i+1);
|
||||
l_data=line2data(i+1);
|
||||
((TMov_mag *)this)->insert_line(l_key,l_data);
|
||||
}
|
||||
if ((res=THead_lines_record::rewrite(f,atdate))==NOERR )
|
||||
// effettua la variazione dei saldi
|
||||
res=update_balances();
|
||||
return res;
|
||||
}
|
||||
|
||||
const char *TMov_mag::get_next_key()
|
||||
{
|
||||
TLocalisamfile f(LF_MOVMAG);
|
||||
f.last();
|
||||
int a=atoi(f.get("NUMREG"))+1;
|
||||
return _nextcod.format("%d",a);
|
||||
}
|
||||
|
||||
|
||||
// settaggio campi variabili
|
||||
//void TMov_mag::set_fields(TAuto_variable_rectype & rec)
|
||||
//{
|
||||
//}
|
||||
|
||||
|
||||
//*******
|
||||
// gestione delle variazione dei saldi
|
||||
//
|
||||
//
|
||||
TLine_movmag TMov_mag::line2data(int numriga) const
|
||||
{
|
||||
TLine_movmag rest;
|
||||
rest.um=row(numriga).get("UM");
|
||||
rest.quant=(const char *)row(numriga).get("QUANT");
|
||||
rest.prezzo=(const char *)row(numriga).get("PREZZO");
|
||||
return rest;
|
||||
}
|
||||
|
||||
TToken_string TMov_mag::line2key(int numriga) const
|
||||
{
|
||||
TToken_string key;
|
||||
key.add(row(numriga).get("CODART"));
|
||||
key.add(row(numriga).get("CODMAG"));
|
||||
key.add(row(numriga).get("LIVGIAC"));
|
||||
return key;
|
||||
}
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
||||
|
||||
int TMov_mag::insert_line(TToken_string &k,TLine_movmag &r)
|
||||
{
|
||||
if (_codcaus != get("CODCAUS") || _annoes != get("ANNOES")) {
|
||||
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;
|
||||
}
|
||||
|
||||
int TMov_mag::delete_line(TToken_string &k,TLine_movmag &r)
|
||||
{
|
||||
if (_codcaus != get("CODCAUS") || _annoes != get("ANNOES")) {
|
||||
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à 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_putkey2(TLocalisamfile & mag,TString16 annoes,TToken_string curr_key)
|
||||
{
|
||||
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"));
|
||||
}
|
||||
|
||||
|
||||
// aggiorna tutti i saldi in base alle modifiche fatte.
|
||||
// il lock su anagrafica dovrebbe garantire il lock su tutte le
|
||||
// giacenze dell'articolo
|
||||
int TMov_mag::update_balances() const
|
||||
{
|
||||
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();
|
||||
|
||||
while (curr_key) {
|
||||
if (lock_anamag(key2field(*curr_key,"CODART"))) {
|
||||
// lock gained
|
||||
giac_putkey2(mag,get("ANNOES"),*curr_key);
|
||||
if (mag.read()!=NOERR) {
|
||||
// non trovato: aggiungo
|
||||
giac_putkey2(mag,get("ANNOES"),*curr_key);
|
||||
mag.put("NRIGA",giac_last_item(get("ANNOES"),key2field(*curr_key,"CODART"))+1);
|
||||
mag.write();
|
||||
}
|
||||
// modifica questo record (e lo sblocca)
|
||||
update_balances(mag.curr(),(TLine_movmag &)lines_to_add[*curr_key],get("CODCAUS"),+1);
|
||||
/*// ottimizzazione :(cerca di sfruttare la lettura fatta per un eventuale saldo vecchio)
|
||||
// ciò causa la modifica dell'oggetto TMov_mag (il metodo non è più const)
|
||||
if (_annoes == get("ANNOES")
|
||||
&& lines_to_subtract.is_key(*curr_key)) {
|
||||
update_balances(mag.curr(),(TLine_movmag &)lines_to_subtract[*curr_key],_codcaus,-1);
|
||||
((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_putkey2(mag,_annoes,*rem_key);
|
||||
if (mag.read()==NOERR) {
|
||||
update_balances(mag.curr(),(TLine_movmag &)lines_to_subtract[*rem_key],_codcaus,-1);
|
||||
mag.rewrite();
|
||||
}
|
||||
keys_to_remove.remove_item();
|
||||
}
|
||||
rem_key=(TToken_string *)keys_to_remove.succ_item();
|
||||
}
|
||||
unlock_anamag(key2field(*curr_key,"CODART"));
|
||||
} else {
|
||||
updated_bal=FALSE;
|
||||
}
|
||||
curr_key=(TToken_string *)keys_to_add.succ_item();
|
||||
}
|
||||
// togli i saldi vecchi
|
||||
curr_key=(TToken_string *)keys_to_remove.first_item();
|
||||
|
||||
while (curr_key) {
|
||||
if (lock_anamag(key2field(*curr_key,"CODART"))) {
|
||||
giac_putkey2(mag,_annoes,*curr_key);
|
||||
// modifica questo record (e lo sblocca)
|
||||
if (mag.read()==NOERR) {
|
||||
update_balances(mag.curr(),(TLine_movmag &)lines_to_subtract[*curr_key],_codcaus,-1);
|
||||
mag.rewrite();
|
||||
}
|
||||
unlock_anamag(key2field(*curr_key,"CODART"));
|
||||
} 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 0;
|
||||
}
|
||||
|
||||
// aggiorna i saldi del record corrente
|
||||
// in base alla causale e alla modifica fatta (con segno + o -)
|
||||
int TMov_mag::update_balances(TRectype & magrec, const TLine_movmag &l,TString16 codcaus,int rett_sign) const
|
||||
{
|
||||
TCausale_magazzino caus(codcaus);
|
||||
TLocalisamfile anamag(LF_ANAMAG);
|
||||
TLocalisamfile umart(LF_UMART);
|
||||
real diff,diff_val;
|
||||
umart.put("CODART",magrec.get("CODART"));
|
||||
umart.put("UM",l.um);
|
||||
umart.read();
|
||||
real fc=umart.get_real("FC");
|
||||
|
||||
diff=fc*rett_sign*l.quant;
|
||||
diff_val=diff*l.prezzo;
|
||||
update_balance(magrec,"GIAC",diff*caus.sgn(s_giac)); // update ..
|
||||
update_balance(magrec,"ACQ",diff*caus.sgn(s_acq)); // update ..
|
||||
update_balance(magrec,"VALACQ",diff_val*caus.sgn(s_acq)); // update ..
|
||||
update_balance(magrec,"ENT",diff*caus.sgn(s_ent));
|
||||
update_balance(magrec,"VALENT",diff_val*caus.sgn(s_ent));
|
||||
update_balance(magrec,"VEN",diff*caus.sgn(s_ven));
|
||||
update_balance(magrec,"VALVEN",diff_val*caus.sgn(s_ven));
|
||||
update_balance(magrec,"USC",diff*caus.sgn(s_usc));
|
||||
update_balance(magrec,"VALUSC",diff_val*caus.sgn(s_usc));
|
||||
update_balance(magrec,"ORDC",diff*caus.sgn(s_ordc));
|
||||
update_balance(magrec,"VALORDC",diff_val*caus.sgn(s_ordc));
|
||||
update_balance(magrec,"ORDF",diff*caus.sgn(s_ordf));
|
||||
update_balance(magrec,"VALORDF",diff_val*caus.sgn(s_ordf));
|
||||
update_balance(magrec,"RIM",diff*caus.sgn(s_rim));
|
||||
update_balance(magrec,"VALRIM",diff_val*caus.sgn(s_rim));
|
||||
update_balance(magrec,"SCARTI",diff*caus.sgn(s_scart));
|
||||
update_balance(magrec,"VALSCARTI",diff_val*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));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void TMov_mag::update_balance(TRectype & magrec, const char * fieldname, real diff) const
|
||||
{
|
||||
magrec.put(fieldname,magrec.get_int(fieldname)+diff);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int TMov_mag::codice_esercizio(TDate &d)
|
||||
{
|
||||
return _esercizi.date2esc(d);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
225
mg/mglib01.h
225
mg/mglib01.h
@ -1,5 +1,131 @@
|
||||
// *******************************
|
||||
// LIBRERIA DI utility del magazzino
|
||||
// *******************************
|
||||
|
||||
// **************************************
|
||||
// **************************************
|
||||
// **************************************
|
||||
// *** classi per la libreria
|
||||
// ***
|
||||
#include <varrec.h>
|
||||
#include <msksheet.h>
|
||||
class THead_lines_record ;
|
||||
//**************************************
|
||||
// classe per il controllo dei record composti da una testata e N righe
|
||||
// è implementato come un TRectype che contiene anche un TRecord_array
|
||||
//
|
||||
class THead_lines_record : public TAuto_variable_rectype {
|
||||
|
||||
// @ cmember Array di TRectype per le righe
|
||||
TRecord_array * _rows; //
|
||||
// @ cmember flag indicatore di record nuovo
|
||||
bool _nuovo;
|
||||
// @ cmember file principale
|
||||
int _file;
|
||||
// @ cmember file delle righe
|
||||
int _rfile;
|
||||
// @ cmember nome del campo "numeratore" delle righe
|
||||
TString _numfield;
|
||||
|
||||
|
||||
protected:
|
||||
// @ cmember restituisce la riga del corpo
|
||||
virtual TRectype & row(int index) const;
|
||||
virtual void put_str(const char* fieldname, const char* val);
|
||||
// @ cmember funzione per estrarre dal record della testata la chiave delle righe
|
||||
virtual void copy_linekey(const TRectype & headrecord, TRectype & linesrecord)=0;
|
||||
// @ cmember renumer la chiave del corpo
|
||||
virtual long renum(long numdoc=-1)=0;
|
||||
|
||||
int write_rewrite(TBaseisamfile& f ,bool re = FALSE) const ;
|
||||
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 numero di record nel corpo
|
||||
int rows() const { return _rows->rows(); }
|
||||
// @ cmember restituisce il record array del corpo
|
||||
TRecord_array * rows_record() { return _rows; }
|
||||
|
||||
// @ cmember restituisce il record n-esimo del del corpo
|
||||
virtual const TRectype& operator[](int index) const
|
||||
{ return (const TRectype&)((THead_lines_record *)this)->row(index); }
|
||||
// @ cmember restituisce il record n-esimo del del corpo
|
||||
virtual TRectype& operator[](int index)
|
||||
{ return (TRectype&)row(index); }
|
||||
|
||||
TRectype & insert_row(int row, const char *tipo = NULL);
|
||||
TRectype & new_row(const char *tipo = NULL);
|
||||
bool destroy_row(int n, bool pack = FALSE) { return _rows->destroy_row(n, pack); }
|
||||
void destroy_rows() { _rows->destroy_rows(); }
|
||||
|
||||
//***********************
|
||||
// record e I/O
|
||||
virtual void dirty_fields();
|
||||
|
||||
virtual const char *get_next_key() =0 ;
|
||||
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(const char * fieldname);
|
||||
virtual void zero(char c = '\0');
|
||||
|
||||
void reset_fields(TAuto_variable_rectype & rec) { rec.remove_field(); }
|
||||
virtual void set_fields(TAuto_variable_rectype & rec);
|
||||
|
||||
virtual int read(TBaseisamfile& f, word op = _isequal, word lockop = _nolock, TDate& atdate = (TDate&)botime);
|
||||
|
||||
virtual int write(TBaseisamfile& f, TDate& atdate = (TDate&)botime) const ;
|
||||
virtual int rewrite(TBaseisamfile& f, TDate& atdate = (TDate&)botime) const ;
|
||||
virtual int remove(TBaseisamfile& f, TDate& atdate = (TDate&)botime) const ;
|
||||
|
||||
//**************************
|
||||
// @ cmember costruttore dal numero del file
|
||||
THead_lines_record(int hfn, int rfn,const char *numfield);
|
||||
// @ cmember costruttore dal file
|
||||
THead_lines_record(const TBaseisamfile* head_file,int rfn,const char *numfield);
|
||||
// @ cmember costruttore dal record
|
||||
THead_lines_record(const TRectype & r,int rfn,const char *numfield);
|
||||
// @ cmember costruttore di copia
|
||||
THead_lines_record(const THead_lines_record& r);
|
||||
virtual ~THead_lines_record();
|
||||
};
|
||||
|
||||
//**********************
|
||||
// classe per la gestione delle finestre temporizzate
|
||||
class TTimed_box: public TMask
|
||||
{
|
||||
long _timer_delay;
|
||||
long _timer_id;
|
||||
short _button_id;
|
||||
protected:
|
||||
virtual void handler(WINDOW win, EVENT* ep);
|
||||
virtual void start_run();
|
||||
public:
|
||||
TTimed_box(const char * header,const char * message,int seconds,short button_id,int x,int y);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************
|
||||
// **************************************
|
||||
// **************************************
|
||||
// fine classi da portare in libreria:
|
||||
|
||||
// *******************************
|
||||
// LIBRERIA DI utility del magazzino
|
||||
// *******************************
|
||||
#include "..\cg\cglib.h"
|
||||
//#include "..\ve\velib03.h"
|
||||
|
||||
|
||||
#define MANY_MAG_LEV 10
|
||||
class TMag_livelli {
|
||||
bool _enabled[MANY_MAG_LEV];
|
||||
@ -114,3 +240,102 @@ public:
|
||||
~TMetachar();
|
||||
};
|
||||
|
||||
// *********************
|
||||
// classe che incapsula le causali di magazzino (record della tabella CAU)
|
||||
typedef enum {
|
||||
s_giac,
|
||||
s_acq,s_ent,
|
||||
s_ven,s_usc,
|
||||
s_ordc,s_ordf,
|
||||
s_acl,s_incl,
|
||||
s_prodc,s_prodf,
|
||||
s_rim,
|
||||
s_scart,
|
||||
s_label
|
||||
} TTipo_saldomag;
|
||||
|
||||
class TCausale_magazzino : public TRectype {
|
||||
public:
|
||||
const char * get_descr() {return get("S0");}
|
||||
const char get_tipoprz() {return get_char("S6");}
|
||||
const char get_tipomov() {return get_char("S7");}
|
||||
const char * get_raggfisc() {return get("S8");}
|
||||
int sgn(TTipo_saldomag fieldname) ;
|
||||
TCausale_magazzino(const char * codice);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class TLine_movmag ; // convenience...
|
||||
|
||||
// dati della linea di movimento di magazzino
|
||||
class TLine_movmag : public TObject {
|
||||
public:
|
||||
TString16 um;
|
||||
real quant;
|
||||
real prezzo;
|
||||
int operator==(TLine_movmag &);
|
||||
|
||||
virtual TObject* dup() const {return new TLine_movmag(*this);};
|
||||
|
||||
TLine_movmag() {};
|
||||
TLine_movmag(const TLine_movmag &);
|
||||
virtual ~TLine_movmag() {};
|
||||
};
|
||||
|
||||
// classe per la definizione dei movimenti di magazzino
|
||||
// ( un movimento (testata+righe) == un oggetto TMov_mag )
|
||||
class TMov_mag : public THead_lines_record {
|
||||
|
||||
TEsercizi_contabili _esercizi;
|
||||
//
|
||||
TString16 _codcaus;
|
||||
TString16 _annoes;
|
||||
//
|
||||
TString16 _nextcod;
|
||||
//
|
||||
TAssoc_array lines_to_add;
|
||||
TAssoc_array lines_to_subtract;
|
||||
|
||||
protected:
|
||||
virtual void copy_linekey(const TRectype & headrecord, TRectype & linesrecord );
|
||||
virtual long renum(long numdoc=-1); // rinumerazione ;
|
||||
|
||||
// ************ gestione saldi
|
||||
// @member: compone le parti chiave + dati a partire dalla riga dello sheet
|
||||
void line2key_data(int numriga, TToken_string &key,TLine_movmag &rest) const;
|
||||
// @member: compone la chiave a partire dalla riga dello sheet
|
||||
TToken_string line2key(int numriga) const;
|
||||
// @member: compone la dati a partire dalla riga dello sheet
|
||||
TLine_movmag line2data(int numriga) const;
|
||||
// @member: estrae dalla Tokenstring della chiave i valori corrispondenti ai campi del file
|
||||
static TString key2field(TToken_string &key,const char * f);
|
||||
// @member: memorizza la linea come "da togliere"
|
||||
int delete_line(TToken_string &key,TLine_movmag &rest);
|
||||
// @member: memorizza la linea come "da aggiungere"
|
||||
int insert_line(TToken_string &key,TLine_movmag &rest);
|
||||
// @member: effettua l'aggiornamento dei saldi relativi alle giacenze interessate al movimento
|
||||
int update_balances() const;
|
||||
// @member: effettua l'aggiornamento dei saldi di una giacenza
|
||||
int update_balances(TRectype & magrec, const TLine_movmag &l,TString16 codcaus,int sign) const;
|
||||
// @member: effettua l'aggiornamento di un saldo di una giacenza
|
||||
void update_balance(TRectype & magrec, const char * fieldname, real diff) const;
|
||||
|
||||
static void giac_putkey2(TLocalisamfile & mag,TString16 annoes,TToken_string curr_key);
|
||||
static bool lock_anamag(const char *codart);
|
||||
static bool unlock_anamag(const char *codart) ;
|
||||
public:
|
||||
// IO ad alto livello
|
||||
virtual const char *get_next_key() ;
|
||||
virtual int read(TBaseisamfile& f, word op = _isequal, word lockop = _nolock, TDate& atdate = (TDate&)botime);
|
||||
virtual int remove(TBaseisamfile& f, TDate& atdate = (TDate&)botime) const ;
|
||||
virtual int write(TBaseisamfile& f, TDate& atdate = (TDate&)botime) const ;
|
||||
virtual int rewrite(TBaseisamfile& f, TDate& atdate = (TDate&)botime) const ;
|
||||
|
||||
//
|
||||
int codice_esercizio(TDate &d);
|
||||
// costruttori e distruttori
|
||||
TMov_mag();
|
||||
virtual ~TMov_mag();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user