Patch level : 10.0

Files correlati     : mg1.exe mg1200.msk
Ricompilazione Demo : [ ]
Commento            :
Corretto ricalcolo saldi di magazzino


git-svn-id: svn://10.65.10.50/trunk@19183 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2009-08-05 13:14:51 +00:00
parent f6e08c7fe8
commit 35a2a2dc74
5 changed files with 161 additions and 152 deletions

View File

@ -45,7 +45,6 @@ bool TMask_buildmov::handle_annoes(TMask_field &fld, KEY k)
return TRUE; return TRUE;
} }
class TApp_rebuildbalances : public TSkeleton_application class TApp_rebuildbalances : public TSkeleton_application
{ {
TRelation* _rel; // relazione TRelation* _rel; // relazione
@ -56,20 +55,14 @@ class TApp_rebuildbalances : public TSkeleton_application
protected: protected:
virtual bool create(); virtual bool create();
virtual void main_loop(); virtual void main_loop();
public:
TApp_rebuildbalances() {}
virtual ~TApp_rebuildbalances() {}
}; };
bool TApp_rebuildbalances::create() bool TApp_rebuildbalances::create()
{ {
open_files(LF_UMART, LF_MAG, LF_RMOVMAG, LF_TABCOM, LF_STOMAG, open_files(LF_UMART, LF_MAG, LF_RMOVMAG, LF_TABCOM, LF_STOMAG, LF_DESLIN, LF_CODCORR, 0);
LF_DESLIN, LF_CODCORR, 0);
return TSkeleton_application::create(); return TSkeleton_application::create();
} }
void TApp_rebuildbalances::main_loop() void TApp_rebuildbalances::main_loop()
{ {
TMask_buildmov m; TMask_buildmov m;
@ -77,14 +70,12 @@ void TApp_rebuildbalances::main_loop()
{ {
if (!rebuild_balances(m.get_int(F_ANNOES))) if (!rebuild_balances(m.get_int(F_ANNOES)))
warning_box(TR("A causa degli errori riscontrati i saldi di magazzino \npotrebbero non essere stati del tutto aggiornati. \nProcedere ad una nuova operazione di ''Ricostruzione saldi''")); warning_box(TR("A causa degli errori riscontrati i saldi di magazzino \npotrebbero non essere stati del tutto aggiornati. \nProcedere ad una nuova operazione di ''Ricostruzione saldi''"));
} }
} }
int mg1200(int argc, char* argv[]) int mg1200(int argc, char* argv[])
{ {
TApp_rebuildbalances a; TApp_rebuildbalances a;
a.run(argc, argv, TR("Ricostruzione saldi")); a.run(argc, argv, TR("Ricostruzione saldi"));
return 0; return 0;
} }

View File

@ -1,10 +1,6 @@
#include "mg1200.h" #include "mg1200.h"
TOOLBAR "topbar" 0 0 0 2 PAGE "Ricostruzione Saldi" -1 -1 40 3
#include <elabar.h>
ENDPAGE
PAGE "Ricostruzione Saldi" 0 0 0 0
DATE F_DATA DATE F_DATA
BEGIN BEGIN
@ -27,5 +23,11 @@ BEGIN
END END
ENDPAGE ENDPAGE
TOOLBAR "topbar" 0 0 0 2
#include <elabar.h>
ENDPAGE
ENDMASK ENDMASK

View File

@ -553,10 +553,10 @@ protected:
// @member: effettua l'aggiornamento dei saldi di una giacenza sulle gacenze per ciente/fornitore // @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); void update_balances_clifo(TRectype & clifomagrec, const TSaldo_mag_clifo & s);
// @member: effettua l'aggiornamento di un saldo di una giacenza // @member: effettua l'aggiornamento di un saldo di una giacenza
void update_balance(TRectype & rec, const char * fieldname, real diff) const; void update_balance(TRectype & rec, const char * fieldname, const real& diff, int sgn) const;
void giac_putkey(TLocalisamfile & mag, TSaldo_mag & s); void giac_putkey(TRectype& mag, const TSaldo_mag & s);
void giac_putkey_clifo(TLocalisamfile & clifomag, TSaldo_mag_clifo & s); void giac_putkey_clifo(TRectype& clifomag, const TSaldo_mag_clifo & s);
bool lock_anamag(const char *codart); bool lock_anamag(const char *codart);
bool unlock_anamag(const char *codart) ; bool unlock_anamag(const char *codart) ;
virtual const char * codmag_rauto(int r) const { return NULL;} virtual const char * codmag_rauto(int r) const { return NULL;}

View File

