Patch level : 12.0 916

Files correlati     : mg1.exe lv0.exe lv1.exe lv3.exe
Commento            :

Corretta ricostruzione saldi per clifogiac sulle dotazioni
lv0.exe lv1.exe lv3.exe
This commit is contained in:
Alessandro Bonazzi 2020-01-02 10:20:49 +01:00
parent 83594bcdd5
commit 349e4210c0
2 changed files with 419 additions and 190 deletions

View File

@ -609,15 +609,9 @@ protected:
void add_saldi(const bool plus = true);
// @member: effettua l'aggiornamento dei saldi relativi alle giacenze interessate al movimento
bool update_balances(bool lock = true) ;
// @member: effettua l'aggiornamento dei saldi di una giacenza
void update_balances(TRectype& magrec, const TSaldo_mag& s, const TCausale_magazzino& caus) const;
// @member: effettua l'aggiornamento dei saldi di una giacenza sulle gacenze per ciente/fornitore
void update_balances_clifo(TRectype& clifomagrec, const TSaldo_mag_clifo & s);
// @member: effettua l'aggiornamento di un saldo di una giacenza
void update_balance(TRectype& rec, const char * fieldname, const real& diff, int sgn) const;
void giac_putkey(TRectype& mag, const TSaldo_mag & s);
void giac_putkey_clifo(TRectype& clifomag, const TSaldo_mag_clifo & s);
bool lock_anamag(const char *codart);
bool unlock_anamag(const char *codart) ;
virtual const char * codmag_rauto(int r) const { return NULL;}
@ -813,7 +807,7 @@ const char* add_depcode(TString & codmagdep, const char* d);
const char* get_magcode(const TString & codmagdep);
const char* get_depcode(const TString & codmagdep);
bool riporta_ordinato();
void update_clifogiac(TRectype& rec, const TRectype& oldrec);
//void update_clifogiac(TRectype& rec, const TRectype& oldrec);
void reset_clifogiac(TRectype& rec, const TRectype& oldrec, bool closed);
#endif //__MGLIB_H

View File

