diff --git a/cg/cg1100.cpp b/cg/cg1100.cpp index 7f3d0accb..8cf59dc91 100755 --- a/cg/cg1100.cpp +++ b/cg/cg1100.cpp @@ -667,8 +667,11 @@ void CG1100_application::set_senza_IV() } if (sottoc != 0l) { + char tipospric = rec.get_char(PCN_TIPOSPRIC); + if (tipospric == '\0') tipospric = '0'; set_row (i, "@104g@1n", FLD(LF_PCON, PCN_RICSER) ); - set_row (i, "@109g@1n", FLD(LF_PCON, PCN_TIPOSPRIC) ); + //set_row (i, "@109g@1n", FLD(LF_PCON, PCN_TIPOSPRIC) ); + set_row (i, "@109g%c", tipospric); set_row (i, "@115g@1s", FLD(LF_PCON, PCN_SEZSALDI) ); set_row (i, "@129g@f", FLD(LF_PCON, PCN_STSOTTAB) ); } @@ -712,7 +715,6 @@ void CG1100_application::set_con_ana() void CG1100_application::set_senza_ana() { - reset_row (1); set_row (1, "$[r]@pn$[n] $[r]@pn$[n] $[r]@pn$[n]", @@ -731,14 +733,14 @@ void CG1100_application::set_senza_ana() set_row (1, "@92g@1s", FLD(LF_PCON, PCN_TMCF) ); set_row (1, "@99g@f", FLD(LF_PCON, PCN_STSOTTBIL) ); set_row (1, "@107g@f", FLD(LF_PCON, PCN_COMPENS) ); - set_row (1, "@114g@1n", FLD(LF_PCON, PCN_TIPOSPRIC) ); + //set_row (1, "@114g@1n", FLD(LF_PCON, PCN_TIPOSPRIC) ); set_row (1, "@120g@1s", FLD(LF_PCON, PCN_SEZSALDI) ); } void CG1100_application::set_completa() { - TRectype & rec = current_cursor()->curr(); + TRectype& rec = current_cursor()->curr(); char sezione; int i; @@ -790,8 +792,11 @@ void CG1100_application::set_completa() } if (sottoc != 0l) { + char tipospric = rec.get_char(PCN_TIPOSPRIC); + if (tipospric == '\0') tipospric = '0'; set_row (i, "@104g@1n", FLD(LF_PCON, PCN_RICSER) ); - set_row (i, "@109g@1n", FLD(LF_PCON, PCN_TIPOSPRIC) ); + //set_row (i, "@109g@1n", FLD(LF_PCON, PCN_TIPOSPRIC) ); + set_row (i, "@109g%c", tipospric); set_row (i, "@115g@1s", FLD(LF_PCON, PCN_SEZSALDI) ); set_row (i, "@129g@f", FLD(LF_PCON, PCN_STSOTTAB) ); } @@ -818,6 +823,9 @@ bool CG1100_application::elabora_riga() // se e' un sottoconto stampo sotttab in 127 if (sottoc != 0) { + char tipospric = curr_rec.get_char(PCN_TIPOSPRIC); + if (tipospric == '\0') tipospric = '0'; + set_row (1, "@114g%c", tipospric); set_row (1, "@127g@f", FLD(LF_PCON, PCN_STSOTTAB)); set_row (1, "@117g "); } @@ -908,7 +916,7 @@ bool CG1100_application::preprocess_page(int file,int counter) { if (file == LF_PCON) { - TRectype & rec = current_cursor()->curr(); + TRectype& rec = current_cursor()->curr(); int gruppo = rec.get_int (PCN_GRUPPO); int conto = rec.get_int (PCN_CONTO); long sottoc = rec.get_long(PCN_SOTTOCONTO); @@ -963,8 +971,8 @@ bool CG1100_application::preprocess_page(int file,int counter) } if (_tipo_stampa == senza_ana_bil) { - TRectype & rec = current_cursor()->curr(); - + TRectype& rec = current_cursor()->curr(); + force_setpage(); if (rec.get_int(PCN_CONTO) == 0) return FALSE; if (rec.get_long(PCN_SOTTOCONTO) == 0L) a1 = rec.get(PCN_CODCBL); @@ -1165,7 +1173,7 @@ bool CG1100_application::user_create() add_file(LF_PCON); - set_print_zero(); + //set_print_zero(); _tipo_stampa = completa; _salto_pag = FALSE; diff --git a/cg/cg1302.cpp b/cg/cg1302.cpp index a07fbcf92..86daa97c8 100755 --- a/cg/cg1302.cpp +++ b/cg/cg1302.cpp @@ -1,163 +1,163 @@ -//**************************** -//* Aggiornamento Tipo Conto * -//**************************** -#include -#include -#include -#include "conto.h" -#include "cg1302.h" - -const int TAgg_tconto::look_reg (const char* cod, int anno) -{ - TTable tab_reg("REG"); - TString codtab; - codtab.format("%4d%-3s", anno, cod); - int tipo_reg; - - tab_reg.zero(); - tab_reg.put("CODTAB", codtab); - if (tab_reg.read() == NOERR) - tipo_reg = tab_reg.get_int("I0"); - else - tipo_reg = 0; - - return tipo_reg; -} - -bool TAgg_tconto::user_create() -{ - _rel = new TRelation(LF_MOV); - _rel->add(LF_RMOVIVA, "NUMREG=NUMREG",1); - _cur = new TCursor(_rel,"",1); - add_cursor(_cur); - - add_file (LF_MOV); - add_file (LF_RMOVIVA); - - _pcon = new TLocalisamfile(LF_PCON); - _nditte = new TLocalisamfile(LF_NDITTE); - _tabreg = new TTable("REG"); - - return TRUE; -} - -bool TAgg_tconto::user_destroy() -{ - delete _rel; - delete _cur; - delete _pcon; - delete _nditte; - delete _tabreg; - - return TRUE; -} - -bool TAgg_tconto::set_print(int) -{ - TMask msk("cg1300a"); - - while (msk.run() == K_ENTER) - { - setta_intestazione(); - printer().footerlen(5); - return TRUE; - } - return FALSE; -} - -void TAgg_tconto::postclose_print() -{ - message_box("Aggiornamento tipo conto completato"); -} - -bool TAgg_tconto::preprocess_page(int file,int counter) -{ - if (counter) return TRUE; - - TCursor* cur = current_cursor(); - if (file == LF_MOV) - { - TString16 reg = cur->curr().get(MOV_REG); - if (reg.empty()) return FALSE; - } - else if (file == LF_RMOVIVA) - { - TRectype pcon(LF_PCON); - int gruppo = cur->curr(LF_RMOVIVA).get_int(RMI_GRUPPO); - int conto = cur->curr(LF_RMOVIVA).get_int(RMI_CONTO); - long sottoconto = cur->curr(LF_RMOVIVA).get_long(RMI_SOTTOCONTO); - long numreg = cur->curr(LF_RMOVIVA).get_long(RMI_NUMREG); - int nrigimp = cur->curr(LF_RMOVIVA).get_int("RIGAIMP"); - - TBill tc (gruppo,conto,0L); - tc.read(pcon); - if (!pcon.empty()) - if (pcon.get_char("TMCF") != '\0') - return FALSE; - - tc.set(gruppo,conto,sottoconto); - tc.read(pcon); - if (!pcon.empty()) - { - if (tc.sospeso()) - { - set_row(1, "@4g%7ld@23g%3d@31g%3d@37g%3d@45g%6ld ** Conto sospeso **", - numreg, nrigimp, gruppo, conto, sottoconto); - return TRUE; - } - int t = tc.tipo_cr(); - TString16 reg = cur->curr().get(MOV_REG); - int annoiva = cur->curr().get_int(MOV_ANNOIVA); - const int tipo = look_reg(reg, annoiva); //cerca il tipo del registro - //aggiorno sul movimento iva il tipo costo/ricavo - //con quello letto dal piano conti - _rel->lfile(LF_RMOVIVA).put(RMI_TIPOCR, t); - if (tipo == 1 && (t == 2 || t == 3)) - _rel->lfile(LF_RMOVIVA).put(RMI_TIPOCR, 4); - _rel->lfile(LF_RMOVIVA).rewrite(); - } - else - { - set_row(1, "@4g%7ld@23g%3d@31g%3d@37g%3d@45g%6ld ** Conto inesistente **", - numreg, nrigimp, gruppo, conto, sottoconto); - return TRUE; - } - return FALSE; - } - return TRUE; -} - -void TAgg_tconto::setta_intestazione() -{ - int soh = 1; - TString sep(132); - TString ragsoc(50); - - TLocalisamfile nditte(LF_NDITTE); - nditte.zero(); - nditte.put(NDT_CODDITTA, get_firm()); - if (nditte.read() == NOERR) - ragsoc = nditte.get(NDT_RAGSOC); - - reset_header(); - - sep << "Ditta " << get_firm(); - sep << " " << ragsoc; - - sep.left_just(132); - - set_header (soh++, (const char*) sep); - - sep = ""; - sep << "Data @< Pag. @#"; - - sep.right_just(127); - - sep.overwrite ("AGGIORNAMENTO TIPO CONTO SU MOVIMENTI IVA - Lista errori"); - set_header (soh++, (const char*)sep); - sep.fill('-'); - set_header (soh++, (const char *) sep); - set_header (soh++, "Numero Registrazione Riga Gruppo Conto Sottoconto"); - set_header (soh++, (const char *) sep); - set_header (soh, ""); -} +//**************************** +//* Aggiornamento Tipo Conto * +//**************************** +#include +#include +#include +#include "conto.h" +#include "cg1302.h" + +const int TAgg_tconto::look_reg (const char* cod, int anno) +{ + TTable tab_reg("REG"); + TString codtab; + codtab.format("%4d%-3s", anno, cod); + int tipo_reg; + + tab_reg.zero(); + tab_reg.put("CODTAB", codtab); + if (tab_reg.read() == NOERR) + tipo_reg = tab_reg.get_int("I0"); + else + tipo_reg = 0; + + return tipo_reg; +} + +bool TAgg_tconto::user_create() +{ + _rel = new TRelation(LF_MOV); + _rel->add(LF_RMOVIVA, "NUMREG=NUMREG",1); + _cur = new TCursor(_rel,"",1); + add_cursor(_cur); + + add_file (LF_MOV); + add_file (LF_RMOVIVA); + + _pcon = new TLocalisamfile(LF_PCON); + _nditte = new TLocalisamfile(LF_NDITTE); + _tabreg = new TTable("REG"); + + return TRUE; +} + +bool TAgg_tconto::user_destroy() +{ + delete _rel; + delete _cur; + delete _pcon; + delete _nditte; + delete _tabreg; + + return TRUE; +} + +bool TAgg_tconto::set_print(int) +{ + TMask msk("cg1300a"); + + while (msk.run() == K_ENTER) + { + setta_intestazione(); + printer().footerlen(5); + return TRUE; + } + return FALSE; +} + +void TAgg_tconto::postclose_print() +{ + message_box("Aggiornamento tipo conto completato"); +} + +bool TAgg_tconto::preprocess_page(int file,int counter) +{ + if (counter) return TRUE; + + TCursor* cur = current_cursor(); + if (file == LF_MOV) + { + TString16 reg = cur->curr().get(MOV_REG); + if (reg.empty()) return FALSE; + } + else if (file == LF_RMOVIVA) + { + TRectype pcon(LF_PCON); + int gruppo = cur->curr(LF_RMOVIVA).get_int(RMI_GRUPPO); + int conto = cur->curr(LF_RMOVIVA).get_int(RMI_CONTO); + long sottoconto = cur->curr(LF_RMOVIVA).get_long(RMI_SOTTOCONTO); + long numreg = cur->curr(LF_RMOVIVA).get_long(RMI_NUMREG); + int nrigimp = cur->curr(LF_RMOVIVA).get_int("RIGAIMP"); + + TBill tc (gruppo,conto,0L); + tc.read(pcon); + if (!pcon.empty()) + if (pcon.get_char("TMCF") != '\0') + return FALSE; + + tc.set(gruppo,conto,sottoconto); + tc.read(pcon); + if (!pcon.empty()) + { + if (tc.sospeso()) + { + set_row(1, "@4g%7ld@23g%3d@31g%3d@37g%3d@45g%6ld ** Conto sospeso **", + numreg, nrigimp, gruppo, conto, sottoconto); + return TRUE; + } + int t = tc.tipo_cr(); + TString16 reg = cur->curr().get(MOV_REG); + int annoiva = cur->curr().get_int(MOV_ANNOIVA); + const int tipo = look_reg(reg, annoiva); //cerca il tipo del registro + //aggiorno sul movimento iva il tipo costo/ricavo + //con quello letto dal piano conti + _rel->lfile(LF_RMOVIVA).put(RMI_TIPOCR, t); + if (tipo == 1 && (t == 2 || t == 3)) + _rel->lfile(LF_RMOVIVA).put(RMI_TIPOCR, 4); + _rel->lfile(LF_RMOVIVA).rewrite(); + } + else + { + set_row(1, "@4g%7ld@23g%3d@31g%3d@37g%3d@45g%6ld ** Conto inesistente **", + numreg, nrigimp, gruppo, conto, sottoconto); + return TRUE; + } + return FALSE; + } + return TRUE; +} + +void TAgg_tconto::setta_intestazione() +{ + int soh = 1; + TString sep(132); + TString ragsoc(50); + + TLocalisamfile nditte(LF_NDITTE); + nditte.zero(); + nditte.put(NDT_CODDITTA, get_firm()); + if (nditte.read() == NOERR) + ragsoc = nditte.get(NDT_RAGSOC); + + reset_header(); + + sep << "Ditta " << get_firm(); + sep << " " << ragsoc; + + sep.left_just(132); + + set_header (soh++, (const char*) sep); + + sep = ""; + sep << "Data @< Pag. @#"; + + sep.right_just(127); + + sep.overwrite ("AGGIORNAMENTO TIPO CONTO SU MOVIMENTI IVA - Lista errori"); + set_header (soh++, (const char*)sep); + sep.fill('-'); + set_header (soh++, (const char *) sep); + set_header (soh++, "Numero Registrazione Riga Gruppo Conto Sottoconto"); + set_header (soh++, (const char *) sep); + set_header (soh, ""); +} diff --git a/cg/cg1302.h b/cg/cg1302.h index bdb998ae4..9318417d7 100755 --- a/cg/cg1302.h +++ b/cg/cg1302.h @@ -1,28 +1,28 @@ -#include -#include -#include -#include -#include -#include -#include - -class TAgg_tconto : public TPrintapp -{ - TLocalisamfile* _pcon,* _nditte; - TTable* _tabreg; - TRelation* _rel; - TCursor* _cur; - -public: - virtual bool user_create(); - virtual bool user_destroy(); - virtual bool set_print(int i); - virtual bool preprocess_page(int, int); - virtual void postclose_print(); - - void setta_intestazione(); - const int look_reg(const char*, int); - - TAgg_tconto() {}; - virtual ~TAgg_tconto() {}; -}; +#include +#include +#include +#include +#include +#include +#include + +class TAgg_tconto : public TPrintapp +{ + TLocalisamfile* _pcon,* _nditte; + TTable* _tabreg; + TRelation* _rel; + TCursor* _cur; + +public: + virtual bool user_create(); + virtual bool user_destroy(); + virtual bool set_print(int i); + virtual bool preprocess_page(int, int); + virtual void postclose_print(); + + void setta_intestazione(); + const int look_reg(const char*, int); + + TAgg_tconto() {}; + virtual ~TAgg_tconto() {}; +}; diff --git a/cg/cg1304.cpp b/cg/cg1304.cpp index 3c1de3dca..25fb185f5 100755 --- a/cg/cg1304.cpp +++ b/cg/cg1304.cpp @@ -1,168 +1,168 @@ -//***************************************************** -//* Aggiornamento codice attivita' su progressivi IVA * -//***************************************************** -#include -#include "cg1300.h" -#include "cg1304.h" -#include "cg2103.h" - -HIDDEN TAgg_codatt& app() { return (TAgg_codatt&) main_app(); } - -bool TAgg_codatt::create() -{ - TApplication::create(); - - _tab = new TLocalisamfile(LF_TAB); - - dispatch_e_menu (BAR_ITEM(1)); - return TRUE; -} - -bool TAgg_codatt::destroy() -{ - delete _tab; - - return TApplication::destroy(); -} - -bool TAgg_codatt::menu(MENU_TAG m) -{ - TProgind* pri; - TMask msk("cg1300c"); - - /* - TConfig conf(CONFIG_DITTA); - int annoiva = conf.get_int("AnLiIv"); - - msk.set(F_ANNO, annoiva); - */ - while (msk.run() == K_ENTER) - { - pri = new TProgind(2,"Aggiornamento in corso...",FALSE,TRUE,50); - _pass = msk.get_bool(F_PASS); - if (_pass) - { - _anno = msk.get_int(F_ANNO); - _da = msk.get(F_DA); //se c'e' _da c'e' anche _a e viceversa - _a = msk.get(F_A); //_da e' la vecchia attivita' - //_a e' la nuova attivita' - pri->addstatus(1); - aggiorna_att("PIM"); - aggiorna_att("PUM"); - aggiorna_att("POM"); - aggiorna_att("PAM"); - aggiorna_att("PPA"); - aggiorna_att("PLA"); - aggiorna_att("PLM"); - } - else - { - pri->addstatus(1); - cancella_rec(); - } - pri->addstatus(1); - msk.reset(); - //msk.reset(F_ANNO); - //msk.reset(F_DA); - //msk.reset(F_A); - delete pri; - message_box("Aggiornamento codice attivita' completato"); - } - return FALSE; -} - -void TAgg_codatt::cancella_rec() -{ - TTable plm("PLM"); - for (plm.first(); !plm.eof(); plm.next()) - plm.remove(); - - TTable pum("PUM"); - for (pum.first(); !pum.eof(); pum.next()) - pum.remove(); - - TTable pom("POM"); - for (pom.first(); !pom.eof(); pom.next()) - pom.remove(); - - TTable pam("PAM"); - for (pam.first(); !pam.eof(); pam.next()) - pam.remove(); - - TTable ppa("PPA"); - for (ppa.first(); !ppa.eof(); ppa.next()) - ppa.remove(); - - //non e' indicata la vecchia attivita' => : - TTable pim("PIM"); - for (pim.first(); !pim.eof(); pim.next()) - { - const TString80 codtab = pim.get("CODTAB"); - int anno = atoi(codtab.mid(0,4)); - const TString16 codatt = codtab.mid(4,5); - const TString16 codreg = codtab.mid(10,3); - if (codreg.not_empty()) - { - TRegistro reg(codreg,anno); - if (!reg.name().empty()) //se esiste quel registro (ma perche' non dovrebbe?) - { - const TString16 cda = reg.attivita(); - if (codatt != cda) - { - TRectype vecchio (pim.curr()); - TRectype nuovo (pim.curr()); - const TString80 cc = codtab.sub(9); - TString80 cod; - cod << anno << cda << cc; - nuovo.put("CODTAB", cod); - pim.write(nuovo); - pim.read(vecchio); - pim.remove(); - } - } - } - } - - TTable pla("PLA"); - for (pla.first(); !pla.eof(); pla.next()) - pla.remove(); - /*** - TTable rmb("RMB"); - for (rmb.first(); !rmb.eof(); rmb.next()) - rmb.remove(); - ***/ -} - -void TAgg_codatt::aggiorna_att(const char* nome) -{ - TTable tab(nome); - tab.setkey(1); - tab.zero(); - TString16 chiave; - TString16 old_att(_da); old_att.right_just(5,'0'); - TString16 new_att(_a); new_att.right_just(5,'0'); - chiave << _anno << old_att; - tab.put("CODTAB", chiave); - TRectype curr (tab.curr()); - tab.read(_isgteq); - for (; !tab.eof(); tab.next()) - { - if (tab.curr() != curr) break; - - const TString80 codtab = tab.get("CODTAB"); - //const TString16 cod_att = codtab.mid(4,5); //e' uguale a old_att - if (old_att != new_att) - { - TRectype vecchio (tab.curr()); - TRectype nuovo (tab.curr()); - const TString80 cc = codtab.sub(9); - TString80 cod; - cod << _anno << new_att << cc; - nuovo.put("CODTAB", cod); - tab.write(nuovo); - tab.read(vecchio); - tab.remove(); - } - } -} - +//***************************************************** +//* Aggiornamento codice attivita' su progressivi IVA * +//***************************************************** +#include +#include "cg1300.h" +#include "cg1304.h" +#include "cg2103.h" + +HIDDEN TAgg_codatt& app() { return (TAgg_codatt&) main_app(); } + +bool TAgg_codatt::create() +{ + TApplication::create(); + + _tab = new TLocalisamfile(LF_TAB); + + dispatch_e_menu (BAR_ITEM(1)); + return TRUE; +} + +bool TAgg_codatt::destroy() +{ + delete _tab; + + return TApplication::destroy(); +} + +bool TAgg_codatt::menu(MENU_TAG m) +{ + TProgind* pri; + TMask msk("cg1300c"); + + /* + TConfig conf(CONFIG_DITTA); + int annoiva = conf.get_int("AnLiIv"); + + msk.set(F_ANNO, annoiva); + */ + while (msk.run() == K_ENTER) + { + pri = new TProgind(2,"Aggiornamento in corso...",FALSE,TRUE,50); + _pass = msk.get_bool(F_PASS); + if (_pass) + { + _anno = msk.get_int(F_ANNO); + _da = msk.get(F_DA); //se c'e' _da c'e' anche _a e viceversa + _a = msk.get(F_A); //_da e' la vecchia attivita' + //_a e' la nuova attivita' + pri->addstatus(1); + aggiorna_att("PIM"); + aggiorna_att("PUM"); + aggiorna_att("POM"); + aggiorna_att("PAM"); + aggiorna_att("PPA"); + aggiorna_att("PLA"); + aggiorna_att("PLM"); + } + else + { + pri->addstatus(1); + cancella_rec(); + } + pri->addstatus(1); + msk.reset(); + //msk.reset(F_ANNO); + //msk.reset(F_DA); + //msk.reset(F_A); + delete pri; + message_box("Aggiornamento codice attivita' completato"); + } + return FALSE; +} + +void TAgg_codatt::cancella_rec() +{ + TTable plm("PLM"); + for (plm.first(); !plm.eof(); plm.next()) + plm.remove(); + + TTable pum("PUM"); + for (pum.first(); !pum.eof(); pum.next()) + pum.remove(); + + TTable pom("POM"); + for (pom.first(); !pom.eof(); pom.next()) + pom.remove(); + + TTable pam("PAM"); + for (pam.first(); !pam.eof(); pam.next()) + pam.remove(); + + TTable ppa("PPA"); + for (ppa.first(); !ppa.eof(); ppa.next()) + ppa.remove(); + + //non e' indicata la vecchia attivita' => : + TTable pim("PIM"); + for (pim.first(); !pim.eof(); pim.next()) + { + const TString80 codtab = pim.get("CODTAB"); + int anno = atoi(codtab.mid(0,4)); + const TString16 codatt = codtab.mid(4,5); + const TString16 codreg = codtab.mid(10,3); + if (codreg.not_empty()) + { + TRegistro reg(codreg,anno); + if (!reg.name().empty()) //se esiste quel registro (ma perche' non dovrebbe?) + { + const TString16 cda = reg.attivita(); + if (codatt != cda) + { + TRectype vecchio (pim.curr()); + TRectype nuovo (pim.curr()); + const TString80 cc = codtab.sub(9); + TString80 cod; + cod << anno << cda << cc; + nuovo.put("CODTAB", cod); + pim.write(nuovo); + pim.read(vecchio); + pim.remove(); + } + } + } + } + + TTable pla("PLA"); + for (pla.first(); !pla.eof(); pla.next()) + pla.remove(); + /*** + TTable rmb("RMB"); + for (rmb.first(); !rmb.eof(); rmb.next()) + rmb.remove(); + ***/ +} + +void TAgg_codatt::aggiorna_att(const char* nome) +{ + TTable tab(nome); + tab.setkey(1); + tab.zero(); + TString16 chiave; + TString16 old_att(_da); old_att.right_just(5,'0'); + TString16 new_att(_a); new_att.right_just(5,'0'); + chiave << _anno << old_att; + tab.put("CODTAB", chiave); + TRectype curr (tab.curr()); + tab.read(_isgteq); + for (; !tab.eof(); tab.next()) + { + if (tab.curr() != curr) break; + + const TString80 codtab = tab.get("CODTAB"); + //const TString16 cod_att = codtab.mid(4,5); //e' uguale a old_att + if (old_att != new_att) + { + TRectype vecchio (tab.curr()); + TRectype nuovo (tab.curr()); + const TString80 cc = codtab.sub(9); + TString80 cod; + cod << _anno << new_att << cc; + nuovo.put("CODTAB", cod); + tab.write(nuovo); + tab.read(vecchio); + tab.remove(); + } + } +} + diff --git a/cg/cg3400.cpp b/cg/cg3400.cpp index 84a326df0..79ed968f8 100755 --- a/cg/cg3400.cpp +++ b/cg/cg3400.cpp @@ -1,1999 +1,1999 @@ -// cg3400 - Stampa libro giornale - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "conto.h" -#include "cglib03.h" -#include "cg2103.h" -#include "cg3400a.h" -#include "cg3400b.h" - -HIDDEN const char* REAL_PICTURE = "###.###.###.###"; - -HIDDEN const int RIGHE_FOOTER = 3; - -HIDDEN const int WCAUS132 = 20; -HIDDEN const int WOPER132 = 28; -HIDDEN const int WCONTO132 = 35; -HIDDEN const int POSCONTO = 74; - -HIDDEN const int DARE132 = 95; -HIDDEN const int AVERE132 = 112; -HIDDEN const int DARE198 = 150; -HIDDEN const int AVERE198 = 174; - -HIDDEN TString256 tmp; - -HIDDEN int date2esc(const TDate& d, int* prevesc = NULL); - -HIDDEN enum descr { causale, conto, operazione }; - -class TContoOccas : public TBill -{ - long _s; - char _t; - TString16 _occfpi; - TString80 _descrizione; - -public: - const TContoOccas& set(int g = 0, int c = 0, long s = 0L, char t = ' ', - const char* d = NULL, int r = -1, const char* occfpi = NULL); - - const TString& descrizione(); - - TContoOccas() : _occfpi(NULL) {}; - virtual ~TContoOccas() {}; -}; - -const TContoOccas& TContoOccas::set(int g, int c, long s, char t,const char* d, int r, const char* occfpi) -{ - _s = s; _t = t; - TBill::set(g,c,s,t,d,r); - _occfpi = occfpi; - return *this; -} - -const TString& TContoOccas::descrizione() -{ - bool really_occas = FALSE; - - if (_occfpi.not_empty()) - { - TLocalisamfile clifo(LF_CLIFO); - clifo.zero(); - clifo.put(CLI_CODCF, (long)_s); - clifo.put(CLI_TIPOCF, _t); - - const bool clifo_ok = (clifo.read() == NOERR); - - if (clifo_ok) really_occas = clifo.get_bool(CLI_OCCAS); - } - - if (_occfpi.empty() || !really_occas) - _descrizione = TBill::descrizione(); - else - { - TLocalisamfile occ(LF_OCCAS); - - occ.zero(); - occ.put(OCC_CFPI, _occfpi); - if (occ.read() != NOERR) occ.zero(); - - _descrizione = occ.get("RAGSOC"); - - /* Immissione occasionale: la ragione sociale e' un campo unico - TString80 nome = _descrizione.mid(30); - _descrizione.cut(30); - _descrizione.trim(); - nome.trim(); - _descrizione << ' ' << nome;*/ - } - return _descrizione; -} - -class CG3400_application : public TPrintapp -{ - static bool mask_a_cod_reg (TMask_field& f, KEY k); - static bool data_a_hndl (TMask_field& f, KEY k); - static bool data_da_hndl (TMask_field& f, KEY k); - static bool mask_b_ripristina(TMask_field& f, KEY k); - static bool mask_b_warning (TMask_field& f, KEY k); - - static bool filter_func(const TRelation * r); - static bool filtra_reg (const TRelation * r); - -private: - TRelation* _rel; - TCursor* _cur; - TRectype* _RecPartoDa, *_RecArrivoA; - int _ae; // anno esercizio di ALLA_DATA - int _tipo; // tipo del registro - int _annoEsMov; // anno esercizio letto da mov - TString16 _reg; - int _anno_iva; - bool _stampa_definitiva; - bool _MovGiaStampato; - bool _gia_settato_ariportare; - bool _forza_ariportare; - bool _nuovo_mese; // Finito il mese ? - long _num_rig; - real _importo; - char _sezione; - // TParagraph_string* _descr_conto; - -public: - TDate _inizioEs, _fineEs; // date inizio e fine esercizio - TRigaiva_array _iva_array; - - TString16 _reg_cod; - TString80 _reg_descr; - TDate _data_da, _data_a, _last_data; - real _tot_dare, _tot_avere; // valori di partenza - real _tot_dare_progr, _tot_avere_progr; // progressivi anno in corso - real _tot_dare_progr_ap, _tot_avere_progr_ap; // progr. anno prec. - real _tot_dare_gg , _tot_avere_gg ; // giornalieri - real _tot_dare_gg_ap , _tot_avere_gg_ap ; // giornalieri anno precedente - real _tot_dare_generale, _tot_avere_generale; // tot. generali - long _nprog_da, _nprog_mov; - int _stampa_width, _stampa_len; - - int _pagine_stampate, _pagine_numerate, _stampa_ok, _pagina_da; - TDate _data_corr, _data_succ, _ultima_data_mov; - int _mese_corr, _mese_succ; - int _last_header; // prima riga di intestazione "libera" - - bool _stampa_stesso_registro; - bool _libro_giornale_iva_unico, _libro_cronologico, _stampa_intesta; - // bool _gia_settata_riga_mov; // per la stampa no iva - - TString80 _ragsoc, _paiva, _comunefis, _viafis; - TString16 _provfis, _cap, _occfpi; - TString80 _cofi; - // TString16 _caus; - - TLocalisamfile * _com, *_clifo,*_pconti,*_nditte,*_anag, *_causali; - - TLocalisamfile* _attiv; // da togliere in futuro (?) - - TTable *_tabreg, *_tabval, *_tabes, *_tabiva; - -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 void postclose_print(); -// virtual bool cancel_hook(); - virtual bool set_print(int); - - virtual bool user_create(); - virtual bool user_destroy(); - - void set_rows (int file, int counter); - int setta_righe_indirizzo(char tipocf, long codcf, int rdesc); - int setta_righe_iva(); - int setta_righe_valuta(int start_riga); - int setta_righe_descr(TParagraph_string&, enum descr); - - void fill_page(int row); - void calcola_iva(); - void init_print(); - bool init_cursor(); - - void init_totals(); - int stampa_intestazione_ditta(); - int set_headers(); - - bool leggi_tabreg(const char * codreg, int annoes); - bool controlla_mov_aep(); - - bool competenza_ep() const { return _ae != _annoEsMov; } - bool competenza_ec() const { return !competenza_ep(); } // tertium non datur ? - - void aggiorna_tabreg(int, int); - void aggiorna_mov(); - int set_totali_giorno(const TDate& giorno, const int righeivasettate); - int set_totali_pagina(int r); - void get_dati_ditta (); - - const char* get_descr_caus (const char * codcaus); - TRectype& look_com (const char * cod); - const char* get_codiva_des(const char* codiva); - void get_date_aep(int aep, TDate* in, TDate* fin); - void update_totals (char sezione, real& importo); - void set_reg_filter(TMask& m); - - CG3400_application() {}; - virtual ~CG3400_application() {}; -}; - -HIDDEN CG3400_application& app() { return (CG3400_application&) main_app(); } - -bool CG3400_application::filtra_reg(const TRelation * r) -{ - const TRectype& rec = r->lfile().curr(); - const int anno = atoi(rec.get("CODTAB").left(4)); - - if (app()._ae) - { - if (anno == app()._ae) - return TRUE; - else - return FALSE; - } - return TRUE; -} - -bool CG3400_application::filter_func(const TRelation * r) -{ - const TRectype& recmov = r->lfile().curr(); - TRectype& recrmov = r->lfile(LF_RMOV).curr(); - const long numreg = recmov.get_long("NUMREG"); - - // Scarto SEMPRE i provvisori - TString16 provvis = recmov.get(MOV_PROVVIS); - if (provvis.trim().not_empty()) - return FALSE; - - // In caso di NO libro con iva scarta quelli che non hanno righe contabili - if (!app()._libro_giornale_iva_unico) - { - recrmov.zero(); - recrmov.put("NUMREG", (long)numreg); - // TRectype cfr(r->lfile(LF_RMOV).curr()); - if (r->lfile(LF_RMOV).read()) - { - const long numreg2 = recrmov.get_long("NUMREG"); - if (numreg2 != numreg) - return FALSE; - else - return TRUE; - } - } - return TRUE; -} - - -////////////////////////////////////////////////////////////////////////// -// Funzioni legate ai parametri ditta -////////////////////////////////////////////////////////////////////////// -HIDDEN bool libro_giornale_iva_unico() -{ - TConfig conf(CONFIG_DITTA); - return conf.get_bool("StLgiU"); -} - -HIDDEN bool libro_cronologico() -{ - TConfig conf(CONFIG_DITTA); - return conf.get_bool("GsLbCn"); -} - -TRectype& CG3400_application::look_com (const char * cod) -{ - _com->zero(); - _com->put(COM_COM, cod); - if (_com->read() != NOERR) - _com->zero(); - - return _com->curr(); -} - -const char * CG3400_application::get_descr_caus (const char * codcaus) -{ - TLocalisamfile& caus = *_causali; - - caus.zero(); - caus.put (CAU_CODCAUS, codcaus); - if (caus.read() != NOERR) caus.zero(); - - tmp = caus.get(CAU_DESCR); - return tmp; -} - -void CG3400_application::get_dati_ditta () -{ - TString16 codanagr; - char 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_char(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); - _comunefis = _anag->get(ANA_COMRF); - - if (_comunefis.empty()) - _comunefis = _anag->get(ANF_COMRES); - - TRectype dep = look_com (_comunefis); - - _comunefis = dep.get(COM_DENCOM); - _provfis = dep.get(COM_PROVCOM); - _cap = dep.get(COM_CAPCOM); - - if (_comunefis.empty()) - { - _viafis = _anag->get(ANA_INDRF); - _viafis.rtrim(); - _viafis << " " << _anag->curr().get (ANA_CIVRF); - } - else - { - _viafis = _anag->get(ANA_INDRES); - _viafis.rtrim(); - _viafis << " " << _anag->get (ANA_CIVRES); - } -} - -bool CG3400_application::user_create() -{ - _ae = 0; - _tabreg = new TTable ("REG"); - _tabval = new TTable ("%VAL"); - _tabes = new TTable ("ESC"); - _tabiva = new TTable ("%IVA"); - - _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); - _causali = new TLocalisamfile(LF_CAUSALI); - _attiv = new TLocalisamfile(LF_ATTIV); // da togliere - - _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: DATAREG+NUMREG - - _RecPartoDa = new TRectype(_cur->file(LF_MOV).curr()); - _RecArrivoA = new TRectype(_cur->file(LF_MOV).curr()); - - add_cursor (_cur); - - add_file (LF_MOV); - add_file (LF_RMOV); - add_file (LF_RMOVIVA); - return TRUE; -} - -bool CG3400_application::user_destroy() -{ - delete _rel; - delete _cur; - delete _RecPartoDa; - delete _RecArrivoA; - - delete _com; delete _clifo; delete _causali; delete _pconti; - delete _nditte; delete _anag; - delete _tabreg; delete _tabes; delete _tabval; delete _tabiva; - - delete _attiv; // da togliere in futuro - - delete _nditte; - delete _anag; - return TRUE; -} - -void CG3400_application::aggiorna_mov() -{ - TLocalisamfile& mov = _cur->file(LF_MOV); - long nprog = _nprog_da + 1; - - const TRectype da(*_RecPartoDa); - const TRectype a(*_RecArrivoA); - _cur->setregion(da, a); - (*_cur) = 0L; - -#ifndef DBG - TProgind prnd (_cur->items(), "Aggiornamento movimenti ...", FALSE, TRUE); -#endif - // for (mov.read(_isgteq, _lock); mov.curr() < *_RecArrivoA && !mov.eof(); mov.next(_lock)) - - for ( ; _cur->pos() < _cur->items(); ++(*_cur)) - { -#ifdef DBG - long numreg = _cur->file(LF_MOV).get_long("NUMREG"); - TString datareg(_cur->file(LF_MOV).get("DATAREG")); - - message_box("Numreg: %ld Datareg: %s", numreg, (const char*)datareg); -#endif - const bool gia_stampato = _cur->file(LF_MOV).get_bool(MOV_STAMPATO); - if (!gia_stampato) - { - _cur->file(LF_MOV).put (MOV_STAMPATO, TRUE); - _cur->file(LF_MOV).put (MOV_NUMGIO, nprog); - mov.rewrite(); - nprog++; - } - // else mov.reread(_unlock); -#ifndef DBG - prnd.addstatus(1); -#endif - } - // mov.reread(_unlock); -} - -int CG3400_application::set_totali_giorno(const TDate& data, const int righeiva) -{ - int r; - char dep[200]; - const int SHIFT = 15; - const int STACC = 51 + SHIFT; - - r = righeiva == 0 ? 1 : righeiva; - - // Se e' l'unico totale lo stampo anche se e' zero - if (competenza_ec() || (_tot_avere_gg != ZERO || _tot_dare_gg != ZERO)) - { - TString td(_tot_dare_gg.string(REAL_PICTURE)); - TString ta(_tot_avere_gg.string(REAL_PICTURE)); - - sprintf(dep, "@b@%dgTotale operazioni del %s @%dg%c %s @%dg%c @%dg%s", - _stampa_width == 132 ? DARE132-STACC : DARE198-STACC, - data.string(), - _stampa_width == 132 ? DARE132-3 : DARE198-2, - 'D', - (const char*)td, - _stampa_width == 132 ? DARE132+16 : DARE198+20, - 'A', - _stampa_width == 132 ? AVERE132 : AVERE198, - (const char*)ta - ); - - set_row (r++, "%s", dep); - _tot_dare_gg = _tot_avere_gg = ZERO; - } - - if (competenza_ep() || (_tot_avere_gg_ap != ZERO || _tot_dare_gg_ap != ZERO)) - { - TString tdp(_tot_dare_gg_ap.string(REAL_PICTURE)); - TString tap(_tot_avere_gg_ap.string(REAL_PICTURE)); - - sprintf (dep, "@b@%dgTotale operazioni del %s Anno precedente @%dg%c %s @%dg%c @%dg%s", - _stampa_width == 132 ? DARE132-STACC : DARE198-STACC, - data.string(), - _stampa_width == 132 ? DARE132-3 : DARE198-2, - 'D', - (const char*)tdp, - _stampa_width == 132 ? DARE132+16 : DARE198+20, - 'A', - _stampa_width == 132 ? AVERE132 : AVERE198, - (const char*)tap - ); - - set_row (r++, "%s", dep); - - _tot_avere_gg_ap = _tot_dare_gg_ap = ZERO; - } - return r; -} - - -void CG3400_application::postclose_print() -{ - if (_stampa_definitiva) - { - const int ultima_fatta = printer().getcurrentpage() - 1; - - if (yesno_box("La stampa e' corretta ?")) - { - aggiorna_mov (); - aggiorna_tabreg (_pagina_da, ultima_fatta); - } - } -} - - -void CG3400_application::preprocess_footer() -{ - TString progr_dare_ap(22), progr_avere_ap(22); - TString progr_dare, progr_avere, dts, ats; - TString256 riga; - bool ap = FALSE; - int r=2; - const int STUMB = 42; - real dt, at; - - reset_footer(); - - if (_tot_avere_progr_ap != ZERO || _tot_dare_progr_ap != ZERO) - { - progr_dare_ap = _tot_dare_progr_ap.string(REAL_PICTURE); - progr_avere_ap = _tot_avere_progr_ap.string(REAL_PICTURE); - ap = TRUE; - } - - // - // Non stampo "A riportare" - // SE : - // 1. E' gia' stato stampato - // OPPURE - // 2. Sono sull'ultima riga - // - - const bool riporta = _forza_ariportare || - (!_gia_settato_ariportare && _cur->pos() < _cur->items()-1); - - if (riporta) - { - dt = _tot_dare_progr + _tot_dare_progr_ap; - at = _tot_avere_progr + _tot_avere_progr_ap; - dts = dt.string(REAL_PICTURE); - ats = at.string(REAL_PICTURE); - - riga.format ("@b@%dg%s@%dg%c %s @%dg%c @%dg%s", - _stampa_width == 132 ? DARE132-STUMB : DARE198-STUMB, - (_nuovo_mese && !_forza_ariportare) ? "Totale progressivi generali " : "A riportare ", - _stampa_width == 132 ? DARE132-3 : DARE198, - 'D', - (const char *) dts, - _stampa_width == 132 ? DARE132+16 : DARE198+20, - 'A', - _stampa_width == 132 ? AVERE132 : AVERE198, - (const char *) ats); - set_footer (r++, (const char*) riga); - - _forza_ariportare = FALSE; - } -} - - -int CG3400_application::set_totali_pagina(int righe) -{ - TString progr_dare_ap(22), progr_avere_ap(22); - TString progr_dare, progr_avere, dts, ats; - TString256 riga; - bool ap = FALSE; - const int SHIFT = 15; - const int STUMB = 51 + SHIFT; - real dt, at; - int r = righe == 0 ? 1 : righe; - // reset_footer(); - - if (_tot_avere_progr_ap != ZERO || _tot_dare_progr_ap != ZERO) - { - progr_dare_ap = _tot_dare_progr_ap.string(REAL_PICTURE); - progr_avere_ap = _tot_avere_progr_ap.string(REAL_PICTURE); - ap = TRUE; - } - - // SONO SULL'ULTIMO ???????????? SI O NO ???????????? - // if (_cur->pos() >= _cur->items()-1) // se sono sull'ultimo - if (_cur->pos() == _cur->items()-1) // se sono sull'ultimo - { - // I totali distinti tra anno precedente e corrente SOLO SE STAMPA DI PROVA - if (!_stampa_definitiva) - { - progr_dare = _tot_dare_progr.string(REAL_PICTURE); - progr_avere = _tot_avere_progr.string(REAL_PICTURE); - riga = ""; - riga.format("@b@%dgTotale progressivi @%dg%c %s @%dg%c @%dg%s", - _stampa_width == 132 ? DARE132-STUMB : DARE198-STUMB, - _stampa_width == 132 ? DARE132-3 : DARE198-2, - 'D', - (const char *) progr_dare, - _stampa_width == 132 ? DARE132+16 : DARE198+20, - 'A', - _stampa_width == 132 ? AVERE132 : AVERE198, - (const char *) progr_avere - ); - - set_row (r++, (const char*) riga); - - if (ap) - { - riga.format("@b@%dgTotale progressivi anno precedente @%dg%c %s @%dg%c @%dg%s", - _stampa_width == 132 ? DARE132-STUMB : DARE198-STUMB, - _stampa_width == 132 ? DARE132-3 : DARE198-2, - 'D', - (const char *) progr_dare_ap, - _stampa_width == 132 ? DARE132+16 : DARE198+20, - 'A', - _stampa_width == 132 ? AVERE132 : AVERE198, - (const char *) progr_avere_ap - ); - set_row (r++, (const char*) riga); - } - } // !stampa_definitiva - - _tot_dare_generale = _tot_dare_progr + _tot_dare_progr_ap; - _tot_avere_generale = _tot_avere_progr + _tot_avere_progr_ap; - dts = _tot_dare_generale.string(REAL_PICTURE); - ats = _tot_avere_generale.string(REAL_PICTURE); - - riga.format("@b@%dgTotale progressivi generali @%dg%c %s @%dg%c @%dg%s", - _stampa_width == 132 ? DARE132-STUMB : DARE198-STUMB, - _stampa_width == 132 ? DARE132-3 : DARE198-2, - 'D', - (const char *) dts, - _stampa_width == 132 ? DARE132+16 : DARE198+20, - 'A', - _stampa_width == 132 ? AVERE132 : AVERE198, - (const char *) ats - ); - - set_row (r++, (const char*) riga); - } - else // Non ancora totale generale - { - // Se il movimento ha righe che continuano nella pagina successiva - // "A riportare" viene stampato dalla preprocess_footer senno' qui - - _gia_settato_ariportare = TRUE; - - dt = _tot_dare_progr + _tot_dare_progr_ap; - at = _tot_avere_progr + _tot_avere_progr_ap; - dts = dt.string(REAL_PICTURE); - ats = at.string(REAL_PICTURE); - - // "Se il mese e' finito devo scrivere Totale progressivi generali - // invece che A riportare" - - riga.format ("@b@%dgTotale progressivi generali @%dg%c %s @%dg%c @%dg%s", - _stampa_width == 132 ? DARE132-STUMB : DARE198-STUMB, - _stampa_width == 132 ? DARE132-3 : DARE198-2, - 'D', - (const char *) dts, - _stampa_width == 132 ? DARE132+16 : DARE198+20, - 'A', - _stampa_width == 132 ? AVERE132 : AVERE198, - (const char *) ats); - set_row (r++, (const char*) riga); - } - return r; -} - -int CG3400_application::stampa_intestazione_ditta() -{ - int r=1; - TString256 intes; - TString riga(_stampa_width); - - get_dati_ditta(); - - riga.fill('-'); - set_header(r, riga); - - set_header (++r, "Ditta: %5ld %-.50s %.35s %.5s %.20s %.2s", - get_firm(), - (const char *)_ragsoc, - (const char *)_viafis, (const char *)_cap, - (const char *)_comunefis, (const char *)_provfis); - - if (_stampa_definitiva) - intes.format ("Partita iva %s @24gCodice fiscale %s", - (const char*)_paiva, (const char*)_cofi, - _stampa_width == 132 ? 102 : 168 - ); - else - intes.format ("Partita iva %s @24gCodice fiscale %s @%dg%s @%dgData @>", - (const char*)_paiva, (const char*)_cofi, - _stampa_width == 132 ? 102 : 168, - "LIBRO DI PROVA", - _stampa_width == 132 ? 117 : 183 - ); - - set_header (++r, "%s", (const char*)intes); - r++; - return r; -} - -int CG3400_application::set_headers() -{ - int r=1; - TString riga(_stampa_width); - TString16 data_da = _data_da.string(); - TString16 data_a = _data_a.string(); - - if (_stampa_intesta || !_stampa_definitiva) - r = stampa_intestazione_ditta(); - - if (_stampa_definitiva) - set_header(r++, "Codice libro: %s %s ",(const char *) _reg_cod, (const char *) _reg_descr); - else - set_header(r++, "Codice libro: %s %s @%dgdalla data: %s alla data: %s @%dgEsercizio: %04d", - (const char *) _reg_cod, (const char *) _reg_descr, - _stampa_width == 132 ? 69 : 135, - (const char *) data_da, (const char *) data_a, - _stampa_width == 132 ? 117 : 183, - _ae - ); - - riga.fill('-'); - set_header(r++, riga); - - if (_libro_cronologico) - set_header(r, "@59gCodice Conto"); - - if (!_stampa_definitiva) { - if (_stampa_width == 132) { - set_header(r++, "@131gS"); - set_header(r, "@1gN.riga"); - } - else { - set_header(r++, "@197gS"); - set_header(r, "@1gN.riga"); - } - } - else - if (_libro_cronologico) r++; // NON LASCIARE RIGHE IN BIANCO!! - - // set_header(r, "@6gCod.Causale@34gDescrizione operazione"); - set_header(r, "@8gDescrizione operazione@36gCausale"); - if (_libro_cronologico) - // POSCONTO = 74; - set_header(r, "@74gGeneralita' cliente/fornitore"); - else - set_header(r, "@59gCodice Conto"); - - if (_stampa_width == 132) - set_header(r, "@120gImporto"); - else - set_header(r, "@161gDare @184gAvere"); - - if (!_stampa_definitiva) - set_header(r, _stampa_width == 132 ? "@131gB" : "@197gB"); - - r++; - - riga.fill('-'); - set_header(r, riga); - - return r; -} - -void CG3400_application::preprocess_header() -{ - int r = _last_header + 1; - int pag = printer().getcurrentpage(); - TString256 riporto; - real riporto_dare, riporto_avere; - - _gia_settato_ariportare = FALSE; - - if (pag > 0) // Stampa riporti - { - riporto_dare = _tot_dare_progr + _tot_dare_progr_ap; - riporto_avere = _tot_avere_progr + _tot_avere_progr_ap; - - // Non stampa nulla se ZERO SOLO SE DI PROVA <<<<<--------------------- - // Lascio una riga senno' vado a finire sull'intestazione - if (!_stampa_definitiva) - if (riporto_dare == ZERO && riporto_avere == ZERO) - { - set_header (r, ""); - return; - } - - TString dare (riporto_dare.string(REAL_PICTURE)); - TString avere(riporto_avere.string(REAL_PICTURE)); - - riporto.format("@b@%dgRiporto: %c @%dg%15s %c@%dg%15s", - _stampa_width == 132 ? 83 : DARE198-11, - _stampa_width == 132 ? 'D' : ' ', - _stampa_width == 132 ? DARE132-1 : DARE198, - (const char *) dare, - _stampa_width == 132 ? 'A' : ' ', - _stampa_width == 132 ? AVERE132 : AVERE198, - (const char *) avere - ); - - set_header (r++, "%s", (const char *) riporto); - } -} - -// -// 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) -{ - switch (file) - { - case LF_MOV: - _nuovo_mese = FALSE; - _iva_array.destroy(); - _nprog_mov = _nprog_da; - *_RecPartoDa = _cur->file(LF_MOV).curr(); - break; - default: - break; - } - return TRUE; -} - -/*** -bool CG3400_application::cancel_hook() -{ - int ultima_fatta = printer().getcurrentpage() - 1; - // int stampate = ultima_fatta - _pagina_da + 1; - - if (yesno_box ("Interrompo la stampa ?")) - { - if (_stampa_definitiva) - aggiorna_tabreg (ultima_fatta, ultima_fatta); - return TRUE; - } - else - return FALSE; -} -***/ - -void CG3400_application::fill_page(int riga) -{ - TString256 rigas; - // char frm[4]; - int r_l = printer().rows_left() - 2; // Tolgo le 2 righe del totale - if (r_l < 0) - { - r_l += printer().formlen() - 8; // Tolgo la testata - _forza_ariportare = TRUE; - } - - // Se sono rimaste righe da riempire - if (r_l > 0) - { - rigas.fill('=', _stampa_width); - rigas.cut(_stampa_width+1); - // sprintf(frm, "%%%3ds", _stampa_width); - set_row(riga++, "%s", (const char*) rigas); - // rigas = ""; - // if (--r_l) - // { - // int j=0; - // Calcola una specie di coefficiente angolare - // int alfa = _stampa_width / r_l; - // for (int i = riga+1; i < r_l; i++, j++) - // { - // if (j*alfa >= _stampa_width-alfa) break; // non uscire dai margini - // rigas.format("@%dg======", j*alfa); - // set_row(i, "%s", (const char*)rigas); - // } - // } - int j=0; - // Calcola una specie di coefficiente angolare - int alfa = (_stampa_width - 6) / r_l; - - for ( ; r_l > 1; r_l--) // Non stampare sulla riga orizzontale! - { - rigas.format("@%dg======", j); - set_row(riga++, rigas); - j += alfa; - } - } -} - -print_action CG3400_application::postprocess_page(int file, int counter) -{ - int righe_iva_settate=0; - bool FINITO = FALSE; - - if (counter) - { - if (_nuovo_mese) { - printer().formfeed(); - _nuovo_mese = FALSE; - } - return NEXT_PAGE; - } - - switch (file) - { - case LF_MOV: - - reset_print(); - - if (_libro_giornale_iva_unico) - { - righe_iva_settate = setta_righe_iva(); - righe_iva_settate = setta_righe_valuta(righe_iva_settate); - } - - _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 || _cur->pos() == _cur->items()-1) - { - _nuovo_mese = (_mese_succ != _mese_corr); - int righe = set_totali_giorno(_data_corr, righe_iva_settate); - if (_nuovo_mese) - { - righe = set_totali_pagina(righe); - // Nella stampa su bollato metto un segno su tutte le righe - if (_stampa_definitiva) - fill_page(righe); - } - return REPEAT_PAGE; - } - - if (righe_iva_settate > 0) - return REPEAT_PAGE; - - break; - - case LF_RMOV: - // Sposto qui per evitare di aggiornare i progressivi con una riga della - // pagina dopo - update_totals(_sezione, _importo); - break; - default: - break; - } - return NEXT_PAGE; -} - -void CG3400_application::update_totals (char sezione, real& importo) -{ -#ifdef DBG - TString dgap(_tot_dare_gg_ap.string()); - TString dgpp(_tot_dare_progr_ap.string()); - TString dgac(_tot_dare_gg.string()); - TString dgpc(_tot_dare_progr.string()); - TString agap(_tot_avere_gg_ap.string()); - TString agpp(_tot_avere_progr_ap.string()); - TString agac(_tot_avere_gg.string()); - TString agpc(_tot_avere_progr.string()); -#endif - - if (sezione == 'D') - { - if (_annoEsMov != _ae) { - _tot_dare_gg_ap += importo; // prog. anno precedente - _tot_dare_progr_ap += importo; - } - else { - _tot_dare_gg += importo; // prog. giornalieri - _tot_dare_progr += importo; // prog. generali - } - } - else - { - if (_annoEsMov != _ae) { - _tot_avere_gg_ap += importo; - _tot_avere_progr_ap += importo; - } - else { - _tot_avere_gg += importo; - _tot_avere_progr += importo; - } - } -#ifdef DBG - dgap = _tot_dare_gg_ap.string(); - dgpp = _tot_dare_progr_ap.string(); - dgac = _tot_dare_gg.string(); - dgpc = _tot_dare_progr.string(); - agap = _tot_avere_gg_ap.string(); - agpp = _tot_avere_progr_ap.string(); - agac = _tot_avere_gg.string(); - agpc = _tot_avere_progr.string(); -#endif -} - - - -void CG3400_application::set_rows (int file, int counter) -{ - TString16 datadoc_str, datareg_str, numdoc, frm, caus; - TDate datadoc, datareg; - TString80 mov_descr, rmv_descr; - TParagraph_string descr_conto("", 50); - TContoOccas tc; - long numreg, protiva; - int r = 1; - int g, c; - long s; - static char cf = ' '; - static int rdes = 1; - - switch (file) - { - case LF_MOV: - reset_row(1); - reset_row(2); - - datareg = _cur->file(LF_MOV).get_date("DATAREG"); - datadoc = _cur->file(LF_MOV).get_date("DATADOC"); - datareg_str = datareg.string(); - // "Fai vedere lo stesso ..-..-.... anche se non c'e' la data..." - if (datareg_str.empty()) - datareg_str = " - - "; - datadoc_str = datadoc.string(); - if (datadoc_str.empty()) - datadoc_str = " - - "; - numdoc = _cur->file(LF_MOV).get("NUMDOC"); - numreg = _cur->file(LF_MOV).get_long("NUMREG"); - mov_descr = _cur->file(LF_MOV).get("DESCR"); - - // Usati in setta_righe_iva per determinare tipo attivita' - _reg = _cur->file(LF_MOV).get(MOV_REG); - _anno_iva = _cur->file(LF_MOV).get_int(MOV_ANNOIVA); - /////////////////////////////////////////////////////////// - - protiva = _cur->file(LF_MOV).get_long(MOV_PROTIVA); - caus = _cur->file(LF_MOV).get(MOV_CODCAUS); - _occfpi = _cur->file(LF_MOV).get(MOV_OCFPI); - _annoEsMov = _cur->file(LF_MOV).get_int(MOV_ANNOES); - _MovGiaStampato = _cur->file(LF_MOV).get_bool(MOV_STAMPATO); - - if (_stampa_definitiva) - { - set_row(r,"Operazione n. @b%-7ld@r", _nprog_mov); - set_row(r," del @b%s@r", (const char*)datareg_str); // XX/XX/XXXX - set_row(r," doc. n. @b%-7s@r",(const char*)numdoc); - set_row(r," del @b%s@r %-50s",(const char*)datadoc_str, - (const char*)mov_descr); - } - else - { - set_row(r,"Operazione n. @b%-7ld@r", numreg); - set_row(r," del @b%s@r", (const char*) datareg_str); - set_row(r," doc. n. @b%-7s@r", (const char*) numdoc); - set_row(r," del @b%s@r %-50s", (const char*)datadoc_str,(const char*)mov_descr); - } - - if (_annoEsMov != _ae) - set_row(r," Comp. %04d", _annoEsMov); - - if (_MovGiaStampato && !_stampa_definitiva) - set_row(r,format("@%dg*",_stampa_width == 132 ? 131 : 197)); - - if (caus.not_empty()) - { - TString80 desc_caus(get_descr_caus(caus)); - set_row(r+1, "@36gCausale %3s %-50s", (const char*) caus, (const char*) desc_caus); - if (_reg.not_empty()) - set_row(r+1, " (R.IVA @b%3s@r Prot. @b%ld@r) ", (const char*)_reg,protiva); - } - - break; - - case LF_RMOV: - - _num_rig++; - - reset_print(); - - g = _cur->file(LF_RMOV).get_int("GRUPPO"); - c = _cur->file(LF_RMOV).get_int("CONTO"); - s = _cur->file(LF_RMOV).get_long("SOTTOCONTO"); - cf = _cur->file(LF_RMOV).get_char(RMV_TIPOC); - - if (cf != 'C' && cf != 'F') - cf = ' '; - - numreg = _cur->file(LF_RMOV).get_long("NUMREG"); - datareg = _cur->file(LF_RMOV).get("DATAREG"); - - _sezione = _cur->file(LF_RMOV).get_char (RMV_SEZIONE); - _importo = _cur->file(LF_RMOV).get_real (RMV_IMPORTO); - - rmv_descr = _cur->file(LF_RMOV).get(RMV_DESCR); - - r=1; - - // Num. progressivo di operazione. Azzerato in preprocess_page - if (!_stampa_definitiva) set_row (r, "%7ld", _num_rig); - - set_row (r, "@8g%-50s", (const char*) rmv_descr); - - set_row (r, "@59g%03d.", g); - if (c != 0) - set_row (r, "%03d.", c); - if (s != 0L) - set_row (r, "%06ld", s); - - tc.set(g,c,s,cf,NULL,-1,_occfpi); - - if (_stampa_width == 132) - descr_conto.set_width (WCONTO132); - else // se a 198 non spezzo le descrizioni - descr_conto.set_width(198); - - descr_conto = tc.descrizione(); - - if (_stampa_width == 132) - rdes = setta_righe_descr (descr_conto, conto); - else - { - rdes = 2; - frm.format("@%dg%%-%ds", POSCONTO,50); - set_row (r, frm, (const char*) descr_conto); - } - - if (cf > ' ') - if (_libro_cronologico) - rdes = setta_righe_indirizzo(cf, s, rdes); - - // NB Totali aggiornati in postprocess_page (update_totals()) - - if (_stampa_width == 132) - { - set_row (r, "@112g%r", &_importo); - set_row (r, "@128g%c", _sezione); - } - else // stampa_width == 198 - set_row (r, _sezione == 'D' ? "@150g%r" : "@174g%r", &_importo); - - if (_MovGiaStampato && !_stampa_definitiva) - set_row(r,format("@%dg*",_stampa_width == 132 ? 131 : 197)); - - break; - - default: - break; - } -} - -// -// PREPROCESS_PAGE -// -// Non scarto nulla qui, non si deve mai vedere una stampa vuota -// -bool CG3400_application::preprocess_page(int file, int counter) -{ - if (counter) return TRUE; - - switch (file) { - - case LF_MOV: - - _annoEsMov = _anno_iva = 0; - _iva_array.destroy(); - - *_RecArrivoA = _cur->file(LF_MOV).curr(); - - _nprog_mov++; - // Il numero di operazione deve ripartire da 0 per ogni movimento - _num_rig = 0; - - _data_corr = _cur->file(LF_MOV).get_date(MOV_DATAREG); - - // _ultima_data_mov finisce sul registro come ultima data di stampa - if (_data_corr > _ultima_data_mov) _ultima_data_mov = _data_corr; - - _mese_corr = _data_corr.month(); - - break; - - case LF_RMOV: - break; - - case LF_RMOVIVA: - if (_libro_giornale_iva_unico) calcola_iva (); - break; - - default: - break; - } - set_rows (file, counter); - return TRUE; -} - -void CG3400_application::calcola_iva() -{ - TString codiva; - int tipocr, tipodet, tipoatt; - real impo, impos; - bool intra; - 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); - tipoatt = iva.get_int ("TIPOATT"); - codiva = iva.get (RMI_CODIVA); - intra = iva.get_bool (RMI_INTRA); - _iva_array.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,0,intra,tipoatt); - } -} - -int CG3400_application::setta_righe_descr(TParagraph_string& str, enum descr des) -{ - int i = 1; - TString16 frm; - const char* r; - // char descr[51]; - TString80 descr; - - switch (des) - { - case causale: // lunga 20 - if (_libro_giornale_iva_unico) - frm.format("@10g\0x25%ds", _stampa_width == 132 ? WCAUS132 : 40); - else - frm.format("@48g%%d", WCAUS132); - break; - case conto: // lunga 21 - // if (_libro_giornale_iva_unico) - frm.format("@%dg%%-%ds", POSCONTO,WCONTO132); - /* - else - frm.format("@26g%%d", POSCONTO,WCONTO132); */ - break; - case operazione: // lunga 28 - if (_libro_giornale_iva_unico) - frm.format("@31g%%d", WOPER132); - else - frm.format("@69g%%d", WOPER132); - break; - default: - break; - } - while ((r = str.get()) != NULL) - { - descr = r; - descr.ltrim(); - set_row (i++, (const char*)frm, (const char*)descr); - } - - return i; -} - -const char* CG3400_application::get_codiva_des(const char* codiva) -{ - _tabiva->zero(); - _tabiva->put("CODTAB", codiva); - if (_tabiva->read() == NOERR) - return _tabiva->get("S0"); - else - return NULL; -} - -// NB -// Questa funzione ritorna il numero di righe che ha settato. -// Se questo e' diverso da 0 viene fatta una REPEAT_PAGE -// Attenzione quindi se si modifica la variabile r -int CG3400_application::setta_righe_iva() -{ - int r=0, j; - TString80 rig; - - for (j = 0; j < _iva_array.items(); j++) - { - TRigaiva& riga = (TRigaiva&)_iva_array[j]; - r = j+1; - set_row(r, " Imponibile@15g%r", &riga._imponibile); - set_row(r, "@31gImposta@39g%r", &riga._imposta); - // set_row(r, "@58gCod.Iva@68g%3s", (const char*)riga._codiva); - set_row(r, "@56gCod.Iva %3s", (const char*)riga._codiva); - const TString80 codiva_des(get_codiva_des(riga._codiva)); - const int tipoatt = riga._tipoatt; - if (_stampa_width == 132) - set_row(r, "@68g%-.17s", (const char*)codiva_des); - else - set_row(r, "@68g%-.50s", (const char*)codiva_des); - const int S132 = 89; - const int S198 = 119; - rig.format("@%dg", _stampa_width == 132 ? S132 : S198); - switch (riga._tipodet) - { - case 0 : - rig << "Detraibile "; - break; - case 1 : - rig << "Indetraibile su op.es. "; - break; - case 3 : - rig << "Passaggi interni "; - break; - case 9 : - rig << "Indetraibile art.19 "; - break; - default: break; - } - set_row(r, (const char*)rig); - - TRegistro reg(_reg, _anno_iva); - const bool att_mista_ev = reg.attivita_mista(); - if (tipoatt != 0 && att_mista_ev) - set_row(r, " Tipo attivita' %d", tipoatt); - } - _iva_array.destroy(); - return r; -} - -int CG3400_application::setta_righe_valuta(int riga) -{ - TString16 codvali; - real corrval; - int r = riga+1; - - corrval = current_cursor()->file(LF_MOV).get_real(MOV_CORRVALUTA); - - if (corrval != ZERO) - { - codvali = current_cursor()->file(LF_MOV).get(MOV_CODVALI); - TString valut(corrval.string("###.###.###.###,@@")); - - set_row(r,"@56gValuta %3s", (const char*)codvali); - if (_stampa_width == 132) - set_row(r++,"@89gCorr.in valuta @109g%s", (const char*)valut); - else - set_row(r++,"@119gCorr.in valuta @171g%s", (const char*)valut); - } - return r; -} - -// Cerca l'indirizzo del C/F. -// Legge CLIFO o OCCAS a seconda di _occas -// Setta le righe 2 e 3 che vengono poi resettate al record successivo -int CG3400_application::setta_righe_indirizzo(char tipocf, long codcf,int rdes) -{ - TString16 prov, comcf, capcf, civcf, statocf; - TString80 viacf, comune; - bool really_occas = FALSE; - char tipoa; - long codanagr; - char riga[256]; - int r = rdes; - - _clifo->zero(); - _clifo->put(CLI_CODCF, codcf); - _clifo->put(CLI_TIPOCF, tipocf); - - const bool clifo_ok = (_clifo->read() == NOERR); - - if (clifo_ok) really_occas = _clifo->get_bool(CLI_OCCAS); - - if (_occfpi.not_empty() && really_occas) // => e' un occasionale... - { - TLocalisamfile occ(LF_OCCAS); - - occ.zero(); - occ.put(OCC_CFPI, _occfpi); - if (occ.read() != NOERR) occ.zero(); - - viacf = occ.get (OCC_INDIR); - civcf = occ.get (OCC_CIV); - capcf = occ.get (OCC_CAP); - comcf = occ.get (OCC_COM); - } -else -{ - // E' possibile cio' ? - if (!clifo_ok) return r; - - 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); - tipoa = _clifo->get_char(CLI_TIPOAPER); - codanagr = _clifo->get_long(CLI_CODANAGPER); -} - -TRectype rec = look_com (comcf); -comune = rec.get(COM_DENCOM); -prov = rec.get(COM_PROVCOM); - -if (viacf.not_empty()) -{ - sprintf (riga, "@%dg%s %s", - POSCONTO, - (const char*) viacf, - (const char*) civcf - ); - - set_row (r++, riga); -} - -if (comune.not_empty() || prov.not_empty() || capcf.not_empty()) -{ - sprintf (riga, "@%dg%s %s %s", - POSCONTO, - (const char*) capcf, (const char*) comune, - (const char*) prov - ); - set_row (r++, riga); -} - -// Se fisica prendo anche data nascita e luogo -if (tipoa == 'F') -{ - TString80 comna; - TString16 datana, codcomna, provna, capna, statona; - - datana = _clifo->get("DATANASC"); - - if (datana.not_empty()) - { - codcomna = _clifo->get("COMNASC"); - TRectype dep = look_com (codcomna); - - comna = dep.get(COM_DENCOM); - provna = dep.get(COM_PROVCOM); - capna = dep.get(COM_CAPCOM); - - statona = dep.get("STATO"); - - sprintf (riga, "@%dg%s %s %s %s", POSCONTO, - (const char*)datana, - (const char*)comna, - (const char*)provna, (const char*) capna); - - set_row(r++, riga); - } -} -return r; -} - -// -// Lettura/aggiornamento tabella registri -// -void CG3400_application::aggiorna_tabreg(int partito_da, int stampate) -{ - TString16 codtab; - - codtab.format ("%04d%-3s", _ae, (const char*) _reg_cod); - - _tabreg->zero(); - _tabreg->put("CODTAB", codtab); - _tabreg->read(); - - if (_tabreg->good()) - { - // _tabreg->put ("I8", (long)partito_da); // partito_da = -1 se stampa OK - _tabreg->put ("I1", (long)_pagine_stampate + stampate); // pagine stampate - _tabreg->put ("I6", _nprog_mov); // ultimo numero di riga - _tabreg->put ("R1", _tot_dare_generale); - _tabreg->put ("R2", _tot_avere_generale); - _tabreg->put ("D3", _ultima_data_mov); // Data piu' alta trovata - _tabreg->rewrite(); - } -} - -void CG3400_application::get_date_aep(int aep, TDate* in, TDate* fin) -{ - TTable esc("ESC"); - - esc.zero(); esc.put("CODTAB", format("%04d",aep)); - if (esc.read() == NOERR) - { - *in = esc.get_date("D0"); - *fin = esc.get_date("D1"); - } -} - -const int es_prec(const int es_corr) -{ - TTable ese("ESC"); - TString16 first; - TString codtab; - - ese.first(); - first = ese.get("CODTAB"); - - codtab.format("%04d",es_corr); - - if (codtab == first) - return 0; - - return es_corr - 1; -} - -bool CG3400_application::controlla_mov_aep() -{ - const int aep = es_prec(_ae); - bool gia_stampati = TRUE; - TDate inizio_ep, fine_ep; - - if (aep == 0) // = e' il primo esercizio - return TRUE; -else - get_date_aep(aep,&inizio_ep, &fine_ep); - -#ifdef DBG - TString instr(inizio_ep.string()); - TString finstr(fine_ep.string()); -#endif - - TRectype da (_cur->file(LF_MOV).curr()); - TRectype a (_cur->file(LF_MOV).curr()); - - da.zero(); a.zero(); - da.put(MOV_DATAREG, inizio_ep); - a.put (MOV_DATAREG, fine_ep); - - _cur->setregion(da, a); - _cur->set_filterfunction(filter_func); - // _cur->setfilter(format("ANNOES=%04d && STAMPATO!=\"X\"", aep)); - - (*_cur) = 0L; - for ( ; _cur->pos() < _cur->items(); ++(*_cur)) - { -#ifdef DBG - TString datareg(_cur->file().get("DATAREG")); - TString numreg(_cur->file().get("NUMREG")); -#endif - gia_stampati = _cur->file().get_bool("STAMPATO"); - if (!gia_stampati) break; // basta trovarne uno ancora da stampare - } - - if (_cur->items() > 0L && !gia_stampati) - { - _cur->setfilter(""); - warning_box("Impossibile proseguire nella stampa.\nEsistono movimenti nell'esercizio precedente non ancora stampati su bollato"); - return FALSE; - } - _cur->setfilter(""); - return TRUE; -} - -bool CG3400_application::leggi_tabreg(const char * reg_cod, int reg_anno) -{ - TString16 codtab; - - _ae = reg_anno; - - codtab.format ("%04d%-3s", reg_anno, reg_cod); - - _tabreg->zero(); - _tabreg->put("CODTAB", codtab); - const bool ok = (_tabreg->read() == NOERR); - - if (!ok) _tabreg->zero(); - - _pagine_stampate = _tabreg->get_int("I1"); - _pagine_numerate = _tabreg->get_int("I2"); - // _stampa_ok = _tabreg->get_int("I8"); - _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"); - _stampa_stesso_registro = _tabreg->get_bool ("B8"); - _reg_descr = _tabreg->get ("S0"); - _tipo = _tabreg->get_int("I0"); - - return ok; -} - -// Calcola l'anno di esercizio di una data -// Certified 99% -HIDDEN int date2esc(const TDate& d, int* prevesc) -{ - if (prevesc) *prevesc = 0; - TTable esc("ESC"); - for (int err = esc.first(); err == NOERR; err = esc.next()) - { - const TDate ia(esc.get("D0")); // Data inizio esercizio - const TDate fa(esc.get("D1")); // Data fine esercizio - app()._inizioEs = ia; - app()._fineEs = fa; - const anno = esc.get_int("CODTAB"); - if (d >= ia && d <= fa) - return anno; - if (prevesc) *prevesc = anno; - } - return 0; -} - -void CG3400_application::set_reg_filter(TMask& m) -{ - TEdit_field& reg = m.efield(CODREG); - reg.browse()->cursor()->set_filterfunction(filtra_reg); -} - -//----------------------------------------------------------------------- -// -// MASCHERE -// -//----------------------------------------------------------------------- - -// NB -// Qui viene compilato app()._ae -// L'anno di esercizio e' determinato da DATA_A -// -bool CG3400_application::data_a_hndl (TMask_field& f, KEY k) -{ - TMask& m = f.mask(); - - if (f.to_check(k)) - { - const TDate data_a(f.get()); - TString16 dep(data_a.string()); - - if (dep.empty()) return TRUE; - - const int ae = date2esc(data_a); // Anno esercizio - - app()._ae = ae; - if (ae == 0) - return f.error_box("La data specificata non appartiene a nessun esercizio"); - else - { - m.set(ANNO_ESER, ae); - m.send_key(K_TAB, CODREG); - } - } - - if (k == K_ENTER) - { - const bool definitiva = m.get_bool(STAMPA_DEF); - const TDate data_da(m.get(DATA_DA)); - const TDate data_a(f.get()); - TString16 dtda(data_da.string()); - const int ae = app()._ae; - const TMask_field& fld_dtda = m.field(DATA_DA); - - if (definitiva) - { - if (dtda.not_empty()) // senno' ci metto inizioEs - { - if (data_da < app()._inizioEs || data_a > app()._fineEs); - return f.warning_box("Le date specificate non appartengono allo stesso esercizio"); - if (data_da > data_a) - return f.warning_box("La data di partenza non puo' essere maggiore della data finale"); - } - } - } // if K_ENTER - - return TRUE; -} - -bool CG3400_application::data_da_hndl(TMask_field& f, KEY k) -{ - TMask& m = f.mask(); - // if (f.to_check(k)) - if (k == K_TAB) - { - const TDate data_da (f.get()); - const TString16 data_a(m.get(DATA_A)); - const int ae_data_da = date2esc(data_da); - const TString16 dep(data_da.string()); - - if (dep.empty() || data_a.empty()) - return TRUE; - - if (app()._ae != 0) - if (app()._ae != ae_data_da) - return f.error_box("Le due date non appartengono allo stesso esercizio"); - } - - if (k == K_ENTER) - { - const bool definitiva = m.get_bool(STAMPA_DEF); - const TDate data_a(m.get(DATA_A)); - const TDate data_da(f.get()); - TString16 dtda(data_da.string()); - - // Controlli sulle date - - // se la stampa e' di prova DALLA_DATA e' obbligatoria - if (!definitiva) - if (dtda.empty()) - return f.warning_box("Manca la data di partenza"); - - if (dtda.not_empty()) - if (data_da > data_a) - return f.warning_box("La data di partenza non puo' essere maggiore della data finale"); - } - return TRUE; -} - -// -// MASK_A_COD_REG -// -// ----------->>>> SCRIVO ANCHE QUI _ae <<<<---------------- -// -bool CG3400_application::mask_a_cod_reg (TMask_field& f, KEY k) -{ - if (f.to_check(k)) - { - TMask& m = f.mask(); - CG3400_application& a = app(); - const bool definitiva = m.get_bool(STAMPA_DEF); - const TString16 data_astr(m.get(DATA_A)); - const TDate data_a(m.get(DATA_A)); - - // 25/11 controlli sul registro solo DOPO aver messo la DATA_A - if (data_astr.empty()) - return TRUE; - else - a._ae = date2esc(data_a); // Anno esercizio - - const TString16 reg_cod(f.get()); - - if (reg_cod.empty()) - { - if (k == K_TAB) // Magari ci ripassa e lo inserisce - return TRUE; - else // Se e' K_ENTER mi serve davvero - return f.error_box("Manca il codice registro"); - } - - bool reg_ok = a.leggi_tabreg(reg_cod, a._ae); - - // Output da qui della descrizione del registro e dell'anno - m.set(REG_DESC, a._reg_descr); - m.set(ANNO_ESER, a._ae); - /* - // CHECKTYPE NORMAL abolito! (nella maschera non ho l'anno... - if (!reg_ok) - return f.warning_box("Registro inesistente"); - - if (app()._tipo != 5) - return f.warning_box("Il registro %s per l'anno %d non e' di tipo libro giornale", - (const char *) reg_cod, a._ae); - */ - } - return TRUE; -} - -// -// mask_b_ripristina -// -// Se premo il bottone rimetto i valori precedenti -// dentro ai campi (per ripetere la stampa) -// -bool CG3400_application::mask_b_ripristina (TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - CG3400_application& a = (CG3400_application&)main_app(); - f.mask().set(PROGR_DARE, a._tot_dare.string()); - f.mask().set(ULTIMA_DATA, a._last_data.string()); - f.mask().set(N_RIGA_STAMPATO, a._nprog_da); - f.mask().set(PAGINA_DA, a._pagine_stampate); - } - return TRUE; -} - -bool CG3400_application::mask_b_warning (TMask_field& f, KEY k) -{ - static bool gia_detto = FALSE; - - if (!gia_detto) - if (k == K_SPACE) - { - f.warning_box("Le modifiche a questi progressivi saranno scritte nel registro"); - gia_detto = TRUE; - return TRUE; - } - - if (k == K_ENTER || k == K_ESC) - gia_detto = FALSE; - - return TRUE; -} - -void CG3400_application::init_print() -{ - // 17.5.95 Leggo parametri di stampa del registro - TString16 config; - const long codditta = get_firm(); - const char* reg = (const char*)_reg_cod; - - config.format("REG%05ld%03s", codditta, reg); - - printer().read_configuration(config); - - if (_stampa_len != 0) - printer().formlen(_stampa_len); - - printer().footerlen(RIGHE_FOOTER); - - reset_print(); - reset_header(); - reset_footer(); - set_background(); - - for (int i=1; ifile(LF_MOV).curr()); - TRectype a (_cur->file(LF_MOV).curr()); - -#ifdef DBG - TString instr(_data_da.string()); - TString finstr(_data_a.string()); -#endif - - da.zero(); a.zero(); - da.put(MOV_DATAREG, _data_da); - a.put (MOV_DATAREG, _data_a); - - _cur->setregion(da, a); - _cur->set_filterfunction(filter_func); - - if (_stampa_definitiva) - _cur->setfilter("STAMPATO!=\"X\""); - - (*_cur) = 0L; - - if (_cur->items() == 0L) - { - _cur->setfilter(""); - return warning_box ("Non ci sono movimenti da stampare nel periodo selezionato.\nLa stampa e' annullata"); - } - - return TRUE; -} - -bool CG3400_application::set_print(int) -{ - TMask ma ("cg3400a"); - KEY tasto; - - ma.set_handler (CODREG, mask_a_cod_reg); - ma.set_handler (DATA_A, data_a_hndl); - ma.set_handler (DATA_DA,data_da_hndl); - // set_reg_filter(ma); - - _pagina_da = 0; // Parto dall'inizio - _forza_ariportare = FALSE; - - while ((tasto = ma.run()) != K_QUIT) - { - _libro_giornale_iva_unico = libro_giornale_iva_unico(); - _libro_cronologico = libro_cronologico(); - - _reg_cod = ma.get(CODREG); - _stampa_definitiva = ma.get_bool(STAMPA_DEF); - _data_da = ma.get(DATA_DA); - _data_a = ma.get(DATA_A); - - _stampa_width = ma.get_int(STAMPA_WIDTH); - _stampa_len = ma.get_int(STAMPA_LEN); - - // Se stampa definitiva DALLA_DATA e' la data di inizio esercizio - // e si scartano i movimenti gia' stampati su bollato - if (_stampa_definitiva) - { - _data_da = _inizioEs; - - // Controlla che non siano rimasti movimenti ancora da stampare dell'es.prec. - if (_stampa_stesso_registro) - if (!controlla_mov_aep()) - continue; - } - - if (!init_cursor()) continue; - - if (_stampa_definitiva) - { - TMask mb("cg3400b"); - mb.set_handler (DLG_RIPRISTINA, mask_b_ripristina); - mb.set_handler (PROGR_DARE, mask_b_warning); - mb.set_handler (N_RIGA_STAMPATO,mask_b_warning); - mb.set_handler (ULTIMA_DATA, mask_b_warning); - mb.set (PROGR_DARE, _tot_dare.string()); - mb.set (N_RIGA_STAMPATO, _nprog_da); - mb.set (ULTIMA_DATA, _last_data.string()); - mb.set (PAGINA_DA, _pagine_stampate); - - tasto = mb.run(); - if (tasto == K_ENTER) - { - real dare2; - _nprog_da = mb.get_long(N_RIGA_STAMPATO); - _last_data = mb.get(ULTIMA_DATA); - dare2 = mb.get_long(PROGR_DARE); - _pagina_da = mb.get_int(PAGINA_DA); - // "Se l'utente cambia il progressivo dare, esso viene uguagliato all'avere" - if (dare2 != _tot_dare) - { - _tot_dare = dare2; - _tot_avere = dare2; - } - } - else - continue; - } - - init_print(); - init_totals(); - - return TRUE; - } - return FALSE; -} - -int cg3400 (int argc, char * argv[]) -{ - CG3400_application app; - app.run(argc, argv, "Stampa libro giornale"); - return TRUE; -} - +// cg3400 - Stampa libro giornale + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "conto.h" +#include "cglib03.h" +#include "cg2103.h" +#include "cg3400a.h" +#include "cg3400b.h" + +HIDDEN const char* REAL_PICTURE = "###.###.###.###"; + +HIDDEN const int RIGHE_FOOTER = 3; + +HIDDEN const int WCAUS132 = 20; +HIDDEN const int WOPER132 = 28; +HIDDEN const int WCONTO132 = 35; +HIDDEN const int POSCONTO = 74; + +HIDDEN const int DARE132 = 95; +HIDDEN const int AVERE132 = 112; +HIDDEN const int DARE198 = 150; +HIDDEN const int AVERE198 = 174; + +HIDDEN TString256 tmp; + +HIDDEN int date2esc(const TDate& d, int* prevesc = NULL); + +HIDDEN enum descr { causale, conto, operazione }; + +class TContoOccas : public TBill +{ + long _s; + char _t; + TString16 _occfpi; + TString80 _descrizione; + +public: + const TContoOccas& set(int g = 0, int c = 0, long s = 0L, char t = ' ', + const char* d = NULL, int r = -1, const char* occfpi = NULL); + + const TString& descrizione(); + + TContoOccas() : _occfpi(NULL) {}; + virtual ~TContoOccas() {}; +}; + +const TContoOccas& TContoOccas::set(int g, int c, long s, char t,const char* d, int r, const char* occfpi) +{ + _s = s; _t = t; + TBill::set(g,c,s,t,d,r); + _occfpi = occfpi; + return *this; +} + +const TString& TContoOccas::descrizione() +{ + bool really_occas = FALSE; + + if (_occfpi.not_empty()) + { + TLocalisamfile clifo(LF_CLIFO); + clifo.zero(); + clifo.put(CLI_CODCF, (long)_s); + clifo.put(CLI_TIPOCF, _t); + + const bool clifo_ok = (clifo.read() == NOERR); + + if (clifo_ok) really_occas = clifo.get_bool(CLI_OCCAS); + } + + if (_occfpi.empty() || !really_occas) + _descrizione = TBill::descrizione(); + else + { + TLocalisamfile occ(LF_OCCAS); + + occ.zero(); + occ.put(OCC_CFPI, _occfpi); + if (occ.read() != NOERR) occ.zero(); + + _descrizione = occ.get("RAGSOC"); + + /* Immissione occasionale: la ragione sociale e' un campo unico + TString80 nome = _descrizione.mid(30); + _descrizione.cut(30); + _descrizione.trim(); + nome.trim(); + _descrizione << ' ' << nome;*/ + } + return _descrizione; +} + +class CG3400_application : public TPrintapp +{ + static bool mask_a_cod_reg (TMask_field& f, KEY k); + static bool data_a_hndl (TMask_field& f, KEY k); + static bool data_da_hndl (TMask_field& f, KEY k); + static bool mask_b_ripristina(TMask_field& f, KEY k); + static bool mask_b_warning (TMask_field& f, KEY k); + + static bool filter_func(const TRelation * r); + static bool filtra_reg (const TRelation * r); + +private: + TRelation* _rel; + TCursor* _cur; + TRectype* _RecPartoDa, *_RecArrivoA; + int _ae; // anno esercizio di ALLA_DATA + int _tipo; // tipo del registro + int _annoEsMov; // anno esercizio letto da mov + TString16 _reg; + int _anno_iva; + bool _stampa_definitiva; + bool _MovGiaStampato; + bool _gia_settato_ariportare; + bool _forza_ariportare; + bool _nuovo_mese; // Finito il mese ? + long _num_rig; + real _importo; + char _sezione; + // TParagraph_string* _descr_conto; + +public: + TDate _inizioEs, _fineEs; // date inizio e fine esercizio + TRigaiva_array _iva_array; + + TString16 _reg_cod; + TString80 _reg_descr; + TDate _data_da, _data_a, _last_data; + real _tot_dare, _tot_avere; // valori di partenza + real _tot_dare_progr, _tot_avere_progr; // progressivi anno in corso + real _tot_dare_progr_ap, _tot_avere_progr_ap; // progr. anno prec. + real _tot_dare_gg , _tot_avere_gg ; // giornalieri + real _tot_dare_gg_ap , _tot_avere_gg_ap ; // giornalieri anno precedente + real _tot_dare_generale, _tot_avere_generale; // tot. generali + long _nprog_da, _nprog_mov; + int _stampa_width, _stampa_len; + + int _pagine_stampate, _pagine_numerate, _stampa_ok, _pagina_da; + TDate _data_corr, _data_succ, _ultima_data_mov; + int _mese_corr, _mese_succ; + int _last_header; // prima riga di intestazione "libera" + + bool _stampa_stesso_registro; + bool _libro_giornale_iva_unico, _libro_cronologico, _stampa_intesta; + // bool _gia_settata_riga_mov; // per la stampa no iva + + TString80 _ragsoc, _paiva, _comunefis, _viafis; + TString16 _provfis, _cap, _occfpi; + TString80 _cofi; + // TString16 _caus; + + TLocalisamfile * _com, *_clifo,*_pconti,*_nditte,*_anag, *_causali; + + TLocalisamfile* _attiv; // da togliere in futuro (?) + + TTable *_tabreg, *_tabval, *_tabes, *_tabiva; + +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 void postclose_print(); + // virtual bool cancel_hook(); + virtual bool set_print(int); + + virtual bool user_create(); + virtual bool user_destroy(); + + void set_rows (int file, int counter); + int setta_righe_indirizzo(char tipocf, long codcf, int rdesc); + int setta_righe_iva(); + int setta_righe_valuta(int start_riga); + int setta_righe_descr(TParagraph_string&, enum descr); + + void fill_page(int row); + void calcola_iva(); + void init_print(); + bool init_cursor(); + + void init_totals(); + int stampa_intestazione_ditta(); + int set_headers(); + + bool leggi_tabreg(const char * codreg, int annoes); + bool controlla_mov_aep(); + + bool competenza_ep() const { return _ae != _annoEsMov; } + bool competenza_ec() const { return !competenza_ep(); } // tertium non datur ? + + void aggiorna_tabreg(int, int); + void aggiorna_mov(); + int set_totali_giorno(const TDate& giorno, const int righeivasettate); + int set_totali_pagina(int r); + void get_dati_ditta (); + + const char* get_descr_caus (const char * codcaus); + TRectype& look_com (const char * cod); + const char* get_codiva_des(const char* codiva); + void get_date_aep(int aep, TDate* in, TDate* fin); + void update_totals (char sezione, real& importo); + void set_reg_filter(TMask& m); + + CG3400_application() {}; + virtual ~CG3400_application() {}; +}; + +HIDDEN CG3400_application& app() { return (CG3400_application&) main_app(); } + +bool CG3400_application::filtra_reg(const TRelation * r) +{ + const TRectype& rec = r->lfile().curr(); + const int anno = atoi(rec.get("CODTAB").left(4)); + + if (app()._ae) + { + if (anno == app()._ae) + return TRUE; + else + return FALSE; + } + return TRUE; +} + +bool CG3400_application::filter_func(const TRelation * r) +{ + const TRectype& recmov = r->lfile().curr(); + TRectype& recrmov = r->lfile(LF_RMOV).curr(); + const long numreg = recmov.get_long("NUMREG"); + + // Scarto SEMPRE i provvisori + TString16 provvis = recmov.get(MOV_PROVVIS); + if (provvis.trim().not_empty()) + return FALSE; + + // In caso di NO libro con iva scarta quelli che non hanno righe contabili + if (!app()._libro_giornale_iva_unico) + { + recrmov.zero(); + recrmov.put("NUMREG", (long)numreg); + // TRectype cfr(r->lfile(LF_RMOV).curr()); + if (r->lfile(LF_RMOV).read()) + { + const long numreg2 = recrmov.get_long("NUMREG"); + if (numreg2 != numreg) + return FALSE; + else + return TRUE; + } + } + return TRUE; +} + + +////////////////////////////////////////////////////////////////////////// +// Funzioni legate ai parametri ditta +////////////////////////////////////////////////////////////////////////// +HIDDEN bool libro_giornale_iva_unico() +{ + TConfig conf(CONFIG_DITTA); + return conf.get_bool("StLgiU"); +} + +HIDDEN bool libro_cronologico() +{ + TConfig conf(CONFIG_DITTA); + return conf.get_bool("GsLbCn"); +} + +TRectype& CG3400_application::look_com (const char * cod) +{ + _com->zero(); + _com->put(COM_COM, cod); + if (_com->read() != NOERR) + _com->zero(); + + return _com->curr(); +} + +const char * CG3400_application::get_descr_caus (const char * codcaus) +{ + TLocalisamfile& caus = *_causali; + + caus.zero(); + caus.put (CAU_CODCAUS, codcaus); + if (caus.read() != NOERR) caus.zero(); + + tmp = caus.get(CAU_DESCR); + return tmp; +} + +void CG3400_application::get_dati_ditta () +{ + TString16 codanagr; + char 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_char(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); + _comunefis = _anag->get(ANA_COMRF); + + if (_comunefis.empty()) + _comunefis = _anag->get(ANF_COMRES); + + TRectype dep = look_com (_comunefis); + + _comunefis = dep.get(COM_DENCOM); + _provfis = dep.get(COM_PROVCOM); + _cap = dep.get(COM_CAPCOM); + + if (_comunefis.empty()) + { + _viafis = _anag->get(ANA_INDRF); + _viafis.rtrim(); + _viafis << " " << _anag->curr().get (ANA_CIVRF); + } + else + { + _viafis = _anag->get(ANA_INDRES); + _viafis.rtrim(); + _viafis << " " << _anag->get (ANA_CIVRES); + } +} + +bool CG3400_application::user_create() +{ + _ae = 0; + _tabreg = new TTable ("REG"); + _tabval = new TTable ("%VAL"); + _tabes = new TTable ("ESC"); + _tabiva = new TTable ("%IVA"); + + _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); + _causali = new TLocalisamfile(LF_CAUSALI); + _attiv = new TLocalisamfile(LF_ATTIV); // da togliere + + _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: DATAREG+NUMREG + + _RecPartoDa = new TRectype(_cur->file(LF_MOV).curr()); + _RecArrivoA = new TRectype(_cur->file(LF_MOV).curr()); + + add_cursor (_cur); + + add_file (LF_MOV); + add_file (LF_RMOV); + add_file (LF_RMOVIVA); + return TRUE; +} + +bool CG3400_application::user_destroy() +{ + delete _rel; + delete _cur; + delete _RecPartoDa; + delete _RecArrivoA; + + delete _com; delete _clifo; delete _causali; delete _pconti; + delete _nditte; delete _anag; + delete _tabreg; delete _tabes; delete _tabval; delete _tabiva; + + delete _attiv; // da togliere in futuro + + delete _nditte; + delete _anag; + return TRUE; +} + +void CG3400_application::aggiorna_mov() +{ + TLocalisamfile& mov = _cur->file(LF_MOV); + long nprog = _nprog_da + 1; + + const TRectype da(*_RecPartoDa); + const TRectype a(*_RecArrivoA); + _cur->setregion(da, a); + (*_cur) = 0L; + +#ifndef DBG + TProgind prnd (_cur->items(), "Aggiornamento movimenti ...", FALSE, TRUE); +#endif + // for (mov.read(_isgteq, _lock); mov.curr() < *_RecArrivoA && !mov.eof(); mov.next(_lock)) + + for ( ; _cur->pos() < _cur->items(); ++(*_cur)) + { +#ifdef DBG + long numreg = _cur->file(LF_MOV).get_long("NUMREG"); + TString datareg(_cur->file(LF_MOV).get("DATAREG")); + + message_box("Numreg: %ld Datareg: %s", numreg, (const char*)datareg); +#endif + const bool gia_stampato = _cur->file(LF_MOV).get_bool(MOV_STAMPATO); + if (!gia_stampato) + { + _cur->file(LF_MOV).put (MOV_STAMPATO, TRUE); + _cur->file(LF_MOV).put (MOV_NUMGIO, nprog); + mov.rewrite(); + nprog++; + } + // else mov.reread(_unlock); +#ifndef DBG + prnd.addstatus(1); +#endif + } + // mov.reread(_unlock); +} + +int CG3400_application::set_totali_giorno(const TDate& data, const int righeiva) +{ + int r; + char dep[200]; + const int SHIFT = 15; + const int STACC = 51 + SHIFT; + + r = righeiva == 0 ? 1 : righeiva; + + // Se e' l'unico totale lo stampo anche se e' zero + if (competenza_ec() || (_tot_avere_gg != ZERO || _tot_dare_gg != ZERO)) + { + TString td(_tot_dare_gg.string(REAL_PICTURE)); + TString ta(_tot_avere_gg.string(REAL_PICTURE)); + + sprintf(dep, "@b@%dgTotale operazioni del %s @%dg%c %s @%dg%c @%dg%s", + _stampa_width == 132 ? DARE132-STACC : DARE198-STACC, + data.string(), + _stampa_width == 132 ? DARE132-3 : DARE198-2, + 'D', + (const char*)td, + _stampa_width == 132 ? DARE132+16 : DARE198+20, + 'A', + _stampa_width == 132 ? AVERE132 : AVERE198, + (const char*)ta + ); + + set_row (r++, "%s", dep); + _tot_dare_gg = _tot_avere_gg = ZERO; + } + + if (competenza_ep() || (_tot_avere_gg_ap != ZERO || _tot_dare_gg_ap != ZERO)) + { + TString tdp(_tot_dare_gg_ap.string(REAL_PICTURE)); + TString tap(_tot_avere_gg_ap.string(REAL_PICTURE)); + + sprintf (dep, "@b@%dgTotale operazioni del %s Anno precedente @%dg%c %s @%dg%c @%dg%s", + _stampa_width == 132 ? DARE132-STACC : DARE198-STACC, + data.string(), + _stampa_width == 132 ? DARE132-3 : DARE198-2, + 'D', + (const char*)tdp, + _stampa_width == 132 ? DARE132+16 : DARE198+20, + 'A', + _stampa_width == 132 ? AVERE132 : AVERE198, + (const char*)tap + ); + + set_row (r++, "%s", dep); + + _tot_avere_gg_ap = _tot_dare_gg_ap = ZERO; + } + return r; +} + + +void CG3400_application::postclose_print() +{ + if (_stampa_definitiva) + { + const int ultima_fatta = printer().getcurrentpage() - 1; + + if (yesno_box("La stampa e' corretta ?")) + { + aggiorna_mov (); + aggiorna_tabreg (_pagina_da, ultima_fatta); + } + } +} + + +void CG3400_application::preprocess_footer() +{ + TString progr_dare_ap(22), progr_avere_ap(22); + TString progr_dare, progr_avere, dts, ats; + TString256 riga; + bool ap = FALSE; + int r=2; + const int STUMB = 42; + real dt, at; + + reset_footer(); + + if (_tot_avere_progr_ap != ZERO || _tot_dare_progr_ap != ZERO) + { + progr_dare_ap = _tot_dare_progr_ap.string(REAL_PICTURE); + progr_avere_ap = _tot_avere_progr_ap.string(REAL_PICTURE); + ap = TRUE; + } + + // + // Non stampo "A riportare" + // SE : + // 1. E' gia' stato stampato + // OPPURE + // 2. Sono sull'ultima riga + // + + const bool riporta = _forza_ariportare || + (!_gia_settato_ariportare && _cur->pos() < _cur->items()-1); + + if (riporta) + { + dt = _tot_dare_progr + _tot_dare_progr_ap; + at = _tot_avere_progr + _tot_avere_progr_ap; + dts = dt.string(REAL_PICTURE); + ats = at.string(REAL_PICTURE); + + riga.format ("@b@%dg%s@%dg%c %s @%dg%c @%dg%s", + _stampa_width == 132 ? DARE132-STUMB : DARE198-STUMB, + (_nuovo_mese && !_forza_ariportare) ? "Totale progressivi generali " : "A riportare ", + _stampa_width == 132 ? DARE132-3 : DARE198, + 'D', + (const char *) dts, + _stampa_width == 132 ? DARE132+16 : DARE198+20, + 'A', + _stampa_width == 132 ? AVERE132 : AVERE198, + (const char *) ats); + set_footer (r++, (const char*) riga); + + _forza_ariportare = FALSE; + } +} + + +int CG3400_application::set_totali_pagina(int righe) +{ + TString progr_dare_ap(22), progr_avere_ap(22); + TString progr_dare, progr_avere, dts, ats; + TString256 riga; + bool ap = FALSE; + const int SHIFT = 15; + const int STUMB = 51 + SHIFT; + real dt, at; + int r = righe == 0 ? 1 : righe; + // reset_footer(); + + if (_tot_avere_progr_ap != ZERO || _tot_dare_progr_ap != ZERO) + { + progr_dare_ap = _tot_dare_progr_ap.string(REAL_PICTURE); + progr_avere_ap = _tot_avere_progr_ap.string(REAL_PICTURE); + ap = TRUE; + } + + // SONO SULL'ULTIMO ???????????? SI O NO ???????????? + // if (_cur->pos() >= _cur->items()-1) // se sono sull'ultimo + if (_cur->pos() == _cur->items()-1) // se sono sull'ultimo + { + // I totali distinti tra anno precedente e corrente SOLO SE STAMPA DI PROVA + if (!_stampa_definitiva) + { + progr_dare = _tot_dare_progr.string(REAL_PICTURE); + progr_avere = _tot_avere_progr.string(REAL_PICTURE); + riga = ""; + riga.format("@b@%dgTotale progressivi @%dg%c %s @%dg%c @%dg%s", + _stampa_width == 132 ? DARE132-STUMB : DARE198-STUMB, + _stampa_width == 132 ? DARE132-3 : DARE198-2, + 'D', + (const char *) progr_dare, + _stampa_width == 132 ? DARE132+16 : DARE198+20, + 'A', + _stampa_width == 132 ? AVERE132 : AVERE198, + (const char *) progr_avere + ); + + set_row (r++, (const char*) riga); + + if (ap) + { + riga.format("@b@%dgTotale progressivi anno precedente @%dg%c %s @%dg%c @%dg%s", + _stampa_width == 132 ? DARE132-STUMB : DARE198-STUMB, + _stampa_width == 132 ? DARE132-3 : DARE198-2, + 'D', + (const char *) progr_dare_ap, + _stampa_width == 132 ? DARE132+16 : DARE198+20, + 'A', + _stampa_width == 132 ? AVERE132 : AVERE198, + (const char *) progr_avere_ap + ); + set_row (r++, (const char*) riga); + } + } // !stampa_definitiva + + _tot_dare_generale = _tot_dare_progr + _tot_dare_progr_ap; + _tot_avere_generale = _tot_avere_progr + _tot_avere_progr_ap; + dts = _tot_dare_generale.string(REAL_PICTURE); + ats = _tot_avere_generale.string(REAL_PICTURE); + + riga.format("@b@%dgTotale progressivi generali @%dg%c %s @%dg%c @%dg%s", + _stampa_width == 132 ? DARE132-STUMB : DARE198-STUMB, + _stampa_width == 132 ? DARE132-3 : DARE198-2, + 'D', + (const char *) dts, + _stampa_width == 132 ? DARE132+16 : DARE198+20, + 'A', + _stampa_width == 132 ? AVERE132 : AVERE198, + (const char *) ats + ); + + set_row (r++, (const char*) riga); + } + else // Non ancora totale generale + { + // Se il movimento ha righe che continuano nella pagina successiva + // "A riportare" viene stampato dalla preprocess_footer senno' qui + + _gia_settato_ariportare = TRUE; + + dt = _tot_dare_progr + _tot_dare_progr_ap; + at = _tot_avere_progr + _tot_avere_progr_ap; + dts = dt.string(REAL_PICTURE); + ats = at.string(REAL_PICTURE); + + // "Se il mese e' finito devo scrivere Totale progressivi generali + // invece che A riportare" + + riga.format ("@b@%dgTotale progressivi generali @%dg%c %s @%dg%c @%dg%s", + _stampa_width == 132 ? DARE132-STUMB : DARE198-STUMB, + _stampa_width == 132 ? DARE132-3 : DARE198-2, + 'D', + (const char *) dts, + _stampa_width == 132 ? DARE132+16 : DARE198+20, + 'A', + _stampa_width == 132 ? AVERE132 : AVERE198, + (const char *) ats); + set_row (r++, (const char*) riga); + } + return r; +} + +int CG3400_application::stampa_intestazione_ditta() +{ + int r=1; + TString256 intes; + TString riga(_stampa_width); + + get_dati_ditta(); + + riga.fill('-'); + set_header(r, riga); + + set_header (++r, "Ditta: %5ld %-.50s %.35s %.5s %.20s %.2s", + get_firm(), + (const char *)_ragsoc, + (const char *)_viafis, (const char *)_cap, + (const char *)_comunefis, (const char *)_provfis); + + if (_stampa_definitiva) + intes.format ("Partita iva %s @24gCodice fiscale %s", + (const char*)_paiva, (const char*)_cofi, + _stampa_width == 132 ? 102 : 168 + ); + else + intes.format ("Partita iva %s @24gCodice fiscale %s @%dg%s @%dgData @>", + (const char*)_paiva, (const char*)_cofi, + _stampa_width == 132 ? 102 : 168, + "LIBRO DI PROVA", + _stampa_width == 132 ? 117 : 183 + ); + + set_header (++r, "%s", (const char*)intes); + r++; + return r; +} + +int CG3400_application::set_headers() +{ + int r=1; + TString riga(_stampa_width); + TString16 data_da = _data_da.string(); + TString16 data_a = _data_a.string(); + + if (_stampa_intesta || !_stampa_definitiva) + r = stampa_intestazione_ditta(); + + if (_stampa_definitiva) + set_header(r++, "Codice libro: %s %s ",(const char *) _reg_cod, (const char *) _reg_descr); + else + set_header(r++, "Codice libro: %s %s @%dgdalla data: %s alla data: %s @%dgEsercizio: %04d", + (const char *) _reg_cod, (const char *) _reg_descr, + _stampa_width == 132 ? 69 : 135, + (const char *) data_da, (const char *) data_a, + _stampa_width == 132 ? 117 : 183, + _ae + ); + + riga.fill('-'); + set_header(r++, riga); + + if (_libro_cronologico) + set_header(r, "@59gCodice Conto"); + + if (!_stampa_definitiva) { + if (_stampa_width == 132) { + set_header(r++, "@131gS"); + set_header(r, "@1gN.riga"); + } + else { + set_header(r++, "@197gS"); + set_header(r, "@1gN.riga"); + } + } + else + if (_libro_cronologico) r++; // NON LASCIARE RIGHE IN BIANCO!! + + // set_header(r, "@6gCod.Causale@34gDescrizione operazione"); + set_header(r, "@8gDescrizione operazione@36gCausale"); + if (_libro_cronologico) + // POSCONTO = 74; + set_header(r, "@74gGeneralita' cliente/fornitore"); + else + set_header(r, "@59gCodice Conto"); + + if (_stampa_width == 132) + set_header(r, "@120gImporto"); + else + set_header(r, "@161gDare @184gAvere"); + + if (!_stampa_definitiva) + set_header(r, _stampa_width == 132 ? "@131gB" : "@197gB"); + + r++; + + riga.fill('-'); + set_header(r, riga); + + return r; +} + +void CG3400_application::preprocess_header() +{ + int r = _last_header + 1; + int pag = printer().getcurrentpage(); + TString256 riporto; + real riporto_dare, riporto_avere; + + _gia_settato_ariportare = FALSE; + + if (pag > 0) // Stampa riporti + { + riporto_dare = _tot_dare_progr + _tot_dare_progr_ap; + riporto_avere = _tot_avere_progr + _tot_avere_progr_ap; + + // Non stampa nulla se ZERO SOLO SE DI PROVA <<<<<--------------------- + // Lascio una riga senno' vado a finire sull'intestazione + if (!_stampa_definitiva) + if (riporto_dare == ZERO && riporto_avere == ZERO) + { + set_header (r, ""); + return; + } + + TString dare (riporto_dare.string(REAL_PICTURE)); + TString avere(riporto_avere.string(REAL_PICTURE)); + + riporto.format("@b@%dgRiporto: %c @%dg%15s %c@%dg%15s", + _stampa_width == 132 ? 83 : DARE198-11, + _stampa_width == 132 ? 'D' : ' ', + _stampa_width == 132 ? DARE132-1 : DARE198, + (const char *) dare, + _stampa_width == 132 ? 'A' : ' ', + _stampa_width == 132 ? AVERE132 : AVERE198, + (const char *) avere + ); + + set_header (r++, "%s", (const char *) riporto); + } +} + +// +// 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) +{ + switch (file) + { + case LF_MOV: + _nuovo_mese = FALSE; + _iva_array.destroy(); + _nprog_mov = _nprog_da; + *_RecPartoDa = _cur->file(LF_MOV).curr(); + break; + default: + break; + } + return TRUE; +} + +/*** + bool CG3400_application::cancel_hook() + { + int ultima_fatta = printer().getcurrentpage() - 1; + // int stampate = ultima_fatta - _pagina_da + 1; + + if (yesno_box ("Interrompo la stampa ?")) + { + if (_stampa_definitiva) + aggiorna_tabreg (ultima_fatta, ultima_fatta); + return TRUE; + } + else + return FALSE; + } + ***/ + +void CG3400_application::fill_page(int riga) +{ + TString256 rigas; + // char frm[4]; + int r_l = printer().rows_left() - 2; // Tolgo le 2 righe del totale + if (r_l < 0) + { + r_l += printer().formlen() - 8; // Tolgo la testata + _forza_ariportare = TRUE; + } + + // Se sono rimaste righe da riempire + if (r_l > 0) + { + rigas.fill('=', _stampa_width); + rigas.cut(_stampa_width+1); + // sprintf(frm, "%%%3ds", _stampa_width); + set_row(riga++, "%s", (const char*) rigas); + // rigas = ""; + // if (--r_l) + // { + // int j=0; + // Calcola una specie di coefficiente angolare + // int alfa = _stampa_width / r_l; + // for (int i = riga+1; i < r_l; i++, j++) + // { + // if (j*alfa >= _stampa_width-alfa) break; // non uscire dai margini + // rigas.format("@%dg======", j*alfa); + // set_row(i, "%s", (const char*)rigas); + // } + // } + int j=0; + // Calcola una specie di coefficiente angolare + int alfa = (_stampa_width - 6) / r_l; + + for ( ; r_l > 1; r_l--) // Non stampare sulla riga orizzontale! + { + rigas.format("@%dg======", j); + set_row(riga++, rigas); + j += alfa; + } + } +} + +print_action CG3400_application::postprocess_page(int file, int counter) +{ + int righe_iva_settate=0; + bool FINITO = FALSE; + + if (counter) + { + if (_nuovo_mese) { + printer().formfeed(); + _nuovo_mese = FALSE; + } + return NEXT_PAGE; + } + + switch (file) + { + case LF_MOV: + + reset_print(); + + if (_libro_giornale_iva_unico) + { + righe_iva_settate = setta_righe_iva(); + righe_iva_settate = setta_righe_valuta(righe_iva_settate); + } + + _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 || _cur->pos() == _cur->items()-1) + { + _nuovo_mese = (_mese_succ != _mese_corr); + int righe = set_totali_giorno(_data_corr, righe_iva_settate); + if (_nuovo_mese) + { + righe = set_totali_pagina(righe); + // Nella stampa su bollato metto un segno su tutte le righe + if (_stampa_definitiva) + fill_page(righe); + } + return REPEAT_PAGE; + } + + if (righe_iva_settate > 0) + return REPEAT_PAGE; + + break; + + case LF_RMOV: + // Sposto qui per evitare di aggiornare i progressivi con una riga della + // pagina dopo + update_totals(_sezione, _importo); + break; + default: + break; + } + return NEXT_PAGE; +} + +void CG3400_application::update_totals (char sezione, real& importo) +{ +#ifdef DBG + TString dgap(_tot_dare_gg_ap.string()); + TString dgpp(_tot_dare_progr_ap.string()); + TString dgac(_tot_dare_gg.string()); + TString dgpc(_tot_dare_progr.string()); + TString agap(_tot_avere_gg_ap.string()); + TString agpp(_tot_avere_progr_ap.string()); + TString agac(_tot_avere_gg.string()); + TString agpc(_tot_avere_progr.string()); +#endif + + if (sezione == 'D') + { + if (_annoEsMov != _ae) { + _tot_dare_gg_ap += importo; // prog. anno precedente + _tot_dare_progr_ap += importo; + } + else { + _tot_dare_gg += importo; // prog. giornalieri + _tot_dare_progr += importo; // prog. generali + } + } + else + { + if (_annoEsMov != _ae) { + _tot_avere_gg_ap += importo; + _tot_avere_progr_ap += importo; + } + else { + _tot_avere_gg += importo; + _tot_avere_progr += importo; + } + } +#ifdef DBG + dgap = _tot_dare_gg_ap.string(); + dgpp = _tot_dare_progr_ap.string(); + dgac = _tot_dare_gg.string(); + dgpc = _tot_dare_progr.string(); + agap = _tot_avere_gg_ap.string(); + agpp = _tot_avere_progr_ap.string(); + agac = _tot_avere_gg.string(); + agpc = _tot_avere_progr.string(); +#endif +} + + + +void CG3400_application::set_rows (int file, int counter) +{ + TString16 datadoc_str, datareg_str, numdoc, frm, caus; + TDate datadoc, datareg; + TString80 mov_descr, rmv_descr; + TParagraph_string descr_conto("", 50); + TContoOccas tc; + long numreg, protiva; + int r = 1; + int g, c; + long s; + static char cf = ' '; + static int rdes = 1; + + switch (file) + { + case LF_MOV: + reset_row(1); + reset_row(2); + + datareg = _cur->file(LF_MOV).get_date("DATAREG"); + datadoc = _cur->file(LF_MOV).get_date("DATADOC"); + datareg_str = datareg.string(); + // "Fai vedere lo stesso ..-..-.... anche se non c'e' la data..." + if (datareg_str.empty()) + datareg_str = " - - "; + datadoc_str = datadoc.string(); + if (datadoc_str.empty()) + datadoc_str = " - - "; + numdoc = _cur->file(LF_MOV).get("NUMDOC"); + numreg = _cur->file(LF_MOV).get_long("NUMREG"); + mov_descr = _cur->file(LF_MOV).get("DESCR"); + + // Usati in setta_righe_iva per determinare tipo attivita' + _reg = _cur->file(LF_MOV).get(MOV_REG); + _anno_iva = _cur->file(LF_MOV).get_int(MOV_ANNOIVA); + /////////////////////////////////////////////////////////// + + protiva = _cur->file(LF_MOV).get_long(MOV_PROTIVA); + caus = _cur->file(LF_MOV).get(MOV_CODCAUS); + _occfpi = _cur->file(LF_MOV).get(MOV_OCFPI); + _annoEsMov = _cur->file(LF_MOV).get_int(MOV_ANNOES); + _MovGiaStampato = _cur->file(LF_MOV).get_bool(MOV_STAMPATO); + + if (_stampa_definitiva) + { + set_row(r,"Operazione n. @b%-7ld@r", _nprog_mov); + set_row(r," del @b%s@r", (const char*)datareg_str); // XX/XX/XXXX + set_row(r," doc. n. @b%-7s@r",(const char*)numdoc); + set_row(r," del @b%s@r %-50s",(const char*)datadoc_str, + (const char*)mov_descr); + } + else + { + set_row(r,"Operazione n. @b%-7ld@r", numreg); + set_row(r," del @b%s@r", (const char*) datareg_str); + set_row(r," doc. n. @b%-7s@r", (const char*) numdoc); + set_row(r," del @b%s@r %-50s", (const char*)datadoc_str,(const char*)mov_descr); + } + + if (_annoEsMov != _ae) + set_row(r," Comp. %04d", _annoEsMov); + + if (_MovGiaStampato && !_stampa_definitiva) + set_row(r,format("@%dg*",_stampa_width == 132 ? 131 : 197)); + + if (caus.not_empty()) + { + TString80 desc_caus(get_descr_caus(caus)); + set_row(r+1, "@36gCausale %3s %-50s", (const char*) caus, (const char*) desc_caus); + if (_reg.not_empty()) + set_row(r+1, " (R.IVA @b%3s@r Prot. @b%ld@r) ", (const char*)_reg,protiva); + } + + break; + + case LF_RMOV: + + _num_rig++; + + reset_print(); + + g = _cur->file(LF_RMOV).get_int("GRUPPO"); + c = _cur->file(LF_RMOV).get_int("CONTO"); + s = _cur->file(LF_RMOV).get_long("SOTTOCONTO"); + cf = _cur->file(LF_RMOV).get_char(RMV_TIPOC); + + if (cf != 'C' && cf != 'F') + cf = ' '; + + numreg = _cur->file(LF_RMOV).get_long("NUMREG"); + datareg = _cur->file(LF_RMOV).get("DATAREG"); + + _sezione = _cur->file(LF_RMOV).get_char (RMV_SEZIONE); + _importo = _cur->file(LF_RMOV).get_real (RMV_IMPORTO); + + rmv_descr = _cur->file(LF_RMOV).get(RMV_DESCR); + + r=1; + + // Num. progressivo di operazione. Azzerato in preprocess_page + if (!_stampa_definitiva) set_row (r, "%7ld", _num_rig); + + set_row (r, "@8g%-50s", (const char*) rmv_descr); + + set_row (r, "@59g%03d.", g); + if (c != 0) + set_row (r, "%03d.", c); + if (s != 0L) + set_row (r, "%06ld", s); + + tc.set(g,c,s,cf,NULL,-1,_occfpi); + + if (_stampa_width == 132) + descr_conto.set_width (WCONTO132); + else // se a 198 non spezzo le descrizioni + descr_conto.set_width(198); + + descr_conto = tc.descrizione(); + + if (_stampa_width == 132) + rdes = setta_righe_descr (descr_conto, conto); + else + { + rdes = 2; + frm.format("@%dg%%-%ds", POSCONTO,50); + set_row (r, frm, (const char*) descr_conto); + } + + if (cf > ' ') + if (_libro_cronologico) + rdes = setta_righe_indirizzo(cf, s, rdes); + + // NB Totali aggiornati in postprocess_page (update_totals()) + + if (_stampa_width == 132) + { + set_row (r, "@112g%r", &_importo); + set_row (r, "@128g%c", _sezione); + } + else // stampa_width == 198 + set_row (r, _sezione == 'D' ? "@150g%r" : "@174g%r", &_importo); + + if (_MovGiaStampato && !_stampa_definitiva) + set_row(r,format("@%dg*",_stampa_width == 132 ? 131 : 197)); + + break; + + default: + break; + } +} + +// +// PREPROCESS_PAGE +// +// Non scarto nulla qui, non si deve mai vedere una stampa vuota +// +bool CG3400_application::preprocess_page(int file, int counter) +{ + if (counter) return TRUE; + + switch (file) { + + case LF_MOV: + + _annoEsMov = _anno_iva = 0; + _iva_array.destroy(); + + *_RecArrivoA = _cur->file(LF_MOV).curr(); + + _nprog_mov++; + // Il numero di operazione deve ripartire da 0 per ogni movimento + _num_rig = 0; + + _data_corr = _cur->file(LF_MOV).get_date(MOV_DATAREG); + + // _ultima_data_mov finisce sul registro come ultima data di stampa + if (_data_corr > _ultima_data_mov) _ultima_data_mov = _data_corr; + + _mese_corr = _data_corr.month(); + + break; + + case LF_RMOV: + break; + + case LF_RMOVIVA: + if (_libro_giornale_iva_unico) calcola_iva (); + break; + + default: + break; + } + set_rows (file, counter); + return TRUE; +} + +void CG3400_application::calcola_iva() +{ + TString codiva; + int tipocr, tipodet, tipoatt; + real impo, impos; + bool intra; + 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); + tipoatt = iva.get_int ("TIPOATT"); + codiva = iva.get (RMI_CODIVA); + intra = iva.get_bool (RMI_INTRA); + _iva_array.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,0,intra,tipoatt); + } +} + +int CG3400_application::setta_righe_descr(TParagraph_string& str, enum descr des) +{ + int i = 1; + TString16 frm; + const char* r; + // char descr[51]; + TString80 descr; + + switch (des) + { + case causale: // lunga 20 + if (_libro_giornale_iva_unico) + frm.format("@10g\0x25%ds", _stampa_width == 132 ? WCAUS132 : 40); + else + frm.format("@48g%%d", WCAUS132); + break; + case conto: // lunga 21 + // if (_libro_giornale_iva_unico) + frm.format("@%dg%%-%ds", POSCONTO,WCONTO132); + /* + else + frm.format("@26g%%d", POSCONTO,WCONTO132); */ + break; + case operazione: // lunga 28 + if (_libro_giornale_iva_unico) + frm.format("@31g%%d", WOPER132); + else + frm.format("@69g%%d", WOPER132); + break; + default: + break; + } + while ((r = str.get()) != NULL) + { + descr = r; + descr.ltrim(); + set_row (i++, (const char*)frm, (const char*)descr); + } + + return i; +} + +const char* CG3400_application::get_codiva_des(const char* codiva) +{ + _tabiva->zero(); + _tabiva->put("CODTAB", codiva); + if (_tabiva->read() == NOERR) + return _tabiva->get("S0"); + else + return NULL; +} + +// NB +// Questa funzione ritorna il numero di righe che ha settato. +// Se questo e' diverso da 0 viene fatta una REPEAT_PAGE +// Attenzione quindi se si modifica la variabile r +int CG3400_application::setta_righe_iva() +{ + int r=0, j; + TString80 rig; + + for (j = 0; j < _iva_array.items(); j++) + { + TRigaiva& riga = (TRigaiva&)_iva_array[j]; + r = j+1; + set_row(r, " Imponibile@15g%r", &riga._imponibile); + set_row(r, "@31gImposta@39g%r", &riga._imposta); + // set_row(r, "@58gCod.Iva@68g%3s", (const char*)riga._codiva); + set_row(r, "@56gCod.Iva %3s", (const char*)riga._codiva); + const TString80 codiva_des(get_codiva_des(riga._codiva)); + const int tipoatt = riga._tipoatt; + if (_stampa_width == 132) + set_row(r, "@68g%-.17s", (const char*)codiva_des); + else + set_row(r, "@68g%-.50s", (const char*)codiva_des); + const int S132 = 89; + const int S198 = 119; + rig.format("@%dg", _stampa_width == 132 ? S132 : S198); + switch (riga._tipodet) + { + case 0 : + rig << "Detraibile "; + break; + case 1 : + rig << "Indetraibile su op.es. "; + break; + case 3 : + rig << "Passaggi interni "; + break; + case 9 : + rig << "Indetraibile art.19 "; + break; + default: break; + } + set_row(r, (const char*)rig); + + TRegistro reg(_reg, _anno_iva); + const bool att_mista_ev = reg.attivita_mista(); + if (tipoatt != 0 && att_mista_ev) + set_row(r, " Tipo attivita' %d", tipoatt); + } + _iva_array.destroy(); + return r; +} + +int CG3400_application::setta_righe_valuta(int riga) +{ + TString16 codvali; + real corrval; + int r = riga+1; + + corrval = current_cursor()->file(LF_MOV).get_real(MOV_CORRVALUTA); + + if (corrval != ZERO) + { + codvali = current_cursor()->file(LF_MOV).get(MOV_CODVALI); + TString valut(corrval.string("###.###.###.###,@@")); + + set_row(r,"@56gValuta %3s", (const char*)codvali); + if (_stampa_width == 132) + set_row(r++,"@89gCorr.in valuta @109g%s", (const char*)valut); + else + set_row(r++,"@119gCorr.in valuta @171g%s", (const char*)valut); + } + return r; +} + +// Cerca l'indirizzo del C/F. +// Legge CLIFO o OCCAS a seconda di _occas +// Setta le righe 2 e 3 che vengono poi resettate al record successivo +int CG3400_application::setta_righe_indirizzo(char tipocf, long codcf,int rdes) +{ + TString16 prov, comcf, capcf, civcf, statocf; + TString80 viacf, comune; + bool really_occas = FALSE; + char tipoa; + long codanagr; + char riga[256]; + int r = rdes; + + _clifo->zero(); + _clifo->put(CLI_CODCF, codcf); + _clifo->put(CLI_TIPOCF, tipocf); + + const bool clifo_ok = (_clifo->read() == NOERR); + + if (clifo_ok) really_occas = _clifo->get_bool(CLI_OCCAS); + + if (_occfpi.not_empty() && really_occas) // => e' un occasionale... + { + TLocalisamfile occ(LF_OCCAS); + + occ.zero(); + occ.put(OCC_CFPI, _occfpi); + if (occ.read() != NOERR) occ.zero(); + + viacf = occ.get (OCC_INDIR); + civcf = occ.get (OCC_CIV); + capcf = occ.get (OCC_CAP); + comcf = occ.get (OCC_COM); + } +else +{ + // E' possibile cio' ? + if (!clifo_ok) return r; + + 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); + tipoa = _clifo->get_char(CLI_TIPOAPER); + codanagr = _clifo->get_long(CLI_CODANAGPER); +} + +TRectype rec = look_com (comcf); +comune = rec.get(COM_DENCOM); +prov = rec.get(COM_PROVCOM); + +if (viacf.not_empty()) +{ + sprintf (riga, "@%dg%s %s", + POSCONTO, + (const char*) viacf, + (const char*) civcf + ); + + set_row (r++, riga); +} + +if (comune.not_empty() || prov.not_empty() || capcf.not_empty()) +{ + sprintf (riga, "@%dg%s %s %s", + POSCONTO, + (const char*) capcf, (const char*) comune, + (const char*) prov + ); + set_row (r++, riga); +} + +// Se fisica prendo anche data nascita e luogo +if (tipoa == 'F') +{ + TString80 comna; + TString16 datana, codcomna, provna, capna, statona; + + datana = _clifo->get("DATANASC"); + + if (datana.not_empty()) + { + codcomna = _clifo->get("COMNASC"); + TRectype dep = look_com (codcomna); + + comna = dep.get(COM_DENCOM); + provna = dep.get(COM_PROVCOM); + capna = dep.get(COM_CAPCOM); + + statona = dep.get("STATO"); + + sprintf (riga, "@%dg%s %s %s %s", POSCONTO, + (const char*)datana, + (const char*)comna, + (const char*)provna, (const char*) capna); + + set_row(r++, riga); + } +} +return r; +} + +// +// Lettura/aggiornamento tabella registri +// +void CG3400_application::aggiorna_tabreg(int partito_da, int stampate) +{ + TString16 codtab; + + codtab.format ("%04d%-3s", _ae, (const char*) _reg_cod); + + _tabreg->zero(); + _tabreg->put("CODTAB", codtab); + _tabreg->read(); + + if (_tabreg->good()) + { + // _tabreg->put ("I8", (long)partito_da); // partito_da = -1 se stampa OK + _tabreg->put ("I1", (long)_pagine_stampate + stampate); // pagine stampate + _tabreg->put ("I6", _nprog_mov); // ultimo numero di riga + _tabreg->put ("R1", _tot_dare_generale); + _tabreg->put ("R2", _tot_avere_generale); + _tabreg->put ("D3", _ultima_data_mov); // Data piu' alta trovata + _tabreg->rewrite(); + } +} + +void CG3400_application::get_date_aep(int aep, TDate* in, TDate* fin) +{ + TTable esc("ESC"); + + esc.zero(); esc.put("CODTAB", format("%04d",aep)); + if (esc.read() == NOERR) + { + *in = esc.get_date("D0"); + *fin = esc.get_date("D1"); + } +} + +const int es_prec(const int es_corr) +{ + TTable ese("ESC"); + TString16 first; + TString codtab; + + ese.first(); + first = ese.get("CODTAB"); + + codtab.format("%04d",es_corr); + + if (codtab == first) + return 0; + + return es_corr - 1; +} + +bool CG3400_application::controlla_mov_aep() +{ + const int aep = es_prec(_ae); + bool gia_stampati = TRUE; + TDate inizio_ep, fine_ep; + + if (aep == 0) // = e' il primo esercizio + return TRUE; +else + get_date_aep(aep,&inizio_ep, &fine_ep); + +#ifdef DBG + TString instr(inizio_ep.string()); + TString finstr(fine_ep.string()); +#endif + + TRectype da (_cur->file(LF_MOV).curr()); + TRectype a (_cur->file(LF_MOV).curr()); + + da.zero(); a.zero(); + da.put(MOV_DATAREG, inizio_ep); + a.put (MOV_DATAREG, fine_ep); + + _cur->setregion(da, a); + _cur->set_filterfunction(filter_func); + // _cur->setfilter(format("ANNOES=%04d && STAMPATO!=\"X\"", aep)); + + (*_cur) = 0L; + for ( ; _cur->pos() < _cur->items(); ++(*_cur)) + { +#ifdef DBG + TString datareg(_cur->file().get("DATAREG")); + TString numreg(_cur->file().get("NUMREG")); +#endif + gia_stampati = _cur->file().get_bool("STAMPATO"); + if (!gia_stampati) break; // basta trovarne uno ancora da stampare + } + + if (_cur->items() > 0L && !gia_stampati) + { + _cur->setfilter(""); + warning_box("Impossibile proseguire nella stampa.\nEsistono movimenti nell'esercizio precedente non ancora stampati su bollato"); + return FALSE; + } + _cur->setfilter(""); + return TRUE; +} + +bool CG3400_application::leggi_tabreg(const char * reg_cod, int reg_anno) +{ + TString16 codtab; + + _ae = reg_anno; + + codtab.format ("%04d%-3s", reg_anno, reg_cod); + + _tabreg->zero(); + _tabreg->put("CODTAB", codtab); + const bool ok = (_tabreg->read() == NOERR); + + if (!ok) _tabreg->zero(); + + _pagine_stampate = _tabreg->get_int("I1"); + _pagine_numerate = _tabreg->get_int("I2"); + // _stampa_ok = _tabreg->get_int("I8"); + _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"); + _stampa_stesso_registro = _tabreg->get_bool ("B8"); + _reg_descr = _tabreg->get ("S0"); + _tipo = _tabreg->get_int("I0"); + + return ok; +} + +// Calcola l'anno di esercizio di una data +// Certified 99% +HIDDEN int date2esc(const TDate& d, int* prevesc) +{ + if (prevesc) *prevesc = 0; + TTable esc("ESC"); + for (int err = esc.first(); err == NOERR; err = esc.next()) + { + const TDate ia(esc.get("D0")); // Data inizio esercizio + const TDate fa(esc.get("D1")); // Data fine esercizio + app()._inizioEs = ia; + app()._fineEs = fa; + const anno = esc.get_int("CODTAB"); + if (d >= ia && d <= fa) + return anno; + if (prevesc) *prevesc = anno; + } + return 0; +} + +void CG3400_application::set_reg_filter(TMask& m) +{ + TEdit_field& reg = m.efield(CODREG); + reg.browse()->cursor()->set_filterfunction(filtra_reg); +} + +//----------------------------------------------------------------------- +// +// MASCHERE +// +//----------------------------------------------------------------------- + +// NB +// Qui viene compilato app()._ae +// L'anno di esercizio e' determinato da DATA_A +// +bool CG3400_application::data_a_hndl (TMask_field& f, KEY k) +{ + TMask& m = f.mask(); + + if (f.to_check(k)) + { + const TDate data_a(f.get()); + TString16 dep(data_a.string()); + + if (dep.empty()) return TRUE; + + const int ae = date2esc(data_a); // Anno esercizio + + app()._ae = ae; + if (ae == 0) + return f.error_box("La data specificata non appartiene a nessun esercizio"); + else + { + m.set(ANNO_ESER, ae); + m.send_key(K_TAB, CODREG); + } + } + + if (k == K_ENTER) + { + const bool definitiva = m.get_bool(STAMPA_DEF); + const TDate data_da(m.get(DATA_DA)); + const TDate data_a(f.get()); + TString16 dtda(data_da.string()); + const int ae = app()._ae; + const TMask_field& fld_dtda = m.field(DATA_DA); + + if (definitiva) + { + if (dtda.not_empty()) // senno' ci metto inizioEs + { + if (data_da < app()._inizioEs || data_a > app()._fineEs); + return f.warning_box("Le date specificate non appartengono allo stesso esercizio"); + if (data_da > data_a) + return f.warning_box("La data di partenza non puo' essere maggiore della data finale"); + } + } + } // if K_ENTER + + return TRUE; +} + +bool CG3400_application::data_da_hndl(TMask_field& f, KEY k) +{ + TMask& m = f.mask(); + // if (f.to_check(k)) + if (k == K_TAB) + { + const TDate data_da (f.get()); + const TString16 data_a(m.get(DATA_A)); + const int ae_data_da = date2esc(data_da); + const TString16 dep(data_da.string()); + + if (dep.empty() || data_a.empty()) + return TRUE; + + if (app()._ae != 0) + if (app()._ae != ae_data_da) + return f.error_box("Le due date non appartengono allo stesso esercizio"); + } + + if (k == K_ENTER) + { + const bool definitiva = m.get_bool(STAMPA_DEF); + const TDate data_a(m.get(DATA_A)); + const TDate data_da(f.get()); + TString16 dtda(data_da.string()); + + // Controlli sulle date + + // se la stampa e' di prova DALLA_DATA e' obbligatoria + if (!definitiva) + if (dtda.empty()) + return f.warning_box("Manca la data di partenza"); + + if (dtda.not_empty()) + if (data_da > data_a) + return f.warning_box("La data di partenza non puo' essere maggiore della data finale"); + } + return TRUE; +} + +// +// MASK_A_COD_REG +// +// ----------->>>> SCRIVO ANCHE QUI _ae <<<<---------------- +// +bool CG3400_application::mask_a_cod_reg (TMask_field& f, KEY k) +{ + if (f.to_check(k)) + { + TMask& m = f.mask(); + CG3400_application& a = app(); + const bool definitiva = m.get_bool(STAMPA_DEF); + const TString16 data_astr(m.get(DATA_A)); + const TDate data_a(m.get(DATA_A)); + + // 25/11 controlli sul registro solo DOPO aver messo la DATA_A + if (data_astr.empty()) + return TRUE; + else + a._ae = date2esc(data_a); // Anno esercizio + + const TString16 reg_cod(f.get()); + + if (reg_cod.empty()) + { + if (k == K_TAB) // Magari ci ripassa e lo inserisce + return TRUE; + else // Se e' K_ENTER mi serve davvero + return f.error_box("Manca il codice registro"); + } + + bool reg_ok = a.leggi_tabreg(reg_cod, a._ae); + + // Output da qui della descrizione del registro e dell'anno + m.set(REG_DESC, a._reg_descr); + m.set(ANNO_ESER, a._ae); + /* + // CHECKTYPE NORMAL abolito! (nella maschera non ho l'anno... + if (!reg_ok) + return f.warning_box("Registro inesistente"); + + if (app()._tipo != 5) + return f.warning_box("Il registro %s per l'anno %d non e' di tipo libro giornale", + (const char *) reg_cod, a._ae); + */ + } + return TRUE; +} + +// +// mask_b_ripristina +// +// Se premo il bottone rimetto i valori precedenti +// dentro ai campi (per ripetere la stampa) +// +bool CG3400_application::mask_b_ripristina (TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + CG3400_application& a = (CG3400_application&)main_app(); + f.mask().set(PROGR_DARE, a._tot_dare.string()); + f.mask().set(ULTIMA_DATA, a._last_data.string()); + f.mask().set(N_RIGA_STAMPATO, a._nprog_da); + f.mask().set(PAGINA_DA, a._pagine_stampate); + } + return TRUE; +} + +bool CG3400_application::mask_b_warning (TMask_field& f, KEY k) +{ + static bool gia_detto = FALSE; + + if (!gia_detto) + if (k == K_SPACE) + { + f.warning_box("Le modifiche a questi progressivi saranno scritte nel registro"); + gia_detto = TRUE; + return TRUE; + } + + if (k == K_ENTER || k == K_ESC) + gia_detto = FALSE; + + return TRUE; +} + +void CG3400_application::init_print() +{ + // 17.5.95 Leggo parametri di stampa del registro + TString16 config; + const long codditta = get_firm(); + const char* reg = (const char*)_reg_cod; + + config.format("REG%05ld%03s", codditta, reg); + + printer().read_configuration(config); + + if (_stampa_len != 0) + printer().formlen(_stampa_len); + + printer().footerlen(RIGHE_FOOTER); + + reset_print(); + reset_header(); + reset_footer(); + set_background(); + + for (int i=1; ifile(LF_MOV).curr()); + TRectype a (_cur->file(LF_MOV).curr()); + +#ifdef DBG + TString instr(_data_da.string()); + TString finstr(_data_a.string()); +#endif + + da.zero(); a.zero(); + da.put(MOV_DATAREG, _data_da); + a.put (MOV_DATAREG, _data_a); + + _cur->setregion(da, a); + _cur->set_filterfunction(filter_func); + + if (_stampa_definitiva) + _cur->setfilter("STAMPATO!=\"X\""); + + (*_cur) = 0L; + + if (_cur->items() == 0L) + { + _cur->setfilter(""); + return warning_box ("Non ci sono movimenti da stampare nel periodo selezionato.\nLa stampa e' annullata"); + } + + return TRUE; +} + +bool CG3400_application::set_print(int) +{ + TMask ma ("cg3400a"); + KEY tasto; + + ma.set_handler (CODREG, mask_a_cod_reg); + ma.set_handler (DATA_A, data_a_hndl); + ma.set_handler (DATA_DA,data_da_hndl); + // set_reg_filter(ma); + + _pagina_da = 0; // Parto dall'inizio + _forza_ariportare = FALSE; + + while ((tasto = ma.run()) != K_QUIT) + { + _libro_giornale_iva_unico = libro_giornale_iva_unico(); + _libro_cronologico = libro_cronologico(); + + _reg_cod = ma.get(CODREG); + _stampa_definitiva = ma.get_bool(STAMPA_DEF); + _data_da = ma.get(DATA_DA); + _data_a = ma.get(DATA_A); + + _stampa_width = ma.get_int(STAMPA_WIDTH); + _stampa_len = ma.get_int(STAMPA_LEN); + + // Se stampa definitiva DALLA_DATA e' la data di inizio esercizio + // e si scartano i movimenti gia' stampati su bollato + if (_stampa_definitiva) + { + _data_da = _inizioEs; + + // Controlla che non siano rimasti movimenti ancora da stampare dell'es.prec. + if (_stampa_stesso_registro) + if (!controlla_mov_aep()) + continue; + } + + if (!init_cursor()) continue; + + if (_stampa_definitiva) + { + TMask mb("cg3400b"); + mb.set_handler (DLG_RIPRISTINA, mask_b_ripristina); + mb.set_handler (PROGR_DARE, mask_b_warning); + mb.set_handler (N_RIGA_STAMPATO,mask_b_warning); + mb.set_handler (ULTIMA_DATA, mask_b_warning); + mb.set (PROGR_DARE, _tot_dare.string()); + mb.set (N_RIGA_STAMPATO, _nprog_da); + mb.set (ULTIMA_DATA, _last_data.string()); + mb.set (PAGINA_DA, _pagine_stampate); + + tasto = mb.run(); + if (tasto == K_ENTER) + { + real dare2; + _nprog_da = mb.get_long(N_RIGA_STAMPATO); + _last_data = mb.get(ULTIMA_DATA); + dare2 = mb.get_long(PROGR_DARE); + _pagina_da = mb.get_int(PAGINA_DA); + // "Se l'utente cambia il progressivo dare, esso viene uguagliato all'avere" + if (dare2 != _tot_dare) + { + _tot_dare = dare2; + _tot_avere = dare2; + } + } + else + continue; + } + + init_print(); + init_totals(); + + return TRUE; + } + return FALSE; +} + +int cg3400 (int argc, char * argv[]) +{ + CG3400_application app; + app.run(argc, argv, "Stampa libro giornale"); + return TRUE; +} + diff --git a/cg/cg4400.cpp b/cg/cg4400.cpp index 99b5f1790..6afe65ceb 100755 --- a/cg/cg4400.cpp +++ b/cg/cg4400.cpp @@ -1,3321 +1,3321 @@ -// ******************* -// Stampa registri IVA -// ******************* -#include "cg4.h" -#include "cg4400.h" -#include "cg4400a.h" -#include "cg4400b.h" - -static TString256 TMP; - -inline CG4400_application& app() { return (CG4400_application&)main_app(); } - -bool CG4400_application::filter_func (const TRelation * r) -{ - TLocalisamfile& mov = r->lfile(LF_MOV); - TString16 codreg = mov.get(MOV_REG); - TDate datareg = mov.get_date(MOV_DATAREG); - int annoiva = mov.get_int(MOV_ANNOIVA); - bool regst = mov.get_bool(MOV_REGST); - - if (codreg != (app()._codreg) || annoiva != (app()._annoes)) - return FALSE; - - if (app()._data_da.string() != "" && app()._data_a.string() != "") - if ( (datareg < app()._data_da || datareg > app()._data_a ) || (!datareg.ok()) ) - return FALSE; - - if (app()._tipo_stampa != 1) //stampa di bollato - if (regst) //il movimento e' gia' - return FALSE; //stato stampato in forma definitiva - - if (datareg.month() < app()._stampa_mese) - app()._stampa_mese = datareg.month(); - return TRUE; -} - -HIDDEN int compare_rows(const TObject** o1, const TObject** o2) -{ - TRiga* r1 = (TRiga*)*o1; - TRiga* r2 = (TRiga*)*o2; - - return (strcmp((const char*)r1->_codiva, (const char*)r2->_codiva)); -} - -HIDDEN int compare_fields(const TObject** o1, const TObject** o2) -{ - TRigaiva* r1 = (TRigaiva*)*o1; - TRigaiva* r2 = (TRigaiva*)*o2; - TString16 campo1; - TString16 campo2; - - campo1.format("%d%4s", r1->_tipodet, (const char*)r1->_codiva); - campo2.format("%d%4s", r2->_tipodet, (const char*)r2->_codiva); - return strcmp(campo1, campo2); -} - -bool CG4400_application::stampa_totali_finali() -{ - TConfig conf(CONFIG_DITTA); - return conf.get_bool("StTfFr"); -} - -bool CG4400_application::stampa_datareg() -{ - TConfig conf(CONFIG_STUDIO); - return conf.get_bool("NoDtRg"); -} - -bool CG4400_application::mask_select (TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - app()._ditte->enable_check(); - // seleziona e aggiungi alle gia' selezionate - if (app()._ditte->run() == K_ENTER) - { - for (long j = 0l; j < app()._ditte->items(); j++) - app()._selected.set(j, app()._ditte->checked(j)); - app().set_choice_limits(f.mask()); - } - } - return TRUE; -} - -bool CG4400_application::mask_azzera (TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - app()._selected.reset(); - f.mask().reset(F_SELECT); - f.mask().reset(DA_CODICE); - f.mask().reset(A_CODICE); - app()._ditte->check(-1, FALSE); - } - return TRUE; -} - -bool CG4400_application::mask_tipo_stampa(TMask_field& f, KEY k) -{ - TMask& m = f.mask(); - - if (k == K_SPACE) - { - int tipo_stampa = m.get_int(TIPO_STAMPA); - if (tipo_stampa == 3) //stampa su libro unico - { - m.enable_page(1); - TMask_field& cc = f.mask().field(CODICE_LIB_UN); - cc.set_dirty(); - } - else - m.disable_page(1); - } - return TRUE; -} - -bool CG4400_application::mask_mese (TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - const short id = f.dlg(); - int mese; - if (id == MESE) //Per stampa su libro unico - mese = f.mask().get_int(MESE); - if (id == FINO_A_MESE) - mese = f.mask().get_int(FINO_A_MESE); //Per stampa su bollato - if (id == MESE) - { - if (mese == 12) - { - f.mask().show (TIPO_RIEPILOGATIVO); - f.mask().show (RIF_VID); - } - else - { - f.mask().hide (TIPO_RIEPILOGATIVO); - f.mask().hide (RIF_VID); - } - } - if (id == FINO_A_MESE) - { - if (mese == 12) - f.mask().show (TIPO_RIEPILOGATIVO); - else f.mask().hide (TIPO_RIEPILOGATIVO); - } - } - if (k==K_TAB && f.mask().is_running()) - { - const short id = f.dlg(); - if (id == MESE) - f.mask().send_key(K_TAB, CODICE_LIBRO_IVA); - } - return TRUE; -} - -bool CG4400_application::look_reg(int i, int anno, TString& codlib, int m, const char* cod, int* umese, long ditta) -{ - TString16 y; - - y << anno << cod; - _tabreg->zero(); - _tabreg->put("CODTAB", y); - - if (_tabreg->read() == NOERR) - { - int tipo = _tabreg->get_int("I0"); - if (tipo == 1 || tipo == 2) - { - TString16 cod_lib_un = _tabreg->get("S6"); - TDate u_data = _tabreg->get_date("D3"); - TDate sca_vid = _tabreg->get_date("D1"); - if (codlib != cod_lib_un) - { - if (_selected.ones() == 1L) - if (_selected[i]) - message_box("Ditta %ld: il codice libro unico del registro non e' uguale al codice libro unico indicato", ditta); - return FALSE; - } - if (m < *umese) - { - if (_selected.ones() == 1L) - if (_selected[i]) - message_box("Ditta %ld: il mese indicato e' inferiore al mese dell'ultima data di stampa del registro", ditta); - return FALSE; - } - if (u_data.ok()) - *umese = u_data.month(); - else *umese = 0; - - if (sca_vid.ok()) - if (sca_vid.month() < m) - { - if (_selected.ones() == 1L) - if (_selected[i]) - message_box("Ditta %ld: la data scadenza di vidimazione del registro non deve essere inferiore al mese indicato", ditta); - return FALSE; - } - } - return TRUE; - } - return FALSE; -} - -bool CG4400_application::look_regs(int anno, TString& codlib, int m, int* umese, long ditta, TProgind* prog) -{ - int a, tipo; - TString16 codtab; - bool ok = FALSE; - *umese = 13; - - for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) - { - tipo = _tabreg->get_int("I0"); - codtab = _tabreg->get("CODTAB"); - a = atoi(codtab.mid(0,4)); - if (a > anno) - break; - if (a == anno) - if ( tipo == 1 || tipo == 2 ) //registro iva - { - TString16 cod_lib_un = _tabreg->get("S6"); - TDate sca_vid = _tabreg->get_date("D1"); - TDate u_data = _tabreg->get_date("D3"); - if (codlib != cod_lib_un) - continue; - if (u_data.ok()) - if (m < u_data.month()) - continue; - if (u_data.ok()) - *umese = (*umese < u_data.month()) ? *umese : u_data.month(); - if (sca_vid.ok()) - if (sca_vid.month() < m) - continue; - int month; - if (!u_data.ok()) - month = 0; - else month = u_data.month(); - if (month < m - 1) - { - app().set_firm(__firm); - delete prog; - error_box("Ditta %ld: Stampare i registri dei mesi precedenti", ditta); - app().stop_run(); - } - ok = TRUE; - } - } - return ok; -} - -bool CG4400_application::mask_libun (TMask_field& f, KEY k) -{ - if (k==K_TAB && f.mask().is_running()) - { - TString16 codlib(f.mask().get(CODICE_LIB_UN)); - //modifica del 26/04/1995 - if (codlib.empty()) - { - app()._test = TRUE; - return FALSE; - } - //fine modifica - - if (app()._selected.ones() == 0l) return FALSE; - - TProgind* p = new TProgind(app()._ditte->items()/2,"Verifica parametri in corso...",FALSE,TRUE,30); - - TString16 cod(f.mask().get(CODICE_LIBRO_IVA)); - int fino_a_mese = f.mask().get_int(MESE); - int anno = f.mask().get_int(ANNO); - bool ok = FALSE; - int last_mese = 13; - int mese = 0; - - app().__firm = app().get_firm(); - - for (int i = 0; i < app()._ditte->items(); i++) - { - //p->addstatus(1); - long ditta = app()._ditte->row(i).get_long(1); - if (prefix().exist(ditta)) - { - p->addstatus(1); - app().set_firm(ditta); - if (cod.not_empty()) - { - ok = app().look_reg(i,anno,codlib,fino_a_mese,cod,&mese,ditta); - if (!ok) - { - //modifica del 21/04/1995 suggerita da Cinzia!!! - /*****Rimodifica del 19/07/95 MI0817 - if (app()._selected.ones() == 1L) //solo se ho selezionato 1 ditta devo dare il messaggio - if (app()._selected[i]) - f.message_box("Ditta %ld: il registro %s non soddisfa i parametri indicati", ditta, (const char*)cod); - *****/ - continue; - } - if (mese < fino_a_mese - 1) //indipendentemente se si tratta di una ditta selezionata oppure no - { - app().set_firm(app().__firm); - delete p; - f.error_box("Ditta %ld: Stampare i registri dei mesi precedenti", ditta); - app().stop_run(); - } - } - else - { - ok = app().look_regs(anno,codlib,fino_a_mese,&mese,ditta,p); - if (!ok) - { - if (app()._selected.ones() == 1L) //solo se ho selezionato 1 ditta devo dare il messaggio - if (app()._selected[i]) - f.message_box("Ditta %ld: nessun registro soddisfa i parametri indicati", ditta); - continue; - } - } - //if (app()._selected[i]) - last_mese = (last_mese < mese) ? last_mese : mese; - } - } - app().set_firm(app().__firm); - - if (last_mese == 13) - last_mese = 0; //l'ultima data di stampa sul/sui registri specificati e' vuota (cioe' non sono ancora stati stampati sul libro unico specificato per l'anno specificato) - const char* me = ""; - me = format("%02d", last_mese); - f.mask().set(ULTIMO_MESE, me); - delete p; - } - return TRUE; -} - -bool CG4400_application::mask_cod (TMask_field& f, KEY k) -{ - if (k == K_TAB) - { - TTable TabLbu ("%LBU"); - TString codtab; - int anno; - - TString16 codlib(f.get()); - anno = f.mask().get_int(ANNO); - TabLbu.zero(); - codtab.format ("%04d%-3s", anno, (const char*)codlib); - TabLbu.put ("CODTAB", codtab); - TabLbu.read(); - if ( TabLbu.good() ) - { - //f.mask().set(ULTIMO_MESE,TabLbu.get_long("I0")); - f.mask().set(ULTIMA_PAGINA,TabLbu.get_long("I1")); - app()._codice_vidi = TabLbu.get("S4"); - } - //modifica del 26/04/1995 - if (app()._test) - { - f.mask().send_key(K_TAB, CODICE_LIBRO_IVA); - app()._test = FALSE; - } - //fine modifica - } - return TRUE; -} - -bool CG4400_application::mask_data (TMask_field& f, KEY k) -{ - if (k == K_TAB && f.mask().is_running()) - { - const int anno = f.mask().get_int(ANNO); - TDate data(f.get()); - if (data.ok()) - if (data.year() != anno) - { - f.warning_box("L'anno delle date limite deve essere uguale all'anno iva specificato"); - return FALSE; - } - if (f.dlg() == A_DATA) - if (data.ok) - { - if ( data.day() == 31 && data.month() == 12 ) - f.mask().show (TIPO_RIEPILOGATIVO); - else f.mask().hide (TIPO_RIEPILOGATIVO); - } - } - return TRUE; -} - -const char * CG4400_application::descr_doc() -{ - TTable tab_tpd("%TPD"); - TString codtab(format("%-2s",(const char*) _tipodoc)); - - tab_tpd.zero(); - tab_tpd.put("CODTAB", codtab); - if (tab_tpd.read()==NOERR) - TMP = tab_tpd.get("S0"); - else - TMP = ""; - - return TMP; -} - -const char * CG4400_application::descr_iva(const char * cod) -{ - TTable tab_iva("%IVA"); - TString codtab(format ("%-4s", cod)); - - tab_iva.zero(); - tab_iva.put("CODTAB", codtab); - if (tab_iva.read()==NOERR) - TMP = tab_iva.get("S0"); - else - TMP = ""; - - return TMP; -} - -const char * CG4400_application::tipo_attivita() -{ - TLocalisamfile attiv (LF_ATTIV); - - attiv.zero(); - attiv.put("CODDITTA", get_firm()); - attiv.put("CODATT", _codatt); - if (attiv.read() == NOERR) - TMP = attiv.get("TIPOATT"); - else TMP = ""; - return TMP; -} - -const char * CG4400_application::desc_attivita() -{ - TTable attiv ("%AIS"); - - attiv.zero(); - attiv.put("CODTAB", _codatt); - if (attiv.read()==NOERR) - TMP = attiv.get("S0"); - else - TMP = ""; - return TMP; -} - -TRectype& CG4400_application::ricerca_cf(char tipocf, long codcf) -{ - _clifo->zero(); - _clifo->put(CLI_TIPOCF, tipocf); - _clifo->put(CLI_CODCF, codcf); - _clifo->read(); - if (_clifo->bad()) - _clifo->zero(); - - return _clifo->curr(); -} - -TRectype& CG4400_application::ricerca_occ(const char * occ) -{ - TLocalisamfile occas (LF_OCCAS); - occas.zero(); - occas.put(OCC_CFPI, occ); - occas.read(); - if (occas.bad()) - occas.zero(); - - return occas.curr(); -} - -bool CG4400_application::year_handler(TMask_field& f, KEY key) -{ - if (key == K_TAB && f.focusdirty()) - { - app().begin_wait(); - app().set_year(atoi(f.get())); - app().build_nomiditte(); - app().build_ditte_sheet(); - app().end_wait(); - } - return TRUE; -} - -void CG4400_application::build_ditte_sheet() -{ - // build sheet - _ditte->destroy(); - for (int i = 0; i < _nomiditte.items(); i++) - { - TToken_string* d = new TToken_string(64); - *d = (TToken_string&)_nomiditte[i]; - const char vers = d->get_char(2); - bool selectable = vers == '?'; - d->insert(" |", 0); - const long pos = _ditte->add(d); - if (selectable) - _ditte->disable(pos); - else if (_selected[i]) - _ditte->check(pos); - } -} - -// --------------------------- handlers per selezione ditte - -bool CG4400_application::to_ditt_handler(TMask_field& f, KEY key) -{ - TMask& m = f.mask(); - if (key == K_F9) - app().to_butt_handler(m.field(BUT_DTO), K_SPACE); - if (key == K_TAB && f.focusdirty()) - { - const long l = app().select_firm_range(m.get_long(DA_CODICE), m.get_long(A_CODICE)); - app().set_choice_limits(m); - m.field(F_SELECT).set(format("%ld", l)); - } - return TRUE; -} - -bool CG4400_application::fr_ditt_handler(TMask_field& f, KEY key) -{ - TMask& m = f.mask(); - if (key == K_F9) - app().fr_butt_handler(m.field(BUT_DFR), K_SPACE); - else if (key == K_TAB && f.focusdirty()) - { - const long l = app().select_firm_range(m.get_long(DA_CODICE), m.get_long(A_CODICE)); - app().set_choice_limits(m); - m.field(F_SELECT).set(format("%ld", l)); - } - return TRUE; -} - -bool CG4400_application::to_butt_handler(TMask_field& f, KEY key) -{ - if (key == K_SPACE) - { - TArray_sheet* sh = app().get_ditte_sheet(); - TMask& m = f.mask(); - - sh->disable_check(); - if (sh->run() == K_ENTER) - { - app().select_firm_range(m.get_long(DA_CODICE),sh->row(sh->selected()).get_long(1)); - app().set_choice_limits(m); - } - } - return TRUE; -} - -bool CG4400_application::fr_butt_handler(TMask_field& f, KEY key) -{ - if (key == K_SPACE) - { - TMask& m = f.mask(); - TArray_sheet* sh = app().get_ditte_sheet(); - - sh->disable_check(); - if (sh->run() == K_ENTER) - { - app().select_firm_range(sh->row(sh->selected()).get_long(1), m.get_long(A_CODICE)); - app().set_choice_limits(m); - } - } - return TRUE; -} - -void CG4400_application::set_choice_limits(TMask& m) -{ - long first = -1l, last = -1l; - for (int i = 0; i < _ditte->items(); i++) - { - if (_selected[i]) - { - long dit = _ditte->row(i).get_long(1); - if (first == -1l) first = dit; - if (last < dit) last = dit; - } - } - if (first != -1) m.field(DA_CODICE).set(format("%ld",first)); - if (last != -1) m.field(A_CODICE).set(format("%ld",last)); - m.set(F_SELECT, _selected.ones()); - //modifica del 02/06/1995 - if (m.is_running()) - if (first != -1l) app().set_firm(first); - //fine -} - -long CG4400_application::select_firm_range(long from, long to) -{ - if (to == 0l) to = 99999L; - for (int i = 0; i < _ditte->items(); i++) - { - if (_ditte->disabled(i)) - continue; - - TToken_string& d = _ditte->row(i); - const char vers = d.get_char(3); - if (vers == '?') - continue; - - const long cod = d.get_long(1); - if (cod >= from && cod <= to) - { - _selected.set(i); - _ditte->check(i); - } - else - { - _selected.set(i,FALSE); - _ditte->uncheck(i); - } - } - return _selected.ones(); -} - -void CG4400_application::build_nomiditte(TProgind* pnd) -{ - _nomiditte.destroy(); - // ricostruire _nomiditte e rifare build_ditte_sheet - TLocalisamfile& dt = _nditte->lfile(); - - for (dt.first(); !dt.eof(); dt.next()) - { - // check no archivi - bool good = prefix().exist(dt.get_long("CODDITTA")); - if (good) - { - // check no parametri liquidazione - //TApplication::set_firm(dt.get_long("CODDITTA")); - if (!look_lia(dt.get_long("CODDITTA"))) good = FALSE; - } - _n_ditte++; - TToken_string* d = new TToken_string(64); - d->add(dt.get("CODDITTA")); - d->add(dt.get("RAGSOC")); - if (good) d->add(_tablia->get("S7")); - else d->add("??"); - - _nomiditte.add(d); - } - //if (pnd) pnd->addstatus(1); - //TApplication::set_firm(__firm); -} - -bool CG4400_application::user_create() -{ - //TProgind* pnd = NULL; - - //pnd = new TProgind (2,"Preparazione archivi\nPrego attendere", - // FALSE, TRUE, 30); - - _com = new TLocalisamfile(LF_COMUNI); - _anag = new TLocalisamfile(LF_ANAG); - _unloc = new TLocalisamfile(LF_UNLOC); - _attiv = new TLocalisamfile(LF_ATTIV); - _tab = new TLocalisamfile(LF_TAB); - _tabcom = new TLocalisamfile(LF_TABCOM); - _indlib = new TLocalisamfile(LF_INDLIB); - _tabreg = new TTable("REG"); - _tabiva = new TTable("%IVA"); - _tablbu = new TTable("%LBU"); - _tablim = new TTable("LIM"); - _tabpim = new TTable("PIM"); - _tablia = new TTable("%LIA"); - _tabpla = new TTable("%PLA"); - _tabppa = new TTable("PPA"); - _tabvid = new TTable("%VID"); - _clifo = new TLocalisamfile(LF_CLIFO); - _occas = new TLocalisamfile(LF_OCCAS); - - _desc27 = new TParagraph_string("", 27); - - _nditte = new TRelation(LF_NDITTE); - - _rel = new TRelation (LF_MOV); - _rel->add(LF_CAUSALI,"CODCAUS=CODCAUS",1,LF_MOV); - _rel->add(LF_RMOVIVA,"NUMREG=NUMREG",1,LF_MOV); - - _cur = new TCursor(_rel, "", 2); - - _ditte = new TArray_sheet(-1, -1, 0, 0, "Selezione Ditte", - "@1|Cod.@5R|Ragione Sociale@50|Vers."); - - //if (pnd) pnd->addstatus(1); - - _n_ditte = 0l; - __firm = TApplication::get_firm(); - - TDate oggi(TODAY); - _annoes = oggi.year(); - - build_nomiditte(); - build_ditte_sheet(); - - add_cursor(_cur); - add_file(LF_MOV); - add_file(LF_RMOVIVA); - - //delete pnd; - - return TRUE; -} - -bool CG4400_application::user_destroy() -{ - delete _ditte; - delete _nditte; - delete _com; - delete _unloc; - delete _anag; - delete _attiv; - delete _indlib; - delete _tab; - delete _tabcom; - delete _tabreg; - delete _tabiva; - delete _tablbu; - delete _tablim; - delete _tabpim; - delete _tablia; - delete _tabpla; - delete _tabppa; - delete _tabvid; - delete _clifo; - delete _occas; - delete _cur; - delete _rel; - delete _desc27; - - return TRUE; -} - -void CG4400_application::calcola_progressivi() -{ - TTable pim ("PIM"); - TString80 chiave; - int i, num=0; - - if (_tipo_stampa == 3) - num = _fino_a_mese; - if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) - num = _datareg.month(); - - //il discorso e' indipendente dalla frequenza! - //if (_frequiva == 'T') - // if (num%3 != 0) - // num = num - (num%3); - - //calcolo i totali del periodo - - chiave = ""; - //_codatt e' gia' Z perche' lo leggo dal registro - chiave << _annoes << _codatt; - pim.zero(); - pim.put ("CODTAB", chiave); - TRectype r (pim.curr()); - pim.read(_isgteq); - for (; !pim.eof(); pim.next()) - { - if (pim.curr() != r) break; - - TString80 codtab = pim.get("CODTAB"); - TString16 codreg = codtab.mid(10,3); - int mese = atoi(codtab.mid(13,2)); - if (_codreg == codreg.trim() && mese == num) - { - TString16 codiva = codtab.mid(16,4); - int tipodet = atoi(codtab.mid(20,1)); - real impo = pim.get_real("R0"); - real impos = pim.get_real("R1"); - real implo = pim.get_real("R2"); - //se il registro e' corrispettivi l'imponibile e l'iva li trovo in S2 - if (_corrispettivi) - { - TToken_string cs (pim.get("S2")); - impo = cs.get(0); - impos = cs.get(1); - } - //se in sospensione d'imposta l'imponibile e l'iva li trovo in R11 e R12 - if (_sosp_imposta) //in genere non sara' mai un corrispettivo - { - impo = pim.get_real("R11"); - impos = pim.get_real("R12"); - } - TToken_string fatt_rit (pim.get("S1")); //e' sempre un acquisto - real im (fatt_rit.get(0)); - real is (fatt_rit.get(1)); - impo += im; - impos += is; - implo += im+is; // potrei percio' ignorare l'importo lordo - if (impo != ZERO || impos != ZERO || implo != ZERO) - _tot_iva_array.add_riga(impo,impos,implo,ZERO,ZERO,ZERO,codiva); - if (_tipo_reg == 2) //registro acquisti - if (impo != ZERO || impos != ZERO) - _iva_array.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,0,TRUE); - } - } - - //calcolo i totali progressivi - if (_tipo_stampa == 3) - num = _fino_a_mese; - if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) - num = _datareg.month(); - - for (i=1; i<=num; i++) - { - chiave = ""; - chiave << _annoes << _codatt; - pim.zero(); - pim.put("CODTAB", chiave); - TRectype r (pim.curr()); - pim.read(_isgteq); - for (; !pim.eof(); pim.next()) - { - if (pim.curr() != r) break; - TString80 codtab = pim.get("CODTAB"); - TString16 codreg = codtab.mid(10,3); - int mese = atoi(codtab.mid(13,2)); - if (_codreg == codreg.trim() && mese == i) - { - TString16 codiva = codtab.mid(16,4); - int tipodet = atoi(codtab.mid(20,1)); - real impo = pim.get_real("R0"); - real impos = pim.get_real("R1"); - real implo = pim.get_real("R2"); - //se il registro e' corrispettivi l'imponibile e l'iva li trovo in S2 - if (_corrispettivi) - { - TToken_string cs (pim.get("S2")); - impo = cs.get(0); - impos = cs.get(1); - } - //se in sospensione d'imposta l'imponibile e l'iva li trovo in R11 e R12 - if (_sosp_imposta) - { - impo = pim.get_real("R11"); - impos = pim.get_real("R12"); - } - TToken_string fatt_rit (pim.get("S1")); - real im (fatt_rit.get(0)); - real is (fatt_rit.get(1)); - impo += im; - impos += is; - implo += im+is; - if (impo != ZERO || impos != ZERO || implo != ZERO) - _tot_iva_array.add_riga(ZERO,ZERO,ZERO,impo,impos,implo,codiva); - if (_tipo_reg == 2) //registro acquisti - if (impo != ZERO || impos != ZERO) - _iva_array.add_riga(ZERO,ZERO,impo,impos,codiva,tipodet,0,TRUE); - } - } - } -} - -int CG4400_application::riga_rmoviva() -{ - TString codiva; - real impo, impos; - int tipodet, tipocr, tipoatt; - bool intra; - - TLocalisamfile& rmoviva = _cur->file(LF_RMOVIVA); - bool ok = _cur->is_first_match(LF_RMOVIVA); - int nrec = 0; - - TRecnotype nr = rmoviva.recno(); - - while (ok) - { - nrec++; - TRectype iva (rmoviva.curr()); - tipodet = iva.get_int (RMI_TIPODET); - tipocr = iva.get_int (RMI_TIPOCR); - impo = iva.get_real(RMI_IMPONIBILE); - impos = iva.get_real(RMI_IMPOSTA); - codiva = iva.get(RMI_CODIVA); - intra = iva.get_bool(RMI_INTRA); - tipoatt = iva.get_int("TIPOATT"); - - _riga_rmi.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,tipocr,intra,tipoatt); - - if (_tipo_stampa == 1) //stampa di prova - { - if (_tipodoc == "FS") - { - real somma = -(impo + impos); - _tot_iva_array.add_riga(ZERO,ZERO,somma,ZERO,ZERO,ZERO,codiva); - } - else if (_tipodoc == "CR" || _tipodoc == "RF" || _tipodoc == "SC") - _tot_iva_array.add_riga(ZERO,ZERO,impo+impos,ZERO,ZERO,ZERO,codiva); - if (_tipodoc != "CR" && _tipodoc != "SC" && _tipodoc != "RF") - _tot_iva_array.add_riga(impo,impos,ZERO,ZERO,ZERO,ZERO,codiva); - - if (_tipo_reg == 2) //registro acquisti (non ha senso parlare di importi lordi) - _iva_array.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,0,TRUE); - } - - ok = _cur->next_match(LF_RMOVIVA); - } - rmoviva.readat(nr); - - return nrec; -} - -int CG4400_application::setta_riga(int r, const TRigaiva& riga, real& tot1, - real& tot2, real& tot3, real& tot4) -{ - set_row(r, "%4s", (const char*)riga._codiva); - TString descr = descr_iva(riga._codiva); - set_row(r, "@5g%-.21s",(const char*)descr); - if (riga._imponibile != ZERO) - set_row(r, "@25g%r", &riga._imponibile); - if (riga._imposta != ZERO) - set_row(r, "@41g%r", &riga._imposta); - if (_tipo_stampa != 1) - { - if (riga._imponibilep != ZERO) - set_row(r, "@81g%r", &riga._imponibilep); - if (riga._impostap != ZERO) - set_row(r++, "@98g%r", &riga._impostap); - } - else r++; - tot1 += riga._imponibile; - tot2 += riga._imposta; - tot3 += riga._imponibilep; - tot4 += riga._impostap; - - return r; -} - -messaggio CG4400_application::controlla_b0() -{ - TTable lim ("LIM"); - TString16 chiave = ""; - TString16 ditta = ""; - int i, mese; - ditta << get_firm(); - - if (_tipo_stampa == 1) //stampa di prova - mese = _data_a.month(); - else - mese = _fino_a_mese; - - if (_tipo_riepilogativo == ' ' || _tipo_riepilogativo == 'P') - { - if (_frequiva == 'T') //nella tabella LIM ho solo i mesi 3, 6, 9, 12 - { - for (i=3; i<=mese; i+=3) - { - chiave = ""; - TString16 m (format("%02d", i)); - chiave << _annoes << m; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - if (! lim.get_bool("B0")) - return no_liquidazione; - } - else return no_liquidazione; - } - } - if (_frequiva == 'M') - { - for (i=1 ; i<=mese; i++) - { - chiave = ""; - TString16 m (format("%02d", i)); - chiave << _annoes << m; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - if (! lim.get_bool("B0")) - return no_liquidazione; - } - else return no_liquidazione; - } - } - } - else if (_tipo_riepilogativo == 'A') - //if (_riep_liq) - { - chiave = ""; - chiave << _annoes << 13; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - if (! lim.get_bool("B0")) - return no_liquidazione; - } - else return no_liquidazione; - } - return B0_settato; -} - -messaggio CG4400_application::controlla_liquidazione() -{ - TTable lim ("LIM"); - TString mesi_cal = ""; - TString16 chiave = ""; - TString16 ditta = ""; - int i, mese; - bool continua; - ditta << get_firm(); - - if (_tipo_stampa == 1) //stampa di prova - mese = _data_a.month(); - else - mese = _fino_a_mese; - - if (_tipo_riepilogativo == ' ' || _tipo_riepilogativo == 'P') - { - if (_frequiva == 'T') //nella tabella LIM ho solo i mesi 3, 6, 9, 12 - { - for (i=3; i<=mese; i+=3) - { - chiave = ""; - TString16 m (format("%02d", i)); - chiave << _annoes << m; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - if (! lim.get_bool("B0")) - mesi_cal << itom(i) << "\n"; - } - else mesi_cal << itom(i) << "\n"; - } - } - if (_frequiva == 'M') - { - for (i=1 ; i<=mese; i++) - { - chiave = ""; - TString16 m (format("%02d", i)); - chiave << _annoes << m; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - if (! lim.get_bool("B0")) - mesi_cal << itom(i) << "\n"; - } - else mesi_cal << itom(i) << "\n"; - } - } - if (mesi_cal.not_empty()) - { - warning_box ("Ditta %s: la liquidazione da stampare sul registro %s relativa ai mesi di \n %s non e' stata ancora calcolata", (const char*)ditta, (const char*) _codreg, (const char *)mesi_cal); - continua = yesno_box("Si desidera ugualmente proseguire?"); - if (!continua) return non_proseguire; - continua = yesno_box("Si desidera proseguire con il calcolo e la stampa di liquidazione? \n (altrimenti si prosegue con la sola stampa di liquidazione)"); - if (!continua) return prosegui_stampa; - return prosegui_cal_stampa; - } - } - else if (_tipo_riepilogativo == 'A') - //if (_riep_liq) - { - chiave = ""; - chiave << _annoes << 13; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - if (! lim.get_bool("B0")) - { - continua = yesno_box("Ditta %s: non eseguito calcolo liquidazione annuale da stampare sul registro %s. Si desidera ugualmente proseguire?", (const char*)ditta, (const char*) _codreg); - if (!continua) return non_proseguire; - continua = yesno_box("Si desidera proseguire con il calcolo e la stampa di liquidazione? \n (altrimenti si prosegue con la sola stampa di liquidazione)"); - if (!continua) return prosegui_stampa; - return prosegui_cal_stampa; - } - } - else - { - continua = yesno_box("Ditta %s: non eseguito calcolo liquidazione annuale da stampare sul registro %s. Si desidera ugualmente proseguire?", (const char*)ditta, (const char*) _codreg); - if (!continua) return non_proseguire; - continua = yesno_box("Si desidera proseguire con il calcolo e la stampa di liquidazione? \n (altrimenti si prosegue con la sola stampa di liquidazione)"); - if (!continua) return prosegui_stampa; - return prosegui_cal_stampa; - } - } - return B0_settato; -} - -//controlla che i movimenti con anno data di registrazione < dell'anno indicato a video siano stati gia' stampati in forma definitiva*/ -//questo controllo viene fatto solo per stampa di bollato (non su libro unico) -bool CG4400_application::controlla_mov() -{ - TLocalisamfile mov (LF_MOV); - bool ok = TRUE; - byte tipo; - TString16 ditta = ""; - TRecnotype rec = _tabreg->recno(); - for (mov.first(); !mov.eof(); mov.next()) - { - TString16 reg = mov.get(MOV_REG); - if (reg.empty()) continue; //non e' un movimento iva - TDate datareg = mov.get_date(MOV_DATAREG); - if (_stampa_tutti_i_registri) - cerca_reg (reg, &tipo); - if ( (_stampa_tutti_i_registri && (tipo == 1 || tipo == 2)) - || (!_stampa_tutti_i_registri && reg == _codreg) ) - { - bool stampato = mov.get_bool(MOV_REGST); - if ( datareg.year() < _annoes ) - { - long numreg = mov.get_long(MOV_NUMREG); - if (!stampato) - ok = FALSE; - } - } - } - _tabreg->readat(rec); - return ok; -} - -bool CG4400_application::cerca_libro_gio(TString& datas, bool* good) -{ - TString app(4); - app = format("%04d", _annoes); - - *good = TRUE; - TRecnotype rec = _tabreg->recno(); - _tabreg->zero(); - _tabreg->put ("CODTAB", app); - TRectype r (_tabreg->curr()); - _tabreg->read(_isgteq); - for (; !_tabreg->eof(); _tabreg->next()) - { - if (_tabreg->curr() != r) break; - - int tiporeg = _tabreg->get_int("I0"); - if (tiporeg == 5) //libro giornale - { - const TDate& data = _tabreg->get_date("D3"); - if (data > _data_a) - { -// datas = format("%02/%02d/%4d", data.day(), data.month(), data.year()); - datas = data; // Meglio cosi' - *good = FALSE; - return FALSE; - } - return TRUE; - } - } - _tabreg->readat(rec); - //return TRUE; - return FALSE; -} - -void CG4400_application::cerca_reg(const TString& c, byte* t) -{ - TString16 cod = ""; - - cod << _annoes << c; - _tabreg->zero(); - _tabreg->put("CODTAB", cod); - if (_tabreg->read() == NOERR) - *t = _tabreg->get_int ("I0"); -} - -bool CG4400_application::ventilazione(const char* iva) -{ - TTable tabiva ("%IVA"); - TString16 chiave = ""; - chiave << iva; - tabiva.put("CODTAB", chiave); - if (tabiva.read()==NOERR) - { - TString16 vent = tabiva.get("S1"); - if (vent == "VE") - return TRUE; - } - return FALSE; -} - -int CG4400_application::stampa_prospetto() -{ - TString riga(_stampa_width); - int r=1, rr=0; - - reset_print(); - riga.fill('-'); - set_row(r, "%s", (const char*)riga); - r++; - set_row(r, "Legenda Tipo Operazione: 1=operazione intracomunitaria 2=AF art.34 comma 3"); - if (_auto_intraf) - set_row(r, "@78g3=operazione intracomunitaria e AF art.34 comma 3"); - r++; - - _stampa = stampa_totali_finali(); - if (_stampa) - { - set_row(++r, "Tipo documento@54gTotale documento"); - r+=2; - for (int j = 0; j < _doc_array.items(); j++) - { - TTipodoc& doc = (TTipodoc&)_doc_array[j]; - rr = r+j; - set_row(rr, "%2s", (const char*) doc._tipodoc); - set_row(rr, "@3g%s", (const char*) doc._descrdoc); - set_row(rr, "@54g%r", &doc._totdoc); - } - _doc_array.destroy(); - } - - if (rr > 0) - rr++; - else - rr = r; - - if (_stampa && _tipo_reg == 2) - { - if (_stampa_cred_pre && _mese_credito==0 && _credito > ZERO) - { - set_row (++rr, "** CREDITO INIZIO ANNO @39g%r", &_credito); - rr++; - } - } - - if (_esiste_riga_iva && _stampa) - { - if (_tipo_reg == 1 && _corrispettivi) - set_row(++rr, "@26g------------------ P E R I O D O -------------------"); - else - set_row(++rr, "@26g---------- P E R I O D O -----------"); - if (_tipo_stampa != 1) - { - if (_tipo_reg == 1 && _corrispettivi) - set_row(rr,"@84g----------- P R O G R E S S I V I --------------"); - else - set_row(rr,"@82g------ P R O G R E S S I V I ------"); - } - rr++; - set_row(rr, "Cod."); - if (_tipo_reg == 2) - { - set_row(rr, "@36gA C Q U I S T I"); - if (_tipo_stampa != 1) - set_row(rr, "@92gA C Q U I S T I"); - } - if (_tipo_reg == 1) //un registro corrispettivi puo' solo essere un registro vendite - { - set_row(rr, "@37gV E N D I T E"); - if (_corrispettivi) - set_row(rr, "@63gCORRISPETTIVI"); - if (_tipo_stampa != 1) - { - if (_corrispettivi) - set_row(rr, "@94gV E N D I T E@118gCORRISPETTIVI"); - else - set_row(rr, "@93gV E N D I T E"); - } - } - rr++; - set_row(rr, "iva Descrizione@30gImponibile@49gImposta"); - if (_tipo_reg == 1 && _corrispettivi) - set_row(rr, "@63gImporti lordi"); - if (_tipo_stampa != 1) - { - if (_tipo_reg == 1 && _corrispettivi) - set_row(rr++, "@87gImponibile@107gImposta@118gImporti Lordi"); - else - set_row(rr++, "@86gImponibile@106gImposta"); - } - else rr++; - rr++; - } - return rr; -} - -//la stampa "tipi di indetraibilita'" viene fatta solo per gli acquisti -int CG4400_application::stampa_acquisti(int row) -{ - real tot_imponib, tot_imposta, tot_imponibp, tot_impostap; - row+=2; - int tdetprec = -1; - int rw = row; - tot_imponib = tot_imposta = tot_imponibp = tot_impostap = ZERO; - - _iva_array.sort(compare_fields); - for (int s = 0; s < _iva_array.items(); s++) - { - TRigaiva& riga = (TRigaiva&)_iva_array[s]; - switch (riga._tipodet) - { - case 1: if (riga._tipodet != tdetprec) - { - set_row(rw++, "----- Indetraibile su op.es. -----"); - set_row(rw, "Cod."); - rw++; - set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); - if (_tipo_stampa != 1) - set_row(rw++, "@86gImponibile@106gImposta"); - else rw++; - rw++; - } - rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); - tdetprec = riga._tipodet; - break; - case 3: if (tdetprec == 1) - { - //set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); - set_row(++rw, "TOTALE"); - if (tot_imponib != ZERO) - set_row(rw, "@25g%r", &tot_imponib); - if (tot_imposta != ZERO) - set_row(rw, "@41g%r", &tot_imposta); - - if (_tipo_stampa != 1) - { - //set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); - if (tot_imponibp != ZERO) - set_row(rw, "@81g%r", &tot_imponibp); - if (tot_impostap != ZERO) - set_row(rw, "@98g%r", &tot_impostap); - } - tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; - rw+=2; - } - if (riga._tipodet != tdetprec) - { - set_row(rw++, "----- Passaggi interni -----"); - set_row(rw, "Cod."); - rw++; - set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); - if (_tipo_stampa != 1) - set_row(rw++, "@86gImponibile@106gImposta"); - else rw++; - rw++; - } - rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); - tdetprec = riga._tipodet; - break; - case 9: if ( (tdetprec == 1) || (tdetprec == 3) ) - { - //set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); - set_row(++rw, "TOTALE"); - if (tot_imponib != ZERO) - set_row(rw, "@25g%r", &tot_imponib); - if (tot_imposta != ZERO) - set_row(rw, "@41g%r", &tot_imposta); - if (_tipo_stampa != 1) - { - //set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); - if (tot_imponibp != ZERO) - set_row(rw, "@81g%r", &tot_imponibp); - if (tot_impostap != ZERO) - set_row(rw, "@98g%r", &tot_impostap); - } - tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; - rw+=2; - } - if (riga._tipodet != tdetprec) - { - set_row(rw++, "----- N.D. 9 - acquisti indeducibili per ART.19 -----"); - set_row(rw, "Cod."); - rw++; - set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); - if (_tipo_stampa != 1) - set_row(rw++, "@86gImponibile@106gImposta"); - else rw++; - rw++; - } - rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); - tdetprec = riga._tipodet; - break; - default: break; - } - } - if (_iva_array.items() > 0) - if (tdetprec == 9) - { - //set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); - set_row(++rw, "TOTALE"); - if (tot_imponib != ZERO) - set_row(rw, "@25g%r", &tot_imponib); - if (tot_imposta != ZERO) - set_row(rw, "@41g%r", &tot_imposta); - if (_tipo_stampa != 1) - { - //set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); - if (tot_imponibp != ZERO) - set_row(rw, "@81g%r", &tot_imponibp); - if (tot_impostap != ZERO) - set_row(rw, "@98g%r", &tot_impostap); - } - } - _iva_array.destroy(); - rw++; - return rw; -} - -void CG4400_application::set_page_tot_reg() -{ - int rr=0; - - rr = stampa_prospetto(); - - if (_esiste_riga_iva && _stampa) - { - real tot_imponib, tot_imposta, tot_lordo, tot_imponibp, tot_impostap, tot_lordop; - tot_imponib = tot_imposta = tot_lordo = tot_imponibp = tot_impostap = tot_lordop = ZERO; - - _tot_iva_array.sort(compare_rows); //viene ordinato per codice iva - - for (int k = 0; k < _tot_iva_array.items(); k++) - { - TRiga& riga = (TRiga&)_tot_iva_array[k]; - //row = rr+k; - set_row(rr, "%4s", (const char*)riga._codiva); - TString80 descr = descr_iva(riga._codiva); - set_row(rr, "@5g%-.21s",(const char*)descr); - if (riga._imponibile != ZERO) - set_row(rr, "@25g%r", &riga._imponibile); - if (riga._imposta != ZERO) - set_row(rr, "@41g%r", &riga._imposta); - if (_tipo_reg == 1 && _corrispettivi) - if (riga._implordo != ZERO) - set_row(rr, "@61g%r", &riga._implordo); - if (_tipo_stampa != 1) - { - if (riga._imponibilep != ZERO) - set_row(rr, "@81g%r", &riga._imponibilep); - if (riga._impostap != ZERO) - set_row(rr, "@98g%r", &riga._impostap); - if (_tipo_reg == 1 && _corrispettivi) - if (riga._implordop != ZERO) - set_row(rr, "@115g%r", &riga._implordop); - } - rr++; - tot_imponib += riga._imponibile; - tot_imposta += riga._imposta; - tot_lordo += riga._implordo; - tot_imponibp+= riga._imponibilep; - tot_impostap+= riga._impostap; - tot_lordop += riga._implordop; - } - _tot_iva_array.destroy(); - rr++; - //set_row(rr, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); - set_row(rr, "TOTALE"); - if (tot_imponib != ZERO) - set_row(rr, "@25g%r", &tot_imponib); - if (tot_imposta != ZERO) - set_row(rr, "@41g%r", &tot_imposta); - if (_tipo_reg == 1 && _corrispettivi) - if (tot_lordo != ZERO) - set_row(rr, "@61g%r", &tot_lordo); - if (_tipo_stampa != 1) - { - //set_row(rr, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); - if (tot_imponibp != ZERO) - set_row(rr, "@81g%r", &tot_imponibp); - if (tot_impostap != ZERO) - set_row(rr, "@98g%r", &tot_impostap); - if (_tipo_reg == 1 && _corrispettivi) - if (tot_lordop != ZERO) - set_row(rr, "@115g%r", &tot_lordop); - } - - if (_tipo_reg == 2) rr = stampa_acquisti(rr); - } - if (_tipo_reg == 2 && _tipo_stampa != 1) - stampa_plafonds(rr); -} - -void CG4400_application::stampa_plafonds(int r) -{ - TTable pla ("%PLA"); - TTable ppa ("PPA"); - TString80 chiave; - int num; - real r1, r2, r3; - - r1 = r2 = r3 = ZERO; - - if (_tipo_stampa == 3) - num = _fino_a_mese; - if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) - num = _datareg.month(); - - TString16 nm (format("%02d", num)); - - // forza il tipoatt a 1 - //char buf[10]; strcpy(buf,_codatt); - //buf[strlen(buf) - 1] = '1'; - - chiave = ""; - //chiave << _annoes << buf; - - chiave.format("%05ld", get_firm()); - chiave << _annoes; - chiave << _codatt << "1"; - pla.put("CODTAB", chiave); - - if (pla.read() == NOERR) - { - r1 = pla.get_real("R5"); //totali esp. art.8 - r2 = pla.get_real("R6"); //totali esp. art.8 bis - r3 = pla.get_real("R7"); //totali esp. art 9 - } - - if (r1 > ZERO || r2 > ZERO || r3 > ZERO) - { - set_row(++r, "QUADRO RELATIVO ALLA DISPONIBILITA' E UTILIZZAZIONE MENSILE DEI PLAFONDS"); - r++; - TString mese(9); - mese = itom(num); - mese.right_just(); - set_row(++r, "%s", (const char*) mese); - set_row(++r, ""); - r++; - } - else return; - - if (r1 > ZERO) - { - real r8 = ZERO; - r8 = stampa_valori_plafonds(r1, num, ppa, "1"); - //if (r8 > ZERO) - if (!r8.is_zero()) - { - real pri = ZERO; - real pre = ZERO; - chiave = ""; - chiave << _annoes << _codatt << "1" << nm << "1"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri = ppa.get_real("R0"); - pre = ppa.get_real("R1"); - } - chiave = ""; - chiave << _annoes << _codatt << "2" << nm << "1"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri += ppa.get_real("R0"); - pre += ppa.get_real("R1"); - } - real x = r8 - pri - pre; - set_row(r++, "ART. 8 1° comma lettere a-b Disponibile %r", &r8); - set_row(r++, "Utilizzato all'interno@44g%r", &pri); - set_row(r++, "Utilizzato per l'importazione@44g%r riporto %r", &pre, &x); - } - } - - if (r2 > ZERO) - { - real r8b = ZERO; - r8b = stampa_valori_plafonds(r2, num, ppa, "2"); - //if (r8b > ZERO) - if (!r8b.is_zero()) - { - real pri = ZERO; - real pre = ZERO; - chiave = ""; - chiave << _annoes << _codatt << "1" << nm << "2"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri = ppa.get_real("R0"); - pre = ppa.get_real("R1"); - } - chiave = ""; - chiave << _annoes << _codatt << "2" << nm << "2"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri += ppa.get_real("R0"); - pre += ppa.get_real("R1"); - } - real x = r8b - pri - pre; - r++; - set_row(r++, "ART. 8 bis 1° comma Disponibile %r", &r8b); - set_row(r++, "Utilizzato all'interno@44g%r", &pri); - set_row(r++, "Utilizzato per l'importazione@44g%r riporto %r", &pre, &x); - } - } - - if (r3 > ZERO) - { - real r9 = ZERO; - r9 = stampa_valori_plafonds(r3, num, ppa, "3"); - //if (r9 > ZERO) - if (!r9.is_zero()) - { - real pri = ZERO; - real pre = ZERO; - chiave = ""; - chiave << _annoes << _codatt << "1" << nm << "3"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri = ppa.get_real("R0"); - pre = ppa.get_real("R1"); - } - chiave = ""; - chiave << _annoes << _codatt << "2" << nm << "3"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri += ppa.get_real("R0"); - pre += ppa.get_real("R1"); - } - real x = r9 - pri - pre; - r++; - set_row(r++, "ART. 9 1° comma Disponibile %r", &r9); - set_row(r++, "Utilizzato all'interno@44g%r", &pri); - set_row(r++, "Utilizzato per l'importazione@44g%r riporto %r", &pre, &x); - } - } -} - -real CG4400_application::stampa_valori_plafonds(const real& r1, const int mese, TTable& ppa, const char* tipo) -{ - real r, si8, se8; - TString80 chiave; - int i; - - r = r1; - si8 = se8 = ZERO; - if (mese > 1) - { - for (i=1; ifirst(); - if (!_tabreg->eof()) - { - codtab = _tabreg->get("CODTAB"); - anno = atoi(codtab.mid(0,4)); - if (anno > _annoes) - { - if (_tipo_stampa != 3) //per il libro unico e' gia' stato controllato nell'handler - warning_box("Non esistono registri IVA della Ditta %ld per l'anno %d", - _ditta, _annoes); - return FALSE; - } - } - } - else // stampa un solo registro - { - _stampa_tutti_i_registri = FALSE; - codtab << _annoes << _codreg; - _tabreg->zero(); - _tabreg->put("CODTAB", codtab); - if (_tabreg->read() != NOERR) - { - if (_tipo_stampa != 3) - warning_box("Il registro IVA specificato non esiste nella \n Ditta %ld", _ditta); - return FALSE; - } - else - { - _tipo_reg = _tabreg->get_int("I0"); - if (_tipo_reg == 1 || _tipo_reg == 2) //registro iva - { - cod_lib_un = _tabreg->get("S6"); - sca_vid = _tabreg->get_date("D1"); - if (_tipo_stampa != 1) - _u_data = _tabreg->get_date ("D3"); - if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) - { - if (cod_lib_un.not_empty()) - { - warning_box ("Ditta %ld: sul registro non deve essere indicato il codice del libro unico", _ditta); - return FALSE; - } - if (sca_vid.ok()) - if (sca_vid.month() < _fino_a_mese) - { - warning_box ("Ditta %ld: il mese della data scadenza vidimazione riportata sul registro non deve essere inferiore al mese indicato", _ditta); - return FALSE; - } - if (_u_data.ok()) - if (_data_a < _u_data) - { -// TString16 datas = format("%02d/%02d/%4d", _u_data.day(), _u_data.month(), _u_data.year()); -// warning_box ("Ditta %ld: la data specificata non deve essere inferiore al %s (ultima data di stampa specificata sul registro)", _ditta, (const char*)datas); -// return FALSE; - return warning_box ("Ditta %ld: la data specificata non deve essere inferiore al %s (ultima data di stampa specificata sul registro)", _ditta, (const char*)_u_data.string()); - } - if (_tipo_stampa == 4) //stampa con riferimenti al libro giornale - { - TString16 datas; - bool good; - bool ok = cerca_libro_gio(datas,&good); - if (!ok) - { - if (!good) - warning_box ("Ditta %ld: la data indicata non deve essere superiore al %s (ultima data di stampa del libro giornale)", _ditta, (const char*)datas); - return FALSE; - } - } - } - _pagine_stampate = _tabreg->get_long("I1"); - _numini = _pagine_stampate; - _corrispettivi = _tabreg->get_bool("B0"); - _sosp_imposta = _tabreg->get_bool("B1"); - _liquidazione = _tabreg->get_bool("B7"); - _riep_liq = _tabreg->get_bool("B6"); - _stampa_cred_pre = _tabreg->get_bool("B4"); - _stampa_ind_ditta = _tabreg->get_bool("B9"); - _stampa_ind_comp = _tabreg->get_bool("B5"); - _cod_un_loc = _tabreg->get_int ("I7"); - _mese_credito = _tabreg->get_int ("I8"); //campo nascosto sulla tabella dei registri: mese di stampa credito anno precedente - _mese_ultima_liq = _tabreg->get_int ("I4"); - _codatt = _tabreg->get("S8"); - _tipoatt = tipo_attivita(); - _attivita = desc_attivita(); - _desc_lib = _tabreg->get ("S0"); - } - else return FALSE; - } - } - return TRUE; -} - -bool CG4400_application::compila_lib() -{ - TTable tab_lib ("%LBU"); - TString16 cod; - - cod << _annoes << _codlib; - tab_lib.zero(); - tab_lib.put("CODTAB", cod); - - if (tab_lib.read() == NOERR) - { - _stampa_ind_ditta = tab_lib.get_bool("B1"); - return TRUE; - } - return FALSE; -} - -bool CG4400_application::preprocess_print(int file, int counter) -{ - if (file == LF_MOV) - { - long items = _cur->items(); - if (!items) - return FALSE; - _iva_array.destroy(); - _riga_rmi.destroy(); - _tot_iva_array.destroy(); - _doc_array.destroy(); - _dataregp = ""; - _esiste_riga_iva = FALSE; - _auto_intraf = FALSE; - _intesta_liq = FALSE; - set_print_zero(); - } - return TRUE; -} - -bool CG4400_application::preprocess_page(int file, int counter) -{ - if (file == LF_MOV) - { - if (counter) return TRUE; - - reset_print(); - int rr = 0, riga = 0; - bool intra; - TString80 comune, prov, comcf, capcf, civcf; - TString80 viacf; - TString ragsoc; - TString tipo_op = ""; - - TLocalisamfile& mov = _cur->file(LF_MOV); - TLocalisamfile& caus = _cur->file(LF_CAUSALI); - - _datareg = mov.get_date(MOV_DATAREG); - - if (_tipo_stampa != 3 && _liquidazione) - { - int da; - if (_tipo_stampa == 1) - da = _data_da.month(); - else da = 1; - int a = _datareg.month(); - for (int m = da; m < a; m++) - { - if (!_st_liq[m]) - if (stampo_liquidazione(m)) - { -// _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header (intestazione per la stampa liquidazione) - _datareg = TDate(1, m, _annoes); // Meglio cosi' - TFilename t; - t.temp("reg"); - if (_scelta == B0_settato || _scelta == prosegui_stampa) - { - if (_tipo_stampa == 1) - send_message('S',t, m); - else send_message('s',t, m); - } - else //_scelta == prosegui_cal_stampa - { - if (_tipo_stampa == 1) - send_message('L', t, m); - else send_message('l', t, m); - } - //TString80 nomef; nomef = t.path(); nomef << "\\" << t.name(); - //if (fexist(nomef)) - if (fexist(t)) - { - _intesta_liq = TRUE; - //printer().footerlen(0); - if (!_mov_empty) printer().formfeed(); - merge_export_file(t,FALSE,TRUE); - _intesta_liq = FALSE; - reset_print(); - remove(t); - } - } - _st_liq[m] = TRUE; - } - } - - _datareg = mov.get_date(MOV_DATAREG); - _mov_empty = FALSE; - - if ( _datareg.month() != _dataregp.month() && _dataregp.ok() ) - { - _auto_intraf = FALSE; - printer().formfeed(); - //printer().footerlen(5); //devo rimetterlo cosi' - } - - _dataregp = _datareg; - - TDate datadoc = mov.get_date(MOV_DATADOC); - long numreg = mov.get_long(MOV_NUMREG); - long protiva = mov.get_long(MOV_PROTIVA); - long uprotiva = mov.get_long(MOV_UPROTIVA); - real totdoc = mov.get_real(MOV_TOTDOC); - TString16 numdoc = mov.get(MOV_NUMDOC); - char tipocf = mov.get(MOV_TIPO)[0]; - TString16 ocfpi = mov.get(MOV_OCFPI); - long codcf = mov.get_long(MOV_CODCF); - long numgio = mov.get_long(MOV_NUMGIO); - bool stampato = mov.get_bool(MOV_REGST); - TString16 codval = mov.get(MOV_CODVALI); - real corrval = mov.get_real(MOV_CORRVALUTA); - //bool intra = caus.get_bool(CAU_INTRACOM); //da prendere sul movimento - bool autof = caus.get_bool(CAU_AUTOFATT); - TString80 descrcau = caus.get(CAU_DESCR); - - if (_cur->pos() == 0) - _uprotivap = uprotiva ? uprotiva : protiva; - - //aggiornamento di mov - if (_tipo_stampa != 1) - if (!stampato) - { - mov.put(MOV_REGST,TRUE); - mov.rewrite(); - } - - if (codcf == 0l) - ragsoc = descrcau; - else - { - if (ocfpi.trim().empty()) - { - TRectype dep = ricerca_cf(tipocf, codcf); - ragsoc = dep.get (CLI_RAGSOC); - viacf = dep.get (CLI_INDCF); - civcf = dep.get (CLI_CIVCF); - capcf = dep.get (CLI_CAPCF); - comcf = dep.get (CLI_COMCF); - char tipoa = dep.get_char(CLI_TIPOAPER); - if (tipoa == 'F') - { - TString80 cognome, nome; - cognome = ragsoc.mid(0,30); - nome = ragsoc.mid(30,20); - cognome.trim(); nome.trim(); - ragsoc = cognome; - ragsoc << " " << nome; - } - } - else - { - TRectype dep = ricerca_occ(ocfpi); - ragsoc = dep.get (OCC_RAGSOC); - viacf = dep.get (OCC_INDIR); - civcf = dep.get (OCC_CIV); - capcf = dep.get (OCC_CAP); - comcf = dep.get (OCC_COM); - } - TRectype com = look_comuni(comcf); - comune = com.get(COM_DENCOM); - prov = com.get(COM_PROVCOM); - } - - _tipodoc = mov.get(MOV_TIPODOC); - _descr_doc = descr_doc(); - TString app(datadoc.string(brief, '/')); - - if (stampa_totali_finali()) - _doc_array.add_riga(_tipodoc,_descr_doc,totdoc); - - //setto le righe di stampa - _r = 1; - if (!_stampa_data_reg) - set_row(_r, "%s", (const char* ) _datareg.string(brief, '/')); - set_row(_r, "@9g%5ld", protiva); - if (datadoc.ok()) - set_row(_r, "@15g%s", (const char*) app); - set_row(_r, "@24g%s", (const char*) numdoc); - if (codcf != 0l) - set_row(_r, "@31g%6ld", codcf); - *_desc27 = (const char*) ragsoc; - //set_row(_r, "@38g#a", _desc25); - set_row(_r, "@68g%2s", (const char*) _tipodoc); - if (_stampa_width == 132) - set_row(_r, "@70g%r", &totdoc); - else set_row(_r, "@78g%r", &totdoc); - - if (_tipo_stampa == 1) //in caso di stampa di prova - if (! (_tipo_reg == 1 && _corrispettivi)) //e se non si tratta di registro vendite corrispettivi - if (! (_cur->pos()==0)) //il primo movimento non va controllato - { - if (protiva != _uprotivap + 1) - { - set_row(_r+1, "@2g*** NUM.PROT.FUORI SEQUENZA"); - riga = _r+2; - } - _uprotivap = uprotiva ? uprotiva : protiva; - } - - const char* r; - int i = 1; - while ((r = _desc27->get()) != NULL) - { - set_row (i, "@38g%s", r); - i++; - } - if (i > riga) riga = i; - - if (codcf != 0l && _stampa_ind_comp) - { - //set_row(_r, "@38g%-.27s", (const char*)ragsoc); - if (viacf.not_empty()) //se la via non e' vuota non puo' essere vuoto il comune - { - set_row (/*_r+1*/ i++, "@38g%-.23s %-3s",(const char *)viacf, (const char *)civcf); - set_row (/*_r+2*/ i++, "@38g%s %-.21s", (const char *)capcf, (const char *)comune); - riga = /*_r+3*/ i; - } - else if (comune.not_empty()) - { - set_row (/*_r+1*/ i++, "@38g%s %-.21s", (const char *)capcf, (const char *)comune); - riga = /*_r+2*/ i; - } - } - - _nrec = riga_rmoviva(); - if (_nrec > 0) - { - _esiste_riga_iva = TRUE; - for (int j = 0; j < _riga_rmi.items(); j++) - { - TRigaiva& riga = (TRigaiva&)_riga_rmi[j]; - rr = _r+j; - intra = riga._intra; - if (_stampa_width == 132) - { - set_row(rr, "@85g%r", &riga._imponibile); - set_row(rr, "@101g%4s",(const char*)riga._codiva); - if (_tipo_reg == 2) - set_row(rr, "@106g%d", riga._tipodet); - set_row(rr, "@107g%r", &riga._imposta); - set_row(rr, "@123g%d", riga._tipocr); - if (_tipoatt == "E" && _tipo_reg != 2) - set_row(rr, "@125g%d", riga._tipoatt); - if (_tipo_stampa == 4) //stampa con riferimento al libro giornale - set_row(rr, "@126g%5ld", numgio); - } - else //stampa a 198 - { - set_row(rr, "@93g%r", &riga._imponibile); - set_row(rr, "@109g%4s",(const char*)riga._codiva); - if (_tipo_reg == 2) - set_row(rr, "@114g%d", riga._tipodet); - set_row(rr, "@116g%r", &riga._imposta); - if (_tipoatt == "E" && _tipo_reg != 2) - set_row(rr, "@132g%d", riga._tipoatt); - set_row(rr, "@134g%d", riga._tipocr); - if (_tipo_stampa == 4) //stampa con riferimento al libro giornale - set_row(rr, "@136g%7ld", numgio); - } - } - _riga_rmi.destroy(); - } - - if ( intra && autof) - { - _auto_intraf = TRUE; - tipo_op = "3"; - } - else if (intra) - tipo_op = "1"; - else if (autof) - tipo_op = "2"; - - set_row(_r, "@66g%s", (const char*) tipo_op); - - if (_tipo_stampa == 1) //stampa di prova - { - if (_stampa_width == 132) - { - set_row(_r, "@126g%5ld", numreg); - if (stampato) - set_row(_r, "@131g*"); //solo in stampa di prova! - } - else //198 - { - set_row(_r, "@136g%7ld", numreg); - if (stampato) - set_row(_r, "@144g*"); - } - } - if (_tipo_stampa == 4 && _stampa_width == 198) - { - TLocalisamfile rmoviva (LF_RMOVIVA); - rmoviva.zero(); - rmoviva.put(RMI_NUMREG,numreg); - TRectype rec(rmoviva.curr()); - rmoviva.read(_isgteq); - for ( ; !rmoviva.eof(); rmoviva.next()) - { - if (rmoviva.curr() != rec) break; - - int gruppo = rmoviva.get_int("GRUPPO"); - int conto = rmoviva.get_int("CONTO"); - long sottoc = rmoviva.get_long("SOTTOCONTO"); - TConto tc (gruppo,conto,sottoc); - TString80 descr = tc.descrizione(); - set_row(_r, "@144g%3d %3d %6d", gruppo, conto, sottoc); - set_row(_r, "@159g%-.39s", (const char*) descr); - break; - } - } - - if (riga <= rr) riga = ++rr; - - if (corrval != ZERO) - { - TString vall (corrval.string("###.###.###.###,@@")); - set_row(riga, "@24gCodice valuta %-3s Corrispettivo in valuta %s", (const char*) codval, (const char*) vall); - } - } - return TRUE; -} - -void CG4400_application::scrivi_reg() -{ - TString16 codtab; - TTable Tabreg ("REG"); - - codtab << _annoes << _codreg; - Tabreg.zero(); - Tabreg.put("CODTAB", codtab); - if (Tabreg.read() == NOERR) - { - const TDate d = Tabreg.get_date("D3"); - if (!_mov_empty) //cioe' se e' stata stampata almeno una pagina - { -// TDate ultima_data = format("%02d/%02d/%4d", _datareg.last_day(_datareg.month(), _annoes), _datareg.month(), _annoes); - TDate ultima_data(_datareg); - ultima_data.set_end_month(); // Meglio cosi' - - if (ultima_data > d) - Tabreg.put("D3", ultima_data); - } - else if (_data_a > d) - Tabreg.put("D3", _data_a); - - if (_tipo_reg == 2 && _stampa_cred_pre) - if (_mese_credito == 0 && _credito > ZERO) - if (_mov_empty) - Tabreg.put("I8", (long)_fino_a_mese); - else Tabreg.put("I8", (long)_datareg.month()); - - Tabreg.rewrite(); - } - - if (_tipo_stampa == 3) - { - TString16 cod = ""; - TTable lbu ("%LBU"); - - cod << _annoes << _codlib; - lbu.zero(); - lbu.put("CODTAB", cod); - if (lbu.read() == NOERR) - { - lbu.put("I0", (long) _fino_a_mese); - lbu.rewrite(); - } - } -} - -void CG4400_application::aggiorna_reg(const bool aggiorna_vidi) -{ - TString16 codtab; - TTable Tabreg ("REG"); - TLocalisamfile IndBil (LF_INDLIB); - - codtab << _annoes << _codreg; - Tabreg.zero(); - Tabreg.put("CODTAB", codtab); - if (Tabreg.read() == NOERR) - { - TDate d = Tabreg.get_date("D3"); - if (!_mov_empty) //cioe' se e' stata stampata almeno una pagina - { -// TDate ultima_data = format("%02d/%02d/%4d", _datareg.last_day(_datareg.month(), _annoes), _datareg.month(), _annoes); - TDate ultima_data(_datareg); - ultima_data.set_end_month(); // Meglio cosi' - - if (ultima_data > d) - Tabreg.put("D3", ultima_data); - } - else if (_data_a > d) - Tabreg.put("D3", _data_a); - - Tabreg.put("I1", _pagine_stampate); - - if (_intesta_liq) - if (_tipo_riepilogativo == 'A') - Tabreg.put("I4", 13L); - else Tabreg.put("I4", (long)_datareg.month()); - - if (_tipo_reg == 2 && _stampa_cred_pre) - if (_mese_credito == 0 && _credito > ZERO) - if (_mov_empty) - Tabreg.put("I8", (long)_fino_a_mese); - else Tabreg.put("I8", (long)_datareg.month()); - - Tabreg.rewrite(); - } - - if (_tipo_stampa == 3) //stampa su libro unico - - // sul file indlib (indice libro unico) devo generare una riga per ogni - // registro stampato (ricordarsi che la stampa su libro unico deve - // avvenire mese per mese!) - // inoltre non posso stampare due volte lo stesso mese perche' la stampa - // avviene a fine mese - - { - long numero_riga = 1L; - if (!aggiorna_vidi) - { - bool trovato = FALSE; - //long ditta = get_firm(); - - IndBil.zero(); - - TRectype nuovo (IndBil.curr()); - - IndBil.put("ANNO", _annoes); - IndBil.put("CODLIB", _codlib); - TRectype rec (IndBil.curr()); - - for (IndBil.read(_isgteq); !IndBil.eof(); IndBil.next()) - { - if (IndBil.curr() != rec) break; - - int annoreg = IndBil.get_int("ANNOREG"); - int mesereg = IndBil.get_int("MESEREG"); - long cditta = IndBil.get_long("CODDITTA"); - TString16 codreg = IndBil.get("CODREG"); - TString16 codvid = IndBil.get("CODVID"); - if (_annoes == annoreg && _fino_a_mese == mesereg - && _ditta == cditta && codreg == _codreg && _codice_vidi == codvid) - { - trovato = TRUE; - numero_riga = IndBil.get_long("NUMREG"); - break; - } - else numero_riga = IndBil.get_long("NUMREG") + 1; - // cosi' mi posiziono su quel mese (altrimenti rischio di generare - // due righe per lo stesso mese e registro => la stampa di vidimazione - // mi sballa tutta!!! - } - nuovo.put("ANNO", _annoes); - nuovo.put("CODLIB", _codlib); - nuovo.put("NUMREG", numero_riga); - - nuovo.put("ANNOREG", _annoes); - nuovo.put("MESEREG", _fino_a_mese); // su libro unico ho un solo mese in gioco! - nuovo.put("PAGINI", _primast + 1); // numero iniziale pagina libro unico - nuovo.put("PAGFIN", _u_stampata); // numero finale pagina libro unico - nuovo.put("CODDITTA", _ditta); - nuovo.put("CODREG", _codreg); - nuovo.put("CODVID", _codice_vidi); - nuovo.put("PAGINIUT", _numini + 1); - nuovo.put("PAGFINUT", _pagine_stampate); - - if (!trovato) - IndBil.write(nuovo); - else IndBil.rewrite(nuovo); - } - //_primast = _u_stampata; //per la numerazione dei registri successivi - aggiorna_lib(); - } -} - -void CG4400_application::aggiorna_lib() -{ - TString16 cod = ""; - TTable lbu ("%LBU"); - - cod << _annoes << _codlib; - lbu.zero(); - lbu.put("CODTAB", cod); - if (lbu.read() == NOERR) - { - lbu.put("I0", (long) _fino_a_mese); - lbu.put("I1", (long) _u_stampata); - lbu.rewrite(); - } -} - -bool CG4400_application::stampo_liquidazione(int mese) -{ - //test tradotti alla lettera da AS/400 - //assolutamente incongruenti !!! - if (_tipo_stampa == 1) - { - if ( (_frequiva == 'T' && (mese == 3 || mese == 6 || mese == 9 || mese == 12)) - || _frequiva != 'T' || (mese == 12 && _tipo_riepilogativo == 'A') ) - return TRUE; - } - else - { - if ( (_frequiva == 'T' && (mese == 3 || mese == 6 || mese == 9 || mese == 12)) - || _frequiva != 'T' || (mese == 12 && _tipo_riepilogativo == 'A') ) - if ( (mese == 12 && _tipo_riepilogativo == 'A' && _mese_ultima_liq != 13) - || (mese != 12 && mese > _mese_ultima_liq) - || (mese == 12 && _tipo_riepilogativo != 'A' && mese > _mese_ultima_liq) ) - return TRUE; - } - return FALSE; -} - -void CG4400_application::stampa_vidi() -{ - TLocalisamfile IndBil (LF_INDLIB); - TTable TabVid ("%VID"); - TString16 codreg; - TString16 vid; - long ditta, pagfin, pagfinut; - int mese; - TPrintrow row; - - _ok_vidi = FALSE; - - if (!printer().isopen()) - printer().open(); - - IndBil.zero(); - IndBil.put("ANNO", _annoes); - IndBil.put("CODLIB", _codlib); - TRectype rec (IndBil.curr()); - IndBil.read (_isgteq); - for (; !IndBil.eof(); IndBil.next()) - { - if (IndBil.curr() != rec) break; - ditta = IndBil.get_long("CODDITTA"); - codreg = IndBil.get("CODREG"); - if (ditta == _ditta && codreg == _codreg) - { - if (!_ok_vidi) - { - ++_u_stampata; - ++_pagine_stampate; - _ok_vidi = TRUE; - } - mese = IndBil.get_int("MESEREG"); - pagfin = IndBil.get_long("PAGFIN"); - pagfinut = IndBil.get_long("PAGFINUT"); - if (mese == 12) - { - ++pagfin; - ++pagfinut; - TRectype nuovo (IndBil.curr()); - nuovo.put("PAGFIN", pagfin); - nuovo.put("PAGFINUT", pagfinut); - IndBil.rewrite(nuovo); - } - row.reset(); - row.put(format("%s", itom(mese)), 0); - row.put(format("%5ld", IndBil.get_long("PAGINI")), 10); - row.put(format("%5ld", pagfin), 17); - row.put(format("%5ld", IndBil.get_long("PAGINIUT")), 25); - row.put(format("%5ld", pagfinut), 32); - vid = IndBil.get("CODVID"); - TabVid.zero(); - TabVid.put("CODTAB", vid); - if (TabVid.read() == NOERR) - { - row.put(format("%s", (const char*)TabVid.get("S0")), 39); - row.put(format("%7d",TabVid.get_long("I0")), 71); - row.put(format("%7d",TabVid.get_long("I1")), 79); - row.put(format("%7d",TabVid.get_long("I2")), 87); - TDate d(TabVid.get_long("D0")); - row.put(format("%s", (const char*)d.string()), 95); - row.put(format("%s", (const char*)TabVid.get("S1")), 106); - } - printer().print(row); - } - } - printer().close(); -} - -void CG4400_application::liq_b0_settato() -{ - TFilename f; - f.temp("rg"); - if (_tipo_stampa == 1) - send_message('S',f, _datareg.month()); - else send_message('s',f, _datareg.month()); - //TString80 nomef; - //nomef = f.path(); nomef << "\\" << f.name(); - //if (fexist(nomef)) - if (fexist(f)) - { - printer().formfeed(); - _intesta_liq = TRUE; - //printer().footerlen(0); - merge_export_file(f,FALSE,TRUE); - _intesta_liq = FALSE; - remove(f); - } -} - -void CG4400_application::liq_other_case() -{ - if (_scelta == prosegui_cal_stampa) - { - if (stampo_liquidazione(_datareg.month())) - { - _t.temp("reg"); - if (_tipo_stampa == 1) - send_message('L', _t, _datareg.month()); - else send_message('l', _t, _datareg.month()); - } - else //se chiamo la liquidazione con L o l mi calcola anche i progressivi - if (_tipo_stampa != 1) - { - TFilename app; - app.temp(); - send_message('C', app, _datareg.month()); - } - } - if (_scelta == prosegui_stampa) - { - if (stampo_liquidazione(_datareg.month())) - { - _t.temp("reg"); - if (_tipo_stampa == 1) - send_message('S', _t, _datareg.month()); - else send_message('s', _t, _datareg.month()); - } - if (_tipo_stampa != 1) //in stampa di prova i progressivi me li calcolo io!!! - { //Why??? - TFilename app; - app.temp(); - send_message('C', app, _datareg.month()); - } - } - if (_scelta == no_liquidazione && _tipo_stampa != 1) - { - TFilename app; - app.temp(); - send_message('C', app, _datareg.month()); - } -} - -print_action CG4400_application::postprocess_page (int file, int counter) -{ - if (file == LF_MOV) - { - if (counter) //dopo aver fatto un REPEAT_PAGE (cioe' dopo aver stampato le righe settate in set_page_tot_reg()), in pratica a rottura di mese o alla fine - { - reset_print(); - if (_liquidazione) - if (!_st_liq[_datareg.month()] && stampo_liquidazione(_datareg.month())) - { - _st_liq[_datareg.month()] = TRUE; - if (_scelta == B0_settato) - liq_b0_settato(); - if (_scelta == prosegui_stampa || _scelta == prosegui_cal_stampa) - { - if (fexist(_t)) - { - printer().formfeed(); - _intesta_liq = TRUE; - //printer().footerlen(0); - merge_export_file(_t,FALSE,TRUE); - _intesta_liq = FALSE; - remove(_t); - } - } - } - //modifica del 26/07/1995 - TRecnotype pos = _cur->pos(); - long items = _cur->items(); - if (pos == items-1) - if (_tipo_stampa != 3 && _liquidazione) - stampa_liq_mesi_succ(); - //fine modifica - } - if (!counter) - { - bool FINITO = FALSE; - TRecnotype pos = _cur->pos(); - long items = _cur->items(); - - FINITO = (pos == items-1); - - if ( FINITO ) - { - liq_other_case(); - if (_tipo_stampa != 1) - calcola_progressivi(); - set_page_tot_reg(); - return REPEAT_PAGE; - } - else - { - TLocalisamfile& mov = _cur->file(LF_MOV); - _cur->save_status(); - ++(*_cur); - _dataregs = mov.get_date(MOV_DATAREG); - --(*_cur); - _cur->restore_status(); - - if (_dataregs.month() != _dataregp.month()) - { - liq_other_case(); - if (_tipo_stampa != 1) - calcola_progressivi(); - set_page_tot_reg(); - return REPEAT_PAGE; - } - } - } - } - return NEXT_PAGE; -} - -bool CG4400_application::set_print(int n) -{ - TMask m ("cg4400a"); - int giorni_del_mese; - bool ok; - - m.set_handler (TIPO_STAMPA, mask_tipo_stampa); - m.set_handler (DA_DATA, mask_data); - m.set_handler (A_DATA, mask_data); - m.set_handler (MESE, mask_mese); - m.set_handler (FINO_A_MESE, mask_mese); - m.set_handler (CODICE_LIB_UN, mask_cod); - m.set_handler (CODICE_LIBRO_IVA, mask_libun); - m.set_handler (DLG_SELECT, mask_select); - m.set_handler (F_ANNULLA, mask_azzera); - m.set_handler (A_CODICE, to_ditt_handler); - m.set_handler (DA_CODICE, fr_ditt_handler); - m.set_handler (BUT_DTO, to_butt_handler); - m.set_handler (BUT_DFR, fr_butt_handler); - m.set_handler (ANNO, year_handler); - - m.field(F_SELECT).set(format("%ld",_selected.ones())); - set_choice_limits(m); - - //printer().footerlen(5); - set_real_picture("###.###.###.###"); - - while (ok = set_ditte(m)) - { - if (_selected.ones() > 0l) - { - _annoes = m.get_int(ANNO);//in realta' e' l'anno IVA !!! - _tipo_stampa = m.get_int(TIPO_STAMPA); - _stampa_width = m.get_int(STAMPA_WIDTH); - _stampa_len = m.get_int(STAMPA_LEN); - if (_stampa_width == 1) - _stampa_width = 132; - else _stampa_width = 198; - if (_stampa_len != 0) - printer().formlen(_stampa_len); - //Se stampa di prova l'utente indica data_da e data_a - if (_tipo_stampa == 1) - { - _data_stampa = m.get(DATA_STAMPA); - _data_da = m.get(DA_DATA); - _data_a = m.get(A_DATA); - - if (!_data_da.ok()) -// _data_da = format("01/01/%4d", _annoes); - _data_da = TDate(1, 1, _annoes); // Meglio cosi' - - if (!_data_a.ok()) -// _data_a = format("31/12/%4d", _annoes); - _data_a = TDate(31, 12, _annoes); // Meglio cosi' - - const TDate d(31,12,_annoes); - if (_data_a == d) - _tipo_riepilogativo = m.get(TIPO_RIEPILOGATIVO)[0]; - else _tipo_riepilogativo = ' '; - printer().setdate(_data_stampa); - } - else //stampe definitive - { - if ( (_tipo_stampa == 2) || (_tipo_stampa == 4) ) - { - _fino_a_mese = m.get_int(FINO_A_MESE); -// _data_da = format("01/01/%4d", _annoes); //e non ultima data di stampa del registro (come invece verrebbe spontaneo di pensare) - _data_da = TDate(1, 1, _annoes); // Meglio cosi' - } - else //stampa su libro unico - { - _codlib = m.get(CODICE_LIB_UN); - _fino_a_mese = m.get_int(MESE); - _u_stampata = m.get_int(ULTIMA_PAGINA); - _rif_vid = m.get_bool(RIF_VID); - _primast = _u_stampata; -// _data_da = format("01/%02d/%04d", _fino_a_mese, _annoes); - _data_da = TDate(1, _fino_a_mese, _annoes); // Meglio cosi' - } - if (_fino_a_mese == 12) - { - giorni_del_mese = 31; - _tipo_riepilogativo = m.get(TIPO_RIEPILOGATIVO)[0]; - } - else - { - _tipo_riepilogativo = ' '; -// TDate primo = format("01/%02d/%4d", _fino_a_mese+1, _annoes); -// --primo; - TDate primo(1, _fino_a_mese, _annoes); - primo.set_end_month(); // Meglio cosi' - - giorni_del_mese = primo.day(); - } -// _data_a=format("%02d/%02d/%4d",giorni_del_mese,_fino_a_mese,_annoes); - _data_a = TDate(giorni_del_mese, _fino_a_mese, _annoes); // Meglio cosi' - } - _stampa_data_reg = stampa_datareg(); - if (_tipo_stampa == 3) - compila_lib(); - stampa_registri_IVA(m); - } - else - { - warning_box("Nessuna ditta selezionata!"); - continue; - } - } - return FALSE; -} - -bool CG4400_application::look_lia(long ditta) -{ - if (ditta == 0l) ditta = get_firm(); - - TString16 y; y.format("%05ld%04d", ditta, _annoes); - - _tablia->zero(); - _tablia->put("CODTAB", y); - _tablia->read(); - const bool ok = _tablia->good(); - if (ok) - _credito = _tablia->get_real("R0"); - else _credito = ZERO; - return ok; -} - -void CG4400_application::look_reg() -{ - _liquidazione = _tabreg->get_bool("B7"); - _riep_liq = _tabreg->get_bool("B6"); - _corrispettivi = _tabreg->get_bool("B0"); - _sosp_imposta = _tabreg->get_bool("B1"); - _pagine_stampate = _tabreg->get_long("I1"); - _numini = _pagine_stampate; - _cod_un_loc = _tabreg->get_int("I7"); - _mese_ultima_liq = _tabreg->get_int("I4"); - _mese_credito = _tabreg->get_int("I8"); - _codatt = _tabreg->get("S8"); - _tipoatt = tipo_attivita(); - _attivita = desc_attivita(); - _desc_lib = _tabreg->get ("S0"); - _stampa_ind_ditta = _tabreg->get_bool ("B9"); - _stampa_ind_comp = _tabreg->get_bool ("B5"); - _stampa_cred_pre = _tabreg->get_bool ("B4"); -} - -void CG4400_application::clear_stliq() -{ - for (int i=0; i <= 12; i++) - _st_liq[i] = FALSE; -} - -bool CG4400_application::setta_mask(long i) -{ - if (_stampa_mese == 13) _stampa_mese = 0; - if (_tipo_stampa == 2 || _tipo_stampa == 4) - { - TMask mb("cg4400b"); - mb.set(F_CODDITTA, _ditta); - mb.set(F_RAGSOC, _ditte->row(i).get(2)); - mb.set(COD_LIB, _codreg); - const char* m = ""; - m = format("%02d", _stampa_mese); - mb.set(U_MESE, m); - mb.set(U_PAGINA, _pagine_stampate); - if (_u_data.ok()) - mb.set(U_DATA, _u_data.string()); - KEY tasto = mb.run(); - if (tasto != K_ENTER) return FALSE; - } - return TRUE; -} - -void CG4400_application::no_movimenti() -{ - _mov_empty = TRUE; - if (_liquidazione) - { - int da, a; - //stampo la liquidazione per tutti i mesi fino a _fino_a_mese - if (_tipo_stampa == 2 || _tipo_stampa == 4) - da = 1; - if (_tipo_stampa == 3) - da = _fino_a_mese; - if (_tipo_stampa == 1) - da = _data_da.month(); - if (_tipo_stampa == 1) - a = _data_a.month(); - else a = _fino_a_mese; - for (int m = da; m <= a; m++) - { - if (stampo_liquidazione(m)) - { - if (! printer().isopen()) - printer().open(); - TFilename f; - f.temp("rgp"); -// _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header - _datareg = TDate(1, m, _annoes); // Meglio cosi' - - if (_scelta == B0_settato || _scelta == prosegui_stampa) - { - if (_tipo_stampa == 1) - send_message('S',f, m); - else send_message('s',f, m); - } - else //_scelta == prosegui_cal_stampa - { - if (_tipo_stampa == 1) - send_message('L', f, m); - else send_message('l', f, m); - } - if (fexist(f)) - { - _intesta_liq = TRUE; - //printer().footerlen(0); - merge_export_file(f,FALSE,TRUE); - printer().formfeed(); - _intesta_liq = FALSE; - remove(f); - } - } - } - if (printer().isopen()) printer().close(); - } - if (_tipo_stampa != 1) scrivi_reg(); //aggiorno il registro anche se non ho stampato proprio nulla per quel mese! -} - -bool CG4400_application::stampa_registri_IVA(const TMask& m) -{ - bool ok = FALSE; - for (int i = 0; i < _ditte->items(); i++) - { - if (_selected[(long)i]) - { - bool msg = TRUE; - _ditta = _ditte->row(i).get_long(1); - _frequiva = _ditte->row(i).get_char(3); - _intesta_liq = FALSE; - _intesta_vidi = FALSE; - _primast = _u_stampata; - _ok_vidi = FALSE; - _stampa_mese = 13; - - TApplication::set_firm(_ditta); - look_lia(); - ok = compila_reg(m); - if (!ok) continue; - if (_tipo_stampa == 2 || _tipo_stampa == 4) - if (!controlla_mov()) - { - TApplication::set_firm(__firm); - return fatal_box("Finire di stampare registri anno precedente"); - } - if (!_stampa_tutti_i_registri) - { - _scelta = controlla_b0(); - _cur->set_filterfunction(filter_func); - ok = setta_mask(i); - if (!ok) continue; - if (_liquidazione) - { - if (_tipo_stampa == 2 || _tipo_stampa == 4) - _size_header = _stampa_ind_ditta ? 3 : 2; - else _size_header = 3; - clear_stliq(); - _scelta = controlla_liquidazione(); - if (_scelta == non_proseguire) - return FALSE; - } - - (*_cur) = 0L; //la filter function viene chiamata quando posiziono il cursore - const long item = _cur->items(); - - // 17.5.95 Leggo parametri di stampa del registro - TString16 config; - const long codditta = get_firm(); - const char* reg = (const char*)_codreg; - config.format("REG%05ld%03s", codditta, reg); - printer().read_configuration(config); - - if (item > 0l) - { - //modifica del 26/07/1995 - _mov_empty = TRUE; - //fine - - print(); - - if (is_cancelled()) return FALSE; - - /*** - if (_tipo_stampa != 3 && _liquidazione) - stampa_liq_mesi_succ(); - ***/ - } - //non ci sono movimenti da stampare nel periodo richiesto! - else no_movimenti(); - - if (_tipo_stampa == 3 && _rif_vid) - { - _intesta_vidi = TRUE; - stampa_vidi(); //stampa riferimenti vidimazione - } - } - else //stampa tutti i registri - { - TString16 codtab, cod_lib_un; - int anno; - TDate sca_vid; - for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) - { - _tipo_reg = _tabreg->get_int("I0"); - codtab = _tabreg->get("CODTAB"); - anno = atoi(codtab.mid(0,4)); - if (anno > _annoes) - break; - if (anno == _annoes) - if ( _tipo_reg == 1 || _tipo_reg == 2 ) //registro iva - { - _codreg = codtab.mid(4,3); - cod_lib_un = _tabreg->get("S6"); - sca_vid = _tabreg->get_date("D1"); - _stampa_ind_ditta = _tabreg->get_bool("B9"); - _liquidazione = _tabreg->get_bool("B7"); - if (_tipo_stampa != 1) - _u_data = _tabreg->get_date("D3"); - if (_tipo_stampa == 2 || _tipo_stampa == 4) - { - if (cod_lib_un.not_empty()) - continue; - if (sca_vid.ok()) - if (sca_vid.month() < _fino_a_mese) - continue; - if (_u_data.ok()) - if (_data_a < _u_data) //e' molto imp. che rimanga < e non <= !!! - { //(per via del discorso liq. annuale) - message_box("Ditta %ld: Il registro %s e' gia' stato stampato come bollato di %s", _ditta, (const char*) _codreg, itom(_fino_a_mese)); - continue; - } - } - if (_tipo_stampa == 4) //stampa con riferimenti al libro giornale - { - TString16 d; - bool good; - TRecnotype rec = _tabreg->recno(); - bool trovato = cerca_libro_gio(d, &good); - _tabreg->readat(rec); - if (!trovato) - continue; - } - if (_tipo_stampa == 3) //stampa su libro unico - { - if (cod_lib_un != _codlib) - continue; - if (sca_vid.ok()) - if (sca_vid.month() < _fino_a_mese) - continue; - if (_u_data.ok()) - if (_fino_a_mese < _u_data.month()) //significa che e' gia' - continue; //stato stampato - } - msg = FALSE; - - look_reg(); - - _intesta_liq = FALSE; - _intesta_vidi = FALSE; - _primast = _u_stampata; //per la numerazione dei registri successivi - _ok_vidi = FALSE; - _stampa_mese = 13; - _scelta = controlla_b0(); //sul registro non va stampata la liq. ma comunque - //va richiamata per il calcolo progressivi (a seconda di b0) - //se non e' stampa di prova - ok = setta_mask(i); - if (!ok) continue; - - if (_liquidazione) - { - if (_tipo_stampa == 2 || _tipo_stampa == 4) - _size_header = _stampa_ind_ditta ? 3 : 2; - else _size_header = 3; - clear_stliq(); - _scelta = controlla_liquidazione(); - if (_scelta == non_proseguire) - return FALSE; - } - - _cur->set_filterfunction(NULL); - _cur->set_filterfunction(filter_func); - - // Vado a vedere se ci sono movimenti - (*_cur) = 0L; - const long items = _cur->items(); - - // 17.5.95 Leggo parametri di stampa del registro - TString16 config; - const long codditta = get_firm(); - const char* reg = (const char*)_codreg; - config.format("REG%05ld%03s", codditta, reg); - printer().read_configuration(config); - - if (items > 0l) - { - //modifica del 26/07/1995; - _mov_empty = TRUE; - //fine - - print(); - - if (is_cancelled()) return FALSE; - - /*** - if (_tipo_stampa != 3 && _liquidazione) - stampa_liq_mesi_succ(); - ***/ - } - else - no_movimenti(); - - if (_tipo_stampa == 3 && _rif_vid) - { - _intesta_vidi = TRUE; - stampa_vidi(); //stampa riferimenti vidimazione - } - } - } //for - if (msg) - //if ( (_tipo_stampa != 3) || (_tipo_stampa == 3 && _fino_a_mese == 1 && _selected.ones() == 1L) ) //il messaggio seguente, nel caso di stampa su libro unico, - if(_tipo_stampa == 3 && _fino_a_mese == 1 && _selected.ones() == 1L) - message_box("Ditta %ld: nessun registro soddisfa i parametri indicati", _ditta); //viene gia' dato nell'handler - } //da Gennaio) - } - } - TApplication::set_firm(__firm); - return TRUE; -} - - -void CG4400_application::stampa_liq_mesi_succ() -{ - int da = _datareg.month() + 1; - int a = _data_a.month(); - for (int m = da; m <= a; m++) - { - if (stampo_liquidazione(m)) - { - /* - if (!printer().isopen()) - printer().open(); - */ -// _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header (intestazione per la stampa liquidazione) - _datareg = TDate(1, m, _annoes); // Meglio cosi' - TFilename t; - t.temp("iva"); - if (_tipo_stampa == 1) - send_message('L',t, m); //prima era S ma non andava bene! - else send_message('l',t,m); //prima era s - //TString80 nomef; nomef = t.path(); nomef << "\\" << t.name(); - //if (fexist(nomef)) - if (fexist(t)) - { - _intesta_liq = TRUE; - printer().formfeed(); - //printer().footerlen(0); - merge_export_file(t,FALSE,TRUE); - _intesta_liq = FALSE; - remove(t); - } - } - } - //if (printer().isopen()) printer().close(); -} - -void CG4400_application::send_message(char tipo, const TFilename& nome, int mese) -{ - const char* app; - - if (tipo == 'S' || tipo == 's') - app = "cg4 -2 -S"; - else if (tipo == 'C') - app = "cg4 -2 -C"; - else app = "cg4 -2"; - - TToken_string ss(10); - - ss.add(_annoes); - if (_tipo_riepilogativo == 'A' && mese == 12) - ss.add(13); - else ss.add(mese); - ss.add(_ditta); - ss.add(tipo); - ss.add(_data_stampa.string()); - ss.add(nome); - ss.add(_size_header); - //ss.add("x"); - - TMessage liq (app, "RCL", ss); - liq.send(); - - TExternal_app pn(app); - pn.run(); -} - -bool CG4400_application::set_ditte(TMask& m) -{ - /* - _selected.reset(); - m.field(F_SELECT).set("0"); - m.field(DA_CODICE).set(""); - m.field(A_CODICE).set(""); - */ - m.field(TIPO_STAMPA).set("1"); - m.field(DA_DATA).set(""); - m.field(A_DATA).set(""); - m.field(CODICE_LIBRO_PROVA).set(""); - - KEY tasto; - tasto = m.run(); - // m.first_focus(tasto); - return tasto == K_ENTER; -} - -TRectype& CG4400_application::look_comuni (const char * cod) -{ - _com->zero(); - _com->put(COM_COM, cod); - _com->read(); - if (_com->bad()) - _com->zero(); - - return _com->curr(); -} - -void CG4400_application::get_dati_ditta() -{ - TLocalisamfile nditte(LF_NDITTE); - TLocalisamfile anag(LF_ANAG); - TLocalisamfile unloc(LF_UNLOC); - TString codanagr; - TString tipoa; - - nditte.zero(); - nditte.put(NDT_CODDITTA, get_firm()); - nditte.read(); - - if (nditte.bad()) nditte.zero(); - - codanagr = nditte.get(NDT_CODANAGR); - tipoa = nditte.get(NDT_TIPOA); - _ragsoc = nditte.get(NDT_RAGSOC); - - anag.setkey(1); - anag.zero(); - anag.put (ANA_TIPOA, tipoa); - anag.put (ANA_CODANAGR, codanagr); - anag.read(); - if (anag.bad()) anag.zero(); - - _cofi = anag.get(ANA_COFI); - _paiva = anag.get(ANA_PAIV); - _comunefis = anag.get(ANA_COMRF); - - if (_comunefis.empty()) - _comunefis = anag.get(ANA_COMRES); - - TRectype dep = look_comuni (_comunefis); - - _comunefis = dep.get(COM_DENCOM); - _provfis = dep.get(COM_PROVCOM); - _cap = dep.get(COM_CAPCOM); - if (_comunefis.empty()) - { - _viafis = anag.get(ANA_INDRF); - _viafis.rtrim(); - _viafis << " " << anag.get (ANA_CIVRF); - } - else - { - _viafis = anag.get(ANA_INDRES); - _viafis.rtrim(); - _viafis << " " << anag.get (ANA_CIVRES); - } - - if (_cod_un_loc) - { - unloc.zero(); - unloc.put(ULC_CODDITTA, get_firm()); - unloc.put(ULC_CODULC, _cod_un_loc); - unloc.read(); - if (unloc.read() == NOERR) - { - TRectype dep = look_comuni (unloc.get(ULC_COMULC)); - _comunefis = dep.get(COM_DENCOM); - _provfis = dep.get(COM_PROVCOM); - _cap = dep.get(COM_CAPCOM); - _viafis = unloc.get(ULC_INDULC); - _viafis.rtrim(); - _viafis << " " << unloc.get(ULC_CIVULC); - } - } -} - -int CG4400_application::stampa_intestazione() -{ - int r = 1; - TString codice_ditta; - TString riga(_stampa_width); - - get_dati_ditta(); - codice_ditta << get_firm(); - - set_header (r, "Ditta %s %s %s %s %s %s", (const char*)codice_ditta, - (const char*)_ragsoc, (const char*)_viafis, - (const char*)_cap, (const char*)_comunefis, - (const char*)_provfis); - r++; - //printer().setdate(_data); - if (_tipo_stampa == 1) - { - riga = "REGISTRO DI PROVA Data @<"; - riga.right_just(_stampa_width-6); - } - riga.overwrite (format("Partita iva %s Codice fiscale %s", (const char*)_paiva, (const char*)_cofi)); - set_header (r, riga); - - return r; -} - -void CG4400_application::preprocess_header() -{ - int r=1; - char cor, nd1, nd2; - char tipo = ' '; - char type = ' '; - int mese, anno; - TString riga(_stampa_width); - TString data(30); - - riga.fill('-'); - - if (_tipo_stampa != 3) - { - mese = _datareg.month(); - anno = _datareg.year(); - } - else //se _tipo_stampa == 3 (su libro unico) sto stampando un solo mese - { - mese = _fino_a_mese; - anno = _annoes; - } - - data.format("%s %s %d", "mese di", itom(mese), anno); - - reset_header(); - - if (_tipo_stampa == 2 || _tipo_stampa == 4) - { - if (_stampa_ind_ditta) - r = stampa_intestazione(); - } - else // se stampa di prova o su libro unico l'intestazione della ditta - // va sempre stampata - r = stampa_intestazione(); - - if (_tipo_stampa == 3 && !_intesta_vidi) - { - ++_u_stampata; - ++_pagine_stampate; - } - - if (_tipo_stampa == 2 || _tipo_stampa == 4) - ++_pagine_stampate; - - if (_tipo_stampa == 3) - set_header(r, "@94gProgr.Studio %ld@114gProgr.Utente %ld", _u_stampata, _pagine_stampate); - - // cosi' sono sicura che l'aggiornamento viene fatto ad ogni salto pagina - // (cioe' a rottura di mese) - if (_tipo_stampa != 1) aggiorna_reg(_ok_vidi); - - r++; - - /* - if (!_intesta_vidi) - set_header(r, "Registro IVA: %s %s %s Attivita\' %s %s", - (const char *) _codreg, (const char *) _desc_lib, - (const char *) data, (const char *) _codatt, - (const char *) _attivita); - */ - if (!_intesta_vidi) - { - if (_intesta_liq) - set_header(r, "Registro IVA: %s %s %s", (const char*)_codreg, - (const char*)_desc_lib, (const char*) data); - else set_header(r, "Registro IVA: %s %s %s Attivita\' %s %s", - (const char*) _codreg, (const char*) _desc_lib, - (const char*) data, (const char*) _codatt, - (const char*) _attivita); - } - else - { - set_header(r++, "Registro IVA: %s %s", (const char *) _codreg, (const char *) _desc_lib); - set_header(r, "RIFERIMENTI VIDIMAZIONE"); - } - - if (_intesta_liq) - { - /* - r++; - set_header(r++, "CALCOLO LIQUIDAZIONE IVA"); - set_header(r++,riga); - TString title (80); - title << "Liquidazione IVA "; - if (_tipo_riepilogativo == 'A' && mese == 12) - title << "Annuale " << format("%d", anno); - else - { - title << "del periodo"; - title << format(" %s %d", itom(mese), anno); - } - set_header(r++, "%s@102g Frequenza %s", (const char*) title, _frequiva == 'T' ? "T" : "M"); - set_header(r++,riga); - set_header(r,""); - */ - } - else //non sto stampando la liquidazione - { - r++; - set_header(r, riga); - r++; - if (_tipo_reg == 1) //registro vendite - { - cor = 'R'; - nd1 = ' '; - nd2 = ' '; - } - if (_tipo_reg == 2) - { - cor = 'C'; - nd1 = 'N'; - nd2 = 'D'; - } - if (_tipoatt == "E") //attivita' mista - { - tipo = 'A'; - type = 'T'; - } - /* - if ((!_stampa_data_reg) && _stampa_width == 132) - set_header(r,"Data I/P"); - */ - if (_tipo_stampa == 1) //stampa di prova (_intesta_vidi e' di sicuro FALSE) - { - if (_stampa_width == 132) - { - set_header(r,"@10gNum.@19gDocumento@66gT Tipo@102gCod %c@123gT %c@128gNum", nd1, tipo); - r++; - set_header(r, "Data reg. prot.@17gData@24gNumero Codice Ragione sociale/descrizione@66gO Doc.@74gTotale doc.@90gImponibile Iva %c@115gImposta@123g%c %c@128gReg", nd2, cor, type); - r++; - } - else //stampa a 198 - { - set_header(r,"Registrazione Documento@66gT Tipo@110gCod %c@132g%c T@139gNum.", nd1, tipo, cor); - r++; - set_header(r, "Data Protocollo Data@24gNumero Codice Ragione sociale/descrizione@66gO Documento@80gTot.Documento@98gImponibile Iva %c@124gImposta@132g%c %c@139gReg.", nd2, type, cor); - r++; - } - } - else if (!_intesta_vidi) - { - if (_stampa_width == 132) - { - set_header(r,"@10gNum.@19gDocumento@66gT Tipo@102gCod %c@123gT %c", nd1, tipo); - if (_tipo_stampa == 4) //stampa definitiva con rif. al libro giornale - set_header(r, "@128gNum."); - r++; - set_header(r, "Data reg. prot.@17gData@24gNumero Codice Ragione sociale/descrizione@66gO Doc.@74gTotale doc.@90gImponibile Iva %c@115gImposta@123g%c %c", - nd2, cor, type); - if (_tipo_stampa == 4) - set_header(r, "@128gop."); - r++; - } - else //stampa a 198 - { - set_header(r,"Registrazione Documento@66gT Tipo@110gCod %c@132g%c T", nd1, tipo); - if (_tipo_stampa == 4) - set_header(r, "@139gNum."); - r++; - set_header(r, "Data Protocollo Data@24gNumero Codice Ragione sociale/descrizione@66gO Documento@80gTot.Documento@98gImponibile Iva %c@124gImposta@132g%c %c", nd2, type, cor); - if (_tipo_stampa == 4) - set_header(r, "@139gop. @144gCodice conto @159gDescrizione sottoconto"); - r++; - } - } - else if (_tipo_stampa == 3 && _intesta_vidi) - { - TString tr(52); - tr.fill('-'); - set_header(r++,"@10gPagine studio Pagine utente ---------------- V I D I M A Z I O N E %s", (const char*)tr); - set_header(r++,"Mese@12gda@20ga@27gda@35ga Intestatario@71gN.fogli Pag.in. Pag.fin. Data Ufficio"); - } - if (_stampa_ind_comp && !_intesta_vidi) - set_header(r++, "@38gGeneralita'"); - - set_header(r, riga); - } -} - -int cg4400 (int argc, char * argv[]) -{ - CG4400_application a; - a.run(argc, argv, "Stampa registri IVA"); - return 0; -} - - - - - - - - - - - - - - +// ******************* +// Stampa registri IVA +// ******************* +#include "cg4.h" +#include "cg4400.h" +#include "cg4400a.h" +#include "cg4400b.h" + +static TString256 TMP; + +inline CG4400_application& app() { return (CG4400_application&)main_app(); } + +bool CG4400_application::filter_func (const TRelation * r) +{ + TLocalisamfile& mov = r->lfile(LF_MOV); + TString16 codreg = mov.get(MOV_REG); + TDate datareg = mov.get_date(MOV_DATAREG); + int annoiva = mov.get_int(MOV_ANNOIVA); + bool regst = mov.get_bool(MOV_REGST); + + if (codreg != (app()._codreg) || annoiva != (app()._annoes)) + return FALSE; + + if (app()._data_da.string() != "" && app()._data_a.string() != "") + if ( (datareg < app()._data_da || datareg > app()._data_a ) || (!datareg.ok()) ) + return FALSE; + + if (app()._tipo_stampa != 1) //stampa di bollato + if (regst) //il movimento e' gia' + return FALSE; //stato stampato in forma definitiva + + if (datareg.month() < app()._stampa_mese) + app()._stampa_mese = datareg.month(); + return TRUE; +} + +HIDDEN int compare_rows(const TObject** o1, const TObject** o2) +{ + TRiga* r1 = (TRiga*)*o1; + TRiga* r2 = (TRiga*)*o2; + + return (strcmp((const char*)r1->_codiva, (const char*)r2->_codiva)); +} + +HIDDEN int compare_fields(const TObject** o1, const TObject** o2) +{ + TRigaiva* r1 = (TRigaiva*)*o1; + TRigaiva* r2 = (TRigaiva*)*o2; + TString16 campo1; + TString16 campo2; + + campo1.format("%d%4s", r1->_tipodet, (const char*)r1->_codiva); + campo2.format("%d%4s", r2->_tipodet, (const char*)r2->_codiva); + return strcmp(campo1, campo2); +} + +bool CG4400_application::stampa_totali_finali() +{ + TConfig conf(CONFIG_DITTA); + return conf.get_bool("StTfFr"); +} + +bool CG4400_application::stampa_datareg() +{ + TConfig conf(CONFIG_STUDIO); + return conf.get_bool("NoDtRg"); +} + +bool CG4400_application::mask_select (TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + app()._ditte->enable_check(); + // seleziona e aggiungi alle gia' selezionate + if (app()._ditte->run() == K_ENTER) + { + for (long j = 0l; j < app()._ditte->items(); j++) + app()._selected.set(j, app()._ditte->checked(j)); + app().set_choice_limits(f.mask()); + } + } + return TRUE; +} + +bool CG4400_application::mask_azzera (TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + app()._selected.reset(); + f.mask().reset(F_SELECT); + f.mask().reset(DA_CODICE); + f.mask().reset(A_CODICE); + app()._ditte->check(-1, FALSE); + } + return TRUE; +} + +bool CG4400_application::mask_tipo_stampa(TMask_field& f, KEY k) +{ + TMask& m = f.mask(); + + if (k == K_SPACE) + { + int tipo_stampa = m.get_int(TIPO_STAMPA); + if (tipo_stampa == 3) //stampa su libro unico + { + m.enable_page(1); + TMask_field& cc = f.mask().field(CODICE_LIB_UN); + cc.set_dirty(); + } + else + m.disable_page(1); + } + return TRUE; +} + +bool CG4400_application::mask_mese (TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + const short id = f.dlg(); + int mese; + if (id == MESE) //Per stampa su libro unico + mese = f.mask().get_int(MESE); + if (id == FINO_A_MESE) + mese = f.mask().get_int(FINO_A_MESE); //Per stampa su bollato + if (id == MESE) + { + if (mese == 12) + { + f.mask().show (TIPO_RIEPILOGATIVO); + f.mask().show (RIF_VID); + } + else + { + f.mask().hide (TIPO_RIEPILOGATIVO); + f.mask().hide (RIF_VID); + } + } + if (id == FINO_A_MESE) + { + if (mese == 12) + f.mask().show (TIPO_RIEPILOGATIVO); + else f.mask().hide (TIPO_RIEPILOGATIVO); + } + } + if (k==K_TAB && f.mask().is_running()) + { + const short id = f.dlg(); + if (id == MESE) + f.mask().send_key(K_TAB, CODICE_LIBRO_IVA); + } + return TRUE; +} + +bool CG4400_application::look_reg(int i, int anno, TString& codlib, int m, const char* cod, int* umese, long ditta) +{ + TString16 y; + + y << anno << cod; + _tabreg->zero(); + _tabreg->put("CODTAB", y); + + if (_tabreg->read() == NOERR) + { + int tipo = _tabreg->get_int("I0"); + if (tipo == 1 || tipo == 2) + { + TString16 cod_lib_un = _tabreg->get("S6"); + TDate u_data = _tabreg->get_date("D3"); + TDate sca_vid = _tabreg->get_date("D1"); + if (codlib != cod_lib_un) + { + if (_selected.ones() == 1L) + if (_selected[i]) + message_box("Ditta %ld: il codice libro unico del registro non e' uguale al codice libro unico indicato", ditta); + return FALSE; + } + if (m < *umese) + { + if (_selected.ones() == 1L) + if (_selected[i]) + message_box("Ditta %ld: il mese indicato e' inferiore al mese dell'ultima data di stampa del registro", ditta); + return FALSE; + } + if (u_data.ok()) + *umese = u_data.month(); + else *umese = 0; + + if (sca_vid.ok()) + if (sca_vid.month() < m) + { + if (_selected.ones() == 1L) + if (_selected[i]) + message_box("Ditta %ld: la data scadenza di vidimazione del registro non deve essere inferiore al mese indicato", ditta); + return FALSE; + } + } + return TRUE; + } + return FALSE; +} + +bool CG4400_application::look_regs(int anno, TString& codlib, int m, int* umese, long ditta, TProgind* prog) +{ + int a, tipo; + TString16 codtab; + bool ok = FALSE; + *umese = 13; + + for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) + { + tipo = _tabreg->get_int("I0"); + codtab = _tabreg->get("CODTAB"); + a = atoi(codtab.mid(0,4)); + if (a > anno) + break; + if (a == anno) + if ( tipo == 1 || tipo == 2 ) //registro iva + { + TString16 cod_lib_un = _tabreg->get("S6"); + TDate sca_vid = _tabreg->get_date("D1"); + TDate u_data = _tabreg->get_date("D3"); + if (codlib != cod_lib_un) + continue; + if (u_data.ok()) + if (m < u_data.month()) + continue; + if (u_data.ok()) + *umese = (*umese < u_data.month()) ? *umese : u_data.month(); + if (sca_vid.ok()) + if (sca_vid.month() < m) + continue; + int month; + if (!u_data.ok()) + month = 0; + else month = u_data.month(); + if (month < m - 1) + { + app().set_firm(__firm); + delete prog; + error_box("Ditta %ld: Stampare i registri dei mesi precedenti", ditta); + app().stop_run(); + } + ok = TRUE; + } + } + return ok; +} + +bool CG4400_application::mask_libun (TMask_field& f, KEY k) +{ + if (k==K_TAB && f.mask().is_running()) + { + TString16 codlib(f.mask().get(CODICE_LIB_UN)); + //modifica del 26/04/1995 + if (codlib.empty()) + { + app()._test = TRUE; + return FALSE; + } + //fine modifica + + if (app()._selected.ones() == 0l) return FALSE; + + TProgind* p = new TProgind(app()._ditte->items()/2,"Verifica parametri in corso...",FALSE,TRUE,30); + + TString16 cod(f.mask().get(CODICE_LIBRO_IVA)); + int fino_a_mese = f.mask().get_int(MESE); + int anno = f.mask().get_int(ANNO); + bool ok = FALSE; + int last_mese = 13; + int mese = 0; + + app().__firm = app().get_firm(); + + for (int i = 0; i < app()._ditte->items(); i++) + { + //p->addstatus(1); + long ditta = app()._ditte->row(i).get_long(1); + if (prefix().exist(ditta)) + { + p->addstatus(1); + app().set_firm(ditta); + if (cod.not_empty()) + { + ok = app().look_reg(i,anno,codlib,fino_a_mese,cod,&mese,ditta); + if (!ok) + { + //modifica del 21/04/1995 suggerita da Cinzia!!! + /*****Rimodifica del 19/07/95 MI0817 + if (app()._selected.ones() == 1L) //solo se ho selezionato 1 ditta devo dare il messaggio + if (app()._selected[i]) + f.message_box("Ditta %ld: il registro %s non soddisfa i parametri indicati", ditta, (const char*)cod); + *****/ + continue; + } + if (mese < fino_a_mese - 1) //indipendentemente se si tratta di una ditta selezionata oppure no + { + app().set_firm(app().__firm); + delete p; + f.error_box("Ditta %ld: Stampare i registri dei mesi precedenti", ditta); + app().stop_run(); + } + } + else + { + ok = app().look_regs(anno,codlib,fino_a_mese,&mese,ditta,p); + if (!ok) + { + if (app()._selected.ones() == 1L) //solo se ho selezionato 1 ditta devo dare il messaggio + if (app()._selected[i]) + f.message_box("Ditta %ld: nessun registro soddisfa i parametri indicati", ditta); + continue; + } + } + //if (app()._selected[i]) + last_mese = (last_mese < mese) ? last_mese : mese; + } + } + app().set_firm(app().__firm); + + if (last_mese == 13) + last_mese = 0; //l'ultima data di stampa sul/sui registri specificati e' vuota (cioe' non sono ancora stati stampati sul libro unico specificato per l'anno specificato) + const char* me = ""; + me = format("%02d", last_mese); + f.mask().set(ULTIMO_MESE, me); + delete p; + } + return TRUE; +} + +bool CG4400_application::mask_cod (TMask_field& f, KEY k) +{ + if (k == K_TAB) + { + TTable TabLbu ("%LBU"); + TString codtab; + int anno; + + TString16 codlib(f.get()); + anno = f.mask().get_int(ANNO); + TabLbu.zero(); + codtab.format ("%04d%-3s", anno, (const char*)codlib); + TabLbu.put ("CODTAB", codtab); + TabLbu.read(); + if ( TabLbu.good() ) + { + //f.mask().set(ULTIMO_MESE,TabLbu.get_long("I0")); + f.mask().set(ULTIMA_PAGINA,TabLbu.get_long("I1")); + app()._codice_vidi = TabLbu.get("S4"); + } + //modifica del 26/04/1995 + if (app()._test) + { + f.mask().send_key(K_TAB, CODICE_LIBRO_IVA); + app()._test = FALSE; + } + //fine modifica + } + return TRUE; +} + +bool CG4400_application::mask_data (TMask_field& f, KEY k) +{ + if (k == K_TAB && f.mask().is_running()) + { + const int anno = f.mask().get_int(ANNO); + TDate data(f.get()); + if (data.ok()) + if (data.year() != anno) + { + f.warning_box("L'anno delle date limite deve essere uguale all'anno iva specificato"); + return FALSE; + } + if (f.dlg() == A_DATA) + if (data.ok) + { + if ( data.day() == 31 && data.month() == 12 ) + f.mask().show (TIPO_RIEPILOGATIVO); + else f.mask().hide (TIPO_RIEPILOGATIVO); + } + } + return TRUE; +} + +const char * CG4400_application::descr_doc() +{ + TTable tab_tpd("%TPD"); + TString codtab(format("%-2s",(const char*) _tipodoc)); + + tab_tpd.zero(); + tab_tpd.put("CODTAB", codtab); + if (tab_tpd.read()==NOERR) + TMP = tab_tpd.get("S0"); + else + TMP = ""; + + return TMP; +} + +const char * CG4400_application::descr_iva(const char * cod) +{ + TTable tab_iva("%IVA"); + TString codtab(format ("%-4s", cod)); + + tab_iva.zero(); + tab_iva.put("CODTAB", codtab); + if (tab_iva.read()==NOERR) + TMP = tab_iva.get("S0"); + else + TMP = ""; + + return TMP; +} + +const char * CG4400_application::tipo_attivita() +{ + TLocalisamfile attiv (LF_ATTIV); + + attiv.zero(); + attiv.put("CODDITTA", get_firm()); + attiv.put("CODATT", _codatt); + if (attiv.read() == NOERR) + TMP = attiv.get("TIPOATT"); + else TMP = ""; + return TMP; +} + +const char * CG4400_application::desc_attivita() +{ + TTable attiv ("%AIS"); + + attiv.zero(); + attiv.put("CODTAB", _codatt); + if (attiv.read()==NOERR) + TMP = attiv.get("S0"); + else + TMP = ""; + return TMP; +} + +TRectype& CG4400_application::ricerca_cf(char tipocf, long codcf) +{ + _clifo->zero(); + _clifo->put(CLI_TIPOCF, tipocf); + _clifo->put(CLI_CODCF, codcf); + _clifo->read(); + if (_clifo->bad()) + _clifo->zero(); + + return _clifo->curr(); +} + +TRectype& CG4400_application::ricerca_occ(const char * occ) +{ + TLocalisamfile occas (LF_OCCAS); + occas.zero(); + occas.put(OCC_CFPI, occ); + occas.read(); + if (occas.bad()) + occas.zero(); + + return occas.curr(); +} + +bool CG4400_application::year_handler(TMask_field& f, KEY key) +{ + if (key == K_TAB && f.focusdirty()) + { + app().begin_wait(); + app().set_year(atoi(f.get())); + app().build_nomiditte(); + app().build_ditte_sheet(); + app().end_wait(); + } + return TRUE; +} + +void CG4400_application::build_ditte_sheet() +{ + // build sheet + _ditte->destroy(); + for (int i = 0; i < _nomiditte.items(); i++) + { + TToken_string* d = new TToken_string(64); + *d = (TToken_string&)_nomiditte[i]; + const char vers = d->get_char(2); + bool selectable = vers == '?'; + d->insert(" |", 0); + const long pos = _ditte->add(d); + if (selectable) + _ditte->disable(pos); + else if (_selected[i]) + _ditte->check(pos); + } +} + +// --------------------------- handlers per selezione ditte + +bool CG4400_application::to_ditt_handler(TMask_field& f, KEY key) +{ + TMask& m = f.mask(); + if (key == K_F9) + app().to_butt_handler(m.field(BUT_DTO), K_SPACE); + if (key == K_TAB && f.focusdirty()) + { + const long l = app().select_firm_range(m.get_long(DA_CODICE), m.get_long(A_CODICE)); + app().set_choice_limits(m); + m.field(F_SELECT).set(format("%ld", l)); + } + return TRUE; +} + +bool CG4400_application::fr_ditt_handler(TMask_field& f, KEY key) +{ + TMask& m = f.mask(); + if (key == K_F9) + app().fr_butt_handler(m.field(BUT_DFR), K_SPACE); + else if (key == K_TAB && f.focusdirty()) + { + const long l = app().select_firm_range(m.get_long(DA_CODICE), m.get_long(A_CODICE)); + app().set_choice_limits(m); + m.field(F_SELECT).set(format("%ld", l)); + } + return TRUE; +} + +bool CG4400_application::to_butt_handler(TMask_field& f, KEY key) +{ + if (key == K_SPACE) + { + TArray_sheet* sh = app().get_ditte_sheet(); + TMask& m = f.mask(); + + sh->disable_check(); + if (sh->run() == K_ENTER) + { + app().select_firm_range(m.get_long(DA_CODICE),sh->row(sh->selected()).get_long(1)); + app().set_choice_limits(m); + } + } + return TRUE; +} + +bool CG4400_application::fr_butt_handler(TMask_field& f, KEY key) +{ + if (key == K_SPACE) + { + TMask& m = f.mask(); + TArray_sheet* sh = app().get_ditte_sheet(); + + sh->disable_check(); + if (sh->run() == K_ENTER) + { + app().select_firm_range(sh->row(sh->selected()).get_long(1), m.get_long(A_CODICE)); + app().set_choice_limits(m); + } + } + return TRUE; +} + +void CG4400_application::set_choice_limits(TMask& m) +{ + long first = -1l, last = -1l; + for (int i = 0; i < _ditte->items(); i++) + { + if (_selected[i]) + { + long dit = _ditte->row(i).get_long(1); + if (first == -1l) first = dit; + if (last < dit) last = dit; + } + } + if (first != -1) m.field(DA_CODICE).set(format("%ld",first)); + if (last != -1) m.field(A_CODICE).set(format("%ld",last)); + m.set(F_SELECT, _selected.ones()); + //modifica del 02/06/1995 + if (m.is_running()) + if (first != -1l) app().set_firm(first); + //fine +} + +long CG4400_application::select_firm_range(long from, long to) +{ + if (to == 0l) to = 99999L; + for (int i = 0; i < _ditte->items(); i++) + { + if (_ditte->disabled(i)) + continue; + + TToken_string& d = _ditte->row(i); + const char vers = d.get_char(3); + if (vers == '?') + continue; + + const long cod = d.get_long(1); + if (cod >= from && cod <= to) + { + _selected.set(i); + _ditte->check(i); + } + else + { + _selected.set(i,FALSE); + _ditte->uncheck(i); + } + } + return _selected.ones(); +} + +void CG4400_application::build_nomiditte(TProgind* pnd) +{ + _nomiditte.destroy(); + // ricostruire _nomiditte e rifare build_ditte_sheet + TLocalisamfile& dt = _nditte->lfile(); + + for (dt.first(); !dt.eof(); dt.next()) + { + // check no archivi + bool good = prefix().exist(dt.get_long("CODDITTA")); + if (good) + { + // check no parametri liquidazione + //TApplication::set_firm(dt.get_long("CODDITTA")); + if (!look_lia(dt.get_long("CODDITTA"))) good = FALSE; + } + _n_ditte++; + TToken_string* d = new TToken_string(64); + d->add(dt.get("CODDITTA")); + d->add(dt.get("RAGSOC")); + if (good) d->add(_tablia->get("S7")); + else d->add("??"); + + _nomiditte.add(d); + } + //if (pnd) pnd->addstatus(1); + //TApplication::set_firm(__firm); +} + +bool CG4400_application::user_create() +{ + //TProgind* pnd = NULL; + + //pnd = new TProgind (2,"Preparazione archivi\nPrego attendere", + // FALSE, TRUE, 30); + + _com = new TLocalisamfile(LF_COMUNI); + _anag = new TLocalisamfile(LF_ANAG); + _unloc = new TLocalisamfile(LF_UNLOC); + _attiv = new TLocalisamfile(LF_ATTIV); + _tab = new TLocalisamfile(LF_TAB); + _tabcom = new TLocalisamfile(LF_TABCOM); + _indlib = new TLocalisamfile(LF_INDLIB); + _tabreg = new TTable("REG"); + _tabiva = new TTable("%IVA"); + _tablbu = new TTable("%LBU"); + _tablim = new TTable("LIM"); + _tabpim = new TTable("PIM"); + _tablia = new TTable("%LIA"); + _tabpla = new TTable("%PLA"); + _tabppa = new TTable("PPA"); + _tabvid = new TTable("%VID"); + _clifo = new TLocalisamfile(LF_CLIFO); + _occas = new TLocalisamfile(LF_OCCAS); + + _desc27 = new TParagraph_string("", 27); + + _nditte = new TRelation(LF_NDITTE); + + _rel = new TRelation (LF_MOV); + _rel->add(LF_CAUSALI,"CODCAUS=CODCAUS",1,LF_MOV); + _rel->add(LF_RMOVIVA,"NUMREG=NUMREG",1,LF_MOV); + + _cur = new TCursor(_rel, "", 2); + + _ditte = new TArray_sheet(-1, -1, 0, 0, "Selezione Ditte", + "@1|Cod.@5R|Ragione Sociale@50|Vers."); + + //if (pnd) pnd->addstatus(1); + + _n_ditte = 0l; + __firm = TApplication::get_firm(); + + TDate oggi(TODAY); + _annoes = oggi.year(); + + build_nomiditte(); + build_ditte_sheet(); + + add_cursor(_cur); + add_file(LF_MOV); + add_file(LF_RMOVIVA); + + //delete pnd; + + return TRUE; +} + +bool CG4400_application::user_destroy() +{ + delete _ditte; + delete _nditte; + delete _com; + delete _unloc; + delete _anag; + delete _attiv; + delete _indlib; + delete _tab; + delete _tabcom; + delete _tabreg; + delete _tabiva; + delete _tablbu; + delete _tablim; + delete _tabpim; + delete _tablia; + delete _tabpla; + delete _tabppa; + delete _tabvid; + delete _clifo; + delete _occas; + delete _cur; + delete _rel; + delete _desc27; + + return TRUE; +} + +void CG4400_application::calcola_progressivi() +{ + TTable pim ("PIM"); + TString80 chiave; + int i, num=0; + + if (_tipo_stampa == 3) + num = _fino_a_mese; + if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) + num = _datareg.month(); + + //il discorso e' indipendente dalla frequenza! + //if (_frequiva == 'T') + // if (num%3 != 0) + // num = num - (num%3); + + //calcolo i totali del periodo + + chiave = ""; + //_codatt e' gia' Z perche' lo leggo dal registro + chiave << _annoes << _codatt; + pim.zero(); + pim.put ("CODTAB", chiave); + TRectype r (pim.curr()); + pim.read(_isgteq); + for (; !pim.eof(); pim.next()) + { + if (pim.curr() != r) break; + + TString80 codtab = pim.get("CODTAB"); + TString16 codreg = codtab.mid(10,3); + int mese = atoi(codtab.mid(13,2)); + if (_codreg == codreg.trim() && mese == num) + { + TString16 codiva = codtab.mid(16,4); + int tipodet = atoi(codtab.mid(20,1)); + real impo = pim.get_real("R0"); + real impos = pim.get_real("R1"); + real implo = pim.get_real("R2"); + //se il registro e' corrispettivi l'imponibile e l'iva li trovo in S2 + if (_corrispettivi) + { + TToken_string cs (pim.get("S2")); + impo = cs.get(0); + impos = cs.get(1); + } + //se in sospensione d'imposta l'imponibile e l'iva li trovo in R11 e R12 + if (_sosp_imposta) //in genere non sara' mai un corrispettivo + { + impo = pim.get_real("R11"); + impos = pim.get_real("R12"); + } + TToken_string fatt_rit (pim.get("S1")); //e' sempre un acquisto + real im (fatt_rit.get(0)); + real is (fatt_rit.get(1)); + impo += im; + impos += is; + implo += im+is; // potrei percio' ignorare l'importo lordo + if (impo != ZERO || impos != ZERO || implo != ZERO) + _tot_iva_array.add_riga(impo,impos,implo,ZERO,ZERO,ZERO,codiva); + if (_tipo_reg == 2) //registro acquisti + if (impo != ZERO || impos != ZERO) + _iva_array.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,0,TRUE); + } + } + + //calcolo i totali progressivi + if (_tipo_stampa == 3) + num = _fino_a_mese; + if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) + num = _datareg.month(); + + for (i=1; i<=num; i++) + { + chiave = ""; + chiave << _annoes << _codatt; + pim.zero(); + pim.put("CODTAB", chiave); + TRectype r (pim.curr()); + pim.read(_isgteq); + for (; !pim.eof(); pim.next()) + { + if (pim.curr() != r) break; + TString80 codtab = pim.get("CODTAB"); + TString16 codreg = codtab.mid(10,3); + int mese = atoi(codtab.mid(13,2)); + if (_codreg == codreg.trim() && mese == i) + { + TString16 codiva = codtab.mid(16,4); + int tipodet = atoi(codtab.mid(20,1)); + real impo = pim.get_real("R0"); + real impos = pim.get_real("R1"); + real implo = pim.get_real("R2"); + //se il registro e' corrispettivi l'imponibile e l'iva li trovo in S2 + if (_corrispettivi) + { + TToken_string cs (pim.get("S2")); + impo = cs.get(0); + impos = cs.get(1); + } + //se in sospensione d'imposta l'imponibile e l'iva li trovo in R11 e R12 + if (_sosp_imposta) + { + impo = pim.get_real("R11"); + impos = pim.get_real("R12"); + } + TToken_string fatt_rit (pim.get("S1")); + real im (fatt_rit.get(0)); + real is (fatt_rit.get(1)); + impo += im; + impos += is; + implo += im+is; + if (impo != ZERO || impos != ZERO || implo != ZERO) + _tot_iva_array.add_riga(ZERO,ZERO,ZERO,impo,impos,implo,codiva); + if (_tipo_reg == 2) //registro acquisti + if (impo != ZERO || impos != ZERO) + _iva_array.add_riga(ZERO,ZERO,impo,impos,codiva,tipodet,0,TRUE); + } + } + } +} + +int CG4400_application::riga_rmoviva() +{ + TString codiva; + real impo, impos; + int tipodet, tipocr, tipoatt; + bool intra; + + TLocalisamfile& rmoviva = _cur->file(LF_RMOVIVA); + bool ok = _cur->is_first_match(LF_RMOVIVA); + int nrec = 0; + + TRecnotype nr = rmoviva.recno(); + + while (ok) + { + nrec++; + TRectype iva (rmoviva.curr()); + tipodet = iva.get_int (RMI_TIPODET); + tipocr = iva.get_int (RMI_TIPOCR); + impo = iva.get_real(RMI_IMPONIBILE); + impos = iva.get_real(RMI_IMPOSTA); + codiva = iva.get(RMI_CODIVA); + intra = iva.get_bool(RMI_INTRA); + tipoatt = iva.get_int("TIPOATT"); + + _riga_rmi.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,tipocr,intra,tipoatt); + + if (_tipo_stampa == 1) //stampa di prova + { + if (_tipodoc == "FS") + { + real somma = -(impo + impos); + _tot_iva_array.add_riga(ZERO,ZERO,somma,ZERO,ZERO,ZERO,codiva); + } + else if (_tipodoc == "CR" || _tipodoc == "RF" || _tipodoc == "SC") + _tot_iva_array.add_riga(ZERO,ZERO,impo+impos,ZERO,ZERO,ZERO,codiva); + if (_tipodoc != "CR" && _tipodoc != "SC" && _tipodoc != "RF") + _tot_iva_array.add_riga(impo,impos,ZERO,ZERO,ZERO,ZERO,codiva); + + if (_tipo_reg == 2) //registro acquisti (non ha senso parlare di importi lordi) + _iva_array.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,0,TRUE); + } + + ok = _cur->next_match(LF_RMOVIVA); + } + rmoviva.readat(nr); + + return nrec; +} + +int CG4400_application::setta_riga(int r, const TRigaiva& riga, real& tot1, + real& tot2, real& tot3, real& tot4) +{ + set_row(r, "%4s", (const char*)riga._codiva); + TString descr = descr_iva(riga._codiva); + set_row(r, "@5g%-.21s",(const char*)descr); + if (riga._imponibile != ZERO) + set_row(r, "@25g%r", &riga._imponibile); + if (riga._imposta != ZERO) + set_row(r, "@41g%r", &riga._imposta); + if (_tipo_stampa != 1) + { + if (riga._imponibilep != ZERO) + set_row(r, "@81g%r", &riga._imponibilep); + if (riga._impostap != ZERO) + set_row(r++, "@98g%r", &riga._impostap); + } + else r++; + tot1 += riga._imponibile; + tot2 += riga._imposta; + tot3 += riga._imponibilep; + tot4 += riga._impostap; + + return r; +} + +messaggio CG4400_application::controlla_b0() +{ + TTable lim ("LIM"); + TString16 chiave = ""; + TString16 ditta = ""; + int i, mese; + ditta << get_firm(); + + if (_tipo_stampa == 1) //stampa di prova + mese = _data_a.month(); + else + mese = _fino_a_mese; + + if (_tipo_riepilogativo == ' ' || _tipo_riepilogativo == 'P') + { + if (_frequiva == 'T') //nella tabella LIM ho solo i mesi 3, 6, 9, 12 + { + for (i=3; i<=mese; i+=3) + { + chiave = ""; + TString16 m (format("%02d", i)); + chiave << _annoes << m; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + if (! lim.get_bool("B0")) + return no_liquidazione; + } + else return no_liquidazione; + } + } + if (_frequiva == 'M') + { + for (i=1 ; i<=mese; i++) + { + chiave = ""; + TString16 m (format("%02d", i)); + chiave << _annoes << m; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + if (! lim.get_bool("B0")) + return no_liquidazione; + } + else return no_liquidazione; + } + } + } + else if (_tipo_riepilogativo == 'A') + //if (_riep_liq) + { + chiave = ""; + chiave << _annoes << 13; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + if (! lim.get_bool("B0")) + return no_liquidazione; + } + else return no_liquidazione; + } + return B0_settato; +} + +messaggio CG4400_application::controlla_liquidazione() +{ + TTable lim ("LIM"); + TString mesi_cal = ""; + TString16 chiave = ""; + TString16 ditta = ""; + int i, mese; + bool continua; + ditta << get_firm(); + + if (_tipo_stampa == 1) //stampa di prova + mese = _data_a.month(); + else + mese = _fino_a_mese; + + if (_tipo_riepilogativo == ' ' || _tipo_riepilogativo == 'P') + { + if (_frequiva == 'T') //nella tabella LIM ho solo i mesi 3, 6, 9, 12 + { + for (i=3; i<=mese; i+=3) + { + chiave = ""; + TString16 m (format("%02d", i)); + chiave << _annoes << m; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + if (! lim.get_bool("B0")) + mesi_cal << itom(i) << "\n"; + } + else mesi_cal << itom(i) << "\n"; + } + } + if (_frequiva == 'M') + { + for (i=1 ; i<=mese; i++) + { + chiave = ""; + TString16 m (format("%02d", i)); + chiave << _annoes << m; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + if (! lim.get_bool("B0")) + mesi_cal << itom(i) << "\n"; + } + else mesi_cal << itom(i) << "\n"; + } + } + if (mesi_cal.not_empty()) + { + warning_box ("Ditta %s: la liquidazione da stampare sul registro %s relativa ai mesi di \n %s non e' stata ancora calcolata", (const char*)ditta, (const char*) _codreg, (const char *)mesi_cal); + continua = yesno_box("Si desidera ugualmente proseguire?"); + if (!continua) return non_proseguire; + continua = yesno_box("Si desidera proseguire con il calcolo e la stampa di liquidazione? \n (altrimenti si prosegue con la sola stampa di liquidazione)"); + if (!continua) return prosegui_stampa; + return prosegui_cal_stampa; + } + } + else if (_tipo_riepilogativo == 'A') + //if (_riep_liq) + { + chiave = ""; + chiave << _annoes << 13; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + if (! lim.get_bool("B0")) + { + continua = yesno_box("Ditta %s: non eseguito calcolo liquidazione annuale da stampare sul registro %s. Si desidera ugualmente proseguire?", (const char*)ditta, (const char*) _codreg); + if (!continua) return non_proseguire; + continua = yesno_box("Si desidera proseguire con il calcolo e la stampa di liquidazione? \n (altrimenti si prosegue con la sola stampa di liquidazione)"); + if (!continua) return prosegui_stampa; + return prosegui_cal_stampa; + } + } + else + { + continua = yesno_box("Ditta %s: non eseguito calcolo liquidazione annuale da stampare sul registro %s. Si desidera ugualmente proseguire?", (const char*)ditta, (const char*) _codreg); + if (!continua) return non_proseguire; + continua = yesno_box("Si desidera proseguire con il calcolo e la stampa di liquidazione? \n (altrimenti si prosegue con la sola stampa di liquidazione)"); + if (!continua) return prosegui_stampa; + return prosegui_cal_stampa; + } + } + return B0_settato; +} + +//controlla che i movimenti con anno data di registrazione < dell'anno indicato a video siano stati gia' stampati in forma definitiva*/ +//questo controllo viene fatto solo per stampa di bollato (non su libro unico) +bool CG4400_application::controlla_mov() +{ + TLocalisamfile mov (LF_MOV); + bool ok = TRUE; + byte tipo; + TString16 ditta = ""; + TRecnotype rec = _tabreg->recno(); + for (mov.first(); !mov.eof(); mov.next()) + { + TString16 reg = mov.get(MOV_REG); + if (reg.empty()) continue; //non e' un movimento iva + TDate datareg = mov.get_date(MOV_DATAREG); + if (_stampa_tutti_i_registri) + cerca_reg (reg, &tipo); + if ( (_stampa_tutti_i_registri && (tipo == 1 || tipo == 2)) + || (!_stampa_tutti_i_registri && reg == _codreg) ) + { + bool stampato = mov.get_bool(MOV_REGST); + if ( datareg.year() < _annoes ) + { + long numreg = mov.get_long(MOV_NUMREG); + if (!stampato) + ok = FALSE; + } + } + } + _tabreg->readat(rec); + return ok; +} + +bool CG4400_application::cerca_libro_gio(TString& datas, bool* good) +{ + TString app(4); + app = format("%04d", _annoes); + + *good = TRUE; + TRecnotype rec = _tabreg->recno(); + _tabreg->zero(); + _tabreg->put ("CODTAB", app); + TRectype r (_tabreg->curr()); + _tabreg->read(_isgteq); + for (; !_tabreg->eof(); _tabreg->next()) + { + if (_tabreg->curr() != r) break; + + int tiporeg = _tabreg->get_int("I0"); + if (tiporeg == 5) //libro giornale + { + const TDate& data = _tabreg->get_date("D3"); + if (data > _data_a) + { +// datas = format("%02/%02d/%4d", data.day(), data.month(), data.year()); + datas = data; // Meglio cosi' + *good = FALSE; + return FALSE; + } + return TRUE; + } + } + _tabreg->readat(rec); + //return TRUE; + return FALSE; +} + +void CG4400_application::cerca_reg(const TString& c, byte* t) +{ + TString16 cod = ""; + + cod << _annoes << c; + _tabreg->zero(); + _tabreg->put("CODTAB", cod); + if (_tabreg->read() == NOERR) + *t = _tabreg->get_int ("I0"); +} + +bool CG4400_application::ventilazione(const char* iva) +{ + TTable tabiva ("%IVA"); + TString16 chiave = ""; + chiave << iva; + tabiva.put("CODTAB", chiave); + if (tabiva.read()==NOERR) + { + TString16 vent = tabiva.get("S1"); + if (vent == "VE") + return TRUE; + } + return FALSE; +} + +int CG4400_application::stampa_prospetto() +{ + TString riga(_stampa_width); + int r=1, rr=0; + + reset_print(); + riga.fill('-'); + set_row(r, "%s", (const char*)riga); + r++; + set_row(r, "Legenda Tipo Operazione: 1=operazione intracomunitaria 2=AF art.34 comma 3"); + if (_auto_intraf) + set_row(r, "@78g3=operazione intracomunitaria e AF art.34 comma 3"); + r++; + + _stampa = stampa_totali_finali(); + if (_stampa) + { + set_row(++r, "Tipo documento@54gTotale documento"); + r+=2; + for (int j = 0; j < _doc_array.items(); j++) + { + TTipodoc& doc = (TTipodoc&)_doc_array[j]; + rr = r+j; + set_row(rr, "%2s", (const char*) doc._tipodoc); + set_row(rr, "@3g%s", (const char*) doc._descrdoc); + set_row(rr, "@54g%r", &doc._totdoc); + } + _doc_array.destroy(); + } + + if (rr > 0) + rr++; + else + rr = r; + + if (_stampa && _tipo_reg == 2) + { + if (_stampa_cred_pre && _mese_credito==0 && _credito > ZERO) + { + set_row (++rr, "** CREDITO INIZIO ANNO @39g%r", &_credito); + rr++; + } + } + + if (_esiste_riga_iva && _stampa) + { + if (_tipo_reg == 1 && _corrispettivi) + set_row(++rr, "@26g------------------ P E R I O D O -------------------"); + else + set_row(++rr, "@26g---------- P E R I O D O -----------"); + if (_tipo_stampa != 1) + { + if (_tipo_reg == 1 && _corrispettivi) + set_row(rr,"@84g----------- P R O G R E S S I V I --------------"); + else + set_row(rr,"@82g------ P R O G R E S S I V I ------"); + } + rr++; + set_row(rr, "Cod."); + if (_tipo_reg == 2) + { + set_row(rr, "@36gA C Q U I S T I"); + if (_tipo_stampa != 1) + set_row(rr, "@92gA C Q U I S T I"); + } + if (_tipo_reg == 1) //un registro corrispettivi puo' solo essere un registro vendite + { + set_row(rr, "@37gV E N D I T E"); + if (_corrispettivi) + set_row(rr, "@63gCORRISPETTIVI"); + if (_tipo_stampa != 1) + { + if (_corrispettivi) + set_row(rr, "@94gV E N D I T E@118gCORRISPETTIVI"); + else + set_row(rr, "@93gV E N D I T E"); + } + } + rr++; + set_row(rr, "iva Descrizione@30gImponibile@49gImposta"); + if (_tipo_reg == 1 && _corrispettivi) + set_row(rr, "@63gImporti lordi"); + if (_tipo_stampa != 1) + { + if (_tipo_reg == 1 && _corrispettivi) + set_row(rr++, "@87gImponibile@107gImposta@118gImporti Lordi"); + else + set_row(rr++, "@86gImponibile@106gImposta"); + } + else rr++; + rr++; + } + return rr; +} + +//la stampa "tipi di indetraibilita'" viene fatta solo per gli acquisti +int CG4400_application::stampa_acquisti(int row) +{ + real tot_imponib, tot_imposta, tot_imponibp, tot_impostap; + row+=2; + int tdetprec = -1; + int rw = row; + tot_imponib = tot_imposta = tot_imponibp = tot_impostap = ZERO; + + _iva_array.sort(compare_fields); + for (int s = 0; s < _iva_array.items(); s++) + { + TRigaiva& riga = (TRigaiva&)_iva_array[s]; + switch (riga._tipodet) + { + case 1: if (riga._tipodet != tdetprec) + { + set_row(rw++, "----- Indetraibile su op.es. -----"); + set_row(rw, "Cod."); + rw++; + set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); + if (_tipo_stampa != 1) + set_row(rw++, "@86gImponibile@106gImposta"); + else rw++; + rw++; + } + rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); + tdetprec = riga._tipodet; + break; + case 3: if (tdetprec == 1) + { + //set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); + set_row(++rw, "TOTALE"); + if (tot_imponib != ZERO) + set_row(rw, "@25g%r", &tot_imponib); + if (tot_imposta != ZERO) + set_row(rw, "@41g%r", &tot_imposta); + + if (_tipo_stampa != 1) + { + //set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); + if (tot_imponibp != ZERO) + set_row(rw, "@81g%r", &tot_imponibp); + if (tot_impostap != ZERO) + set_row(rw, "@98g%r", &tot_impostap); + } + tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; + rw+=2; + } + if (riga._tipodet != tdetprec) + { + set_row(rw++, "----- Passaggi interni -----"); + set_row(rw, "Cod."); + rw++; + set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); + if (_tipo_stampa != 1) + set_row(rw++, "@86gImponibile@106gImposta"); + else rw++; + rw++; + } + rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); + tdetprec = riga._tipodet; + break; + case 9: if ( (tdetprec == 1) || (tdetprec == 3) ) + { + //set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); + set_row(++rw, "TOTALE"); + if (tot_imponib != ZERO) + set_row(rw, "@25g%r", &tot_imponib); + if (tot_imposta != ZERO) + set_row(rw, "@41g%r", &tot_imposta); + if (_tipo_stampa != 1) + { + //set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); + if (tot_imponibp != ZERO) + set_row(rw, "@81g%r", &tot_imponibp); + if (tot_impostap != ZERO) + set_row(rw, "@98g%r", &tot_impostap); + } + tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; + rw+=2; + } + if (riga._tipodet != tdetprec) + { + set_row(rw++, "----- N.D. 9 - acquisti indeducibili per ART.19 -----"); + set_row(rw, "Cod."); + rw++; + set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); + if (_tipo_stampa != 1) + set_row(rw++, "@86gImponibile@106gImposta"); + else rw++; + rw++; + } + rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); + tdetprec = riga._tipodet; + break; + default: break; + } + } + if (_iva_array.items() > 0) + if (tdetprec == 9) + { + //set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); + set_row(++rw, "TOTALE"); + if (tot_imponib != ZERO) + set_row(rw, "@25g%r", &tot_imponib); + if (tot_imposta != ZERO) + set_row(rw, "@41g%r", &tot_imposta); + if (_tipo_stampa != 1) + { + //set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); + if (tot_imponibp != ZERO) + set_row(rw, "@81g%r", &tot_imponibp); + if (tot_impostap != ZERO) + set_row(rw, "@98g%r", &tot_impostap); + } + } + _iva_array.destroy(); + rw++; + return rw; +} + +void CG4400_application::set_page_tot_reg() +{ + int rr=0; + + rr = stampa_prospetto(); + + if (_esiste_riga_iva && _stampa) + { + real tot_imponib, tot_imposta, tot_lordo, tot_imponibp, tot_impostap, tot_lordop; + tot_imponib = tot_imposta = tot_lordo = tot_imponibp = tot_impostap = tot_lordop = ZERO; + + _tot_iva_array.sort(compare_rows); //viene ordinato per codice iva + + for (int k = 0; k < _tot_iva_array.items(); k++) + { + TRiga& riga = (TRiga&)_tot_iva_array[k]; + //row = rr+k; + set_row(rr, "%4s", (const char*)riga._codiva); + TString80 descr = descr_iva(riga._codiva); + set_row(rr, "@5g%-.21s",(const char*)descr); + if (riga._imponibile != ZERO) + set_row(rr, "@25g%r", &riga._imponibile); + if (riga._imposta != ZERO) + set_row(rr, "@41g%r", &riga._imposta); + if (_tipo_reg == 1 && _corrispettivi) + if (riga._implordo != ZERO) + set_row(rr, "@61g%r", &riga._implordo); + if (_tipo_stampa != 1) + { + if (riga._imponibilep != ZERO) + set_row(rr, "@81g%r", &riga._imponibilep); + if (riga._impostap != ZERO) + set_row(rr, "@98g%r", &riga._impostap); + if (_tipo_reg == 1 && _corrispettivi) + if (riga._implordop != ZERO) + set_row(rr, "@115g%r", &riga._implordop); + } + rr++; + tot_imponib += riga._imponibile; + tot_imposta += riga._imposta; + tot_lordo += riga._implordo; + tot_imponibp+= riga._imponibilep; + tot_impostap+= riga._impostap; + tot_lordop += riga._implordop; + } + _tot_iva_array.destroy(); + rr++; + //set_row(rr, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); + set_row(rr, "TOTALE"); + if (tot_imponib != ZERO) + set_row(rr, "@25g%r", &tot_imponib); + if (tot_imposta != ZERO) + set_row(rr, "@41g%r", &tot_imposta); + if (_tipo_reg == 1 && _corrispettivi) + if (tot_lordo != ZERO) + set_row(rr, "@61g%r", &tot_lordo); + if (_tipo_stampa != 1) + { + //set_row(rr, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); + if (tot_imponibp != ZERO) + set_row(rr, "@81g%r", &tot_imponibp); + if (tot_impostap != ZERO) + set_row(rr, "@98g%r", &tot_impostap); + if (_tipo_reg == 1 && _corrispettivi) + if (tot_lordop != ZERO) + set_row(rr, "@115g%r", &tot_lordop); + } + + if (_tipo_reg == 2) rr = stampa_acquisti(rr); + } + if (_tipo_reg == 2 && _tipo_stampa != 1) + stampa_plafonds(rr); +} + +void CG4400_application::stampa_plafonds(int r) +{ + TTable pla ("%PLA"); + TTable ppa ("PPA"); + TString80 chiave; + int num; + real r1, r2, r3; + + r1 = r2 = r3 = ZERO; + + if (_tipo_stampa == 3) + num = _fino_a_mese; + if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) + num = _datareg.month(); + + TString16 nm (format("%02d", num)); + + // forza il tipoatt a 1 + //char buf[10]; strcpy(buf,_codatt); + //buf[strlen(buf) - 1] = '1'; + + chiave = ""; + //chiave << _annoes << buf; + + chiave.format("%05ld", get_firm()); + chiave << _annoes; + chiave << _codatt << "1"; + pla.put("CODTAB", chiave); + + if (pla.read() == NOERR) + { + r1 = pla.get_real("R5"); //totali esp. art.8 + r2 = pla.get_real("R6"); //totali esp. art.8 bis + r3 = pla.get_real("R7"); //totali esp. art 9 + } + + if (r1 > ZERO || r2 > ZERO || r3 > ZERO) + { + set_row(++r, "QUADRO RELATIVO ALLA DISPONIBILITA' E UTILIZZAZIONE MENSILE DEI PLAFONDS"); + r++; + TString mese(9); + mese = itom(num); + mese.right_just(); + set_row(++r, "%s", (const char*) mese); + set_row(++r, ""); + r++; + } + else return; + + if (r1 > ZERO) + { + real r8 = ZERO; + r8 = stampa_valori_plafonds(r1, num, ppa, "1"); + //if (r8 > ZERO) + if (!r8.is_zero()) + { + real pri = ZERO; + real pre = ZERO; + chiave = ""; + chiave << _annoes << _codatt << "1" << nm << "1"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri = ppa.get_real("R0"); + pre = ppa.get_real("R1"); + } + chiave = ""; + chiave << _annoes << _codatt << "2" << nm << "1"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri += ppa.get_real("R0"); + pre += ppa.get_real("R1"); + } + real x = r8 - pri - pre; + set_row(r++, "ART. 8 1° comma lettere a-b Disponibile %r", &r8); + set_row(r++, "Utilizzato all'interno@44g%r", &pri); + set_row(r++, "Utilizzato per l'importazione@44g%r riporto %r", &pre, &x); + } + } + + if (r2 > ZERO) + { + real r8b = ZERO; + r8b = stampa_valori_plafonds(r2, num, ppa, "2"); + //if (r8b > ZERO) + if (!r8b.is_zero()) + { + real pri = ZERO; + real pre = ZERO; + chiave = ""; + chiave << _annoes << _codatt << "1" << nm << "2"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri = ppa.get_real("R0"); + pre = ppa.get_real("R1"); + } + chiave = ""; + chiave << _annoes << _codatt << "2" << nm << "2"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri += ppa.get_real("R0"); + pre += ppa.get_real("R1"); + } + real x = r8b - pri - pre; + r++; + set_row(r++, "ART. 8 bis 1° comma Disponibile %r", &r8b); + set_row(r++, "Utilizzato all'interno@44g%r", &pri); + set_row(r++, "Utilizzato per l'importazione@44g%r riporto %r", &pre, &x); + } + } + + if (r3 > ZERO) + { + real r9 = ZERO; + r9 = stampa_valori_plafonds(r3, num, ppa, "3"); + //if (r9 > ZERO) + if (!r9.is_zero()) + { + real pri = ZERO; + real pre = ZERO; + chiave = ""; + chiave << _annoes << _codatt << "1" << nm << "3"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri = ppa.get_real("R0"); + pre = ppa.get_real("R1"); + } + chiave = ""; + chiave << _annoes << _codatt << "2" << nm << "3"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri += ppa.get_real("R0"); + pre += ppa.get_real("R1"); + } + real x = r9 - pri - pre; + r++; + set_row(r++, "ART. 9 1° comma Disponibile %r", &r9); + set_row(r++, "Utilizzato all'interno@44g%r", &pri); + set_row(r++, "Utilizzato per l'importazione@44g%r riporto %r", &pre, &x); + } + } +} + +real CG4400_application::stampa_valori_plafonds(const real& r1, const int mese, TTable& ppa, const char* tipo) +{ + real r, si8, se8; + TString80 chiave; + int i; + + r = r1; + si8 = se8 = ZERO; + if (mese > 1) + { + for (i=1; ifirst(); + if (!_tabreg->eof()) + { + codtab = _tabreg->get("CODTAB"); + anno = atoi(codtab.mid(0,4)); + if (anno > _annoes) + { + if (_tipo_stampa != 3) //per il libro unico e' gia' stato controllato nell'handler + warning_box("Non esistono registri IVA della Ditta %ld per l'anno %d", + _ditta, _annoes); + return FALSE; + } + } + } + else // stampa un solo registro + { + _stampa_tutti_i_registri = FALSE; + codtab << _annoes << _codreg; + _tabreg->zero(); + _tabreg->put("CODTAB", codtab); + if (_tabreg->read() != NOERR) + { + if (_tipo_stampa != 3) + warning_box("Il registro IVA specificato non esiste nella \n Ditta %ld", _ditta); + return FALSE; + } + else + { + _tipo_reg = _tabreg->get_int("I0"); + if (_tipo_reg == 1 || _tipo_reg == 2) //registro iva + { + cod_lib_un = _tabreg->get("S6"); + sca_vid = _tabreg->get_date("D1"); + if (_tipo_stampa != 1) + _u_data = _tabreg->get_date ("D3"); + if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) + { + if (cod_lib_un.not_empty()) + { + warning_box ("Ditta %ld: sul registro non deve essere indicato il codice del libro unico", _ditta); + return FALSE; + } + if (sca_vid.ok()) + if (sca_vid.month() < _fino_a_mese) + { + warning_box ("Ditta %ld: il mese della data scadenza vidimazione riportata sul registro non deve essere inferiore al mese indicato", _ditta); + return FALSE; + } + if (_u_data.ok()) + if (_data_a < _u_data) + { +// TString16 datas = format("%02d/%02d/%4d", _u_data.day(), _u_data.month(), _u_data.year()); +// warning_box ("Ditta %ld: la data specificata non deve essere inferiore al %s (ultima data di stampa specificata sul registro)", _ditta, (const char*)datas); +// return FALSE; + return warning_box ("Ditta %ld: la data specificata non deve essere inferiore al %s (ultima data di stampa specificata sul registro)", _ditta, (const char*)_u_data.string()); + } + if (_tipo_stampa == 4) //stampa con riferimenti al libro giornale + { + TString16 datas; + bool good; + bool ok = cerca_libro_gio(datas,&good); + if (!ok) + { + if (!good) + warning_box ("Ditta %ld: la data indicata non deve essere superiore al %s (ultima data di stampa del libro giornale)", _ditta, (const char*)datas); + return FALSE; + } + } + } + _pagine_stampate = _tabreg->get_long("I1"); + _numini = _pagine_stampate; + _corrispettivi = _tabreg->get_bool("B0"); + _sosp_imposta = _tabreg->get_bool("B1"); + _liquidazione = _tabreg->get_bool("B7"); + _riep_liq = _tabreg->get_bool("B6"); + _stampa_cred_pre = _tabreg->get_bool("B4"); + _stampa_ind_ditta = _tabreg->get_bool("B9"); + _stampa_ind_comp = _tabreg->get_bool("B5"); + _cod_un_loc = _tabreg->get_int ("I7"); + _mese_credito = _tabreg->get_int ("I8"); //campo nascosto sulla tabella dei registri: mese di stampa credito anno precedente + _mese_ultima_liq = _tabreg->get_int ("I4"); + _codatt = _tabreg->get("S8"); + _tipoatt = tipo_attivita(); + _attivita = desc_attivita(); + _desc_lib = _tabreg->get ("S0"); + } + else return FALSE; + } + } + return TRUE; +} + +bool CG4400_application::compila_lib() +{ + TTable tab_lib ("%LBU"); + TString16 cod; + + cod << _annoes << _codlib; + tab_lib.zero(); + tab_lib.put("CODTAB", cod); + + if (tab_lib.read() == NOERR) + { + _stampa_ind_ditta = tab_lib.get_bool("B1"); + return TRUE; + } + return FALSE; +} + +bool CG4400_application::preprocess_print(int file, int counter) +{ + if (file == LF_MOV) + { + long items = _cur->items(); + if (!items) + return FALSE; + _iva_array.destroy(); + _riga_rmi.destroy(); + _tot_iva_array.destroy(); + _doc_array.destroy(); + _dataregp = ""; + _esiste_riga_iva = FALSE; + _auto_intraf = FALSE; + _intesta_liq = FALSE; + set_print_zero(); + } + return TRUE; +} + +bool CG4400_application::preprocess_page(int file, int counter) +{ + if (file == LF_MOV) + { + if (counter) return TRUE; + + reset_print(); + int rr = 0, riga = 0; + bool intra; + TString80 comune, prov, comcf, capcf, civcf; + TString80 viacf; + TString ragsoc; + TString tipo_op = ""; + + TLocalisamfile& mov = _cur->file(LF_MOV); + TLocalisamfile& caus = _cur->file(LF_CAUSALI); + + _datareg = mov.get_date(MOV_DATAREG); + + if (_tipo_stampa != 3 && _liquidazione) + { + int da; + if (_tipo_stampa == 1) + da = _data_da.month(); + else da = 1; + int a = _datareg.month(); + for (int m = da; m < a; m++) + { + if (!_st_liq[m]) + if (stampo_liquidazione(m)) + { +// _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header (intestazione per la stampa liquidazione) + _datareg = TDate(1, m, _annoes); // Meglio cosi' + TFilename t; + t.temp("reg"); + if (_scelta == B0_settato || _scelta == prosegui_stampa) + { + if (_tipo_stampa == 1) + send_message('S',t, m); + else send_message('s',t, m); + } + else //_scelta == prosegui_cal_stampa + { + if (_tipo_stampa == 1) + send_message('L', t, m); + else send_message('l', t, m); + } + //TString80 nomef; nomef = t.path(); nomef << "\\" << t.name(); + //if (fexist(nomef)) + if (fexist(t)) + { + _intesta_liq = TRUE; + //printer().footerlen(0); + if (!_mov_empty) printer().formfeed(); + merge_export_file(t,FALSE,TRUE); + _intesta_liq = FALSE; + reset_print(); + remove(t); + } + } + _st_liq[m] = TRUE; + } + } + + _datareg = mov.get_date(MOV_DATAREG); + _mov_empty = FALSE; + + if ( _datareg.month() != _dataregp.month() && _dataregp.ok() ) + { + _auto_intraf = FALSE; + printer().formfeed(); + //printer().footerlen(5); //devo rimetterlo cosi' + } + + _dataregp = _datareg; + + TDate datadoc = mov.get_date(MOV_DATADOC); + long numreg = mov.get_long(MOV_NUMREG); + long protiva = mov.get_long(MOV_PROTIVA); + long uprotiva = mov.get_long(MOV_UPROTIVA); + real totdoc = mov.get_real(MOV_TOTDOC); + TString16 numdoc = mov.get(MOV_NUMDOC); + char tipocf = mov.get(MOV_TIPO)[0]; + TString16 ocfpi = mov.get(MOV_OCFPI); + long codcf = mov.get_long(MOV_CODCF); + long numgio = mov.get_long(MOV_NUMGIO); + bool stampato = mov.get_bool(MOV_REGST); + TString16 codval = mov.get(MOV_CODVALI); + real corrval = mov.get_real(MOV_CORRVALUTA); + //bool intra = caus.get_bool(CAU_INTRACOM); //da prendere sul movimento + bool autof = caus.get_bool(CAU_AUTOFATT); + TString80 descrcau = caus.get(CAU_DESCR); + + if (_cur->pos() == 0) + _uprotivap = uprotiva ? uprotiva : protiva; + + //aggiornamento di mov + if (_tipo_stampa != 1) + if (!stampato) + { + mov.put(MOV_REGST,TRUE); + mov.rewrite(); + } + + if (codcf == 0l) + ragsoc = descrcau; + else + { + if (ocfpi.trim().empty()) + { + TRectype dep = ricerca_cf(tipocf, codcf); + ragsoc = dep.get (CLI_RAGSOC); + viacf = dep.get (CLI_INDCF); + civcf = dep.get (CLI_CIVCF); + capcf = dep.get (CLI_CAPCF); + comcf = dep.get (CLI_COMCF); + char tipoa = dep.get_char(CLI_TIPOAPER); + if (tipoa == 'F') + { + TString80 cognome, nome; + cognome = ragsoc.mid(0,30); + nome = ragsoc.mid(30,20); + cognome.trim(); nome.trim(); + ragsoc = cognome; + ragsoc << " " << nome; + } + } + else + { + TRectype dep = ricerca_occ(ocfpi); + ragsoc = dep.get (OCC_RAGSOC); + viacf = dep.get (OCC_INDIR); + civcf = dep.get (OCC_CIV); + capcf = dep.get (OCC_CAP); + comcf = dep.get (OCC_COM); + } + TRectype com = look_comuni(comcf); + comune = com.get(COM_DENCOM); + prov = com.get(COM_PROVCOM); + } + + _tipodoc = mov.get(MOV_TIPODOC); + _descr_doc = descr_doc(); + TString app(datadoc.string(brief, '/')); + + if (stampa_totali_finali()) + _doc_array.add_riga(_tipodoc,_descr_doc,totdoc); + + //setto le righe di stampa + _r = 1; + if (!_stampa_data_reg) + set_row(_r, "%s", (const char* ) _datareg.string(brief, '/')); + set_row(_r, "@9g%5ld", protiva); + if (datadoc.ok()) + set_row(_r, "@15g%s", (const char*) app); + set_row(_r, "@24g%s", (const char*) numdoc); + if (codcf != 0l) + set_row(_r, "@31g%6ld", codcf); + *_desc27 = (const char*) ragsoc; + //set_row(_r, "@38g#a", _desc25); + set_row(_r, "@68g%2s", (const char*) _tipodoc); + if (_stampa_width == 132) + set_row(_r, "@70g%r", &totdoc); + else set_row(_r, "@78g%r", &totdoc); + + if (_tipo_stampa == 1) //in caso di stampa di prova + if (! (_tipo_reg == 1 && _corrispettivi)) //e se non si tratta di registro vendite corrispettivi + if (! (_cur->pos()==0)) //il primo movimento non va controllato + { + if (protiva != _uprotivap + 1) + { + set_row(_r+1, "@2g*** NUM.PROT.FUORI SEQUENZA"); + riga = _r+2; + } + _uprotivap = uprotiva ? uprotiva : protiva; + } + + const char* r; + int i = 1; + while ((r = _desc27->get()) != NULL) + { + set_row (i, "@38g%s", r); + i++; + } + if (i > riga) riga = i; + + if (codcf != 0l && _stampa_ind_comp) + { + //set_row(_r, "@38g%-.27s", (const char*)ragsoc); + if (viacf.not_empty()) //se la via non e' vuota non puo' essere vuoto il comune + { + set_row (/*_r+1*/ i++, "@38g%-.23s %-3s",(const char *)viacf, (const char *)civcf); + set_row (/*_r+2*/ i++, "@38g%s %-.21s", (const char *)capcf, (const char *)comune); + riga = /*_r+3*/ i; + } + else if (comune.not_empty()) + { + set_row (/*_r+1*/ i++, "@38g%s %-.21s", (const char *)capcf, (const char *)comune); + riga = /*_r+2*/ i; + } + } + + _nrec = riga_rmoviva(); + if (_nrec > 0) + { + _esiste_riga_iva = TRUE; + for (int j = 0; j < _riga_rmi.items(); j++) + { + TRigaiva& riga = (TRigaiva&)_riga_rmi[j]; + rr = _r+j; + intra = riga._intra; + if (_stampa_width == 132) + { + set_row(rr, "@85g%r", &riga._imponibile); + set_row(rr, "@101g%4s",(const char*)riga._codiva); + if (_tipo_reg == 2) + set_row(rr, "@106g%d", riga._tipodet); + set_row(rr, "@107g%r", &riga._imposta); + set_row(rr, "@123g%d", riga._tipocr); + if (_tipoatt == "E" && _tipo_reg != 2) + set_row(rr, "@125g%d", riga._tipoatt); + if (_tipo_stampa == 4) //stampa con riferimento al libro giornale + set_row(rr, "@126g%5ld", numgio); + } + else //stampa a 198 + { + set_row(rr, "@93g%r", &riga._imponibile); + set_row(rr, "@109g%4s",(const char*)riga._codiva); + if (_tipo_reg == 2) + set_row(rr, "@114g%d", riga._tipodet); + set_row(rr, "@116g%r", &riga._imposta); + if (_tipoatt == "E" && _tipo_reg != 2) + set_row(rr, "@132g%d", riga._tipoatt); + set_row(rr, "@134g%d", riga._tipocr); + if (_tipo_stampa == 4) //stampa con riferimento al libro giornale + set_row(rr, "@136g%7ld", numgio); + } + } + _riga_rmi.destroy(); + } + + if ( intra && autof) + { + _auto_intraf = TRUE; + tipo_op = "3"; + } + else if (intra) + tipo_op = "1"; + else if (autof) + tipo_op = "2"; + + set_row(_r, "@66g%s", (const char*) tipo_op); + + if (_tipo_stampa == 1) //stampa di prova + { + if (_stampa_width == 132) + { + set_row(_r, "@126g%5ld", numreg); + if (stampato) + set_row(_r, "@131g*"); //solo in stampa di prova! + } + else //198 + { + set_row(_r, "@136g%7ld", numreg); + if (stampato) + set_row(_r, "@144g*"); + } + } + if (_tipo_stampa == 4 && _stampa_width == 198) + { + TLocalisamfile rmoviva (LF_RMOVIVA); + rmoviva.zero(); + rmoviva.put(RMI_NUMREG,numreg); + TRectype rec(rmoviva.curr()); + rmoviva.read(_isgteq); + for ( ; !rmoviva.eof(); rmoviva.next()) + { + if (rmoviva.curr() != rec) break; + + int gruppo = rmoviva.get_int("GRUPPO"); + int conto = rmoviva.get_int("CONTO"); + long sottoc = rmoviva.get_long("SOTTOCONTO"); + TConto tc (gruppo,conto,sottoc); + TString80 descr = tc.descrizione(); + set_row(_r, "@144g%3d %3d %6d", gruppo, conto, sottoc); + set_row(_r, "@159g%-.39s", (const char*) descr); + break; + } + } + + if (riga <= rr) riga = ++rr; + + if (corrval != ZERO) + { + TString vall (corrval.string("###.###.###.###,@@")); + set_row(riga, "@24gCodice valuta %-3s Corrispettivo in valuta %s", (const char*) codval, (const char*) vall); + } + } + return TRUE; +} + +void CG4400_application::scrivi_reg() +{ + TString16 codtab; + TTable Tabreg ("REG"); + + codtab << _annoes << _codreg; + Tabreg.zero(); + Tabreg.put("CODTAB", codtab); + if (Tabreg.read() == NOERR) + { + const TDate d = Tabreg.get_date("D3"); + if (!_mov_empty) //cioe' se e' stata stampata almeno una pagina + { +// TDate ultima_data = format("%02d/%02d/%4d", _datareg.last_day(_datareg.month(), _annoes), _datareg.month(), _annoes); + TDate ultima_data(_datareg); + ultima_data.set_end_month(); // Meglio cosi' + + if (ultima_data > d) + Tabreg.put("D3", ultima_data); + } + else if (_data_a > d) + Tabreg.put("D3", _data_a); + + if (_tipo_reg == 2 && _stampa_cred_pre) + if (_mese_credito == 0 && _credito > ZERO) + if (_mov_empty) + Tabreg.put("I8", (long)_fino_a_mese); + else Tabreg.put("I8", (long)_datareg.month()); + + Tabreg.rewrite(); + } + + if (_tipo_stampa == 3) + { + TString16 cod = ""; + TTable lbu ("%LBU"); + + cod << _annoes << _codlib; + lbu.zero(); + lbu.put("CODTAB", cod); + if (lbu.read() == NOERR) + { + lbu.put("I0", (long) _fino_a_mese); + lbu.rewrite(); + } + } +} + +void CG4400_application::aggiorna_reg(const bool aggiorna_vidi) +{ + TString16 codtab; + TTable Tabreg ("REG"); + TLocalisamfile IndBil (LF_INDLIB); + + codtab << _annoes << _codreg; + Tabreg.zero(); + Tabreg.put("CODTAB", codtab); + if (Tabreg.read() == NOERR) + { + TDate d = Tabreg.get_date("D3"); + if (!_mov_empty) //cioe' se e' stata stampata almeno una pagina + { +// TDate ultima_data = format("%02d/%02d/%4d", _datareg.last_day(_datareg.month(), _annoes), _datareg.month(), _annoes); + TDate ultima_data(_datareg); + ultima_data.set_end_month(); // Meglio cosi' + + if (ultima_data > d) + Tabreg.put("D3", ultima_data); + } + else if (_data_a > d) + Tabreg.put("D3", _data_a); + + Tabreg.put("I1", _pagine_stampate); + + if (_intesta_liq) + if (_tipo_riepilogativo == 'A') + Tabreg.put("I4", 13L); + else Tabreg.put("I4", (long)_datareg.month()); + + if (_tipo_reg == 2 && _stampa_cred_pre) + if (_mese_credito == 0 && _credito > ZERO) + if (_mov_empty) + Tabreg.put("I8", (long)_fino_a_mese); + else Tabreg.put("I8", (long)_datareg.month()); + + Tabreg.rewrite(); + } + + if (_tipo_stampa == 3) //stampa su libro unico + + // sul file indlib (indice libro unico) devo generare una riga per ogni + // registro stampato (ricordarsi che la stampa su libro unico deve + // avvenire mese per mese!) + // inoltre non posso stampare due volte lo stesso mese perche' la stampa + // avviene a fine mese + + { + long numero_riga = 1L; + if (!aggiorna_vidi) + { + bool trovato = FALSE; + //long ditta = get_firm(); + + IndBil.zero(); + + TRectype nuovo (IndBil.curr()); + + IndBil.put("ANNO", _annoes); + IndBil.put("CODLIB", _codlib); + TRectype rec (IndBil.curr()); + + for (IndBil.read(_isgteq); !IndBil.eof(); IndBil.next()) + { + if (IndBil.curr() != rec) break; + + int annoreg = IndBil.get_int("ANNOREG"); + int mesereg = IndBil.get_int("MESEREG"); + long cditta = IndBil.get_long("CODDITTA"); + TString16 codreg = IndBil.get("CODREG"); + TString16 codvid = IndBil.get("CODVID"); + if (_annoes == annoreg && _fino_a_mese == mesereg + && _ditta == cditta && codreg == _codreg && _codice_vidi == codvid) + { + trovato = TRUE; + numero_riga = IndBil.get_long("NUMREG"); + break; + } + else numero_riga = IndBil.get_long("NUMREG") + 1; + // cosi' mi posiziono su quel mese (altrimenti rischio di generare + // due righe per lo stesso mese e registro => la stampa di vidimazione + // mi sballa tutta!!! + } + nuovo.put("ANNO", _annoes); + nuovo.put("CODLIB", _codlib); + nuovo.put("NUMREG", numero_riga); + + nuovo.put("ANNOREG", _annoes); + nuovo.put("MESEREG", _fino_a_mese); // su libro unico ho un solo mese in gioco! + nuovo.put("PAGINI", _primast + 1); // numero iniziale pagina libro unico + nuovo.put("PAGFIN", _u_stampata); // numero finale pagina libro unico + nuovo.put("CODDITTA", _ditta); + nuovo.put("CODREG", _codreg); + nuovo.put("CODVID", _codice_vidi); + nuovo.put("PAGINIUT", _numini + 1); + nuovo.put("PAGFINUT", _pagine_stampate); + + if (!trovato) + IndBil.write(nuovo); + else IndBil.rewrite(nuovo); + } + //_primast = _u_stampata; //per la numerazione dei registri successivi + aggiorna_lib(); + } +} + +void CG4400_application::aggiorna_lib() +{ + TString16 cod = ""; + TTable lbu ("%LBU"); + + cod << _annoes << _codlib; + lbu.zero(); + lbu.put("CODTAB", cod); + if (lbu.read() == NOERR) + { + lbu.put("I0", (long) _fino_a_mese); + lbu.put("I1", (long) _u_stampata); + lbu.rewrite(); + } +} + +bool CG4400_application::stampo_liquidazione(int mese) +{ + //test tradotti alla lettera da AS/400 + //assolutamente incongruenti !!! + if (_tipo_stampa == 1) + { + if ( (_frequiva == 'T' && (mese == 3 || mese == 6 || mese == 9 || mese == 12)) + || _frequiva != 'T' || (mese == 12 && _tipo_riepilogativo == 'A') ) + return TRUE; + } + else + { + if ( (_frequiva == 'T' && (mese == 3 || mese == 6 || mese == 9 || mese == 12)) + || _frequiva != 'T' || (mese == 12 && _tipo_riepilogativo == 'A') ) + if ( (mese == 12 && _tipo_riepilogativo == 'A' && _mese_ultima_liq != 13) + || (mese != 12 && mese > _mese_ultima_liq) + || (mese == 12 && _tipo_riepilogativo != 'A' && mese > _mese_ultima_liq) ) + return TRUE; + } + return FALSE; +} + +void CG4400_application::stampa_vidi() +{ + TLocalisamfile IndBil (LF_INDLIB); + TTable TabVid ("%VID"); + TString16 codreg; + TString16 vid; + long ditta, pagfin, pagfinut; + int mese; + TPrintrow row; + + _ok_vidi = FALSE; + + if (!printer().isopen()) + printer().open(); + + IndBil.zero(); + IndBil.put("ANNO", _annoes); + IndBil.put("CODLIB", _codlib); + TRectype rec (IndBil.curr()); + IndBil.read (_isgteq); + for (; !IndBil.eof(); IndBil.next()) + { + if (IndBil.curr() != rec) break; + ditta = IndBil.get_long("CODDITTA"); + codreg = IndBil.get("CODREG"); + if (ditta == _ditta && codreg == _codreg) + { + if (!_ok_vidi) + { + ++_u_stampata; + ++_pagine_stampate; + _ok_vidi = TRUE; + } + mese = IndBil.get_int("MESEREG"); + pagfin = IndBil.get_long("PAGFIN"); + pagfinut = IndBil.get_long("PAGFINUT"); + if (mese == 12) + { + ++pagfin; + ++pagfinut; + TRectype nuovo (IndBil.curr()); + nuovo.put("PAGFIN", pagfin); + nuovo.put("PAGFINUT", pagfinut); + IndBil.rewrite(nuovo); + } + row.reset(); + row.put(format("%s", itom(mese)), 0); + row.put(format("%5ld", IndBil.get_long("PAGINI")), 10); + row.put(format("%5ld", pagfin), 17); + row.put(format("%5ld", IndBil.get_long("PAGINIUT")), 25); + row.put(format("%5ld", pagfinut), 32); + vid = IndBil.get("CODVID"); + TabVid.zero(); + TabVid.put("CODTAB", vid); + if (TabVid.read() == NOERR) + { + row.put(format("%s", (const char*)TabVid.get("S0")), 39); + row.put(format("%7d",TabVid.get_long("I0")), 71); + row.put(format("%7d",TabVid.get_long("I1")), 79); + row.put(format("%7d",TabVid.get_long("I2")), 87); + TDate d(TabVid.get_long("D0")); + row.put(format("%s", (const char*)d.string()), 95); + row.put(format("%s", (const char*)TabVid.get("S1")), 106); + } + printer().print(row); + } + } + printer().close(); +} + +void CG4400_application::liq_b0_settato() +{ + TFilename f; + f.temp("rg"); + if (_tipo_stampa == 1) + send_message('S',f, _datareg.month()); + else send_message('s',f, _datareg.month()); + //TString80 nomef; + //nomef = f.path(); nomef << "\\" << f.name(); + //if (fexist(nomef)) + if (fexist(f)) + { + printer().formfeed(); + _intesta_liq = TRUE; + //printer().footerlen(0); + merge_export_file(f,FALSE,TRUE); + _intesta_liq = FALSE; + remove(f); + } +} + +void CG4400_application::liq_other_case() +{ + if (_scelta == prosegui_cal_stampa) + { + if (stampo_liquidazione(_datareg.month())) + { + _t.temp("reg"); + if (_tipo_stampa == 1) + send_message('L', _t, _datareg.month()); + else send_message('l', _t, _datareg.month()); + } + else //se chiamo la liquidazione con L o l mi calcola anche i progressivi + if (_tipo_stampa != 1) + { + TFilename app; + app.temp(); + send_message('C', app, _datareg.month()); + } + } + if (_scelta == prosegui_stampa) + { + if (stampo_liquidazione(_datareg.month())) + { + _t.temp("reg"); + if (_tipo_stampa == 1) + send_message('S', _t, _datareg.month()); + else send_message('s', _t, _datareg.month()); + } + if (_tipo_stampa != 1) //in stampa di prova i progressivi me li calcolo io!!! + { //Why??? + TFilename app; + app.temp(); + send_message('C', app, _datareg.month()); + } + } + if (_scelta == no_liquidazione && _tipo_stampa != 1) + { + TFilename app; + app.temp(); + send_message('C', app, _datareg.month()); + } +} + +print_action CG4400_application::postprocess_page (int file, int counter) +{ + if (file == LF_MOV) + { + if (counter) //dopo aver fatto un REPEAT_PAGE (cioe' dopo aver stampato le righe settate in set_page_tot_reg()), in pratica a rottura di mese o alla fine + { + reset_print(); + if (_liquidazione) + if (!_st_liq[_datareg.month()] && stampo_liquidazione(_datareg.month())) + { + _st_liq[_datareg.month()] = TRUE; + if (_scelta == B0_settato) + liq_b0_settato(); + if (_scelta == prosegui_stampa || _scelta == prosegui_cal_stampa) + { + if (fexist(_t)) + { + printer().formfeed(); + _intesta_liq = TRUE; + //printer().footerlen(0); + merge_export_file(_t,FALSE,TRUE); + _intesta_liq = FALSE; + remove(_t); + } + } + } + //modifica del 26/07/1995 + TRecnotype pos = _cur->pos(); + long items = _cur->items(); + if (pos == items-1) + if (_tipo_stampa != 3 && _liquidazione) + stampa_liq_mesi_succ(); + //fine modifica + } + if (!counter) + { + bool FINITO = FALSE; + TRecnotype pos = _cur->pos(); + long items = _cur->items(); + + FINITO = (pos == items-1); + + if ( FINITO ) + { + liq_other_case(); + if (_tipo_stampa != 1) + calcola_progressivi(); + set_page_tot_reg(); + return REPEAT_PAGE; + } + else + { + TLocalisamfile& mov = _cur->file(LF_MOV); + _cur->save_status(); + ++(*_cur); + _dataregs = mov.get_date(MOV_DATAREG); + --(*_cur); + _cur->restore_status(); + + if (_dataregs.month() != _dataregp.month()) + { + liq_other_case(); + if (_tipo_stampa != 1) + calcola_progressivi(); + set_page_tot_reg(); + return REPEAT_PAGE; + } + } + } + } + return NEXT_PAGE; +} + +bool CG4400_application::set_print(int n) +{ + TMask m ("cg4400a"); + int giorni_del_mese; + bool ok; + + m.set_handler (TIPO_STAMPA, mask_tipo_stampa); + m.set_handler (DA_DATA, mask_data); + m.set_handler (A_DATA, mask_data); + m.set_handler (MESE, mask_mese); + m.set_handler (FINO_A_MESE, mask_mese); + m.set_handler (CODICE_LIB_UN, mask_cod); + m.set_handler (CODICE_LIBRO_IVA, mask_libun); + m.set_handler (DLG_SELECT, mask_select); + m.set_handler (F_ANNULLA, mask_azzera); + m.set_handler (A_CODICE, to_ditt_handler); + m.set_handler (DA_CODICE, fr_ditt_handler); + m.set_handler (BUT_DTO, to_butt_handler); + m.set_handler (BUT_DFR, fr_butt_handler); + m.set_handler (ANNO, year_handler); + + m.field(F_SELECT).set(format("%ld",_selected.ones())); + set_choice_limits(m); + + //printer().footerlen(5); + set_real_picture("###.###.###.###"); + + while (ok = set_ditte(m)) + { + if (_selected.ones() > 0l) + { + _annoes = m.get_int(ANNO);//in realta' e' l'anno IVA !!! + _tipo_stampa = m.get_int(TIPO_STAMPA); + _stampa_width = m.get_int(STAMPA_WIDTH); + _stampa_len = m.get_int(STAMPA_LEN); + if (_stampa_width == 1) + _stampa_width = 132; + else _stampa_width = 198; + if (_stampa_len != 0) + printer().formlen(_stampa_len); + //Se stampa di prova l'utente indica data_da e data_a + if (_tipo_stampa == 1) + { + _data_stampa = m.get(DATA_STAMPA); + _data_da = m.get(DA_DATA); + _data_a = m.get(A_DATA); + + if (!_data_da.ok()) +// _data_da = format("01/01/%4d", _annoes); + _data_da = TDate(1, 1, _annoes); // Meglio cosi' + + if (!_data_a.ok()) +// _data_a = format("31/12/%4d", _annoes); + _data_a = TDate(31, 12, _annoes); // Meglio cosi' + + const TDate d(31,12,_annoes); + if (_data_a == d) + _tipo_riepilogativo = m.get(TIPO_RIEPILOGATIVO)[0]; + else _tipo_riepilogativo = ' '; + printer().setdate(_data_stampa); + } + else //stampe definitive + { + if ( (_tipo_stampa == 2) || (_tipo_stampa == 4) ) + { + _fino_a_mese = m.get_int(FINO_A_MESE); +// _data_da = format("01/01/%4d", _annoes); //e non ultima data di stampa del registro (come invece verrebbe spontaneo di pensare) + _data_da = TDate(1, 1, _annoes); // Meglio cosi' + } + else //stampa su libro unico + { + _codlib = m.get(CODICE_LIB_UN); + _fino_a_mese = m.get_int(MESE); + _u_stampata = m.get_int(ULTIMA_PAGINA); + _rif_vid = m.get_bool(RIF_VID); + _primast = _u_stampata; +// _data_da = format("01/%02d/%04d", _fino_a_mese, _annoes); + _data_da = TDate(1, _fino_a_mese, _annoes); // Meglio cosi' + } + if (_fino_a_mese == 12) + { + giorni_del_mese = 31; + _tipo_riepilogativo = m.get(TIPO_RIEPILOGATIVO)[0]; + } + else + { + _tipo_riepilogativo = ' '; +// TDate primo = format("01/%02d/%4d", _fino_a_mese+1, _annoes); +// --primo; + TDate primo(1, _fino_a_mese, _annoes); + primo.set_end_month(); // Meglio cosi' + + giorni_del_mese = primo.day(); + } +// _data_a=format("%02d/%02d/%4d",giorni_del_mese,_fino_a_mese,_annoes); + _data_a = TDate(giorni_del_mese, _fino_a_mese, _annoes); // Meglio cosi' + } + _stampa_data_reg = stampa_datareg(); + if (_tipo_stampa == 3) + compila_lib(); + stampa_registri_IVA(m); + } + else + { + warning_box("Nessuna ditta selezionata!"); + continue; + } + } + return FALSE; +} + +bool CG4400_application::look_lia(long ditta) +{ + if (ditta == 0l) ditta = get_firm(); + + TString16 y; y.format("%05ld%04d", ditta, _annoes); + + _tablia->zero(); + _tablia->put("CODTAB", y); + _tablia->read(); + const bool ok = _tablia->good(); + if (ok) + _credito = _tablia->get_real("R0"); + else _credito = ZERO; + return ok; +} + +void CG4400_application::look_reg() +{ + _liquidazione = _tabreg->get_bool("B7"); + _riep_liq = _tabreg->get_bool("B6"); + _corrispettivi = _tabreg->get_bool("B0"); + _sosp_imposta = _tabreg->get_bool("B1"); + _pagine_stampate = _tabreg->get_long("I1"); + _numini = _pagine_stampate; + _cod_un_loc = _tabreg->get_int("I7"); + _mese_ultima_liq = _tabreg->get_int("I4"); + _mese_credito = _tabreg->get_int("I8"); + _codatt = _tabreg->get("S8"); + _tipoatt = tipo_attivita(); + _attivita = desc_attivita(); + _desc_lib = _tabreg->get ("S0"); + _stampa_ind_ditta = _tabreg->get_bool ("B9"); + _stampa_ind_comp = _tabreg->get_bool ("B5"); + _stampa_cred_pre = _tabreg->get_bool ("B4"); +} + +void CG4400_application::clear_stliq() +{ + for (int i=0; i <= 12; i++) + _st_liq[i] = FALSE; +} + +bool CG4400_application::setta_mask(long i) +{ + if (_stampa_mese == 13) _stampa_mese = 0; + if (_tipo_stampa == 2 || _tipo_stampa == 4) + { + TMask mb("cg4400b"); + mb.set(F_CODDITTA, _ditta); + mb.set(F_RAGSOC, _ditte->row(i).get(2)); + mb.set(COD_LIB, _codreg); + const char* m = ""; + m = format("%02d", _stampa_mese); + mb.set(U_MESE, m); + mb.set(U_PAGINA, _pagine_stampate); + if (_u_data.ok()) + mb.set(U_DATA, _u_data.string()); + KEY tasto = mb.run(); + if (tasto != K_ENTER) return FALSE; + } + return TRUE; +} + +void CG4400_application::no_movimenti() +{ + _mov_empty = TRUE; + if (_liquidazione) + { + int da, a; + //stampo la liquidazione per tutti i mesi fino a _fino_a_mese + if (_tipo_stampa == 2 || _tipo_stampa == 4) + da = 1; + if (_tipo_stampa == 3) + da = _fino_a_mese; + if (_tipo_stampa == 1) + da = _data_da.month(); + if (_tipo_stampa == 1) + a = _data_a.month(); + else a = _fino_a_mese; + for (int m = da; m <= a; m++) + { + if (stampo_liquidazione(m)) + { + if (! printer().isopen()) + printer().open(); + TFilename f; + f.temp("rgp"); +// _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header + _datareg = TDate(1, m, _annoes); // Meglio cosi' + + if (_scelta == B0_settato || _scelta == prosegui_stampa) + { + if (_tipo_stampa == 1) + send_message('S',f, m); + else send_message('s',f, m); + } + else //_scelta == prosegui_cal_stampa + { + if (_tipo_stampa == 1) + send_message('L', f, m); + else send_message('l', f, m); + } + if (fexist(f)) + { + _intesta_liq = TRUE; + //printer().footerlen(0); + merge_export_file(f,FALSE,TRUE); + printer().formfeed(); + _intesta_liq = FALSE; + remove(f); + } + } + } + if (printer().isopen()) printer().close(); + } + if (_tipo_stampa != 1) scrivi_reg(); //aggiorno il registro anche se non ho stampato proprio nulla per quel mese! +} + +bool CG4400_application::stampa_registri_IVA(const TMask& m) +{ + bool ok = FALSE; + for (int i = 0; i < _ditte->items(); i++) + { + if (_selected[(long)i]) + { + bool msg = TRUE; + _ditta = _ditte->row(i).get_long(1); + _frequiva = _ditte->row(i).get_char(3); + _intesta_liq = FALSE; + _intesta_vidi = FALSE; + _primast = _u_stampata; + _ok_vidi = FALSE; + _stampa_mese = 13; + + TApplication::set_firm(_ditta); + look_lia(); + ok = compila_reg(m); + if (!ok) continue; + if (_tipo_stampa == 2 || _tipo_stampa == 4) + if (!controlla_mov()) + { + TApplication::set_firm(__firm); + return fatal_box("Finire di stampare registri anno precedente"); + } + if (!_stampa_tutti_i_registri) + { + _scelta = controlla_b0(); + _cur->set_filterfunction(filter_func); + ok = setta_mask(i); + if (!ok) continue; + if (_liquidazione) + { + if (_tipo_stampa == 2 || _tipo_stampa == 4) + _size_header = _stampa_ind_ditta ? 3 : 2; + else _size_header = 3; + clear_stliq(); + _scelta = controlla_liquidazione(); + if (_scelta == non_proseguire) + return FALSE; + } + + (*_cur) = 0L; //la filter function viene chiamata quando posiziono il cursore + const long item = _cur->items(); + + // 17.5.95 Leggo parametri di stampa del registro + TString16 config; + const long codditta = get_firm(); + const char* reg = (const char*)_codreg; + config.format("REG%05ld%03s", codditta, reg); + printer().read_configuration(config); + + if (item > 0l) + { + //modifica del 26/07/1995 + _mov_empty = TRUE; + //fine + + print(); + + if (is_cancelled()) return FALSE; + + /*** + if (_tipo_stampa != 3 && _liquidazione) + stampa_liq_mesi_succ(); + ***/ + } + //non ci sono movimenti da stampare nel periodo richiesto! + else no_movimenti(); + + if (_tipo_stampa == 3 && _rif_vid) + { + _intesta_vidi = TRUE; + stampa_vidi(); //stampa riferimenti vidimazione + } + } + else //stampa tutti i registri + { + TString16 codtab, cod_lib_un; + int anno; + TDate sca_vid; + for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) + { + _tipo_reg = _tabreg->get_int("I0"); + codtab = _tabreg->get("CODTAB"); + anno = atoi(codtab.mid(0,4)); + if (anno > _annoes) + break; + if (anno == _annoes) + if ( _tipo_reg == 1 || _tipo_reg == 2 ) //registro iva + { + _codreg = codtab.mid(4,3); + cod_lib_un = _tabreg->get("S6"); + sca_vid = _tabreg->get_date("D1"); + _stampa_ind_ditta = _tabreg->get_bool("B9"); + _liquidazione = _tabreg->get_bool("B7"); + if (_tipo_stampa != 1) + _u_data = _tabreg->get_date("D3"); + if (_tipo_stampa == 2 || _tipo_stampa == 4) + { + if (cod_lib_un.not_empty()) + continue; + if (sca_vid.ok()) + if (sca_vid.month() < _fino_a_mese) + continue; + if (_u_data.ok()) + if (_data_a < _u_data) //e' molto imp. che rimanga < e non <= !!! + { //(per via del discorso liq. annuale) + message_box("Ditta %ld: Il registro %s e' gia' stato stampato come bollato di %s", _ditta, (const char*) _codreg, itom(_fino_a_mese)); + continue; + } + } + if (_tipo_stampa == 4) //stampa con riferimenti al libro giornale + { + TString16 d; + bool good; + TRecnotype rec = _tabreg->recno(); + bool trovato = cerca_libro_gio(d, &good); + _tabreg->readat(rec); + if (!trovato) + continue; + } + if (_tipo_stampa == 3) //stampa su libro unico + { + if (cod_lib_un != _codlib) + continue; + if (sca_vid.ok()) + if (sca_vid.month() < _fino_a_mese) + continue; + if (_u_data.ok()) + if (_fino_a_mese < _u_data.month()) //significa che e' gia' + continue; //stato stampato + } + msg = FALSE; + + look_reg(); + + _intesta_liq = FALSE; + _intesta_vidi = FALSE; + _primast = _u_stampata; //per la numerazione dei registri successivi + _ok_vidi = FALSE; + _stampa_mese = 13; + _scelta = controlla_b0(); //sul registro non va stampata la liq. ma comunque + //va richiamata per il calcolo progressivi (a seconda di b0) + //se non e' stampa di prova + ok = setta_mask(i); + if (!ok) continue; + + if (_liquidazione) + { + if (_tipo_stampa == 2 || _tipo_stampa == 4) + _size_header = _stampa_ind_ditta ? 3 : 2; + else _size_header = 3; + clear_stliq(); + _scelta = controlla_liquidazione(); + if (_scelta == non_proseguire) + return FALSE; + } + + _cur->set_filterfunction(NULL); + _cur->set_filterfunction(filter_func); + + // Vado a vedere se ci sono movimenti + (*_cur) = 0L; + const long items = _cur->items(); + + // 17.5.95 Leggo parametri di stampa del registro + TString16 config; + const long codditta = get_firm(); + const char* reg = (const char*)_codreg; + config.format("REG%05ld%03s", codditta, reg); + printer().read_configuration(config); + + if (items > 0l) + { + //modifica del 26/07/1995; + _mov_empty = TRUE; + //fine + + print(); + + if (is_cancelled()) return FALSE; + + /*** + if (_tipo_stampa != 3 && _liquidazione) + stampa_liq_mesi_succ(); + ***/ + } + else + no_movimenti(); + + if (_tipo_stampa == 3 && _rif_vid) + { + _intesta_vidi = TRUE; + stampa_vidi(); //stampa riferimenti vidimazione + } + } + } //for + if (msg) + //if ( (_tipo_stampa != 3) || (_tipo_stampa == 3 && _fino_a_mese == 1 && _selected.ones() == 1L) ) //il messaggio seguente, nel caso di stampa su libro unico, + if(_tipo_stampa == 3 && _fino_a_mese == 1 && _selected.ones() == 1L) + message_box("Ditta %ld: nessun registro soddisfa i parametri indicati", _ditta); //viene gia' dato nell'handler + } //da Gennaio) + } + } + TApplication::set_firm(__firm); + return TRUE; +} + + +void CG4400_application::stampa_liq_mesi_succ() +{ + int da = _datareg.month() + 1; + int a = _data_a.month(); + for (int m = da; m <= a; m++) + { + if (stampo_liquidazione(m)) + { + /* + if (!printer().isopen()) + printer().open(); + */ +// _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header (intestazione per la stampa liquidazione) + _datareg = TDate(1, m, _annoes); // Meglio cosi' + TFilename t; + t.temp("iva"); + if (_tipo_stampa == 1) + send_message('L',t, m); //prima era S ma non andava bene! + else send_message('l',t,m); //prima era s + //TString80 nomef; nomef = t.path(); nomef << "\\" << t.name(); + //if (fexist(nomef)) + if (fexist(t)) + { + _intesta_liq = TRUE; + printer().formfeed(); + //printer().footerlen(0); + merge_export_file(t,FALSE,TRUE); + _intesta_liq = FALSE; + remove(t); + } + } + } + //if (printer().isopen()) printer().close(); +} + +void CG4400_application::send_message(char tipo, const TFilename& nome, int mese) +{ + const char* app; + + if (tipo == 'S' || tipo == 's') + app = "cg4 -2 -S"; + else if (tipo == 'C') + app = "cg4 -2 -C"; + else app = "cg4 -2"; + + TToken_string ss(10); + + ss.add(_annoes); + if (_tipo_riepilogativo == 'A' && mese == 12) + ss.add(13); + else ss.add(mese); + ss.add(_ditta); + ss.add(tipo); + ss.add(_data_stampa.string()); + ss.add(nome); + ss.add(_size_header); + //ss.add("x"); + + TMessage liq (app, "RCL", ss); + liq.send(); + + TExternal_app pn(app); + pn.run(); +} + +bool CG4400_application::set_ditte(TMask& m) +{ + /* + _selected.reset(); + m.field(F_SELECT).set("0"); + m.field(DA_CODICE).set(""); + m.field(A_CODICE).set(""); + */ + m.field(TIPO_STAMPA).set("1"); + m.field(DA_DATA).set(""); + m.field(A_DATA).set(""); + m.field(CODICE_LIBRO_PROVA).set(""); + + KEY tasto; + tasto = m.run(); + // m.first_focus(tasto); + return tasto == K_ENTER; +} + +TRectype& CG4400_application::look_comuni (const char * cod) +{ + _com->zero(); + _com->put(COM_COM, cod); + _com->read(); + if (_com->bad()) + _com->zero(); + + return _com->curr(); +} + +void CG4400_application::get_dati_ditta() +{ + TLocalisamfile nditte(LF_NDITTE); + TLocalisamfile anag(LF_ANAG); + TLocalisamfile unloc(LF_UNLOC); + TString codanagr; + TString tipoa; + + nditte.zero(); + nditte.put(NDT_CODDITTA, get_firm()); + nditte.read(); + + if (nditte.bad()) nditte.zero(); + + codanagr = nditte.get(NDT_CODANAGR); + tipoa = nditte.get(NDT_TIPOA); + _ragsoc = nditte.get(NDT_RAGSOC); + + anag.setkey(1); + anag.zero(); + anag.put (ANA_TIPOA, tipoa); + anag.put (ANA_CODANAGR, codanagr); + anag.read(); + if (anag.bad()) anag.zero(); + + _cofi = anag.get(ANA_COFI); + _paiva = anag.get(ANA_PAIV); + _comunefis = anag.get(ANA_COMRF); + + if (_comunefis.empty()) + _comunefis = anag.get(ANA_COMRES); + + TRectype dep = look_comuni (_comunefis); + + _comunefis = dep.get(COM_DENCOM); + _provfis = dep.get(COM_PROVCOM); + _cap = dep.get(COM_CAPCOM); + if (_comunefis.empty()) + { + _viafis = anag.get(ANA_INDRF); + _viafis.rtrim(); + _viafis << " " << anag.get (ANA_CIVRF); + } + else + { + _viafis = anag.get(ANA_INDRES); + _viafis.rtrim(); + _viafis << " " << anag.get (ANA_CIVRES); + } + + if (_cod_un_loc) + { + unloc.zero(); + unloc.put(ULC_CODDITTA, get_firm()); + unloc.put(ULC_CODULC, _cod_un_loc); + unloc.read(); + if (unloc.read() == NOERR) + { + TRectype dep = look_comuni (unloc.get(ULC_COMULC)); + _comunefis = dep.get(COM_DENCOM); + _provfis = dep.get(COM_PROVCOM); + _cap = dep.get(COM_CAPCOM); + _viafis = unloc.get(ULC_INDULC); + _viafis.rtrim(); + _viafis << " " << unloc.get(ULC_CIVULC); + } + } +} + +int CG4400_application::stampa_intestazione() +{ + int r = 1; + TString codice_ditta; + TString riga(_stampa_width); + + get_dati_ditta(); + codice_ditta << get_firm(); + + set_header (r, "Ditta %s %s %s %s %s %s", (const char*)codice_ditta, + (const char*)_ragsoc, (const char*)_viafis, + (const char*)_cap, (const char*)_comunefis, + (const char*)_provfis); + r++; + //printer().setdate(_data); + if (_tipo_stampa == 1) + { + riga = "REGISTRO DI PROVA Data @<"; + riga.right_just(_stampa_width-6); + } + riga.overwrite (format("Partita iva %s Codice fiscale %s", (const char*)_paiva, (const char*)_cofi)); + set_header (r, riga); + + return r; +} + +void CG4400_application::preprocess_header() +{ + int r=1; + char cor, nd1, nd2; + char tipo = ' '; + char type = ' '; + int mese, anno; + TString riga(_stampa_width); + TString data(30); + + riga.fill('-'); + + if (_tipo_stampa != 3) + { + mese = _datareg.month(); + anno = _datareg.year(); + } + else //se _tipo_stampa == 3 (su libro unico) sto stampando un solo mese + { + mese = _fino_a_mese; + anno = _annoes; + } + + data.format("%s %s %d", "mese di", itom(mese), anno); + + reset_header(); + + if (_tipo_stampa == 2 || _tipo_stampa == 4) + { + if (_stampa_ind_ditta) + r = stampa_intestazione(); + } + else // se stampa di prova o su libro unico l'intestazione della ditta + // va sempre stampata + r = stampa_intestazione(); + + if (_tipo_stampa == 3 && !_intesta_vidi) + { + ++_u_stampata; + ++_pagine_stampate; + } + + if (_tipo_stampa == 2 || _tipo_stampa == 4) + ++_pagine_stampate; + + if (_tipo_stampa == 3) + set_header(r, "@94gProgr.Studio %ld@114gProgr.Utente %ld", _u_stampata, _pagine_stampate); + + // cosi' sono sicura che l'aggiornamento viene fatto ad ogni salto pagina + // (cioe' a rottura di mese) + if (_tipo_stampa != 1) aggiorna_reg(_ok_vidi); + + r++; + + /* + if (!_intesta_vidi) + set_header(r, "Registro IVA: %s %s %s Attivita\' %s %s", + (const char *) _codreg, (const char *) _desc_lib, + (const char *) data, (const char *) _codatt, + (const char *) _attivita); + */ + if (!_intesta_vidi) + { + if (_intesta_liq) + set_header(r, "Registro IVA: %s %s %s", (const char*)_codreg, + (const char*)_desc_lib, (const char*) data); + else set_header(r, "Registro IVA: %s %s %s Attivita\' %s %s", + (const char*) _codreg, (const char*) _desc_lib, + (const char*) data, (const char*) _codatt, + (const char*) _attivita); + } + else + { + set_header(r++, "Registro IVA: %s %s", (const char *) _codreg, (const char *) _desc_lib); + set_header(r, "RIFERIMENTI VIDIMAZIONE"); + } + + if (_intesta_liq) + { + /* + r++; + set_header(r++, "CALCOLO LIQUIDAZIONE IVA"); + set_header(r++,riga); + TString title (80); + title << "Liquidazione IVA "; + if (_tipo_riepilogativo == 'A' && mese == 12) + title << "Annuale " << format("%d", anno); + else + { + title << "del periodo"; + title << format(" %s %d", itom(mese), anno); + } + set_header(r++, "%s@102g Frequenza %s", (const char*) title, _frequiva == 'T' ? "T" : "M"); + set_header(r++,riga); + set_header(r,""); + */ + } + else //non sto stampando la liquidazione + { + r++; + set_header(r, riga); + r++; + if (_tipo_reg == 1) //registro vendite + { + cor = 'R'; + nd1 = ' '; + nd2 = ' '; + } + if (_tipo_reg == 2) + { + cor = 'C'; + nd1 = 'N'; + nd2 = 'D'; + } + if (_tipoatt == "E") //attivita' mista + { + tipo = 'A'; + type = 'T'; + } + /* + if ((!_stampa_data_reg) && _stampa_width == 132) + set_header(r,"Data I/P"); + */ + if (_tipo_stampa == 1) //stampa di prova (_intesta_vidi e' di sicuro FALSE) + { + if (_stampa_width == 132) + { + set_header(r,"@10gNum.@19gDocumento@66gT Tipo@102gCod %c@123gT %c@128gNum", nd1, tipo); + r++; + set_header(r, "Data reg. prot.@17gData@24gNumero Codice Ragione sociale/descrizione@66gO Doc.@74gTotale doc.@90gImponibile Iva %c@115gImposta@123g%c %c@128gReg", nd2, cor, type); + r++; + } + else //stampa a 198 + { + set_header(r,"Registrazione Documento@66gT Tipo@110gCod %c@132g%c T@139gNum.", nd1, tipo, cor); + r++; + set_header(r, "Data Protocollo Data@24gNumero Codice Ragione sociale/descrizione@66gO Documento@80gTot.Documento@98gImponibile Iva %c@124gImposta@132g%c %c@139gReg.", nd2, type, cor); + r++; + } + } + else if (!_intesta_vidi) + { + if (_stampa_width == 132) + { + set_header(r,"@10gNum.@19gDocumento@66gT Tipo@102gCod %c@123gT %c", nd1, tipo); + if (_tipo_stampa == 4) //stampa definitiva con rif. al libro giornale + set_header(r, "@128gNum."); + r++; + set_header(r, "Data reg. prot.@17gData@24gNumero Codice Ragione sociale/descrizione@66gO Doc.@74gTotale doc.@90gImponibile Iva %c@115gImposta@123g%c %c", + nd2, cor, type); + if (_tipo_stampa == 4) + set_header(r, "@128gop."); + r++; + } + else //stampa a 198 + { + set_header(r,"Registrazione Documento@66gT Tipo@110gCod %c@132g%c T", nd1, tipo); + if (_tipo_stampa == 4) + set_header(r, "@139gNum."); + r++; + set_header(r, "Data Protocollo Data@24gNumero Codice Ragione sociale/descrizione@66gO Documento@80gTot.Documento@98gImponibile Iva %c@124gImposta@132g%c %c", nd2, type, cor); + if (_tipo_stampa == 4) + set_header(r, "@139gop. @144gCodice conto @159gDescrizione sottoconto"); + r++; + } + } + else if (_tipo_stampa == 3 && _intesta_vidi) + { + TString tr(52); + tr.fill('-'); + set_header(r++,"@10gPagine studio Pagine utente ---------------- V I D I M A Z I O N E %s", (const char*)tr); + set_header(r++,"Mese@12gda@20ga@27gda@35ga Intestatario@71gN.fogli Pag.in. Pag.fin. Data Ufficio"); + } + if (_stampa_ind_comp && !_intesta_vidi) + set_header(r++, "@38gGeneralita'"); + + set_header(r, riga); + } +} + +int cg4400 (int argc, char * argv[]) +{ + CG4400_application a; + a.run(argc, argv, "Stampa registri IVA"); + return 0; +} + + + + + + + + + + + + + + diff --git a/cg/cg4400.h b/cg/cg4400.h index 0d26a80b5..bf5fc1b01 100755 --- a/cg/cg4400.h +++ b/cg/cg4400.h @@ -1,160 +1,160 @@ -// -// cg4400.h -// -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "cglib03.h" -#include "cglib04.h" -#include "conto.h" - -enum messaggio { - no_liquidazione, - B0_settato, - non_proseguire, - prosegui_stampa, - prosegui_cal_stampa - }; - -class CG4400_application : public TPrintapp -{ - TCursor * _cur; - TRelation *_rel, *_nditte; - TLocalisamfile *_clifo, *_occas, *_tab, *_tabcom, *_com, *_anag, *_unloc, *_attiv, *_indlib; - TTable *_tabreg, *_tablbu, *_tablim, *_tabpim, *_tablia, *_tabiva; - TTable *_tabpla, *_tabppa, *_tabvid; - TRigaiva_array _iva_array, _riga_rmi; - TTipodoc_array _doc_array; - TRiga_array _tot_iva_array; - TBit_array _selected; - TArray_sheet *_ditte; - TArray _nomiditte; - bool _st_liq[13]; - bool _test; - TRecnotype _nrec; - bool _mov_empty, _stampa_ind_ditta, _stampa_tutti_i_registri, _auto_intraf, _stampa; - bool _corrispettivi, _liquidazione, _riep_liq, _stampa_ind_comp, _esiste_riga_iva, _stampa_cred_pre; - bool _rif_vid, _intesta_vidi, _intesta_liq, _stampa_data_reg, _ok_vidi; - bool _sosp_imposta; - char _frequiva, _tipo_riepilogativo; - TDate _data_da, _data_a, _data_stampa, _dataregp, _dataregs, _datareg; - TDate _u_data; - long _n_ditte, _u_stampata, _primast, __firm, _uprotivap, _ditta; - long _numini, _pagine_stampate; - int _fino_a_mese, _tipo_reg, _tipo_stampa, _cod_un_loc; - int _annoes, _r, _stampa_width, _mese_ultima_liq, _mese_credito; - int _stampa_len, _stampa_mese, _size_header; - real _totale_doc, _credito; - TString _codreg, _desc_lib, _codatt, _attivita, _tipoatt; - TString _tipodoc, _descr_doc, _codlib, _codice_vidi; - TString _cofi,_cap,_paiva,_ragsoc,_comunefis,_provfis,_viafis; - TFilename _t, _pippo; - - TParagraph_string* _desc27; - messaggio _scelta; - -protected: - - static bool filter_func (const TRelation * r); - static bool mask_tipo_stampa (TMask_field&, KEY); - static bool to_ditt_handler (TMask_field&, KEY); - static bool fr_ditt_handler (TMask_field&, KEY); - static bool to_butt_handler (TMask_field&, KEY); - static bool fr_butt_handler (TMask_field&, KEY); - static bool mask_cod (TMask_field&, KEY); - static bool mask_libun (TMask_field&, KEY); - static bool mask_data (TMask_field&, KEY); - static bool mask_mese (TMask_field&, KEY); - static bool mask_fino_a_mese (TMask_field&, KEY); - static bool mask_select (TMask_field&, KEY); - static bool mask_azzera (TMask_field&, KEY); - static bool year_handler (TMask_field&, KEY); - -public: - - const char* desc_attivita (); - const char* tipo_attivita (); - const char* descr_doc (); - const char* descr_iva (const char *); - TRectype& ricerca_occ(const char*); - TRectype& ricerca_cf (char, long); - TRectype& look_comuni(const char*); - TArray_sheet* get_ditte_sheet() { return _ditte; } - int setta_riga (int, const TRigaiva&, real&, real&, real&, real&); - int riga_rmoviva(); - bool set_print(int); - bool set_ditte(TMask&); - bool compila_reg(const TMask&); - bool compila_lib(); - messaggio controlla_liquidazione(); - messaggio controlla_b0(); - bool controlla_mov(); - bool stampo_liquidazione(int); - bool ventilazione(const char*); - bool cerca_libro_gio(TString&, bool*); - bool look_reg (int, int, TString&, int, const char*, int*, long); - bool look_regs(int, TString&, int, int*, long, TProgind*); - bool stampa_totali_finali(); - bool stampa_datareg(); - bool stampa_registri_IVA(const TMask&); - bool look_lia(long ditta = 0l); - bool ricerca_mese(TString&,TString&,int,int,TMask_field&); - void set_choice_limits(TMask&); - void build_ditte_sheet(); - void cerca_reg(const TString&, byte*); - void set_page_tot_reg(); - void send_message(char, const TFilename&,int); - void aggiorna_reg(const bool aggiorna_vidi); - void aggiorna_lib(); - void calcola_progressivi(); - void stampa_liq_mesi_succ(); - void look_reg(); - void no_movimenti(); - void liq_b0_settato(); - void liq_other_case(); - bool setta_mask(long); - bool preprocess_page(int, int); - int stampa_intestazione(); - int stampa_prospetto(); - long select_firm_range(long,long); - void stampa_plafonds(int); - void get_dati_ditta(); - void stampa_vidi(); - void scrivi_reg(); - int stampa_acquisti(int); - real stampa_valori_plafonds(const real&, const int, TTable&, const char*); - void build_nomiditte(TProgind* pnd = NULL); - void set_year(int y) { _annoes = y; } - void clear_stliq(); - virtual bool preprocess_print(int, int); - virtual bool user_create(); - virtual bool user_destroy(); - virtual print_action postprocess_page (int, int); - virtual void preprocess_header(); - - CG4400_application() : TPrintapp(), _ditte(NULL), _selected(10000), _nomiditte(100), _test(FALSE) {} - virtual ~CG4400_application() {} -}; - - - - +// +// cg4400.h +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "cglib03.h" +#include "cglib04.h" +#include "conto.h" + +enum messaggio { + no_liquidazione, + B0_settato, + non_proseguire, + prosegui_stampa, + prosegui_cal_stampa + }; + +class CG4400_application : public TPrintapp +{ + TCursor * _cur; + TRelation *_rel, *_nditte; + TLocalisamfile *_clifo, *_occas, *_tab, *_tabcom, *_com, *_anag, *_unloc, *_attiv, *_indlib; + TTable *_tabreg, *_tablbu, *_tablim, *_tabpim, *_tablia, *_tabiva; + TTable *_tabpla, *_tabppa, *_tabvid; + TRigaiva_array _iva_array, _riga_rmi; + TTipodoc_array _doc_array; + TRiga_array _tot_iva_array; + TBit_array _selected; + TArray_sheet *_ditte; + TArray _nomiditte; + bool _st_liq[13]; + bool _test; + TRecnotype _nrec; + bool _mov_empty, _stampa_ind_ditta, _stampa_tutti_i_registri, _auto_intraf, _stampa; + bool _corrispettivi, _liquidazione, _riep_liq, _stampa_ind_comp, _esiste_riga_iva, _stampa_cred_pre; + bool _rif_vid, _intesta_vidi, _intesta_liq, _stampa_data_reg, _ok_vidi; + bool _sosp_imposta; + char _frequiva, _tipo_riepilogativo; + TDate _data_da, _data_a, _data_stampa, _dataregp, _dataregs, _datareg; + TDate _u_data; + long _n_ditte, _u_stampata, _primast, __firm, _uprotivap, _ditta; + long _numini, _pagine_stampate; + int _fino_a_mese, _tipo_reg, _tipo_stampa, _cod_un_loc; + int _annoes, _r, _stampa_width, _mese_ultima_liq, _mese_credito; + int _stampa_len, _stampa_mese, _size_header; + real _totale_doc, _credito; + TString _codreg, _desc_lib, _codatt, _attivita, _tipoatt; + TString _tipodoc, _descr_doc, _codlib, _codice_vidi; + TString _cofi,_cap,_paiva,_ragsoc,_comunefis,_provfis,_viafis; + TFilename _t, _pippo; + + TParagraph_string* _desc27; + messaggio _scelta; + +protected: + + static bool filter_func (const TRelation * r); + static bool mask_tipo_stampa (TMask_field&, KEY); + static bool to_ditt_handler (TMask_field&, KEY); + static bool fr_ditt_handler (TMask_field&, KEY); + static bool to_butt_handler (TMask_field&, KEY); + static bool fr_butt_handler (TMask_field&, KEY); + static bool mask_cod (TMask_field&, KEY); + static bool mask_libun (TMask_field&, KEY); + static bool mask_data (TMask_field&, KEY); + static bool mask_mese (TMask_field&, KEY); + static bool mask_fino_a_mese (TMask_field&, KEY); + static bool mask_select (TMask_field&, KEY); + static bool mask_azzera (TMask_field&, KEY); + static bool year_handler (TMask_field&, KEY); + +public: + + const char* desc_attivita (); + const char* tipo_attivita (); + const char* descr_doc (); + const char* descr_iva (const char *); + TRectype& ricerca_occ(const char*); + TRectype& ricerca_cf (char, long); + TRectype& look_comuni(const char*); + TArray_sheet* get_ditte_sheet() { return _ditte; } + int setta_riga (int, const TRigaiva&, real&, real&, real&, real&); + int riga_rmoviva(); + bool set_print(int); + bool set_ditte(TMask&); + bool compila_reg(const TMask&); + bool compila_lib(); + messaggio controlla_liquidazione(); + messaggio controlla_b0(); + bool controlla_mov(); + bool stampo_liquidazione(int); + bool ventilazione(const char*); + bool cerca_libro_gio(TString&, bool*); + bool look_reg (int, int, TString&, int, const char*, int*, long); + bool look_regs(int, TString&, int, int*, long, TProgind*); + bool stampa_totali_finali(); + bool stampa_datareg(); + bool stampa_registri_IVA(const TMask&); + bool look_lia(long ditta = 0l); + bool ricerca_mese(TString&,TString&,int,int,TMask_field&); + void set_choice_limits(TMask&); + void build_ditte_sheet(); + void cerca_reg(const TString&, byte*); + void set_page_tot_reg(); + void send_message(char, const TFilename&,int); + void aggiorna_reg(const bool aggiorna_vidi); + void aggiorna_lib(); + void calcola_progressivi(); + void stampa_liq_mesi_succ(); + void look_reg(); + void no_movimenti(); + void liq_b0_settato(); + void liq_other_case(); + bool setta_mask(long); + bool preprocess_page(int, int); + int stampa_intestazione(); + int stampa_prospetto(); + long select_firm_range(long,long); + void stampa_plafonds(int); + void get_dati_ditta(); + void stampa_vidi(); + void scrivi_reg(); + int stampa_acquisti(int); + real stampa_valori_plafonds(const real&, const int, TTable&, const char*); + void build_nomiditte(TProgind* pnd = NULL); + void set_year(int y) { _annoes = y; } + void clear_stliq(); + virtual bool preprocess_print(int, int); + virtual bool user_create(); + virtual bool user_destroy(); + virtual print_action postprocess_page (int, int); + virtual void preprocess_header(); + + CG4400_application() : TPrintapp(), _ditte(NULL), _selected(10000), _nomiditte(100), _test(FALSE) {} + virtual ~CG4400_application() {} +}; + + + + diff --git a/cg/cg4400b.uml b/cg/cg4400b.uml index 1085aa888..25a653791 100755 --- a/cg/cg4400b.uml +++ b/cg/cg4400b.uml @@ -1,59 +1,59 @@ -#include "cg4400b.h" - -PAGE "Stampa registri IVA" -1 -1 78 12 - -GROUPBOX DLG_NULL 78 3 -BEGIN - PROMPT 1 0 "" -END - -NUMBER F_CODDITTA 5 -BEGIN - PROMPT 3 1 "Ditta " - FLAGS "D" -END - -STRING F_RAGSOC 50 -BEGIN - PROMPT 17 1 "Ragione " - FLAGS "D" -END - -STRING COD_LIB 3 -BEGIN - PROMPT 3 4 "Codice Libro " - FLAGS "D" -END - -LISTBOX U_MESE 10 -BEGIN - PROMPT 3 5 "Stampa mese " - FLAGS "MD" - ITEM "00|Nessuno" -END - -NUMBER U_PAGINA 4 -BEGIN - PROMPT 3 6 "Ult.num.pagina stampata libro ditta " - FLAGS "R" -END - -DATE U_DATA -BEGIN - PROMPT 3 7 "Ultima data di stampa " - FLAGS "D" -END - -BUTTON DLG_OK 9 2 -BEGIN - PROMPT -12 -1 "" -END - -BUTTON DLG_CANCEL 9 2 -BEGIN - PROMPT -22 -1 "" -END - -ENDPAGE - +#include "cg4400b.h" + +PAGE "Stampa registri IVA" -1 -1 78 12 + +GROUPBOX DLG_NULL 78 3 +BEGIN + PROMPT 1 0 "" +END + +NUMBER F_CODDITTA 5 +BEGIN + PROMPT 3 1 "Ditta " + FLAGS "D" +END + +STRING F_RAGSOC 50 +BEGIN + PROMPT 17 1 "Ragione " + FLAGS "D" +END + +STRING COD_LIB 3 +BEGIN + PROMPT 3 4 "Codice Libro " + FLAGS "D" +END + +LISTBOX U_MESE 10 +BEGIN + PROMPT 3 5 "Stampa mese " + FLAGS "MD" + ITEM "00|Nessuno" +END + +NUMBER U_PAGINA 4 +BEGIN + PROMPT 3 6 "Ult.num.pagina stampata libro ditta " + FLAGS "R" +END + +DATE U_DATA +BEGIN + PROMPT 3 7 "Ultima data di stampa " + FLAGS "D" +END + +BUTTON DLG_OK 9 2 +BEGIN + PROMPT -12 -1 "" +END + +BUTTON DLG_CANCEL 9 2 +BEGIN + PROMPT -22 -1 "" +END + +ENDPAGE + ENDMASK \ No newline at end of file