diff --git a/ba/ba3200.cpp b/ba/ba3200.cpp index e1e31e27b..01c35935d 100755 --- a/ba/ba3200.cpp +++ b/ba/ba3200.cpp @@ -1,267 +1,267 @@ -// ba3200 Stampa tabelle -// -// legge un file con estensione .rpt che descrive la stampa. -// Vedi file leggimi.txt per il formato del file -// - -#include -#include -#include -#include -#include - -#include "ba3.h" -#include "ba3200.h" - -#define FOOTER_LEN 4 // se non ridefinito nel .rpt - -class BA3200_application : public TPrintapp -{ -// TTable* _tab; - TString _tabname; - TFilename _rptname; - TRelation* _rel; - TCursor *_cur; - TMask* _msk; - TString _maskname; -// TScanner *_rpt; - int _logicnum; - -public: - - virtual void user_create() ; - virtual void user_destroy() ; - virtual bool set_print(int) ; - - virtual void set_page(int, int); - - void leggi_rpt(); - void set_headers(); - void set_rows(); - void set_footers(); - void set_translations(); - BA3200_application(const char * tabname) : _tabname(tabname) {} - virtual ~BA3200_application() {} -}; - - -bool BA3200_application::set_print(int) -{ - TRectype from(_rel->lfile()->curr()); - TRectype to (_rel->lfile()->curr()); - - from.zero(); - to.zero(); - const KEY tasto = _msk->run(); - - if (tasto == K_ENTER) - { - const int campi_maschera = _msk->fields(); // - 2; Tolgo bottoni... - for (int i = 0; i < campi_maschera; i++) - { - const TMask_field& campo_maschera = _msk->fld(i); - const char* val = campo_maschera.get(); - const TFieldref* campo_ref = campo_maschera.field(); - if (*val && campo_ref != NULL && campo_ref->ok()) - { - if (campo_maschera.in_group(1)) campo_ref->write(val, from); else - if (campo_maschera.in_group(2)) campo_ref->write(val, to); - } - } - - _cur->filter ("", from.empty() ? NULL : &from, to.empty() ? NULL : &to); - return TRUE; - } - return FALSE; -} - -void BA3200_application::set_page (int , int ) -{ - leggi_rpt(); -} - -void BA3200_application::set_headers() -{ - TString NomeTabella, sep, formato_intesta, testo_intesta; - int LungRiga, riga_intesta=0, last_riga=1; - TToken_string line; - - reset_header (); - - TScanner rpt(_rptname); - rpt.paragraph("Headers"); - - // Leggo la lunghezza della riga (usata per centrare l'intestazione) - line = rpt.line(); - LungRiga = line.get_int(); - - // Leggo il nome della tabella - line = rpt.line(); - NomeTabella = line.get(); - - // Centro il nome della tabella e aggiungo il numero di pagina - NomeTabella.center_just (LungRiga); - NomeTabella.overwrite ("Pag. @#", NomeTabella.len()-8); - set_header (last_riga, "%s", (const char *)NomeTabella); - last_riga++; - - // Aggiungo una riga vuota per separare prima intestazione - sep.fill ('-', LungRiga); - set_header (last_riga, "%s", (const char *)sep); - - line = rpt.line(); - while ( (line != "") && (line[0] != '[') ) - { - riga_intesta = atoi (line.get()); - formato_intesta = line.get(); - testo_intesta = (const char *) line.get(); - if (riga_intesta) - set_header (last_riga+riga_intesta, (const char *)formato_intesta, - (const char *)testo_intesta); - line = rpt.line(); - } - - if (riga_intesta) last_riga += riga_intesta; - last_riga++; - set_header (last_riga, (const char *)sep); - last_riga++; - sep.fill(' '); - set_header (last_riga, (const char *)sep); -} - -void BA3200_application::set_rows() -{ - TToken_string line; - TFieldref campo; - int from, to, riga_record; - TString formato_campo, picture; - const char * name; - - TScanner rpt(_rptname); - rpt.paragraph("Rows"); - - line = rpt.line(); - while ( (line != "") && (line[0] != '[') ) - { - riga_record = line.get_int(); - - campo = line.get(); - from = campo.from(); - to = campo.to(); - name = campo.name(); - - formato_campo = line.get(); - formato_campo.trim(); - - if (formato_campo.lower() == "@pn") - picture = line.get(); - else - picture = ""; - - if (to == -1) - if (picture != "") - set_row (riga_record, formato_campo, FLD(_logicnum,name,picture) ); - else - set_row (riga_record, formato_campo, FLD(_logicnum,name) ); - else - set_row (riga_record, formato_campo, FLD(_logicnum,name,from,to) ); - - line = (const char *) rpt.line(); - } -} - -void BA3200_application::set_footers() -{ - TToken_string line; - int footer_len, riga; - TString formato, testo; - - reset_footer(); - - TScanner rpt(_rptname); - rpt.paragraph("Footers"); - - line = rpt.line(); - footer_len = line.get_int(); - if (footer_len) printer().footerlen (footer_len); - - line = rpt.line(); - while ( (line != "") && (line[0] != '[') ) - { - riga = line.get_int(); - formato = line.get(); - testo = line.get(); - set_footer (riga, (const char *)formato, (const char*)testo); - line = rpt.line(); - } -} - -void BA3200_application::set_translations() -{ - TString campo, from, to; - TToken_string line; - int logicnum; - - TScanner rpt(_rptname); - rpt.paragraph("Translations"); - - line = rpt.line(); - while ( (line != "") && (line[0] != '[') ) - { - logicnum = line.get_int(); - campo = line.get(); - from = line.get(); - to = line.get(); - set_translation (logicnum, (char*)(const char *)campo, (char*)(const char *)from, (char*)(const char *)to); - line = rpt.line(); - } -} - -void BA3200_application::leggi_rpt() -{ - set_rows(); -} - -void BA3200_application::user_create() -{ - _rptname << "batb" << _tabname << ".rpt" ; - if (!fexist(_rptname)) - fatal_box("Impossibile aprire il file '%s'", (const char*)_rptname); - - -// _tab = new TTable (_tabname); - _rel = new TRelation (_tabname); - _cur = new TCursor (_rel); - - _maskname << "bast" << _tabname; - _msk = new TMask (_maskname) ; - - add_cursor (_cur); - add_file (_tabname); - - _logicnum = _cur->file()->num(); - - reset_print (); - - printer().footerlen (FOOTER_LEN); - for (int i=1; i <= FOOTER_LEN; i++) set_footer(i, "%s", " "); - - set_headers(); - set_footers(); - set_translations(); -} - -void BA3200_application::user_destroy() -{ - delete _msk; - delete _cur; - delete _rel; -// delete _tab; -} - -int ba3200(int argc, char* argv[]) -{ - BA3200_application a(argv[2]) ; - a.run(argc, argv, "Tabella"); - return 0; -} +// ba3200 Stampa tabelle +// +// legge un file con estensione .rpt che descrive la stampa. +// Vedi file leggimi.txt per il formato del file +// + +#include +#include +#include +#include +#include + +#include "ba3.h" +#include "ba3200.h" + +#define FOOTER_LEN 4 // se non ridefinito nel .rpt + +class BA3200_application : public TPrintapp +{ + // TTable* _tab; + TString _tabname; + TFilename _rptname; + TRelation* _rel; + TCursor *_cur; + TMask* _msk; + TString _maskname; + // TScanner *_rpt; + int _logicnum; + +public: + + virtual void user_create() ; + virtual void user_destroy() ; + virtual bool set_print(int) ; + + virtual void set_page(int, int); + + void leggi_rpt(); + void set_headers(); + void set_rows(); + void set_footers(); + void set_translations(); + BA3200_application(const char * tabname) : _tabname(tabname) {} + virtual ~BA3200_application() {} +}; + + +bool BA3200_application::set_print(int) +{ + TRectype from(_rel->lfile()->curr()); + TRectype to (_rel->lfile()->curr()); + + from.zero(); + to.zero(); + const KEY tasto = _msk->run(); + + if (tasto == K_ENTER) + { + const int campi_maschera = _msk->fields(); // - 2; Tolgo bottoni... + for (int i = 0; i < campi_maschera; i++) + { + const TMask_field& campo_maschera = _msk->fld(i); + const char* val = campo_maschera.get(); + const TFieldref* campo_ref = campo_maschera.field(); + if (*val && campo_ref != NULL && campo_ref->ok()) + { + if (campo_maschera.in_group(1)) campo_ref->write(val, from); else + if (campo_maschera.in_group(2)) campo_ref->write(val, to); + } + } + + _cur->setregion (from, to); + return TRUE; + } + return FALSE; +} + +void BA3200_application::set_page (int , int ) +{ + leggi_rpt(); +} + +void BA3200_application::set_headers() +{ + TString NomeTabella, sep, formato_intesta, testo_intesta; + int LungRiga, riga_intesta=0, last_riga=1; + TToken_string line; + + reset_header (); + + TScanner rpt(_rptname); + rpt.paragraph("Headers"); + + // Leggo la lunghezza della riga (usata per centrare l'intestazione) + line = rpt.line(); + LungRiga = line.get_int(); + + // Leggo il nome della tabella + line = rpt.line(); + NomeTabella = line.get(); + + // Centro il nome della tabella e aggiungo il numero di pagina + NomeTabella.center_just (LungRiga); + NomeTabella.overwrite ("Pag. @#", NomeTabella.len()-8); + set_header (last_riga, "%s", (const char *)NomeTabella); + last_riga++; + + // Aggiungo una riga vuota per separare prima intestazione + sep.fill ('-', LungRiga); + set_header (last_riga, "%s", (const char *)sep); + + line = rpt.line(); + while ( (line != "") && (line[0] != '[') ) + { + riga_intesta = atoi (line.get()); + formato_intesta = line.get(); + testo_intesta = (const char *) line.get(); + if (riga_intesta) + set_header (last_riga+riga_intesta, (const char *)formato_intesta, + (const char *)testo_intesta); + line = rpt.line(); + } + + if (riga_intesta) last_riga += riga_intesta; + last_riga++; + set_header (last_riga, (const char *)sep); + last_riga++; + sep.fill(' '); + set_header (last_riga, (const char *)sep); +} + +void BA3200_application::set_rows() +{ + TToken_string line; + TFieldref campo; + int from, to, riga_record; + TString formato_campo, picture; + const char * name; + + TScanner rpt(_rptname); + rpt.paragraph("Rows"); + + line = rpt.line(); + while ( (line != "") && (line[0] != '[') ) + { + riga_record = line.get_int(); + + campo = line.get(); + from = campo.from(); + to = campo.to(); + name = campo.name(); + + formato_campo = line.get(); + formato_campo.trim(); + + if (formato_campo.lower() == "@pn") + picture = line.get(); + else + picture = ""; + + if (to == -1) + if (picture != "") + set_row (riga_record, formato_campo, FLD(_logicnum,name,picture) ); + else + set_row (riga_record, formato_campo, FLD(_logicnum,name) ); + else + set_row (riga_record, formato_campo, FLD(_logicnum,name,from,to) ); + + line = (const char *) rpt.line(); + } +} + +void BA3200_application::set_footers() +{ + TToken_string line; + int footer_len, riga; + TString formato, testo; + + reset_footer(); + + TScanner rpt(_rptname); + rpt.paragraph("Footers"); + + line = rpt.line(); + footer_len = line.get_int(); + if (footer_len) printer().footerlen (footer_len); + + line = rpt.line(); + while ( (line != "") && (line[0] != '[') ) + { + riga = line.get_int(); + formato = line.get(); + testo = line.get(); + set_footer (riga, (const char *)formato, (const char*)testo); + line = rpt.line(); + } +} + +void BA3200_application::set_translations() +{ + TString campo, from, to; + TToken_string line; + int logicnum; + + TScanner rpt(_rptname); + rpt.paragraph("Translations"); + + line = rpt.line(); + while ( (line != "") && (line[0] != '[') ) + { + logicnum = line.get_int(); + campo = line.get(); + from = line.get(); + to = line.get(); + set_translation (logicnum, (char*)(const char *)campo, (char*)(const char *)from, (char*)(const char *)to); + line = rpt.line(); + } +} + +void BA3200_application::leggi_rpt() +{ + set_rows(); +} + +void BA3200_application::user_create() +{ + _rptname << "batb" << _tabname << ".rpt" ; + if (!fexist(_rptname)) + fatal_box("Impossibile aprire il file '%s'", (const char*)_rptname); + + + // _tab = new TTable (_tabname); + _rel = new TRelation (_tabname); + _cur = new TCursor (_rel); + + _maskname << "bast" << _tabname; + _msk = new TMask (_maskname) ; + + add_cursor (_cur); + add_file (_tabname); + + _logicnum = _cur->file()->num(); + + reset_print (); + + printer().footerlen (FOOTER_LEN); + for (int i=1; i <= FOOTER_LEN; i++) set_footer(i, "%s", " "); + + set_headers(); + set_footers(); + set_translations(); +} + +void BA3200_application::user_destroy() +{ + delete _msk; + delete _cur; + delete _rel; + // delete _tab; +} + +int ba3200(int argc, char* argv[]) +{ + BA3200_application a(argv[2]) ; + a.run(argc, argv, "Tabella"); + return 0; +} diff --git a/ba/ba4200c.uml b/ba/ba4200c.uml index 077b6f412..1fa96acc9 100755 --- a/ba/ba4200c.uml +++ b/ba/ba4200c.uml @@ -43,7 +43,7 @@ BEGIN INPUT TIPOA "G" INPUT CODANAGR FLD_CODANAGR DISPLAY "Codice" CODANAGR - DISPLAY "Denominazione@50" RAGSOC + DISPLAY "Ragione sociale@50" RAGSOC DISPLAY "Codice Fiscale@16" COFI OUTPUT FLD_CODANAGR CODANAGR OUTPUT FLD_AG1_RAGSOC RAGSOC @@ -64,7 +64,7 @@ BEGIN INPUT TIPOA "G" CHECKTYPE REQUIRED INPUT RAGSOC FLD_AG1_RAGSOC - DISPLAY "Denominazione@50" RAGSOC + DISPLAY "Ragione sociale@50" RAGSOC DISPLAY "Codice" CODANAGR DISPLAY "Codice Fiscale " COFI COPY OUTPUT FLD_CODANAGR @@ -115,7 +115,7 @@ BEGIN INPUT TIPOA "G" INPUT COFI FLD_AG1_COFI DISPLAY "Codice Fiscale@16" COFI - DISPLAY "Denominazione@50" RAGSOC + DISPLAY "Ragione sociale@50" RAGSOC DISPLAY "Codice" CODANAGR COPY OUTPUT FLD_CODANAGR CHECKTYPE REQUIRED @@ -1071,7 +1071,7 @@ END STRING F_IMP_PROVCOM 5 BEGIN - PROMPT 64 6 "Prov." + PROMPT 62 6 "Prov." FLAGS "D" END @@ -1092,10 +1092,15 @@ BEGIN WARNING "Ufficio imposte assente" END -STRINF F_DENUFFIIDD 50 +STRINF F_DENUFFIIDD 50 48 BEGIN PROMPT 23 7 " " - FLAGS "D" + USE %UID KEY 2 + INPUT S0 F_DENUFFIIDD + DISPLAY "Denominazione@50" S0 + DISPLAY "Ufficio" CODTAB + DISPLAY "C.C.@8" S4 + COPY OUTPUT F_UFFIIDD END STRING F_CC_ESATTORIA 8 @@ -1115,7 +1120,7 @@ BEGIN FLAGS "UDG" END -STRING F_DENUFFREG 50 +STRING F_DENUFFREG 50 48 BEGIN PROMPT 24 9 "" FLAGS "D" @@ -1132,7 +1137,7 @@ BEGIN CHECKTYPE NORMAL END -STRING F_DENUFFCONC 50 +STRING F_DENUFFCONC 50 48 BEGIN PROMPT 24 10 "" FLAGS "D" @@ -1149,7 +1154,7 @@ BEGIN CHECKTYPE NORMAL END -STRING F_DENUFFSERV 50 +STRING F_DENUFFSERV 50 48 BEGIN PROMPT 24 11 "" FLAGS "D" diff --git a/ba/ba4300a.uml b/ba/ba4300a.uml index c9d20036c..4e7ec0a0b 100755 --- a/ba/ba4300a.uml +++ b/ba/ba4300a.uml @@ -309,7 +309,7 @@ STRING FLD_GD1_COMAA_COMUNI_DESCR 50 BEGIN PROMPT 8 12 ": Nome " USE LF_COMUNI KEY 2 SELECT STATO="" - INPUT COM FLD_GD1_COMAA_COMUNI_DESCR + INPUT DENCOM FLD_GD1_COMAA_COMUNI_DESCR #include OUTPUT FLD_GD1_COMAA COM OUTPUT FLD_GD1_COMAA_COMUNI_DESCR DENCOM diff --git a/ba/ba6100.cpp b/ba/ba6100.cpp index dedb83314..96d350fad 100755 --- a/ba/ba6100.cpp +++ b/ba/ba6100.cpp @@ -1,567 +1,566 @@ -// ********************************************************************** -// Stampa anagrafiche -// Control code -// *********************************************************************** - -#include "ba6100.h" -#include -#include -#include - -// ------- utils -------------------------------------------- - - -TRectype& BA6100_App::look_com(const char* cod) -{ - _comuni->curr().zero(); - if (*cod) - { - _comuni->curr().put("COM",cod); - _comuni->read(); - if (_comuni->bad()) - _comuni->curr().zero(); - } - return _comuni->curr(); -} - -const char* BA6100_App::look_tab(const char* tabname, const char* cod, - const char* fld) -{ - if (*cod == 0) return ""; - TTable tab(tabname); - tab.curr().zero(); - tab.curr().put("CODTAB",cod); - tab.read(); - if (tab.bad()) tab.curr().zero(); - return tab.curr().get(fld); -} - -// link - -void BA6100_App::process_link(int id, const char* txt) -{ - if (id == _ana_link) - { - TString ss = "1|"; ss << txt; - TMessage fs(cmd2name("ba4","-1"), MSG_LN, ss); - TMailbox m; - m.send(fs); - TExternal_app ba4(_pr_what == anafis ? "ba4 -1 F" : "ba4 -1 G"); - if (ba4.run()) beep(); - } - else if (id == _dit_link) - { - TString ss = "1|"; ss << txt << "|" << txt; - TMessage fs(cmd2name("ba4","-2"), MSG_LN, ss); - TMailbox m; - m.send(fs); - TExternal_app ba4("ba4 -2"); - if (ba4.run()) beep(); - } -} - -// ---- here we go ------------------------------------------------- - -void BA6100_App::set_page(int file, int cnt) -{ - switch(file) - { - case LF_ANAG: - case LF_NDITTE: - if (_pr_type == elenco) - { - if (_pr_what != nditte && file == LF_NDITTE) - { - set_row(1,"@50g$[r]@pN$[n]@66g@S", FLD(LF_NDITTE,"CODDITTA","@@@@@"), - FLD(LF_NDITTE,"RAGSOC")); - set_row(2,""); - } - else - set_elenco(); - } - else if (_pr_type == rubriche) set_rubriche(); - else if (_pr_type == schede) - { - if (_pr_what != nditte && file == LF_NDITTE) - set_scheda_ditta(); - else - set_schede(); - } - else if (_pr_type == etichette) set_etichette(); - break; - case LF_ATTIV: - set_scheda_attiv(); - break; - case LF_UNLOC: - set_scheda_unloc(); - break; - case LF_SOCI: - set_scheda_socio(); - break; - } -} - - -bool BA6100_App::preprocess_page(int file, int counter) -{ - // non stampa la prima ditta se sta facendo l'elenco visto - // che la stampa a fianco dell'anagrafica - if (file == LF_NDITTE && _pr_type == elenco && _inclditte - && _pr_what != nditte) - if (current_cursor()->is_first_match(LF_NDITTE)) - return FALSE; - - if (_pr_type == rubriche) - { - // vale per ditte, anagiu, anafis - _com = current_cursor()->curr(LF_ANAG).get("COMRES"); - if (_com.empty()) - _com = current_cursor()->curr(LF_ANAG).get("COMRF"); - _phone = current_cursor()->curr(LF_ANAG).get("PTELRF"); - _phone.trim(); - if (!_phone.empty()) _phone << '/'; - _phone << current_cursor()->curr(LF_ANAG).get("TELRF"); - - TRectype& cc = look_com(_com); - _com = cc.get("DENCOM"); - _cap = cc.get("CAPCOM"); - _prov = cc.get("PROVCOM"); - } - else if (_pr_type == etichette) - preprocess_etichette(); - return TRUE; -} - - -bool mask_reset_fields(TMask_field& mf, KEY k) -{ - if (k == K_SPACE) - { - BA6100_App* a = (BA6100_App*)MainApp(); - mf.mask().field(FLD_BA6B_INDROW).set(format("%d",a->_ind_row)); - mf.mask().field(FLD_BA6B_INDCOL).set(format("%d",a->_ind_col)); - mf.mask().field(FLD_BA6B_PIVROW).set(format("%d",a->_piv_row)); - mf.mask().field(FLD_BA6B_PIVCOL).set(format("%d",a->_piv_col)); - mf.mask().field(FLD_BA6B_CODROW).set(format("%d",a->_cod_row)); - mf.mask().field(FLD_BA6B_CODCOL).set(format("%d",a->_cod_col)); - mf.mask().field(FLD_BA6B_TOTROW).set(format("%d",a->_rows_et)); - mf.mask().field(FLD_BA6B_TOTCOL).set(format("%d",a->_cols_et)); - mf.mask().field(CHK_BA6B_PIVA).set(a->_is_piv ? "X" : " "); - mf.mask().field(CHK_BA6B_CODICE).set(a->_is_cod ?"X": " "); - } - return TRUE; -} - - -void BA6100_App::preprocess_etichette() -{ - // everything goes into strings - _name = get_field(LF_ANAG,"RAGSOC"); - _cod = get_field(LF_ANAG,"CODANAGR"); - _cofi = get_field(LF_ANAG,"COFI"); - TRectype& cc = look_com(get_field(LF_ANAG,"COMCORR")); - if (_cofi.empty()) - _cofi = get_field(LF_ANAG,"PAIV"); - - if (_pr_what == anafis) - { - _surname = _name.mid(30,50); _surname.trim(); - _name = _name.mid(0,30); _name.trim(); - } - switch (_ind_what) - { - case corrispondenza: - _address = get_field(LF_ANAG,"INDCORR"); - _civ = get_field(LF_ANAG,"CIVCORR"); - _stato = look_tab("%STA",get_field(LF_ANAG,"STATOCORR")); - _cap = get_field(LF_ANAG,"CAPCORR"); - _com = cc.get("DENCOM"); - _prov = cc.get("PROVCOM"); - if (_cap.empty()) - _cap = cc.get("CAPCOM"); - if (!_address.empty()) - break; - // else fall down - case domfisc: - _address = get_field(LF_ANAG,"INDRF"); - _civ = get_field(LF_ANAG,"CIVRF"); - _stato = look_tab("%STA",get_field(LF_ANAG,"STATORF")); - _cap = get_field(LF_ANAG,"CAPRF"); - cc = look_com(get_field(LF_ANAG,"COMRF")); - _com = cc.get("DENCOM"); - _prov = cc.get("PROVCOM"); - if (_cap.empty()) - _cap = cc.get("CAPCOM"); - if (!_address.empty()) - break; - // else fall down - case residenza: - _address = get_field(LF_ANAG,"INDRES"); - _civ = get_field(LF_ANAG,"CIVRES"); - _stato = look_tab("%STA",get_field(LF_ANAG,"STATORES")); - _cap = get_field(LF_ANAG,"CAPRES"); - cc = look_com(get_field(LF_ANAG,"COMRES")); - _com = cc.get("DENCOM"); - _prov = cc.get("PROVCOM"); - if (_cap.empty()) - _cap = cc.get("CAPCOM"); - break; - } -} - - -void BA6100_App::init_print() -{ - reset_print(); - reset_files(); - - // select cursor and main file - switch(_pr_what) - { - case anafis: - select_cursor(cfis()); - add_file(LF_ANAG); - break; - case anagiu: - select_cursor(cgiu()); - add_file(LF_ANAG); - break; - case nditte: - select_cursor(cdit()); - add_file(LF_NDITTE); - break; - } - - force_setpage(_pr_type == schede); - - // setup secondary links - if (_inclditte) - { - switch(_pr_type) - { - case elenco: - if (_pr_what != nditte) - add_file(LF_NDITTE); - break; - case schede: - if (_pr_what != nditte) - add_file(LF_NDITTE); - add_file(LF_ATTIV,LF_NDITTE); - add_file(LF_UNLOC,LF_NDITTE); - add_file(LF_SOCI, LF_NDITTE); - break; - default: - break; - } - } - set_headers(); -} - -bool BA6100_App::set_print(int) -{ - TMask mask("ba6100a.msk"); - // set print type - switch (mask.run()) - { - case K_ESC: - case K_QUIT: - return FALSE; - case BUT_BA6_ELENCO: - _pr_type = elenco; - // cio' che e' blu collega al modulo anagrafiche - _ana_link = enable_link("Collegamento archivio anagrafiche: ", 'b'); - _dit_link = enable_link("Collegamento archivio ditte: ", 'r'); - break; - case BUT_BA6_SCHEDE: - disable_links(); - _pr_type = schede; - break; - case BUT_BA6_ETICHETTE: - disable_links(); - if (_pr_what != nditte) - { - _pr_type = etichette; - // set additionals - TMask mask2("ba6100b.msk"); - - mask2.set_workfile("ba6100.set"); - mask2.set_handler(BUT_BA6B_RESET, mask_reset_fields); - - if (fexist("ba6100b.set")) - { - mask2.load(); - - _ind_what = (in)atoi(mask2.get(RDB_BA6B_INDIR)); - _ind_row = atoi(mask2.get(FLD_BA6B_INDROW)); - _piv_row = atoi(mask2.get(FLD_BA6B_PIVROW)); - _cod_row = atoi(mask2.get(FLD_BA6B_CODROW)); - _rows_et = atoi(mask2.get(FLD_BA6B_TOTROW)); - _ind_col = atoi(mask2.get(FLD_BA6B_INDCOL)); - _piv_col = atoi(mask2.get(FLD_BA6B_PIVCOL)); - _cod_col = atoi(mask2.get(FLD_BA6B_CODCOL)); - _cols_et = atoi(mask2.get(FLD_BA6B_TOTCOL)); - - _is_piv = mask2.get(CHK_BA6B_PIVA) == "X"; - _is_cod = mask2.get(CHK_BA6B_CODICE) == "X"; - } - else - { - mask2.field(FLD_BA6B_INDROW).set(format("%d",_ind_row)); - mask2.field(FLD_BA6B_INDCOL).set(format("%d",_ind_col)); - mask2.field(FLD_BA6B_PIVROW).set(format("%d",_piv_row)); - mask2.field(FLD_BA6B_PIVCOL).set(format("%d",_piv_col)); - mask2.field(FLD_BA6B_CODROW).set(format("%d",_cod_row)); - mask2.field(FLD_BA6B_CODCOL).set(format("%d",_cod_col)); - mask2.field(FLD_BA6B_TOTROW).set(format("%d",_rows_et)); - mask2.field(FLD_BA6B_TOTCOL).set(format("%d",_cols_et)); - mask2.field(CHK_BA6B_PIVA).set(_is_piv ? "X" : " "); - mask2.field(CHK_BA6B_CODICE).set(_is_cod ?"X": " "); - } - - mask2.run(); - - _ind_what = (in)atoi(mask2.get(RDB_BA6B_INDIR)); - _ind_row = atoi(mask2.get(FLD_BA6B_INDROW)); - _piv_row = atoi(mask2.get(FLD_BA6B_PIVROW)); - _cod_row = atoi(mask2.get(FLD_BA6B_CODROW)); - _rows_et = atoi(mask2.get(FLD_BA6B_TOTROW)); - _ind_col = atoi(mask2.get(FLD_BA6B_INDCOL)); - _piv_col = atoi(mask2.get(FLD_BA6B_PIVCOL)); - _cod_col = atoi(mask2.get(FLD_BA6B_CODCOL)); - _cols_et = atoi(mask2.get(FLD_BA6B_TOTCOL)); - - _is_piv = mask2.get(CHK_BA6B_PIVA) == "X"; - _is_cod = mask2.get(CHK_BA6B_CODICE) == "X"; - - if (_frpos) delete _frpos; - _frpos = new bool[_rows_et]; - memset(_frpos,FALSE,sizeof(_frpos)); - _frpos[_ind_row-1] = TRUE; - _frpos[_ind_row] = TRUE; - if (_is_piv) _frpos[_piv_row-1] = TRUE; - if (_is_cod) _frpos[_cod_row-1] = TRUE; - - for (int jk = 0; jk < _rows_et; jk++) - if (!_frpos[jk]) set_row(jk+1,""); - - // save settings - if (mask2.get(CHK_BA6B_SAVE) == "X") - mask2.save(); - } - break; - case BUT_BA6_RUBRICHE: - _ana_link = enable_link("Collegamento archivio anagrafiche: ", 'b'); - _dit_link = enable_link("Collegamento archivio ditte: ", 'r'); - _pr_type = rubriche; - break; - } - _pr_what = (pw)atoi(mask.get(RDB_BA6_TYPE)); - _sort = atoi(mask.get(RDB_BA6_SORT)); - _inclditte = (bool)(mask.get(CHK_BA6_INCLDI) == "X"); - - TString cod_from(5), cod_to(5); - TLocalisamfile* fl; - - switch(_pr_what) - { - case anafis: - case anagiu: - select_cursor(_pr_what == anafis ? cfis() : cgiu()); - if (_sort == 1) - { - cod_from = mask.get(_pr_what == anafis ? FLD_ANF_CODFR - : FLD_ANG_CODFR); - cod_to = mask.get(_pr_what == anafis ? FLD_ANF_CODTO - : FLD_ANG_CODTO); - } - else - { - cod_from = mask.get(_pr_what == anafis ? FLD_ANF_RAGSOCFR - : FLD_ANG_RAGSOCFR); - cod_to = mask.get(_pr_what == anafis ? FLD_ANF_RAGSOCTO - : FLD_ANG_RAGSOCTO); - } - { - fl = current_cursor()->file(LF_ANAG); - TRectype tr1(fl->curr()); - TRectype tr2(fl->curr()); - tr1.zero(); tr2.zero(); - tr1.put("TIPOA", _pr_what == anafis ? "F" : "G"); - tr2.put("TIPOA", _pr_what == anafis ? "F" : "G"); - if (!cod_from.empty() || !cod_to.empty()) - { - if (_sort == 1) - { - if (cod_from.not_empty()) - { - tr1.put("CODANAGR",cod_from); - tr2.put("CODANAGR",cod_to); - } - } - else - { - if (cod_from.not_empty()) - { - tr1.put("RAGSOC",cod_from); - tr2.put("RAGSOC",cod_to); - } - } - } - current_cursor()->setregion(&tr1, &tr2); - } - break; - case nditte: - select_cursor(cdit()); - if (_sort == 1) - { - cod_from = mask.get(FLD_DITTE_CODFR); - cod_to = mask.get(FLD_DITTE_CODTO); - } - else - { - cod_from = mask.get(FLD_DITTE_RAGSOCFR); - cod_to = mask.get(FLD_DITTE_RAGSOCTO); - } - if (!cod_from.empty() || !cod_to.empty()) - { - fl = current_cursor()->file(LF_NDITTE); - TRectype tr1(fl->curr()); - TRectype tr2(fl->curr()); - tr1.zero(); tr2.zero(); - if (_sort == 1) - { - tr1.put("CODDITTA",cod_from); - tr2.put("CODDITTA",cod_to); - } - else - { - tr1.put("RAGSOC",cod_from); - tr2.put("RAGSOC",cod_to); - } - current_cursor()->setregion(cod_from.empty() ? NULL : &tr1, - cod_to.empty() ? NULL : &tr2); - } - break; - } - // setup links and set headers - init_print(); - -// enable_print_menu(); - - return TRUE; -} - -void BA6100_App::user_create() -{ - TToken_string rxp(40); - { - TProgind p(5, "Preparazione archivi\nPrego attendere", FALSE, TRUE, 30); - - // setup relation - _rel_fis = new TRelation(LF_ANAG); - _rel_giu = new TRelation(LF_ANAG); - _rel_dit = new TRelation(LF_NDITTE); - - p.addstatus(1); - - rxp.add("CODANAGR=CODANAGR"); - - _rel_fis->add(LF_ANAGFIS,rxp); - _rel_giu->add(LF_ANAGGIU,rxp); - - rxp.add("TIPOA=TIPOA"); - - _rel_fis->add(LF_NDITTE, rxp, 4); - _rel_giu->add(LF_NDITTE, rxp, 4); - _rel_dit->add(LF_ANAG, rxp); - - p.addstatus(1); - - // add unloc & attiv - rxp = "CODDITTA=CODDITTA"; - - _rel_fis->add(LF_ATTIV, rxp, 1, LF_NDITTE); - _rel_fis->add(LF_UNLOC, rxp, 1, LF_NDITTE); - _rel_giu->add(LF_ATTIV, rxp, 1, LF_NDITTE); - _rel_giu->add(LF_UNLOC, rxp, 1, LF_NDITTE); - _rel_dit->add(LF_ATTIV, rxp, 1); - _rel_dit->add(LF_UNLOC, rxp, 1); - _rel_fis->add(LF_SOCI, rxp, 1, LF_NDITTE); - _rel_giu->add(LF_SOCI, rxp, 1, LF_NDITTE); - _rel_dit->add(LF_SOCI, rxp, 1); - - p.addstatus(1); - - _cfis1 = add_cursor(new TCursor(_rel_fis, "" , 1)); - _cgiu1 = add_cursor(new TCursor(_rel_giu, "" , 1)); - _cdit1 = add_cursor(new TCursor(_rel_dit, "", 1)); - _cfis2 = add_cursor(new TCursor(_rel_fis, "" , 2)); - _cgiu2 = add_cursor(new TCursor(_rel_giu, "" , 2)); - _cdit2 = add_cursor(new TCursor(_rel_dit, "", 2)); - - p.addstatus(1); - - _comuni = new TLocalisamfile(LF_COMUNI); - - // set translated field values - set_translation(LF_ANAGFIS,"STATCIV","1","Celibe/Nubile"); - set_translation(LF_ANAGFIS,"STATCIV","2","Coniugato/a"); - set_translation(LF_ANAGFIS,"STATCIV","3","Vedovo/a"); - set_translation(LF_ANAGFIS,"STATCIV","4","Separato/a"); - set_translation(LF_ANAGFIS,"STATCIV","5","Divorziato/a"); - set_translation(LF_ANAGFIS,"STATCIV","6","Deceduto/a"); - set_translation(LF_ANAGFIS,"STATCIV","7","Tutelato/a"); - set_translation(LF_ANAGFIS,"STATCIV","8","Figlio/a minore"); - set_translation(LF_ANAGFIS,"TITSTU", "1" ,"Nessuno"); - set_translation(LF_ANAGFIS,"TITSTU", "2" ,"Lic. Elem."); - set_translation(LF_ANAGFIS,"TITSTU", "3" ,"Lic. Media"); - set_translation(LF_ANAGFIS,"TITSTU", "4" ,"Diploma"); - set_translation(LF_ANAGFIS,"TITSTU", "5" ,"Laurea"); - set_translation(LF_ANAGFIS,"SESSO", "M", "Maschio"); - set_translation(LF_ANAGFIS,"SESSO", "F", "Femmina"); - set_translation(LF_NDITTE,"FREQVIVA","M","Mensile"); - set_translation(LF_NDITTE,"FREQVIVA","T","Trimestrale"); - set_translation(LF_NDITTE,"DATLAV","1","Si"); - set_translation(LF_NDITTE,"DATLAV","2","No"); - set_translation(LF_NDITTE,"DATLAV","3","Lavoro Agricolo"); - set_translation(LF_NDITTE,"STATOSOC","1","Normale attivita'"); - set_translation(LF_NDITTE,"STATOSOC","2","Liquidazione cessata attivita'"); - set_translation(LF_NDITTE,"STATOSOC","3", - "Fallimento o Liquidazione coatta amm."); - set_translation(LF_NDITTE,"STATOSOC","4","Estinto"); - set_translation(LF_ANAGGIU,"STATOSOC","1","Normale attivita'"); - set_translation(LF_ANAGGIU,"STATOSOC","2","Liquidazione cessata attivita'"); - set_translation(LF_ANAGGIU,"STATOSOC","3", - "Fallimento o Liquidazione coatta amm."); - set_translation(LF_ANAGGIU,"STATOSOC","4","Estinto"); - set_translation(LF_ANAGGIU,"SITSOC","1","Inizio"); - set_translation(LF_ANAGGIU,"SITSOC","2","Liquidazione"); - set_translation(LF_ANAGGIU,"SITSOC","3","Termine liquidazione"); - set_translation(LF_ANAGGIU,"SITSOC","4","Estinzione"); - set_translation(LF_ANAGGIU,"SITSOC","5","Trasf. IRPEG"); - set_translation(LF_ANAGGIU,"SITSOC","6","Normale"); - - set_fillchar('_'); - set_wait_threshold(0); - - p.addstatus(1); - } -} - -void BA6100_App::user_destroy() -{ - if (_rel_fis) delete _rel_fis; - if (_rel_giu) delete _rel_giu; - if (_rel_dit) delete _rel_dit; - if (_frpos) delete _frpos; - - delete _comuni; -} - - -int ba6100(int argc, char* argv[]) -{ - BA6100_App app; - app.run(argc, argv, "Stampe Anagrafiche"); - return 0; -} +// ********************************************************************** +// Stampa anagrafiche +// Control code +// *********************************************************************** + +#include "ba6100.h" +#include +#include +#include + +// ------- utils -------------------------------------------- + + +TRectype& BA6100_App::look_com(const char* cod) +{ + _comuni->curr().zero(); + if (*cod) + { + _comuni->curr().put("COM",cod); + _comuni->read(); + if (_comuni->bad()) + _comuni->curr().zero(); + } + return _comuni->curr(); +} + +const char* BA6100_App::look_tab(const char* tabname, const char* cod, + const char* fld) +{ + if (*cod == 0) return ""; + TTable tab(tabname); + tab.curr().zero(); + tab.curr().put("CODTAB",cod); + tab.read(); + if (tab.bad()) tab.curr().zero(); + return tab.curr().get(fld); +} + +// link + +void BA6100_App::process_link(int id, const char* txt) +{ + if (id == _ana_link) + { + TString ss = "1|"; ss << txt; + TMessage fs(cmd2name("ba4","-1"), MSG_LN, ss); + TMailbox m; + m.send(fs); + TExternal_app ba4(_pr_what == anafis ? "ba4 -1 F" : "ba4 -1 G"); + if (ba4.run()) beep(); + } + else if (id == _dit_link) + { + TString ss = "1|"; ss << txt << "|" << txt; + TMessage fs(cmd2name("ba4","-2"), MSG_LN, ss); + TMailbox m; + m.send(fs); + TExternal_app ba4("ba4 -2"); + if (ba4.run()) beep(); + } +} + +// ---- here we go ------------------------------------------------- + +void BA6100_App::set_page(int file, int cnt) +{ + switch(file) + { + case LF_ANAG: + case LF_NDITTE: + if (_pr_type == elenco) + { + if (_pr_what != nditte && file == LF_NDITTE) + { + set_row(1,"@50g$[r]@pN$[n]@66g@S", FLD(LF_NDITTE,"CODDITTA","@@@@@"), + FLD(LF_NDITTE,"RAGSOC")); + set_row(2,""); + } + else + set_elenco(); + } + else if (_pr_type == rubriche) set_rubriche(); + else if (_pr_type == schede) + { + if (_pr_what != nditte && file == LF_NDITTE) + set_scheda_ditta(); + else + set_schede(); + } + else if (_pr_type == etichette) set_etichette(); + break; + case LF_ATTIV: + set_scheda_attiv(); + break; + case LF_UNLOC: + set_scheda_unloc(); + break; + case LF_SOCI: + set_scheda_socio(); + break; + } +} + + +bool BA6100_App::preprocess_page(int file, int counter) +{ + // non stampa la prima ditta se sta facendo l'elenco visto + // che la stampa a fianco dell'anagrafica + if (file == LF_NDITTE && _pr_type == elenco && _inclditte + && _pr_what != nditte) + if (current_cursor()->is_first_match(LF_NDITTE)) + return FALSE; + + if (_pr_type == rubriche) + { + // vale per ditte, anagiu, anafis + _com = current_cursor()->curr(LF_ANAG).get("COMRES"); + if (_com.empty()) + _com = current_cursor()->curr(LF_ANAG).get("COMRF"); + _phone = current_cursor()->curr(LF_ANAG).get("PTELRF"); + _phone.trim(); + if (!_phone.empty()) _phone << '/'; + _phone << current_cursor()->curr(LF_ANAG).get("TELRF"); + + TRectype& cc = look_com(_com); + _com = cc.get("DENCOM"); + _cap = cc.get("CAPCOM"); + _prov = cc.get("PROVCOM"); + } + else if (_pr_type == etichette) + preprocess_etichette(); + return TRUE; +} + + +bool mask_reset_fields(TMask_field& mf, KEY k) +{ + if (k == K_SPACE) + { + BA6100_App* a = (BA6100_App*)MainApp(); + mf.mask().field(FLD_BA6B_INDROW).set(format("%d",a->_ind_row)); + mf.mask().field(FLD_BA6B_INDCOL).set(format("%d",a->_ind_col)); + mf.mask().field(FLD_BA6B_PIVROW).set(format("%d",a->_piv_row)); + mf.mask().field(FLD_BA6B_PIVCOL).set(format("%d",a->_piv_col)); + mf.mask().field(FLD_BA6B_CODROW).set(format("%d",a->_cod_row)); + mf.mask().field(FLD_BA6B_CODCOL).set(format("%d",a->_cod_col)); + mf.mask().field(FLD_BA6B_TOTROW).set(format("%d",a->_rows_et)); + mf.mask().field(FLD_BA6B_TOTCOL).set(format("%d",a->_cols_et)); + mf.mask().field(CHK_BA6B_PIVA).set(a->_is_piv ? "X" : " "); + mf.mask().field(CHK_BA6B_CODICE).set(a->_is_cod ?"X": " "); + } + return TRUE; +} + + +void BA6100_App::preprocess_etichette() +{ + // everything goes into strings + _name = get_field(LF_ANAG,"RAGSOC"); + _cod = get_field(LF_ANAG,"CODANAGR"); + _cofi = get_field(LF_ANAG,"COFI"); + TRectype& cc = look_com(get_field(LF_ANAG,"COMCORR")); + if (_cofi.empty()) + _cofi = get_field(LF_ANAG,"PAIV"); + + if (_pr_what == anafis) + { + _surname = _name.mid(30,50); _surname.trim(); + _name = _name.mid(0,30); _name.trim(); + } + switch (_ind_what) + { + case corrispondenza: + _address = get_field(LF_ANAG,"INDCORR"); + _civ = get_field(LF_ANAG,"CIVCORR"); + _stato = look_tab("%STA",get_field(LF_ANAG,"STATOCORR")); + _cap = get_field(LF_ANAG,"CAPCORR"); + _com = cc.get("DENCOM"); + _prov = cc.get("PROVCOM"); + if (_cap.empty()) + _cap = cc.get("CAPCOM"); + if (!_address.empty()) + break; + // else fall down + case domfisc: + _address = get_field(LF_ANAG,"INDRF"); + _civ = get_field(LF_ANAG,"CIVRF"); + _stato = look_tab("%STA",get_field(LF_ANAG,"STATORF")); + _cap = get_field(LF_ANAG,"CAPRF"); + cc = look_com(get_field(LF_ANAG,"COMRF")); + _com = cc.get("DENCOM"); + _prov = cc.get("PROVCOM"); + if (_cap.empty()) + _cap = cc.get("CAPCOM"); + if (!_address.empty()) + break; + // else fall down + case residenza: + _address = get_field(LF_ANAG,"INDRES"); + _civ = get_field(LF_ANAG,"CIVRES"); + _stato = look_tab("%STA",get_field(LF_ANAG,"STATORES")); + _cap = get_field(LF_ANAG,"CAPRES"); + cc = look_com(get_field(LF_ANAG,"COMRES")); + _com = cc.get("DENCOM"); + _prov = cc.get("PROVCOM"); + if (_cap.empty()) + _cap = cc.get("CAPCOM"); + break; + } +} + + +void BA6100_App::init_print() +{ + reset_print(); + reset_files(); + + // select cursor and main file + switch(_pr_what) + { + case anafis: + select_cursor(cfis()); + add_file(LF_ANAG); + break; + case anagiu: + select_cursor(cgiu()); + add_file(LF_ANAG); + break; + case nditte: + select_cursor(cdit()); + add_file(LF_NDITTE); + break; + } + + force_setpage(_pr_type == schede); + + // setup secondary links + if (_inclditte) + { + switch(_pr_type) + { + case elenco: + if (_pr_what != nditte) + add_file(LF_NDITTE); + break; + case schede: + if (_pr_what != nditte) + add_file(LF_NDITTE); + add_file(LF_ATTIV,LF_NDITTE); + add_file(LF_UNLOC,LF_NDITTE); + add_file(LF_SOCI, LF_NDITTE); + break; + default: + break; + } + } + set_headers(); +} + +bool BA6100_App::set_print(int) +{ + TMask mask("ba6100a.msk"); + // set print type + switch (mask.run()) + { + case K_ESC: + case K_QUIT: + return FALSE; + case BUT_BA6_ELENCO: + _pr_type = elenco; + // cio' che e' blu collega al modulo anagrafiche + _ana_link = enable_link("Collegamento archivio anagrafiche: ", 'b'); + _dit_link = enable_link("Collegamento archivio ditte: ", 'r'); + break; + case BUT_BA6_SCHEDE: + disable_links(); + _pr_type = schede; + break; + case BUT_BA6_ETICHETTE: + disable_links(); + if (_pr_what != nditte) + { + _pr_type = etichette; + // set additionals + TMask mask2("ba6100b.msk"); + + mask2.set_workfile("ba6100.set"); + mask2.set_handler(BUT_BA6B_RESET, mask_reset_fields); + + if (fexist("ba6100b.set")) + { + mask2.load(); + + _ind_what = (in)atoi(mask2.get(RDB_BA6B_INDIR)); + _ind_row = atoi(mask2.get(FLD_BA6B_INDROW)); + _piv_row = atoi(mask2.get(FLD_BA6B_PIVROW)); + _cod_row = atoi(mask2.get(FLD_BA6B_CODROW)); + _rows_et = atoi(mask2.get(FLD_BA6B_TOTROW)); + _ind_col = atoi(mask2.get(FLD_BA6B_INDCOL)); + _piv_col = atoi(mask2.get(FLD_BA6B_PIVCOL)); + _cod_col = atoi(mask2.get(FLD_BA6B_CODCOL)); + _cols_et = atoi(mask2.get(FLD_BA6B_TOTCOL)); + + _is_piv = mask2.get(CHK_BA6B_PIVA) == "X"; + _is_cod = mask2.get(CHK_BA6B_CODICE) == "X"; + } + else + { + mask2.field(FLD_BA6B_INDROW).set(format("%d",_ind_row)); + mask2.field(FLD_BA6B_INDCOL).set(format("%d",_ind_col)); + mask2.field(FLD_BA6B_PIVROW).set(format("%d",_piv_row)); + mask2.field(FLD_BA6B_PIVCOL).set(format("%d",_piv_col)); + mask2.field(FLD_BA6B_CODROW).set(format("%d",_cod_row)); + mask2.field(FLD_BA6B_CODCOL).set(format("%d",_cod_col)); + mask2.field(FLD_BA6B_TOTROW).set(format("%d",_rows_et)); + mask2.field(FLD_BA6B_TOTCOL).set(format("%d",_cols_et)); + mask2.field(CHK_BA6B_PIVA).set(_is_piv ? "X" : " "); + mask2.field(CHK_BA6B_CODICE).set(_is_cod ?"X": " "); + } + + mask2.run(); + + _ind_what = (in)atoi(mask2.get(RDB_BA6B_INDIR)); + _ind_row = atoi(mask2.get(FLD_BA6B_INDROW)); + _piv_row = atoi(mask2.get(FLD_BA6B_PIVROW)); + _cod_row = atoi(mask2.get(FLD_BA6B_CODROW)); + _rows_et = atoi(mask2.get(FLD_BA6B_TOTROW)); + _ind_col = atoi(mask2.get(FLD_BA6B_INDCOL)); + _piv_col = atoi(mask2.get(FLD_BA6B_PIVCOL)); + _cod_col = atoi(mask2.get(FLD_BA6B_CODCOL)); + _cols_et = atoi(mask2.get(FLD_BA6B_TOTCOL)); + + _is_piv = mask2.get(CHK_BA6B_PIVA) == "X"; + _is_cod = mask2.get(CHK_BA6B_CODICE) == "X"; + + if (_frpos) delete _frpos; + _frpos = new bool[_rows_et]; + memset(_frpos,FALSE,sizeof(_frpos)); + _frpos[_ind_row-1] = TRUE; + _frpos[_ind_row] = TRUE; + if (_is_piv) _frpos[_piv_row-1] = TRUE; + if (_is_cod) _frpos[_cod_row-1] = TRUE; + + for (int jk = 0; jk < _rows_et; jk++) + if (!_frpos[jk]) set_row(jk+1,""); + + // save settings + if (mask2.get(CHK_BA6B_SAVE) == "X") + mask2.save(); + } + break; + case BUT_BA6_RUBRICHE: + _ana_link = enable_link("Collegamento archivio anagrafiche: ", 'b'); + _dit_link = enable_link("Collegamento archivio ditte: ", 'r'); + _pr_type = rubriche; + break; + } + _pr_what = (pw)atoi(mask.get(RDB_BA6_TYPE)); + _sort = atoi(mask.get(RDB_BA6_SORT)); + _inclditte = (bool)(mask.get(CHK_BA6_INCLDI) == "X"); + + TString cod_from(5), cod_to(5); + TLocalisamfile* fl; + + switch(_pr_what) + { + case anafis: + case anagiu: + select_cursor(_pr_what == anafis ? cfis() : cgiu()); + if (_sort == 1) + { + cod_from = mask.get(_pr_what == anafis ? FLD_ANF_CODFR + : FLD_ANG_CODFR); + cod_to = mask.get(_pr_what == anafis ? FLD_ANF_CODTO + : FLD_ANG_CODTO); + } + else + { + cod_from = mask.get(_pr_what == anafis ? FLD_ANF_RAGSOCFR + : FLD_ANG_RAGSOCFR); + cod_to = mask.get(_pr_what == anafis ? FLD_ANF_RAGSOCTO + : FLD_ANG_RAGSOCTO); + } + { + fl = current_cursor()->file(LF_ANAG); + TRectype tr1(fl->curr()); + TRectype tr2(fl->curr()); + tr1.zero(); tr2.zero(); + tr1.put("TIPOA", _pr_what == anafis ? "F" : "G"); + tr2.put("TIPOA", _pr_what == anafis ? "F" : "G"); + if (!cod_from.empty() || !cod_to.empty()) + { + if (_sort == 1) + { + if (cod_from.not_empty()) + { + tr1.put("CODANAGR",cod_from); + tr2.put("CODANAGR",cod_to); + } + } + else + { + if (cod_from.not_empty()) + { + tr1.put("RAGSOC",cod_from); + tr2.put("RAGSOC",cod_to); + } + } + } + current_cursor()->setregion(tr1, tr2); + } + break; + case nditte: + select_cursor(cdit()); + if (_sort == 1) + { + cod_from = mask.get(FLD_DITTE_CODFR); + cod_to = mask.get(FLD_DITTE_CODTO); + } + else + { + cod_from = mask.get(FLD_DITTE_RAGSOCFR); + cod_to = mask.get(FLD_DITTE_RAGSOCTO); + } + if (!cod_from.empty() || !cod_to.empty()) + { + fl = current_cursor()->file(LF_NDITTE); + TRectype tr1(fl->curr()); + TRectype tr2(fl->curr()); + tr1.zero(); tr2.zero(); + if (_sort == 1) + { + tr1.put("CODDITTA",cod_from); + tr2.put("CODDITTA",cod_to); + } + else + { + tr1.put("RAGSOC",cod_from); + tr2.put("RAGSOC",cod_to); + } + current_cursor()->setregion(tr1, tr2); + } + break; + } + // setup links and set headers + init_print(); + + // enable_print_menu(); + + return TRUE; +} + +void BA6100_App::user_create() +{ + TToken_string rxp(40); +{ + TProgind p(5, "Preparazione archivi\nPrego attendere", FALSE, TRUE, 30); + + // setup relation + _rel_fis = new TRelation(LF_ANAG); + _rel_giu = new TRelation(LF_ANAG); + _rel_dit = new TRelation(LF_NDITTE); + + p.addstatus(1); + + rxp.add("CODANAGR=CODANAGR"); + + _rel_fis->add(LF_ANAGFIS,rxp); + _rel_giu->add(LF_ANAGGIU,rxp); + + rxp.add("TIPOA=TIPOA"); + + _rel_fis->add(LF_NDITTE, rxp, 4); + _rel_giu->add(LF_NDITTE, rxp, 4); + _rel_dit->add(LF_ANAG, rxp); + + p.addstatus(1); + + // add unloc & attiv + rxp = "CODDITTA=CODDITTA"; + + _rel_fis->add(LF_ATTIV, rxp, 1, LF_NDITTE); + _rel_fis->add(LF_UNLOC, rxp, 1, LF_NDITTE); + _rel_giu->add(LF_ATTIV, rxp, 1, LF_NDITTE); + _rel_giu->add(LF_UNLOC, rxp, 1, LF_NDITTE); + _rel_dit->add(LF_ATTIV, rxp, 1); + _rel_dit->add(LF_UNLOC, rxp, 1); + _rel_fis->add(LF_SOCI, rxp, 1, LF_NDITTE); + _rel_giu->add(LF_SOCI, rxp, 1, LF_NDITTE); + _rel_dit->add(LF_SOCI, rxp, 1); + + p.addstatus(1); + + _cfis1 = add_cursor(new TCursor(_rel_fis, "" , 1)); + _cgiu1 = add_cursor(new TCursor(_rel_giu, "" , 1)); + _cdit1 = add_cursor(new TCursor(_rel_dit, "", 1)); + _cfis2 = add_cursor(new TCursor(_rel_fis, "" , 2)); + _cgiu2 = add_cursor(new TCursor(_rel_giu, "" , 2)); + _cdit2 = add_cursor(new TCursor(_rel_dit, "", 2)); + + p.addstatus(1); + + _comuni = new TLocalisamfile(LF_COMUNI); + + // set translated field values + set_translation(LF_ANAGFIS,"STATCIV","1","Celibe/Nubile"); + set_translation(LF_ANAGFIS,"STATCIV","2","Coniugato/a"); + set_translation(LF_ANAGFIS,"STATCIV","3","Vedovo/a"); + set_translation(LF_ANAGFIS,"STATCIV","4","Separato/a"); + set_translation(LF_ANAGFIS,"STATCIV","5","Divorziato/a"); + set_translation(LF_ANAGFIS,"STATCIV","6","Deceduto/a"); + set_translation(LF_ANAGFIS,"STATCIV","7","Tutelato/a"); + set_translation(LF_ANAGFIS,"STATCIV","8","Figlio/a minore"); + set_translation(LF_ANAGFIS,"TITSTU", "1" ,"Nessuno"); + set_translation(LF_ANAGFIS,"TITSTU", "2" ,"Lic. Elem."); + set_translation(LF_ANAGFIS,"TITSTU", "3" ,"Lic. Media"); + set_translation(LF_ANAGFIS,"TITSTU", "4" ,"Diploma"); + set_translation(LF_ANAGFIS,"TITSTU", "5" ,"Laurea"); + set_translation(LF_ANAGFIS,"SESSO", "M", "Maschio"); + set_translation(LF_ANAGFIS,"SESSO", "F", "Femmina"); + set_translation(LF_NDITTE,"FREQVIVA","M","Mensile"); + set_translation(LF_NDITTE,"FREQVIVA","T","Trimestrale"); + set_translation(LF_NDITTE,"DATLAV","1","Si"); + set_translation(LF_NDITTE,"DATLAV","2","No"); + set_translation(LF_NDITTE,"DATLAV","3","Lavoro Agricolo"); + set_translation(LF_NDITTE,"STATOSOC","1","Normale attivita'"); + set_translation(LF_NDITTE,"STATOSOC","2","Liquidazione cessata attivita'"); + set_translation(LF_NDITTE,"STATOSOC","3", + "Fallimento o Liquidazione coatta amm."); + set_translation(LF_NDITTE,"STATOSOC","4","Estinto"); + set_translation(LF_ANAGGIU,"STATOSOC","1","Normale attivita'"); + set_translation(LF_ANAGGIU,"STATOSOC","2","Liquidazione cessata attivita'"); + set_translation(LF_ANAGGIU,"STATOSOC","3", + "Fallimento o Liquidazione coatta amm."); + set_translation(LF_ANAGGIU,"STATOSOC","4","Estinto"); + set_translation(LF_ANAGGIU,"SITSOC","1","Inizio"); + set_translation(LF_ANAGGIU,"SITSOC","2","Liquidazione"); + set_translation(LF_ANAGGIU,"SITSOC","3","Termine liquidazione"); + set_translation(LF_ANAGGIU,"SITSOC","4","Estinzione"); + set_translation(LF_ANAGGIU,"SITSOC","5","Trasf. IRPEG"); + set_translation(LF_ANAGGIU,"SITSOC","6","Normale"); + + set_fillchar('_'); + set_wait_threshold(0); + + p.addstatus(1); +} +} + +void BA6100_App::user_destroy() +{ + if (_rel_fis) delete _rel_fis; + if (_rel_giu) delete _rel_giu; + if (_rel_dit) delete _rel_dit; + if (_frpos) delete _frpos; + + delete _comuni; +} + + +int ba6100(int argc, char* argv[]) +{ + BA6100_App app; + app.run(argc, argv, "Stampe Anagrafiche"); + return 0; +} diff --git a/ba/ba6200.cpp b/ba/ba6200.cpp index f1b165fb4..91189ab67 100755 --- a/ba/ba6200.cpp +++ b/ba/ba6200.cpp @@ -183,7 +183,7 @@ bool BA6200_application::set_print(int) a.put(COM_STATO,statofine); a.put(COM_COM ,codicefine); - current_cursor()->setregion(&da, &a); + current_cursor()->setregion(da, a); } else if (scelta == 2) @@ -207,7 +207,7 @@ bool BA6200_application::set_print(int) a.put (COM_DENCOM, denomfine); - current_cursor()->setregion(&da, &a); + current_cursor()->setregion(da, a); } //set_print_zero(); @@ -257,7 +257,7 @@ void BA6200_application::user_create() _comuni = new TLocalisamfile (LF_COMUNI); - _descr_comune = new TParagraph_string ("",25); + _descr_comune = new TParagraph_string ("",25); _msk = new TMask("ba6200a"); } diff --git a/cg/cg0100.cpp b/cg/cg0100.cpp index 817b62116..548685d3c 100755 --- a/cg/cg0100.cpp +++ b/cg/cg0100.cpp @@ -288,14 +288,13 @@ HIDDEN bool sottoc_handler(TMask_field& f, KEY key) { if (key == K_TAB) { - TString gruppo(f.mask().get(FLD_CM1_GRUPPO)); - if (gruppo.empty()) return TRUE; - TString conto(f.mask().get(FLD_CM1_CONTO)); - TString sottoconto(f.mask().get(FLD_CM1_SOTTOCONTO)); - if (sottoconto.not_empty() && conto.empty()) return f.error_box("Manca il CONTO"); - dispatch_e_char(f.parent(), K_AUTO_ENTER); + int gruppo = f.mask().get_int(FLD_CM1_GRUPPO); + if (gruppo == 0) return TRUE; + int conto = f.mask().get_int(FLD_CM1_CONTO); + long sottoconto = f.mask().get_long(FLD_CM1_SOTTOCONTO); + if (sottoconto != 0 && conto == 0) return f.error_box("Manca il CONTO"); + f.mask().stop_run(K_AUTO_ENTER); } - return TRUE; } diff --git a/cg/cg0300.cpp b/cg/cg0300.cpp index b981ec4df..a216f802f 100755 --- a/cg/cg0300.cpp +++ b/cg/cg0300.cpp @@ -50,7 +50,7 @@ HIDDEN bool key_handler (TMask_field& f, KEY k) if (m.get(F_ANNO).not_empty() && m.get(F_CODATT).not_empty() && m.get(F_CODCF).not_empty()) - m.send_key(K_AUTO_ENTER, 0); + m.stop_run(K_AUTO_ENTER); } return TRUE; } diff --git a/cg/cg1500.cpp b/cg/cg1500.cpp index 60819e2ff..19b4000ba 100755 --- a/cg/cg1500.cpp +++ b/cg/cg1500.cpp @@ -2813,9 +2813,9 @@ bool CG1500_application::set_print(int) _cur->setkey(3); if (_situazione.not_empty()) - _cur->filter(format("TIPOCF = \"%s\"",(const char*)_situazione)); + _cur->setfilter(format("TIPOCF = \"%s\"",(const char*)_situazione)); else - _cur->filter(""); + _cur->setfilter(""); _prog = new TProgind(_cur->items(),"Elaborazione in corso... prego attendere",FALSE); diff --git a/cg/cg3100.cpp b/cg/cg3100.cpp index 14e0ca4d6..101c708a6 100755 --- a/cg/cg3100.cpp +++ b/cg/cg3100.cpp @@ -1,1780 +1,1780 @@ -//Stampa movimenti - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cg3.h" -#include "cg3100.h" -#include "cg3401.h" - -const MAXSTR = 128; -static char __tmp [MAXSTR]; -static TFixed_string tmp (__tmp, MAXSTR); - -enum liste { - movimenti=1, - fatture=2, - movimenti_sezionale=3 -}; - -bool filter_func (const TRelation *); -bool filter_func_fatture (const TRelation *); - -class CG3100_application : public TPrintapp -{ - friend bool filter_func (const TRelation *); - friend bool filter_func_fatture (const TRelation *); - - TRigaiva_array _c; - TTable * _tabiva, * _tabtpd, * _tabreg; - TLocalisamfile * _caus,* _comuni,* _rmoviva, * _clifo, * _pcon, * _attiv; - TRelation * _relmov,* _relmov1,* _relmov2,* _relmov3; - TCursor * _curr1, * _curr2, * _curr3; - TDate _data_ini, _data_fin, _datareg, _data_prec; - TString _descr, _descr_doc, _descr_causale, _totali_a, _totali_d; - TString _totalegen_dare, _totalegen_avere, _tipo_ini, _masc, _causale; - TString _causale_ini, _causale_fin, _registro,_registro_ini, _registro_fin; - TString _tipoatt, _tipo_elenco,_tipo_clifo_prec,_cod,_tipoelsucc; - TString _tipo_clifo_precedente; - TString _appoggio, _tipodoc, _tipodocumento, _err1, _msg, _err, _err2; - TString _ragsoc, _indcf, _civcf, _paiv, _codcaus, _dencom, _provcom, _cofi; - TString _capcf, _codval, _simbolo, _statocf, _comcf, _tipo_fin; - long _documenti, _codice_ini, _codice_fin, _numero_reg,_codcf; - long _numreg, _numreg_fin, _numreg_ini, _codalleg, _numeroregp,_codclifosucc; - long _codcf_prec; - int _anno, _annoes; - real _totdocumenti, _totdoc, _totimponibile, _totimposta, _importo; - real _op_esenti, _op_non_imp, _impo, _impos; - real _tot_dare, _tot_avere, _tot_avere_giornaliero; - real _tot_dare_giornaliero, _tot_dare_generale, _tot_avere_generale; - bool _intracom, _no_preprocess_page, _salto_pagina; - bool _stampa_parte_iva,_alleg_causale,_stampa_mess_alleg_iva,_allegb,_ricser; - bool _settata_prima_riga; - int _cur1,_cur2,_cur2b,_cur3,_cur4,_decidi,_tipod,_controllo_mov_errati; - int _numero_riga, _alleg, _tiporegistro, _tipocr, _scelta_stampa, _nr, _n; - liste _tipo_lista; - word _flags; - -protected: - virtual void preprocess_header(); - virtual bool preprocess_page(int,int); - virtual print_action postprocess_page(int,int); - virtual print_action postprocess_print(int,int); - virtual void set_page(int,int); - virtual bool set_print(int m); - void init_print(const TMask& m); - -public: - - void user_create() ; - void user_destroy(); - bool segnala_errori_primariga(); - bool segnala_errori_ogniriga(); - void stampa_errori_rmov(); - void stampa_errori_mov(); - void stampa_intestazione(); - void incrementa_totali(); - void compila_clifo(); - void compila_comuni(); - int my_next (TLocalisamfile*); - - CG3100_application() {} -}; - -void CG3100_application::compila_clifo() -{ - _clifo->setkey(1); - _clifo->zero(); - _clifo->put(CLI_TIPOCF,_tipo_elenco); - _clifo->put(CLI_CODCF,_codcf); - _clifo->read(); - if (_clifo->bad()) - _clifo->zero(); - _alleg = _clifo->curr().get_int(CLI_ALLEG); - _statocf = _clifo->curr().get(CLI_STATOCF); - _comcf = _clifo->curr().get(CLI_COMCF); - _ragsoc = _clifo->curr().get(CLI_RAGSOC); - _indcf = _clifo->curr().get(CLI_INDCF); - _civcf = _clifo->curr().get(CLI_CIVCF); - _paiv = _clifo->curr().get(CLI_PAIV); - _capcf = _clifo->curr().get(CLI_CAPCF); - _cofi = _clifo->curr().get(CLI_COFI); - _codalleg = _clifo->curr().get_long(CLI_CODALLEG); -} - -void CG3100_application::compila_comuni() -{ - _comuni->setkey(1); - _comuni->zero(); - _comuni->put(COM_STATO,_statocf); - _comuni->put(COM_COM,_comcf); - _comuni->read(); - if (_comuni->bad()) - _comuni->curr().zero(); - _dencom = _comuni->get(COM_DENCOM); - _provcom = _comuni->get(COM_PROVCOM); -} - -const int AllegClifo (int gruppo, int conto, long sottoconto) -{ - TLocalisamfile clifo(LF_CLIFO); - int alleg; - - clifo.setkey(3); - clifo.zero(); - clifo.put(CLI_GRUPPO, gruppo); - clifo.put(CLI_CONTO, conto); - clifo.put(CLI_CODCF, sottoconto); - clifo.read(); - if (clifo.good()) - alleg = clifo.curr().get_int(CLI_ALLEG); - else - alleg = 0; - - return alleg; -} - -const char * DescrConto (long gruppo, long conto, long sottoconto, - const char* tipocf) -{ - TLocalisamfile pcon(LF_PCON); - TLocalisamfile clifo(LF_CLIFO); - - pcon.setkey(1); - pcon.zero(); - pcon.put(PCN_GRUPPO, gruppo); - if (conto != 0) - pcon.put(PCN_CONTO, conto); - if (sottoconto != 0) - pcon.put(PCN_SOTTOCONTO,sottoconto); - pcon.read(); - if (pcon.good()) - tmp = pcon.curr().get(PCN_DESCR); - else - { - clifo.setkey(1); - clifo.zero(); - clifo.put(CLI_CODCF, sottoconto); - clifo.put(CLI_TIPOCF,tipocf); - clifo.read(); - if (clifo.good()) - tmp = clifo.get(CLI_RAGSOC); - } - return __tmp; -} - -bool CausAlleg (const char * cod) -{ - TLocalisamfile caus(LF_CAUSALI); - bool allegb; - - caus.setkey(1); - caus.zero(); - caus.put(CAU_CODCAUS,cod); - caus.read(); - if (caus.bad()) - caus.zero(); - allegb = caus.get_bool(CAU_ALLEG); - - return allegb; -} - -const char * TipoAttivita (const char * attreg, long codice_ditta) -{ - TLocalisamfile attiv(LF_ATTIV); - - attiv.setkey(1); - attiv.zero(); - attiv.put(ATT_CODDITTA, codice_ditta); - attiv.put(ATT_CODATT, attreg); - - attiv.read(); - if (attiv.good()) - tmp = attiv.curr().get(ATT_TIPOATT); - else - tmp = ""; - - return __tmp; -} - -const char * SimboloValuta (const char * cod) -{ - TTable tab_val(TAB_VAL); - TString codtab = format ("%-3s", cod); - - tab_val.zero(); - - tab_val.put("CODTAB", codtab); - tab_val.read(); - if (tab_val.good()) - tmp = tab_val.get("S7"); - else - tmp = ""; - - return __tmp; -} - -const char * DescrDoc (const char * tipo) -{ - TTable tab_tpd(TAB_TPD); - TString codtab = format ("%-2s", tipo); - - tab_tpd.zero(); - - tab_tpd.put("CODTAB", codtab); - tab_tpd.read(); - if (tab_tpd.good()) - tmp = tab_tpd.get("S0"); - else - tmp = ""; - - return __tmp; -} - -const char * AttivitaRegistro (const char * cod, int anno) -{ - TTable tab_reg("REG"); - TString codtab ( format ("%04d%-3s", anno, cod) ); - - tab_reg.zero(); - - tab_reg.put("CODTAB", codtab); - tab_reg.read(); - - if (tab_reg.good()) - tmp = tab_reg.get("S8"); - else - tmp = ""; - - return __tmp; -} - -const int CodiceRegistro (const char* cod, int anno) -{ - TTable tab_reg("REG"); - TString codtab; - codtab.format("%4d%-3s", anno, cod); - //sprintf (__tmp, "%04d%-3s", anno, cod); - //TString codtab (__tmp); - int tipo_reg; - - tab_reg.zero(); - - tab_reg.put("CODTAB", codtab); - tab_reg.read(); - - if (tab_reg.good()) - tipo_reg = tab_reg.get_int("I0"); - else - tipo_reg = 0; - - return tipo_reg; -} - -bool filter_func_fatture (const TRelation * rel) -{ - CG3100_application * app = (CG3100_application*)MainApp(); - int tipo_reg; - int ann_reg; - TString cod_reg; - TLocalisamfile * mov = rel->lfile(LF_MOV); - TRectype from (mov->curr()); - TRectype to (mov->curr()); - ann_reg = mov->get_int (MOV_ANNOES); - cod_reg = mov->get (MOV_REG); - ann_reg = mov->get_int (MOV_ANNOES); - tipo_reg = CodiceRegistro (cod_reg, ann_reg); - from.zero(); - to.zero(); - if (app->_annoes != 0) - { - from.put(MOV_ANNOES, app->_annoes); - to.put(MOV_ANNOES, app->_annoes); - } - from.put(MOV_DATAREG, app->_data_ini); - from.put(MOV_TIPO, app->_tipo_ini); - if (app->_codice_ini != 0) - from.put(MOV_CODCF, app->_codice_ini); - to.put(MOV_DATAREG, app->_data_fin); - to.put(MOV_TIPO, app->_tipo_fin); - if (app->_codice_fin != 0) - to.put(MOV_CODCF, app->_codice_fin); - - if (((mov->curr() >= from) && (mov->curr() <= to)) && - ((tipo_reg == 1) || (tipo_reg == 2))) - return TRUE; - - return FALSE; -} - -bool filter_func (const TRelation * rel) -{ - CG3100_application * app = (CG3100_application*)MainApp(); - int tipo_reg, ann_reg; - TString cod_reg, causale; - TLocalisamfile * mov = rel->lfile(LF_MOV); - TRectype from (mov->curr()); - TRectype to (mov->curr()); - switch (app->_scelta_stampa) - { - case 0: - ann_reg = mov->get_int(MOV_ANNOES); - causale = mov->get (MOV_CODCAUS); - from.zero(); - to.zero(); - if (app->_annoes != 0) - { - from.put(MOV_ANNOES, app->_annoes); - to.put(MOV_ANNOES, app->_annoes); - } - from.put(MOV_CODCAUS, app->_causale_ini); - to.put(MOV_CODCAUS, app->_causale_fin); - from.put(MOV_REG, app->_registro_ini); - to.put(MOV_REG, app->_registro_fin); - if ((mov->curr() >= from) && (mov->curr() <= to)) - return TRUE; - break; - case 1: - cod_reg = mov->get (MOV_REG); - ann_reg = mov->get_int (MOV_ANNOES); - tipo_reg = CodiceRegistro(cod_reg, ann_reg); - causale = mov->get (MOV_CODCAUS); - from.zero(); - to.zero(); - if (app->_annoes != 0) - { - from.put(MOV_ANNOES, app->_annoes); - to.put(MOV_ANNOES, app->_annoes); - } - from.put(MOV_CODCAUS, app->_causale_ini); - to.put(MOV_CODCAUS, app->_causale_fin); - - if (((mov->curr() >= from) && (mov->curr() <= to)) && - ((tipo_reg != 1) && (tipo_reg != 2))) - return TRUE; - - break; - - default: - break; - } - return FALSE; -} - -void CG3100_application::stampa_errori_rmov() -{ - if (_scelta_stampa == 0) //stampa tutti i movimenti (iva e non) - { - if (_controllo_mov_errati != 3) - { - _nr = 2; - if (_descr == "") - { - reset_row(_nr); - set_row(_nr++, "@11g%s", ERR_66); - } - if (_stampa_mess_alleg_iva) - { - if (!_alleg_causale) - { - reset_row(_nr); - set_row(_nr++, "@11g%61s", MSG_20); - } - if ((_alleg == 1)||(_alleg == 2)) - { - reset_row(_nr); - set_row(_nr++, "@11g%s", MSG_31); - } - } - if (_err2 == ERR_1) - { - reset_row(_nr); - set_row(_nr++, "@11g%s",ERR_1); - } - if (_err == ERR_2) - { - reset_row(_nr); - set_row(_nr++, "@11g%s",ERR_2); - } - if (_msg == MSG_54) - { - reset_row(_nr); - set_row(_nr++, "@11g%s",MSG_54); - } - if (_err1 == ERR_09) - { - reset_row(_nr); - set_row(_nr, "@11g%s",ERR_09); - } - } - } - -} - -void CG3100_application::stampa_errori_mov() -{ - if (_scelta_stampa == 0) - { - if ((_controllo_mov_errati != 3)&&((_tiporegistro == 1)|| - (_tiporegistro == 2)))//controlli su movimenti iva - { - if (_caus->bad()) - set_row(++_n, "@11g%s", ERR_16); - - if (_tipodocumento != _tipodoc) - set_row(++_n, "@11g%s", MSG_19); - - if ((_stampa_mess_alleg_iva)&&(!_alleg_causale)) - set_row(++_n, "@11g%s", MSG_20); - - if (_tiporegistro == 0) - set_row(++_n, "@11g%s", ERR_21); - } - } -} +//Stampa movimenti -void CG3100_application::set_page(int file, int count) -{ - switch (_tipo_lista) - { - case movimenti: - if (file == LF_RMOVIVA) - break; - if (file == LF_RMOV) - { - _nr = 1; - set_row(_nr,"@3n",FLD(LF_RMOV,RMV_NUMRIG)); - set_row(_nr,"@5g@3s",FLD(LF_MOV,MOV_CODCAUS)); - set_row(_nr,"@9g#.20t", &_descr_causale); - set_row(_nr,"@31g@24s",FLD(LF_RMOV,RMV_DESCR)); - set_row(_nr,"@56g@4n",FLD(LF_RMOV,RMV_GRUPPO)); - set_row(_nr,"@61g@3n",FLD(LF_RMOV,RMV_CONTO)); - set_row(_nr,"@65g@6n",FLD(LF_RMOV,RMV_SOTTOCONTO)); - set_row(_nr,"@72g#.20t",&_descr); - _appoggio = current_cursor()->curr(LF_RMOV).get(RMV_SEZIONE); - if ((_appoggio=="D")||(_appoggio=="d")) - set_row(_nr,"@93g@pN",FLD(LF_RMOV,RMV_IMPORTO,"###.###.###.###")); - else - set_row(_nr,"@111g@pN",FLD(LF_RMOV,RMV_IMPORTO,"###.###.###.###")); - set_row(_nr,"@130g@f",FLD(LF_MOV,MOV_STAMPATO)); - } - else if (file == LF_MOV) - { - _n = 1; - set_row (_n, "Registrazione n. @18g@7n", FLD(LF_MOV,MOV_NUMREG)); - set_row (_n, "@26gdel@30g@d",FLD(LF_MOV,MOV_DATAREG)); - set_row (_n, "@41g@40s",FLD(LF_MOV,MOV_DESCR)); - set_row (_n, "@82gdocumento n.@95g@7s",FLD(LF_MOV,MOV_NUMDOC)); - set_row (_n, "@103gdel@107g@d", FLD(LF_MOV,MOV_DATADOC)); - set_row (_n, "@118g@4n", FLD(LF_MOV,MOV_ANNOES)); - set_row (_n, "@130g@f", FLD(LF_MOV,MOV_STAMPATO)); - } - break; - - case fatture: - break; - - case movimenti_sezionale: - break; - - default: - break; - } - -} - -void CG3100_application::stampa_intestazione() -{ - TString sep; - sep = ""; - set_row (1,(const char*)sep); - if (_tipo_elenco == "C") - set_row (2, "Cliente@9g@b@6n", FLD(LF_MOV,MOV_CODCF)); - else - set_row (2, "Fornitore@12g@b@6n", FLD(LF_MOV,MOV_CODCF)); - set_row (2, "@18g#35t", &_ragsoc); - set_row (2, "@54gInd #29t", &_indcf); - set_row (2, "@87g#10t", &_civcf); - set_row (2, "@98gP.I. #11t", &_paiv); - if (_alleg == 0) - set_row (2, "@121gAllegato NO"); - else - set_row (2, "@121gAllegato SI"); - set_row (3, "@54gCap #5t", &_capcf); - set_row (3,"@64gLoc #20t", &_dencom); - set_row (3,"@89gPr #5t", &_provcom); - set_row (3, "@98gC.F. #16t", &_cofi); - if (_alleg == 0) - set_row (3, "@120gRifer@126g#6d", _codalleg); -} - -bool CG3100_application::preprocess_page(int file,int counter) -{ - TCursor * cur = current_cursor(); - - if (counter) return TRUE; - - switch (_tipo_lista) - { - case movimenti: - if (_scelta_stampa == 0) - { - if (file == LF_MOV) - { - _tot_avere = 0; - _tot_dare = 0; - _c.destroy(); - _no_preprocess_page = FALSE; - _causale = current_cursor()->curr(LF_MOV).get(MOV_CODCAUS); - _registro = current_cursor()->curr(LF_MOV).get(MOV_REG); - _anno = current_cursor()->curr(LF_MOV).get_int(MOV_ANNOES); - _tipodoc = current_cursor()->curr(LF_MOV).get(MOV_TIPODOC); - _datareg = current_cursor()->file(LF_MOV)->get_date(MOV_DATAREG); - //TDate data_corrente (current_cursor()->file(LF_MOV)->get_date(MOV_DATAREG)); - _tiporegistro = CodiceRegistro(_registro, _anno); - - TLocalisamfile* fl = current_cursor()->file(LF_MOV); - TRectype da (fl->curr()); - TRectype a (fl->curr()); - da.zero(); - a.zero(); - if (_annoes != 0) - { - da.put(MOV_ANNOES, _annoes); - a.put(MOV_ANNOES, _annoes); - } - da.put(MOV_CODCAUS, _causale_ini); - da.put(MOV_REG, _registro_ini); - a.put(MOV_CODCAUS, _causale_fin); - a.put(MOV_REG, _registro_fin); - - if ((fl->curr() >= da) && (fl->curr() <= a)) - //&&((_tiporegistro == 1)||(_tiporegistro == 2))) - { - - _caus->setkey(1); - _caus->curr().put(CAU_CODCAUS,_causale); - _caus->read(); - if (_caus->bad()) - _caus->curr().zero(); - _descr_causale = _caus->curr().get(CAU_DESCR); - _alleg_causale = _caus->curr().get_bool(CAU_ALLEG); - _tipodocumento = _caus->curr().get(CAU_TIPODOC); - - if ( ((_controllo_mov_errati == 1)&&(segnala_errori_primariga())) - || (_controllo_mov_errati == 2)) - { - stampa_errori_mov(); - return TRUE; - } - else if ((_controllo_mov_errati == 1)&&(!segnala_errori_primariga())) - return FALSE; - else if (_controllo_mov_errati == 3) - return TRUE; - } - } - else if (file == LF_RMOV) - { - if (((_controllo_mov_errati == 1)&&(segnala_errori_ogniriga()))||(_controllo_mov_errati == 2)||(_controllo_mov_errati == 3)) - { - int gruppo = current_cursor()->curr(LF_RMOV).get_int(RMV_GRUPPO); - int conto = current_cursor()->curr(LF_RMOV).get_int(RMV_CONTO); - long sottoconto = current_cursor()->curr(LF_RMOV).get_long(RMV_SOTTOCONTO); - TString tipoc = current_cursor()->curr(LF_RMOV).get(RMV_TIPOC); - _descr = DescrConto(gruppo, conto, sottoconto, tipoc); - _alleg = AllegClifo(gruppo, conto, sottoconto); - _importo = current_cursor()->file(LF_RMOV)->get_real(RMV_IMPORTO); - _appoggio = current_cursor()->curr(LF_RMOV).get(RMV_SEZIONE); - if (!_no_preprocess_page) - { - if ((_appoggio=="D")||(_appoggio=="d")) - { - _tot_dare_generale += _importo; - _tot_dare += _importo; - } - else if ((_appoggio=="A")||(_appoggio=="a")) - { - _tot_avere += _importo; - _tot_avere_generale += _importo; - } - stampa_errori_rmov(); - } - return TRUE; - } - } - else if ((_stampa_parte_iva)&&(file == LF_RMOVIVA)) - { - TRectype iva(current_cursor()->file(LF_RMOVIVA)->curr()); - _impo = iva.get_real(RMI_IMPONIBILE); - _impos = iva.get_real(RMI_IMPOSTA); - _tipocr = iva.get_int(RMI_TIPOCR); - _tipod = iva.get_int(RMI_TIPODET); - _cod = iva.get(RMI_CODIVA); - if (_stampa_parte_iva) - _c.add_riga(_impo,_impos,_cod,_tipod,0.00,0.00); - - return TRUE; - } - } - else //_scelta_stampa == 1 - { - if (file == LF_MOV) - { - _tot_avere = 0; - _tot_dare = 0; - _no_preprocess_page = FALSE; - _causale = current_cursor()->curr(LF_MOV).get(MOV_CODCAUS); - _registro = current_cursor()->curr(LF_MOV).get(MOV_REG); - _anno = current_cursor()->curr(LF_MOV).get_int(MOV_ANNOES); - _tipodoc = current_cursor()->curr(LF_MOV).get(MOV_TIPODOC); - - TLocalisamfile* fl = current_cursor()->file(LF_MOV); - TRectype da (fl->curr()); - TRectype a (fl->curr()); - da.zero(); - a.zero(); - if (_annoes != 0) - { - da.put(MOV_ANNOES, _annoes); - a.put(MOV_ANNOES, _annoes); - } - da.put(MOV_CODCAUS, _causale_ini); - a.put(MOV_CODCAUS, _causale_fin); - - if ((fl->curr() >= da) && (fl->curr() <= a)) - /* - if ((_annoes == _anno) || (_annoes == 0)) - if ((_causale >= _causale_ini) && (_causale <= _causale_fin)) - */ - { - _caus->setkey(1); - _caus->curr().put(CAU_CODCAUS,_causale); - _caus->read(); - _descr_causale = _caus->curr().get(CAU_DESCR); - _alleg_causale = _caus->curr().get_bool(CAU_ALLEG); - _tipodocumento = _caus->curr().get(CAU_TIPODOC); - - _tiporegistro = CodiceRegistro (_registro, _anno); - - if ((_tiporegistro != 1)&&(_tiporegistro != 2))//se si tratta di un movimento di sola prima nota - return TRUE; - } - } - else - if (file == LF_RMOV) - { - long gruppo = atol(current_cursor()->curr(LF_RMOV).get(RMV_GRUPPO)); - long conto = atol(current_cursor()->curr(LF_RMOV).get(RMV_CONTO)); - long sottoconto = atol(current_cursor()->curr(LF_RMOV).get(RMV_SOTTOCONTO)); - TString tipoc = current_cursor()->curr(LF_RMOV).get(RMV_TIPOC); - _descr = DescrConto(gruppo, conto, sottoconto, tipoc); - _importo = current_cursor()->file(LF_RMOV)->get_real(RMV_IMPORTO); - _appoggio = current_cursor()->curr(LF_RMOV).get(RMV_SEZIONE); - if (!_no_preprocess_page) - { - if ((_appoggio=="D")||(_appoggio=="d")) - { - _tot_dare_generale += _importo; - _tot_dare += _importo; - } - - else if ((_appoggio=="A")||(_appoggio=="a")) - { - _tot_avere += _importo; - _tot_avere_generale += _importo; - } - } - return TRUE; - } - } - break; - - case fatture: - { - if (file == LF_MOV) - { - int anno = cur->curr(LF_MOV).get_int(MOV_ANNOES); - TString codreg = cur->curr(LF_MOV).get(MOV_REG); - - _tipo_elenco = current_cursor()->curr(LF_MOV).get(MOV_TIPO); - _codcf = current_cursor()->curr(LF_MOV).get_long(MOV_CODCF); - int tiporeg = CodiceRegistro (codreg, anno); - TString attreg = AttivitaRegistro (codreg, anno); - - if ((tiporeg == 1)||(tiporeg == 2))//se si tratta di un movimento iva - { - _tipoatt = TipoAttivita(attreg, get_firm()); - _tipo_elenco = cur->curr(LF_MOV).get(MOV_TIPO); - _codcf = cur->curr(LF_MOV).get_long(MOV_CODCF); - _codcaus = cur->curr(LF_MOV).get(MOV_CODCAUS); - _tipodoc = cur->curr(LF_MOV).get(MOV_TIPODOC); - _codval = cur->curr(LF_MOV).get(MOV_CODVAL); - _totdoc = cur->curr(LF_MOV).get_real(MOV_TOTDOC); - - if ((_tipo_elenco != _tipo_clifo_precedente) && - (_tipo_clifo_precedente != "") && _salto_pagina) - printer().formfeed(); - - TLocalisamfile* file = cur->file(LF_MOV); - TRectype da (file->curr()); - TRectype a (file->curr()); - da.zero(); - a.zero(); - - if (_annoes != 0) - { - da.put(MOV_ANNOES, _annoes); - a.put(MOV_ANNOES, _annoes); - } - da.put(MOV_DATAREG, _data_ini); - da.put(MOV_TIPO, _tipo_ini); - if (_codice_ini != 0) - da.put(MOV_CODCF, _codice_ini); - a.put(MOV_DATAREG, _data_fin); - a.put(MOV_TIPO, _tipo_fin); - if (_codice_fin != 0) - a.put(MOV_CODCF, _codice_fin); - - if ((file->curr() >= da) && (file->curr() <= a)) - { - compila_clifo(); - compila_comuni(); - - if ((_tipo_clifo_prec == "")&&(_codcf_prec == 0l)) - { - _tipo_clifo_prec = _tipo_elenco; - _codcf_prec = _codcf; - stampa_intestazione(); - } - else - if ((_tipo_clifo_prec != _tipo_elenco)&&(_codcf_prec != _codcf)) - { - stampa_intestazione(); - _tipo_clifo_prec = _tipo_elenco; - _codcf_prec = _codcf; - } - return TRUE; - } - } - } - else if (file == LF_RMOVIVA) - { - _simbolo = SimboloValuta(_codval); - _allegb = CausAlleg(_codcaus); - _descr_doc = DescrDoc(_tipodoc); - - _totdocumenti += _totdoc; - _ricser = current_cursor()->curr(LF_RMOVIVA).get_int(RMI_RICSER); - _intracom = current_cursor()->curr(LF_RMOVIVA).get_bool(RMI_INTRA); - // long numeroreg = cur->curr(LF_RMOVIVA).get_long(RMI_NUMREG); - - if ((_codval != "LIT") && _intracom) - { - reset_row(1); - set_row(1,"Corr.in lire@14g@pN",FLD(LF_RMOVIVA,RMI_CORRLIRE,"###.###.###.###")); - set_row(1,"@34gCorr.in valuta@49g@pN",FLD(LF_RMOVIVA,RMI_CORRVALUTA,"###.###.###.###")); - if (_simbolo.not_empty()) - set_row(1,"@65g%.5s", (const char *)_simbolo); - else - set_row(1,"@65g%.3s", (const char *)_codval); - } - else if (!_settata_prima_riga) - { - reset_row(1); - set_row(1,"@7n",FLD(LF_MOV,MOV_NUMREG)); - set_row(1,"@8g@d",FLD(LF_MOV,MOV_DATAREG)); - set_row(1,"@17g@3,rs",FLD(LF_MOV,MOV_REG)); - set_row(1,"@21g@5n",FLD(LF_MOV,MOV_PROTIVA)); - - TString protiva = cur->curr(LF_MOV).get(MOV_PROTIVA); - TString uprotiva = cur->curr(LF_MOV).get(MOV_UPROTIVA); - - if (uprotiva.not_empty()) - { - for (int i = 0; protiva[i] && (protiva[i] == uprotiva[i]); i++); - uprotiva = uprotiva.mid(i); - set_row(1, "@24g/@25g%s", (const char*) uprotiva); - } - set_row(1, "@33g@d", FLD(LF_MOV,MOV_DATADOC)); - set_row(1,"@42g@6,rs",FLD(LF_MOV,MOV_NUMDOC)); - set_row(1,"@49g@3s",FLD(LF_MOV,MOV_CODCAUS)); - set_row(1,"@53g@2s",FLD(LF_MOV,MOV_TIPODOC)); - set_row(1,"@56g%.11s", (const char *)_descr_doc); - set_row(1,"@68g@pN",FLD(LF_MOV,MOV_TOTDOC,"###.###.###.###")); - set_row(1,"@84g@pN",FLD(LF_RMOVIVA,RMI_IMPONIBILE,"###.###.###.###")); - set_row(1,"@101g@4s",FLD(LF_RMOVIVA,RMI_CODIVA)); - set_row(1,"@105g@1n",FLD(LF_RMOVIVA,RMI_TIPODET)); - if (_tipoatt == "E") - if (_ricser == 1) - set_row(1,"@109g1"); - else if (_ricser == 2) - set_row(1,"@109g2"); - set_row(1,"@111g@f",FLD(LF_RMOVIVA,RMI_INTRA)); - set_row(1,"@113g@pN",FLD(LF_RMOVIVA,RMI_IMPOSTA,"###.###.###.###")); - if (!_allegb) - set_row(1,"@131g*"); - - incrementa_totali(); - _settata_prima_riga = TRUE; - ++_documenti; - - } - else if (_settata_prima_riga) - { - reset_row(1); - set_row(1,"@84g@pN", FLD(LF_RMOVIVA,RMI_IMPONIBILE,"###.###.###.###")); - set_row(1,"@101g@4s", FLD(LF_RMOVIVA,RMI_CODIVA)); - set_row(1,"@113g@pN", FLD(LF_RMOVIVA,RMI_IMPOSTA,"###.###.###.###")); - incrementa_totali(); - } - return TRUE; - } - } - break; - - case movimenti_sezionale: - break; - - default: - break; - } - return FALSE; -} - -print_action CG3100_application::postprocess_page(int file,int count) -{ - if (count) - { - reset_print(); - return NEXT_PAGE; - } - switch (_tipo_lista) - { - case movimenti: +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cg3.h" +#include "cg3100.h" +#include "cg3401.h" + +const MAXSTR = 128; +static char __tmp [MAXSTR]; +static TFixed_string tmp (__tmp, MAXSTR); + +enum liste { + movimenti=1, + fatture=2, + movimenti_sezionale=3 + }; + +bool filter_func (const TRelation *); +bool filter_func_fatture (const TRelation *); + +class CG3100_application : public TPrintapp +{ + friend bool filter_func (const TRelation *); + friend bool filter_func_fatture (const TRelation *); + + TRigaiva_array _c; + TTable * _tabiva, * _tabtpd, * _tabreg; + TLocalisamfile * _caus,* _comuni,* _rmoviva, * _clifo, * _pcon, * _attiv; + TRelation * _relmov,* _relmov1,* _relmov2,* _relmov3; + TCursor * _curr1, * _curr2, * _curr3; + TDate _data_ini, _data_fin, _datareg, _data_prec; + TString _descr, _descr_doc, _descr_causale, _totali_a, _totali_d; + TString _totalegen_dare, _totalegen_avere, _tipo_ini, _masc, _causale; + TString _causale_ini, _causale_fin, _registro,_registro_ini, _registro_fin; + TString _tipoatt, _tipo_elenco,_tipo_clifo_prec,_cod,_tipoelsucc; + TString _tipo_clifo_precedente; + TString _appoggio, _tipodoc, _tipodocumento, _err1, _msg, _err, _err2; + TString _ragsoc, _indcf, _civcf, _paiv, _codcaus, _dencom, _provcom, _cofi; + TString _capcf, _codval, _simbolo, _statocf, _comcf, _tipo_fin; + long _documenti, _codice_ini, _codice_fin, _numero_reg,_codcf; + long _numreg, _numreg_fin, _numreg_ini, _codalleg, _numeroregp,_codclifosucc; + long _codcf_prec; + int _anno, _annoes; + real _totdocumenti, _totdoc, _totimponibile, _totimposta, _importo; + real _op_esenti, _op_non_imp, _impo, _impos; + real _tot_dare, _tot_avere, _tot_avere_giornaliero; + real _tot_dare_giornaliero, _tot_dare_generale, _tot_avere_generale; + bool _intracom, _no_preprocess_page, _salto_pagina; + bool _stampa_parte_iva,_alleg_causale,_stampa_mess_alleg_iva,_allegb,_ricser; + bool _settata_prima_riga; + int _cur1,_cur2,_cur2b,_cur3,_cur4,_decidi,_tipod,_controllo_mov_errati; + int _numero_riga, _alleg, _tiporegistro, _tipocr, _scelta_stampa, _nr, _n; + liste _tipo_lista; + word _flags; + +protected: + virtual void preprocess_header(); + virtual bool preprocess_page(int,int); + virtual print_action postprocess_page(int,int); + virtual print_action postprocess_print(int,int); + virtual void set_page(int,int); + virtual bool set_print(int m); + void init_print(const TMask& m); + +public: + + void user_create() ; + void user_destroy(); + bool segnala_errori_primariga(); + bool segnala_errori_ogniriga(); + void stampa_errori_rmov(); + void stampa_errori_mov(); + void stampa_intestazione(); + void incrementa_totali(); + void compila_clifo(); + void compila_comuni(); + int my_next (TLocalisamfile*); + + CG3100_application() {} +}; + +void CG3100_application::compila_clifo() +{ + _clifo->setkey(1); + _clifo->zero(); + _clifo->put(CLI_TIPOCF,_tipo_elenco); + _clifo->put(CLI_CODCF,_codcf); + _clifo->read(); + if (_clifo->bad()) + _clifo->zero(); + _alleg = _clifo->curr().get_int(CLI_ALLEG); + _statocf = _clifo->curr().get(CLI_STATOCF); + _comcf = _clifo->curr().get(CLI_COMCF); + _ragsoc = _clifo->curr().get(CLI_RAGSOC); + _indcf = _clifo->curr().get(CLI_INDCF); + _civcf = _clifo->curr().get(CLI_CIVCF); + _paiv = _clifo->curr().get(CLI_PAIV); + _capcf = _clifo->curr().get(CLI_CAPCF); + _cofi = _clifo->curr().get(CLI_COFI); + _codalleg = _clifo->curr().get_long(CLI_CODALLEG); +} + +void CG3100_application::compila_comuni() +{ + _comuni->setkey(1); + _comuni->zero(); + _comuni->put(COM_STATO,_statocf); + _comuni->put(COM_COM,_comcf); + _comuni->read(); + if (_comuni->bad()) + _comuni->curr().zero(); + _dencom = _comuni->get(COM_DENCOM); + _provcom = _comuni->get(COM_PROVCOM); +} + +const int AllegClifo (int gruppo, int conto, long sottoconto) +{ + TLocalisamfile clifo(LF_CLIFO); + int alleg; + + clifo.setkey(3); + clifo.zero(); + clifo.put(CLI_GRUPPO, gruppo); + clifo.put(CLI_CONTO, conto); + clifo.put(CLI_CODCF, sottoconto); + clifo.read(); + if (clifo.good()) + alleg = clifo.curr().get_int(CLI_ALLEG); + else + alleg = 0; + + return alleg; +} + +const char * DescrConto (long gruppo, long conto, long sottoconto, + const char* tipocf) +{ + TLocalisamfile pcon(LF_PCON); + TLocalisamfile clifo(LF_CLIFO); + + pcon.setkey(1); + pcon.zero(); + pcon.put(PCN_GRUPPO, gruppo); + if (conto != 0) + pcon.put(PCN_CONTO, conto); + if (sottoconto != 0) + pcon.put(PCN_SOTTOCONTO,sottoconto); + pcon.read(); + if (pcon.good()) + tmp = pcon.curr().get(PCN_DESCR); + else + { + clifo.setkey(1); + clifo.zero(); + clifo.put(CLI_CODCF, sottoconto); + clifo.put(CLI_TIPOCF,tipocf); + clifo.read(); + if (clifo.good()) + tmp = clifo.get(CLI_RAGSOC); + } + return __tmp; +} + +bool CausAlleg (const char * cod) +{ + TLocalisamfile caus(LF_CAUSALI); + bool allegb; + + caus.setkey(1); + caus.zero(); + caus.put(CAU_CODCAUS,cod); + caus.read(); + if (caus.bad()) + caus.zero(); + allegb = caus.get_bool(CAU_ALLEG); + + return allegb; +} + +const char * TipoAttivita (const char * attreg, long codice_ditta) +{ + TLocalisamfile attiv(LF_ATTIV); + + attiv.setkey(1); + attiv.zero(); + attiv.put(ATT_CODDITTA, codice_ditta); + attiv.put(ATT_CODATT, attreg); + + attiv.read(); + if (attiv.good()) + tmp = attiv.curr().get(ATT_TIPOATT); + else + tmp = ""; + + return __tmp; +} + +const char * SimboloValuta (const char * cod) +{ + TTable tab_val(TAB_VAL); + TString codtab = format ("%-3s", cod); + + tab_val.zero(); + + tab_val.put("CODTAB", codtab); + tab_val.read(); + if (tab_val.good()) + tmp = tab_val.get("S7"); + else + tmp = ""; + + return __tmp; +} + +const char * DescrDoc (const char * tipo) +{ + TTable tab_tpd(TAB_TPD); + TString codtab = format ("%-2s", tipo); + + tab_tpd.zero(); + + tab_tpd.put("CODTAB", codtab); + tab_tpd.read(); + if (tab_tpd.good()) + tmp = tab_tpd.get("S0"); + else + tmp = ""; + + return __tmp; +} + +const char * AttivitaRegistro (const char * cod, int anno) +{ + TTable tab_reg("REG"); + TString codtab ( format ("%04d%-3s", anno, cod) ); + + tab_reg.zero(); + + tab_reg.put("CODTAB", codtab); + tab_reg.read(); + + if (tab_reg.good()) + tmp = tab_reg.get("S8"); + else + tmp = ""; + + return __tmp; +} + +const int CodiceRegistro (const char* cod, int anno) +{ + TTable tab_reg("REG"); + TString codtab; + codtab.format("%4d%-3s", anno, cod); + //sprintf (__tmp, "%04d%-3s", anno, cod); + //TString codtab (__tmp); + int tipo_reg; + + tab_reg.zero(); + + tab_reg.put("CODTAB", codtab); + tab_reg.read(); + + if (tab_reg.good()) + tipo_reg = tab_reg.get_int("I0"); + else + tipo_reg = 0; + + return tipo_reg; +} + +bool filter_func_fatture (const TRelation * rel) +{ + CG3100_application * app = (CG3100_application*)MainApp(); + int tipo_reg; + int ann_reg; + TString cod_reg; + TLocalisamfile * mov = rel->lfile(LF_MOV); + TRectype from (mov->curr()); + TRectype to (mov->curr()); + ann_reg = mov->get_int (MOV_ANNOES); + cod_reg = mov->get (MOV_REG); + ann_reg = mov->get_int (MOV_ANNOES); + tipo_reg = CodiceRegistro (cod_reg, ann_reg); + from.zero(); + to.zero(); + if (app->_annoes != 0) + { + from.put(MOV_ANNOES, app->_annoes); + to.put(MOV_ANNOES, app->_annoes); + } + from.put(MOV_DATAREG, app->_data_ini); + from.put(MOV_TIPO, app->_tipo_ini); + if (app->_codice_ini != 0) + from.put(MOV_CODCF, app->_codice_ini); + to.put(MOV_DATAREG, app->_data_fin); + to.put(MOV_TIPO, app->_tipo_fin); + if (app->_codice_fin != 0) + to.put(MOV_CODCF, app->_codice_fin); + + if (((mov->curr() >= from) && (mov->curr() <= to)) && + ((tipo_reg == 1) || (tipo_reg == 2))) + return TRUE; + + return FALSE; +} + +bool filter_func (const TRelation * rel) +{ + CG3100_application * app = (CG3100_application*)MainApp(); + int tipo_reg, ann_reg; + TString cod_reg, causale; + TLocalisamfile * mov = rel->lfile(LF_MOV); + TRectype from (mov->curr()); + TRectype to (mov->curr()); + switch (app->_scelta_stampa) + { + case 0: + ann_reg = mov->get_int(MOV_ANNOES); + causale = mov->get (MOV_CODCAUS); + from.zero(); + to.zero(); + if (app->_annoes != 0) + { + from.put(MOV_ANNOES, app->_annoes); + to.put(MOV_ANNOES, app->_annoes); + } + from.put(MOV_CODCAUS, app->_causale_ini); + to.put(MOV_CODCAUS, app->_causale_fin); + from.put(MOV_REG, app->_registro_ini); + to.put(MOV_REG, app->_registro_fin); + if ((mov->curr() >= from) && (mov->curr() <= to)) + return TRUE; + break; + case 1: + cod_reg = mov->get (MOV_REG); + ann_reg = mov->get_int (MOV_ANNOES); + tipo_reg = CodiceRegistro(cod_reg, ann_reg); + causale = mov->get (MOV_CODCAUS); + from.zero(); + to.zero(); + if (app->_annoes != 0) + { + from.put(MOV_ANNOES, app->_annoes); + to.put(MOV_ANNOES, app->_annoes); + } + from.put(MOV_CODCAUS, app->_causale_ini); + to.put(MOV_CODCAUS, app->_causale_fin); + + if (((mov->curr() >= from) && (mov->curr() <= to)) && + ((tipo_reg != 1) && (tipo_reg != 2))) + return TRUE; + + break; + + default: + break; + } + return FALSE; +} + +void CG3100_application::stampa_errori_rmov() +{ + if (_scelta_stampa == 0) //stampa tutti i movimenti (iva e non) + { + if (_controllo_mov_errati != 3) + { + _nr = 2; + if (_descr == "") + { + reset_row(_nr); + set_row(_nr++, "@11g%s", ERR_66); + } + if (_stampa_mess_alleg_iva) + { + if (!_alleg_causale) + { + reset_row(_nr); + set_row(_nr++, "@11g%61s", MSG_20); + } + if ((_alleg == 1)||(_alleg == 2)) + { + reset_row(_nr); + set_row(_nr++, "@11g%s", MSG_31); + } + } + if (_err2 == ERR_1) + { + reset_row(_nr); + set_row(_nr++, "@11g%s",ERR_1); + } + if (_err == ERR_2) + { + reset_row(_nr); + set_row(_nr++, "@11g%s",ERR_2); + } + if (_msg == MSG_54) + { + reset_row(_nr); + set_row(_nr++, "@11g%s",MSG_54); + } + if (_err1 == ERR_09) + { + reset_row(_nr); + set_row(_nr, "@11g%s",ERR_09); + } + } + } + +} + +void CG3100_application::stampa_errori_mov() +{ + if (_scelta_stampa == 0) + { + if ((_controllo_mov_errati != 3)&&((_tiporegistro == 1)|| + (_tiporegistro == 2)))//controlli su movimenti iva + { + if (_caus->bad()) + set_row(++_n, "@11g%s", ERR_16); + + if (_tipodocumento != _tipodoc) + set_row(++_n, "@11g%s", MSG_19); + + if ((_stampa_mess_alleg_iva)&&(!_alleg_causale)) + set_row(++_n, "@11g%s", MSG_20); + + if (_tiporegistro == 0) + set_row(++_n, "@11g%s", ERR_21); + } + } +} + +void CG3100_application::set_page(int file, int count) +{ + switch (_tipo_lista) + { + case movimenti: + if (file == LF_RMOVIVA) + break; + if (file == LF_RMOV) + { + _nr = 1; + set_row(_nr,"@3n",FLD(LF_RMOV,RMV_NUMRIG)); + set_row(_nr,"@5g@3s",FLD(LF_MOV,MOV_CODCAUS)); + set_row(_nr,"@9g#.20t", &_descr_causale); + set_row(_nr,"@31g@24s",FLD(LF_RMOV,RMV_DESCR)); + set_row(_nr,"@56g@4n",FLD(LF_RMOV,RMV_GRUPPO)); + set_row(_nr,"@61g@3n",FLD(LF_RMOV,RMV_CONTO)); + set_row(_nr,"@65g@6n",FLD(LF_RMOV,RMV_SOTTOCONTO)); + set_row(_nr,"@72g#.20t",&_descr); + _appoggio = current_cursor()->curr(LF_RMOV).get(RMV_SEZIONE); + if ((_appoggio=="D")||(_appoggio=="d")) + set_row(_nr,"@93g@pN",FLD(LF_RMOV,RMV_IMPORTO,"###.###.###.###")); + else + set_row(_nr,"@111g@pN",FLD(LF_RMOV,RMV_IMPORTO,"###.###.###.###")); + set_row(_nr,"@130g@f",FLD(LF_MOV,MOV_STAMPATO)); + } + else if (file == LF_MOV) + { + _n = 1; + set_row (_n, "Registrazione n. @18g@7n", FLD(LF_MOV,MOV_NUMREG)); + set_row (_n, "@26gdel@30g@d",FLD(LF_MOV,MOV_DATAREG)); + set_row (_n, "@41g@40s",FLD(LF_MOV,MOV_DESCR)); + set_row (_n, "@82gdocumento n.@95g@7s",FLD(LF_MOV,MOV_NUMDOC)); + set_row (_n, "@103gdel@107g@d", FLD(LF_MOV,MOV_DATADOC)); + set_row (_n, "@118g@4n", FLD(LF_MOV,MOV_ANNOES)); + set_row (_n, "@130g@f", FLD(LF_MOV,MOV_STAMPATO)); + } + break; + + case fatture: + break; + + case movimenti_sezionale: + break; + + default: + break; + } + +} + +void CG3100_application::stampa_intestazione() +{ + TString sep; + sep = ""; + set_row (1,(const char*)sep); + if (_tipo_elenco == "C") + set_row (2, "Cliente@9g@b@6n", FLD(LF_MOV,MOV_CODCF)); + else + set_row (2, "Fornitore@12g@b@6n", FLD(LF_MOV,MOV_CODCF)); + set_row (2, "@18g#35t", &_ragsoc); + set_row (2, "@54gInd #29t", &_indcf); + set_row (2, "@87g#10t", &_civcf); + set_row (2, "@98gP.I. #11t", &_paiv); + if (_alleg == 0) + set_row (2, "@121gAllegato NO"); + else + set_row (2, "@121gAllegato SI"); + set_row (3, "@54gCap #5t", &_capcf); + set_row (3,"@64gLoc #20t", &_dencom); + set_row (3,"@89gPr #5t", &_provcom); + set_row (3, "@98gC.F. #16t", &_cofi); + if (_alleg == 0) + set_row (3, "@120gRifer@126g#6d", _codalleg); +} + +bool CG3100_application::preprocess_page(int file,int counter) +{ + TCursor * cur = current_cursor(); + + if (counter) return TRUE; + + switch (_tipo_lista) + { + case movimenti: + if (_scelta_stampa == 0) + { + if (file == LF_MOV) + { + _tot_avere = 0; + _tot_dare = 0; + _c.destroy(); + _no_preprocess_page = FALSE; + _causale = current_cursor()->curr(LF_MOV).get(MOV_CODCAUS); + _registro = current_cursor()->curr(LF_MOV).get(MOV_REG); + _anno = current_cursor()->curr(LF_MOV).get_int(MOV_ANNOES); + _tipodoc = current_cursor()->curr(LF_MOV).get(MOV_TIPODOC); + _datareg = current_cursor()->file(LF_MOV)->get_date(MOV_DATAREG); + //TDate data_corrente (current_cursor()->file(LF_MOV)->get_date(MOV_DATAREG)); + _tiporegistro = CodiceRegistro(_registro, _anno); + + TLocalisamfile* fl = current_cursor()->file(LF_MOV); + TRectype da (fl->curr()); + TRectype a (fl->curr()); + da.zero(); + a.zero(); + if (_annoes != 0) + { + da.put(MOV_ANNOES, _annoes); + a.put(MOV_ANNOES, _annoes); + } + da.put(MOV_CODCAUS, _causale_ini); + da.put(MOV_REG, _registro_ini); + a.put(MOV_CODCAUS, _causale_fin); + a.put(MOV_REG, _registro_fin); + + if ((fl->curr() >= da) && (fl->curr() <= a)) + //&&((_tiporegistro == 1)||(_tiporegistro == 2))) + { + + _caus->setkey(1); + _caus->curr().put(CAU_CODCAUS,_causale); + _caus->read(); + if (_caus->bad()) + _caus->curr().zero(); + _descr_causale = _caus->curr().get(CAU_DESCR); + _alleg_causale = _caus->curr().get_bool(CAU_ALLEG); + _tipodocumento = _caus->curr().get(CAU_TIPODOC); + + if ( ((_controllo_mov_errati == 1)&&(segnala_errori_primariga())) + || (_controllo_mov_errati == 2)) + { + stampa_errori_mov(); + return TRUE; + } + else if ((_controllo_mov_errati == 1)&&(!segnala_errori_primariga())) + return FALSE; + else if (_controllo_mov_errati == 3) + return TRUE; + } + } + else if (file == LF_RMOV) + { + if (((_controllo_mov_errati == 1)&&(segnala_errori_ogniriga()))||(_controllo_mov_errati == 2)||(_controllo_mov_errati == 3)) + { + int gruppo = current_cursor()->curr(LF_RMOV).get_int(RMV_GRUPPO); + int conto = current_cursor()->curr(LF_RMOV).get_int(RMV_CONTO); + long sottoconto = current_cursor()->curr(LF_RMOV).get_long(RMV_SOTTOCONTO); + TString tipoc = current_cursor()->curr(LF_RMOV).get(RMV_TIPOC); + _descr = DescrConto(gruppo, conto, sottoconto, tipoc); + _alleg = AllegClifo(gruppo, conto, sottoconto); + _importo = current_cursor()->file(LF_RMOV)->get_real(RMV_IMPORTO); + _appoggio = current_cursor()->curr(LF_RMOV).get(RMV_SEZIONE); + if (!_no_preprocess_page) + { + if ((_appoggio=="D")||(_appoggio=="d")) + { + _tot_dare_generale += _importo; + _tot_dare += _importo; + } + else if ((_appoggio=="A")||(_appoggio=="a")) + { + _tot_avere += _importo; + _tot_avere_generale += _importo; + } + stampa_errori_rmov(); + } + return TRUE; + } + } + else if ((_stampa_parte_iva)&&(file == LF_RMOVIVA)) + { + TRectype iva(current_cursor()->file(LF_RMOVIVA)->curr()); + _impo = iva.get_real(RMI_IMPONIBILE); + _impos = iva.get_real(RMI_IMPOSTA); + _tipocr = iva.get_int(RMI_TIPOCR); + _tipod = iva.get_int(RMI_TIPODET); + _cod = iva.get(RMI_CODIVA); + if (_stampa_parte_iva) + _c.add_riga(_impo,_impos,_cod,_tipod,0.00,0.00); + + return TRUE; + } + } + else //_scelta_stampa == 1 + { + if (file == LF_MOV) + { + _tot_avere = 0; + _tot_dare = 0; + _no_preprocess_page = FALSE; + _causale = current_cursor()->curr(LF_MOV).get(MOV_CODCAUS); + _registro = current_cursor()->curr(LF_MOV).get(MOV_REG); + _anno = current_cursor()->curr(LF_MOV).get_int(MOV_ANNOES); + _tipodoc = current_cursor()->curr(LF_MOV).get(MOV_TIPODOC); + + TLocalisamfile* fl = current_cursor()->file(LF_MOV); + TRectype da (fl->curr()); + TRectype a (fl->curr()); + da.zero(); + a.zero(); + if (_annoes != 0) + { + da.put(MOV_ANNOES, _annoes); + a.put(MOV_ANNOES, _annoes); + } + da.put(MOV_CODCAUS, _causale_ini); + a.put(MOV_CODCAUS, _causale_fin); + + if ((fl->curr() >= da) && (fl->curr() <= a)) + /* + if ((_annoes == _anno) || (_annoes == 0)) + if ((_causale >= _causale_ini) && (_causale <= _causale_fin)) + */ + { + _caus->setkey(1); + _caus->curr().put(CAU_CODCAUS,_causale); + _caus->read(); + _descr_causale = _caus->curr().get(CAU_DESCR); + _alleg_causale = _caus->curr().get_bool(CAU_ALLEG); + _tipodocumento = _caus->curr().get(CAU_TIPODOC); + + _tiporegistro = CodiceRegistro (_registro, _anno); + + if ((_tiporegistro != 1)&&(_tiporegistro != 2))//se si tratta di un movimento di sola prima nota + return TRUE; + } + } + else + if (file == LF_RMOV) + { + long gruppo = atol(current_cursor()->curr(LF_RMOV).get(RMV_GRUPPO)); + long conto = atol(current_cursor()->curr(LF_RMOV).get(RMV_CONTO)); + long sottoconto = atol(current_cursor()->curr(LF_RMOV).get(RMV_SOTTOCONTO)); + TString tipoc = current_cursor()->curr(LF_RMOV).get(RMV_TIPOC); + _descr = DescrConto(gruppo, conto, sottoconto, tipoc); + _importo = current_cursor()->file(LF_RMOV)->get_real(RMV_IMPORTO); + _appoggio = current_cursor()->curr(LF_RMOV).get(RMV_SEZIONE); + if (!_no_preprocess_page) + { + if ((_appoggio=="D")||(_appoggio=="d")) + { + _tot_dare_generale += _importo; + _tot_dare += _importo; + } + + else if ((_appoggio=="A")||(_appoggio=="a")) + { + _tot_avere += _importo; + _tot_avere_generale += _importo; + } + } + return TRUE; + } + } + break; + + case fatture: + { + if (file == LF_MOV) + { + int anno = cur->curr(LF_MOV).get_int(MOV_ANNOES); + TString codreg = cur->curr(LF_MOV).get(MOV_REG); + + _tipo_elenco = current_cursor()->curr(LF_MOV).get(MOV_TIPO); + _codcf = current_cursor()->curr(LF_MOV).get_long(MOV_CODCF); + int tiporeg = CodiceRegistro (codreg, anno); + TString attreg = AttivitaRegistro (codreg, anno); + + if ((tiporeg == 1)||(tiporeg == 2))//se si tratta di un movimento iva + { + _tipoatt = TipoAttivita(attreg, get_firm()); + _tipo_elenco = cur->curr(LF_MOV).get(MOV_TIPO); + _codcf = cur->curr(LF_MOV).get_long(MOV_CODCF); + _codcaus = cur->curr(LF_MOV).get(MOV_CODCAUS); + _tipodoc = cur->curr(LF_MOV).get(MOV_TIPODOC); + _codval = cur->curr(LF_MOV).get(MOV_CODVAL); + _totdoc = cur->curr(LF_MOV).get_real(MOV_TOTDOC); + + if ((_tipo_elenco != _tipo_clifo_precedente) && + (_tipo_clifo_precedente != "") && _salto_pagina) + printer().formfeed(); + + TLocalisamfile* file = cur->file(LF_MOV); + TRectype da (file->curr()); + TRectype a (file->curr()); + da.zero(); + a.zero(); + + if (_annoes != 0) + { + da.put(MOV_ANNOES, _annoes); + a.put(MOV_ANNOES, _annoes); + } + da.put(MOV_DATAREG, _data_ini); + da.put(MOV_TIPO, _tipo_ini); + if (_codice_ini != 0) + da.put(MOV_CODCF, _codice_ini); + a.put(MOV_DATAREG, _data_fin); + a.put(MOV_TIPO, _tipo_fin); + if (_codice_fin != 0) + a.put(MOV_CODCF, _codice_fin); + + if ((file->curr() >= da) && (file->curr() <= a)) + { + compila_clifo(); + compila_comuni(); + + if ((_tipo_clifo_prec == "")&&(_codcf_prec == 0l)) + { + _tipo_clifo_prec = _tipo_elenco; + _codcf_prec = _codcf; + stampa_intestazione(); + } + else + if ((_tipo_clifo_prec != _tipo_elenco)&&(_codcf_prec != _codcf)) + { + stampa_intestazione(); + _tipo_clifo_prec = _tipo_elenco; + _codcf_prec = _codcf; + } + return TRUE; + } + } + } + else if (file == LF_RMOVIVA) + { + _simbolo = SimboloValuta(_codval); + _allegb = CausAlleg(_codcaus); + _descr_doc = DescrDoc(_tipodoc); + + _totdocumenti += _totdoc; + _ricser = current_cursor()->curr(LF_RMOVIVA).get_int(RMI_RICSER); + _intracom = current_cursor()->curr(LF_RMOVIVA).get_bool(RMI_INTRA); + // long numeroreg = cur->curr(LF_RMOVIVA).get_long(RMI_NUMREG); + + if ((_codval != "LIT") && _intracom) + { + reset_row(1); + set_row(1,"Corr.in lire@14g@pN",FLD(LF_RMOVIVA,RMI_CORRLIRE,"###.###.###.###")); + set_row(1,"@34gCorr.in valuta@49g@pN",FLD(LF_RMOVIVA,RMI_CORRVALUTA,"###.###.###.###")); + if (_simbolo.not_empty()) + set_row(1,"@65g%.5s", (const char *)_simbolo); + else + set_row(1,"@65g%.3s", (const char *)_codval); + } + else if (!_settata_prima_riga) + { + reset_row(1); + set_row(1,"@7n",FLD(LF_MOV,MOV_NUMREG)); + set_row(1,"@8g@d",FLD(LF_MOV,MOV_DATAREG)); + set_row(1,"@17g@3,rs",FLD(LF_MOV,MOV_REG)); + set_row(1,"@21g@5n",FLD(LF_MOV,MOV_PROTIVA)); + + TString protiva = cur->curr(LF_MOV).get(MOV_PROTIVA); + TString uprotiva = cur->curr(LF_MOV).get(MOV_UPROTIVA); + + if (uprotiva.not_empty()) + { + for (int i = 0; protiva[i] && (protiva[i] == uprotiva[i]); i++); + uprotiva = uprotiva.mid(i); + set_row(1, "@24g/@25g%s", (const char*) uprotiva); + } + set_row(1, "@33g@d", FLD(LF_MOV,MOV_DATADOC)); + set_row(1,"@42g@6,rs",FLD(LF_MOV,MOV_NUMDOC)); + set_row(1,"@49g@3s",FLD(LF_MOV,MOV_CODCAUS)); + set_row(1,"@53g@2s",FLD(LF_MOV,MOV_TIPODOC)); + set_row(1,"@56g%.11s", (const char *)_descr_doc); + set_row(1,"@68g@pN",FLD(LF_MOV,MOV_TOTDOC,"###.###.###.###")); + set_row(1,"@84g@pN",FLD(LF_RMOVIVA,RMI_IMPONIBILE,"###.###.###.###")); + set_row(1,"@101g@4s",FLD(LF_RMOVIVA,RMI_CODIVA)); + set_row(1,"@105g@1n",FLD(LF_RMOVIVA,RMI_TIPODET)); + if (_tipoatt == "E") + if (_ricser == 1) + set_row(1,"@109g1"); + else if (_ricser == 2) + set_row(1,"@109g2"); + set_row(1,"@111g@f",FLD(LF_RMOVIVA,RMI_INTRA)); + set_row(1,"@113g@pN",FLD(LF_RMOVIVA,RMI_IMPOSTA,"###.###.###.###")); + if (!_allegb) + set_row(1,"@131g*"); + + incrementa_totali(); + _settata_prima_riga = TRUE; + ++_documenti; + + } + else if (_settata_prima_riga) + { + reset_row(1); + set_row(1,"@84g@pN", FLD(LF_RMOVIVA,RMI_IMPONIBILE,"###.###.###.###")); + set_row(1,"@101g@4s", FLD(LF_RMOVIVA,RMI_CODIVA)); + set_row(1,"@113g@pN", FLD(LF_RMOVIVA,RMI_IMPOSTA,"###.###.###.###")); + incrementa_totali(); + } + return TRUE; + } + } + break; + + case movimenti_sezionale: + break; + + default: + break; + } + return FALSE; +} + +print_action CG3100_application::postprocess_page(int file,int count) +{ + if (count) + { + reset_print(); + return NEXT_PAGE; + } + switch (_tipo_lista) + { + case movimenti: if (file == LF_RMOV) - force_setpage(); - break; - if (_scelta_stampa == 0) - { - if (file == LF_MOV) - { - if (_stampa_parte_iva) - { - int r = 0; - for (int j = 0; j < _c.items(); j++) - { - TRigaiva& riga = (TRigaiva&)_c[j]; - r = j+1; - set_row(r, "Imponibile@12g%15.0r", &riga._imponibile); - set_row(r, "@31gImposta@39g%15.0r", &riga._imposta); - set_row(r, "@58gCodice Iva@68g%3s", (const char*)riga._codiva); - switch (riga._tipodet) - { - case 0 : set_row(r, "@73gDetraibile"); - break; - case 1 : set_row(r, "@73gIndetraibile su op.es."); - break; - case 3 : set_row(r, "@73gPassaggi interni"); - break; - case 9 : set_row(r, "@73gIndetraibile art.19"); - break; - default: break; - } - } - _c.destroy(); - if (r > 0) - return REPEAT_PAGE; - else - return NEXT_PAGE; - } - } - } - break; - - case fatture: - if (file == LF_MOV) - { - TRecnotype pos, items; - bool FINITO = FALSE; - TLocalisamfile* mov; - - mov = current_cursor()->file(LF_MOV); - TCursor * cur = current_cursor(); - - pos = current_cursor()->pos(); - items = current_cursor()->items(); - - FINITO = (pos == items-1); - - if (!FINITO) - { - cur->save_status(); - ++(*cur); - _tipoelsucc = cur->file(LF_MOV)->get(MOV_TIPO); - _codclifosucc = cur->file(LF_MOV)->get_long(MOV_CODCF); - --(*cur); - cur->restore_status(); - } - - if (FINITO || (_tipo_elenco != _tipoelsucc)||(_codcf != _codclifosucc)) - { - reset_print(); - TString blank = ""; - set_row(1,(const char*)blank); - if ((_tipo_elenco == "C")||(_tipo_elenco == "c")) - set_row(2, "Totali Cliente@18gDocumenti Totale documenti@45gAllegati:@56gImponibile@75gImposta@94gop. esenti@112gop. non imp."); - else - set_row(2, "Totali Fornitore@18gDocumenti Totale documenti@47gAllegati:@56gImponibile@75gImposta@94gop. esenti@112gop. non imp."); - set_row(3, "@18g%9d", _documenti); - set_row(3, "@28g%r", &_totdocumenti); - set_row(3, "@56g%r", &_totimponibile); - set_row(3, "@75g%r", &_totimposta); - set_row(3, "@94g%r", &_op_esenti); - set_row(3, "@112g%r", &_op_non_imp); - _tipo_clifo_precedente = _tipo_elenco; - _totimposta = 0; - _totimponibile = 0; - _op_esenti = 0; - _op_non_imp = 0; - _documenti = 0; - _tipo_clifo_prec = ""; - _codcf_prec = 0l; - return REPEAT_PAGE; - } - } - else if (file == LF_RMOVIVA) - { - long numrec; - TLocalisamfile* rmoviva = current_cursor()->file(LF_RMOVIVA); - - _numreg = current_cursor()->file(LF_RMOVIVA)->get_long(MOV_NUMREG); - - TRecnotype recno = rmoviva->recno(); - rmoviva->next(); - //if (rmoviva->bad()) rmoviva->zero(); - numrec = rmoviva->get_long(RMI_NUMREG); - rmoviva->readat(recno); - - if (_numreg != numrec) - _settata_prima_riga = FALSE; - else - _settata_prima_riga = TRUE; - - } - - break; - - case movimenti_sezionale: - break; - - default: - break; - - } - return NEXT_PAGE; -} - - -int CG3100_application::my_next(TLocalisamfile * mov) -{ - int esito; - TString cod_reg, causale; - int tipo_reg; - int ann_reg; - - esito = mov->next(); - - switch (_scelta_stampa) - { - case 0: - return esito; - case 1: - while (!mov->eof()) - { - cod_reg = mov->get (MOV_REG); - ann_reg = mov->get_int (MOV_ANNOES); - causale = mov->get (MOV_CODCAUS); - - if ( ( ( _annoes != 0l) && (ann_reg != _annoes) ) - || ( (causale < (const char*)_causale_ini) || (causale > (const char*)_causale_fin)) ) - { - esito=mov->next(); - continue; - } - tipo_reg = CodiceRegistro (cod_reg, ann_reg); - if ( (tipo_reg != 1) && (tipo_reg != 2) ) - return esito; - - esito=mov->next(); - } - break; - - default: - break; - } - return esito; -} - -print_action CG3100_application::postprocess_print(int file,int count) -{ - if (count) - { - reset_print(); - return NEXT_PAGE; - } - - switch (_tipo_lista) - { - case movimenti: - if (file == LF_RMOV) - { - TRecnotype pos, items; - bool FINITO = FALSE; - - reset_print(); - int n = 1; - if ((_scelta_stampa == 0)&&(_controllo_mov_errati != 3)&&(_tot_dare != _tot_avere)) - set_row(n++, "@11g%s", ERR_77); - - TLocalisamfile* mov; - mov=current_cursor()->file(LF_MOV); - // nrec = mov->recno(); - - pos = current_cursor()->pos(); - items = current_cursor()->items(); - - FINITO = (pos == items-1); - - _datareg = current_cursor()->file(LF_MOV)->get_date(MOV_DATAREG); - _numreg = current_cursor()->file(LF_MOV)->get_long(MOV_NUMREG); - - TDate datarec (_datareg); - if (!FINITO) - { - TCursor * cur = current_cursor(); - cur->save_status(); - ++(*cur); - datarec = cur->file(LF_MOV)->get_date(MOV_DATAREG); - --(*cur); - cur->restore_status(); - } -/* - esito = my_next(mov); - if (esito == NOERR) - { - long numrec = mov->get_long(MOV_NUMREG); - datarec = mov->get_date(MOV_DATAREG); - } -*/ - // mov->readat(nrec); - - _tot_avere_giornaliero += _tot_avere; - _tot_dare_giornaliero += _tot_dare; - - //stampa i totali giornalieri - if ( FINITO || - (_datareg != datarec)||(_numreg == _numreg_fin)) - { - if (( (_scelta_stampa == 0) && (_controllo_mov_errati != 1) && (_decidi == 2)) || ((_scelta_stampa == 1)&&(_decidi == 2))) - { - TString data = _datareg.string(); - set_row(n, "@50gTotali del"); - set_row(n, "@61ggiorno %s", (const char *)data); - set_row(n, "@93g%r", &_tot_dare_giornaliero); - set_row(n++, "@111g%r", &_tot_avere_giornaliero); - _tot_avere_giornaliero = 0; - _tot_dare_giornaliero = 0; - - } - else if (((_scelta_stampa == 0)&&(_controllo_mov_errati != 1)&&(_decidi == 1)&&(FINITO)) || ((_scelta_stampa == 1)&&(_decidi == 1)&&(FINITO))) - { - TString sep; - sep = ""; - set_row (n,(const char*)sep); - set_row(++n, "@60gTotale generale"); - set_row(n, "@93g%r", &_tot_dare_generale); - set_row(n++, "@111g%r", &_tot_avere_generale); - } - } - - if (n == 1) - { - force_setpage(); - return NEXT_PAGE; - } - else - { - _no_preprocess_page = TRUE; - force_setpage(FALSE); - return REPEAT_PAGE; - } - - } - - break; - - case fatture: - break; - - case movimenti_sezionale: - break; - - default: - break; - } - return NEXT_PAGE; -} - -bool CG3100_application::segnala_errori_primariga() -{ - int tiporeg; - - if ((_tiporegistro == 1)||(_tiporegistro == 2)) - { - tiporeg = CodiceRegistro (_registro, _anno); - - if ( (tiporeg == 0) || - (_caus->bad()) || - (_tipodocumento != _tipodoc) || - ((_stampa_mess_alleg_iva) && (!_alleg_causale))) - return TRUE; - } - return FALSE; -} - - -bool CG3100_application::segnala_errori_ogniriga() -{ - bool trovato = FALSE; - TString dep1; - - if ((_tiporegistro == 1)||(_tiporegistro == 2)) - { - long record, numreg; - TLocalisamfile* rmoviva; - // int conta = 0; - - rmoviva = current_cursor()->file(LF_RMOVIVA); - _numreg = current_cursor()->file(LF_MOV)->get_long(MOV_NUMREG); - if (current_cursor()->is_first_match(LF_RMOVIVA)) - { - record = rmoviva->recno(); - rmoviva->zero(); - rmoviva->put(RMI_NUMREG, _numreg); - for (rmoviva->read(); !rmoviva->eof() ;rmoviva->next()) - { - _cod = rmoviva->get(RMI_CODIVA); - _tipod = rmoviva->get_int(RMI_TIPODET); - _impo = rmoviva->get_real(RMI_IMPONIBILE); - _impos = rmoviva->get_real(RMI_IMPOSTA); - _tipocr = rmoviva->get_int(RMI_TIPOCR); - numreg = rmoviva->get_long(RMI_NUMREG); - if (numreg != _numreg) - break; - else - { - if (_tiporegistro == 1) - switch (_tipocr) - { - case 2 : case 3: case 5: case 8: case 9: _err1 = ERR_09; - trovato = TRUE; - break; - default: break; - } - else - if (_tiporegistro == 2) - switch (_tipocr) - { - case 4: case 9: _err1 = ERR_09; - trovato = TRUE; - break; - default: break; - } - if (_tipodoc != "AN") - { - _tabiva->setkey(1); - _tabiva->zero(); - dep1.format("%-4s",(const char*) _cod); - _tabiva->put("CODTAB", (const char*)dep1); - _tabiva->read(); - if (_tabiva->good()) - { - //conta += 1; - TString colonnac = _tabiva->get("S7"); - TString colonnaf = _tabiva->get("S8"); - bool sospeso = _tabiva->get_bool("B2"); - if (sospeso) - { - _err = ERR_2; - trovato = TRUE; - } - else if ((_stampa_mess_alleg_iva)&&((colonnac==" ") - ||(colonnaf==" "))) - { - _msg = MSG_54; - trovato = TRUE; - } - // break; - } - else - _err2 = ERR_1; - } - - } - } - // if (conta) - // _err2 = ""; - rmoviva->readat (record); - } - } - return trovato; -} - -void CG3100_application::incrementa_totali() -{ - TString dep1; - real imponibile, imposta; - - imponibile = current_cursor()->file(LF_RMOVIVA)->get_real(RMI_IMPONIBILE); - imposta = current_cursor()->file(LF_RMOVIVA)->get_real(RMI_IMPOSTA); - TString codiva = current_cursor()->file(LF_RMOVIVA)->get(RMI_CODIVA); - _tabiva->zero(); - dep1.format("%-4s",(const char*) codiva); - _tabiva->put("CODTAB", (const char*)dep1); - _tabiva->read(); - if (_tabiva->bad()) - _tabiva->zero(); - if ((_tipo_elenco == "C")||(_tipo_elenco == "c")) - { - TString colonna = _tabiva->get("S7"); - if ((colonna == "1")||(colonna == "3")) - _totimposta += imposta; - if (colonna == "1") - _totimponibile += imponibile; - else - if (colonna == "3") - _op_esenti += imponibile; - } - else - { - TString colonna = _tabiva->get("S8"); - if ((colonna == "1")||(colonna == "3")||(colonna == "4")) - _totimposta += imposta; - if (colonna == "1") - _totimponibile += imponibile; - else - if (colonna == "3") - _op_esenti += imponibile; - else - if (colonna == "4") - _op_non_imp += imponibile; - } -} - -bool CG3100_application::set_print(int m) -{ - _masc = ""; - switch(m) - { - case 1: - _masc = "cg3100a"; - _tipo_lista = movimenti; - break; - case 2: - _masc = "cg3100b"; - _tipo_lista = fatture; - break; - case 3: - _masc = "cg3100c"; - _tipo_lista = movimenti_sezionale; - break; - default: - break; - } - - TMask msk(_masc); - if (msk.run() != K_ENTER) return FALSE; - - reset_files(); - TLocalisamfile* fl; - switch (_tipo_lista) - { - case movimenti: - { - _scelta_stampa = atoi(msk.get(F_MOVIMENTI)); - _annoes = msk.get_int (F_ANNO); - _decidi = msk.get_int(F_DECIDI); - _causale_ini = msk.get(F_CAUSALEINI); - _causale_fin = msk.get(F_CAUSALEFIN); - if (_scelta_stampa == 0) - { - _registro_ini = msk.get(F_REGISTROINI); - _registro_fin = msk.get(F_REGISTROFIN); - } - _numreg_ini = atol(msk.get(F_NUMEROINI)); - _data_ini = msk.get(F_DATAINI); - _data_fin = msk.get(F_DATAFIN); - _numreg_fin = atoi(msk.get(F_NUMEROFIN)); - bool provvis = msk.get_bool(F_STAMPAMOVP); - if (_decidi == 1) - { - select_cursor(_cur1); - if (!provvis) - _curr1->filter("(PROVVIS=\"\")"); - else _curr1->filter(""); - fl = current_cursor()->file(LF_MOV); - TRectype da (fl->curr()); - TRectype a (fl->curr()); - da.zero(); - a.zero(); - da.put(MOV_NUMREG, _numreg_ini); - a.put(MOV_NUMREG, _numreg_fin); - current_cursor()->setregion(&da,&a); - add_file(LF_MOV); - add_file(LF_RMOV,LF_MOV); - add_file(LF_RMOVIVA,LF_MOV); - } - else - { - select_cursor(_cur2); - if (!provvis) - _curr2->filter("(PROVVIS=\"\")"); else _curr2->filter(""); - fl = current_cursor()->file(LF_MOV); - TRectype da (fl->curr()); - TRectype a (fl->curr()); - da.zero(); - a.zero(); - da.put(MOV_DATAREG, _data_ini); - a.put(MOV_DATAREG, _data_fin); - current_cursor()->setregion(&da,&a); - add_file(LF_MOV); - add_file(LF_RMOV,LF_MOV); - add_file(LF_RMOVIVA,LF_MOV); - } - } - break; - - case fatture: - { - fl = current_cursor()->file(LF_MOV); - TString tipo = msk.get(F_TIPOELENCO); - bool movprov = msk.get_bool(F_STAMPAMOVP); - if ((tipo=="C")||(tipo=="F")) - { - _codice_ini = atol(msk.get(F_CODICEINI)); - _codice_fin = atol(msk.get(F_CODICEFIN)); - } - else - { - _codice_ini = atol(msk.get(F_CODICEINI1)); - _codice_fin = atol(msk.get(F_CODICEFIN1)); - } - - // _relmov->add(LF_MOV, "NUMREG=NUMREG",1, LF_RMOVIVA,100); //creo un alias per il file LF_MOV - if (tipo == "E") - { - _tipo_ini = "C"; - _tipo_fin = "F"; - } - else - { - _tipo_ini = tipo; - _tipo_fin = tipo; - } - select_cursor(_cur3); - if (!movprov) - _curr3->filter("(PROVVIS=\"\")"); - else _curr3->filter(""); - TRectype da (fl->curr()); - TRectype a (fl->curr()); - da.zero(); - a.zero(); - if (_codice_ini != 0) - da.put(MOV_CODCF, _codice_ini); - a.put(MOV_TIPO, _tipo_fin); - if (_codice_fin != 0) - a.put(MOV_CODCF, _codice_fin); - da.put(MOV_DATAREG, _data_ini); - a.put(MOV_DATAREG, _data_fin); - da.put(MOV_TIPO, _tipo_ini); - current_cursor()->setregion(&da,&a); - add_file(LF_MOV); - add_file(LF_RMOVIVA,LF_MOV); - - } - - break; - - - case movimenti_sezionale: - break; - - default: - break; - } - - init_print(msk); - - return TRUE; -} - - -void CG3100_application::user_create() -{ - _relmov1 = new TRelation (LF_MOV); - _relmov2 = new TRelation (LF_MOV); - _relmov3 = new TRelation (LF_MOV); - - _relmov1->add(LF_RMOV, "NUMREG=NUMREG",1); - _relmov1->add(LF_RMOVIVA, "NUMREG=NUMREG",1); - _relmov2->add(LF_RMOV, "NUMREG=NUMREG",1); - _relmov2->add(LF_RMOVIVA, "NUMREG=NUMREG",1); - _relmov3->add(LF_RMOVIVA, "NUMREG=NUMREG",1); - - _curr1 = new TCursor (_relmov1, "", 1); - _curr2 = new TCursor (_relmov2, "", 2); - _curr3 = new TCursor (_relmov3, "", 3); - - _cur1 = add_cursor (_curr1); - _cur2 = add_cursor (_curr2); - _cur3 = add_cursor (_curr3); - - _curr1->set_filterfunction (filter_func); - _curr2->set_filterfunction (filter_func); - _curr3->set_filterfunction (filter_func_fatture); - - _caus = new TLocalisamfile(LF_CAUSALI); - _clifo = new TLocalisamfile(LF_CLIFO); - _comuni = new TLocalisamfile(LF_COMUNI); - _attiv = new TLocalisamfile(LF_ATTIV); - _pcon = new TLocalisamfile(LF_PCON); - _rmoviva = new TLocalisamfile(LF_RMOVIVA); - _tabiva = new TTable(TAB_IVA); - _tabtpd = new TTable(TAB_TPD); - _tabreg = new TTable("REG"); -} - -void CG3100_application::user_destroy() // releasev e arrmask -{ - //delete _msk; - delete _relmov; - delete _clifo; - delete _caus; - delete _pcon; - delete _attiv; - delete _comuni; - delete _tabiva; - delete _tabreg; - delete _tabtpd; - delete _rmoviva; -} - -void CG3100_application::init_print(const TMask& msk) -{ - set_real_picture("###.###.###.###"); - - TDate data (msk.get(F_DATASTAMPA)); - printer().setdate(data); - - - switch (_tipo_lista) - { - case movimenti: - { - reset_print(); - _flags = 0; - _tot_dare_giornaliero = 0; - _tot_avere_giornaliero = 0; - _tot_dare_generale = 0; - _tot_avere_generale = 0; - if (_scelta_stampa == 0) - { - _annoes = msk.get_int(F_ANNO); - _stampa_parte_iva = (bool)(msk.get(F_STAMPA)=="X"); - if (_stampa_parte_iva) - _flags |= ST_DATI_IVA; - _stampa_mess_alleg_iva = (bool)(msk.get(F_ALLEGATO)=="X"); - if (_stampa_mess_alleg_iva) - _flags |= ST_MESS_ALLEG; - _controllo_mov_errati = atoi(msk.get(F_CONTROLLO)); - if (_controllo_mov_errati == 1) - _flags |= ST_SOLO_MOVERR; - else if (_controllo_mov_errati == 2) - _flags |= ST_CONTROLLO; - else _flags |= ST_SENZA_CONTR; - if ((_numreg_ini != 0)&&(_decidi == 1)) - _flags |= ST_NUMERO; - if ((_data_ini.ok())&&(_decidi == 2)) - _flags |= ST_DATA; - _causale_ini = msk.get(F_CAUSALEINI); - if (_causale_ini != "") - _flags |= ST_CAUSALE; - _registro_ini = msk.get(F_REGISTROINI); - if (_registro_ini != "") - _flags |= ST_REGISTRO; - if ((_data_fin.ok())&&(_decidi == 2)) - _flags |= ST_DATA; - if ((_numreg_fin != 0)&&(_decidi == 2)) - _flags |= ST_NUMERO; - _causale_fin = msk.get(F_CAUSALEFIN); - if (_causale_fin != "") - _flags |= ST_CAUSALE; - _registro_fin = msk.get(F_REGISTROFIN); - if (_registro_fin != "") - _flags |= ST_REGISTRO; - } - else //_scelta_stampa == 1 - { - _annoes = msk.get_int(F_ANNO); - if (_numreg_ini != 0) - _flags |= ST_NUMERO; - if (_data_ini.ok()) - _flags |= ST_DATA; - _causale_ini = msk.get(F_CAUSALEINI); - if (_causale_ini != "") - _flags |= ST_CAUSALE; - if (_data_fin.ok()) - _flags |= ST_DATA; - if (_numreg_fin != 0) - _flags |= ST_NUMERO; - _causale_fin = msk.get(F_CAUSALEFIN); - if (_causale_fin != "") - _flags |= ST_CAUSALE; - } - } - break; - - - case fatture: - { - _flags = 0; - { - reset_print(); - _settata_prima_riga = FALSE; - _tipo_clifo_prec = ""; - _tipo_clifo_precedente = ""; - _codcf_prec = 0l; - _numeroregp = 0; - _documenti = 0; - _totdocumenti = 0; - _totimponibile = 0; - _totimposta = 0; - _op_esenti = 0; - _op_non_imp = 0; - _annoes = msk.get_int(F_ANNO); - _salto_pagina = (bool)(msk.get(F_CAMBIO)=="X"); - _data_ini = msk.get(F_DATAINI); - if (_data_ini.ok()) - _flags |= ST_DATA; - _data_fin = msk.get(F_DATAFIN); - if (_data_fin.ok()) - _flags |= ST_DATA; - TString tipo = msk.get(F_TIPOELENCO); - if ((tipo=="C")||(tipo=="F")) - { - _codice_ini = atol(msk.get(F_CODICEINI)); - _codice_fin = atol(msk.get(F_CODICEFIN)); - } - else - { - _codice_ini = atol(msk.get(F_CODICEINI1)); - _codice_fin = atol(msk.get(F_CODICEFIN1)); - } - if (_codice_ini != 0) - _flags |= ST_CODICE; - if (_codice_fin != 0) - _flags |= ST_CODICE; - if (tipo == "E") - { - _tipo_ini = "C"; - _tipo_fin = "F"; - } - else - { - _tipo_ini = tipo; - _tipo_fin = tipo; - } - } - } - break; - - - case movimenti_sezionale: - break; - - default: - break; - } - -} - -void CG3100_application::preprocess_header() -{ - int soh; // riga d'inizio dell'intestazione - TString sep(132); - - reset_header(); - - soh=1; - - sep << "Ditta " << get_firm(); - sep.left_just(132); - - set_header (soh++, (const char*) sep); - - sep = "Studio "; - sep << "Data @< Pag. @#"; - - sep.right_just(127); - - switch (_tipo_lista) - { - case movimenti: - if (_scelta_stampa == 0) - { - sep.overwrite ("Lista movimenti"); - set_header (soh++, (const char*)sep); - if (_decidi == 2) - { - if (_flags & ST_DATA) - { - set_header (soh, "Dalla data@12g%s",_data_ini.string()); - set_header (soh, "@24galla data@34g%s",_data_fin.string()); - } - else - set_header (soh, "Completa in ordine di data"); - } - else - if (_flags & ST_NUMERO) - { - set_header (soh, "dal numero@12g%d", _numreg_ini); - set_header (soh, "@20gal numero@30g%d", _numreg_fin); - } - else - set_header (soh, "Completa in ordine di numero"); - if (_flags & ST_CAUSALE) - { - set_header (soh, "@46gdalla causale@60g%s",(const char*)_causale_ini); - set_header (soh++, "@64galla causale@77g%s",(const char*)_causale_fin); - } - else - set_header (soh++, " tutte le causali"); - if (_flags & ST_REGISTRO) - { - set_header (soh, "dal registro@14g%s",(const char*)_registro_ini); - set_header (soh, "@18gal registro@30g%s",(const char*)_registro_fin); - } - else - set_header (soh, "tutti i registri"); - if (_flags & ST_DATI_IVA) - set_header (soh, "@34gstampa dati iva"); - if (_flags & ST_CONTROLLO) - set_header (soh, "@50g(controllo movimenti)"); - else if (_flags & ST_SOLO_MOVERR) - set_header (soh, "@50g(solo movimenti errati)"); - else set_header (soh, "@50g(senza controllo movimenti)"); - if ((_flags & (ST_ANNO_COMP|ST_MESS_ALLEG)) == 1) - set_header (soh, "@78gcon messaggi: anno di competenza, allegato iva"); - else if (_flags & ST_ANNO_COMP) - set_header (soh, "@78gcon messaggi: anno di competenza"); - else if (_flags & ST_MESS_ALLEG) - set_header (soh, "@78gcon messaggi: allegato iva"); - sep.fill('-'); - set_header (++soh, (const char *) sep); - set_header (++soh, "Rg Cod Causale@30gDescrizione@56gCodice conto@72gDescrizione conto@93gDare@112gAvere@130gSB"); - } - else - { - sep.overwrite ("Lista movimenti di sola prima nota"); - set_header (soh++, (const char*)sep); - if (_flags & ST_DATA) - { - set_header (soh, "Dalla data@12g%s",_data_ini.string()); - set_header (soh, "@24galla data@34g%s",_data_fin.string()); - } - else - set_header (soh, "Completa in ordine di data"); - if (_flags & ST_NUMERO) - { - set_header (soh, "@46gdal numero@57g%d", (const char*)_numreg_ini); - set_header (soh, "@65gal numero@75g%d",(const char*)_numreg_fin); - } - else - set_header (soh, "@46gcompleta in ordine di numero"); - if (_flags & ST_CAUSALE) - { - set_header(soh, "@86gdalla causale@100g%3s",(const char*)_causale_ini); - set_header(soh++,"@103galla causale@116g%3s",(const char*)_causale_fin); - } - else - set_header (soh++, "@86gtutte le causali"); - sep.fill('-'); - set_header (soh++, (const char *) sep); - set_header (soh++, "Rg Cod Causale@30gDescrizione@56gCodice conto@72gDescrizione conto@93gDare@112gAvere@130gSB"); - } - break; - - case fatture: - sep.overwrite ("Lista fatture"); - set_header (soh, (const char*)sep); - if (_flags & ST_DATA) - { - set_header (soh, "@15gdalla data@26g%s",_data_ini.string()); - set_header (soh, "@37galla data@47g%s",_data_fin.string()); - } - else - set_header (soh, "@15gcompleta in ordine di data"); - if (_flags & ST_CODICE) - { - set_header (soh, "@99gdal codice@110g%d",_codice_ini); - set_header (soh, "@117gal codice@127g%d",_codice_fin); - } - sep.fill('-'); - set_header (++soh, (const char *) sep); - set_header (++soh, "Registrazione @17gCod Protoc. Documento@49gCod Tp @68gTotale@101gCd Tp T O@129gNo"); - set_header (++soh, "Numero Data@17gReg Numero Data@42gNumero@49gCau Dc @56gDescrizione@68gDocumento@84gImponibile @101gIv Det A I@113gImposta@129gAll"); - break; - - case movimenti_sezionale: - sep.fill(' '); - sep.overwrite ("Lista movimenti di solo sezionale"); - set_header (soh++, (const char*)sep); - sep.fill('-'); - set_header (soh++, (const char *) sep); - break; - - default: - break; - } - set_header (++soh,(const char*)sep); - if (_tipo_lista != fatture) - { - sep = ""; - set_header (++soh,(const char*)sep); - } -} - -int cg3100(int argc, char* argv[]) -{ - CG3100_application a; - a.run(argc, argv, "Stampa movimenti"); - return 0; -} - - + force_setpage(); + break; + if (_scelta_stampa == 0) + { + if (file == LF_MOV) + { + if (_stampa_parte_iva) + { + int r = 0; + for (int j = 0; j < _c.items(); j++) + { + TRigaiva& riga = (TRigaiva&)_c[j]; + r = j+1; + set_row(r, "Imponibile@12g%15.0r", &riga._imponibile); + set_row(r, "@31gImposta@39g%15.0r", &riga._imposta); + set_row(r, "@58gCodice Iva@68g%3s", (const char*)riga._codiva); + switch (riga._tipodet) + { + case 0 : set_row(r, "@73gDetraibile"); + break; + case 1 : set_row(r, "@73gIndetraibile su op.es."); + break; + case 3 : set_row(r, "@73gPassaggi interni"); + break; + case 9 : set_row(r, "@73gIndetraibile art.19"); + break; + default: break; + } + } + _c.destroy(); + if (r > 0) + return REPEAT_PAGE; + else + return NEXT_PAGE; + } + } + } + break; + + case fatture: + if (file == LF_MOV) + { + TRecnotype pos, items; + bool FINITO = FALSE; + TLocalisamfile* mov; + + mov = current_cursor()->file(LF_MOV); + TCursor * cur = current_cursor(); + + pos = current_cursor()->pos(); + items = current_cursor()->items(); + + FINITO = (pos == items-1); + + if (!FINITO) + { + cur->save_status(); + ++(*cur); + _tipoelsucc = cur->file(LF_MOV)->get(MOV_TIPO); + _codclifosucc = cur->file(LF_MOV)->get_long(MOV_CODCF); + --(*cur); + cur->restore_status(); + } + + if (FINITO || (_tipo_elenco != _tipoelsucc)||(_codcf != _codclifosucc)) + { + reset_print(); + TString blank = ""; + set_row(1,(const char*)blank); + if ((_tipo_elenco == "C")||(_tipo_elenco == "c")) + set_row(2, "Totali Cliente@18gDocumenti Totale documenti@45gAllegati:@56gImponibile@75gImposta@94gop. esenti@112gop. non imp."); + else + set_row(2, "Totali Fornitore@18gDocumenti Totale documenti@47gAllegati:@56gImponibile@75gImposta@94gop. esenti@112gop. non imp."); + set_row(3, "@18g%9d", _documenti); + set_row(3, "@28g%r", &_totdocumenti); + set_row(3, "@56g%r", &_totimponibile); + set_row(3, "@75g%r", &_totimposta); + set_row(3, "@94g%r", &_op_esenti); + set_row(3, "@112g%r", &_op_non_imp); + _tipo_clifo_precedente = _tipo_elenco; + _totimposta = 0; + _totimponibile = 0; + _op_esenti = 0; + _op_non_imp = 0; + _documenti = 0; + _tipo_clifo_prec = ""; + _codcf_prec = 0l; + return REPEAT_PAGE; + } + } + else if (file == LF_RMOVIVA) + { + long numrec; + TLocalisamfile* rmoviva = current_cursor()->file(LF_RMOVIVA); + + _numreg = current_cursor()->file(LF_RMOVIVA)->get_long(MOV_NUMREG); + + TRecnotype recno = rmoviva->recno(); + rmoviva->next(); + //if (rmoviva->bad()) rmoviva->zero(); + numrec = rmoviva->get_long(RMI_NUMREG); + rmoviva->readat(recno); + + if (_numreg != numrec) + _settata_prima_riga = FALSE; + else + _settata_prima_riga = TRUE; + + } + + break; + + case movimenti_sezionale: + break; + + default: + break; + + } + return NEXT_PAGE; +} + + +int CG3100_application::my_next(TLocalisamfile * mov) +{ + int esito; + TString cod_reg, causale; + int tipo_reg; + int ann_reg; + + esito = mov->next(); + + switch (_scelta_stampa) + { + case 0: + return esito; + case 1: + while (!mov->eof()) + { + cod_reg = mov->get (MOV_REG); + ann_reg = mov->get_int (MOV_ANNOES); + causale = mov->get (MOV_CODCAUS); + + if ( ( ( _annoes != 0l) && (ann_reg != _annoes) ) + || ( (causale < (const char*)_causale_ini) || (causale > (const char*)_causale_fin)) ) + { + esito=mov->next(); + continue; + } + tipo_reg = CodiceRegistro (cod_reg, ann_reg); + if ( (tipo_reg != 1) && (tipo_reg != 2) ) + return esito; + + esito=mov->next(); + } + break; + + default: + break; + } + return esito; +} + +print_action CG3100_application::postprocess_print(int file,int count) +{ + if (count) + { + reset_print(); + return NEXT_PAGE; + } + + switch (_tipo_lista) + { + case movimenti: + if (file == LF_RMOV) + { + TRecnotype pos, items; + bool FINITO = FALSE; + + reset_print(); + int n = 1; + if ((_scelta_stampa == 0)&&(_controllo_mov_errati != 3)&&(_tot_dare != _tot_avere)) + set_row(n++, "@11g%s", ERR_77); + + TLocalisamfile* mov; + mov=current_cursor()->file(LF_MOV); + // nrec = mov->recno(); + + pos = current_cursor()->pos(); + items = current_cursor()->items(); + + FINITO = (pos == items-1); + + _datareg = current_cursor()->file(LF_MOV)->get_date(MOV_DATAREG); + _numreg = current_cursor()->file(LF_MOV)->get_long(MOV_NUMREG); + + TDate datarec (_datareg); + if (!FINITO) + { + TCursor * cur = current_cursor(); + cur->save_status(); + ++(*cur); + datarec = cur->file(LF_MOV)->get_date(MOV_DATAREG); + --(*cur); + cur->restore_status(); + } + /* + esito = my_next(mov); + if (esito == NOERR) + { + long numrec = mov->get_long(MOV_NUMREG); + datarec = mov->get_date(MOV_DATAREG); + } + */ + // mov->readat(nrec); + + _tot_avere_giornaliero += _tot_avere; + _tot_dare_giornaliero += _tot_dare; + + //stampa i totali giornalieri + if ( FINITO || + (_datareg != datarec)||(_numreg == _numreg_fin)) + { + if (( (_scelta_stampa == 0) && (_controllo_mov_errati != 1) && (_decidi == 2)) || ((_scelta_stampa == 1)&&(_decidi == 2))) + { + TString data = _datareg.string(); + set_row(n, "@50gTotali del"); + set_row(n, "@61ggiorno %s", (const char *)data); + set_row(n, "@93g%r", &_tot_dare_giornaliero); + set_row(n++, "@111g%r", &_tot_avere_giornaliero); + _tot_avere_giornaliero = 0; + _tot_dare_giornaliero = 0; + + } + else if (((_scelta_stampa == 0)&&(_controllo_mov_errati != 1)&&(_decidi == 1)&&(FINITO)) || ((_scelta_stampa == 1)&&(_decidi == 1)&&(FINITO))) + { + TString sep; + sep = ""; + set_row (n,(const char*)sep); + set_row(++n, "@60gTotale generale"); + set_row(n, "@93g%r", &_tot_dare_generale); + set_row(n++, "@111g%r", &_tot_avere_generale); + } + } + + if (n == 1) + { + force_setpage(); + return NEXT_PAGE; + } + else + { + _no_preprocess_page = TRUE; + force_setpage(FALSE); + return REPEAT_PAGE; + } + + } + + break; + + case fatture: + break; + + case movimenti_sezionale: + break; + + default: + break; + } + return NEXT_PAGE; +} + +bool CG3100_application::segnala_errori_primariga() +{ + int tiporeg; + + if ((_tiporegistro == 1)||(_tiporegistro == 2)) + { + tiporeg = CodiceRegistro (_registro, _anno); + + if ( (tiporeg == 0) || + (_caus->bad()) || + (_tipodocumento != _tipodoc) || + ((_stampa_mess_alleg_iva) && (!_alleg_causale))) + return TRUE; + } + return FALSE; +} + + +bool CG3100_application::segnala_errori_ogniriga() +{ + bool trovato = FALSE; + TString dep1; + + if ((_tiporegistro == 1)||(_tiporegistro == 2)) + { + long record, numreg; + TLocalisamfile* rmoviva; + // int conta = 0; + + rmoviva = current_cursor()->file(LF_RMOVIVA); + _numreg = current_cursor()->file(LF_MOV)->get_long(MOV_NUMREG); + if (current_cursor()->is_first_match(LF_RMOVIVA)) + { + record = rmoviva->recno(); + rmoviva->zero(); + rmoviva->put(RMI_NUMREG, _numreg); + for (rmoviva->read(); !rmoviva->eof() ;rmoviva->next()) + { + _cod = rmoviva->get(RMI_CODIVA); + _tipod = rmoviva->get_int(RMI_TIPODET); + _impo = rmoviva->get_real(RMI_IMPONIBILE); + _impos = rmoviva->get_real(RMI_IMPOSTA); + _tipocr = rmoviva->get_int(RMI_TIPOCR); + numreg = rmoviva->get_long(RMI_NUMREG); + if (numreg != _numreg) + break; + else + { + if (_tiporegistro == 1) + switch (_tipocr) + { + case 2 : case 3: case 5: case 8: case 9: _err1 = ERR_09; + trovato = TRUE; + break; + default: break; + } + else + if (_tiporegistro == 2) + switch (_tipocr) + { + case 4: case 9: _err1 = ERR_09; + trovato = TRUE; + break; + default: break; + } + if (_tipodoc != "AN") + { + _tabiva->setkey(1); + _tabiva->zero(); + dep1.format("%-4s",(const char*) _cod); + _tabiva->put("CODTAB", (const char*)dep1); + _tabiva->read(); + if (_tabiva->good()) + { + //conta += 1; + TString colonnac = _tabiva->get("S7"); + TString colonnaf = _tabiva->get("S8"); + bool sospeso = _tabiva->get_bool("B2"); + if (sospeso) + { + _err = ERR_2; + trovato = TRUE; + } + else if ((_stampa_mess_alleg_iva)&&((colonnac==" ") + ||(colonnaf==" "))) + { + _msg = MSG_54; + trovato = TRUE; + } + // break; + } + else + _err2 = ERR_1; + } + + } + } + // if (conta) + // _err2 = ""; + rmoviva->readat (record); + } + } + return trovato; +} + +void CG3100_application::incrementa_totali() +{ + TString dep1; + real imponibile, imposta; + + imponibile = current_cursor()->file(LF_RMOVIVA)->get_real(RMI_IMPONIBILE); + imposta = current_cursor()->file(LF_RMOVIVA)->get_real(RMI_IMPOSTA); + TString codiva = current_cursor()->file(LF_RMOVIVA)->get(RMI_CODIVA); + _tabiva->zero(); + dep1.format("%-4s",(const char*) codiva); + _tabiva->put("CODTAB", (const char*)dep1); + _tabiva->read(); + if (_tabiva->bad()) + _tabiva->zero(); + if ((_tipo_elenco == "C")||(_tipo_elenco == "c")) + { + TString colonna = _tabiva->get("S7"); + if ((colonna == "1")||(colonna == "3")) + _totimposta += imposta; + if (colonna == "1") + _totimponibile += imponibile; + else + if (colonna == "3") + _op_esenti += imponibile; + } + else + { + TString colonna = _tabiva->get("S8"); + if ((colonna == "1")||(colonna == "3")||(colonna == "4")) + _totimposta += imposta; + if (colonna == "1") + _totimponibile += imponibile; + else + if (colonna == "3") + _op_esenti += imponibile; + else + if (colonna == "4") + _op_non_imp += imponibile; + } +} + +bool CG3100_application::set_print(int m) +{ + _masc = ""; + switch(m) + { + case 1: + _masc = "cg3100a"; + _tipo_lista = movimenti; + break; + case 2: + _masc = "cg3100b"; + _tipo_lista = fatture; + break; + case 3: + _masc = "cg3100c"; + _tipo_lista = movimenti_sezionale; + break; + default: + break; + } + + TMask msk(_masc); + if (msk.run() != K_ENTER) return FALSE; + + reset_files(); + TLocalisamfile* fl; + switch (_tipo_lista) + { + case movimenti: + { + _scelta_stampa = atoi(msk.get(F_MOVIMENTI)); + _annoes = msk.get_int (F_ANNO); + _decidi = msk.get_int(F_DECIDI); + _causale_ini = msk.get(F_CAUSALEINI); + _causale_fin = msk.get(F_CAUSALEFIN); + if (_scelta_stampa == 0) + { + _registro_ini = msk.get(F_REGISTROINI); + _registro_fin = msk.get(F_REGISTROFIN); + } + _numreg_ini = atol(msk.get(F_NUMEROINI)); + _data_ini = msk.get(F_DATAINI); + _data_fin = msk.get(F_DATAFIN); + _numreg_fin = atoi(msk.get(F_NUMEROFIN)); + bool provvis = msk.get_bool(F_STAMPAMOVP); + if (_decidi == 1) + { + select_cursor(_cur1); + if (!provvis) + _curr1->setfilter("(PROVVIS=\"\")"); + else _curr1->setfilter(""); + fl = current_cursor()->file(LF_MOV); + TRectype da (fl->curr()); + TRectype a (fl->curr()); + da.zero(); + a.zero(); + da.put(MOV_NUMREG, _numreg_ini); + a.put(MOV_NUMREG, _numreg_fin); + current_cursor()->setregion(da,a); + add_file(LF_MOV); + add_file(LF_RMOV,LF_MOV); + add_file(LF_RMOVIVA,LF_MOV); + } + else + { + select_cursor(_cur2); + if (!provvis) + _curr2->setfilter("(PROVVIS=\"\")"); else _curr2->setfilter(""); + fl = current_cursor()->file(LF_MOV); + TRectype da (fl->curr()); + TRectype a (fl->curr()); + da.zero(); + a.zero(); + da.put(MOV_DATAREG, _data_ini); + a.put(MOV_DATAREG, _data_fin); + current_cursor()->setregion(da,a); + add_file(LF_MOV); + add_file(LF_RMOV,LF_MOV); + add_file(LF_RMOVIVA,LF_MOV); + } + } + break; + + case fatture: +{ + fl = current_cursor()->file(LF_MOV); + TString tipo = msk.get(F_TIPOELENCO); + bool movprov = msk.get_bool(F_STAMPAMOVP); + if ((tipo=="C")||(tipo=="F")) + { + _codice_ini = atol(msk.get(F_CODICEINI)); + _codice_fin = atol(msk.get(F_CODICEFIN)); + } + else + { + _codice_ini = atol(msk.get(F_CODICEINI1)); + _codice_fin = atol(msk.get(F_CODICEFIN1)); + } + + // _relmov->add(LF_MOV, "NUMREG=NUMREG",1, LF_RMOVIVA,100); //creo un alias per il file LF_MOV + if (tipo == "E") + { + _tipo_ini = "C"; + _tipo_fin = "F"; + } + else + { + _tipo_ini = tipo; + _tipo_fin = tipo; + } + select_cursor(_cur3); + if (!movprov) + _curr3->setfilter("(PROVVIS=\"\")"); + else _curr3->setfilter(""); + TRectype da (fl->curr()); + TRectype a (fl->curr()); + da.zero(); + a.zero(); + if (_codice_ini != 0) + da.put(MOV_CODCF, _codice_ini); + a.put(MOV_TIPO, _tipo_fin); + if (_codice_fin != 0) + a.put(MOV_CODCF, _codice_fin); + da.put(MOV_DATAREG, _data_ini); + a.put(MOV_DATAREG, _data_fin); + da.put(MOV_TIPO, _tipo_ini); + current_cursor()->setregion(da,a); + add_file(LF_MOV); + add_file(LF_RMOVIVA,LF_MOV); + +} + +break; + + + case movimenti_sezionale: + break; + +default: +break; +} + +init_print(msk); + +return TRUE; +} + + +void CG3100_application::user_create() +{ + _relmov1 = new TRelation (LF_MOV); + _relmov2 = new TRelation (LF_MOV); + _relmov3 = new TRelation (LF_MOV); + + _relmov1->add(LF_RMOV, "NUMREG=NUMREG",1); + _relmov1->add(LF_RMOVIVA, "NUMREG=NUMREG",1); + _relmov2->add(LF_RMOV, "NUMREG=NUMREG",1); + _relmov2->add(LF_RMOVIVA, "NUMREG=NUMREG",1); + _relmov3->add(LF_RMOVIVA, "NUMREG=NUMREG",1); + + _curr1 = new TCursor (_relmov1, "", 1); + _curr2 = new TCursor (_relmov2, "", 2); + _curr3 = new TCursor (_relmov3, "", 3); + + _cur1 = add_cursor (_curr1); + _cur2 = add_cursor (_curr2); + _cur3 = add_cursor (_curr3); + + _curr1->set_filterfunction (filter_func); + _curr2->set_filterfunction (filter_func); + _curr3->set_filterfunction (filter_func_fatture); + + _caus = new TLocalisamfile(LF_CAUSALI); + _clifo = new TLocalisamfile(LF_CLIFO); + _comuni = new TLocalisamfile(LF_COMUNI); + _attiv = new TLocalisamfile(LF_ATTIV); + _pcon = new TLocalisamfile(LF_PCON); + _rmoviva = new TLocalisamfile(LF_RMOVIVA); + _tabiva = new TTable(TAB_IVA); + _tabtpd = new TTable(TAB_TPD); + _tabreg = new TTable("REG"); +} + +void CG3100_application::user_destroy() // releasev e arrmask +{ + //delete _msk; + delete _relmov; + delete _clifo; + delete _caus; + delete _pcon; + delete _attiv; + delete _comuni; + delete _tabiva; + delete _tabreg; + delete _tabtpd; + delete _rmoviva; +} + +void CG3100_application::init_print(const TMask& msk) +{ + set_real_picture("###.###.###.###"); + + TDate data (msk.get(F_DATASTAMPA)); + printer().setdate(data); + + + switch (_tipo_lista) + { + case movimenti: + { + reset_print(); + _flags = 0; + _tot_dare_giornaliero = 0; + _tot_avere_giornaliero = 0; + _tot_dare_generale = 0; + _tot_avere_generale = 0; + if (_scelta_stampa == 0) + { + _annoes = msk.get_int(F_ANNO); + _stampa_parte_iva = (bool)(msk.get(F_STAMPA)=="X"); + if (_stampa_parte_iva) + _flags |= ST_DATI_IVA; + _stampa_mess_alleg_iva = (bool)(msk.get(F_ALLEGATO)=="X"); + if (_stampa_mess_alleg_iva) + _flags |= ST_MESS_ALLEG; + _controllo_mov_errati = atoi(msk.get(F_CONTROLLO)); + if (_controllo_mov_errati == 1) + _flags |= ST_SOLO_MOVERR; + else if (_controllo_mov_errati == 2) + _flags |= ST_CONTROLLO; + else _flags |= ST_SENZA_CONTR; + if ((_numreg_ini != 0)&&(_decidi == 1)) + _flags |= ST_NUMERO; + if ((_data_ini.ok())&&(_decidi == 2)) + _flags |= ST_DATA; + _causale_ini = msk.get(F_CAUSALEINI); + if (_causale_ini != "") + _flags |= ST_CAUSALE; + _registro_ini = msk.get(F_REGISTROINI); + if (_registro_ini != "") + _flags |= ST_REGISTRO; + if ((_data_fin.ok())&&(_decidi == 2)) + _flags |= ST_DATA; + if ((_numreg_fin != 0)&&(_decidi == 2)) + _flags |= ST_NUMERO; + _causale_fin = msk.get(F_CAUSALEFIN); + if (_causale_fin != "") + _flags |= ST_CAUSALE; + _registro_fin = msk.get(F_REGISTROFIN); + if (_registro_fin != "") + _flags |= ST_REGISTRO; + } + else //_scelta_stampa == 1 + { + _annoes = msk.get_int(F_ANNO); + if (_numreg_ini != 0) + _flags |= ST_NUMERO; + if (_data_ini.ok()) + _flags |= ST_DATA; + _causale_ini = msk.get(F_CAUSALEINI); + if (_causale_ini != "") + _flags |= ST_CAUSALE; + if (_data_fin.ok()) + _flags |= ST_DATA; + if (_numreg_fin != 0) + _flags |= ST_NUMERO; + _causale_fin = msk.get(F_CAUSALEFIN); + if (_causale_fin != "") + _flags |= ST_CAUSALE; + } + } + break; + + + case fatture: +{ + _flags = 0; +{ + reset_print(); + _settata_prima_riga = FALSE; + _tipo_clifo_prec = ""; + _tipo_clifo_precedente = ""; + _codcf_prec = 0l; + _numeroregp = 0; + _documenti = 0; + _totdocumenti = 0; + _totimponibile = 0; + _totimposta = 0; + _op_esenti = 0; + _op_non_imp = 0; + _annoes = msk.get_int(F_ANNO); + _salto_pagina = (bool)(msk.get(F_CAMBIO)=="X"); + _data_ini = msk.get(F_DATAINI); + if (_data_ini.ok()) + _flags |= ST_DATA; + _data_fin = msk.get(F_DATAFIN); + if (_data_fin.ok()) + _flags |= ST_DATA; + TString tipo = msk.get(F_TIPOELENCO); + if ((tipo=="C")||(tipo=="F")) + { + _codice_ini = atol(msk.get(F_CODICEINI)); + _codice_fin = atol(msk.get(F_CODICEFIN)); + } + else + { + _codice_ini = atol(msk.get(F_CODICEINI1)); + _codice_fin = atol(msk.get(F_CODICEFIN1)); + } + if (_codice_ini != 0) + _flags |= ST_CODICE; + if (_codice_fin != 0) + _flags |= ST_CODICE; + if (tipo == "E") + { + _tipo_ini = "C"; + _tipo_fin = "F"; + } + else + { + _tipo_ini = tipo; + _tipo_fin = tipo; + } +} +} +break; + + + case movimenti_sezionale: + break; + +default: +break; +} + +} + +void CG3100_application::preprocess_header() +{ + int soh; // riga d'inizio dell'intestazione + TString sep(132); + + reset_header(); + + soh=1; + + sep << "Ditta " << get_firm(); + sep.left_just(132); + + set_header (soh++, (const char*) sep); + + sep = "Studio "; + sep << "Data @< Pag. @#"; + + sep.right_just(127); + + switch (_tipo_lista) + { + case movimenti: + if (_scelta_stampa == 0) + { + sep.overwrite ("Lista movimenti"); + set_header (soh++, (const char*)sep); + if (_decidi == 2) + { + if (_flags & ST_DATA) + { + set_header (soh, "Dalla data@12g%s",_data_ini.string()); + set_header (soh, "@24galla data@34g%s",_data_fin.string()); + } + else + set_header (soh, "Completa in ordine di data"); + } + else + if (_flags & ST_NUMERO) + { + set_header (soh, "dal numero@12g%d", _numreg_ini); + set_header (soh, "@20gal numero@30g%d", _numreg_fin); + } + else + set_header (soh, "Completa in ordine di numero"); + if (_flags & ST_CAUSALE) + { + set_header (soh, "@46gdalla causale@60g%s",(const char*)_causale_ini); + set_header (soh++, "@64galla causale@77g%s",(const char*)_causale_fin); + } + else + set_header (soh++, " tutte le causali"); + if (_flags & ST_REGISTRO) + { + set_header (soh, "dal registro@14g%s",(const char*)_registro_ini); + set_header (soh, "@18gal registro@30g%s",(const char*)_registro_fin); + } + else + set_header (soh, "tutti i registri"); + if (_flags & ST_DATI_IVA) + set_header (soh, "@34gstampa dati iva"); + if (_flags & ST_CONTROLLO) + set_header (soh, "@50g(controllo movimenti)"); + else if (_flags & ST_SOLO_MOVERR) + set_header (soh, "@50g(solo movimenti errati)"); + else set_header (soh, "@50g(senza controllo movimenti)"); + if ((_flags & (ST_ANNO_COMP|ST_MESS_ALLEG)) == 1) + set_header (soh, "@78gcon messaggi: anno di competenza, allegato iva"); + else if (_flags & ST_ANNO_COMP) + set_header (soh, "@78gcon messaggi: anno di competenza"); + else if (_flags & ST_MESS_ALLEG) + set_header (soh, "@78gcon messaggi: allegato iva"); + sep.fill('-'); + set_header (++soh, (const char *) sep); + set_header (++soh, "Rg Cod Causale@30gDescrizione@56gCodice conto@72gDescrizione conto@93gDare@112gAvere@130gSB"); + } + else + { + sep.overwrite ("Lista movimenti di sola prima nota"); + set_header (soh++, (const char*)sep); + if (_flags & ST_DATA) + { + set_header (soh, "Dalla data@12g%s",_data_ini.string()); + set_header (soh, "@24galla data@34g%s",_data_fin.string()); + } + else + set_header (soh, "Completa in ordine di data"); + if (_flags & ST_NUMERO) + { + set_header (soh, "@46gdal numero@57g%d", (const char*)_numreg_ini); + set_header (soh, "@65gal numero@75g%d",(const char*)_numreg_fin); + } + else + set_header (soh, "@46gcompleta in ordine di numero"); + if (_flags & ST_CAUSALE) + { + set_header(soh, "@86gdalla causale@100g%3s",(const char*)_causale_ini); + set_header(soh++,"@103galla causale@116g%3s",(const char*)_causale_fin); + } + else + set_header (soh++, "@86gtutte le causali"); + sep.fill('-'); + set_header (soh++, (const char *) sep); + set_header (soh++, "Rg Cod Causale@30gDescrizione@56gCodice conto@72gDescrizione conto@93gDare@112gAvere@130gSB"); + } + break; + + case fatture: + sep.overwrite ("Lista fatture"); + set_header (soh, (const char*)sep); + if (_flags & ST_DATA) + { + set_header (soh, "@15gdalla data@26g%s",_data_ini.string()); + set_header (soh, "@37galla data@47g%s",_data_fin.string()); + } + else + set_header (soh, "@15gcompleta in ordine di data"); + if (_flags & ST_CODICE) + { + set_header (soh, "@99gdal codice@110g%d",_codice_ini); + set_header (soh, "@117gal codice@127g%d",_codice_fin); + } + sep.fill('-'); + set_header (++soh, (const char *) sep); + set_header (++soh, "Registrazione @17gCod Protoc. Documento@49gCod Tp @68gTotale@101gCd Tp T O@129gNo"); + set_header (++soh, "Numero Data@17gReg Numero Data@42gNumero@49gCau Dc @56gDescrizione@68gDocumento@84gImponibile @101gIv Det A I@113gImposta@129gAll"); + break; + + case movimenti_sezionale: + sep.fill(' '); + sep.overwrite ("Lista movimenti di solo sezionale"); + set_header (soh++, (const char*)sep); + sep.fill('-'); + set_header (soh++, (const char *) sep); + break; + + default: + break; + } + set_header (++soh,(const char*)sep); + if (_tipo_lista != fatture) + { + sep = ""; + set_header (++soh,(const char*)sep); + } +} + +int cg3100(int argc, char* argv[]) +{ + CG3100_application a; + a.run(argc, argv, "Stampa movimenti"); + return 0; +} + + diff --git a/cg/cg3200.cpp b/cg/cg3200.cpp index 362825933..2a1b17eb6 100755 --- a/cg/cg3200.cpp +++ b/cg/cg3200.cpp @@ -996,7 +996,7 @@ bool CG3200_application::set_print(int) a.put(PCN_CONTO,contofine); a.put(PCN_SOTTOCONTO,sottocontofine); - current_cursor()->setregion(&da, &a); + current_cursor()->setregion(da, a); } else { @@ -1026,7 +1026,7 @@ bool CG3200_application::set_print(int) a.put(CLI_CONTO,contofine); a.put(CLI_CODCF,sottocontofine); - current_cursor()->setregion(&da, &a); + current_cursor()->setregion(da, a); } if (_stampatotiva) @@ -1280,6 +1280,81 @@ void CG3200_application::calcola_progressivi_al() void CG3200_application::calcola_progressivi() { +<<<<<<< cg3200.cpp + TLocalisamfile pconti(LF_PCON); + TLocalisamfile saldi (LF_SALDI); + real pdaresca,paveresca,pdarescap,paverescap; + real progdare_attuale,progavere_attuale,progdare_prec,progavere_prec; + real saldo,progredare_eseprec,progreavere_eseprec,pdarep,paverep; + int indbil; + char salini; + TRectype record(saldi.curr()); + + saldo = 0.00; + pdarep = 0.00; + paverep = 0.00; + pdaresca = 0.00; + paveresca = 0.00; + pdarescap = 0.00; + paverescap = 0.00; + // Ricerca sull'archivio saldi dei record con gruppo,conto,sottoconto + // uguali a quelli di rmov per il calcolo dei progressivi precedenti + + record.zero(); + record.put(SLD_GRUPPO, _gruppo); + record.put(SLD_CONTO, _conto); + record.put(SLD_SOTTOCONTO, _sottoc); + + if (_ricerca == 'P') + indbil = atoi (current_cursor()->file(LF_PCON)->get(PCN_INDBIL)); + else + { + if ((_ricerca == 'C') || (_ricerca == 'F')) + { + pconti.setkey(1); + pconti.zero(); + pconti.put(PCN_GRUPPO, _gruppo); + pconti.put(PCN_CONTO , _conto); + pconti.read(); + if (pconti.good()) + indbil = atoi (pconti.get(PCN_INDBIL)); + else + indbil = 0; + } + } + + saldi.setkey(2); + + saldi.zero(); + saldi.put(SLD_GRUPPO, _gruppo); + saldi.put(SLD_CONTO, _conto); + saldi.put(SLD_SOTTOCONTO, _sottoc); + + for ( saldi.read(); + ((saldi.curr()==record) && !saldi.eof()); + saldi.next()) + { + long annoes_saldi = saldi.curr().get_long(SLD_ANNOES); + + //Calcola i progressivi dell'esercizio attuale + + if (annoes_saldi == _annomsk) + { + pdaresca = saldi.curr().get_real(SLD_PDARESCA); + paveresca = saldi.curr().get_real(SLD_PAVERESCA); + saldo = saldi.curr().get_real(SLD_SALDO); + salini = saldi.curr().get(SLD_FLAGSALINI)[0]; + } + + //Calcola i progressivi dell'esercizio precedente + + if (annoes_saldi == _annoesmsk) + { + pdarescap = saldi.curr().get_real(SLD_PDARESCA); + pdarep = saldi.curr().get_real(SLD_PDARE); + paverescap = saldi.curr().get_real(SLD_PAVERESCA); + paverep = saldi.curr().get_real(SLD_PAVERE); +======= TLocalisamfile pconti(LF_PCON); TLocalisamfile saldi (LF_SALDI); real pdaresca,paveresca,pdarescap,paverescap; @@ -1353,6 +1428,7 @@ void CG3200_application::calcola_progressivi() pdarep = saldi.curr().get_real(SLD_PDARE); paverescap = saldi.curr().get_real(SLD_PAVERESCA); paverep = saldi.curr().get_real(SLD_PAVERE); +>>>>>>> 1.2 // Se il saldo dell'esercizio attuale e' diverso da 0 allora significa che // quello corrisponde al saldo finale dell'esercizio precedente. Per ottenere diff --git a/cg/cg3400.cpp b/cg/cg3400.cpp index e24eff24e..ff84d0844 100755 --- a/cg/cg3400.cpp +++ b/cg/cg3400.cpp @@ -1,1408 +1,1408 @@ -// cg3400 -// Stampa libro giornale - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef __CG3401_H -#include "cg3401.h" // qui c'e' TRigaiva_array -#endif - -#include "cg3400a.h" -#include "cg3400b.h" - -#define RIGHE_FOOTER 10 -#define REAL_PICTURE "###.###.###.###" - -const MAXSTR = 128; -static char __tmp [MAXSTR]; -static TFixed_string tmp (__tmp, MAXSTR); - -enum descr { causale, conto, operazione }; - -bool mask_a_cod_reg (TMask_field& f, KEY k); -bool mask_a_data (TMask_field& f, KEY k); -bool mask_b_ripristina (TMask_field& f, KEY k); - -class CG3400_application : public TPrintapp -{ - friend bool mask_a_cod_reg (TMask_field& f, KEY k); - friend bool mask_a_data (TMask_field& f, KEY k); - friend bool mask_b_ripristina(TMask_field& f, KEY k); - - TRigaiva_array _iva_array; - TRelation * _rel; - TCursor * _cur; - TRectype * _RecPartoDa, *_RecArrivoA; - - TString _reg_cod, _reg_anno, _reg_descr; - TDate _data_da, _data_a, _last_data; - bool _stampa_definitiva; - real _tot_dare, _tot_avere; // valori di partenza - real _tot_dare_progr, _tot_avere_progr; // progressivi - real _tot_dare_gg , _tot_avere_gg ; // giornalieri - real _tot_dare_ac , _tot_avere_ac ; // anno precedente - long _nprog_da, _nprog_mov; - int _num_rig, _stampa_width, _stampa_len; - - TParagraph_string *_descr_conto; - TParagraph_string *_descr_causale; - TParagraph_string *_descr_operazione; - - int _pagine_stampate, _pagine_numerate, _stampa_ok, _pagina_da; - TDate _data_corr, _data_succ; - int _mese_corr, _mese_succ; - int _last_header; // prima riga di intestazione "libera" - - bool _libro_giornale_iva_unico, _libro_cronologico, _stampa_intesta; - bool _occas; // se e' cliente occasionale - bool _gia_settata_riga_mov; // per la stampa no iva - TString _viacf, _civcf, _comcf, _capcf, _statocf; // dati C/F - TString _ragsoc, _paiva, _comunefis, _provfis, _viafis; // dati ditta - TString _cofi, _cap, _anno_es; - TLocalisamfile * _com, *_clifo,*_pconti,*_nditte,*_anag, *_caus; - TTable *_tabreg, *_tabval, *_tabes; - -public: - virtual void preprocess_header(); - virtual void preprocess_footer(); - virtual bool preprocess_page(int, int); - virtual print_action postprocess_page(int, int); - virtual bool preprocess_print(int, int); - virtual print_action postprocess_print(int, int); - virtual void postclose_print(); - - virtual void user_create(); - virtual void user_destroy(); - - virtual void set_page (int, int); - void set_rows (int, int); - void set_page_132(int, int); - void set_page_198(int, int); - void setta_righe_indirizzo(); - int setta_righe_iva(); - void setta_righe_valuta(); - void setta_righe_descr(TParagraph_string*, enum descr); - void calcola_iva(); - virtual bool cancel_hook(); - virtual bool set_print(int); - - int stampa_intestazione_ditta(); - int set_header_132(); - int set_header_198(); - - bool leggi_tabreg(const char *, const char *); - void aggiorna_tabreg(int, int); - void aggiorna_mov(); - void scrivi_numgio(long); - void stampa_totali_giorno(TDate, bool); - void get_dati_ditta (); - TLocalisamfile * get_descr (TLocalisamfile*,TLocalisamfile*,int, int, long); - - bool IsInEsercizio (TDate& da, TDate& a, int anno_eser); - const char * SimboloValuta (const char * cod); - const char * get_descr_caus (const char * codcaus); - - CG3400_application() : _reg_cod(3), _reg_anno(4), _tot_dare_progr(0.00), - _tot_avere_progr (0.00), _data_da(""), _data_a("") - {}; - virtual ~CG3400_application() {}; -}; - -////////////////////////////////////////////////////////////////////////// -// Funzioni legate ai parametri ditta -////////////////////////////////////////////////////////////////////////// -bool libro_giornale_iva_unico() -{ - TConfig conf(CONFIG_DITTA); - - return conf.get("StLgiU") == "X"; -} - -bool libro_cronologico() -{ - TConfig conf(CONFIG_DITTA); - - return conf.get("GsLbCr") == "X"; -} - -TRectype& look_com (const char * cod, TLocalisamfile *comuni) -{ - comuni->zero(); - comuni->put(COM_COM, cod); - comuni->read(); - if (comuni->bad()) - comuni->zero(); - - return comuni->curr(); -} - -bool CG3400_application::IsInEsercizio (TDate& da, TDate& a, int anno_eser) -{ - TTable& TabEs = *_tabes; - TString codtab; - TDate inizio, fine; - - if (!da.ok() || !a.ok()) return FALSE; - - TabEs.zero(); - - codtab << format ("%-4d", anno_eser); - TabEs.put ("CODTAB", codtab); - TabEs.read(); - if (TabEs.good()) - { - inizio = TabEs.get_date ("D0"); - fine = TabEs.get_date ("D1"); - if ((da >= inizio) && (a <= fine)) - return TRUE; - else - { - TString da(inizio.string()); - TString a(fine.string()); - warning_box("Le date devono essere comprese tra %s e %s", (const char*)da, (const char*)a); - return FALSE; - } - } - return FALSE; -} - -const char * CG3400_application::SimboloValuta (const char * cod) -{ - TTable& tab_val = *_tabval; - TString codtab = format ("%-3s", cod); -// static char simbolo; - - tab_val.zero(); - - tab_val.put("CODTAB", codtab); - tab_val.read(); - if (tab_val.good()) - tmp = tab_val.get("S7"); - else - tmp = ""; - - return __tmp; -} - -const char * CG3400_application::get_descr_caus (const char * codcaus) -{ - TLocalisamfile& caus = *_caus; - - caus.zero(); - caus.put (CAU_CODCAUS, codcaus); - - caus.read(); - - if (caus.bad()) - caus.zero(); - - tmp = caus.get(CAU_DESCR); - return __tmp; -} - -TLocalisamfile * CG3400_application::get_descr (TLocalisamfile *pconti, - TLocalisamfile *clifo, - int g, int c, long s) -{ - pconti->zero(); - pconti->put (PCN_GRUPPO, g); - pconti->put (PCN_CONTO , c); - pconti->put (PCN_SOTTOCONTO, s); - - pconti->read(); - - if (pconti->good()) - return pconti; - - TString tipocf = pconti->get(PCN_TMCF); - long codcf = s; - - clifo->zero(); - clifo->put(CLI_CODCF, codcf); - clifo->put(CLI_TIPOCF, tipocf); - - clifo->read(); - - if (clifo->good()) - { - _viacf = clifo->get(CLI_INDCF); - _civcf = clifo->get(CLI_CIVCF); - _comcf = clifo->get(CLI_COMCF); - _capcf = clifo->get(CLI_CAPCF); - _statocf = clifo->get(CLI_STATOCF); - _occas = clifo->get_bool(CLI_OCCAS); - return clifo; - } - - return NULL; -} - -void CG3400_application::get_dati_ditta () -{ - TString codanagr; - TString tipoa; - - _nditte->zero(); - _nditte->put(NDT_CODDITTA, get_firm()); - _nditte->read(); - - if (_nditte->bad()) _nditte->zero(); - - _ragsoc = _nditte->get(NDT_RAGSOC); - codanagr = _nditte->curr().get(NDT_CODANAGR); - tipoa = _nditte->curr().get(NDT_TIPOA); - - _anag->setkey(1); - _anag->zero(); - _anag->put (ANA_TIPOA, tipoa); - _anag->put (ANA_CODANAGR, codanagr); - _anag->read(); - if (_anag->bad()) _anag->zero(); - - _cofi = _anag->get(ANA_COFI); - _paiva = _anag->get(ANA_PAIV); -// _ragsoc = _anag->get(ANA_RAGSOC); - _comunefis = _anag->get(ANA_COMRF); - - if (_comunefis.empty()) - _comunefis = _anag->get(ANF_COMRES); - - TRectype dep = look_com (_comunefis, _com); - - _comunefis = dep.get(COM_DENCOM); - _provfis = dep.get(COM_PROVCOM); - _cap = dep.get(COM_CAPCOM); - if (_comunefis.empty()) - { - _viafis = _anag->get(ANA_INDRF); - _viafis.rtrim(); - _viafis << " " << _anag->curr().get (ANA_CIVRF); - } - else - { - _viafis = _anag->get(ANA_INDRES); - _viafis.rtrim(); - _viafis << " " << _anag->get (ANA_CIVRES); - } -} - -void CG3400_application::user_create() -{ - _libro_giornale_iva_unico = libro_giornale_iva_unico(); - _libro_cronologico = libro_cronologico(); - - _tabreg = new TTable ("REG"); - _tabval = new TTable ("%VAL"); - _tabes = new TTable ("ESC"); - - _nditte = new TLocalisamfile(LF_NDITTE); - _anag = new TLocalisamfile (LF_ANAG); - _com = new TLocalisamfile(LF_COMUNI); - _clifo = new TLocalisamfile(LF_CLIFO); - _pconti = new TLocalisamfile(LF_PCON); - _caus = new TLocalisamfile(LF_CAUSALI); - - _descr_conto = new TParagraph_string ("",10); - _descr_operazione = new TParagraph_string ("",10); - _descr_causale = new TParagraph_string ("",10); - - disable_print_menu(); - - _rel = new TRelation (LF_MOV); - _rel->add (LF_RMOV, "NUMREG=NUMREG"); - _rel->add (LF_RMOVIVA, "NUMREG=NUMREG"); - - _cur = new TCursor (_rel, "", 2); // usa la chiave 2 su MOV - _RecPartoDa = new TRectype(_cur->file(LF_MOV)); - _RecArrivoA = new TRectype(_cur->file(LF_MOV)); - - add_cursor (_cur); - - add_file (LF_MOV); - add_file (LF_RMOV); - add_file (LF_RMOVIVA); -} - -void CG3400_application::user_destroy() -{ - delete _rel; - delete _cur; - delete _RecPartoDa; - delete _RecArrivoA; - - delete _com; delete _clifo; delete _caus; delete _pconti; - delete _nditte; delete _anag; - delete _tabreg; delete _tabes; delete _tabval; - - delete _descr_conto; - delete _descr_operazione; - delete _descr_causale; - delete _nditte; - delete _anag; -} - -void CG3400_application::aggiorna_mov() -{ - TLocalisamfile mov(LF_MOV); - TProgind prnd (mov.items(), "Aggiornamento movimenti ...", FALSE, TRUE); - - long nprog = _nprog_da; - - mov.curr() = *_RecPartoDa; - - for (mov.read(_isgteq, _lock); mov.curr() < *_RecArrivoA && !mov.eof(); mov.next(_lock)) - { - const bool gia_stampato = mov.get_bool(MOV_STAMPATO); - if (!gia_stampato) - { - mov.put (MOV_STAMPATO, TRUE); - mov.put (MOV_NUMGIO, nprog); - mov.rewrite(); - nprog++; - } - else - mov.reread(_unlock); - - prnd.addstatus(1); - } - mov.reread(_unlock); -} - -void CG3400_application::scrivi_numgio(long nprog) -{ - TLocalisamfile *mov = current_cursor()->file(LF_MOV); - - mov->reread(_lock); - mov->put (MOV_NUMGIO, nprog); - mov->rewrite(); -} - -void CG3400_application::stampa_totali_giorno(TDate data, bool ff) -{ - TString dep(_stampa_width); - - dep = "@10gOperazioni del "; - dep << data.string(); -// dep.center_just(); - - set_row (1, "%s", (const char *)dep); - - if (_stampa_width == 132) -// set_row (1, "@94g %15r @112g %15r", &_tot_dare_gg, &_tot_avere_gg ); - set_row (1, "@94g %r @112g %r", &_tot_dare_gg, &_tot_avere_gg ); - else - set_row (1, "@142g %r @164g %r", &_tot_dare_gg, &_tot_avere_gg ); - - if ( (_tot_avere_ac != 0) || (_tot_dare_ac != 0) ) - { - dep = "@10gOperazioni del "; - dep << data.string() << " " << "Anno precedente"; -// dep.center_just(); - set_row (2, "%s", (const char *)dep); - if (_stampa_width == 132) - set_row (2, "@95g %r @112g %r", &_tot_dare_ac, - &_tot_avere_ac ); - else - set_row (2, "@142g %r @164g %r", &_tot_dare_ac, - &_tot_avere_ac ); - _tot_avere_ac = 0.00; - _tot_dare_ac = 0.00; - set_row (3, ""); - } - else - set_row (2, ""); // Lascio una riga vuota dopo il totale - - if (ff) set_auto_ff (TRUE); - else set_auto_ff (FALSE); -} - -// -------------------------------------------------------------------------- -// -// STAMPA A 132 -// -// -------------------------------------------------------------------------- -void CG3400_application::set_page_132 (int file, int counter) -{ - int r = 1; - switch (file) - { - case LF_MOV: - if (_libro_giornale_iva_unico) - { - if (_stampa_definitiva) - set_row(r,"Registrazione n. #-7ld del @d documento n. @7s del @d @56g@s Anno di competenza %s", - &_nprog_mov, - FLD(LF_MOV, MOV_DATAREG), - FLD(LF_MOV, MOV_NUMDOC), - FLD(LF_MOV, MOV_DATADOC), - FLD(LF_MOV, MOV_DESCR), - (const char *)_reg_anno); - else - set_row(r,"Registrazione n. @7,lpn del @d documento n. @7s del @d @56g@s Anno di competenza %s", - FLD(LF_MOV, MOV_NUMREG, "#######"), - FLD(LF_MOV, MOV_DATAREG), - FLD(LF_MOV, MOV_NUMDOC), - FLD(LF_MOV, MOV_DATADOC), - FLD(LF_MOV, MOV_DESCR), - (const char *)_reg_anno); - - } - else - if (!_gia_settata_riga_mov) - { - set_row (r, "Operazioni del @d", FLD(LF_MOV,MOV_DATAREG)); - _gia_settata_riga_mov = TRUE; - } - - break; - - case LF_RMOV: - break; - case LF_RMOVIVA: - break; - default: - break; - } -} - -// -------------------------------------------------------------------------- -// -// STAMPA A 198 -// -// -------------------------------------------------------------------------- -void CG3400_application::set_page_198 (int file, int counter) -{ - int r = 1; - switch (file) - { - case LF_MOV: - break; - case LF_RMOV: - set_row (r, "@d", FLD(LF_RMOV,RMV_DATAREG)); - set_row (r, "@10g@pn/@pn", FLD(LF_RMOV,RMV_NUMREG,"####"), - FLD(LF_RMOV,RMV_NUMRIG,"##")); - set_row (r, " @d", FLD(LF_RMOV,MOV_DATADOC)); - set_row (r, " @pn",FLD(LF_RMOV,MOV_NUMDOC)); - - set_row (r, "@38g@pn",FLD(LF_RMOV, RMV_GRUPPO, "@@.")); - set_row (r, "@pn",FLD(LF_RMOV, RMV_CONTO , "@@.")); - set_row (r, "@pn",FLD(LF_RMOV, RMV_SOTTOCONTO, "@@@@@@")); - - set_row (r, "#50t", &_descr_conto); - set_row (r, "@80g@3s", FLD(LF_MOV, MOV_CODCAUS)); - set_row (r, "#50t", &_descr_causale); - -// set_row (r, "@50s", FLD(LF_RMOV, RMV_DESCR)); - set_row (r, "#50t", &_descr_operazione); - -// Dare e avere sono settati nella preprocess_page -// Cosi' pure l'indirizzo nel caso di gestione libro cronologico -// _descr contiene la descrizione conto o la ragione sociale -// v. preprocess_page - break; - case LF_RMOVIVA: - break; - default: - break; - } -} - -void CG3400_application::set_rows(int file, int counter) -{ - int r=1; - switch (file) - { - case LF_RMOV: - if (_libro_giornale_iva_unico) - { - if (!_stampa_definitiva) set_row (r, "%3d", _num_rig); - set_row (r, "@5g@3s@60g@pn@pn@pn", - FLD(LF_MOV, MOV_CODCAUS), - FLD(LF_RMOV, RMV_GRUPPO, "@@."), - FLD(LF_RMOV, RMV_CONTO , "@@."), - FLD(LF_RMOV, RMV_SOTTOCONTO, "@@@@@@") - ); - } - else // no libro_giornale_iva_unico - { - if (_stampa_definitiva) - set_row (r, "#-7ld", &_nprog_mov); - else - set_row (r, "@7,rn", FLD(LF_RMOV, RMV_NUMREG)); - set_row (r, "@10g@d@28g@pn@pn@pn", - FLD(LF_RMOV, RMV_DATAREG), - FLD(LF_RMOV, RMV_GRUPPO, "@@."), - FLD(LF_RMOV, RMV_CONTO , "@@."), - FLD(LF_RMOV, RMV_SOTTOCONTO, "@@@@@@") - ); - } - break; - default: - break; - } -} - -void CG3400_application::set_page (int file, int counter) -{ - if (_libro_giornale_iva_unico) - set_page_132(file, counter); - else - if (_stampa_width == 132) - set_page_132(file, counter); - else - set_page_198(file, counter); -} - -print_action CG3400_application::postprocess_print(int file, int counter) -{ - switch (file) - { - case LF_RMOV: - break; - case LF_MOV: - { - printer().formfeed(); - *_RecArrivoA = _cur->file(LF_MOV)->curr(); - } - break; - default: - break; - } - return NEXT_PAGE; -} - -void CG3400_application::postclose_print() -{ - const int ultima_fatta = printer().getcurrentpage(); - const int stampate = ultima_fatta - _pagina_da + 1; - if (yesno_box("La stampa e' corretta ? ")) - { - _pagina_da = -1; - aggiorna_mov (); - } - aggiorna_tabreg (_pagina_da, stampate); -} - -void CG3400_application::preprocess_footer() -{ - TString dare = _tot_dare_progr.string("###.###.###.###"); - TString avere = _tot_dare_progr.string("###.###.###.###"); - int r=1; - - if (_stampa_width == 132) - set_footer (r, "@65gTotale progressivi generali: @95g%s @112g%s", - (const char *)dare, - (const char *)avere); - else - set_footer (r, "@100gTotale progressivi generali: %s @164gTotale avere: %s", - (const char *)dare, - (const char *)avere); - -} - -int CG3400_application::stampa_intestazione_ditta() -{ - int r=1; - TString riga(_stampa_width); - - get_dati_ditta(); - set_header (r, "Ditta: %s Via %s %s %s %s", (const char *)_ragsoc, - (const char *)_viafis, (const char *)_cap, - (const char *)_comunefis, (const char *)_provfis); - r++; - riga = "Data @>"; - riga.right_just(_stampa_width-15); // perche' il codice viene espanso nella data con l'anno in 4 caratteri - riga.overwrite (format ("Partita iva %s @24gCodice fiscale %s", (const char*)_paiva, (const char*)_cofi)); - set_header (r, "%s", (const char*) riga); - r++; - - return r; -} - -int CG3400_application::set_header_198() -{ - int r=1; - TString riga(_stampa_width); - TString data_da = _data_da.string(); - TString data_a = _data_a.string(); - - if (_stampa_intesta) - r = stampa_intestazione_ditta(); - - set_header(r, "Codice libro: %s %s @40gdalla data: %s alla data: %s", - (const char *) _reg_cod, (const char *) _reg_descr, - (const char *) data_da, (const char *) data_a); - r++; - - riga.fill('-'); - set_header(r, riga); - r++; - - set_header(r, " Data Numero Documento"); - - riga = "Anno S"; - riga.right_just(_stampa_width); - if (_libro_cronologico) - riga.overwrite(" Codice conto Descrizione conto"); - else - riga.overwrite(" Codice"); - - set_header(r, "%s", (const char*) riga); - r++; - - riga = "Comp B"; - riga.right_just(_stampa_width); - if (_libro_cronologico) - riga.overwrite("Registr. Registraz. data e numero Generalita' cliente/fornitore@82gCod.Causale@102gDescrizionee operazione@142gDARE@164gAVERE"); - else - riga.overwrite("Registr. Registraz. data e numero Conto Descrizione conto@82gCod.Causale@102gDescrizionee operazione@142gDARE@164gAVERE"); - - set_header(r, "%s", (const char*) riga); - r++; - - riga.fill('-'); - set_header(r, riga); - r++; - - return r; -} - -int CG3400_application::set_header_132() -{ - int r=1; - TString riga(_stampa_width); - TString data_da = _data_da.string(); - TString data_a = _data_a.string(); - - if (_stampa_intesta) - r = stampa_intestazione_ditta(); - - set_header(r, "Codice libro: %s %s @50gdalla data: %s alla data: %s", - (const char *) _reg_cod, (const char *) _reg_descr, - (const char *) data_da, (const char *) data_a); - r++; - - riga.fill('-'); - set_header(r, riga); - r++; - - if (_libro_giornale_iva_unico) - { - set_header(r, "Ri"); - if (_libro_cronologico) - set_header(r, "@60gCodice Conto"); - - set_header(r, "@113gImporti@131gS"); - r++; - - set_header(r, "ga@6gCod.Causale@34gDescrizione operazione"); - if (_libro_cronologico) - set_header(r, "@60gGeneralita' cliente/fornitore"); - - set_header(r, "@106gDARE@122gAVERE@131gB"); - r++; - } - else -//////////////////////////////////////////////////////////////////// -// NO LIBRO GIORNALE IVA UNICO -//////////////////////////////////////////////////////////////////// - { - set_header(r, "Numero@12gDocumento@28gCodice@115gImporti@127g A S"); - r++; - if (_stampa_definitiva) - set_header(r, "Riga"); - else - set_header(r, "Regist."); - - set_header(r, "@10gData e numero@28gConto@41gDescrizione conto@68gDescrizione operazione@106gDare@122gAvere@127g C B"); - r++; - } - - riga.fill('-'); - set_header(r, riga); - r++; - return r; -} - -void CG3400_application::preprocess_header() -{ - int pag = printer().getcurrentpage(); - TString dare = _tot_dare_progr.string(REAL_PICTURE); - TString avere = _tot_dare_progr.string(REAL_PICTURE); - int r = _last_header; - - if (pag > 0) // Stampa riporti - { - TString dep (_stampa_width); - dare.right_just(); - avere.right_just(); - if (_stampa_width == 132) - dep = format ("@86gRiporto:@95g %15s @112g %15s", (const char *) dare, - (const char *) avere ); - else - dep = format ("@100gRiporto %s @140g %s", (const char *) dare, - (const char *) avere ); - set_header (r, "%s", (const char *) dep); - } -} - -// -// PREPROCESS_PRINT -// -// Se non ci sono items nel cursore (= se non ci sono movimenti) -// la stampa e' abortita. -// -// stampa_ok = -1 -> la stampa precedente era OK -// stampa_ok = x -> la stampa precedente non e' andata a buon fine -// ed era partita dalla pagina x. -// -// Se la stampa precedente e' andata male, setto la pagina corrente a -// quella salvata in stampa_ok, e la pagina da cui parte la stampa vera e -// propria a quella che mi dice l'utente: -// -// set_page_number (stampa_ok) -// setfrompage (pagina_da) -// -bool CG3400_application::preprocess_print(int file, int counter) -{ - int i; - switch (file) - { - case LF_MOV: - reset_print(); - reset_header(); - printer().footerlen(RIGHE_FOOTER); - _gia_settata_riga_mov = FALSE; // Stampa o no la riga di mov (solo se - // NO stampa giornale_iva_unico - _num_rig = 0; - _tot_dare_ac = 0.00; - _tot_avere_ac = 0.00; - _tot_dare_gg = 0.00; - _tot_avere_gg = 0.00; - _tot_dare_progr = _tot_dare; - _tot_avere_progr = _tot_avere; - _iva_array.destroy(); - if (current_cursor()->items() == 0) - { - warning_box ("Non ci sono movimenti.\nLa stampa e' annullata"); - return FALSE; - } - - _nprog_mov = _nprog_da; - - *_RecPartoDa = _cur->file(LF_MOV)->curr(); - - for (i=1; i 0) - return REPEAT_PAGE; -// else -// return NEXT_PAGE; - } - _cur->save_status(); - ++(*_cur); - _data_succ = _cur->file(LF_MOV)->get_date(MOV_DATAREG); - _mese_succ = _data_succ.month(); - --(*_cur); - _cur->restore_status(); - if (_data_corr != _data_succ) - { - reset_print(); - if (_mese_succ != _mese_corr) nuovo_mese = TRUE; - else nuovo_mese = FALSE; - stampa_totali_giorno(_data_corr, nuovo_mese); - _tot_dare_gg = 0.00; - _tot_avere_gg = 0.00; - _gia_settata_riga_mov = FALSE; - return REPEAT_PAGE; - } - else - _gia_settata_riga_mov = TRUE; - break; - - case LF_RMOVIVA: - default: - set_auto_ff(FALSE); // ff gia' fatto prima - break; - } - return NEXT_PAGE; -} - -// -// PREPROCESS_PAGE -// -// Non stampo niente se: -// -// 1. STAMPATO = TRUE -// OPPURE -// 2. non ci sono righe di RMOV -// -bool CG3400_application::preprocess_page(int file, int counter) -{ - TLocalisamfile * boh; - int g, c; - long s; - bool gia_stampato=FALSE; - TString sezione, caus, rmv_descr; - real importo; - - if (counter) return TRUE; - - switch (file) - { - case LF_MOV: - _num_rig=0; - _iva_array.destroy(); - - if (!current_cursor()->is_first_match(LF_RMOV)) - return FALSE; - - gia_stampato = current_cursor()->file(LF_MOV)->get_bool(MOV_STAMPATO); - if (gia_stampato) - if (_stampa_definitiva) - return FALSE; - else - set_row (1, "@131g*"); // stampo un * se mov. gia stampato - - if (_libro_giornale_iva_unico) - _nprog_mov++; - - _data_corr = _cur->file(LF_MOV)->get_date(MOV_DATAREG); - _mese_corr = _data_corr.month(); - _anno_es = _cur->file(LF_MOV)->get(MOV_ANNOES); - caus = _cur->file(LF_MOV)->get(MOV_CODCAUS); - break; - case LF_RMOV: - set_auto_ff(FALSE); - _num_rig++; - reset_print(); - set_rows(file, counter); - if (_stampa_width == 132) - { - *_descr_causale = get_descr_caus(caus); - _descr_causale->set_width(10); - } - else - { - *_descr_causale = get_descr_caus(caus); - _descr_causale->set_width(198); - } - setta_righe_descr(_descr_causale, causale); - rmv_descr = current_cursor()->file(LF_RMOV)->get(RMV_DESCR); - if (_stampa_width == 132) - { - *_descr_operazione = (const char *)rmv_descr; - _descr_operazione->set_width(10); - } - else - { - *_descr_operazione = (const char *)rmv_descr; - _descr_operazione->set_width(198); - } - setta_righe_descr(_descr_operazione, operazione); - if (!_libro_giornale_iva_unico) - _nprog_mov++; - g = current_cursor()->curr(LF_RMOV).get_int(RMV_GRUPPO); - c = current_cursor()->curr(LF_RMOV).get_int(RMV_CONTO); - s = current_cursor()->curr(LF_RMOV).get_long(RMV_SOTTOCONTO); -// _descr = get_descr (g,c,s); - boh = get_descr (_pconti, _clifo, g,c,s); - - if (boh!=NULL) - { - if (boh->num() == LF_PCON) - { - if (_stampa_width == 132) - { - *_descr_conto = (const char*)boh->get(PCN_DESCR); - _descr_conto->set_width(10); - } - else - { - *_descr_conto = (const char*)boh->get(PCN_DESCR); - _descr_conto->set_width(198); - } - setta_righe_descr(_descr_conto, conto); - } - else - if (boh->num() == LF_CLIFO) - { - if (_stampa_width == 132) - { - *_descr_conto = (const char*)boh->get(CLI_RAGSOC); - _descr_conto->set_width(10); - } - else - { - *_descr_conto = (const char*)boh->get(CLI_RAGSOC); - _descr_conto->set_width(198); - } - setta_righe_descr(_descr_conto, conto); - if (_libro_cronologico) - setta_righe_indirizzo(); - } - } - sezione = _cur->file(LF_RMOV)->get (RMV_SEZIONE); - importo = _cur->file(LF_RMOV)->get_real (RMV_IMPORTO); - -// imp = importo.string ("######"); - if (sezione == "D") - { - _tot_dare_progr += importo; // prog. generali - if (_anno_es != _reg_anno) - _tot_dare_ac += importo; // prog. anno precedente - else - _tot_dare_gg += importo; // prog. giornalieri - - if (_stampa_width == 132) - set_row (1, "@95g%r", &importo); - else - set_row (1, "@142g%r", &importo); - } - else - { - _tot_avere_progr += importo; - if (_anno_es != _reg_anno) - _tot_avere_ac += importo; - else - _tot_avere_gg += importo; - if (_stampa_width == 132) - set_row (1, "@112g%r", &importo); - else - set_row (1, "@164g%r", &importo); - } - break; - case LF_RMOVIVA: - set_auto_ff(FALSE); - if (_libro_giornale_iva_unico) - { - calcola_iva (); - setta_righe_valuta(); - } - break; - default: - set_auto_ff(FALSE); - break; - } - return TRUE; -} - -void CG3400_application::calcola_iva() -{ - TString codiva; - int tipocr, tipodet; - real impo, impos; - TRectype iva (_cur->file(LF_RMOVIVA)->curr()); - - if (!iva.empty()) - { - impo = iva.get_real (RMI_IMPONIBILE); - impos = iva.get_real (RMI_IMPOSTA); - tipocr = iva.get_int (RMI_TIPOCR); - tipodet = iva.get_int (RMI_TIPODET); - codiva = iva.get (RMI_CODIVA); - _iva_array.add_riga(impo,impos,codiva,tipodet,0.00,0.00); - } -} - -void CG3400_application::setta_righe_descr(TParagraph_string* str, enum descr des) -{ - const char * r; - int i = 1; - TString frm; - - switch (des) - { - case causale: - if (_libro_giornale_iva_unico) - frm = "@8g%s"; - else - frm = "@57g%s"; - break; - case conto: - if (_libro_giornale_iva_unico) - frm = "@73g%s"; - else - frm = "@41g%s"; - break; - case operazione: - if (_libro_giornale_iva_unico) - frm = "@34g%s"; - else - frm = "@68g%s"; - break; - default: - break; - } - while ((r = str->get()) != NULL) - { -// reset_row(i); - set_row (i, (const char*)frm, r); - i++; - } -} - -int CG3400_application::setta_righe_iva() -{ - int r=0; - - for (int j = 0; j < _iva_array.items(); j++) - { - TRigaiva& riga = (TRigaiva&)_iva_array[j]; - r = j+1; - set_row(r, "Imponibile@12g%r", &riga._imponibile); - set_row(r, "@31gImposta@39g%r", &riga._imposta); - set_row(r, "@58gCodice Iva@68g%3s", (const char*)riga._codiva); - switch (riga._tipodet) - { - case 0 : set_row(r, "@73gDetraibile"); - break; - case 1 : set_row(r, "@73gIndetraibile su op.es."); - break; - case 3 : set_row(r, "@73gPassaggi interni"); - break; - case 9 : set_row(r, "@73gIndetraibile art.19"); - break; - default: break; - } - } - _iva_array.destroy(); - return r; -} - -void CG3400_application::setta_righe_valuta() -{ - TString simbolo, codval; - bool intracom; - - codval = current_cursor()->file(LF_MOV)->get(MOV_CODVAL); - intracom = current_cursor()->curr(LF_RMOVIVA).get_bool(RMI_INTRA); - simbolo = SimboloValuta(codval); - -// _allegb = CausAlleg(_codcaus); -// _descr_doc = DescrDoc(_tipodoc); -// _totdocumenti += _totdoc; -// _ricser = current_cursor()->curr(LF_RMOVIVA).get_int(RMI_RICSER); -// long numeroreg = cur->curr(LF_RMOVIVA).get_long(RMI_NUMREG); - - if ((codval != "LIT") && intracom) - { - reset_row(1); - set_row(1,"Corr.in lire@14g@pN", - FLD(LF_RMOVIVA,RMI_CORRLIRE,"###.###.###.###.###")); - set_row(1,"@34gCorr.in valuta@49g@pN", - FLD(LF_RMOVIVA,RMI_CORRVALUTA,"###.###.###.###.###")); - if (simbolo.not_empty()) - set_row(1,"@53g%.5s", (const char *)simbolo); - else - set_row(1,"@53g%.3s", (const char *)codval); - } -} - -void CG3400_application::setta_righe_indirizzo() -{ - TString comune, prov; - -// Se e' un cliente occasionale leggo indirizzo da mov, senno' e' stato -// gia' letto da clifo nella get_descr, richiamata nella preprocess_page - if (_occas) - { - TCursor * cur = current_cursor(); +// cg3400 +// Stampa libro giornale + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef __CG3401_H +#include "cg3401.h" // qui c'e' TRigaiva_array +#endif + +#include "cg3400a.h" +#include "cg3400b.h" + +#define RIGHE_FOOTER 10 +#define REAL_PICTURE "###.###.###.###" + +const MAXSTR = 128; +static char __tmp [MAXSTR]; +static TFixed_string tmp (__tmp, MAXSTR); + +enum descr { causale, conto, operazione }; + +bool mask_a_cod_reg (TMask_field& f, KEY k); +bool mask_a_data (TMask_field& f, KEY k); +bool mask_b_ripristina (TMask_field& f, KEY k); + +class CG3400_application : public TPrintapp +{ + friend bool mask_a_cod_reg (TMask_field& f, KEY k); + friend bool mask_a_data (TMask_field& f, KEY k); + friend bool mask_b_ripristina(TMask_field& f, KEY k); + + TRigaiva_array _iva_array; + TRelation * _rel; + TCursor * _cur; + TRectype * _RecPartoDa, *_RecArrivoA; + + TString _reg_cod, _reg_anno, _reg_descr; + TDate _data_da, _data_a, _last_data; + bool _stampa_definitiva; + real _tot_dare, _tot_avere; // valori di partenza + real _tot_dare_progr, _tot_avere_progr; // progressivi + real _tot_dare_gg , _tot_avere_gg ; // giornalieri + real _tot_dare_ac , _tot_avere_ac ; // anno precedente + long _nprog_da, _nprog_mov; + int _num_rig, _stampa_width, _stampa_len; + + TParagraph_string *_descr_conto; + TParagraph_string *_descr_causale; + TParagraph_string *_descr_operazione; + + int _pagine_stampate, _pagine_numerate, _stampa_ok, _pagina_da; + TDate _data_corr, _data_succ; + int _mese_corr, _mese_succ; + int _last_header; // prima riga di intestazione "libera" + + bool _libro_giornale_iva_unico, _libro_cronologico, _stampa_intesta; + bool _occas; // se e' cliente occasionale + bool _gia_settata_riga_mov; // per la stampa no iva + TString _viacf, _civcf, _comcf, _capcf, _statocf; // dati C/F + TString _ragsoc, _paiva, _comunefis, _provfis, _viafis; // dati ditta + TString _cofi, _cap, _anno_es; + TLocalisamfile * _com, *_clifo,*_pconti,*_nditte,*_anag, *_caus; + TTable *_tabreg, *_tabval, *_tabes; + +public: + virtual void preprocess_header(); + virtual void preprocess_footer(); + virtual bool preprocess_page(int, int); + virtual print_action postprocess_page(int, int); + virtual bool preprocess_print(int, int); + virtual print_action postprocess_print(int, int); + virtual void postclose_print(); + + virtual void user_create(); + virtual void user_destroy(); + + virtual void set_page (int, int); + void set_rows (int, int); + void set_page_132(int, int); + void set_page_198(int, int); + void setta_righe_indirizzo(); + int setta_righe_iva(); + void setta_righe_valuta(); + void setta_righe_descr(TParagraph_string*, enum descr); + void calcola_iva(); + virtual bool cancel_hook(); + virtual bool set_print(int); + + int stampa_intestazione_ditta(); + int set_header_132(); + int set_header_198(); + + bool leggi_tabreg(const char *, const char *); + void aggiorna_tabreg(int, int); + void aggiorna_mov(); + void scrivi_numgio(long); + void stampa_totali_giorno(TDate, bool); + void get_dati_ditta (); + TLocalisamfile * get_descr (TLocalisamfile*,TLocalisamfile*,int, int, long); + + bool IsInEsercizio (TDate& da, TDate& a, int anno_eser); + const char * SimboloValuta (const char * cod); + const char * get_descr_caus (const char * codcaus); + + CG3400_application() : _reg_cod(3), _reg_anno(4), _tot_dare_progr(0.00), + _tot_avere_progr (0.00), _data_da(""), _data_a("") + {}; + virtual ~CG3400_application() {}; +}; + +////////////////////////////////////////////////////////////////////////// +// Funzioni legate ai parametri ditta +////////////////////////////////////////////////////////////////////////// +bool libro_giornale_iva_unico() +{ + TConfig conf(CONFIG_DITTA); + + return conf.get("StLgiU") == "X"; +} + +bool libro_cronologico() +{ + TConfig conf(CONFIG_DITTA); + + return conf.get("GsLbCr") == "X"; +} + +TRectype& look_com (const char * cod, TLocalisamfile *comuni) +{ + comuni->zero(); + comuni->put(COM_COM, cod); + comuni->read(); + if (comuni->bad()) + comuni->zero(); + + return comuni->curr(); +} + +bool CG3400_application::IsInEsercizio (TDate& da, TDate& a, int anno_eser) +{ + TTable& TabEs = *_tabes; + TString codtab; + TDate inizio, fine; + + if (!da.ok() || !a.ok()) return FALSE; + + TabEs.zero(); + + codtab << format ("%-4d", anno_eser); + TabEs.put ("CODTAB", codtab); + TabEs.read(); + if (TabEs.good()) + { + inizio = TabEs.get_date ("D0"); + fine = TabEs.get_date ("D1"); + if ((da >= inizio) && (a <= fine)) + return TRUE; + else + { + TString da(inizio.string()); + TString a(fine.string()); + warning_box("Le date devono essere comprese tra %s e %s", (const char*)da, (const char*)a); + return FALSE; + } + } + return FALSE; +} + +const char * CG3400_application::SimboloValuta (const char * cod) +{ + TTable& tab_val = *_tabval; + TString codtab = format ("%-3s", cod); + // static char simbolo; + + tab_val.zero(); + + tab_val.put("CODTAB", codtab); + tab_val.read(); + if (tab_val.good()) + tmp = tab_val.get("S7"); + else + tmp = ""; + + return __tmp; +} + +const char * CG3400_application::get_descr_caus (const char * codcaus) +{ + TLocalisamfile& caus = *_caus; + + caus.zero(); + caus.put (CAU_CODCAUS, codcaus); + + caus.read(); + + if (caus.bad()) + caus.zero(); + + tmp = caus.get(CAU_DESCR); + return __tmp; +} + +TLocalisamfile * CG3400_application::get_descr (TLocalisamfile *pconti, + TLocalisamfile *clifo, + int g, int c, long s) +{ + pconti->zero(); + pconti->put (PCN_GRUPPO, g); + pconti->put (PCN_CONTO , c); + pconti->put (PCN_SOTTOCONTO, s); + + pconti->read(); + + if (pconti->good()) + return pconti; + + TString tipocf = pconti->get(PCN_TMCF); + long codcf = s; + + clifo->zero(); + clifo->put(CLI_CODCF, codcf); + clifo->put(CLI_TIPOCF, tipocf); + + clifo->read(); + + if (clifo->good()) + { + _viacf = clifo->get(CLI_INDCF); + _civcf = clifo->get(CLI_CIVCF); + _comcf = clifo->get(CLI_COMCF); + _capcf = clifo->get(CLI_CAPCF); + _statocf = clifo->get(CLI_STATOCF); + _occas = clifo->get_bool(CLI_OCCAS); + return clifo; + } + + return NULL; +} + +void CG3400_application::get_dati_ditta () +{ + TString codanagr; + TString tipoa; + + _nditte->zero(); + _nditte->put(NDT_CODDITTA, get_firm()); + _nditte->read(); + + if (_nditte->bad()) _nditte->zero(); + + _ragsoc = _nditte->get(NDT_RAGSOC); + codanagr = _nditte->curr().get(NDT_CODANAGR); + tipoa = _nditte->curr().get(NDT_TIPOA); + + _anag->setkey(1); + _anag->zero(); + _anag->put (ANA_TIPOA, tipoa); + _anag->put (ANA_CODANAGR, codanagr); + _anag->read(); + if (_anag->bad()) _anag->zero(); + + _cofi = _anag->get(ANA_COFI); + _paiva = _anag->get(ANA_PAIV); + // _ragsoc = _anag->get(ANA_RAGSOC); + _comunefis = _anag->get(ANA_COMRF); + + if (_comunefis.empty()) + _comunefis = _anag->get(ANF_COMRES); + + TRectype dep = look_com (_comunefis, _com); + + _comunefis = dep.get(COM_DENCOM); + _provfis = dep.get(COM_PROVCOM); + _cap = dep.get(COM_CAPCOM); + if (_comunefis.empty()) + { + _viafis = _anag->get(ANA_INDRF); + _viafis.rtrim(); + _viafis << " " << _anag->curr().get (ANA_CIVRF); + } + else + { + _viafis = _anag->get(ANA_INDRES); + _viafis.rtrim(); + _viafis << " " << _anag->get (ANA_CIVRES); + } +} + +void CG3400_application::user_create() +{ + _libro_giornale_iva_unico = libro_giornale_iva_unico(); + _libro_cronologico = libro_cronologico(); + + _tabreg = new TTable ("REG"); + _tabval = new TTable ("%VAL"); + _tabes = new TTable ("ESC"); + + _nditte = new TLocalisamfile(LF_NDITTE); + _anag = new TLocalisamfile (LF_ANAG); + _com = new TLocalisamfile(LF_COMUNI); + _clifo = new TLocalisamfile(LF_CLIFO); + _pconti = new TLocalisamfile(LF_PCON); + _caus = new TLocalisamfile(LF_CAUSALI); + + _descr_conto = new TParagraph_string ("",10); + _descr_operazione = new TParagraph_string ("",10); + _descr_causale = new TParagraph_string ("",10); + + disable_print_menu(); + + _rel = new TRelation (LF_MOV); + _rel->add (LF_RMOV, "NUMREG=NUMREG"); + _rel->add (LF_RMOVIVA, "NUMREG=NUMREG"); + + _cur = new TCursor (_rel, "", 2); // usa la chiave 2 su MOV + _RecPartoDa = new TRectype(_cur->file(LF_MOV)); + _RecArrivoA = new TRectype(_cur->file(LF_MOV)); + + add_cursor (_cur); + + add_file (LF_MOV); + add_file (LF_RMOV); + add_file (LF_RMOVIVA); +} + +void CG3400_application::user_destroy() +{ + delete _rel; + delete _cur; + delete _RecPartoDa; + delete _RecArrivoA; + + delete _com; delete _clifo; delete _caus; delete _pconti; + delete _nditte; delete _anag; + delete _tabreg; delete _tabes; delete _tabval; + + delete _descr_conto; + delete _descr_operazione; + delete _descr_causale; + delete _nditte; + delete _anag; +} + +void CG3400_application::aggiorna_mov() +{ + TLocalisamfile mov(LF_MOV); + TProgind prnd (mov.items(), "Aggiornamento movimenti ...", FALSE, TRUE); + + long nprog = _nprog_da; + + mov.curr() = *_RecPartoDa; + + for (mov.read(_isgteq, _lock); mov.curr() < *_RecArrivoA && !mov.eof(); mov.next(_lock)) + { + const bool gia_stampato = mov.get_bool(MOV_STAMPATO); + if (!gia_stampato) + { + mov.put (MOV_STAMPATO, TRUE); + mov.put (MOV_NUMGIO, nprog); + mov.rewrite(); + nprog++; + } + else + mov.reread(_unlock); + + prnd.addstatus(1); + } + mov.reread(_unlock); +} + +void CG3400_application::scrivi_numgio(long nprog) +{ + TLocalisamfile *mov = current_cursor()->file(LF_MOV); + + mov->reread(_lock); + mov->put (MOV_NUMGIO, nprog); + mov->rewrite(); +} + +void CG3400_application::stampa_totali_giorno(TDate data, bool ff) +{ + TString dep(_stampa_width); + + dep = "@10gOperazioni del "; + dep << data.string(); + // dep.center_just(); + + set_row (1, "%s", (const char *)dep); + + if (_stampa_width == 132) + // set_row (1, "@94g %15r @112g %15r", &_tot_dare_gg, &_tot_avere_gg ); + set_row (1, "@94g %r @112g %r", &_tot_dare_gg, &_tot_avere_gg ); + else + set_row (1, "@142g %r @164g %r", &_tot_dare_gg, &_tot_avere_gg ); + + if ( (_tot_avere_ac != 0) || (_tot_dare_ac != 0) ) + { + dep = "@10gOperazioni del "; + dep << data.string() << " " << "Anno precedente"; + // dep.center_just(); + set_row (2, "%s", (const char *)dep); + if (_stampa_width == 132) + set_row (2, "@95g %r @112g %r", &_tot_dare_ac, + &_tot_avere_ac ); + else + set_row (2, "@142g %r @164g %r", &_tot_dare_ac, + &_tot_avere_ac ); + _tot_avere_ac = 0.00; + _tot_dare_ac = 0.00; + set_row (3, ""); + } + else + set_row (2, ""); // Lascio una riga vuota dopo il totale + + if (ff) set_auto_ff (TRUE); + else set_auto_ff (FALSE); +} + +// -------------------------------------------------------------------------- +// +// STAMPA A 132 +// +// -------------------------------------------------------------------------- +void CG3400_application::set_page_132 (int file, int counter) +{ + int r = 1; + switch (file) + { + case LF_MOV: + if (_libro_giornale_iva_unico) + { + if (_stampa_definitiva) + set_row(r,"Registrazione n. #-7ld del @d documento n. @7s del @d @56g@s Anno di competenza %s", + &_nprog_mov, + FLD(LF_MOV, MOV_DATAREG), + FLD(LF_MOV, MOV_NUMDOC), + FLD(LF_MOV, MOV_DATADOC), + FLD(LF_MOV, MOV_DESCR), + (const char *)_reg_anno); + else + set_row(r,"Registrazione n. @7,lpn del @d documento n. @7s del @d @56g@s Anno di competenza %s", + FLD(LF_MOV, MOV_NUMREG, "#######"), + FLD(LF_MOV, MOV_DATAREG), + FLD(LF_MOV, MOV_NUMDOC), + FLD(LF_MOV, MOV_DATADOC), + FLD(LF_MOV, MOV_DESCR), + (const char *)_reg_anno); + + } + else + if (!_gia_settata_riga_mov) + { + set_row (r, "Operazioni del @d", FLD(LF_MOV,MOV_DATAREG)); + _gia_settata_riga_mov = TRUE; + } + + break; + + case LF_RMOV: + break; + case LF_RMOVIVA: + break; + default: + break; + } +} + +// -------------------------------------------------------------------------- +// +// STAMPA A 198 +// +// -------------------------------------------------------------------------- +void CG3400_application::set_page_198 (int file, int counter) +{ + int r = 1; + switch (file) + { + case LF_MOV: + break; + case LF_RMOV: + set_row (r, "@d", FLD(LF_RMOV,RMV_DATAREG)); + set_row (r, "@10g@pn/@pn", FLD(LF_RMOV,RMV_NUMREG,"####"), + FLD(LF_RMOV,RMV_NUMRIG,"##")); + set_row (r, " @d", FLD(LF_RMOV,MOV_DATADOC)); + set_row (r, " @pn",FLD(LF_RMOV,MOV_NUMDOC)); + + set_row (r, "@38g@pn",FLD(LF_RMOV, RMV_GRUPPO, "@@.")); + set_row (r, "@pn",FLD(LF_RMOV, RMV_CONTO , "@@.")); + set_row (r, "@pn",FLD(LF_RMOV, RMV_SOTTOCONTO, "@@@@@@")); + + set_row (r, "#50t", &_descr_conto); + set_row (r, "@80g@3s", FLD(LF_MOV, MOV_CODCAUS)); + set_row (r, "#50t", &_descr_causale); + + // set_row (r, "@50s", FLD(LF_RMOV, RMV_DESCR)); + set_row (r, "#50t", &_descr_operazione); + + // Dare e avere sono settati nella preprocess_page + // Cosi' pure l'indirizzo nel caso di gestione libro cronologico + // _descr contiene la descrizione conto o la ragione sociale + // v. preprocess_page + break; + case LF_RMOVIVA: + break; + default: + break; + } +} + +void CG3400_application::set_rows(int file, int counter) +{ + int r=1; + switch (file) + { + case LF_RMOV: + if (_libro_giornale_iva_unico) + { + if (!_stampa_definitiva) set_row (r, "%3d", _num_rig); + set_row (r, "@5g@3s@60g@pn@pn@pn", + FLD(LF_MOV, MOV_CODCAUS), + FLD(LF_RMOV, RMV_GRUPPO, "@@."), + FLD(LF_RMOV, RMV_CONTO , "@@."), + FLD(LF_RMOV, RMV_SOTTOCONTO, "@@@@@@") + ); + } + else // no libro_giornale_iva_unico + { + if (_stampa_definitiva) + set_row (r, "#-7ld", &_nprog_mov); + else + set_row (r, "@7,rn", FLD(LF_RMOV, RMV_NUMREG)); + set_row (r, "@10g@d@28g@pn@pn@pn", + FLD(LF_RMOV, RMV_DATAREG), + FLD(LF_RMOV, RMV_GRUPPO, "@@."), + FLD(LF_RMOV, RMV_CONTO , "@@."), + FLD(LF_RMOV, RMV_SOTTOCONTO, "@@@@@@") + ); + } + break; + default: + break; + } +} + +void CG3400_application::set_page (int file, int counter) +{ + if (_libro_giornale_iva_unico) + set_page_132(file, counter); + else + if (_stampa_width == 132) + set_page_132(file, counter); + else + set_page_198(file, counter); +} + +print_action CG3400_application::postprocess_print(int file, int counter) +{ + switch (file) + { + case LF_RMOV: + break; + case LF_MOV: + { + printer().formfeed(); + *_RecArrivoA = _cur->file(LF_MOV)->curr(); + } + break; + default: + break; + } + return NEXT_PAGE; +} + +void CG3400_application::postclose_print() +{ + const int ultima_fatta = printer().getcurrentpage(); + const int stampate = ultima_fatta - _pagina_da + 1; + if (yesno_box("La stampa e' corretta ? ")) + { + _pagina_da = -1; + aggiorna_mov (); + } + aggiorna_tabreg (_pagina_da, stampate); +} + +void CG3400_application::preprocess_footer() +{ + TString dare = _tot_dare_progr.string("###.###.###.###"); + TString avere = _tot_dare_progr.string("###.###.###.###"); + int r=1; + + if (_stampa_width == 132) + set_footer (r, "@65gTotale progressivi generali: @95g%s @112g%s", + (const char *)dare, + (const char *)avere); + else + set_footer (r, "@100gTotale progressivi generali: %s @164gTotale avere: %s", + (const char *)dare, + (const char *)avere); + +} + +int CG3400_application::stampa_intestazione_ditta() +{ + int r=1; + TString riga(_stampa_width); + + get_dati_ditta(); + set_header (r, "Ditta: %s Via %s %s %s %s", (const char *)_ragsoc, + (const char *)_viafis, (const char *)_cap, + (const char *)_comunefis, (const char *)_provfis); + r++; + riga = "Data @>"; + riga.right_just(_stampa_width-15); // perche' il codice viene espanso nella data con l'anno in 4 caratteri + riga.overwrite (format ("Partita iva %s @24gCodice fiscale %s", (const char*)_paiva, (const char*)_cofi)); + set_header (r, "%s", (const char*) riga); + r++; + + return r; +} + +int CG3400_application::set_header_198() +{ + int r=1; + TString riga(_stampa_width); + TString data_da = _data_da.string(); + TString data_a = _data_a.string(); + + if (_stampa_intesta) + r = stampa_intestazione_ditta(); + + set_header(r, "Codice libro: %s %s @40gdalla data: %s alla data: %s", + (const char *) _reg_cod, (const char *) _reg_descr, + (const char *) data_da, (const char *) data_a); + r++; + + riga.fill('-'); + set_header(r, riga); + r++; + + set_header(r, " Data Numero Documento"); + + riga = "Anno S"; + riga.right_just(_stampa_width); + if (_libro_cronologico) + riga.overwrite(" Codice conto Descrizione conto"); + else + riga.overwrite(" Codice"); + + set_header(r, "%s", (const char*) riga); + r++; + + riga = "Comp B"; + riga.right_just(_stampa_width); + if (_libro_cronologico) + riga.overwrite("Registr. Registraz. data e numero Generalita' cliente/fornitore@82gCod.Causale@102gDescrizionee operazione@142gDARE@164gAVERE"); + else + riga.overwrite("Registr. Registraz. data e numero Conto Descrizione conto@82gCod.Causale@102gDescrizionee operazione@142gDARE@164gAVERE"); + + set_header(r, "%s", (const char*) riga); + r++; + + riga.fill('-'); + set_header(r, riga); + r++; + + return r; +} + +int CG3400_application::set_header_132() +{ + int r=1; + TString riga(_stampa_width); + TString data_da = _data_da.string(); + TString data_a = _data_a.string(); + + if (_stampa_intesta) + r = stampa_intestazione_ditta(); + + set_header(r, "Codice libro: %s %s @50gdalla data: %s alla data: %s", + (const char *) _reg_cod, (const char *) _reg_descr, + (const char *) data_da, (const char *) data_a); + r++; + + riga.fill('-'); + set_header(r, riga); + r++; + + if (_libro_giornale_iva_unico) + { + set_header(r, "Ri"); + if (_libro_cronologico) + set_header(r, "@60gCodice Conto"); + + set_header(r, "@113gImporti@131gS"); + r++; + + set_header(r, "ga@6gCod.Causale@34gDescrizione operazione"); + if (_libro_cronologico) + set_header(r, "@60gGeneralita' cliente/fornitore"); + + set_header(r, "@106gDARE@122gAVERE@131gB"); + r++; + } + else + //////////////////////////////////////////////////////////////////// + // NO LIBRO GIORNALE IVA UNICO + //////////////////////////////////////////////////////////////////// + { + set_header(r, "Numero@12gDocumento@28gCodice@115gImporti@127g A S"); + r++; + if (_stampa_definitiva) + set_header(r, "Riga"); + else + set_header(r, "Regist."); + + set_header(r, "@10gData e numero@28gConto@41gDescrizione conto@68gDescrizione operazione@106gDare@122gAvere@127g C B"); + r++; + } + + riga.fill('-'); + set_header(r, riga); + r++; + return r; +} + +void CG3400_application::preprocess_header() +{ + int pag = printer().getcurrentpage(); + TString dare = _tot_dare_progr.string(REAL_PICTURE); + TString avere = _tot_dare_progr.string(REAL_PICTURE); + int r = _last_header; + + if (pag > 0) // Stampa riporti + { + TString dep (_stampa_width); + dare.right_just(); + avere.right_just(); + if (_stampa_width == 132) + dep = format ("@86gRiporto:@95g %15s @112g %15s", (const char *) dare, + (const char *) avere ); + else + dep = format ("@100gRiporto %s @140g %s", (const char *) dare, + (const char *) avere ); + set_header (r, "%s", (const char *) dep); + } +} + +// +// PREPROCESS_PRINT +// +// Se non ci sono items nel cursore (= se non ci sono movimenti) +// la stampa e' abortita. +// +// stampa_ok = -1 -> la stampa precedente era OK +// stampa_ok = x -> la stampa precedente non e' andata a buon fine +// ed era partita dalla pagina x. +// +// Se la stampa precedente e' andata male, setto la pagina corrente a +// quella salvata in stampa_ok, e la pagina da cui parte la stampa vera e +// propria a quella che mi dice l'utente: +// +// set_page_number (stampa_ok) +// setfrompage (pagina_da) +// +bool CG3400_application::preprocess_print(int file, int counter) +{ + int i; + switch (file) + { + case LF_MOV: + reset_print(); + reset_header(); + printer().footerlen(RIGHE_FOOTER); + _gia_settata_riga_mov = FALSE; // Stampa o no la riga di mov (solo se + // NO stampa giornale_iva_unico + _num_rig = 0; + _tot_dare_ac = 0.00; + _tot_avere_ac = 0.00; + _tot_dare_gg = 0.00; + _tot_avere_gg = 0.00; + _tot_dare_progr = _tot_dare; + _tot_avere_progr = _tot_avere; + _iva_array.destroy(); + if (current_cursor()->items() == 0) + { + warning_box ("Non ci sono movimenti.\nLa stampa e' annullata"); + return FALSE; + } + + _nprog_mov = _nprog_da; + + *_RecPartoDa = _cur->file(LF_MOV)->curr(); + + for (i=1; i 0) + return REPEAT_PAGE; + // else + // return NEXT_PAGE; + } + _cur->save_status(); + ++(*_cur); + _data_succ = _cur->file(LF_MOV)->get_date(MOV_DATAREG); + _mese_succ = _data_succ.month(); + --(*_cur); + _cur->restore_status(); + if (_data_corr != _data_succ) + { + reset_print(); + if (_mese_succ != _mese_corr) nuovo_mese = TRUE; + else nuovo_mese = FALSE; + stampa_totali_giorno(_data_corr, nuovo_mese); + _tot_dare_gg = 0.00; + _tot_avere_gg = 0.00; + _gia_settata_riga_mov = FALSE; + return REPEAT_PAGE; + } + else + _gia_settata_riga_mov = TRUE; + break; + + case LF_RMOVIVA: + default: + set_auto_ff(FALSE); // ff gia' fatto prima + break; + } + return NEXT_PAGE; +} + +// +// PREPROCESS_PAGE +// +// Non stampo niente se: +// +// 1. STAMPATO = TRUE +// OPPURE +// 2. non ci sono righe di RMOV +// +bool CG3400_application::preprocess_page(int file, int counter) +{ + TLocalisamfile * boh; + int g, c; + long s; + bool gia_stampato=FALSE; + TString sezione, caus, rmv_descr; + real importo; + + if (counter) return TRUE; + + switch (file) + { + case LF_MOV: + _num_rig=0; + _iva_array.destroy(); + + if (!current_cursor()->is_first_match(LF_RMOV)) + return FALSE; + + gia_stampato = current_cursor()->file(LF_MOV)->get_bool(MOV_STAMPATO); + if (gia_stampato) + if (_stampa_definitiva) + return FALSE; + else + set_row (1, "@131g*"); // stampo un * se mov. gia stampato + + if (_libro_giornale_iva_unico) + _nprog_mov++; + + _data_corr = _cur->file(LF_MOV)->get_date(MOV_DATAREG); + _mese_corr = _data_corr.month(); + _anno_es = _cur->file(LF_MOV)->get(MOV_ANNOES); + caus = _cur->file(LF_MOV)->get(MOV_CODCAUS); + break; + case LF_RMOV: + set_auto_ff(FALSE); + _num_rig++; + reset_print(); + set_rows(file, counter); + if (_stampa_width == 132) + { + *_descr_causale = get_descr_caus(caus); + _descr_causale->set_width(10); + } + else + { + *_descr_causale = get_descr_caus(caus); + _descr_causale->set_width(198); + } + setta_righe_descr(_descr_causale, causale); + rmv_descr = current_cursor()->file(LF_RMOV)->get(RMV_DESCR); + if (_stampa_width == 132) + { + *_descr_operazione = (const char *)rmv_descr; + _descr_operazione->set_width(10); + } + else + { + *_descr_operazione = (const char *)rmv_descr; + _descr_operazione->set_width(198); + } + setta_righe_descr(_descr_operazione, operazione); + if (!_libro_giornale_iva_unico) + _nprog_mov++; + g = current_cursor()->curr(LF_RMOV).get_int(RMV_GRUPPO); + c = current_cursor()->curr(LF_RMOV).get_int(RMV_CONTO); + s = current_cursor()->curr(LF_RMOV).get_long(RMV_SOTTOCONTO); + // _descr = get_descr (g,c,s); + boh = get_descr (_pconti, _clifo, g,c,s); + + if (boh!=NULL) + { + if (boh->num() == LF_PCON) + { + if (_stampa_width == 132) + { + *_descr_conto = (const char*)boh->get(PCN_DESCR); + _descr_conto->set_width(10); + } + else + { + *_descr_conto = (const char*)boh->get(PCN_DESCR); + _descr_conto->set_width(198); + } + setta_righe_descr(_descr_conto, conto); + } + else + if (boh->num() == LF_CLIFO) + { + if (_stampa_width == 132) + { + *_descr_conto = (const char*)boh->get(CLI_RAGSOC); + _descr_conto->set_width(10); + } + else + { + *_descr_conto = (const char*)boh->get(CLI_RAGSOC); + _descr_conto->set_width(198); + } + setta_righe_descr(_descr_conto, conto); + if (_libro_cronologico) + setta_righe_indirizzo(); + } + } + sezione = _cur->file(LF_RMOV)->get (RMV_SEZIONE); + importo = _cur->file(LF_RMOV)->get_real (RMV_IMPORTO); + + // imp = importo.string ("######"); + if (sezione == "D") + { + _tot_dare_progr += importo; // prog. generali + if (_anno_es != _reg_anno) + _tot_dare_ac += importo; // prog. anno precedente + else + _tot_dare_gg += importo; // prog. giornalieri + + if (_stampa_width == 132) + set_row (1, "@95g%r", &importo); + else + set_row (1, "@142g%r", &importo); + } + else + { + _tot_avere_progr += importo; + if (_anno_es != _reg_anno) + _tot_avere_ac += importo; + else + _tot_avere_gg += importo; + if (_stampa_width == 132) + set_row (1, "@112g%r", &importo); + else + set_row (1, "@164g%r", &importo); + } + break; + case LF_RMOVIVA: + set_auto_ff(FALSE); + if (_libro_giornale_iva_unico) + { + calcola_iva (); + setta_righe_valuta(); + } + break; + default: + set_auto_ff(FALSE); + break; + } + return TRUE; +} + +void CG3400_application::calcola_iva() +{ + TString codiva; + int tipocr, tipodet; + real impo, impos; + TRectype iva (_cur->file(LF_RMOVIVA)->curr()); + + if (!iva.empty()) + { + impo = iva.get_real (RMI_IMPONIBILE); + impos = iva.get_real (RMI_IMPOSTA); + tipocr = iva.get_int (RMI_TIPOCR); + tipodet = iva.get_int (RMI_TIPODET); + codiva = iva.get (RMI_CODIVA); + _iva_array.add_riga(impo,impos,codiva,tipodet,0.00,0.00); + } +} + +void CG3400_application::setta_righe_descr(TParagraph_string* str, enum descr des) +{ + const char * r; + int i = 1; + TString frm; + + switch (des) + { + case causale: + if (_libro_giornale_iva_unico) + frm = "@8g%s"; + else + frm = "@57g%s"; + break; + case conto: + if (_libro_giornale_iva_unico) + frm = "@73g%s"; + else + frm = "@41g%s"; + break; + case operazione: + if (_libro_giornale_iva_unico) + frm = "@34g%s"; + else + frm = "@68g%s"; + break; + default: + break; + } + while ((r = str->get()) != NULL) + { + // reset_row(i); + set_row (i, (const char*)frm, r); + i++; + } +} + +int CG3400_application::setta_righe_iva() +{ + int r=0; + + for (int j = 0; j < _iva_array.items(); j++) + { + TRigaiva& riga = (TRigaiva&)_iva_array[j]; + r = j+1; + set_row(r, "Imponibile@12g%r", &riga._imponibile); + set_row(r, "@31gImposta@39g%r", &riga._imposta); + set_row(r, "@58gCodice Iva@68g%3s", (const char*)riga._codiva); + switch (riga._tipodet) + { + case 0 : set_row(r, "@73gDetraibile"); + break; + case 1 : set_row(r, "@73gIndetraibile su op.es."); + break; + case 3 : set_row(r, "@73gPassaggi interni"); + break; + case 9 : set_row(r, "@73gIndetraibile art.19"); + break; + default: break; + } + } + _iva_array.destroy(); + return r; +} + +void CG3400_application::setta_righe_valuta() +{ + TString simbolo, codval; + bool intracom; + + codval = current_cursor()->file(LF_MOV)->get(MOV_CODVAL); + intracom = current_cursor()->curr(LF_RMOVIVA).get_bool(RMI_INTRA); + simbolo = SimboloValuta(codval); + + // _allegb = CausAlleg(_codcaus); + // _descr_doc = DescrDoc(_tipodoc); + // _totdocumenti += _totdoc; + // _ricser = current_cursor()->curr(LF_RMOVIVA).get_int(RMI_RICSER); + // long numeroreg = cur->curr(LF_RMOVIVA).get_long(RMI_NUMREG); + + if ((codval != "LIT") && intracom) + { + reset_row(1); + set_row(1,"Corr.in lire@14g@pN", + FLD(LF_RMOVIVA,RMI_CORRLIRE,"###.###.###.###.###")); + set_row(1,"@34gCorr.in valuta@49g@pN", + FLD(LF_RMOVIVA,RMI_CORRVALUTA,"###.###.###.###.###")); + if (simbolo.not_empty()) + set_row(1,"@53g%.5s", (const char *)simbolo); + else + set_row(1,"@53g%.3s", (const char *)codval); + } +} + +void CG3400_application::setta_righe_indirizzo() +{ + TString comune, prov; + + // Se e' un cliente occasionale leggo indirizzo da mov, senno' e' stato + // gia' letto da clifo nella get_descr, richiamata nella preprocess_page + if (_occas) + { + TCursor * cur = current_cursor(); TLocalisamfile * occ = cur->file(LF_OCCAS); - _viacf = occ->get (OCC_INDIR); - _civcf = occ->get (OCC_CIV); - _capcf = occ->get (OCC_CAP); - _comcf = occ->get (OCC_COM); + _viacf = occ->get (OCC_INDIR); + _civcf = occ->get (OCC_CIV); + _capcf = occ->get (OCC_CAP); + _comcf = occ->get (OCC_COM); + + /****** + _viacf = cur->file(LF_MOV)->get (MOV_OCINDIR); + _civcf = cur->file(LF_MOV)->get (MOV_OCCIV); + _capcf = cur->file(LF_MOV)->get (MOV_OCCAP); + _comcf = cur->file(LF_MOV)->get (MOV_OCCOM); + ********/ + } + + TRectype dep = look_com (_comcf, _com); + comune = dep.get(COM_DENCOM); + prov = dep.get(COM_PROVCOM); + if (_libro_giornale_iva_unico) + { + set_row (2, "@64g%s %s", (const char *)_viacf, (const char *)_civcf); + set_row (3, "@64g%s %s %s", (const char *)_capcf, (const char *)comune, + (const char *) prov); + } + else // no libro iva unico. Cambia la colonna di inizio + { + set_row (2, "@31g%s %s", (const char *)_viacf, (const char *)_civcf); + set_row (3, "@31g%s %s %s", (const char *)_capcf, (const char *)comune, + (const char *) prov); + } +} + +// +// Lettura/aggiornamento tabella registri +// +void CG3400_application::aggiorna_tabreg(int partito_da, int stampate) +{ + TString codtab = format ("%4s%-3s", (const char*) _reg_anno, + (const char*) _reg_cod); + _tabreg->zero(); + _tabreg->put("CODTAB", codtab); + _tabreg->read(); + + if (_tabreg->good()) + { + _tabreg->put ("I1", _pagine_stampate + stampate); + _tabreg->put ("I7", partito_da); // partito_da = -1 se stampa OK + _tabreg->put ("I6", _nprog_mov); + _tabreg->put ("R1", _tot_dare_progr); + _tabreg->put ("R2", _tot_avere_progr); + _tabreg->put ("D3", _data_a); + _tabreg->rewrite(); + } +} + +bool CG3400_application::leggi_tabreg(const char * reg_cod, + const char * reg_anno) +{ + TString codtab = format ("%4s%-3s", reg_anno, reg_cod); + + _tabreg->zero(); + _tabreg->put("CODTAB", codtab); + _tabreg->read(); + + if (_tabreg->good()) + { + _pagine_stampate = _tabreg->get_int("I1"); + _pagine_numerate = _tabreg->get_int("I2"); + _stampa_ok = _tabreg->get_int("I7"); + _nprog_da = _tabreg->get_long ("I6"); + _tot_dare = _tabreg->get_real ("R1"); + _tot_avere = _tabreg->get_real ("R2"); + _last_data = _tabreg->get_date ("D3"); + _stampa_intesta = _tabreg->get_bool ("B9"); + _reg_descr = _tabreg->get ("S0"); + } + return TRUE; +} + +//----------------------------------------------------------------------- +// +// MASCHERE +// +//----------------------------------------------------------------------- + +bool mask_a_data (TMask_field& f, KEY k) +{ + CG3400_application * app = (CG3400_application*) MainApp(); + if (k == K_ENTER) + { + TDate da(f.mask().get(DATA_DA)); + TDate a(f.mask().get(DATA_A)); + int anno = atoi(f.mask().field(ANNO_ESER).get()); + if ( (f.dlg() == DATA_DA) && (anno == 0 ) ) + f.mask().field(ANNO_ESER).set (format ("%4d",da.year())); + if (!app->IsInEsercizio(da,a,anno)) + return FALSE; + } + return TRUE; +} + +// +// MASK_A_COD_REG +// +// Aggiorna il campo PAGINA_DA della maschera +// +// Legge la tabella dei registri e controlla se la stampa precedente +// era andata a buon fine. +// Se no, riempie il campo PAGINA_DA con il valore precedente. +// Se si', mette semplicemente l'ultimo numero di pagina precedente + 1 +// +bool mask_a_cod_reg (TMask_field& f, KEY k) +{ + TString reg_cod(""),reg_anno(""); + + if (k == K_TAB) + { + CG3400_application * a = (CG3400_application*) MainApp(); + + reg_cod = f.mask().field(REG_COD).get(); + reg_anno = f.mask().field(ANNO_ESER).get(); + + a->leggi_tabreg(reg_cod, reg_anno); + + TString pag(8), stok(8); + pag << (a->_pagine_stampate+1); + stok << a->_stampa_ok; + if (a->_stampa_ok == -1) // stampa precedente andata bene + f.mask().field(PAGINA_DA).set(pag); + else + f.mask().field(PAGINA_DA).set(stok); + + f.mask().field(DATA_DA).set (a->_last_data.string()); + + } + return TRUE; +} + +// +// mask_b_ripristina +// +// Se premo il bottone rimetto i valori precedenti +// dentro ai campi (per ripetere la stampa) +// +bool mask_b_ripristina (TMask_field& f, KEY k) +{ + CG3400_application * a = (CG3400_application*) MainApp(); + + if (k == K_TAB) + { + f.mask().field(PROGR_DARE).set(a->_tot_dare.string()); + f.mask().field(ULTIMA_DATA).set(a->_last_data.string()); + f.mask().field(N_RIGA_STAMPATO).set(format ("%6d", a->_nprog_da)); + } + return TRUE; +} + +bool CG3400_application::set_print(int) +{ + TMask ma ("cg3400a"); + TMask mb ("cg3400b"); + KEY tasto; + + ma.set_handler (REG_COD, mask_a_cod_reg); + ma.set_handler (DATA_DA, mask_a_data); + ma.set_handler (DATA_A, mask_a_data); + mb.set_handler (DLG_RIPRISTINA, mask_b_ripristina); + + // m.set_handler (REG_ANNO, mask_set_pagina_da); + // m.set_handler (REG_DESC, mask_set_pagina_da); + + tasto = ma.run(); + + if (tasto == K_ENTER) + { + _reg_cod = ma.get(REG_COD); + _reg_anno = ma.get(ANNO_ESER); + _stampa_definitiva = (bool) (ma.get(STAMPA_DEF) == "X"); + _data_da = ma.get(DATA_DA); + _data_a = ma.get(DATA_A); + _pagina_da = atoi(ma.get(PAGINA_DA)); + _stampa_width = (int)ma.get_long(STAMPA_WIDTH); + _stampa_len = (int)ma.get_long(STAMPA_LEN); + + if (_stampa_len) printer().formlen(_stampa_len); + if (_stampa_width == 1) _stampa_width = 132; + else _stampa_width = 198; + + TRectype da (_cur->file(LF_MOV)); + TRectype a (_cur->file(LF_MOV)); + + da.zero(); + a.zero(); + da.put(MOV_DATAREG, _data_da); + a.put (MOV_DATAREG, _data_a); + + _cur->setregion(da, a); + + mb.set (PROGR_DARE, _tot_dare.string()); + mb.set (N_RIGA_STAMPATO, _nprog_da); + mb.set (ULTIMA_DATA, _last_data.string()); + tasto = mb.run(); + if (tasto == K_ENTER) + return TRUE; + else + return FALSE; + } + return FALSE; +} + +int cg3400 (int argc, char * argv[]) +{ + CG3400_application app; + app.run(argc, argv, "Stampa libro giornale"); + return TRUE; +} -/****** - _viacf = cur->file(LF_MOV)->get (MOV_OCINDIR); - _civcf = cur->file(LF_MOV)->get (MOV_OCCIV); - _capcf = cur->file(LF_MOV)->get (MOV_OCCAP); - _comcf = cur->file(LF_MOV)->get (MOV_OCCOM); -********/ - } - - TRectype dep = look_com (_comcf, _com); - comune = dep.get(COM_DENCOM); - prov = dep.get(COM_PROVCOM); - if (_libro_giornale_iva_unico) - { - set_row (2, "@64g%s %s", (const char *)_viacf, (const char *)_civcf); - set_row (3, "@64g%s %s %s", (const char *)_capcf, (const char *)comune, - (const char *) prov); - } - else // no libro iva unico. Cambia la colonna di inizio - { - set_row (2, "@31g%s %s", (const char *)_viacf, (const char *)_civcf); - set_row (3, "@31g%s %s %s", (const char *)_capcf, (const char *)comune, - (const char *) prov); - } -} - -// -// Lettura/aggiornamento tabella registri -// -void CG3400_application::aggiorna_tabreg(int partito_da, int stampate) -{ - TString codtab = format ("%4s%-3s", (const char*) _reg_anno, - (const char*) _reg_cod); - _tabreg->zero(); - _tabreg->put("CODTAB", codtab); - _tabreg->read(); - - if (_tabreg->good()) - { - _tabreg->put ("I1", _pagine_stampate + stampate); - _tabreg->put ("I7", partito_da); // partito_da = -1 se stampa OK - _tabreg->put ("I6", _nprog_mov); - _tabreg->put ("R1", _tot_dare_progr); - _tabreg->put ("R2", _tot_avere_progr); - _tabreg->put ("D3", _data_a); - _tabreg->rewrite(); - } -} - -bool CG3400_application::leggi_tabreg(const char * reg_cod, - const char * reg_anno) -{ - TString codtab = format ("%4s%-3s", reg_anno, reg_cod); - - _tabreg->zero(); - _tabreg->put("CODTAB", codtab); - _tabreg->read(); - - if (_tabreg->good()) - { - _pagine_stampate = _tabreg->get_int("I1"); - _pagine_numerate = _tabreg->get_int("I2"); - _stampa_ok = _tabreg->get_int("I7"); - _nprog_da = _tabreg->get_long ("I6"); - _tot_dare = _tabreg->get_real ("R1"); - _tot_avere = _tabreg->get_real ("R2"); - _last_data = _tabreg->get_date ("D3"); - _stampa_intesta = _tabreg->get_bool ("B9"); - _reg_descr = _tabreg->get ("S0"); - } - return TRUE; -} - -//----------------------------------------------------------------------- -// -// MASCHERE -// -//----------------------------------------------------------------------- - -bool mask_a_data (TMask_field& f, KEY k) -{ - CG3400_application * app = (CG3400_application*) MainApp(); - if (k == K_ENTER) - { - TDate da(f.mask().get(DATA_DA)); - TDate a(f.mask().get(DATA_A)); - int anno = atoi(f.mask().field(ANNO_ESER).get()); - if ( (f.dlg() == DATA_DA) && (anno == 0 ) ) - f.mask().field(ANNO_ESER).set (format ("%4d",da.year())); - if (!app->IsInEsercizio(da,a,anno)) - return FALSE; - } - return TRUE; -} - -// -// MASK_A_COD_REG -// -// Aggiorna il campo PAGINA_DA della maschera -// -// Legge la tabella dei registri e controlla se la stampa precedente -// era andata a buon fine. -// Se no, riempie il campo PAGINA_DA con il valore precedente. -// Se si', mette semplicemente l'ultimo numero di pagina precedente + 1 -// -bool mask_a_cod_reg (TMask_field& f, KEY k) -{ - TString reg_cod(""),reg_anno(""); - - if (k == K_TAB) - { - CG3400_application * a = (CG3400_application*) MainApp(); - - reg_cod = f.mask().field(REG_COD).get(); - reg_anno = f.mask().field(ANNO_ESER).get(); - - a->leggi_tabreg(reg_cod, reg_anno); - - TString pag(8), stok(8); - pag << (a->_pagine_stampate+1); - stok << a->_stampa_ok; - if (a->_stampa_ok == -1) // stampa precedente andata bene - f.mask().field(PAGINA_DA).set(pag); - else - f.mask().field(PAGINA_DA).set(stok); - - f.mask().field(DATA_DA).set (a->_last_data.string()); - - } - return TRUE; -} - -// -// mask_b_ripristina -// -// Se premo il bottone rimetto i valori precedenti -// dentro ai campi (per ripetere la stampa) -// -bool mask_b_ripristina (TMask_field& f, KEY k) -{ - CG3400_application * a = (CG3400_application*) MainApp(); - - if (k == K_TAB) - { - f.mask().field(PROGR_DARE).set(a->_tot_dare.string()); - f.mask().field(ULTIMA_DATA).set(a->_last_data.string()); - f.mask().field(N_RIGA_STAMPATO).set(format ("%6d", a->_nprog_da)); - } - return TRUE; -} - -bool CG3400_application::set_print(int) -{ - TMask ma ("cg3400a"); - TMask mb ("cg3400b"); - KEY tasto; - - ma.set_handler (REG_COD, mask_a_cod_reg); - ma.set_handler (DATA_DA, mask_a_data); - ma.set_handler (DATA_A, mask_a_data); - mb.set_handler (DLG_RIPRISTINA, mask_b_ripristina); - -// m.set_handler (REG_ANNO, mask_set_pagina_da); -// m.set_handler (REG_DESC, mask_set_pagina_da); - - tasto = ma.run(); - - if (tasto == K_ENTER) - { - _reg_cod = ma.get(REG_COD); - _reg_anno = ma.get(ANNO_ESER); - _stampa_definitiva = (bool) (ma.get(STAMPA_DEF) == "X"); - _data_da = ma.get(DATA_DA); - _data_a = ma.get(DATA_A); - _pagina_da = atoi(ma.get(PAGINA_DA)); - _stampa_width = (int)ma.get_long(STAMPA_WIDTH); - _stampa_len = (int)ma.get_long(STAMPA_LEN); - - if (_stampa_len) printer().formlen(_stampa_len); - if (_stampa_width == 1) _stampa_width = 132; - else _stampa_width = 198; - - TRectype da (_cur->file(LF_MOV)); - TRectype a (_cur->file(LF_MOV)); - - da.zero(); - a.zero(); - da.put(MOV_DATAREG, _data_da); - a.put (MOV_DATAREG, _data_a); - - _cur->setregion (&da, &a); - - mb.set (PROGR_DARE, _tot_dare.string()); - mb.set (N_RIGA_STAMPATO, _nprog_da); - mb.set (ULTIMA_DATA, _last_data.string()); - tasto = mb.run(); - if (tasto == K_ENTER) - return TRUE; - else - return FALSE; - } - return FALSE; -} - -int cg3400 (int argc, char * argv[]) -{ - CG3400_application app; - app.run(argc, argv, "Stampa libro giornale"); - return TRUE; -} - diff --git a/cg/cg4300.cpp b/cg/cg4300.cpp index dc42e7441..7240e829f 100755 --- a/cg/cg4300.cpp +++ b/cg/cg4300.cpp @@ -1,327 +1,327 @@ -// ------------------------------------------------------------ -// Calcolo liquidazioni -// Part 1: interfaccia -// fv 21-1-94 -// ------------------------------------------------------------ - -#include "cg4300.h" -#include "cg4300a.h" - -void CG4300_App::user_create() -{ - TProgind pnd(3,"Preparazione archivi\nPrego attendere", - FALSE, TRUE, 30); - - _nditte = new TRelation(LF_NDITTE); - _nditte->add(LF_ATTIV,"CODDITTA=CODDITTA"); - _nditte_r = &(_nditte->curr()); - _att_r = &(_nditte->curr(LF_ATTIV)); - - _ditte = new TArray_sheet(-1, -1, 0, 0, "Selezione Ditte", - "@1|Cod.@5|Ragione Sociale@50|Vers."); - _n_ditte = 0l; - - pnd.addstatus(1); - - for (_nditte->first(); !_nditte->eof(); _nditte->next()) - { - TString cod = _nditte_r->get("CODDITTA"); - TString vers = _nditte_r->get("FREQVIVA"); - _n_ditte++; - - TToken_string* d = new TToken_string(" "); - - // add record - d->add(cod); - d->add(_nditte_r->get("RAGSOC")); - d->add(vers); - _nomiditte.add(d); - } - - pnd.addstatus(1); - - _rel = new TRelation(LF_MOV); - _rel->add(LF_RMOVIVA,"NUMREG=NUMREG"); - - _cur = new TCursor(_rel); - (*_cur) = 0; - - _pim = new TTable("PIM"); - _ppa = new TTable("PPA"); - _plm = new TTable("PLM"); - _ptm = new TTable("PTM"); - _lim = new TTable("LIM"); - _pla = new TTable("PLA"); - _reg = new TTable("REG"); - _iva = new TTable("%IVA"); - _del = new TTable("%DEL"); - _lia = new TTable("LIA"); - - _mov = _cur->file(LF_MOV); - _rmoviva = _cur->file(LF_RMOVIVA); - - _pim_r = &(_pim->curr()); - _plm_r = &(_plm->curr()); - _ptm_r = &(_ptm->curr()); - _lim_r = &(_lim->curr()); - _iva_r = &(_iva->curr()); - _del_r = &(_del->curr()); - _pla_r = &(_pla->curr()); - _ppa_r = &(_ppa->curr()); - _reg_r = &(_reg->curr()); - _rmoviva_r = &(_cur->curr(LF_RMOVIVA)); - _mov_r = &(_mov->curr()); - - - // ACHTUNG: tutti i _codatt (codici attivita') sono - // in realta' composti dal codice attivita' piu' il - // tipo attivita' (1 o 2) - - _pim_anno = new TRecfield(*_pim_r,"CODTAB",0,3); - _pim_codatt = new TRecfield(*_pim_r,"CODTAB",4,9); - _pim_codreg = new TRecfield(*_pim_r,"CODTAB",10,12); - _pim_mese = new TRecfield(*_pim_r,"CODTAB",13,14); - _pim_tipocr = new TRecfield(*_pim_r,"CODTAB",15,15); - _pim_codiva = new TRecfield(*_pim_r,"CODTAB",16,17); - _ppa_year = new TRecfield(*_ppa_r,"CODTAB",0,3); - _ppa_codatt = new TRecfield(*_ppa_r,"CODTAB",4,9); - _ppa_month = new TRecfield(*_ppa_r,"CODTAB",10,11); - _ppa_kind = new TRecfield(*_ppa_r,"CODTAB",12,12); - _plm_anno = new TRecfield(*_plm_r,"CODTAB",0,3); - _plm_codatt = new TRecfield(*_plm_r,"CODTAB",4,9); - _plm_mese = new TRecfield(*_plm_r,"CODTAB",10,11); - _ptm_anno = new TRecfield(*_ptm_r,"CODTAB",0,3); - _ptm_codatt = new TRecfield(*_ptm_r,"CODTAB",4,9); - _ptm_mese = new TRecfield(*_ptm_r,"CODTAB",10,11); - _lim_anno = new TRecfield(*_lim_r,"CODTAB",0,3); - _lim_mese = new TRecfield(*_lim_r,"CODTAB",4,6); - _pla_anno = new TRecfield(*_pla_r,"CODTAB",0,3); - _pla_codatt = new TRecfield(*_pla_r,"CODTAB",4,9); - _del_ditta = new TRecfield(*_del_r,"CODTAB",0,4); - _del_anno = new TRecfield(*_del_r,"CODTAB",5,8); - _del_mese = new TRecfield(*_del_r,"CODTAB",9,10); - _del_tipo = new TRecfield(*_del_r,"CODTAB",11,11); - - pnd.addstatus(1); - set_real_picture(REAL_PICTURE); -} - -void CG4300_App::user_destroy() -{ - delete _ditte; - - delete _pim_anno; - delete _pim_codreg; - delete _pim_mese; - delete _pim_tipocr; - delete _pim_codiva; - delete _ppa_year; - delete _ppa_codatt; - delete _ppa_month; - delete _ppa_kind; - delete _plm_anno; - delete _plm_codatt; - delete _plm_mese; - delete _ptm_anno; - delete _ptm_codatt; - delete _ptm_mese; - delete _lim_anno; - delete _lim_mese; - delete _pla_anno; - delete _pla_codatt; - delete _pim_codatt; - delete _del_ditta; - delete _del_anno; - delete _del_mese; - delete _del_tipo; - - delete _pim; - delete _ppa; - delete _plm; - delete _ptm; - delete _lim; - delete _pla; - delete _del; - - delete _nditte; - delete _rel; - delete _cur; -} - -bool CG4300_App::set_print(int n) -{ - TString yy = _year; - - _descr_arr.destroy(); - - switch(n) - { - case 1: // liquidazione - _isprint = TRUE; - if (set_liquidazione()) - { - if (_selected.ones() > 0l) - { - if (_year != yy) - { - TString cond(format("ANNOES=%s",(const char*)_year)); - _cur->filter(cond); - } - recalc_all(); - return _isprint; - } - else warning_box("Nessuna ditta selezionata!"); - } - break; - case 2: // estrazione deleghe - _isprint = FALSE; - if (set_deleghe()) - { - if (_year != yy) - { - TString cond(format("ANNOES=%s",(const char*)_year)); - _cur->filter(cond); - } - extract_deleghe(); - return FALSE; - } - break; - case 3: // calcolo acconto - _isprint = TRUE; - if (set_acconto()) - { - if (_year != yy) - { - TString cond(format("ANNOES=%s",(const char*)_year)); - _cur->filter(cond); - } - recalc_acconti(); - return _isprint; - } - break; - } - return FALSE; -} - - -bool CG4300_App::set_liquidazione() -{ - TMask m("cg4300a.msk"); - - m.field(CG43_FLD_SELECTED).set("0"); - _selected.reset(); - TBit_array selected = _selected; - - KEY k; - // stampa abilitata per default - m.set(CG43_CHK_STAMPA,"X"); - - do { - k = m.run(); - - if (k == K_ESC) break; - - _what = (wht)atoi(m.get(CG43_RDB_VERS)); - _month = atoi(m.get(CG43_LST_MESE)); - - if (_what == all) - { - if (_month != 3 && _month != 6 && _month != 9 && - _month != 12 && _month != 13) - _what = mnt; - } - else if (_what == quarter) - _month = atoi(m.get(CG43_LST_TRIM)); - - _year = m.get(CG43_FLD_ANNO); - _date = m.get(CG43_FLD_DATA); - _isprint = m.get_bool(CG43_CHK_STAMPA); - _recalc = (recalc)m.get_long(CG43_LST_CALC); - _isfinal = m.get_bool(CG43_CHK_FINAL); - - if (_isprint) printer().setdate(_date); - - TString from = m.get(CG43_FLD_DFR); - TString to = m.get(CG43_FLD_DTO); - - m.field(CG43_FLD_DFR).set(""); - m.field(CG43_FLD_DTO).set(""); - - // ------------------------------------------------ - m.first_focus(k); - - long j, cnt, chk; int i; - - switch(k) - { - case DLG_SELECT: - // build sheet - _ditte->destroy(); chk = 0l; - for (i = 0; i < _nomiditte.items(); i++) - { - if (_selected[i]) continue; - TToken_string d = (const char*)((TToken_string&)_nomiditte[i]); - TString cod = d.get(0); - TString vers = d.get(2); - if ((_what == mnt && vers == "T") || - (_what == quarter && vers == "M")) - continue; - - _ditte->add(d); - - // check - if (!from.empty() || !to.empty()) - { - if (from.empty()) from = "0"; - if (to.empty()) to = "999999999"; - if (atol(cod) >= atol(from) && atol(cod) <= atol(to)) - _ditte->check(chk++); - } - } - - // seleziona e aggiungi alle gia' selezionate - if (_ditte->run() == K_ENTER) - { - cnt = 0; - for (j = 0l; j < _n_ditte; j++) - { - if (_selected[j]) continue; - if (_ditte->checked(cnt++)) - selected.set(j); - } - _selected |= selected; - selected.reset(); - } - m.field(CG43_FLD_SELECTED).set(format("%ld",(long)_selected.ones())); - break; - case CG43_BUT_ANN: - _selected.reset(); - m.field(CG43_FLD_SELECTED).set("0"); - break; - case CG43_BUT_CHK: - { - _ditte->destroy(); - for (i = 0; i < _nomiditte.items(); i++) - { - TToken_string d = (const char*)((TToken_string&)_nomiditte[i]); - _ditte->add(d); - if (_selected[i]) _ditte->check(i); - } - _ditte->disable_check(); - _ditte->run(); - _ditte->enable_check(); - } - break; - } - } - while (k != K_ENTER && k != K_ESC); - - return k == K_ENTER; -} - -int cg4300(int argc, char* argv[]) -{ - CG4300_App main_app; - main_app.run(argc, argv, "Liquidazione IVA"); - return TRUE; -} +// ------------------------------------------------------------ +// Calcolo liquidazioni +// Part 1: interfaccia +// fv 21-1-94 +// ------------------------------------------------------------ + +#include "cg4300.h" +#include "cg4300a.h" + +void CG4300_App::user_create() +{ + TProgind pnd(3,"Preparazione archivi\nPrego attendere", + FALSE, TRUE, 30); + + _nditte = new TRelation(LF_NDITTE); + _nditte->add(LF_ATTIV,"CODDITTA=CODDITTA"); + _nditte_r = &(_nditte->curr()); + _att_r = &(_nditte->curr(LF_ATTIV)); + + _ditte = new TArray_sheet(-1, -1, 0, 0, "Selezione Ditte", + "@1|Cod.@5|Ragione Sociale@50|Vers."); + _n_ditte = 0l; + + pnd.addstatus(1); + + for (_nditte->first(); !_nditte->eof(); _nditte->next()) + { + TString cod = _nditte_r->get("CODDITTA"); + TString vers = _nditte_r->get("FREQVIVA"); + _n_ditte++; + + TToken_string* d = new TToken_string(" "); + + // add record + d->add(cod); + d->add(_nditte_r->get("RAGSOC")); + d->add(vers); + _nomiditte.add(d); + } + + pnd.addstatus(1); + + _rel = new TRelation(LF_MOV); + _rel->add(LF_RMOVIVA,"NUMREG=NUMREG"); + + _cur = new TCursor(_rel); + (*_cur) = 0; + + _pim = new TTable("PIM"); + _ppa = new TTable("PPA"); + _plm = new TTable("PLM"); + _ptm = new TTable("PTM"); + _lim = new TTable("LIM"); + _pla = new TTable("PLA"); + _reg = new TTable("REG"); + _iva = new TTable("%IVA"); + _del = new TTable("%DEL"); + _lia = new TTable("LIA"); + + _mov = _cur->file(LF_MOV); + _rmoviva = _cur->file(LF_RMOVIVA); + + _pim_r = &(_pim->curr()); + _plm_r = &(_plm->curr()); + _ptm_r = &(_ptm->curr()); + _lim_r = &(_lim->curr()); + _iva_r = &(_iva->curr()); + _del_r = &(_del->curr()); + _pla_r = &(_pla->curr()); + _ppa_r = &(_ppa->curr()); + _reg_r = &(_reg->curr()); + _rmoviva_r = &(_cur->curr(LF_RMOVIVA)); + _mov_r = &(_mov->curr()); + + + // ACHTUNG: tutti i _codatt (codici attivita') sono + // in realta' composti dal codice attivita' piu' il + // tipo attivita' (1 o 2) + + _pim_anno = new TRecfield(*_pim_r,"CODTAB",0,3); + _pim_codatt = new TRecfield(*_pim_r,"CODTAB",4,9); + _pim_codreg = new TRecfield(*_pim_r,"CODTAB",10,12); + _pim_mese = new TRecfield(*_pim_r,"CODTAB",13,14); + _pim_tipocr = new TRecfield(*_pim_r,"CODTAB",15,15); + _pim_codiva = new TRecfield(*_pim_r,"CODTAB",16,17); + _ppa_year = new TRecfield(*_ppa_r,"CODTAB",0,3); + _ppa_codatt = new TRecfield(*_ppa_r,"CODTAB",4,9); + _ppa_month = new TRecfield(*_ppa_r,"CODTAB",10,11); + _ppa_kind = new TRecfield(*_ppa_r,"CODTAB",12,12); + _plm_anno = new TRecfield(*_plm_r,"CODTAB",0,3); + _plm_codatt = new TRecfield(*_plm_r,"CODTAB",4,9); + _plm_mese = new TRecfield(*_plm_r,"CODTAB",10,11); + _ptm_anno = new TRecfield(*_ptm_r,"CODTAB",0,3); + _ptm_codatt = new TRecfield(*_ptm_r,"CODTAB",4,9); + _ptm_mese = new TRecfield(*_ptm_r,"CODTAB",10,11); + _lim_anno = new TRecfield(*_lim_r,"CODTAB",0,3); + _lim_mese = new TRecfield(*_lim_r,"CODTAB",4,6); + _pla_anno = new TRecfield(*_pla_r,"CODTAB",0,3); + _pla_codatt = new TRecfield(*_pla_r,"CODTAB",4,9); + _del_ditta = new TRecfield(*_del_r,"CODTAB",0,4); + _del_anno = new TRecfield(*_del_r,"CODTAB",5,8); + _del_mese = new TRecfield(*_del_r,"CODTAB",9,10); + _del_tipo = new TRecfield(*_del_r,"CODTAB",11,11); + + pnd.addstatus(1); + set_real_picture(REAL_PICTURE); +} + +void CG4300_App::user_destroy() +{ + delete _ditte; + + delete _pim_anno; + delete _pim_codreg; + delete _pim_mese; + delete _pim_tipocr; + delete _pim_codiva; + delete _ppa_year; + delete _ppa_codatt; + delete _ppa_month; + delete _ppa_kind; + delete _plm_anno; + delete _plm_codatt; + delete _plm_mese; + delete _ptm_anno; + delete _ptm_codatt; + delete _ptm_mese; + delete _lim_anno; + delete _lim_mese; + delete _pla_anno; + delete _pla_codatt; + delete _pim_codatt; + delete _del_ditta; + delete _del_anno; + delete _del_mese; + delete _del_tipo; + + delete _pim; + delete _ppa; + delete _plm; + delete _ptm; + delete _lim; + delete _pla; + delete _del; + + delete _nditte; + delete _rel; + delete _cur; +} + +bool CG4300_App::set_print(int n) +{ + TString yy = _year; + + _descr_arr.destroy(); + + switch(n) + { + case 1: // liquidazione + _isprint = TRUE; + if (set_liquidazione()) + { + if (_selected.ones() > 0l) + { + if (_year != yy) + { + TString cond(format("ANNOES=%s",(const char*)_year)); + _cur->setfilter(cond); + } + recalc_all(); + return _isprint; + } + else warning_box("Nessuna ditta selezionata!"); + } + break; + case 2: // estrazione deleghe + _isprint = FALSE; + if (set_deleghe()) + { + if (_year != yy) + { + TString cond(format("ANNOES=%s",(const char*)_year)); + _cur->setfilter(cond); + } + extract_deleghe(); + return FALSE; + } + break; + case 3: // calcolo acconto + _isprint = TRUE; + if (set_acconto()) + { + if (_year != yy) + { + TString cond(format("ANNOES=%s",(const char*)_year)); + _cur->setfilter(cond); + } + recalc_acconti(); + return _isprint; + } + break; + } + return FALSE; +} + + +bool CG4300_App::set_liquidazione() +{ + TMask m("cg4300a.msk"); + + m.field(CG43_FLD_SELECTED).set("0"); + _selected.reset(); + TBit_array selected = _selected; + + KEY k; + // stampa abilitata per default + m.set(CG43_CHK_STAMPA,"X"); + + do { + k = m.run(); + + if (k == K_ESC) break; + + _what = (wht)atoi(m.get(CG43_RDB_VERS)); + _month = atoi(m.get(CG43_LST_MESE)); + + if (_what == all) + { + if (_month != 3 && _month != 6 && _month != 9 && + _month != 12 && _month != 13) + _what = mnt; + } + else if (_what == quarter) + _month = atoi(m.get(CG43_LST_TRIM)); + + _year = m.get(CG43_FLD_ANNO); + _date = m.get(CG43_FLD_DATA); + _isprint = m.get_bool(CG43_CHK_STAMPA); + _recalc = (recalc)m.get_long(CG43_LST_CALC); + _isfinal = m.get_bool(CG43_CHK_FINAL); + + if (_isprint) printer().setdate(_date); + + TString from = m.get(CG43_FLD_DFR); + TString to = m.get(CG43_FLD_DTO); + + m.field(CG43_FLD_DFR).set(""); + m.field(CG43_FLD_DTO).set(""); + + // ------------------------------------------------ + m.first_focus(k); + + long j, cnt, chk; int i; + + switch(k) + { + case DLG_SELECT: + // build sheet + _ditte->destroy(); chk = 0l; + for (i = 0; i < _nomiditte.items(); i++) + { + if (_selected[i]) continue; + TToken_string d = (const char*)((TToken_string&)_nomiditte[i]); + TString cod = d.get(0); + TString vers = d.get(2); + if ((_what == mnt && vers == "T") || + (_what == quarter && vers == "M")) + continue; + + _ditte->add(d); + + // check + if (!from.empty() || !to.empty()) + { + if (from.empty()) from = "0"; + if (to.empty()) to = "999999999"; + if (atol(cod) >= atol(from) && atol(cod) <= atol(to)) + _ditte->check(chk++); + } + } + + // seleziona e aggiungi alle gia' selezionate + if (_ditte->run() == K_ENTER) + { + cnt = 0; + for (j = 0l; j < _n_ditte; j++) + { + if (_selected[j]) continue; + if (_ditte->checked(cnt++)) + selected.set(j); + } + _selected |= selected; + selected.reset(); + } + m.field(CG43_FLD_SELECTED).set(format("%ld",(long)_selected.ones())); + break; + case CG43_BUT_ANN: + _selected.reset(); + m.field(CG43_FLD_SELECTED).set("0"); + break; + case CG43_BUT_CHK: + { + _ditte->destroy(); + for (i = 0; i < _nomiditte.items(); i++) + { + TToken_string d = (const char*)((TToken_string&)_nomiditte[i]); + _ditte->add(d); + if (_selected[i]) _ditte->check(i); + } + _ditte->disable_check(); + _ditte->run(); + _ditte->enable_check(); + } + break; + } + } + while (k != K_ENTER && k != K_ESC); + + return k == K_ENTER; +} + +int cg4300(int argc, char* argv[]) +{ + CG4300_App main_app; + main_app.run(argc, argv, "Liquidazione IVA"); + return TRUE; +} diff --git a/include/maskfld.cpp b/include/maskfld.cpp index 6c7e5f6d0..9d217b842 100755 --- a/include/maskfld.cpp +++ b/include/maskfld.cpp @@ -1,4 +1,4 @@ -// $Id: maskfld.cpp,v 1.4 1994-08-26 13:07:14 guy Exp $ +// $Id: maskfld.cpp,v 1.5 1994-08-26 14:05:29 alex Exp $ #include #include @@ -1160,7 +1160,8 @@ int TBrowse::do_input(bool filter) else work << _filter[i]; } - const char* w = work.empty() ? NULL : (const char*) work; + _cursor->setfilter(work); + _cursor->setregion(filtrec, filtrec); if (filtrec.empty()) _cursor->filter(w); else _cursor->filter(w, &filtrec, &filtrec); diff --git a/include/msksheet.cpp b/include/msksheet.cpp index adc7ac5bd..fb96691f9 100755 --- a/include/msksheet.cpp +++ b/include/msksheet.cpp @@ -718,7 +718,7 @@ bool TSpreadsheet::on_key(KEY k) { switch(k) { - case K_SHIFT_ENTER: + case K_CTRL_ENTER: case K_ESC: mask().send_key(k, 0); return TRUE; diff --git a/include/relapp.cpp b/include/relapp.cpp index 3fa610f24..31bf82400 100755 --- a/include/relapp.cpp +++ b/include/relapp.cpp @@ -1,4 +1,4 @@ -// $Id: relapp.cpp,v 1.3 1994-08-23 13:52:26 guy Exp $ +// $Id: relapp.cpp,v 1.4 1994-08-26 14:05:47 alex Exp $ #include #include #include @@ -829,7 +829,8 @@ bool TRelation_application::filter() if (campo != NULL) campo->write(t.mid(u+1), rec); } - cur->filter("", &rec, &rec); + cur->setfilter(""); + cur->setregion(rec, rec); if (s == NULL) id = 0; } } diff --git a/include/relation.cpp b/include/relation.cpp index 9525dd4e7..cf9eb2aa7 100755 --- a/include/relation.cpp +++ b/include/relation.cpp @@ -1,4 +1,4 @@ -// $Id: relation.cpp,v 1.4 1994-08-24 07:24:04 villa Exp $ +// $Id: relation.cpp,v 1.5 1994-08-26 14:06:00 alex Exp $ // relation.cpp // fv 12/8/93 // relation class for isam files @@ -845,7 +845,8 @@ TRecnotype TCursor::update() } -void TCursor::filter(const char* filter, TRectype *from, TRectype* to) +void TCursor::filter(const char* filter, const TRectype *from, + const TRectype* to) { CHECK(!_frozen, "Impossibile filtrare un cursore congelato"); diff --git a/include/relation.h b/include/relation.h index 12b80837a..1cadcc192 100755 --- a/include/relation.h +++ b/include/relation.h @@ -1,4 +1,4 @@ -/* $Id: relation.h,v 1.1.1.1 1994-08-12 10:52:02 alex Exp $ */ +/* $Id: relation.h,v 1.2 1994-08-26 14:06:07 alex Exp $ */ // join.h // fv 12/8/93 // join class for isam files @@ -19,124 +19,124 @@ class TRelation : public TObject { - friend class TRelationdef; + friend class TRelationdef; -// class TRelation : public TLocalisamfile -// @END + // class TRelation : public TLocalisamfile + // @END -// @DPRIV - TToken_string _status; // stato della relazione - TArray _files; // file descriptors - TArray _reldefs; // TRelationdef array - int _errors; -// @END + // @DPRIV + TToken_string _status; // stato della relazione + TArray _files; // file descriptors + TArray _reldefs; // TRelationdef array + int _errors; + // @END -// @FPROT + // @FPROT protected: - virtual void print_on(ostream& out) const; + virtual void print_on(ostream& out) const; - int log2ind(int logicnum) const; - int alias2ind(byte alias) const; - int name2ind(const char* name) const; + int log2ind(int logicnum) const; + int alias2ind(byte alias) const; + int name2ind(const char* name) const; - TRelationdef* reldef(int i) const { return (TRelationdef*)&_reldefs[i]; } - TLocalisamfile* file(int i = 0) const { return (TLocalisamfile*)&_files[i]; } + TRelationdef* reldef(int i) const { return (TRelationdef*)&_reldefs[i]; } + TLocalisamfile* file(int i = 0) const { return (TLocalisamfile*)&_files[i]; } - // @LONGDES - // position_rels fa tutto il lavoro: se non trova un record - // adatto su un file, svuota il record corrente e non ritorna errore. - // write etc. poi procedono normalmente - // @END - int position_rels(TIsamop op = _isequal, TReclock lockop = _nolock, TDate& atdate = botime, int first = 0); + // @LONGDES + // position_rels fa tutto il lavoro: se non trova un record + // adatto su un file, svuota il record corrente e non ritorna errore. + // write etc. poi procedono normalmente + // @END + int position_rels(TIsamop op = _isequal, TReclock lockop = _nolock, TDate& atdate = botime, int first = 0); -friend class TCursor; + friend class TCursor; - public: -// @FPUB - int update() { return position_rels(_isequal, _nolock);} - void zero(); - virtual int next(TReclock lockop = _nolock) { return file()->next(lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); } - virtual int prev(TReclock lockop = _nolock) { return file()->prev(lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); } - virtual int next(TDate& atdate) { return file()->next(atdate) == NOERR ? position_rels(_isequal, _nolock, atdate) : file()->status(); } - virtual int prev(TDate& atdate) { return file()->prev(atdate) == NOERR ? position_rels(_isequal, _nolock, atdate) : file()->status(); } - virtual int first(TReclock lockop = _nolock) { return file()->first(lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); } - virtual int last(TReclock lockop = _nolock) { return file()->last(lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); } - virtual int skip(TRecnotype nrec, TReclock lockop = _nolock) { return file()->skip(nrec, lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); } - virtual int read(TIsamop op = _isgteq, TReclock lockop = _nolock, TDate& atdate = botime) { return file()->read(op, lockop, atdate) == NOERR ? position_rels(_isequal, lockop, atdate) : file()->status();} +public: + // @FPUB + int update() { return position_rels(_isequal, _nolock);} + void zero(); + virtual int next(TReclock lockop = _nolock) { return file()->next(lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); } + virtual int prev(TReclock lockop = _nolock) { return file()->prev(lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); } + virtual int next(TDate& atdate) { return file()->next(atdate) == NOERR ? position_rels(_isequal, _nolock, atdate) : file()->status(); } + virtual int prev(TDate& atdate) { return file()->prev(atdate) == NOERR ? position_rels(_isequal, _nolock, atdate) : file()->status(); } + virtual int first(TReclock lockop = _nolock) { return file()->first(lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); } + virtual int last(TReclock lockop = _nolock) { return file()->last(lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); } + virtual int skip(TRecnotype nrec, TReclock lockop = _nolock) { return file()->skip(nrec, lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); } + virtual int read(TIsamop op = _isgteq, TReclock lockop = _nolock, TDate& atdate = botime) { return file()->read(op, lockop, atdate) == NOERR ? position_rels(_isequal, lockop, atdate) : file()->status();} - TLocalisamfile* lfile(int logicnum = 0) const; - TLocalisamfile* lfile(const char* name) const; - void write_enable(int logicnum = -1, const bool on = TRUE) ; - void write_enable(const char* name, const bool on = TRUE) ; - void write_disable(int logicnum = -1) { write_enable(logicnum, FALSE); } - void write_disable(const char* name) { write_enable(name, FALSE); } + TLocalisamfile* lfile(int logicnum = 0) const; + TLocalisamfile* lfile(const char* name) const; + void write_enable(int logicnum = -1, const bool on = TRUE) ; + void write_enable(const char* name, const bool on = TRUE) ; + void write_disable(int logicnum = -1) { write_enable(logicnum, FALSE); } + void write_disable(const char* name) { write_enable(name, FALSE); } - TRectype& curr(int logicnum = 0) const { return lfile(logicnum)->curr(); } - // next_match for 0ne-to-many relations; positions logicnum (!= main) - // on next matching record; returns TRUE or FALSE if no more matches; in - // any case relation is kept consistent except when inconsistent in - // first place - bool next_match(int logicnum, const char* fieldlist = NULL, int nkey = 0); + TRectype& curr(int logicnum = 0) const { return lfile(logicnum)->curr(); } + // next_match for 0ne-to-many relations; positions logicnum (!= main) + // on next matching record; returns TRUE or FALSE if no more matches; in + // any case relation is kept consistent except when inconsistent in + // first place + bool next_match(int logicnum, const char* fieldlist = NULL, int nkey = 0); - // @DES add relation - // @FPUB - bool add(int logicnum, const char* relexprs, int key = 1, - int linkto = 0, byte alias = 0, bool allow_lock = FALSE); - bool add(const char* tabname, const char* relexprs, int key = 1, - int linkto = 0, byte alias = 0, bool allow_lock = FALSE); + // @DES add relation + // @FPUB + bool add(int logicnum, const char* relexprs, int key = 1, + int linkto = 0, byte alias = 0, bool allow_lock = FALSE); + bool add(const char* tabname, const char* relexprs, int key = 1, + int linkto = 0, byte alias = 0, bool allow_lock = FALSE); - // @DES write methods - // @FPUB - virtual int write (bool force = TRUE, TDate& atdate = botime); - virtual int rewrite(bool force = TRUE, TDate& atdate = botime); - virtual int remove (TDate& atdate = botime); + // @DES write methods + // @FPUB + virtual int write (bool force = TRUE, TDate& atdate = botime); + virtual int rewrite(bool force = TRUE, TDate& atdate = botime); + virtual int remove (TDate& atdate = botime); - // @DES checking methods - // @FPUB - bool eof( int logicnum = 0) { return lfile(logicnum)->eof(); } - bool bof( int logicnum = 0) { return lfile(logicnum)->bof(); } + // @DES checking methods + // @FPUB + bool eof( int logicnum = 0) { return lfile(logicnum)->eof(); } + bool bof( int logicnum = 0) { return lfile(logicnum)->bof(); } - // @N - // status(), good() and bad() return the status of the relation when called - // with no args, or the status of the file when called with - // a logical number - // @END + // @N + // status(), good() and bad() return the status of the relation when called + // with no args, or the status of the file when called with + // a logical number + // @END - bool status(int logicnum = 0) { return lfile(logicnum)->status(); } - bool good( int logicnum = 0) { return lfile(logicnum)->good(); } - bool bad( int logicnum = 0) { return lfile(logicnum)->bad(); } - bool empty( int logicnum = 0) { return lfile(logicnum)->empty(); } - // @END + bool status(int logicnum = 0) { return lfile(logicnum)->status(); } + bool good( int logicnum = 0) { return lfile(logicnum)->good(); } + bool bad( int logicnum = 0) { return lfile(logicnum)->bad(); } + bool empty( int logicnum = 0) { return lfile(logicnum)->empty(); } + // @END - // @LONGDES - // isconsistent() returns TRUE if every file in the relation is - // OK, current record is non-empty, and relation is consistent. - // If it's not and reset is TRUE, it tries to reset the relation - // to a consistent state (based on main record) -- no further check - // is done. - // Also called internally by update and remove. - // @END - bool isconsistent(bool reset = FALSE); + // @LONGDES + // isconsistent() returns TRUE if every file in the relation is + // OK, current record is non-empty, and relation is consistent. + // If it's not and reset is TRUE, it tries to reset the relation + // to a consistent state (based on main record) -- no further check + // is done. + // Also called internally by update and remove. + // @END + bool isconsistent(bool reset = FALSE); - // TRUE se c'e' un record ed e' il primo match (non si e' mai fatta - // position_rels) - bool is_first_match(int logicnum); + // TRUE se c'e' un record ed e' il primo match (non si e' mai fatta + // position_rels) + bool is_first_match(int logicnum); - void save_status () ; - void restore_status () ; + void save_status () ; + void restore_status () ; - // @DES positioning operators. return status - // @FPUB + // @DES positioning operators. return status + // @FPUB - TRecnotype operator +=(const TRecnotype npos) { return skip(npos); } - TRecnotype operator -=(const TRecnotype npos) { return skip(-npos); } - TRecnotype operator ++() { return next(); } - TRecnotype operator --() { return prev(); } + TRecnotype operator +=(const TRecnotype npos) { return skip(npos); } + TRecnotype operator -=(const TRecnotype npos) { return skip(-npos); } + TRecnotype operator ++() { return next(); } + TRecnotype operator --() { return prev(); } - TRelation(int logicnum, bool linkrecinst = TRUE); - TRelation(const char* tabname, bool linkrecinst = TRUE); - virtual ~TRelation(); + TRelation(int logicnum, bool linkrecinst = TRUE); + TRelation(const char* tabname, bool linkrecinst = TRUE); + virtual ~TRelation(); }; // @C @@ -150,81 +150,83 @@ typedef bool (*FILTERFUNCTION)(const TRelation* r); class TCursor : public TObject { -// @DPRIV - TRelation* _if; - int _nkey; - TRecnotype _pos; // Posizione corrente - TRecnotype _totrec; - TRecnotype _lastrec; - TRecnotype _lastkrec; - TFilename _filename; - TString _filter; // Filtro - TString _keyfrom; // chiave iniziale - TString _keyto; // chiave finale - TExpression* _fexpr; // Espressione relativo filtro - bool _frozen; - FILTERFUNCTION _filterfunction; - TFilename _indexname; -// @END + // @DPRIV + TRelation* _if; + int _nkey; + TRecnotype _pos; // Posizione corrente + TRecnotype _totrec; + TRecnotype _lastrec; + TRecnotype _lastkrec; + TFilename _filename; + TString _filter; // Filtro + TString _keyfrom; // chiave iniziale + TString _keyto; // chiave finale + TExpression* _fexpr; // Espressione relativo filtro + bool _frozen; + FILTERFUNCTION _filterfunction; + TFilename _indexname; + // @END -// @FPRIV - virtual TRecnotype buildcursor(TRecnotype rp); - int filtercursor(int pagecnt, TRecnotype* page); - bool changed(); + // @FPRIV + virtual TRecnotype buildcursor(TRecnotype rp); + int filtercursor(int pagecnt, TRecnotype* page); + bool changed(); - FILE* open_index(bool create = FALSE) const; - TRecnotype update(); + FILE* open_index(bool create = FALSE) const; + TRecnotype update(); - protected: - TRecnotype readrec(); +protected: + TRecnotype readrec(); + void filter(const char* filter, const TRectype* from = NULL, + const TRectype* to = NULL); - public: -// @FPUB - TRecnotype operator =(const TRecnotype nr); // Assegnazione - TCursor& operator +=(const TRecnotype nr); // Scorri avanti - TCursor& operator -=(const TRecnotype nr); // Scorri indietro - TCursor& operator ++(); // Avanti di un record - TCursor& operator --(); // Indietro di un record - TRecnotype pos() const { return _pos; } - TRecnotype items(); - TRecnotype size() const { return file()->eod(); } - const TString& from() const { return _keyfrom; } - const TString& to() const { return _keyto; } +public: + // @FPUB + TRecnotype operator =(const TRecnotype nr); // Assegnazione + TCursor& operator +=(const TRecnotype nr); // Scorri avanti + TCursor& operator -=(const TRecnotype nr); // Scorri indietro + TCursor& operator ++(); // Avanti di un record + TCursor& operator --(); // Indietro di un record + TRecnotype pos() const { return _pos; } + TRecnotype items(); + TRecnotype size() const { return file()->eod(); } + const TString& from() const { return _keyfrom; } + const TString& to() const { return _keyto; } - TRectype& curr(int log = 0) const { return _if->curr(log); } - TRectype& curr(const char * tab) const - { return _if->lfile(tab)->curr(); } - TRecnotype read(TIsamop op = _isgteq, TReclock lockop = _nolock, TDate& atdate = botime); - virtual bool ok() const; + TRectype& curr(int log = 0) const { return _if->curr(log); } + TRectype& curr(const char * tab) const + { return _if->lfile(tab)->curr(); } + TRecnotype read(TIsamop op = _isgteq, TReclock lockop = _nolock, TDate& atdate = botime); + virtual bool ok() const; - void filter(const char* filter, TRectype* from = NULL, TRectype* to = NULL); - const char* filter() const { return _filter; } - void freeze(bool on = TRUE) { _frozen = on; } - bool frozen() const { return _frozen; } - void setregion(TRectype* from = NULL, TRectype* to = NULL) - { filter(NULL,from,to); } + const char* filter() const { return _filter; } + void freeze(bool on = TRUE) { _frozen = on; } + bool frozen() const { return _frozen; } + void setfilter(const char* filter_expr) { filter(filter_expr); } + void setregion(const TRectype& from, const TRectype& to) + { filter(NULL,&from, &to); } - TRelation* relation() const { return _if; } - TLocalisamfile* file(int lnum = 0) const { return _if->lfile(lnum); } - TLocalisamfile* file(const char* name) const { return _if->lfile(name); } - int repos() { return _if->position_rels(); } + TRelation* relation() const { return _if; } + TLocalisamfile* file(int lnum = 0) const { return _if->lfile(lnum); } + TLocalisamfile* file(const char* name) const { return _if->lfile(name); } + int repos() { return _if->position_rels(); } - void setkey() { file()->setkey(_nkey); } - void setkey(int nkey); - int key() const { return _nkey; } + void setkey() { file()->setkey(_nkey); } + void setkey(int nkey); + int key() const { return _nkey; } - bool next_match(int lognum, const char* fl = NULL, int nk = 0); - bool is_first_match(int ln); - - void set_filterfunction(FILTERFUNCTION ff) { _filterfunction = ff; _lastrec = 0L;} - bool has_filter() const { return _filter.not_empty() || _filterfunction; } + bool next_match(int lognum, const char* fl = NULL, int nk = 0); + bool is_first_match(int ln); + + void set_filterfunction(FILTERFUNCTION ff) { _filterfunction = ff; _lastrec = 0L;} + bool has_filter() const { return _filter.not_empty() || _filterfunction; } - void save_status () { _if->save_status(); } - void restore_status () { _if->restore_status(); } + void save_status () { _if->save_status(); } + void restore_status () { _if->restore_status(); } - TCursor(TRelation* f, const char* filter = "", int key = 1, TRectype* from = NULL, TRectype* to = NULL); - virtual ~TCursor(); + TCursor(TRelation* f, const char* filter = "", int key = 1, TRectype* from = NULL, TRectype* to = NULL); + virtual ~TCursor(); }; @@ -234,33 +236,33 @@ class TCursor : public TObject class TFieldref : public TObject { -// @DPRIV - short _fileid; // Numero del file - TString16 _id; // Nome tabella o stringa col numero del file - TString16 _name; // Nome del campo - int _from, _to; // Substring + // @DPRIV + short _fileid; // Numero del file + TString16 _id; // Nome tabella o stringa col numero del file + TString16 _name; // Nome del campo + int _from, _to; // Substring protected: - virtual void print_on(ostream& out) const; + virtual void print_on(ostream& out) const; public: -// @FPUB - TFieldref(); - TFieldref(const TString&, short defid); + // @FPUB + TFieldref(); + TFieldref(const TString&, short defid); - TFieldref& operator =(const TString& s); // Operatore di assegnazione + TFieldref& operator =(const TString& s); // Operatore di assegnazione - virtual bool ok() const { return _name.not_empty(); } // Vero se il numero del file e' valido + virtual bool ok() const { return _name.not_empty(); } // Vero se il numero del file e' valido - int file() const { return _fileid; } // ritorna il file - const char* name() const { return (const char*) _name; } // ritorna il nome del campo - int from() const { return _from; } - int to() const { return _to; } - int len(TRectype &rec) const; - const char* read(const TRelation* = NULL) const; - const char* read(const TRectype&) const; - void write(const char* val, TRelation* = NULL) const; - void write(const char* val, TRectype& rec) const; + int file() const { return _fileid; } // ritorna il file + const char* name() const { return (const char*) _name; } // ritorna il nome del campo + int from() const { return _from; } + int to() const { return _to; } + int len(TRectype &rec) const; + const char* read(const TRelation* = NULL) const; + const char* read(const TRectype&) const; + void write(const char* val, TRelation* = NULL) const; + void write(const char* val, TRectype& rec) const; }; // Converte una stringa in numero logico o numero tabella int name2log(const char* name);