campo-sirio/cg/cg1100.cpp

666 lines
16 KiB
C++
Executable File

// cg1100.cpp
// Stampa piano dei conti
#include <mask.h>
#include <printapp.h>
#include <scanner.h>
#include <relation.h>
#include <tabutil.h>
#include <utility.h>
#include <lffiles.h>
#include <sort.h>
#include <pconti.h>
#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, _cur_c3, _cur_c4;
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_sez (const char * );
const char * decodifica_IV_dir (const char * , const char * , const char * , int);
CG1100_application() : _tab (TAB_IVD), _tab_anabil (TAB_ANABIL) {}
};
print_action CG1100_application::postprocess_page(int file,int counter)
{
switch (_tipo_stampa)
{
case completa:
break;
case con_IV_direttiva:
const char * buf;
if ( (buf = _sort->retrieve()) != NULL)
{
(*_rec) = buf;
return REPEAT_PAGE;
}
break;
case senza_IV_direttiva:
break;
case con_ana_bil:
{
const char * buf;
if ( (buf = _sort->retrieve()) != NULL)
{
(*_rec) = buf;
return REPEAT_PAGE;
}
break;
}
case senza_ana_bil:
break;
default:
break;
}
return NEXT_PAGE;
}
void CG1100_application::set_page(int file,int counter)
{
switch (_tipo_stampa)
{
case completa:
set_completa();
break;
case con_IV_direttiva:
break;
case senza_IV_direttiva:
set_senza_IV();
break;
case con_ana_bil:
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()
{
TString c1;
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();
long last = cursor->items();
for ( *cursor = 0; cursor->pos() < last; ++(*cursor) )
{
c1 = cursor->curr(LF_PCON).get(PCN_SEZIVD);
if ( c1.trim().not_empty() )
_sort->sort (cursor->curr(LF_PCON).string());
}
_sort->endsort();
select_cursor (_cur_c2);
break;
}
case senza_IV_direttiva:
select_cursor (_cur_c3);
break;
case con_ana_bil:
{
TRecfield codcbl (*_rec, PCN_CODCBL);
_sort->addsortkey (codcbl);
_sort->init();
select_cursor (_cur_c1);
TCursor * cursor = current_cursor();
long last = cursor->items();
for ( *cursor = 0; cursor->pos() < last; ++(*cursor) )
{
c1 = cursor->curr(LF_PCON).get(PCN_CODCBL);
if ( c1.trim().not_empty() )
_sort->sort (cursor->curr(LF_PCON).string());
}
_sort->endsort();
select_cursor (_cur_c2);
break;
}
case senza_ana_bil:
select_cursor (_cur_c4);
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:
if ((buf = _sort->retrieve()) != NULL)
{
(*_rec) = buf;
return TRUE;
}
else
return FALSE;
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()
{
// campi della classe
TString c1, c2, c3;
int c4;
TString descr_IV_sez, descr_IV_dir;
// campi della classe di segno opposto
TString o1, o2,o3;
int o4;
// Descrizioni
TString d1;
// gruppo, conto e sottoconto
int g,c,s;
c1 = _rec->get(PCN_SEZIVD);
c2 = _rec->get(PCN_LETTIVD);
c3 = _rec->get(PCN_NUMRIVD);
c4 = _rec->get_int(PCN_NUMIVD);
descr_IV_sez = decodifica_IV_sez (c1);
descr_IV_dir = decodifica_IV_dir (c1, c2, c3, c4);
o1 = _rec->get (PCN_SEZIVDOPP);
o2 = _rec->get (PCN_LETTIVDOPP);
o3 = _rec->get (PCN_NUMRIVDOPP);
o4 = _rec->get_int (PCN_NUMIVDOPP);
g = _rec->get_int (PCN_GRUPPO);
c = _rec->get_int (PCN_CONTO);
s = _rec->get_int (PCN_SOTTOCONTO);
d1 = _rec->get (PCN_DESCR);
reset_row (1);
reset_row (2);
set_row (1, "@1g%50s", (const char *) descr_IV_sez);
set_row (2, "@1g%3s", (const char *) c2);
set_row (2, "@5g%8s", (const char *) c3);
set_row (2, "@14g%2d", c4);
set_row (2, "@18g%40s", (const char *) descr_IV_dir);
set_row (2, "@60g%03d.", (const char *) g);
set_row (2, "@64g%03d.", (const char *) c);
set_row (2, "@68g%06d", (const char *) s);
set_row (2, "@78g%2d", (const char *) c4);
}
void CG1100_application::set_senza_IV()
{
int lnum = LF_PCON;
reset_row (1);
set_row (1, "@1g@pn", FLD(lnum,PCN_GRUPPO, "@@@.") );
set_row (1, "@5g@pn", FLD(lnum,PCN_CONTO, "@@@.") );
set_row (1, "@9g@pn", FLD(lnum, PCN_SOTTOCONTO, "@@@@@@") );
set_row (1, "@16g@50s", FLD(lnum,PCN_DESCR) );
set_row (1, "@69g@1s", FLD(lnum, PCN_SEZIVD) );
set_row (1, "@71g@1s", FLD(lnum, PCN_LETTIVD) );
set_row (1, "@73g@8s", FLD(lnum, PCN_NUMRIVD) );
set_row (1, "@82g@pn", FLD(lnum, PCN_NUMIVD, "@@") );
set_row (1, "@87g@pn", FLD(lnum, PCN_INDBIL, "##") );
set_row (1, "@92g@1s", FLD(lnum, PCN_TMCF) );
set_row (1, "@99g@f", FLD(lnum, PCN_STSOTTBIL) );
set_row (1, "@107g@f", FLD(lnum, PCN_COMPENS) );
set_row (1, "@114g@1n", FLD(lnum, PCN_TIPOSPRIC) );
set_row (1, "@120g@1s", FLD(lnum, PCN_SEZSALDI) );
// set_row (1, "@118g@f", FLD(lnum, PCN_STSOTTAB));
}
void CG1100_application::set_con_ana()
{
TString CodTabAnabil, DescrCodTabAnabil(30);
// Descrizioni
TString d1;
const char * d;
// 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);
d1 = _rec->get (PCN_DESCR);
TParagraph_string desc_conto(d1,25);
CodTabAnabil = _rec->get(PCN_CODCBL);
set_row (1, "%-10s", (const char *)CodTabAnabil);
// DescrCodTabAnabil = decodifica_codanabil(CodTabAnabil);
set_row (1, "@15g%-10s", (const char *)DescrCodTabAnabil);
set_row (1, "@61g%03d.", g );
set_row (1, "%03d.", c );
set_row (1, "%06ld", s );
int r=1;
while ((d = desc_conto.get()) != NULL)
{
if (r>1) reset_row(r);
set_row (r, "@78g%25s", d);
r++;
}
}
void CG1100_application::set_senza_ana()
{
int lnum = LF_PCON;
reset_row (1);
set_row (1, "@1g@pn", FLD(lnum,PCN_GRUPPO, "@@@.") );
set_row (1, "@5g@pn", FLD(lnum,PCN_CONTO, "@@@.") );
set_row (1, "@9g@pn", FLD(lnum, PCN_SOTTOCONTO, "@@@@@@") );
set_row (1, "@16g@50s", FLD(lnum,PCN_DESCR) );
set_row (1, "@69g@1s", FLD(lnum, PCN_SEZIVD) );
set_row (1, "@71g@1s", FLD(lnum, PCN_LETTIVD) );
set_row (1, "@73g@8s", FLD(lnum, PCN_NUMRIVD) );
set_row (1, "@82g@pn", FLD(lnum, PCN_NUMIVD, "@@") );
set_row (1, "@87g@pn", FLD(lnum, PCN_INDBIL, "##") );
set_row (1, "@92g@1s", FLD(lnum, PCN_TMCF) );
set_row (1, "@99g@f", FLD(lnum, PCN_STSOTTBIL) );
set_row (1, "@107g@f", FLD(lnum, PCN_COMPENS) );
set_row (1, "@114g@1n", FLD(lnum, PCN_TIPOSPRIC) );
set_row (1, "@120g@1s", FLD(lnum, PCN_SEZSALDI) );
// set_row (1, "@118g@f", FLD(lnum, PCN_STSOTTAB));
}
void CG1100_application::set_completa()
{
int lnum = LF_PCON;
reset_row (1);
set_row (1, "@1g@pn", FLD(lnum,PCN_GRUPPO, "@@@.") );
set_row (1, "@5g@pn", FLD(lnum,PCN_CONTO, "@@@.") );
set_row (1, "@9g@pn", FLD(lnum, PCN_SOTTOCONTO, "@@@@@@") );
set_row (1, "@16g@50s", FLD(lnum,PCN_DESCR) );
set_row (1, "@69g@1s", FLD(lnum, PCN_SEZIVD) );
set_row (1, "@71g@1s", FLD(lnum, PCN_LETTIVD) );
set_row (1, "@73g@8s", FLD(lnum, PCN_NUMRIVD) );
set_row (1, "@82g@pn", FLD(lnum, PCN_NUMIVD, "@@") );
set_row (1, "@87g@pn", FLD(lnum, PCN_INDBIL, "##") );
set_row (1, "@92g@1s", FLD(lnum, PCN_TMCF) );
set_row (1, "@99g@f", FLD(lnum, PCN_STSOTTBIL) );
set_row (1, "@107g@f", FLD(lnum, PCN_COMPENS) );
set_row (1, "@114g@1n", FLD(lnum, PCN_TIPOSPRIC) );
set_row (1, "@120g@1s", FLD(lnum, PCN_SEZSALDI) );
// set_row (1, "@118g@f", FLD(lnum, PCN_STSOTTAB));
}
bool CG1100_application::elabora_riga()
{
static int old_gruppo = 0;
int new_gruppo = 0, new_conto = 0;
long new_sottoc = 0l;
switch (_tipo_stampa)
{
case completa:
case senza_ana_bil:
case senza_IV_direttiva:
{
TRectype curr_rec = current_cursor()->curr(LF_PCON);
new_gruppo = curr_rec.get_int(PCN_GRUPPO);
new_conto = curr_rec.get_int(PCN_CONTO);
new_sottoc = curr_rec.get_long(PCN_SOTTOCONTO);
// se e' un sottoconto stampo sotttab in 127
if ((new_gruppo != 0) && (new_conto != 0) && (new_sottoc != 0))
{
set_row (1, "@127g@f", FLD(LF_PCON, PCN_STSOTTAB));
set_row (1, "@124g ");
}
else
// se e' un conto stampo sotttab in 124
if ((new_gruppo != 0) && (new_conto != 0) && (new_sottoc == 0))
{
set_row (1, "@124g@f", FLD(LF_PCON, PCN_STSOTTAB));
set_row (1, "@127g ");
}
break;
}
case con_ana_bil:
case con_IV_direttiva:
new_gruppo = _rec->get_int(PCN_GRUPPO);
new_conto = _rec->get_int(PCN_CONTO);
new_sottoc = _rec->get_long(PCN_SOTTOCONTO);
// se e' un sottoconto stampo sotttab in 127
if ((new_gruppo != 0) && (new_conto != 0) && (new_sottoc != 0))
{
set_row (1, "@127g%c", (char)_rec->get_bool(PCN_STSOTTAB));
set_row (1, "@124g ");
}
else
// se e' un conto stampo sotttab in 124
if ((new_gruppo != 0) && (new_conto != 0) && (new_sottoc == 0))
{
set_row (1, "@124g%c", (char)_rec->get_bool(PCN_STSOTTAB));
set_row (1, "@127g ");
}
break;
default:
break;
}
// Gestione salto pagina
if (old_gruppo == 0) old_gruppo = new_gruppo;
if (new_gruppo != old_gruppo)
{
old_gruppo = new_gruppo;
if (_salto_pag) return TRUE;
}
return FALSE;
}
bool CG1100_application::preprocess_page(int file,int counter)
{
if (elabora_riga())
printer().formfeed();
// set_auto_ff(TRUE);
// else
// set_auto_ff(FALSE);
if (_tipo_stampa == con_IV_direttiva) set_con_IV();
if (_tipo_stampa == con_ana_bil) set_con_ana();
return TRUE;
}
bool CG1100_application::set_print(int)
{
KEY tasto;
tasto = _msk->run();
if (tasto == K_ENTER)
{
_tipo_stampa = (stampe)atoi(_msk->get (F_SCELTA_STAMPA));
_salto_pag = (bool) (_msk->get (F_SALTO_PAGINA) == "X");
intesta (_tipo_stampa);
scegli_cur();
return TRUE;
}
return FALSE;
}
void CG1100_application::intesta (stampe tipo)
{
int soh; // riga d'inizio dell'intestazione
TString sep(132);
reset_header ();
soh=1;
sep << "Ditta : " << get_firm();
sep.left_just(132);
set_header (soh++, (const char*) sep);
sep = "Studio : ";
sep << "Data : @< Pag. @#";
sep.right_just(132 - (10 + 4));
sep.overwrite ("PIANO DEI CONTI");
set_header (soh++, (const char*)sep);
sep.fill('_');
set_header (soh++, (const char *) sep);
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 @123gSot.con.");
break;
case con_IV_direttiva:
set_header (soh++, "@60gCodici Piano@111gSez. e Classe");
set_header (soh++, "Classe@18gDescrizione@60gdei Conti @78gDescrizione@110g di segno opposto");
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 @123gSot.con.");
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 @123gSot.con.");
break;
default:
break;
}
set_header (soh++,(const char*)sep);
sep = "";
set_header (soh, (const char *) sep);
}
const char * CG1100_application::decodifica_IV_dir (const char * sezivd, const char * lettivd, const char * numrivd, int numivd)
{
TString dep (CODTABLEN);
_tab.curr().zero();
dep << format ("%1s%1s%8s%02d", sezivd, lettivd, numrivd, numivd);
_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");
}
const char * CG1100_application::decodifica_IV_sez (const char * sezivd)
{
TString dep (CODTABLEN);
TString dep2(CODTABLEN);
_tab.zero();
dep << format ("%1s", sezivd);
_tab.put("CODTAB", dep);
_tab.read();
dep2 = _tab.get("CODTAB");
if (dep != dep2)
_tab.zero();
return _tab.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);
_cur_c3 = add_cursor (new TCursor (_rel,"SEZIVD=\"\"", 1));
_cur_c4 = add_cursor (new TCursor (_rel,"CODCBL=\"\"", 1));
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;
}