diff --git a/ba/bacnv.cpp b/ba/bacnv.cpp index 5fd7581c3..66765032e 100755 --- a/ba/bacnv.cpp +++ b/ba/bacnv.cpp @@ -1,173 +1,173 @@ -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -#define usage "Errore - uso : bacnv 1 ditta" - -class TConversione_archivi : public TApplication -{ - int _nconv; - long _codditta; - long _oldditta; - int _error; - -protected: - virtual bool create() ; - virtual bool destroy() ; - virtual bool menu(MENU_TAG); - - bool convert_rmov(TLocalisamfile & rmov, TArray & recs, int nrecs); - void contropartita_rmov(); - -public: - TConversione_archivi() : _oldditta(0), _codditta(0), _error(0) {} -}; - -bool TConversione_archivi::create() -{ - if (argc() < 3) - { - _error = 101; - TMessage msg("ba1100", 0, format("%d", _error)); - - msg.send(); - return FALSE; - } - else - { - _oldditta = get_firm(); - _codditta = atol(argv(argc() - 1)); - _nconv = atoi(argv(1)); - if (_codditta != _oldditta) - { - if (_codditta == 0) prefhndl->set("com"); - else set_firm(_codditta); - } - dispatch_e_menu(MENU_ITEM(1)); - return TRUE; - } -} - -bool TConversione_archivi::destroy() -{ - if (_codditta != _oldditta) - { - if (_oldditta == 0) prefhndl->set("com"); - else set_firm(_oldditta); - } - if (_error > 0) - { - TMessage msg("ba1100", 0, format("%d", _error)); - msg.send(); - } - return TRUE; -} - -bool TConversione_archivi::menu(MENU_TAG) -{ - switch (_nconv) - { - case 1: - contropartita_rmov(); break; - default: - break; - } - return FALSE; -} - -bool TConversione_archivi::convert_rmov(TLocalisamfile & rmov, TArray & recs, int nrecs) -{ - const TRecnotype pos = rmov.recno(); - - for (int i = 0; i < nrecs; i++) - { - TRectype & r0 = (TRectype &) recs[i]; - const int rcontr = r0.get_int(RMV_RCONTR) - 1; - - if (rcontr >= 0 && rcontr < nrecs) - { - const TRectype & r1 = (const TRectype &) recs[rcontr]; - - r0.put(RMV_TIPOCC, r1.get(RMV_TIPOC)); - r0.put(RMV_GRUPPOC, r1.get_int(RMV_GRUPPO)); - r0.put(RMV_CONTOC, r1.get_int(RMV_CONTO)); - r0.put(RMV_SOTTOCONTOC, r1.get_long(RMV_SOTTOCONTO)); - } - r0.zero(RMV_RCONTR); - if (rmov.rewrite(r0) != NOERR) - { - const long reg = r0.get_long(RMV_NUMREG); - error_box("Non riesco ad aggiornare la riga contabile %ld / %d\nErrore n. %d", reg, i + 1, rmov.status()); - rmov.readat(pos); - _error = 102; - return FALSE; - } - } - rmov.readat(pos); - return TRUE; -} - -void TConversione_archivi::contropartita_rmov() -{ - TDir d; - d.get(LF_RMOV); - if (d.eox() == 0) return; - - TLocalisamfile rmov(LF_RMOV); - const TRecnotype nitems = rmov.items(); - TArray recs; - long oldreg = -1; - long reg = -1; - int nrow = 0; - TProgind p(nitems ? nitems : 1, - format("Conversione righe di movimento della ditta %ld", get_firm()), - TRUE, TRUE, 70); - for (rmov.first(); rmov.good(); rmov.next()) - { - p.addstatus(1); - reg = rmov.get_long(RMV_NUMREG); - if (oldreg != reg) - { - if (oldreg > 0) - if (convert_rmov(rmov, recs, nrow) == FALSE) - return; - oldreg = reg; - nrow = 0; - } - recs.add(rmov.curr(), nrow++); - CHECKD(nrow == rmov.get_int(RMV_NUMRIG), "Missed row ", nrow); - } - if (oldreg > 0) - if (convert_rmov(rmov, recs, nrow) == FALSE) - return; -} - -HIDDEN void bacnv(int argc, char** argv) -{ - TConversione_archivi a ; - a.run(argc, argv, "Conversione archivi"); -} - -int main(int argc,char** argv) -{ - const int r = (argc > 1) ? atoi(argv[1]) : 0; - - if (r <= 0 || r > 1) - { - error_box(usage); - return 100; - } - - bacnv(argc, argv); - return 0; -} - - +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#define usage "Errore - uso : bacnv 1 ditta" + +class TConversione_archivi : public TApplication +{ + int _nconv; + long _codditta; + long _oldditta; + int _error; + +protected: + virtual bool create() ; + virtual bool destroy() ; + virtual bool menu(MENU_TAG); + + bool convert_rmov(TLocalisamfile & rmov, TArray & recs, int nrecs); + void contropartita_rmov(); + +public: + TConversione_archivi() : _oldditta(0), _codditta(0), _error(0) {} +}; + +bool TConversione_archivi::create() +{ + if (argc() < 3) + { + _error = 101; + TMessage msg("ba1100", 0, format("%d", _error)); + + msg.send(); + return FALSE; + } + else + { + _oldditta = get_firm(); + _codditta = atol(argv(argc() - 1)); + _nconv = atoi(argv(1)); + if (_codditta != _oldditta) + { + if (_codditta == 0) prefhndl->set("com"); + else set_firm(_codditta); + } + dispatch_e_menu(MENU_ITEM(1)); + return TRUE; + } +} + +bool TConversione_archivi::destroy() +{ + if (_codditta != _oldditta) + { + if (_oldditta == 0) prefhndl->set("com"); + else set_firm(_oldditta); + } + if (_error > 0) + { + TMessage msg("ba1100", 0, format("%d", _error)); + msg.send(); + } + return TRUE; +} + +bool TConversione_archivi::menu(MENU_TAG) +{ + switch (_nconv) + { + case 1: + contropartita_rmov(); break; + default: + break; + } + return FALSE; +} + +bool TConversione_archivi::convert_rmov(TLocalisamfile & rmov, TArray & recs, int nrecs) +{ + const TRecnotype pos = rmov.recno(); + + for (int i = 0; i < nrecs; i++) + { + TRectype & r0 = (TRectype &) recs[i]; + const int rcontr = r0.get_int(RMV_RCONTR) - 1; + + if (rcontr >= 0 && rcontr < nrecs) + { + const TRectype & r1 = (const TRectype &) recs[rcontr]; + + r0.put(RMV_TIPOCC, r1.get(RMV_TIPOC)); + r0.put(RMV_GRUPPOC, r1.get_int(RMV_GRUPPO)); + r0.put(RMV_CONTOC, r1.get_int(RMV_CONTO)); + r0.put(RMV_SOTTOCONTOC, r1.get_long(RMV_SOTTOCONTO)); + } + r0.zero(RMV_RCONTR); + if (rmov.rewrite(r0) != NOERR) + { + const long reg = r0.get_long(RMV_NUMREG); + error_box("Non riesco ad aggiornare la riga contabile %ld / %d\nErrore n. %d", reg, i + 1, rmov.status()); + rmov.readat(pos); + _error = 102; + return FALSE; + } + } + rmov.readat(pos); + return TRUE; +} + +void TConversione_archivi::contropartita_rmov() +{ + TDir d; + d.get(LF_RMOV); + if (d.eox() == 0) return; + + TLocalisamfile rmov(LF_RMOV); + const TRecnotype nitems = rmov.items(); + TArray recs; + long oldreg = -1; + long reg = -1; + int nrow = 0; + TProgind p(nitems ? nitems : 1, + format("Conversione righe di movimento della ditta %ld", get_firm()), + TRUE, TRUE, 70); + for (rmov.first(); rmov.good(); rmov.next()) + { + p.addstatus(1); + reg = rmov.get_long(RMV_NUMREG); + if (oldreg != reg) + { + if (oldreg > 0) + if (convert_rmov(rmov, recs, nrow) == FALSE) + return; + oldreg = reg; + nrow = 0; + } + recs.add(rmov.curr(), nrow++); + CHECKD(nrow == rmov.get_int(RMV_NUMRIG), "Missed row ", nrow); + } + if (oldreg > 0) + if (convert_rmov(rmov, recs, nrow) == FALSE) + return; +} + +HIDDEN void bacnv(int argc, char** argv) +{ + TConversione_archivi a ; + a.run(argc, argv, "Conversione archivi"); +} + +int main(int argc,char** argv) +{ + const int r = (argc > 1) ? atoi(argv[1]) : 0; + + if (r <= 0 || r > 1) + { + error_box(usage); + return 100; + } + + bacnv(argc, argv); + return 0; +} + +