@ -13,6 +13,17 @@
#include "../cg/cglib01.h"
#include "../db/dblib.h"
void update_balance(TRectype& rec, const char* fieldname, const real& val, const int sgn)
{
if (sgn != 0 && !val.is_zero())
{
if (sgn > 0)
rec.add(fieldname, val);
else
rec.sub(fieldname, val);
}
}
class TSaldo_mag : public TObject
{
int _codes;
@ -32,7 +43,10 @@ public:
const real& quant() const { return _quant; }
const real& valore() const { return _valore; }
void set(int codes, const char * codmag, const char * codart, const char * livello, const char * codcaus);
int operator==(const TSaldo_mag&) const;
int operator==(const TSaldo_mag& s) const;
const TSaldo_mag & operator+=(const TSaldo_mag& s);
const TSaldo_mag & operator-=(const TSaldo_mag& s);
const char * operator<<(const TSaldo_mag& s) const;
virtual TObject* dup() const { return new TSaldo_mag(*this); }
@ -41,9 +55,15 @@ public:
void add_quant(const real & q, bool plus = true) { _quant += (plus ? q : -q); }
void add_valore(const real & v, bool plus = true) { _valore += (plus ? v : -v); }
void add(const real & q, const real & v, bool plus = true) { add_quant(q, plus); add_valore(v, plus); }
void add(const TSaldo_mag & s, bool plus = true) { add_quant(s._quant, plus); add_valore(s._valore, plus); }
void sub_quant(const real & q) { add_quant(q, false); }
void sub_valore(const real & v) { add_valore(v, false); }
void sub(const real & q, const real & v) { add(q, v, false); }
void sub(const TSaldo_mag & s) { add(s, false); }
void putkey(TRectype& mag) const;
// @member: effettua l'aggiornamento dei saldi di una giacenza
void update_record(TRectype& magrec) const;
TSaldo_mag(int codes, const char * codmag, const char * codart, const char * livello, const char * codcaus) {set(codes, codmag, codart, livello, codcaus);}
TSaldo_mag(const TRectype & head, const TRectype & row);
@ -69,6 +89,51 @@ int TSaldo_mag::operator==(const TSaldo_mag & s) const
(_codcaus == s._codcaus);
}
const TSaldo_mag & TSaldo_mag::operator+=(const TSaldo_mag & s)
{
if (*this == s)
add(s);
#ifdef DBG
else
{
TString msg(TR("Somma di saldi incompatibili : "));
msg << *this << " - " << s;
error_box(msg);
}
#endif
return *this;
}
const TSaldo_mag & TSaldo_mag::operator-=(const TSaldo_mag & s)
{
if (*this == s)
sub(s);
#ifdef DBG
else
{
TString msg(TR("Somma di saldi incompatibili : "));
msg << *this << " - " << s;
error_box(msg);
}
#endif
return *this;
}
const char * TSaldo_mag::operator<<(const TSaldo_mag& s) const
{
TString & tmp = get_tmp_string(256);
tmp << "Articolo " << codart();
if (livello().full())
tmp << " Livello " << livello();
tmp << " Magazzino " << codmag()
<< " Esercizio " << codes()
<< " Causale " << codcaus();
return tmp;
}
TToken_string & TSaldo_mag::key(const TRectype & head, const TRectype & row)
{
TToken_string& key = get_tmp_string();
@ -93,6 +158,71 @@ TSaldo_mag::TSaldo_mag(const TRectype & head, const TRectype & row)
_codcaus = head.get(MOVMAG_CODCAUS);
}
void TSaldo_mag::putkey(TRectype& mag) const
{
mag.zero();
mag.put(MAG_ANNOES, codes());
mag.put(MAG_CODMAG, codmag());
mag.put(MAG_CODART, codart());
mag.put(MAG_LIVELLO, livello());
}
void TSaldo_mag::update_record(TRectype& magrec) const
{
const TCausale_magazzino& caus = cached_causale_magazzino(codcaus());
if (caus.update_qta())
{
const real diff = quant();
if (!diff.is_zero())
{
update_balance(magrec, MAG_GIAC, diff, caus.sgn(s_giac)); // update ..
update_balance(magrec, MAG_ACQ, diff, caus.sgn(s_acq)); // update ..
update_balance(magrec, MAG_ENT, diff, caus.sgn(s_ent));
update_balance(magrec, MAG_VEN, diff, caus.sgn(s_ven));
update_balance(magrec, MAG_USC, diff, caus.sgn(s_usc));
update_balance(magrec, MAG_ORDC, diff, caus.sgn(s_ordc));
update_balance(magrec, MAG_ORDF, diff, caus.sgn(s_ordf));
update_balance(magrec, MAG_RIM, diff, caus.sgn(s_rim));
update_balance(magrec, MAG_SCARTI, diff, caus.sgn(s_scart));
update_balance(magrec, MAG_INCL, diff, caus.sgn(s_incl));
update_balance(magrec, MAG_ACL, diff, caus.sgn(s_acl));
update_balance(magrec, MAG_PRODCOMP, diff, caus.sgn(s_prodc));
update_balance(magrec, MAG_PRODFIN, diff, caus.sgn(s_prodf));
update_balance(magrec, MAG_NLABEL, diff, caus.sgn(s_label));
update_balance(magrec, MAG_USER1, diff, caus.sgn(s_user1));
update_balance(magrec, MAG_USER2, diff, caus.sgn(s_user2));
update_balance(magrec, MAG_USER3, diff, caus.sgn(s_user3));
update_balance(magrec, MAG_USER4, diff, caus.sgn(s_user4));
update_balance(magrec, MAG_USER5, diff, caus.sgn(s_user5));
update_balance(magrec, MAG_USER6, diff, caus.sgn(s_user6));
}
}
if (caus.update_val())
{
const real diff_val = valore();
if (!diff_val.is_zero())
{
update_balance(magrec, MAG_VALACQ, diff_val, caus.sgn(s_acq)); // update ..
update_balance(magrec, MAG_VALENT, diff_val, caus.sgn(s_ent));
update_balance(magrec, MAG_VALVEN, diff_val, caus.sgn(s_ven));
update_balance(magrec, MAG_VALUSC, diff_val, caus.sgn(s_usc));
update_balance(magrec, MAG_VALORDC, diff_val, caus.sgn(s_ordc));
update_balance(magrec, MAG_VALORDF, diff_val, caus.sgn(s_ordf));
update_balance(magrec, MAG_VALRIM, diff_val, caus.sgn(s_rim));
update_balance(magrec, MAG_VALSCARTI, diff_val, caus.sgn(s_scart));
update_balance(magrec, MAG_USERVAL1, diff_val, caus.sgn(s_user1));
update_balance(magrec, MAG_USERVAL2, diff_val, caus.sgn(s_user2));
update_balance(magrec, MAG_USERVAL3, diff_val, caus.sgn(s_user3));
update_balance(magrec, MAG_USERVAL4, diff_val, caus.sgn(s_user4));
update_balance(magrec, MAG_USERVAL5, diff_val, caus.sgn(s_user5));
update_balance(magrec, MAG_USERVAL6, diff_val, caus.sgn(s_user6));
}
}
}
TSaldo_mag::TSaldo_mag(const TSaldo_mag & s)
{
set(s._codes, s._codmag, s._codart, s._livello, s._codcaus);
@ -126,6 +256,9 @@ public:
const real& valore() const { return _valore; }
void set(int codes, char tipocf, const char * codcf, int codindsp, const char * codart, const char * livello, const char * codcaus);
int operator==(const TSaldo_mag_clifo&) const;
const TSaldo_mag_clifo & operator+=(const TSaldo_mag_clifo& s);
const TSaldo_mag_clifo & operator-=(const TSaldo_mag_clifo& s);
const char * operator<<(const TSaldo_mag_clifo& s) const;
virtual TObject* dup() const { return new TSaldo_mag_clifo(*this); }
@ -134,10 +267,16 @@ public:
void add_quant(const real & q, bool plus = true) { _quant = _quant + (plus ? q : -q); }
void add_valore(const real & v, bool plus = true) { _valore = _valore + (plus ? v : -v); }
void add(const real & q, const real & v, bool plus = true) { add_quant(q, plus); add_valore(v, plus); }
void add(const TSaldo_mag_clifo & s, bool plus = true) { add_quant(s._quant, plus); add_valore(s._valore, plus); }
void sub_quant(const real & q) { add_quant(q, false); }
void sub_valore(const real & v) { add_valore(v, false); }
void sub(const real & q, const real & v) { add(q, v, false); }
void sub(const TSaldo_mag_clifo & s) { add(s, false); }
void putkey(TRectype& clifomag) const;
// @member: effettua l'aggiornamento dei saldi di una giacenza sulle gacenze per ciente/fornitore
void update_record(TRectype& clifomagrec) const;
TSaldo_mag_clifo(int codes, char tipocf, const char * codcf, int codindsp, const char * codart, const char * livello, const char * codcaus);
TSaldo_mag_clifo(const TRectype & head, const TRectype & row);
TSaldo_mag_clifo(const TSaldo_mag_clifo & s);
@ -167,6 +306,53 @@ int TSaldo_mag_clifo::operator==(const TSaldo_mag_clifo & s) const
(_codcaus == s._codcaus);
}
const TSaldo_mag_clifo & TSaldo_mag_clifo::operator+=(const TSaldo_mag_clifo & s)
{
if (*this == s)
add(s);
#ifdef DBG
else
{
TString msg(TR("Somma di saldi incompatibili : "));
msg << *this << " - " << s;
error_box(msg);
}
#endif
return *this;
}
const TSaldo_mag_clifo & TSaldo_mag_clifo::operator-=(const TSaldo_mag_clifo & s)
{
if (*this == s)
sub(s);
#ifdef DBG
else
{
TString msg(TR("Somma di saldi incompatibili : "));
msg << *this << " - " << s;
error_box(msg);
}
#endif
return *this;
}
const char * TSaldo_mag_clifo::operator<<(const TSaldo_mag_clifo& s) const
{
TString & tmp = get_tmp_string(256);
tmp << (tipocf() == 'C' ? "Cliente " : "Fornitore ") << codcf();
if (codindsp() != 0)
tmp << " Indirizzo " << codindsp();
tmp << "Articolo " << codart();
if (livello().full())
tmp << " Livello " << livello();
tmp << " Esercizio " << codes()
<< " Causale " << codcaus();
return tmp;
}
TToken_string & TSaldo_mag_clifo::key(const TRectype & head, const TRectype & row)
{
TToken_string& key = get_tmp_string();
@ -184,6 +370,74 @@ TToken_string & TSaldo_mag_clifo::key(const TRectype & head, const TRectype & ro
return key;
}
void TSaldo_mag_clifo::putkey(TRectype& clifomag) const
{
clifomag.zero();
clifomag.put(CLIFOGIAC_ANNOES, codes());
clifomag.put(CLIFOGIAC_TIPOCF, tipocf());
clifomag.put(CLIFOGIAC_CODCF, codcf());
clifomag.put(CLIFOGIAC_INDSPED, codindsp());
clifomag.put(CLIFOGIAC_CODART, codart());
clifomag.put(CLIFOGIAC_LIVELLO, livello());
}
// aggiorna i saldi del record corrente
// in base alla causale e alla modifica fatta (con segno + o -)
// aggiorna i saldi del record corrente
// in base alla causale e alla modifica fatta (con segno + o -)
void TSaldo_mag_clifo::update_record(TRectype & clifomagrec) const
{
const TCausale_magazzino& caus = cached_causale_magazzino(codcaus());
if (caus.update_qta())
{
const real diff = quant();
update_balance(clifomagrec, CLIFOGIAC_GIAC, -diff, caus.sgn(s_giac)); // update ..
update_balance(clifomagrec, CLIFOGIAC_ACQ, diff, caus.sgn(s_ven)); // update ..
update_balance(clifomagrec, CLIFOGIAC_ENT, diff, caus.sgn(s_ent));
update_balance(clifomagrec, CLIFOGIAC_VEN, diff, caus.sgn(s_acq));
update_balance(clifomagrec, CLIFOGIAC_USC, diff, caus.sgn(s_usc));
update_balance(clifomagrec, CLIFOGIAC_ORDC, diff, caus.sgn(s_ordf));
update_balance(clifomagrec, CLIFOGIAC_ORDF, diff, caus.sgn(s_ordc));
update_balance(clifomagrec, CLIFOGIAC_RIM, -diff, caus.sgn(s_rim));
update_balance(clifomagrec, CLIFOGIAC_SCARTI, -diff, caus.sgn(s_scart));
update_balance(clifomagrec, CLIFOGIAC_INCL, diff, caus.sgn(s_acl));
update_balance(clifomagrec, CLIFOGIAC_ACL, diff, caus.sgn(s_incl));
update_balance(clifomagrec, CLIFOGIAC_PRODCOMP, -diff, caus.sgn(s_prodc));
update_balance(clifomagrec, CLIFOGIAC_PRODFIN, -diff, caus.sgn(s_prodf));
update_balance(clifomagrec, CLIFOGIAC_DOTIN, diff, caus.sgn(s_dotin));
update_balance(clifomagrec, CLIFOGIAC_DOTOD, diff, caus.sgn(s_dotod));
update_balance(clifomagrec, CLIFOGIAC_DOTTM, diff, caus.sgn(s_dottm));
update_balance(clifomagrec, CLIFOGIAC_CONSANNO, diff, caus.sgn(s_consanno));
update_balance(clifomagrec, CLIFOGIAC_USER1, diff, caus.sgn(s_user1));
update_balance(clifomagrec, CLIFOGIAC_USER2, diff, caus.sgn(s_user2));
update_balance(clifomagrec, CLIFOGIAC_USER3, diff, caus.sgn(s_user3));
update_balance(clifomagrec, CLIFOGIAC_USER4, diff, caus.sgn(s_user4));
update_balance(clifomagrec, CLIFOGIAC_USER5, diff, caus.sgn(s_user5));
update_balance(clifomagrec, CLIFOGIAC_USER6, diff, caus.sgn(s_user6));
}
if (caus.update_val())
{
const real diff_val = valore();
update_balance(clifomagrec, CLIFOGIAC_VALACQ, diff_val, caus.sgn(s_ven)); // update ..
update_balance(clifomagrec, CLIFOGIAC_VALENT, diff_val, caus.sgn(s_ent));
update_balance(clifomagrec, CLIFOGIAC_VALVEN, diff_val, caus.sgn(s_acq));
update_balance(clifomagrec, CLIFOGIAC_VALUSC, diff_val, caus.sgn(s_usc));
update_balance(clifomagrec, CLIFOGIAC_VALORDC, diff_val, caus.sgn(s_ordf));
update_balance(clifomagrec, CLIFOGIAC_VALORDF, diff_val, caus.sgn(s_ordc));
update_balance(clifomagrec, CLIFOGIAC_VALRIM, -diff_val, caus.sgn(s_rim));
update_balance(clifomagrec, CLIFOGIAC_VALSCARTI, -diff_val, caus.sgn(s_scart));
update_balance(clifomagrec, CLIFOGIAC_USERVAL1, diff_val, caus.sgn(s_user1));
update_balance(clifomagrec, CLIFOGIAC_USERVAL2, diff_val, caus.sgn(s_user2));
update_balance(clifomagrec, CLIFOGIAC_USERVAL3, diff_val, caus.sgn(s_user3));
update_balance(clifomagrec, CLIFOGIAC_USERVAL4, diff_val, caus.sgn(s_user4));
update_balance(clifomagrec, CLIFOGIAC_USERVAL5, diff_val, caus.sgn(s_user5));
update_balance(clifomagrec, CLIFOGIAC_USERVAL6, diff_val, caus.sgn(s_user6));
}
}
TSaldo_mag_clifo::TSaldo_mag_clifo(const TRectype & head, const TRectype & row)
{
_codes = head.get_int(MOVMAG_ANNOES);
@ -204,6 +458,10 @@ TSaldo_mag_clifo::TSaldo_mag_clifo(const TSaldo_mag_clifo & s)
_valore = s._valore;
}
static bool __cache_saldi = false;
static TAssoc_array __saldi_mag;
static TAssoc_array __saldi_mag_clifo;
// ********************************
// TMov_mag
@ -480,7 +738,7 @@ bool TMov_mag::force_update_bal()
_saldi_mag.destroy();
_saldi_mag_clifo.destroy();
add_saldi();
return update_balances(false);
return __cache_saldi ? true : update_balances(false);
}
void TMov_mag::renum_mov(const long numreg)
@ -499,11 +757,14 @@ void TMov_mag::add_saldi(const bool plus)
{
const TRectype & rec = b[i];
TToken_string & key_mag = TSaldo_mag::key(*this, rec);
TSaldo_mag * s_mag = (TSaldo_mag*) _saldi_mag.objptr(key_mag);
TSaldo_mag * s_mag = (TSaldo_mag*)(__cache_saldi ? __saldi_mag.objptr(key_mag) : _saldi_mag.objptr(key_mag));
if (s_mag == NULL)
{
s_mag = new TSaldo_mag(*this, rec);
if (__cache_saldi)
__saldi_mag.add(key_mag, s_mag);
else
_saldi_mag.add(key_mag, s_mag);
}
@ -520,11 +781,14 @@ void TMov_mag::add_saldi(const bool plus)
if (caus.aggiorna_clifo()&& get_long(MOVMAG_CODCF) > 0L)
{
TToken_string & key_clifo = TSaldo_mag_clifo::key(*this, rec);
TSaldo_mag_clifo * s_clifo = (TSaldo_mag_clifo*) _saldi_mag_clifo.objptr(key_clifo);
TSaldo_mag_clifo * s_clifo = (TSaldo_mag_clifo*)(__cache_saldi ? __saldi_mag_clifo.objptr(key_clifo) : _saldi_mag_clifo.objptr(key_clifo));
if (s_clifo == NULL)
{
s_clifo = new TSaldo_mag_clifo(*this, rec);
if (__cache_saldi)
__saldi_mag_clifo.add(key_clifo, s_clifo);
else
_saldi_mag_clifo.add(key_clifo, s_clifo);
}
s_clifo->add(quant, valore, plus);
@ -561,27 +825,6 @@ bool TMov_mag::lock_anamag(const char *codart)
return FALSE;
}
void TMov_mag::giac_putkey(TRectype& mag, const TSaldo_mag & s)
{
mag.zero();
mag.put(MAG_ANNOES, s.codes());
mag.put(MAG_CODMAG, s.codmag());
mag.put(MAG_CODART, s.codart());
mag.put(MAG_LIVELLO, s.livello());
}
void TMov_mag::giac_putkey_clifo(TRectype& clifomag, const TSaldo_mag_clifo & s)
{
clifomag.zero();
clifomag.put(CLIFOGIAC_ANNOES, s.codes());
clifomag.put(CLIFOGIAC_TIPOCF, s.tipocf());
clifomag.put(CLIFOGIAC_CODCF, s.codcf());
clifomag.put(CLIFOGIAC_INDSPED, s.codindsp());
clifomag.put(CLIFOGIAC_CODART, s.codart());
clifomag.put(CLIFOGIAC_LIVELLO, s.livello());
}
// aggiorna tutti i saldi in base alle modifiche fatte.
// il lock su anagrafica dovrebbe garantire il lock su tutte le giacenze dell'articolo
bool TMov_mag::update_balances(bool lock)
@ -606,39 +849,41 @@ bool TMov_mag::update_balances(bool lock)
if (_saldi_mag.items() > 0)
{
TFast_isamfile mag(LF_MAG);
mag.setkey(2);
TRectype& magcurr = mag.curr();
TString_array keys_mag;
mag.setkey(2);
_saldi_mag.get_keys(keys_mag);
keys_mag.sort();
int err = NOERR;
TString msg;
msg << TR("Aggiornamento saldi del movimento ") << get(MOVMAG_NUMREG)
int err = NOERR;
TString msg;
msg << TR("Aggiornamento saldi del movimento ") << get(MOVMAG_NUMREG)
<< ": " << get(MOVMAG_DESCR);
TProgress_monitor pi(keys_mag.items(), msg, false);
FOR_EACH_ARRAY_ROW(keys_mag, r, curr_key)
TProgress_monitor pi(keys_mag.items(), msg, false);
FOR_EACH_ARRAY_ROW(keys_mag, r, curr_key)
{
const TSaldo_mag& saldo = (const TSaldo_mag&)_saldi_mag[*curr_key];
const TCodice_articolo& codart = saldo.codart();
TArticolo_giacenza& art = cached_article_balances(codart);
const TCausale_magazzino& caus = cached_causale_magazzino(saldo.codcaus());
giac_putkey(magcurr, saldo);
saldo.putkey(magcurr);
err = art.lock_and_prompt_giac(magcurr, lock ? _testandlock : _nolock);
if (err != NOERR)
{
TRecord_array& sld = art.mag(saldo.codes());
const int nriga = sld.rows() + 1;
giac_putkey(magcurr, saldo);
saldo.putkey(magcurr);
magcurr.put(MAG_NRIGA, nriga);
sld.add_row(magcurr);
err = mag.write();
CHECKD(err == NOERR, "Errore di write:" , err);
}
update_balances(magcurr, saldo, caus);
saldo.update_record(magcurr);
err = mag.rewrite();
if (err != NOERR)
updated_bal = false;
@ -652,48 +897,57 @@ bool TMov_mag::update_balances(bool lock)
if (_saldi_mag_clifo.items() > 0)
{
TFast_isamfile clifomag(LF_CLIFOGIAC);
clifomag.setkey(2);
TRectype& clifomag_curr = clifomag.curr();
TString_array keys_clifo;
clifomag.setkey(2);
_saldi_mag_clifo.get_keys(keys_clifo);
keys_clifo.sort();
int err = NOERR;
TString msg;
msg << TR("Aggiornamento saldi del movimento ") << get(MOVMAG_NUMREG)
<< ": " << get(MOVMAG_DESCR);
TProgress_monitor pi(keys_clifo.items(), msg, false);
for (TToken_string* curr_key = (TToken_string*)keys_clifo.first_item();
curr_key != NULL; curr_key = (TToken_string*)keys_clifo.succ_item())
{
TSaldo_mag_clifo & saldo=(TSaldo_mag_clifo &)_saldi_mag_clifo[*curr_key];
const TCodice_articolo& codart = saldo.codart();
TArticolo_giacenza & art = cached_article_balances(codart);
giac_putkey_clifo(clifomag_curr, saldo);
saldo.putkey(clifomag_curr);
err = art.lock_and_prompt_giac_cf(clifomag_curr, lock ? _testandlock : _nolock);
if (err != NOERR)
{
// non trovato: aggiungo
clifomag.setkey(1);
giac_putkey_clifo(clifomag_curr, saldo);
saldo.putkey(clifomag_curr);
clifomag_curr.put(CLIFOGIAC_NRIGA, 999);
if (clifomag.read(_isgteq) == NOERR)
clifomag.prev();
saldo.putkey(clifomag_curr);
int nriga = 1;
if (clifomag_curr.get_int(CLIFOGIAC_ANNOES) == saldo.codes() &&
clifomag_curr.get_char(CLIFOGIAC_TIPOCF) == saldo.tipocf() &&
clifomag_curr.get(CLIFOGIAC_CODCF) == saldo.codcf() &&
clifomag_curr.get(CLIFOGIAC_CODART) == saldo.codart() &&
clifomag_curr.get(CLIFOGIAC_LIVELLO ) == saldo.livello())
clifomag_curr.get_char(CLIFOGIAC_TIPOCF) == saldo.tipocf() &&
clifomag_curr.get(CLIFOGIAC_CODCF) == saldo.codcf() &&
clifomag_curr.get(CLIFOGIAC_CODART) == saldo.codart() &&
clifomag_curr.get(CLIFOGIAC_LIVELLO) == saldo.livello())
nriga = clifomag_curr.get_int(CLIFOGIAC_NRIGA) + 1;
giac_putkey_clifo(clifomag_curr, saldo);
clifomag_curr.put(CLIFOGIAC_NRIGA, nriga);
clifomag.write();
}
update_balances_clifo(clifomag_curr, saldo);
saldo.update_record(clifomag_curr);
clifomag.rewrite();
if (lock)
art.unlock_giac_cf(clifomag_curr);
pi.add_status();
}
}
_saldi_mag.destroy();
@ -701,115 +955,6 @@ bool TMov_mag::update_balances(bool lock)
return updated_bal;
}
// aggiorna i saldi del record corrente
// in base alla causale e alla modifica fatta (con segno + o -)
void TMov_mag::update_balances(TRectype& magrec, const TSaldo_mag& s, const TCausale_magazzino& caus) const
{
if (caus.update_qta())
{
const real diff = s.quant();
if (!diff.is_zero())
{
update_balance(magrec, MAG_GIAC, diff, caus.sgn(s_giac)); // update ..
update_balance(magrec, MAG_ACQ, diff, caus.sgn(s_acq)); // update ..
update_balance(magrec, MAG_ENT, diff, caus.sgn(s_ent));
update_balance(magrec, MAG_VEN, diff, caus.sgn(s_ven));
update_balance(magrec, MAG_USC, diff, caus.sgn(s_usc));
update_balance(magrec, MAG_ORDC, diff, caus.sgn(s_ordc));
update_balance(magrec, MAG_ORDF, diff, caus.sgn(s_ordf));
update_balance(magrec, MAG_RIM, diff, caus.sgn(s_rim));
update_balance(magrec, MAG_SCARTI, diff, caus.sgn(s_scart));
update_balance(magrec, MAG_INCL, diff, caus.sgn(s_incl));
update_balance(magrec, MAG_ACL, diff, caus.sgn(s_acl));
update_balance(magrec, MAG_PRODCOMP, diff, caus.sgn(s_prodc));
update_balance(magrec, MAG_PRODFIN, diff, caus.sgn(s_prodf));
update_balance(magrec, MAG_NLABEL, diff, caus.sgn(s_label));
update_balance(magrec, MAG_USER1, diff, caus.sgn(s_user1));
update_balance(magrec, MAG_USER2, diff, caus.sgn(s_user2));
update_balance(magrec, MAG_USER3, diff, caus.sgn(s_user3));
update_balance(magrec, MAG_USER4, diff, caus.sgn(s_user4));
update_balance(magrec, MAG_USER5, diff, caus.sgn(s_user5));
update_balance(magrec, MAG_USER6, diff, caus.sgn(s_user6));
}
}
if (caus.update_val())
{
const real diff_val = s.valore();
if (!diff_val.is_zero())
{
update_balance(magrec, MAG_VALACQ, diff_val, caus.sgn(s_acq)); // update ..
update_balance(magrec, MAG_VALENT, diff_val, caus.sgn(s_ent));
update_balance(magrec, MAG_VALVEN, diff_val, caus.sgn(s_ven));
update_balance(magrec, MAG_VALUSC, diff_val, caus.sgn(s_usc));
update_balance(magrec, MAG_VALORDC, diff_val, caus.sgn(s_ordc));
update_balance(magrec, MAG_VALORDF, diff_val, caus.sgn(s_ordf));
update_balance(magrec, MAG_VALRIM, diff_val, caus.sgn(s_rim));
update_balance(magrec, MAG_VALSCARTI, diff_val, caus.sgn(s_scart));
update_balance(magrec, MAG_USERVAL1, diff_val, caus.sgn(s_user1));
update_balance(magrec, MAG_USERVAL2, diff_val, caus.sgn(s_user2));
update_balance(magrec, MAG_USERVAL3, diff_val, caus.sgn(s_user3));
update_balance(magrec, MAG_USERVAL4, diff_val, caus.sgn(s_user4));
update_balance(magrec, MAG_USERVAL5, diff_val, caus.sgn(s_user5));
update_balance(magrec, MAG_USERVAL6, diff_val, caus.sgn(s_user6));
}
}
}
// aggiorna i saldi del record corrente
// in base alla causale e alla modifica fatta (con segno + o -)
void TMov_mag::update_balances_clifo(TRectype & clifomagrec, const TSaldo_mag_clifo & s)
{
const TCausale_magazzino& caus = cached_causale_magazzino(s.codcaus());
if (caus.update_qta())
{
const real diff = s.quant();
update_balance(clifomagrec, CLIFOGIAC_GIAC, -diff, caus.sgn(s_giac)); // update ..
update_balance(clifomagrec, CLIFOGIAC_ACQ, diff, caus.sgn(s_ven)); // update ..
update_balance(clifomagrec, CLIFOGIAC_ENT, diff, caus.sgn(s_usc));
update_balance(clifomagrec, CLIFOGIAC_VEN, diff, caus.sgn(s_acq));
update_balance(clifomagrec, CLIFOGIAC_USC, diff, caus.sgn(s_ent));
update_balance(clifomagrec, CLIFOGIAC_ORDC, diff, caus.sgn(s_ordf));
update_balance(clifomagrec, CLIFOGIAC_ORDF, diff, caus.sgn(s_ordc));
update_balance(clifomagrec, CLIFOGIAC_RIM, -diff, caus.sgn(s_rim));
update_balance(clifomagrec, CLIFOGIAC_SCARTI, -diff, caus.sgn(s_scart));
update_balance(clifomagrec, CLIFOGIAC_INCL, diff, caus.sgn(s_acl));
update_balance(clifomagrec, CLIFOGIAC_ACL, diff, caus.sgn(s_incl));
update_balance(clifomagrec, CLIFOGIAC_PRODCOMP, -diff, caus.sgn(s_prodc));
update_balance(clifomagrec, CLIFOGIAC_PRODFIN, -diff, caus.sgn(s_prodf));
update_balance(clifomagrec, CLIFOGIAC_DOTIN, diff, caus.sgn(s_dotin));
update_balance(clifomagrec, CLIFOGIAC_DOTOD, diff, caus.sgn(s_dotod));
update_balance(clifomagrec, CLIFOGIAC_DOTTM, diff, caus.sgn(s_dottm));
update_balance(clifomagrec, CLIFOGIAC_CONSANNO, diff, caus.sgn(s_consanno));
update_balance(clifomagrec, CLIFOGIAC_USER1, diff, caus.sgn(s_user1));
update_balance(clifomagrec, CLIFOGIAC_USER2, diff, caus.sgn(s_user2));
update_balance(clifomagrec, CLIFOGIAC_USER3, diff, caus.sgn(s_user3));
update_balance(clifomagrec, CLIFOGIAC_USER4, diff, caus.sgn(s_user4));
update_balance(clifomagrec, CLIFOGIAC_USER5, diff, caus.sgn(s_user5));
update_balance(clifomagrec, CLIFOGIAC_USER6, diff, caus.sgn(s_user6));
}
if (caus.update_val())
{
const real diff_val = s.valore();
update_balance(clifomagrec, CLIFOGIAC_VALACQ, diff_val, caus.sgn(s_ven)); // update ..
update_balance(clifomagrec, CLIFOGIAC_VALENT, diff_val, caus.sgn(s_usc));
update_balance(clifomagrec, CLIFOGIAC_VALVEN, diff_val, caus.sgn(s_acq));
update_balance(clifomagrec, CLIFOGIAC_VALUSC, diff_val, caus.sgn(s_ven));
update_balance(clifomagrec, CLIFOGIAC_VALORDC, diff_val, caus.sgn(s_ordf));
update_balance(clifomagrec, CLIFOGIAC_VALORDF, diff_val, caus.sgn(s_ordc));
update_balance(clifomagrec, CLIFOGIAC_VALRIM, -diff_val, caus.sgn(s_rim));
update_balance(clifomagrec, CLIFOGIAC_VALSCARTI, -diff_val, caus.sgn(s_scart));
update_balance(clifomagrec, CLIFOGIAC_USERVAL1, diff_val, caus.sgn(s_user1));
update_balance(clifomagrec, CLIFOGIAC_USERVAL2, diff_val, caus.sgn(s_user2));
update_balance(clifomagrec, CLIFOGIAC_USERVAL3, diff_val, caus.sgn(s_user3));
update_balance(clifomagrec, CLIFOGIAC_USERVAL4, diff_val, caus.sgn(s_user4));
update_balance(clifomagrec, CLIFOGIAC_USERVAL5, diff_val, caus.sgn(s_user5));
update_balance(clifomagrec, CLIFOGIAC_USERVAL6, diff_val, caus.sgn(s_user6));
}
}
void TMov_mag::update_balances(TRectype& magrec, int numrig, bool plus)
{
const TRectype& rec = body()[numrig];
@ -823,8 +968,7 @@ void TMov_mag::update_balances(TRectype& magrec, int numrig, bool plus)
const real valore = (quant.is_zero() && caus.update_val()) ? rec.get_real(RMOVMAG_PREZZO) : rec.get_real(RMOVMAG_PREZZO) * quant;
saldo.add(quant, valore, plus);
return update_balances(magrec, saldo, caus);
return saldo.update_record(magrec);
}
void TMov_mag::update_balances_clifo(TRectype& cliforec, int numrig, bool plus)
@ -841,7 +985,7 @@ void TMov_mag::update_balances_clifo(TRectype& cliforec, int numrig, bool plus)
saldo.add(quant, valore, plus);
return update_balances_clifo(cliforec, saldo);
return saldo.update_record(cliforec);
}
int TMov_mag::codice_esercizio(const TDate& d) const
@ -851,13 +995,7 @@ int TMov_mag::codice_esercizio(const TDate& d) const
void TMov_mag::update_balance(TRectype& rec, const char* fieldname, const real& val, const int sgn) const
{
if (sgn != 0 && !val.is_zero())
{
if (sgn > 0)
rec.add(fieldname, val);
else
rec.add(fieldname, -val);
}
::update_balance(rec, fieldname, val, sgn);
}
struct TBalance_params
@ -914,14 +1052,12 @@ void reset_clifogiac(TRectype& rec, const TRectype& oldrec, bool closed)
rec.zero(CLIFOGIAC_ORDC);
rec.zero(CLIFOGIAC_VALORDC);
}
rec.put(CLIFOGIAC_DOTOD, oldrec.get(CLIFOGIAC_DOTOD));
rec.put(CLIFOGIAC_DOTIN, oldrec.get(CLIFOGIAC_DOTIN));
rec.put(CLIFOGIAC_DOTTM, oldrec.get(CLIFOGIAC_DOTTM));
}
else
{
rec.put(CLIFOGIAC_DOTOD, oldrec.get(CLIFOGIAC_DOTOD));
rec.put(CLIFOGIAC_DOTIN, oldrec.get(CLIFOGIAC_DOTIN));
rec.put(CLIFOGIAC_DOTTM, oldrec.get(CLIFOGIAC_DOTTM));
}
else
{
for (int i = 0; zero_fields[i]; i++)
rec.zero(zero_fields[i]);
rec.zero(CLIFOGIAC_DOTIN);
@ -931,6 +1067,7 @@ void reset_clifogiac(TRectype& rec, const TRectype& oldrec, bool closed)
rec.zero(CLIFOGIAC_CONSANNO);
}
/*
void update_clifogiac(TRectype & rec, const TRectype & oldrec)
{
if (!oldrec.empty())
@ -959,11 +1096,12 @@ void update_clifogiac(TRectype & rec, const TRectype & oldrec)
rec.add(CLIFOGIAC_ORDC, oldrec.get_real(CLIFOGIAC_ORDC));
rec.add(CLIFOGIAC_VALORDC, oldrec.get_real(CLIFOGIAC_VALORDC));
}
rec.add(CLIFOGIAC_DOTOD, oldrec.get_real(CLIFOGIAC_DOTOD));
rec.add(CLIFOGIAC_DOTIN, oldrec.get_real(CLIFOGIAC_DOTIN));
rec.add(CLIFOGIAC_DOTTM, oldrec.get_real(CLIFOGIAC_DOTTM));
// rec.add(CLIFOGIAC_DOTOD, oldrec.get_real(CLIFOGIAC_DOTOD));
// rec.add(CLIFOGIAC_DOTIN, oldrec.get_real(CLIFOGIAC_DOTIN));
// rec.add(CLIFOGIAC_DOTTM, oldrec.get_real(CLIFOGIAC_DOTTM));
}
}
*/
HIDDEN bool rel_reset_clifogiac(const TRelation& rel, void* pJolly)
{
@ -1060,8 +1198,8 @@ bool rebuild_balances(int codes, const TTipo_valorizz tipo_valorizz,
// Compattamento giacenze dopo cancellazione
{
//prefix().close_closeable_isamfiles(); // Altrimenti segnala -69 durante la pack
TSystemisamfile mag(LF_MAG);
mag.pack(true, true);
// TSystemisamfile mag(LF_MAG);
// mag.pack(true, true);
/* Mi da sempre errore di compattamento
if (p.codesprec > 0)
@ -1076,14 +1214,111 @@ bool rebuild_balances(int codes, const TTipo_valorizz tipo_valorizz,
bool ok = true;
{
TRelation relmovmag(LF_MOVMAG);
TRectype& rec = relmovmag.curr();
rec.put(MOVMAG_ANNOES, codes);
TRectype filter(LF_MOVMAG);
filter.put(MOVMAG_ANNOES, codes);
TCursor mov_cur(&relmovmag, "", 2, &filter, &filter);
mov_cur = 0L; //non togliere
mov_cur.freeze(); // non togliere
TCursor mov_cur(&relmovmag, "", 2, &rec, &rec);
relmovmag.lfile().set_curr(new TMov_mag());
msg.format(FR("Ricostruzione saldi esercizio %04d ..."), codes);
__cache_saldi = true;
mov_cur.scan(recalc_mov, (void*)&ok, msg);
if (__cache_saldi && __saldi_mag.items() > 0)
{
TFast_isamfile mag(LF_MAG);
TRectype& magcurr = mag.curr();
TString_array keys_mag;
mag.setkey(2);
__saldi_mag.get_keys(keys_mag);
keys_mag.sort();
TString msg = TR("Aggiornamento saldi magazzini");
TProgress_monitor pi(keys_mag.items(), msg, false);
FOR_EACH_ARRAY_ROW(keys_mag, r, curr_key)
{
const TSaldo_mag& saldo = (const TSaldo_mag&)__saldi_mag[*curr_key];
const TCodice_articolo& codart = saldo.codart();
TArticolo_giacenza& art = cached_article_balances(codart);
saldo.putkey(magcurr);
if (magcurr.read(mag, _isequal) != NOERR)
{
TRecord_array& sld = art.mag(saldo.codes());
const int nriga = sld.rows() + 1;
saldo.putkey(magcurr);
magcurr.put(MAG_NRIGA, nriga);
sld.add_row(magcurr);
int err = mag.write();
CHECKD(err == NOERR, "Errore di write:", err);
}
saldo.update_record(magcurr);
if (mag.rewrite() != NOERR)
ok = false;
pi.add_status();
}
}
if (__cache_saldi && __saldi_mag_clifo.items() > 0)
{
TFast_isamfile clifomag(LF_CLIFOGIAC);
TRectype& clifomag_curr = clifomag.curr();
TString_array keys_clifo;
clifomag.setkey(2);
__saldi_mag_clifo.get_keys(keys_clifo);
keys_clifo.sort();
TString msg = TR("Aggiornamento saldi magazzini clienti");
TProgress_monitor pi(keys_clifo.items(), msg, false);
for (TToken_string* curr_key = (TToken_string*)keys_clifo.first_item();
curr_key != NULL; curr_key = (TToken_string*)keys_clifo.succ_item())
{
TSaldo_mag_clifo & saldo = (TSaldo_mag_clifo &)__saldi_mag_clifo[*curr_key];
const TCodice_articolo& codart = saldo.codart();
TArticolo_giacenza & art = cached_article_balances(codart);
saldo.putkey(clifomag_curr);
if (clifomag.read(_isequal) != NOERR)
{
// non trovato: aggiungo
clifomag.setkey(1);
saldo.putkey(clifomag_curr);
clifomag_curr.put(CLIFOGIAC_NRIGA, 999);
if (clifomag.read(_isgteq) == NOERR)
clifomag.prev();
saldo.putkey(clifomag_curr);
int nriga = 1;
if (clifomag_curr.get_int(CLIFOGIAC_ANNOES) == saldo.codes() &&
clifomag_curr.get_char(CLIFOGIAC_TIPOCF) == saldo.tipocf() &&
clifomag_curr.get(CLIFOGIAC_CODCF) == saldo.codcf() &&
clifomag_curr.get(CLIFOGIAC_CODART) == saldo.codart() &&
clifomag_curr.get(CLIFOGIAC_LIVELLO) == saldo.livello())
nriga = clifomag_curr.get_int(CLIFOGIAC_NRIGA) + 1;
clifomag_curr.put(CLIFOGIAC_NRIGA, nriga);
clifomag.write();
clifomag.setkey(2);
}
saldo.update_record(clifomag_curr);
if (clifomag.rewrite() != NOERR)
ok = false;
pi.add_status();
}
}
__saldi_mag.destroy();
__saldi_mag_clifo.destroy();
__cache_saldi = false;
}
a.close();