diff --git a/cg/cg0100.cpp b/cg/cg0100.cpp index d1496d2a5..76056a3db 100755 --- a/cg/cg0100.cpp +++ b/cg/cg0100.cpp @@ -1,343 +1,343 @@ -#include -#include - -#include "cg0.h" -#include "cg0100.h" - -#define ATTIVITA 1 -#define PASSIVITA 2 -#define COSTI 3 -#define RICAVI 4 -#define ORDINE 5 - -class CG0100_application : public TRelation_application -{ - TMask* _msk; - TRelation *_rel; - TLocalisamfile* _saldi; - TLocalisamfile* _tabcom; - - bool user_create(); - bool user_destroy(); - virtual TMask* get_mask(int mode) {return _msk;} - virtual bool changing_mask(int mode) {return FALSE;} - virtual bool protected_record(TRectype &rec); - virtual void init_query_mode(TMask& m); - virtual void init_insert_mode(TMask& m); - virtual void init_modify_mode(TMask& m) {init_insert_mode(m);} - virtual int write(const TMask& m); - virtual int rewrite(const TMask & m); - virtual int read(TMask& m); - -public: - virtual TRelation* get_relation() const {return _rel;} - CG0100_application() {} -}; -HIDDEN inline CG0100_application & app() { return (CG0100_application &) main_app();} - - -int CG0100_application::read(TMask& m) - -{ - const TRelation *r = get_relation(); - m.autoload(r); - if (m.get(FLD_CM1_LETTIVD).empty()) - { - int sezivd = m.get_int(FLD_CM1_SEZIVD); - if (sezivd == 1 || sezivd == 2) - m.set(FLD_CM1_SEZIVD, sezivd + 5); - } - if (m.get(FLD_CM1_LETTIVDOPP).empty()) - { - int sezivd = m.get_int(FLD_CM1_SEZIVDOPP); - if (sezivd == 1 || sezivd == 2) - m.set(FLD_CM1_SEZIVDOPP, sezivd + 5); - } - return NOERR; -} - -int CG0100_application::rewrite(const TMask& m) - -{ - TRelation *r = get_relation(); - - m.autosave(r); - int sezivd = m.get_int(FLD_CM1_SEZIVD); - TString16 sez; - - if (sezivd == 6 || sezivd == 7) - { - sez.format("%d", sezivd - 5); - r->lfile().put(PCN_SEZIVD, sez); - } - sezivd = m.get_int(FLD_CM1_SEZIVDOPP); - if (sezivd == 6 || sezivd == 7) - { - sez.format("%d", sezivd - 5); - r->lfile().put(PCN_SEZIVDOPP, sez); - } - return r->rewrite(); -} - -int CG0100_application::write(const TMask& m) - -{ - TRelation *r = get_relation(); - TString16 sez; - - m.autosave(r); - int sezivd = m.get_int(FLD_CM1_SEZIVD); - - if (sezivd == 6 || sezivd == 7) - { - sez.format("%d", sezivd - 5); - r->lfile().put(PCN_SEZIVD, sez); - } - sezivd = m.get_int(FLD_CM1_SEZIVDOPP); - if (sezivd == 6 || sezivd == 7) - { - sez.format("%d", sezivd - 5); - r->lfile().put(PCN_SEZIVDOPP, sez); - } - return r->write(); -} - -// Controlla se puo' essere effettuata la cancellazione di un conto - -bool CG0100_application::protected_record(TRectype &rec) -{ - TMask* m = get_mask(MODE_MOD); - TLocalisamfile& pconti = _rel->lfile(); - const int gruppo = atoi(m->get(FLD_CM1_GRUPPO)); - const int conto = atoi(m->get(FLD_CM1_CONTO)); - const long sottoc = atol(m->get(FLD_CM1_SOTTOCONTO)); - - // Se e' un sottoconto posso cancellarlo se non esistono saldi - if ((gruppo != 0) && (conto != 0) && (sottoc != 0)) - { - _saldi->zero(); - _saldi->put(PCN_GRUPPO, gruppo); - _saldi->put(PCN_CONTO, conto); - _saldi->put(PCN_SOTTOCONTO, sottoc); - _saldi->read(_isgteq); - - return _saldi->good() && gruppo ==_saldi->get_int(PCN_GRUPPO) && - conto ==_saldi->get_int(PCN_CONTO) && - sottoc ==_saldi->get_long(PCN_SOTTOCONTO); - } - get_relation()->save_status(); - pconti.zero() ; - pconti.put(PCN_GRUPPO, gruppo); - // Se e' un conto controllo se ha dei sottoconti - if (conto != 0) - pconti.put(PCN_CONTO, conto); - TRectype rec1(pconti.curr()); - - pconti.setkey(1) ; - pconti.read(); - pconti.next(); - const bool prot = (pconti.good() && (pconti.curr() == rec1)); - get_relation()->restore_status(); - return prot; -} - -void CG0100_application::init_query_mode(TMask& m) - -{ - m.send_key(K_SHIFT + K_CTRL + 's', -1); - m.send_key(K_SHIFT + K_CTRL + 's', -2); - m.send_key(K_SHIFT + K_CTRL + 's', -3); -} - -HIDDEN bool tmcf_handler(TMask_field& f, KEY key) - -{ - if (f.active() && key == K_SPACE) - { - TMask& m = f.mask(); - const int conto = atoi(m.get(FLD_CM1_CONTO)); - const long sottoc = atol(m.get(FLD_CM1_SOTTOCONTO)); - const bool enable_sezsaldi = (sottoc != 0) || (sottoc == 0 && conto != 0 && m.get(FLD_CM1_TMCF).not_empty()); - - m.show(FLD_CM2_SEZSALDI, enable_sezsaldi); - } - return TRUE; -} - - -void CG0100_application::init_insert_mode(TMask& m) - -{ - const int gruppo = atoi(m.get(FLD_CM1_GRUPPO)); - const int conto = atoi(m.get(FLD_CM1_CONTO)); - const long sottoc = atol(m.get(FLD_CM1_SOTTOCONTO)); - bool ivd_enable = TRUE; - - if (conto == 0 && sottoc == 0) - m.send_key(K_SHIFT + K_CTRL + 'h', -1); - else - if (sottoc == 0) - m.send_key(K_SHIFT + K_CTRL + 'h', -2); - else - m.send_key(K_SHIFT + K_CTRL + 'h', -3); - - TLocalisamfile& pconti = _rel->lfile(); - TString s(15), s2(1), s3(8), s4(2); - int s1 = 0; - - pconti.setkey(1) ; - - int indbil = 0; - - if (sottoc != 0) - { - pconti.zero(); - pconti.put(PCN_GRUPPO, gruppo); - pconti.put(PCN_CONTO, conto); - pconti.read(); - if (pconti.good()) - { - s = pconti.get(PCN_CODCBL); - s1 = atoi(pconti.get(PCN_SEZIVD)); - s2 = pconti.get(PCN_LETTIVD); - s3 = pconti.get(PCN_NUMRIVD); - s4 = pconti.get(PCN_NUMIVD); - indbil = pconti.get_int(PCN_INDBIL); - } - ivd_enable = (s1 == 0) && s2.empty() && s3.empty() && s4.empty(); - } - m.show(FLD_CM1_RICSER, indbil == PASSIVITA || indbil == RICAVI); - if (conto != 0) - { - m.enable(FLD_CM1_SEZIVD, ivd_enable); - m.show(FLD_CM1_LETTIVD, ivd_enable); - m.show(FLD_CM1_NUMRIVD, ivd_enable); - m.show(FLD_CM1_NUMIVD, ivd_enable); - m.show(FLD_CM1_LETTIVDH, !ivd_enable); - m.show(FLD_CM1_NUMRIVDH, !ivd_enable); - m.show(FLD_CM1_NUMIVDH, !ivd_enable); - if (!ivd_enable) - { - m.set(FLD_CM1_SEZIVD, s1); - m.set(FLD_CM1_LETTIVDH, s2); - m.set(FLD_CM1_NUMRIVDH, s3); - m.set(FLD_CM1_NUMIVDH, s4); - m.enable(FLD_CM1_SEZIVDOPP); - } - pconti.zero(); - pconti.put(PCN_GRUPPO, gruppo); - pconti.read(); - if (pconti.good()) - if (s.empty()) s = pconti.get(PCN_CODCBL); - } - if (s.not_empty()) - { - m.set(FLD_CM1_CODANALISIH, s); - m.show(FLD_CM1_CODANALISIH); - m.hide(FLD_CM1_CODTABANALISI); - } - else - { - m.show(FLD_CM1_CODTABANALISI); - m.hide(FLD_CM1_CODANALISIH); - } - const bool enable_sezsaldi = (sottoc != 0) || (sottoc == 0 && conto != 0 && m.get(FLD_CM1_TMCF).not_empty()); - m.show(FLD_CM2_SEZSALDI, enable_sezsaldi); -} - - -HIDDEN bool gruppo_handler(TMask_field& f, KEY key) -{ - if (key == K_ENTER) - { - const TMask& m = f.mask(); - const int gruppo = atoi(m.get(FLD_CM1_GRUPPO)); - const int conto = atoi(m.get(FLD_CM1_CONTO)); - TLocalisamfile& pconti = app().get_relation()->lfile(); - if (gruppo != 0 && conto != 0) - { - pconti.zero() ; - pconti.put(PCN_GRUPPO, gruppo) ; - pconti.setkey(1) ; - pconti.read(); - if (pconti.bad()) - return f.warning_box ("Il gruppo non esiste"); - } - } - return TRUE; -} - -HIDDEN bool conto_handler(TMask_field& f, KEY key) -{ - if (key == K_ENTER) - { - const TMask& m = f.mask(); - const int gruppo = atoi(m.get(FLD_CM1_GRUPPO)); - const int conto = atoi(m.get(FLD_CM1_CONTO)); - const long sottoc = atol(m.get(FLD_CM1_SOTTOCONTO)); - TLocalisamfile& pconti = app().get_relation()->lfile(); - - if (gruppo != 0 && conto != 0 && sottoc != 0) - { - pconti.zero() ; - pconti.put(PCN_GRUPPO, gruppo) ; - pconti.put(PCN_CONTO, conto) ; - pconti.setkey(1) ; - pconti.read(); - if (pconti.bad()) - return m.field(FLD_CM1_CONTO).warning_box ("Il conto non esiste"); - else - { - if (pconti.get(PCN_TMCF).not_empty()) - return m.field(FLD_CM1_SOTTOCONTO).warning_box ("Non e' possibile inserire un sottoconto di un conto relativo ad un cliente/fornitore"); - } - } - } - return TRUE; -} - -HIDDEN bool sottoc_handler(TMask_field& f, KEY key) -{ - if (key == K_TAB) - { - const int gruppo = f.mask().get_int(FLD_CM1_GRUPPO); - if (gruppo == 0) return TRUE; - const int conto = f.mask().get_int(FLD_CM1_CONTO); - const long sottoconto = f.mask().get_long(FLD_CM1_SOTTOCONTO); - if (sottoconto != 0 && conto == 0) - return f.mask().field(FLD_CM1_CONTO).error_box("Manca il conto"); - return f.mask().stop_run(K_AUTO_ENTER); - } - return TRUE; -} - -bool CG0100_application::user_create() -{ - _msk = new TMask("cg0100a") ; - _msk->set_handler(FLD_CM1_GRUPPO, gruppo_handler); - _msk->set_handler(FLD_CM1_CONTO, conto_handler); - _msk->set_handler(FLD_CM1_SOTTOCONTO, sottoc_handler); - _msk->set_handler(FLD_CM1_TMCF, tmcf_handler); - - _rel = new TRelation(LF_PCON); - _saldi = new TLocalisamfile(LF_SALDI); - _saldi->setkey(2); - set_search_field(FLD_CM1_GRUPPO); - return TRUE; - -} - -bool CG0100_application::user_destroy() -{ - delete _msk; - delete _rel; - delete _saldi; - return TRUE; -} - -int cg0100(int argc, char* argv[]) -{ - CG0100_application a ; - a.run(argc, argv, "Piano dei conti"); - return 0; -} +#include +#include + +#include "cg0.h" +#include "cg0100.h" + +#define ATTIVITA 1 +#define PASSIVITA 2 +#define COSTI 3 +#define RICAVI 4 +#define ORDINE 5 + +class CG0100_application : public TRelation_application +{ + TMask* _msk; + TRelation *_rel; + TLocalisamfile* _saldi; + TLocalisamfile* _tabcom; + + bool user_create(); + bool user_destroy(); + virtual TMask* get_mask(int mode) {return _msk;} + virtual bool changing_mask(int mode) {return FALSE;} + virtual bool protected_record(TRectype &rec); + virtual void init_query_mode(TMask& m); + virtual void init_insert_mode(TMask& m); + virtual void init_modify_mode(TMask& m) {init_insert_mode(m);} + virtual int write(const TMask& m); + virtual int rewrite(const TMask & m); + virtual int read(TMask& m); + +public: + virtual TRelation* get_relation() const {return _rel;} + CG0100_application() {} +}; +HIDDEN inline CG0100_application & app() { return (CG0100_application &) main_app();} + + +int CG0100_application::read(TMask& m) + +{ + const TRelation *r = get_relation(); + m.autoload(r); + if (m.get(FLD_CM1_LETTIVD).empty()) + { + int sezivd = m.get_int(FLD_CM1_SEZIVD); + if (sezivd == 1 || sezivd == 2) + m.set(FLD_CM1_SEZIVD, sezivd + 5); + } + if (m.get(FLD_CM1_LETTIVDOPP).empty()) + { + int sezivd = m.get_int(FLD_CM1_SEZIVDOPP); + if (sezivd == 1 || sezivd == 2) + m.set(FLD_CM1_SEZIVDOPP, sezivd + 5); + } + return NOERR; +} + +int CG0100_application::rewrite(const TMask& m) + +{ + TRelation *r = get_relation(); + + m.autosave(r); + int sezivd = m.get_int(FLD_CM1_SEZIVD); + TString16 sez; + + if (sezivd == 6 || sezivd == 7) + { + sez.format("%d", sezivd - 5); + r->lfile().put(PCN_SEZIVD, sez); + } + sezivd = m.get_int(FLD_CM1_SEZIVDOPP); + if (sezivd == 6 || sezivd == 7) + { + sez.format("%d", sezivd - 5); + r->lfile().put(PCN_SEZIVDOPP, sez); + } + return r->rewrite(); +} + +int CG0100_application::write(const TMask& m) + +{ + TRelation *r = get_relation(); + TString16 sez; + + m.autosave(r); + int sezivd = m.get_int(FLD_CM1_SEZIVD); + + if (sezivd == 6 || sezivd == 7) + { + sez.format("%d", sezivd - 5); + r->lfile().put(PCN_SEZIVD, sez); + } + sezivd = m.get_int(FLD_CM1_SEZIVDOPP); + if (sezivd == 6 || sezivd == 7) + { + sez.format("%d", sezivd - 5); + r->lfile().put(PCN_SEZIVDOPP, sez); + } + return r->write(); +} + +// Controlla se puo' essere effettuata la cancellazione di un conto + +bool CG0100_application::protected_record(TRectype &rec) +{ + TMask* m = get_mask(MODE_MOD); + TLocalisamfile& pconti = _rel->lfile(); + const int gruppo = atoi(m->get(FLD_CM1_GRUPPO)); + const int conto = atoi(m->get(FLD_CM1_CONTO)); + const long sottoc = atol(m->get(FLD_CM1_SOTTOCONTO)); + + // Se e' un sottoconto posso cancellarlo se non esistono saldi + if ((gruppo != 0) && (conto != 0) && (sottoc != 0)) + { + _saldi->zero(); + _saldi->put(PCN_GRUPPO, gruppo); + _saldi->put(PCN_CONTO, conto); + _saldi->put(PCN_SOTTOCONTO, sottoc); + _saldi->read(_isgteq); + + return _saldi->good() && gruppo ==_saldi->get_int(PCN_GRUPPO) && + conto ==_saldi->get_int(PCN_CONTO) && + sottoc ==_saldi->get_long(PCN_SOTTOCONTO); + } + get_relation()->save_status(); + pconti.zero() ; + pconti.put(PCN_GRUPPO, gruppo); + // Se e' un conto controllo se ha dei sottoconti + if (conto != 0) + pconti.put(PCN_CONTO, conto); + TRectype rec1(pconti.curr()); + + pconti.setkey(1) ; + pconti.read(); + pconti.next(); + const bool prot = (pconti.good() && (pconti.curr() == rec1)); + get_relation()->restore_status(); + return prot; +} + +void CG0100_application::init_query_mode(TMask& m) + +{ + m.show(-1); //m.send_key(K_SHIFT + K_CTRL + 's', -1); + m.show(-2); //m.send_key(K_SHIFT + K_CTRL + 's', -2); + m.show(-3); //m.send_key(K_SHIFT + K_CTRL + 's', -3); +} + +HIDDEN bool tmcf_handler(TMask_field& f, KEY key) + +{ + if (f.active() && key == K_SPACE) + { + TMask& m = f.mask(); + const int conto = atoi(m.get(FLD_CM1_CONTO)); + const long sottoc = atol(m.get(FLD_CM1_SOTTOCONTO)); + const bool enable_sezsaldi = (sottoc != 0) || (sottoc == 0 && conto != 0 && m.get(FLD_CM1_TMCF).not_empty()); + + m.show(FLD_CM2_SEZSALDI, enable_sezsaldi); + } + return TRUE; +} + + +void CG0100_application::init_insert_mode(TMask& m) + +{ + const int gruppo = atoi(m.get(FLD_CM1_GRUPPO)); + const int conto = atoi(m.get(FLD_CM1_CONTO)); + const long sottoc = atol(m.get(FLD_CM1_SOTTOCONTO)); + bool ivd_enable = TRUE; + + if (conto == 0 && sottoc == 0) + m.show(-1, FALSE); // send_key(K_SHIFT + K_CTRL + 'h', -1); + else + if (sottoc == 0) + m.show(-2, FALSE); //m.send_key(K_SHIFT + K_CTRL + 'h', -2); + else + m.show(-3, FALSE); //m.send_key(K_SHIFT + K_CTRL + 'h', -3); + + TLocalisamfile& pconti = _rel->lfile(); + TString s(15), s2(1), s3(8), s4(2); + int s1 = 0; + + pconti.setkey(1) ; + + int indbil = 0; + + if (sottoc != 0) + { + pconti.zero(); + pconti.put(PCN_GRUPPO, gruppo); + pconti.put(PCN_CONTO, conto); + pconti.read(); + if (pconti.good()) + { + s = pconti.get(PCN_CODCBL); + s1 = atoi(pconti.get(PCN_SEZIVD)); + s2 = pconti.get(PCN_LETTIVD); + s3 = pconti.get(PCN_NUMRIVD); + s4 = pconti.get(PCN_NUMIVD); + indbil = pconti.get_int(PCN_INDBIL); + } + ivd_enable = (s1 == 0) && s2.empty() && s3.empty() && s4.empty(); + } + m.show(FLD_CM1_RICSER, indbil == PASSIVITA || indbil == RICAVI); + if (conto != 0) + { + m.enable(FLD_CM1_SEZIVD, ivd_enable); + m.show(FLD_CM1_LETTIVD, ivd_enable); + m.show(FLD_CM1_NUMRIVD, ivd_enable); + m.show(FLD_CM1_NUMIVD, ivd_enable); + m.show(FLD_CM1_LETTIVDH, !ivd_enable); + m.show(FLD_CM1_NUMRIVDH, !ivd_enable); + m.show(FLD_CM1_NUMIVDH, !ivd_enable); + if (!ivd_enable) + { + m.set(FLD_CM1_SEZIVD, s1); + m.set(FLD_CM1_LETTIVDH, s2); + m.set(FLD_CM1_NUMRIVDH, s3); + m.set(FLD_CM1_NUMIVDH, s4); + m.enable(FLD_CM1_SEZIVDOPP); + } + pconti.zero(); + pconti.put(PCN_GRUPPO, gruppo); + pconti.read(); + if (pconti.good()) + if (s.empty()) s = pconti.get(PCN_CODCBL); + } + if (s.not_empty()) + { + m.set(FLD_CM1_CODANALISIH, s); + m.show(FLD_CM1_CODANALISIH); + m.hide(FLD_CM1_CODTABANALISI); + } + else + { + m.show(FLD_CM1_CODTABANALISI); + m.hide(FLD_CM1_CODANALISIH); + } + const bool enable_sezsaldi = (sottoc != 0) || (sottoc == 0 && conto != 0 && m.get(FLD_CM1_TMCF).not_empty()); + m.show(FLD_CM2_SEZSALDI, enable_sezsaldi); +} + + +HIDDEN bool gruppo_handler(TMask_field& f, KEY key) +{ + if (key == K_ENTER) + { + const TMask& m = f.mask(); + const int gruppo = atoi(m.get(FLD_CM1_GRUPPO)); + const int conto = atoi(m.get(FLD_CM1_CONTO)); + TLocalisamfile& pconti = app().get_relation()->lfile(); + if (gruppo != 0 && conto != 0) + { + pconti.zero() ; + pconti.put(PCN_GRUPPO, gruppo) ; + pconti.setkey(1) ; + pconti.read(); + if (pconti.bad()) + return f.warning_box ("Il gruppo non esiste"); + } + } + return TRUE; +} + +HIDDEN bool conto_handler(TMask_field& f, KEY key) +{ + if (key == K_ENTER) + { + const TMask& m = f.mask(); + const int gruppo = atoi(m.get(FLD_CM1_GRUPPO)); + const int conto = atoi(m.get(FLD_CM1_CONTO)); + const long sottoc = atol(m.get(FLD_CM1_SOTTOCONTO)); + TLocalisamfile& pconti = app().get_relation()->lfile(); + + if (gruppo != 0 && conto != 0 && sottoc != 0) + { + pconti.zero() ; + pconti.put(PCN_GRUPPO, gruppo) ; + pconti.put(PCN_CONTO, conto) ; + pconti.setkey(1) ; + pconti.read(); + if (pconti.bad()) + return m.field(FLD_CM1_CONTO).warning_box ("Il conto non esiste"); + else + { + if (pconti.get(PCN_TMCF).not_empty()) + return m.field(FLD_CM1_SOTTOCONTO).warning_box ("Non e' possibile inserire un sottoconto di un conto relativo ad un cliente/fornitore"); + } + } + } + return TRUE; +} + +HIDDEN bool sottoc_handler(TMask_field& f, KEY key) +{ + if (key == K_TAB) + { + const int gruppo = f.mask().get_int(FLD_CM1_GRUPPO); + if (gruppo == 0) return TRUE; + const int conto = f.mask().get_int(FLD_CM1_CONTO); + const long sottoconto = f.mask().get_long(FLD_CM1_SOTTOCONTO); + if (sottoconto != 0 && conto == 0) + return f.mask().field(FLD_CM1_CONTO).error_box("Manca il conto"); + return f.mask().stop_run(K_AUTO_ENTER); + } + return TRUE; +} + +bool CG0100_application::user_create() +{ + _msk = new TMask("cg0100a") ; + _msk->set_handler(FLD_CM1_GRUPPO, gruppo_handler); + _msk->set_handler(FLD_CM1_CONTO, conto_handler); + _msk->set_handler(FLD_CM1_SOTTOCONTO, sottoc_handler); + _msk->set_handler(FLD_CM1_TMCF, tmcf_handler); + + _rel = new TRelation(LF_PCON); + _saldi = new TLocalisamfile(LF_SALDI); + _saldi->setkey(2); + set_search_field(FLD_CM1_GRUPPO); + return TRUE; + +} + +bool CG0100_application::user_destroy() +{ + delete _msk; + delete _rel; + delete _saldi; + return TRUE; +} + +int cg0100(int argc, char* argv[]) +{ + CG0100_application a ; + a.run(argc, argv, "Piano dei conti"); + return 0; +} diff --git a/cg/cg0100a.uml b/cg/cg0100a.uml index d8a50ee5c..28bc98699 100755 --- a/cg/cg0100a.uml +++ b/cg/cg0100a.uml @@ -1,354 +1,354 @@ -#include "cg0100.h" - -TOOLBAR "" 0 20 0 2 - -#include - -ENDPAGE - -PAGE "Piano dei conti " 0 -1 0 19 - -GROUPBOX DLG_NULL 76 5 -BEGIN - PROMPT 1 0 "" - FLAGS "R" -END - -NUMBER FLD_CM1_GRUPPO 3 -BEGIN - PROMPT 2 1 "Gruppo " - HELP "Codice del gruppo" - FIELD LF_PCON->GRUPPO - FLAGS "R" - KEY 1 - USE LF_PCON KEY 1 SELECT CONTO="" - INPUT GRUPPO FLD_CM1_GRUPPO - DISPLAY "Gruppo" GRUPPO - DISPLAY "Descrizione@50" DESCR - OUTPUT FLD_CM1_GRUPPO GRUPPO - OUTPUT FLD_CM1_DESCG DESCR - CHECKTYPE NORMAL -END - -STRING FLD_CM1_DESCG 50 -BEGIN - PROMPT 23 1 "" - FLAGS "D" -END - -NUMBER FLD_CM1_CONTO 3 -BEGIN - PROMPT 2 2 "Conto " - HELP "Codice dell'eventuale conto" - FIELD LF_PCON->CONTO - FLAGS "R" - KEY 1 - USE LF_PCON KEY 1 SELECT ((CONTO!="") && (SOTTOCONTO="")) - COPY INPUT FLD_CM1_GRUPPO - INPUT CONTO FLD_CM1_CONTO - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Descrizione@50" DESCR - OUTPUT FLD_CM1_GRUPPO GRUPPO - OUTPUT FLD_CM1_CONTO CONTO - OUTPUT FLD_CM1_DESCC DESCR - CHECKTYPE NORMAL -END - -STRING FLD_CM1_DESCC 50 -BEGIN - PROMPT 23 2 "" - FLAGS "D" -END - -NUMBER FLD_CM1_SOTTOCONTO 6 -BEGIN - PROMPT 2 3 "Sottoconto " - HELP "Codice dell'eventuale sottoconto" - FIELD LF_PCON->SOTTOCONTO - FLAGS "R" - KEY 1 - USE LF_PCON KEY 1 SELECT SOTTOCONTO!="" - COPY INPUT FLD_CM1_CONTO - INPUT SOTTOCONTO FLD_CM1_SOTTOCONTO - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Sottoconto" SOTTOCONTO - DISPLAY "Sospeso" SOSPESO - DISPLAY "Descrizione@70" DESCR - OUTPUT FLD_CM1_SOTTOCONTO SOTTOCONTO - OUTPUT FLD_CM1_GRUPPO GRUPPO - OUTPUT FLD_CM1_CONTO CONTO - OUTPUT FLD_CM1_DESC DESCR -END - -STRING FLD_CM1_DESC 50 -BEGIN - PROMPT 23 3 "" - FIELD LF_PCON->DESCR - KEY 2 - USE LF_PCON KEY 2 - INPUT DESCR FLD_CM1_DESC - DISPLAY "Descrizione@50" DESCR - DISPLAY "Sospeso" SOSPESO - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Sottoconto " SOTTOCONTO - COPY OUTPUT FLD_CM1_SOTTOCONTO - CHECKTYPE REQUIRED - HELP "Descrizione del gruppo o del conto o del sottoconto" - WARNING "Manca la descrizione" -END - -NUMBER FLD_CM1_CODTABANALISI 10 -BEGIN - PROMPT 1 5 "Codice Tabella Analisi " - HELP "Codice di raggruppamento per l'analisi di bilancio" - FIELD LF_PCON->CODCBL - FLAGS "R" -END - -NUMBER FLD_CM1_CODANALISIH 10 -BEGIN - PROMPT 1 5 "Codice Tabella Analisi " - FLAGS "RHD" -END - -LIST FLD_CM1_INDBIL 1 22 -BEGIN - PROMPT 1 6 "Sezione di bilancio " - FIELD LF_PCON->INDBIL - GROUP 1 3 - HELP "Sezione di appartenenza del conto" - ITEM "1|1. Attivita'" - ITEM "2|2. Passivita'" - ITEM "3|3. Costi" - ITEM "4|4. Ricavi" - ITEM "5|5. Conti d'ordine" -END - -LIST FLD_CM1_SEZIVD 1 22 -BEGIN - PROMPT 1 7 "Sez. e classe IV dir. " - FIELD LF_PCON->SEZIVD - GROUP 1 4 - ITEM "0|0. Nessuna" MESSAGE CLEAR,5@|CLEAR,6@ - ITEM "1|1. Attivita'" MESSAGE ENABLE,5@|ENABLE,6@ - ITEM "2|2. Passivita'" MESSAGE ENABLE,5@|ENABLE,6@ - ITEM "5|5. Conto d'ordine" MESSAGE CLEAR,5@|ENABLE,6@ - ITEM "6|6. C.ordine attivo" MESSAGE CLEAR,5@|ENABLE,6@ - ITEM "7|7. C.ordine passivo" MESSAGE CLEAR,5@|ENABLE,6@ - ITEM "9|9. Conto economico" MESSAGE ENABLE,5@|ENABLE,6@ - HELP "Codice del conto secondo la IV direttiva CEE" -END - -STRING FLD_CM1_LETTIVD 1 1 -BEGIN - PROMPT 56 7 "" - HELP "Codice del conto secondo la IV direttiva CEE" - FIELD LF_PCON->LETTIVD - GROUP 1 5 - FLAGS "U" -END - -STRING FLD_CM1_LETTIVDH 1 -BEGIN - PROMPT 56 7 "" - FLAGS "HDU" - GROUP 5 -END - -NUMBER FLD_CM1_NUMRIVD 8 4 -BEGIN - PROMPT 60 7 "" - HELP "Codice del conto secondo la IV direttiva CEE" - FIELD LF_PCON->NUMRIVD - GROUP 1 5 - FLAGS "MZ" -END - -NUMBER FLD_CM1_NUMRIVDH 8 4 -BEGIN - PROMPT 60 7 "" - FLAGS "HDMZ" - GROUP 5 -END - -NUMBER FLD_CM1_NUMIVD 2 -BEGIN - PROMPT 71 7 "" - HELP "Codice del conto secondo la IV direttiva CEE" - FIELD LF_PCON->NUMIVD - FLAGS "RZ" - GROUP 1 5 - USE %IVD - INPUT CODTAB[1,1] FLD_CM1_SEZIVD - INPUT CODTAB[2,2] FLD_CM1_LETTIVD - INPUT CODTAB[3,6] FLD_CM1_NUMRIVD - INPUT CODTAB[7,8] FLD_CM1_NUMIVD - DISPLAY "Sezione" CODTAB[1,1] - DISPLAY "Lettera" CODTAB[2,2] - DISPLAY "Classe @M" CODTAB[3,6] - DISPLAY "Numero" CODTAB[7,8] - DISPLAY "Descrizione@70" S0 - OUTPUT FLD_CM1_SEZIVD CODTAB[1,1] - OUTPUT FLD_CM1_LETTIVD CODTAB[2,2] - OUTPUT FLD_CM1_NUMRIVD CODTAB[3,6] - OUTPUT FLD_CM1_NUMIVD CODTAB[7,8] - CHECKTYPE NORMAL - WARNING "Codice non presente" -END - -NUMBER FLD_CM1_NUMIVDH 2 -BEGIN - PROMPT 71 7 "" - FLAGS "HDRZ" - GROUP 1 5 -END - -LIST FLD_CM1_SEZIVDOPP 1 22 -BEGIN - PROMPT 1 8 "Classe segno opposto " - FIELD LF_PCON->SEZIVDOPP - GROUP 1 2 4 6 - ITEM "0|0. Nessuna" MESSAGE CLEAR,7@ - ITEM "1|1. Attivita'" MESSAGE ENABLE,7@ - ITEM "2|2. Passivita'" MESSAGE ENABLE,7@ - ITEM "5|5. Conto d'ordine" MESSAGE CLEAR,7@ - ITEM "6|6. C.ordine attivo" MESSAGE CLEAR,7@ - ITEM "7|7. C.ordine passivo" MESSAGE CLEAR,7@ - ITEM "9|9. Conto economico" MESSAGE ENABLE,7@ - HELP "Codice del conto di sezione opposta secondo la IV direttiva CEE" -END - -STRING FLD_CM1_LETTIVDOPP 1 -BEGIN - PROMPT 56 8 "" - HELP "Codice del conto di sezione opposta secondo la IV direttiva CEE" - FIELD LF_PCON->LETTIVDOPP - FLAGS "U" - GROUP 1 2 4 7 -END - -NUMBER FLD_CM1_NUMRIVDOPP 8 4 -BEGIN - PROMPT 60 8 "" - HELP "Codice del conto di sezione opposta secondo la IV direttiva CEE" - FIELD LF_PCON->NUMRIVDOPP - FLAGS "MZ" - GROUP 1 2 4 7 -END - -NUMBER FLD_CM1_NUMIVDOPP 2 -BEGIN - PROMPT 71 8 "" - HELP "Codice del conto di sezione opposta secondo la IV direttiva CEE" - FIELD LF_PCON->NUMIVDOPP - FLAGS "RZ" - GROUP 1 2 4 7 - COPY USE FLD_CM1_NUMIVD - INPUT CODTAB[1,1] FLD_CM1_SEZIVDOPP - INPUT CODTAB[2,2] FLD_CM1_LETTIVDOPP - INPUT CODTAB[3,6] FLD_CM1_NUMRIVDOPP - INPUT CODTAB[7,8] FLD_CM1_NUMIVDOPP - COPY DISPLAY FLD_CM1_NUMIVD - OUTPUT FLD_CM1_SEZIVDOPP CODTAB[1,1] - OUTPUT FLD_CM1_LETTIVDOPP CODTAB[2,2] - OUTPUT FLD_CM1_NUMRIVDOPP CODTAB[3,6] - OUTPUT FLD_CM1_NUMIVDOPP CODTAB[7,8] - CHECKTYPE NORMAL - WARNING "Codice non presente" -END - -LIST FLD_CM1_TIPOSPRIC 1 50 -BEGIN - PROMPT 1 9 "Tipo Spesa/Ricavo " - FIELD LF_PCON->TIPOSPRIC - GROUP 1 2 - HELP "Specificare il tipo do conto" - ITEM "0|0. Acquisti o vendite in genere" - ITEM "1|1. Acquisti beni per rivendita" - ITEM "2|2. Acquisti beni ammortizzabili" - ITEM "3|3. Acquisti beni ammortizzabili con detr. 6%" - ITEM "4|4. Vendita beni strumentali art. 17" - ITEM "5|5. Beni per rivendita da non ventilare" - ITEM "8|8. Altri beni strumentali acquistati in leasing" - ITEM "9|9. Spese Generali" -END - -LIST FLD_CM1_RICSER 1 18 -BEGIN - PROMPT 1 10 "Ricavi per servizi " - FIELD RICSER - FLAGS "H" - ITEM "0|Altre attivita'" - ITEM "1|Servizi" -END - -LIST FLD_CM1_TMCF 1 13 -BEGIN - PROMPT 1 11 "Tipo sottoconti " - FIELD LF_PCON->TMCF - GROUP 1 3 - HELP "Tipo dei sottoconti (Normale o clienti/fornitori)" - ITEM " |Normali" - ITEM "C|Clienti" - ITEM "F|Fornitori" -END - -LIST FLD_CM2_SEZSALDI 1 10 -BEGIN - PROMPT 1 12 "Controllo saldo primanota " - HELP "Tipo di controllo del saldo in prima nota" - FIELD LF_PCON->SEZSALDI - GROUP 1 - ITEM " |Nessuno" - ITEM "A|Avere" - ITEM "D|Dare" -END - -BOOLEAN FLD_CM2_STSOTTBIL -BEGIN - PROMPT 1 14 "Stampa dettaglio sottoconti su bilanci " - HELP "Indicare se stampare il dettaglio dei sottoconti nei bilanci di verifica" - FIELD LF_PCON->STSOTTBIL - GROUP 1 3 -END - -BOOLEAN FLD_CM2_COMPENS -BEGIN - PROMPT 50 14 "Compensazione saldi " - HELP "Indicare se e' ammessa la compensazione dei saldi" - FIELD LF_PCON->COMPENS - GROUP 1 3 -END - -BOOLEAN FLD_CM2_STSOTTAB -BEGIN - PROMPT 1 15 "Stampa dettaglio sottoconti su analisi " - HELP "Indicare se stampare il dettaglio dei sottoconti nell'analisi di bilancio" - FIELD LF_PCON->STSOTTAB - GROUP 1 3 - MESSAGE COPY,FLD_CM2_STSOTTABS -END - -BOOLEAN FLD_CM2_STSOTTABS -BEGIN - PROMPT 1 15 "Stampa dettaglio movimenti su analisi " - FIELD LF_PCON->STSOTTAB - FLAGS "H" - GROUP 1 2 - MESSAGE COPY,FLD_CM2_STSOTTAB -END - -BOOLEAN FLD_CM2_SOSPESO -BEGIN - PROMPT 50 15 "Conto sospeso" - HELP "Indicare se sospendere il conto in prima nota" - FIELD LF_PCON->SOSPESO - GROUP 1 2 -END - -ENDPAGE - -ENDMASK +#include "cg0100.h" + +TOOLBAR "" 0 20 0 2 + +#include + +ENDPAGE + +PAGE "Piano dei conti " 0 -1 0 19 + +GROUPBOX DLG_NULL 76 5 +BEGIN + PROMPT 1 0 "" + FLAGS "R" +END + +NUMBER FLD_CM1_GRUPPO 3 +BEGIN + PROMPT 2 1 "Gruppo " + HELP "Codice del gruppo" + FIELD LF_PCON->GRUPPO + FLAGS "R" + KEY 1 + USE LF_PCON KEY 1 SELECT CONTO="" + INPUT GRUPPO FLD_CM1_GRUPPO + DISPLAY "Gruppo" GRUPPO + DISPLAY "Descrizione@50" DESCR + OUTPUT FLD_CM1_GRUPPO GRUPPO + OUTPUT FLD_CM1_DESCG DESCR + CHECKTYPE NORMAL +END + +STRING FLD_CM1_DESCG 50 +BEGIN + PROMPT 23 1 "" + FLAGS "D" +END + +NUMBER FLD_CM1_CONTO 3 +BEGIN + PROMPT 2 2 "Conto " + HELP "Codice dell'eventuale conto" + FIELD LF_PCON->CONTO + FLAGS "R" + KEY 1 + USE LF_PCON KEY 1 SELECT ((CONTO!="") && (SOTTOCONTO="")) + COPY INPUT FLD_CM1_GRUPPO + INPUT CONTO FLD_CM1_CONTO + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Descrizione@50" DESCR + OUTPUT FLD_CM1_GRUPPO GRUPPO + OUTPUT FLD_CM1_CONTO CONTO + OUTPUT FLD_CM1_DESCC DESCR + CHECKTYPE NORMAL +END + +STRING FLD_CM1_DESCC 50 +BEGIN + PROMPT 23 2 "" + FLAGS "D" +END + +NUMBER FLD_CM1_SOTTOCONTO 6 +BEGIN + PROMPT 2 3 "Sottoconto " + HELP "Codice dell'eventuale sottoconto" + FIELD LF_PCON->SOTTOCONTO + FLAGS "R" + KEY 1 + USE LF_PCON KEY 1 SELECT SOTTOCONTO!="" + COPY INPUT FLD_CM1_CONTO + INPUT SOTTOCONTO FLD_CM1_SOTTOCONTO + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Sottoconto" SOTTOCONTO + DISPLAY "Sospeso" SOSPESO + DISPLAY "Descrizione@70" DESCR + OUTPUT FLD_CM1_SOTTOCONTO SOTTOCONTO + OUTPUT FLD_CM1_GRUPPO GRUPPO + OUTPUT FLD_CM1_CONTO CONTO + OUTPUT FLD_CM1_DESC DESCR +END + +STRING FLD_CM1_DESC 50 +BEGIN + PROMPT 23 3 "" + FIELD LF_PCON->DESCR + KEY 2 + USE LF_PCON KEY 2 + INPUT DESCR FLD_CM1_DESC + DISPLAY "Descrizione@50" DESCR + DISPLAY "Sospeso" SOSPESO + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Sottoconto " SOTTOCONTO + COPY OUTPUT FLD_CM1_SOTTOCONTO + CHECKTYPE REQUIRED + HELP "Descrizione del gruppo o del conto o del sottoconto" + WARNING "Manca la descrizione" +END + +NUMBER FLD_CM1_CODTABANALISI 10 +BEGIN + PROMPT 1 5 "Codice Tabella Analisi " + HELP "Codice di raggruppamento per l'analisi di bilancio" + FIELD LF_PCON->CODCBL + FLAGS "R" +END + +NUMBER FLD_CM1_CODANALISIH 10 +BEGIN + PROMPT 1 5 "Codice Tabella Analisi " + FLAGS "RHD" +END + +LIST FLD_CM1_INDBIL 1 22 +BEGIN + PROMPT 1 6 "Sezione di bilancio " + FIELD LF_PCON->INDBIL + GROUP 1 3 + HELP "Sezione di appartenenza del conto" + ITEM "1|1. Attivita'" + ITEM "2|2. Passivita'" + ITEM "3|3. Costi" + ITEM "4|4. Ricavi" + ITEM "5|5. Conti d'ordine" +END + +LIST FLD_CM1_SEZIVD 1 22 +BEGIN + PROMPT 1 7 "Sez. e classe IV dir. " + FIELD LF_PCON->SEZIVD + ITEM "0|0. Nessuna" MESSAGE CLEAR,5@|CLEAR,6@ + ITEM "1|1. Attivita'" MESSAGE ENABLE,5@|ENABLE,6@ + ITEM "2|2. Passivita'" MESSAGE ENABLE,5@|ENABLE,6@ + ITEM "5|5. Conto d'ordine" MESSAGE CLEAR,5@|ENABLE,6@ + ITEM "6|6. C.ordine attivo" MESSAGE CLEAR,5@|ENABLE,6@ + ITEM "7|7. C.ordine passivo" MESSAGE CLEAR,5@|ENABLE,6@ + ITEM "9|9. Conto economico" MESSAGE ENABLE,5@|ENABLE,6@ + HELP "Codice del conto secondo la IV direttiva CEE" + GROUP 1 4 +END + +STRING FLD_CM1_LETTIVD 1 1 +BEGIN + PROMPT 56 7 "" + HELP "Codice del conto secondo la IV direttiva CEE" + FIELD LF_PCON->LETTIVD + GROUP 1 5 + FLAGS "U" +END + +STRING FLD_CM1_LETTIVDH 1 +BEGIN + PROMPT 56 7 "" + FLAGS "HDU" + GROUP 1 5 +END + +NUMBER FLD_CM1_NUMRIVD 8 4 +BEGIN + PROMPT 60 7 "" + HELP "Codice del conto secondo la IV direttiva CEE" + FIELD LF_PCON->NUMRIVD + GROUP 1 5 + FLAGS "MZ" +END + +NUMBER FLD_CM1_NUMRIVDH 8 4 +BEGIN + PROMPT 60 7 "" + FLAGS "HDMZ" + GROUP 1 5 +END + +NUMBER FLD_CM1_NUMIVD 2 +BEGIN + PROMPT 71 7 "" + HELP "Codice del conto secondo la IV direttiva CEE" + FIELD LF_PCON->NUMIVD + FLAGS "RZ" + GROUP 1 5 + USE %IVD + INPUT CODTAB[1,1] FLD_CM1_SEZIVD + INPUT CODTAB[2,2] FLD_CM1_LETTIVD + INPUT CODTAB[3,6] FLD_CM1_NUMRIVD + INPUT CODTAB[7,8] FLD_CM1_NUMIVD + DISPLAY "Sezione" CODTAB[1,1] + DISPLAY "Lettera" CODTAB[2,2] + DISPLAY "Classe @M" CODTAB[3,6] + DISPLAY "Numero" CODTAB[7,8] + DISPLAY "Descrizione@70" S0 + OUTPUT FLD_CM1_SEZIVD CODTAB[1,1] + OUTPUT FLD_CM1_LETTIVD CODTAB[2,2] + OUTPUT FLD_CM1_NUMRIVD CODTAB[3,6] + OUTPUT FLD_CM1_NUMIVD CODTAB[7,8] + CHECKTYPE NORMAL + WARNING "Codice non presente" +END + +NUMBER FLD_CM1_NUMIVDH 2 +BEGIN + PROMPT 71 7 "" + FLAGS "HDRZ" + GROUP 1 5 +END + +LIST FLD_CM1_SEZIVDOPP 1 22 +BEGIN + PROMPT 1 8 "Classe segno opposto " + FIELD LF_PCON->SEZIVDOPP + GROUP 1 2 4 6 + ITEM "0|0. Nessuna" MESSAGE CLEAR,7@ + ITEM "1|1. Attivita'" MESSAGE ENABLE,7@ + ITEM "2|2. Passivita'" MESSAGE ENABLE,7@ + ITEM "5|5. Conto d'ordine" MESSAGE CLEAR,7@ + ITEM "6|6. C.ordine attivo" MESSAGE CLEAR,7@ + ITEM "7|7. C.ordine passivo" MESSAGE CLEAR,7@ + ITEM "9|9. Conto economico" MESSAGE ENABLE,7@ + HELP "Codice del conto di sezione opposta secondo la IV direttiva CEE" +END + +STRING FLD_CM1_LETTIVDOPP 1 +BEGIN + PROMPT 56 8 "" + HELP "Codice del conto di sezione opposta secondo la IV direttiva CEE" + FIELD LF_PCON->LETTIVDOPP + FLAGS "U" + GROUP 1 2 4 7 +END + +NUMBER FLD_CM1_NUMRIVDOPP 8 4 +BEGIN + PROMPT 60 8 "" + HELP "Codice del conto di sezione opposta secondo la IV direttiva CEE" + FIELD LF_PCON->NUMRIVDOPP + FLAGS "MZ" + GROUP 1 2 4 7 +END + +NUMBER FLD_CM1_NUMIVDOPP 2 +BEGIN + PROMPT 71 8 "" + HELP "Codice del conto di sezione opposta secondo la IV direttiva CEE" + FIELD LF_PCON->NUMIVDOPP + FLAGS "RZ" + GROUP 1 2 4 7 + COPY USE FLD_CM1_NUMIVD + INPUT CODTAB[1,1] FLD_CM1_SEZIVDOPP + INPUT CODTAB[2,2] FLD_CM1_LETTIVDOPP + INPUT CODTAB[3,6] FLD_CM1_NUMRIVDOPP + INPUT CODTAB[7,8] FLD_CM1_NUMIVDOPP + COPY DISPLAY FLD_CM1_NUMIVD + OUTPUT FLD_CM1_SEZIVDOPP CODTAB[1,1] + OUTPUT FLD_CM1_LETTIVDOPP CODTAB[2,2] + OUTPUT FLD_CM1_NUMRIVDOPP CODTAB[3,6] + OUTPUT FLD_CM1_NUMIVDOPP CODTAB[7,8] + CHECKTYPE NORMAL + WARNING "Codice non presente" +END + +LIST FLD_CM1_TIPOSPRIC 1 50 +BEGIN + PROMPT 1 9 "Tipo Spesa/Ricavo " + FIELD LF_PCON->TIPOSPRIC + GROUP 1 2 + HELP "Specificare il tipo do conto" + ITEM "0|0. Acquisti o vendite in genere" + ITEM "1|1. Acquisti beni per rivendita" + ITEM "2|2. Acquisti beni ammortizzabili" + ITEM "3|3. Acquisti beni ammortizzabili con detr. 6%" + ITEM "4|4. Vendita beni strumentali art. 17" + ITEM "5|5. Beni per rivendita da non ventilare" + ITEM "8|8. Altri beni strumentali acquistati in leasing" + ITEM "9|9. Spese Generali" +END + +LIST FLD_CM1_RICSER 1 18 +BEGIN + PROMPT 1 10 "Ricavi per servizi " + FIELD RICSER + FLAGS "H" + ITEM "0|Altre attivita'" + ITEM "1|Servizi" +END + +LIST FLD_CM1_TMCF 1 13 +BEGIN + PROMPT 1 11 "Tipo sottoconti " + FIELD LF_PCON->TMCF + GROUP 1 3 + HELP "Tipo dei sottoconti (Normale o clienti/fornitori)" + ITEM " |Normali" + ITEM "C|Clienti" + ITEM "F|Fornitori" +END + +LIST FLD_CM2_SEZSALDI 1 10 +BEGIN + PROMPT 1 12 "Controllo saldo primanota " + HELP "Tipo di controllo del saldo in prima nota" + FIELD LF_PCON->SEZSALDI + GROUP 1 + ITEM " |Nessuno" + ITEM "A|Avere" + ITEM "D|Dare" +END + +BOOLEAN FLD_CM2_STSOTTBIL +BEGIN + PROMPT 1 14 "Stampa dettaglio sottoconti su bilanci " + HELP "Indicare se stampare il dettaglio dei sottoconti nei bilanci di verifica" + FIELD LF_PCON->STSOTTBIL + GROUP 1 3 +END + +BOOLEAN FLD_CM2_COMPENS +BEGIN + PROMPT 50 14 "Compensazione saldi " + HELP "Indicare se e' ammessa la compensazione dei saldi" + FIELD LF_PCON->COMPENS + GROUP 1 3 +END + +BOOLEAN FLD_CM2_STSOTTAB +BEGIN + PROMPT 1 15 "Stampa dettaglio sottoconti su analisi " + HELP "Indicare se stampare il dettaglio dei sottoconti nell'analisi di bilancio" + FIELD LF_PCON->STSOTTAB + GROUP 1 3 + MESSAGE COPY,FLD_CM2_STSOTTABS +END + +BOOLEAN FLD_CM2_STSOTTABS +BEGIN + PROMPT 1 15 "Stampa dettaglio movimenti su analisi " + FIELD LF_PCON->STSOTTAB + FLAGS "H" + GROUP 1 2 + MESSAGE COPY,FLD_CM2_STSOTTAB +END + +BOOLEAN FLD_CM2_SOSPESO +BEGIN + PROMPT 50 15 "Conto sospeso" + HELP "Indicare se sospendere il conto in prima nota" + FIELD LF_PCON->SOSPESO + GROUP 1 2 +END + +ENDPAGE + +ENDMASK diff --git a/cg/cg1.url b/cg/cg1.url index b169aa746..510555ecd 100755 --- a/cg/cg1.url +++ b/cg/cg1.url @@ -1,43 +1,33 @@ -#include - - -MENU TASK_MENUBAR - SUBMENU MENU_FILE "~File" - - -MENUBAR MENU_BAR(1) - -MENU MENU_BAR(1) - SUBMENU MENU_FILE "~File" - - -MENUBAR MENU_BAR(2) - -MENU MENU_BAR(2) - SUBMENU MENU_FILE "~File" - -MENU BAR_ITEM(1) - ITEM MENU_ITEM(1) "~Header" - ITEM MENU_ITEM(2) "~Body" - ITEM MENU_ITEM(3) "~Footer" - -MENUBAR MENU_BAR(3) - -MENU MENU_BAR(3) - SUBMENU MENU_FILE "~File" - -MENUBAR MENU_BAR(4) - -MENU MENU_BAR(4) - SUBMENU MENU_FILE "~File" - -MENUBAR MENU_BAR(5) - -MENU MENU_BAR(5) - SUBMENU MENU_FILE "~File" - -MENUBAR MENU_BAR(6) - -MENU MENU_BAR(6) - SUBMENU MENU_FILE "~File" - +#include + + +MENU TASK_MENUBAR + SUBMENU MENU_FILE "~File" + + +MENUBAR MENU_BAR(1) + +MENU MENU_BAR(1) + SUBMENU MENU_FILE "~File" + + +MENUBAR MENU_BAR(3) + +MENU MENU_BAR(3) + SUBMENU MENU_FILE "~File" + +MENUBAR MENU_BAR(4) + +MENU MENU_BAR(4) + SUBMENU MENU_FILE "~File" + +MENUBAR MENU_BAR(5) + +MENU MENU_BAR(5) + SUBMENU MENU_FILE "~File" + +MENUBAR MENU_BAR(6) + +MENU MENU_BAR(6) + SUBMENU MENU_FILE "~File" + diff --git a/cg/cg1200.cpp b/cg/cg1200.cpp index 3af1fe950..a49efaf89 100755 --- a/cg/cg1200.cpp +++ b/cg/cg1200.cpp @@ -1,949 +1,949 @@ -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "cg1.h" -#include "cg1200a.h" -#include "cg1200b.h" -#include - -#define COMRF_ALIAS 50 -#define COMNASC_ALIAS 51 - -enum pt { undefined = 0, elenco = 1, rubriche = 2, etichette = 3, vendite = 4 }; -enum pw { clienti = 1, fornitori = 2, both = 3 }; - -bool mask2_reset_fields(TMask_field& mf, KEY k); - -extern char __tmp [MAXSTR]; -static TFixed_string tmp(__tmp, MAXSTR); - -class CG1200_App : public TPrintapp -{ - friend bool mask2_reset_fields(TMask_field& mf, KEY k); - - pt _pr_type; - pw _pr_what; - TRelation* _rel; - int _cur_1, _cur_2; - int _sort; - int _interline; - bool _mov_only; - TLocalisamfile* _mov; - TLocalisamfile* _comuni; - - // etichette - int _startrow, _rows_et, _cols_et, _startcol; - - // variable field slots - TString _piva,_cpercip,_fax,_telex,_name,_telefono,_indir,_localita; - TString _cod_from,_cod_to,_data_stampa,_cofi,_d_c_ric,_d_alleg; - TString _datanas; - long _codice; - char _tipocf,_tipoaper; - bool _gia_iniziati_fornitori; - -public: - - virtual bool preprocess_page(int file, int counter); - virtual bool preprocess_print(int file, int counter); - virtual print_action postprocess_print(int file, int counter); - virtual void preprocess_header(); - virtual bool user_create(); - virtual bool user_destroy(); - virtual bool set_print(int); - - int ccur() { return _sort == 1 ? _cur_1 : _cur_2; } - - const char* look_tab(const char* tabname, TString& cod, - const char* fld = "S0"); - const char* get_field(int ln, const char* fn) - { return current_cursor()->curr(ln).get(fn); } - - virtual void set_page (int file, int counter); - void set_elenco(); - void set_rubriche(); - void set_etichette(); - void set_vendite(int f, int c) ; - void process_link(int id, const char* txt); - void ultimo_codice(char tipo); - const char* compatta_ragsoc(TString& ragsoc,char tipoaper); - void header_elenco(); - void header_rubriche(); - const char* descrizione_conto_ric(int,int,long); - const char* descrizione_allegato(char,long); - - CG1200_App() : TPrintapp(),_piva(18), _cpercip(10), _fax(50), _telex(50), - _name(60), _telefono(90), _indir(70), _localita(90) - { - _rel = NULL; _pr_type = undefined; _startrow = 2; _startcol = 3; - _rows_et = 9; _cols_et = 40; - } - -}; - - - -/* -------------------------------------------------------------------- */ -/* ---------------------------- Code ---------------------------------- */ -/* -------------------------------------------------------------------- */ - - -void CG1200_App::process_link(int id, const char* txt) -{ - TString ss = "1|"; - ss << txt; - TMessage fs(cmd2name("cg0","-1"), MSG_LN, ss); - TMailbox m; - m.send(fs); - TExternal_app cg0("cg0 -1"); - if (cg0.run()) beep(); -} - -const char* CG1200_App::look_tab(const char* tabname, TString& cod, - const char* fld) -{ - TTable tab(tabname); - tab.curr().zero(); - tab.curr().put("CODTAB",cod); - tab.read(); - if (tab.bad()) tab.curr().zero(); - return tab.curr().get(fld); -} - -const char* CG1200_App::descrizione_conto_ric(int gruppo, int conto, long sottoc) -{ - TLocalisamfile pconti(LF_PCON, FALSE); - - pconti.setkey(1); - pconti.zero(); - pconti.put(PCN_GRUPPO, gruppo); - pconti.put(PCN_CONTO, conto); - pconti.put(PCN_SOTTOCONTO, sottoc); - pconti.read(); - if (pconti.bad()) - pconti.zero(); - tmp = pconti.get(PCN_DESCR); - - return (__tmp); -} - -const char* CG1200_App::descrizione_allegato(char tipocf,long cod) -{ - TLocalisamfile clifo(LF_CLIFO, FALSE); - - clifo.setkey(1); - clifo.zero(); - clifo.put(CLI_TIPOCF, tipocf); - clifo.put(CLI_CODCF , cod); - clifo.read(); - if (clifo.bad()) - clifo.zero(); - _tipoaper = clifo.get_char(CLI_TIPOAPER); - tmp = clifo.get(CLI_RAGSOC); - - return (__tmp); -} - -bool CG1200_App::preprocess_page(int file, int counter) -{ - TString s; - int g_ric,c_ric; - long s_ric,codall; - - switch (file) - { - case LF_CLIFO: - { - if (_mov_only) - { - const TString16 tipocf(get_field(LF_CLIFO,CLI_TIPOCF)); - const TString16 codice(get_field(LF_CLIFO,CLI_CODCF)); - - _mov->curr().zero(); - _mov->curr().put(MOV_TIPO, tipocf); - _mov->curr().put(MOV_CODCF, codice); - _mov->read(); - if (_mov->get(MOV_TIPO) != tipocf || - _mov->get(MOV_CODCF) != codice) - return FALSE; - } - - _tipocf = current_cursor()->curr(LF_CLIFO).get_char(CLI_TIPOCF); - - // set variable fields - _cofi = get_field(LF_CLIFO, CLI_COFI); - //_piva = get_field(LF_CLIFO, CLI_COFI); - //if (_piva.empty()) _piva = get_field(LF_CLIFO, CLI_PAIV); - _piva = get_field(LF_CLIFO, CLI_PAIV); - _telefono = get_field(LF_CLIFO, CLI_PTEL); - if (!_telefono.empty()) _telefono << "/"; - _telefono << get_field(LF_CLIFO, CLI_TEL) << " "; - s = get_field(LF_CLIFO, CLI_PTEL2); - if (!s.empty()) s << "/"; - _telefono << s << get_field(LF_CLIFO, CLI_TEL2) << " "; - s = get_field(LF_CLIFO, CLI_PTEL3); - if (!s.empty()) s << "/"; - _telefono << s << get_field(LF_CLIFO, CLI_TEL3); - _fax = get_field(LF_CLIFO, CLI_PFAX); - if (!_fax.empty()) _fax << "/"; - _fax << get_field(LF_CLIFO, CLI_FAX); - _telex = get_field(LF_CLIFO, CLI_PTELEX); - if (!_telex.empty()) _telex << "/"; - _telex << get_field(LF_CLIFO, CLI_TELEX); - _indir = get_field(LF_CLIFO, CLI_INDCF); - g_ric = atoi(get_field(LF_CLIFO, CLI_GRUPPORIC)); - c_ric = atoi(get_field(LF_CLIFO, CLI_CONTORIC)); - s_ric = atol(get_field(LF_CLIFO, CLI_SOTTOCRIC)); - codall = atol(get_field(LF_CLIFO, CLI_CODALLEG)); - _datanas = get_field(LF_CLIFO, CLI_DATANASC); - const TString16 tipoaper(get_field(LF_CLIFO, CLI_TIPOAPER)); - - _d_alleg = ""; - if (codall != 0) - { - _d_alleg = descrizione_allegato(_tipocf,codall); - if (_tipoaper == 'F') - { - TString surname = _d_alleg.mid(30,50); surname.trim(); - _d_alleg = _d_alleg.mid(0,30); _d_alleg.trim(); - _d_alleg << " " << surname; - } - } - - _d_c_ric = descrizione_conto_ric(g_ric,c_ric,s_ric); - - _d_c_ric = _d_c_ric.mid(0,31); - _d_alleg = _d_alleg.mid(0,26); - - if (!_indir.empty()) _indir << " "; - _indir << get_field(LF_CLIFO, CLI_CIVCF); - - _localita = get_field(LF_CLIFO, CLI_LOCCF); - if (!_localita.empty()) - _localita.trim(); - - _name = get_field(LF_CLIFO, CLI_RAGSOC); - s = get_field(LF_CLIFO, CLI_CODANAGPER); - _cpercip = ""; - - - if (s.not_empty()) _cpercip << tipoaper << " " << s; - - if (tipoaper == "F") - { - TString surname = _name.mid(30,50); surname.trim(); - _name = _name.mid(0,30); _name.trim(); - _name << " " << surname; - } - - switch(_pr_type) - { - case elenco: - case rubriche: - if (_pr_what == both) - if (_tipocf == 'F' && !_gia_iniziati_fornitori) - { - _gia_iniziati_fornitori = TRUE; - printer().formfeed(); - } - break; - default: - break; - } - } - break; - case LF_INDSP: - current_cursor()->items(); - if (atoi(get_field(LF_INDSP,IND_CODIND)) == 0) - return FALSE; - _telefono = get_field(LF_INDSP, IND_PTEL); - if (!_telefono.empty()) _telefono << "/"; - _telefono << get_field(LF_INDSP, IND_TEL); - _fax = get_field(LF_INDSP, IND_PFAX); - if (!_fax.empty()) _fax << "/"; - _fax << get_field(LF_INDSP, IND_FAX); - _localita = get_field(LF_INDSP,IND_LOCALITA); - if (!_localita.empty()) - _localita << " - "; - _comuni->curr().zero(); - _comuni->curr().put(COM_STATO,get_field(LF_INDSP,IND_STATO)); - _comuni->curr().put(COM_COM,get_field(LF_INDSP,IND_COM)); - _comuni->read(); - _localita << _comuni->curr().get(COM_DENCOM); - _localita << " "; - _localita << _comuni->curr().get(COM_PROVCOM); - break; -default: - break; -} - return TRUE; -} - -print_action CG1200_App::postprocess_print(int file, int counter) -{ - /* - static bool more = FALSE; - if (_pr_what == both) - { - if (more) - { - more = FALSE; - select_cursor(ccur()); - return NEXT_PAGE; - } - else - { - more = TRUE; - select_cursor(ccur()); - return REPEAT_PAGE; - } - } - */ - return NEXT_PAGE; -} - -bool gest_vend() -{ - TConfig c(CONFIG_DITTA,"cg"); - return (c.get("GesVen") == "X"); -} - -bool rdbtype_handler(TMask_field& f, KEY k) -{ - if (k == K_TAB) - //every time that change focus or value, check flag to enable button - { - if (gest_vend()) - f.mask().enable(BUT_CG12_VENDITE); - else - f.mask().disable(BUT_CG12_VENDITE); - } - return TRUE; -} - -bool mask_ctrl_handler(TMask_field& mf, KEY k) -{ - if (k == K_SPACE) - { - mf.mask().stop_run(mf.dlg()); - } - return TRUE; -} - -// set printrows - -void CG1200_App::set_page(int file, int counter) -{ - switch(_pr_type) - { - case elenco: - if (file == LF_CLIFO) - set_elenco(); - break; - case rubriche: - if (file == LF_CLIFO) - set_rubriche(); - break; - case etichette: - if (file == LF_CLIFO) - set_etichette(); - break; - case vendite: - set_vendite(file, counter); - default: - break; - } -} - -void CG1200_App::ultimo_codice(char tipocf) -{ - TLocalisamfile clifo(LF_CLIFO,FALSE); - - char tipopr = tipocf; - - clifo.setkey(1); - clifo.zero(); - clifo.put(CLI_TIPOCF,tipocf); - - for (clifo.read();!clifo.eof();clifo.next()) - { - char tipo = clifo.get_char(CLI_TIPOCF); - - if (tipo != tipopr) break; - - _codice = clifo.get_long(CLI_CODCF); - } -} - -const char* CG1200_App::compatta_ragsoc(TString& ragsoc,char tipoa) -{ - if (tipoa == 'F') - { - TString80 cognome, nome; - cognome = ragsoc.mid(0,30); - nome = ragsoc.mid(30,20); - cognome.trim(); nome.trim(); - - ragsoc = cognome; - ragsoc << " " << nome; - } - - tmp = ragsoc; - - return (__tmp); -} - -void CG1200_App::preprocess_header() -{ - switch(_pr_type) - { - case elenco: - header_elenco(); - break; - case rubriche: - header_rubriche(); - break; - default: - break; - } -} - -void CG1200_App::header_elenco() -{ - reset_header(); - // intestazione - const long firm = get_firm(); - TString var; - int j = 1; - char tipocf; - TLocalisamfile ditte(LF_NDITTE); - ditte.zero(); - ditte.put(NDT_CODDITTA, firm); - ditte.read(); - if (ditte.bad()) ditte.zero(); - TString s(ditte.get(NDT_RAGSOC)); - - set_header(j, "Ditta %ld %s@125gPag @#", firm, (const char*) s); - set_header(j++, "@102gData %s", (const char*) _data_stampa); - /* - if (_pr_what == both) - { - current_cursor()->save_status(); - ++(*current_cursor()); - tipocf = current_cursor()->curr(LF_CLIFO).get_char(CLI_TIPOCF); - --(*current_cursor()); - current_cursor()->restore_status(); - } - else - */ - tipocf = current_cursor()->curr(LF_CLIFO).get_char(CLI_TIPOCF); - - if (tipocf == 'C') - var = "Clienti"; - else - if (tipocf == 'F') - var = "Fornitori"; - - set_header(j, "Elenco %s",(const char*) var); - - if (_sort == 1) - var = "Ordine di codice"; - else - var = "Ordine alfabetico"; - - set_header(j, "@30g%s", (const char*) var); - - if (_mov_only) - set_header(j, "@55gSolo i movimentati"); - - ultimo_codice(_tipocf); - - set_header(j++, "@102gUltimo cod.utilizzato %ld" , _codice); - - if (_pr_what != both) - { - if (_cod_from.not_empty() || _cod_to.not_empty()) - { - set_header(j, "Estremi selezione"); - if (_cod_from.not_empty()) - set_header(j, " da %s", (const char*) _cod_from); - if (_cod_to.not_empty()) - if (_sort == 1) - set_header(j, " a %s", (const char*) _cod_to); - else - set_header(j, " a %s", (const char*) _cod_to); - j++; - } - } - - set_header(j++, (const char *)(TString(132).fill('-'))); - set_header(j++, " Codice Ragione sociale"); - set_header(j++, "@9gIndirizzo@56gC.A.P.@63gLocalita'"); - set_header(j++, "@9gTelefoni@90gFAX @115gTelex"); - set_header(j++, "@9gLuogo di nascita@45gData@56gPartita IVA Codice fiscale"); - set_header(j++, "@9gConto di costo/ricavo@56gCodice allegato@90gPercipiente 770"); - set_header(j, (const char *)(TString(132).fill('-'))); -} - -void CG1200_App::header_rubriche() -{ - reset_header(); - // intestazione - const long firm = get_firm(); - TString var; - int j = 1; - char tipocf; - TLocalisamfile ditte(LF_NDITTE); - ditte.zero(); - ditte.put(NDT_CODDITTA, firm); - ditte.read(); - if (ditte.bad()) ditte.zero(); - TString s(ditte.get(NDT_RAGSOC)); - set_header(j, "Ditta %ld %s@125gPag @#", firm, (const char*) s); - set_header(j++, "@102gData %s", (const char*) _data_stampa); - /* - if (_pr_what == both) - { - current_cursor()->save_status(); - ++(*current_cursor()); - tipocf = current_cursor()->curr(LF_CLIFO).get_char(CLI_TIPOCF); - --(*current_cursor()); - current_cursor()->restore_status(); - } - else - */ - tipocf = current_cursor()->curr(LF_CLIFO).get_char(CLI_TIPOCF); - - if (tipocf == 'C') - var = "Clienti"; - else - if (tipocf == 'F') - var = "Fornitori"; - - set_header(j, "Rubrica %s",(const char*) var); - - if (_sort == 1) - var = "Ordine di codice"; - else - var = "Ordine alfabetico"; - - set_header(j, "@30g%s", (const char*) var); - - if (_mov_only) - set_header(j, "@55gSolo i movimentati"); - - ultimo_codice(_tipocf); - - set_header(j++, "@102gUltimo cod.utilizzato %ld" , _codice); - - if (_pr_what != both) - { - if (_cod_from.not_empty() || _cod_to.not_empty()) - { - set_header(j, "Estremi selezione"); - if (_cod_from.not_empty()) - set_header(j, " da %s", (const char*) _cod_from); - if (_cod_to.not_empty()) - if (_sort == 1) - set_header(j, " a %s", (const char*) _cod_to); - else - set_header(j, " a %s", (const char*) _cod_to); - j++; - } - } - - set_header(j++, (const char *)(TString(132).fill('-'))); - set_header(j++, " Codice Ragione sociale@60gIndirizzo@100gC.A.P.@106gLocalita'@127gProv."); - set_header(j++, "@9gPartita iva@25gTelefoni"); - set_header(j++, (const char *)(TString(132).fill('-'))); -} - -void CG1200_App::set_elenco() -{ - // body - set_row(1,"$[r]@1s$[n] $[r]@pn$[n] #t", FLD(LF_CLIFO, CLI_TIPOCF), - FLD(LF_CLIFO, CLI_CODCF,"@@@@@@"), &_name); - set_row(2,"@9g#t@56g@s@63g#t @s @s", &_indir, FLD(LF_CLIFO, CLI_CAPCF), - &_localita, FLD(-COMRF_ALIAS,COM_DENCOM), FLD(-COMRF_ALIAS,COM_PROVCOM)); - set_row(3,"@9g#t@90g#t@115g#t", &_telefono, &_fax, &_telex); - set_row(4,"@9g@s @s@45g#t@56g#t@69g#t",FLD(-COMNASC_ALIAS, COM_DENCOM), - FLD(-COMNASC_ALIAS, COM_PROVCOM), &_datanas, &_piva,&_cofi); - - set_row(5,"@9g@3n @3n @6n #t@56g@n #t@90g#t",FLD(LF_CLIFO,CLI_GRUPPORIC), - FLD(LF_CLIFO,CLI_CONTORIC), FLD(LF_CLIFO, CLI_SOTTOCRIC),&_d_c_ric, - FLD(LF_CLIFO, CLI_CODALLEG), &_d_alleg, &_cpercip); - - for(int i = 0; i < _interline; i++) - set_row(i+5,""); -} - -void CG1200_App::set_rubriche() -{ - // body - set_row(1,"$[r]@1s$[n] $[r]@pn$[n] #t", FLD(LF_CLIFO,CLI_TIPOCF), - FLD(LF_CLIFO,CLI_CODCF,"@@@@@@"), &_name); - set_row(1,"@60g#t@100g@s@106g#t @127g@s", &_indir, FLD(LF_CLIFO, CLI_CAPCF), - &_localita, FLD(-COMRF_ALIAS,COM_PROVCOM)); - set_row(2,"@9g#t@25g#t", &_piva,&_telefono); - - for(int i = 0; i < _interline; i++) - set_row(i+4,""); -} - -bool mask2_reset_fields(TMask_field& mf, KEY k) -{ - if (k == K_SPACE) - { - CG1200_App* a = (CG1200_App*)MainApp(); - mf.mask().field(FLD_CGB_STARTROW).set(format("%d",a->_startrow)); - mf.mask().field(FLD_CGB_STARTCOL).set(format("%d",a->_startcol)); - mf.mask().field(FLD_CGB_ROWSET).set(format("%d",a->_rows_et)); - mf.mask().field(FLD_CGB_COLSET).set(format("%d",a->_cols_et)); - } - return TRUE; -} - -void CG1200_App::set_etichette() -{ - int r=_startrow; - TString loccf=get_field(LF_CLIFO,CLI_LOCCF); - - reset_header(); - for (int i = 1; i < _startrow; i++) - set_row(i,""); - - set_row(r++, format("@%dg#-%dt",_startcol, _cols_et - _startcol), - &_name); - set_row(r++, format("@%dg#-%dt",_startcol, _cols_et - _startcol), - &_indir); - if (!loccf.empty()) - set_row(r++,format("@%dg#-%dt",_startcol, _cols_et - _startcol), &_localita); - set_row(r++, format("@%dg@5s @%ds @2s",_startcol, - _cols_et - _startcol - 9), - FLD(LF_CLIFO, CLI_CAPCF), - FLD(-COMRF_ALIAS, COM_DENCOM), - FLD(-COMRF_ALIAS, COM_PROVCOM)); - - for (i = r; i <= _rows_et; i++) - set_row(i,""); -} - -void CG1200_App::set_vendite(int f, int c) - -{ TString* rigs = new TString(132); - - rigs->fill('-'); - - reset_header(); - // intestazione - const long firm = get_firm(); - TLocalisamfile ditte(LF_NDITTE); - ditte.zero(); - ditte.put(NDT_CODDITTA, firm); - ditte.read(); - if (ditte.bad()) ditte.zero(); - TString s(ditte.get(NDT_RAGSOC)); - - switch (f) - { - case LF_CFVEN: - ///////////////////////////////// - // Prints CFVEN information // - ///////////////////////////////// - set_header(1, "Ditta %ld %s @102gData @<@125gPag @#", firm, (const char*) s); - set_header(2, "Dati Clienti/Fornitori per Vendite"); - set_header(3, (const char *)(TString(132).fill('-'))); - set_header(4," Codice Ragione sociale"); - set_header(5,"@9gNote Cli/For @25gLegale per contenz. @46gCat.Finanziaria @63gCat.Vendita @76gAss.Fiscale @93gZona @101gAgente @112gProvvigione"); - set_header(6,"@9gCod.Listino @25gCod. Magazzino @46gSpese da Addeb. @63gBolli Tr. @76gBolli R.B. @93gSpese incasso @112gBolli sup. 50.000"); - set_header(7,"@9gCli/For ass. @25gCod. Meccanografico @46gGest. Contratto @63gRid. Iva @76gUltimo sollecito @93gUltimo estr. conto @112gTitolo onorifico"); - set_header(8,"@9gSconto cliente @25gSconto di riga @46gSconto incond. @63gFatt. Sosp. @76gVs. Lettera Esenzione @112gNs. Lettera Esenz."); - set_header(9,"@9gCod. ABI p.e. @25gCod. CAB p.e. @46gInd. Effetti @63gEmiss. Eff. @76gImporto Minimo @93gEffetti non acc. @112gScadenza effetti"); - set_header(10,"@9gInd.Documento @25gInd. Spedizione @46gNote Documento @63gCod.Mezzo @76gPorto @93gVettori"); - set_header(11,"@9gRaggr. ordini @25gImporto Minimo @46gImporto Massimo @63gPriorita ev. @76gTipo Evasione"); - set_header(12, (const char *)(TString(132).fill('-'))); - - set_row(1,"$[r]@1s$[n] $[r]@pn$[n] #t", FLD(LF_CLIFO, CLI_TIPOCF), - FLD(LF_CLIFO, CLI_CODCF,"@@@@@@"), &_name); - - set_row(2,"@9g@2s @25g@2s @46g@2s @63g@2s @76g@2s @93g@2s @101g@3s @112g@n", - FLD(LF_CFVEN, CFV_CODNOTE),FLD(LF_CFVEN,CFV_CODLEG), - FLD(LF_CFVEN,CFV_CATFIN),FLD(LF_CFVEN,CFV_CATVEN), - FLD(LF_CFVEN,CFV_ASSFIS),FLD(LF_CFVEN,CFV_CODZONA), - FLD(LF_CFVEN,CFV_CODAG),FLD(LF_CFVEN,CFV_PROVV)); - - set_row(3,"@9g@5s @25g@3s @46g@3s @3s @3s @3s @63g@f @76g@f @93g@f @112g@f", - FLD(LF_CFVEN,CFV_CODLIST),FLD(LF_CFVEN,CFV_CODMAG), - FLD(LF_CFVEN,CFV_CODSP1),FLD(LF_CFVEN,CFV_CODSP2), - FLD(LF_CFVEN,CFV_CODSP3),FLD(LF_CFVEN,CFV_CODSP4), - FLD(LF_CFVEN,CFV_ADDBOLLITR),FLD(LF_CFVEN,CFV_ADDBOLLIRB), - FLD(LF_CFVEN,CFV_ADDSPINC),FLD(LF_CFVEN,CFV_ADDBNS1500)); - - set_row(4,"@9g@pn @25g@s @46g@f @63g@f @76g@d @93g@d @112g@2s", - FLD(LF_CFVEN,CFV_CODCFASS,"@@@@@@"), - FLD(LF_CFVEN,CFV_CODPRCF),FLD(LF_CFVEN,CFV_GESTCONTR), - FLD(LF_CFVEN,CFV_IVARID),FLD(LF_CFVEN,CFV_DATAESC), - FLD(LF_CFVEN,CFV_DATASOLL),FLD(LF_CFVEN,CFV_TITOLO)); - - set_row(5,"@9g@n @25g@15s @46g@2s @63g@f @76g@s del @d @112g@s del @d", - FLD(LF_CFVEN,CFV_SCONTOCL),FLD(LF_CFVEN,CFV_SCONTOR), - FLD(LF_CFVEN,CFV_CODSCINC),FLD(LF_CFVEN,CFV_FATTSOSP), - FLD(LF_CFVEN,CFV_VSNRPROT),FLD(LF_CFVEN,CFV_VSDATAREG), - FLD(LF_CFVEN,CFV_NSNPROT),FLD(LF_CFVEN,CFV_NSDATAREG)); - - set_row(6,"@9g@5pn @25g@5pn @46g@3,rn @63g@f @76g@pn @93g@s @112g@s", - FLD(LF_CFVEN,CFV_CODABIPR,"@@@@@"), - FLD(LF_CFVEN,CFV_CODCABPR,"@@@@@"), - FLD(LF_CFVEN,CFV_CODINDEFF),FLD(LF_CFVEN,CFV_EMEFFRICH), - FLD(LF_CFVEN,CFV_IMPMINEFF,"."), - FLD(LF_CFVEN,CFV_NONACCEFF), - FLD(LF_CFVEN,CFV_NONSCADEFF)); - - set_row(7,"@9g@3,rn @25g@3,rn @46g@2s @53g@2s @63g@2s @76g@2s @93g@3pn @96g@3pn @103g@3pn", - FLD(LF_CFVEN,CFV_CODINDDOC),FLD(LF_CFVEN,CFV_CODINDSP), - FLD(LF_CFVEN,CFV_CODNOTESP1),FLD(LF_CFVEN,CFV_CODNOTESP2), - FLD(LF_CFVEN,CFV_CODSPMEZZO),FLD(LF_CFVEN,CFV_CODPORTO), - FLD(LF_CFVEN,CFV_CODVETT1,"@@@"), - FLD(LF_CFVEN,CFV_CODVETT2,"@@@"), - FLD(LF_CFVEN,CFV_CODVETT3,"@@@")); - - set_row(8,"@9g@s @25g@pn @46g@pn @63g@n @76g@2s", - FLD(LF_CFVEN,CFV_RAGGOR),FLD(LF_CFVEN,CFV_MINORD,"."), - FLD(LF_CFVEN,CFV_MAXORD,"."),FLD(LF_CFVEN,CFV_PREVORD), - FLD(LF_CFVEN,CFV_TIPOEVORD)); - if (current_cursor()->is_first_match(LF_INDSP)) - { // Test whether there are any Addresses. If so, prints - // the header. - set_row(9,""); - set_row(10,"@9gIndirizzi di Spedizione"); - set_row(11,"@9g%t",rigs); - set_row(12,"@9gCodice @17gRagione Sociale"); - set_row(13,"@17gIndirizzo @65gC.A.P. @72gLocalita"); - set_row(14,"@17gTelefono @60gFax @102gRiduzione IVA"); - set_row(15,"@9g%t",rigs); - } else - for (int i=0;i<_interline;i++) - set_row(i+9,""); - break; - ///////////////////////////////////////// - // End of printing CFVEN information // - ///////////////////////////////////////// - case LF_INDSP: - ////////////////////////////////////////////////// - // Prints INDSP information for each customer // - ////////////////////////////////////////////////// - - set_row(1,"@9g@pn @17g@s",FLD(LF_INDSP,IND_CODIND,"@@@"), - FLD(LF_INDSP,IND_RAGSOC)); - set_row(2,"@17g@s @s @65g@s @72g#t",FLD(LF_INDSP,IND_INDIR), - FLD(LF_INDSP,IND_CIV),FLD(LF_INDSP,IND_CAP), &_localita); - set_row(3,"@17g#t @60g#t @102g@f",&_telefono,&_fax, - FLD(LF_INDSP,IND_IVARID)); - current_cursor()->save_status(); - if (!current_cursor()->next_match(LF_INDSP)) - for (int i=0;i<_interline;i++) - set_row(i+4,""); - else - set_row(4,""); - current_cursor()->restore_status(); - ///////////////////////////////////////// - // End of printing INDSP information // - ///////////////////////////////////////// - break; - - default: - break; - } - delete rigs; - } - -bool CG1200_App::set_print(int) -{ - disable_links(); - set_multiple_link(FALSE); - - TMask mask("cg1200a.msk"); - - mask.set_handler(RDB_CG12_TYPE, rdbtype_handler); - mask.set_handler(BUT_CG12_ELENCO, mask_ctrl_handler); - mask.set_handler(BUT_CG12_RUBRICHE, mask_ctrl_handler); - mask.set_handler(BUT_CG12_ETICHETTE, mask_ctrl_handler); - mask.run(); - - force_setpage(FALSE); - // set print type - switch (mask.last_key()) - { - case K_ESC: - case K_QUIT: - return FALSE; - break; - case BUT_CG12_ELENCO: - _pr_type = elenco; - break; - case BUT_CG12_ETICHETTE: - { - TMask mask2("cg1200b.msk"); - - /* TBI read/save from - to config file */ - _pr_type = etichette; - - mask2.set_handler(BUT_CGB_RESET, mask2_reset_fields); - - mask2.field(FLD_CGB_ROWSET).set(format("%d",_rows_et)); - mask2.field(FLD_CGB_COLSET).set(format("%d",_cols_et)); - - mask2.field(FLD_CGB_STARTROW).set(format("%d",_startrow)); - mask2.field(FLD_CGB_STARTCOL).set(format("%d",_startcol)); - - // set defaults - - mask2.run(); - - _startrow = atoi(mask2.get(FLD_CGB_STARTROW)); - _startcol = atoi(mask2.get(FLD_CGB_STARTCOL)); - _rows_et = atoi(mask2.get(FLD_CGB_ROWSET)); - _cols_et = atoi(mask2.get(FLD_CGB_COLSET)); - force_setpage(); - break; - } - case BUT_CG12_RUBRICHE: - _pr_type = rubriche; - break; - case BUT_CG12_VENDITE: - _pr_type = vendite; - force_setpage(); - break; - } - - if (_pr_type != etichette) - { - set_multiple_link(TRUE); - enable_link("Collegamento clienti e fornitori : ", 'r'); - } - - _sort = mask.get_int(RDB_CG12_SORT); - _pr_what = (pw) mask.get_int(RDB_CG12_TYPE); - _interline = mask.get_int(LST_CG12_INTERLINE); - _mov_only = mask.get_bool(CHK_CG12_MOVIM); - char tipoafr = mask.get(F_TIPOAPERFR)[0]; - char tipoato = mask.get(F_TIPOAPERTO)[0]; - TDate data_stampa (mask.get(F_DATA_STAMPA)); - _data_stampa = data_stampa.string(); - _codice = 0; - - select_cursor(ccur()); - - TRectype tr1(current_cursor()->curr()); - tr1.zero(); - TRectype tr2(tr1); - - if (_pr_what != both) - { - // filter - tr1.put(CLI_TIPOCF, _pr_what == clienti ? "C" : "F"); - tr2.put(CLI_TIPOCF, _pr_what == clienti ? "C" : "F"); - short fromid, toid; - TString16 nome_campo; - - if (_sort == 1) - { - fromid = (_pr_what == clienti) ? FLD_CLI_CODFR : FLD_FOR_CODFR; - toid = (_pr_what == clienti) ? FLD_CLI_CODTO : FLD_FOR_CODTO; - nome_campo = CLI_CODCF; - } - else - { - fromid = (_pr_what == clienti) ? FLD_CLI_RAGSOCFR : FLD_FOR_RAGSOCFR; - toid = (_pr_what == clienti) ? FLD_CLI_RAGSOCTO : FLD_FOR_RAGSOCTO; - nome_campo = CLI_RAGSOC; - } - TString cod_from(mask.get(fromid)); - TString cod_to(mask.get(toid)); - - if (cod_from.not_empty()) tr1.put(nome_campo, cod_from); - if (cod_to.not_empty()) tr2.put(nome_campo, cod_to); - - if (_sort == 1) - { - _cod_from = cod_from; - _cod_to = cod_to; - } - else - { - _cod_from = compatta_ragsoc(cod_from,tipoafr); - _cod_to = compatta_ragsoc(cod_to,tipoato); - } - } - current_cursor()->setregion(tr1, tr2); - - return TRUE; -} - - -bool CG1200_App::preprocess_print(int file, int counter) -{ - reset_print(); - if (_pr_type == undefined) - return set_print(counter); - - if (file == LF_CLIFO) - if (_pr_what == both) - _gia_iniziati_fornitori = FALSE; - - return TRUE; -} - -bool CG1200_App::user_create() -{ - // set relation and cursors - _rel = new TRelation(LF_CLIFO); - _rel->add(LF_COMUNI, "STATO==STATOCF|COM==COMCF", 1, 0, COMRF_ALIAS); - _rel->add(LF_COMUNI, "STATO==STATONASC|COM==COMNASC", 1, 0, COMNASC_ALIAS); - if (gest_vend()) - { - _rel->add(LF_CFVEN,"TIPOCF=TIPOCF|CODCF=CODCF"); - _rel->add(LF_INDSP,"TIPOCF=TIPOCF|CODCF=CODCF"); - } - - _mov = new TLocalisamfile(LF_MOV); _mov->setkey(3); - _comuni = new TLocalisamfile(LF_COMUNI); - _cur_1 = add_cursor(new TCursor(_rel,"",1)); - _cur_2 = add_cursor(new TCursor(_rel,"",2)); - add_file(LF_CLIFO); - if (gest_vend()) - { - add_file(LF_CFVEN,LF_CLIFO); - add_file(LF_INDSP,LF_CLIFO); - } - enable_print_menu(); - return TRUE; -} - -bool CG1200_App::user_destroy() -{ - if (_rel) - delete _rel; - delete _mov; - delete _comuni; - return TRUE; -} - -int cg1200(int argc, char* argv[]) -{ - CG1200_App app; - app.run(argc, argv, "Stampa Clienti/Fornitori"); - return 0; -} +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "cg1.h" +#include "cg1200a.h" +#include "cg1200b.h" +#include + +#define COMRF_ALIAS 50 +#define COMNASC_ALIAS 51 + +enum pt { undefined = 0, elenco = 1, rubriche = 2, etichette = 3, vendite = 4 }; +enum pw { clienti = 1, fornitori = 2, both = 3 }; + +bool mask2_reset_fields(TMask_field& mf, KEY k); + +extern char __tmp [MAXSTR]; +static TFixed_string tmp(__tmp, MAXSTR); + +class CG1200_App : public TPrintapp +{ + friend bool mask2_reset_fields(TMask_field& mf, KEY k); + + pt _pr_type; + pw _pr_what; + TRelation* _rel; + int _cur_1, _cur_2; + int _sort; + int _interline; + bool _mov_only; + TLocalisamfile* _mov; + TLocalisamfile* _comuni; + + // etichette + int _startrow, _rows_et, _cols_et, _startcol; + + // variable field slots + TString _piva,_cpercip,_fax,_telex,_name,_telefono,_indir,_localita; + TString _cod_from,_cod_to,_data_stampa,_cofi,_d_c_ric,_d_alleg; + TString _datanas; + long _codice; + char _tipocf,_tipoaper; + bool _gia_iniziati_fornitori; + +public: + + virtual bool preprocess_page(int file, int counter); + virtual bool preprocess_print(int file, int counter); + virtual print_action postprocess_print(int file, int counter); + virtual void preprocess_header(); + virtual bool user_create(); + virtual bool user_destroy(); + virtual bool set_print(int); + + int ccur() { return _sort == 1 ? _cur_1 : _cur_2; } + + const char* look_tab(const char* tabname, TString& cod, + const char* fld = "S0"); + const char* get_field(int ln, const char* fn) + { return current_cursor()->curr(ln).get(fn); } + + virtual void set_page (int file, int counter); + void set_elenco(); + void set_rubriche(); + void set_etichette(); + void set_vendite(int f, int c) ; + void process_link(int id, const char* txt); + void ultimo_codice(char tipo); + const char* compatta_ragsoc(TString& ragsoc,char tipoaper); + void header_elenco(); + void header_rubriche(); + const char* descrizione_conto_ric(int,int,long); + const char* descrizione_allegato(char,long); + + CG1200_App() : TPrintapp(),_piva(18), _cpercip(10), _fax(50), _telex(50), + _name(60), _telefono(90), _indir(70), _localita(90) + { + _rel = NULL; _pr_type = undefined; _startrow = 2; _startcol = 3; + _rows_et = 9; _cols_et = 40; + } + +}; + + + +/* -------------------------------------------------------------------- */ +/* ---------------------------- Code ---------------------------------- */ +/* -------------------------------------------------------------------- */ + + +void CG1200_App::process_link(int id, const char* txt) +{ + TString ss = "1|"; + ss << txt; + TMessage fs(cmd2name("cg0","-1"), MSG_LN, ss); + TMailbox m; + m.send(fs); + TExternal_app cg0("cg0 -1"); + if (cg0.run()) beep(); +} + +const char* CG1200_App::look_tab(const char* tabname, TString& cod, + const char* fld) +{ + TTable tab(tabname); + tab.curr().zero(); + tab.curr().put("CODTAB",cod); + tab.read(); + if (tab.bad()) tab.curr().zero(); + return tab.curr().get(fld); +} + +const char* CG1200_App::descrizione_conto_ric(int gruppo, int conto, long sottoc) +{ + TLocalisamfile pconti(LF_PCON, FALSE); + + pconti.setkey(1); + pconti.zero(); + pconti.put(PCN_GRUPPO, gruppo); + pconti.put(PCN_CONTO, conto); + pconti.put(PCN_SOTTOCONTO, sottoc); + pconti.read(); + if (pconti.bad()) + pconti.zero(); + tmp = pconti.get(PCN_DESCR); + + return (__tmp); +} + +const char* CG1200_App::descrizione_allegato(char tipocf,long cod) +{ + TLocalisamfile clifo(LF_CLIFO, FALSE); + + clifo.setkey(1); + clifo.zero(); + clifo.put(CLI_TIPOCF, tipocf); + clifo.put(CLI_CODCF , cod); + clifo.read(); + if (clifo.bad()) + clifo.zero(); + _tipoaper = clifo.get_char(CLI_TIPOAPER); + tmp = clifo.get(CLI_RAGSOC); + + return (__tmp); +} + +bool CG1200_App::preprocess_page(int file, int counter) +{ + TString s; + int g_ric,c_ric; + long s_ric,codall; + + switch (file) + { + case LF_CLIFO: + { + if (_mov_only) + { + const TString16 tipocf(get_field(LF_CLIFO,CLI_TIPOCF)); + const TString16 codice(get_field(LF_CLIFO,CLI_CODCF)); + + _mov->curr().zero(); + _mov->curr().put(MOV_TIPO, tipocf); + _mov->curr().put(MOV_CODCF, codice); + _mov->read(); + if (_mov->get(MOV_TIPO) != tipocf || + _mov->get(MOV_CODCF) != codice) + return FALSE; + } + + _tipocf = current_cursor()->curr(LF_CLIFO).get_char(CLI_TIPOCF); + + // set variable fields + _cofi = get_field(LF_CLIFO, CLI_COFI); + //_piva = get_field(LF_CLIFO, CLI_COFI); + //if (_piva.empty()) _piva = get_field(LF_CLIFO, CLI_PAIV); + _piva = get_field(LF_CLIFO, CLI_PAIV); + _telefono = get_field(LF_CLIFO, CLI_PTEL); + if (!_telefono.empty()) _telefono << "/"; + _telefono << get_field(LF_CLIFO, CLI_TEL) << " "; + s = get_field(LF_CLIFO, CLI_PTEL2); + if (!s.empty()) s << "/"; + _telefono << s << get_field(LF_CLIFO, CLI_TEL2) << " "; + s = get_field(LF_CLIFO, CLI_PTEL3); + if (!s.empty()) s << "/"; + _telefono << s << get_field(LF_CLIFO, CLI_TEL3); + _fax = get_field(LF_CLIFO, CLI_PFAX); + if (!_fax.empty()) _fax << "/"; + _fax << get_field(LF_CLIFO, CLI_FAX); + _telex = get_field(LF_CLIFO, CLI_PTELEX); + if (!_telex.empty()) _telex << "/"; + _telex << get_field(LF_CLIFO, CLI_TELEX); + _indir = get_field(LF_CLIFO, CLI_INDCF); + g_ric = atoi(get_field(LF_CLIFO, CLI_GRUPPORIC)); + c_ric = atoi(get_field(LF_CLIFO, CLI_CONTORIC)); + s_ric = atol(get_field(LF_CLIFO, CLI_SOTTOCRIC)); + codall = atol(get_field(LF_CLIFO, CLI_CODALLEG)); + _datanas = get_field(LF_CLIFO, CLI_DATANASC); + const TString16 tipoaper(get_field(LF_CLIFO, CLI_TIPOAPER)); + + _d_alleg = ""; + if (codall != 0) + { + _d_alleg = descrizione_allegato(_tipocf,codall); + if (_tipoaper == 'F') + { + TString surname = _d_alleg.mid(30,50); surname.trim(); + _d_alleg = _d_alleg.mid(0,30); _d_alleg.trim(); + _d_alleg << " " << surname; + } + } + + _d_c_ric = descrizione_conto_ric(g_ric,c_ric,s_ric); + + _d_c_ric = _d_c_ric.mid(0,31); + _d_alleg = _d_alleg.mid(0,26); + + if (!_indir.empty()) _indir << " "; + _indir << get_field(LF_CLIFO, CLI_CIVCF); + + _localita = get_field(LF_CLIFO, CLI_LOCCF); + if (!_localita.empty()) + _localita.trim(); + + _name = get_field(LF_CLIFO, CLI_RAGSOC); + s = get_field(LF_CLIFO, CLI_CODANAGPER); + _cpercip = ""; + + + if (s.not_empty()) _cpercip << tipoaper << " " << s; + + if (tipoaper == "F") + { + TString surname = _name.mid(30,50); surname.trim(); + _name = _name.mid(0,30); _name.trim(); + _name << " " << surname; + } + + switch(_pr_type) + { + case elenco: + case rubriche: + if (_pr_what == both) + if (_tipocf == 'F' && !_gia_iniziati_fornitori) + { + _gia_iniziati_fornitori = TRUE; + printer().formfeed(); + } + break; + default: + break; + } + } + break; + case LF_INDSP: + current_cursor()->items(); + if (atoi(get_field(LF_INDSP,IND_CODIND)) == 0) + return FALSE; + _telefono = get_field(LF_INDSP, IND_PTEL); + if (!_telefono.empty()) _telefono << "/"; + _telefono << get_field(LF_INDSP, IND_TEL); + _fax = get_field(LF_INDSP, IND_PFAX); + if (!_fax.empty()) _fax << "/"; + _fax << get_field(LF_INDSP, IND_FAX); + _localita = get_field(LF_INDSP,IND_LOCALITA); + if (!_localita.empty()) + _localita << " - "; + _comuni->curr().zero(); + _comuni->curr().put(COM_STATO,get_field(LF_INDSP,IND_STATO)); + _comuni->curr().put(COM_COM,get_field(LF_INDSP,IND_COM)); + _comuni->read(); + _localita << _comuni->curr().get(COM_DENCOM); + _localita << " "; + _localita << _comuni->curr().get(COM_PROVCOM); + break; +default: + break; +} + return TRUE; +} + +print_action CG1200_App::postprocess_print(int file, int counter) +{ + /* + static bool more = FALSE; + if (_pr_what == both) + { + if (more) + { + more = FALSE; + select_cursor(ccur()); + return NEXT_PAGE; + } + else + { + more = TRUE; + select_cursor(ccur()); + return REPEAT_PAGE; + } + } + */ + return NEXT_PAGE; +} + +bool gest_vend() +{ + TConfig c(CONFIG_DITTA,"cg"); + return (c.get("GesVen") == "X"); +} + +bool rdbtype_handler(TMask_field& f, KEY k) +{ + if (k == K_TAB) + //every time that change focus or value, check flag to enable button + { + if (gest_vend()) + f.mask().enable(BUT_CG12_VENDITE); + else + f.mask().disable(BUT_CG12_VENDITE); + } + return TRUE; +} + +bool mask_ctrl_handler(TMask_field& mf, KEY k) +{ + if (k == K_SPACE) + { + mf.mask().stop_run(mf.dlg()); + } + return TRUE; +} + +// set printrows + +void CG1200_App::set_page(int file, int counter) +{ + switch(_pr_type) + { + case elenco: + if (file == LF_CLIFO) + set_elenco(); + break; + case rubriche: + if (file == LF_CLIFO) + set_rubriche(); + break; + case etichette: + if (file == LF_CLIFO) + set_etichette(); + break; + case vendite: + set_vendite(file, counter); + default: + break; + } +} + +void CG1200_App::ultimo_codice(char tipocf) +{ + TLocalisamfile clifo(LF_CLIFO,FALSE); + + char tipopr = tipocf; + + clifo.setkey(1); + clifo.zero(); + clifo.put(CLI_TIPOCF,tipocf); + + for (clifo.read();!clifo.eof();clifo.next()) + { + char tipo = clifo.get_char(CLI_TIPOCF); + + if (tipo != tipopr) break; + + _codice = clifo.get_long(CLI_CODCF); + } +} + +const char* CG1200_App::compatta_ragsoc(TString& ragsoc,char tipoa) +{ + if (tipoa == 'F') + { + TString80 cognome, nome; + cognome = ragsoc.mid(0,30); + nome = ragsoc.mid(30,20); + cognome.trim(); nome.trim(); + + ragsoc = cognome; + ragsoc << " " << nome; + } + + tmp = ragsoc; + + return (__tmp); +} + +void CG1200_App::preprocess_header() +{ + switch(_pr_type) + { + case elenco: + header_elenco(); + break; + case rubriche: + header_rubriche(); + break; + default: + break; + } +} + +void CG1200_App::header_elenco() +{ + reset_header(); + // intestazione + const long firm = get_firm(); + TString var; + int j = 1; + char tipocf; + TLocalisamfile ditte(LF_NDITTE); + ditte.zero(); + ditte.put(NDT_CODDITTA, firm); + ditte.read(); + if (ditte.bad()) ditte.zero(); + TString s(ditte.get(NDT_RAGSOC)); + + set_header(j, "Ditta %ld %s@125gPag @#", firm, (const char*) s); + set_header(j++, "@102gData %s", (const char*) _data_stampa); + /* + if (_pr_what == both) + { + current_cursor()->save_status(); + ++(*current_cursor()); + tipocf = current_cursor()->curr(LF_CLIFO).get_char(CLI_TIPOCF); + --(*current_cursor()); + current_cursor()->restore_status(); + } + else + */ + tipocf = current_cursor()->curr(LF_CLIFO).get_char(CLI_TIPOCF); + + if (tipocf == 'C') + var = "Clienti"; + else + if (tipocf == 'F') + var = "Fornitori"; + + set_header(j, "Elenco %s",(const char*) var); + + if (_sort == 1) + var = "Ordine di codice"; + else + var = "Ordine alfabetico"; + + set_header(j, "@30g%s", (const char*) var); + + if (_mov_only) + set_header(j, "@55gSolo i movimentati"); + + ultimo_codice(_tipocf); + + set_header(j++, "@102gUltimo cod.utilizzato %ld" , _codice); + + if (_pr_what != both) + { + if (_cod_from.not_empty() || _cod_to.not_empty()) + { + set_header(j, "Estremi selezione"); + if (_cod_from.not_empty()) + set_header(j, " da %s", (const char*) _cod_from); + if (_cod_to.not_empty()) + if (_sort == 1) + set_header(j, " a %s", (const char*) _cod_to); + else + set_header(j, " a %s", (const char*) _cod_to); + j++; + } + } + + set_header(j++, (const char *)(TString(132).fill('-'))); + set_header(j++, " Codice Ragione sociale"); + set_header(j++, "@9gIndirizzo@56gC.A.P.@63gLocalita'"); + set_header(j++, "@9gTelefoni@90gFAX @115gTelex"); + set_header(j++, "@9gLuogo di nascita@45gData@56gPartita IVA Codice fiscale"); + set_header(j++, "@9gConto di costo/ricavo@56gCodice allegato@90gPercipiente 770"); + set_header(j, (const char *)(TString(132).fill('-'))); +} + +void CG1200_App::header_rubriche() +{ + reset_header(); + // intestazione + const long firm = get_firm(); + TString var; + int j = 1; + char tipocf; + TLocalisamfile ditte(LF_NDITTE); + ditte.zero(); + ditte.put(NDT_CODDITTA, firm); + ditte.read(); + if (ditte.bad()) ditte.zero(); + TString s(ditte.get(NDT_RAGSOC)); + set_header(j, "Ditta %ld %s@125gPag @#", firm, (const char*) s); + set_header(j++, "@102gData %s", (const char*) _data_stampa); + /* + if (_pr_what == both) + { + current_cursor()->save_status(); + ++(*current_cursor()); + tipocf = current_cursor()->curr(LF_CLIFO).get_char(CLI_TIPOCF); + --(*current_cursor()); + current_cursor()->restore_status(); + } + else + */ + tipocf = current_cursor()->curr(LF_CLIFO).get_char(CLI_TIPOCF); + + if (tipocf == 'C') + var = "Clienti"; + else + if (tipocf == 'F') + var = "Fornitori"; + + set_header(j, "Rubrica %s",(const char*) var); + + if (_sort == 1) + var = "Ordine di codice"; + else + var = "Ordine alfabetico"; + + set_header(j, "@30g%s", (const char*) var); + + if (_mov_only) + set_header(j, "@55gSolo i movimentati"); + + ultimo_codice(_tipocf); + + set_header(j++, "@102gUltimo cod.utilizzato %ld" , _codice); + + if (_pr_what != both) + { + if (_cod_from.not_empty() || _cod_to.not_empty()) + { + set_header(j, "Estremi selezione"); + if (_cod_from.not_empty()) + set_header(j, " da %s", (const char*) _cod_from); + if (_cod_to.not_empty()) + if (_sort == 1) + set_header(j, " a %s", (const char*) _cod_to); + else + set_header(j, " a %s", (const char*) _cod_to); + j++; + } + } + + set_header(j++, (const char *)(TString(132).fill('-'))); + set_header(j++, " Codice Ragione sociale@60gIndirizzo@100gC.A.P.@106gLocalita'@127gProv."); + set_header(j++, "@9gPartita iva@25gTelefoni"); + set_header(j++, (const char *)(TString(132).fill('-'))); +} + +void CG1200_App::set_elenco() +{ + // body + set_row(1,"$[r]@1s$[n] $[r]@pn$[n] #t", FLD(LF_CLIFO, CLI_TIPOCF), + FLD(LF_CLIFO, CLI_CODCF,"@@@@@@"), &_name); + set_row(2,"@9g#t@56g@s@63g#t @s @s", &_indir, FLD(LF_CLIFO, CLI_CAPCF), + &_localita, FLD(-COMRF_ALIAS,COM_DENCOM), FLD(-COMRF_ALIAS,COM_PROVCOM)); + set_row(3,"@9g#t@90g#t@115g#t", &_telefono, &_fax, &_telex); + set_row(4,"@9g@s @s@45g#t@56g#t@69g#t",FLD(-COMNASC_ALIAS, COM_DENCOM), + FLD(-COMNASC_ALIAS, COM_PROVCOM), &_datanas, &_piva,&_cofi); + + set_row(5,"@9g@3n @3n @6n #t@56g@n #t@90g#t",FLD(LF_CLIFO,CLI_GRUPPORIC), + FLD(LF_CLIFO,CLI_CONTORIC), FLD(LF_CLIFO, CLI_SOTTOCRIC),&_d_c_ric, + FLD(LF_CLIFO, CLI_CODALLEG), &_d_alleg, &_cpercip); + + for(int i = 0; i < _interline; i++) + set_row(i+5,""); +} + +void CG1200_App::set_rubriche() +{ + // body + set_row(1,"$[r]@1s$[n] $[r]@pn$[n] #t", FLD(LF_CLIFO,CLI_TIPOCF), + FLD(LF_CLIFO,CLI_CODCF,"@@@@@@"), &_name); + set_row(1,"@60g#t@100g@s@106g#t @127g@s", &_indir, FLD(LF_CLIFO, CLI_CAPCF), + &_localita, FLD(-COMRF_ALIAS,COM_PROVCOM)); + set_row(2,"@9g#t@25g#t", &_piva,&_telefono); + + for(int i = 0; i < _interline; i++) + set_row(i+4,""); +} + +bool mask2_reset_fields(TMask_field& mf, KEY k) +{ + if (k == K_SPACE) + { + CG1200_App* a = (CG1200_App*)MainApp(); + mf.mask().field(FLD_CGB_STARTROW).set(format("%d",a->_startrow)); + mf.mask().field(FLD_CGB_STARTCOL).set(format("%d",a->_startcol)); + mf.mask().field(FLD_CGB_ROWSET).set(format("%d",a->_rows_et)); + mf.mask().field(FLD_CGB_COLSET).set(format("%d",a->_cols_et)); + } + return TRUE; +} + +void CG1200_App::set_etichette() +{ + int r=_startrow; + TString loccf=get_field(LF_CLIFO,CLI_LOCCF); + + reset_header(); + for (int i = 1; i < _startrow; i++) + set_row(i,""); + + set_row(r++, format("@%dg#-%dt",_startcol, _cols_et - _startcol), + &_name); + set_row(r++, format("@%dg#-%dt",_startcol, _cols_et - _startcol), + &_indir); + if (!loccf.empty()) + set_row(r++,format("@%dg#-%dt",_startcol, _cols_et - _startcol), &_localita); + set_row(r++, format("@%dg@5s @%ds @2s",_startcol, + _cols_et - _startcol - 9), + FLD(LF_CLIFO, CLI_CAPCF), + FLD(-COMRF_ALIAS, COM_DENCOM), + FLD(-COMRF_ALIAS, COM_PROVCOM)); + + for (i = r; i <= _rows_et; i++) + set_row(i,""); +} + +void CG1200_App::set_vendite(int f, int c) + +{ TString* rigs = new TString(132); + + rigs->fill('-'); + + reset_header(); + // intestazione + const long firm = get_firm(); + TLocalisamfile ditte(LF_NDITTE); + ditte.zero(); + ditte.put(NDT_CODDITTA, firm); + ditte.read(); + if (ditte.bad()) ditte.zero(); + TString s(ditte.get(NDT_RAGSOC)); + + switch (f) + { + case LF_CFVEN: + ///////////////////////////////// + // Prints CFVEN information // + ///////////////////////////////// + set_header(1, "Ditta %ld %s @102gData @<@125gPag @#", firm, (const char*) s); + set_header(2, "Dati Clienti/Fornitori per Vendite"); + set_header(3, (const char *)(TString(132).fill('-'))); + set_header(4," Codice Ragione sociale"); + set_header(5,"@9gNote Cli/For @25gLegale per contenz. @46gCat.Finanziaria @63gCat.Vendita @76gAss.Fiscale @93gZona @101gAgente @112gProvvigione"); + set_header(6,"@9gCod.Listino @25gCod. Magazzino @46gSpese da Addeb. @63gBolli Tr. @76gBolli R.B. @93gSpese incasso @112gBolli sup. 50.000"); + set_header(7,"@9gCli/For ass. @25gCod. Meccanografico @46gGest. Contratto @63gRid. Iva @76gUltimo sollecito @93gUltimo estr. conto @112gTitolo onorifico"); + set_header(8,"@9gSconto cliente @25gSconto di riga @46gSconto incond. @63gFatt. Sosp. @76gVs. Lettera Esenzione @112gNs. Lettera Esenz."); + set_header(9,"@9gCod. ABI p.e. @25gCod. CAB p.e. @46gInd. Effetti @63gEmiss. Eff. @76gImporto Minimo @93gEffetti non acc. @112gScadenza effetti"); + set_header(10,"@9gInd.Documento @25gInd. Spedizione @46gNote Documento @63gCod.Mezzo @76gPorto @93gVettori"); + set_header(11,"@9gRaggr. ordini @25gImporto Minimo @46gImporto Massimo @63gPriorita ev. @76gTipo Evasione"); + set_header(12, (const char *)(TString(132).fill('-'))); + + set_row(1,"$[r]@1s$[n] $[r]@pn$[n] #t", FLD(LF_CLIFO, CLI_TIPOCF), + FLD(LF_CLIFO, CLI_CODCF,"@@@@@@"), &_name); + + set_row(2,"@9g@2s @25g@2s @46g@2s @63g@2s @76g@2s @93g@2s @101g@3s @112g@n", + FLD(LF_CFVEN, CFV_CODNOTE),FLD(LF_CFVEN,CFV_CODLEG), + FLD(LF_CFVEN,CFV_CATFIN),FLD(LF_CFVEN,CFV_CATVEN), + FLD(LF_CFVEN,CFV_ASSFIS),FLD(LF_CFVEN,CFV_CODZONA), + FLD(LF_CFVEN,CFV_CODAG),FLD(LF_CFVEN,CFV_PROVV)); + + set_row(3,"@9g@5s @25g@3s @46g@3s @3s @3s @3s @63g@f @76g@f @93g@f @112g@f", + FLD(LF_CFVEN,CFV_CODLIST),FLD(LF_CFVEN,CFV_CODMAG), + FLD(LF_CFVEN,CFV_CODSP1),FLD(LF_CFVEN,CFV_CODSP2), + FLD(LF_CFVEN,CFV_CODSP3),FLD(LF_CFVEN,CFV_CODSP4), + FLD(LF_CFVEN,CFV_ADDBOLLITR),FLD(LF_CFVEN,CFV_ADDBOLLIRB), + FLD(LF_CFVEN,CFV_ADDSPINC),FLD(LF_CFVEN,CFV_ADDBNS1500)); + + set_row(4,"@9g@pn @25g@s @46g@f @63g@f @76g@d @93g@d @112g@2s", + FLD(LF_CFVEN,CFV_CODCFASS,"@@@@@@"), + FLD(LF_CFVEN,CFV_CODPRCF),FLD(LF_CFVEN,CFV_GESTCONTR), + FLD(LF_CFVEN,CFV_IVARID),FLD(LF_CFVEN,CFV_DATAESC), + FLD(LF_CFVEN,CFV_DATASOLL),FLD(LF_CFVEN,CFV_TITOLO)); + + set_row(5,"@9g@n @25g@15s @46g@2s @63g@f @76g@s del @d @112g@s del @d", + FLD(LF_CFVEN,CFV_SCONTOCL),FLD(LF_CFVEN,CFV_SCONTOR), + FLD(LF_CFVEN,CFV_CODSCINC),FLD(LF_CFVEN,CFV_FATTSOSP), + FLD(LF_CFVEN,CFV_VSNRPROT),FLD(LF_CFVEN,CFV_VSDATAREG), + FLD(LF_CFVEN,CFV_NSNPROT),FLD(LF_CFVEN,CFV_NSDATAREG)); + + set_row(6,"@9g@5pn @25g@5pn @46g@3,rn @63g@f @76g@pn @93g@s @112g@s", + FLD(LF_CFVEN,CFV_CODABIPR,"@@@@@"), + FLD(LF_CFVEN,CFV_CODCABPR,"@@@@@"), + FLD(LF_CFVEN,CFV_CODINDEFF),FLD(LF_CFVEN,CFV_EMEFFRICH), + FLD(LF_CFVEN,CFV_IMPMINEFF,"."), + FLD(LF_CFVEN,CFV_NONACCEFF), + FLD(LF_CFVEN,CFV_NONSCADEFF)); + + set_row(7,"@9g@3,rn @25g@3,rn @46g@2s @53g@2s @63g@2s @76g@2s @93g@3pn @96g@3pn @103g@3pn", + FLD(LF_CFVEN,CFV_CODINDDOC),FLD(LF_CFVEN,CFV_CODINDSP), + FLD(LF_CFVEN,CFV_CODNOTESP1),FLD(LF_CFVEN,CFV_CODNOTESP2), + FLD(LF_CFVEN,CFV_CODSPMEZZO),FLD(LF_CFVEN,CFV_CODPORTO), + FLD(LF_CFVEN,CFV_CODVETT1,"@@@"), + FLD(LF_CFVEN,CFV_CODVETT2,"@@@"), + FLD(LF_CFVEN,CFV_CODVETT3,"@@@")); + + set_row(8,"@9g@s @25g@pn @46g@pn @63g@n @76g@2s", + FLD(LF_CFVEN,CFV_RAGGOR),FLD(LF_CFVEN,CFV_MINORD,"."), + FLD(LF_CFVEN,CFV_MAXORD,"."),FLD(LF_CFVEN,CFV_PREVORD), + FLD(LF_CFVEN,CFV_TIPOEVORD)); + if (current_cursor()->is_first_match(LF_INDSP)) + { // Test whether there are any Addresses. If so, prints + // the header. + set_row(9,""); + set_row(10,"@9gIndirizzi di Spedizione"); + set_row(11,"@9g%t",rigs); + set_row(12,"@9gCodice @17gRagione Sociale"); + set_row(13,"@17gIndirizzo @65gC.A.P. @72gLocalita"); + set_row(14,"@17gTelefono @60gFax @102gRiduzione IVA"); + set_row(15,"@9g%t",rigs); + } else + for (int i=0;i<_interline;i++) + set_row(i+9,""); + break; + ///////////////////////////////////////// + // End of printing CFVEN information // + ///////////////////////////////////////// + case LF_INDSP: + ////////////////////////////////////////////////// + // Prints INDSP information for each customer // + ////////////////////////////////////////////////// + + set_row(1,"@9g@pn @17g@s",FLD(LF_INDSP,IND_CODIND,"@@@"), + FLD(LF_INDSP,IND_RAGSOC)); + set_row(2,"@17g@s @s @65g@s @72g#t",FLD(LF_INDSP,IND_INDIR), + FLD(LF_INDSP,IND_CIV),FLD(LF_INDSP,IND_CAP), &_localita); + set_row(3,"@17g#t @60g#t @102g@f",&_telefono,&_fax, + FLD(LF_INDSP,IND_IVARID)); + current_cursor()->save_status(); + if (!current_cursor()->next_match(LF_INDSP)) + for (int i=0;i<_interline;i++) + set_row(i+4,""); + else + set_row(4,""); + current_cursor()->restore_status(); + ///////////////////////////////////////// + // End of printing INDSP information // + ///////////////////////////////////////// + break; + + default: + break; + } + delete rigs; + } + +bool CG1200_App::set_print(int) +{ + disable_links(); + set_multiple_link(FALSE); + + TMask mask("cg1200a.msk"); + + mask.set_handler(RDB_CG12_TYPE, rdbtype_handler); + mask.set_handler(BUT_CG12_ELENCO, mask_ctrl_handler); + mask.set_handler(BUT_CG12_RUBRICHE, mask_ctrl_handler); + mask.set_handler(BUT_CG12_ETICHETTE, mask_ctrl_handler); + mask.run(); + + force_setpage(FALSE); + // set print type + switch (mask.last_key()) + { + case K_ESC: + case K_QUIT: + return FALSE; + break; + case BUT_CG12_ELENCO: + _pr_type = elenco; + break; + case BUT_CG12_ETICHETTE: + { + TMask mask2("cg1200b.msk"); + + /* TBI read/save from - to config file */ + _pr_type = etichette; + + mask2.set_handler(BUT_CGB_RESET, mask2_reset_fields); + + mask2.field(FLD_CGB_ROWSET).set(format("%d",_rows_et)); + mask2.field(FLD_CGB_COLSET).set(format("%d",_cols_et)); + + mask2.field(FLD_CGB_STARTROW).set(format("%d",_startrow)); + mask2.field(FLD_CGB_STARTCOL).set(format("%d",_startcol)); + + // set defaults + + mask2.run(); + + _startrow = atoi(mask2.get(FLD_CGB_STARTROW)); + _startcol = atoi(mask2.get(FLD_CGB_STARTCOL)); + _rows_et = atoi(mask2.get(FLD_CGB_ROWSET)); + _cols_et = atoi(mask2.get(FLD_CGB_COLSET)); + force_setpage(); + break; + } + case BUT_CG12_RUBRICHE: + _pr_type = rubriche; + break; + case BUT_CG12_VENDITE: + _pr_type = vendite; + force_setpage(); + break; + } + + if (_pr_type != etichette) + { + set_multiple_link(TRUE); + enable_link("Collegamento clienti e fornitori : ", 'r'); + } + + _sort = mask.get_int(RDB_CG12_SORT); + _pr_what = (pw) mask.get_int(RDB_CG12_TYPE); + _interline = mask.get_int(LST_CG12_INTERLINE); + _mov_only = mask.get_bool(CHK_CG12_MOVIM); + char tipoafr = mask.get(F_TIPOAPERFR)[0]; + char tipoato = mask.get(F_TIPOAPERTO)[0]; + TDate data_stampa (mask.get(F_DATA_STAMPA)); + _data_stampa = data_stampa.string(); + _codice = 0; + + select_cursor(ccur()); + + TRectype tr1(current_cursor()->curr()); + tr1.zero(); + TRectype tr2(tr1); + + if (_pr_what != both) + { + // filter + tr1.put(CLI_TIPOCF, _pr_what == clienti ? "C" : "F"); + tr2.put(CLI_TIPOCF, _pr_what == clienti ? "C" : "F"); + short fromid, toid; + TString16 nome_campo; + + if (_sort == 1) + { + fromid = (_pr_what == clienti) ? FLD_CLI_CODFR : FLD_FOR_CODFR; + toid = (_pr_what == clienti) ? FLD_CLI_CODTO : FLD_FOR_CODTO; + nome_campo = CLI_CODCF; + } + else + { + fromid = (_pr_what == clienti) ? FLD_CLI_RAGSOCFR : FLD_FOR_RAGSOCFR; + toid = (_pr_what == clienti) ? FLD_CLI_RAGSOCTO : FLD_FOR_RAGSOCTO; + nome_campo = CLI_RAGSOC; + } + TString cod_from(mask.get(fromid)); + TString cod_to(mask.get(toid)); + + if (cod_from.not_empty()) tr1.put(nome_campo, cod_from); + if (cod_to.not_empty()) tr2.put(nome_campo, cod_to); + + if (_sort == 1) + { + _cod_from = cod_from; + _cod_to = cod_to; + } + else + { + _cod_from = compatta_ragsoc(cod_from,tipoafr); + _cod_to = compatta_ragsoc(cod_to,tipoato); + } + } + current_cursor()->setregion(tr1, tr2); + + return TRUE; +} + + +bool CG1200_App::preprocess_print(int file, int counter) +{ + reset_print(); + if (_pr_type == undefined) + return set_print(counter); + + if (file == LF_CLIFO) + if (_pr_what == both) + _gia_iniziati_fornitori = FALSE; + + return TRUE; +} + +bool CG1200_App::user_create() +{ + // set relation and cursors + _rel = new TRelation(LF_CLIFO); + _rel->add(LF_COMUNI, "STATO==STATOCF|COM==COMCF", 1, 0, COMRF_ALIAS); + _rel->add(LF_COMUNI, "STATO==STATONASC|COM==COMNASC", 1, 0, COMNASC_ALIAS); + if (gest_vend()) + { + _rel->add(LF_CFVEN,"TIPOCF=TIPOCF|CODCF=CODCF"); + _rel->add(LF_INDSP,"TIPOCF=TIPOCF|CODCF=CODCF"); + } + + _mov = new TLocalisamfile(LF_MOV); _mov->setkey(3); + _comuni = new TLocalisamfile(LF_COMUNI); + _cur_1 = add_cursor(new TCursor(_rel,"",1)); + _cur_2 = add_cursor(new TCursor(_rel,"",2)); + add_file(LF_CLIFO); + if (gest_vend()) + { + add_file(LF_CFVEN,LF_CLIFO); + add_file(LF_INDSP,LF_CLIFO); + } + enable_print_menu(); + return TRUE; +} + +bool CG1200_App::user_destroy() +{ + if (_rel) + delete _rel; + delete _mov; + delete _comuni; + return TRUE; +} + +int cg1200(int argc, char* argv[]) +{ + CG1200_App app; + app.run(argc, argv, "Stampa Clienti/Fornitori"); + return 0; +} diff --git a/cg/cg1300.cpp b/cg/cg1300.cpp index 13b085b5f..de7c3f3ce 100755 --- a/cg/cg1300.cpp +++ b/cg/cg1300.cpp @@ -1,102 +1,7 @@ -#include -#include -#include -#include -#include - - -class TEdit_form : public TApplication -{ - const char* _name; - TForm* _form; - -protected: - virtual bool create(); - virtual bool destroy(); - virtual bool menu(MENU_TAG); - -public: - TEdit_form(const char* name); - const char* name() const { return _name; } -}; - - -TEdit_form::TEdit_form(const char* name) -: _name(name), _form(NULL) -{} - - -bool TEdit_form::create() -{ - _form = new TForm(name()); - dispatch_e_menu(MENU_ITEM(2)); - return TRUE; -} - - -bool TEdit_form::destroy() -{ - delete _form; - return TRUE; -} - - -bool TEdit_form::menu(MENU_TAG tag) -{ - char sec = 'B'; - switch(tag) - { - case MENU_ITEM(1): - sec = 'H'; break; - case MENU_ITEM(3): - sec = 'F'; break; - default: - break; - } - _form->edit(sec, odd_page); - return TRUE; -} - - -int cg1300(int argc, char* argv[]) -{ - TApplication::check_parameters(argc, argv); - if (argc < 3) - { - error_box("Specificare il nome del profilo di stampa"); - return 1; - } - - TFilename form(argv[2]); form.ext("frm"); - - const char mode = argc > 3 ? toupper(argv[3][1]) : 'M'; - const bool crea = (mode == 'C') || !fexist(form); - - if (crea) - { - TFilename base(form.left(3)); base.ext("frm"); - if (!fexist(base)) - { - error_box("Non esiste il file %s", (const char*)base); - return 1; - } - if (!fcopy(base, form)) - { - error_box("Impossibile copiare %s in %s", (const char*)base, (const char*)form); - return 1; - } - } - - if (!fexist(form)) - { - error_box("Non esiste il file %s", (const char*)form); - return 1; - } - - TEdit_form a(form); - TString80 title; - title << (crea ? "Creazione" : "Modifica") << ": " << a.name(); - a.run(argc, argv, title); - - return 0; -} +#include + +int cg1300(int argc, char* argv[]) +{ + error_box("Applicazione ancora da sviluppare"); + return 1; +} diff --git a/cg/cg2100.cpp b/cg/cg2100.cpp index 4f50ecdc7..04f577359 100755 --- a/cg/cg2100.cpp +++ b/cg/cg2100.cpp @@ -1,952 +1,951 @@ -#include -#include -#include -#include -#include - -#include "cg2100.h" -#include "cg2102.h" - -// Nomi dei campi -#include -#include -#include - -TPrimanota_application::TPrimanota_application() -: _rel(NULL), _lastreg(0), _mode(0), _iva(nessuna_iva), _causale(NULL), _giornale(NULL) -{ - memset(_msk, 0, sizeof(_msk)); -} - - -TMask* TPrimanota_application::load_mask(int n) -{ - if (_msk[n] != NULL) - return _msk[n]; - - if (n == 1 || n == 2) - { - const int d = 3-n; - if (_msk[d] != NULL) - { - delete _msk[d]; - _msk[d] = NULL; - } - } - - TFilename name("cg2100"); name << char(n == 3 ? 'o' : 'a'+n); - TMask* m = new TMask(name); - - switch (n) - { - case 0: - { - m->set_handler(F_NUMREG, num_handler); - m->set_handler(F_CODCAUS, caus_query_handler); - m->set_handler(F_DATAREG, datareg_handler); - m->set_handler(F_DATACOMP, datacomp_handler); - - TConfig c(CONFIG_STUDIO, "cg"); - const bool dr = c.get_bool("PoCuDr"); // Scelta primo campo col focus - m->first_focus(dr ? F_DATAREG : F_CODCAUS); - - _savenew = !c.get_bool("Cg21SN"); - } - break; - case 2: -{ - m->set_handler(F_DATADOC, doc_handler); - m->set_handler(F_NUMDOC, doc_handler); - m->set_handler(F_DATA74TER, data74ter_handler); - m->set_handler(F_PROTIVA, protiva_handler); - m->set_handler(F_CLIENTE, clifo_handler); - m->set_handler(F_FORNITORE, clifo_handler); - m->set_handler(F_TOTALE, totale_handler); - m->set_handler(F_RITFIS, ritfis_handler); - m->set_handler(F_RITSOC, ritsoc_handler); - m->set_handler(F_CORRLIRE, corrlire_handler); - m->set_handler(F_CORRVALUTA, corrvaluta_handler); - m->set_handler(F_CODIVA, main_codiva_handler); - m->set_handler(F_OCCASEDIT, occas_handler); - m->set_handler(F_SOLAIVA, solaiva_handler); - m->set_handler(F_SHEETIVA, iva_handler); - - TSheet_field& is = (TSheet_field&)m->field(F_SHEETIVA); - is.set_notify(iva_notify); - TMask& ism = is.sheet_mask(); - ism.set_handler(101, imponibile_handler); - ism.set_handler(102, codiva_handler); - ism.set_handler(103, detrazione_handler); - ism.set_handler(104, imposta_handler); - ism.set_handler(109, iva_sottoconto_handler); - ism.set_handler(209, sheet_clifo_handler); - ism.set_handler(309, sheet_clifo_handler); -} -_iva_showed = FALSE; - case 1: -{ - m->set_handler(F_DATAREG, datareg_handler); - m->set_handler(F_DATACOMP, datacomp_handler); - m->set_handler(F_DESCR, descr_handler); - m->set_handler(F_CODCAUS, caus_modify_handler); - m->set_handler(F_SHEETCG, cg_handler); - m->set_handler(F_CAMBIO, cambio_handler); - m->set_handler(F_VISVAL, visval_handler); - - TSheet_field& cg = (TSheet_field&)m->field(F_SHEETCG); - cg.set_notify(cg_notify); - TMask& cgm = cg.sheet_mask(); - cgm.set_handler(101, dareavere_handler); - cgm.set_handler(102, dareavere_handler); - cgm.set_handler(105, cg_conto_handler); - cgm.set_handler(106, suspended_handler); - cgm.set_handler(206, sheet_clifo_handler); - cgm.set_handler(306, sheet_clifo_handler); - cgm.set_handler(112, suspended_handler); - cgm.set_handler(113, suspended_handler); - cgm.set_handler(213, sheet_clifo_handler); - cgm.set_handler(313, sheet_clifo_handler); -} -break; - case 3: - m->set_handler(O_CODICE, occas_code_handler); - break; -default: -CHECKD(0, "Che cavolo di maschera e' la ", n); -break; -} - -return _msk[n] = m; -} - - -bool TPrimanota_application::user_create() -{ - _tabcom = new TLocalisamfile(LF_TABCOM); - _tab = new TLocalisamfile(LF_TAB); - _caus = new TLocalisamfile(LF_CAUSALI); - _rcaus = new TLocalisamfile(LF_RCAUSALI); - _clifo = new TLocalisamfile(LF_CLIFO); - _pcon = new TLocalisamfile(LF_PCON); - _attiv = new TLocalisamfile(LF_ATTIV); - _saldo = new TLocalisamfile(LF_SALDI); - _comuni = new TLocalisamfile(LF_COMUNI); - _occas = new TLocalisamfile(LF_OCCAS); - _nditte = new TLocalisamfile(LF_NDITTE); - - _rel = new TMovimentoPN; - _rel->add(LF_PARTITE, "NREG=NUMREG", 2); - - _causale = new TCausale(); - _giornale = new TLibro_giornale(); - - set_search_field(F_NUMREG); // Set field for default search - load_mask(0); - - return TRUE; -} - - -bool TPrimanota_application::save_and_new() const -{ return _savenew; } - - -bool TPrimanota_application::user_destroy() -{ - for (int m = 3; m >= 0; m--) - if (_msk[m] != NULL) delete _msk[m]; - - delete _giornale; - delete _causale; - delete _rel; - delete _nditte; - delete _occas; - delete _comuni; - delete _saldo; - delete _attiv; - delete _pcon; - delete _clifo; - delete _rcaus; - delete _caus; - delete _tab; - delete _tabcom; - - return TRUE; -} - -// Legge la causale di codice cod ed il relativo registro dell'anno year -// Certified 99% -bool TPrimanota_application::read_caus(const char* cod, int year) -{ - bool ok = TRUE; - - if (cod != NULL) - ok = causale().read(cod, year); - - bool nob = FALSE, dob = FALSE, sal = FALSE; - TipoIVA iva = nessuna_iva; - - if (ok) - { - sal = gestione_saldaconto() && causale().saldaconto(); - dob = sal | causale().data_doc(); - nob = sal | causale().num_doc(); - iva = causale().iva(); - } - - TMask* m = _msk[iva == nessuna_iva ? 1 : 2]; - if (m == NULL) return TRUE; - - const bool ins = m->insert_mode(); - - m->efield(F_NUMDOC).check_type(nob ? CHECK_REQUIRED : CHECK_NORMAL); // Num. doc. obbligatorio - m->efield(F_DATADOC).check_type(dob ? CHECK_REQUIRED : CHECK_NORMAL); // Data doc. obbligatoria - - if (iva != nessuna_iva) - { - m->efield(F_CODPAG).check_type(sal ? CHECK_REQUIRED : CHECK_NORMAL);// Cod. pag. obbligatorio - const bool av = causale().reg().agenzia_viaggi(); - m->show(F_DATA74TER, av); - if (!av) m->reset(F_DATA74TER); - - m->show(F_ANNORIF, sal); // Mostra/nasconde anno e riferimento partita - m->show(F_NUMRIF, sal); - m->enable(F_ANNORIF, ins); // Dis/abilita anno e riferimento partita - m->enable(F_NUMRIF, ins); - - if (ins) - { - const long protiva = causale().reg().protocol() + 1; - m->set(F_PROTIVA, protiva); // Aggiorna protocollo IVA - } - } - - if (ins && !ci_sono_importi()) - { - cgs().reset(); - for (int i = 1; i < causale().size(); i++) - { - const TRectype* rcaus = (TRectype*)causale().objptr(i); - if (rcaus == NULL) continue; // Evita eventuali righe nulle - - const int nriga = rcaus->get_int(RCA_NRIGA); - if (nriga < 1) continue; // Considera solo righe reali (non riempimenti) - - TBill tc; causale().bill(nriga, tc); - if (tc.gruppo() < 1) continue; // Considera solo gruppi validi - - if (tc.tipo() > ' ' && tc.ok()) - { - TBill clifo(0, 0, tc.sottoconto(), tc.tipo()); - clifo.descrizione(); - if (clifo.conto() != 0) - tc = clifo; - } - - const char sezione = rcaus->get_char(RCA_SEZIONE); - const TImporto zero('D', ZERO); - const TString80 desc(causale().desc_agg(i)); - - if (nriga == 1) m->set(F_DESCR, desc); - - if (iva == nessuna_iva) - { - const int pos = set_cgs_row(-1,zero,tc,desc,' '); - if (sezione > ' ') - cgs().disable_cell(pos, sezione == 'A' ? 0 : 1); - } - else - { - if (nriga >= 2 && nriga <= 9) - continue; // Conti per IVA detraibile e non, ritenute sociali e fiscali - - const char tipo = nriga == 1 ? 'T' : ' '; - if (nriga == 1 && tc.tipo() > ' ' && tc.ok()) - m->set(tc.tipo() == 'C' ? F_CLIENTE : F_FORNITORE, tc.sottoconto()); - set_cgs_row(-1,zero,tc,desc,tipo); - } - } - fill_sheet(*m); - } - - return ok; -} - -void TPrimanota_application::print() -{ - TExternal_app stampa("cg3 -0"); - stampa.run(); -} - - -bool TPrimanota_application::changing_mask(int mode) -{ - if (mode == MODE_QUERY) - { - const bool flag = _mode != MODE_QUERY; - - if (flag && _iva != nessuna_iva && !_iva_showed) - { - WINDOW w = ivas().parent(); - show_window(w, TRUE); - set_front_window(w); - process_events(); - show_window(w, FALSE); - _iva_showed = TRUE; - } - - return flag; - } - _iva = iva_errata; - return TRUE; -} - - -TMask* TPrimanota_application::get_mask(int mode) -{ - int annoes = 0, annoiva = 0; - TString16 caus; - - _mode = mode; - - switch (mode) - { - case MODE_INS: - annoes = _msk[0]->get_int(F_ANNOES); - annoiva = _msk[0]->get_int(F_ANNOIVA); - caus = _msk[0]->get(F_CODCAUS); - break; - case MODE_MOD: - annoes = _rel->lfile().get_int("ANNOES"); - annoiva = _rel->lfile().get_int("ANNOIVA"); - caus = _rel->lfile().get("CODCAUS"); - break; - default: - return load_mask(0); - } - - if (giornale().year() != annoes) - giornale().read(annoes); - - if (caus != causale().codice() || causale().reg().year() != annoiva) - causale().read(caus, annoiva); - _iva = causale().iva(); - - return load_mask(_iva == nessuna_iva ? 1 : 2); -} - - -void TPrimanota_application::on_firm_change() -{ - _rel->lfile().last(); - _lastreg = _rel->lfile().get_long(MOV_NUMREG); // Init last registration number -} - -void TPrimanota_application::on_config_change() -{ - TConfig cnf(CONFIG_DITTA); - _ges_val = cnf.get_bool("GesVal"); - _ges_sal = cnf.get_bool("GesSal"); -} - - -void TPrimanota_application::init_mask(TMask& m) -{ - disable_menu_item(M_FILE_PRINT); - - read_caus(NULL, 0); // Setta campi obbligatori - fill_sheet(m); - - const bool valintra = causale().valintra(); - const bool corrisp = causale().corrispettivi(); - - if (_iva != nessuna_iva) - { - char clig, forg; - if (_iva == iva_acquisti) - { - forg = 's'; - clig = 'h'; - } - else - { - forg = 'h'; - clig = corrisp ? 'h' : 's'; - } - m.send_key(K_SHIFT+K_CTRL+clig, -1); // GROUP 1 (clienti) - m.send_key(K_SHIFT+K_CTRL+forg, -2); // GROUP 2 (fornitori) - if (corrisp) m.hide(F_STATOPAIV); - - // Show/Hide campi valuta: F_VALUTAINTRA, F_CAMBIOINTRA, F_CORRLIRE, F_CORRVAL (GROUP 4) - m.show(-4, valintra); - - m.show(F_CODIVA, m.mode() == MODE_INS); // Codice IVA standard - } - - // Show/Hide campi valuta: F_VALUTA, F_CAMBIO, F_VISVAL (GROUP 3) - const bool valuta = _ges_val && causale().valuta(); - m.show(-3, valuta); -} - -void TPrimanota_application::init_query_mode(TMask& m) -{ - enable_menu_item(M_FILE_PRINT); -} - - -void TPrimanota_application::fill_sheet(TMask& m) const -{ - TSheet_field& cgs = (TSheet_field&)m.field(F_SHEETCG); - for (int r = cgs.items(); r < 16; r++) cgs.row(r); - - if (_iva != nessuna_iva) - { - TSheet_field& ivas = (TSheet_field&)m.field(F_SHEETIVA); - for (r = ivas.items(); r < 16; r++) ivas.row(r); - ivas.enable_column(2, _iva == iva_acquisti); // Tipo detrazione - ivas.enable_column(4, _iva == iva_acquisti); // Tipo costo ricavo - } -} - - -// Ritorna il prossimo numero di registrazione libero -// Certified 100% -const char* TPrimanota_application::get_next_key() -{ - TToken_string k(80); - k.add(F_NUMREG); k.add(_lastreg+1); - - TMask& m = curr_mask(); - if (m.insert_mode()) - { - k.add(F_CODCAUS); k.add(m.get(F_CODCAUS)); // Ricopia causale - k.add(F_DATAREG); k.add(m.get(F_DATAREG)); // data operazione - k.add(F_DATACOMP); k.add(m.get(F_DATACOMP)); // competenza - k.add(F_DATADOC); k.add(m.get(F_DATADOC)); // documento - - if (iva() == iva_vendite) - { - const long n = m.get_long(F_NUMDOC); - if (n > 0) - { k.add(F_NUMDOC); k.add(n+1); } // incrementa numero documento - } - } - - return strcpy(__tmp_string, k); -} - - -void TPrimanota_application::init_insert_mode(TMask& m) -{ - if (iva() != nessuna_iva) - occas_mask().reset(); - - init_mask(m); - _saldi.reset(); // Inizializza saldi - _saldi.set_movprovv(_rel->lfile().get_char("PROVVIS") > ' ' ? TRUE : FALSE); - _saldi.set_movap(causale().apertura()); - _saldi.set_anno_es(m.get_int(F_ANNOES)); - _saldi.set_num_ulmov(m.get_long(F_NUMREG)); - _saldi.set_data_ulmov((TDate)m.get(F_DATAREG)); -} - - -void TPrimanota_application::init_modify_mode(TMask& m) -{ - init_mask(m); - calcola_saldo(); // Verifica eventuali sbilanci contabili - if (iva() != nessuna_iva) - calcola_imp(); // Calcola totale imponibile ed imposte -} - - -// Legge un conto da una riga contabile o iva di prima nota -bool TPrimanota_application::get_conto(const TRectype& r, TBill& c) const -{ - c.set(r.get_int("GRUPPO"), r.get_int("CONTO"), - r.get_long("SOTTOCONTO"), r.get_char("TIPOC")); - if (r.num() == LF_RMOVIVA) - c.tipo_cr(r.get_int("TIPOCR")); - return c.ok(); -} - -// Scrive un conto su una riga di proma nota -void TPrimanota_application::put_conto(TRectype& r, const TBill& c) const -{ - r.put("TIPOC", c.tipo()); - r.put("GRUPPO", c.gruppo()); - r.put("CONTO", c.conto()); - r.put("SOTTOCONTO", c.sottoconto()); -} - - -// Controlla sulla causale se il segno del totale documento (ritsoc=FALSE) -// o quello delle ritenute sociali (ritsoc=TRUE) e' invertito rispetto al normale -bool TPrimanota_application::test_swap(bool ritsoc) -{ - bool s = FALSE; - - const char sez = ritsoc ? causale().sezione_ritsoc() : causale().sezione_clifo(); - s = (iva() == iva_vendite) ^ sez == 'D'; - return s; -} - - -int TPrimanota_application::read(TMask& m) -{ - m.autoload(_rel); - - cgs().reset(); - - if (_iva != nessuna_iva) - { - ivas().reset(); - - const TString16 occode(_rel->lfile().get("OCFPI")); - occas_mask().set(O_CODICE, occode); - - const char clifo = _rel->lfile().get_char("TIPO"); - if (_iva == iva_acquisti && clifo == 'C') - error_box("Registrazione di acquisto attribuita ad un cliente"); else - if (_iva == iva_vendite && clifo == 'F') - error_box("Registrazione di vendita attribuita ad un fornitore"); - } - - // Inizializza cambio - real cambio(_rel->lfile().get("CAMBIO")); - if (cambio < 1.0) cambio = 1.0; - m.set_exchange(FALSE, cambio); - - _saldi.reset(); // Azzera saldi - _saldi.set_movprovv(_rel->lfile().get_bool("PROVVIS")); - _saldi.set_movap(causale().apertura()); - _saldi.set_anno_es(m.get_int(F_ANNOES)); - _saldi.set_num_ulmov(m.get_long(F_NUMREG)); - _saldi.set_data_ulmov((TDate)m.get(F_DATAREG)); - - TToken_string riga(255); - - for (int i = 0; i < _rel->cg_items(); i++) - { - const TRectype& r = _rel->cg(i); - riga.cut(0); // Vuota la riga - - const char sezione = toupper(r.get_char("SEZIONE")); - const real im(r.get_real("IMPORTO")); - - TImporto import(sezione, im); - import.add_to(riga); // Dare/Avere 101-102 - - TConto conto; get_conto(r, conto); - riga.add(conto.string(0x3)); // Conto 103-107 - if (conto.ok()) - _saldi.aggiorna(conto, im, sezione, FALSE); - - riga.add(""); // Codice descrizione 108 - riga.add(r.get("DESCR")); // Descrizione riga 109 - - conto.set(r.get_int("GRUPPOC"), r.get_int("CONTOC"), - r.get_long("SOTTOCONTC"), r.get_char("TIPOCC")); - riga.add(conto.string(0x3)); // Contropartita 110-114 - - const char tipo = r.get_char("ROWTYPE"); - riga.add(tipo); // Tipo di riga 115 - - cgs().row(i) = riga; - disable_cgs_cells(i, tipo); - } - - if (_iva == nessuna_iva) - return _rel->status(); - - const bool solaiva = i == 0; - m.set(F_SOLAIVA, solaiva ? "X" : " "); - m.field(F_SOLAIVA).on_hit(); - - const bool to_swap = test_swap(FALSE); - if (to_swap) - { - real totdoc(m.get(F_TOTALE)); - totdoc = -totdoc; - m.set(F_TOTALE, totdoc.string()); - } - for (i = 0; i < _rel->iva_items(); i++) - { - TRectype& r = _rel->iva(i); - riga.cut(0); - - real imponibile(r.get("IMPONIBILE")); - if (to_swap) imponibile = -imponibile; - riga.add(imponibile.string()); // Imponibile 101 - - riga.add(r.get("CODIVA")); // IVA 102 - riga.add(r.get("TIPODET")); // Detrazione 103 - - - real imposta(r.get("IMPOSTA")); - if (to_swap) imposta = -imposta; - if (imponibile.sign() * imposta.sign() < 0) - { - warning_box("Registrazione con imponibile e imposta con segni discordi:\n" - "assegnato il segno dell'imponibile"); - imposta = -imposta; - } - riga.add(imposta.string()); // Imposta 104 - - TBill c; get_conto(r, c); - c.add_to(riga, 4, 0x7); // Conto 105-110 - - ivas().row(i) = riga; - } - - return _rel->status(); -} - - -// Trasferisce i dati da maschera a movimento di prima nota -void TPrimanota_application::mask2rel(const TMask& m) -{ - _rel->lfile().zero(); - m.autosave(_rel); - - const long numreg = m.get_long(F_NUMREG); - const TDate datareg(m.get(F_DATAREG)); - const int annoes = m.get_int(F_ANNOES); - - _saldi.set_movprovv(m.get_bool(F_PROVVISORIO)); - _saldi.set_movap(causale().apertura()); - _saldi.set_anno_es(annoes); - - _rel->destroy_rows(); // Destroy all records - cgs_pack(); // Destroy all null rows - - TArray& rows = cgs().rows_array(); - - // Controlla se e' un movimento con righe contabili - if (iva() == nessuna_iva || !m.get_bool(F_SOLAIVA)) - { - for (int i = 0; i < rows.items(); i++) - { - TToken_string& row = (TToken_string&)rows[i]; - - TImporto n; n = row; - const TConto conto(row, 2, 0x3); - _saldi.aggiorna(conto, n.valore(), n.sezione(), TRUE); - - TRectype &r = _rel->cg(i); - r.zero(); - - r.put("NUMREG", numreg); // Numero registrazione - r.put("ANNOES", annoes); // Anno esercizio - r.put("DATAREG", datareg); // Data di registrazione - r.put("NUMRIG", i+1); // Numero riga - - r.put("SEZIONE", n.sezione()); // Sezione - r.put("IMPORTO", n.valore()); // Importo - put_conto(r, conto); // Conto - - row.get(); // Codice descrizione - r.put("DESCR", row.get()); // Descrizione riga - - r.put("TIPOCC", row.get()); // Contropartita - r.put("GRUPPOC", row.get()); - r.put("CONTOC", row.get()); - r.put("SOTTOCONTC", row.get()); - row.get(); // Descrizione contropartita - - r.put("ROWTYPE", row.get()); // Tipo riga - } - } - if (_iva == nessuna_iva) return; - - if (causale().corrispettivi()) - { - TRectype& rec = _rel->lfile().curr(); - rec.put("TIPO", ""); - rec.put("CODCF", ""); // Azzera il cliente nei movimenti dei corrispettivi - } - else - { - _rel->lfile().put("TIPO", clifo()); - - int err = ~NOERR; - if (m.get_bool(F_OCCASIONALE)) - { - TRelation occas(LF_OCCAS); - const TMask& om = occas_mask(); - om.autosave(&occas); - - err = occas.write(); - if (err == _isreinsert) - err = occas.rewrite(); - - if (err == NOERR) - _rel->lfile().put("OCFPI", occas_mask().get(O_CODICE)); - else - error_box("Errore di scrittura sul file dei clienti/fornitori occasionali: %d", err); - } - if (err) _rel->lfile().zero("OCFPI"); - } - - const bool intra = causale().intra(); - const bool to_swap = test_swap(FALSE); - if (to_swap) - { - real totale = _rel->lfile().get("TOTDOC"); - totale = -totale; - _rel->lfile().put("TOTDOC", totale); - } - - TArray& irows = ivas().rows_array(); - for (int i = 0; i < irows.items(); i++) - { - TToken_string& row = (TToken_string&)irows[i]; - if (row.empty_items()) - continue; - - TRectype &r = _rel->iva(i); - r.zero(); - r.put("ANNOES", annoes); - r.put("NUMREG", numreg); - r.put("INTRA", intra); // Causale intra - r.put("NUMRIG", i+1); - - real imponibile(row.get(0)); - if (to_swap) imponibile = -imponibile; - r.put("IMPONIBILE", imponibile); - - r.put("CODIVA", row.get()); - r.put("TIPODET", row.get()); - - real imposta(row.get()); - if (to_swap) imposta = -imposta; - r.put("IMPOSTA", imposta); - - r.put("TIPOCR", row.get()); - - const TBill c(row, -1, 0x1); - const int rimp = bill2pos(c, 'I')+1; - r.put("RIGAIMP", rimp); - put_conto(r, c); - } -} - - -int TPrimanota_application::write(const TMask& m) -{ - const long numreg = m.get_long(F_NUMREG); - if (numreg > _lastreg) _lastreg = numreg; // Aggiorna ultima registrazione - - mask2rel(m); - const int err = _rel->write(TRUE); - if (err == NOERR) - { - _saldi.registra(); - - if (iva() != nessuna_iva) - { - causale().reg().reread(); // Aggiorna protocollo IVA - if (!gestione_saldaconto() && !m.get_bool(F_SOLAIVA)) - { - const TString16 causimm(causale().causale_inc_imm()); - if (causimm.not_empty()) - genera_incasso(causimm); - } - } - - if (gestione_saldaconto() && causale().saldaconto()) - aggiorna_scadenzario(m); - } - return err; -} - - -int TPrimanota_application::rewrite(const TMask& m) -{ - mask2rel(m); - const int err = _rel->rewrite(TRUE); - if (err == NOERR) - _saldi.registra(); - if (gestione_saldaconto() && causale().saldaconto()) - aggiorna_scadenzario(m); - return err; -} - - -bool TPrimanota_application::remove() -{ - const bool ok = TRelation_application::remove(); - if (ok) - _saldi.registra(); - return ok; -} - - -HIDDEN bool incasso_handler(TMask_field& f, KEY k) -{ - if (k == K_ENTER) - { - TMask& m = f.mask(); - TImporto tot(m.get(I_SEZIONE1)[0], (real)m.get(F_TOTALE)); - - for (int i = 2; i < 5; i++) - { - const int sid = i == 2 ? I_SEZIONE2 : (i == 3 ? I_SEZIONE3 : I_SEZIONE4); - const real val(m.get(sid+1)); - const TImporto imp(m.get(sid)[0], val); - tot += imp; - } - if (tot.valore() != ZERO) - return f.error_box("Il movimento e' sbilaciato di %s", tot.valore().string(".")); - } - return TRUE; -} - - -void TPrimanota_application::genera_incasso(const char* causimm) -{ - TMask m("cg2100i"); - if (iva() == iva_acquisti) m.set_caption("Movimento di pagamento immediato"); - - m.set_handler(F_DATAREG, datareg_handler); - m.set_handler(F_DATACOMP, datacomp_handler); - m.set_handler(F_TOTALE, incasso_handler); - - TCausale caus(causimm); // Causale da usare - - if (caus.data_doc()) m.efield(F_DATADOC).check_type(CHECK_REQUIRED); - if (caus.num_doc()) m.efield(F_NUMDOC).check_type(CHECK_REQUIRED); - - m.set(F_DATAREG, curr_mask().get(F_DATAREG)); - m.set(F_DATACOMP, curr_mask().get(F_DATACOMP)); - m.set(F_DATADOC, curr_mask().get(F_DATADOC)); - m.set(F_NUMDOC, curr_mask().get(F_NUMDOC)); - m.set(F_NUMREG, _lastreg+1); // Incrementa numero di registrazione - m.set(F_DESCR, caus.desc_agg(1)); // Descrizione - m.set(F_CODCAUS, causimm); // Cambia causale - m.set(F_DESCRCAUS, caus.descrizione()); - - m.set(I_SEZIONE1, caus.sezione_clifo() == 'D' ? "D" : "A"); - m.set(F_TOTALE, curr_mask().get(F_TOTALE)); - - m.set(F_CLIFO, _rel->cg(0).get("TIPOC")); - m.set(F_GRUPPOCLIFO, _rel->cg(0).get("GRUPPO")); - m.set(F_CONTOCLIFO, _rel->cg(0).get("CONTO")); - const TString& clifo = _rel->cg(0).get("SOTTOCONTO"); - m.set(F_CLIENTE, clifo); m.set(F_FORNITORE, clifo); m.set(I_SOTTOCONTO, clifo); - - TBill conto; caus.bill(2, conto); // Conto della seconda riga della causale - m.set(I_SEZIONE2, caus.sezione_clifo() == 'D' ? "A" : "D"); - m.set(I_IMPORTO2, curr_mask().get(F_TOTALE)); - m.set(I_GRUPPO2, conto.gruppo()); - m.set(I_CONTO2, conto.conto()); - m.set(I_SOTTOCONTO2, conto.sottoconto()); - - if (m.run() == K_SAVE) - { - TMovimentoPN inc; // Nuovo movimento di incasso immediato - - m.autosave(&inc); - inc.lfile().put("TIPODOC", caus.tipo_doc()); // Tipo documento - inc.lfile().put("REG", caus.reg().name()); // Registro - - const int annoes = m.get_int(F_ANNOES); - const TString16 datareg = m.get(F_DATAREG); - long num = m.get_long(F_NUMREG); - - TRectype& r = inc.cg(0); - r.zero(); - r.put("NUMREG", num); - r.put("NUMRIG", 1); - r.put("DATAREG", datareg); - r.put("ANNOES", annoes); - r.put("SEZIONE", m.get(I_SEZIONE1)); - r.put("IMPORTO", m.get(F_TOTALE)); - r.put("TIPOC", m.get(F_CLIFO)); - r.put("GRUPPO", m.get(F_GRUPPOCLIFO)); - r.put("CONTO", m.get(F_CONTOCLIFO)); - - short clifo_id; - switch (m.get(F_CLIFO)[0]) - { - case 'C': - clifo_id = F_CLIENTE; break; - case 'F': - clifo_id = F_FORNITORE; break; - default : - clifo_id = I_SOTTOCONTO; break; - } - r.put("SOTTOCONTO", m.get(clifo_id)); - r.put("DESCR", m.get(F_DESCR)); - r.put("TIPOCC", " "); - r.put("GRUPPOC", m.get(I_GRUPPO2)); - r.put("CONTOC", m.get(I_CONTO2)); - r.put("SOTTOCONTC", m.get(I_SOTTOCONTO2)); - - r.put("ROWTYPE", " "); - - for (int i = 2; i < 5; i++) - { - const int sid = i == 2 ? I_SEZIONE2 : (i == 3 ? I_SEZIONE3 : I_SEZIONE4); - const char* imp = m.get(sid+1); - if (*imp == '\0') break; - - TRectype& r = inc.cg(i-1); - r.zero(); - r.put("IMPORTO", imp); - r.put("NUMREG", num); - r.put("NUMRIG", i); - r.put("DATAREG", datareg); - r.put("ANNOES", annoes); - r.put("SEZIONE", m.get(sid)); - r.put("TIPOC", ' '); - r.put("GRUPPO", m.get(sid+2)); - r.put("CONTO", m.get(sid+3)); - r.put("SOTTOCONTO", m.get(sid+4)); - if (i == 2) - r.put("DESCR", caus.desc_agg(2)); - - r.put("TIPOCC", m.get(F_CLIFO)); - r.put("GRUPPOC", m.get(F_GRUPPOCLIFO)); - r.put("CONTOC", m.get(F_CONTOCLIFO)); - r.put("SOTTOCONTC", m.get(clifo_id)); - - r.put("ROWTYPE", " "); - } - - while (inc.write() == _isreinsert) // In caso di riscrittura - { - num++; // Incrementa numero registrazione - inc.lfile().put("NUMREG", num); - } - - if (inc.good()) - { - if (num > _lastreg) _lastreg = num; - - _saldi.reset(); // Inizializza saldi - _saldi.set_movprovv(FALSE); - _saldi.set_movap(FALSE); - _saldi.set_anno_es(m.get_int(F_ANNOES)); - _saldi.set_num_ulmov(_lastreg); - _saldi.set_data_ulmov((TDate)m.get(F_DATAREG)); - for (int r = 0; r < i; r++) - { - const TRectype& rec = inc.cg(r); - TConto c; get_conto(rec, c); - const real im(rec.get("IMPORTO")); - const char sezione = rec.get_char("SEZIONE"); - _saldi.aggiorna(c, im, sezione, TRUE); - } - _saldi.registra(); - } - } -} - - -int cg2100 (int argc, char** argv) -{ - TPrimanota_application a; - a.run(argc, argv, "Prima nota"); - return 0; -} +#include +#include +#include +#include +#include + +#include "cg2100.h" +#include "cg2102.h" + +// Nomi dei campi +#include +#include +#include + +TPrimanota_application::TPrimanota_application() +: _rel(NULL), _lastreg(0), _mode(0), _iva(nessuna_iva), _causale(NULL), _giornale(NULL) +{ + memset(_msk, 0, sizeof(_msk)); +} + + +TMask* TPrimanota_application::load_mask(int n) +{ + if (_msk[n] != NULL) + return _msk[n]; + + if (n == 1 || n == 2) + { + const int d = 3-n; + if (_msk[d] != NULL) + { + delete _msk[d]; + _msk[d] = NULL; + } + } + + TFilename name("cg2100"); name << char(n == 3 ? 'o' : 'a'+n); + TMask* m = new TMask(name); + + switch (n) + { + case 0: + { + m->set_handler(F_NUMREG, num_handler); + m->set_handler(F_CODCAUS, caus_query_handler); + m->set_handler(F_DATAREG, datareg_handler); + m->set_handler(F_DATACOMP, datacomp_handler); + + TConfig c(CONFIG_STUDIO, "cg"); + const bool dr = c.get_bool("PoCuDr"); // Scelta primo campo col focus + m->first_focus(dr ? F_DATAREG : F_CODCAUS); + + _savenew = !c.get_bool("Cg21SN"); + } + break; + case 2: +{ + m->set_handler(F_DATADOC, doc_handler); + m->set_handler(F_NUMDOC, doc_handler); + m->set_handler(F_DATA74TER, data74ter_handler); + m->set_handler(F_PROTIVA, protiva_handler); + m->set_handler(F_CLIENTE, clifo_handler); + m->set_handler(F_FORNITORE, clifo_handler); + m->set_handler(F_TOTALE, totale_handler); + m->set_handler(F_RITFIS, ritfis_handler); + m->set_handler(F_RITSOC, ritsoc_handler); + m->set_handler(F_CORRLIRE, corrlire_handler); + m->set_handler(F_CORRVALUTA, corrvaluta_handler); + m->set_handler(F_CODIVA, main_codiva_handler); + m->set_handler(F_OCCASEDIT, occas_handler); + m->set_handler(F_SOLAIVA, solaiva_handler); + m->set_handler(F_SHEETIVA, iva_handler); + + TSheet_field& is = (TSheet_field&)m->field(F_SHEETIVA); + is.set_notify(iva_notify); + TMask& ism = is.sheet_mask(); + ism.set_handler(101, imponibile_handler); + ism.set_handler(102, codiva_handler); + ism.set_handler(103, detrazione_handler); + ism.set_handler(104, imposta_handler); + ism.set_handler(109, iva_sottoconto_handler); + ism.set_handler(209, sheet_clifo_handler); + ism.set_handler(309, sheet_clifo_handler); +} +_iva_showed = FALSE; + case 1: +{ + m->set_handler(F_DATAREG, datareg_handler); + m->set_handler(F_DATACOMP, datacomp_handler); + m->set_handler(F_DESCR, descr_handler); + m->set_handler(F_CODCAUS, caus_modify_handler); + m->set_handler(F_SHEETCG, cg_handler); + m->set_handler(F_CAMBIO, cambio_handler); + m->set_handler(F_VISVAL, visval_handler); + + TSheet_field& cg = (TSheet_field&)m->field(F_SHEETCG); + cg.set_notify(cg_notify); + TMask& cgm = cg.sheet_mask(); + cgm.set_handler(101, dareavere_handler); + cgm.set_handler(102, dareavere_handler); + cgm.set_handler(105, cg_conto_handler); + cgm.set_handler(106, suspended_handler); + cgm.set_handler(206, sheet_clifo_handler); + cgm.set_handler(306, sheet_clifo_handler); + cgm.set_handler(112, suspended_handler); + cgm.set_handler(113, suspended_handler); + cgm.set_handler(213, sheet_clifo_handler); + cgm.set_handler(313, sheet_clifo_handler); +} +break; + case 3: + m->set_handler(O_CODICE, occas_code_handler); + break; +default: +CHECKD(0, "Che cavolo di maschera e' la ", n); +break; +} + +return _msk[n] = m; +} + + +bool TPrimanota_application::user_create() +{ + _tabcom = new TLocalisamfile(LF_TABCOM); + _tab = new TLocalisamfile(LF_TAB); + _caus = new TLocalisamfile(LF_CAUSALI); + _rcaus = new TLocalisamfile(LF_RCAUSALI); + _clifo = new TLocalisamfile(LF_CLIFO); + _pcon = new TLocalisamfile(LF_PCON); + _attiv = new TLocalisamfile(LF_ATTIV); + _saldo = new TLocalisamfile(LF_SALDI); + _comuni = new TLocalisamfile(LF_COMUNI); + _occas = new TLocalisamfile(LF_OCCAS); + _nditte = new TLocalisamfile(LF_NDITTE); + + _rel = new TMovimentoPN; + _rel->add(LF_PARTITE, "NREG=NUMREG", 2); + + _causale = new TCausale(); + _giornale = new TLibro_giornale(); + + set_search_field(F_NUMREG); // Set field for default search + load_mask(0); + + return TRUE; +} + + +bool TPrimanota_application::save_and_new() const +{ return _savenew; } + + +bool TPrimanota_application::user_destroy() +{ + for (int m = 3; m >= 0; m--) + if (_msk[m] != NULL) delete _msk[m]; + + delete _giornale; + delete _causale; + delete _rel; + delete _nditte; + delete _occas; + delete _comuni; + delete _saldo; + delete _attiv; + delete _pcon; + delete _clifo; + delete _rcaus; + delete _caus; + delete _tab; + delete _tabcom; + + return TRUE; +} + +// Legge la causale di codice cod ed il relativo registro dell'anno year +// Certified 99% +bool TPrimanota_application::read_caus(const char* cod, int year) +{ + bool ok = TRUE; + + if (cod != NULL) + ok = causale().read(cod, year); + + bool nob = FALSE, dob = FALSE, sal = FALSE; + TipoIVA iva = nessuna_iva; + + if (ok) + { + sal = gestione_saldaconto() && causale().saldaconto(); + dob = sal | causale().data_doc(); + nob = sal | causale().num_doc(); + iva = causale().iva(); + } + + TMask* m = _msk[iva == nessuna_iva ? 1 : 2]; + if (m == NULL) return TRUE; + + const bool ins = m->insert_mode(); + + m->efield(F_NUMDOC).check_type(nob ? CHECK_REQUIRED : CHECK_NORMAL); // Num. doc. obbligatorio + m->efield(F_DATADOC).check_type(dob ? CHECK_REQUIRED : CHECK_NORMAL); // Data doc. obbligatoria + + if (iva != nessuna_iva) + { + m->efield(F_CODPAG).check_type(sal ? CHECK_REQUIRED : CHECK_NORMAL);// Cod. pag. obbligatorio + const bool av = causale().reg().agenzia_viaggi(); + m->show(F_DATA74TER, av); + if (!av) m->reset(F_DATA74TER); + + m->show(F_ANNORIF, sal); // Mostra/nasconde anno e riferimento partita + m->show(F_NUMRIF, sal); + m->enable(F_ANNORIF, ins); // Dis/abilita anno e riferimento partita + m->enable(F_NUMRIF, ins); + + if (ins) + { + const long protiva = causale().reg().protocol() + 1; + m->set(F_PROTIVA, protiva); // Aggiorna protocollo IVA + } + } + + if (ins && !ci_sono_importi()) + { + cgs().reset(); + for (int i = 1; i < causale().size(); i++) + { + const TRectype* rcaus = (TRectype*)causale().objptr(i); + if (rcaus == NULL) continue; // Evita eventuali righe nulle + + const int nriga = rcaus->get_int(RCA_NRIGA); + if (nriga < 1) continue; // Considera solo righe reali (non riempimenti) + + TBill tc; causale().bill(nriga, tc); + if (tc.gruppo() < 1) continue; // Considera solo gruppi validi + + if (tc.tipo() > ' ' && tc.ok()) + { + TBill clifo(0, 0, tc.sottoconto(), tc.tipo()); + clifo.descrizione(); + if (clifo.conto() != 0) + tc = clifo; + } + + const char sezione = rcaus->get_char(RCA_SEZIONE); + const TImporto zero('D', ZERO); + const TString80 desc(causale().desc_agg(i)); + + if (nriga == 1) m->set(F_DESCR, desc); + + if (iva == nessuna_iva) + { + const int pos = set_cgs_row(-1,zero,tc,desc,' '); + if (sezione > ' ') + cgs().disable_cell(pos, sezione == 'A' ? 0 : 1); + } + else + { + if (nriga >= 2 && nriga <= 9) + continue; // Conti per IVA detraibile e non, ritenute sociali e fiscali + + const char tipo = nriga == 1 ? 'T' : ' '; + if (nriga == 1 && tc.tipo() > ' ' && tc.ok()) + m->set(tc.tipo() == 'C' ? F_CLIENTE : F_FORNITORE, tc.sottoconto()); + set_cgs_row(-1,zero,tc,desc,tipo); + } + } + fill_sheet(*m); + } + + return ok; +} + +void TPrimanota_application::print() +{ + TExternal_app stampa("cg3 -0"); + stampa.run(); +} + + +bool TPrimanota_application::changing_mask(int mode) +{ + if (mode == MODE_QUERY) + { + const bool flag = _mode != MODE_QUERY; + + if (flag && _iva != nessuna_iva && !_iva_showed) + { + WINDOW w = ivas().parent(); + show_window(w, TRUE); + set_front_window(w); + process_events(); + show_window(w, FALSE); + _iva_showed = TRUE; + } + + return flag; + } + _iva = iva_errata; + return TRUE; +} + + +TMask* TPrimanota_application::get_mask(int mode) +{ + int annoes = 0, annoiva = 0; + TString16 caus; + + _mode = mode; + + switch (mode) + { + case MODE_INS: + annoes = _msk[0]->get_int(F_ANNOES); + annoiva = _msk[0]->get_int(F_ANNOIVA); + caus = _msk[0]->get(F_CODCAUS); + break; + case MODE_MOD: + annoes = _rel->lfile().get_int("ANNOES"); + annoiva = _rel->lfile().get_int("ANNOIVA"); + caus = _rel->lfile().get("CODCAUS"); + break; + default: + return load_mask(0); + } + + if (giornale().year() != annoes) + giornale().read(annoes); + + if (caus != causale().codice() || causale().reg().year() != annoiva) + causale().read(caus, annoiva); + _iva = causale().iva(); + + return load_mask(_iva == nessuna_iva ? 1 : 2); +} + + +void TPrimanota_application::on_firm_change() +{ + _rel->lfile().last(); + _lastreg = _rel->lfile().get_long(MOV_NUMREG); // Init last registration number +} + +void TPrimanota_application::on_config_change() +{ + TConfig cnf(CONFIG_DITTA); + _ges_val = cnf.get_bool("GesVal"); + _ges_sal = cnf.get_bool("GesSal"); +} + + +void TPrimanota_application::init_mask(TMask& m) +{ + disable_menu_item(M_FILE_PRINT); + + read_caus(NULL, 0); // Setta campi obbligatori + fill_sheet(m); + + const bool valintra = causale().valintra(); + const bool corrisp = causale().corrispettivi(); + + if (_iva != nessuna_iva) + { + char clig, forg; + if (_iva == iva_acquisti) + { + forg = 's'; + clig = 'h'; + } + else + { + forg = 'h'; + clig = corrisp ? 'h' : 's'; + } + m.send_key(K_SHIFT+K_CTRL+clig, -1); // GROUP 1 (clienti) + m.send_key(K_SHIFT+K_CTRL+forg, -2); // GROUP 2 (fornitori) + if (corrisp) m.hide(F_STATOPAIV); + + // Show/Hide campi valuta: F_VALUTAINTRA, F_CAMBIOINTRA, F_CORRLIRE, F_CORRVAL (GROUP 4) + m.show(-4, valintra); + + m.show(F_CODIVA, m.mode() == MODE_INS); // Codice IVA standard + } + + // Show/Hide campi valuta: F_VALUTA, F_CAMBIO, F_VISVAL (GROUP 3) + const bool valuta = _ges_val && causale().valuta(); + m.show(-3, valuta); +} + +void TPrimanota_application::init_query_mode(TMask& m) +{ + enable_menu_item(M_FILE_PRINT); +} + + +void TPrimanota_application::fill_sheet(TMask& m) const +{ + TSheet_field& cgs = (TSheet_field&)m.field(F_SHEETCG); + for (int r = cgs.items(); r < 16; r++) cgs.row(r); + + if (_iva != nessuna_iva) + { + TSheet_field& ivas = (TSheet_field&)m.field(F_SHEETIVA); + for (r = ivas.items(); r < 16; r++) ivas.row(r); + ivas.enable_column(2, _iva == iva_acquisti); // Tipo detrazione + ivas.enable_column(4, _iva == iva_acquisti); // Tipo costo ricavo + } +} + + +// Ritorna il prossimo numero di registrazione libero +// Certified 100% +const char* TPrimanota_application::get_next_key() +{ + TToken_string k(80); + k.add(F_NUMREG); k.add(_lastreg+1); + + if (_rel->good()) // Not reinsert + { + TMask& m = curr_mask(); + if (m.insert_mode()) + { + k.add(F_CODCAUS); k.add(m.get(F_CODCAUS)); // Ricopia causale + k.add(F_DATAREG); k.add(m.get(F_DATAREG)); // data operazione + k.add(F_DATACOMP); k.add(m.get(F_DATACOMP)); // competenza + k.add(F_DATADOC); k.add(m.get(F_DATADOC)); // documento + + if (iva() == iva_vendite) + { + const long n = m.get_long(F_NUMDOC); + if (n > 0) + { k.add(F_NUMDOC); k.add(n+1); } // incrementa numero documento + } + } + } + + return strcpy(__tmp_string, k); +} + + +void TPrimanota_application::init_insert_mode(TMask& m) +{ + if (iva() != nessuna_iva) + occas_mask().reset(); + + init_mask(m); + _saldi.reset(); // Inizializza saldi +} + + +void TPrimanota_application::init_modify_mode(TMask& m) +{ + init_mask(m); + calcola_saldo(); // Verifica eventuali sbilanci contabili + if (iva() != nessuna_iva) + calcola_imp(); // Calcola totale imponibile ed imposte +} + + +// Legge un conto da una riga contabile o iva di prima nota +bool TPrimanota_application::get_conto(const TRectype& r, TBill& c) const +{ + c.set(r.get_int("GRUPPO"), r.get_int("CONTO"), + r.get_long("SOTTOCONTO"), r.get_char("TIPOC")); + if (r.num() == LF_RMOVIVA) + c.tipo_cr(r.get_int("TIPOCR")); + return c.ok(); +} + +// Scrive un conto su una riga di proma nota +void TPrimanota_application::put_conto(TRectype& r, const TBill& c) const +{ + r.put("TIPOC", c.tipo()); + r.put("GRUPPO", c.gruppo()); + r.put("CONTO", c.conto()); + r.put("SOTTOCONTO", c.sottoconto()); +} + + +// Controlla sulla causale se il segno del totale documento (ritsoc=FALSE) +// o quello delle ritenute sociali (ritsoc=TRUE) e' invertito rispetto al normale +bool TPrimanota_application::test_swap(bool ritsoc) +{ + bool s = FALSE; + + const char sez = ritsoc ? causale().sezione_ritsoc() : causale().sezione_clifo(); + s = (iva() == iva_vendite) ^ sez == 'D'; + return s; +} + + +int TPrimanota_application::read(TMask& m) +{ + m.autoload(_rel); + + cgs().reset(); + + if (_iva != nessuna_iva) + { + ivas().reset(); + + const TString16 occode(_rel->lfile().get("OCFPI")); + occas_mask().set(O_CODICE, occode); + + const char clifo = _rel->lfile().get_char("TIPO"); + if (_iva == iva_acquisti && clifo == 'C') + error_box("Registrazione di acquisto attribuita ad un cliente"); else + if (_iva == iva_vendite && clifo == 'F') + error_box("Registrazione di vendita attribuita ad un fornitore"); + } + + // Inizializza cambio + real cambio(_rel->lfile().get("CAMBIO")); + if (cambio < 1.0) cambio = 1.0; + m.set_exchange(FALSE, cambio); + + _saldi.reset(); // Azzera saldi + _saldi.set_movprovv(_rel->lfile().get_bool("PROVVIS")); + _saldi.set_movap(causale().apertura()); + _saldi.set_anno_es(m.get_int(F_ANNOES)); + _saldi.set_num_ulmov(m.get_long(F_NUMREG)); + _saldi.set_data_ulmov((TDate)m.get(F_DATAREG)); + + TToken_string riga(255); + + for (int i = 0; i < _rel->cg_items(); i++) + { + const TRectype& r = _rel->cg(i); + riga.cut(0); // Vuota la riga + + const char sezione = toupper(r.get_char("SEZIONE")); + const real im(r.get_real("IMPORTO")); + + TImporto import(sezione, im); + import.add_to(riga); // Dare/Avere 101-102 + + TConto conto; get_conto(r, conto); + riga.add(conto.string(0x3)); // Conto 103-107 + _saldi.aggiorna(conto, im, sezione, FALSE); + + riga.add(""); // Codice descrizione 108 + riga.add(r.get("DESCR")); // Descrizione riga 109 + + conto.set(r.get_int("GRUPPOC"), r.get_int("CONTOC"), + r.get_long("SOTTOCONTC"), r.get_char("TIPOCC")); + riga.add(conto.string(0x3)); // Contropartita 110-114 + + const char tipo = r.get_char("ROWTYPE"); + riga.add(tipo); // Tipo di riga 115 + + cgs().row(i) = riga; + disable_cgs_cells(i, tipo); + } + + if (_iva == nessuna_iva) + return _rel->status(); + + const bool solaiva = i == 0; + m.set(F_SOLAIVA, solaiva ? "X" : " "); + m.field(F_SOLAIVA).on_hit(); + + const bool to_swap = test_swap(FALSE); + if (to_swap) + { + real totdoc(m.get(F_TOTALE)); + totdoc = -totdoc; + m.set(F_TOTALE, totdoc.string()); + } + for (i = 0; i < _rel->iva_items(); i++) + { + TRectype& r = _rel->iva(i); + riga.cut(0); + + real imponibile(r.get("IMPONIBILE")); + if (to_swap) imponibile = -imponibile; + riga.add(imponibile.string()); // Imponibile 101 + + riga.add(r.get("CODIVA")); // IVA 102 + riga.add(r.get("TIPODET")); // Detrazione 103 + + + real imposta(r.get("IMPOSTA")); + if (to_swap) imposta = -imposta; + if (imponibile.sign() * imposta.sign() < 0) + { + warning_box("Registrazione con imponibile e imposta con segni discordi:\n" + "assegnato il segno dell'imponibile"); + imposta = -imposta; + } + riga.add(imposta.string()); // Imposta 104 + + TBill c; get_conto(r, c); + c.add_to(riga, 4, 0x7); // Conto 105-110 + + ivas().row(i) = riga; + } + + return _rel->status(); +} + + +// Trasferisce i dati da maschera a movimento di prima nota +void TPrimanota_application::mask2rel(const TMask& m) +{ + _rel->lfile().zero(); + m.autosave(_rel); + + const long numreg = m.get_long(F_NUMREG); + const TDate datareg(m.get(F_DATAREG)); + const int annoes = m.get_int(F_ANNOES); + + _saldi.set_movprovv(m.get_bool(F_PROVVISORIO)); + _saldi.set_movap(causale().apertura()); + _saldi.set_anno_es(annoes); + _saldi.set_num_ulmov(m.get_long(F_NUMREG)); + _saldi.set_data_ulmov((TDate)m.get(F_DATAREG)); + + _rel->destroy_rows(); // Destroy all records + cgs_pack(); // Destroy all null rows + + TArray& rows = cgs().rows_array(); + + // Controlla se e' un movimento con righe contabili + if (iva() == nessuna_iva || !m.get_bool(F_SOLAIVA)) + { + for (int i = 0; i < rows.items(); i++) + { + TToken_string& row = (TToken_string&)rows[i]; + + TImporto n; n = row; + const TConto conto(row, 2, 0x3); + _saldi.aggiorna(conto, n.valore(), n.sezione(), TRUE); + + TRectype &r = _rel->cg(i); + r.zero(); + + r.put("NUMREG", numreg); // Numero registrazione + r.put("ANNOES", annoes); // Anno esercizio + r.put("DATAREG", datareg); // Data di registrazione + r.put("NUMRIG", i+1); // Numero riga + + r.put("SEZIONE", n.sezione()); // Sezione + r.put("IMPORTO", n.valore()); // Importo + put_conto(r, conto); // Conto + + row.get(); // Codice descrizione + r.put("DESCR", row.get()); // Descrizione riga + + r.put("TIPOCC", row.get()); // Contropartita + r.put("GRUPPOC", row.get()); + r.put("CONTOC", row.get()); + r.put("SOTTOCONTC", row.get()); + row.get(); // Descrizione contropartita + + r.put("ROWTYPE", row.get()); // Tipo riga + } + } + if (_iva == nessuna_iva) return; + + if (causale().corrispettivi()) + { + TRectype& rec = _rel->lfile().curr(); + rec.put("TIPO", ""); + rec.put("CODCF", ""); // Azzera il cliente nei movimenti dei corrispettivi + } + else + { + _rel->lfile().put("TIPO", clifo()); + + int err = ~NOERR; + if (m.get_bool(F_OCCASIONALE)) + { + TRelation occas(LF_OCCAS); + const TMask& om = occas_mask(); + om.autosave(&occas); + + err = occas.write(); + if (err == _isreinsert) + err = occas.rewrite(); + + if (err == NOERR) + _rel->lfile().put("OCFPI", occas_mask().get(O_CODICE)); + else + error_box("Errore di scrittura sul file dei clienti/fornitori occasionali: %d", err); + } + if (err) _rel->lfile().zero("OCFPI"); + } + + const bool intra = causale().intra(); + const bool to_swap = test_swap(FALSE); + if (to_swap) + { + real totale = _rel->lfile().get("TOTDOC"); + totale = -totale; + _rel->lfile().put("TOTDOC", totale); + } + + TArray& irows = ivas().rows_array(); + for (int i = 0; i < irows.items(); i++) + { + TToken_string& row = (TToken_string&)irows[i]; + if (row.empty_items()) + continue; + + TRectype &r = _rel->iva(i); + r.zero(); + r.put("ANNOES", annoes); + r.put("NUMREG", numreg); + r.put("INTRA", intra); // Causale intra + r.put("NUMRIG", i+1); + + real imponibile(row.get(0)); + if (to_swap) imponibile = -imponibile; + r.put("IMPONIBILE", imponibile); + + r.put("CODIVA", row.get()); + r.put("TIPODET", row.get()); + + real imposta(row.get()); + if (to_swap) imposta = -imposta; + r.put("IMPOSTA", imposta); + + r.put("TIPOCR", row.get()); + + const TBill c(row, -1, 0x1); + const int rimp = bill2pos(c, 'I')+1; + r.put("RIGAIMP", rimp); + put_conto(r, c); + } +} + + +int TPrimanota_application::write(const TMask& m) +{ + const long numreg = m.get_long(F_NUMREG); + if (numreg > _lastreg) _lastreg = numreg; // Aggiorna ultima registrazione + + mask2rel(m); + const int err = _rel->write(TRUE); + if (err == NOERR) + { + _saldi.registra(); + + if (iva() != nessuna_iva) + { + causale().reg().reread(); // Aggiorna protocollo IVA + if (!gestione_saldaconto() && !m.get_bool(F_SOLAIVA)) + { + const TString16 causimm(causale().causale_inc_imm()); + if (causimm.not_empty()) + genera_incasso(causimm); + } + } + + if (gestione_saldaconto() && causale().saldaconto()) + aggiorna_scadenzario(m); + } + return err; +} + + +int TPrimanota_application::rewrite(const TMask& m) +{ + mask2rel(m); + const int err = _rel->rewrite(TRUE); + if (err == NOERR) + _saldi.registra(); + if (gestione_saldaconto() && causale().saldaconto()) + aggiorna_scadenzario(m); + return err; +} + + +bool TPrimanota_application::remove() +{ + const bool ok = TRelation_application::remove(); + if (ok) + _saldi.registra(); + return ok; +} + + +HIDDEN bool incasso_handler(TMask_field& f, KEY k) +{ + if (k == K_ENTER) + { + TMask& m = f.mask(); + TImporto tot(m.get(I_SEZIONE1)[0], (real)m.get(F_TOTALE)); + + for (int i = 2; i < 5; i++) + { + const int sid = i == 2 ? I_SEZIONE2 : (i == 3 ? I_SEZIONE3 : I_SEZIONE4); + const real val(m.get(sid+1)); + const TImporto imp(m.get(sid)[0], val); + tot += imp; + } + if (tot.valore() != ZERO) + return f.error_box("Il movimento e' sbilaciato di %s", tot.valore().string(".")); + } + return TRUE; +} + + +void TPrimanota_application::genera_incasso(const char* causimm) +{ + TMask m("cg2100i"); + if (iva() == iva_acquisti) m.set_caption("Movimento di pagamento immediato"); + + m.set_handler(F_DATAREG, datareg_handler); + m.set_handler(F_DATACOMP, datacomp_handler); + m.set_handler(F_TOTALE, incasso_handler); + + TCausale caus(causimm); // Causale da usare + + if (caus.data_doc()) m.efield(F_DATADOC).check_type(CHECK_REQUIRED); + if (caus.num_doc()) m.efield(F_NUMDOC).check_type(CHECK_REQUIRED); + + m.set(F_DATAREG, curr_mask().get(F_DATAREG)); + m.set(F_DATACOMP, curr_mask().get(F_DATACOMP)); + m.set(F_DATADOC, curr_mask().get(F_DATADOC)); + m.set(F_NUMDOC, curr_mask().get(F_NUMDOC)); + m.set(F_NUMREG, _lastreg+1); // Incrementa numero di registrazione + m.set(F_DESCR, caus.desc_agg(1)); // Descrizione + m.set(F_CODCAUS, causimm); // Cambia causale + m.set(F_DESCRCAUS, caus.descrizione()); + + m.set(I_SEZIONE1, caus.sezione_clifo() == 'D' ? "D" : "A"); + m.set(F_TOTALE, curr_mask().get(F_TOTALE)); + + m.set(F_CLIFO, _rel->cg(0).get("TIPOC")); + m.set(F_GRUPPOCLIFO, _rel->cg(0).get("GRUPPO")); + m.set(F_CONTOCLIFO, _rel->cg(0).get("CONTO")); + const TString& clifo = _rel->cg(0).get("SOTTOCONTO"); + m.set(F_CLIENTE, clifo); m.set(F_FORNITORE, clifo); m.set(I_SOTTOCONTO, clifo); + + TBill conto; caus.bill(2, conto); // Conto della seconda riga della causale + m.set(I_SEZIONE2, caus.sezione_clifo() == 'D' ? "A" : "D"); + m.set(I_IMPORTO2, curr_mask().get(F_TOTALE)); + m.set(I_GRUPPO2, conto.gruppo()); + m.set(I_CONTO2, conto.conto()); + m.set(I_SOTTOCONTO2, conto.sottoconto()); + + if (m.run() == K_SAVE) + { + TMovimentoPN inc; // Nuovo movimento di incasso immediato + + m.autosave(&inc); + inc.lfile().put("TIPODOC", caus.tipo_doc()); // Tipo documento + inc.lfile().put("REG", caus.reg().name()); // Registro + + const int annoes = m.get_int(F_ANNOES); + const TString16 datareg = m.get(F_DATAREG); + long num = m.get_long(F_NUMREG); + + TRectype& r = inc.cg(0); + r.zero(); + r.put("NUMREG", num); + r.put("NUMRIG", 1); + r.put("DATAREG", datareg); + r.put("ANNOES", annoes); + r.put("SEZIONE", m.get(I_SEZIONE1)); + r.put("IMPORTO", m.get(F_TOTALE)); + r.put("TIPOC", m.get(F_CLIFO)); + r.put("GRUPPO", m.get(F_GRUPPOCLIFO)); + r.put("CONTO", m.get(F_CONTOCLIFO)); + + short clifo_id; + switch (m.get(F_CLIFO)[0]) + { + case 'C': + clifo_id = F_CLIENTE; break; + case 'F': + clifo_id = F_FORNITORE; break; + default : + clifo_id = I_SOTTOCONTO; break; + } + r.put("SOTTOCONTO", m.get(clifo_id)); + r.put("DESCR", m.get(F_DESCR)); + r.put("TIPOCC", " "); + r.put("GRUPPOC", m.get(I_GRUPPO2)); + r.put("CONTOC", m.get(I_CONTO2)); + r.put("SOTTOCONTC", m.get(I_SOTTOCONTO2)); + + r.put("ROWTYPE", " "); + + for (int i = 2; i < 5; i++) + { + const int sid = i == 2 ? I_SEZIONE2 : (i == 3 ? I_SEZIONE3 : I_SEZIONE4); + const char* imp = m.get(sid+1); + if (*imp == '\0') break; + + TRectype& r = inc.cg(i-1); + r.zero(); + r.put("IMPORTO", imp); + r.put("NUMREG", num); + r.put("NUMRIG", i); + r.put("DATAREG", datareg); + r.put("ANNOES", annoes); + r.put("SEZIONE", m.get(sid)); + r.put("TIPOC", ' '); + r.put("GRUPPO", m.get(sid+2)); + r.put("CONTO", m.get(sid+3)); + r.put("SOTTOCONTO", m.get(sid+4)); + if (i == 2) + r.put("DESCR", caus.desc_agg(2)); + + r.put("TIPOCC", m.get(F_CLIFO)); + r.put("GRUPPOC", m.get(F_GRUPPOCLIFO)); + r.put("CONTOC", m.get(F_CONTOCLIFO)); + r.put("SOTTOCONTC", m.get(clifo_id)); + + r.put("ROWTYPE", " "); + } + + while (inc.write() == _isreinsert) // In caso di riscrittura + { + num++; // Incrementa numero registrazione + inc.lfile().put("NUMREG", num); + } + + if (inc.good()) + { + if (num > _lastreg) _lastreg = num; + + _saldi.reset(); // Inizializza saldi + _saldi.set_movprovv(FALSE); + _saldi.set_movap(FALSE); + _saldi.set_anno_es(m.get_int(F_ANNOES)); + _saldi.set_num_ulmov(_lastreg); + _saldi.set_data_ulmov((TDate)m.get(F_DATAREG)); + for (int r = 0; r < i; r++) + { + const TRectype& rec = inc.cg(r); + TConto c; get_conto(rec, c); + const real im(rec.get("IMPORTO")); + const char sezione = rec.get_char("SEZIONE"); + _saldi.aggiorna(c, im, sezione, TRUE); + } + _saldi.registra(); + } + } +} + + +int cg2100 (int argc, char** argv) +{ + TPrimanota_application a; + a.run(argc, argv, "Prima nota"); + return 0; +} diff --git a/cg/cg2101.cpp b/cg/cg2101.cpp index 22375c46a..a3775a57d 100755 --- a/cg/cg2101.cpp +++ b/cg/cg2101.cpp @@ -1,323 +1,330 @@ -#include - -#include -#include -#include - -#include "cg2101.h" -#include "cg2103.h" - -#include -#include -#include - - -// Calcola l'anno di esercizio di una data -// Certified 99% -int date2esc(const TDate& d, int* prevesc) -{ - if (prevesc) *prevesc = 0; - TTable esc("ESC"); - for (int err = esc.first(); err == NOERR; err = esc.next()) - { - const TDate ia(esc.get("D0")); // Data inizio esercizio - const TDate fa(esc.get("D1")); // Data fine esercizio - TString16 sanno(esc.get("CODTAB")); sanno.cut(4); - const int anno = atoi(sanno); - if (d >= ia && d <= fa) - return anno; - if (prevesc) *prevesc = anno; - } - return 0; -} - -/////////////////////////////////////////////////////////// -// Movimento di prima nota -/////////////////////////////////////////////////////////// - -TMovimentoPN::TMovimentoPN() -: TRelation(LF_MOV), _oldcg(0), _oldiva(0) -{ - add(LF_RMOV, "NUMREG=NUMREG"); - add(LF_RMOVIVA, "NUMREG=NUMREG"); -} - -void TMovimentoPN::destroy_rows() -{ - _cg.destroy(); - _iva.destroy(); -} - - -TRectype& TMovimentoPN::cg(int i) -{ - TRectype* r = (TRectype*)_cg.objptr(i); - if (r == NULL) - { - r = new TRectype(LF_RMOV); - _cg.add(r, i); - } - return *r; -} - -TRectype& TMovimentoPN::iva(int i) -{ - TRectype* r = (TRectype*)_iva.objptr(i); - if (r == NULL) - { - r = new TRectype(LF_RMOVIVA); - _iva.add(r, i); - } - return *r; -} - - -int TMovimentoPN::read_mov_rows() -{ - const TLocalisamfile& rm = lfile(LF_RMOV); - const TLocalisamfile& ri = lfile(LF_RMOVIVA); - position_rels(); - - destroy_rows(); - for(bool ok = is_first_match(LF_RMOV); ok; ok = next_match(LF_RMOV)) - { - const int row = rm.get_int(RMV_NUMRIG) - 1; - cg(row) = rm.curr(); - } - _oldcg = cg_items(); - - for(ok = is_first_match(LF_RMOVIVA); ok; ok = next_match(LF_RMOVIVA)) - { - const int row = ri.get_int(RMI_NUMRIG) - 1; - iva(row) = ri.curr(); - } - _oldiva = iva_items(); - - return NOERR; -} - - -int TMovimentoPN::read(TIsamop op, TReclock lockop, TDate& atdate) -{ - int err = file().read(op, lockop, atdate); - if (err == NOERR) - { - _olddate = file().get("DATAREG"); - err = read_mov_rows(); - } - return err; -} - - -int TMovimentoPN::write_rec(bool re, const TRectype& rec, TLocalisamfile& f) -{ - const bool scrivi = re ? (f.rewrite(rec) != NOERR) : TRUE; - if (scrivi) - f.write(rec); - - return f.status(); -} - - -int TMovimentoPN::cancella(TLocalisamfile& f, int da, int a) -{ - const long numreg = lfile().get_long(MOV_NUMREG); - for (int i = da; i <= a; i++) - { - f.put(MOV_NUMREG, numreg); - f.put(RMV_NUMRIG, i); - if (f.read(_isequal, _lock) == NOERR) - f.remove(); - } - return f.status(); -} - -char TMovimentoPN::frequenza_versamenti(int year) const -{ - static int last_year = 0; - static char last_freq = ' '; - - if (year != last_year) - { - TString16 key; - key << year; - TTable lia("LIA"); - lia.setkey(1); - lia.put("CODTAB", key); - if (lia.read() != NOERR) - { - TLocalisamfile nditte(LF_NDITTE); - nditte.setkey(1); - nditte.put("CODDITTA", main_app().get_firm()); - nditte.read(); - last_freq = nditte.get_char("FREQVIVA"); - } - else - last_freq = lia.get_char("S7"); - CHECK(last_freq == 'M' || last_freq == 'T', "Frequenza versamenti IVA assurda"); - } - - return last_freq; -} - -int TMovimentoPN::date2liq(const TDate& data) const -{ - const int anno = data.year(); - int mese = data.month(); - if (frequenza_versamenti(anno) == 'T') - mese += 2 - ((mese-1) % 3); - return mese; -} - - -bool TMovimentoPN::controlla_liquidazione(const TDate& data, bool reset) const -{ - bool calcolata = FALSE; - - const int anno = data.year(); - const int mese = date2liq(data); - - // Chiave di LIM: Anno (1-4), Mese (5-6) - TString16 key; - key << anno << mese; - TTable lim("LIM"); - lim.setkey(1); - lim.put("CODTAB", key); - if (lim.read() == NOERR) - calcolata = lim.get_bool("B1"); // Controlla se calcolata in definitivo - - if (reset && lim.get_bool("B0")) - { - // Resetta i flag di calcolato sulla liquidazione IVA del mese di registrazione - lim.put("B0", FALSE); // calcolato - lim.put("B1", FALSE); // definitivo - lim.rewrite(); - } - - return calcolata; -} - - -int TMovimentoPN::registra(bool re, bool force) -{ - TLocalisamfile& m = lfile(); - - const int err = write_rec(re, m.curr(), m); - if (err != NOERR) return err; - - TLocalisamfile& rm = lfile(LF_RMOV); - TLocalisamfile& ri = lfile(LF_RMOVIVA); - - const long numreg = m.get_long("NUMREG"); - - for (int i = 0 ; i < cg_items(); i++) - { - if (!re) cg(i).put("NUMREG", numreg); - const int err = write_rec(re, cg(i), rm); - if (!force && err != NOERR) return err; - } - if (i < _oldcg) - cancella(rm, i+1, _oldcg); - _oldcg = cg_items(); - - - const int annoiva = m.get_int("ANNOIVA"); - const TString16 reg(m.get("REG")); - TRegistro registro(reg, annoiva); - const bool att_mista = reg.empty() ? FALSE : registro.attivita_mista(); - - for (i = 0 ; i < iva_items(); i++) - { - TRectype& r = iva(i); - - if (!re) r.put("NUMREG", numreg); // Force correct number - - int tipoatt = 1; - if (att_mista) - { - const char tipo = r.get_char("TIPOC"); - if (tipo <= ' ') - { - TBill c(r.get_int("GRUPPO"), r.get_int("CONTO"), r.get_long("SOTTOCONTO")); - tipoatt = c.tipo_att(); - } - } - r.put("TIPOATT", tipoatt); - - const int err = write_rec(re, r, ri); - if (!force && err != NOERR) return err; - } - - if (i < _oldiva) - cancella(ri, i+1, _oldiva); - _oldiva = iva_items(); - - // Aggiorna data registrazione e protocollo IVA sul registro - const TDate datareg(m.get("DATAREG")); - if (reg.not_empty()) - { - const long protiva = m.get_long("PROTIVA"); - const long uprotiva = m.get_long("UPROTIVA"); - registro.update(max(protiva, uprotiva), datareg); - } - - // Aggiorna flags di ricalcolo liquidazione - - controlla_liquidazione(datareg, TRUE); - if (re && datareg != _olddate) - controlla_liquidazione(_olddate, TRUE); - - const int att = att_mista ? 2 : 1; - // Chiave di PLM: Anno (1-4), Cod. Att. (5-9), Tipo att. (10-10), Mese (11-12) - TTable plm("PLM"); - plm.setkey(1); - for (int a = 1; a <= att; a++) - { - TString16 chiave; - chiave << annoiva << registro.attivita() << a << date2liq(datareg); - plm.put("CODTAB", chiave); - if (plm.read() == NOERR) - { - const bool calcolato = plm.get_bool("B0"); - if (calcolato) - { - plm.put("B0", FALSE); - plm.rewrite(); - } - } - } - - return err; -} - - -int TMovimentoPN::write(bool force, TDate&) -{ - const TRectype& r = lfile().curr(); - - _oldcg = _oldiva = 0; - int err = registra(FALSE, force); - - return err; -} - - -int TMovimentoPN::rewrite(bool force, TDate&) -{ - return registra(TRUE, force); -} - - -int TMovimentoPN::remove(TDate&) -{ - TLocalisamfile& m = lfile(); - TLocalisamfile& rm = lfile(LF_RMOV); - TLocalisamfile& ri = lfile(LF_RMOVIVA); - - cancella(rm, 1, _oldcg); - cancella(ri, 1, _oldiva); - m.remove(); - _oldcg = _oldiva = 0; - return m.status(); -} - +#include + +#include +#include +#include + +#include "cg2101.h" +#include "cg2103.h" + +#include +#include +#include + + +// Calcola l'anno di esercizio di una data +// Certified 99% +int date2esc(const TDate& d, int* prevesc) +{ + if (prevesc) *prevesc = 0; + TTable esc("ESC"); + for (int err = esc.first(); err == NOERR; err = esc.next()) + { + const TDate ia(esc.get("D0")); // Data inizio esercizio + const TDate fa(esc.get("D1")); // Data fine esercizio + TString16 sanno(esc.get("CODTAB")); sanno.cut(4); + const int anno = atoi(sanno); + if (d >= ia && d <= fa) + return anno; + if (prevesc) *prevesc = anno; + } + return 0; +} + +/////////////////////////////////////////////////////////// +// Movimento di prima nota +/////////////////////////////////////////////////////////// + +TMovimentoPN::TMovimentoPN() +: TRelation(LF_MOV), _oldcg(0), _oldiva(0) +{ + add(LF_RMOV, "NUMREG=NUMREG"); + add(LF_RMOVIVA, "NUMREG=NUMREG"); +} + +void TMovimentoPN::destroy_rows() +{ + _cg.destroy(); + _iva.destroy(); +} + + +TRectype& TMovimentoPN::cg(int i) +{ + TRectype* r = (TRectype*)_cg.objptr(i); + if (r == NULL) + { + r = new TRectype(LF_RMOV); + _cg.add(r, i); + } + return *r; +} + +TRectype& TMovimentoPN::iva(int i) +{ + TRectype* r = (TRectype*)_iva.objptr(i); + if (r == NULL) + { + r = new TRectype(LF_RMOVIVA); + _iva.add(r, i); + } + return *r; +} + + +int TMovimentoPN::read_mov_rows() +{ + const TLocalisamfile& rm = lfile(LF_RMOV); + const TLocalisamfile& ri = lfile(LF_RMOVIVA); + position_rels(); + + destroy_rows(); + for(bool ok = is_first_match(LF_RMOV); ok; ok = next_match(LF_RMOV)) + { + const int row = rm.get_int(RMV_NUMRIG) - 1; + cg(row) = rm.curr(); + } + _oldcg = cg_items(); + + for(ok = is_first_match(LF_RMOVIVA); ok; ok = next_match(LF_RMOVIVA)) + { + const int row = ri.get_int(RMI_NUMRIG) - 1; + iva(row) = ri.curr(); + } + _oldiva = iva_items(); + + return NOERR; +} + + +int TMovimentoPN::read(TIsamop op, TReclock lockop, TDate& atdate) +{ + int err = file().read(op, lockop, atdate); + if (err == NOERR) + { + _olddate = file().get("DATAREG"); + err = read_mov_rows(); + } + return err; +} + + +int TMovimentoPN::write_rec(bool re, const TRectype& rec, TLocalisamfile& f) +{ + const bool scrivi = re ? (f.rewrite(rec) != NOERR) : TRUE; + if (scrivi) + f.write(rec); + +#ifdef TRC + const long numreg = rec.get_long("NUMREG"); + const int numrig = f.num() == LF_MOV ? 0 : rec.get_int("NUMRIG"); + TRACE("write file=%d record=%ld nummov=%ld numrig=%d status=%d", + f.num(), f.recno(), numreg, numrig, f.status()); +#endif + + return f.status(); +} + + +int TMovimentoPN::cancella(TLocalisamfile& f, int da, int a) +{ + const long numreg = lfile().get_long(MOV_NUMREG); + for (int i = da; i <= a; i++) + { + f.put(MOV_NUMREG, numreg); + f.put(RMV_NUMRIG, i); + if (f.read(_isequal, _lock) == NOERR) + f.remove(); + } + return f.status(); +} + +char TMovimentoPN::frequenza_versamenti(int year) const +{ + static int last_year = 0; + static char last_freq = ' '; + + if (year != last_year) + { + TString16 key; + key << year; + TTable lia("LIA"); + lia.setkey(1); + lia.put("CODTAB", key); + if (lia.read() != NOERR) + { + TLocalisamfile nditte(LF_NDITTE); + nditte.setkey(1); + nditte.put("CODDITTA", main_app().get_firm()); + nditte.read(); + last_freq = nditte.get_char("FREQVIVA"); + } + else + last_freq = lia.get_char("S7"); + CHECK(last_freq == 'M' || last_freq == 'T', "Frequenza versamenti IVA assurda"); + } + + return last_freq; +} + +int TMovimentoPN::date2liq(const TDate& data) const +{ + const int anno = data.year(); + int mese = data.month(); + if (frequenza_versamenti(anno) == 'T') + mese += 2 - ((mese-1) % 3); + return mese; +} + + +bool TMovimentoPN::controlla_liquidazione(const TDate& data, bool reset) const +{ + bool calcolata = FALSE; + + const int anno = data.year(); + const int mese = date2liq(data); + + // Chiave di LIM: Anno (1-4), Mese (5-6) + TString16 key; + key << anno << mese; + TTable lim("LIM"); + lim.setkey(1); + lim.put("CODTAB", key); + if (lim.read() == NOERR) + calcolata = lim.get_bool("B1"); // Controlla se calcolata in definitivo + + if (reset && lim.get_bool("B0")) + { + // Resetta i flag di calcolato sulla liquidazione IVA del mese di registrazione + lim.put("B0", FALSE); // calcolato + lim.put("B1", FALSE); // definitivo + lim.rewrite(); + } + + return calcolata; +} + + +int TMovimentoPN::registra(bool re, bool force) +{ + TLocalisamfile& m = lfile(); + + const int err = write_rec(re, m.curr(), m); + if (err != NOERR) return err; + + TLocalisamfile& rm = lfile(LF_RMOV); + TLocalisamfile& ri = lfile(LF_RMOVIVA); + + const long numreg = m.get_long("NUMREG"); + + for (int i = 0 ; i < cg_items(); i++) + { + if (!re) cg(i).put("NUMREG", numreg); + const int err = write_rec(re, cg(i), rm); + if (!force && err != NOERR) return err; + } + if (i < _oldcg) + cancella(rm, i+1, _oldcg); + _oldcg = cg_items(); + + + const int annoiva = m.get_int("ANNOIVA"); + const TString16 reg(m.get("REG")); + TRegistro registro(reg, annoiva); + const bool att_mista = reg.empty() ? FALSE : registro.attivita_mista(); + + for (i = 0 ; i < iva_items(); i++) + { + TRectype& r = iva(i); + + if (!re) r.put("NUMREG", numreg); // Force correct number + + int tipoatt = 1; + if (att_mista) + { + const char tipo = r.get_char("TIPOC"); + if (tipo <= ' ') + { + TBill c(r.get_int("GRUPPO"), r.get_int("CONTO"), r.get_long("SOTTOCONTO")); + tipoatt = c.tipo_att(); + } + } + r.put("TIPOATT", tipoatt); + + const int err = write_rec(re, r, ri); + if (!force && err != NOERR) return err; + } + + if (i < _oldiva) + cancella(ri, i+1, _oldiva); + _oldiva = iva_items(); + + // Aggiorna data registrazione e protocollo IVA sul registro + const TDate datareg(m.get("DATAREG")); + if (reg.not_empty()) + { + const long protiva = m.get_long("PROTIVA"); + const long uprotiva = m.get_long("UPROTIVA"); + registro.update(max(protiva, uprotiva), datareg); + } + + // Aggiorna flags di ricalcolo liquidazione + + controlla_liquidazione(datareg, TRUE); + if (re && datareg != _olddate) + controlla_liquidazione(_olddate, TRUE); + + const int att = att_mista ? 2 : 1; + // Chiave di PLM: Anno (1-4), Cod. Att. (5-9), Tipo att. (10-10), Mese (11-12) + TTable plm("PLM"); + plm.setkey(1); + for (int a = 1; a <= att; a++) + { + TString16 chiave; + chiave << annoiva << registro.attivita() << a << date2liq(datareg); + plm.put("CODTAB", chiave); + if (plm.read() == NOERR) + { + const bool calcolato = plm.get_bool("B0"); + if (calcolato) + { + plm.put("B0", FALSE); + plm.rewrite(); + } + } + } + + return err; +} + + +int TMovimentoPN::write(bool force, TDate&) +{ + const TRectype& r = lfile().curr(); + + _oldcg = _oldiva = 0; + int err = registra(FALSE, force); + + return err; +} + + +int TMovimentoPN::rewrite(bool force, TDate&) +{ + return registra(TRUE, force); +} + + +int TMovimentoPN::remove(TDate&) +{ + TLocalisamfile& m = lfile(); + TLocalisamfile& rm = lfile(LF_RMOV); + TLocalisamfile& ri = lfile(LF_RMOVIVA); + + cancella(rm, 1, _oldcg); + cancella(ri, 1, _oldiva); + m.remove(); + _oldcg = _oldiva = 0; + return m.status(); +} + diff --git a/cg/cg21iva.uml b/cg/cg21iva.uml index 2b7a0a89d..471d85585 100755 --- a/cg/cg21iva.uml +++ b/cg/cg21iva.uml @@ -1,266 +1,267 @@ -PAGE "RIGA IVA" -1 -1 78 13 - -GROUPBOX DLG_NULL 76 5 -BEGIN - PROMPT 1 1 "@BImposta" -END - -STRING 102 4 -BEGIN - PROMPT 2 2 "IVA " - HELP "Codice IVA della riga" - FLAGS "U" - USE %IVA - INPUT CODTAB 102 - DISPLAY "Codice" CODTAB - DISPLAY "Descrizione@50" S0 - DISPLAY "%@6" R0 - DISPLAY "Tipo" S1 - OUTPUT 102 CODTAB - OUTPUT 211 S0 - CHECKTYPE NORMAL - WARNING "Codice IVA assente" - VALIDATE ZEROFILL_FUNC 2 -END - -STRING 211 58 -BEGIN - PROMPT 16 2 "" - FLAGS "D" -END - -NUMBER 103 1 -BEGIN - PROMPT 2 3 "Detraibilita' " - HELP "Indicare il tipo di detraibilita' della riga" - SHEET "Codice|Tipo detraibilita'@75" - INPUT 103 - ITEM " |Regime normale" - ITEM "1|IVA indetraibile su acquisti riferiti a ricavi esenti" - ITEM "3|IVA indicata per passaggi interni al solo fine del calcolo di ventilazione" - ITEM "9|IVA non detraibile per l'articolo 19" - OUTPUT 103 - OUTPUT 130 -END - -STRING 130 75 52 -BEGIN - PROMPT 22 3 "" - FLAGS "D" -END - -NUMBER 101 15 -BEGIN - PROMPT 2 4 "Imponibile " - HELP "Importo imponibile" - FLAGS "RV" - PICTURE "." -END - -NUMBER 104 15 -BEGIN - PROMPT 48 4 "Imposta " - HELP "Importo dell'IVA. Se e' nullo, col tasto F8 si puo' effettuare lo scorporo" - FLAGS "RV" - PICTURE "." -END - -GROUPBOX DLG_NULL 76 5 -BEGIN - PROMPT 1 6 "@BConto" -END - -LIST 106 1 12 -BEGIN - PROMPT 2 7 "Tipo " - HELP "Tipo del conto" - FIELD TMCF - ITEM " |Conto" - MESSAGE SHOW,109|HIDE,209|HIDE,309|SHOW,110|HIDE,210|HIDE,310 - ITEM "C|Cliente" - MESSAGE SHOW,209|HIDE,109|HIDE,309|SHOW,210|HIDE,110|HIDE,310 - ITEM "F|Fornitore" - MESSAGE SHOW,309|HIDE,109|HIDE,209|SHOW,310|HIDE,110|HIDE,210 - FLAGS "U" -END - -NUMBER 107 3 -BEGIN - PROMPT 22 7 "Gruppo " - HELP "Codice del gruppo" - FIELD GRUPPO -END - -NUMBER 108 3 -BEGIN - PROMPT 38 7 "Conto " - HELP "Codice del conto" - FIELD CONTO - USE LF_PCON SELECT (CONTO!="") && (SOTTOCONTO="") - INPUT GRUPPO 107 - INPUT CONTO 108 - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Descrizione@50" DESCR - DISPLAY "Tipo" TMCF - OUTPUT 106 TMCF - OUTPUT 107 GRUPPO - OUTPUT 108 CONTO - OUTPUT 110 DESCR - ADD RUN cg0 -0 - MESSAGE DIRTY,109|DIRTY,209|DIRTY,309 - CHECKTYPE NORMAL - WARNING "Conto assente" -END - - -NUMBER 109 6 -BEGIN - PROMPT 55 7 "Sottoconto " - HELP "Codice del sottoconto" - FIELD SOTTOCONTO - USE LF_PCON SELECT SOTTOCONTO!="" - INPUT GRUPPO 107 - INPUT CONTO 108 - INPUT SOTTOCONTO 109 - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Sottoconto" SOTTOCONTO - DISPLAY "Descrizione@50" DESCR - DISPLAY "C/R" TIPOSPRIC - OUTPUT 109 SOTTOCONTO - OUTPUT 107 GRUPPO - OUTPUT 108 CONTO - OUTPUT 110 DESCR - ADD RUN cg0 -0 - CHECKTYPE NORMAL - VALIDATE REQIF_FUNC 1 101 - WARNING "Sottoconto assente" -END - - -NUMBER 209 6 -BEGIN - PROMPT 55 7 "Cliente " - HELP "Codice del cliente" - USE LF_CLIFO - INPUT TIPOCF "C" - INPUT CODCF 209 - DISPLAY "Codice" CODCF - DISPLAY "Ragione Sociale Cliente@50" RAGSOC - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - OUTPUT 209 CODCF - OUTPUT 210 RAGSOC - CHECKTYPE NORMAL - ADD RUN cg0 -1 - MESSAGE COPY,109 - VALIDATE REQIF_FUNC 1 101 - WARNING "Cliente assente" -END - -NUMBER 309 6 -BEGIN - PROMPT 55 7 "Fornitore " - HELP "Codice del fornitore" - USE LF_CLIFO - INPUT TIPOCF "F" - INPUT CODCF 309 - DISPLAY "Codice" CODCF - DISPLAY "Ragione Sociale Fornitore@50" RAGSOC - OUTPUT 107 GRUPPO - OUTPUT 108 CONTO - OUTPUT 309 CODCF - OUTPUT 310 RAGSOC - CHECKTYPE NORMAL - ADD RUN cg0 -1 - MESSAGE COPY,109 - VALIDATE REQIF_FUNC 1 101 - WARNING "Fornitore assente" -END - -STRING 110 50 -BEGIN - PROMPT 2 8 "Descrizione " - HELP "Descrizione del conto" - FIELD LF_PCON->DESCR - USE LF_PCON KEY 2 - INPUT DESCR 110 - DISPLAY "Descrizione@50" DESCR - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Sottoconto" SOTTOCONTO - COPY OUTPUT 109 - CHECKTYPE NORMAL - ADD RUN cg0 -0 -END - -STRING 210 50 -BEGIN - PROMPT 2 8 "Cliente " - HELP "Ragione sociale del cliente" - FIELD LF_CLIFO->RAGSOC - USE LF_CLIFO KEY 2 - INPUT TIPOCF "C" - INPUT RAGSOC 210 - DISPLAY "Ragione Sociale Cliente@50" RAGSOC - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Codice" CODCF - COPY OUTPUT 209 - MESSAGE COPY,110 - ADD RUN cg0 -1 - CHECKTYPE NORMAL -END - -STRING 310 50 -BEGIN - PROMPT 2 8 "Fornitore " - HELP "Ragione sociale del forntore" - FIELD LF_PCON->SOTTOCONTO - USE LF_CLIFO KEY 2 - INPUT TIPOCF "F" - INPUT RAGSOC 310 - DISPLAY "Ragione Sociale Fornitore@50" RAGSOC - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Codice" CODCF - COPY OUTPUT 309 - MESSAGE COPY,110 - ADD RUN cg0 -1 - CHECKTYPE NORMAL -END - -LIST 105 1 53 -BEGIN - PROMPT 2 9 "Tipo Costo/Ricavo " - ITEM " |0. Acquisti o vendite in genere" - ITEM "1|1. Acquisti beni per rivendita" - ITEM "2|2. Acquisti beni ammortizzabili" - ITEM "3|3. Acquisti beni ammortizzabili con detr. 6%" - ITEM "4|4. Vendita beni strumentali art. 17" - ITEM "5|5. Beni per rivendita da non ventilare" - ITEM "8|8. Altri beni strumentali acquistati in leasing" - FLAGS "D" - HELP "Tipo Costo/Ricavo del conto" -END - -BUTTON DLG_OK 9 2 -BEGIN - PROMPT -13 -1 "" -END - -BUTTON DLG_CANCEL 9 2 -BEGIN - PROMPT -23 -1 "" -END - -BUTTON DLG_DELREC 9 2 -BEGIN - PROMPT -33 -1 "Elimina" - MESSAGE EXIT,K_DEL -END - -ENDPAGE - -ENDMASK +PAGE "RIGA IVA" -1 -1 78 13 + +GROUPBOX DLG_NULL 76 5 +BEGIN + PROMPT 1 1 "@BImposta" +END + +STRING 102 4 +BEGIN + PROMPT 2 2 "IVA " + HELP "Codice IVA della riga" + FLAGS "U" + USE %IVA + INPUT CODTAB 102 + DISPLAY "Codice" CODTAB + DISPLAY "Descrizione@50" S0 + DISPLAY "%@6" R0 + DISPLAY "Tipo" S1 + OUTPUT 102 CODTAB + OUTPUT 211 S0 + CHECKTYPE NORMAL + WARNING "Codice IVA assente" + VALIDATE ZEROFILL_FUNC 2 +END + +STRING 211 58 +BEGIN + PROMPT 16 2 "" + FLAGS "D" +END + +NUMBER 103 1 +BEGIN + PROMPT 2 3 "Detraibilita' " + HELP "Indicare il tipo di detraibilita' della riga" + SHEET "Codice|Tipo detraibilita'@75" + INPUT 103 + ITEM " |Regime normale" + ITEM "1|IVA indetraibile su acquisti riferiti a ricavi esenti" + ITEM "3|IVA indicata per passaggi interni al solo fine del calcolo di ventilazione" + ITEM "9|IVA non detraibile per l'articolo 19" + OUTPUT 103 + OUTPUT 130 +END + +STRING 130 75 52 +BEGIN + PROMPT 22 3 "" + FLAGS "D" +END + +NUMBER 101 15 +BEGIN + PROMPT 2 4 "Imponibile " + HELP "Importo imponibile" + FLAGS "RV" + PICTURE "." +END + +NUMBER 104 15 +BEGIN + PROMPT 48 4 "Imposta " + HELP "Importo dell'IVA. Se e' nullo, col tasto F8 si puo' effettuare lo scorporo" + FLAGS "RV" + PICTURE "." +END + +GROUPBOX DLG_NULL 76 5 +BEGIN + PROMPT 1 6 "@BConto" +END + +LIST 106 1 12 +BEGIN + PROMPT 2 7 "Tipo " + HELP "Tipo del conto" + FIELD TMCF + ITEM " |Conto" + MESSAGE SHOW,109|HIDE,209|HIDE,309|SHOW,110|HIDE,210|HIDE,310 + ITEM "C|Cliente" + MESSAGE SHOW,209|HIDE,109|HIDE,309|SHOW,210|HIDE,110|HIDE,310 + ITEM "F|Fornitore" + MESSAGE SHOW,309|HIDE,109|HIDE,209|SHOW,310|HIDE,110|HIDE,210 + FLAGS "U" +END + +NUMBER 107 3 +BEGIN + PROMPT 22 7 "Gruppo " + HELP "Codice del gruppo" + FIELD GRUPPO +END + +NUMBER 108 3 +BEGIN + PROMPT 38 7 "Conto " + HELP "Codice del conto" + FIELD CONTO + USE LF_PCON SELECT (CONTO!="") && (SOTTOCONTO="") + INPUT GRUPPO 107 + INPUT CONTO 108 + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Descrizione@50" DESCR + DISPLAY "Tipo" TMCF + OUTPUT 106 TMCF + OUTPUT 107 GRUPPO + OUTPUT 108 CONTO + OUTPUT 110 DESCR + ADD RUN cg0 -0 + MESSAGE DIRTY,109|DIRTY,209|DIRTY,309 + CHECKTYPE NORMAL + WARNING "Conto assente" +END + + +NUMBER 109 6 +BEGIN + PROMPT 55 7 "Sottoconto " + HELP "Codice del sottoconto" + FIELD SOTTOCONTO + USE LF_PCON SELECT SOTTOCONTO!="" + INPUT GRUPPO 107 + INPUT CONTO 108 + INPUT SOTTOCONTO 109 + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Sottoconto" SOTTOCONTO + DISPLAY "Descrizione@50" DESCR + DISPLAY "C/R" TIPOSPRIC + OUTPUT 109 SOTTOCONTO + OUTPUT 107 GRUPPO + OUTPUT 108 CONTO + OUTPUT 110 DESCR + ADD RUN cg0 -0 + CHECKTYPE NORMAL + VALIDATE REQIF_FUNC 1 101 + WARNING "Sottoconto assente" +END + + +NUMBER 209 6 +BEGIN + PROMPT 55 7 "Cliente " + HELP "Codice del cliente" + USE LF_CLIFO + INPUT TIPOCF "C" + INPUT CODCF 209 + DISPLAY "Codice" CODCF + DISPLAY "Ragione Sociale Cliente@50" RAGSOC + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + OUTPUT 209 CODCF + OUTPUT 210 RAGSOC + CHECKTYPE NORMAL + ADD RUN cg0 -1 + MESSAGE COPY,109 + VALIDATE REQIF_FUNC 1 101 + WARNING "Cliente assente" +END + +NUMBER 309 6 +BEGIN + PROMPT 55 7 "Fornitore " + HELP "Codice del fornitore" + USE LF_CLIFO + INPUT TIPOCF "F" + INPUT CODCF 309 + DISPLAY "Codice" CODCF + DISPLAY "Ragione Sociale Fornitore@50" RAGSOC + OUTPUT 107 GRUPPO + OUTPUT 108 CONTO + OUTPUT 309 CODCF + OUTPUT 310 RAGSOC + CHECKTYPE NORMAL + ADD RUN cg0 -1 + MESSAGE COPY,109 + VALIDATE REQIF_FUNC 1 101 + WARNING "Fornitore assente" +END + +STRING 110 50 +BEGIN + PROMPT 2 8 "Descrizione " + HELP "Descrizione del conto" + FIELD LF_PCON->DESCR + USE LF_PCON KEY 2 + INPUT DESCR 110 + DISPLAY "Descrizione@50" DESCR + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Sottoconto" SOTTOCONTO + COPY OUTPUT 109 + CHECKTYPE NORMAL + ADD RUN cg0 -0 +END + +STRING 210 50 +BEGIN + PROMPT 2 8 "Cliente " + HELP "Ragione sociale del cliente" + FIELD LF_CLIFO->RAGSOC + USE LF_CLIFO KEY 2 + INPUT TIPOCF "C" + INPUT RAGSOC 210 + DISPLAY "Ragione Sociale Cliente@50" RAGSOC + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Codice" CODCF + COPY OUTPUT 209 + MESSAGE COPY,110 + ADD RUN cg0 -1 + CHECKTYPE NORMAL +END + +STRING 310 50 +BEGIN + PROMPT 2 8 "Fornitore " + HELP "Ragione sociale del forntore" + FIELD LF_PCON->SOTTOCONTO + USE LF_CLIFO KEY 2 + INPUT TIPOCF "F" + INPUT RAGSOC 310 + DISPLAY "Ragione Sociale Fornitore@50" RAGSOC + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Codice" CODCF + COPY OUTPUT 309 + MESSAGE COPY,110 + ADD RUN cg0 -1 + CHECKTYPE NORMAL +END + +LIST 105 1 53 +BEGIN + PROMPT 2 9 "Tipo Costo/Ricavo " + ITEM " |0. Acquisti o vendite in genere" + ITEM "1|1. Acquisti beni per rivendita" + ITEM "2|2. Acquisti beni ammortizzabili" + ITEM "3|3. Acquisti beni ammortizzabili con detr. 6%" + ITEM "4|4. Vendita beni strumentali art. 17" + ITEM "5|5. Beni per rivendita da non ventilare" + ITEM "8|8. Altri beni strumentali acquistati in leasing" + ITEM "9|9. Spese generali" + FLAGS "D" + HELP "Tipo Costo/Ricavo del conto" +END + +BUTTON DLG_OK 9 2 +BEGIN + PROMPT -13 -1 "" +END + +BUTTON DLG_CANCEL 9 2 +BEGIN + PROMPT -23 -1 "" +END + +BUTTON DLG_DELREC 9 2 +BEGIN + PROMPT -33 -1 "Elimina" + MESSAGE EXIT,K_DEL +END + +ENDPAGE + +ENDMASK diff --git a/cg/cg4100.cpp b/cg/cg4100.cpp index ca0360581..228f1ea3f 100755 --- a/cg/cg4100.cpp +++ b/cg/cg4100.cpp @@ -1,423 +1,423 @@ -// Rinumerazione movimenti e saldi -// fv 12/12/93 -// ------------------------------------------------------------------------- -// *TBI* Partenza dall'ultimo movimento stampato -// *TBI* Aggiornamento scadenziario -// *TBI* Aggiornamento cespiti -// ------------------------------------------------------------------------- - -#include -//#if XVT_OS == XVT_OS_SCOUNIX -#include -//#endif - -#include -#include -#include -#include -#include -#include -#include - -#define FLD_CG41_YEAR 100 -#define MAX_CNT 300 - -#include -#include -#include -#include -#include - -#include "cglib.h" - -struct therec { - char DATAREG[9]; - char REG[4]; - char DATADOC[9]; - char NUMPROT[9]; - char ANNOES[5]; - char NUMREG[8]; -}; - -class CG4100_App : public TApplication -{ - TString _year; - char _optype; - -public: - - virtual bool create(); - virtual bool destroy(); - - bool set_parms(); - virtual bool menu(MENU_TAG m); - - void restore_mov(TSystemisamfile& a, TSystemisamfile& b, TSystemisamfile& c); - void sort_all(); - bool sort_mov(); - bool sort_sal(); - - CG4100_App() : TApplication(), _year(4), _optype('S') {} - virtual ~CG4100_App() {} -}; - - -bool CG4100_App::create() -{ - TApplication::create(); - - // UNIX: signal() per intercettare errori -#if XVT_OS == XVT_OS_SCOUNIX - signal(SIGINT,SIG_IGN); -#endif - - if (fexist("__sal__.sav")) - warning_box("Un'operazione di riordino saldi si e' conclusa" - " impropriamente. Si raccomanda di rieseguirla"); - - if (fexist("__mov__.sav")) - warning_box("Un'operazione di riordino movimenti si e' conclusa" - " impropriamente. Si raccomanda di rieseguirla"); - if (argc() > 2) - _optype = toupper(argv(2)[0]); - dispatch_e_menu(MENU_ITEM(1)); - return TRUE; -} - -bool CG4100_App::destroy() -{ - // UNIX: resettare i segnali -#if XVT_OS == XVT_OS_SCOUNIX - signal(SIGINT,SIG_DFL); -#endif - - return TApplication::destroy(); -} - -bool CG4100_App::set_parms() -{ - const bool saldi = _optype == 'S'; - TMask m(saldi ? "cg4100b" : "cg4100a"); - - m.run(); - - if (saldi) - _year = m.get(FLD_CG41_YEAR); - else - _year = 0; - - return m.last_key() == K_ENTER; -} - - -bool CG4100_App::menu(MENU_TAG m) -{ - if (_optype == 'S') - sort_sal(); - else - if (_optype == 'M') - sort_mov(); - return FALSE; -} - - -void CG4100_App::restore_mov(TSystemisamfile& mov, TSystemisamfile& rmov, - TSystemisamfile& rmoviva) -{ - long rn, rec; - if (fexist("__mov__.ind")) - { - // rebuild all indexes - mov.close(); rmov.close(); rmoviva.close(); - mov.packfile(); rmov.packfile(); rmoviva.packfile(); - mov.packindex(); rmov.packindex(); rmoviva.packindex(); - remove("__mov__.ind"); - return; - } - - FILE* fp = fopen("__mov__.sav","r"); - if (feof(fp)) - { - warning_box("File di ripristino vuoto; il ripristino non e' necessario"); - remove("__mov__.sav"); - return; - }; - - for (;;) - { - if (feof(fp)) break; - fscanf(fp,"%ld %ld", &rn, &rec); - - mov.readat(rec); - mov.put(MOV_NUMREG,rn); - mov.rewrite(); - - for (;;) - { - if (feof(fp)) break; - fscanf(fp,"%ld",&rec); - if (rec == -1l) break; - rmov.readat(rec); - rmov.put(RMV_NUMREG,rn); - rmov.rewrite(); - } - for (;;) - { - if (feof(fp)) break; - fscanf(fp,"%ld",&rec); - if (rec == -1l) break; - rmoviva.readat(rec); - rmoviva.put(RMI_NUMREG,rn); - rmoviva.rewrite(); - } - } - - fclose(fp); - remove("__mov__.sav"); -} - - -bool CG4100_App::sort_mov() -{ - if (!set_parms()) - return FALSE; - - TSystemisamfile mov(LF_MOV); - TSystemisamfile rmov(LF_RMOV); - TSystemisamfile rmoviva(LF_RMOVIVA); - - if (mov.open(_excllock) || rmov.open(_excllock) || - rmoviva.open(_excllock)) - { - warning_box("Gli archivi sono in uso. Operazione interrotta"); - return FALSE; - } - - mov.indexoff(); rmov.indexoff(); rmoviva.indexoff(); - mov.first(); - - TSort sort(sizeof(struct therec)); - - if (fexist("__mov__.sav") || fexist("__mov__.ind")) - { - // previous operation failed - if (yesno_box("Un riordinamento precedente e' fallito.\n" - " Ripristino la situazione iniziale ora?" )) - restore_mov(mov, rmov, rmoviva); - else return FALSE; - } - - therec rbuf; - - sort.addsortkey(rbuf.DATAREG - (char*)&rbuf, 8); - sort.addsortkey(rbuf.REG - (char*)&rbuf, 3); - sort.addsortkey(rbuf.NUMPROT - (char*)&rbuf, 8); - sort.addsortkey(rbuf.DATADOC - (char*)&rbuf, 8); - sort.addsortkey(rbuf.NUMREG - (char*)&rbuf, 7); - - sort.init(); - - TProgind prnd(mov.items(), - "Riordino archivio movimenti in corso\nOrdinamento file movimenti...", - FALSE,TRUE,30); - TString16 s; - - while (!mov.eof()) - { - do_events(); - TDate d(mov.get(MOV_DATAREG)); - strcpy(rbuf.DATAREG, d.string(ANSI)); - strcpy(rbuf.REG, mov.get(MOV_REG)); - d = mov.get(MOV_DATADOC); - s = mov.get(MOV_PROTIVA); - if (s.len() > 0 && isdigit(s[s.len() - 1])) s << " "; - s.right_just(8); - strcpy(rbuf.NUMPROT, (const char *) s); - strcpy(rbuf.DATADOC, d.string(ANSI)); - strcpy(rbuf.ANNOES, mov.get(MOV_ANNOES)); - strcpy(rbuf.NUMREG, mov.get(MOV_NUMREG)); - - sort.sort((char*)&rbuf); - mov.next(); - prnd.addstatus(1); - } - sort.endsort(); - - prnd.setstatus(0); - prnd.set_text("Riordino archivio movimenti in corso\nRiscrittura file movimenti..."); - - therec* rr; - long num = 1; - TRecnotype recno; - - while ((rr = (therec*)sort.retrieve()) != NULL) - { - do_events(); - if (atol(rr->NUMREG) != num) - { - // find record - mov.curr().zero(); - mov.put(MOV_NUMREG, rr->NUMREG); - - mov.read(); - // should never happen - CHECK(mov.good(), "Archivio movimenti inconsistente. Questo si' che e' un casino."); - - // retrieve and change NUMREG - recno = mov.recno(); - TString rgn = rr->NUMREG; - FILE* fsav = fopen("__mov__.sav","a"); - fprintf(fsav,"%s %d ", (const char*)rgn, recno); - fclose(fsav); - - mov.put(MOV_NUMREG,num); - mov.rewriteat(recno); - // update linked records - - rmov.curr().zero(); - rmov.put(RMV_NUMREG,rgn); - rmov.read(_isgteq); - - int row = 0; - - while (!rmov.eof() && rgn == rmov.get(RMV_NUMREG) && - row++ < rmov.get_int(RMV_NUMRIG)) - { - recno = rmov.recno(); - fsav = fopen("__mov__.sav","a"); - fprintf(fsav,"%ld ", recno); - fclose(fsav); - rmov.put(RMV_NUMREG,num); - rmov.rewriteat(recno); - rmov.next(); - } - fsav = fopen("__mov__.sav","a"); - fprintf(fsav,"-1"); fclose(fsav); - - rmoviva.zero(); - rmoviva.put(RMI_NUMREG,rgn); - rmoviva.read(_isgteq); - - row = 0; - - while (!rmoviva.eof() && rgn == rmoviva.get(RMV_NUMREG) && - row++ < rmoviva.get_int(RMV_NUMRIG)) - { - recno = rmoviva.recno(); - fsav = fopen("__mov__.sav","a"); - fprintf(fsav,"%ld ", recno); - fclose(fsav); - rmoviva.put(RMI_NUMREG,num); - rmoviva.rewriteat(recno); - rmoviva.next(); - } - fsav = fopen("__mov__.sav","a"); - fprintf(fsav,"-1"); fclose(fsav); - } - num++; - prnd.addstatus(1); - } - - remove("__mov__.sav"); - - FILE* fsav = fopen("__mov__.ind","w"); fclose(fsav); - - prnd.set_text("Riordino archivio movimenti in corso\nRicostruzione files indice..."); - - // rebuild indexes - mov.close(); rmov.close(); rmoviva.close(); - mov.indexon(); rmov.indexon(); rmoviva.indexon(); - mov.packfile(); rmov.packfile(); rmoviva.packfile(); - mov.packindex(); rmov.packindex(); rmoviva.packindex(); - - remove("__mov__.ind"); - - return TRUE; -} - - -bool CG4100_App::sort_sal() -{ - - if (!set_parms()) - return FALSE; - - FILE* fp = fopen ("__sal__.sav","w"); - fclose(fp); - - TLocalisamfile rmov(LF_RMOV); - TLocalisamfile mov(LF_MOV); - TLocalisamfile causali(LF_CAUSALI); - TSaldo_agg sal; - int gruppo, conto; - const int year = atoi(_year); - long oldnumreg = 0L, sottoconto; - TProgind prnd(rmov.items(), - "Riordino archivio saldi in corso\nLettura archivio movimenti...", - FALSE,TRUE,30); - - causali.zero(); - mov.setkey(1); - rmov.first(); - sal.reset(); - sal.set_anno_es(year); - sal.clear_saldi(year); - while (!rmov.eof()) - { - if (_year == rmov.get(RMV_ANNOES)) - { - const long numreg = rmov.get_long(RMV_NUMREG); - - gruppo = rmov.get_int(RMV_GRUPPO); - conto = rmov.get_int(RMV_CONTO); - sottoconto = rmov.get_long(RMV_SOTTOCONTO); - if (numreg != oldnumreg) - { - oldnumreg = numreg; - mov.zero(); - mov.put(MOV_NUMREG, numreg); - mov.read(); - CHECK(mov.good(),"Archivi movimenti e righe inconsistenti"); - - const char* codcaus = mov.get(MOV_CODCAUS); - - // cerca causale - causali.zero(); - if (*codcaus) - { - causali.put(CAU_CODCAUS, codcaus); - causali.read(); - CHECK(causali.good(),"Archivi causali e movimenti inconsistenti"); - } - } - const char sezione = rmov.get(RMV_SEZIONE)[0]; - real importo(rmov.get(RMV_IMPORTO)); - - sal.set_movap(causali.get(CAU_MOVAP) == "A"); - sal.set_movprovv(mov.get(MOV_PROVVIS).not_empty()); - sal.aggiorna(gruppo, conto, sottoconto, importo, sezione); - if (sal.items() > MAX_CNT) - { - sal.registra(); - sal.reset(); - sal.set_anno_es(atoi(_year)); - } - } - rmov.next(); - prnd.addstatus(1); - do_events(); - } - if (sal.items() > 0) - sal.registra(); - remove("__sal__.sav"); - return TRUE; -} - - -int cg4100(int argc, char* argv[]) -{ - CG4100_App main_app; - main_app.run(argc, argv, "Riordinamento movimenti/Ricalcolo Saldi"); - return TRUE; -} - +// Rinumerazione movimenti e saldi +// fv 12/12/93 +// ------------------------------------------------------------------------- +// *TBI* Partenza dall'ultimo movimento stampato +// *TBI* Aggiornamento scadenziario +// *TBI* Aggiornamento cespiti +// ------------------------------------------------------------------------- + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define FLD_CG41_YEAR 100 +#define MAX_CNT 300 + +#include +#include +#include +#include +#include + +#include "cglib.h" + +struct therec { + char DATAREG[9]; + char REG[4]; + char DATADOC[9]; + char NUMPROT[9]; + char ANNOES[5]; + char NUMREG[8]; +}; + +class CG4100_App : public TApplication +{ + TString _year; + char _optype; + TMask* _msk; + +public: + + virtual bool create(); + virtual bool destroy(); + + bool set_parms(); + virtual bool menu(MENU_TAG m); + + void restore_mov(TSystemisamfile& a, TSystemisamfile& b, TSystemisamfile& c); + void sort_all(); + bool sort_mov(); + bool sort_sal(); + + CG4100_App() : TApplication(), _year(4), _optype('S') {} + virtual ~CG4100_App() {} +}; + + +bool CG4100_App::create() +{ + TApplication::create(); + + // UNIX: signal() per intercettare errori +#if XVT_OS == XVT_OS_SCOUNIX + signal(SIGINT,SIG_IGN); +#endif + + if (fexist("__sal__.sav")) + warning_box("Un'operazione di riordino saldi si e' conclusa" + " impropriamente. Si raccomanda di rieseguirla"); + + if (fexist("__mov__.sav")) + warning_box("Un'operazione di riordino movimenti si e' conclusa" + " impropriamente. Si raccomanda di rieseguirla"); + + if (argc() > 2) + _optype = toupper(argv(2)[0]); + + _msk = new TMask(_optype == 'S' ? "cg4100b" : "cg4100a"); + + dispatch_e_menu(MENU_ITEM(1)); + return TRUE; +} + +bool CG4100_App::destroy() +{ + // UNIX: resettare i segnali +#if XVT_OS == XVT_OS_SCOUNIX + signal(SIGINT,SIG_DFL); +#endif + delete _msk; + return TApplication::destroy(); +} + +bool CG4100_App::set_parms() +{ + _msk->run(); + + if (_optype == 'S') + _year = _msk->get(FLD_CG41_YEAR); + else + _year = 0; + + return _msk->last_key() == K_ENTER; +} + + +bool CG4100_App::menu(MENU_TAG) +{ + if (_optype == 'S') + sort_sal(); + else + sort_mov(); + + return FALSE; +} + + +void CG4100_App::restore_mov(TSystemisamfile& mov, TSystemisamfile& rmov, + TSystemisamfile& rmoviva) +{ + long rn, rec; + if (fexist("__mov__.ind")) + { + // rebuild all indexes + mov.close(); rmov.close(); rmoviva.close(); + mov.packfile(); rmov.packfile(); rmoviva.packfile(); + mov.packindex(); rmov.packindex(); rmoviva.packindex(); + remove("__mov__.ind"); + return; + } + + FILE* fp = fopen("__mov__.sav","r"); + if (feof(fp)) + { + warning_box("File di ripristino vuoto; il ripristino non e' necessario"); + remove("__mov__.sav"); + return; + }; + + for (;;) + { + if (feof(fp)) break; + fscanf(fp,"%ld %ld", &rn, &rec); + + mov.readat(rec); + mov.put(MOV_NUMREG,rn); + mov.rewrite(); + + for (;;) + { + if (feof(fp)) break; + fscanf(fp,"%ld",&rec); + if (rec == -1l) break; + rmov.readat(rec); + rmov.put(RMV_NUMREG,rn); + rmov.rewrite(); + } + for (;;) + { + if (feof(fp)) break; + fscanf(fp,"%ld",&rec); + if (rec == -1l) break; + rmoviva.readat(rec); + rmoviva.put(RMI_NUMREG,rn); + rmoviva.rewrite(); + } + } + + fclose(fp); + remove("__mov__.sav"); +} + + +bool CG4100_App::sort_mov() +{ + if (!set_parms()) + return FALSE; + + TSystemisamfile mov(LF_MOV); + TSystemisamfile rmov(LF_RMOV); + TSystemisamfile rmoviva(LF_RMOVIVA); + + if (mov.open(_excllock) || rmov.open(_excllock) || + rmoviva.open(_excllock)) + { + warning_box("Gli archivi sono in uso. Operazione interrotta"); + return FALSE; + } + + mov.indexoff(); rmov.indexoff(); rmoviva.indexoff(); + mov.first(); + + TSort sort(sizeof(struct therec)); + + if (fexist("__mov__.sav") || fexist("__mov__.ind")) + { + // previous operation failed + if (yesno_box("Un riordinamento precedente e' fallito.\n" + " Ripristino la situazione iniziale ora?" )) + restore_mov(mov, rmov, rmoviva); + else return FALSE; + } + + therec rbuf; + + sort.addsortkey(rbuf.DATAREG - (char*)&rbuf, 8); + sort.addsortkey(rbuf.REG - (char*)&rbuf, 3); + sort.addsortkey(rbuf.NUMPROT - (char*)&rbuf, 8); + sort.addsortkey(rbuf.DATADOC - (char*)&rbuf, 8); + sort.addsortkey(rbuf.NUMREG - (char*)&rbuf, 7); + + sort.init(); + + TProgind prnd(mov.items(), + "Riordino archivio movimenti in corso\nOrdinamento file movimenti...", + FALSE,TRUE,30); + TString16 s; + + while (!mov.eof()) + { + do_events(); + TDate d(mov.get(MOV_DATAREG)); + strcpy(rbuf.DATAREG, d.string(ANSI)); + strcpy(rbuf.REG, mov.get(MOV_REG)); + d = mov.get(MOV_DATADOC); + s = mov.get(MOV_PROTIVA); + if (s.len() > 0 && isdigit(s[s.len() - 1])) s << " "; + s.right_just(8); + strcpy(rbuf.NUMPROT, (const char *) s); + strcpy(rbuf.DATADOC, d.string(ANSI)); + strcpy(rbuf.ANNOES, mov.get(MOV_ANNOES)); + strcpy(rbuf.NUMREG, mov.get(MOV_NUMREG)); + + sort.sort((char*)&rbuf); + mov.next(); + prnd.addstatus(1); + } + sort.endsort(); + + prnd.setstatus(0); + prnd.set_text("Riordino archivio movimenti in corso\nRiscrittura file movimenti..."); + + therec* rr; + long num = 1; + TRecnotype recno; + + while ((rr = (therec*)sort.retrieve()) != NULL) + { + do_events(); + if (atol(rr->NUMREG) != num) + { + // find record + mov.curr().zero(); + mov.put(MOV_NUMREG, rr->NUMREG); + + mov.read(); + // should never happen + CHECK(mov.good(), "Archivio movimenti inconsistente. Questo si' che e' un casino."); + + // retrieve and change NUMREG + recno = mov.recno(); + TString rgn = rr->NUMREG; + FILE* fsav = fopen("__mov__.sav","a"); + fprintf(fsav,"%s %d ", (const char*)rgn, recno); + fclose(fsav); + + mov.put(MOV_NUMREG,num); + mov.rewriteat(recno); + // update linked records + + rmov.curr().zero(); + rmov.put(RMV_NUMREG,rgn); + rmov.read(_isgteq); + + int row = 0; + + while (!rmov.eof() && rgn == rmov.get(RMV_NUMREG) && + row++ < rmov.get_int(RMV_NUMRIG)) + { + recno = rmov.recno(); + fsav = fopen("__mov__.sav","a"); + fprintf(fsav,"%ld ", recno); + fclose(fsav); + rmov.put(RMV_NUMREG,num); + rmov.rewriteat(recno); + rmov.next(); + } + fsav = fopen("__mov__.sav","a"); + fprintf(fsav,"-1"); fclose(fsav); + + rmoviva.zero(); + rmoviva.put(RMI_NUMREG,rgn); + rmoviva.read(_isgteq); + + row = 0; + + while (!rmoviva.eof() && rgn == rmoviva.get(RMV_NUMREG) && + row++ < rmoviva.get_int(RMV_NUMRIG)) + { + recno = rmoviva.recno(); + fsav = fopen("__mov__.sav","a"); + fprintf(fsav,"%ld ", recno); + fclose(fsav); + rmoviva.put(RMI_NUMREG,num); + rmoviva.rewriteat(recno); + rmoviva.next(); + } + fsav = fopen("__mov__.sav","a"); + fprintf(fsav,"-1"); fclose(fsav); + } + num++; + prnd.addstatus(1); + } + + remove("__mov__.sav"); + + FILE* fsav = fopen("__mov__.ind","w"); fclose(fsav); + + prnd.set_text("Riordino archivio movimenti in corso\nRicostruzione files indice..."); + + // rebuild indexes + mov.close(); rmov.close(); rmoviva.close(); + mov.indexon(); rmov.indexon(); rmoviva.indexon(); + mov.packfile(); rmov.packfile(); rmoviva.packfile(); + mov.packindex(); rmov.packindex(); rmoviva.packindex(); + + remove("__mov__.ind"); + + return TRUE; +} + + +bool CG4100_App::sort_sal() +{ + + if (!set_parms()) + return FALSE; + + FILE* fp = fopen ("__sal__.sav","w"); + fclose(fp); + + TLocalisamfile rmov(LF_RMOV); + TLocalisamfile mov(LF_MOV); + TLocalisamfile causali(LF_CAUSALI); + TSaldo_agg sal; + int gruppo, conto; + const int year = atoi(_year); + long oldnumreg = 0L, sottoconto; + TProgind prnd(rmov.items(), + "Riordino archivio saldi in corso\nLettura archivio movimenti...", + FALSE,TRUE,30); + + causali.zero(); + mov.setkey(1); + rmov.first(); + sal.reset(); + sal.set_anno_es(year); + sal.clear_saldi(year); + while (!rmov.eof()) + { + if (_year == rmov.get(RMV_ANNOES)) + { + const long numreg = rmov.get_long(RMV_NUMREG); + + gruppo = rmov.get_int(RMV_GRUPPO); + conto = rmov.get_int(RMV_CONTO); + sottoconto = rmov.get_long(RMV_SOTTOCONTO); + if (numreg != oldnumreg) + { + oldnumreg = numreg; + mov.zero(); + mov.put(MOV_NUMREG, numreg); + mov.read(); + CHECK(mov.good(),"Archivi movimenti e righe inconsistenti"); + + const char* codcaus = mov.get(MOV_CODCAUS); + + // cerca causale + causali.zero(); + if (*codcaus) + { + causali.put(CAU_CODCAUS, codcaus); + causali.read(); + CHECK(causali.good(),"Archivi causali e movimenti inconsistenti"); + } + } + const char sezione = rmov.get(RMV_SEZIONE)[0]; + real importo(rmov.get(RMV_IMPORTO)); + + sal.set_movap(causali.get(CAU_MOVAP) == "A"); + sal.set_movprovv(mov.get(MOV_PROVVIS).not_empty()); + sal.aggiorna(gruppo, conto, sottoconto, importo, sezione); + if (sal.items() > MAX_CNT) + { + sal.registra(); + sal.reset(); + sal.set_anno_es(atoi(_year)); + } + } + rmov.next(); + prnd.addstatus(1); + do_events(); + } + if (sal.items() > 0) + sal.registra(); + remove("__sal__.sav"); + return TRUE; +} + + +int cg4100(int argc, char* argv[]) +{ + CG4100_App main_app; + main_app.run(argc, argv, "Ricalcolo Saldi"); + return TRUE; +} + diff --git a/cg/cg4400.cpp b/cg/cg4400.cpp index d85778130..cd1014f87 100755 --- a/cg/cg4400.cpp +++ b/cg/cg4400.cpp @@ -1,2802 +1,2924 @@ -// cg4400.cpp -// Stampa registri IVA -#include "cg4.h" -#include "cg4400.h" -#include "cg4400a.h" -#include "cg4400b.h" - -static TString256 TMP; - -inline CG4400_application& app() { return (CG4400_application&)main_app(); } - -bool CG4400_application::filter_func (const TRelation * r) -{ - TLocalisamfile& mov = r->lfile(LF_MOV); - TString16 codreg = mov.get(MOV_REG); - TDate datareg = mov.get_date(MOV_DATAREG); - int annoiva = mov.get_int(MOV_ANNOIVA); - bool regst = mov.get_bool(MOV_REGST); - - if (codreg != (app()._codreg) || annoiva != (app()._annoes)) - return FALSE; - - if (app()._data_da.string() != "" && app()._data_a.string() != "") - if ( (datareg < app()._data_da || datareg > app()._data_a ) || (!datareg.ok()) ) - return FALSE; - - if (app()._tipo_stampa == 2 || app()._tipo_stampa == 4) //stampa di bollato - if (regst) //il movimento e' gia' stato stampato in forma definitiva - return FALSE; - - return TRUE; -} - -HIDDEN int compare_rows(const TObject** o1, const TObject** o2) -{ - TRiga* r1 = (TRiga*)*o1; - TRiga* r2 = (TRiga*)*o2; - - return (strcmp((const char*)r1->_codiva, (const char*)r2->_codiva)); -} - -HIDDEN int compare_fields(const TObject** o1, const TObject** o2) -{ - TRigaiva* r1 = (TRigaiva*)*o1; - TRigaiva* r2 = (TRigaiva*)*o2; - TString16 campo1; - TString16 campo2; - - campo1.format("%d%4s", r1->_tipodet, (const char*)r1->_codiva); - campo2.format("%d%4s", r2->_tipodet, (const char*)r2->_codiva); - return strcmp(campo1, campo2); -} - -bool CG4400_application::stampa_totali_finali() -{ - TConfig conf(CONFIG_DITTA); - return conf.get_bool("StTfFr"); -} - -bool CG4400_application::stampa_datareg() -{ - TConfig conf(CONFIG_STUDIO); - return conf.get_bool("NoDtRg"); -} - -bool CG4400_application::mask_select (TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - TBit_array& sel = app()._selected; - TArray_sheet& dit = *app()._ditte; - - for (int j = 0; j < dit.items(); j++) - dit.check(j, sel[j]); - - // seleziona e aggiungi alle gia' selezionate - if (dit.run() == K_ENTER) - { - for (int j = 0; j < dit.items(); j++) - sel.set(j, dit.checked(j)); - } - const long numd = sel.ones(); - f.mask().set(F_SELECT, numd); - } - return TRUE; -} - -bool CG4400_application::mask_azzera (TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - app()._selected.reset(); - app()._ditte->uncheck(-1); - f.mask().reset(F_SELECT); - } - return TRUE; -} - -bool CG4400_application::mask_firm_to (TMask_field& f, KEY k) -{ - if (k == K_TAB && f.focusdirty()) - { - TMask& m = f.mask(); - const long from = m.get_long(DA_CODICE); - long to = m.get_long(A_CODICE); - if (from != 0 || to != 0) - { - TBit_array& sel = app()._selected; - if (to == 0) to = 99999; - for (int i = 0; i < app()._ditte->items(); i++) - { - TToken_string& d = app()._ditte->row(i); - const long cod = d.get_long(1); - if (cod >= from && cod <= to) - sel.set(i); - } - // m.reset(DA_CODICE); - // m.reset(A_CODICE); - const long numd = sel.ones(); - f.mask().set(F_SELECT, numd); - } - } - return TRUE; -} - -bool CG4400_application::mask_tipo_stampa(TMask_field& f, KEY k) -{ - TMask& m = f.mask(); - - if (k == K_SPACE) - { - int tipo_stampa = m.get_int(TIPO_STAMPA); - if (tipo_stampa == 3) //stampa su libro unico - m.enable_page(1); - else - m.disable_page(1); - } - return TRUE; -} - -bool CG4400_application::mask_mese (TMask_field& f, KEY k) -{ - const short id = f.dlg(); - int mese; - if (id == MESE) //Per stampa su libro unico - mese = f.mask().get_int(MESE); - if (id == FINO_A_MESE) - mese = f.mask().get_int(FINO_A_MESE); //Per stampa su bollato - - /* - if (k == K_ENTER) - { - if (id == MESE) //Per stampa su libro unico - { - int umese = f.mask().get_int(ULTIMO_MESE); - if (mese != umese+1) - return f.warning_box ("Le stampe devono essere richieste mese per mese!\n" - "I mesi successivi a %s non sono ancora stati stampati.", itom(umese)); - } - } - */ - if (k == K_SPACE) - { - if (id == MESE) - if (mese == 12) - { - f.mask().show (TIPO_RIEPILOGATIVO); - f.mask().show (RIF_VID); - } - else - { - f.mask().hide (TIPO_RIEPILOGATIVO); - f.mask().hide (RIF_VID); - } - if (id == FINO_A_MESE) - { - if (mese == 12) - f.mask().show (TIPO_RIEPILOGATIVO); - else f.mask().hide (TIPO_RIEPILOGATIVO); - } - } - return TRUE; -} - -bool CG4400_application::look_reg(long l, int anno, TString& codlib, int m, const char* cod, int* umese) -{ - TString16 y; - - y << anno << cod; - _tabreg->zero(); - _tabreg->put("CODTAB", y); - - if (_tabreg->read() == NOERR) - { - int tipo = _tabreg->get_int("I0"); - if (tipo == 1 || tipo == 2) - { - TString16 cod_lib_un = _tabreg->get("S6"); - TDate u_data = _tabreg->get_date("D3"); - TDate sca_vid = _tabreg->get_date("D0"); - *umese = u_data.month(); - if (_selected[l]) - { - if (codlib != cod_lib_un) - { - message_box("Ditta %ld: il codice libro unico del registro non e' uguale al codice libro unico indicato", _nditte->get_long("CODDITTA")); - return FALSE; - } - if (m < *umese) - { - message_box("Ditta %ld: il mese indicato e' inferiore al mese dell'ultima data di stampa del registro", _nditte->get_long("CODDITTA")); - return FALSE; - } - if (sca_vid.month() < m) - { - message_box("Ditta %ld: la data scadenza di vidimazione del registro non deve essere inferiore al mese indicato", _nditte->get_long("CODDITTA")); - return FALSE; - } - } - /* - if (*umese < m - 1) - { - app().TApplication::set_firm(__firm); - return error_box("Ditta %ld: Stampare i registri dei mesi precedenti", _nditte->get_long("CODDITTA")); - } - */ - return TRUE; - } - } - return FALSE; -} - -bool CG4400_application::look_regs(int anno, TString& codlib, int m, int* umese) -{ - int a, tipo; - TString16 codtab; - *umese = 13; - - for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) - { - tipo = _tabreg->get_int("I0"); - codtab = _tabreg->get("CODTAB"); - a = atoi(codtab.mid(0,4)); - if (a > anno) - { - // message_box("Non esistono registri IVA della Ditta %ld per l'anno %d", _nditte->get_long("CODDITTA"), anno); - // break; - return FALSE; - } - if (a == anno) - if ( tipo == 1 || tipo == 2 ) //registro iva - { - TString16 cod_lib_un = _tabreg->get("S6"); - TDate sca_vid = _tabreg->get_date("D0"); - TDate u_data = _tabreg->get_date("D3"); - if (codlib != cod_lib_un) - continue; - if (m < u_data.month()) - continue; - if (sca_vid.month() < m) - continue; - if (u_data.month() < m - 1) - { - app().TApplication::set_firm(__firm); - return error_box("Ditta %ld: Stampare i registri dei mesi precedenti", _nditte->get_long("CODDITTA")); - } - *umese = (*umese < u_data.month()) ? *umese : u_data.month(); - } - } - return TRUE; -} - -bool CG4400_application::mask_libun (TMask_field& f, KEY k) -{ - //TString16 cod(f.mask().get(CODICE_LIBRO_IVA)); - - //if ( (k == K_TAB && f.mask().is_running()) || (k == K_ENTER && cod.not_empty()) ) - if ( k == K_ENTER ) - { - TString16 cod(f.mask().get(CODICE_LIBRO_IVA)); - TString16 codlib(f.mask().get(CODICE_LIB_UN)); - int fino_a_mese = f.mask().get_int(MESE); - int anno = f.mask().get_int(ANNO); - bool ok = FALSE; - long l; - int last_mese = 13; - int mese; - - app().__firm = app().TApplication::get_firm(); - - for (l = 0l, app()._nditte->first(); !app()._nditte->eof(); l++, app()._nditte->next()) - { - if (!prefhndl->exist(app()._nditte->get_long("CODDITTA"))) - continue; - app().TApplication::set_firm(app()._nditte->get_long("CODDITTA")); - - if (cod.not_empty()) - { - ok = app().look_reg(l,anno,codlib,fino_a_mese,cod,&mese); - if ( app()._selected[l] && !ok) - { - f.message_box("Ditta %ld: il registro %s non soddisfa i parametri indicati",app()._nditte->get_long("CODDITTA"), (const char*)cod); - continue; - } - if (mese < fino_a_mese - 1) //indipendentemente se si tratta di una ditta selezionata oppure no - { - app().TApplication::set_firm(app().__firm); - return error_box("Ditta %ld: Stampare i registri dei mesi precedenti", app()._nditte->get_long("CODDITTA")); - } - } - else - { - ok = app().look_regs(anno,codlib,fino_a_mese,&mese); - - if ( app()._selected[l] && (!ok || mese == 13) ) - { - f.message_box("Ditta %ld: nessun registro soddisfa i parametri indicati", app()._nditte->get_long("CODDITTA")); - continue; - } - } - if (app()._selected[l]) - last_mese = (last_mese < mese) ? last_mese : mese; - } - app().TApplication::set_firm(app().__firm); - if (last_mese == 13) - return FALSE; - const char* me = ""; - me = format("%02d", last_mese); - f.mask().set(ULTIMO_MESE, me); - } - return TRUE; -} - -bool CG4400_application::mask_cod (TMask_field& f, KEY k) -{ - TTable TabLbu ("%LBU"); - TString codtab; - int anno; - - if (k == K_TAB || f.focusdirty()) - { - TString codlib = f.mask().get(CODICE_LIB_UN); - anno = f.mask().get_int(ANNO); - - TabLbu.zero(); - codtab.format ("%04d%-3s", anno, (const char*)codlib); - TabLbu.put ("CODTAB", codtab); - TabLbu.read(); - if ( TabLbu.good() ) - { - //f.mask().set(ULTIMO_MESE,TabLbu.get_long("I0")); - f.mask().set(ULTIMA_PAGINA,TabLbu.get_long("I1")); - app()._codice_vidi = TabLbu.get("S4"); - } - } - return TRUE; -} - -bool CG4400_application::mask_data (TMask_field& f, KEY k) -{ - if (k == K_TAB) - { - const int anno = f.mask().get_int(ANNO); - TDate data(f.get()); - if (data.ok()) - if (data.year() != anno) - { - f.warning_box("L'anno delle date limite deve essere uguale all'anno iva specificato"); - return FALSE; - } - if (f.dlg() == A_DATA) - if (data.ok) - if ( data.day() == 31 && data.month() == 12 ) - f.mask().show (TIPO_RIEPILOGATIVO); - else f.mask().hide (TIPO_RIEPILOGATIVO); - } - return TRUE; -} - -const char * CG4400_application::descr_doc() -{ - TTable tab_tpd("%TPD"); - TString codtab(format("%-2s",(const char*) _tipodoc)); - - tab_tpd.zero(); - tab_tpd.put("CODTAB", codtab); - if (tab_tpd.read()==NOERR) - TMP = tab_tpd.get("S0"); - else - TMP = ""; - - return TMP; -} - -const char * CG4400_application::descr_iva(const char * cod) -{ - TTable tab_iva("%IVA"); - TString codtab(format ("%-4s", cod)); - - tab_iva.zero(); - tab_iva.put("CODTAB", codtab); - if (tab_iva.read()==NOERR) - TMP = tab_iva.get("S0"); - else - TMP = ""; - - return TMP; -} - -const char * CG4400_application::tipo_attivita() -{ - TLocalisamfile attiv (LF_ATTIV); - - attiv.zero(); - attiv.put("CODDITTA", get_firm()); - attiv.put("CODATT", _codatt); - if (attiv.read() == NOERR) - TMP = attiv.get("TIPOATT"); - else TMP = ""; - return TMP; -} - -const char * CG4400_application::desc_attivita() -{ - TTable attiv ("%AIS"); - - attiv.zero(); - attiv.put("CODTAB", _codatt); - if (attiv.read()==NOERR) - TMP = attiv.get("S0"); - else - TMP = ""; - return TMP; -} - -TRectype& CG4400_application::ricerca_cf(char tipocf, long codcf) -{ - _clifo->zero(); - _clifo->put(CLI_TIPOCF, tipocf); - _clifo->put(CLI_CODCF, codcf); - _clifo->read(); - if (_clifo->bad()) - _clifo->zero(); - - return _clifo->curr(); -} - -TRectype& CG4400_application::ricerca_occ(const char * occ) -{ - TLocalisamfile occas (LF_OCCAS); - occas.zero(); - occas.put(OCC_CFPI, occ); - occas.read(); - if (occas.bad()) - occas.zero(); - - return occas.curr(); -} - -bool CG4400_application::user_create() -{ - _nditte = new TLocalisamfile(LF_NDITTE); - _com = new TLocalisamfile(LF_COMUNI); - _anag = new TLocalisamfile(LF_ANAG); - _unloc = new TLocalisamfile(LF_UNLOC); - _attiv = new TLocalisamfile(LF_ATTIV); - _tab = new TLocalisamfile(LF_TAB); - _tabcom = new TLocalisamfile(LF_TABCOM); - _tabreg = new TTable("REG"); - _tabiva = new TTable("%IVA"); - _tablbu = new TTable("%LBU"); - _tabinl = new TTable("%INL"); - _tablim = new TTable("LIM"); - _tabpim = new TTable("PIM"); - _tablia = new TTable("LIA"); - _tabpla = new TTable("PLA"); - _tabppa = new TTable("PPA"); - _tabvid = new TTable("VID"); - _clifo = new TLocalisamfile(LF_CLIFO); - _occas = new TLocalisamfile(LF_OCCAS); - _rel = new TRelation (LF_MOV); - - _rel->add(LF_CAUSALI,"CODCAUS=CODCAUS",1,LF_MOV); - _rel->add(LF_RMOVIVA,"NUMREG=NUMREG",1,LF_MOV); - - _cur = new TCursor(_rel, "", 2); - - _ditte = new TArray_sheet(-1, -1, 0, 0, "Selezione Ditte", - "@1|Cod.@5|Ragione Sociale@50"); - - long firm = TApplication::get_firm(); - - for (_nditte->first(); !_nditte->eof(); _nditte->next()) - { - if (!prefhndl->exist(_nditte->get_long("CODDITTA"))) - continue; - TToken_string* d = new TToken_string(64); - d->add(" "); - d->add(_nditte->get("CODDITTA")); - d->add(_nditte->get("RAGSOC")); - _ditte->add(*d); - } - _n_ditte = _ditte->items(); - - TApplication::set_firm(firm); - - add_cursor(_cur); - add_file(LF_MOV); - add_file(LF_RMOVIVA); - - return TRUE; -} - -bool CG4400_application::user_destroy() -{ - delete _ditte; - delete _nditte; - delete _com; - delete _unloc; - delete _anag; - delete _attiv; - delete _tab; - delete _tabcom; - delete _tabreg; - delete _tabiva; - delete _tablbu; - delete _tabinl; - delete _tablim; - delete _tabpim; - delete _tablia; - delete _tabpla; - delete _tabppa; - delete _tabvid; - delete _clifo; - delete _occas; - delete _cur; - delete _rel; - - return TRUE; -} - -/* - void CG4400_application::calcola_progressivi(real& r0, real& r1, real& r2, const char* codiva, const int tipocr) - { - TTable pim ("PIM"); - TString chiave; - int i, num=0; - - if (_tipo_stampa == 2) - num = _datareg.month(); - if ( (_tipo_stampa == 3) || (_tipo_stampa == 4) ) - num = _fino_a_mese; - - if (_frequiva == 'T') - for (i=3; isave_status(); - TLocalisamfile& rmoviva = _cur->file(LF_RMOVIVA); - bool ok = _cur->is_first_match(LF_RMOVIVA); - int nrec = 0; - - TRecnotype nr = rmoviva.recno(); - - while (ok) - { - nrec++; - TRectype iva (rmoviva.curr()); - tipodet = iva.get_int (RMI_TIPODET); - tipocr = iva.get_int (RMI_TIPOCR); - impo = iva.get_real(RMI_IMPONIBILE); - impos = iva.get_real(RMI_IMPOSTA); - codiva = iva.get(RMI_CODIVA); - intra = iva.get_bool(RMI_INTRA); - tipoatt = iva.get_int("TIPOATT"); - - _riga_rmi.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,tipocr,intra,tipoatt); - - if (_tipo_stampa == 1) //stampa di prova - { - if (_tipodoc == "FS") - { - real somma = -(impo + impos); - _tot_iva_array.add_riga(ZERO,ZERO,somma,ZERO,ZERO,ZERO,codiva); - } - else if (_tipodoc == "CR" || _tipodoc == "RF" || _tipodoc == "SC") - _tot_iva_array.add_riga(ZERO,ZERO,impo+impos,ZERO,ZERO,ZERO,codiva); - if (_tipodoc != "CR" && _tipodoc != "SC" && _tipodoc != "RF") - _tot_iva_array.add_riga(impo,impos,ZERO,ZERO,ZERO,ZERO,codiva); - - if (_tipo_reg == 2) //registro acquisti (non ha senso parlare di importi lordi) - _iva_array.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,0,TRUE); - } - - ok = _cur->next_match(LF_RMOVIVA); - } - //_cur->restore_status(); - rmoviva.readat(nr); - - return nrec; -} - -int CG4400_application::setta_riga(int r, const TRigaiva& riga, real& tot1, - real& tot2, real& tot3, real& tot4) -{ - set_row(r, "%3s", (const char*)riga._codiva); - TString descr = descr_iva(riga._codiva); - set_row(r, "@5g%s",(const char*)descr); - set_row(r, "@25g%r", &riga._imponibile); - set_row(r, "@41g%r", &riga._imposta); - if (_tipo_stampa != 1) - { - set_row(r, "@81g%r", &riga._imponibilep); - set_row(r++, "@98g%r", &riga._impostap); - } - else r++; - tot1 += riga._imponibile; - tot2 += riga._imposta; - tot3 += riga._imponibilep; - tot4 += riga._impostap; - - return r; -} - -bool CG4400_application::controlla_liquidazione() -{ - TTable lim ("LIM"); - TTable pim ("PIM"); - TString mesi_ric = ""; - TString mesi_cal = ""; - TString16 chiave = ""; - TString16 ditta = ""; - int i, mese; - - ditta << get_firm(); - - if (lim.empty()) - return yesno_box("Ditta %s: non esiste la tabella liquidazione iva mensile! Vuoi ugualmente continuare la stampa?", (const char*) ditta); - if (pim.empty()) - return yesno_box("Ditta %s: non esiste la tabella progressivi iva mensile! Vuoi ugualmente continuare la stampa?", (const char*) ditta); - - if (_tipo_stampa == 1) //stampa di prova - mese = _data_a.month(); - else - mese = _fino_a_mese; - - if (_tipo_riepilogativo == ' ' || _tipo_riepilogativo == 'P') - { - if (_frequiva == 'T') //nella tabella LIM ho solo i mesi 3, 6, 9, 12 - { - for (i=3; i<=mese; i+=3) - { - chiave = ""; - chiave << _annoes << i; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - bool calcolato = lim.get_bool("B0"); - if (!calcolato) - mesi_ric << itom(i) << "\n"; - } - else - mesi_cal << itom(i) << "\n"; - } - } - if (_frequiva == 'M') - { - for (i=1 ; i<=mese; i++) - { - chiave = ""; - chiave << _annoes << i; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - bool calcolato = lim.get_bool("B0"); - if (!calcolato) - mesi_ric << itom(i) << "\n"; - } - else - mesi_cal << itom(i) << "\n"; - } - } - if (mesi_ric.not_empty()) - { - _liquidazione = FALSE; - warning_box ("Ditta %s: deve essere ricalcolata la liquidazione relativa ai mesi di:\n %s ", (const char*)ditta, (const char *)mesi_ric); - return yesno_box("Vuoi ugualmente continuare la stampa?"); - } - if (mesi_cal.not_empty()) - { - _liquidazione = FALSE; - warning_box ("Ditta %s: la liquidazione relativa ai mesi di \n %s non e' stata ancora calcolata", (const char*)ditta, (const char *)mesi_cal); - return yesno_box("Vuoi ugualmente continuare la stampa?"); - } - } - else if (_tipo_riepilogativo == 'A') - if (_riep_liq) - { - chiave = ""; - chiave << _annoes << 13; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - bool calcolato = lim.get_bool("B0"); - if (!calcolato) - { - _liquidazione = FALSE; - return yesno_box("Ditta %s: non eseguito calcolo liquidazione. Vuoi ugualmente continuare la stampa?", (const char*)ditta); - } - } - //else ? - } - return TRUE; -} - -//controlla che i movimenti con anno data di registrazione < dell'anno indicato a video siano stati gia' stampati in forma definitiva*/ -//questo controllo viene fatto solo per stampa di bollato (non su libro unico) -bool CG4400_application::controlla_mov() -{ - TLocalisamfile mov (LF_MOV); - bool ok = TRUE; - bool first = TRUE; - byte tipo; - TString16 ditta = ""; - TRecnotype rec = _tabreg->recno(); - _stampa_mese = 0; - for (mov.first(); !mov.eof(); mov.next()) - { - TString16 reg = mov.get(MOV_REG); - if (reg.empty()) continue; //non e' un movimento iva - TDate datareg = mov.get_date(MOV_DATAREG); - if (_stampa_tutti_i_registri) - cerca_reg (reg, &tipo); - if ( (_stampa_tutti_i_registri && (tipo == 1 || tipo == 2)) - || (!_stampa_tutti_i_registri && reg == _codreg) ) - { - bool stampato = mov.get_bool(MOV_REGST); - if ( datareg.year() < _annoes ) - { - long numreg = mov.get_long(MOV_NUMREG); - if (!stampato) - { - ditta = ""; - ditta << get_firm(); - warning_box("Ditta %s : il movimento con numero di registrazione %ld non e' ancora stato stampato in forma definitiva!", (const char*)ditta, numreg); - ok = FALSE; - } - } - if ( datareg.year() == _annoes && first) - if (!stampato) - { - _stampa_mese = datareg.month(); - first = FALSE; - } - } - } - _tabreg->readat(rec); - return ok; -} - -bool CG4400_application::cerca_libro_gio(TString& datas) -{ - TString app(4); - app = format("%04d", _annoes); - - TRecnotype rec = _tabreg->recno(); - _tabreg->zero(); - _tabreg->put ("CODTAB", app); - TRectype r (_tabreg->curr()); - _tabreg->read(_isgteq); - for (; !_tabreg->eof(); _tabreg->next()) - { - if (_tabreg->curr() != r) break; - - int tiporeg = _tabreg->get_int("I0"); - if (tiporeg == 5) //libro giornale - { - TDate data = _tabreg->get_date("D3"); - if (_data_a > data) - { - datas = format("%02/%02d/%4d", data.day(), data.month(), data.year()); - return FALSE; - } - } - } - _tabreg->readat(rec); - return TRUE; -} - -void CG4400_application::cerca_reg(const TString& c, byte* t) -{ - TString16 cod = ""; - - cod << _annoes << c; - _tabreg->zero(); - _tabreg->put("CODTAB", cod); - if (_tabreg->read() == NOERR) - *t = _tabreg->get_int ("I0"); -} - -bool CG4400_application::ventilazione(const char* iva) -{ - TTable tabiva ("%IVA"); - TString16 chiave = ""; - chiave << iva; - tabiva.put("CODTAB", chiave); - if (tabiva.read()==NOERR) - { - TString16 vent = tabiva.get("S1"); - if (vent == "VE") - return TRUE; - } - return FALSE; -} - -int CG4400_application::stampa_prospetto() -{ - TString riga(_stampa_width); - int r=1, rr=0; - - reset_print(); - riga.fill('-'); - set_row(r, "%s", (const char*)riga); - r++; - set_row(r, "Legenda Tipo Operazione: 1=operazione intracomunitaria 2=AF art.34 comma 3"); - if (_auto_intraf) - set_row(r, "@78g3=operazione intracomunitaria e AF art.34 comma 3"); - r++; - - _stampa = stampa_totali_finali(); - if (_stampa) - { - set_row(++r, "Tipo documento@30gTotale documento"); - r+=2; - for (int j = 0; j < _doc_array.items(); j++) - { - TTipodoc& doc = (TTipodoc&)_doc_array[j]; - rr = r+j; - set_row(rr, "%2s", (const char*) doc._tipodoc); - set_row(rr, "@3g%.25s", (const char*) doc._descrdoc); - set_row(rr, "@29g%r", &doc._totdoc); - } - _doc_array.destroy(); - } - - if (rr > 0) - rr++; - else - rr = r; - - if (_stampa && _tipo_reg == 2) - if (_stampa_cred_pre && _mese_credito==0 && _credito > ZERO) - { - set_row (++rr, "** CREDITO INIZIO ANNO %r = credito iva anno precedente", &_credito); - rr++; - } - - if (_esiste_riga_iva && _stampa) - { - if (_tipo_reg == 1 && _corrispettivi) - set_row(++rr, "@26g------------------ P E R I O D O -------------------"); - else - set_row(++rr, "@26g---------- P E R I O D O -----------"); - if (_tipo_stampa != 1) - { - if (_tipo_reg == 1 && _corrispettivi) - set_row(rr,"@84g----------- P R O G R E S S I V I --------------"); - else - set_row(rr,"@82g------ P R O G R E S S I V I ------"); - } - rr++; - set_row(rr, "Cod."); - if (_tipo_reg == 2) - { - set_row(rr, "@36gA C Q U I S T I"); - if (_tipo_stampa != 1) - set_row(rr, "@92gA C Q U I S T I"); - } - if (_tipo_reg == 1) //un registro corrispettivi puo' solo essere un registro vendite - { - set_row(rr, "@37gV E N D I T E"); - if (_corrispettivi) - set_row(rr, "@63gCORRISPETTIVI"); - if (_tipo_stampa != 1) - { - if (_corrispettivi) - set_row(rr, "@94gV E N D I T E@118gCORRISPETTIVI"); - else - set_row(rr, "@93gV E N D I T E"); - } - } - rr++; - set_row(rr, "iva Descrizione@30gImponibile@49gImposta"); - if (_tipo_reg == 1 && _corrispettivi) - set_row(rr, "@63gImporti lordi"); - if (_tipo_stampa != 1) - { - if (_tipo_reg == 1 && _corrispettivi) - set_row(rr++, "@87gImponibile@107gImposta@118gImporti Lordi"); - else - set_row(rr++, "@86gImponibile@106gImposta"); - } - else rr++; - rr++; - } - return rr; -} - -//la stampa "tipi di indetraibilita'" viene fatta solo per gli acquisti -int CG4400_application::stampa_acquisti(int row) -{ - real tot_imponib, tot_imposta, tot_imponibp, tot_impostap; - row+=2; - int tdetprec = -1; - int rw = row; - tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; - - _iva_array.sort(compare_fields); - for (int s = 0; s < _iva_array.items(); s++) - { - TRigaiva& riga = (TRigaiva&)_iva_array[s]; - switch (riga._tipodet) - { - case 1: if (riga._tipodet != tdetprec) - { - set_row(rw++, "----- Indetraibile su op.es. -----"); - set_row(rw, "Cod."); - rw++; - set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); - if (_tipo_stampa != 1) - set_row(rw++, "@86gImponibile@106gImposta"); - else rw++; - rw++; - } - rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); - tdetprec = riga._tipodet; - break; - case 3: if (tdetprec == 1) - { - set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); - if (_tipo_stampa != 1) - set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); - tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; - rw+=2; - } - if (riga._tipodet != tdetprec) - { - set_row(rw++, "----- Passaggi interni -----"); - set_row(rw, "Cod."); - rw++; - set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); - if (_tipo_stampa != 1) - set_row(rw++, "@86gImponibile@106gImposta"); - else rw++; - rw++; - } - rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); - tdetprec = riga._tipodet; - break; - case 9: if ( (tdetprec == 1) || (tdetprec == 3) ) - { - set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); - if (_tipo_stampa != 1) - set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); - tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; - rw+=2; - } - if (riga._tipodet != tdetprec) - { - set_row(rw++, "----- N.D. 9 - acquisti indeducibili per ART.19 -----"); - set_row(rw, "Cod."); - rw++; - set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); - if (_tipo_stampa != 1) - set_row(rw++, "@86gImponibile@106gImposta"); - else rw++; - rw++; - } - rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); - tdetprec = riga._tipodet; - break; - default: break; - } - } - if (_iva_array.items() > 0) - if (tdetprec == 9) - { - set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); - if (_tipo_stampa != 1) - set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); - } - _iva_array.destroy(); - rw++; - return rw; -} - -/* - void CG4400_application::set_page_tot_reg() - { - TString16 codivaprec = ""; - int row=0, rr=0; - - rr = stampa_prospetto(); - - //if (_nrec > 0) //numero di records di rmoviva - if (_esiste_riga_iva && _stampa) - { - real tot_imponib, tot_imposta, tot_imponibp, tot_impostap, tot_lordo; - real dep_imponib, dep_imposta, dep_lordo; - tot_imponib = tot_imposta = tot_imponibp = tot_impostap = tot_lordo = ZERO; - dep_imponib = dep_imposta = dep_lordo = ZERO; - - _tot_iva_array.sort(compare_rows); //viene ordinato per codice iva - - for (int k = 0; k < _tot_iva_array.items(); k++) - { - TRiga& riga = (TRiga&)_tot_iva_array[k]; - //row = rr+k; - if (codivaprec == "") - codivaprec = riga._codiva; - if (codivaprec != riga._codiva) - { - set_row(rr, "%3s", (const char*)codivaprec); - TString descr = descr_iva(codivaprec); - set_row(rr, "@5g%s",(const char*)descr); - if (dep_imponib != ZERO) - set_row(rr, "@25g%r", &dep_imponib); - if (dep_imposta != ZERO) - set_row(rr, "@41g%r", &dep_imposta); - if (dep_lordo != ZERO) - set_row(rr, "@61g%r", &dep_lordo); - } - rr++; - codivaprec = riga._codiva; - dep_imponib = dep_imposta = dep_lordo = ZERO; - } - if (riga._tipodoc == "FS") - { - real somma = -(riga._imponibile + riga._imposta); - dep_lordo += somma; - } - else if (riga._tipodoc == "CR" || riga._tipodoc == "RF" || riga._tipodoc == "SC") - { - dep_lordo += riga._imponibile + riga._imposta; - tot_lordo += riga._imponibile + riga._imposta; - } - - if (riga._tipodoc != "CR" && riga._tipodoc != "SC" && riga._tipodoc == "RF") - { - dep_imponib += riga._imponibile; - dep_imposta += riga._imposta; - tot_imponib += riga._imponibile; - tot_imposta += riga._imposta; - } - - if (k == (_tot_iva_array.items()-1)) - { - set_row(rr, "%3s", (const char*)riga._codiva); - TString descr = descr_iva(riga._codiva); - set_row(rr, "@5g%s", (const char*)descr); - if (dep_imponib != ZERO) - set_row(rr, "@25g%r", &dep_imponib); - if (dep_imposta != ZERO) - set_row(rr, "@41g%r", &dep_imposta); - if (dep_lordo != ZERO) - set_row(rr, "@61g%r", &dep_lordo); - } - } - _tot_iva_array.destroy(); - rr++; - set_row(++rr, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); - if (_corrispettivi) - if (tot_lordo != ZERO) - set_row(rr, "@61g%r", &tot_lordo); - - if (_tipo_reg == 2) rr = stampa_acquisti(rr); - - if (_tipo_reg == 2 && _tipo_stampa != 1) - stampa_plafonds(rr); - } - } - */ - -void CG4400_application::set_page_tot_reg() -{ - int rr=0; - - rr = stampa_prospetto(); - - //if (_nrec > 0) //numero di records di rmoviva - if (_esiste_riga_iva && _stampa) - { - real tot_imponib, tot_imposta, tot_lordo, tot_imponibp, tot_impostap, tot_lordop; - tot_imponib = tot_imposta = tot_lordo = tot_imponibp = tot_impostap = tot_lordop = ZERO; - - _tot_iva_array.sort(compare_rows); //viene ordinato per codice iva - - for (int k = 0; k < _tot_iva_array.items(); k++) - { - TRiga& riga = (TRiga&)_tot_iva_array[k]; - //row = rr+k; - set_row(rr, "%3s", (const char*)riga._codiva); - TString80 descr = descr_iva(riga._codiva); - set_row(rr, "@5g%s",(const char*)descr); - if (riga._imponibile != ZERO) - set_row(rr, "@25g%r", &riga._imponibile); - if (riga._imposta != ZERO) - set_row(rr, "@41g%r", &riga._imposta); - if (_tipo_reg == 1 && _corrispettivi) - if (riga._implordo != ZERO) - set_row(rr, "@61g%r", &riga._implordo); - if (_tipo_stampa != 1) - { - if (riga._imponibilep != ZERO) - set_row(rr, "@81g%r", &riga._imponibilep); - if (riga._impostap != ZERO) - set_row(rr, "@98g%r", &riga._impostap); - if (_tipo_reg == 1 && _corrispettivi) - if (riga._implordop != ZERO) - set_row(rr, "@115g%r", &riga._implordop); - } - rr++; - tot_imponib += riga._imponibile; - tot_imposta += riga._imposta; - tot_lordo += riga._implordo; - tot_imponibp+= riga._imponibilep; - tot_impostap+= riga._impostap; - tot_lordop += riga._implordop; - } - _tot_iva_array.destroy(); - rr++; - set_row(++rr, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); - if (_tipo_reg == 1 && _corrispettivi) - set_row(rr, "@61g%r", &tot_lordo); - if (_tipo_stampa != 1) - { - set_row(rr, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); - if (_tipo_reg == 1 && _corrispettivi) - set_row(rr, "@115g%r", &tot_lordop); - } - - if (_tipo_reg == 2) rr = stampa_acquisti(rr); - - if (_tipo_reg == 2 && _tipo_stampa != 1) - stampa_plafonds(rr); - } -} - -void CG4400_application::stampa_plafonds(int r) -{ - TTable pla ("PLA"); - TTable ppa ("PPA"); - TString80 chiave; - int num; - real r1, r2, r3; - - r1 = r2 = r3 = ZERO; - - if (_tipo_stampa == 3) - num = _fino_a_mese; - if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) - num = _datareg.month(); - - // forza il tipoatt a 1 - char buf[10]; strcpy(buf,_codatt); - buf[strlen(buf) - 1] = '1'; - - chiave = ""; - chiave << _annoes << buf; - pla.put("CODTAB", chiave); - - if (pla.read() == NOERR) - { - r1 = pla.get_real("R1"); //totali esp. art.8 - r2 = pla.get_real("R2"); //totali esp. art.8 bis - r3 = pla.get_real("R3"); //totali esp. art 9 - } - - if (r1 > ZERO || r2 > ZERO || r3 > ZERO) - { - set_row(++r, "QUADRO RELATIVO ALLA DISPONIBILITA' E UTILIZZAZIONE MENSILE DEI PLAFONDS"); - r++; - TString mese(9); - mese = itom(num); - mese.right_just(); - set_row(++r, "%s", (const char*) mese); - r++; - } - else return; - - if (r1 > ZERO) - { - real r8 = ZERO; - r8 = stampa_valori_plafonds(r1, num, ppa); - if (r8 > ZERO) - { - real pri = ZERO; - real pre = ZERO; - chiave = ""; - chiave << _annoes << _codatt << "1" << num << "1"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri = ppa.get_real("R0"); - pre = ppa.get_real("R1"); - } - chiave = ""; - chiave << _annoes << _codatt << "2" << num << "1"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri += ppa.get_real("R0"); - pre += ppa.get_real("R1"); - } - real x = r8 - pri - pre; - set_row(r++, "ART. 8 1° comma lettere a-b Disponibile %r", &r8); - set_row(r++, "Utilizzato all'interno@33g%r", &pri); - set_row(r++, "Utilizzato per l'importazione@33g%r riporto %r", &pre, &x); - } - } - - if (r2 > ZERO) - { - real r8b = ZERO; - r8b = stampa_valori_plafonds(r2, num, ppa); - if (r8b > ZERO) - { - real pri = ZERO; - real pre = ZERO; - chiave = ""; - chiave << _annoes << _codatt << "1" << num << "2"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri = ppa.get_real("R0"); - pre = ppa.get_real("R1"); - } - chiave = ""; - chiave << _annoes << _codatt << "2" << num << "2"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri += ppa.get_real("R0"); - pre += ppa.get_real("R1"); - } - real x = r8b - pri - pre; - r++; - set_row(r++, "ART. 8 bis 1° comma Disponibile %r", &r8b); - set_row(r++, "Utilizzato all'interno@33g%r", &pri); - set_row(r++, "Utilizzato per l'importazione@33g%r riporto %r", &pre, &x); - } - } - - if (r3 > ZERO) - { - real r9 = ZERO; - r9 = stampa_valori_plafonds(r3, num, ppa); - if (r9 > ZERO) - { - real pri = ZERO; - real pre = ZERO; - chiave = ""; - chiave << _annoes << _codatt << "1" << num << "3"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri = ppa.get_real("R0"); - pre = ppa.get_real("R1"); - } - chiave = ""; - chiave << _annoes << _codatt << "2" << num << "3"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri += ppa.get_real("R0"); - pre += ppa.get_real("R1"); - } - real x = r9 - pri - pre; - r++; - set_row(r++, "ART. 8 bis 1° comma Disponibile %r", &r9); - set_row(r++, "Utilizzato all'interno@33g%r", &pri); - set_row(r++, "Utilizzato per l'importazione@33g%r riporto %r", &pre, &x); - } - } -} - -real CG4400_application::stampa_valori_plafonds(const real& r1, const int mese, TTable& ppa) -{ - real r, si8, se8; - TString80 chiave; - int i; - - r = r1; - si8 = se8 = ZERO; - if (mese > 1) - { - for (i=1; iget_long("CODDITTA"); - TString16 codtab = ""; - TString16 cod_lib_un; - TDate sca_vid; - - _tipo_stampa = m.get_int(TIPO_STAMPA); - if (_tipo_stampa == 3) //stampa su libro unico di studio - _codreg = m.get(CODICE_LIBRO_IVA); - else if (_tipo_stampa == 1) //stampa di prova - _codreg = m.get(CODICE_LIBRO_PROVA); - else _codreg = m.get(CODICE_LIBRO); - - if (_codreg.trim().empty()) - { - _stampa_tutti_i_registri = TRUE; - _tabreg->first(); - if (!_tabreg->eof()) - { - codtab = _tabreg->get("CODTAB"); - anno = atoi(codtab.mid(0,4)); - if (anno > _annoes) - { - if (_tipo_stampa != 3) //per il libro unico e' gia' stato controllato - warning_box("Non esistono registri IVA della Ditta %ld per l'anno %d", - codditta, _annoes); - return FALSE; - } - } - } - else // stampa un solo registro - { - _stampa_tutti_i_registri = FALSE; - codtab << _annoes << _codreg; - _tabreg->zero(); - _tabreg->put("CODTAB", codtab); - if (_tabreg->read() == NOERR) - { - _tipo_reg = _tabreg->get_int("I0"); - if (_tipo_reg == 1 || _tipo_reg == 2) //registro iva - { - cod_lib_un = _tabreg->get("S6"); - sca_vid = _tabreg->get_date("D0"); - if (_tipo_stampa != 1) - { - _u_data = _tabreg->get_date ("D3"); - if (!_u_data.ok()) - _u_data = format("01/01/%4d", _annoes); - } - if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) - { - if (_data_a < _u_data) - { - TString16 datas = format("%02d/%02d/%4d", _u_data.day(), _u_data.month(), _u_data.year()); - warning_box ("Ditta %ld: la data specificata non deve essere inferiore al %s (ultima data di stampa specificata sul registro)", codditta, (const char*)datas); - return FALSE; - } - if (cod_lib_un.not_empty()) - { - warning_box ("Ditta %ld: sul registro non deve essere indicato il codice del libro unico", codditta); - return FALSE; - } - if (sca_vid.month() < _fino_a_mese) - { - warning_box ("Ditta %ld: il mese della data scadenza vidimazione riportata sul registro non deve essere inferiore al mese indicato", codditta); - return FALSE; - } - if (_tipo_stampa == 4) //stampa con riferimenti al libro giornale - { - TString16 datas; - bool ok = cerca_libro_gio(datas); - if (!ok) - { - warning_box ("Ditta %ld: la data indicata non deve essere superiore al %s (ultima data di stampa del libro giornale)", codditta, (const char*)datas); - return FALSE; - } - } - } - _pagine_stampate = _tabreg->get_long("I1"); - _numini = _pagine_stampate; - _corrispettivi = _tabreg->get_bool("B0"); - _liquidazione = _tabreg->get_bool("B7"); - _riep_liq = _tabreg->get_bool("B6"); - _stampa_cred_pre = _tabreg->get_bool("B4"); - _stampa_ind_ditta = _tabreg->get_bool("B9"); - _stampa_ind_comp = _tabreg->get_bool("B5"); - _cod_un_loc = _tabreg->get_int ("I7"); - _mese_credito = _tabreg->get_int ("I8"); //campo nascosto sulla tabella dei registri: mese di stampa credito anno precedente - _mese_ultima_liq = _tabreg->get_int ("I4"); - _codatt = _tabreg->get("S8"); - _tipoatt = tipo_attivita(); - _attivita = desc_attivita(); - _desc_lib = _tabreg->get ("S0"); - } - } - else if (_tipo_stampa != 3) - { - warning_box("Il registro IVA specificato non esiste nella \n Ditta %ld", codditta); - return FALSE; - } - } - return TRUE; -} - -bool CG4400_application::compila_lib() -{ - TTable tab_lib ("%LBU"); - TString16 cod; - - cod << _annoes << _codlib; - tab_lib.zero(); - tab_lib.put("CODTAB", cod); - - if (tab_lib.read() == NOERR) - { - _stampa_ind_ditta = tab_lib.get_bool("B1"); - return TRUE; - } - return FALSE; -} - -bool CG4400_application::preprocess_print(int file, int counter) -{ - if (file == LF_MOV) - { - long items = _cur->items(); - if (!items) - return FALSE; - _iva_array.destroy(); - _riga_rmi.destroy(); - _tot_iva_array.destroy(); - _doc_array.destroy(); - _dataregp = ""; - _esiste_riga_iva = FALSE; - _auto_intraf = FALSE; - _intesta_liq = FALSE; - set_print_zero(); - if (_tipo_stampa == 3) - calcola_progressivi(); - } - return TRUE; -} - -bool CG4400_application::preprocess_page(int file, int counter) -{ - if (file == LF_MOV) - { - if (counter) return TRUE; - - reset_print(); - int rr = 0, riga = 0; - TString80 comune, prov, comcf, capcf, civcf; - TString80 viacf; - TString ragsoc; - TString tipo_op = ""; - - TLocalisamfile& mov = _cur->file(LF_MOV); - TLocalisamfile& caus = _cur->file(LF_CAUSALI); - - _datareg = mov.get_date(MOV_DATAREG); - - if (_tipo_stampa == 2 || _tipo_stampa == 4) - for (int m = _stampa_mese; m > 0 && m < _datareg.month(); m++) - { - if (!_st_liq[m]) - if (stampo_liquidazione(m)) - { - _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header - _intesta_liq = TRUE; - TFilename t; - t.temp(); - send_message('L',t, m); - if (m > 1) printer().formfeed(); - merge_export_file(t,FALSE,TRUE); - _intesta_liq = FALSE; - _st_liq[m] = TRUE; - } - } - - _datareg = mov.get_date(MOV_DATAREG); - _mov_empty = FALSE; - - if ( _datareg.month() != _dataregp.month() && _dataregp.ok() ) - { - _auto_intraf = FALSE; - printer().formfeed(); - } - - _dataregp = _datareg; - - TDate datadoc = mov.get_date(MOV_DATADOC); - long numreg = mov.get_long(MOV_NUMREG); - long protiva = mov.get_long(MOV_PROTIVA); - long uprotiva = mov.get_long(MOV_UPROTIVA); - real totdoc = mov.get_real(MOV_TOTDOC); - TString16 numdoc = mov.get(MOV_NUMDOC); - char tipocf = mov.get(MOV_TIPO)[0]; - TString16 ocfpi = mov.get(MOV_OCFPI); - long codcf = mov.get_long(MOV_CODCF); - long numgio = mov.get_long(MOV_NUMGIO); - bool stampato = mov.get_bool(MOV_REGST); - TString16 codval = mov.get(MOV_CODVALI); - real corrval = mov.get_real(MOV_CORRVALUTA); - bool intra = caus.get_bool(CAU_INTRACOM); //da prendere sul movimento ? - bool autof = caus.get_bool(CAU_AUTOFATT); - TString80 descrcau = caus.get(CAU_DESCR); - - if (_cur->pos() == 0) - _uprotivap = uprotiva ? uprotiva : protiva; - - //aggiornamento di mov - if (_tipo_stampa != 1) - if (!stampato) - { - mov.put(MOV_REGST,TRUE); - mov.rewrite(); - } - - if ( intra && autof) - { - _auto_intraf = TRUE; - tipo_op = "3"; - } - else if (intra) - tipo_op = "1"; - else if (autof) - tipo_op = "2"; - - if (codcf == 0l) - ragsoc = descrcau; - else - { - if (ocfpi.trim().empty()) - { - TRectype dep = ricerca_cf(tipocf, codcf); - ragsoc = dep.get (CLI_RAGSOC); - viacf = dep.get (CLI_INDCF); - civcf = dep.get (CLI_CIVCF); - capcf = dep.get (CLI_CAPCF); - comcf = dep.get (CLI_COMCF); - } - else - { - TRectype dep = ricerca_occ(ocfpi); - ragsoc = dep.get (OCC_RAGSOC); - viacf = dep.get (OCC_INDIR); - civcf = dep.get (OCC_CIV); - capcf = dep.get (OCC_CAP); - comcf = dep.get (OCC_COM); - } - TRectype com = look_comuni(comcf); - comune = com.get(COM_DENCOM); - prov = com.get(COM_PROVCOM); - } - - _tipodoc = mov.get(MOV_TIPODOC); - _descr_doc = descr_doc(); - TString app = datadoc.string(2, '/'); - - if (stampa_totali_finali()) - _doc_array.add_riga(_tipodoc,_descr_doc,totdoc); - - //setto le righe di stampa - _r = 1; - if (_stampa_data_reg) - set_row(_r, "%s", (const char*) _datareg.string(2, '/')); - set_row(_r, "@9g%5d", protiva); - if (datadoc.ok()) - set_row(_r, "@15g%s", (const char*) app); - set_row(_r, "@24g%s", (const char*) numdoc); - set_row(_r, "@32g%ld", codcf); - set_row(_r, "@39g%.28s",(const char*) ragsoc); - set_row(_r, "@68g%s", (const char*) tipo_op); - set_row(_r, "@70g%2s", (const char*) _tipodoc); - if (_stampa_width == 132) - set_row(_r, "@72g%r", &totdoc); - else set_row(_r, "@78g%r", &totdoc); - - if (_tipo_stampa == 1) //in caso di stampa di prova - if (! (_tipo_reg == 1 && _corrispettivi)) //e se non si tratta di registro vendite corrispettivi - if (! (_cur->pos()==0)) //il primo movimento non va controllato - { - if (protiva != _uprotivap + 1) - { - set_row(_r+1, "@5g*** NUM.PROT.FUORI SEQUENZA"); - riga = _r+2; - } - _uprotivap = uprotiva ? uprotiva : protiva; - } - - if (codcf != 0l && _stampa_ind_comp) - { - set_row (_r+1, "@39g%.24s %.3s",(const char *)viacf, (const char *)civcf); - set_row (_r+2, "@39g%s %.22s", (const char *)capcf, (const char *)comune); - riga = _r+3; - } - _nrec = riga_rmoviva(); - if (_nrec > 0) - { - _esiste_riga_iva = TRUE; - for (int j = 0; j < _riga_rmi.items(); j++) - { - TRigaiva& riga = (TRigaiva&)_riga_rmi[j]; - rr = _r+j; - if (_stampa_width == 132) - { - set_row(rr, "@87g%r", &riga._imponibile); - set_row(rr, "@102g%4s",(const char*)riga._codiva); - if (_tipo_reg == 2) - set_row(rr, "@107g%d", riga._tipodet); - set_row(rr, "@108g%r", &riga._imposta); - set_row(rr, "@124g%d", riga._tipocr); - if (_tipoatt == "E") - set_row(rr, "@126g%d", riga._tipoatt); - if (_tipo_stampa == 4) //stampa con riferimento al libro giornale - set_row(rr, "@127g%4ld", numgio); - } - else //stampa a 198 - { - set_row(rr, "@93g%r", &riga._imponibile); - set_row(rr, "@109g%4s",(const char*)riga._codiva); - if (_tipo_reg == 2) - set_row(rr, "@114g%d", riga._tipodet); - set_row(rr, "@116g%r", &riga._imposta); - if (_tipoatt == "E") - set_row(rr, "@132g%d", riga._tipoatt); - set_row(rr, "@134g%d", riga._tipocr); - if (_tipo_stampa == 4) //stampa con riferimento al libro giornale - set_row(rr, "@136g%7ld", numgio); - } - } - _riga_rmi.destroy(); - } - if (_tipo_stampa == 1) //stampa di prova - { - if (_stampa_width == 132) - { - set_row(_r, "@127g%4ld", numreg); - if (stampato) - set_row(_r, "@131g*"); //solo in stampa di prova! - } - else //198 - { - set_row(_r, "@136g%7ld", numreg); - if (stampato) - set_row(_r, "@144g*"); - } - } - if (_tipo_stampa == 4 && _stampa_width == 198) - { - TLocalisamfile rmoviva (LF_RMOVIVA); - rmoviva.zero(); - rmoviva.put(RMI_NUMREG,numreg); - TRectype rec(rmoviva.curr()); - rmoviva.read(_isgteq); - for ( ; !rmoviva.eof(); rmoviva.next()) - { - if (rmoviva.curr() != rec) break; - - int gruppo = rmoviva.get_int("GRUPPO"); - int conto = rmoviva.get_int("CONTO"); - long sottoc = rmoviva.get_long("SOTTOCONTO"); - TConto tc (gruppo,conto,sottoc); - TString80 descr = tc.descrizione(); - set_row(_r, "@144g%3d %3d %6d", gruppo, conto, sottoc); - set_row(_r, "@160g%s", (const char*) descr); - break; - } - } - - if (riga == 0) riga = ++rr; - - if (corrval != ZERO) - set_row(riga, "@30gCodice valuta %s Corrispettivo in valuta %r", (const char*) codval, &corrval); - - //int tipocr = _cur->file(LF_RMOVIVA)->get_int(RMI_TIPOCR); - //set_row(_r, "@124g%d", tipocr); - - //if (_tipo_stampa == 4) - // set_row(_r, "@125g%ld", numgio); - } - return TRUE; -} - -void CG4400_application::aggiorna_reg() -{ - TString16 codtab; - TTable Tabreg ("REG"); - TTable TabInl ("%INL"); - int mese; - //long pag; - //long stampate; - - word ultimast = get_page_number(); - if (_stampa_tutti_i_registri) //ho fatto un salto pagina dopo avere stampato un registro - --ultimast; - - codtab << _annoes << _codreg; - Tabreg.zero(); - Tabreg.put("CODTAB", codtab); - if (Tabreg.read() == NOERR) - { - TDate d = Tabreg.get_date("D3"); - //stampate = ultimast + 1; - if (!_mov_empty) //cioe' se e' stata stampata almeno una pagina - { - TDate ultima_data = format("%02d/%02d/%4d", _datareg.last_day(_datareg.month(), _annoes), _datareg.month(), _annoes); - if (ultima_data > d) - Tabreg.put("D3", ultima_data); - //pag = _pagine_stampate + ultimast; - //Tabreg.put("I1", pag); - } - else if (_data_a > d) - Tabreg.put("D3", _data_a); - - Tabreg.put("I1", _pagine_stampate); - if (_tipo_reg == 2 && _stampa_cred_pre) - if (_mese_credito == 0 && _credito > ZERO) - if (_mov_empty) - Tabreg.put("I8", (long)_fino_a_mese); - else Tabreg.put("I8", _datareg.month()); - - Tabreg.rewrite(); - } - if (_tipo_stampa == 3) //stampa su libro unico - //sulla tabella %inl (indice libro unico) devo generare una riga per ogni registro stampato (ricordarsi che la stampa su libro unico deve avvenire mese per mese! - //inoltre non posso stampare due volte lo stesso mese perche' la stampa avviene a fine mese - if (!_mov_empty || _ok_vidi) //se ho stampato almeno un movimento oppure ho stampato la vidimazione - { - bool trovato = FALSE; - codtab = ""; - codtab << _annoes << _codlib; - TabInl.zero(); - TRectype nuovo (TabInl.curr()); - TRectype recprec (TabInl.curr()); - TabInl.put("CODTAB", codtab); - - TRectype rec (TabInl.curr()); - TabInl.read (_isgteq); - for (; !TabInl.eof(); TabInl.next()) - { - if (TabInl.curr() != rec) break; - - mese = TabInl.get_int("I1"); - trovato = TRUE; - recprec = TabInl.curr(); - if (mese == _fino_a_mese) break; //cosi' mi posiziono su quel mese (altrimenti rischio di generare due righe per lo stesso mese e registro => la stampa di vidimazione mi sballa tutta!!! - } - TString cod = ""; - if (trovato && mese != _fino_a_mese) - { - TString16 cod_inl = recprec.get("CODTAB"); - long numero_riga = atol(cod_inl.mid(7,6)) + 1; - TString16 num_riga (format("%6d", numero_riga)); - cod_inl = cod_inl.mid(0,7); - nuovo = recprec; - cod << cod_inl << num_riga; - } - else if (mese != _fino_a_mese) - { - TString16 num_riga ( format("%6d", 0L) ); - cod << codtab << num_riga; - } - else - { - TString16 cod_inl = recprec.get("CODTAB"); - TString16 numero_riga = cod_inl.mid(7,6); - cod << codtab << numero_riga; - } - //long numini = _pagine_stampate + 1; - nuovo.put("CODTAB", cod); - nuovo.put("I0", (long)_annoes); - nuovo.put("I1", (long)_fino_a_mese); // su libro unico ho un solo mese in gioco! - nuovo.put("I2", (long)(_primast + 1)); // numero iniziale pagina libro unico - //nuovo.put("I3", (long)(_primast + ultimast)); // numero finale pagina libro unico - nuovo.put("I3", (long)(_u_stampata)); // numero finale pagina libro unico - nuovo.put("I4", get_firm()); - nuovo.put("S0", _codreg); - nuovo.put("S1", _codice_vidi); - //nuovo.put("I5", (long)numini); //numero iniziale pagina registro utente - //nuovo.put("I6", (long)(numini + ultimast - 1)); //numero finale pagina registro utente - nuovo.put("I5", _numini + 1); - nuovo.put("I6", _pagine_stampate); - - if (mese == _fino_a_mese) - TabInl.rewrite(nuovo); - else - TabInl.write(nuovo); - - //_u_stampata += ultimast; //ultima pagina stampata sul libro unico - aggiorna_lib(); - } -} - -void CG4400_application::aggiorna_lib() -{ - TString16 cod = ""; - TTable lbu ("%LBU"); - - cod << _annoes << _codlib; - lbu.zero(); - lbu.put("CODTAB", cod); - if (lbu.read() == NOERR) - { - lbu.put("I0", (long) _fino_a_mese); - lbu.put("I1", (long) _u_stampata); - lbu.rewrite(); - } -} - -bool CG4400_application::stampo_liquidazione(int mese) -{ - if (_liquidazione) - if ( (_frequiva == 'T' && (mese == 3 || mese == 6 || mese == 9 || mese == 12)) - || _frequiva != 'T' || (mese == 12 && _tipo_riepilogativo == 'A') ) - if ( (mese == 12 && _tipo_riepilogativo == 'A' && _mese_ultima_liq != 13) - || (mese != 12 && mese > _mese_ultima_liq) - || (mese == 12 && _tipo_riepilogativo != 'A' && mese > _mese_ultima_liq) ) - return TRUE; - - return FALSE; -} - -void CG4400_application::stampa_vidi() -{ - TTable TabInl ("%INL"); - TTable TabVid ("VID"); - TString16 codtab = ""; - TString16 codreg; - TString16 vid; - long ditta; - int mese; - _ok_vidi = FALSE; - TPrintrow row; - - printer().open(); - - codtab << _annoes << _codlib; - TabInl.zero(); - TabInl.put("CODTAB", codtab); - - TRectype rec (TabInl.curr()); - TabInl.read (_isgteq); - for (; !TabInl.eof(); TabInl.next()) - { - if (TabInl.curr() != rec) break; - ditta = TabInl.get_long("I4"); - codreg = TabInl.get("S0"); - if (ditta == get_firm() && codreg == _codreg) - { - if (!_ok_vidi) - { - ++_u_stampata; - ++_pagine_stampate; - _ok_vidi = TRUE; - } - mese = TabInl.get_int("I1"); - row.reset(); - row.put(format("%s", itom(mese)), 0); - row.put(format("%6ld", TabInl.get_long("I2")), 10); - row.put(format("%6ld", _u_stampata), 17); - row.put(format("%6ld", TabInl.get_long("I5")), 25); - row.put(format("%6ld", _pagine_stampate), 32); - vid = TabInl.get("S1"); - TabVid.zero(); - TabVid.put("CODTAB", vid); - if (TabVid.read() == NOERR) - { - row.put(format("%s", (const char*)TabVid.get("S0")), 39); - row.put(format("%7d",TabVid.get_long("I0")), 71); - row.put(format("%7d",TabVid.get_long("I1")), 79); - row.put(format("%7d",TabVid.get_long("I2")), 87); - TDate d(TabVid.get_long("D0")); - row.put(format("%s", (const char*)d.string()), 95); - row.put(format("%s", (const char*)TabVid.get("S1")), 106); - } - printer().print(row); - } - } - printer().close(); -} - -print_action CG4400_application::postprocess_page (int file, int counter) -{ - if (file == LF_MOV) - { - if (counter) //dopo aver fatto un REPEAT_PAGE (cioe' dopo aver stampato le righe settate in set_page_tot_reg()), in pratica a rottura di mese o alla fine - { - //if (_tipo_stampa != 1) aggiorna_reg(); // => l'aggiornamento viene fatto o a rottura di mese o alla fine - - reset_print(); - if (_tipo_stampa != 1) - if (stampo_liquidazione(_datareg.month())) - { - _st_liq[_datareg.month()] = TRUE; - _intesta_liq = TRUE; - printer().formfeed(); - TFilename t; - t.temp(); - send_message('L',t, _datareg.month()); //stampa liquidazione - merge_export_file(t,FALSE,TRUE); - _intesta_liq = FALSE; - //if (_tipo_stampa != 1) aggiorna_reg(); - } - } - if (!counter) - { - bool FINITO = FALSE; - TRecnotype pos = _cur->pos(); - long items = _cur->items(); - - FINITO = (pos == items-1); - - if ( FINITO ) - { - if (_tipo_stampa == 2 || _tipo_stampa == 4) - calcola_progressivi(); - set_page_tot_reg(); - return REPEAT_PAGE; - } - else - { - TLocalisamfile& mov = _cur->file(LF_MOV); - _cur->save_status(); - ++(*_cur); - _dataregs = mov.get_date(MOV_DATAREG); - --(*_cur); - _cur->restore_status(); - - if (_dataregs.month() != _dataregp.month()) - { - if (_tipo_stampa == 2 || _tipo_stampa == 4) - calcola_progressivi(); - set_page_tot_reg(); - return REPEAT_PAGE; - } - } - } - } - return NEXT_PAGE; -} - -/* - print_action CG4400_application::postprocess_print(int file, int counter) - { - if (file == LF_MOV) - { - if (_stampa_tutti_i_registri) - //if (!_mov_empty ) - { - if (_tipo_stampa == 3) - ++ _u_stampata; - } - } - return NEXT_PAGE; - } - */ - -bool CG4400_application::set_print(int n) -{ - TMask m("cg4400a"); - int giorni_del_mese; - bool ok; - - m.set_handler (TIPO_STAMPA, mask_tipo_stampa); - m.set_handler (A_CODICE, mask_firm_to); - m.set_handler (DA_DATA, mask_data); - m.set_handler (A_DATA, mask_data); - m.set_handler (MESE, mask_mese); - m.set_handler (FINO_A_MESE, mask_mese); - m.set_handler (CODICE_LIB_UN, mask_cod); - m.set_handler (CODICE_LIBRO_IVA, mask_libun); - m.set_handler (DLG_SELECT, mask_select); - m.set_handler (F_ANNULLA, mask_azzera); - - set_real_picture("###.###.###.###"); - - while (ok = set_ditte(m)) - { - if (_selected.ones() > 0l) - { - _annoes = m.get_int(ANNO);//in realta' e' l'anno IVA !!! - _tipo_stampa = m.get_int(TIPO_STAMPA); - _intesta_vidi = FALSE; - _stampa_width = m.get_int(STAMPA_WIDTH); - _stampa_len = m.get_int(STAMPA_LEN); - if (_stampa_width == 1) - _stampa_width = 132; - else _stampa_width = 198; - if (_stampa_len != 0) - printer().formlen(_stampa_len); - else printer().formlen(66); - //Se stampa di prova l'utente indica data_da e data_a - if (_tipo_stampa == 1) - { - _data_stampa = m.get(DATA_STAMPA); - _data_da = m.get(DA_DATA); - _data_a = m.get(A_DATA); - if (!_data_da.ok()) - _data_da = format("01/01/%4d", _annoes); - if (!_data_a.ok()) - _data_a = format("31/12/%4d", _annoes); - TDate d(31,12,_annoes); - if (_data_a == d) - _tipo_riepilogativo = m.get(TIPO_RIEPILOGATIVO)[0]; - else _tipo_riepilogativo = ' '; - printer().setdate(_data_stampa); - } - else //stampe definitive - { - if ( (_tipo_stampa == 2) || (_tipo_stampa == 4) ) - { - _fino_a_mese = m.get_int(FINO_A_MESE); - _data_da = format("01/01/%4d", _annoes); //e non ultima data di stampa del registro (come invece verrebbe spontaneo di pensare) - } - else //stampa su libro unico - { - _codlib = m.get(CODICE_LIB_UN); - _fino_a_mese = m.get_int(MESE); - _u_stampata = m.get_int(ULTIMA_PAGINA); - _rif_vid = m.get_bool(RIF_VID); - _primast = _u_stampata; - _data_da = format("01/%02d/%04d", _fino_a_mese, _annoes); - //set_page_number(_u_stampata + 1); - } - if (_fino_a_mese == 12) - { - giorni_del_mese = 31; - _tipo_riepilogativo = m.get(TIPO_RIEPILOGATIVO)[0]; - } - else - { - _tipo_riepilogativo = ' '; - TDate primo = format("01/%02d/%4d", _fino_a_mese+1, _annoes); - --primo; - giorni_del_mese = primo.day(); - } - _data_a=format("%02d/%02d/%4d",giorni_del_mese,_fino_a_mese,_annoes); - } - _stampa_data_reg = stampa_datareg(); - if (_tipo_stampa == 3) - compila_lib(); - stampa_registri_IVA(m); - } - else - { - warning_box("Nessuna ditta selezionata!"); - continue; - } - } - return FALSE; -} - -bool CG4400_application::stampa_registri_IVA(const TMask& m) -{ - long l; - __firm = TApplication::get_firm(); - bool ok = FALSE; - - for (l = 0l, _nditte->first(); !_nditte->eof(); l++, _nditte->next()) - { - if (_selected[l]) - { - bool msg = TRUE; - TApplication::set_firm(_nditte->get_long("CODDITTA")); - TString16 y; y << _annoes; - _tablia->zero(); - _tablia->put("CODTAB", y); - if (_tablia->read() == NOERR) - { - _frequiva = _tablia->get("S7")[0]; - _credito = _tablia->get_real("R0"); //credito iva anno precedente - } - else - { - warning_box("Ditta %ld: non esiste sulla tabella di liquidazione IVA annuale il record relativo all'anno %d", _nditte->get_long("CODDITTA"), _annoes); - continue; //passa alla ditta successiva, se selezionata - } - ok = compila_reg(m); - if (!ok) continue; - if (_tipo_stampa == 2 || _tipo_stampa == 4) - if (!controlla_mov()) - { - TApplication::set_firm(__firm); - return fatal_box("Finire di stampare registri anno precedente"); - } - if (!_stampa_tutti_i_registri) - _cur->set_filterfunction(filter_func); - //_frequiva = _nditte->get("FREQVIVA")[0]; - if (!_stampa_tutti_i_registri) - { - if (_liquidazione) - { - ok = controlla_liquidazione(); - if (!ok) continue; - } - for (int i=0; i < 12; i++) - _st_liq[i] = FALSE; - - (*_cur) = 0L; - const long item = _cur->items(); - if (item > 0) //cioe' se ci sono dei movimenti da stampare - { - if (_tipo_stampa == 2 || _tipo_stampa == 4) - { - TMask mb("cg4400b"); - mb.set(COD_LIB, _codreg); - const char* m = ""; - m = format("%02d", _stampa_mese); - mb.set(U_MESE, m); - mb.set(U_PAGINA, _pagine_stampate); - mb.set(U_DATA, _u_data.string()); - KEY tasto = mb.run(); - if (tasto != K_ENTER) continue; - } - if (_tipo_stampa != 1) - { - TFilename t; - t.temp(); - send_message('C',t, _fino_a_mese); - } - print(); - } -else -{ - _mov_empty = TRUE; - int limite; - //stampo la liquidazione per tutti i mesi fino a _fino_a_mese (in caso di stampa = 2/3/4) - if (_tipo_stampa == 2 || _tipo_stampa == 4) - limite = _stampa_mese; - if (_tipo_stampa == 3) - limite = _fino_a_mese; - printer().open(); - for (int m = limite; m > 0 && m <= _fino_a_mese; m++) - { - if (stampo_liquidazione(m)) - { - _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header - _intesta_liq = TRUE; - TFilename t; - t.temp(); - send_message('L',t, m); - if (m > 1) printer().formfeed(); - merge_export_file(t,FALSE,TRUE); - _intesta_liq = FALSE; - } - } - printer().close(); -} -if (_tipo_stampa == 3 && _rif_vid) -{ - _intesta_vidi = TRUE; - stampa_vidi(); //stampa riferimenti vidimazione -} -} -else -{ - TString16 codtab, cod_lib_un; - int anno; - TDate sca_vid; - for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) - { - _tipo_reg = _tabreg->get_int("I0"); - codtab = _tabreg->get("CODTAB"); - anno = atoi(codtab.mid(0,4)); - if (anno > _annoes) - break; - if (anno == _annoes) - if ( _tipo_reg == 1 || _tipo_reg == 2 ) //registro iva - { - _codreg = codtab.mid(4,3); - cod_lib_un = _tabreg->get("S6"); - sca_vid = _tabreg->get_date("D0"); - if (_tipo_stampa != 1) - { - _u_data = _tabreg->get_date("D3"); - if (!_u_data.ok()) //e' la prima volta che stampo - _u_data = format("01/01/%4d", _annoes); - } - if (_tipo_stampa == 2 || _tipo_stampa == 4) - { - if (_data_a < _u_data) - { - message_box("Ditta %ld: Il registro %s e' gia' stato stampato come bollato di %s", _nditte->get_long("CODDITTA"), (const char*) _codreg, itom(_fino_a_mese)); - continue; - } - if (cod_lib_un.not_empty()) - continue; - if (sca_vid.month() < _fino_a_mese) - continue; - } - if (_tipo_stampa == 4) //stampa con riferimenti al libro giornale - { - long codditta = _nditte->get_long("CODDITTA"); - TString16 d; - TRecnotype rec = _tabreg->recno(); - bool trovato = cerca_libro_gio(d); - _tabreg->readat(rec); - if (!trovato) - continue; - } - if (_tipo_stampa == 3) //stampa su libro unico - { - if (cod_lib_un != _codlib) - continue; - if (_fino_a_mese < _u_data.month()) - continue; - if (sca_vid.month() < _fino_a_mese) - continue; - } - msg = FALSE; - _liquidazione = _tabreg->get_bool("B7"); - - if (_liquidazione) //per i registri "validi" eseguo il controllo liquidazione - { - ok = controlla_liquidazione(); - if (!ok) continue; - } - _riep_liq = _tabreg->get_bool("B6"); - _corrispettivi = _tabreg->get_bool("B0"); - _pagine_stampate = _tabreg->get_long("I1"); - _numini = _pagine_stampate; - _cod_un_loc = _tabreg->get_int("I7"); - _mese_ultima_liq = _tabreg->get_int("I4"); - _mese_credito = _tabreg->get_int("I8"); - _codatt = _tabreg->get("S8"); - _tipoatt = tipo_attivita(); - _attivita = desc_attivita(); - _desc_lib = _tabreg->get ("S0"); - _stampa_ind_ditta = _tabreg->get_bool ("B9"); - _stampa_ind_comp = _tabreg->get_bool ("B5"); - _stampa_cred_pre = _tabreg->get_bool ("B4"); - _cur->set_filterfunction(NULL); - _cur->set_filterfunction(filter_func); - - for (int i=0; i < 12; i++) - _st_liq[i] = FALSE; - // Vado a vedere se ci sono movimenti - (*_cur) = 0L; - const long items = _cur->items(); - if (items > 0) - { - if (_tipo_stampa == 2 || _tipo_stampa == 4) - { - TMask mb("cg4400b"); - mb.set(COD_LIB, _codreg); - const char* m = ""; - m = format("%02d", _stampa_mese); - mb.set(U_MESE, m); - mb.set(U_PAGINA, _pagine_stampate); - mb.set(U_DATA, _u_data.string()); - KEY tasto = mb.run(); - if (tasto != K_ENTER) continue; - } - if (_tipo_stampa != 1) - { - TFilename t; - t.temp(); - send_message('C',t, _fino_a_mese); - } - print(); - } - else - { - int limite; - _mov_empty = TRUE; - //stampo la liquidazione per tutti i mesi fino a _fino_a_mese (in caso di stampa = 2/3/4) - if (_tipo_stampa == 2 || _tipo_stampa == 4) - limite = _stampa_mese; - if (_tipo_stampa == 3) - limite = _fino_a_mese; - printer().open(); - for (int m = limite; m > 0 && m <= _fino_a_mese; m++) - { - if (stampo_liquidazione(m)) - { - _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header - _intesta_liq = TRUE; - TFilename t; - t.temp(); - send_message('L',t, m); - if (m > 1) printer().formfeed(); - merge_export_file(t,FALSE,TRUE); - _intesta_liq = FALSE; - } - } - printer().close(); - //if (_tipo_stampa != 1) aggiorna_reg(); - } - if (_tipo_stampa == 3 && _rif_vid) - { - _intesta_vidi = TRUE; - stampa_vidi(); //stampa riferimenti vidimazione - } - } - } //for - if (msg) - message_box("Ditta %ld: Nessun registro soddisfa i parametri indicati", _nditte->get_long("CODDITTA")); -} -//if (_tipo_stampa == 3) -// aggiorna_lib(); -} -} -TApplication::set_firm(__firm); -return TRUE; -} - - -void CG4400_application::send_message(char tipo, const TFilename& nome, int mese) -{ - //const char* const app = "cg4a -2 -icon"; - const char* const app = "cg4a -2"; - TToken_string ss(10); - //int mese ; - - /* - if (tipo == 'L') - { - if (_tipo_stampa == 3) //stampa su libro unico - mese = _fino_a_mese; - if (_tipo_stampa == 2 || _tipo_stampa == 4) - mese = _datareg.month(); - } - else mese = _fino_a_mese; - */ - - ss.add(_annoes); - ss.add(mese); - ss.add(_nditte->get_long("CODDITTA")); - ss.add(tipo); - - //if (tipo == 'L') - //{ - ss.add(_data_stampa.string()); - ss.add(nome); - ss.add("x"); - //} - - TMessage liq ("cg4a -2", "RCL", ss); - liq.send(); - - TExternal_app pn(app); - pn.run(); -} - -bool CG4400_application::set_ditte(TMask& m) -{ - _selected.reset(); - - m.field(F_SELECT).set("0"); - m.field(DA_CODICE).set(""); - m.field(A_CODICE).set(""); - m.field(TIPO_STAMPA).set("1"); - - KEY tasto; - tasto = m.run(); - // m.first_focus(tasto); - return tasto == K_ENTER; -} - -TRectype& CG4400_application::look_comuni (const char * cod) -{ - _com->zero(); - _com->put(COM_COM, cod); - _com->read(); - if (_com->bad()) - _com->zero(); - - return _com->curr(); -} - -void CG4400_application::get_dati_ditta() -{ - TLocalisamfile nditte(LF_NDITTE); - TLocalisamfile anag(LF_ANAG); - TLocalisamfile unloc(LF_UNLOC); - TString codanagr; - TString tipoa; - - nditte.zero(); - nditte.put(NDT_CODDITTA, get_firm()); - nditte.read(); - - if (nditte.bad()) nditte.zero(); - - codanagr = nditte.get(NDT_CODANAGR); - tipoa = nditte.get(NDT_TIPOA); - _ragsoc = nditte.get(NDT_RAGSOC); - - anag.setkey(1); - anag.zero(); - anag.put (ANA_TIPOA, tipoa); - anag.put (ANA_CODANAGR, codanagr); - anag.read(); - if (anag.bad()) anag.zero(); - - _cofi = anag.get(ANA_COFI); - _paiva = anag.get(ANA_PAIV); - _comunefis = anag.get(ANA_COMRF); - - if (_comunefis.empty()) - _comunefis = anag.get(ANA_COMRES); - - TRectype dep = look_comuni (_comunefis); - - _comunefis = dep.get(COM_DENCOM); - _provfis = dep.get(COM_PROVCOM); - _cap = dep.get(COM_CAPCOM); - if (_comunefis.empty()) - { - _viafis = anag.get(ANA_INDRF); - _viafis.rtrim(); - _viafis << " " << anag.get (ANA_CIVRF); - } - else - { - _viafis = anag.get(ANA_INDRES); - _viafis.rtrim(); - _viafis << " " << anag.get (ANA_CIVRES); - } - - if (_cod_un_loc) - { - unloc.zero(); - unloc.put(ULC_CODDITTA, get_firm()); - unloc.put(ULC_CODULC, _cod_un_loc); - unloc.read(); - if (unloc.read() == NOERR) - { - TRectype dep = look_comuni (unloc.get(ULC_COMULC)); - _comunefis = dep.get(COM_DENCOM); - _provfis = dep.get(COM_PROVCOM); - _cap = dep.get(COM_CAPCOM); - _viafis = unloc.get(ULC_INDULC); - _viafis.rtrim(); - _viafis << " " << unloc.get(ULC_CIVULC); - } - } -} - -int CG4400_application::stampa_intestazione() -{ - int r = 1; - TString codice_ditta; - TString riga(_stampa_width); - - get_dati_ditta(); - codice_ditta << get_firm(); - - set_header (r, "Ditta %s %s %s %s %s %s", (const char*)codice_ditta, - (const char*)_ragsoc, (const char*)_viafis, - (const char*)_cap, (const char*)_comunefis, - (const char*)_provfis); - r++; - //printer().setdate(_data); - if (_tipo_stampa == 1) - { - riga = "REGISTRO DI PROVA Data @<"; - riga.right_just(_stampa_width-6); - } - riga.overwrite (format("Partita iva %s Codice fiscale %s", (const char*)_paiva, (const char*)_cofi)); - set_header (r, riga); - - return r; -} - -void CG4400_application::preprocess_header() -{ - int r=1; - char cor, nd1, nd2; - char tipo = ' '; - char type = ' '; - int mese, anno; - TString riga(_stampa_width); - TString data(30); - - riga.fill('-'); - - if (_tipo_stampa != 3) - { - mese = _datareg.month(); - anno = _datareg.year(); - } - else - { - mese = _fino_a_mese; - anno = _annoes; - } - - data.format("%s %s %d", "mese di", itom(mese), anno); - - reset_header(); - - if (_tipo_stampa == 2 || _tipo_stampa == 4) - { - if (_stampa_ind_ditta) - r = stampa_intestazione(); - } - else //se stampa di prova o su libro unico l'intestazione della ditta va sempre stampata - r = stampa_intestazione(); - - if (_tipo_stampa == 3 && !_intesta_vidi) - { - ++_u_stampata; - ++_pagine_stampate; - } - - if (_tipo_stampa == 3) - //set_header(r, "@94gProgr.Studio %ld@114gProgr.Utente @#", _u_stampata); - set_header(r, "@94gProgr.Studio %ld@114gProgr.Utente %ld", _u_stampata, _pagine_stampate); - - if (_tipo_stampa != 1) aggiorna_reg(); //cosi' sono sicura che l'aggiornamento viene fatto ad ogni salto pagina (cioe' a rottura di mese) - - r++; - - if (!_intesta_vidi) - set_header(r, "Registro IVA: %s %s %s Attivita\' %s %s", - (const char *) _codreg, (const char *) _desc_lib, - (const char *) data, (const char *) _codatt, - (const char *) _attivita); - else - { - set_header(r++, "Registro IVA: %s %s", (const char *) _codreg, (const char *) _desc_lib); - set_header(r, "RIFERIMENTI VIDIMAZIONE"); - } - - if (_intesta_liq) - { - r++; - set_header(r++, "CALCOLO LIQUIDAZIONE IVA"); - set_header(r++,riga); - TString title (80); - title << "Liquidazione IVA del periodo: "; - title << format(" %s %d", itom(mese), anno); - set_header(r++, "%s@102g Frequenza %s", (const char*) title, _frequiva == 'T' ? "T" : "M"); - set_header(r++,riga); - set_header(r,""); - } - else - { - r++; - set_header(r, riga); - r++; - if (_tipo_reg == 1) //registro vendite - { - cor = 'R'; - nd1 = NULL; - nd2 = NULL; - } - if (_tipo_reg == 2) - { - cor = 'C'; - nd1 = 'N'; - nd2 = 'D'; - } - if (_tipoatt == "E") //attivita' mista - { - tipo = 'A'; - type = 'T'; - } - if (_stampa_data_reg && _stampa_width == 132) - set_header(r,"Data I/P"); - if (_tipo_stampa == 1) //stampa di prova (_intesta_vidi e' di sicuro FALSE) - { - if (_stampa_width == 132) - { - set_header(r,"@10gNum.@19gDocumento@68gT Tipo@76gIncassi/Pag.@103gCod %c@124gT %c@128gNum", nd1, tipo); - r++; - set_header(r, "Data reg. prot.@17gData@25gNumero Codice Ragione sociale/descrizione@68gO Doc.@76gTotale doc.@91gImponibile Iva %c@112gImposta@124g%c %c@128gReg", nd2, cor, type); - r++; - } - else //stampa a 198 - { - set_header(r,"Registrazione Documento@68gT Tipo@80gTot.Inc./Pag.@110gCod %c@132g%c T@139gNum.", nd1, tipo, cor); - r++; - set_header(r, "Data Protocollo Data@25gNumero Codice Ragione sociale/descrizione@68gO Documento@80gTot.Documento@99gImponibile Iva %c@124gImposta@132g%c %c@139gReg.", nd2, type, cor); - r++; - } - } -else if (!_intesta_vidi) -{ - if (_stampa_width == 132) - { - set_header(r,"@10gNum.@19gDocumento@68gT Tipo@76gIncassi/Pag.@103gCod %c@124gT %c", nd1, tipo); - if (_tipo_stampa == 4) //stampa definitiva con rif. al libro giornale - set_header(r, "@128gNum."); - r++; - set_header(r, "Data reg. prot.@17gData@25gNumero Codice Ragione sociale/descrizione@68gO Doc.@76gTotale doc.@91gImponibile Iva %c@112gImposta@124g%c %c", - nd2, cor, type); - if (_tipo_stampa == 4) - set_header(r, "@128gop."); - r++; - } - else //stampa a 198 - { - set_header(r,"Registrazione Documento@68gT Tipo@80gTot.Inc./Pag.@110gCod %c@132g%c T", nd1, tipo); - if (_tipo_stampa == 4) - set_header(r, "@139gNum."); - r++; - set_header(r, "Data Protocollo Data@25gNumero Codice Ragione sociale/descrizione@68gO Documento@80gTot.Documento@99gImponibile Iva %c@124gImposta@132g%c %c", nd2, type, cor); - if (_tipo_stampa == 4) - set_header(r, "@139gop. @144gCodice conto @160gDescrizione sottoconto"); - r++; - } -} -else if (_tipo_stampa == 3 && _intesta_vidi) -{ - TString tr(52); - tr.fill('-'); - set_header(r++,"@10gPagine studio Pagine utente ---------------- V I D I M A Z I O N E %s", (const char*)tr); - set_header(r++,"Mese@12gda@20ga@27gda@35ga Intestatario@71gN.fogli Pag.in. Pag.fin. Data Ufficio"); -} -if (_stampa_ind_comp && !_intesta_vidi) - set_header(r++, "@39gGeneralita'"); - - set_header(r, riga); -} -} - -int cg4400 (int argc, char * argv[]) -{ - CG4400_application a; - a.run(argc, argv, "Stampa registri IVA"); - return 0; -} - - - - - - - - - - - - - - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "conto.h" +#include "cglib03.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// cg4400.cpp +// Stampa registri IVA +#include "cg4.h" +#include "cg4400a.h" +#include "cg4400b.h" + +const int TABREG = (int)TTable::name2log("REG"); + +class CG4400_application : public TPrintapp +{ + TCursor * _cur; + TRelation *_rel; + TLocalisamfile *_clifo, *_nditte, *_occas, *_tab, *_tabcom, *_com, *_anag, *_unloc, *_attiv; + TTable *_tabreg, *_tablbu, *_tabinl, *_tablim, *_tabpim, *_tablia, *_tabiva; + TTable *_tabpla, *_tabppa, *_tabvid; + TRigaiva_array _iva_array, _riga_rmi; + TTipodoc_array _doc_array; + TRiga_array _tot_iva_array; + + TBit_array _selected; + TArray_sheet *_ditte; + bool _st_liq[12]; + TRecnotype _nrec; + bool _mov_empty, _stampa_ind_ditta, _stampa_tutti_i_registri, _auto_intraf, _stampa; + bool _corrispettivi, _liquidazione, _riep_liq, _stampa_ind_comp, _esiste_riga_iva, _stampa_cred_pre; + bool _rif_vid, _intesta_vidi, _intesta_liq, _stampa_data_reg, _ok_vidi; + char _frequiva, _tipo_riepilogativo; + TDate _data_da, _data_a, _data_stampa, _dataregp, _dataregs, _datareg; + TDate _u_data; + long _n_ditte, _u_stampata, _primast, __firm, _uprotivap; + long _numini, _pagine_stampate; + int _fino_a_mese, _tipo_reg, _tipo_stampa, _cod_un_loc; + int _annoes, _r, _stampa_width, _mese_ultima_liq, _mese_credito; + int _stampa_len, _stampa_mese; + real _totale_doc, _credito; + TString _codreg, _desc_lib, _codatt, _attivita, _tipoatt; + TString _tipodoc, _descr_doc, _codlib, _codice_vidi; + TString _cofi,_cap,_paiva,_ragsoc,_comunefis,_provfis,_viafis; + +protected: + const char* desc_attivita (); + const char* tipo_attivita (); + const char* descr_doc (); + const char* descr_iva (const char *); + TRectype& ricerca_occ(const char*); + TRectype& ricerca_cf (char, long); + TRectype& look_comuni(const char*); + int setta_riga (int, const TRigaiva&, real&, real&, real&, real&); + int riga_rmoviva(); + bool set_print(int); + bool set_ditte(TMask&); + bool compila_reg(const TMask&); + bool compila_lib(); + bool controlla_liquidazione(); + bool controlla_mov(); + bool stampo_liquidazione(int); + bool ventilazione(const char*); + bool cerca_libro_gio(TString&); + bool look_reg (long, int, TString&, int, const char*, int*); + bool look_regs(int, TString&, int, int*); + bool stampa_totali_finali(); + bool stampa_datareg(); + bool stampa_registri_IVA(const TMask&); + void cerca_reg(const TString&, byte*); + void set_page_tot_reg(); + void send_message(char, const TFilename&,int); + void aggiorna_reg(); + void aggiorna_lib(); + void calcola_progressivi(); + bool user_create(); + bool user_destroy(); + bool preprocess_page(int, int); + int stampa_intestazione(); + int stampa_prospetto(); + void stampa_plafonds(int); + void get_dati_ditta(); + void stampa_vidi(); + int stampa_acquisti(int); + real stampa_valori_plafonds(const real&, const int, TTable&); + bool preprocess_print(int, int); + //print_action postprocess_print(int, int); + print_action postprocess_page (int, int); + void preprocess_header(); + + static bool filter_func (const TRelation * r); + + static bool mask_tipo_stampa (TMask_field&, KEY); + static bool mask_firm_to (TMask_field&, KEY); + static bool mask_cod (TMask_field&, KEY); + static bool mask_libun (TMask_field&, KEY); + static bool mask_data (TMask_field&, KEY); + static bool mask_mese (TMask_field&, KEY); + static bool mask_fino_a_mese (TMask_field&, KEY); + static bool mask_select (TMask_field&, KEY); + static bool mask_azzera (TMask_field&, KEY); + +public: + + CG4400_application() : TPrintapp(), _ditte(NULL) {} + virtual ~CG4400_application() {} +}; + +static TString256 TMP; + +inline CG4400_application& app() { return (CG4400_application&)main_app(); } + +bool CG4400_application::filter_func (const TRelation * r) +{ + TLocalisamfile& mov = r->lfile(LF_MOV); + TString16 codreg = mov.get(MOV_REG); + TDate datareg = mov.get_date(MOV_DATAREG); + int annoiva = mov.get_int(MOV_ANNOIVA); + bool regst = mov.get_bool(MOV_REGST); + + if (codreg != (app()._codreg) || annoiva != (app()._annoes)) + return FALSE; + + if (app()._data_da.string() != "" && app()._data_a.string() != "") + if ( (datareg < app()._data_da || datareg > app()._data_a ) || (!datareg.ok()) ) + return FALSE; + + if (app()._tipo_stampa == 2 || app()._tipo_stampa == 4) //stampa di bollato + if (regst) //il movimento e' gia' stato stampato in forma definitiva + return FALSE; + + return TRUE; +} + +HIDDEN int compare_rows(const TObject** o1, const TObject** o2) +{ + TRiga* r1 = (TRiga*)*o1; + TRiga* r2 = (TRiga*)*o2; + + return (strcmp((const char*)r1->_codiva, (const char*)r2->_codiva)); +} + +HIDDEN int compare_fields(const TObject** o1, const TObject** o2) +{ + TRigaiva* r1 = (TRigaiva*)*o1; + TRigaiva* r2 = (TRigaiva*)*o2; + TString16 campo1; + TString16 campo2; + + campo1.format("%d%4s", r1->_tipodet, (const char*)r1->_codiva); + campo2.format("%d%4s", r2->_tipodet, (const char*)r2->_codiva); + return strcmp(campo1, campo2); +} + +bool CG4400_application::stampa_totali_finali() +{ + TConfig conf(CONFIG_DITTA); + return conf.get_bool("StTfFr"); +} + +bool CG4400_application::stampa_datareg() +{ + TConfig conf(CONFIG_STUDIO); + return conf.get_bool("NoDtRg"); +} + +bool CG4400_application::mask_select (TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + TBit_array& sel = app()._selected; + TArray_sheet& dit = *app()._ditte; + + for (int j = 0; j < dit.items(); j++) + dit.check(j, sel[j]); + + // seleziona e aggiungi alle gia' selezionate + if (dit.run() == K_ENTER) + { + for (int j = 0; j < dit.items(); j++) + sel.set(j, dit.checked(j)); + } + const long numd = sel.ones(); + f.mask().set(F_SELECT, numd); + } + return TRUE; +} + +bool CG4400_application::mask_azzera (TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + app()._selected.reset(); + app()._ditte->uncheck(-1); + f.mask().reset(F_SELECT); + } + return TRUE; +} + +bool CG4400_application::mask_firm_to (TMask_field& f, KEY k) +{ + if (k == K_TAB && f.focusdirty()) + { + TMask& m = f.mask(); + const long from = m.get_long(DA_CODICE); + long to = m.get_long(A_CODICE); + if (from != 0 || to != 0) + { + TBit_array& sel = app()._selected; + if (to == 0) to = 99999; + for (int i = 0; i < app()._ditte->items(); i++) + { + TToken_string& d = app()._ditte->row(i); + const long cod = d.get_long(1); + if (cod >= from && cod <= to) + sel.set(i); + } + // m.reset(DA_CODICE); + // m.reset(A_CODICE); + const long numd = sel.ones(); + f.mask().set(F_SELECT, numd); + } + } + return TRUE; +} + +bool CG4400_application::mask_tipo_stampa(TMask_field& f, KEY k) +{ + TMask& m = f.mask(); + + if (k == K_SPACE) + { + int tipo_stampa = m.get_int(TIPO_STAMPA); + if (tipo_stampa == 3) //stampa su libro unico + m.enable_page(1); + else + m.disable_page(1); + } + return TRUE; +} + +bool CG4400_application::mask_mese (TMask_field& f, KEY k) +{ + const short id = f.dlg(); + int mese; + if (id == MESE) //Per stampa su libro unico + mese = f.mask().get_int(MESE); + if (id == FINO_A_MESE) + mese = f.mask().get_int(FINO_A_MESE); //Per stampa su bollato + + /* + if (k == K_ENTER) + { + if (id == MESE) //Per stampa su libro unico + { + int umese = f.mask().get_int(ULTIMO_MESE); + if (mese != umese+1) + return f.warning_box ("Le stampe devono essere richieste mese per mese!\n" + "I mesi successivi a %s non sono ancora stati stampati.", itom(umese)); + } + } + */ + if (k == K_SPACE) + { + if (id == MESE) + if (mese == 12) + { + f.mask().show (TIPO_RIEPILOGATIVO); + f.mask().show (RIF_VID); + } + else + { + f.mask().hide (TIPO_RIEPILOGATIVO); + f.mask().hide (RIF_VID); + } + if (id == FINO_A_MESE) + { + if (mese == 12) + f.mask().show (TIPO_RIEPILOGATIVO); + else f.mask().hide (TIPO_RIEPILOGATIVO); + } + } + return TRUE; +} + +bool CG4400_application::look_reg(long l, int anno, TString& codlib, int m, const char* cod, int* umese) +{ + TString16 y; + + y << anno << cod; + _tabreg->zero(); + _tabreg->put("CODTAB", y); + + if (_tabreg->read() == NOERR) + { + int tipo = _tabreg->get_int("I0"); + if (tipo == 1 || tipo == 2) + { + TString16 cod_lib_un = _tabreg->get("S6"); + TDate u_data = _tabreg->get_date("D3"); + TDate sca_vid = _tabreg->get_date("D0"); + *umese = u_data.month(); + if (_selected[l]) + { + if (codlib != cod_lib_un) + { + message_box("Ditta %ld: il codice libro unico del registro non e' uguale al codice libro unico indicato", _nditte->get_long("CODDITTA")); + return FALSE; + } + if (m < *umese) + { + message_box("Ditta %ld: il mese indicato e' inferiore al mese dell'ultima data di stampa del registro", _nditte->get_long("CODDITTA")); + return FALSE; + } + if (sca_vid.month() < m) + { + message_box("Ditta %ld: la data scadenza di vidimazione del registro non deve essere inferiore al mese indicato", _nditte->get_long("CODDITTA")); + return FALSE; + } + } + /* + if (*umese < m - 1) + { + app().TApplication::set_firm(__firm); + return error_box("Ditta %ld: Stampare i registri dei mesi precedenti", _nditte->get_long("CODDITTA")); + } + */ + return TRUE; + } + } + return FALSE; +} + +bool CG4400_application::look_regs(int anno, TString& codlib, int m, int* umese) +{ + int a, tipo; + TString16 codtab; + *umese = 13; + + for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) + { + tipo = _tabreg->get_int("I0"); + codtab = _tabreg->get("CODTAB"); + a = atoi(codtab.mid(0,4)); + if (a > anno) + { + // message_box("Non esistono registri IVA della Ditta %ld per l'anno %d", _nditte->get_long("CODDITTA"), anno); + // break; + return FALSE; + } + if (a == anno) + if ( tipo == 1 || tipo == 2 ) //registro iva + { + TString16 cod_lib_un = _tabreg->get("S6"); + TDate sca_vid = _tabreg->get_date("D0"); + TDate u_data = _tabreg->get_date("D3"); + if (codlib != cod_lib_un) + continue; + if (m < u_data.month()) + continue; + if (sca_vid.month() < m) + continue; + if (u_data.month() < m - 1) + { + app().TApplication::set_firm(__firm); + return error_box("Ditta %ld: Stampare i registri dei mesi precedenti", _nditte->get_long("CODDITTA")); + } + *umese = (*umese < u_data.month()) ? *umese : u_data.month(); + } + } + return TRUE; +} + +bool CG4400_application::mask_libun (TMask_field& f, KEY k) +{ + //TString16 cod(f.mask().get(CODICE_LIBRO_IVA)); + + //if ( (k == K_TAB && f.mask().is_running()) || (k == K_ENTER && cod.not_empty()) ) + if ( k == K_ENTER ) + { + TString16 cod(f.mask().get(CODICE_LIBRO_IVA)); + TString16 codlib(f.mask().get(CODICE_LIB_UN)); + int fino_a_mese = f.mask().get_int(MESE); + int anno = f.mask().get_int(ANNO); + bool ok = FALSE; + long l; + int last_mese = 13; + int mese; + + app().__firm = app().TApplication::get_firm(); + + for (l = 0l, app()._nditte->first(); !app()._nditte->eof(); l++, app()._nditte->next()) + { + if (!prefhndl->exist(app()._nditte->get_long("CODDITTA"))) + continue; + app().TApplication::set_firm(app()._nditte->get_long("CODDITTA")); + + if (cod.not_empty()) + { + ok = app().look_reg(l,anno,codlib,fino_a_mese,cod,&mese); + if ( app()._selected[l] && !ok) + { + f.message_box("Ditta %ld: il registro %s non soddisfa i parametri indicati",app()._nditte->get_long("CODDITTA"), (const char*)cod); + continue; + } + if (mese < fino_a_mese - 1) //indipendentemente se si tratta di una ditta selezionata oppure no + { + app().TApplication::set_firm(app().__firm); + return error_box("Ditta %ld: Stampare i registri dei mesi precedenti", app()._nditte->get_long("CODDITTA")); + } + } + else + { + ok = app().look_regs(anno,codlib,fino_a_mese,&mese); + + if ( app()._selected[l] && (!ok || mese == 13) ) + { + f.message_box("Ditta %ld: nessun registro soddisfa i parametri indicati", app()._nditte->get_long("CODDITTA")); + continue; + } + } + if (app()._selected[l]) + last_mese = (last_mese < mese) ? last_mese : mese; + } + app().TApplication::set_firm(app().__firm); + if (last_mese == 13) + return FALSE; + const char* me = ""; + me = format("%02d", last_mese); + f.mask().set(ULTIMO_MESE, me); + } + return TRUE; +} + +bool CG4400_application::mask_cod (TMask_field& f, KEY k) +{ + TTable TabLbu ("%LBU"); + TString codtab; + int anno; + + if (k == K_TAB || f.focusdirty()) + { + TString codlib = f.mask().get(CODICE_LIB_UN); + anno = f.mask().get_int(ANNO); + + TabLbu.zero(); + codtab.format ("%04d%-3s", anno, (const char*)codlib); + TabLbu.put ("CODTAB", codtab); + TabLbu.read(); + if ( TabLbu.good() ) + { + //f.mask().set(ULTIMO_MESE,TabLbu.get_long("I0")); + f.mask().set(ULTIMA_PAGINA,TabLbu.get_long("I1")); + app()._codice_vidi = TabLbu.get("S4"); + } + } + return TRUE; +} + +bool CG4400_application::mask_data (TMask_field& f, KEY k) +{ + if (k == K_TAB) + { + const int anno = f.mask().get_int(ANNO); + TDate data(f.get()); + if (data.ok()) + if (data.year() != anno) + { + f.warning_box("L'anno delle date limite deve essere uguale all'anno iva specificato"); + return FALSE; + } + if (f.dlg() == A_DATA) + if (data.ok) + if ( data.day() == 31 && data.month() == 12 ) + f.mask().show (TIPO_RIEPILOGATIVO); + else f.mask().hide (TIPO_RIEPILOGATIVO); + } + return TRUE; +} + +const char * CG4400_application::descr_doc() +{ + TTable tab_tpd("%TPD"); + TString codtab(format("%-2s",(const char*) _tipodoc)); + + tab_tpd.zero(); + tab_tpd.put("CODTAB", codtab); + if (tab_tpd.read()==NOERR) + TMP = tab_tpd.get("S0"); + else + TMP = ""; + + return TMP; +} + +const char * CG4400_application::descr_iva(const char * cod) +{ + TTable tab_iva("%IVA"); + TString codtab(format ("%-4s", cod)); + + tab_iva.zero(); + tab_iva.put("CODTAB", codtab); + if (tab_iva.read()==NOERR) + TMP = tab_iva.get("S0"); + else + TMP = ""; + + return TMP; +} + +const char * CG4400_application::tipo_attivita() +{ + TLocalisamfile attiv (LF_ATTIV); + + attiv.zero(); + attiv.put("CODDITTA", get_firm()); + attiv.put("CODATT", _codatt); + if (attiv.read() == NOERR) + TMP = attiv.get("TIPOATT"); + else TMP = ""; + return TMP; +} + +const char * CG4400_application::desc_attivita() +{ + TTable attiv ("%AIS"); + + attiv.zero(); + attiv.put("CODTAB", _codatt); + if (attiv.read()==NOERR) + TMP = attiv.get("S0"); + else + TMP = ""; + return TMP; +} + +TRectype& CG4400_application::ricerca_cf(char tipocf, long codcf) +{ + _clifo->zero(); + _clifo->put(CLI_TIPOCF, tipocf); + _clifo->put(CLI_CODCF, codcf); + _clifo->read(); + if (_clifo->bad()) + _clifo->zero(); + + return _clifo->curr(); +} + +TRectype& CG4400_application::ricerca_occ(const char * occ) +{ + TLocalisamfile occas (LF_OCCAS); + occas.zero(); + occas.put(OCC_CFPI, occ); + occas.read(); + if (occas.bad()) + occas.zero(); + + return occas.curr(); +} + +bool CG4400_application::user_create() +{ + _nditte = new TLocalisamfile(LF_NDITTE); + _com = new TLocalisamfile(LF_COMUNI); + _anag = new TLocalisamfile(LF_ANAG); + _unloc = new TLocalisamfile(LF_UNLOC); + _attiv = new TLocalisamfile(LF_ATTIV); + _tab = new TLocalisamfile(LF_TAB); + _tabcom = new TLocalisamfile(LF_TABCOM); + _tabreg = new TTable("REG"); + _tabiva = new TTable("%IVA"); + _tablbu = new TTable("%LBU"); + _tabinl = new TTable("%INL"); + _tablim = new TTable("LIM"); + _tabpim = new TTable("PIM"); + _tablia = new TTable("LIA"); + _tabpla = new TTable("PLA"); + _tabppa = new TTable("PPA"); + _tabvid = new TTable("VID"); + _clifo = new TLocalisamfile(LF_CLIFO); + _occas = new TLocalisamfile(LF_OCCAS); + _rel = new TRelation (LF_MOV); + + _rel->add(LF_CAUSALI,"CODCAUS=CODCAUS",1,LF_MOV); + _rel->add(LF_RMOVIVA,"NUMREG=NUMREG",1,LF_MOV); + + _cur = new TCursor(_rel, "", 2); + + _ditte = new TArray_sheet(-1, -1, 0, 0, "Selezione Ditte", + "@1|Cod.@5|Ragione Sociale@50"); + + long firm = TApplication::get_firm(); + + for (_nditte->first(); !_nditte->eof(); _nditte->next()) + { + if (!prefhndl->exist(_nditte->get_long("CODDITTA"))) + continue; + TToken_string* d = new TToken_string(64); + d->add(" "); + d->add(_nditte->get("CODDITTA")); + d->add(_nditte->get("RAGSOC")); + _ditte->add(*d); + } + _n_ditte = _ditte->items(); + + TApplication::set_firm(firm); + + add_cursor(_cur); + add_file(LF_MOV); + add_file(LF_RMOVIVA); + + return TRUE; +} + +bool CG4400_application::user_destroy() +{ + delete _ditte; + delete _nditte; + delete _com; + delete _unloc; + delete _anag; + delete _attiv; + delete _tab; + delete _tabcom; + delete _tabreg; + delete _tabiva; + delete _tablbu; + delete _tabinl; + delete _tablim; + delete _tabpim; + delete _tablia; + delete _tabpla; + delete _tabppa; + delete _tabvid; + delete _clifo; + delete _occas; + delete _cur; + delete _rel; + + return TRUE; +} + +/* + void CG4400_application::calcola_progressivi(real& r0, real& r1, real& r2, const char* codiva, const int tipocr) + { + TTable pim ("PIM"); + TString chiave; + int i, num=0; + + if (_tipo_stampa == 2) + num = _datareg.month(); + if ( (_tipo_stampa == 3) || (_tipo_stampa == 4) ) + num = _fino_a_mese; + + if (_frequiva == 'T') + for (i=3; isave_status(); + TLocalisamfile& rmoviva = _cur->file(LF_RMOVIVA); + bool ok = _cur->is_first_match(LF_RMOVIVA); + int nrec = 0; + + TRecnotype nr = rmoviva.recno(); + + while (ok) + { + nrec++; + TRectype iva (rmoviva.curr()); + tipodet = iva.get_int (RMI_TIPODET); + tipocr = iva.get_int (RMI_TIPOCR); + impo = iva.get_real(RMI_IMPONIBILE); + impos = iva.get_real(RMI_IMPOSTA); + codiva = iva.get(RMI_CODIVA); + intra = iva.get_bool(RMI_INTRA); + tipoatt = iva.get_int("TIPOATT"); + + _riga_rmi.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,tipocr,intra,tipoatt); + + if (_tipo_stampa == 1) //stampa di prova + { + if (_tipodoc == "FS") + { + real somma = -(impo + impos); + _tot_iva_array.add_riga(ZERO,ZERO,somma,ZERO,ZERO,ZERO,codiva); + } + else if (_tipodoc == "CR" || _tipodoc == "RF" || _tipodoc == "SC") + _tot_iva_array.add_riga(ZERO,ZERO,impo+impos,ZERO,ZERO,ZERO,codiva); + if (_tipodoc != "CR" && _tipodoc != "SC" && _tipodoc != "RF") + _tot_iva_array.add_riga(impo,impos,ZERO,ZERO,ZERO,ZERO,codiva); + + if (_tipo_reg == 2) //registro acquisti (non ha senso parlare di importi lordi) + _iva_array.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,0,TRUE); + } + + ok = _cur->next_match(LF_RMOVIVA); + } + //_cur->restore_status(); + rmoviva.readat(nr); + + return nrec; +} + +int CG4400_application::setta_riga(int r, const TRigaiva& riga, real& tot1, + real& tot2, real& tot3, real& tot4) +{ + set_row(r, "%3s", (const char*)riga._codiva); + TString descr = descr_iva(riga._codiva); + set_row(r, "@5g%s",(const char*)descr); + set_row(r, "@25g%r", &riga._imponibile); + set_row(r, "@41g%r", &riga._imposta); + if (_tipo_stampa != 1) + { + set_row(r, "@81g%r", &riga._imponibilep); + set_row(r++, "@98g%r", &riga._impostap); + } + else r++; + tot1 += riga._imponibile; + tot2 += riga._imposta; + tot3 += riga._imponibilep; + tot4 += riga._impostap; + + return r; +} + +bool CG4400_application::controlla_liquidazione() +{ + TTable lim ("LIM"); + TTable pim ("PIM"); + TString mesi_ric = ""; + TString mesi_cal = ""; + TString16 chiave = ""; + TString16 ditta = ""; + int i, mese; + + ditta << get_firm(); + + if (lim.empty()) + return yesno_box("Ditta %s: non esiste la tabella liquidazione iva mensile! Vuoi ugualmente continuare la stampa?", (const char*) ditta); + if (pim.empty()) + return yesno_box("Ditta %s: non esiste la tabella progressivi iva mensile! Vuoi ugualmente continuare la stampa?", (const char*) ditta); + + if (_tipo_stampa == 1) //stampa di prova + mese = _data_a.month(); + else + mese = _fino_a_mese; + + if (_tipo_riepilogativo == ' ' || _tipo_riepilogativo == 'P') + { + if (_frequiva == 'T') //nella tabella LIM ho solo i mesi 3, 6, 9, 12 + { + for (i=3; i<=mese; i+=3) + { + chiave = ""; + chiave << _annoes << i; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + bool calcolato = lim.get_bool("B0"); + if (!calcolato) + mesi_ric << itom(i) << "\n"; + } + else + mesi_cal << itom(i) << "\n"; + } + } + if (_frequiva == 'M') + { + for (i=1 ; i<=mese; i++) + { + chiave = ""; + chiave << _annoes << i; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + bool calcolato = lim.get_bool("B0"); + if (!calcolato) + mesi_ric << itom(i) << "\n"; + } + else + mesi_cal << itom(i) << "\n"; + } + } + if (mesi_ric.not_empty()) + { + _liquidazione = FALSE; + warning_box ("Ditta %s: deve essere ricalcolata la liquidazione relativa ai mesi di:\n %s ", (const char*)ditta, (const char *)mesi_ric); + return yesno_box("Vuoi ugualmente continuare la stampa?"); + } + if (mesi_cal.not_empty()) + { + _liquidazione = FALSE; + warning_box ("Ditta %s: la liquidazione relativa ai mesi di \n %s non e' stata ancora calcolata", (const char*)ditta, (const char *)mesi_cal); + return yesno_box("Vuoi ugualmente continuare la stampa?"); + } + } + else if (_tipo_riepilogativo == 'A') + if (_riep_liq) + { + chiave = ""; + chiave << _annoes << 13; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + bool calcolato = lim.get_bool("B0"); + if (!calcolato) + { + _liquidazione = FALSE; + return yesno_box("Ditta %s: non eseguito calcolo liquidazione. Vuoi ugualmente continuare la stampa?", (const char*)ditta); + } + } + //else ? + } + return TRUE; +} + +//controlla che i movimenti con anno data di registrazione < dell'anno indicato a video siano stati gia' stampati in forma definitiva*/ +//questo controllo viene fatto solo per stampa di bollato (non su libro unico) +bool CG4400_application::controlla_mov() +{ + TLocalisamfile mov (LF_MOV); + bool ok = TRUE; + bool first = TRUE; + byte tipo; + TString16 ditta = ""; + TRecnotype rec = _tabreg->recno(); + _stampa_mese = 0; + for (mov.first(); !mov.eof(); mov.next()) + { + TString16 reg = mov.get(MOV_REG); + if (reg.empty()) continue; //non e' un movimento iva + TDate datareg = mov.get_date(MOV_DATAREG); + if (_stampa_tutti_i_registri) + cerca_reg (reg, &tipo); + if ( (_stampa_tutti_i_registri && (tipo == 1 || tipo == 2)) + || (!_stampa_tutti_i_registri && reg == _codreg) ) + { + bool stampato = mov.get_bool(MOV_REGST); + if ( datareg.year() < _annoes ) + { + long numreg = mov.get_long(MOV_NUMREG); + if (!stampato) + { + ditta = ""; + ditta << get_firm(); + warning_box("Ditta %s : il movimento con numero di registrazione %ld non e' ancora stato stampato in forma definitiva!", (const char*)ditta, numreg); + ok = FALSE; + } + } + if ( datareg.year() == _annoes && first) + if (!stampato) + { + _stampa_mese = datareg.month(); + first = FALSE; + } + } + } + _tabreg->readat(rec); + return ok; +} + +bool CG4400_application::cerca_libro_gio(TString& datas) +{ + TString app(4); + app = format("%04d", _annoes); + + TRecnotype rec = _tabreg->recno(); + _tabreg->zero(); + _tabreg->put ("CODTAB", app); + TRectype r (_tabreg->curr()); + _tabreg->read(_isgteq); + for (; !_tabreg->eof(); _tabreg->next()) + { + if (_tabreg->curr() != r) break; + + int tiporeg = _tabreg->get_int("I0"); + if (tiporeg == 5) //libro giornale + { + TDate data = _tabreg->get_date("D3"); + if (_data_a > data) + { + datas = format("%02/%02d/%4d", data.day(), data.month(), data.year()); + return FALSE; + } + } + } + _tabreg->readat(rec); + return TRUE; +} + +void CG4400_application::cerca_reg(const TString& c, byte* t) +{ + TString16 cod = ""; + + cod << _annoes << c; + _tabreg->zero(); + _tabreg->put("CODTAB", cod); + if (_tabreg->read() == NOERR) + *t = _tabreg->get_int ("I0"); +} + +bool CG4400_application::ventilazione(const char* iva) +{ + TTable tabiva ("%IVA"); + TString16 chiave = ""; + chiave << iva; + tabiva.put("CODTAB", chiave); + if (tabiva.read()==NOERR) + { + TString16 vent = tabiva.get("S1"); + if (vent == "VE") + return TRUE; + } + return FALSE; +} + +int CG4400_application::stampa_prospetto() +{ + TString riga(_stampa_width); + int r=1, rr=0; + + reset_print(); + riga.fill('-'); + set_row(r, "%s", (const char*)riga); + r++; + set_row(r, "Legenda Tipo Operazione: 1=operazione intracomunitaria 2=AF art.34 comma 3"); + if (_auto_intraf) + set_row(r, "@78g3=operazione intracomunitaria e AF art.34 comma 3"); + r++; + + _stampa = stampa_totali_finali(); + if (_stampa) + { + set_row(++r, "Tipo documento@30gTotale documento"); + r+=2; + for (int j = 0; j < _doc_array.items(); j++) + { + TTipodoc& doc = (TTipodoc&)_doc_array[j]; + rr = r+j; + set_row(rr, "%2s", (const char*) doc._tipodoc); + set_row(rr, "@3g%.25s", (const char*) doc._descrdoc); + set_row(rr, "@29g%r", &doc._totdoc); + } + _doc_array.destroy(); + } + + if (rr > 0) + rr++; + else + rr = r; + + if (_stampa && _tipo_reg == 2) + if (_stampa_cred_pre && _mese_credito==0 && _credito > ZERO) + { + set_row (++rr, "** CREDITO INIZIO ANNO %r = credito iva anno precedente", &_credito); + rr++; + } + + if (_esiste_riga_iva && _stampa) + { + if (_tipo_reg == 1 && _corrispettivi) + set_row(++rr, "@26g------------------ P E R I O D O -------------------"); + else + set_row(++rr, "@26g---------- P E R I O D O -----------"); + if (_tipo_stampa != 1) + { + if (_tipo_reg == 1 && _corrispettivi) + set_row(rr,"@84g----------- P R O G R E S S I V I --------------"); + else + set_row(rr,"@82g------ P R O G R E S S I V I ------"); + } + rr++; + set_row(rr, "Cod."); + if (_tipo_reg == 2) + { + set_row(rr, "@36gA C Q U I S T I"); + if (_tipo_stampa != 1) + set_row(rr, "@92gA C Q U I S T I"); + } + if (_tipo_reg == 1) //un registro corrispettivi puo' solo essere un registro vendite + { + set_row(rr, "@37gV E N D I T E"); + if (_corrispettivi) + set_row(rr, "@63gCORRISPETTIVI"); + if (_tipo_stampa != 1) + { + if (_corrispettivi) + set_row(rr, "@94gV E N D I T E@118gCORRISPETTIVI"); + else + set_row(rr, "@93gV E N D I T E"); + } + } + rr++; + set_row(rr, "iva Descrizione@30gImponibile@49gImposta"); + if (_tipo_reg == 1 && _corrispettivi) + set_row(rr, "@63gImporti lordi"); + if (_tipo_stampa != 1) + { + if (_tipo_reg == 1 && _corrispettivi) + set_row(rr++, "@87gImponibile@107gImposta@118gImporti Lordi"); + else + set_row(rr++, "@86gImponibile@106gImposta"); + } + else rr++; + rr++; + } + return rr; +} + +//la stampa "tipi di indetraibilita'" viene fatta solo per gli acquisti +int CG4400_application::stampa_acquisti(int row) +{ + real tot_imponib, tot_imposta, tot_imponibp, tot_impostap; + row+=2; + int tdetprec = -1; + int rw = row; + tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; + + _iva_array.sort(compare_fields); + for (int s = 0; s < _iva_array.items(); s++) + { + TRigaiva& riga = (TRigaiva&)_iva_array[s]; + switch (riga._tipodet) + { + case 1: if (riga._tipodet != tdetprec) + { + set_row(rw++, "----- Indetraibile su op.es. -----"); + set_row(rw, "Cod."); + rw++; + set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); + if (_tipo_stampa != 1) + set_row(rw++, "@86gImponibile@106gImposta"); + else rw++; + rw++; + } + rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); + tdetprec = riga._tipodet; + break; + case 3: if (tdetprec == 1) + { + set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); + if (_tipo_stampa != 1) + set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); + tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; + rw+=2; + } + if (riga._tipodet != tdetprec) + { + set_row(rw++, "----- Passaggi interni -----"); + set_row(rw, "Cod."); + rw++; + set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); + if (_tipo_stampa != 1) + set_row(rw++, "@86gImponibile@106gImposta"); + else rw++; + rw++; + } + rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); + tdetprec = riga._tipodet; + break; + case 9: if ( (tdetprec == 1) || (tdetprec == 3) ) + { + set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); + if (_tipo_stampa != 1) + set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); + tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; + rw+=2; + } + if (riga._tipodet != tdetprec) + { + set_row(rw++, "----- N.D. 9 - acquisti indeducibili per ART.19 -----"); + set_row(rw, "Cod."); + rw++; + set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); + if (_tipo_stampa != 1) + set_row(rw++, "@86gImponibile@106gImposta"); + else rw++; + rw++; + } + rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); + tdetprec = riga._tipodet; + break; + default: break; + } + } + if (_iva_array.items() > 0) + if (tdetprec == 9) + { + set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); + if (_tipo_stampa != 1) + set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); + } + _iva_array.destroy(); + rw++; + return rw; +} + +/* + void CG4400_application::set_page_tot_reg() + { + TString16 codivaprec = ""; + int row=0, rr=0; + + rr = stampa_prospetto(); + + //if (_nrec > 0) //numero di records di rmoviva + if (_esiste_riga_iva && _stampa) + { + real tot_imponib, tot_imposta, tot_imponibp, tot_impostap, tot_lordo; + real dep_imponib, dep_imposta, dep_lordo; + tot_imponib = tot_imposta = tot_imponibp = tot_impostap = tot_lordo = ZERO; + dep_imponib = dep_imposta = dep_lordo = ZERO; + + _tot_iva_array.sort(compare_rows); //viene ordinato per codice iva + + for (int k = 0; k < _tot_iva_array.items(); k++) + { + TRiga& riga = (TRiga&)_tot_iva_array[k]; + //row = rr+k; + if (codivaprec == "") + codivaprec = riga._codiva; + if (codivaprec != riga._codiva) + { + set_row(rr, "%3s", (const char*)codivaprec); + TString descr = descr_iva(codivaprec); + set_row(rr, "@5g%s",(const char*)descr); + if (dep_imponib != ZERO) + set_row(rr, "@25g%r", &dep_imponib); + if (dep_imposta != ZERO) + set_row(rr, "@41g%r", &dep_imposta); + if (dep_lordo != ZERO) + set_row(rr, "@61g%r", &dep_lordo); + } + rr++; + codivaprec = riga._codiva; + dep_imponib = dep_imposta = dep_lordo = ZERO; + } + if (riga._tipodoc == "FS") + { + real somma = -(riga._imponibile + riga._imposta); + dep_lordo += somma; + } + else if (riga._tipodoc == "CR" || riga._tipodoc == "RF" || riga._tipodoc == "SC") + { + dep_lordo += riga._imponibile + riga._imposta; + tot_lordo += riga._imponibile + riga._imposta; + } + + if (riga._tipodoc != "CR" && riga._tipodoc != "SC" && riga._tipodoc == "RF") + { + dep_imponib += riga._imponibile; + dep_imposta += riga._imposta; + tot_imponib += riga._imponibile; + tot_imposta += riga._imposta; + } + + if (k == (_tot_iva_array.items()-1)) + { + set_row(rr, "%3s", (const char*)riga._codiva); + TString descr = descr_iva(riga._codiva); + set_row(rr, "@5g%s", (const char*)descr); + if (dep_imponib != ZERO) + set_row(rr, "@25g%r", &dep_imponib); + if (dep_imposta != ZERO) + set_row(rr, "@41g%r", &dep_imposta); + if (dep_lordo != ZERO) + set_row(rr, "@61g%r", &dep_lordo); + } + } + _tot_iva_array.destroy(); + rr++; + set_row(++rr, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); + if (_corrispettivi) + if (tot_lordo != ZERO) + set_row(rr, "@61g%r", &tot_lordo); + + if (_tipo_reg == 2) rr = stampa_acquisti(rr); + + if (_tipo_reg == 2 && _tipo_stampa != 1) + stampa_plafonds(rr); + } + } + */ + +void CG4400_application::set_page_tot_reg() +{ + int rr=0; + + rr = stampa_prospetto(); + + //if (_nrec > 0) //numero di records di rmoviva + if (_esiste_riga_iva && _stampa) + { + real tot_imponib, tot_imposta, tot_lordo, tot_imponibp, tot_impostap, tot_lordop; + tot_imponib = tot_imposta = tot_lordo = tot_imponibp = tot_impostap = tot_lordop = ZERO; + + _tot_iva_array.sort(compare_rows); //viene ordinato per codice iva + + for (int k = 0; k < _tot_iva_array.items(); k++) + { + TRiga& riga = (TRiga&)_tot_iva_array[k]; + //row = rr+k; + set_row(rr, "%3s", (const char*)riga._codiva); + TString80 descr = descr_iva(riga._codiva); + set_row(rr, "@5g%s",(const char*)descr); + if (riga._imponibile != ZERO) + set_row(rr, "@25g%r", &riga._imponibile); + if (riga._imposta != ZERO) + set_row(rr, "@41g%r", &riga._imposta); + if (_tipo_reg == 1 && _corrispettivi) + if (riga._implordo != ZERO) + set_row(rr, "@61g%r", &riga._implordo); + if (_tipo_stampa != 1) + { + if (riga._imponibilep != ZERO) + set_row(rr, "@81g%r", &riga._imponibilep); + if (riga._impostap != ZERO) + set_row(rr, "@98g%r", &riga._impostap); + if (_tipo_reg == 1 && _corrispettivi) + if (riga._implordop != ZERO) + set_row(rr, "@115g%r", &riga._implordop); + } + rr++; + tot_imponib += riga._imponibile; + tot_imposta += riga._imposta; + tot_lordo += riga._implordo; + tot_imponibp+= riga._imponibilep; + tot_impostap+= riga._impostap; + tot_lordop += riga._implordop; + } + _tot_iva_array.destroy(); + rr++; + set_row(++rr, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); + if (_tipo_reg == 1 && _corrispettivi) + set_row(rr, "@61g%r", &tot_lordo); + if (_tipo_stampa != 1) + { + set_row(rr, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); + if (_tipo_reg == 1 && _corrispettivi) + set_row(rr, "@115g%r", &tot_lordop); + } + + if (_tipo_reg == 2) rr = stampa_acquisti(rr); + + if (_tipo_reg == 2 && _tipo_stampa != 1) + stampa_plafonds(rr); + } +} + +void CG4400_application::stampa_plafonds(int r) +{ + TTable pla ("PLA"); + TTable ppa ("PPA"); + TString80 chiave; + int num; + real r1, r2, r3; + + r1 = r2 = r3 = ZERO; + + if (_tipo_stampa == 3) + num = _fino_a_mese; + if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) + num = _datareg.month(); + + // forza il tipoatt a 1 + char buf[10]; strcpy(buf,_codatt); + buf[strlen(buf) - 1] = '1'; + + chiave = ""; + chiave << _annoes << buf; + pla.put("CODTAB", chiave); + + if (pla.read() == NOERR) + { + r1 = pla.get_real("R1"); //totali esp. art.8 + r2 = pla.get_real("R2"); //totali esp. art.8 bis + r3 = pla.get_real("R3"); //totali esp. art 9 + } + + if (r1 > ZERO || r2 > ZERO || r3 > ZERO) + { + set_row(++r, "QUADRO RELATIVO ALLA DISPONIBILITA' E UTILIZZAZIONE MENSILE DEI PLAFONDS"); + r++; + TString mese(9); + mese = itom(num); + mese.right_just(); + set_row(++r, "%s", (const char*) mese); + r++; + } + else return; + + if (r1 > ZERO) + { + real r8 = ZERO; + r8 = stampa_valori_plafonds(r1, num, ppa); + if (r8 > ZERO) + { + real pri = ZERO; + real pre = ZERO; + chiave = ""; + chiave << _annoes << _codatt << "1" << num << "1"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri = ppa.get_real("R0"); + pre = ppa.get_real("R1"); + } + chiave = ""; + chiave << _annoes << _codatt << "2" << num << "1"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri += ppa.get_real("R0"); + pre += ppa.get_real("R1"); + } + real x = r8 - pri - pre; + set_row(r++, "ART. 8 1° comma lettere a-b Disponibile %r", &r8); + set_row(r++, "Utilizzato all'interno@33g%r", &pri); + set_row(r++, "Utilizzato per l'importazione@33g%r riporto %r", &pre, &x); + } + } + + if (r2 > ZERO) + { + real r8b = ZERO; + r8b = stampa_valori_plafonds(r2, num, ppa); + if (r8b > ZERO) + { + real pri = ZERO; + real pre = ZERO; + chiave = ""; + chiave << _annoes << _codatt << "1" << num << "2"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri = ppa.get_real("R0"); + pre = ppa.get_real("R1"); + } + chiave = ""; + chiave << _annoes << _codatt << "2" << num << "2"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri += ppa.get_real("R0"); + pre += ppa.get_real("R1"); + } + real x = r8b - pri - pre; + r++; + set_row(r++, "ART. 8 bis 1° comma Disponibile %r", &r8b); + set_row(r++, "Utilizzato all'interno@33g%r", &pri); + set_row(r++, "Utilizzato per l'importazione@33g%r riporto %r", &pre, &x); + } + } + + if (r3 > ZERO) + { + real r9 = ZERO; + r9 = stampa_valori_plafonds(r3, num, ppa); + if (r9 > ZERO) + { + real pri = ZERO; + real pre = ZERO; + chiave = ""; + chiave << _annoes << _codatt << "1" << num << "3"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri = ppa.get_real("R0"); + pre = ppa.get_real("R1"); + } + chiave = ""; + chiave << _annoes << _codatt << "2" << num << "3"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri += ppa.get_real("R0"); + pre += ppa.get_real("R1"); + } + real x = r9 - pri - pre; + r++; + set_row(r++, "ART. 8 bis 1° comma Disponibile %r", &r9); + set_row(r++, "Utilizzato all'interno@33g%r", &pri); + set_row(r++, "Utilizzato per l'importazione@33g%r riporto %r", &pre, &x); + } + } +} + +real CG4400_application::stampa_valori_plafonds(const real& r1, const int mese, TTable& ppa) +{ + real r, si8, se8; + TString80 chiave; + int i; + + r = r1; + si8 = se8 = ZERO; + if (mese > 1) + { + for (i=1; iget_long("CODDITTA"); + TString16 codtab = ""; + TString16 cod_lib_un; + TDate sca_vid; + + _tipo_stampa = m.get_int(TIPO_STAMPA); + if (_tipo_stampa == 3) //stampa su libro unico di studio + _codreg = m.get(CODICE_LIBRO_IVA); + else if (_tipo_stampa == 1) //stampa di prova + _codreg = m.get(CODICE_LIBRO_PROVA); + else _codreg = m.get(CODICE_LIBRO); + + if (_codreg.trim().empty()) + { + _stampa_tutti_i_registri = TRUE; + _tabreg->first(); + if (!_tabreg->eof()) + { + codtab = _tabreg->get("CODTAB"); + anno = atoi(codtab.mid(0,4)); + if (anno > _annoes) + { + if (_tipo_stampa != 3) //per il libro unico e' gia' stato controllato + warning_box("Non esistono registri IVA della Ditta %ld per l'anno %d", + codditta, _annoes); + return FALSE; + } + } + } + else // stampa un solo registro + { + _stampa_tutti_i_registri = FALSE; + codtab << _annoes << _codreg; + _tabreg->zero(); + _tabreg->put("CODTAB", codtab); + if (_tabreg->read() == NOERR) + { + _tipo_reg = _tabreg->get_int("I0"); + if (_tipo_reg == 1 || _tipo_reg == 2) //registro iva + { + cod_lib_un = _tabreg->get("S6"); + sca_vid = _tabreg->get_date("D0"); + if (_tipo_stampa != 1) + { + _u_data = _tabreg->get_date ("D3"); + if (!_u_data.ok()) + _u_data = format("01/01/%4d", _annoes); + } + if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) + { + if (_data_a < _u_data) + { + TString16 datas = format("%02d/%02d/%4d", _u_data.day(), _u_data.month(), _u_data.year()); + warning_box ("Ditta %ld: la data specificata non deve essere inferiore al %s (ultima data di stampa specificata sul registro)", codditta, (const char*)datas); + return FALSE; + } + if (cod_lib_un.not_empty()) + { + warning_box ("Ditta %ld: sul registro non deve essere indicato il codice del libro unico", codditta); + return FALSE; + } + if (sca_vid.month() < _fino_a_mese) + { + warning_box ("Ditta %ld: il mese della data scadenza vidimazione riportata sul registro non deve essere inferiore al mese indicato", codditta); + return FALSE; + } + if (_tipo_stampa == 4) //stampa con riferimenti al libro giornale + { + TString16 datas; + bool ok = cerca_libro_gio(datas); + if (!ok) + { + warning_box ("Ditta %ld: la data indicata non deve essere superiore al %s (ultima data di stampa del libro giornale)", codditta, (const char*)datas); + return FALSE; + } + } + } + _pagine_stampate = _tabreg->get_long("I1"); + _numini = _pagine_stampate; + _corrispettivi = _tabreg->get_bool("B0"); + _liquidazione = _tabreg->get_bool("B7"); + _riep_liq = _tabreg->get_bool("B6"); + _stampa_cred_pre = _tabreg->get_bool("B4"); + _stampa_ind_ditta = _tabreg->get_bool("B9"); + _stampa_ind_comp = _tabreg->get_bool("B5"); + _cod_un_loc = _tabreg->get_int ("I7"); + _mese_credito = _tabreg->get_int ("I8"); //campo nascosto sulla tabella dei registri: mese di stampa credito anno precedente + _mese_ultima_liq = _tabreg->get_int ("I4"); + _codatt = _tabreg->get("S8"); + _tipoatt = tipo_attivita(); + _attivita = desc_attivita(); + _desc_lib = _tabreg->get ("S0"); + } + } + else if (_tipo_stampa != 3) + { + warning_box("Il registro IVA specificato non esiste nella \n Ditta %ld", codditta); + return FALSE; + } + } + return TRUE; +} + +bool CG4400_application::compila_lib() +{ + TTable tab_lib ("%LBU"); + TString16 cod; + + cod << _annoes << _codlib; + tab_lib.zero(); + tab_lib.put("CODTAB", cod); + + if (tab_lib.read() == NOERR) + { + _stampa_ind_ditta = tab_lib.get_bool("B1"); + return TRUE; + } + return FALSE; +} + +bool CG4400_application::preprocess_print(int file, int counter) +{ + if (file == LF_MOV) + { + long items = _cur->items(); + if (!items) + return FALSE; + _iva_array.destroy(); + _riga_rmi.destroy(); + _tot_iva_array.destroy(); + _doc_array.destroy(); + _dataregp = ""; + _esiste_riga_iva = FALSE; + _auto_intraf = FALSE; + _intesta_liq = FALSE; + set_print_zero(); + if (_tipo_stampa == 3) + calcola_progressivi(); + } + return TRUE; +} + +bool CG4400_application::preprocess_page(int file, int counter) +{ + if (file == LF_MOV) + { + if (counter) return TRUE; + + reset_print(); + int rr = 0, riga = 0; + TString80 comune, prov, comcf, capcf, civcf; + TString80 viacf; + TString ragsoc; + TString tipo_op = ""; + + TLocalisamfile& mov = _cur->file(LF_MOV); + TLocalisamfile& caus = _cur->file(LF_CAUSALI); + + _datareg = mov.get_date(MOV_DATAREG); + + if (_tipo_stampa == 2 || _tipo_stampa == 4) + for (int m = _stampa_mese; m > 0 && m < _datareg.month(); m++) + { + if (!_st_liq[m]) + if (stampo_liquidazione(m)) + { + _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header + _intesta_liq = TRUE; + TFilename t; + t.temp(); + send_message('L',t, m); + if (m > 1) printer().formfeed(); + merge_export_file(t,FALSE,TRUE); + _intesta_liq = FALSE; + _st_liq[m] = TRUE; + } + } + + _datareg = mov.get_date(MOV_DATAREG); + _mov_empty = FALSE; + + if ( _datareg.month() != _dataregp.month() && _dataregp.ok() ) + { + _auto_intraf = FALSE; + printer().formfeed(); + } + + _dataregp = _datareg; + + TDate datadoc = mov.get_date(MOV_DATADOC); + long numreg = mov.get_long(MOV_NUMREG); + long protiva = mov.get_long(MOV_PROTIVA); + long uprotiva = mov.get_long(MOV_UPROTIVA); + real totdoc = mov.get_real(MOV_TOTDOC); + TString16 numdoc = mov.get(MOV_NUMDOC); + char tipocf = mov.get(MOV_TIPO)[0]; + TString16 ocfpi = mov.get(MOV_OCFPI); + long codcf = mov.get_long(MOV_CODCF); + long numgio = mov.get_long(MOV_NUMGIO); + bool stampato = mov.get_bool(MOV_REGST); + TString16 codval = mov.get(MOV_CODVALI); + real corrval = mov.get_real(MOV_CORRVALUTA); + bool intra = caus.get_bool(CAU_INTRACOM); //da prendere sul movimento ? + bool autof = caus.get_bool(CAU_AUTOFATT); + TString80 descrcau = caus.get(CAU_DESCR); + + if (_cur->pos() == 0) + _uprotivap = uprotiva ? uprotiva : protiva; + + //aggiornamento di mov + if (_tipo_stampa != 1) + if (!stampato) + { + mov.put(MOV_REGST,TRUE); + mov.rewrite(); + } + + if ( intra && autof) + { + _auto_intraf = TRUE; + tipo_op = "3"; + } + else if (intra) + tipo_op = "1"; + else if (autof) + tipo_op = "2"; + + if (codcf == 0l) + ragsoc = descrcau; + else + { + if (ocfpi.trim().empty()) + { + TRectype dep = ricerca_cf(tipocf, codcf); + ragsoc = dep.get (CLI_RAGSOC); + viacf = dep.get (CLI_INDCF); + civcf = dep.get (CLI_CIVCF); + capcf = dep.get (CLI_CAPCF); + comcf = dep.get (CLI_COMCF); + } + else + { + TRectype dep = ricerca_occ(ocfpi); + ragsoc = dep.get (OCC_RAGSOC); + viacf = dep.get (OCC_INDIR); + civcf = dep.get (OCC_CIV); + capcf = dep.get (OCC_CAP); + comcf = dep.get (OCC_COM); + } + TRectype com = look_comuni(comcf); + comune = com.get(COM_DENCOM); + prov = com.get(COM_PROVCOM); + } + + _tipodoc = mov.get(MOV_TIPODOC); + _descr_doc = descr_doc(); + TString app = datadoc.string(2, '/'); + + if (stampa_totali_finali()) + _doc_array.add_riga(_tipodoc,_descr_doc,totdoc); + + //setto le righe di stampa + _r = 1; + if (_stampa_data_reg) + set_row(_r, "%s", (const char*) _datareg.string(2, '/')); + set_row(_r, "@9g%5d", protiva); + if (datadoc.ok()) + set_row(_r, "@15g%s", (const char*) app); + set_row(_r, "@24g%s", (const char*) numdoc); + set_row(_r, "@32g%ld", codcf); + set_row(_r, "@39g%.28s",(const char*) ragsoc); + set_row(_r, "@68g%s", (const char*) tipo_op); + set_row(_r, "@70g%2s", (const char*) _tipodoc); + if (_stampa_width == 132) + set_row(_r, "@72g%r", &totdoc); + else set_row(_r, "@78g%r", &totdoc); + + if (_tipo_stampa == 1) //in caso di stampa di prova + if (! (_tipo_reg == 1 && _corrispettivi)) //e se non si tratta di registro vendite corrispettivi + if (! (_cur->pos()==0)) //il primo movimento non va controllato + { + if (protiva != _uprotivap + 1) + { + set_row(_r+1, "@5g*** NUM.PROT.FUORI SEQUENZA"); + riga = _r+2; + } + _uprotivap = uprotiva ? uprotiva : protiva; + } + + if (codcf != 0l && _stampa_ind_comp) + { + set_row (_r+1, "@39g%.24s %.3s",(const char *)viacf, (const char *)civcf); + set_row (_r+2, "@39g%s %.22s", (const char *)capcf, (const char *)comune); + riga = _r+3; + } + _nrec = riga_rmoviva(); + if (_nrec > 0) + { + _esiste_riga_iva = TRUE; + for (int j = 0; j < _riga_rmi.items(); j++) + { + TRigaiva& riga = (TRigaiva&)_riga_rmi[j]; + rr = _r+j; + if (_stampa_width == 132) + { + set_row(rr, "@87g%r", &riga._imponibile); + set_row(rr, "@102g%4s",(const char*)riga._codiva); + if (_tipo_reg == 2) + set_row(rr, "@107g%d", riga._tipodet); + set_row(rr, "@108g%r", &riga._imposta); + set_row(rr, "@124g%d", riga._tipocr); + if (_tipoatt == "E") + set_row(rr, "@126g%d", riga._tipoatt); + if (_tipo_stampa == 4) //stampa con riferimento al libro giornale + set_row(rr, "@127g%4ld", numgio); + } + else //stampa a 198 + { + set_row(rr, "@93g%r", &riga._imponibile); + set_row(rr, "@109g%4s",(const char*)riga._codiva); + if (_tipo_reg == 2) + set_row(rr, "@114g%d", riga._tipodet); + set_row(rr, "@116g%r", &riga._imposta); + if (_tipoatt == "E") + set_row(rr, "@132g%d", riga._tipoatt); + set_row(rr, "@134g%d", riga._tipocr); + if (_tipo_stampa == 4) //stampa con riferimento al libro giornale + set_row(rr, "@136g%7ld", numgio); + } + } + _riga_rmi.destroy(); + } + if (_tipo_stampa == 1) //stampa di prova + { + if (_stampa_width == 132) + { + set_row(_r, "@127g%4ld", numreg); + if (stampato) + set_row(_r, "@131g*"); //solo in stampa di prova! + } + else //198 + { + set_row(_r, "@136g%7ld", numreg); + if (stampato) + set_row(_r, "@144g*"); + } + } + if (_tipo_stampa == 4 && _stampa_width == 198) + { + TLocalisamfile rmoviva (LF_RMOVIVA); + rmoviva.zero(); + rmoviva.put(RMI_NUMREG,numreg); + TRectype rec(rmoviva.curr()); + rmoviva.read(_isgteq); + for ( ; !rmoviva.eof(); rmoviva.next()) + { + if (rmoviva.curr() != rec) break; + + int gruppo = rmoviva.get_int("GRUPPO"); + int conto = rmoviva.get_int("CONTO"); + long sottoc = rmoviva.get_long("SOTTOCONTO"); + TConto tc (gruppo,conto,sottoc); + TString80 descr = tc.descrizione(); + set_row(_r, "@144g%3d %3d %6d", gruppo, conto, sottoc); + set_row(_r, "@160g%s", (const char*) descr); + break; + } + } + + if (riga == 0) riga = ++rr; + + if (corrval != ZERO) + set_row(riga, "@30gCodice valuta %s Corrispettivo in valuta %r", (const char*) codval, &corrval); + + //int tipocr = _cur->file(LF_RMOVIVA)->get_int(RMI_TIPOCR); + //set_row(_r, "@124g%d", tipocr); + + //if (_tipo_stampa == 4) + // set_row(_r, "@125g%ld", numgio); + } + return TRUE; +} + +void CG4400_application::aggiorna_reg() +{ + TString16 codtab; + TTable Tabreg ("REG"); + TTable TabInl ("%INL"); + int mese; + //long pag; + //long stampate; + + word ultimast = get_page_number(); + if (_stampa_tutti_i_registri) //ho fatto un salto pagina dopo avere stampato un registro + --ultimast; + + codtab << _annoes << _codreg; + Tabreg.zero(); + Tabreg.put("CODTAB", codtab); + if (Tabreg.read() == NOERR) + { + TDate d = Tabreg.get_date("D3"); + //stampate = ultimast + 1; + if (!_mov_empty) //cioe' se e' stata stampata almeno una pagina + { + TDate ultima_data = format("%02d/%02d/%4d", _datareg.last_day(_datareg.month(), _annoes), _datareg.month(), _annoes); + if (ultima_data > d) + Tabreg.put("D3", ultima_data); + //pag = _pagine_stampate + ultimast; + //Tabreg.put("I1", pag); + } + else if (_data_a > d) + Tabreg.put("D3", _data_a); + + Tabreg.put("I1", _pagine_stampate); + if (_tipo_reg == 2 && _stampa_cred_pre) + if (_mese_credito == 0 && _credito > ZERO) + if (_mov_empty) + Tabreg.put("I8", (long)_fino_a_mese); + else Tabreg.put("I8", _datareg.month()); + + Tabreg.rewrite(); + } + if (_tipo_stampa == 3) //stampa su libro unico + //sulla tabella %inl (indice libro unico) devo generare una riga per ogni registro stampato (ricordarsi che la stampa su libro unico deve avvenire mese per mese! + //inoltre non posso stampare due volte lo stesso mese perche' la stampa avviene a fine mese + if (!_mov_empty || _ok_vidi) //se ho stampato almeno un movimento oppure ho stampato la vidimazione + { + bool trovato = FALSE; + codtab = ""; + codtab << _annoes << _codlib; + TabInl.zero(); + TRectype nuovo (TabInl.curr()); + TRectype recprec (TabInl.curr()); + TabInl.put("CODTAB", codtab); + + TRectype rec (TabInl.curr()); + TabInl.read (_isgteq); + for (; !TabInl.eof(); TabInl.next()) + { + if (TabInl.curr() != rec) break; + + mese = TabInl.get_int("I1"); + trovato = TRUE; + recprec = TabInl.curr(); + if (mese == _fino_a_mese) break; //cosi' mi posiziono su quel mese (altrimenti rischio di generare due righe per lo stesso mese e registro => la stampa di vidimazione mi sballa tutta!!! + } + TString cod = ""; + if (trovato && mese != _fino_a_mese) + { + TString16 cod_inl = recprec.get("CODTAB"); + long numero_riga = atol(cod_inl.mid(7,6)) + 1; + TString16 num_riga (format("%6d", numero_riga)); + cod_inl = cod_inl.mid(0,7); + nuovo = recprec; + cod << cod_inl << num_riga; + } + else if (mese != _fino_a_mese) + { + TString16 num_riga ( format("%6d", 0L) ); + cod << codtab << num_riga; + } + else + { + TString16 cod_inl = recprec.get("CODTAB"); + TString16 numero_riga = cod_inl.mid(7,6); + cod << codtab << numero_riga; + } + //long numini = _pagine_stampate + 1; + nuovo.put("CODTAB", cod); + nuovo.put("I0", (long)_annoes); + nuovo.put("I1", (long)_fino_a_mese); // su libro unico ho un solo mese in gioco! + nuovo.put("I2", (long)(_primast + 1)); // numero iniziale pagina libro unico + //nuovo.put("I3", (long)(_primast + ultimast)); // numero finale pagina libro unico + nuovo.put("I3", (long)(_u_stampata)); // numero finale pagina libro unico + nuovo.put("I4", get_firm()); + nuovo.put("S0", _codreg); + nuovo.put("S1", _codice_vidi); + //nuovo.put("I5", (long)numini); //numero iniziale pagina registro utente + //nuovo.put("I6", (long)(numini + ultimast - 1)); //numero finale pagina registro utente + nuovo.put("I5", _numini + 1); + nuovo.put("I6", _pagine_stampate); + + if (mese == _fino_a_mese) + TabInl.rewrite(nuovo); + else + TabInl.write(nuovo); + + //_u_stampata += ultimast; //ultima pagina stampata sul libro unico + aggiorna_lib(); + } +} + +void CG4400_application::aggiorna_lib() +{ + TString16 cod = ""; + TTable lbu ("%LBU"); + + cod << _annoes << _codlib; + lbu.zero(); + lbu.put("CODTAB", cod); + if (lbu.read() == NOERR) + { + lbu.put("I0", (long) _fino_a_mese); + lbu.put("I1", (long) _u_stampata); + lbu.rewrite(); + } +} + +bool CG4400_application::stampo_liquidazione(int mese) +{ + if (_liquidazione) + if ( (_frequiva == 'T' && (mese == 3 || mese == 6 || mese == 9 || mese == 12)) + || _frequiva != 'T' || (mese == 12 && _tipo_riepilogativo == 'A') ) + if ( (mese == 12 && _tipo_riepilogativo == 'A' && _mese_ultima_liq != 13) + || (mese != 12 && mese > _mese_ultima_liq) + || (mese == 12 && _tipo_riepilogativo != 'A' && mese > _mese_ultima_liq) ) + return TRUE; + + return FALSE; +} + +void CG4400_application::stampa_vidi() +{ + TTable TabInl ("%INL"); + TTable TabVid ("VID"); + TString16 codtab = ""; + TString16 codreg; + TString16 vid; + long ditta; + int mese; + _ok_vidi = FALSE; + TPrintrow row; + + printer().open(); + + codtab << _annoes << _codlib; + TabInl.zero(); + TabInl.put("CODTAB", codtab); + + TRectype rec (TabInl.curr()); + TabInl.read (_isgteq); + for (; !TabInl.eof(); TabInl.next()) + { + if (TabInl.curr() != rec) break; + ditta = TabInl.get_long("I4"); + codreg = TabInl.get("S0"); + if (ditta == get_firm() && codreg == _codreg) + { + if (!_ok_vidi) + { + ++_u_stampata; + ++_pagine_stampate; + _ok_vidi = TRUE; + } + mese = TabInl.get_int("I1"); + row.reset(); + row.put(format("%s", itom(mese)), 0); + row.put(format("%6ld", TabInl.get_long("I2")), 10); + row.put(format("%6ld", _u_stampata), 17); + row.put(format("%6ld", TabInl.get_long("I5")), 25); + row.put(format("%6ld", _pagine_stampate), 32); + vid = TabInl.get("S1"); + TabVid.zero(); + TabVid.put("CODTAB", vid); + if (TabVid.read() == NOERR) + { + row.put(format("%s", (const char*)TabVid.get("S0")), 39); + row.put(format("%7d",TabVid.get_long("I0")), 71); + row.put(format("%7d",TabVid.get_long("I1")), 79); + row.put(format("%7d",TabVid.get_long("I2")), 87); + TDate d(TabVid.get_long("D0")); + row.put(format("%s", (const char*)d.string()), 95); + row.put(format("%s", (const char*)TabVid.get("S1")), 106); + } + printer().print(row); + } + } + printer().close(); +} + +print_action CG4400_application::postprocess_page (int file, int counter) +{ + if (file == LF_MOV) + { + if (counter) //dopo aver fatto un REPEAT_PAGE (cioe' dopo aver stampato le righe settate in set_page_tot_reg()), in pratica a rottura di mese o alla fine + { + //if (_tipo_stampa != 1) aggiorna_reg(); // => l'aggiornamento viene fatto o a rottura di mese o alla fine + + reset_print(); + if (_tipo_stampa != 1) + if (stampo_liquidazione(_datareg.month())) + { + _st_liq[_datareg.month()] = TRUE; + _intesta_liq = TRUE; + printer().formfeed(); + TFilename t; + t.temp(); + send_message('L',t, _datareg.month()); //stampa liquidazione + merge_export_file(t,FALSE,TRUE); + _intesta_liq = FALSE; + //if (_tipo_stampa != 1) aggiorna_reg(); + } + } + if (!counter) + { + bool FINITO = FALSE; + TRecnotype pos = _cur->pos(); + long items = _cur->items(); + + FINITO = (pos == items-1); + + if ( FINITO ) + { + if (_tipo_stampa == 2 || _tipo_stampa == 4) + calcola_progressivi(); + set_page_tot_reg(); + return REPEAT_PAGE; + } + else + { + TLocalisamfile& mov = _cur->file(LF_MOV); + _cur->save_status(); + ++(*_cur); + _dataregs = mov.get_date(MOV_DATAREG); + --(*_cur); + _cur->restore_status(); + + if (_dataregs.month() != _dataregp.month()) + { + if (_tipo_stampa == 2 || _tipo_stampa == 4) + calcola_progressivi(); + set_page_tot_reg(); + return REPEAT_PAGE; + } + } + } + } + return NEXT_PAGE; +} + +/* + print_action CG4400_application::postprocess_print(int file, int counter) + { + if (file == LF_MOV) + { + if (_stampa_tutti_i_registri) + //if (!_mov_empty ) + { + if (_tipo_stampa == 3) + ++ _u_stampata; + } + } + return NEXT_PAGE; + } + */ + +bool CG4400_application::set_print(int n) +{ + TMask m("cg4400a"); + int giorni_del_mese; + bool ok; + + m.set_handler (TIPO_STAMPA, mask_tipo_stampa); + m.set_handler (A_CODICE, mask_firm_to); + m.set_handler (DA_DATA, mask_data); + m.set_handler (A_DATA, mask_data); + m.set_handler (MESE, mask_mese); + m.set_handler (FINO_A_MESE, mask_mese); + m.set_handler (CODICE_LIB_UN, mask_cod); + m.set_handler (CODICE_LIBRO_IVA, mask_libun); + m.set_handler (DLG_SELECT, mask_select); + m.set_handler (F_ANNULLA, mask_azzera); + + set_real_picture("###.###.###.###"); + + while (ok = set_ditte(m)) + { + if (_selected.ones() > 0l) + { + _annoes = m.get_int(ANNO);//in realta' e' l'anno IVA !!! + _tipo_stampa = m.get_int(TIPO_STAMPA); + _intesta_vidi = FALSE; + _stampa_width = m.get_int(STAMPA_WIDTH); + _stampa_len = m.get_int(STAMPA_LEN); + if (_stampa_width == 1) + _stampa_width = 132; + else _stampa_width = 198; + if (_stampa_len != 0) + printer().formlen(_stampa_len); + else printer().formlen(66); + //Se stampa di prova l'utente indica data_da e data_a + if (_tipo_stampa == 1) + { + _data_stampa = m.get(DATA_STAMPA); + _data_da = m.get(DA_DATA); + _data_a = m.get(A_DATA); + if (!_data_da.ok()) + _data_da = format("01/01/%4d", _annoes); + if (!_data_a.ok()) + _data_a = format("31/12/%4d", _annoes); + TDate d(31,12,_annoes); + if (_data_a == d) + _tipo_riepilogativo = m.get(TIPO_RIEPILOGATIVO)[0]; + else _tipo_riepilogativo = ' '; + printer().setdate(_data_stampa); + } + else //stampe definitive + { + if ( (_tipo_stampa == 2) || (_tipo_stampa == 4) ) + { + _fino_a_mese = m.get_int(FINO_A_MESE); + _data_da = format("01/01/%4d", _annoes); //e non ultima data di stampa del registro (come invece verrebbe spontaneo di pensare) + } + else //stampa su libro unico + { + _codlib = m.get(CODICE_LIB_UN); + _fino_a_mese = m.get_int(MESE); + _u_stampata = m.get_int(ULTIMA_PAGINA); + _rif_vid = m.get_bool(RIF_VID); + _primast = _u_stampata; + _data_da = format("01/%02d/%04d", _fino_a_mese, _annoes); + //set_page_number(_u_stampata + 1); + } + if (_fino_a_mese == 12) + { + giorni_del_mese = 31; + _tipo_riepilogativo = m.get(TIPO_RIEPILOGATIVO)[0]; + } + else + { + _tipo_riepilogativo = ' '; + TDate primo = format("01/%02d/%4d", _fino_a_mese+1, _annoes); + --primo; + giorni_del_mese = primo.day(); + } + _data_a=format("%02d/%02d/%4d",giorni_del_mese,_fino_a_mese,_annoes); + } + _stampa_data_reg = stampa_datareg(); + if (_tipo_stampa == 3) + compila_lib(); + stampa_registri_IVA(m); + } + else + { + warning_box("Nessuna ditta selezionata!"); + continue; + } + } + return FALSE; +} + +bool CG4400_application::stampa_registri_IVA(const TMask& m) +{ + long l; + __firm = TApplication::get_firm(); + bool ok = FALSE; + + for (l = 0l, _nditte->first(); !_nditte->eof(); l++, _nditte->next()) + { + if (_selected[l]) + { + bool msg = TRUE; + TApplication::set_firm(_nditte->get_long("CODDITTA")); + TString16 y; y << _annoes; + _tablia->zero(); + _tablia->put("CODTAB", y); + if (_tablia->read() == NOERR) + { + _frequiva = _tablia->get("S7")[0]; + _credito = _tablia->get_real("R0"); //credito iva anno precedente + } + else + { + warning_box("Ditta %ld: non esiste sulla tabella di liquidazione IVA annuale il record relativo all'anno %d", _nditte->get_long("CODDITTA"), _annoes); + continue; //passa alla ditta successiva, se selezionata + } + ok = compila_reg(m); + if (!ok) continue; + if (_tipo_stampa == 2 || _tipo_stampa == 4) + if (!controlla_mov()) + { + TApplication::set_firm(__firm); + return fatal_box("Finire di stampare registri anno precedente"); + } + if (!_stampa_tutti_i_registri) + _cur->set_filterfunction(filter_func); + //_frequiva = _nditte->get("FREQVIVA")[0]; + if (!_stampa_tutti_i_registri) + { + if (_liquidazione) + { + ok = controlla_liquidazione(); + if (!ok) continue; + } + for (int i=0; i < 12; i++) + _st_liq[i] = FALSE; + + (*_cur) = 0L; + const long item = _cur->items(); + if (item > 0) //cioe' se ci sono dei movimenti da stampare + { + if (_tipo_stampa == 2 || _tipo_stampa == 4) + { + TMask mb("cg4400b"); + mb.set(COD_LIB, _codreg); + const char* m = ""; + m = format("%02d", _stampa_mese); + mb.set(U_MESE, m); + mb.set(U_PAGINA, _pagine_stampate); + mb.set(U_DATA, _u_data.string()); + KEY tasto = mb.run(); + if (tasto != K_ENTER) continue; + } + if (_tipo_stampa != 1) + { + TFilename t; + t.temp(); + send_message('C',t, _fino_a_mese); + } + print(); + } +else +{ + _mov_empty = TRUE; + int limite; + //stampo la liquidazione per tutti i mesi fino a _fino_a_mese (in caso di stampa = 2/3/4) + if (_tipo_stampa == 2 || _tipo_stampa == 4) + limite = _stampa_mese; + if (_tipo_stampa == 3) + limite = _fino_a_mese; + printer().open(); + for (int m = limite; m > 0 && m <= _fino_a_mese; m++) + { + if (stampo_liquidazione(m)) + { + _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header + _intesta_liq = TRUE; + TFilename t; + t.temp(); + send_message('L',t, m); + if (m > 1) printer().formfeed(); + merge_export_file(t,FALSE,TRUE); + _intesta_liq = FALSE; + } + } + printer().close(); +} +if (_tipo_stampa == 3 && _rif_vid) +{ + _intesta_vidi = TRUE; + stampa_vidi(); //stampa riferimenti vidimazione +} +} +else +{ + TString16 codtab, cod_lib_un; + int anno; + TDate sca_vid; + for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) + { + _tipo_reg = _tabreg->get_int("I0"); + codtab = _tabreg->get("CODTAB"); + anno = atoi(codtab.mid(0,4)); + if (anno > _annoes) + break; + if (anno == _annoes) + if ( _tipo_reg == 1 || _tipo_reg == 2 ) //registro iva + { + _codreg = codtab.mid(4,3); + cod_lib_un = _tabreg->get("S6"); + sca_vid = _tabreg->get_date("D0"); + if (_tipo_stampa != 1) + { + _u_data = _tabreg->get_date("D3"); + if (!_u_data.ok()) //e' la prima volta che stampo + _u_data = format("01/01/%4d", _annoes); + } + if (_tipo_stampa == 2 || _tipo_stampa == 4) + { + if (_data_a < _u_data) + { + message_box("Ditta %ld: Il registro %s e' gia' stato stampato come bollato di %s", _nditte->get_long("CODDITTA"), (const char*) _codreg, itom(_fino_a_mese)); + continue; + } + if (cod_lib_un.not_empty()) + continue; + if (sca_vid.month() < _fino_a_mese) + continue; + } + if (_tipo_stampa == 4) //stampa con riferimenti al libro giornale + { + long codditta = _nditte->get_long("CODDITTA"); + TString16 d; + TRecnotype rec = _tabreg->recno(); + bool trovato = cerca_libro_gio(d); + _tabreg->readat(rec); + if (!trovato) + continue; + } + if (_tipo_stampa == 3) //stampa su libro unico + { + if (cod_lib_un != _codlib) + continue; + if (_fino_a_mese < _u_data.month()) + continue; + if (sca_vid.month() < _fino_a_mese) + continue; + } + msg = FALSE; + _liquidazione = _tabreg->get_bool("B7"); + + if (_liquidazione) //per i registri "validi" eseguo il controllo liquidazione + { + ok = controlla_liquidazione(); + if (!ok) continue; + } + _riep_liq = _tabreg->get_bool("B6"); + _corrispettivi = _tabreg->get_bool("B0"); + _pagine_stampate = _tabreg->get_long("I1"); + _numini = _pagine_stampate; + _cod_un_loc = _tabreg->get_int("I7"); + _mese_ultima_liq = _tabreg->get_int("I4"); + _mese_credito = _tabreg->get_int("I8"); + _codatt = _tabreg->get("S8"); + _tipoatt = tipo_attivita(); + _attivita = desc_attivita(); + _desc_lib = _tabreg->get ("S0"); + _stampa_ind_ditta = _tabreg->get_bool ("B9"); + _stampa_ind_comp = _tabreg->get_bool ("B5"); + _stampa_cred_pre = _tabreg->get_bool ("B4"); + _cur->set_filterfunction(NULL); + _cur->set_filterfunction(filter_func); + + for (int i=0; i < 12; i++) + _st_liq[i] = FALSE; + // Vado a vedere se ci sono movimenti + (*_cur) = 0L; + const long items = _cur->items(); + if (items > 0) + { + if (_tipo_stampa == 2 || _tipo_stampa == 4) + { + TMask mb("cg4400b"); + mb.set(COD_LIB, _codreg); + const char* m = ""; + m = format("%02d", _stampa_mese); + mb.set(U_MESE, m); + mb.set(U_PAGINA, _pagine_stampate); + mb.set(U_DATA, _u_data.string()); + KEY tasto = mb.run(); + if (tasto != K_ENTER) continue; + } + if (_tipo_stampa != 1) + { + TFilename t; + t.temp(); + send_message('C',t, _fino_a_mese); + } + print(); + } + else + { + int limite; + _mov_empty = TRUE; + //stampo la liquidazione per tutti i mesi fino a _fino_a_mese (in caso di stampa = 2/3/4) + if (_tipo_stampa == 2 || _tipo_stampa == 4) + limite = _stampa_mese; + if (_tipo_stampa == 3) + limite = _fino_a_mese; + printer().open(); + for (int m = limite; m > 0 && m <= _fino_a_mese; m++) + { + if (stampo_liquidazione(m)) + { + _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header + _intesta_liq = TRUE; + TFilename t; + t.temp(); + send_message('L',t, m); + if (m > 1) printer().formfeed(); + merge_export_file(t,FALSE,TRUE); + _intesta_liq = FALSE; + } + } + printer().close(); + //if (_tipo_stampa != 1) aggiorna_reg(); + } + if (_tipo_stampa == 3 && _rif_vid) + { + _intesta_vidi = TRUE; + stampa_vidi(); //stampa riferimenti vidimazione + } + } + } //for + if (msg) + message_box("Ditta %ld: Nessun registro soddisfa i parametri indicati", _nditte->get_long("CODDITTA")); +} +//if (_tipo_stampa == 3) +// aggiorna_lib(); +} +} +TApplication::set_firm(__firm); +return TRUE; +} + + +void CG4400_application::send_message(char tipo, const TFilename& nome, int mese) +{ + //const char* const app = "cg4a -2 -icon"; + const char* const app = "cg4a -2"; + TToken_string ss(10); + //int mese ; + + /* + if (tipo == 'L') + { + if (_tipo_stampa == 3) //stampa su libro unico + mese = _fino_a_mese; + if (_tipo_stampa == 2 || _tipo_stampa == 4) + mese = _datareg.month(); + } + else mese = _fino_a_mese; + */ + + ss.add(_annoes); + ss.add(mese); + ss.add(_nditte->get_long("CODDITTA")); + ss.add(tipo); + + //if (tipo == 'L') + //{ + ss.add(_data_stampa.string()); + ss.add(nome); + ss.add("x"); + //} + + TMessage liq ("cg4a -2", "RCL", ss); + liq.send(); + + TExternal_app pn(app); + pn.run(); +} + +bool CG4400_application::set_ditte(TMask& m) +{ + _selected.reset(); + + m.field(F_SELECT).set("0"); + m.field(DA_CODICE).set(""); + m.field(A_CODICE).set(""); + m.field(TIPO_STAMPA).set("1"); + + KEY tasto; + tasto = m.run(); + // m.first_focus(tasto); + return tasto == K_ENTER; +} + +TRectype& CG4400_application::look_comuni (const char * cod) +{ + _com->zero(); + _com->put(COM_COM, cod); + _com->read(); + if (_com->bad()) + _com->zero(); + + return _com->curr(); +} + +void CG4400_application::get_dati_ditta() +{ + TLocalisamfile nditte(LF_NDITTE); + TLocalisamfile anag(LF_ANAG); + TLocalisamfile unloc(LF_UNLOC); + TString codanagr; + TString tipoa; + + nditte.zero(); + nditte.put(NDT_CODDITTA, get_firm()); + nditte.read(); + + if (nditte.bad()) nditte.zero(); + + codanagr = nditte.get(NDT_CODANAGR); + tipoa = nditte.get(NDT_TIPOA); + _ragsoc = nditte.get(NDT_RAGSOC); + + anag.setkey(1); + anag.zero(); + anag.put (ANA_TIPOA, tipoa); + anag.put (ANA_CODANAGR, codanagr); + anag.read(); + if (anag.bad()) anag.zero(); + + _cofi = anag.get(ANA_COFI); + _paiva = anag.get(ANA_PAIV); + _comunefis = anag.get(ANA_COMRF); + + if (_comunefis.empty()) + _comunefis = anag.get(ANA_COMRES); + + TRectype dep = look_comuni (_comunefis); + + _comunefis = dep.get(COM_DENCOM); + _provfis = dep.get(COM_PROVCOM); + _cap = dep.get(COM_CAPCOM); + if (_comunefis.empty()) + { + _viafis = anag.get(ANA_INDRF); + _viafis.rtrim(); + _viafis << " " << anag.get (ANA_CIVRF); + } + else + { + _viafis = anag.get(ANA_INDRES); + _viafis.rtrim(); + _viafis << " " << anag.get (ANA_CIVRES); + } + + if (_cod_un_loc) + { + unloc.zero(); + unloc.put(ULC_CODDITTA, get_firm()); + unloc.put(ULC_CODULC, _cod_un_loc); + unloc.read(); + if (unloc.read() == NOERR) + { + TRectype dep = look_comuni (unloc.get(ULC_COMULC)); + _comunefis = dep.get(COM_DENCOM); + _provfis = dep.get(COM_PROVCOM); + _cap = dep.get(COM_CAPCOM); + _viafis = unloc.get(ULC_INDULC); + _viafis.rtrim(); + _viafis << " " << unloc.get(ULC_CIVULC); + } + } +} + +int CG4400_application::stampa_intestazione() +{ + int r = 1; + TString codice_ditta; + TString riga(_stampa_width); + + get_dati_ditta(); + codice_ditta << get_firm(); + + set_header (r, "Ditta %s %s %s %s %s %s", (const char*)codice_ditta, + (const char*)_ragsoc, (const char*)_viafis, + (const char*)_cap, (const char*)_comunefis, + (const char*)_provfis); + r++; + //printer().setdate(_data); + if (_tipo_stampa == 1) + { + riga = "REGISTRO DI PROVA Data @<"; + riga.right_just(_stampa_width-6); + } + riga.overwrite (format("Partita iva %s Codice fiscale %s", (const char*)_paiva, (const char*)_cofi)); + set_header (r, riga); + + return r; +} + +void CG4400_application::preprocess_header() +{ + int r=1; + char cor, nd1, nd2; + char tipo = ' '; + char type = ' '; + int mese, anno; + TString riga(_stampa_width); + TString data(30); + + riga.fill('-'); + + if (_tipo_stampa != 3) + { + mese = _datareg.month(); + anno = _datareg.year(); + } + else + { + mese = _fino_a_mese; + anno = _annoes; + } + + data.format("%s %s %d", "mese di", itom(mese), anno); + + reset_header(); + + if (_tipo_stampa == 2 || _tipo_stampa == 4) + { + if (_stampa_ind_ditta) + r = stampa_intestazione(); + } + else //se stampa di prova o su libro unico l'intestazione della ditta va sempre stampata + r = stampa_intestazione(); + + if (_tipo_stampa == 3 && !_intesta_vidi) + { + ++_u_stampata; + ++_pagine_stampate; + } + + if (_tipo_stampa == 3) + //set_header(r, "@94gProgr.Studio %ld@114gProgr.Utente @#", _u_stampata); + set_header(r, "@94gProgr.Studio %ld@114gProgr.Utente %ld", _u_stampata, _pagine_stampate); + + if (_tipo_stampa != 1) aggiorna_reg(); //cosi' sono sicura che l'aggiornamento viene fatto ad ogni salto pagina (cioe' a rottura di mese) + + r++; + + if (!_intesta_vidi) + set_header(r, "Registro IVA: %s %s %s Attivita\' %s %s", + (const char *) _codreg, (const char *) _desc_lib, + (const char *) data, (const char *) _codatt, + (const char *) _attivita); + else + { + set_header(r++, "Registro IVA: %s %s", (const char *) _codreg, (const char *) _desc_lib); + set_header(r, "RIFERIMENTI VIDIMAZIONE"); + } + + if (_intesta_liq) + { + r++; + set_header(r++, "CALCOLO LIQUIDAZIONE IVA"); + set_header(r++,riga); + TString title (80); + title << "Liquidazione IVA del periodo: "; + title << format(" %s %d", itom(mese), anno); + set_header(r++, "%s@102g Frequenza %s", (const char*) title, _frequiva == 'T' ? "T" : "M"); + set_header(r++,riga); + set_header(r,""); + } + else + { + r++; + set_header(r, riga); + r++; + if (_tipo_reg == 1) //registro vendite + { + cor = 'R'; + nd1 = NULL; + nd2 = NULL; + } + if (_tipo_reg == 2) + { + cor = 'C'; + nd1 = 'N'; + nd2 = 'D'; + } + if (_tipoatt == "E") //attivita' mista + { + tipo = 'A'; + type = 'T'; + } + if (_stampa_data_reg && _stampa_width == 132) + set_header(r,"Data I/P"); + if (_tipo_stampa == 1) //stampa di prova (_intesta_vidi e' di sicuro FALSE) + { + if (_stampa_width == 132) + { + set_header(r,"@10gNum.@19gDocumento@68gT Tipo@76gIncassi/Pag.@103gCod %c@124gT %c@128gNum", nd1, tipo); + r++; + set_header(r, "Data reg. prot.@17gData@25gNumero Codice Ragione sociale/descrizione@68gO Doc.@76gTotale doc.@91gImponibile Iva %c@112gImposta@124g%c %c@128gReg", nd2, cor, type); + r++; + } + else //stampa a 198 + { + set_header(r,"Registrazione Documento@68gT Tipo@80gTot.Inc./Pag.@110gCod %c@132g%c T@139gNum.", nd1, tipo, cor); + r++; + set_header(r, "Data Protocollo Data@25gNumero Codice Ragione sociale/descrizione@68gO Documento@80gTot.Documento@99gImponibile Iva %c@124gImposta@132g%c %c@139gReg.", nd2, type, cor); + r++; + } + } +else if (!_intesta_vidi) +{ + if (_stampa_width == 132) + { + set_header(r,"@10gNum.@19gDocumento@68gT Tipo@76gIncassi/Pag.@103gCod %c@124gT %c", nd1, tipo); + if (_tipo_stampa == 4) //stampa definitiva con rif. al libro giornale + set_header(r, "@128gNum."); + r++; + set_header(r, "Data reg. prot.@17gData@25gNumero Codice Ragione sociale/descrizione@68gO Doc.@76gTotale doc.@91gImponibile Iva %c@112gImposta@124g%c %c", + nd2, cor, type); + if (_tipo_stampa == 4) + set_header(r, "@128gop."); + r++; + } + else //stampa a 198 + { + set_header(r,"Registrazione Documento@68gT Tipo@80gTot.Inc./Pag.@110gCod %c@132g%c T", nd1, tipo); + if (_tipo_stampa == 4) + set_header(r, "@139gNum."); + r++; + set_header(r, "Data Protocollo Data@25gNumero Codice Ragione sociale/descrizione@68gO Documento@80gTot.Documento@99gImponibile Iva %c@124gImposta@132g%c %c", nd2, type, cor); + if (_tipo_stampa == 4) + set_header(r, "@139gop. @144gCodice conto @160gDescrizione sottoconto"); + r++; + } +} +else if (_tipo_stampa == 3 && _intesta_vidi) +{ + TString tr(52); + tr.fill('-'); + set_header(r++,"@10gPagine studio Pagine utente ---------------- V I D I M A Z I O N E %s", (const char*)tr); + set_header(r++,"Mese@12gda@20ga@27gda@35ga Intestatario@71gN.fogli Pag.in. Pag.fin. Data Ufficio"); +} +if (_stampa_ind_comp && !_intesta_vidi) + set_header(r++, "@39gGeneralita'"); + + set_header(r, riga); +} +} + +int cg4400 (int argc, char * argv[]) +{ + CG4400_application a; + a.run(argc, argv, "Stampa registri IVA"); + return 0; +} + + + + + + + + + + + + + + diff --git a/cg/cglib.h b/cg/cglib.h index 9f31df563..f6404548e 100755 --- a/cg/cglib.h +++ b/cg/cglib.h @@ -1,141 +1,141 @@ -#ifndef __CGLIB_H -#define __CGLIB_H - -#ifndef __ISAM_H -#include -#endif -#ifndef __REAL_H -#include -#endif -#ifndef __DATE_H -#include -#endif - -#include -#include "conto.h" - -//TLocalisamfile * get_descr_cf(TLocalisamfile * pconti,TLocalisamfile * clifo , int g, int c, long s); - -class TSaldi_list : public TAssoc_array -{ -public: - TSaldi_list (int g, int c, int aec, int aep=0); - TRectype* saldi() const; -}; - -#define Saldo TSaldo - -enum tipobil { DataLimite=1, UltimaImmissione }; - -class TSaldo -{ - real _saldo, _saldo_iniziale; - real _prg_dare, _prg_avere, _prg_daresca, _prg_averesca; - int _indbil; - TRectype _saldo_ep; - int _annoes; - TDate _inizioEs, _fineEs; - TString16 _codcaus; - TDate _datareg; - TDate _datacomp; - TString _provv; - - bool _movimentato; - bool _significativo; - bool _rec_presente_ec; - bool _rec_presente_ep; - -protected: - void InFinEs(int); - void leggi_mov(long numreg); // Leggi testata - real calcola_saldo_iniziale(int g, int c, long s, int indbil); - -public: - - bool movimentato() const { return _movimentato; } - bool significativo() const { return _significativo; } - bool esiste_saldo() const { return _rec_presente_ec || _rec_presente_ep;} - - const int EsePre (const int annocorr); // Determina esercizio precedente - int annoes () const { return _annoes; } - void set_annoes (int anno) { _annoes = anno; } - - bool causale_mov(long, const TDate&, const TDate&, TString&); - const char* causale_chiusura_es(); - const char* causale_apertura_es(); - - bool ultima_immissione_bilancio(int anno,int g,int c,long s,int indbil); - bool ultima_immissione_verifica(int anno,int g,int c,long s,int indbil); - bool data_limite_bilancio(int,int,int,long,const TDate&,const TDate&,int,bool); - - TRectype& ricerca_progr_prec(int, int, int, long); - - real saldofin_esprec(int,int,int,long); - bool prg_attuali(int,TConto&,real&,real&); - bool prg_mov_eliminati(int,TConto&,real&,real&); - - real saldo() const {return _saldo;} - real saldoini() const {return _saldo_iniziale;} - real prgdare() const {return _prg_dare;} - real prgavere() const {return _prg_avere;} - bool prg_attuali(int,TConto&,int,real&,real&); - bool prg_mov_eliminati(int,TConto&,int,real&,real&); - Saldo(); - ~Saldo(); -}; - -class TTab_conti : public TAssoc_array -{ - void do_agg(TConto* tc, int anno_es, const real& importo, char sezione, - bool movap, bool provv, bool somma, const char* key); -public: - void aggiorna_conto(const TConto& tc, int anno_es, const real& importo, - char sezione, bool movap, bool provv, bool somma); - void aggiorna_conto (int gruppo, int conto, long sottoconto, int anno_es, - const real& importo, char sezione, bool movap, - bool provv, bool somma); -}; - -class TSaldo_agg : public TObject -{ - TTab_conti _tab_conti; - bool _movap; // se e' mov. d'apertura (aggiorno SALDO e FLAGSALINI in - // saldi) - bool _provv; - int _anno_es; // anno esercizio - TDate _data_ulmov; // data ultimo movimento - long _num_ulmov; // numero ultimo movimento - TRectype * _rec; // record corrente sui saldi - THash_object * tconti() { return _tab_conti.get_hashobj(); } - -public: - void clear_saldi(int year); - void registra(); - void aggiorna (const TConto& tc, const real& importo, char sezione, - bool somma=TRUE); - void aggiorna (int gruppo, int conto, long sottoconto, const real& importo, - char sezione, bool somma=TRUE); - - void set_anno_es(int anno) { _anno_es = anno; } - int anno_es() const { return _anno_es; } - - void set_movap (bool movap) { _movap = movap; } - bool movap() const { return _movap; } - - void set_movprovv (bool p) { _provv = p; } - bool movprovv() { return _provv; } - - void set_data_ulmov (const TDate& data) { _data_ulmov = data; } - const TDate& data_ulmov() const { return _data_ulmov; } - - void set_num_ulmov (long num) { _num_ulmov = num; } - long num_ulmov() const { return _num_ulmov; } - - void reset(); // pulisce l'array dei conti - TSaldo_agg(); - int items() const { return _tab_conti.items();} -}; - - -#endif - +#ifndef __CGLIB_H +#define __CGLIB_H + +#ifndef __ISAM_H +#include +#endif +#ifndef __REAL_H +#include +#endif +#ifndef __DATE_H +#include +#endif + +#include +#include "conto.h" + +//TLocalisamfile * get_descr_cf(TLocalisamfile * pconti,TLocalisamfile * clifo , int g, int c, long s); + +class TSaldi_list : public TAssoc_array +{ +public: + TSaldi_list (int g, int c, int aec, int aep=0); + TRectype* saldi() const; +}; + +#define Saldo TSaldo + +enum tipobil { DataLimite=1, UltimaImmissione }; + +class TSaldo +{ + real _saldo, _saldo_iniziale; + real _prg_dare, _prg_avere, _prg_daresca, _prg_averesca; + int _indbil; + TRectype _saldo_ep; + int _annoes; + TDate _inizioEs, _fineEs; + TString16 _codcaus; + TDate _datareg; + TDate _datacomp; + TString _provv; + + bool _movimentato; + bool _significativo; + bool _rec_presente_ec; + bool _rec_presente_ep; + +protected: + void InFinEs(int); + void leggi_mov(long numreg); // Leggi testata + real calcola_saldo_iniziale(int g, int c, long s, int indbil); + +public: + + bool movimentato() const { return _movimentato; } + bool significativo() const { return _significativo; } + bool esiste_saldo() const { return _rec_presente_ec || _rec_presente_ep;} + + const int EsePre (const int annocorr); // Determina esercizio precedente + int annoes () const { return _annoes; } + void set_annoes (int anno) { _annoes = anno; } + + bool causale_mov(long, const TDate&, const TDate&, TString&); + const char* causale_chiusura_es(); + const char* causale_apertura_es(); + + bool ultima_immissione_bilancio(int anno,int g,int c,long s,int indbil); + bool ultima_immissione_verifica(int anno,int g,int c,long s,int indbil); + bool data_limite_bilancio(int,int,int,long,const TDate&,const TDate&,int,bool); + + TRectype& ricerca_progr_prec(int, int, int, long); + + real saldofin_esprec(int,int,int,long); + bool prg_attuali(int,TConto&,real&,real&); + bool prg_mov_eliminati(int,TConto&,real&,real&); + + const real& saldo() const { return _saldo;} + const real& saldoini() const { return _saldo_iniziale;} + const real& prgdare() const { return _prg_dare;} + const real& prgavere() const { return _prg_avere;} + bool prg_attuali(int,TConto&,int,real&,real&); + bool prg_mov_eliminati(int,TConto&,int,real&,real&); + Saldo(); + ~Saldo(); +}; + +class TTab_conti : public TAssoc_array +{ + void do_agg(TConto* tc, int anno_es, const real& importo, char sezione, + bool movap, bool provv, bool somma, const char* key); +public: + void aggiorna_conto(const TConto& tc, int anno_es, const real& importo, + char sezione, bool movap, bool provv, bool somma); + void aggiorna_conto (int gruppo, int conto, long sottoconto, int anno_es, + const real& importo, char sezione, bool movap, + bool provv, bool somma); +}; + +class TSaldo_agg : public TObject +{ + TTab_conti _tab_conti; + bool _movap; // se e' mov. d'apertura (aggiorno SALDO e FLAGSALINI in + // saldi) + bool _provv; + int _anno_es; // anno esercizio + TDate _data_ulmov; // data ultimo movimento + long _num_ulmov; // numero ultimo movimento + TRectype * _rec; // record corrente sui saldi + THash_object * tconti() { return _tab_conti.get_hashobj(); } + +public: + void clear_saldi(int year); + void registra(); + void aggiorna (const TConto& tc, const real& importo, char sezione, + bool somma=TRUE); + void aggiorna (int gruppo, int conto, long sottoconto, const real& importo, + char sezione, bool somma=TRUE); + + void set_anno_es(int anno) { _anno_es = anno; } + int anno_es() const { return _anno_es; } + + void set_movap (bool movap) { _movap = movap; } + bool movap() const { return _movap; } + + void set_movprovv (bool p) { _provv = p; } + bool movprovv() const { return _provv; } + + void set_data_ulmov (const TDate& data) { _data_ulmov = data; } + const TDate& data_ulmov() const { return _data_ulmov; } + + void set_num_ulmov (long num) { _num_ulmov = num; } + long num_ulmov() const { return _num_ulmov; } + + void reset(); // pulisce l'array dei conti + TSaldo_agg(); + int items() const { return _tab_conti.items();} +}; + + +#endif + diff --git a/cg/cglib02.cpp b/cg/cglib02.cpp index 0e5b945fa..2553b72dd 100755 --- a/cg/cglib02.cpp +++ b/cg/cglib02.cpp @@ -1,251 +1,256 @@ -///////////////////////////////////////////////////////////////////////////// -// cglib02.cpp -// -// Aggiornamento saldi -// -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include - -#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) -{ - real i = somma ? importo : -importo; - - if (movap) - { - if (sezione == 'D') tc->saldo() += i; - else tc->saldo() -= i; - } - else - if (provv) - { - if (sezione == 'D') tc->darepro() += i; - else tc->averepro() += i; - } - else - { - if (sezione == 'D') tc->dare() += i; - else tc->avere() += i; - } - - // 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); -} - - -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; - _data_ulmov = ""; - _num_ulmov = 0l; - _movap = FALSE; - _provv = FALSE; - reset(); // pulizia dell'array dei conti -} - -void TSaldo_agg::aggiorna(const TConto& tc, const real& importo, char sezione, - bool 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, - sezione, _movap, _provv, somma); -} - -void TSaldo_agg::reset() -{ - _tab_conti.destroy(); -} - -/////////////////////////////////////////////////////////////////////////////// -// pulizia file saldi -// -// Scorro il file saldi per l' anno year o per tutti gli anni se year = 0 -// e azzero i progressivi. -// -/////////////////////////////////////////////////////////////////////////////// -void TSaldo_agg::clear_saldi(int year) -{ - TLocalisamfile saldi(LF_SALDI); - - set_anno_es(year); - saldi.zero(); - if (anno_es() != 0) - saldi.put(SLD_ANNOES, anno_es()); - - TRectype last(saldi.curr()); - - for (saldi.read(_isgteq, _lock); - !saldi.eof() && saldi.curr() <= last; - saldi.next(_lock)) - { - saldi.put(SLD_FLAGSALINI, "D"); - saldi.zero(SLD_SALDO); - saldi.zero(SLD_PDAREPRO); - saldi.zero(SLD_PAVEREPRO); - saldi.zero(SLD_PDARE); - saldi.zero(SLD_PAVERE); - saldi.zero(SLD_NUMULTMOV); - saldi.zero(SLD_DATAULMOV); - saldi.rewrite(); - } - saldi.reread(_unlock); -} - -/////////////////////////////////////////////////////////////////////////////// -// Aggiornamento file saldi -// -// Scorro la tabella dei conti interna _tab_conti. -// Per ogni conto cerco il record su saldi, se non c'e' lo creo. -// Se c'e' gia' lo aggiorno nel seguente modo: -// -/////////////////////////////////////////////////////////////////////////////// -void TSaldo_agg::registra() -{ - real s, r; - TString Flagsalini; - TDate data_ulmov; - long num_ulmov; - TLocalisamfile saldi(LF_SALDI); - int conti = _tab_conti.items(); - - _tab_conti.restart(); - for (int i=0; i < conti; i++) - { - THash_object * hobj = tconti(); - TConto & tcon = (TConto &)hobj->obj(); - - if (!tcon.ok()) continue; - saldi.zero(); - saldi.put(SLD_ANNOES, atoi(hobj->key().left(4)) ); - saldi.put(SLD_GRUPPO, tcon.gruppo()); - saldi.put(SLD_CONTO, tcon.conto()); - saldi.put(SLD_SOTTOCONTO, tcon.sottoconto()); - if (saldi.read(_isequal, _lock) == NOERR) - { - num_ulmov = saldi.get_long(SLD_NUMULTMOV); - data_ulmov = saldi.get_date(SLD_DATAULMOV); - - if (((_num_ulmov != 0L) && (_num_ulmov > num_ulmov)) || - ((_data_ulmov.ok()) && (_data_ulmov > data_ulmov))) - { - saldi.put(SLD_DATAULMOV, _data_ulmov); - saldi.put(SLD_NUMULTMOV, _num_ulmov); - } - r = tcon.saldo(); - 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) - { - Flagsalini = "A"; s = -s; - } - else - Flagsalini = "D"; - saldi.put(SLD_FLAGSALINI, (const char *) Flagsalini); - saldi.put(SLD_SALDO, s); - } - r = saldi.get_real(SLD_PDAREPRO); - r += tcon.darepro(); - saldi.put(SLD_PDAREPRO, r); - r = saldi.get_real(SLD_PAVEREPRO); - r += tcon.averepro(); - saldi.put(SLD_PAVEREPRO, r); - r = saldi.get_real(SLD_PDARE); - r += tcon.dare(); - saldi.put(SLD_PDARE, r); - r = saldi.get_real(SLD_PAVERE); - r += tcon.avere(); - saldi.put(SLD_PAVERE, r); - saldi.rewrite(); - } - else - { - saldi.zero(); - saldi.put(SLD_ANNOES, anno_es()); - 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; - } - else - Flagsalini = "D"; - - saldi.put(SLD_FLAGSALINI, (const char *) Flagsalini); - saldi.put(SLD_SALDO, s); - saldi.put(SLD_PDAREPRO, tcon.darepro()); - saldi.put(SLD_PAVEREPRO, tcon.averepro()); - saldi.put(SLD_PDARE, tcon.dare()); - - saldi.put(SLD_PAVERE, tcon.avere()); - if (_num_ulmov != 0L) saldi.put(SLD_NUMULTMOV, _num_ulmov); - if (_data_ulmov.ok()) saldi.put(SLD_DATAULMOV, _data_ulmov); - saldi.write(); - } - } -} - - +///////////////////////////////////////////////////////////////////////////// +// cglib02.cpp +// +// Aggiornamento saldi +// +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include + +#include + +#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) +{ + real i = somma ? importo : -importo; + + if (movap) + { + if (sezione == 'D') tc->saldo() += i; + else tc->saldo() -= i; + } + else + if (provv) + { + if (sezione == 'D') tc->darepro() += i; + else tc->averepro() += i; + } + else + { + if (sezione == 'D') tc->dare() += i; + else tc->avere() += i; + } + + // 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); +} + + +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; + _data_ulmov = ""; + _num_ulmov = 0l; + _movap = FALSE; + _provv = FALSE; + reset(); // pulizia dell'array dei conti +} + +void TSaldo_agg::aggiorna(const TConto& tc, const real& importo, char sezione, + bool 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, + sezione, _movap, _provv, somma); +} + +void TSaldo_agg::reset() +{ + _tab_conti.destroy(); +} + +/////////////////////////////////////////////////////////////////////////////// +// pulizia file saldi +// +// Scorro il file saldi per l' anno year o per tutti gli anni se year = 0 +// e azzero i progressivi. +// +/////////////////////////////////////////////////////////////////////////////// +void TSaldo_agg::clear_saldi(int year) +{ + TLocalisamfile saldi(LF_SALDI); + + set_anno_es(year); + saldi.zero(); + if (anno_es() != 0) + saldi.put(SLD_ANNOES, anno_es()); + + TRectype last(saldi.curr()); + + for (saldi.read(_isgteq, _lock); + !saldi.eof() && saldi.curr() <= last; + saldi.next(_lock)) + { + saldi.put(SLD_FLAGSALINI, "D"); + saldi.zero(SLD_SALDO); + saldi.zero(SLD_PDAREPRO); + saldi.zero(SLD_PAVEREPRO); + saldi.zero(SLD_PDARE); + saldi.zero(SLD_PAVERE); + saldi.zero(SLD_NUMULTMOV); + saldi.zero(SLD_DATAULMOV); + saldi.rewrite(); + } + saldi.reread(_unlock); +} + +/////////////////////////////////////////////////////////////////////////////// +// Aggiornamento file saldi +// +// Scorro la tabella dei conti interna _tab_conti. +// Per ogni conto cerco il record su saldi, se non c'e' lo creo. +// Se c'e' gia' lo aggiorno nel seguente modo: +// +/////////////////////////////////////////////////////////////////////////////// +void TSaldo_agg::registra() +{ + real s, r; + TString Flagsalini; + TDate data_ulmov; + long num_ulmov; + TLocalisamfile saldi(LF_SALDI); + int conti = _tab_conti.items(); + + _tab_conti.restart(); + for (int i = 0; i < conti; i++) + { + THash_object * hobj = tconti(); + const TConto& tcon = (TConto &)hobj->obj(); + CHECK(tcon.ok(), "Tentativo di saldare un conto incompleto"); + + saldi.zero(); + saldi.put(SLD_ANNOES, atoi(hobj->key().left(4)) ); + saldi.put(SLD_GRUPPO, tcon.gruppo()); + saldi.put(SLD_CONTO, tcon.conto()); + saldi.put(SLD_SOTTOCONTO, tcon.sottoconto()); + + bool update = TRUE; + + if (saldi.read(_isequal, _lock) != NOERR) + { + saldi.zero(); + saldi.put(SLD_ANNOES, anno_es()); + 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; } + else + Flagsalini = "D"; + + saldi.put(SLD_FLAGSALINI, (const char *) Flagsalini); + saldi.put(SLD_SALDO, s); + saldi.put(SLD_PDAREPRO, tcon.darepro()); + saldi.put(SLD_PAVEREPRO, tcon.averepro()); + saldi.put(SLD_PDARE, tcon.dare()); + + saldi.put(SLD_PAVERE, tcon.avere()); + if (_num_ulmov != 0L) saldi.put(SLD_NUMULTMOV, _num_ulmov); + if (_data_ulmov.ok()) saldi.put(SLD_DATAULMOV, _data_ulmov); + update = saldi.write() == _isreinsert; + if (update) + saldi.read(_isequal, _lock); + } + + if (update) + { + num_ulmov = saldi.get_long(SLD_NUMULTMOV); + data_ulmov = saldi.get_date(SLD_DATAULMOV); + + if (((_num_ulmov != 0L) && (_num_ulmov > num_ulmov)) || + ((_data_ulmov.ok()) && (_data_ulmov > data_ulmov))) + { + saldi.put(SLD_DATAULMOV, _data_ulmov); + saldi.put(SLD_NUMULTMOV, _num_ulmov); + } + r = tcon.saldo(); + 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) + { + Flagsalini = "A"; s = -s; + } + else + Flagsalini = "D"; + saldi.put(SLD_FLAGSALINI, Flagsalini); + saldi.put(SLD_SALDO, s); + } + r = saldi.get_real(SLD_PDAREPRO); + r += tcon.darepro(); + saldi.put(SLD_PDAREPRO, r); + r = saldi.get_real(SLD_PAVEREPRO); + r += tcon.averepro(); + saldi.put(SLD_PAVEREPRO, r); + r = saldi.get_real(SLD_PDARE); + r += tcon.dare(); + saldi.put(SLD_PDARE, r); + r = saldi.get_real(SLD_PAVERE); + r += tcon.avere(); + saldi.put(SLD_PAVERE, r); + saldi.rewrite(); + } + } +} + + diff --git a/cg/conto.h b/cg/conto.h index 295dc9479..739e1fdcf 100755 --- a/cg/conto.h +++ b/cg/conto.h @@ -1,84 +1,93 @@ -#ifndef __CONTO_H -#define __CONTO_H - -#ifndef __STRINGS_H -#include -#endif - -#ifndef __REAL_H -#include -#endif - -class TBill : public TSortable -{ - char _tipo; // ' ' = Conto, 'C' = Cliente, 'F' = 'Fornitore' - int _gruppo, _conto; - long _sottoconto; // Sottoconto, codice cliente o fornitore - TString80 _descrizione; // Vuota fino alla chiamata di describe - int _tipo_cr; // Tipo costo/ricavo - bool _sospeso; - -protected: - virtual int compare(const TSortable& s) const; - virtual const char* class_name() const { return "Conto"; } - void describe(); - - const TBill& copy(const TBill& b); - -public: - TBill(int g = 0, int c = 0, long s = 0L, char t = ' ', const char* d = NULL, int r = -1) - : _tipo(t), _gruppo(g), _conto(c), _sottoconto(s), _descrizione(d), _tipo_cr(r) { set(g,c,s,t,d,r);} - - TBill(TToken_string& tgcsd, int from, int mode = 0); - TBill(const TBill& b) { copy(b); } - virtual ~TBill() {} - - const TBill& set(int g = 0, int c = 0, long s = 0L, char t = ' ', - const char* d = NULL, int r = -1); - const TBill& add_to(TToken_string& ts, int from, int mode = 0); - const TBill& operator=(const TBill& b) { return copy(b); } - - virtual bool ok() const; // Gruppo, Conto e Sottoconto non nulli - bool empty() const { return _gruppo==0 && _conto==0 && _sottoconto == 0; } - - char tipo() const { return _tipo; } - int gruppo() const { return _gruppo; } - int conto() const { return _conto; } - long sottoconto() const { return _sottoconto; } - - const TString& descrizione(); - int tipo_cr(); - void tipo_cr(int tcr) { _tipo_cr = tcr; } - - int tipo_att(); - bool read(TRectype& r); - bool sospeso() const { return _sospeso;} // _sospeso e' letto nella read() - - const char* string(int mode = 0); -}; - - -enum TIndbil { ib_null, ib_attivita, ib_passivita, ib_costi, ib_ricavi, ib_conti_ordine }; - -class TConto : public TBill -{ - real _dare, _avere, _darepro, _averepro, _saldo; - -public: - TConto(int g = 0, int c = 0, long s = 0L, char t = ' ', const char* d = NULL) - : TBill(g, c, s, t, d) {} - TConto (TToken_string& tgcsd, int from, int mode = 0) - : TBill(tgcsd, from, mode) {}; - - real& dare() { return _dare; } - real& avere() { return _avere; } - real& darepro() { return _darepro; } - real& averepro() { return _averepro; } - real& saldo() { return _saldo; } -}; - -#endif - - - - +#ifndef __CONTO_H +#define __CONTO_H + +#ifndef __STRINGS_H +#include +#endif + +#ifndef __REAL_H +#include +#endif + +class TBill : public TSortable +{ + char _tipo; // ' ' = Conto, 'C' = Cliente, 'F' = 'Fornitore' + int _gruppo, _conto; + long _sottoconto; // Sottoconto, codice cliente o fornitore + TString80 _descrizione; // Vuota fino alla chiamata di describe + int _tipo_cr; // Tipo costo/ricavo + bool _sospeso; + +protected: + virtual int compare(const TSortable& s) const; + virtual const char* class_name() const { return "Conto"; } + void describe(); + + const TBill& copy(const TBill& b); + +public: + TBill(int g = 0, int c = 0, long s = 0L, char t = ' ', const char* d = NULL, int r = -1) + : _tipo(t), _gruppo(g), _conto(c), _sottoconto(s), _descrizione(d), _tipo_cr(r) { set(g,c,s,t,d,r);} + + TBill(TToken_string& tgcsd, int from, int mode = 0); + TBill(const TBill& b) { copy(b); } + virtual ~TBill() {} + + const TBill& set(int g = 0, int c = 0, long s = 0L, char t = ' ', + const char* d = NULL, int r = -1); + const TBill& add_to(TToken_string& ts, int from, int mode = 0); + const TBill& operator=(const TBill& b) { return copy(b); } + + virtual bool ok() const; // Gruppo, Conto e Sottoconto non nulli + bool empty() const { return _gruppo==0 && _conto==0 && _sottoconto == 0; } + + char tipo() const { return _tipo; } + int gruppo() const { return _gruppo; } + int conto() const { return _conto; } + long sottoconto() const { return _sottoconto; } + + const TString& descrizione(); + int tipo_cr(); + void tipo_cr(int tcr) { _tipo_cr = tcr; } + + int tipo_att(); + bool read(TRectype& r); + bool sospeso() const { return _sospeso;} // _sospeso e' letto nella read() + + const char* string(int mode = 0); +}; + + +enum TIndbil { ib_null, ib_attivita, ib_passivita, ib_costi, ib_ricavi, ib_conti_ordine }; + +class TConto : public TBill +{ + real _dare, _avere, _darepro, _averepro, _saldo; + +public: + TConto(int g = 0, int c = 0, long s = 0L, char t = ' ', const char* d = NULL) + : TBill(g, c, s, t, d) {} + TConto (TToken_string& tgcsd, int from, int mode = 0) + : TBill(tgcsd, from, mode) {}; + + real& dare() { return _dare; } + const real& dare() const { return _dare; } + + real& avere() { return _avere; } + const real& avere() const { return _avere; } + + real& darepro() { return _darepro; } + const real& darepro() const { return _darepro; } + + real& averepro() { return _averepro; } + const real& averepro() const { return _averepro; } + + real& saldo() { return _saldo; } + const real& saldo() const { return _saldo; } +}; + +#endif + + + +