From 5f655ece6d7a40ccd7465f418f227d70ab8a647e Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 22 Sep 1994 16:46:40 +0000 Subject: [PATCH] Leggere modifiche al programma clienti (eliminazione di variabili static) Correzione errori cancellazione movimenti provvisori (che pero' non funzionano ancora) Aggiunta classe TBill da cui deriva TConto git-svn-id: svn://10.65.10.50/trunk@278 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- cg/cg0200.cpp | 1262 +++++++++---------- cg/cg0201.h | 70 +- cg/cg2.h | 16 +- cg/cg2100b.uml | 416 +++---- cg/cg2101.h | 102 +- cg/cg2102.cpp | 63 +- cg/cg2103.cpp | 12 +- cg/cg2200.cpp | 94 +- cg/cg2200a.uml | 31 +- cg/cg4400.cpp | 3216 ++++++++++++++++++++++++------------------------ cg/cg5100a.uml | 4 + cg/cglib.h | 250 ++-- 12 files changed, 2801 insertions(+), 2735 deletions(-) diff --git a/cg/cg0200.cpp b/cg/cg0200.cpp index 84e9679a2..f79cef28a 100755 --- a/cg/cg0200.cpp +++ b/cg/cg0200.cpp @@ -1,631 +1,631 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "cg0.h" -#include "cg0200.h" -#include "cg0201.h" - - -bool gest_vend() -{ - TConfig c(CONFIG_DITTA,"cg"); - return (c.get("GesVen") == "X"); -} - -class CG0200_application : public TRelation_application -{ - TMask* _msk; - TClifoVI *_rel; - TLocalisamfile* _saldi; - TLocalisamfile* _anag; - TLocalisamfile* _fis; - TLocalisamfile* _comuni; - TLocalisamfile* _pcon; - - 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 const char* get_next_key(); - void init_pages(TMask& m); - virtual void init_query_mode(TMask& m); - virtual void init_query_insert_mode(TMask& m) {init_query_mode(m);} - virtual void init_insert_mode(TMask& m) {init_query_mode(m);} - virtual void init_modify_mode(TMask& m) {init_pages(m);} - - //////////// - static bool indsp_notify(int r, KEY key); - static bool indsp_handler(TMask_field& f, KEY key) ; - virtual int write(const TMask& m); - virtual int rewrite(const TMask& m); - virtual int read(TMask& m); - TSheet_field& indsp_sheet() const; - TArray_sheet* field_sheet(const int n) const; - void reset_sheet(); - void indsp_pack(); - void common_f(const TMask& m); - /////////// - - public: - virtual TRelation* get_relation() const {return (TRelation*)_rel;} - CG0200_application() {} -}; - -inline CG0200_application& app() -{return (CG0200_application&)*MainApp();} - -bool CG0200_application::protected_record(TRectype &rec) - -{ - TMask* m = get_mask(MODE_MOD); - const int gruppo = atoi(m->get(F_GRUPPO)); - const int conto = atoi(m->get(F_CONTO)); - const long sottoc = atol(m->get(F_CODCF)); - - _saldi->zero(); - _saldi->put(PCN_GRUPPO, gruppo); - _saldi->put(PCN_CONTO, conto); - _saldi->put(PCN_SOTTOCONTO, sottoc); - _saldi->read(); - - return _saldi->good() && - gruppo ==_saldi->get_int(PCN_GRUPPO) && - conto ==_saldi->get_int(PCN_CONTO) && - sottoc ==_saldi->get_long(PCN_SOTTOCONTO); -} - -const char* CG0200_application::get_next_key() - -{ - TLocalisamfile& clifo = _rel->lfile() ; - long codcf = 1L ; - const TString tipo(_msk->get(F_TIPOCF)) ; - - if (!clifo.empty()) - { - clifo.zero() ; - clifo.setkey(1) ; - if ( tipo == TCLI ) - { - clifo.put(CLI_TIPOCF, (const char* ) TFOR); - clifo.read(_isgteq ) ; - if (clifo.good()) - clifo.prev() ; - clifo.setstatus(NOERR); - } - else clifo.last( ) ; - if ( clifo.good() ) - { - const TFixed_string tipocf(clifo.get(CLI_TIPOCF)); - if ( tipocf == tipo ) - codcf += clifo.get_long(CLI_CODCF); - } - } - return format("%d|%s|%d|%ld", F_TIPOCF, (const char*) tipo, F_CODCF, codcf); -} - -HIDDEN bool no_dup_fis(TMask_field& f, KEY key) -{ - TMask& msk = f.mask() ; - - if (msk.query_mode() || !f.to_check(key)) return TRUE; - CG0200_application* app = (CG0200_application*) MainApp(); - TLocalisamfile& clifo = app->get_relation()->lfile(LF_CLIFO) ; - - if ( f.get().not_empty() && !clifo.empty() ) - { - clifo.zero() ; - const char t1 = msk.get(F_TIPOCF)[0] ; - - clifo.put(CLI_TIPOCF, t1); - clifo.put(CLI_COFI, f.get()); - clifo.setkey(4) ; - clifo.read() ; - clifo.setkey(1) ; - const char t = clifo.get_char(CLI_TIPOCF); - const TFixed_string s = clifo.get(CLI_CODCF); - const TFixed_string s1(msk.get(F_CODCF)); - - if (clifo.good() && (t1 != t || s1 != s)) - { - f.yesno_box("Codice fiscale gia' utilizzato per il codice : %c/%s", - t, (const char*) s); - return FALSE; - } - } - return TRUE ; -} - -HIDDEN bool no_dup_iva(TMask_field& f, KEY key) -{ - TMask& msk = f.mask() ; - - if (msk.query_mode() || !f.to_check(key)) return TRUE; - - CG0200_application* app = (CG0200_application*) MainApp(); - TLocalisamfile& clifo = app->get_relation()->lfile(LF_CLIFO) ; - - if ( f.get().not_empty() && !clifo.empty() ) - { - clifo.zero() ; - const char t1 = msk.get(F_TIPOCF)[0]; - - clifo.put(CLI_TIPOCF, t1) ; - clifo.put(CLI_STATOPAIV, msk.get(F_STATOPAIV)) ; - clifo.put(CLI_PAIV, f.get()) ; - clifo.setkey(5) ; - clifo.read() ; - clifo.setkey(1) ; - const char t = clifo.get_char(CLI_TIPOCF); - const TFixed_string s = clifo.get(CLI_CODCF); - const TFixed_string s1(msk.get(F_CODCF)); - - if (clifo.good() && (t1 != t || s1 != s)) - { - f.error_box("Partita iva gia' definita per il codice : %c/%s", - t, (const char*) s); - return FALSE ; - } - } - return TRUE ; -} - -HIDDEN bool autoexit_handler(TMask_field& f, KEY key) - -{ - if (f.mask().query_mode()) - { - if (key == K_TAB && f.focusdirty()) - { - TArray parms; - parms.add((TString)format("%d", f.dlg())); - ::validate(AUTOEXIT_FUNC, (TEdit_field&) f, key, parms); - } - } - else - if (f.to_check(key) && f.mask().get(F_ALLEG) != "4") - { - if (f.dlg() == F_COFI) return no_dup_fis(f, key); - else return no_dup_iva(f, key); - } - return TRUE; -} - -HIDDEN bool lbcn = FALSE; - -HIDDEN bool tipo_handler(TMask_field& f, KEY key) - -{ - TMask& m = f.mask(); - - const bool fis = f.get() == "F"; - - m.send_key(K_SHIFT + K_CTRL + (lbcn && fis ? 's' : 'h'), -5); - return TRUE; -} - -HIDDEN bool tipocf_handler(TMask_field& f, KEY key) -{ - TMask& m = f.mask(); - const bool cf = (f.get() == "F"); - - if (key == K_TAB) - { - if (cf || !gest_vend()) // If it's a FORNICATOR disable pages - for (int j=3; j<8;j++) - m.disable_page(j); -else // If it's a CUSTOMER enable pages -{ - for (int j=3; j<8;j++) - m.enable_page(j); -} -} -return TRUE; -} - -HIDDEN bool percip_handler(TMask_field& f, KEY key) - -{ - TMask& m = f.mask(); - - - if (f.to_check(key) && m.get(F_CODANAGPER).not_empty()) - { - TLocalisamfile anag(LF_ANAG); - TString c(m.get(F_COFI)), p(m.get(F_PAIV)); - - if ((c.not_empty() && c != anag.get(ANA_COFI)) || - (p.not_empty() && p != anag.get(ANA_PAIV))) return error_box("Percipiente non corretto"); - TString r(anag.get(ANA_RAGSOC)); - if (m.get(F_RAGSOC).empty() || - (key == K_TAB && yesno_box("Ragione sociale differente correggo in %s", (const char*) r))) - m.set(F_RAGSOC, r, TRUE); - if (m.get(F_INDCF).empty()) m.set(F_INDCF, anag.get(ANA_INDRES)); - if (m.get(F_CIVCF).empty()) m.set(F_CIVCF, anag.get(ANA_CIVRES)); - if (m.get(F_CAPCF).empty()) m.set(F_CAPCF, anag.get(ANA_CAPRES)); - if (m.get(F_COMCF).empty()) - { - m.set(F_STATOCF, anag.get(ANA_STATORES), TRUE); - m.set(F_COMCF, anag.get(ANA_COMRES), TRUE); - } - if (c.empty()) m.set(F_COFI, anag.get(ANA_COFI)); - if (p.empty()) m.set(F_PAIV, anag.get(ANA_PAIV)); - if (m.get(F_TIPOAPER) == "F") - { - m.send_key(K_SHIFT + K_CTRL + (lbcn ? 's' : 'h'), -5); - if (lbcn) - { - TLocalisamfile fis(LF_ANAGFIS); - - fis.zero(); - fis.put(ANF_CODANAGR, anag.get(ANA_CODANAGR)); - fis.read(); - if (fis.good()) - { - if (m.get(F_DATANASC).empty()) m.set(F_DATANASC, fis.get(ANF_DATANASC)); - if (m.get(F_COMNASC).empty()) - { - m.set(F_STATONASC, fis.get(ANF_STATONASC)); - m.set(F_COMNASC, fis.get(ANF_COMNASC)); - } - } - } - } - } - return TRUE; -} - - -HIDDEN bool alleg_handler(TMask_field& f, KEY key) - -{ - if (f.to_check(key)) - { - const int tipoall = atoi(f.get()); - TMask& m = f.mask(); - - if (tipoall == 0 || tipoall == 4) m.enable(F_CODALLEG); - else - { - m.disable(F_CODALLEG); - m.reset(F_CODALLEG); - } - m.set(F_OCCASIONALE, (tipoall == 2) ? "X" : " "); - } - return TRUE; -} - -HIDDEN bool occas_handler(TMask_field& f, KEY key) - -{ - if (f.to_check(key)) - { - const bool occas = f.get().not_empty(); - TMask& m = f.mask(); - - if (occas) m.set(F_ALLEG, "2"); - else - if (m.get_int(F_ALLEG) == 2) m.set(F_ALLEG, " "); - } - return TRUE; -} - -HIDDEN bool codalleg_handler(TMask_field& f, KEY key) - -{ - if (f.to_check(key)) - { - const TString cod(f.get()); - - if (cod.not_empty()) - { - TMask& m = f.mask(); - - if (cod == m.get(F_TIPOCF)) - return error_box("Codice per allegato non corretto"); - - TLocalisamfile clifo(LF_CLIFO); - const TString tipo(m.get(F_TIPOCF)); - - clifo.zero() ; - clifo.setkey(1) ; - clifo.put(CLI_TIPOCF, tipo); - clifo.put(CLI_CODCF, cod); - clifo.read() ; - if (clifo.bad()) return FALSE; - TString tipoall(clifo.get(CLI_ALLEG)); - if (clifo.get(CLI_CODALLEG).not_empty() || - clifo.get(CLI_PAIV).empty() || - (tipoall.not_empty() && tipoall != "4")) - return error_box("Codice per allegato non corretto"); - } - } - return TRUE; -} - -void CG0200_application::init_pages(TMask& m) - -{ - TConfig conf(CONFIG_DITTA, "cg"); - const bool tipocf=(m.get(F_TIPOCF) == "F"); - - lbcn = (conf.get("GsLbCn") == "X"); - m.send_key(K_SHIFT + K_CTRL + (lbcn ? 's' : 'h'), -5); - // Se non e' abilitata la gestione delle vendite disabilita le - // maschere dalla 4 in poi - if (!gest_vend() || tipocf) - { - for (int j=3; j<8;j++) - m.disable_page(j); - } - else - { - for (int j=3; j<8;j++) - m.enable_page(j); - } -} - -void CG0200_application::init_query_mode(TMask& m) - -{ - init_pages(m); - if (gest_vend()) - reset_sheet(); -} - -int CG0200_application::read(TMask& m) -{ - - TToken_string riga(240); - - m.autoload(_rel); - indsp_sheet().reset(); - for (int i=0; i< _rel->indirizzi_items();i++) - { - TRectype& rec=_rel->indirizzo(i); - riga.cut(0); - riga.add(rec.get(IND_RAGSOC)); - riga.add(rec.get(IND_INDIR)); - riga.add(rec.get(IND_CIV)); - riga.add(rec.get(IND_LOCALITA)); - riga.add(rec.get(IND_CAP)); - riga.add(rec.get(IND_STATO)); - riga.add(rec.get(IND_COM)); - riga.add(rec.get(IND_PTEL)); - riga.add(rec.get(IND_TEL)); - riga.add(rec.get(IND_PFAX)); - riga.add(rec.get(IND_FAX)); - riga.add(rec.get(IND_IVARID)); - riga.add(rec.get(IND_CODIND)); - indsp_sheet().row(i)=riga; - - // Load the sheets of CODINDDOC, CODINDSP, CODINDEFF. - riga.cut(0); - riga.add(rec.get(IND_CODIND)); - riga.add(rec.get(IND_RAGSOC)); - riga.add(rec.get(IND_INDIR)); - riga.add(rec.get(IND_CIV)); - riga.add(rec.get(IND_LOCALITA)); - field_sheet(F_CODINDDOC)->add(riga); - field_sheet(F_CODINDSP)->add(riga); - field_sheet(F_CODINDEFF)->add(riga); - } - return _rel->status(); -} - -int CG0200_application::rewrite(const TMask& m) -{ - common_f(m); - return _rel->rewrite(TRUE); -} - -int CG0200_application::write(const TMask& m) -{ - common_f(m); - return _rel->write(TRUE); -} - -TArray_sheet* CG0200_application::field_sheet(const int n) const -{ - TEdit_field& f=(TEdit_field&) _msk->field(n); - TArray_sheet* S=(TArray_sheet*) f.sheet()->sheet(); - return S; -} - -TSheet_field& CG0200_application::indsp_sheet() const -{ - TSheet_field& o_sheet=(TSheet_field&) _msk->field(F_SHEET_G_VEN); - return o_sheet; -} - -void CG0200_application::reset_sheet() -{ - const TToken_string nulla("|**Nessuno**||||"); - - app().field_sheet(F_CODINDDOC)->destroy(); - app().field_sheet(F_CODINDDOC)->add(nulla); - app().field_sheet(F_CODINDSP)->destroy(); - app().field_sheet(F_CODINDSP)->add(nulla); - app().field_sheet(F_CODINDEFF)->destroy(); - app().field_sheet(F_CODINDEFF)->add(nulla); -} - -void CG0200_application::indsp_pack() -{ - TArray& rows = indsp_sheet().rows_array(); - int nr=rows.items(); - - for (int i=0; ilfile().zero(); - m.autosave(_rel); - _rel->destroy_rows(); - indsp_pack(); - TArray& rows=indsp_sheet().rows_array(); - int n_items = rows.items(); - for (int i=0; iindirizzo(i); - row.restart(); - rec.zero(); - rec.put(IND_TIPOCF,tipocf); - rec.put(IND_CODCF,codcf); - rec.put(IND_RAGSOC,row.get()); - rec.put(IND_INDIR,row.get()); - rec.put(IND_CIV,row.get()); - rec.put(IND_LOCALITA,row.get()); - rec.put(IND_CAP,row.get()); - rec.put(IND_STATO,row.get_int()); - rec.put(IND_COM,row.get()); - rec.put(IND_PTEL,row.get()); - rec.put(IND_TEL,row.get()); - rec.put(IND_PFAX,row.get()); - rec.put(IND_FAX,row.get()); - rec.put(IND_IVARID,row.get()); - rec.put(IND_CODIND,i+1); - } -} - -bool CG0200_application::indsp_handler(TMask_field& f, KEY key) -{ - static int first_time=1; - - if (key == K_TAB && f.dirty()) // Was it changed ? - if (first_time) - { - TArray& righe=app().indsp_sheet().rows_array(); - int n=righe.items(); - app().reset_sheet(); - // Rebuild Sheets - for (int i=0; iadd(rigav); - app().field_sheet(F_CODINDSP)->add(rigav); - app().field_sheet(F_CODINDEFF)->add(rigav); - } - first_time=0; - } else - first_time=1; - return TRUE; -} - -bool CG0200_application::indsp_notify(int r, KEY key) -{ - TSheet_field& indsp=app().indsp_sheet(); - - switch (key) - { - case K_SPACE: - { - // Request to modify row #r - // Disable field CODIND update # of row - TMask& m = indsp.sheet_mask(); - - if (m.get_int(F_CODINDI)==0) // Is it a new row ? - m.set(F_CODINDI,(long)(r+1)); - m.disable(F_CODINDI); - } - break; - case K_INS: - // request to add the row #r - // To avoid rewriting of existing record. - if (indsp.items() >= 999) - { - error_box("Raggiunto il numero massimo degli indirizzi per questo C/F"); - return FALSE; // Refuse Permission - } else - // To avoid inserts in the middle of the sheet - if (r != -1 && indsp.items() > r) - { - error_box("Si possono aggiungere indirizzi solo alla fine"); - return FALSE; //Refuse permission - } - break; -default: - break; -} - return TRUE; -} - -bool CG0200_application::user_create() // initvar e arrmask -{ - - _rel = new TClifoVI; - - _saldi = new TLocalisamfile(LF_SALDI); - _anag = new TLocalisamfile(LF_ANAG); - _fis = new TLocalisamfile(LF_ANAGFIS); - _pcon = new TLocalisamfile(LF_PCON); - _comuni = new TLocalisamfile(LF_COMUNI); - _msk = new TMask("cg0200a") ; - _msk->set_handler(F_TIPOCF,tipocf_handler); - _msk->set_handler(F_OCCASIONALE, occas_handler); - _msk->set_handler(F_COFI, autoexit_handler); - _msk->set_handler(F_PAIV, autoexit_handler); - _msk->set_handler(F_CODANAGPER, percip_handler); - _msk->set_handler(F_TIPOPERS, tipo_handler); - _msk->set_handler(F_ALLEG, alleg_handler); - _msk->set_handler(F_CODALLEG, codalleg_handler); - - _msk->set_handler(F_SHEET_G_VEN, indsp_handler); - - TSheet_field& ind = (TSheet_field&) _msk->field(F_SHEET_G_VEN); - - ind.set_notify(indsp_notify); - - _saldi->setkey(2); - return TRUE; -} - -bool CG0200_application::user_destroy() // releasev e arrmask -{ - delete _msk; - delete _rel; - delete _saldi; - delete _anag; - delete _fis; - delete _pcon; - delete _comuni; - return TRUE; -} - -int cg0200(int argc, char* argv[]) -{ - CG0200_application a ; - a.run(argc, argv, "Clienti/Fornitori"); - return 0; -} +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "cg0.h" +#include "cg0200.h" +#include "cg0201.h" + + +bool gest_vend() +{ + TConfig c(CONFIG_DITTA,"cg"); + return (c.get("GesVen") == "X"); +} + +class CG0200_application : public TRelation_application +{ + TMask* _msk; + TClifoVI *_rel; + TLocalisamfile* _saldi; + TLocalisamfile* _anag; + TLocalisamfile* _fis; + TLocalisamfile* _comuni; + TLocalisamfile* _pcon; + + bool _lbcn; + +protected: + 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 const char* get_next_key(); + void init_pages(TMask& m); + virtual void init_query_mode(TMask& m); + virtual void init_query_insert_mode(TMask& m) {init_query_mode(m);} + virtual void init_insert_mode(TMask& m) {init_query_mode(m);} + virtual void init_modify_mode(TMask& m) {init_pages(m);} + + //////////// + static bool indsp_notify(int r, KEY key); + static bool indsp_handler(TMask_field& f, KEY key) ; + virtual int write(const TMask& m); + virtual int rewrite(const TMask& m); + virtual int read(TMask& m); + TSheet_field& indsp_sheet() const; + TArray_sheet* field_sheet(const int n) const; + void reset_sheet(); + void indsp_pack(); + void common_f(const TMask& m); + /////////// + + static bool tipo_handler(TMask_field& f, KEY key); + static bool percip_handler(TMask_field& f, KEY key); + +public: + virtual TRelation* get_relation() const {return (TRelation*)_rel;} + CG0200_application() {} +}; + +inline CG0200_application& app() { return (CG0200_application&)main_app(); } + +bool CG0200_application::protected_record(TRectype &rec) + +{ + TMask* m = get_mask(MODE_MOD); + const int gruppo = atoi(m->get(F_GRUPPO)); + const int conto = atoi(m->get(F_CONTO)); + const long sottoc = atol(m->get(F_CODCF)); + + _saldi->zero(); + _saldi->put(PCN_GRUPPO, gruppo); + _saldi->put(PCN_CONTO, conto); + _saldi->put(PCN_SOTTOCONTO, sottoc); + _saldi->read(); + + return _saldi->good() && + gruppo ==_saldi->get_int(PCN_GRUPPO) && + conto ==_saldi->get_int(PCN_CONTO) && + sottoc ==_saldi->get_long(PCN_SOTTOCONTO); +} + +const char* CG0200_application::get_next_key() + +{ + TLocalisamfile& clifo = _rel->lfile() ; + long codcf = 1L ; + const TString tipo(_msk->get(F_TIPOCF)) ; + + if (!clifo.empty()) + { + clifo.zero() ; + clifo.setkey(1) ; + if ( tipo == TCLI ) + { + clifo.put(CLI_TIPOCF, (const char* ) TFOR); + clifo.read(_isgteq ) ; + if (clifo.good()) + clifo.prev() ; + clifo.setstatus(NOERR); + } + else clifo.last( ) ; + if ( clifo.good() ) + { + const TFixed_string tipocf(clifo.get(CLI_TIPOCF)); + if ( tipocf == tipo ) + codcf += clifo.get_long(CLI_CODCF); + } + } + return format("%d|%s|%d|%ld", F_TIPOCF, (const char*) tipo, F_CODCF, codcf); +} + +HIDDEN bool no_dup_fis(TMask_field& f, KEY key) +{ + TMask& msk = f.mask() ; + + if (msk.query_mode() || !f.to_check(key)) return TRUE; + TLocalisamfile& clifo = app().get_relation()->lfile(LF_CLIFO) ; + + if ( f.get().not_empty() && !clifo.empty() ) + { + clifo.zero() ; + const char t1 = msk.get(F_TIPOCF)[0] ; + + clifo.put(CLI_TIPOCF, t1); + clifo.put(CLI_COFI, f.get()); + clifo.setkey(4) ; + clifo.read() ; + clifo.setkey(1) ; + const char t = clifo.get_char(CLI_TIPOCF); + const TFixed_string s = clifo.get(CLI_CODCF); + const TFixed_string s1(msk.get(F_CODCF)); + + if (clifo.good() && (t1 != t || s1 != s)) + { + f.yesno_box("Codice fiscale gia' utilizzato per il codice : %c/%s", + t, (const char*) s); + return FALSE; + } + } + return TRUE ; +} + +HIDDEN bool no_dup_iva(TMask_field& f, KEY key) +{ + TMask& msk = f.mask() ; + + if (msk.query_mode() || !f.to_check(key)) return TRUE; + + TLocalisamfile& clifo = app().get_relation()->lfile(LF_CLIFO) ; + + if ( f.get().not_empty() && !clifo.empty() ) + { + clifo.zero() ; + const char t1 = msk.get(F_TIPOCF)[0]; + + clifo.put(CLI_TIPOCF, t1) ; + clifo.put(CLI_STATOPAIV, msk.get(F_STATOPAIV)) ; + clifo.put(CLI_PAIV, f.get()) ; + clifo.setkey(5) ; + clifo.read() ; + clifo.setkey(1) ; + const char t = clifo.get_char(CLI_TIPOCF); + const TFixed_string s = clifo.get(CLI_CODCF); + const TFixed_string s1(msk.get(F_CODCF)); + + if (clifo.good() && (t1 != t || s1 != s)) + { + f.error_box("Partita iva gia' definita per il codice : %c/%s", + t, (const char*) s); + return FALSE ; + } + } + return TRUE ; +} + +HIDDEN bool autoexit_handler(TMask_field& f, KEY key) + +{ + if (f.mask().query_mode()) + { + if (key == K_TAB && f.focusdirty()) + { + TArray parms; + parms.add((TString)format("%d", f.dlg())); + ::validate(AUTOEXIT_FUNC, (TEdit_field&) f, key, parms); + } + } + else + if (f.to_check(key) && f.mask().get(F_ALLEG) != "4") + { + if (f.dlg() == F_COFI) return no_dup_fis(f, key); + else return no_dup_iva(f, key); + } + return TRUE; +} + +bool CG0200_application::tipo_handler(TMask_field& f, KEY key) + +{ + TMask& m = f.mask(); + + const bool fis = f.get() == "F"; + + m.send_key(K_SHIFT + K_CTRL + (app()._lbcn && fis ? 's' : 'h'), -5); + return TRUE; +} + +HIDDEN bool tipocf_handler(TMask_field& f, KEY key) +{ + TMask& m = f.mask(); + const bool cf = (f.get() == "F"); + + if (key == K_TAB) + { + if (cf || !gest_vend()) // If it's a FORNICATOR disable pages + for (int j=3; j<8;j++) + m.disable_page(j); +else // If it's a CUSTOMER enable pages +{ + for (int j=3; j<8;j++) + m.enable_page(j); +} +} +return TRUE; +} + + +bool CG0200_application::percip_handler(TMask_field& f, KEY key) +{ + TMask& m = f.mask(); + + if (f.to_check(key) && m.get(F_CODANAGPER).not_empty()) + { + TLocalisamfile anag(LF_ANAG); + TString80 c(m.get(F_COFI)), p(m.get(F_PAIV)); + + if ((c.not_empty() && c != anag.get(ANA_COFI)) || + (p.not_empty() && p != anag.get(ANA_PAIV))) return error_box("Percipiente non corretto"); + TString80 r(anag.get(ANA_RAGSOC)); + if (m.get(F_RAGSOC).empty() || + (key == K_TAB && yesno_box("Ragione sociale differente correggo in %s", (const char*) r))) + m.set(F_RAGSOC, r, TRUE); + if (m.get(F_INDCF).empty()) m.set(F_INDCF, anag.get(ANA_INDRES)); + if (m.get(F_CIVCF).empty()) m.set(F_CIVCF, anag.get(ANA_CIVRES)); + if (m.get(F_CAPCF).empty()) m.set(F_CAPCF, anag.get(ANA_CAPRES)); + if (m.get(F_COMCF).empty()) + { + m.set(F_STATOCF, anag.get(ANA_STATORES), TRUE); + m.set(F_COMCF, anag.get(ANA_COMRES), TRUE); + } + if (c.empty()) m.set(F_COFI, anag.get(ANA_COFI)); + if (p.empty()) m.set(F_PAIV, anag.get(ANA_PAIV)); + if (m.get(F_TIPOAPER) == "F") + { + m.send_key(K_SHIFT + K_CTRL + (app()._lbcn ? 's' : 'h'), -5); + if (app()._lbcn) + { + TLocalisamfile fis(LF_ANAGFIS); + + fis.zero(); + fis.put(ANF_CODANAGR, anag.get(ANA_CODANAGR)); + fis.read(); + if (fis.good()) + { + if (m.get(F_DATANASC).empty()) m.set(F_DATANASC, fis.get(ANF_DATANASC)); + if (m.get(F_COMNASC).empty()) + { + m.set(F_STATONASC, fis.get(ANF_STATONASC)); + m.set(F_COMNASC, fis.get(ANF_COMNASC)); + } + } + } + } + } + return TRUE; +} + + +HIDDEN bool alleg_handler(TMask_field& f, KEY key) + +{ + if (f.to_check(key)) + { + const int tipoall = atoi(f.get()); + TMask& m = f.mask(); + + if (tipoall == 0 || tipoall == 4) m.enable(F_CODALLEG); + else + { + m.disable(F_CODALLEG); + m.reset(F_CODALLEG); + } + m.set(F_OCCASIONALE, (tipoall == 2) ? "X" : " "); + } + return TRUE; +} + +HIDDEN bool occas_handler(TMask_field& f, KEY key) + +{ + if (f.to_check(key)) + { + const bool occas = f.get().not_empty(); + TMask& m = f.mask(); + + if (occas) m.set(F_ALLEG, "2"); + else + if (m.get_int(F_ALLEG) == 2) m.set(F_ALLEG, " "); + } + return TRUE; +} + +HIDDEN bool codalleg_handler(TMask_field& f, KEY key) + +{ + if (f.to_check(key)) + { + const TString cod(f.get()); + + if (cod.not_empty()) + { + TMask& m = f.mask(); + + if (cod == m.get(F_TIPOCF)) + return error_box("Codice per allegato non corretto"); + + TLocalisamfile clifo(LF_CLIFO); + const TString tipo(m.get(F_TIPOCF)); + + clifo.zero() ; + clifo.setkey(1) ; + clifo.put(CLI_TIPOCF, tipo); + clifo.put(CLI_CODCF, cod); + clifo.read() ; + if (clifo.bad()) return FALSE; + TString tipoall(clifo.get(CLI_ALLEG)); + if (clifo.get(CLI_CODALLEG).not_empty() || + clifo.get(CLI_PAIV).empty() || + (tipoall.not_empty() && tipoall != "4")) + return error_box("Codice per allegato non corretto"); + } + } + return TRUE; +} + +void CG0200_application::init_pages(TMask& m) + +{ + TConfig conf(CONFIG_DITTA, "cg"); + const bool tipocf=(m.get(F_TIPOCF) == "F"); + + _lbcn = (conf.get("GsLbCn") == "X"); + m.send_key(K_SHIFT + K_CTRL + (_lbcn ? 's' : 'h'), -5); + // Se non e' abilitata la gestione delle vendite disabilita le + // maschere dalla 4 in poi + if (!gest_vend() || tipocf) + { + for (int j=3; j<8;j++) + m.disable_page(j); + } + else + { + for (int j=3; j<8;j++) + m.enable_page(j); + } +} + +void CG0200_application::init_query_mode(TMask& m) + +{ + init_pages(m); + if (gest_vend()) + reset_sheet(); +} + +int CG0200_application::read(TMask& m) +{ + + TToken_string riga(240); + + m.autoload(_rel); + indsp_sheet().reset(); + for (int i=0; i< _rel->indirizzi_items();i++) + { + TRectype& rec=_rel->indirizzo(i); + riga.cut(0); + riga.add(rec.get(IND_RAGSOC)); + riga.add(rec.get(IND_INDIR)); + riga.add(rec.get(IND_CIV)); + riga.add(rec.get(IND_LOCALITA)); + riga.add(rec.get(IND_CAP)); + riga.add(rec.get(IND_STATO)); + riga.add(rec.get(IND_COM)); + riga.add(rec.get(IND_PTEL)); + riga.add(rec.get(IND_TEL)); + riga.add(rec.get(IND_PFAX)); + riga.add(rec.get(IND_FAX)); + riga.add(rec.get(IND_IVARID)); + riga.add(rec.get(IND_CODIND)); + indsp_sheet().row(i)=riga; + + // Load the sheets of CODINDDOC, CODINDSP, CODINDEFF. + riga.cut(0); + riga.add(rec.get(IND_CODIND)); + riga.add(rec.get(IND_RAGSOC)); + riga.add(rec.get(IND_INDIR)); + riga.add(rec.get(IND_CIV)); + riga.add(rec.get(IND_LOCALITA)); + field_sheet(F_CODINDDOC)->add(riga); + field_sheet(F_CODINDSP)->add(riga); + field_sheet(F_CODINDEFF)->add(riga); + } + return _rel->status(); +} + +int CG0200_application::rewrite(const TMask& m) +{ + common_f(m); + return _rel->rewrite(TRUE); +} + +int CG0200_application::write(const TMask& m) +{ + common_f(m); + return _rel->write(TRUE); +} + +TArray_sheet* CG0200_application::field_sheet(const int n) const +{ + TEdit_field& f=(TEdit_field&) _msk->field(n); + TArray_sheet* S=(TArray_sheet*) f.sheet()->sheet(); + return S; +} + +TSheet_field& CG0200_application::indsp_sheet() const +{ + TSheet_field& o_sheet=(TSheet_field&) _msk->field(F_SHEET_G_VEN); + return o_sheet; +} + +void CG0200_application::reset_sheet() +{ + const TToken_string nulla("|**Nessuno**||||"); + + app().field_sheet(F_CODINDDOC)->destroy(); + app().field_sheet(F_CODINDDOC)->add(nulla); + app().field_sheet(F_CODINDSP)->destroy(); + app().field_sheet(F_CODINDSP)->add(nulla); + app().field_sheet(F_CODINDEFF)->destroy(); + app().field_sheet(F_CODINDEFF)->add(nulla); +} + +void CG0200_application::indsp_pack() +{ + TArray& rows = indsp_sheet().rows_array(); + int nr=rows.items(); + + for (int i=0; ilfile().zero(); + m.autosave(_rel); + _rel->destroy_rows(); + indsp_pack(); + TArray& rows=indsp_sheet().rows_array(); + int n_items = rows.items(); + for (int i=0; iindirizzo(i); + row.restart(); + rec.zero(); + rec.put(IND_TIPOCF,tipocf); + rec.put(IND_CODCF,codcf); + rec.put(IND_RAGSOC,row.get()); + rec.put(IND_INDIR,row.get()); + rec.put(IND_CIV,row.get()); + rec.put(IND_LOCALITA,row.get()); + rec.put(IND_CAP,row.get()); + rec.put(IND_STATO,row.get_int()); + rec.put(IND_COM,row.get()); + rec.put(IND_PTEL,row.get()); + rec.put(IND_TEL,row.get()); + rec.put(IND_PFAX,row.get()); + rec.put(IND_FAX,row.get()); + rec.put(IND_IVARID,row.get()); + rec.put(IND_CODIND,i+1); + } +} + +bool CG0200_application::indsp_handler(TMask_field& f, KEY key) +{ + static int first_time=1; + + if (key == K_TAB && f.dirty()) // Was it changed ? + if (first_time) + { + TArray& righe=app().indsp_sheet().rows_array(); + int n=righe.items(); + app().reset_sheet(); + // Rebuild Sheets + for (int i=0; iadd(rigav); + app().field_sheet(F_CODINDSP)->add(rigav); + app().field_sheet(F_CODINDEFF)->add(rigav); + } + first_time=0; + } else + first_time=1; + return TRUE; +} + +bool CG0200_application::indsp_notify(int r, KEY key) +{ + TSheet_field& indsp=app().indsp_sheet(); + + switch (key) + { + case K_SPACE: + { + // Request to modify row #r + // Disable field CODIND update # of row + TMask& m = indsp.sheet_mask(); + + if (m.get_int(F_CODINDI)==0) // Is it a new row ? + m.set(F_CODINDI,(long)(r+1)); + m.disable(F_CODINDI); + } + break; + case K_INS: + // request to add the row #r + // To avoid rewriting of existing record. + if (indsp.items() >= 999) + { + error_box("Raggiunto il numero massimo degli indirizzi per questo C/F"); + return FALSE; // Refuse Permission + } else + // To avoid inserts in the middle of the sheet + if (r != -1 && indsp.items() > r) + { + error_box("Si possono aggiungere indirizzi solo alla fine"); + return FALSE; //Refuse permission + } + break; +default: + break; +} + return TRUE; +} + +bool CG0200_application::user_create() // initvar e arrmask +{ + + _rel = new TClifoVI; + + _saldi = new TLocalisamfile(LF_SALDI); + _anag = new TLocalisamfile(LF_ANAG); + _fis = new TLocalisamfile(LF_ANAGFIS); + _pcon = new TLocalisamfile(LF_PCON); + _comuni = new TLocalisamfile(LF_COMUNI); + _msk = new TMask("cg0200a") ; + _msk->set_handler(F_TIPOCF,tipocf_handler); + _msk->set_handler(F_OCCASIONALE, occas_handler); + _msk->set_handler(F_COFI, autoexit_handler); + _msk->set_handler(F_PAIV, autoexit_handler); + _msk->set_handler(F_CODANAGPER, percip_handler); + _msk->set_handler(F_TIPOPERS, tipo_handler); + _msk->set_handler(F_ALLEG, alleg_handler); + _msk->set_handler(F_CODALLEG, codalleg_handler); + + _msk->set_handler(F_SHEET_G_VEN, indsp_handler); + + TSheet_field& ind = (TSheet_field&) _msk->field(F_SHEET_G_VEN); + + ind.set_notify(indsp_notify); + + _saldi->setkey(2); + return TRUE; +} + +bool CG0200_application::user_destroy() // releasev e arrmask +{ + delete _msk; + delete _rel; + delete _saldi; + delete _anag; + delete _fis; + delete _pcon; + delete _comuni; + return TRUE; +} + +int cg0200(int argc, char* argv[]) +{ + CG0200_application a ; + a.run(argc, argv, "Clienti/Fornitori"); + return 0; +} diff --git a/cg/cg0201.h b/cg/cg0201.h index 1b0a0aef9..ab28401af 100755 --- a/cg/cg0201.h +++ b/cg/cg0201.h @@ -1,35 +1,35 @@ -#ifndef __RELATION_H -#include -#endif - -class TClifoVI:public TRelation -{ - // @DPRIV - TArray _indirizzi; - int _oldindirizzi; - // @END -protected: - // @FPROT - int write_rec(bool re, const TRectype& r, TLocalisamfile& f); - int cancella(TLocalisamfile& f, int da, int a); - int registra(bool re, bool force); - int read_indirizzi(); - // @END -public: - virtual int next(TReclock lockop=_nolock) {return (lfile().next(lockop) || read_indirizzi());} - virtual int prev(TReclock lockop=_nolock) {return (lfile().prev(lockop) || read_indirizzi());} - virtual int first(TReclock lockop=_nolock) {return (lfile().first(lockop) || read_indirizzi());} - virtual int last(TReclock lockop=_nolock) {return (lfile().last(lockop) || read_indirizzi());} - virtual int skip(TReclock lockop=_nolock) {return (lfile().skip(lockop) || read_indirizzi());} - virtual int read(TIsamop = _isgteq, TReclock lockop = _nolock, TDate& atdate = (TDate&) botime); - virtual int write(bool force=TRUE, TDate& atdate = (TDate&) botime); - virtual int rewrite(bool force=TRUE, TDate& atdate = (TDate&) botime); - virtual int remove(TDate& atdate = (TDate&) botime); - - TRectype& indirizzo(int i); - int indirizzi_items() const {return _indirizzi.items();} - void destroy_rows(); - - TClifoVI(); - virtual ~TClifoVI() {} -}; +#ifndef __RELATION_H +#include +#endif + +class TClifoVI:public TRelation +{ + // @DPRIV + TArray _indirizzi; + int _oldindirizzi; + // @END +protected: + // @FPROT + int write_rec(bool re, const TRectype& r, TLocalisamfile& f); + int cancella(TLocalisamfile& f, int da, int a); + int registra(bool re, bool force); + int read_indirizzi(); + // @END +public: + virtual int next(TReclock lockop=_nolock) {return (lfile().next(lockop) || read_indirizzi());} + virtual int prev(TReclock lockop=_nolock) {return (lfile().prev(lockop) || read_indirizzi());} + virtual int first(TReclock lockop=_nolock) {return (lfile().first(lockop) || read_indirizzi());} + virtual int last(TReclock lockop=_nolock) {return (lfile().last(lockop) || read_indirizzi());} + virtual int skip(TReclock lockop=_nolock) {return (lfile().skip(lockop) || read_indirizzi());} + virtual int read(TIsamop = _isgteq, TReclock lockop = _nolock, TDate& atdate = (TDate&) botime); + virtual int write(bool force=TRUE, TDate& atdate = (TDate&) botime); + virtual int rewrite(bool force=TRUE, TDate& atdate = (TDate&) botime); + virtual int remove(TDate& atdate = (TDate&) botime); + + TRectype& indirizzo(int i); + int indirizzi_items() const {return _indirizzi.items();} + void destroy_rows(); + + TClifoVI(); + virtual ~TClifoVI() {} +}; diff --git a/cg/cg2.h b/cg/cg2.h index 1314afeb3..b9faeffb8 100755 --- a/cg/cg2.h +++ b/cg/cg2.h @@ -1,8 +1,8 @@ -#ifndef __CG2_H -#define __CG2_H - -int cg2100(int argc, char** argv); -int cg2200(int argc, char** argv); - -#endif // __CG2_H - +#ifndef __CG2_H +#define __CG2_H + +int cg2100(int argc, char** argv); +int cg2200(int argc, char** argv); + +#endif // __CG2_H + diff --git a/cg/cg2100b.uml b/cg/cg2100b.uml index ce37a1f3c..27eb0ed0d 100755 --- a/cg/cg2100b.uml +++ b/cg/cg2100b.uml @@ -1,208 +1,208 @@ -#include "cg2100.h" - -TOOLBAR "" 0 20 0 2 - -#include - -ENDPAGE - -PAGE "OPERAZIONE DI PRIMA NOTA" -1 -1 77 20 - -GROUPBOX DLG_NULL 78 3 -BEGIN - PROMPT 1 0 "@BMovimento di sola contabilita'" -END - -NUMBER F_CODDITTA 5 -BEGIN - PROMPT 3 1 "Ditta " - FLAGS "FRD" - USE LF_NDITTE KEY 1 - INPUT CODDITTA F_CODDITTA - DISPLAY "Codice" CODDITTA - OUTPUT F_RAGSOC RAGSOC - CHECKTYPE REQUIRED -END - -STRING F_RAGSOC 50 -BEGIN - PROMPT 17 1 "Ragione " - FLAGS "D" -END - -NUMBER F_NUMREG 7 -BEGIN - PROMPT 57 3 "Operazione n." - FIELD NUMREG - FLAGS "RD" - KEY 1 -END - -DATE F_DATAREG -BEGIN - PROMPT 1 3 "Data operazione " - FIELD DATAREG -END - - -DATE F_DATACOMP -BEGIN - PROMPT 1 4 "Data di competenza " - FIELD DATACOMP -END - -NUMBER F_ANNOES 4 -BEGIN - PROMPT 57 4 "Esercizio " - FIELD ANNOES - FLAGS "DRZ" -END - -DATE F_DATADOC -BEGIN - PROMPT 1 5 "Data del documento " - FIELD DATADOC - WARNING "Specificare una data del documento non superiore a quella dell'operazione" - VALIDATE DATE_CMP_FUNC <= F_DATAREG -END - -STRING F_NUMDOC 7 -BEGIN - PROMPT 57 5 "Documento n. " - FIELD NUMDOC - WARNING "La causale impone di specificare il numero documento" -END - -NUMBER F_ANNOIVA 4 -BEGIN - FLAGS "H" -END - -STRING F_DESCAGG 5 -BEGIN - PROMPT 1 6 "Descrizione " - FLAGS "U" - USE %DPN - INPUT CODTAB F_DESCAGG - DISPLAY "Codice" CODTAB - DISPLAY "Descrizione@50" S0 - OUTPUT F_DESCAGG CODTAB - OUTPUT F_DESCR S0 - CHECKTYPE NORMAL -END - -STRING F_DESCR 50 -BEGIN - PROMPT 25 6 "" - FIELD DESCR - USE %DPN KEY 2 - INPUT S0 F_DESCR - DISPLAY "Descrizione@50" S0 - DISPLAY "Codice" CODTAB - COPY OUTPUT F_DESCAGG -END - -LIST F_PROVVISORIO 1 25 -BEGIN - PROMPT 1 7 "Movimento provvisorio " - FIELD PROVVIS - ITEM " |No (movimento normale)" - ITEM "P|Si (cancellabile)" - ITEM "N|Si (non cancellabile)" -END - -STRING F_CODCAUS 3 -BEGIN - PROMPT 1 8 "Causale " - FLAGS "U" - FIELD CODCAUS - USE LF_CAUSALI KEY 1 - INPUT CODCAUS F_CODCAUS - DISPLAY "Codice" CODCAUS - DISPLAY "Descrizione@50" DESCR - OUTPUT F_CODCAUS CODCAUS - OUTPUT F_DESCRCAUS DESCR - CHECKTYPE NORMAL - ADD RUN cg0 -4 -END - -STRING F_DESCRCAUS 50 -BEGIN - PROMPT 23 8 "" - USE LF_CAUSALI KEY 2 - INPUT DESCR F_DESCRCAUS - DISPLAY "Descrizione@50" DESCR - DISPLAY "Codice" CODCAUS - COPY OUTPUT F_CODCAUS -END - -STRING F_VALUTA 3 -BEGIN - PROMPT 1 9 "Valuta " - FIELD CODVAL - FLAGS "U" - GROUP 3 - USE %VAL - INPUT CODTAB F_VALUTA - DISPLAY "Codice" CODTAB - DISPLAY "Nome@50" S0 - DISPLAY "Cambio corrente" R0 - OUTPUT F_VALUTA CODTAB - OUTPUT F_CAMBIO R0 -END - -NUMBER F_CAMBIO 10 -BEGIN - PROMPT 16 9 "Cambio " - FIELD CAMBIO - FLAGS "RU" - GROUP 3 - PICTURE ".3" -END - -BOOLEAN F_VISVAL -BEGIN - PROMPT 42 9 "Visualizza importi in valuta" - GROUP 3 -END - -SPREADSHEET F_SHEETCG -BEGIN - PROMPT 0 9 "" - ITEM "Dare@17" - ITEM "Avere@17" - ITEM " @1" - ITEM "Gr." - ITEM "Co." - ITEM "Sottoc." - ITEM "Descrizione conto@50" - ITEM "Codice" - ITEM "Descrizione riga@50" - ITEM " @1" - ITEM "Gr./c" - ITEM "Co./c" - ITEM "Sottoc./c" - ITEM "Descrizione contropartita@50" - ITEM " @1" -END - -NUMBER F_DARE 17 -BEGIN - PROMPT 1 -1 "Sbilancio Dare " - FLAGS "DRV" - PICTURE "." -END - -NUMBER F_AVERE 17 -BEGIN - PROMPT 41 -1 "Sbilancio Avere " - FLAGS "DRV" - PICTURE "." -END - -ENDPAGE - -ENDMASK - -#include "cg21cg.uml" - +#include "cg2100.h" + +TOOLBAR "" 0 20 0 2 + +#include + +ENDPAGE + +PAGE "OPERAZIONE DI PRIMA NOTA" -1 -1 77 20 + +GROUPBOX DLG_NULL 78 3 +BEGIN + PROMPT 1 0 "@BMovimento di sola contabilita'" +END + +NUMBER F_CODDITTA 5 +BEGIN + PROMPT 3 1 "Ditta " + FLAGS "FRD" + USE LF_NDITTE KEY 1 + INPUT CODDITTA F_CODDITTA + DISPLAY "Codice" CODDITTA + OUTPUT F_RAGSOC RAGSOC + CHECKTYPE REQUIRED +END + +STRING F_RAGSOC 50 +BEGIN + PROMPT 17 1 "Ragione " + FLAGS "D" +END + +NUMBER F_NUMREG 7 +BEGIN + PROMPT 57 3 "Operazione n." + FIELD NUMREG + FLAGS "RD" + KEY 1 +END + +DATE F_DATAREG +BEGIN + PROMPT 1 3 "Data operazione " + FIELD DATAREG +END + + +DATE F_DATACOMP +BEGIN + PROMPT 1 4 "Data di competenza " + FIELD DATACOMP +END + +NUMBER F_ANNOES 4 +BEGIN + PROMPT 57 4 "Esercizio " + FIELD ANNOES + FLAGS "DRZ" +END + +DATE F_DATADOC +BEGIN + PROMPT 1 5 "Data del documento " + FIELD DATADOC + WARNING "Specificare una data del documento non superiore a quella dell'operazione" + VALIDATE DATE_CMP_FUNC <= F_DATAREG +END + +STRING F_NUMDOC 7 +BEGIN + PROMPT 57 5 "Documento n. " + FIELD NUMDOC + WARNING "La causale impone di specificare il numero documento" +END + +NUMBER F_ANNOIVA 4 +BEGIN + FLAGS "H" +END + +STRING F_DESCAGG 5 +BEGIN + PROMPT 1 6 "Descrizione " + FLAGS "U" + USE %DPN + INPUT CODTAB F_DESCAGG + DISPLAY "Codice" CODTAB + DISPLAY "Descrizione@50" S0 + OUTPUT F_DESCAGG CODTAB + OUTPUT F_DESCR S0 + CHECKTYPE NORMAL +END + +STRING F_DESCR 50 +BEGIN + PROMPT 25 6 "" + FIELD DESCR + USE %DPN KEY 2 + INPUT S0 F_DESCR + DISPLAY "Descrizione@50" S0 + DISPLAY "Codice" CODTAB + COPY OUTPUT F_DESCAGG +END + +LIST F_PROVVISORIO 1 25 +BEGIN + PROMPT 1 7 "Movimento provvisorio " + FIELD PROVVIS + ITEM " |No (movimento normale)" + ITEM "P|Si (cancellabile)" + ITEM "N|Si (non cancellabile)" +END + +STRING F_CODCAUS 3 +BEGIN + PROMPT 1 8 "Causale " + FLAGS "U" + FIELD CODCAUS + USE LF_CAUSALI KEY 1 + INPUT CODCAUS F_CODCAUS + DISPLAY "Codice" CODCAUS + DISPLAY "Descrizione@50" DESCR + OUTPUT F_CODCAUS CODCAUS + OUTPUT F_DESCRCAUS DESCR + CHECKTYPE NORMAL + ADD RUN cg0 -4 +END + +STRING F_DESCRCAUS 50 +BEGIN + PROMPT 23 8 "" + USE LF_CAUSALI KEY 2 + INPUT DESCR F_DESCRCAUS + DISPLAY "Descrizione@50" DESCR + DISPLAY "Codice" CODCAUS + COPY OUTPUT F_CODCAUS +END + +STRING F_VALUTA 3 +BEGIN + PROMPT 1 9 "Valuta " + FIELD CODVAL + FLAGS "U" + GROUP 3 + USE %VAL + INPUT CODTAB F_VALUTA + DISPLAY "Codice" CODTAB + DISPLAY "Nome@50" S0 + DISPLAY "Cambio corrente" R0 + OUTPUT F_VALUTA CODTAB + OUTPUT F_CAMBIO R0 +END + +NUMBER F_CAMBIO 10 +BEGIN + PROMPT 16 9 "Cambio " + FIELD CAMBIO + FLAGS "RU" + GROUP 3 + PICTURE ".3" +END + +BOOLEAN F_VISVAL +BEGIN + PROMPT 42 9 "Visualizza importi in valuta" + GROUP 3 +END + +SPREADSHEET F_SHEETCG +BEGIN + PROMPT 0 9 "" + ITEM "Dare@17" + ITEM "Avere@17" + ITEM " @1" + ITEM "Gr." + ITEM "Co." + ITEM "Sottoc." + ITEM "Descrizione conto@50" + ITEM "Codice" + ITEM "Descrizione riga@50" + ITEM " @1" + ITEM "Gr./c" + ITEM "Co./c" + ITEM "Sottoc./c" + ITEM "Descrizione contropartita@50" + ITEM " @1" +END + +NUMBER F_DARE 17 +BEGIN + PROMPT 1 -1 "Sbilancio Dare " + FLAGS "DRV" + PICTURE "." +END + +NUMBER F_AVERE 17 +BEGIN + PROMPT 41 -1 "Sbilancio Avere " + FLAGS "DRV" + PICTURE "." +END + +ENDPAGE + +ENDMASK + +#include "cg21cg.uml" + diff --git a/cg/cg2101.h b/cg/cg2101.h index 71a50a3c2..fdfa41d43 100755 --- a/cg/cg2101.h +++ b/cg/cg2101.h @@ -1,51 +1,51 @@ -#ifndef __CG2101_H -#define __CG2101_H - -#ifndef __RELATION_H -#include -#endif - -int date2esc(const TDate& d, int* prevesc = NULL); - -class TMovimentoPN : public TRelation -{ - // class TMovimentoPN : public TRelation - // @END - - // @DPRIV - TArray _cg, _iva; - int _oldcg, _oldiva; - real _balance; - // @END - -protected: - // @FPROT - int write_rec(bool re, const TRectype&r, TLocalisamfile& f); - int cancella(TLocalisamfile& f, int da, int a); - int registra(bool re, bool force); - int read_mov_rows(); - // @END - -public: - // @FPUB - virtual int next(TReclock lockop = _nolock) { return (file().next(lockop) || read_mov_rows()); } - virtual int prev(TReclock lockop = _nolock) { return (file().prev(lockop) || read_mov_rows()); } - virtual int first(TReclock lockop = _nolock) { return (file().first(lockop) || read_mov_rows()); } - virtual int last(TReclock lockop = _nolock) { return (file().last(lockop) || read_mov_rows()); } - virtual int skip(TRecnotype nrec, TReclock lockop = _nolock) { return (file().skip(nrec, lockop) || read_mov_rows()); } - virtual int read(TIsamop op = _isgteq, TReclock lockop = _nolock, TDate& atdate = (TDate&)botime); - virtual int write (bool force = TRUE, TDate& atdate = (TDate&)botime); - virtual int rewrite(bool force = TRUE, TDate& atdate = (TDate&)botime); - virtual int remove (TDate& atdate = (TDate&)botime); - - TRectype& cg(int i); - TRectype& iva(int i); - int cg_items() const { return _cg.items(); } - int iva_items() const { return _iva.items(); } - void destroy_rows(); - - TMovimentoPN(); - virtual ~TMovimentoPN() {} -}; - -#endif +#ifndef __CG2101_H +#define __CG2101_H + +#ifndef __RELATION_H +#include +#endif + +int date2esc(const TDate& d, int* prevesc = NULL); + +class TMovimentoPN : public TRelation +{ + // class TMovimentoPN : public TRelation + // @END + + // @DPRIV + TArray _cg, _iva; + int _oldcg, _oldiva; + real _balance; + // @END + +protected: + // @FPROT + int write_rec(bool re, const TRectype&r, TLocalisamfile& f); + int cancella(TLocalisamfile& f, int da, int a); + int registra(bool re, bool force); + int read_mov_rows(); + // @END + +public: + // @FPUB + virtual int next(TReclock lockop = _nolock) { return (file().next(lockop) || read_mov_rows()); } + virtual int prev(TReclock lockop = _nolock) { return (file().prev(lockop) || read_mov_rows()); } + virtual int first(TReclock lockop = _nolock) { return (file().first(lockop) || read_mov_rows()); } + virtual int last(TReclock lockop = _nolock) { return (file().last(lockop) || read_mov_rows()); } + virtual int skip(TRecnotype nrec, TReclock lockop = _nolock) { return (file().skip(nrec, lockop) || read_mov_rows()); } + virtual int read(TIsamop op = _isgteq, TReclock lockop = _nolock, TDate& atdate = (TDate&)botime); + virtual int write (bool force = TRUE, TDate& atdate = (TDate&)botime); + virtual int rewrite(bool force = TRUE, TDate& atdate = (TDate&)botime); + virtual int remove (TDate& atdate = (TDate&)botime); + + TRectype& cg(int i); + TRectype& iva(int i); + int cg_items() const { return _cg.items(); } + int iva_items() const { return _iva.items(); } + void destroy_rows(); + + TMovimentoPN(); + virtual ~TMovimentoPN() {} +}; + +#endif diff --git a/cg/cg2102.cpp b/cg/cg2102.cpp index 94aabf0d6..094e039d0 100755 --- a/cg/cg2102.cpp +++ b/cg/cg2102.cpp @@ -837,11 +837,12 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key) { const TLibro_giornale& gio = app().giornale(); if (dr <= gio.last_print()) - return f.error_box("La data dell'operazione e' antecedente al %s, ultima stampa\n" - "del libro giornale dell'esercizio %d", gio.last_reg().string(), ae); + return f.error_box("La data dell'operazione e' antecedente al %s,\n" + "ultima stampa del libro giornale dell'esercizio %d", + gio.last_reg().string(), ae); if (dr < gio.last_reg()) - warning_box("La data dell'operazione e' antecedente al %s, ultima registrazione\n" - "sul libro giornale dell'esercizio %d", + warning_box("La data dell'operazione e' antecedente al %s,\n" + "ultima registrazione sul libro giornale dell'esercizio %d", gio.last_reg().string(), ae); if (m.query_mode()) @@ -858,13 +859,13 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key) if (!ok) return FALSE; } - if (dr <= reg.last_print()) - return error_box("La data dell'operazione e' antecedente al %s, ultima\n" - "data di stampa del registro '%s' dell'anno %d", + if (dr < reg.last_print()) + return error_box("La data dell'operazione e' antecedente al %s,\n" + "ultima stampa del registro '%s' dell'anno %d", reg.last_print().string(), (const char*)codreg, dr.year()); if (dr < reg.last_reg()) - warning_box("La data dell'operazione e' antecedente al %s, ultima registrazione\n" - "sul registro '%s' dell'anno %d", + warning_box("La data dell'operazione e' antecedente al %s,\n" + "ultima registrazione sul registro '%s' dell'anno %d", reg.last_reg().string(), (const char*)codreg, dr.year()); } } @@ -876,15 +877,12 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key) // Certified 90% bool TPrimanota_application::datacomp_handler(TMask_field& f, KEY key) { - if (!f.to_check(key, TRUE)) - return TRUE; - - const TDate dc(f.get()); // Data di competenza - const int ae = date2esc(dc); // Esercizio corrispondente - TMask& m = f.mask(); - - if (ae) - { + if ((key == K_TAB && f.focusdirty()) || key == K_ENTER) + { + const TDate dc(f.get()); // Data di competenza + const int ae = date2esc(dc); // Esercizio corrispondente + TMask& m = f.mask(); + const char* data = ""; if (f.dlg() == F_DATACOMP) { @@ -894,19 +892,22 @@ bool TPrimanota_application::datacomp_handler(TMask_field& f, KEY key) else data = "del 74/ter"; - const TDate dr(m.get(F_DATAREG)); // Data operazione - int pr; // Esercizio precedente - const int ar = date2esc(dr, &pr); // Esercizio in corso - if (ae != ar && ae != pr) - { - TString80 e; - e << "La data " << data << " deve appartenere all'esercizio " << ar; - if (pr > 0) e << " o al " << pr; - return f.error_box(e); - } - } - else - return f.error_box("La data non appartiene a nessun esercizio"); + if (ae) + { + const TDate dr(m.get(F_DATAREG)); // Data operazione + int pr; // Esercizio precedente + const int ar = date2esc(dr, &pr); // Esercizio in corso + if (ae != ar && ae != pr) + { + TString80 e; + e << "La data " << data << " deve appartenere all'esercizio " << ar; + if (pr > 0) e << " o al " << pr; + return f.error_box(e); + } + } + else + return f.error_box("La data %s non appartiene a nessun esercizio", data); + } return TRUE; } diff --git a/cg/cg2103.cpp b/cg/cg2103.cpp index 48e5ab1f3..1569b23a6 100755 --- a/cg/cg2103.cpp +++ b/cg/cg2103.cpp @@ -240,23 +240,23 @@ TCausale::TCausale(const char* cod, int year) // Legge le righe della causale attualmente selezionata sulla maschera bool TCausale::read(const char* cod, int year) { + TLocalisamfile caus(LF_CAUSALI); + + _rec = caus.curr(); _rec.zero(); // Delete header destroy(); // Delete all rows - - _iva = iva_errata; + _iva = iva_errata; // Delete misc info _sezione_clifo = _sezione_ritsoc = ' '; if (*cod > ' ') { - - TLocalisamfile caus(LF_CAUSALI); caus.setkey(1); caus.zero(); caus.put(CAU_CODCAUS, cod); int err = caus.read(); - _rec = caus.curr(); if (err != NOERR) return FALSE; - + _rec = caus.curr(); + TLocalisamfile rcaus(LF_RCAUSALI); rcaus.setkey(1); rcaus.zero(); diff --git a/cg/cg2200.cpp b/cg/cg2200.cpp index 329cdf25d..6eef2326f 100755 --- a/cg/cg2200.cpp +++ b/cg/cg2200.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include "cg2200.h" @@ -9,6 +10,28 @@ #include #include +TString& add_plural(TString& s, long num, const char* name) +{ + const TFixed_string n(name); + const char last = *n.right(1); + + if (num < 1) + { + s << "nessun"; + if (strchr("aeiou", n[0]) == NULL) + s << last; + s << ' ' << name; + } + else + { + s << num << ' ' << name; + if (num > 1) + s[s.len()-1] = (last == 'a') ? 'e' : 'i'; + } + + return s; +} + class TDeleteprovv_app : public TApplication { protected: @@ -33,42 +56,75 @@ bool TDeleteprovv_app::destroy() bool TDeleteprovv_app::menu(MENU_TAG) { - TLocalisamfile mov(LF_MOV), rmov(LF_RMOV), rmoviva(LF_RMOVIVA); TMask m("cg2200a"); + TCursor& cur = *m.efield(F_FROMDATE).browse()->cursor(); + TLocalisamfile& mov = cur.file(LF_MOV); + TLocalisamfile rmov(LF_RMOV); + TLocalisamfile rmoviva(LF_RMOVIVA); while (m.run() != K_QUIT) - { - mov.setkey(2); - rmov.setkey(1); - rmoviva.setkey(1); - - TRectype to(mov.curr()); - to.zero(); - to.put(MOV_DATAREG, m.get(F_TODATE)); - to.put(MOV_NUMREG, m.get(F_TOREG)); + { + TRecnotype last = cur.items()-1; + mov.zero(); + const char* s = m.get(F_TODATE); + if (*s) + { + mov.put(MOV_DATAREG, s); + mov.put(MOV_NUMREG, m.get(F_TOREG)); + last = cur.read(); + } mov.zero(); mov.put(MOV_DATAREG, m.get(F_FROMDATE)); mov.put(MOV_NUMREG, m.get(F_FROMREG)); - for (mov.read(_isequal, _lock); mov.good(); mov.next()) + const TRecnotype first = cur.read(); + + const TRecnotype total = last-first+1; + TString80 caption("Cancellazione di "); + add_plural(caption, total, "movimento"); + + if (!yesno_box(caption)) + continue; + + TProgind pi(total, caption, FALSE, TRUE, 24); + + for (cur = first; cur.pos() <= last; ++cur) { - if (mov.curr() > to) break; const long numreg = mov.get_long(MOV_NUMREG); - for (int rig = 1; ; rig++) + + int err = cur.lock(); + for (int rig = 1; err == NOERR; rig++) { rmov.put(RMV_NUMREG, numreg); rmov.put(RMV_NUMRIG, rig); if (rmov.read(_isequal, _lock) != NOERR) break; - rmov.remove(); + err = rmov.remove(); + if (err != NOERR) + caption.format("riga contabile %d", rig); } - for (rig = 1; ; rig++) + for (rig = 1; err == NOERR; rig++) { - rmov.put(RMI_NUMREG, numreg); + rmoviva.put(RMI_NUMREG, numreg); rmoviva.put(RMI_NUMRIG, rig); if (rmoviva.read(_isequal, _lock) != NOERR) break; - rmov.remove(); + err = rmov.remove(); + if (err != NOERR) + caption.format("riga IVA %d", rig); + } + + if (err == NOERR) + err = mov.remove(); + else + caption = "testata"; + + if (err == NOERR) + pi.addstatus(1); + else + { + error_box("Errore %d nella cancellazione della %s del movimento %ld", + err, (const char*)caption, numreg); + break; } - mov.remove(); } } @@ -79,6 +135,6 @@ bool TDeleteprovv_app::menu(MENU_TAG) int cg2200(int argc, char** argv) { TDeleteprovv_app a; - a.run(argc, argv, "Cancellazione movimenti provvisori"); + a.run(argc, argv, "Eliminazione movimenti provvisori"); return 0; } \ No newline at end of file diff --git a/cg/cg2200a.uml b/cg/cg2200a.uml index 40e944651..b9ce5bd1a 100755 --- a/cg/cg2200a.uml +++ b/cg/cg2200a.uml @@ -1,8 +1,8 @@ #include "cg2200.h" -PAGE "Eliminazione Movimenti Provvisori" -1 -1 44 9 +PAGE "Eliminazione Movimenti Provvisori" -1 -1 42 9 -GROUPBOX DLG_NULL 42 3 +GROUPBOX DLG_NULL 40 3 BEGIN PROMPT 1 1 "Dal movimento" END @@ -13,11 +13,11 @@ BEGIN USE LF_MOV KEY 2 SELECT PROVVIS="P" INPUT DATAREG F_FROMDATE INPUT NUMREG F_FROMREG - DISPLAY "Data@10" DATAREG - DISPLAY "Numero@6" NUMREG - DISPLAY "Causale" CODCAUS - DISPLAY "Documento" NUMDOC - DISPLAY "Descrizione@50" DESCR + DISPLAY "Data@10" DATAREG + DISPLAY "Numero@6" NUMREG + DISPLAY "Causale" CODCAUS + DISPLAY "Documento" NUMDOC + DISPLAY "Descrizione@50" DESCR OUTPUT F_FROMDATE DATAREG OUTPUT F_FROMREG NUMREG CHECKTYPE NORMAL @@ -26,10 +26,10 @@ END NUMBER F_FROMREG 5 BEGIN PROMPT 22 2 "Operazione " - FLAGS "D" + FLAGS "DR" END -GROUPBOX DLG_NULL 42 3 +GROUPBOX DLG_NULL 40 3 BEGIN PROMPT 1 4 "Al movimento" END @@ -37,17 +37,22 @@ END DATE F_TODATE BEGIN PROMPT 2 5 "Data " - COPY ALL F_FROMDATE + COPY USE F_FROMDATE + INPUT DATAREG F_TODATE + INPUT NUMREG F_TOREG + COPY DISPLAY F_FROMDATE + OUTPUT F_TODATE DATAREG + OUTPUT F_TOREG NUMREG CHECKTYPE NORMAL END NUMBER F_TOREG 5 BEGIN PROMPT 22 5 "Operazione " - FLAGS "D" + FLAGS "DR" END -BUTTON DLG_DELREC 10 2 +BUTTON DLG_OK 10 2 BEGIN PROMPT -12 -1 "" END @@ -57,4 +62,4 @@ BEGIN PROMPT -22 -1 "" END -ENDPAGE \ No newline at end of file +ENDPAGE diff --git a/cg/cg4400.cpp b/cg/cg4400.cpp index 8a51a3f66..35b039e7c 100755 --- a/cg/cg4400.cpp +++ b/cg/cg4400.cpp @@ -1,1608 +1,1608 @@ -// cg4400.cpp -// Stampa tabella registri -#include "cg4.h" -#include "cg4400.h" -#include "cg4400a.h" - -static TString256 TMP; - -inline CG4400_application& app() { return (CG4400_application&)main_app(); } - -bool filter_func (const TRelation * r) -{ - TLocalisamfile & mov = r->lfile(LF_MOV); - TString codreg = mov.get(MOV_REG); - TDate datareg = mov.get_date(MOV_DATAREG); - int annoiva = mov.get_int(MOV_ANNOIVA); - - 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; - - 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(const TObject** o1, const TObject** o2) -{ - TRigaiva* r1 = (TRigaiva*)*o1; - TRigaiva* r2 = (TRigaiva*)*o2; - TString campo1; - TString campo2; - - campo1.format("%d%4s", r1->_tipodet, (const char*)r1->_codiva); - campo2.format("%d%4s", r2->_tipodet, (const char*)r2->_codiva); - return (strcmp((const char*)campo1, (const char*)campo2)); -} - -/* - bool CG4400_application::libro_giornale_iva_unico() - { - TConfig conf(CONFIG_DITTA); - - return conf.get("StLgiU") == "X"; - } - */ - -bool mask_select (TMask_field& f, KEY k) -{ - long j, cnt, chk; int i; - TString from = f.mask().get(DA_CODICE); - TString to = f.mask().get(A_CODICE); - TBit_array selected = app()._selected; - - // build sheet - if (k == K_SPACE) - { - f.mask().field(DA_CODICE).set(""); - f.mask().field(A_CODICE).set(""); - app()._ditte->destroy(); chk = 0l; - for (i = 0; i < app()._nomiditte.items(); i++) - { - if (app()._selected[i]) continue; - TToken_string d = (const char*)((TToken_string&)app()._nomiditte[i]); - TString cod = d.get(1); - app()._ditte->add(d); - - if (!from.empty() || !to.empty()) - { - if (from.empty()) from = "0"; - if (to.empty()) to = "999999"; - if (atol(cod) >= atol(from) && atol(cod) <= atol(to)) - { - selected.set(chk++); - app()._ditte->check(chk++); - } - } - } - // seleziona e aggiungi alle gia' selezionate - if (app()._ditte->run() == K_ENTER) - { - cnt = 0; - for (j = 0l; j < app()._n_ditte; j++) - { - if (app()._selected[j]) continue; - if (app()._ditte->checked(cnt++)) - selected.set(j); - } - app()._selected |= selected; - selected.reset(); - } - long numd = app()._selected.ones(); - f.mask().set(F_SELECT,numd); - } - return TRUE; -} - -bool mask_verifica (TMask_field& f, KEY k) -{ - int i; - - if (k == K_SPACE) - { - app()._ditte->destroy(); - for (i = 0; i < app()._nomiditte.items(); i++) - { - TToken_string d = (const char*)((TToken_string&)app()._nomiditte[i]); - app()._ditte->add(d); - if (app()._selected[i]) app()._ditte->check(i); - } - app()._ditte->disable_check(); - app()._ditte->run(); - app()._ditte->enable_check(); - } - return TRUE; -} - -bool mask_annulla (TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - app()._selected.reset(); - f.mask().set(F_SELECT, "0"); - } - return TRUE; -} - -bool mask_from_to (TMask_field& f, KEY k) -{ - if (k == K_TAB) - { - app()._selected.reset(); - TString from, to; - const short id = f.dlg(); - from = f.mask().get(id-1); - to = f.mask().get(id); - int i; - if (!from.empty() || !to.empty()) - { - long chk = 0l; - if (from.empty()) from = "0"; - if (to.empty()) to = "999999"; - - for (i = 0; i < app()._nomiditte.items(); i++) - { - TToken_string d = (const char*)((TToken_string&)app()._nomiditte[i]); - TString cod = d.get(1); - - if (atol(cod) >= atol(from) && atol(cod)<= atol(to)) - app()._selected.set(chk++); - } - } - } - return TRUE; -} - -bool mask_mese (TMask_field& f, KEY k) -{ - if (k == K_ENTER) - { - int mese = f.mask().get_int(MESE); - int umese = f.mask().get_int(ULTIMO_MESE); - - if (mese != umese+1) - { - f.warning_box ("Le stampe devono essere richieste mese per mese! I mesi successivi a %s non sono ancora stati stampati.", itom(umese)); - return FALSE; - } - } - return TRUE; -} - -bool mask_cod (TMask_field& f, KEY k) -{ - TTable TabLbu ("%LBU"); - TString codtab; - int anno; - - //if ( (k == K_TAB) && f.mask().is_running() ) - if ( (k == K_SPACE)||(k == K_TAB) ) - { - 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(MESE,TabLbu.get_long("I0")+1); - f.mask().set(ULTIMO_MESE,TabLbu.get_long("I0")); - f.mask().set(ULTIMA_PAGINA,TabLbu.get_long("I1")); - } - } - return TRUE; -} - -bool mask_data (TMask_field& f, KEY k) -{ - const short id = f.dlg(); - - if (k == K_ENTER) - { - int anno = f.mask().get_int(ANNO); - TDate data = f.mask().get(id); - if (data.ok()) - if (data.year() != anno) - { - f.warning_box("L'anno delle date limite deve essere uguale all'anno iva specificato"); - return FALSE; - } - } - return TRUE; -} - -/* - bool mask_fino_a_mese (TMask_field& f, KEY k) - { - if (k == K_ENTER) - { - TTable TabReg ("REG"); - TString16 codtab; - int giorni_del_mese; - TString codreg = f.mask().get(CODICE_LIBRO); - int tipo = f.mask().get_int(TIPO_STAMPA); - int anno = f.mask().get_int(ANNO); - - if ( (tipo == 1) || (tipo == 4) ) - { - int fino_a_mese = f.mask().get_int(FINO_A_MESE); - if (fino_a_mese == 12) - giorni_del_mese = 31; - else - { - TDate primo = format("01/%02d/%4d", fino_a_mese+1, anno); - --primo; - giorni_del_mese = primo.day(); - } - TDate datasup = format("%02d/%02d/%4d",giorni_del_mese,fino_a_mese,anno); - if (codreg != "") - { - TabReg.zero(); - codtab << anno << codreg; - TabReg.put ("CODTAB", codtab); - TabReg.read(); - if ( TabReg.good() ) - { - TDate data = TabReg.get_date("D3"); - if (datasup < data) - { - TString16 datas = format("%02d/%4d", data.month(), data.year()); - f.warning_box ("La data specificata non deve essere inferiore al %s (ultima data di stampa specificata sul registro)", (const char*)datas); - return FALSE; - } - } - } - if (tipo == 4) - { - TabReg.zero(); - TabReg.put ("CODTAB", anno); - 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 (datasup > data) - { - TString16 datas = format("%02d/%4d", data.month(), data.year()); - f.warning_box ("La data specificata non deve essere superiore al %s (ultima data di stampa del libro giornale)", (const char*)datas); - return FALSE; - } - } - } - } - } - } - return TRUE; - } - */ - -//da una SHEET non e' possibile mandare messaggi nella maschera!!! -HIDDEN bool my_handler (TMask_field& f, KEY k) -{ - if (k == K_TAB) - { - TMask& m = f.mask(); - int stampa_su = m.get_int(TIPO_STAMPA); - if ( (stampa_su == 1) || (stampa_su == 4) ) - { - m.hide (CODICE_LIB_UN); - m.hide (CODICE_LIBRO_PROVA); - m.hide (MESE); - m.hide (ULTIMO_MESE); - m.hide (ULTIMA_PAGINA); - m.hide (CODICE_LIBRO_IVA); - m.hide (DATA_STAMPA); - m.hide (DA_DATA); - m.hide (A_DATA); - m.show (CODICE_LIBRO); - m.show (TIPO_RIEPILOGATIVO); - m.show (FINO_A_MESE); - } - if (stampa_su == 2) - { - m.show (CODICE_LIB_UN); - m.hide (CODICE_LIBRO_PROVA); - m.show (MESE); - m.show (ULTIMO_MESE); - m.show (ULTIMA_PAGINA); - m.show (CODICE_LIBRO_IVA); - m.hide (DATA_STAMPA); - m.hide (DA_DATA); - m.hide (A_DATA); - m.hide (CODICE_LIBRO); - m.hide (TIPO_RIEPILOGATIVO); - m.hide (FINO_A_MESE); - } - if (stampa_su == 3) - { - m.hide (CODICE_LIB_UN); - m.hide (MESE); - m.hide (ULTIMO_MESE); - m.hide (ULTIMA_PAGINA); - m.hide (CODICE_LIBRO_IVA); - m.hide (CODICE_LIBRO); - m.show (CODICE_LIBRO_PROVA); - m.show (DATA_STAMPA); - m.show (DA_DATA); - m.show (A_DATA); - m.hide (TIPO_RIEPILOGATIVO); - m.hide (FINO_A_MESE); - } - } - return TRUE; -} - -const char * CG4400_application::descr_doc(const char * tipo) -{ - TTable tab_tpd("%TPD"); - TString codtab = format ("%-2s", tipo); - - 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::desc_attivita(const char * codatt) -{ - TTable attiv ("%AIS"); - - attiv.zero(); - attiv.put("CODTAB", codatt); - if (attiv.read()==NOERR) - TMP = attiv.get("S0"); - else - TMP = ""; - return TMP; -} - -const char * CG4400_application::ricerca_cf(char tipocf, long codcf) -{ - _clifo->zero(); - _clifo->put(CLI_TIPOCF, tipocf); - _clifo->put(CLI_CODCF, codcf); - if (_clifo->read() == NOERR) - TMP = _clifo->get(CLI_RAGSOC); - else - TMP = ""; - return TMP; -} - -const char * CG4400_application::ricerca_occ(const char * occ) -{ - TLocalisamfile occas (LF_OCCAS); - - occas.zero(); - occas.put(OCC_CFPI, occ); - - if (occas.read() == NOERR) - TMP = occas.get(OCC_RAGSOC); - else - TMP = ""; - return TMP; -} - -void CG4400_application::user_create() -{ - _nditte = new TLocalisamfile(LF_NDITTE); - _ditte = new TArray_sheet(-1, -1, 0, 0, "Selezione Ditte", - "@1|Cod.@5|Ragione Sociale@50"); - _n_ditte = 0l; - for (_nditte->first(); !_nditte->eof(); _nditte->next()) - { - TString cod = _nditte->get("CODDITTA"); - _n_ditte++; - TToken_string* d = new TToken_string(" "); - d->add(cod); - d->add(_nditte->get("RAGSOC")); - _nomiditte.add(d); - } - _tab = new TLocalisamfile(LF_TAB); - _tabcom = new TLocalisamfile(LF_TABCOM); - _tabreg = new TTable("REG"); - _tablbu = new TTable("%LBU"); - _tabinl = new TTable("%INL"); - _tablim = new TTable("LIM"); - _tabpim = new TTable("PIM"); - _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, "", 1); - //_cur->set_filterfunction(filter_func); - - add_cursor(_cur); - add_file(LF_MOV); - add_file(LF_RMOVIVA); -} - -void CG4400_application::user_destroy() -{ - delete _ditte; - delete _nditte; - delete _tab; - delete _tabcom; - delete _cur; - delete _rel; - delete _clifo; -} - - -void CG4400_application::calcola_progressivi(real& r0, real& r1, const char* codiva, const int tipocr) -{ - TTable pim ("PIM"); - TString chiave; - int i, num=0; - - if (_tipo_stampa == 1) - num = _datareg.month(); - if ( (_tipo_stampa == 2) || (_tipo_stampa == 4) ) - num = _fino_a_mese; - - if (_frequiva == 'T') - for (i=3; isave_status(); - bool ok = _cur->is_first_match(LF_RMOVIVA); - int nrec = 0; - - while (ok) - { - nrec++; - TRectype iva (_cur->file(LF_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); - - impop = imposp = 0.00; - _riga_rmi.add_riga(impo,impos,codiva,tipodet,impop,imposp); - - if (_tipo_reg == 2) //registro acquisti - { - if (_tipo_stampa != 3) //stampa definitiva - calcola_progressivi(impop,imposp,codiva,tipocr); - _iva_array.add_riga(impo,impos,codiva,tipodet,impop,imposp); - } - - impop = imposp = 0.00; - if (_tipo_stampa != 3) - calcola_progressivi(impop,imposp,codiva,tipocr); - - _tot_iva_array.add_riga(impo,impos,codiva,impop,imposp); - - ok = _cur->next_match(LF_RMOVIVA); - } - _cur->restore_status(); - - 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 != 3) - { - 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"); - TString16 mesi_ric = ""; - TString16 mesi_cal = ""; - TString16 chiave = ""; - int i; - - if (lim.empty()) - return yesno_box("Non esiste la tabella liquidazione iva mensile! Vuoi ugualmente continuare la stampa?"); - if (pim.empty()) - return yesno_box("Non esiste la tabella progressivi iva mensile! Vuoi ugualmente continuare la stampa?"); - - if (_frequiva == 'T') //nella tabella LIM ho solo i mesi 3, 6, 9, 12 - { - for (i=3; i<=_fino_a_mese+3; i+=3) - { - chiave = ""; - chiave << _annoes << i; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - bool calcolato = lim.get_bool("B0"); - if (!calcolato) - - // return yesno_box("La liquidazione relativa al mese di %s deve essere ricalcolata. Vuoi ugualmente continuare la stampa?", itom(i) ); - mesi_ric << itom(i) << "\n\r"; - } - else - // return yesno_box("La liquidazione relativa al mese di %s non e' stata calcolata. Vuoi ugualmente continuare la stampa?", itom(i) ); - mesi_cal << itom(i) << "\n\r"; - } - } - if (_frequiva == 'M') - { - for (i=1; i<=_fino_a_mese; i++); - { - chiave = ""; - chiave << _annoes << i; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - bool calcolato = lim.get_bool("B0"); - if (!calcolato) - // return yesno_box("La liquidazione relativa al mese di %s deve essere ricalcolata. Vuoi ugualmente continuare la stampa?", itom(i) ); - mesi_ric << itom(i) << "\n\r"; - } - else - // return yesno_box("La liquidazione relativa al mese di %s non e' stata calcolata. Vuoi ugualmente continuare la stampa?", itom(i) ); - mesi_cal << itom(i) << "\n\r"; - } - } - if (mesi_ric.not_empty()) - { - warning_box ("Deve essere ricalcolata la liquidazione relativa ai mesi di:\n %s ", (const char *)mesi_ric); - return yesno_box("Vuoi ugualmente continuare la stampa?"); - } - - if (mesi_cal.not_empty()) - { - warning_box ("La liquidazione relativa al mese di %s non e' stata calcolata", (const char *)mesi_cal); - return yesno_box("Vuoi ugualmente continuare la stampa?"); - } - return TRUE; -} - -//controlla che i movimenti con data di registrazione compresa tra l'anno precedente e l'ultima data stampata siano tutti gia' stati stampati in forma definitiva*/ -bool CG4400_application::controlla_mov() -{ - TLocalisamfile mov (LF_MOV); - bool ok = TRUE; - byte tipo; - TDate udata; - TDate data = format("01/01/%4d", _annoes - 1); - TRecnotype rec = _tabreg->recno(); - for (mov.first(); !mov.eof(); mov.next()) - { - TString16 reg = mov.get(MOV_REG); - TDate datareg = mov.get_date(MOV_DATAREG); - if (_stampa_tutti_i_registri) - cerca_reg (reg, tipo, udata); - else udata = _data_da; - if ( (_stampa_tutti_i_registri && ((tipo == 1)||(tipo == 2))) - || ((!_stampa_tutti_i_registri)&&(reg == _codreg)) ) - if ( (datareg >= data) && (datareg <= udata) ) - { - bool stampato = mov.get_bool(MOV_STAMPATO); - long numreg = mov.get_long(MOV_NUMREG); - if (!stampato) - { - warning_box("Il movimento con numero di registrazione %ld non e' ancora stato stampato in forma definitiva!", numreg); - ok = FALSE; - } - } - } - _tabreg->readat(rec); - return ok; -} - -void CG4400_application::cerca_reg(const TString& c, byte& t, TDate& d) -{ - TString16 cod = ""; - - cod << _annoes << c; - _tabreg->zero(); - _tabreg->put("CODTAB", cod); - if (_tabreg->read() == NOERR) - { - t = _tabreg->get_int ("I0"); - d = _tabreg->get_date("D3"); - } -} - -/* - bool CG4400_application::controlla_mov() - { - bool ok = TRUE; - - if (_stampa_tutti_i_registri) - { - TRecnotype rec = _tabreg->recno();//la first l'ho gia' fatta - for (; !_tabreg->eof(); _tabreg->next()) - { - TString codtab = _tabreg->get("CODTAB"); - int anno = atoi(codtab.mid(0,4)); - if (anno != _annoes) break; - - TDate data_da = _tabreg->get_date("D3"); - TString16 codreg = codtab.mid(4,3); - leggi_movimenti(data_da, codreg, ok); - } - _tabreg->readat(rec); - } - else - leggi_movimenti(_data_da, _codreg, ok); - - return ok; - } - - void CG4400_application::leggi_movimenti(const TDate& d, const TString& cod, bool& ok) - { - TLocalisamfile mov (LF_MOV); - bool stampato; - long numreg; - TString codreg; - - TDate data = format("01/01/%4d", _annoes - 1); - mov.zero(); - TRectype a (mov.curr()); - mov.put(MOV_DATAREG, data); - a.put (MOV_DATAREG, d); - mov.read(_isgteq); - while (mov.curr() < a && !mov.eof()) - { - stampato = mov.get_bool(MOV_STAMPATO); - numreg = mov.get_long(MOV_NUMREG); - codreg = mov.get(MOV_REG); - if (codreg == cod) - if (!stampato) - { - warning_box("Il movimento con numero di registrazione %ld non e' ancora stato stampato in forma definitiva!", numreg); - ok = FALSE; - } - mov.next(); - } - } - */ - -void CG4400_application::set_page_tot_reg() -{ - reset_print(); - TString riga(_stampa_width); - int r=1, rr=0, row=0; - real tot_imponib, tot_imposta, tot_imponibp, tot_impostap; - - 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"); - set_row(r, "@78g3=operazione intracomunitaria e AF art.34 comma 3"); - r++; - 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 (_nrec > 0) //numero records di rmoviva - { - set_row(++rr, "@26g---------- P E R I O D O ----------"); - if (_tipo_stampa != 3) - 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 != 3) - set_row(rr, "@92gA C Q U I S T I"); - } - if (_tipo_reg == 1) - { - set_row(rr, "@37gV E N D I T E"); - if (_tipo_stampa != 3) - set_row(rr, "@93gV E N D I T E"); - } - rr++; - set_row(rr, "iva Descrizione@30gImponibile@49gImposta"); - if (_tipo_stampa != 3) - set_row(rr++, "@86gImponibile@106gImposta"); - else rr++; - rr++; - tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; - - _tot_iva_array.sort(compare_rows); - - for (int k = 0; k < _tot_iva_array.items(); k++) - { - TRiga& riga = (TRiga&)_tot_iva_array[k]; - row = rr+k; - set_row(row, "%3s", (const char*)riga._codiva); - TString descr = descr_iva(riga._codiva); - set_row(row, "@5g%s", (const char*)descr); - set_row(row, "@25g%r", &riga._imponibile); - set_row(row, "@41g%r", &riga._imposta); - if (_tipo_stampa != 3) - { - set_row(row, "@81g%r", &riga._imponibilep); - set_row(row, "@98g%r", &riga._impostap); - } - tot_imponib += riga._imponibile; - tot_imposta += riga._imposta; - tot_imponibp += riga._imponibilep; - tot_impostap += riga._impostap; - } - _tot_iva_array.destroy(); - row++; - set_row(++row, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); - if (_tipo_stampa != 3) - set_row(row, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); - //la stampa "tipi di indetraibilita'" viene fatta solo per gli acquisti - if (_tipo_reg == 2) - { - row+=2; - int tdetprec = -1; - int rw = row; - tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; - - _iva_array.sort(compare); - 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 != 3) - 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 != 3) - 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 != 3) - 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 != 3) - 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 != 3) - 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 (tdetprec == 9) - { - set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); - if (_tipo_stampa != 3) - set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); - } - _iva_array.destroy(); - } - } -} - -bool CG4400_application::compila_reg(const TMask& m) -{ - int anno; - long codditta = _nditte->get_long("CODDITTA"); - TString16 codtab = ""; - - _tipo_stampa = m.get_int(TIPO_STAMPA); - if (_tipo_stampa == 2) //stampa su libro unico di studio - _codreg = m.get(CODICE_LIBRO_IVA); - else if (_tipo_stampa == 3) //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) - { - 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"); - _pagine_stampate = _tabreg->get_int("I1"); - //_pagine_numerate = tab_reg.get_int("I2"); - //_stampa_ok = tab_reg.get_int("I7"); - //_nprog_da = tab_reg.get_long ("I6"); - //_tot_dare = tab_reg.get_real ("R1") - //_tot_avere = tab_reg.get_real ("R2"); - if (_tipo_stampa != 3) - _data_da = _tabreg->get_date ("D3"); - if ( _tipo_stampa == 1 || _tipo_stampa == 4 ) - if ( _data_a < _data_da) - { - TString16 datas = format("%02d/%4d", _data_da.month(), _data_da.year()); - warning_box ("La data specificata non deve essere inferiore al %s (ultima data di stampa specificata sul registro)", (const char*)datas); - return FALSE; - } - //_stampa_intesta = _tabreg->get_bool ("B9"); - _codatt = _tabreg->get("S8"); - _attivita = desc_attivita(_codatt); - _desc_lib = _tabreg->get ("S0"); - } - else - { - warning_box("Il registro IVA specificato non esiste nella \n Ditta %ld", codditta); - return FALSE; - } - } - - if (_tipo_stampa == 4) - { - TString app(4); - _tabreg->zero(); - app = format("%04d", _annoes); - _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) - { - TString16 datas = format("%02d/%4d", data.month(), data.year()); - warning_box ("La data specificata non deve essere superiore al %s (ultima data di stampa del libro giornale)", (const char*)datas); - 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) - { - _iva_array.destroy(); - _riga_rmi.destroy(); - _tot_iva_array.destroy(); - _doc_array.destroy(); - _dataregp = ""; - _mov_empty = TRUE; - _primast = _u_stampata; - set_print_zero(); - } - return TRUE; -} - -bool CG4400_application::preprocess_page(int file, int counter) -{ - if (file == LF_MOV) - { - if (counter) return TRUE; - int rr = 0; - TString ragsoc; - TString tipo_op = ""; - - TLocalisamfile& mov = _cur->file(LF_MOV); - TLocalisamfile& caus = _cur->file(LF_CAUSALI); - - //long annoes = mov->get_long(MOV_ANNOES); - //TString16 codreg = mov->get(MOV_REG); - _datareg = mov.get_date(MOV_DATAREG); - - //if (codreg != _codreg || annoes != _annoes) - // return FALSE; - - //if (_data_da.string() != "" && _data_a.string() != "") - // if ( (_datareg < _data_da || _datareg > _data_a) || (!_datareg.ok()) ) - // return FALSE; - - _mov_empty = FALSE; - - //if ( (_tipo_stampa == 1) || (_tipo_stampa == 4) ) - if ( (_datareg.month() != _dataregp.month()) && (_dataregp.ok()) ) - { - if (_tipo_stampa == 2) - ++ _u_stampata; - 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); - real totdoc = mov.get_real(MOV_TOTDOC); - TString numdoc = mov.get(MOV_NUMDOC); - char tipocf = mov.get(MOV_TIPO)[0]; - TString 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_STAMPATO); - bool intra = caus.get_bool(CAU_INTRACOM); - bool autof = caus.get_bool(CAU_AUTOFATT); - TString descrcau = caus.get(CAU_DESCR); - - //aggiornamento di mov - if (_tipo_stampa != 3) - if (!stampato) - { - mov.put(MOV_STAMPATO,TRUE); - mov.rewrite(); - } - - if ( intra && autof) - tipo_op = "3"; - else if (intra) - tipo_op = "1"; - else if (autof) - tipo_op = "2"; - - if ( (tipocf == 'C') || (tipocf == 'F') ) - { - if (ocfpi.trim().empty()) - ragsoc = ricerca_cf(tipocf, codcf); - else - ragsoc = ricerca_occ(ocfpi); - } - else ragsoc = descrcau; - - _tipodoc = mov.get(MOV_TIPODOC); - _descr_doc = descr_doc(_tipodoc); - TString app = datadoc.string(2, '/'); - - _doc_array.add_riga(_tipodoc,_descr_doc,totdoc); - - //setto le righe di stampa - _r = 1; - set_row(_r, "%s", (const char*) _datareg.string(2, '/')); - set_row(_r, "@9g%5d", protiva); - set_row(_r, "@15g%s", (const char*) app); - set_row(_r, "@24g%s", (const char*) numdoc); - set_row(_r, "@32g%6d", 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); - set_row(_r, "@72g%r", &totdoc); - - _nrec = riga_rmoviva(); - if (_nrec > 0) - { - for (int j = 0; j < _riga_rmi.items(); j++) - { - TRigaiva& riga = (TRigaiva&)_riga_rmi[j]; - rr = _r+j; - 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); - } - _riga_rmi.destroy(); - int tipocr = _cur->file(LF_RMOVIVA).get_int(RMI_TIPOCR); - set_row(_r, "@124g%d", tipocr); - } - //int tipocr = _cur->file(LF_RMOVIVA)->get_int(RMI_TIPOCR); - //set_row(_r, "@124g%d", tipocr); - if (_tipo_stampa == 3) //stampa di prova - { - set_row(_r, "@125g%6d", numreg); - if (stampato) - set_row(_r, "@131g*"); - } - if (_tipo_stampa == 4) //stampa con riferimento al libro giornale - set_row(_r, "@125g%ld", numgio); - } - return TRUE; -} - -void CG4400_application::aggiorna_reg() -{ - TString16 codtab; - TTable Tabreg ("REG"); - TTable TabInl ("%INL"); - 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) - { - //stampate = ultimast + 1; - if (!_mov_empty) //cioe' se e' stata stampata almeno una pagina - { - pag = _pagine_stampate + ultimast; - Tabreg.put("I1", pag); - } - Tabreg.put("D3", _data_a); - Tabreg.rewrite(); - } - if (_tipo_stampa == 2) //stampa su libro unico - //sulla tabella %inl (indice libro unico) devo generare una riga per ogni registro stampato - if (!_mov_empty) - { - 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; - - trovato = TRUE; - recprec = TabInl.curr(); - } - - TString cod = ""; - if (trovato) - { - 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 - { - TString16 num_riga ( format("%6d", 1L) ); - cod << codtab << num_riga; - } - - long numini = _pagine_stampate + 1; - nuovo.put("CODTAB", cod); - nuovo.put("I0", (long)_annoes); - nuovo.put("I1", (long)_fino_a_mese); - nuovo.put("I2", (long)(_primast + 1)); - nuovo.put("I3", (long)(_primast + ultimast)); - nuovo.put("I4", get_firm()); - nuovo.put("S0", _codreg); - nuovo.put("I5", (long)numini); - nuovo.put("I6", (long)(numini + ultimast - 1)); - - if (trovato) - TabInl.rewrite(nuovo); - else - TabInl.write(nuovo); - - _u_stampata += ultimast; - } -} - -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(); - } -} - -print_action CG4400_application::postprocess_page (int file, int counter) -{ - if (file == LF_MOV) - if (!counter) - { - bool FINITO = FALSE; - TRecnotype pos = _cur->pos(); - long items = _cur->items(); - - FINITO = (pos == items-1); - - if ( FINITO ) - { - set_page_tot_reg(); - return REPEAT_PAGE; - } - else //if ( (_tipo_stampa == 1) || (_tipo_stampa == 4) ) - { - 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()) - { - set_page_tot_reg(); - return REPEAT_PAGE; - } - } - } - return NEXT_PAGE; -} - -print_action CG4400_application::postprocess_print(int file, int counter) -{ - if (file == LF_MOV) - { - //aggiorna registri solo se non e' stampa di prova - if ( (_tipo_stampa != 3) && (!_stampa_tutti_i_registri) ) - aggiorna_reg(); - if (_stampa_tutti_i_registri) - //if (!_mov_empty ) - { - if (_tipo_stampa == 2) - ++ _u_stampata; - printer().formfeed(); - } - /* - if (_stampa_tutti_i_registri) - { - TString16 codtab; - int anno, tipo; - //vado avanti dal punto in cui sono - _tabreg->next(); - for (; !_tabreg->eof(); _tabreg->next()) - { - tipo = _tabreg->get_int("I0"); - if ( (tipo == 1) || (tipo == 2) ) //registro iva - { - codtab = _tabreg->get("CODTAB"); - anno = atoi(codtab.mid(0,4)); - break; - } - } - if ( (_tabreg->eof()) || (anno != _annoes) ) - { - if (_tipo_stampa == 2) //stampa su libro unico - aggiorna_lib(); - return NEXT_PAGE; - } - else - { - _tipo_reg = _tabreg->get_int("I0"); - _desc_lib = _tabreg->get("S0"); - _data_da = _tabreg->get_date("D3"); - _pagine_stampate = _tabreg->get_int("I1"); - _codreg = codtab.mid(4,3); - _primast = get_page_number(); - if (!_mov_empty ) - printer().formfeed(); - _cur->set_filterfunction(NULL); - _cur->set_filterfunction(filter_func); - _mov_empty = TRUE; - return REPEAT_PAGE; - } - } - */ - } - - return NEXT_PAGE; -} - -bool CG4400_application::set_print(int n) -{ - TMask m("cg4400a"); - int giorni_del_mese; - - if (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); - //Se stampa di prova l'utente indica data_da e data_a - if (_tipo_stampa == 3) - { - _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); - printer().setdate(_data_stampa); - } - // senno' data_da e' letta dal registro - else //stampe definitive - { - if ( (_tipo_stampa == 1) || (_tipo_stampa == 4) ) - _fino_a_mese = m.get_int(FINO_A_MESE); - 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); - //set_page_number(_u_stampata + 1); - } - if (_fino_a_mese == 12) - giorni_del_mese = 31; - else - { - 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); - // NB data_da viene letta nella preprocess_page - } - if (_tipo_stampa == 2) - compila_lib(); - stampa_registri_IVA(m); - } - else warning_box("Nessuna ditta selezionata!"); - return FALSE; -} - -void CG4400_application::stampa_registri_IVA(const TMask& m) -{ - long l; - long firm = TApplication::get_firm(); - bool ok = FALSE; - - for (l = 0l, _nditte->first(); !_nditte->eof(); l++, _nditte->next()) - { - if (_selected[l]) - { - TApplication::set_firm(_nditte->get_long("CODDITTA")); - ok = compila_reg(m); // cerca il primo registro valido (nel caso di stampa tutti i registri), senno' legge i dati del registro specificato - if (!ok) continue; - if (!_stampa_tutti_i_registri) - _cur->set_filterfunction(filter_func); - _frequiva = _nditte->get("FREQVIVA")[0]; - if (_tipo_stampa != 3) //stampa definitiva - ok = controlla_liquidazione() && controlla_mov(); - - if (!ok) continue; - - if (!_stampa_tutti_i_registri) - print(); - else - { - TString16 codtab; - int anno, tipo; - for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) - { - tipo = _tabreg->get_int("I0"); - codtab = _tabreg->get("CODTAB"); - anno = atoi(codtab.mid(0,4)); - if (anno > _annoes) - break; - if (anno == _annoes) - if ( (tipo == 1) || (tipo == 2) ) //registro iva - { - _tipo_reg = _tabreg->get_int("I0"); - _desc_lib = _tabreg->get("S0"); - if (_tipo_stampa != 3) - _data_da = _tabreg->get_date("D3"); - _pagine_stampate = _tabreg->get_int("I1"); - _codreg = codtab.mid(4,3); - _codatt = _tabreg->get("S8"); - _attivita = desc_attivita(_codatt); - _desc_lib = _tabreg->get ("S0"); - //_primast = get_page_number(); - //if (!_mov_empty ) - // printer().formfeed(); - _cur->set_filterfunction(NULL); - _cur->set_filterfunction(filter_func); - //set_page_number(_u_stampata + 1); - print(); - if (_tipo_stampa != 3) aggiorna_reg(); - } - } - } - if (_tipo_stampa == 2) - aggiorna_lib(); - } - } - - TApplication::set_firm(firm); -} - -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"); - - m.set_handler (TIPO_STAMPA, my_handler); - m.set_handler (A_CODICE, mask_from_to); - m.set_handler (DA_DATA, mask_data); - m.set_handler (A_DATA, mask_data); - m.set_handler (MESE, mask_mese); - m.set_handler (CODICE_LIB_UN, mask_cod); - m.set_handler (DLG_SELECT, mask_select); - m.set_handler (F_ANNULLA, mask_annulla); - m.set_handler (F_VERIFICA, mask_verifica); - - KEY tasto; - - _stampa_width = 132; - set_real_picture("###.###.###.###"); - - tasto = m.run(); - - // m.first_focus(tasto); - - return tasto == K_ENTER; -} - -int CG4400_application::stampa_intestazione_ditta() -{ - TDati_ditta tditta(get_firm(), _stampa_width); - TString riga (tditta.prima_riga()); - int r=1; - - set_header (r, "%s", (const char *) riga); - r++; - - riga = tditta.seconda_riga(); - - set_header (r, "%s", (const char*) riga); - r++; - - return r; -} - -void CG4400_application::preprocess_header() -{ - int r=1; - TString cor, nd1, nd2; - TString riga(_stampa_width); - TString data; - - if (_tipo_stampa != 3) //cioe' si tratta di una stampa definitiva - { - if ( (_tipo_stampa == 1) || (_tipo_stampa == 4) ) - data.format("%s %s %d", (const char*)"mese di", itom(_datareg.month()), - _datareg.year()); - else data.format("%s %s %d", (const char*)"mese di", itom(_fino_a_mese), _annoes); - } -else - data = _data_da.string(); - - reset_header(); - - if (_tipo_stampa == 2) - { - if (_stampa_ind_ditta) - r = stampa_intestazione_ditta(); - long num = _u_stampata + 1; - set_header(r++, "@94gProgr.Studio %ld@114gProgr.Utente @#", num); - } - else - r = stampa_intestazione_ditta(); - 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); - r++; - - riga.fill('-'); - set_header(r, riga); - r++; - if (_tipo_reg == 1) //registro vendite - { - cor = "R"; - nd1 = ""; - nd2 = ""; - } - if (_tipo_reg == 2) - { - cor = "C"; - nd1 = "N"; - nd2 = "D"; - } - if (_tipo_stampa == 3) //stampa di prova - { - set_header(r,"@10gNum.@19gDocumento@68gT Tipo@103gCod %s@121g@124gT@128gNum", (const char*) nd1); - r++; - set_header(r, "Data reg. prot.@17gData@25gNumero Codice Ragione sociale/descrizione@68gO Doc.@76gTotale doc.@91gImponibile Iva %s@112gImposta@124g%s@128gReg", (const char*) nd2, (const char*) cor); - r++; - } - else - { - set_header(r,"@10gNum.@19gDocumento@68gT Tipo@103gCod %s@121g@124gT", (const char*) nd1); - 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 %s@112gImposta@124g%s", - (const char*) nd2, (const char*) cor); - if (_tipo_stampa == 4) - set_header(r, "@128gop."); - r++; - } - riga.fill('-'); - set_header(r, riga); -} - -int cg4400 (int argc, char * argv[]) -{ - CG4400_application a; - a.run(argc, argv, "Stampa registri IVA"); - return 0; -} - - - - - - - - - - - - - - +// cg4400.cpp +// Stampa tabella registri +#include "cg4.h" +#include "cg4400.h" +#include "cg4400a.h" + +static TString256 TMP; + +inline CG4400_application& app() { return (CG4400_application&)main_app(); } + +bool filter_func (const TRelation * r) +{ + TLocalisamfile & mov = r->lfile(LF_MOV); + TString codreg = mov.get(MOV_REG); + TDate datareg = mov.get_date(MOV_DATAREG); + int annoiva = mov.get_int(MOV_ANNOIVA); + + 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; + + 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(const TObject** o1, const TObject** o2) +{ + TRigaiva* r1 = (TRigaiva*)*o1; + TRigaiva* r2 = (TRigaiva*)*o2; + TString campo1; + TString campo2; + + campo1.format("%d%4s", r1->_tipodet, (const char*)r1->_codiva); + campo2.format("%d%4s", r2->_tipodet, (const char*)r2->_codiva); + return (strcmp((const char*)campo1, (const char*)campo2)); +} + +/* + bool CG4400_application::libro_giornale_iva_unico() + { + TConfig conf(CONFIG_DITTA); + + return conf.get("StLgiU") == "X"; + } + */ + +bool mask_select (TMask_field& f, KEY k) +{ + long j, cnt, chk; int i; + TString from = f.mask().get(DA_CODICE); + TString to = f.mask().get(A_CODICE); + TBit_array selected = app()._selected; + + // build sheet + if (k == K_SPACE) + { + f.mask().field(DA_CODICE).set(""); + f.mask().field(A_CODICE).set(""); + app()._ditte->destroy(); chk = 0l; + for (i = 0; i < app()._nomiditte.items(); i++) + { + if (app()._selected[i]) continue; + TToken_string d = (const char*)((TToken_string&)app()._nomiditte[i]); + TString cod = d.get(1); + app()._ditte->add(d); + + if (!from.empty() || !to.empty()) + { + if (from.empty()) from = "0"; + if (to.empty()) to = "999999"; + if (atol(cod) >= atol(from) && atol(cod) <= atol(to)) + { + selected.set(chk++); + app()._ditte->check(chk++); + } + } + } + // seleziona e aggiungi alle gia' selezionate + if (app()._ditte->run() == K_ENTER) + { + cnt = 0; + for (j = 0l; j < app()._n_ditte; j++) + { + if (app()._selected[j]) continue; + if (app()._ditte->checked(cnt++)) + selected.set(j); + } + app()._selected |= selected; + selected.reset(); + } + long numd = app()._selected.ones(); + f.mask().set(F_SELECT,numd); + } + return TRUE; +} + +bool mask_verifica (TMask_field& f, KEY k) +{ + int i; + + if (k == K_SPACE) + { + app()._ditte->destroy(); + for (i = 0; i < app()._nomiditte.items(); i++) + { + TToken_string d = (const char*)((TToken_string&)app()._nomiditte[i]); + app()._ditte->add(d); + if (app()._selected[i]) app()._ditte->check(i); + } + app()._ditte->disable_check(); + app()._ditte->run(); + app()._ditte->enable_check(); + } + return TRUE; +} + +bool mask_annulla (TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + app()._selected.reset(); + f.mask().set(F_SELECT, "0"); + } + return TRUE; +} + +bool mask_from_to (TMask_field& f, KEY k) +{ + if (k == K_TAB) + { + app()._selected.reset(); + TString from, to; + const short id = f.dlg(); + from = f.mask().get(id-1); + to = f.mask().get(id); + int i; + if (!from.empty() || !to.empty()) + { + long chk = 0l; + if (from.empty()) from = "0"; + if (to.empty()) to = "999999"; + + for (i = 0; i < app()._nomiditte.items(); i++) + { + TToken_string d = (const char*)((TToken_string&)app()._nomiditte[i]); + TString cod = d.get(1); + + if (atol(cod) >= atol(from) && atol(cod)<= atol(to)) + app()._selected.set(chk++); + } + } + } + return TRUE; +} + +bool mask_mese (TMask_field& f, KEY k) +{ + if (k == K_ENTER) + { + int mese = f.mask().get_int(MESE); + int umese = f.mask().get_int(ULTIMO_MESE); + + if (mese != umese+1) + { + f.warning_box ("Le stampe devono essere richieste mese per mese! I mesi successivi a %s non sono ancora stati stampati.", itom(umese)); + return FALSE; + } + } + return TRUE; +} + +bool mask_cod (TMask_field& f, KEY k) +{ + TTable TabLbu ("%LBU"); + TString codtab; + int anno; + + //if ( (k == K_TAB) && f.mask().is_running() ) + if ( (k == K_SPACE)||(k == K_TAB) ) + { + 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(MESE,TabLbu.get_long("I0")+1); + f.mask().set(ULTIMO_MESE,TabLbu.get_long("I0")); + f.mask().set(ULTIMA_PAGINA,TabLbu.get_long("I1")); + } + } + return TRUE; +} + +bool mask_data (TMask_field& f, KEY k) +{ + const short id = f.dlg(); + + if (k == K_ENTER) + { + int anno = f.mask().get_int(ANNO); + TDate data = f.mask().get(id); + if (data.ok()) + if (data.year() != anno) + { + f.warning_box("L'anno delle date limite deve essere uguale all'anno iva specificato"); + return FALSE; + } + } + return TRUE; +} + +/* + bool mask_fino_a_mese (TMask_field& f, KEY k) + { + if (k == K_ENTER) + { + TTable TabReg ("REG"); + TString16 codtab; + int giorni_del_mese; + TString codreg = f.mask().get(CODICE_LIBRO); + int tipo = f.mask().get_int(TIPO_STAMPA); + int anno = f.mask().get_int(ANNO); + + if ( (tipo == 1) || (tipo == 4) ) + { + int fino_a_mese = f.mask().get_int(FINO_A_MESE); + if (fino_a_mese == 12) + giorni_del_mese = 31; + else + { + TDate primo = format("01/%02d/%4d", fino_a_mese+1, anno); + --primo; + giorni_del_mese = primo.day(); + } + TDate datasup = format("%02d/%02d/%4d",giorni_del_mese,fino_a_mese,anno); + if (codreg != "") + { + TabReg.zero(); + codtab << anno << codreg; + TabReg.put ("CODTAB", codtab); + TabReg.read(); + if ( TabReg.good() ) + { + TDate data = TabReg.get_date("D3"); + if (datasup < data) + { + TString16 datas = format("%02d/%4d", data.month(), data.year()); + f.warning_box ("La data specificata non deve essere inferiore al %s (ultima data di stampa specificata sul registro)", (const char*)datas); + return FALSE; + } + } + } + if (tipo == 4) + { + TabReg.zero(); + TabReg.put ("CODTAB", anno); + 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 (datasup > data) + { + TString16 datas = format("%02d/%4d", data.month(), data.year()); + f.warning_box ("La data specificata non deve essere superiore al %s (ultima data di stampa del libro giornale)", (const char*)datas); + return FALSE; + } + } + } + } + } + } + return TRUE; + } + */ + +//da una SHEET non e' possibile mandare messaggi nella maschera!!! +HIDDEN bool my_handler (TMask_field& f, KEY k) +{ + if (k == K_TAB) + { + TMask& m = f.mask(); + int stampa_su = m.get_int(TIPO_STAMPA); + if ( (stampa_su == 1) || (stampa_su == 4) ) + { + m.hide (CODICE_LIB_UN); + m.hide (CODICE_LIBRO_PROVA); + m.hide (MESE); + m.hide (ULTIMO_MESE); + m.hide (ULTIMA_PAGINA); + m.hide (CODICE_LIBRO_IVA); + m.hide (DATA_STAMPA); + m.hide (DA_DATA); + m.hide (A_DATA); + m.show (CODICE_LIBRO); + m.show (TIPO_RIEPILOGATIVO); + m.show (FINO_A_MESE); + } + if (stampa_su == 2) + { + m.show (CODICE_LIB_UN); + m.hide (CODICE_LIBRO_PROVA); + m.show (MESE); + m.show (ULTIMO_MESE); + m.show (ULTIMA_PAGINA); + m.show (CODICE_LIBRO_IVA); + m.hide (DATA_STAMPA); + m.hide (DA_DATA); + m.hide (A_DATA); + m.hide (CODICE_LIBRO); + m.hide (TIPO_RIEPILOGATIVO); + m.hide (FINO_A_MESE); + } + if (stampa_su == 3) + { + m.hide (CODICE_LIB_UN); + m.hide (MESE); + m.hide (ULTIMO_MESE); + m.hide (ULTIMA_PAGINA); + m.hide (CODICE_LIBRO_IVA); + m.hide (CODICE_LIBRO); + m.show (CODICE_LIBRO_PROVA); + m.show (DATA_STAMPA); + m.show (DA_DATA); + m.show (A_DATA); + m.hide (TIPO_RIEPILOGATIVO); + m.hide (FINO_A_MESE); + } + } + return TRUE; +} + +const char * CG4400_application::descr_doc(const char * tipo) +{ + TTable tab_tpd("%TPD"); + TString codtab = format ("%-2s", tipo); + + 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::desc_attivita(const char * codatt) +{ + TTable attiv ("%AIS"); + + attiv.zero(); + attiv.put("CODTAB", codatt); + if (attiv.read()==NOERR) + TMP = attiv.get("S0"); + else + TMP = ""; + return TMP; +} + +const char * CG4400_application::ricerca_cf(char tipocf, long codcf) +{ + _clifo->zero(); + _clifo->put(CLI_TIPOCF, tipocf); + _clifo->put(CLI_CODCF, codcf); + if (_clifo->read() == NOERR) + TMP = _clifo->get(CLI_RAGSOC); + else + TMP = ""; + return TMP; +} + +const char * CG4400_application::ricerca_occ(const char * occ) +{ + TLocalisamfile occas (LF_OCCAS); + + occas.zero(); + occas.put(OCC_CFPI, occ); + + if (occas.read() == NOERR) + TMP = occas.get(OCC_RAGSOC); + else + TMP = ""; + return TMP; +} + +void CG4400_application::user_create() +{ + _nditte = new TLocalisamfile(LF_NDITTE); + _ditte = new TArray_sheet(-1, -1, 0, 0, "Selezione Ditte", + "@1|Cod.@5|Ragione Sociale@50"); + _n_ditte = 0l; + for (_nditte->first(); !_nditte->eof(); _nditte->next()) + { + TString cod = _nditte->get("CODDITTA"); + _n_ditte++; + TToken_string* d = new TToken_string(" "); + d->add(cod); + d->add(_nditte->get("RAGSOC")); + _nomiditte.add(d); + } + _tab = new TLocalisamfile(LF_TAB); + _tabcom = new TLocalisamfile(LF_TABCOM); + _tabreg = new TTable("REG"); + _tablbu = new TTable("%LBU"); + _tabinl = new TTable("%INL"); + _tablim = new TTable("LIM"); + _tabpim = new TTable("PIM"); + _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, "", 1); + //_cur->set_filterfunction(filter_func); + + add_cursor(_cur); + add_file(LF_MOV); + add_file(LF_RMOVIVA); +} + +void CG4400_application::user_destroy() +{ + delete _ditte; + delete _nditte; + delete _tab; + delete _tabcom; + delete _cur; + delete _rel; + delete _clifo; +} + + +void CG4400_application::calcola_progressivi(real& r0, real& r1, const char* codiva, const int tipocr) +{ + TTable pim ("PIM"); + TString chiave; + int i, num=0; + + if (_tipo_stampa == 1) + num = _datareg.month(); + if ( (_tipo_stampa == 2) || (_tipo_stampa == 4) ) + num = _fino_a_mese; + + if (_frequiva == 'T') + for (i=3; isave_status(); + bool ok = _cur->is_first_match(LF_RMOVIVA); + int nrec = 0; + + while (ok) + { + nrec++; + TRectype iva (_cur->file(LF_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); + + impop = imposp = 0.00; + _riga_rmi.add_riga(impo,impos,codiva,tipodet,impop,imposp); + + if (_tipo_reg == 2) //registro acquisti + { + if (_tipo_stampa != 3) //stampa definitiva + calcola_progressivi(impop,imposp,codiva,tipocr); + _iva_array.add_riga(impo,impos,codiva,tipodet,impop,imposp); + } + + impop = imposp = 0.00; + if (_tipo_stampa != 3) + calcola_progressivi(impop,imposp,codiva,tipocr); + + _tot_iva_array.add_riga(impo,impos,codiva,impop,imposp); + + ok = _cur->next_match(LF_RMOVIVA); + } + _cur->restore_status(); + + 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 != 3) + { + 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"); + TString16 mesi_ric = ""; + TString16 mesi_cal = ""; + TString16 chiave = ""; + int i; + + if (lim.empty()) + return yesno_box("Non esiste la tabella liquidazione iva mensile! Vuoi ugualmente continuare la stampa?"); + if (pim.empty()) + return yesno_box("Non esiste la tabella progressivi iva mensile! Vuoi ugualmente continuare la stampa?"); + + if (_frequiva == 'T') //nella tabella LIM ho solo i mesi 3, 6, 9, 12 + { + for (i=3; i<=_fino_a_mese+3; i+=3) + { + chiave = ""; + chiave << _annoes << i; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + bool calcolato = lim.get_bool("B0"); + if (!calcolato) + + // return yesno_box("La liquidazione relativa al mese di %s deve essere ricalcolata. Vuoi ugualmente continuare la stampa?", itom(i) ); + mesi_ric << itom(i) << "\n\r"; + } + else + // return yesno_box("La liquidazione relativa al mese di %s non e' stata calcolata. Vuoi ugualmente continuare la stampa?", itom(i) ); + mesi_cal << itom(i) << "\n\r"; + } + } + if (_frequiva == 'M') + { + for (i=1; i<=_fino_a_mese; i++); + { + chiave = ""; + chiave << _annoes << i; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + bool calcolato = lim.get_bool("B0"); + if (!calcolato) + // return yesno_box("La liquidazione relativa al mese di %s deve essere ricalcolata. Vuoi ugualmente continuare la stampa?", itom(i) ); + mesi_ric << itom(i) << "\n\r"; + } + else + // return yesno_box("La liquidazione relativa al mese di %s non e' stata calcolata. Vuoi ugualmente continuare la stampa?", itom(i) ); + mesi_cal << itom(i) << "\n\r"; + } + } + if (mesi_ric.not_empty()) + { + warning_box ("Deve essere ricalcolata la liquidazione relativa ai mesi di:\n %s ", (const char *)mesi_ric); + return yesno_box("Vuoi ugualmente continuare la stampa?"); + } + + if (mesi_cal.not_empty()) + { + warning_box ("La liquidazione relativa al mese di %s non e' stata calcolata", (const char *)mesi_cal); + return yesno_box("Vuoi ugualmente continuare la stampa?"); + } + return TRUE; +} + +//controlla che i movimenti con data di registrazione compresa tra l'anno precedente e l'ultima data stampata siano tutti gia' stati stampati in forma definitiva*/ +bool CG4400_application::controlla_mov() +{ + TLocalisamfile mov (LF_MOV); + bool ok = TRUE; + byte tipo; + TDate udata; + TDate data = format("01/01/%4d", _annoes - 1); + TRecnotype rec = _tabreg->recno(); + for (mov.first(); !mov.eof(); mov.next()) + { + TString16 reg = mov.get(MOV_REG); + TDate datareg = mov.get_date(MOV_DATAREG); + if (_stampa_tutti_i_registri) + cerca_reg (reg, tipo, udata); + else udata = _data_da; + if ( (_stampa_tutti_i_registri && ((tipo == 1)||(tipo == 2))) + || ((!_stampa_tutti_i_registri)&&(reg == _codreg)) ) + if ( (datareg >= data) && (datareg <= udata) ) + { + bool stampato = mov.get_bool(MOV_STAMPATO); + long numreg = mov.get_long(MOV_NUMREG); + if (!stampato) + { + warning_box("Il movimento con numero di registrazione %ld non e' ancora stato stampato in forma definitiva!", numreg); + ok = FALSE; + } + } + } + _tabreg->readat(rec); + return ok; +} + +void CG4400_application::cerca_reg(const TString& c, byte& t, TDate& d) +{ + TString16 cod = ""; + + cod << _annoes << c; + _tabreg->zero(); + _tabreg->put("CODTAB", cod); + if (_tabreg->read() == NOERR) + { + t = _tabreg->get_int ("I0"); + d = _tabreg->get_date("D3"); + } +} + +/* + bool CG4400_application::controlla_mov() + { + bool ok = TRUE; + + if (_stampa_tutti_i_registri) + { + TRecnotype rec = _tabreg->recno();//la first l'ho gia' fatta + for (; !_tabreg->eof(); _tabreg->next()) + { + TString codtab = _tabreg->get("CODTAB"); + int anno = atoi(codtab.mid(0,4)); + if (anno != _annoes) break; + + TDate data_da = _tabreg->get_date("D3"); + TString16 codreg = codtab.mid(4,3); + leggi_movimenti(data_da, codreg, ok); + } + _tabreg->readat(rec); + } + else + leggi_movimenti(_data_da, _codreg, ok); + + return ok; + } + + void CG4400_application::leggi_movimenti(const TDate& d, const TString& cod, bool& ok) + { + TLocalisamfile mov (LF_MOV); + bool stampato; + long numreg; + TString codreg; + + TDate data = format("01/01/%4d", _annoes - 1); + mov.zero(); + TRectype a (mov.curr()); + mov.put(MOV_DATAREG, data); + a.put (MOV_DATAREG, d); + mov.read(_isgteq); + while (mov.curr() < a && !mov.eof()) + { + stampato = mov.get_bool(MOV_STAMPATO); + numreg = mov.get_long(MOV_NUMREG); + codreg = mov.get(MOV_REG); + if (codreg == cod) + if (!stampato) + { + warning_box("Il movimento con numero di registrazione %ld non e' ancora stato stampato in forma definitiva!", numreg); + ok = FALSE; + } + mov.next(); + } + } + */ + +void CG4400_application::set_page_tot_reg() +{ + reset_print(); + TString riga(_stampa_width); + int r=1, rr=0, row=0; + real tot_imponib, tot_imposta, tot_imponibp, tot_impostap; + + 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"); + set_row(r, "@78g3=operazione intracomunitaria e AF art.34 comma 3"); + r++; + 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 (_nrec > 0) //numero records di rmoviva + { + set_row(++rr, "@26g---------- P E R I O D O ----------"); + if (_tipo_stampa != 3) + 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 != 3) + set_row(rr, "@92gA C Q U I S T I"); + } + if (_tipo_reg == 1) + { + set_row(rr, "@37gV E N D I T E"); + if (_tipo_stampa != 3) + set_row(rr, "@93gV E N D I T E"); + } + rr++; + set_row(rr, "iva Descrizione@30gImponibile@49gImposta"); + if (_tipo_stampa != 3) + set_row(rr++, "@86gImponibile@106gImposta"); + else rr++; + rr++; + tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; + + _tot_iva_array.sort(compare_rows); + + for (int k = 0; k < _tot_iva_array.items(); k++) + { + TRiga& riga = (TRiga&)_tot_iva_array[k]; + row = rr+k; + set_row(row, "%3s", (const char*)riga._codiva); + TString descr = descr_iva(riga._codiva); + set_row(row, "@5g%s", (const char*)descr); + set_row(row, "@25g%r", &riga._imponibile); + set_row(row, "@41g%r", &riga._imposta); + if (_tipo_stampa != 3) + { + set_row(row, "@81g%r", &riga._imponibilep); + set_row(row, "@98g%r", &riga._impostap); + } + tot_imponib += riga._imponibile; + tot_imposta += riga._imposta; + tot_imponibp += riga._imponibilep; + tot_impostap += riga._impostap; + } + _tot_iva_array.destroy(); + row++; + set_row(++row, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); + if (_tipo_stampa != 3) + set_row(row, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); + //la stampa "tipi di indetraibilita'" viene fatta solo per gli acquisti + if (_tipo_reg == 2) + { + row+=2; + int tdetprec = -1; + int rw = row; + tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; + + _iva_array.sort(compare); + 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 != 3) + 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 != 3) + 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 != 3) + 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 != 3) + 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 != 3) + 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 (tdetprec == 9) + { + set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); + if (_tipo_stampa != 3) + set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); + } + _iva_array.destroy(); + } + } +} + +bool CG4400_application::compila_reg(const TMask& m) +{ + int anno; + long codditta = _nditte->get_long("CODDITTA"); + TString16 codtab = ""; + + _tipo_stampa = m.get_int(TIPO_STAMPA); + if (_tipo_stampa == 2) //stampa su libro unico di studio + _codreg = m.get(CODICE_LIBRO_IVA); + else if (_tipo_stampa == 3) //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) + { + 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"); + _pagine_stampate = _tabreg->get_int("I1"); + //_pagine_numerate = tab_reg.get_int("I2"); + //_stampa_ok = tab_reg.get_int("I7"); + //_nprog_da = tab_reg.get_long ("I6"); + //_tot_dare = tab_reg.get_real ("R1") + //_tot_avere = tab_reg.get_real ("R2"); + if (_tipo_stampa != 3) + _data_da = _tabreg->get_date ("D3"); + if ( _tipo_stampa == 1 || _tipo_stampa == 4 ) + if ( _data_a < _data_da) + { + TString16 datas = format("%02d/%4d", _data_da.month(), _data_da.year()); + warning_box ("La data specificata non deve essere inferiore al %s (ultima data di stampa specificata sul registro)", (const char*)datas); + return FALSE; + } + //_stampa_intesta = _tabreg->get_bool ("B9"); + _codatt = _tabreg->get("S8"); + _attivita = desc_attivita(_codatt); + _desc_lib = _tabreg->get ("S0"); + } + else + { + warning_box("Il registro IVA specificato non esiste nella \n Ditta %ld", codditta); + return FALSE; + } + } + + if (_tipo_stampa == 4) + { + TString app(4); + _tabreg->zero(); + app = format("%04d", _annoes); + _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) + { + TString16 datas = format("%02d/%4d", data.month(), data.year()); + warning_box ("La data specificata non deve essere superiore al %s (ultima data di stampa del libro giornale)", (const char*)datas); + 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) + { + _iva_array.destroy(); + _riga_rmi.destroy(); + _tot_iva_array.destroy(); + _doc_array.destroy(); + _dataregp = ""; + _mov_empty = TRUE; + _primast = _u_stampata; + set_print_zero(); + } + return TRUE; +} + +bool CG4400_application::preprocess_page(int file, int counter) +{ + if (file == LF_MOV) + { + if (counter) return TRUE; + int rr = 0; + TString ragsoc; + TString tipo_op = ""; + + TLocalisamfile& mov = _cur->file(LF_MOV); + TLocalisamfile& caus = _cur->file(LF_CAUSALI); + + //long annoes = mov->get_long(MOV_ANNOES); + //TString16 codreg = mov->get(MOV_REG); + _datareg = mov.get_date(MOV_DATAREG); + + //if (codreg != _codreg || annoes != _annoes) + // return FALSE; + + //if (_data_da.string() != "" && _data_a.string() != "") + // if ( (_datareg < _data_da || _datareg > _data_a) || (!_datareg.ok()) ) + // return FALSE; + + _mov_empty = FALSE; + + //if ( (_tipo_stampa == 1) || (_tipo_stampa == 4) ) + if ( (_datareg.month() != _dataregp.month()) && (_dataregp.ok()) ) + { + if (_tipo_stampa == 2) + ++ _u_stampata; + 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); + real totdoc = mov.get_real(MOV_TOTDOC); + TString numdoc = mov.get(MOV_NUMDOC); + char tipocf = mov.get(MOV_TIPO)[0]; + TString 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_STAMPATO); + bool intra = caus.get_bool(CAU_INTRACOM); + bool autof = caus.get_bool(CAU_AUTOFATT); + TString descrcau = caus.get(CAU_DESCR); + + //aggiornamento di mov + if (_tipo_stampa != 3) + if (!stampato) + { + mov.put(MOV_STAMPATO,TRUE); + mov.rewrite(); + } + + if ( intra && autof) + tipo_op = "3"; + else if (intra) + tipo_op = "1"; + else if (autof) + tipo_op = "2"; + + if ( (tipocf == 'C') || (tipocf == 'F') ) + { + if (ocfpi.trim().empty()) + ragsoc = ricerca_cf(tipocf, codcf); + else + ragsoc = ricerca_occ(ocfpi); + } + else ragsoc = descrcau; + + _tipodoc = mov.get(MOV_TIPODOC); + _descr_doc = descr_doc(_tipodoc); + TString app = datadoc.string(2, '/'); + + _doc_array.add_riga(_tipodoc,_descr_doc,totdoc); + + //setto le righe di stampa + _r = 1; + set_row(_r, "%s", (const char*) _datareg.string(2, '/')); + set_row(_r, "@9g%5d", protiva); + set_row(_r, "@15g%s", (const char*) app); + set_row(_r, "@24g%s", (const char*) numdoc); + set_row(_r, "@32g%6d", 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); + set_row(_r, "@72g%r", &totdoc); + + _nrec = riga_rmoviva(); + if (_nrec > 0) + { + for (int j = 0; j < _riga_rmi.items(); j++) + { + TRigaiva& riga = (TRigaiva&)_riga_rmi[j]; + rr = _r+j; + 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); + } + _riga_rmi.destroy(); + int tipocr = _cur->file(LF_RMOVIVA).get_int(RMI_TIPOCR); + set_row(_r, "@124g%d", tipocr); + } + //int tipocr = _cur->file(LF_RMOVIVA)->get_int(RMI_TIPOCR); + //set_row(_r, "@124g%d", tipocr); + if (_tipo_stampa == 3) //stampa di prova + { + set_row(_r, "@125g%6d", numreg); + if (stampato) + set_row(_r, "@131g*"); + } + if (_tipo_stampa == 4) //stampa con riferimento al libro giornale + set_row(_r, "@125g%ld", numgio); + } + return TRUE; +} + +void CG4400_application::aggiorna_reg() +{ + TString16 codtab; + TTable Tabreg ("REG"); + TTable TabInl ("%INL"); + 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) + { + //stampate = ultimast + 1; + if (!_mov_empty) //cioe' se e' stata stampata almeno una pagina + { + pag = _pagine_stampate + ultimast; + Tabreg.put("I1", pag); + } + Tabreg.put("D3", _data_a); + Tabreg.rewrite(); + } + if (_tipo_stampa == 2) //stampa su libro unico + //sulla tabella %inl (indice libro unico) devo generare una riga per ogni registro stampato + if (!_mov_empty) + { + 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; + + trovato = TRUE; + recprec = TabInl.curr(); + } + + TString cod = ""; + if (trovato) + { + 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 + { + TString16 num_riga ( format("%6d", 1L) ); + cod << codtab << num_riga; + } + + long numini = _pagine_stampate + 1; + nuovo.put("CODTAB", cod); + nuovo.put("I0", (long)_annoes); + nuovo.put("I1", (long)_fino_a_mese); + nuovo.put("I2", (long)(_primast + 1)); + nuovo.put("I3", (long)(_primast + ultimast)); + nuovo.put("I4", get_firm()); + nuovo.put("S0", _codreg); + nuovo.put("I5", (long)numini); + nuovo.put("I6", (long)(numini + ultimast - 1)); + + if (trovato) + TabInl.rewrite(nuovo); + else + TabInl.write(nuovo); + + _u_stampata += ultimast; + } +} + +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(); + } +} + +print_action CG4400_application::postprocess_page (int file, int counter) +{ + if (file == LF_MOV) + if (!counter) + { + bool FINITO = FALSE; + TRecnotype pos = _cur->pos(); + long items = _cur->items(); + + FINITO = (pos == items-1); + + if ( FINITO ) + { + set_page_tot_reg(); + return REPEAT_PAGE; + } + else //if ( (_tipo_stampa == 1) || (_tipo_stampa == 4) ) + { + 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()) + { + set_page_tot_reg(); + return REPEAT_PAGE; + } + } + } + return NEXT_PAGE; +} + +print_action CG4400_application::postprocess_print(int file, int counter) +{ + if (file == LF_MOV) + { + //aggiorna registri solo se non e' stampa di prova + if ( (_tipo_stampa != 3) && (!_stampa_tutti_i_registri) ) + aggiorna_reg(); + if (_stampa_tutti_i_registri) + //if (!_mov_empty ) + { + if (_tipo_stampa == 2) + ++ _u_stampata; + printer().formfeed(); + } + /* + if (_stampa_tutti_i_registri) + { + TString16 codtab; + int anno, tipo; + //vado avanti dal punto in cui sono + _tabreg->next(); + for (; !_tabreg->eof(); _tabreg->next()) + { + tipo = _tabreg->get_int("I0"); + if ( (tipo == 1) || (tipo == 2) ) //registro iva + { + codtab = _tabreg->get("CODTAB"); + anno = atoi(codtab.mid(0,4)); + break; + } + } + if ( (_tabreg->eof()) || (anno != _annoes) ) + { + if (_tipo_stampa == 2) //stampa su libro unico + aggiorna_lib(); + return NEXT_PAGE; + } + else + { + _tipo_reg = _tabreg->get_int("I0"); + _desc_lib = _tabreg->get("S0"); + _data_da = _tabreg->get_date("D3"); + _pagine_stampate = _tabreg->get_int("I1"); + _codreg = codtab.mid(4,3); + _primast = get_page_number(); + if (!_mov_empty ) + printer().formfeed(); + _cur->set_filterfunction(NULL); + _cur->set_filterfunction(filter_func); + _mov_empty = TRUE; + return REPEAT_PAGE; + } + } + */ + } + + return NEXT_PAGE; +} + +bool CG4400_application::set_print(int n) +{ + TMask m("cg4400a"); + int giorni_del_mese; + + if (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); + //Se stampa di prova l'utente indica data_da e data_a + if (_tipo_stampa == 3) + { + _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); + printer().setdate(_data_stampa); + } + // senno' data_da e' letta dal registro + else //stampe definitive + { + if ( (_tipo_stampa == 1) || (_tipo_stampa == 4) ) + _fino_a_mese = m.get_int(FINO_A_MESE); + 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); + //set_page_number(_u_stampata + 1); + } + if (_fino_a_mese == 12) + giorni_del_mese = 31; + else + { + 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); + // NB data_da viene letta nella preprocess_page + } + if (_tipo_stampa == 2) + compila_lib(); + stampa_registri_IVA(m); + } + else warning_box("Nessuna ditta selezionata!"); + return FALSE; +} + +void CG4400_application::stampa_registri_IVA(const TMask& m) +{ + long l; + long firm = TApplication::get_firm(); + bool ok = FALSE; + + for (l = 0l, _nditte->first(); !_nditte->eof(); l++, _nditte->next()) + { + if (_selected[l]) + { + TApplication::set_firm(_nditte->get_long("CODDITTA")); + ok = compila_reg(m); // cerca il primo registro valido (nel caso di stampa tutti i registri), senno' legge i dati del registro specificato + if (!ok) continue; + if (!_stampa_tutti_i_registri) + _cur->set_filterfunction(filter_func); + _frequiva = _nditte->get("FREQVIVA")[0]; + if (_tipo_stampa != 3) //stampa definitiva + ok = controlla_liquidazione() && controlla_mov(); + + if (!ok) continue; + + if (!_stampa_tutti_i_registri) + print(); + else + { + TString16 codtab; + int anno, tipo; + for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) + { + tipo = _tabreg->get_int("I0"); + codtab = _tabreg->get("CODTAB"); + anno = atoi(codtab.mid(0,4)); + if (anno > _annoes) + break; + if (anno == _annoes) + if ( (tipo == 1) || (tipo == 2) ) //registro iva + { + _tipo_reg = _tabreg->get_int("I0"); + _desc_lib = _tabreg->get("S0"); + if (_tipo_stampa != 3) + _data_da = _tabreg->get_date("D3"); + _pagine_stampate = _tabreg->get_int("I1"); + _codreg = codtab.mid(4,3); + _codatt = _tabreg->get("S8"); + _attivita = desc_attivita(_codatt); + _desc_lib = _tabreg->get ("S0"); + //_primast = get_page_number(); + //if (!_mov_empty ) + // printer().formfeed(); + _cur->set_filterfunction(NULL); + _cur->set_filterfunction(filter_func); + //set_page_number(_u_stampata + 1); + print(); + if (_tipo_stampa != 3) aggiorna_reg(); + } + } + } + if (_tipo_stampa == 2) + aggiorna_lib(); + } + } + + TApplication::set_firm(firm); +} + +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"); + + m.set_handler (TIPO_STAMPA, my_handler); + m.set_handler (A_CODICE, mask_from_to); + m.set_handler (DA_DATA, mask_data); + m.set_handler (A_DATA, mask_data); + m.set_handler (MESE, mask_mese); + m.set_handler (CODICE_LIB_UN, mask_cod); + m.set_handler (DLG_SELECT, mask_select); + m.set_handler (F_ANNULLA, mask_annulla); + m.set_handler (F_VERIFICA, mask_verifica); + + KEY tasto; + + _stampa_width = 132; + set_real_picture("###.###.###.###"); + + tasto = m.run(); + + // m.first_focus(tasto); + + return tasto == K_ENTER; +} + +int CG4400_application::stampa_intestazione_ditta() +{ + TDati_ditta tditta(get_firm(), _stampa_width); + TString riga (tditta.prima_riga()); + int r=1; + + set_header (r, "%s", (const char *) riga); + r++; + + riga = tditta.seconda_riga(); + + set_header (r, "%s", (const char*) riga); + r++; + + return r; +} + +void CG4400_application::preprocess_header() +{ + int r=1; + TString cor, nd1, nd2; + TString riga(_stampa_width); + TString data; + + if (_tipo_stampa != 3) //cioe' si tratta di una stampa definitiva + { + if ( (_tipo_stampa == 1) || (_tipo_stampa == 4) ) + data.format("%s %s %d", (const char*)"mese di", itom(_datareg.month()), + _datareg.year()); + else data.format("%s %s %d", (const char*)"mese di", itom(_fino_a_mese), _annoes); + } +else + data = _data_da.string(); + + reset_header(); + + if (_tipo_stampa == 2) + { + if (_stampa_ind_ditta) + r = stampa_intestazione_ditta(); + long num = _u_stampata + 1; + set_header(r++, "@94gProgr.Studio %ld@114gProgr.Utente @#", num); + } + else + r = stampa_intestazione_ditta(); + 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); + r++; + + riga.fill('-'); + set_header(r, riga); + r++; + if (_tipo_reg == 1) //registro vendite + { + cor = "R"; + nd1 = ""; + nd2 = ""; + } + if (_tipo_reg == 2) + { + cor = "C"; + nd1 = "N"; + nd2 = "D"; + } + if (_tipo_stampa == 3) //stampa di prova + { + set_header(r,"@10gNum.@19gDocumento@68gT Tipo@103gCod %s@121g@124gT@128gNum", (const char*) nd1); + r++; + set_header(r, "Data reg. prot.@17gData@25gNumero Codice Ragione sociale/descrizione@68gO Doc.@76gTotale doc.@91gImponibile Iva %s@112gImposta@124g%s@128gReg", (const char*) nd2, (const char*) cor); + r++; + } + else + { + set_header(r,"@10gNum.@19gDocumento@68gT Tipo@103gCod %s@121g@124gT", (const char*) nd1); + 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 %s@112gImposta@124g%s", + (const char*) nd2, (const char*) cor); + if (_tipo_stampa == 4) + set_header(r, "@128gop."); + r++; + } + riga.fill('-'); + 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/cg5100a.uml b/cg/cg5100a.uml index 196274dd7..b610cc54a 100755 --- a/cg/cg5100a.uml +++ b/cg/cg5100a.uml @@ -175,6 +175,7 @@ BEGIN DISPLAY "Descrizione@50" DESCR OUTPUT FLD_COCACH CODCAUS CHECKTYPE NORMAL + ADD RUN cg0 -4 FIELD CoCaCh END @@ -186,6 +187,7 @@ BEGIN INPUT CODCAUS FLD_COCAAP COPY DISPLAY FLD_COCACH OUTPUT FLD_COCAAP CODCAUS + ADD RUN cg0 -4 CHECKTYPE NORMAL FIELD CoCaAp END @@ -464,6 +466,7 @@ BEGIN INPUT CODCAUS FLD_RRCCRA COPY DISPLAY FLD_COCACH OUTPUT FLD_RRCCRA CODCAUS + ADD RUN cg0 -4 FIELD RrCcRa END @@ -475,6 +478,7 @@ BEGIN INPUT CODCAUS FLD_RRCCRI COPY DISPLAY FLD_COCACH OUTPUT FLD_RRCCRI CODCAUS + ADD RUN cg0 -4 FIELD RrCcRi END diff --git a/cg/cglib.h b/cg/cglib.h index f9f0ac797..cc1d43d0e 100755 --- a/cg/cglib.h +++ b/cg/cglib.h @@ -1,125 +1,125 @@ -#ifndef __CGLIB_H -#define __CGLIB_H - -#ifndef __ISAM_H -#include -#endif - -#ifndef __ASSOC_H -#include -#endif - -#include "conto.h" - -TLocalisamfile * get_descr_cf(TLocalisamfile * pconti, - TLocalisamfile * clifo , int g, int c, long s); - - class TClifo_list : public TArray -{ -public: - TClifo_list(int g, int c, char tipocf); - TRectype& clifo(int i)const { return(TRectype&)this->operator[](i); } -}; - -//typedef enum {scalare = 1, verifica} bilancio; - -class Saldo -{ - real _saldo, _saldo_iniziale, _prg_dare, _prg_avere; - int _indbil; - TRectype* _rec; - //bilancio _bilancio; - int _annoes; - TDate _inizioEs, _fineEs; - TString16 _codcaus; - TDate _datareg; - TDate _datacomp; - TString _provv; - -protected: - void InFinEs(int); - -public: - int annoes () const { return _annoes; } - //bilancio bil () const { return _bilancio; } - void set_annoes (int anno) { _annoes = anno; } - //void set_bil (bilancio bil) { _bilancio = bil; } - void leggi_mov(long); - bool causale_mov(long, const TDate&, const TDate&, TString&); - const char* causale_chiusura_es(); - const char* causale_apertura_es(); - bool calcola_data_limite(int,int,int,long,const TDate&,const TDate&,int,bool, - const TDate&,const TDate&,const TDate&,bool); - bool calcola_ultima_immissione(int, int, int, int, long, int); - bool ultima_immissione_bilancio(int anno,int g,int c,long s,int indbil); - bool data_limite_bilancio(int,int,int,long,const TDate&,const TDate&,int,bool); - real calcola_saldo_iniziale(int, int, int, long, int); - bool calcola_clifo(int, int, int, int, int); - TRectype& ricerca_progr_prec(int, int, int, long); - real saldofin_esprec(int,int,int,long); - real saldo() {return _saldo;} - real saldoini() {return _saldo_iniziale;} - real prgdare() {return _prg_dare;} - real prgavere() {return _prg_avere;} - bool calcola(int,int,int,int,long,const TDate&,const TDate&,int,bool, - const TDate&,const TDate&,const TDate&,bool); - 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 - TConto& tconti() { return *(TConto*)_tab_conti.get(); } - -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 - +#ifndef __CGLIB_H +#define __CGLIB_H + +#ifndef __ISAM_H +#include +#endif + +#ifndef __ASSOC_H +#include +#endif + +#include "conto.h" + +TLocalisamfile * get_descr_cf(TLocalisamfile * pconti, + TLocalisamfile * clifo , int g, int c, long s); + + class TClifo_list : public TArray +{ +public: + TClifo_list(int g, int c, char tipocf); + TRectype& clifo(int i)const { return(TRectype&)this->operator[](i); } +}; + +//typedef enum {scalare = 1, verifica} bilancio; + +class Saldo +{ + real _saldo, _saldo_iniziale, _prg_dare, _prg_avere; + int _indbil; + TRectype* _rec; + //bilancio _bilancio; + int _annoes; + TDate _inizioEs, _fineEs; + TString16 _codcaus; + TDate _datareg; + TDate _datacomp; + TString _provv; + +protected: + void InFinEs(int); + +public: + int annoes () const { return _annoes; } + //bilancio bil () const { return _bilancio; } + void set_annoes (int anno) { _annoes = anno; } + //void set_bil (bilancio bil) { _bilancio = bil; } + void leggi_mov(long); + bool causale_mov(long, const TDate&, const TDate&, TString&); + const char* causale_chiusura_es(); + const char* causale_apertura_es(); + bool calcola_data_limite(int,int,int,long,const TDate&,const TDate&,int,bool, + const TDate&,const TDate&,const TDate&,bool); + bool calcola_ultima_immissione(int, int, int, int, long, int); + bool ultima_immissione_bilancio(int anno,int g,int c,long s,int indbil); + bool data_limite_bilancio(int,int,int,long,const TDate&,const TDate&,int,bool); + real calcola_saldo_iniziale(int, int, int, long, int); + bool calcola_clifo(int, int, int, int, int); + TRectype& ricerca_progr_prec(int, int, int, long); + real saldofin_esprec(int,int,int,long); + real saldo() {return _saldo;} + real saldoini() {return _saldo_iniziale;} + real prgdare() {return _prg_dare;} + real prgavere() {return _prg_avere;} + bool calcola(int,int,int,int,long,const TDate&,const TDate&,int,bool, + const TDate&,const TDate&,const TDate&,bool); + 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 + TConto& tconti() { return *(TConto*)_tab_conti.get(); } + +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 +