// cg1100.cpp // Stampa piano dei conti #include #include #include #include #include #include #include #include #include #include #include #include "cg1.h" #include "cg1100.h" const char * TAB_ANABIL = "%IVD"; const char * TAB_IVD = "%IVD"; const int CODTABLEN = 15; enum stampe { completa=1, con_IV_direttiva=2, senza_IV_direttiva=3, con_ana_bil=4, senza_ana_bil=5 }; class CG1100_application : public TPrintapp { TTable _tab; // tabella codici IV direttiva TTable _tab_anabil ; // tabella codici analisi di bilancio TRectype* _rec; TSort* _sort; TRelation* _rel; TMask* _msk; stampe _tipo_stampa; bool _salto_pag; int _pcont_reclen; int _cur_c1, _cur_c2; TString _clivd, _clivdo; public: virtual void user_destroy() ; virtual void user_create() ; virtual void set_page (int,int); virtual bool preprocess_print (int,int); virtual bool preprocess_page (int,int); virtual print_action postprocess_page (int,int); virtual bool set_print(int); void intesta (stampe); bool elabora_riga(); // decide se fare salto pagina o no void scegli_cur(); void set_completa (); void set_con_IV (); void set_senza_IV (); void set_con_ana (); void set_senza_ana (); const char * decodifica_codanabil (const char * ); const char * decodifica_IV_dir (const char * sezivd, const char * lettivd = "", int numrivd = 0, int numivd = 0); void process_link(int id, const char* txt); CG1100_application() : _tab (TAB_IVD), _tab_anabil (TAB_ANABIL), _clivd(8), _clivdo(8) {} }; void CG1100_application::process_link(int id, const char* txt) { TString ss = "1|"; ss << txt; TMessage fs(cmd2name("cg0","-0"), MSG_LN, ss); TMailbox m; m.send(fs); TExternal_app cg0("cg0 -0"); if (cg0.run()) beep(); } print_action CG1100_application::postprocess_page(int file,int counter) { switch (_tipo_stampa) { case completa: case senza_IV_direttiva: case senza_ana_bil: break; case con_IV_direttiva: case con_ana_bil: { const char * buf; if ( (buf = _sort->retrieve()) != NULL) { (*_rec) = buf; return REPEAT_PAGE; } break; } default: break; } return NEXT_PAGE; } void CG1100_application::set_page(int file,int counter) { intesta (_tipo_stampa); switch (_tipo_stampa) { case completa: set_completa(); break; case con_IV_direttiva: set_con_IV(); break; case con_ana_bil: set_con_ana(); break; case senza_IV_direttiva: set_senza_IV(); break; case senza_ana_bil: set_senza_ana(); break; default: break; } } ////////////////////////////////////////////////////////////// // Crea sort se necessario e seleziona il cursore opportuno ////////////////////////////////////////////////////////////// void CG1100_application::scegli_cur() { switch (_tipo_stampa) { case completa: select_cursor (_cur_c1); break; case con_IV_direttiva: { TRecfield sezivd (*_rec, PCN_SEZIVD); TRecfield lettivd (*_rec, PCN_LETTIVD); TRecfield numrivd (*_rec, PCN_NUMRIVD); TRecfield numivd (*_rec, PCN_NUMIVD); _sort->addsortkey (sezivd); _sort->addsortkey (lettivd); _sort->addsortkey (numrivd); _sort->addsortkey (numivd); _sort->init(); select_cursor (_cur_c1); TCursor * cursor = current_cursor(); TRectype & rec = cursor->curr(); long last = cursor->items(); TString c1(4), c2(4), c3(4), c4(4); for ( *cursor = 0; cursor->pos() < last; ++(*cursor) ) { if (rec.get(PCN_CONTO).not_empty() && rec.get(PCN_SOTTOCONTO).empty()) { c1 = rec.get(PCN_SEZIVD); c2 = rec.get(PCN_LETTIVD); c3 = rec.get(PCN_NUMRIVD); c4 = rec.get(PCN_NUMIVD); } else if (rec.get(PCN_SOTTOCONTO).not_empty() && rec.get(PCN_SEZIVD).empty()) { rec.put(PCN_SEZIVD, c1); rec.put(PCN_LETTIVD, c2); rec.put(PCN_NUMRIVD, c3); rec.put(PCN_NUMIVD, c4); } if (rec.get_int(PCN_SEZIVD) != 0) _sort->sort (rec.string()); } _sort->endsort(); select_cursor (_cur_c2); break; } case senza_IV_direttiva: select_cursor (_cur_c1); break; case con_ana_bil: { TRecfield codcbl (*_rec, PCN_CODCBL); _sort->addsortkey (codcbl); _sort->init(); select_cursor (_cur_c1); TCursor * cursor = current_cursor(); TRectype & rec = cursor->curr(); long last = cursor->items(); TString c1(12); for ( *cursor = 0; cursor->pos() < last; ++(*cursor) ) { if (rec.get(PCN_CONTO).not_empty() && rec.get(PCN_SOTTOCONTO).empty()) c1 = rec.get(PCN_CODCBL); else if (rec.get(PCN_SOTTOCONTO).not_empty() && rec.get(PCN_CODCBL).empty()) rec.put(PCN_CODCBL, c1); if (rec.get(PCN_CODCBL).not_empty() ) _sort->sort (rec.string()); } _sort->endsort(); select_cursor (_cur_c2); break; } case senza_ana_bil: select_cursor (_cur_c1); break; default: break; } } bool CG1100_application::preprocess_print (int file,int counter) { const char * buf; reset_print(); set_auto_ff (FALSE); switch (_tipo_stampa) { case con_IV_direttiva: case con_ana_bil: if ((buf = _sort->retrieve()) != NULL) { (*_rec) = buf; return TRUE; } else return FALSE; default: break; } return TRUE; } void CG1100_application::set_con_IV() { static char old_sez[3] = ""; const TString c1(_rec->get(PCN_SEZIVD)); const TString c2(_rec->get(PCN_LETTIVD)); const int c3 = _rec->get_int(PCN_NUMRIVD); const int c4 = _rec->get_int(PCN_NUMIVD); int r = 1; reset_row (1); reset_row (2); reset_row (3); reset_row (4); if (_rec->get(PCN_SEZIVD) != old_sez) { if (*old_sez) r++; strcpy(old_sez, _rec->get(PCN_SEZIVD)); TString dsez(decodifica_IV_dir(c1)); set_row (r++, "%1s@19g%-50s", (const char *) c1, (const char *) dsez); } set_row (r, "@3g%-3s #-8t ", (const char *) c2, &_clivd); if (c4 != 0) set_row (r, "%2d", c4); const TString s(decodifica_IV_dir (c1, c2, c3, c4)); set_row (r, "@19g%-40s", (const char *) s); set_row (r, "@60g$[r]%3d$[n] $[r]%3d$[n] $[r]%6ld$[n]", _rec->get_int (PCN_GRUPPO), _rec->get_int (PCN_CONTO), _rec->get_long (PCN_SOTTOCONTO)); TParagraph_string s1(_rec->get (PCN_DESCR), 30); set_row (r, "@78g%-30s", s1.get()); const TString o1(_rec->get (PCN_SEZIVDOPP)); const TString o2(_rec->get (PCN_LETTIVDOPP)); set_row (r, "@110g%1s %-3s #-8t ", (const char *) o1, (const char *) o2, &_clivdo); const int o4 = _rec->get_int (PCN_NUMIVDOPP); if (o4 != 0) set_row (r, "%2d", o4); const char * s2 = s1.get(); if (s2) set_row (++r, "@78g%-30s", s2); } void CG1100_application::set_senza_IV() { reset_row (1); set_row (1, "$[r]@pn$[n] $[r]@pn$[n] $[r]@pn$[n]", FLD(LF_PCON, PCN_GRUPPO, "###"), FLD(LF_PCON,PCN_CONTO, "###"), FLD(LF_PCON, PCN_SOTTOCONTO, "######")); set_row (1, "@16g@50s", FLD(LF_PCON,PCN_DESCR) ); set_row (1, "@69g@1s", FLD(LF_PCON, PCN_SEZIVD) ); set_row (1, "@71g@1s", FLD(LF_PCON, PCN_LETTIVD) ); set_row (1, "@73g#-8t", &_clivd); set_row (1, "@82g@pn", FLD(LF_PCON, PCN_NUMIVD, "@@") ); set_row (1, "@87g@pn", FLD(LF_PCON, PCN_INDBIL, "##") ); 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, "@120g@1s", FLD(LF_PCON, PCN_SEZSALDI) ); } void CG1100_application::set_con_ana() { // gruppo, conto e sottoconto int g,c; long s; char tmcf; int TipoSpric, IndBil; reset_row (1); g = _rec->get_int (PCN_GRUPPO); c = _rec->get_int (PCN_CONTO); s = _rec->get_long (PCN_SOTTOCONTO); tmcf = _rec->get(PCN_TMCF)[0]; TipoSpric = _rec->get_int(PCN_TIPOSPRIC); IndBil = _rec->get_int(PCN_INDBIL); TString cod(_rec->get(PCN_CODCBL)); set_row (1, "%-10s", (const char *) cod); set_row (1, "@15g%-40s", "") ; /* TBI */ set_row (1, "@60g$[r]%3d$[n] $[r]%3d$[n] $[r]%6ld$[n]", g, c, s); TParagraph_string s1(_rec->get (PCN_DESCR), 30); set_row (1, "@78g%-30s", s1.get()); const char * s2 = s1.get(); if (s2) { reset_row(2); set_row (2, "@78g%-30s", s2); } } void CG1100_application::set_senza_ana() { reset_row (1); set_row (1, "$[r]@pn$[n] $[r]@pn$[n] $[r]@pn$[n]", FLD(LF_PCON, PCN_GRUPPO, "###"), FLD(LF_PCON,PCN_CONTO, "###"), FLD(LF_PCON, PCN_SOTTOCONTO, "######")); set_row (1, "@16g@50s", FLD(LF_PCON,PCN_DESCR) ); set_row (1, "@69g@1s", FLD(LF_PCON, PCN_SEZIVD) ); set_row (1, "@71g@1s", FLD(LF_PCON, PCN_LETTIVD) ); set_row (1, "@73g#-8t", &_clivd); set_row (1, "@82g@pn", FLD(LF_PCON, PCN_NUMIVD, "@@") ); set_row (1, "@87g@pn", FLD(LF_PCON, PCN_INDBIL, "##") ); 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, "@120g@1s", FLD(LF_PCON, PCN_SEZSALDI) ); } void CG1100_application::set_completa() { reset_row (1); set_row (1, "$[r]@pn$[n] $[r]@pn$[n] $[r]@pn$[n]", FLD(LF_PCON, PCN_GRUPPO, "###"), FLD(LF_PCON,PCN_CONTO, "###"), FLD(LF_PCON, PCN_SOTTOCONTO, "######")); set_row (1, "@16g@50s", FLD(LF_PCON,PCN_DESCR) ); set_row (1, "@69g@1s", FLD(LF_PCON, PCN_SEZIVD) ); set_row (1, "@71g@1s", FLD(LF_PCON, PCN_LETTIVD) ); set_row (1, "@73g#-8t", &_clivd ); set_row (1, "@82g@pn", FLD(LF_PCON, PCN_NUMIVD, "@@") ); set_row (1, "@87g@pn", FLD(LF_PCON, PCN_INDBIL, "##") ); 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, "@120g@1s", FLD(LF_PCON, PCN_SEZSALDI) ); } bool CG1100_application::elabora_riga() { static int old_gruppo = 0; TRectype& curr_rec = *_rec; switch (_tipo_stampa) { case completa: case senza_IV_direttiva: curr_rec = current_cursor()->curr(); break; case senza_ana_bil: { curr_rec = current_cursor()->curr(); int conto = curr_rec.get_int(PCN_CONTO); long sottoc = curr_rec.get_long(PCN_SOTTOCONTO); if (conto != 0) { // se e' un sottoconto stampo sotttab in 127 if (sottoc != 0) { set_row (1, "@127g@f", FLD(LF_PCON, PCN_STSOTTAB)); set_row (1, "@117g "); } else // se e' un conto stampo sotttab in 124 { set_row (1, "@117g@f", FLD(LF_PCON, PCN_STSOTTAB)); set_row (1, "@127g "); } } break; } case con_ana_bil: case con_IV_direttiva: curr_rec = *_rec; break; default: break; } // Gestione salto pagina if (_tipo_stampa == con_ana_bil || _tipo_stampa == con_IV_direttiva) return FALSE; int new_gruppo = curr_rec.get_int(PCN_GRUPPO); if (_salto_pag && new_gruppo != old_gruppo) { const bool salta = old_gruppo > 0; old_gruppo = new_gruppo; return salta; } return FALSE; } bool CG1100_application::preprocess_page(int file,int counter) { static int c1 = 0; static TString a1(12); if (_tipo_stampa == senza_IV_direttiva) { TRectype & rec = current_cursor()->curr(); if (rec.get_int(PCN_CONTO) == 0) return FALSE; if (rec.get_long(PCN_SOTTOCONTO) == 0L) c1 = rec.get_int(PCN_SEZIVD); else if (rec.get_int(PCN_SEZIVD) == 0) rec.put(PCN_SEZIVD, c1); if (rec.get_int(PCN_SEZIVD) != 0) return FALSE; } if (_tipo_stampa == senza_ana_bil) { TRectype & rec = current_cursor()->curr(); if (rec.get_int(PCN_CONTO) == 0) return FALSE; if (rec.get_long(PCN_SOTTOCONTO) == 0L) a1 = rec.get(PCN_CODCBL); else if (rec.get(PCN_CODCBL).empty()) rec.put(PCN_CODCBL, a1); if (rec.get(PCN_CODCBL).not_empty()) return FALSE; } if (elabora_riga()) printer().formfeed(); const int c3 = atoi(_rec->get(PCN_NUMRIVD)); const int o3 = atoi(_rec->get(PCN_NUMRIVDOPP)); _clivd = itor(c3); _clivdo = itor(o3); return TRUE; } bool CG1100_application::set_print(int) { KEY tasto; tasto = _msk->run(); if (tasto == K_ENTER) { _tipo_stampa = (stampe)_msk->get_int(F_SCELTA_STAMPA); _salto_pag = _msk->get_bool (F_SALTO_PAGINA); scegli_cur(); enable_link("Collegamento Piano dei conti : ", 'r'); return TRUE; } return FALSE; } void CG1100_application::intesta (stampe tipo) { int soh = 1; // riga d'inizio dell'intestazione const long firm = get_firm(); reset_header (); TLocalisamfile ditte(LF_NDITTE); ditte.zero(); ditte.put(NDT_CODDITTA, firm); ditte.read(); if (ditte.bad()) ditte.zero(); TString s(132); s = ditte.get(NDT_RAGSOC); set_header (soh++, "Ditta : %ld %s@110gData : @< Pag. @#", firm, (const char *) s); set_header (soh++,"@58gPIANO DEI CONTI"); s.fill('_'); set_header (soh++, (const char *) s); switch (tipo) { case completa: set_header (soh++, "Conto @67gSez. Classe@85gTipo@96gDettaglio@112gSpesa @123gDet.bil."); set_header (soh++, "Sottoconto @16gDescrizione@68gIV dir. @85gConto @91gC/F @96gBilancio @106gComp. @112gRicavo @119gSez"); break; case con_IV_direttiva: set_header (soh++, "@60gCodici Piano@111gSez. e Classe"); set_header (soh++, "Classe@19gDescrizione@60gdei Conti @78gDescrizione@110g classe opposta"); break; case senza_IV_direttiva: set_header (soh++, "Conto@85gTipo@96gDettaglio@112gSpesa @123gDet.bil."); set_header (soh++, "Sottoconto @16gDescrizione@85gConto @91gC/F @96gBilancio @106gComp. @112gRicavo @119gSez"); break; case con_ana_bil: set_header (soh++, "Codice @61gCodici Piano@113gDett.alleg.Bilancio"); set_header (soh++, "Tabella@16gDescrizione@60gdei Conti @78gDescrizione @113gSot.con. * Moviment."); break; case senza_ana_bil: set_header (soh++, "Conto @67gSez. Classe@85gTipo@96gDettaglio@112gSpesa @123gDet.bil."); set_header (soh++, "Sottoconto @16gDescrizione@68gIV dir. @85gConto @91gC/F @96gBilancio @106gComp. @112gRicavo @119gSez"); break; default: break; } set_header (soh++,(const char*)s); set_header (soh, ""); } const char * CG1100_application::decodifica_IV_dir (const char * sezivd, const char * lettivd, int numrivd, int numivd) { TString dep (CODTABLEN); _tab.curr().zero(); dep.format("%1s%1s", sezivd, lettivd); if (numivd != 0) { dep << format("%04d", numrivd); dep << format("%02d", numivd); } else if (numrivd != 0) dep << format("%04d", numrivd); _tab.curr().put("CODTAB", (const char*)dep); _tab.read(); if (_tab.bad()) _tab.curr().zero(); return _tab.curr().get ("S0"); } const char * CG1100_application::decodifica_codanabil (const char * codpcab) { // TString dep (CODTABLEN); // non sara' un tabella ma un file _tab_anabil.curr().zero(); _tab_anabil.curr().put("CODTAB", (const char*) codpcab); _tab_anabil.read(); if (_tab_anabil.bad()) _tab_anabil.curr().zero(); return _tab_anabil.curr().get ("S0"); } void CG1100_application::user_create() { _rel = new TRelation (LF_PCON); _msk = new TMask ("cg1100a") ; TCursor *cursor = new TCursor (_rel); _cur_c1 = add_cursor (cursor); _rec = new TRectype (cursor->curr()); _pcont_reclen = _rec->len(); _sort = new TSort(_pcont_reclen); _cur_c2 = add_cursor (NULL); add_file(LF_PCON); _tipo_stampa = completa; _salto_pag = FALSE; } void CG1100_application::user_destroy() { delete _msk; delete _rel; delete _rec; delete _sort; } int cg1100(int argc, char* argv[]) { CG1100_application a; a.run(argc, argv, "Stampa Piano dei Conti"); return 0; }