@ -521,8 +521,10 @@ void TArticolo_giacenza::set_body_key(TRectype & rowrec)
void TArticolo_giacenza::set_anno_mag (int anno) void TArticolo_giacenza::set_anno_mag (int anno)
{ {
if (_anno_mag != anno) if (_anno_mag != anno)
{
remove_body(LF_MAG); remove_body(LF_MAG);
_anno_mag = anno; _anno_mag = anno;
}
} }
void TArticolo_giacenza::set_anno_sto (int anno) void TArticolo_giacenza::set_anno_sto (int anno)
@ -633,13 +635,13 @@ bool TArticolo_giacenza::is_deletable(const TRectype& mag) const
for (i = 0; protected_fields[i]; i++) for (i = 0; protected_fields[i]; i++)
{ {
const TString& val = mag.get(protected_fields[i]); const TString& val = mag.get(protected_fields[i]);
if (val.not_empty() && !real::is_null(val)) if (val.full() && !real::is_null(val))
return false; return false;
} }
for (i = 0; zero_fields[i]; i++) for (i = 0; zero_fields[i]; i++)
{ {
const TString& val = mag.get(zero_fields[i]); const TString& val = mag.get(zero_fields[i]);
if (val.not_empty() && !real::is_null(val)) if (val.full() && !real::is_null(val))
return false; return false;
} }
return true; return true;
@ -647,7 +649,8 @@ bool TArticolo_giacenza::is_deletable(const TRectype& mag) const
bool TArticolo_giacenza::azzera_saldi(int codes, int codespre, bool save_to_disk) bool TArticolo_giacenza::azzera_saldi(int codes, int codespre, bool save_to_disk)
{ {
TRecord_array oldmag = mag(codespre); CHECKD(codes > 0 && codespre != codes, "Davvero azzereresti i saldi dall'esercizio ", codes);
TRecord_array& oldmag = mag(codespre);
TRecord_array& rec_arr = mag(codes); TRecord_array& rec_arr = mag(codes);
const int last = rec_arr.last_row(); const int last = rec_arr.last_row();
@ -656,20 +659,22 @@ bool TArticolo_giacenza::azzera_saldi(int codes, int codespre, bool save_to_disk
TRectype& mag = rec_arr[r]; TRectype& mag = rec_arr[r];
for (int i = 0; zero_fields[i]; i++) for (int i = 0; zero_fields[i]; i++)
mag.zero(zero_fields[i]); mag.zero(zero_fields[i]);
const TString80 liv(mag.get(MAG_LIVELLO));
const int row = find_mag(oldmag, mag.get(MAG_CODMAG), liv);
if (row >= 0) if (codespre > 0)
{ {
const TRectype & oldrec = oldmag[row]; const TString80 liv(mag.get(MAG_LIVELLO));
const int row = find_mag(oldmag, mag.get(MAG_CODMAG), liv);
for (int i = 0; protected_fields[i]; i++) if (row >= 0)
{ {
const TString& val = oldrec.get(protected_fields[i]); const TRectype& oldrec = oldmag[row];
if (val.not_empty() && !real::is_null(val)) for (int i = 0; protected_fields[i]; i++)
mag.put(protected_fields[i], val); {
} const TString& val = oldrec.get(protected_fields[i]);
} if (val.full() && !real::is_null(val))
mag.put(protected_fields[i], val);
}
}
}
if (is_deletable(mag)) if (is_deletable(mag))
rec_arr.destroy_row(r, TRUE); rec_arr.destroy_row(r, TRUE);
} }
@ -682,6 +687,7 @@ bool TArticolo_giacenza::azzera_saldi(int codes, int codespre, bool save_to_disk
bool TArticolo_giacenza::riporta_saldi(int oldes, int newes, const TTipo_valorizz tipo, bool TArticolo_giacenza::riporta_saldi(int oldes, int newes, const TTipo_valorizz tipo,
const char* catven, const char* codlis, bool save_to_disk) const char* catven, const char* codlis, bool save_to_disk)
{ {
CHECKD(oldes > 0 && oldes != newes, "Davvero riporteresti i saldi dall'esercizio ", oldes);
TString8 codmag; TString8 codmag;
TString16 liv; TString16 liv;
TRecord_array& rec_arr = mag(oldes); TRecord_array& rec_arr = mag(oldes);
@ -929,8 +935,7 @@ real TArticolo_giacenza::costo_standard(int annoes) const
real TArticolo_giacenza::costo_medio(int annoes, const char * codmag, const char * livello) const real TArticolo_giacenza::costo_medio(int annoes, const char * codmag, const char * livello) const
{ {
real acq; real acq, valacq;
real valacq;
#ifdef DBG #ifdef DBG
if (strlen(codmag)>3) if (strlen(codmag)>3)

View File

@ -572,7 +572,7 @@ bool TMov_mag::lock_anamag(const char *codart)
} }
void TMov_mag::giac_putkey(TLocalisamfile & mag, TSaldo_mag & s) void TMov_mag::giac_putkey(TRectype& mag, const TSaldo_mag & s)
{ {
mag.zero(); mag.zero();
mag.put(MAG_ANNOES, s.codes()); mag.put(MAG_ANNOES, s.codes());
@ -581,7 +581,7 @@ void TMov_mag::giac_putkey(TLocalisamfile & mag, TSaldo_mag & s)
mag.put(MAG_LIVELLO, s.livello()); mag.put(MAG_LIVELLO, s.livello());
} }
void TMov_mag::giac_putkey_clifo(TLocalisamfile & clifomag, TSaldo_mag_clifo & s) void TMov_mag::giac_putkey_clifo(TRectype& clifomag, const TSaldo_mag_clifo & s)
{ {
clifomag.zero(); clifomag.zero();
clifomag.put(CLIFOGIAC_ANNOES, s.codes()); clifomag.put(CLIFOGIAC_ANNOES, s.codes());
@ -593,35 +593,35 @@ void TMov_mag::giac_putkey_clifo(TLocalisamfile & clifomag, TSaldo_mag_clifo & s
} }
// aggiorna tutti i saldi in base alle modifiche fatte. // aggiorna tutti i saldi in base alle modifiche fatte.
// il lock su anagrafica dovrebbe garantire il lock su tutte le // il lock su anagrafica dovrebbe garantire il lock su tutte le giacenze dell'articolo
// giacenze dell'articolo
bool TMov_mag::update_balances(bool lock) bool TMov_mag::update_balances(bool lock)
{ {
bool updated_bal = true; bool updated_bal = true;
TLocalisamfile mag(LF_MAG); TLocalisamfile mag(LF_MAG);
mag.setkey(2); mag.setkey(2);
TRectype& magcurr = mag.curr();
const TRecord_array& b = body(); const TRecord_array& b = body();
const TString8 hcodcaus(get(MOVMAG_CODCAUS)); const TString8 hcodcaus = get(MOVMAG_CODCAUS);
const long numreg = get_long(MOVMAG_NUMREG);
for (int i = b.last_row(); i > 0; i = b.pred_row(i)) for (int i = b.last_row(); i > 0; i = b.pred_row(i))
if (causale(i).update_ultcos()) if (causale(i).update_ultcos())
{ {
const TRectype & rec = b[i]; const TRectype & rec = b[i];
TArticolo & art = articolo(i); TArticolo & art = articolo(i);
if (art.lock_and_prompt(lock ? _testandlock : _nolock)) if (art.lock_and_prompt(lock ? _testandlock : _nolock))
{ {
const real prezzo = art.convert_to_um(rec.get_real(RMOVMAG_PREZZO), NULL, rec.get(RMOVMAG_UM), false); const real prezzo = art.convert_to_um(rec.get_real(RMOVMAG_PREZZO), NULL, rec.get(RMOVMAG_UM), false);
const long numreg = get_long(MOVMAG_NUMREG);
art.update_ultcosti(prezzo,get_date(MOVMAG_DATACOMP), numreg, i); art.update_ultcosti(prezzo,get_date(MOVMAG_DATACOMP), numreg, i);
art.rewrite(); art.rewrite();
} }
else else
{
if (lock) if (lock)
art.unlock(); art.unlock();
}
} }
if (_saldi_mag.items() > 0) if (_saldi_mag.items() > 0)
@ -631,25 +631,30 @@ bool TMov_mag::update_balances(bool lock)
_saldi_mag.get_keys(keys_mag); _saldi_mag.get_keys(keys_mag);
keys_mag.sort(); keys_mag.sort();
for (TToken_string * curr_key = (TToken_string *)keys_mag.first_item(); for (TToken_string* curr_key = (TToken_string*)keys_mag.first_item();
curr_key != NULL; curr_key != NULL; curr_key = (TToken_string*)keys_mag.succ_item())
curr_key = (TToken_string *)keys_mag.succ_item()
)
{ {
TSaldo_mag & saldo = (TSaldo_mag &)_saldi_mag[*curr_key]; const TSaldo_mag& saldo = (const TSaldo_mag&)_saldi_mag[*curr_key];
TArticolo_giacenza & art = cached_article_balances(saldo.codart()); const TCodice_articolo& codart = saldo.codart();
TArticolo_giacenza& art = cached_article_balances(codart);
if (art.lock_and_prompt(lock ? _testandlock : _nolock)) if (art.lock_and_prompt(lock ? _testandlock : _nolock))
{ {
giac_putkey(mag, saldo); giac_putkey(magcurr, saldo);
if (mag.read() != NOERR) int err = mag.read();
if (err != NOERR)
{ {
giac_putkey(mag, saldo); TRecord_array& sld = art.mag(saldo.codes());
mag.put(MAG_NRIGA, art.mag(get(MOVMAG_ANNOES)).rows() + 1); const int nriga = sld.rows() + 1;
mag.write(); giac_putkey(magcurr, saldo);
magcurr.put(MAG_NRIGA, nriga);
sld.add_row(magcurr);
sld.write(nriga > 1); // write riga singola, rewrite righe multiple
} }
update_balances(mag.curr(), saldo); update_balances(magcurr, saldo);
mag.rewrite(); err = mag.rewrite();
if (err != NOERR)
updated_bal = false;
if (lock) if (lock)
art.unlock(); art.unlock();
@ -661,6 +666,7 @@ bool TMov_mag::update_balances(bool lock)
{ {
TLocalisamfile clifomag(LF_CLIFOGIAC); TLocalisamfile clifomag(LF_CLIFOGIAC);
clifomag.setkey(2); clifomag.setkey(2);
TRectype& clifomag_curr = clifomag.curr();
TString_array keys_clifo; TString_array keys_clifo;
@ -668,8 +674,7 @@ bool TMov_mag::update_balances(bool lock)
keys_clifo.sort(); keys_clifo.sort();
for (TToken_string* curr_key = (TToken_string*)keys_clifo.first_item(); for (TToken_string* curr_key = (TToken_string*)keys_clifo.first_item();
curr_key != NULL; curr_key != NULL; curr_key = (TToken_string*)keys_clifo.succ_item())
curr_key = (TToken_string *)keys_clifo.succ_item())
{ {
TSaldo_mag_clifo & saldo=(TSaldo_mag_clifo &)_saldi_mag_clifo[*curr_key]; TSaldo_mag_clifo & saldo=(TSaldo_mag_clifo &)_saldi_mag_clifo[*curr_key];
@ -677,28 +682,28 @@ bool TMov_mag::update_balances(bool lock)
if (art.lock_and_prompt(lock ? _testandlock : _nolock)) if (art.lock_and_prompt(lock ? _testandlock : _nolock))
{ {
giac_putkey_clifo(clifomag, saldo); giac_putkey_clifo(clifomag_curr, saldo);
if (clifomag.read() != NOERR) if (clifomag.read() != NOERR)
{ {
// non trovato: aggiungo // non trovato: aggiungo
clifomag.setkey(1); clifomag.setkey(1);
giac_putkey_clifo(clifomag, saldo); giac_putkey_clifo(clifomag_curr, saldo);
clifomag.put(CLIFOGIAC_NRIGA, 999); clifomag_curr.put(CLIFOGIAC_NRIGA, 999);
if (clifomag.read(_isgteq) == NOERR) if (clifomag.read(_isgteq) == NOERR)
clifomag.prev(); clifomag.prev();
int nriga = 1; int nriga = 1;
if (clifomag.get_int(CLIFOGIAC_ANNOES) == saldo.codes() && if (clifomag_curr.get_int(CLIFOGIAC_ANNOES) == saldo.codes() &&
clifomag.get_char(CLIFOGIAC_TIPOCF) == saldo.tipocf() && clifomag_curr.get_char(CLIFOGIAC_TIPOCF) == saldo.tipocf() &&
clifomag.get(CLIFOGIAC_CODCF) == saldo.codcf() && clifomag_curr.get(CLIFOGIAC_CODCF) == saldo.codcf() &&
clifomag.get(CLIFOGIAC_CODART) == saldo.codart() && clifomag_curr.get(CLIFOGIAC_CODART) == saldo.codart() &&
clifomag.get(CLIFOGIAC_LIVELLO ) == saldo.livello()) clifomag_curr.get(CLIFOGIAC_LIVELLO ) == saldo.livello())
nriga = clifomag.get_int(CLIFOGIAC_NRIGA) + 1; nriga = clifomag_curr.get_int(CLIFOGIAC_NRIGA) + 1;
giac_putkey_clifo(clifomag, saldo); giac_putkey_clifo(clifomag_curr, saldo);
clifomag.put(CLIFOGIAC_NRIGA, nriga); clifomag_curr.put(CLIFOGIAC_NRIGA, nriga);
clifomag.write(); clifomag.write();
clifomag.setkey(2); clifomag.setkey(2);
} }
update_balances_clifo(clifomag.curr(), saldo); update_balances_clifo(clifomag_curr, saldo);
clifomag.rewrite(); clifomag.rewrite();
if (lock) if (lock)
@ -721,45 +726,45 @@ void TMov_mag::update_balances(TRectype & magrec, const TSaldo_mag & s)
{ {
const real diff = s.quant(); const real diff = s.quant();
update_balance(magrec, MAG_GIAC, diff * (real)caus.sgn(s_giac)); // update .. update_balance(magrec, MAG_GIAC, diff, caus.sgn(s_giac)); // update ..
update_balance(magrec, MAG_ACQ, diff * (real)caus.sgn(s_acq)); // update .. update_balance(magrec, MAG_ACQ, diff, caus.sgn(s_acq)); // update ..
update_balance(magrec, MAG_ENT, diff * (real)caus.sgn(s_ent)); update_balance(magrec, MAG_ENT, diff, caus.sgn(s_ent));
update_balance(magrec, MAG_VEN, diff * (real)caus.sgn(s_ven)); update_balance(magrec, MAG_VEN, diff, caus.sgn(s_ven));
update_balance(magrec, MAG_USC, diff * (real)caus.sgn(s_usc)); update_balance(magrec, MAG_USC, diff, caus.sgn(s_usc));
update_balance(magrec, MAG_ORDC, diff * (real)caus.sgn(s_ordc)); update_balance(magrec, MAG_ORDC, diff, caus.sgn(s_ordc));
update_balance(magrec, MAG_ORDF, diff * (real)caus.sgn(s_ordf)); update_balance(magrec, MAG_ORDF, diff, caus.sgn(s_ordf));
update_balance(magrec, MAG_RIM, diff * (real)caus.sgn(s_rim)); update_balance(magrec, MAG_RIM, diff, caus.sgn(s_rim));
update_balance(magrec, MAG_SCARTI, diff * (real)caus.sgn(s_scart)); update_balance(magrec, MAG_SCARTI, diff, caus.sgn(s_scart));
update_balance(magrec, MAG_INCL, diff * (real)caus.sgn(s_incl)); update_balance(magrec, MAG_INCL, diff, caus.sgn(s_incl));
update_balance(magrec, MAG_ACL, diff * (real)caus.sgn(s_acl)); update_balance(magrec, MAG_ACL, diff, caus.sgn(s_acl));
update_balance(magrec, MAG_PRODCOMP, diff * (real)caus.sgn(s_prodc)); update_balance(magrec, MAG_PRODCOMP, diff, caus.sgn(s_prodc));
update_balance(magrec, MAG_PRODFIN, diff * (real)caus.sgn(s_prodf)); update_balance(magrec, MAG_PRODFIN, diff, caus.sgn(s_prodf));
update_balance(magrec, MAG_NLABEL, diff * (real)caus.sgn(s_label)); update_balance(magrec, MAG_NLABEL, diff, caus.sgn(s_label));
update_balance(magrec, MAG_USER1, diff * (real)caus.sgn(s_user1)); update_balance(magrec, MAG_USER1, diff, caus.sgn(s_user1));
update_balance(magrec, MAG_USER2, diff * (real)caus.sgn(s_user2)); update_balance(magrec, MAG_USER2, diff, caus.sgn(s_user2));
update_balance(magrec, MAG_USER3, diff * (real)caus.sgn(s_user3)); update_balance(magrec, MAG_USER3, diff, caus.sgn(s_user3));
update_balance(magrec, MAG_USER4, diff * (real)caus.sgn(s_user4)); update_balance(magrec, MAG_USER4, diff, caus.sgn(s_user4));
update_balance(magrec, MAG_USER5, diff * (real)caus.sgn(s_user5)); update_balance(magrec, MAG_USER5, diff, caus.sgn(s_user5));
update_balance(magrec, MAG_USER6, diff * (real)caus.sgn(s_user6)); update_balance(magrec, MAG_USER6, diff, caus.sgn(s_user6));
} }
if (caus.update_val()) if (caus.update_val())
{ {
const real diff_val = s.valore(); const real diff_val = s.valore();
update_balance(magrec, MAG_VALACQ, diff_val * (real)caus.sgn(s_acq)); // update .. update_balance(magrec, MAG_VALACQ, diff_val, caus.sgn(s_acq)); // update ..
update_balance(magrec, MAG_VALENT, diff_val * (real)caus.sgn(s_ent)); update_balance(magrec, MAG_VALENT, diff_val, caus.sgn(s_ent));
update_balance(magrec, MAG_VALVEN, diff_val * (real)caus.sgn(s_ven)); update_balance(magrec, MAG_VALVEN, diff_val, caus.sgn(s_ven));
update_balance(magrec, MAG_VALUSC, diff_val * (real)caus.sgn(s_usc)); update_balance(magrec, MAG_VALUSC, diff_val, caus.sgn(s_usc));
update_balance(magrec, MAG_VALORDC, diff_val * (real)caus.sgn(s_ordc)); update_balance(magrec, MAG_VALORDC, diff_val, caus.sgn(s_ordc));
update_balance(magrec, MAG_VALORDF, diff_val * (real)caus.sgn(s_ordf)); update_balance(magrec, MAG_VALORDF, diff_val, caus.sgn(s_ordf));
update_balance(magrec, MAG_VALRIM, diff_val* (real)caus.sgn(s_rim)); update_balance(magrec, MAG_VALRIM, diff_val, caus.sgn(s_rim));
update_balance(magrec, MAG_VALSCARTI, diff_val * (real)caus.sgn(s_scart)); update_balance(magrec, MAG_VALSCARTI, diff_val, caus.sgn(s_scart));
update_balance(magrec, MAG_USERVAL1, diff_val * (real)caus.sgn(s_user1)); update_balance(magrec, MAG_USERVAL1, diff_val, caus.sgn(s_user1));
update_balance(magrec, MAG_USERVAL2, diff_val * (real)caus.sgn(s_user2)); update_balance(magrec, MAG_USERVAL2, diff_val, caus.sgn(s_user2));
update_balance(magrec, MAG_USERVAL3, diff_val * (real)caus.sgn(s_user3)); update_balance(magrec, MAG_USERVAL3, diff_val, caus.sgn(s_user3));
update_balance(magrec, MAG_USERVAL4, diff_val * (real)caus.sgn(s_user4)); update_balance(magrec, MAG_USERVAL4, diff_val, caus.sgn(s_user4));
update_balance(magrec, MAG_USERVAL5, diff_val * (real)caus.sgn(s_user5)); update_balance(magrec, MAG_USERVAL5, diff_val, caus.sgn(s_user5));
update_balance(magrec, MAG_USERVAL6, diff_val * (real)caus.sgn(s_user6)); update_balance(magrec, MAG_USERVAL6, diff_val, caus.sgn(s_user6));
} }
} }
@ -773,48 +778,48 @@ void TMov_mag::update_balances_clifo(TRectype & clifomagrec, const TSaldo_mag_cl
{ {
const real diff = s.quant(); const real diff = s.quant();
update_balance(clifomagrec, CLIFOGIAC_GIAC, -diff * (real)caus.sgn(s_giac)); // update .. update_balance(clifomagrec, CLIFOGIAC_GIAC, -diff, caus.sgn(s_giac)); // update ..
update_balance(clifomagrec, CLIFOGIAC_ACQ, diff * (real)caus.sgn(s_ven)); // update .. update_balance(clifomagrec, CLIFOGIAC_ACQ, diff, caus.sgn(s_ven)); // update ..
update_balance(clifomagrec, CLIFOGIAC_ENT, diff * (real)caus.sgn(s_usc)); update_balance(clifomagrec, CLIFOGIAC_ENT, diff, caus.sgn(s_usc));
update_balance(clifomagrec, CLIFOGIAC_VEN, diff * (real)caus.sgn(s_acq)); update_balance(clifomagrec, CLIFOGIAC_VEN, diff, caus.sgn(s_acq));
update_balance(clifomagrec, CLIFOGIAC_USC, diff * (real)caus.sgn(s_ent)); update_balance(clifomagrec, CLIFOGIAC_USC, diff, caus.sgn(s_ent));
update_balance(clifomagrec, CLIFOGIAC_ORDC, diff * (real)caus.sgn(s_ordf)); update_balance(clifomagrec, CLIFOGIAC_ORDC, diff, caus.sgn(s_ordf));
update_balance(clifomagrec, CLIFOGIAC_ORDF, diff * (real)caus.sgn(s_ordc)); update_balance(clifomagrec, CLIFOGIAC_ORDF, diff, caus.sgn(s_ordc));
update_balance(clifomagrec, CLIFOGIAC_RIM, -diff * (real)caus.sgn(s_rim)); update_balance(clifomagrec, CLIFOGIAC_RIM, -diff, caus.sgn(s_rim));
update_balance(clifomagrec, CLIFOGIAC_SCARTI, -diff * (real)caus.sgn(s_scart)); update_balance(clifomagrec, CLIFOGIAC_SCARTI, -diff, caus.sgn(s_scart));
update_balance(clifomagrec, CLIFOGIAC_INCL, diff * (real)caus.sgn(s_acl)); update_balance(clifomagrec, CLIFOGIAC_INCL, diff, caus.sgn(s_acl));
update_balance(clifomagrec, CLIFOGIAC_ACL, diff * (real)caus.sgn(s_incl)); update_balance(clifomagrec, CLIFOGIAC_ACL, diff, caus.sgn(s_incl));
update_balance(clifomagrec, CLIFOGIAC_PRODCOMP, -diff * (real)caus.sgn(s_prodc)); update_balance(clifomagrec, CLIFOGIAC_PRODCOMP, -diff, caus.sgn(s_prodc));
update_balance(clifomagrec, CLIFOGIAC_PRODFIN, -diff * (real)caus.sgn(s_prodf)); update_balance(clifomagrec, CLIFOGIAC_PRODFIN, -diff, caus.sgn(s_prodf));
update_balance(clifomagrec, CLIFOGIAC_DOTIN, diff * (real)caus.sgn(s_dotin)); update_balance(clifomagrec, CLIFOGIAC_DOTIN, diff, caus.sgn(s_dotin));
update_balance(clifomagrec, CLIFOGIAC_DOTOD, diff * (real)caus.sgn(s_dotod)); update_balance(clifomagrec, CLIFOGIAC_DOTOD, diff, caus.sgn(s_dotod));
update_balance(clifomagrec, CLIFOGIAC_DOTTM, diff * (real)caus.sgn(s_dottm)); update_balance(clifomagrec, CLIFOGIAC_DOTTM, diff, caus.sgn(s_dottm));
update_balance(clifomagrec, CLIFOGIAC_CONSANNO, diff * (real)caus.sgn(s_consanno)); update_balance(clifomagrec, CLIFOGIAC_CONSANNO, diff, caus.sgn(s_consanno));
update_balance(clifomagrec, CLIFOGIAC_USER1, diff * (real)caus.sgn(s_user1)); update_balance(clifomagrec, CLIFOGIAC_USER1, diff, caus.sgn(s_user1));
update_balance(clifomagrec, CLIFOGIAC_USER2, diff * (real)caus.sgn(s_user2)); update_balance(clifomagrec, CLIFOGIAC_USER2, diff, caus.sgn(s_user2));
update_balance(clifomagrec, CLIFOGIAC_USER3, diff * (real)caus.sgn(s_user3)); update_balance(clifomagrec, CLIFOGIAC_USER3, diff, caus.sgn(s_user3));
update_balance(clifomagrec, CLIFOGIAC_USER4, diff * (real)caus.sgn(s_user4)); update_balance(clifomagrec, CLIFOGIAC_USER4, diff, caus.sgn(s_user4));
update_balance(clifomagrec, CLIFOGIAC_USER5, diff * (real)caus.sgn(s_user5)); update_balance(clifomagrec, CLIFOGIAC_USER5, diff, caus.sgn(s_user5));
update_balance(clifomagrec, CLIFOGIAC_USER6, diff * (real)caus.sgn(s_user6)); update_balance(clifomagrec, CLIFOGIAC_USER6, diff, caus.sgn(s_user6));
} }
if (caus.update_val()) if (caus.update_val())
{ {
const real diff_val = s.valore(); const real diff_val = s.valore();
update_balance(clifomagrec, CLIFOGIAC_VALACQ, diff_val * (real)caus.sgn(s_ven)); // update .. update_balance(clifomagrec, CLIFOGIAC_VALACQ, diff_val, caus.sgn(s_ven)); // update ..
update_balance(clifomagrec, CLIFOGIAC_VALENT, diff_val * (real)caus.sgn(s_usc)); update_balance(clifomagrec, CLIFOGIAC_VALENT, diff_val, caus.sgn(s_usc));
update_balance(clifomagrec, CLIFOGIAC_VALVEN, diff_val * (real)caus.sgn(s_acq)); update_balance(clifomagrec, CLIFOGIAC_VALVEN, diff_val, caus.sgn(s_acq));
update_balance(clifomagrec, CLIFOGIAC_VALUSC, diff_val * (real)caus.sgn(s_ven)); update_balance(clifomagrec, CLIFOGIAC_VALUSC, diff_val, caus.sgn(s_ven));
update_balance(clifomagrec, CLIFOGIAC_VALORDC, diff_val * (real)caus.sgn(s_ordf)); update_balance(clifomagrec, CLIFOGIAC_VALORDC, diff_val, caus.sgn(s_ordf));
update_balance(clifomagrec, CLIFOGIAC_VALORDF, diff_val * (real)caus.sgn(s_ordc)); update_balance(clifomagrec, CLIFOGIAC_VALORDF, diff_val, caus.sgn(s_ordc));
update_balance(clifomagrec, CLIFOGIAC_VALRIM, -diff_val* (real)caus.sgn(s_rim)); update_balance(clifomagrec, CLIFOGIAC_VALRIM, -diff_val, caus.sgn(s_rim));
update_balance(clifomagrec, CLIFOGIAC_VALSCARTI, -diff_val * (real)caus.sgn(s_scart)); update_balance(clifomagrec, CLIFOGIAC_VALSCARTI, -diff_val, caus.sgn(s_scart));
update_balance(clifomagrec, CLIFOGIAC_USERVAL1, diff_val * (real)caus.sgn(s_user1)); update_balance(clifomagrec, CLIFOGIAC_USERVAL1, diff_val, caus.sgn(s_user1));
update_balance(clifomagrec, CLIFOGIAC_USERVAL2, diff_val * (real)caus.sgn(s_user2)); update_balance(clifomagrec, CLIFOGIAC_USERVAL2, diff_val, caus.sgn(s_user2));
update_balance(clifomagrec, CLIFOGIAC_USERVAL3, diff_val * (real)caus.sgn(s_user3)); update_balance(clifomagrec, CLIFOGIAC_USERVAL3, diff_val, caus.sgn(s_user3));
update_balance(clifomagrec, CLIFOGIAC_USERVAL4, diff_val * (real)caus.sgn(s_user4)); update_balance(clifomagrec, CLIFOGIAC_USERVAL4, diff_val, caus.sgn(s_user4));
update_balance(clifomagrec, CLIFOGIAC_USERVAL5, diff_val * (real)caus.sgn(s_user5)); update_balance(clifomagrec, CLIFOGIAC_USERVAL5, diff_val, caus.sgn(s_user5));
update_balance(clifomagrec, CLIFOGIAC_USERVAL6, diff_val * (real)caus.sgn(s_user6)); update_balance(clifomagrec, CLIFOGIAC_USERVAL6, diff_val, caus.sgn(s_user6));
} }
} }
@ -857,9 +862,15 @@ int TMov_mag::codice_esercizio(const TDate &d)
return esercizi().date2esc(d); return esercizi().date2esc(d);
} }
void TMov_mag::update_balance(TRectype & rec, const char * fieldname, real diff) const void TMov_mag::update_balance(TRectype & rec, const char * fieldname, const real& val, const int sgn) const
{ {
rec.put(fieldname,rec.get_real(fieldname) + diff); if (sgn != 0)
{
if (sgn > 0)
rec.add(fieldname, val);
else
rec.add(fieldname, -val);
}
} }
struct TBalance_params struct TBalance_params
@ -964,7 +975,8 @@ bool rebuild_balances(int codes, const TTipo_valorizz tipo_valorizz,
p.codes = codes; p.codes = codes;
p.codesprec = esercizi().pred(codes); p.codesprec = esercizi().pred(codes);
p.zero_giac = p.codesprec > 0 && esercizi().esercizio(p.codesprec).chiusura_mag().ok(); //p.zero_giac = p.codesprec > 0 && esercizi().esercizio(p.codesprec).chiusura_mag().ok();
p.zero_giac = p.codesprec <= 0 || esercizi().esercizio(p.codesprec).chiusura_mag().ok();
p.catv = catven; p.catv = catven;
p.codl = codlis; p.codl = codlis;
@ -985,14 +997,13 @@ bool rebuild_balances(int codes, const TTipo_valorizz tipo_valorizz,
// ricostruisce i saldi (ciclo sui movimenti) // ricostruisce i saldi (ciclo sui movimenti)
bool ok = true; bool ok = true;
TRectype rec(LF_MOVMAG);
TRelation relmovmag(LF_MOVMAG);
TRectype& rec = relmovmag.curr();
rec.put(MOVMAG_ANNOES, codes); rec.put(MOVMAG_ANNOES, codes);
TCursor mov_cur(new TRelation(LF_MOVMAG),"", 2, &rec, &rec); TCursor mov_cur(&relmovmag ,"", 2, &rec, &rec);
relmovmag.lfile().set_curr(new TMov_mag());
mov_cur.relation()->lfile().set_curr(new TMov_mag());
mov_cur.freeze();
msg.format(FR("Ricostruzione saldi esercizio %04d : ricalcolo..."), codes); msg.format(FR("Ricostruzione saldi esercizio %04d : ricalcolo..."), codes);
mov_cur.scan(recalc_mov, (void *) &ok, msg); mov_cur.scan(recalc_mov, (void *) &ok, msg);