Riordino
git-svn-id: svn://10.65.10.50/trunk@4522 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
a3b4ca81f9
commit
60e67cef72
471
mg/mglib01.cpp
471
mg/mglib01.cpp
@ -1,3 +1,6 @@
|
||||
// gestione livelli di giacenza e articoli
|
||||
// oggetto movimento di magazzino
|
||||
// funzione di ricostruzione saldi
|
||||
#include <relapp.h>
|
||||
#include <tabutil.h>
|
||||
#include <recarray.h>
|
||||
@ -6,6 +9,10 @@
|
||||
#include <defmask.h>
|
||||
|
||||
#include "mglib01.h"
|
||||
#include "mglib02.h"
|
||||
#include "anamag.h"
|
||||
#include "umart.h"
|
||||
#include "mag.h"
|
||||
#include "..\cg\cglib.h"
|
||||
|
||||
// **************************************
|
||||
@ -138,9 +145,30 @@ int THead_lines_record::read(TBaseisamfile& f, word op, word lockop)
|
||||
{
|
||||
TRectype line_key(_rfile);
|
||||
|
||||
copy_linekey(head(),line_key);
|
||||
|
||||
int err = TRectype::read(f,op,lockop);
|
||||
|
||||
copy_linekey(head(),line_key);
|
||||
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::readat(TBaseisamfile& f, TRecnotype nrec, word lockop)
|
||||
{
|
||||
TRectype line_key(_rfile);
|
||||
|
||||
int err = TRectype::readat(f,nrec,lockop);
|
||||
|
||||
if (err == NOERR)
|
||||
{
|
||||
_nuovo = FALSE;
|
||||
@ -156,6 +184,7 @@ int THead_lines_record::read(TBaseisamfile& f, word op, word lockop)
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/*int THead_lines_record::read(const TRectype& rec)
|
||||
{
|
||||
head() = rec;
|
||||
@ -185,6 +214,7 @@ int THead_lines_record::write(TBaseisamfile& f) const
|
||||
{
|
||||
return write_rewrite(f,FALSE);
|
||||
}
|
||||
|
||||
int THead_lines_record::rewrite(TBaseisamfile& f) const
|
||||
{
|
||||
return write_rewrite(f,TRUE);
|
||||
@ -247,53 +277,6 @@ int THead_lines_record::remove(TBaseisamfile& f) const
|
||||
}
|
||||
|
||||
|
||||
// @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);
|
||||
}
|
||||
|
||||
|
||||
// **********************************
|
||||
// **********************************
|
||||
// **********************************
|
||||
@ -344,12 +327,21 @@ const bool TMag_livelli::enabled(int levnum)
|
||||
|
||||
const int TMag_livelli::code_lenght(int levnum)
|
||||
{
|
||||
if (levnum<=MANY_MAG_LEV && levnum>0)
|
||||
return(_code_lenght[levnum-1]);
|
||||
else
|
||||
return(0) ;
|
||||
if (levnum<=MANY_MAG_LEV && levnum>0)
|
||||
return(_code_lenght[levnum-1]);
|
||||
else
|
||||
return(0) ;
|
||||
}
|
||||
|
||||
const int TMag_livelli::packed_lenght(int levnum)
|
||||
{
|
||||
int start=0;
|
||||
for (int i=1; i<=levnum && levnum<=MANY_MAG_LEV; i++)
|
||||
start+= _code_lenght[i-1];
|
||||
return start;
|
||||
}
|
||||
|
||||
|
||||
const TString & TMag_livelli::name(int levnum)
|
||||
{
|
||||
if (levnum<=MANY_MAG_LEV && levnum>0)
|
||||
@ -368,27 +360,33 @@ const TString & TMag_livelli::picture(int levnum)
|
||||
|
||||
void TMag_livelli::pack_grpcode(TString & pc, const TString &codlev, const int levnum)
|
||||
{
|
||||
|
||||
int start=0;
|
||||
for (int i=1; i<levnum; i++)
|
||||
start+= _code_lenght[i-1];
|
||||
pc.overwrite(codlev.left(_code_lenght[levnum-1]),start);
|
||||
pc.overwrite(codlev.left(_code_lenght[levnum-1]),packed_lenght(levnum-1));
|
||||
}
|
||||
|
||||
TString TMag_livelli::unpack_grpcode(const TString & pc, const int levnum)
|
||||
{
|
||||
int start=0;
|
||||
for (int i=1; i<levnum; i++)
|
||||
start+= _code_lenght[i-1];
|
||||
if (start>=pc.len())
|
||||
return("");
|
||||
else {
|
||||
if (levnum != _last_level && !_enabled[levnum-1])
|
||||
return("");
|
||||
return(pc.mid(start,levnum == _last_level ? -1 : _code_lenght[levnum-1]));
|
||||
}
|
||||
int start=0;
|
||||
for (int i=1; i<levnum; i++)
|
||||
start+= _code_lenght[i-1];
|
||||
if (start>=pc.len())
|
||||
return("");
|
||||
else {
|
||||
if (levnum != _last_level && !_enabled[levnum-1])
|
||||
return("");
|
||||
return(pc.mid(start,levnum == _last_level ? -1 : _code_lenght[levnum-1]));
|
||||
}
|
||||
}
|
||||
|
||||
TString TMag_livelli::build_tabcode(const TString & pc, const int levnum)
|
||||
{
|
||||
TString valore;
|
||||
valore << levnum;
|
||||
valore << unpack_grpcode(pc,levnum);
|
||||
if (valore.len()>1)
|
||||
return valore;
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
// *******************************
|
||||
// *******************************
|
||||
@ -952,14 +950,17 @@ int TCausale_magazzino::sgn(TTipo_saldomag tiposaldo)
|
||||
|
||||
|
||||
TCausale_magazzino::TCausale_magazzino(const char * codice):
|
||||
TRectype(LF_TAB)
|
||||
TRectype(LF_TAB)
|
||||
{
|
||||
TTable f("CAU");
|
||||
f.put("CODTAB",codice);
|
||||
if (f.read() != NOERR)
|
||||
zero();
|
||||
else
|
||||
*this=(TCausale_magazzino &)f.curr();
|
||||
}
|
||||
TCausale_magazzino::~TCausale_magazzino()
|
||||
{
|
||||
TTable f("CAU");
|
||||
f.put("CODTAB",codice);
|
||||
if (f.read() != NOERR)
|
||||
zero();
|
||||
else
|
||||
*this=(TCausale_magazzino &)f.curr();
|
||||
}
|
||||
|
||||
// movimenti
|
||||
@ -1037,6 +1038,27 @@ int TMov_mag::remove(TBaseisamfile& f) const
|
||||
return res;
|
||||
}
|
||||
|
||||
int TMov_mag::force_update_bal()
|
||||
{
|
||||
int res;
|
||||
TToken_string l_key;
|
||||
TLine_movmag l_data;
|
||||
|
||||
// reset delle strutture per il controlli delle variazioni dei saldi
|
||||
_codcaus=get("CODCAUS");
|
||||
_annoes=get("ANNOES");
|
||||
lines_to_add.destroy();
|
||||
lines_to_subtract.destroy();
|
||||
// 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);
|
||||
}
|
||||
res=update_balances();
|
||||
return res;
|
||||
}
|
||||
|
||||
int TMov_mag::write(TBaseisamfile& f) const
|
||||
{
|
||||
int res;
|
||||
@ -1174,13 +1196,13 @@ bool TMov_mag::lock_anamag(const char *codart)
|
||||
}
|
||||
|
||||
|
||||
void TMov_mag::giac_putkey2(TLocalisamfile & mag,TString16 annoes,TToken_string curr_key)
|
||||
void TMov_mag::giac_putkey(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"));
|
||||
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"));
|
||||
}
|
||||
|
||||
|
||||
@ -1202,108 +1224,112 @@ int TMov_mag::update_balances() const
|
||||
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
|
||||
while (curr_key) {
|
||||
TArticolo articolo(key2field(*curr_key,"CODART"));
|
||||
if (articolo.lock_and_prompt()) {
|
||||
TLine_movmag & line_mov=(TLine_movmag &)lines_to_add[*curr_key];
|
||||
articolo.update_ultcosti(line_mov.prezzo,get_date("DATACOMP"));
|
||||
// lock gained
|
||||
giac_putkey(mag,get("ANNOES"),*curr_key);
|
||||
if (mag.read()!=NOERR) {
|
||||
// non trovato: aggiungo
|
||||
giac_putkey(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(),line_mov,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_putkey(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();
|
||||
}
|
||||
articolo.unlock();
|
||||
} 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;
|
||||
while (curr_key) {
|
||||
TArticolo articolo(key2field(*curr_key,"CODART"));
|
||||
if (articolo.lock_and_prompt()) {
|
||||
giac_putkey(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();
|
||||
}
|
||||
articolo.unlock();
|
||||
} 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;
|
||||
}
|
||||
|
||||
// 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");
|
||||
TCausale_magazzino caus(codcaus);
|
||||
TLocalisamfile umart(LF_UMART);
|
||||
real diff,diff_val;
|
||||
umart.setkey(2);
|
||||
umart.put(UMART_CODART,magrec.get(MAG_CODART));
|
||||
umart.put(UMART_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;
|
||||
diff=fc*rett_sign*l.quant;
|
||||
diff_val=rett_sign*l.quant*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;
|
||||
}
|
||||
|
||||
|
||||
@ -1322,3 +1348,100 @@ int TMov_mag::codice_esercizio(TDate &d)
|
||||
|
||||
|
||||
|
||||
//**********************
|
||||
bool rebuild_balances(TString16 annoes, bool reset_giac)
|
||||
{
|
||||
TArray used_files;
|
||||
used_files.add(new TLocalisamfile(LF_RMOVMAG),LF_RMOVMAG);
|
||||
used_files.add(new TLocalisamfile(LF_MOVMAG),LF_MOVMAG);
|
||||
used_files.add(new TTable("CAU"),5);
|
||||
TMov_mag * m_m= new TMov_mag; // record del movimento di magazzino
|
||||
|
||||
// relazione con un solo file (LF_MOVMAG) ma col record Head_Body
|
||||
TRelation rel(LF_MOVMAG);
|
||||
rel.lfile().set_curr(m_m);
|
||||
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"))
|
||||
{
|
||||
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("GIAC",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;
|
||||
}
|
||||
|
||||
static TLocalisamfile *anamag=NULL;
|
||||
|
||||
bool unlock_anamag(const char *codart)
|
||||
{
|
||||
bool rv;
|
||||
if (anamag)
|
||||
{
|
||||
anamag->put("CODART",codart);
|
||||
rv=(anamag->read(_isequal,_unlock)==NOERR);
|
||||
delete anamag;
|
||||
anamag=NULL;
|
||||
return rv;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool lock_anamag(const char *codart)
|
||||
{
|
||||
if (!anamag)
|
||||
anamag = new TLocalisamfile(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;
|
||||
}
|
||||
|
||||
|
71
mg/mglib01.h
71
mg/mglib01.h
@ -9,6 +9,8 @@
|
||||
// ***
|
||||
#include <varrec.h>
|
||||
#include <msksheet.h>
|
||||
#ifndef __MGLIB_H
|
||||
#define __MGLIB_H
|
||||
class THead_lines_record ;
|
||||
//**************************************
|
||||
// classe per il controllo dei record composti da una testata e N righe
|
||||
@ -77,6 +79,7 @@ public:
|
||||
void reset_fields(TAuto_variable_rectype & rec) { rec.remove_field(); }
|
||||
virtual void set_fields(TAuto_variable_rectype & rec);
|
||||
|
||||
virtual int readat(TBaseisamfile& f, TRecnotype nrec, word lockop= _nolock);
|
||||
virtual int read(TBaseisamfile& f, word op = _isequal, word lockop = _nolock);
|
||||
|
||||
virtual int write(TBaseisamfile& f) const ;
|
||||
@ -95,19 +98,6 @@ public:
|
||||
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);
|
||||
};
|
||||
|
||||
// **************************************
|
||||
// **************************************
|
||||
@ -130,14 +120,16 @@ class TMag_livelli {
|
||||
int _last_level;
|
||||
|
||||
public:
|
||||
int last_level() const {return _last_level;}; // Ritorna il numero di livelli abilitati
|
||||
const bool enabled(int levnum=1); // Ritorna se il livello è abilitato
|
||||
const TString & name(int levnum); // Ritorna il nome (descrizione) di quel livello
|
||||
const TString & picture(int levnum);// Ritorna la stringa di picture per i codici gruppo di quel livello
|
||||
const int code_lenght(int levnum); // Ritorna la lunghezza dei codici gruppo di quel livello
|
||||
|
||||
void pack_grpcode(TString & pc, const TString &codlev, const int levnum); // Inserisce il codice del gruppo del livello levnum in pc
|
||||
TString unpack_grpcode(const TString & pc, const int levnum); // Estrae il codice del gruppo del livello levnum da pc
|
||||
int last_level() const {return _last_level;}; // Ritorna il numero di livelli abilitati
|
||||
const bool enabled(int levnum=1); // Ritorna se il livello è abilitato
|
||||
const TString & name(int levnum); // Ritorna il nome (descrizione) di quel livello
|
||||
const TString & picture(int levnum);// Ritorna la stringa di picture per i codici gruppo di quel livello
|
||||
const int code_lenght(int levnum); // Ritorna la lunghezza dei codici gruppo di quel livello
|
||||
const int packed_lenght(int levnum); // Ritorna la lunghezza del codice compatto fino a quel livello
|
||||
|
||||
void pack_grpcode(TString & pc, const TString &codlev, const int levnum); // Inserisce il codice del gruppo del livello levnum in pc
|
||||
TString unpack_grpcode(const TString & pc, const int levnum); // Estrae il codice del gruppo del livello levnum da pc
|
||||
TString build_tabcode(const TString & pc, const int levnum);
|
||||
|
||||
TMag_livelli(const char *tabname); // costruttore
|
||||
~TMag_livelli() {}; // distruttore
|
||||
@ -251,12 +243,13 @@ typedef enum {
|
||||
|
||||
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);
|
||||
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);
|
||||
~TCausale_magazzino();
|
||||
};
|
||||
|
||||
|
||||
@ -278,6 +271,10 @@ public:
|
||||
virtual ~TLine_movmag() {};
|
||||
};
|
||||
|
||||
|
||||
bool lock_anamag(const char *codart);
|
||||
bool unlock_anamag(const char *codart) ;
|
||||
|
||||
// classe per la definizione dei movimenti di magazzino
|
||||
// ( un movimento (testata+righe) == un oggetto TMov_mag )
|
||||
class TMov_mag : public THead_lines_record {
|
||||
@ -315,21 +312,27 @@ protected:
|
||||
// @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 void giac_putkey(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);
|
||||
virtual int remove(TBaseisamfile& f) const ;
|
||||
virtual int remove(TBaseisamfile& f) const ;
|
||||
virtual int write(TBaseisamfile& f) const ;
|
||||
virtual int rewrite(TBaseisamfile& f) const ;
|
||||
int force_update_bal();
|
||||
|
||||
//
|
||||
int codice_esercizio(TDate &d);
|
||||
// costruttori e distruttori
|
||||
TMov_mag();
|
||||
virtual ~TMov_mag();
|
||||
|
||||
//
|
||||
int codice_esercizio(TDate &d);
|
||||
// costruttori e distruttori
|
||||
TMov_mag();
|
||||
virtual ~TMov_mag();
|
||||
};
|
||||
|
||||
bool rebuild_balances(TString16 annoes, bool reset_giac=FALSE);
|
||||
|
||||
#endif //__MGLIB_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user