campo-sirio/cg/cg1100.cpp
alex 4b9323466b Patch level : 2.2 121
Files correlati     :
Ricompilazione Demo : [ ]
Commento            :

Riportata la versione 2.1 320


git-svn-id: svn://10.65.10.50/trunk@13169 c028cbd2-c16b-5b4b-a496-9718f37d4682
2005-06-01 11:20:06 +00:00

1238 lines
33 KiB
C++
Executable File

// cg1100.cpp
// Stampa piano dei conti
#include <execp.h>
#include <mailbox.h>
#include <mask.h>
#include <printapp.h>
#include <sort.h>
#include <recarray.h>
#include <tabutil.h>
#include <utility.h>
#include <progind.h>
#include <nditte.h>
#include <pconti.h>
#include "cg1.h"
#include "cg1100.h"
const char * TAB_IVD = "%IVD";
enum stampe {
completa=1,
con_IV_direttiva,
senza_IV_direttiva,
completa_bil,
con_ana_bil,
senza_ana_bil
};
class CG1100_application : public TPrintapp
{
struct bil_ivd
{
char sez;
char let;
char numr[5];
char num[5];
char gruppo[4];
char conto[4];
char sottoc[8];
char descr[52];
char sez_opp;
char let_opp;
char numr_opp[5];
char num_opp[5];
};
bil_ivd* _bil;
TRectype* _rec;
TSort* _sort;
TMask* _msk;
const char* _buf;
stampe _tipo_stampa;
bool _salto_pag,_resetta_righe_stampa;
int _old_gruppo;
int _i;
int _cur_std, _cur_sorted, _cur_senza_ana;
TString _clivd, _clivdo, _num_dec;
TParagraph_string _d1, _d2, _d3, _d4;
char _sez_da_stamp,_sez_stamp,_let_da_stamp,_let_stamp;
TString _numr_da_stamp,_numr_stamp, _num_stamp, _num_da_stamp;
int _gruppo,_conto, _g_prec,_c_prec;
long _sottoc,_s_prec;
TString _classe_da_stampare,_classe_stampata,_codcbl_da_stamp,_codcbl_stamp;
bool _conto_classificato,_stampa_riga_vuota;
int _sottoc_classificato;
bool _prima_volta;
TDate _data_stampa;
public:
virtual bool user_destroy() ;
virtual bool 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 do_sort();
void set_completa ();
void set_con_IV ();
void set_senza_IV_ana ();
void set_con_ana ();
void init_sort();
const TString & descrizione_numero(char, char, int, const char *);
const TString & descrizione_codcbl(const TString &);
int leggo_sottoc(int,int,long);
void riempi_record(char,char,const TString&, const TString &,int,int,long,const TString&,char,char,const TString&, const TString &);
void set_bil_key(bil_ivd* b, char sezione, char lettera,
const char* numero_romano, const char * numero,
int gruppo = 0, int conto = 0, long sottoconto = 0L);
void set_bil_val(bil_ivd* b, const char* descr,char sez_opp,char let_opp,
const char* numr_opp, const char * num_opp);
virtual bool process_link(int id, const char* txt);
CG1100_application() : _clivd(8), _clivdo(8), _d1("", 30), _d2("", 32), _d3("", 40), _d4("",32) {}
};
const char * num2str(const TString & s)
{
TString & str = get_tmp_string(20);
str = s;
str.trim();
if (str.len() > 2)
{
str = s.left(2);
const int sub = atoi(s.mid(2));
switch (sub)
{
case 0:
case 1:
break;
case 2:
str << "bis";
break;
case 3:
str << "ter";
break;
case 4:
str << "quater";
break;
case 5:
str << "quinquies";
break;
case 6:
str << "sexies";
break;
default:
break;
}
}
return (const char *) str;
}
bool CG1100_application::process_link(int id, const char* txt)
{
TToken_string str(txt);
TRectype pcon(LF_PCON);
pcon.put(PCN_GRUPPO, str.get(0));
pcon.put(PCN_CONTO, str.get(1));
pcon.put(PCN_SOTTOCONTO, str.get(2));
return pcon.edit(LF_PCON, NULL, "cg0 -0");
}
void CG1100_application::init_sort()
{
switch (_tipo_stampa)
{
case con_IV_direttiva:
_sort->reset(sizeof(bil_ivd));
_sort -> addsortkey ((char*)&(_bil->sez) - (char*)&(_bil->sez),1);
_sort -> addsortkey ((char*)&(_bil->let) - (char*)&(_bil->sez),1);
_sort -> addsortkey ((char*)&(_bil->numr) - (char*)&(_bil->sez),4);
_sort -> addsortkey ((char*)&(_bil->num) - (char*)&(_bil->sez),4);
_sort -> addsortkey ((char*)&(_bil->gruppo) - (char*)&(_bil->sez),3);
_sort -> addsortkey ((char*)&(_bil->conto) - (char*)&(_bil->sez),3);
_sort -> addsortkey ((char*)&(_bil->sottoc) - (char*)&(_bil->sez),6);
break;
case con_ana_bil:
{
TRecfield codcbl (*_rec, PCN_CODCBL);
TRecfield gruppo (*_rec, PCN_GRUPPO);
TRecfield conto (*_rec, PCN_CONTO);
TRecfield sottoc (*_rec, PCN_SOTTOCONTO);
_sort->reset(_rec->len());
_sort->addsortkey (codcbl);
_sort->addsortkey (gruppo);
_sort->addsortkey (conto);
_sort->addsortkey (sottoc);
break;
}
default:
break;
}
}
void CG1100_application::set_bil_key(bil_ivd* b, char sezione, char lettera,
const char* numero_romano, const char * numero,
int gruppo, int conto,long sottoconto)
{
b->sez = sezione;
b->let = lettera;
strcpy(b->numr, numero_romano);
sprintf(b->num , "%-4s", numero);
sprintf(b->gruppo , "%3d", gruppo);
sprintf(b->conto , "%3d", conto);
sprintf(b->sottoc , "%6ld", sottoconto);
}
void CG1100_application::set_bil_val(bil_ivd* b, const char* descr,
char sez_opp,char let_opp,
const char* numr_opp, const char * num_opp)
{
strcpy(b->descr, descr);
b->sez_opp = sez_opp;
b->let_opp = let_opp;
strcpy(b->numr_opp, numr_opp);
strcpy(b->num_opp, num_opp);
}
void CG1100_application::riempi_record(char sez,char let,const TString& numr,
const TString & numero,int g,int c,long s,
const TString& descr,char sez_opp,
char let_opp,const TString& numr_opp,
const TString& num_opp)
{
set_bil_key(_bil, sez, let, numr, numero, g, c, s);
set_bil_val(_bil, descr, sez_opp, let_opp, numr_opp, num_opp);
_sort->sort ((const char*) _bil);
}
print_action CG1100_application::postprocess_page(int file,int counter)
{
switch (_tipo_stampa)
{
case completa:
case senza_IV_direttiva:
case completa_bil:
case senza_ana_bil:
break;
case con_IV_direttiva:
{
struct bil_ivd* bil = (struct bil_ivd*) _buf;
_sez_stamp = _sez_da_stamp;
_let_stamp = _let_da_stamp;
_numr_stamp = _numr_da_stamp;
_num_stamp = _num_da_stamp;
_classe_stampata.format("%c%c%s%-4s",_sez_stamp,_let_stamp,(const char*)_numr_stamp, (const char *) _num_stamp);
if ( (_buf = _sort->retrieve()) != NULL)
{
bil = (struct bil_ivd*) _buf;
_sez_da_stamp = bil->sez;
_let_da_stamp = bil->let;
_numr_da_stamp = bil->numr;
_numr_da_stamp.ltrim();
_num_da_stamp = bil->num;
_gruppo = atoi(bil->gruppo);
_conto = atoi(bil->conto);
_sottoc = atol(bil->sottoc);
_classe_da_stampare.format("%c%c%s%-4s",_sez_da_stamp,_let_da_stamp,(const char*)_numr_da_stamp, (const char *) _num_da_stamp);
return REPEAT_PAGE;
}
}
break;
case con_ana_bil:
{
TRectype rec (LF_PCON);
_codcbl_stamp = _codcbl_da_stamp;
if ( (_buf = _sort->retrieve()) != NULL)
{
rec = _buf;
_codcbl_da_stamp = rec.get(PCN_CODCBL);
_gruppo = rec.get_int(PCN_GRUPPO);
_conto = rec.get_int(PCN_CONTO);
_sottoc = rec.get_long(PCN_SOTTOCONTO);
return REPEAT_PAGE;
}
break;
}
default:
break;
}
return NEXT_PAGE;
}
void CG1100_application::set_page(int file,int counter)
{
switch (_tipo_stampa)
{
case con_IV_direttiva:
{
reset_print();
_i = 1;
if (_sez_da_stamp != _sez_stamp)
set_con_IV ();
else
if (_buf != NULL)
set_con_IV();
}
break;
case con_ana_bil:
{
reset_print();
_i = 1;
if (_codcbl_da_stamp != _codcbl_stamp)
set_con_ana ();
else
if (_buf != NULL)
set_con_ana();
}
break;
case senza_IV_direttiva:
set_senza_IV_ana();
break;
case senza_ana_bil:
set_senza_IV_ana();
break;
default:
break;
}
}
//////////////////////////////////////////////////////////////
// Crea sort se necessario e seleziona il cursore opportuno
//////////////////////////////////////////////////////////////
void CG1100_application::do_sort()
{
_sort->init();
select_cursor (_cur_std);
TCursor & c = *current_cursor();
TRectype & rec = c.curr();
const long last = c.items();
TProgind prg (last, TR("Elaborazione Piano dei Conti... Prego attendere"), false, true, 30);
if (_tipo_stampa == con_IV_direttiva)
{
char sez_conto,let_conto;
TString16 numr_conto;
TString16 num_conto;
bool classe_conto = false;
for ( c = 0L; c.pos() < last; ++c)
{
prg.addstatus(1);
int g = rec.get_int(PCN_GRUPPO);
int c = rec.get_int(PCN_CONTO);
long s = rec.get_int(PCN_SOTTOCONTO);
if (g != 0 && c == 0 && s == 0) continue;
char sez = rec.get_char(PCN_SEZIVD);
char let = rec.get_char(PCN_LETTIVD);
const TString16 numr = rec.get (PCN_NUMRIVD);
const TString16 num = rec.get (PCN_NUMIVD);
TString descr = rec.get (PCN_DESCR);
char sez_opp = rec.get_char(PCN_SEZIVDOPP);
char let_opp = rec.get_char(PCN_LETTIVDOPP);
const TString16 numr_opp = rec.get (PCN_NUMRIVDOPP);
const TString16 num_opp = rec.get (PCN_NUMIVDOPP);
if ((g != 0) && (c != 0) && (s == 0))
{
classe_conto = sez > '0';
if (classe_conto)
{
sez_conto = sez;
if (let != '\0')
let_conto = let;
else
if ((sez == '1')||(sez == '2'))
let_conto = 'Z';
else
let_conto = let;
numr_conto = numr;
num_conto = num;
riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,descr,sez_opp,let_opp,numr_opp,num_opp);
}
}
if ((g != 0) && (c != 0) && (s != 0))
{
if (classe_conto)
riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,descr,sez_opp,let_opp,numr_opp,num_opp);
else
{
if (sez > '0')
{
if (let == '\0')
if ((sez == '1')||(sez == '2'))
let = 'Z';
riempi_record(sez,let,numr,num,g,c,s,descr,sez_opp,let_opp,numr_opp,num_opp);
}
}
}
}
}
if (_tipo_stampa == con_ana_bil)
{
bool livello_conto = false;
TString c1(12);
int conto_p = -1;
for ( c = 0L; c.pos() < last; ++c)
{
prg.addstatus(1);
int conto = rec.get_int (PCN_CONTO);
long sottoc = rec.get_long(PCN_SOTTOCONTO);
if (livello_conto && (conto != conto_p) )
{
c1.cut(0);
livello_conto = false;
}
conto_p = conto;
if (conto == 0) // Si tratta di un gruppo
c1 = rec.get(PCN_CODCBL);
else
if (sottoc == 0) // Si tratta di un conto
{
if (rec.get(PCN_CODCBL).empty())
rec.put(PCN_CODCBL, c1);
else
{
c1 = rec.get(PCN_CODCBL);
livello_conto = true;
}
}
else // Si tratta di un sottoconto
if (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_sorted);
}
bool CG1100_application::preprocess_print (int file,int counter)
{
switch (_tipo_stampa)
{
case completa:
case completa_bil:
case senza_IV_direttiva:
break;
case con_IV_direttiva:
{
struct bil_ivd* bil = (struct bil_ivd*) _buf;
if ((_buf = _sort->retrieve()) != NULL)
{
bil = (struct bil_ivd*) _buf;
_sez_da_stamp = bil->sez;
_let_da_stamp = bil->let;
_numr_da_stamp = bil->numr;
_numr_da_stamp.ltrim();
_num_da_stamp = bil->num;
_gruppo = atoi(bil->gruppo);
_conto = atoi(bil->conto);
_sottoc = atol(bil->sottoc);
_classe_da_stampare.format("%c%c%s%-4s",_sez_da_stamp,_let_da_stamp,(const char*)_numr_da_stamp, (const char *)_num_da_stamp);
return true;
}
else
return false;
}
break;
case con_ana_bil:
{
TRectype rec (LF_PCON);
if ((_buf = _sort->retrieve()) != NULL)
{
rec = _buf;
_codcbl_da_stamp = rec.get(PCN_CODCBL);
_gruppo = rec.get_int(PCN_GRUPPO);
_conto = rec.get_int(PCN_CONTO);
_sottoc = rec.get_long(PCN_SOTTOCONTO);
return true;
}
else
return false;
}
break;
case senza_ana_bil:
default:
break;
}
return true;
}
void CG1100_application::set_con_IV()
{
struct bil_ivd* bil = (struct bil_ivd*) _buf;
TString descrizione,descr;
char sez_opp,let_opp;
int numr_opp;
bool stampa_classe = true;
int numr = atoi(_numr_da_stamp);
TString numrom = itor(numr);
TString num_opp(bil->num_opp);
sez_opp = bil->sez_opp;
let_opp = bil->let_opp;
numr_opp = atoi(bil->numr_opp);
TString numrom_opp = itor(numr_opp);
descrizione = descrizione_numero(_sez_da_stamp,_let_da_stamp,numr, _num_da_stamp);
descr = bil->descr;
//Se la classe prelevata dal record corrente del sort e' diversa dalla classe
//prelevata dal record precedente, allora stampo la nuova classe con i relativi
//sottoconti. In caso contrario continuo a stampare solo i sottoconti.
if (_classe_da_stampare != _classe_stampata)
{
if (_sez_da_stamp != _sez_stamp)
{
if ((_sez_da_stamp == '1')&&(_let_da_stamp == 'Z'))
{
char app = ' ';
set_row (_i++,"@0g%c", app);
set_row (_i++,FR("@0gCONTI D' ORDINE ATTIVI"));
set_row (_i++,"@0g%c", app);
stampa_classe = false;
}
else
if ((_sez_da_stamp == '1')&&(_let_da_stamp != 'Z'))
{
char app = ' ';
set_row (_i++,"@0g%c", app);
set_row (_i++,FR("@0gATTIVO"));
set_row (_i++,"@0g%c", app);
}
if ((_sez_da_stamp == '2')&&(_let_da_stamp == 'Z'))
{
char app = ' ';
set_row(_i++,"@0g%c", app);
set_row (_i++,FR("@0gCONTI D' ORDINE PASSIVI"));
set_row(_i++,"@0g%c", app);
stampa_classe = false;
}
else
if ((_sez_da_stamp == '2')&&(_let_da_stamp != 'Z'))
{
char app = ' ';
set_row(_i++,"@0g%c", app);
set_row (_i++,FR("@0gPASSIVO"));
set_row(_i++,"@0g%c", app);
}
if (_sez_da_stamp == '5')
{
char app = ' ';
set_row(_i++,"@0g%c", app);
set_row (_i++,FR("@0gCONTI D' ORDINE"));
set_row(_i++,"@0g%c", app);
stampa_classe = false;
}
if (_sez_da_stamp == '9')
{
char app = ' ';
set_row(_i++,"@0g%c", app);
set_row (_i++,FR("@0gCONTO ECONOMICO"));
set_row(_i++,"@0g%c", app);
}
}
else
if ((_let_da_stamp!=_let_stamp)&&(_sez_da_stamp==_sez_stamp))
{
if ((_sez_da_stamp == '1')&&(_let_da_stamp == 'Z'))
{
char app = ' ';
set_row (_i++,"@0g%c", app);
set_row (_i++,FR("@0gCONTI D' ORDINE ATTIVI"));
set_row (_i++,"@0g%c", app);
stampa_classe = false;
}
if ((_sez_da_stamp == '2')&&(_let_da_stamp == 'Z'))
{
char app = ' ';
set_row(_i++,"@0g%c", app);
set_row (_i++,FR("@0gCONTI D' ORDINE PASSIVI"));
set_row(_i++,"@0g%c", app);
stampa_classe = false;
}
}
if (stampa_classe)
{
if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp== '9'))
{
char app = ' ';
set_row (_i++,"@0g%c", app);
if (_let_da_stamp != ' ')
set_row(_i,"@0g%c", _let_da_stamp);
if (_numr_da_stamp != "")
set_row(_i,"@2g%8s", (const char*) numrom);
set_row(_i,"@11g%s", num2str(_num_da_stamp));
_d2 = descrizione;
set_row(_i,"@23g#a", &_d2);
}
}
}
set_row (_i,"@58g$[b]%3d$[n]", _gruppo);
set_row (_i,"@62g$[b]%3d$[n]", _conto);
if (_sottoc != 0)
set_row (_i,"@66g$[b]%6ld$[n]", _sottoc);
_d4 = descr;
set_row (_i,"@73g#a", &_d4);
if (sez_opp != '0')
{
set_row (_i,"@109g%c", sez_opp);
if (let_opp != '\0')
set_row (_i,"@111g%c", let_opp);
if (numr_opp != 0)
set_row (_i,"@113g%8s", (const char*) numrom_opp);
if (num_opp.not_empty())
set_row (_i++,"@122g%s", num2str(num_opp));
}
else
_i++;
}
void CG1100_application::set_senza_IV_ana()
{
int i;
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);
reset_print ();
i = 1;
if (_prima_volta)
{
_g_prec = gruppo;
_c_prec = conto;
_prima_volta = false;
}
if (sottoc == 0L) // Se si tratta di un conto
{
if (gruppo != _g_prec)
_stampa_riga_vuota = true;
}
else
{
if (gruppo != _g_prec || conto != _c_prec)
_stampa_riga_vuota = true;
}
if (_stampa_riga_vuota)
{
i++;
_stampa_riga_vuota = false;
}
set_row (i, "$[b]@pn$[n] $[b]@pn$[n] $[b]@pn$[n]",
FLD(LF_PCON, PCN_GRUPPO, "###"), FLD(LF_PCON,PCN_CONTO, "###"),
FLD(LF_PCON, PCN_SOTTOCONTO, "######"));
set_row (i, "@16g@50s", FLD(LF_PCON,PCN_DESCR) );
if (conto != 0 && sottoc == 0l)
{
set_row (i, "@76g@pn", FLD(LF_PCON, PCN_INDBIL, "#") );
set_row (i, "@82g@1s", FLD(LF_PCON, PCN_TMCF) );
set_row (i, "@89g@f", FLD(LF_PCON, PCN_STSOTTBIL) );
set_row (i, "@98g@f", FLD(LF_PCON, PCN_COMPENS) );
set_row (i, "@121g@f", FLD(LF_PCON, PCN_STSOTTAB) );
}
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%c", tipospric);
set_row (i, "@115g@1s", FLD(LF_PCON, PCN_SEZSALDI) );
set_row (i, "@129g@f", FLD(LF_PCON, PCN_STSOTTAB) );
}
}
void CG1100_application::set_con_ana()
{
TRectype rec (LF_PCON);
TString16 val;
rec = _buf;
TString codcbl = rec.get(PCN_CODCBL);
int conto = rec.get_int (PCN_CONTO);
long sottoc = rec.get_long(PCN_SOTTOCONTO);
bool stsobi = rec.get_bool(PCN_STSOTTAB);
if (stsobi)
val = TR("Si");
else
val = TR("No");
if (_codcbl_da_stamp != _codcbl_stamp)
{
set_row (_i,"@0g%s", (const char*) _codcbl_da_stamp);
_d3 = descrizione_codcbl(codcbl);
_d3.trim();
set_row (_i,"@13g#a", &_d3);
}
set_row (_i,"@62g$[b]%3d$[n]", _gruppo);
if (_conto != 0)
set_row (_i,"@66g$[b]%3d$[n]", _conto);
if (_sottoc != 0)
set_row (_i,"@70g$[b]%6ld$[n]", _sottoc);
if (_gruppo > 99 || _conto > 99)
set_row(_i,"@76g*");
set_row (_i,"@78g%.40s", (const char*) rec.get(PCN_DESCR));
if (conto != 0 && sottoc == 0l)
set_row (_i, "@121g%s", (const char*) val);
else
if (sottoc != 0l)
set_row (_i, "@129g%s", (const char*) val);
_i++;
}
void CG1100_application::set_completa()
{
TRectype& rec = current_cursor()->curr();
char sezione;
int i;
int conto = rec.get_int (PCN_CONTO);
long sottoc = rec.get_long(PCN_SOTTOCONTO);
sezione = rec.get_char(PCN_SEZIVD);
TString desc = rec.get(PCN_DESCR);
if (_prima_volta)
{
_s_prec = 0;
_prima_volta = false;
}
if (sottoc != 0l && _s_prec != 0l)
i = 1;
else
{
i = 1;
char app = ' ';
set_row (i++,"@0g%c", app);
}
reset_print ();
set_row (i, "$[b]@pn$[n] $[b]@pn$[n] $[b]@pn$[n]",
FLD(LF_PCON, PCN_GRUPPO, "###"), FLD(LF_PCON,PCN_CONTO, "###"),
FLD(LF_PCON, PCN_SOTTOCONTO, "######"));
set_row (i, "@16g%.40s", (const char*) desc); // ???
if (_tipo_stampa == completa)
{
if (sezione != '0' && sezione != '9')
set_row (i, "@58g@1s", FLD(LF_PCON, PCN_SEZIVD) );
set_row (i, "@60g@1s", FLD(LF_PCON, PCN_LETTIVD) );
set_row (i, "@62g#-8t", &_clivd );
set_row (i, "@71g#t", &_num_dec);
}
else
if (_tipo_stampa == completa_bil)
set_row (i, "@60g@12s", FLD(LF_PCON, PCN_CODCBL) );
if (conto != 0 && sottoc == 0l)
{
set_row (i, "@82g@pn", FLD(LF_PCON, PCN_INDBIL, "#") );
set_row (i, "@84g@1s", FLD(LF_PCON, PCN_TMCF) );
set_row (i, "@89g@f", FLD(LF_PCON, PCN_STSOTTBIL) );
set_row (i, "@98g@f", FLD(LF_PCON, PCN_COMPENS) );
set_row (i, "@121g@f", FLD(LF_PCON, PCN_STSOTTAB) );
}
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%c", tipospric);
set_row (i, "@114g@1s", FLD(LF_PCON, PCN_SEZSALDI) );
set_row (i, "@129g@f", FLD(LF_PCON, PCN_STSOTTAB) );
}
_s_prec = sottoc;
}
bool CG1100_application::elabora_riga()
{
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)
{
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 ");
}
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)
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;
}
int CG1100_application::leggo_sottoc(int gruppo,int conto,long sottoc)
{
TLocalisamfile pconti (LF_PCON);
char sez;
int gr,co;
int esito = 0;
bool esiste_conto_classificato = false;
bool esiste_conto_non_classificato = false;
pconti.zero();
pconti.put(PCN_GRUPPO, gruppo);
pconti.put(PCN_CONTO, conto);
pconti.put(PCN_SOTTOCONTO, sottoc);
for (pconti.read(); !pconti.eof() ;pconti.next())
{
gr = pconti.get_int (PCN_GRUPPO);
co = pconti.get_int (PCN_CONTO);
if (gruppo != gr || conto != co) break;
sez = pconti.get_char(PCN_SEZIVD);
if (sez != '0')
esiste_conto_classificato = true;
if (sez == '0')
esiste_conto_non_classificato = true;
}
if (!esiste_conto_classificato && esiste_conto_non_classificato)
esito = 0;
if (esiste_conto_classificato && esiste_conto_non_classificato)
esito = 1;
if (esiste_conto_classificato && !esiste_conto_non_classificato)
esito = 2;
return esito;
}
bool CG1100_application::preprocess_page(int file,int counter)
{
static TString16 a1;
char sez;
TString16 codcbl;
if (_tipo_stampa == completa || _tipo_stampa == completa_bil)
set_completa();
if (_tipo_stampa == senza_IV_direttiva)
{
if (file == LF_PCON)
{
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);
force_setpage();
if (conto == 0) return false; //Scarto i gruppi
if (sottoc == 0L) // Se si tratta di un conto
{
sez = rec.get_char(PCN_SEZIVD);
if (sez == '0')
{
_sottoc_classificato = byte(leggo_sottoc(gruppo,conto,sottoc));
if (_sottoc_classificato == 0)
_conto_classificato = true;
else
if (_sottoc_classificato == 1)
{
_conto_classificato = false;
return false;
}
else
if (_sottoc_classificato == 2)
{
_conto_classificato = true;
return false;
}
}
else
{
_conto_classificato = true;
return false;
}
}
else // Se si tratta di un sottoconto
{
if (!_conto_classificato)
{
char sezione = rec.get_char(PCN_SEZIVD);
if (sezione != '0')
return false;
}
else
return false;
}
_g_prec = gruppo;
_c_prec = conto;
}
}
if (_tipo_stampa == senza_ana_bil)
{
if (file == LF_PCON)
{
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);
force_setpage();
_g_prec = gruppo;
_c_prec = conto;
}
return true;
}
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);
_num_dec = num2str(_rec->get(PCN_NUMIVD));
return true;
}
bool CG1100_application::set_print(int)
{
KEY tasto;
_old_gruppo = 0;
tasto = _msk->run();
if (tasto == K_ENTER)
{
_tipo_stampa = (stampe)_msk->get_int(F_SCELTA_STAMPA);
_salto_pag = _msk->get_bool(F_SALTO_PAGINA);
_data_stampa = _msk->get(F_DATA_STAMPA);
enable_link(TR("Collegamento Piano dei conti: "), 'b');
set_multiple_link(true);
_sez_stamp = ' ';
_let_stamp = ' ';
_numr_stamp = "";
_num_stamp = "";
_classe_stampata = "";
_resetta_righe_stampa = true;
reset_footer();
if (_tipo_stampa == con_ana_bil)
set_footer(2,TR("* Conti collegati ma non trasferibili"));
else
set_footer(2,"");
if (_tipo_stampa == senza_IV_direttiva)
{
_conto_classificato = true;
_sottoc_classificato = 0;
_stampa_riga_vuota = false;
_prima_volta = true;
}
switch (_tipo_stampa)
{
case completa:
case completa_bil:
case senza_IV_direttiva:
select_cursor(_cur_std);
break;
case senza_ana_bil:
select_cursor(_cur_senza_ana);
break;
case con_IV_direttiva:
case con_ana_bil:
init_sort();
do_sort();
break;
default:
break;
}
intesta (_tipo_stampa);
printer().footerlen(5);
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);
TString data = _data_stampa.string();
set_header (soh++, FR("Ditta : %ld %s@105gData %s Pag. @#"), firm, (const char*)s, (const char*)data);
set_header (soh,FR("@0gPIANO DEI CONTI"));
switch (tipo)
{
case completa:
set_header (soh++, FR("@20gStampa completa per IV direttiva"));
s.fill('-');
set_header (soh++, (const char *) s);
set_header (soh++, FR("Conto @59gSez. Classe@82gT@84gC@86gNo Dettaglio@104gT@107gSpesa@118gDet.alleg.bil."));
set_header (soh++, FR("Sottoconto @16gDescrizione@61gIV dir.@82gC@84gF@86gBilancio@97gComp.@104gA@107gRicavo@114gSez@118gSot.con * Mov."));
break;
case con_IV_direttiva:
set_header (soh++, FR("@20gStampa conti riclassificati per IV direttiva"));
s.fill('-');
set_header (soh++, (const char *) s);
set_header (soh++, FR("@58gCodici Piano@109gSez. e Classe"));
set_header (soh++, FR("Classe@23gDescrizione@58gdei Conti @73gDescrizione@109gdi segno opposto"));
break;
case senza_IV_direttiva:
set_header (soh++, FR("@20gStampa conti non collegati per IV direttiva"));
s.fill('-');
set_header (soh++, (const char *) s);
set_header (soh++, FR("Conto @75gTipo@86gNo Dettaglio@104gT@107gSpesa@118gDet.alleg.bil."));
set_header (soh++, FR("Sottoconto @16gDescrizione@75gConto@81gC/F@86gBilancio@97gComp.@104gA@107gRicavo@114gSez@118gSot.con * Mov."));
break;
case completa_bil:
set_header (soh++, FR("@20gStampa completa per analisi di bilancio"));
s.fill('-');
set_header (soh++, (const char *) s);
set_header (soh++, FR("Conto@60gCod.tabella@75gTipo@86gNo Dettaglio@104gT@107gSpesa@118gDet.alleg.bil."));
set_header (soh++, FR("Sottoconto @16gDescrizione@60gAnalis.bil.@75gConto@81gC/F@86gBilancio@97gComp.@104gA@107gRicavo@114gSez@118gSot.con * Mov."));
break;
case con_ana_bil:
set_header (soh++, FR("@20gStampa conti riclassificati per analisi di bilancio"));
s.fill('-');
set_header (soh++, (const char *) s);
set_header (soh++, FR("Codice @62gCodici Piano@118gDet.alleg.bil."));
set_header (soh++, FR("Tabella@13gDescrizione@62gdei Conti @78gDescrizione@118gSot.con * Mov."));
break;
case senza_ana_bil:
set_header (soh++, FR("@20gStampa conti non collegati per analisi di bilancio"));
s.fill('-');
set_header (soh++, (const char *) s);
set_header (soh++, FR("Conto@74gTipo@86gNo Dettaglio@107gSpesa@114gT@116gDett.alleg.bil."));
set_header (soh++, FR("Sottoconto@16gDescrizione@74gConto@81gC/F@86gBilancio@96gCompensaz.@107gRicavo@114gA@116gSot.con * Movim."));
break;
default:
break;
}
set_header (soh++,(const char*)s);
set_header (soh, "");
}
const TString & CG1100_application::descrizione_numero(char sezione, char lettera, int numr, const char * numero)
{
TString key;
if (numr == 0)
key.format("%c%c %-4s",sezione, lettera, numero);
else
key.format("%1c%1c%04d%-4s",sezione, lettera, numr, numero);
key.trim();
const TRectype & ivd = cache().get(TAB_IVD, key);
return ivd.get("S0");
}
const TString & CG1100_application::descrizione_codcbl(const TString& codcbl)
{
const TRectype & abpcon = cache().get(LF_ABPCON, codcbl);
return abpcon.get("DESCRIZ");
}
bool CG1100_application::user_create()
{
open_files(LF_NDITTE, LF_PCON, LF_TABCOM, LF_TAB, 0);
_msk = new TMask ("cg1100a") ;
TCursor * cursor = new TCursor (new TRelation (LF_PCON));
_cur_std = add_cursor (cursor);
_rec = new TRectype (cursor->curr());
_cur_sorted = add_cursor (NULL);
add_file(LF_PCON);
TRelation * rel_ana = new TRelation(LF_PCON);
rel_ana->add(LF_PCON, "GRUPPO==GRUPPO|CONTO==CONTO|SOTTOCONTO==0", 1, 0, 201);
rel_ana->add(LF_PCON, "GRUPPO==GRUPPO|CONTO==0|SOTTOCONTO==0", 1, 0, 202);
_cur_senza_ana = add_cursor(new TCursor(rel_ana));
select_cursor(_cur_senza_ana);
TCursor & c = *current_cursor();
c.setfilter("((SOTTOCONTO!=0)&&(CODCBL==\"\")&&(201@->CODCBL==\"\")&&(202@->CODCBL==\"\"))||((SOTTOCONTO==0)&&(201@->CODCBL==\"\")&&(202@->CODCBL==\"\"))||((CONTO==0)&&(202@->CODCBL==\"\"))");
select_cursor(_cur_std);
_tipo_stampa = completa;
_salto_pag = false;
_bil = new bil_ivd;
_sort = new TSort();
return true;
}
bool CG1100_application::user_destroy()
{
delete _msk;
delete _rec;
delete _bil;
delete _sort;
return true;
}
int cg1100(int argc, char* argv[])
{
CG1100_application a;
a.run(argc, argv, TR("Stampa Piano dei Conti"));
return 0;
}