diff --git a/cg/cglib02.cpp b/cg/cglib02.cpp index 552d0b881..fb0060822 100755 --- a/cg/cglib02.cpp +++ b/cg/cglib02.cpp @@ -15,9 +15,38 @@ #include "conto.h" #include "cglib.h" -void TTab_conti::do_agg(TConto* tc, int anno_es, const real& importo, - char sezione, bool movap, bool provv, bool somma, const char* key) +TConto* TTab_conti::add(const TBill& c, int anno) { + TString80 key; + key.format("%4d%3d%3d%6ld", anno, c.gruppo(), c.conto(), c.sottoconto()); + TConto* tc = new TConto(c.gruppo(), c.conto(), c.sottoconto(), c.tipo()); + TAssoc_array::add(key, tc); + return tc; +} + +TConto* TTab_conti::find(const TBill& c, int anno) +{ + TString80 key; + key.format("%4d%3d%3d%6ld", anno, c.gruppo(), c.conto(), c.sottoconto()); + TConto* tc = (TConto*)objptr(key); + return tc; +} + +void TTab_conti::remove(const TBill& c, int anno) +{ + TString80 key; + key.format("%4d%3d%3d%6ld", anno, c.gruppo(), c.conto(), c.sottoconto()); + TAssoc_array::remove(key); +} + +void TTab_conti::aggiorna_conto(const TBill& tcon, + int anno_es, const real& importo, char sezione, + bool movap, bool provv, bool somma) +{ + TConto* tc = find(tcon, anno_es); + if (tc == NULL) + tc = add(tcon, anno_es); + real i = somma ? importo : -importo; if (movap) @@ -40,53 +69,10 @@ void TTab_conti::do_agg(TConto* tc, int anno_es, const real& importo, // rimuovo dalla tabella il conto se dare e avere vanno a zero if (tc->dare().is_zero() && tc->avere().is_zero() && tc->darepro().is_zero() && tc->averepro().is_zero() && - tc->saldo().is_zero()) remove(key); + tc->saldo().is_zero()) + remove(*tc, anno_es); } - -void TTab_conti::aggiorna_conto(const TConto& tcon, int anno_es, const real& importo, char sezione, bool movap, bool provv, bool somma) -{ - TString80 key; - key << format("%4d", anno_es); - key << format("%3d", tcon.gruppo()); - key << format("%3d", tcon.conto()); - key << format("%6ld", tcon.sottoconto()); - - TConto* tc = (TConto*) objptr(key); - if (tc == NULL) - { - tc = new TConto(tcon.gruppo(), tcon.conto(), tcon.sottoconto(), - tcon.tipo()); - add(key, tc); - tc->dare() = ZERO; - tc->avere() = ZERO; - tc->darepro() = ZERO; - tc->averepro() = ZERO; - tc->saldo() = ZERO; - } - do_agg(tc, anno_es, importo, sezione, movap, provv, somma, key); -} - -void TTab_conti::aggiorna_conto(int gruppo, int conto, long sottoconto, - int anno_es, const real& importo, char sezione, - bool movap, bool provv, bool somma) -{ - TString80 key; - key << format("%4d", anno_es); - key << format("%3d", gruppo); - key << format("%3d", conto); - key << format("%6ld", sottoconto); - - TConto* tc = (TConto*) objptr(key); - if (tc == NULL) - { - tc = new TConto(gruppo, conto, sottoconto); - add(key, tc); - } - do_agg(tc, anno_es, importo, sezione, movap, provv, somma, key); -} - - TSaldo_agg::TSaldo_agg() { _anno_es = 0; @@ -97,16 +83,14 @@ TSaldo_agg::TSaldo_agg() reset(); // pulizia dell'array dei conti } -void TSaldo_agg::aggiorna(const TConto& tc, const real& importo, char sezione, - bool somma) +void TSaldo_agg::aggiorna(const TBill& tc, const real& importo, char sezione, bool somma) { - _tab_conti.aggiorna_conto(tc, _anno_es, importo, sezione, _movap, _provv, - somma); + _tab_conti.aggiorna_conto(tc, _anno_es, importo, sezione, _movap, _provv, somma); } void TSaldo_agg::aggiorna(int gruppo, int conto, long sottoconto, const real& importo, char sezione, bool somma) { - _tab_conti.aggiorna_conto(gruppo, conto, sottoconto, _anno_es, importo, + _tab_conti.aggiorna_conto(TBill(gruppo, conto, sottoconto), _anno_es, importo, sezione, _movap, _provv, somma); } @@ -122,6 +106,7 @@ void TSaldo_agg::reset() // e azzero i progressivi. // /////////////////////////////////////////////////////////////////////////////// + void TSaldo_agg::clear_saldi(int year) { TLocalisamfile saldi(LF_SALDI); @@ -160,8 +145,8 @@ void TSaldo_agg::clear_saldi(int year) /////////////////////////////////////////////////////////////////////////////// void TSaldo_agg::registra() { - real s, r; - TString Flagsalini; + real si, r; + char flag_salini; TDate data_ulmov; long num_ulmov; TLocalisamfile saldi(LF_SALDI); @@ -170,8 +155,8 @@ void TSaldo_agg::registra() _tab_conti.restart(); for (int i = 0; i < conti; i++) { - THash_object * hobj = tconti(); - const TConto& tcon = (TConto &)hobj->obj(); + THash_object* hobj = _tab_conti.get_hashobj(); + TConto& tcon = (TConto &)hobj->obj(); CHECK(tcon.ok(), "Tentativo di saldare un conto incompleto"); saldi.zero(); @@ -189,14 +174,14 @@ void TSaldo_agg::registra() saldi.put(SLD_GRUPPO, tcon.gruppo()); saldi.put(SLD_CONTO, tcon.conto()); saldi.put(SLD_SOTTOCONTO, tcon.sottoconto()); - s = tcon.saldo(); - if (s < ZERO) - { Flagsalini = "A"; s = -s; } + si = tcon.saldo(); + if (si < ZERO) + { flag_salini = 'A'; si = -si; } else - Flagsalini = "D"; + flag_salini = 'D'; - saldi.put(SLD_FLAGSALINI, (const char *) Flagsalini); - saldi.put(SLD_SALDO, s); + saldi.put(SLD_FLAGSALINI, flag_salini); + saldi.put(SLD_SALDO, si); saldi.put(SLD_PDAREPRO, tcon.darepro()); saldi.put(SLD_PAVEREPRO, tcon.averepro()); saldi.put(SLD_PDARE, tcon.dare()); @@ -221,20 +206,20 @@ void TSaldo_agg::registra() saldi.put(SLD_NUMULTMOV, _num_ulmov); } r = tcon.saldo(); + si = saldi.get_real(SLD_SALDO); + flag_salini = saldi.get_char(SLD_FLAGSALINI); if (r != ZERO) { - s = saldi.get_real(SLD_SALDO); - Flagsalini = saldi.get(SLD_FLAGSALINI); - if (Flagsalini == "A") s = r - s; - else s = r + s; - if (s < ZERO) + if (flag_salini == 'A') si = r - si; + else si += r; + if (si < ZERO) { - Flagsalini = "A"; s = -s; + flag_salini = 'A'; si = -si; } else - Flagsalini = "D"; - saldi.put(SLD_FLAGSALINI, Flagsalini); - saldi.put(SLD_SALDO, s); + flag_salini = 'D'; + saldi.put(SLD_FLAGSALINI, flag_salini); + saldi.put(SLD_SALDO, si); } r = saldi.get_real(SLD_PDAREPRO); r += tcon.darepro(); @@ -250,6 +235,14 @@ void TSaldo_agg::registra() saldi.put(SLD_PAVERE, r); saldi.rewrite(); } + + TImporto sf(flag_salini, si); + const TImporto dare('D', saldi.get_real(SLD_PDARE)); + const TImporto avere('A', saldi.get_real(SLD_PAVERE)); + sf += dare; + sf += avere; + sf.normalize(); + tcon.saldo_finale() = sf; } }