diff --git a/mg/mglib02a.cpp b/mg/mglib02a.cpp index 3e0b5ecf7..a9006d4d4 100755 --- a/mg/mglib02a.cpp +++ b/mg/mglib02a.cpp @@ -599,45 +599,50 @@ bool TMov_mag::update_balances(bool lock) { bool updated_bal = true; - TLocalisamfile mag(LF_MAG); - mag.setkey(2); - TRectype& magcurr = mag.curr(); - const TRecord_array& b = body(); const TString8 hcodcaus = get(MOVMAG_CODCAUS); - for (int i = b.last_row(); i > 0; i = b.pred_row(i)) - if (causale(i).update_ultcos()) - { + for (int i = b.last_row(); i > 0; i = b.pred_row(i)) if (causale(i).update_ultcos()) + { + const TRectype & rec = b[i]; + TArticolo & art = articolo(i); - const TRectype & rec = b[i]; - TArticolo & art = articolo(i); - - art.set_nuovo(false); - 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 long numreg = get_long(MOVMAG_NUMREG); - art.update_ultcosti(prezzo,get_date(MOVMAG_DATACOMP), numreg, i); - art.rewrite(); - } - else - { - if (lock) - art.unlock(); - } - } + art.set_nuovo(false); + 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 long numreg = get_long(MOVMAG_NUMREG); + art.update_ultcosti(prezzo,get_date(MOVMAG_DATACOMP), numreg, i); + art.rewrite(); + } + else + { + if (lock) + art.unlock(); + } + } if (_saldi_mag.items() > 0) { + TFast_isamfile mag(LF_MAG); + mag.setkey(2); + TRectype& magcurr = mag.curr(); + TString_array keys_mag; _saldi_mag.get_keys(keys_mag); keys_mag.sort(); - - for (TToken_string* curr_key = (TToken_string*)keys_mag.first_item(); - curr_key != NULL; curr_key = (TToken_string*)keys_mag.succ_item()) + + TProgind* pi = NULL; + if (keys_mag.items() >= 32) + { + TString msg; msg << TR("Aggiornamento saldi del movimento ") << get(MOVMAG_NUMREG); + pi = new TProgind(keys_mag.items(), msg, false, true); + } + + FOR_EACH_ARRAY_ROW(keys_mag, r, curr_key) { + if (pi) pi->addstatus(1); const TSaldo_mag& saldo = (const TSaldo_mag&)_saldi_mag[*curr_key]; const TCodice_articolo& codart = saldo.codart(); TArticolo_giacenza& art = cached_article_balances(codart); @@ -664,11 +669,13 @@ bool TMov_mag::update_balances(bool lock) art.unlock(); } } + + if (pi) delete pi; } if (_saldi_mag_clifo.items() > 0) { - TLocalisamfile clifomag(LF_CLIFOGIAC); + TFast_isamfile clifomag(LF_CLIFOGIAC); clifomag.setkey(2); TRectype& clifomag_curr = clifomag.curr(); @@ -1035,33 +1042,47 @@ bool rebuild_balances(int codes, const TTipo_valorizz tipo_valorizz, p.codl = codlis; p.tipov = tipo_valorizz; - // azzera tutte giacenze (ciclo sulle giacenze) - TCursor anamag_cur(new TRelation(LF_ANAMAG)); - TString msg; + TString msg; + + { + // azzera tutte giacenze (ciclo sulle giacenze) + TRelation anamag_rel(LF_ANAMAG); + TCursor anamag_cur(&anamag_rel); - anamag_cur.relation()->lfile().set_curr(new TArticolo_giacenza()); - anamag_cur.freeze(); - msg.format(FR("Ricostruzione saldi esercizio %04d : azzeramento..."), codes); - anamag_cur.scan(reset_giac, (void *) &p, msg); + anamag_cur.relation()->lfile().set_curr(new TArticolo_giacenza()); + msg.format(FR("Ricostruzione saldi esercizio %04d : azzeramento..."), codes); + anamag_cur.scan(reset_giac, (void*)&p, msg); + } - TString filter; filter << CLIFOGIAC_ANNOES << "==" << p.codesprec; - TCursor c(new TRelation(LF_CLIFOGIAC), filter); + { + TString filter; filter << CLIFOGIAC_ANNOES << "==" << p.codesprec; + TRelation clifogiac_rel(LF_CLIFOGIAC); + TCursor c(&clifogiac_rel, filter); - msg.format(FR("Ricostruzione saldi esercizio %04d : azzeramento giacenze clienti..."), codes); - c.scan(rel_reset_clifogiac, (void *) &p, msg); + msg.format(FR("Ricostruzione saldi esercizio %04d : azzeramento giacenze clienti..."), codes); + c.scan(rel_reset_clifogiac, (void*)&p, msg); + } // ricostruisce i saldi (ciclo sui movimenti) bool ok = true; + { + TRelation relmovmag(LF_MOVMAG); + TRectype& rec = relmovmag.curr(); + rec.put(MOVMAG_ANNOES, codes); - TRelation relmovmag(LF_MOVMAG); - TRectype& rec = relmovmag.curr(); - rec.put(MOVMAG_ANNOES, codes); - - TCursor mov_cur(&relmovmag ,"", 2, &rec, &rec); - relmovmag.lfile().set_curr(new TMov_mag()); - msg.format(FR("Ricostruzione saldi esercizio %04d : ricalcolo..."), codes); - mov_cur.scan(recalc_mov, (void *) &ok, msg); + TCursor mov_cur(&relmovmag, "", 2, &rec, &rec); + relmovmag.lfile().set_curr(new TMov_mag()); + msg.format(FR("Ricostruzione saldi esercizio %04d : ricalcolo..."), codes); + mov_cur.scan(recalc_mov, (void*)&ok, msg); + } a.close(); + + if (ok) + { + TSystemisamfile mag(LF_MAG); + mag.pack(true, true); + } + return ok; }