diff --git a/cg/cg1600.cpp b/cg/cg1600.cpp index 8f04cd4c2..11a0dbcbf 100755 --- a/cg/cg1600.cpp +++ b/cg/cg1600.cpp @@ -1,4975 +1,4975 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cglib.h" -#include "cg1.h" -#include "cg1600.h" - -extern char __tmp [MAXSTR]; -static TFixed_string tmp(__tmp, MAXSTR); - -bool our_handler (TMask_field & f,KEY k); - -class Anno_es : public TObject -{ - TDate _inizio, _fine; - TToken_string *_str; -public: - long anno(); - TDate inizio(); - TDate fine() ; - Anno_es(long anno, TDate& inizio, TDate& fine); - ~Anno_es() { delete _str; } -}; - -TDate Anno_es::inizio() -{ - _inizio = _str->get(1); - return _inizio; -} - -TDate Anno_es::fine() -{ - _fine = _str->get(2); - return _fine; -} - -long Anno_es::anno() -{ - return _str->get_int(0); -} - -Anno_es::Anno_es(long anno, TDate& inizio, TDate& fine) -{ - _str = new TToken_string(35); - _inizio = inizio; - _fine = fine; - _str->add(anno); _str->add(_inizio.string()); _str->add(_fine.string()); -} - -class Anni_es : public TAssoc_array -{ - TTable * _tabesc; -public: - void add(long anno, TDate& inizio, TDate& fine); - void aggiungi_anno(long anno, TDate& inizio, TDate& fine); - Anno_es * trova(long anno, TDate& inizio, TDate& fine); - Anni_es(); - ~Anni_es() { delete _tabesc; } -}; - -Anni_es::Anni_es() -{ - _tabesc = new TTable (TAB_ESC); -} - -void Anni_es::add(long annoe, TDate& in, TDate& fin) -{ - TString key = format("%04ld", annoe); - Anno_es anno(annoe, in, fin); - TAssoc_array::add(key, anno); -} - -Anno_es * Anni_es::trova(long annoe, TDate& in, TDate& fin) -{ - TString key = format("%04ld", annoe); - Anno_es *anno = (Anno_es*) objptr ((const char*) key); - if (anno == NULL) { - in = ""; fin = ""; - } - else { - in = anno->inizio(); - fin = anno->fine(); - } - return anno; -} - -void Anni_es::aggiungi_anno(long annoese, TDate& inizio, TDate& fine) -{ - TString dep; - TString key = format("%04ld", annoese); - Anno_es * anno; - - if (!is_key((const char *) key)) - { - _tabesc->curr().zero(); - dep = format ("%04d",annoese); - _tabesc->curr().put("CODTAB", (const char*) dep); - _tabesc->read(); - if (_tabesc->bad()) - _tabesc->curr().zero(); - inizio = _tabesc->curr().get_date("D0"); - fine = _tabesc->curr().get_date("D1"); - anno = new Anno_es(annoese, inizio, fine); - TAssoc_array::add(key, anno); - } - else - anno = trova (annoese, inizio, fine); -} - -class _riga_sez_opp : public TObject -{ - TToken_string * _str; -public: - int gruppo() { return atoi(_str->get(0)); } - int conto() { return atoi(_str->get(1)); } - int sottoc() { return atoi(_str->get(2)); } - const char * sezione () { return _str->get(3); } - const char * lettera () { return _str->get(4); } - const char * num_rom () { return _str->get(5); } - int numero () { return atoi(_str->get(6)); } - real saldo_conto (); - real saldo_conto_raf(); - void incrementa_saldo(real& nuovo_saldo,real& nuovo_saldo_raf); - _riga_sez_opp(int g, int c, long s, - const char * sezione, const char * lettera, - const char * num_rom, int num, real& saldo, real& saldo_raf); - ~_riga_sez_opp(); -}; - -real _riga_sez_opp::saldo_conto () -{ - real r(_str->get(7)); - return r; -} - -real _riga_sez_opp::saldo_conto_raf () -{ - real r(_str->get(8)); - return r; -} - -void _riga_sez_opp::incrementa_saldo(real& sld,real& sld_raf) -{ - real sld_prec = saldo_conto(); - real sld_prec_raf = saldo_conto_raf(); - sld_prec += sld; - sld_prec_raf += sld_raf; - _str->add(sld_prec.string(), 7); - _str->add(sld_prec_raf.string(), 8); -} - -_riga_sez_opp::_riga_sez_opp(int g, int c, long s, - const char * sezione, const char * lettera, - const char * num_rom, int num, real& saldo, real& saldo_raf) -{ - _str = new TToken_string(30); - _str->add(format("%d",g)); - _str->add(format("%d",c)); - _str->add(format("%ld",s)); - _str->add(sezione); - _str->add(lettera); - _str->add(num_rom); - _str->add(format("%d",num)); - _str->add(saldo.string()); - _str->add(saldo_raf.string()); -} - -_riga_sez_opp::~_riga_sez_opp() -{ - delete _str; -} - -class Righe_sez_opp : public TAssoc_array -{ -public: - _riga_sez_opp* riga() { return (_riga_sez_opp*) get(); } - int gruppo() { return riga()->gruppo(); } - int conto() { return riga()->conto(); } - int sottoc() { return riga()->sottoc(); } - const char * sezione () { return riga()->sezione(); } - const char * lettera () { return riga()->lettera(); } - const char * num_rom () { return riga()->num_rom(); } - int numero () { return riga()->numero(); } - real saldo_conto () { return riga()->saldo_conto(); } - real saldo_conto_raf () { return riga()->saldo_conto_raf(); } - - void add (int g, int c, long s, - const char * sezione, const char * lettera, - const char * num_rom, int num, real saldo, real saldo_raf); -}; - -void Righe_sez_opp::add(int g, int c, long s, - const char * sezione, const char * lettera, - const char * num_rom, int num, real saldo, real saldo_raf) -{ - _riga_sez_opp * riga; - TString key = format("%s%s%s%d",sezione,lettera,num_rom,num); - - if (!is_key((const char *) key)) - { - riga = new _riga_sez_opp (g, c, s, sezione, lettera, num_rom, num, saldo, saldo_raf); - TAssoc_array::add(key,riga); - } - else - { - riga = (_riga_sez_opp*) objptr ((const char*) key); - riga->incrementa_saldo(saldo,saldo_raf); - // add(key,riga,TRUE); - } -} - -int date2esc(const TDate& d, int* prevesc = NULL); - -class CG1600_application : public TPrintapp -{ - friend bool data_limite (TMask_field & f,KEY k); - friend bool tipo_stampa (TMask_field & f,KEY k); - friend bool data_bil_raff (TMask_field & f,KEY k); - friend bool tipo_bilancio (TMask_field & f,KEY k); - friend bool data_inizio (TMask_field & f,KEY k); - friend bool data_fine (TMask_field & f,KEY k); - friend bool anno_esercizio (TMask_field & f,KEY k); - - struct bil_ivd - { - char sez; - char let; - char numr[5]; - char num[4]; - char gruppo[4]; - char conto[4]; - char sottoc[8]; - real saldo; - real saldorafr; - real sld_prg_dare; - real sld_prg_avere; - real mov_dare; - real mov_avere; - char tipocf; - bool conto_dettagliato; - }; - - bil_ivd* _bil; - TMask* _msk; - TTable* _tabesc; - TTable* _tabivd; - TLocalisamfile* _nditte; - TLocalisamfile* _comuni; - TLocalisamfile* _unloc; - TLocalisamfile* _anag; - TLocalisamfile* _pconti; - TLocalisamfile* _clifo; - TLocalisamfile* _saldi; - const char* _buff; - TSort* _sort; - Anni_es* _anni_es; - Righe_sez_opp _sezopps; - TSaldi_list* _listasld; - TProgind* _prog; - TParagraph_string* _descr; - Saldo* _sld; - - TDate _data_fine_ese,_data_fine_ese_prec,_data_fine_raf,_data_fine_raf_prec; - TDate _datastampa,_datalimite,_databilrafr,_datai,_datairaf; - TDate _dataini,_datafine,_data_ini_ese,_data_ini_raf; - int _annoese,_annoeserafr,_anno_esercizio,_anno_esercizio_raf; - bool _competenza,_intera_struttura,_stampamov,_stampacod,_stampa_modulo; - bool _sbilancio_patr_gia_stampato,_attivo_o_passivo; - bool _stampa_mov_prov,_diffprod_fatto,_risimp_fatto; - TString _classe_stampata, _classe_da_stampare,_numr_tot,_num_tot,_numr; - char _sez_da_stamp,_let_da_stamp,_sez_stamp,_let_stamp,_sez_tot,_let_tot,_let,_sez_saldo,_sez,_tot_sez_saldo; - TString _numr_da_stamp,_num_da_stamp,_numr_stamp,_num_stamp,_descr_sez; - int _tipo_bilancio, _tipo_stampa; - int _cont_let,_cont_numr,_cont_num,_cont_gcs,_num; - real _sale,_salerafr,_totale_ordine,_totale_economico; - real _totale_ordine_raf,_totale_economico_raf; - real _totale_numero,_totale_numr,_totale_lettera,_totale_sezione; - real _totale_patrimoniale,_totale_attivita,_totale_passivita; - real _totale_num_raf,_totale_numr_raf,_totale_let_raf,_totale_sez_raf; - real _totale_patrim_raf,_totale_attiv_raf,_totale_passiv_raf; - real _totale_ordine_attivo,_totale_ordine_passivo,_totale_ordine_attivo_raf; - real _totale_ordine_passivo_raf; - real _mov_periodo_dare,_mov_periodo_avere,_prg_prec_dare,_prg_prec_avere,_saldo_ini_dare,_saldo_ini_avere; - real _sld_prg_dare,_sld_prg_avere,_mov_dare,_mov_avere; - real _tot_num_saldo,_tot_numr_saldo,_tot_let_saldo,_tot_gen_saldo; - real _tot_num_prg_d,_tot_numr_prg_d,_tot_let_prg_d,_tot_gen_prg_d; - real _tot_num_prg_a,_tot_numr_prg_a,_tot_let_prg_a,_tot_gen_prg_a; - real _tot_num_mov_d,_tot_numr_mov_d,_tot_let_mov_d,_tot_gen_mov_d; - real _tot_num_mov_a,_tot_numr_mov_a,_tot_let_mov_a,_tot_gen_mov_a; - real _tot_num_saldo_d,_tot_numr_saldo_d,_tot_let_saldo_d,_tot_gen_saldo_d; - real _tot_num_saldo_a,_tot_numr_saldo_a,_tot_let_saldo_a,_tot_gen_saldo_a; - real _totale_parziale,_totale_parziale_raf; - real _tot_parz_sld,_tot_parz_sld_d,_tot_parz_sld_a,_tot_parz_prg_d; - real _tot_parz_prg_a,_tot_parz_mov_d,_tot_parz_mov_a; - int _i; - bool _reset_righe_stampa,_totale_attivita_gia_stampato,_totale_passivita_gia_stampato,_statopatr_no_stamp; - bool _sbilancio_ordine; - TString _causale_ap, _causale_chi; - -public: - - TDate _inizioEs, _fineEs; - - bool menu (MENU_TAG m) { return TPrintapp::menu(m) ; } - virtual bool user_create() ; - virtual bool user_destroy(); - bool set_print(int); - - virtual bool preprocess_page (int,int); - virtual print_action postprocess_page (int,int); - virtual void postclose_print (); - - virtual void preprocess_header(); - virtual void set_page(int,int); - - bool preprocess_stampa_scalare(int); - bool preprocess_stampa_verifica(int); - void crea_intestazione(); - void intesta_scalare(); - void intesta_verifica(); - void intesta_verifica_fissa(); - void init_sort(); - void crea_sort_tabella(); - void crea_sort_piano_conti_scalare(); - void crea_sort_piano_conti_verifica(); - void setta_righe_descr(TParagraph_string*,const TString&,const TString&); - void setta_righe_descr_verifica(TParagraph_string*,const TString&,const TString&); - void scrivi_record(const TString&,const TString&,const TString&,int,int,int,long,const real&,const real&,const real&,const real&,const real&,const real&,char,bool conto_dettagliato = TRUE); - void riempi_record(const TString&,const TString&,const TString&,int,int,int,long,const real&,const real&,const real&,const real&,const real&,const real&,char,bool conto_dettagliato = TRUE); - const char* descrizione_sezione(char); - const char* descrizione_lettera(char, char); - const char* descrizione_numeroromano(char, char, int); - const char* descrizione_numero(char, char, int, int); - const char* descrizione_sottoconto(int, int, long); - const char* descr_sottoc_clifo(char,long); - void setta_righe(const char*); - void setta_righe_verifica(); - void stampa_totali(); - void stampa_totali_con_raffronto(); - void stampa_totali_verifica(); - bool calcola_saldo(real&, real&,int,int,long,int); - bool calcola(int,int,long,const TDate&,const TDate&); - bool sottoc_clifo_scalare (int,int,int,int,real&,real&); - void sottoc_clifo_verifica(int,int,int,char,TString&,TString&,TString&,int,int,bool); - const char* causale_apertura() { return _causale_ap;} - const char* causale_chiusura() { return _causale_chi;} - void stampa_saldo_132(const real&); - void stampa_saldo_198(real&, real&); - void set_bil_key(bil_ivd* b, char sezione, char lettera, - const char* numero_romano, int numero, - bool conti_ordine = TRUE, int conto = 0, - int gruppo = 0, long sottoconto = 0L, char tipocf = ' '); - void set_bil_val(bil_ivd* b, const real& saldo = ZERO, - const real& saldorafr = ZERO, - const real& sld_prg_dare = ZERO, - const real& sld_prg_avere = ZERO, - const real& mov_dare = ZERO, - const real& mov_avere = ZERO,bool conto_dettagliato = TRUE); - CG1600_application() {} -}; - -HIDDEN inline CG1600_application & a() {return (CG1600_application&) main_app(); } - -void CG1600_application::postclose_print() -{ - delete _sort; -} - -void CG1600_application::set_bil_key(bil_ivd* b, char sezione, char lettera, - const char* numero_romano, int numero, - bool conti_ordine, int gruppo, int conto, - long sottoconto, char tipocf) - -{ - b->sez = sezione; - - //Se esiste solamente la sezione,significa che e' un conto d'ordine - //Forzo la lettera della classe a Z, per ottenere, grazie - //all'ordinamento del sort, i record dei conti d'ordine per ultimi - - b->let = (conti_ordine && lettera == '\0' && sezione < '3') ? 'Z' : lettera; - strcpy(b->numr, numero_romano); - sprintf(b->num , "%2d", numero); - if (gruppo < 0) - { - strcpy(b->gruppo, "ZZZ"); - strcpy(b->conto, "ZZZ"); - strcpy(b->sottoc, "ZZZZZZ"); - b->tipocf = ' '; - } - else - if (gruppo == 0) - { - strcpy(b->gruppo, "AAA"); - strcpy(b->conto, "AAA"); - strcpy(b->sottoc, "AAAAAA"); - b->tipocf = ' '; - } - else - { - sprintf(b->gruppo , "%3d", gruppo); - sprintf(b->conto , "%3d", conto); - sprintf(b->sottoc , "%6ld", sottoconto); - b->tipocf = tipocf; - } -} - -void CG1600_application::set_bil_val(bil_ivd* b, const real& saldo, - const real& saldorafr, - const real& sld_prg_dare, - const real& sld_prg_avere, - const real& mov_dare, - const real& mov_avere,bool conto_dettagliato) -{ - b->saldo = saldo; - b->saldorafr = saldorafr; - b->sld_prg_dare = sld_prg_dare; - b->sld_prg_avere = sld_prg_avere; - b->mov_dare = mov_dare; - b->mov_avere = mov_avere; - b->conto_dettagliato = conto_dettagliato; -} - -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 - a()._inizioEs = ia; - a()._fineEs = fa; - const anno = esc.get_int("CODTAB"); - if (d >= ia && d <= fa) - return anno; - if (prevesc) *prevesc = anno; - } - return 0; -} - -bool data_limite (TMask_field& f, KEY key) -{ - if (key == K_ENTER) - { - TMask& m = f.mask(); - int tipobil,tipostampa; - TDate datalim; - TDate in="", fin=""; - // CG1600_application * a = (CG1600_application*) MainApp(); - - tipobil = m.get_int(F_TIPOBIL); - tipostampa = m.get_int(F_TIPOSTAMPA); - int annoese = m.get_int(F_ANNOESE); - - if ((tipobil == 1) && (tipostampa == 1)) - { - datalim = m.get(F_DATALIM); - - if (annoese != 0) - { - a()._anni_es->aggiungi_anno(annoese, in, fin); - a()._data_fine_ese = fin; - a()._data_ini_ese = in; - - a()._anno_esercizio = annoese; - - if (datalim == botime) - a()._datalimite = a()._data_fine_ese; - else - if ((datalim < in)||(datalim > fin)) - { - f.error_box("La data limite non appartiene all' esercizio indicato"); - return FALSE; - } - else - a()._datalimite = datalim; - } - else - if (annoese == 0) - { - if (datalim == botime) - { - f.error_box("La data limite deve essere indicata obbligatoriamente"); - return FALSE; - } - - int anno = date2esc(datalim); - - if (anno == 0) - { - f.error_box("La data limite indicata non appartiene ad alcun esercizio attivo della ditta"); - return FALSE; - } - - a()._data_ini_ese = a()._inizioEs; - a()._data_fine_ese = a()._fineEs; - - a()._datalimite = datalim; - a()._anno_esercizio = anno; - } - } - } - TString data1 = a()._datalimite.string(); - TString data2 = a()._data_ini_ese.string(); - TString data3 = a()._data_fine_ese.string(); - return TRUE; -} - -bool data_bil_raff (TMask_field& f, KEY key) -{ - TMask& m = f.mask(); - int tipobil,tipostampa; - TDate datalim, dataraf; - TDate in = "", fin = "", in_raf = "", fin_raf = ""; - - if (key == K_ENTER) - { - tipobil = atoi(m.get(F_TIPOBIL)); - tipostampa = atoi(m.get(F_TIPOSTAMPA)); - - int annoese = m.get_int(F_ANNOESE); - int annoraf = m.get_int(F_ANNORAFFR); - - if (tipobil == 1) //&& (tipostampa == 1)) - { - dataraf = m.get(F_DATABILRAF); - - datalim = m.get(F_DATALIM); - - if (annoraf == 0) - { - int anno; - - if (datalim != botime) - { - date2esc(datalim); - in = a()._inizioEs; - } - else - a()._anni_es->aggiungi_anno(annoese, in, fin); - - TString instr = in.string(); - if (dataraf != botime) - { - anno = date2esc(dataraf); - in_raf = a()._inizioEs; - fin_raf = a()._fineEs; - a()._anno_esercizio_raf = anno; - } - else - anno == 1; -/**** - if (dataraf == botime) - { - f.error_box("La data bilancio da raffrontare deve essere indicata obbligatoriamente"); - return FALSE; - } - else - { -********/ - if (dataraf > in) - { - f.error_box("La data bilancio da raffrontare non puo' essere maggiore o uguale alla data inizio esercizio in corso"); - return FALSE; - } - - if (anno == 0) - { - f.error_box("La data bilancio da raffrontare indicata non appartiene ad alcun esercizio attivo della ditta"); - return FALSE; - } - - a()._databilrafr = dataraf; - a()._data_ini_raf = in_raf; - a()._data_fine_raf = fin_raf; - //} - } - else - if (annoraf != 0) - { - a()._anni_es->aggiungi_anno(annoraf, in_raf, fin_raf); - a()._data_fine_raf = fin_raf; - a()._data_ini_raf = in_raf; - - if (dataraf == botime) - a()._databilrafr = fin_raf; - - else - if (dataraf < in_raf || dataraf > fin_raf) - { - f.error_box("La data bilancio da raffrontare deve appartenere all' esercizio da raffrontare"); - return FALSE; - } - else - a()._databilrafr = dataraf; - a()._anno_esercizio_raf = annoraf; - } - } - } // IF (key == K_ENTER) - TString data1 = in.string(); - TString data2 = in_raf.string(); - TString data3 = fin_raf.string(); - TString data4 = a()._databilrafr.string(); - TString data5 = a()._data_ini_raf.string(); - TString data6 = a()._data_fine_raf.string(); - return TRUE; -} - -bool anno_ese_raff (TMask_field& f, KEY key) -{ - int annoese, annoraf, anno; - TDate datalim; - - if (key == K_ENTER) - { - annoese = f.mask().get_int(F_ANNOESE); - annoraf = f.mask().get_int(F_ANNORAFFR); - - if (annoraf != 0) - { - if (annoese != 0) - { - if (annoraf >= annoese) - { - f.error_box("L' anno esercizio da raffrontare deve essere inferiore all' anno esercizio in corso"); - return FALSE; - } - } - else - if (annoese == 0) - { - datalim = f.mask().get(F_DATALIM); - - if (datalim != botime) - { - anno = date2esc(datalim); - - if (annoraf >= anno) - { - f.error_box("L' anno esercizio da raffrontare deve essere inferiore all' anno di esercizio di appartenenza della data limite"); - return FALSE; - } - } - } - } - } - return TRUE; -} - -bool tipo_bilancio (TMask_field& f, KEY key) -{ - int tipo_bil, anno; - - if (key == K_SPACE) - { - tipo_bil = f.mask().get_int(F_TIPOBIL); - anno = f.mask().get_int(F_ANNOESE); - if (tipo_bil == 1) - { - f.mask().hide (98); - f.mask().hide (99); - f.mask().hide(96); - f.mask().hide(97); - } - else - if (tipo_bil == 2) - { - if (anno != 0) - { - f.mask().show (96); - f.mask().show (97); - f.mask().hide (98); - f.mask().hide (99); - } - else - if (anno == 0) - { - f.mask().show(98); - f.mask().show(99); - f.mask().hide(96); - f.mask().hide(97); - } - } - } - return TRUE; -} - -bool anno_esercizio (TMask_field& f, KEY key) -{ - int tipo_bil, anno; - - if (key == K_TAB || f.focusdirty()) - { - tipo_bil = f.mask().get_int(F_TIPOBIL); - anno = f.mask().get_int(F_ANNOESE); - if (tipo_bil == 1) - { - f.mask().hide (98); - f.mask().hide (99); - f.mask().hide(96); - f.mask().hide(97); - } - else - if (tipo_bil == 2) - { - if (anno != 0) - { - f.mask().show (96); - f.mask().show (97); - f.mask().hide (98); - f.mask().hide (99); - } - else - if (anno == 0) - { - f.mask().show(98); - f.mask().show(99); - f.mask().hide(96); - f.mask().hide(97); - } - } - } - return TRUE; -} - -bool tipo_stampa(TMask_field& f,KEY k) -{ - int tipo_stampa; - - if (k == K_ENTER) - { - tipo_stampa = f.mask().get_int(F_TIPOSTAMPA); - - int anno = f.mask().get_int(F_ANNOESE); - - if (tipo_stampa == 2) - if (anno == 0) - { - error_box("Nella stampa all' ultima immissione l' anno esercizio e' obbligatorio"); - return FALSE; - } - - } - return TRUE; -} - -bool data_inizio(TMask_field& f, KEY k) -{ - int anno; - TDate data; - TDate in="", fin=""; - - anno = f.mask().get_int(F_ANNOESE); - data = f.mask().get (F_DATAINI); - a()._anno_esercizio = anno; - - if (k == K_ENTER) - { - if (anno != 0) - { - a()._anni_es->aggiungi_anno(anno, in, fin); - a()._data_ini_ese = in; - a()._data_fine_ese = fin; - a()._anno_esercizio = anno; - - if (data == botime) - a()._dataini = in; - else - if (data < in || data > fin) - { - f.error_box("La data non appartiene all' esercizio indicato"); - return FALSE; - } - else - a()._dataini = data; - } - else - if (anno == 0) - { - if (data == botime) - { - f.error_box("La data deve essere obbligatoriamente indicata"); - return FALSE; - } - - int anno = date2esc(data); - - if (anno == 0) - { - f.error_box("La data limite indicata non appartiene ad alcun esercizio attivo della ditta"); - return FALSE; - } - - a()._anno_esercizio = anno; - a()._dataini = data; - } - } - TString datastr = a()._dataini.string(); - TString data1 = a()._data_ini_ese.string(); - TString data2 = a()._data_fine_ese.string(); - return TRUE; -} - -bool data_fine(TMask_field& f, KEY k) -{ - int annoes; - TDate data, data_ini; - TDate in="", fin=""; - - annoes = f.mask().get_int(F_ANNOESE); - data = f.mask().get (F_DATAFINE); - data_ini = f.mask().get (F_DATAINI); - a()._anno_esercizio = annoes; - - if (k == K_ENTER) - { - if (annoes != 0) - { - a()._anni_es->aggiungi_anno(annoes, in, fin); - a()._data_ini_ese = in; - a()._data_fine_ese = fin; - - if (data == botime) - a()._datafine = fin; - else - if (data < in || data > fin) - { - f.error_box("La data non appartiene all' esercizio indicato"); - return FALSE; - } - else - a()._datafine = data; - } - else - if (annoes == 0) - { - if (data == botime) - { - f.error_box("La data deve essere obbligatoriamente indicata"); - return FALSE; - } - - date2esc(data_ini); - TString data3 = a()._inizioEs.string(); - TString data4 = a()._fineEs.string(); - - if (data < a()._inizioEs || data > a()._fineEs) - { - f.error_box("La data non appartiene all' esercizio indicato"); - return FALSE; - } - else - a()._datafine = data; - } - - if (data < data_ini) - { - f.error_box("La data finale non puo' essere inferiore alla data di partenza"); - return FALSE; - } - - - } - TString datastr = a()._datafine.string(); - TString data1 = a()._data_ini_ese.string(); - TString data2 = a()._data_fine_ese.string(); - return TRUE; -} - -void CG1600_application::scrivi_record(const TString& sez, - const TString& let, const TString& numerorom,int numero, - int g,int c,long s,const real& saldo,const real& saldorafr, - const real& sld_dare,const real& sld_avere, - const real& mov_dare,const real& mov_avere,char tipocf,bool conto_dettagliato) -{ - - //Se esiste solamente la sezione,significa che e' un conto d'ordine - //Forzo la lettera della classe a Z, per ottenere, grazie - //all'ordinamento del sort, i record dei conti d'ordine per ultimi - - set_bil_key(_bil, sez[0], let[0], numerorom, numero, TRUE, g, c, s, tipocf); - set_bil_val(_bil, saldo, saldorafr, sld_dare, sld_avere, mov_dare, mov_avere,conto_dettagliato); - _sort->sort ((const char*) _bil); -} - -void CG1600_application::riempi_record(const TString& sez, - const TString& let, const TString& numerorom,int numero, - int g,int c,long s,const real& saldo,const real& saldorafr, - const real& sld_dare,const real& sld_avere, - const real& mov_dare,const real& mov_avere,char tipocf,bool conto_dettagliato) -{ - set_bil_key(_bil, sez[0], let[0], numerorom, numero, FALSE, g, c, s, tipocf); - set_bil_val(_bil, saldo, saldorafr, sld_dare, sld_avere, mov_dare, mov_avere,conto_dettagliato); - _sort->sort ((const char*) _bil); -} - -void CG1600_application::crea_sort_tabella() -{ - TRecnotype recno_prec=0l, recno_curr=0l; - TString codtab_prec; - TTable tabivd(TAB_IVD); - TRecfield codtab_curr(tabivd.curr(),"CODTAB"); - TRecfield sezione (tabivd.curr(),"CODTAB",0,0); - TRecfield lettera (tabivd.curr(),"CODTAB",1,1); - TRecfield numerorom (tabivd.curr(),"CODTAB",2,5); - TRecfield numero (tabivd.curr(),"CODTAB",6,7); - int preclen; - bool FINITO=FALSE; - - tabivd.first(); - codtab_prec = tabivd.get("CODTAB"); - - // Compilo tanti record quante sono le classi IV direttiva trovate sulla - // tabella %IVD, usando dei gruppi, conti e sottoconti fittizi. Successivamente - // nel caso di stampa completa verranno stampati anche questi record; nel caso - // di stampa non completa non verranno stampati. - - do - { - recno_prec = tabivd.recno(); - tabivd.next(); - if (tabivd.eof()) - { - tabivd.zero(); - FINITO=TRUE; - } - recno_curr = tabivd.recno(); - preclen = codtab_prec.len(); - if (!strncmp(codtab_curr,codtab_prec,preclen)) - codtab_prec = (const char *)codtab_curr; - else - { - tabivd.readat(recno_prec); - const char sez = *((const char*) sezione); - const char let = *((const char*) lettera); - TString16 nrom((const char*)numerorom); - const int nu = (int) numero; - - set_bil_key(_bil, sez, let,(const char*)nrom, nu, FALSE,-1); - set_bil_val(_bil); - _sort->sort ((const char*) _bil); - tabivd.readat(recno_curr); - codtab_prec = (const char *)codtab_curr; - } - } while (!FINITO); -} - -// Passo al sort tutti i record presenti su piano dei conti, aventi la classe -// IV direttiva CEE. - -void CG1600_application::crea_sort_piano_conti_scalare() -{ - TLocalisamfile pconti(LF_PCON); - TString sez,let,numerorom; - TString sez_conto,let_conto,numr_conto,sez_opp,let_opp,numr_opp; - int num_conto, indbil; - char sezione,lettera,tmcf; - int numero,g,c,num_opp; - long s; - bool sez_opposta = FALSE; - bool no_sez_opposta = FALSE; - bool classe_conto = FALSE; - bool conto_dettagliato = FALSE; - bool stsottbil; - int gruppo_prec,conto_prec; - real saldo,saldo_raf,saldo_conto,saldo_conto_raf; - real saldo_conto_opp,saldo_conto_raf_opp; - TString saldostr,saldo_rafstr; - c = 0; - num_conto = 0; - tmcf = ' '; - indbil = 0; - - saldo_conto = ZERO; - saldo_conto_raf = ZERO; - saldo_conto_opp = ZERO; - saldo_conto_raf_opp = ZERO; - - gruppo_prec = -1; - conto_prec = -1; - - for (pconti.first(); !pconti.eof(); pconti.next()) - { - _prog->addstatus(1); - g = pconti.get_int (PCN_GRUPPO); - c = pconti.get_int (PCN_CONTO); - s = pconti.get_long(PCN_SOTTOCONTO); - sez = pconti.get(PCN_SEZIVD); - let = pconti.get(PCN_LETTIVD); - sezione = sez[0]; - lettera = let[0]; - numerorom = pconti.get(PCN_NUMRIVD); - numero = pconti.get_int (PCN_NUMIVD); - - saldo = ZERO; - saldo_raf = ZERO; - - //Anche se il conto non e' da dettagliare ma contiene la classe e' da - //mandare ugualmente in stampa con il totale di tutti i suoi sottoconti letti - - if (classe_conto) - { - if (c != conto_prec && conto_prec != -1) - { - if (no_sez_opposta) - { - TString saldo_contostr,saldo_conto_rafstr; - - saldo_contostr = saldo_conto.string(); - saldo_conto_rafstr = saldo_conto_raf.string(); - riempi_record(sez_conto,let_conto,numr_conto,num_conto,gruppo_prec,conto_prec,0,saldo_conto,saldo_conto_raf,ZERO,ZERO,ZERO,ZERO,tmcf,conto_dettagliato); - saldo_conto = ZERO; - saldo_conto_raf = ZERO; - classe_conto = FALSE; - no_sez_opposta = FALSE; - } - if (sez_opposta) - { - int items = _sezopps.items(); - _sezopps.restart(); - for (int i=0; isezione(); - TString let_opp = lriga->lettera(); - TString numr_opp = lriga->num_rom(); - if (numr_opp == " ") //Sembrerebbe che il metodo sezione() quando il numero romano non esiste, ritorni - numr_opp.ltrim(); //una TString contenente uno spazio e non un NULL, sconvolgendo l' ordinamento. - //Per evitare tutto cio' aggiungo il metodo ltrim(), che toglie gli spazi. - //Pero', essendo il numero romano un campo Zerofill, uso ltrim() solo se non c'e'. - int num_opp = lriga->numero(); - real saldo_conto = lriga->saldo_conto(); - real saldo_conto_raf = lriga->saldo_conto_raf(); - riempi_record(sez_opp,let_opp,numr_opp,num_opp,gruppo_prec,conto_prec,0,saldo_conto,saldo_conto_raf,ZERO,ZERO,ZERO,ZERO,tmcf,conto_dettagliato); - } - sez_opposta = FALSE; - - _sezopps.destroy(); - } - } - } - - //Senza questo controllo conto_prec quando viene letto un gruppo verrebbe - //settato a 0 (il conto non c'e'), quindi nella eventuale lettura del conto - //nel ciclo successivo, qualsiasi conto sarebbe diverso da quello precedente. - - if (g != gruppo_prec) - conto_prec = -1; - else - conto_prec = c; - - gruppo_prec = g; - - // Se si tratta di un conto e contiene la classe, allora lo passo al sort. - // Gli eventuali sottoconti avranno la stessa classe. - - if ((g != 0) && (c != 0) && (s == 0)) - { - stsottbil = pconti.get_bool(PCN_STSOTTBIL); - tmcf = pconti.get (PCN_TMCF)[0]; - indbil = pconti.get_int (PCN_INDBIL); - - //Se sono nello stesso gruppo, ma ho un conto diverso da quello precedentemente - //analizzato, e se questi contiene la classe IV dir. CEE, - //allore devo controllare se va dettagliato (STSOTTBIL) - - if (sez != "0") - { - if (!stsottbil || tmcf == 'C' || tmcf == 'F') - conto_dettagliato = FALSE; - else - conto_dettagliato = TRUE; - - sez_conto = sez; - - if (let != "") - let_conto = let; - else - if ((sez == "1")||(sez == "2")) - let_conto = "Z"; - else - let_conto = let; - - numr_conto = numerorom; - num_conto = numero; - classe_conto = TRUE; - - if (tmcf == 'C' || tmcf == 'F') - { - if (sottoc_clifo_scalare(g, c,_anno_esercizio,indbil,saldo_conto,saldo_conto_raf)) - { - if (sez == "2") //Se la sezione e 2 cambio segno comunque - { - //if (saldo_conto < ZERO) - saldo_conto = -saldo_conto; - //if (saldo_conto_raf < ZERO) - saldo_conto_raf = -saldo_conto_raf; - } - no_sez_opposta = TRUE; - } - } - } - else - { - classe_conto = FALSE; // Metto conto dettagliato = TRUE perche' potrebbero esserci dei sottoconti - conto_dettagliato = TRUE; // di questo conto che hanno la classe e quindi vanno stampati. - } - } - - // Se si tratta di un sottoconto e contiene la classe, allora lo passo al sort. - - if ((g != 0) && (c != 0) && (s != 0)) - { - bool rec_es_corr = FALSE; - bool rec_es_prec = FALSE; - - if (!calcola_saldo(saldo,saldo_raf,g,c,s,indbil)) - continue; - - // classe_conto indica se il conto precedentemente letto conteneva - // la classe. In caso affermativo anche questo sottoconto appena - // letto avra' la stessa classe del conto. - - saldostr = saldo.string(); - saldo_rafstr = saldo_raf.string(); - bool stessa_sezione = (saldo * saldo_raf) > ZERO; - - if (classe_conto) - { - sez_opp = pconti.get(PCN_SEZIVDOPP); - if (sez_opp != "0") - { - let_opp = pconti.get(PCN_LETTIVDOPP); - numr_opp = pconti.get(PCN_NUMRIVDOPP); - num_opp = pconti.get_int(PCN_NUMIVDOPP); - - if (sez_conto == "1" && saldo < ZERO)// || (sez_conto == "2" && saldo > ZERO) ) - { - saldo = -saldo; - rec_es_corr = TRUE; - } - if (sez_conto == "1" && saldo_raf < ZERO) //|| (sez_conto == "2" && saldo_raf > ZERO) ) - { - saldo_raf = -saldo_raf; - rec_es_prec = TRUE; - } - if (sez_conto == "2" && saldo > ZERO) - { - rec_es_corr = TRUE; - } - if (sez_conto == "2" && saldo_raf > ZERO) - { - rec_es_prec = TRUE; - } - - if (rec_es_corr && rec_es_prec) - { - if (conto_dettagliato) - { - _sezopps.add(g,c,s,sez_opp,let_opp,numr_opp,num_opp,saldo,saldo_raf); - riempi_record(sez_opp,let_opp,numr_opp,num_opp,g,c,s,saldo,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); - sez_opposta = TRUE; - } - else - sez_opposta = FALSE; - } - else - if (rec_es_corr) - { - if (conto_dettagliato) - { - _sezopps.add(g,c,s,sez_opp,let_opp,numr_opp,num_opp,saldo,ZERO); - riempi_record(sez_opp,let_opp,numr_opp,num_opp,g,c,s,saldo,ZERO,ZERO,ZERO,ZERO,ZERO,tmcf); - if (saldo_raf != ZERO) - { - if (sez_conto == "2") - if (saldo_raf < ZERO) - saldo_raf = -saldo_raf; - - riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,ZERO,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); - //saldo_conto += saldo; - saldo_conto_raf += saldo_raf; - no_sez_opposta = TRUE; - } - sez_opposta = TRUE; - } - else - sez_opposta = FALSE; - } - else - if (rec_es_prec) - { - if (conto_dettagliato) - { - _sezopps.add(g,c,s,sez_opp,let_opp,numr_opp,num_opp,ZERO,saldo_raf); - riempi_record(sez_opp,let_opp,numr_opp,num_opp,g,c,s,ZERO,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); - if (saldo != ZERO) - { - if (sez_conto == "2") - if (saldo < ZERO) - saldo = -saldo; - - riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,saldo,ZERO,ZERO,ZERO,ZERO,ZERO,tmcf); - saldo_conto += saldo; - //saldo_conto_raf += saldo_raf; - no_sez_opposta = TRUE; - } - sez_opposta = TRUE; - } - else - sez_opposta = FALSE; - } - else - { - if (sez_conto == "2") - { - if (saldo < ZERO) - saldo = -saldo; - if (saldo_raf < ZERO) - saldo_raf = -saldo_raf; - } - if (conto_dettagliato) - riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,saldo,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); - - saldo_conto += saldo; - saldo_conto_raf += saldo_raf; - no_sez_opposta = TRUE; - } - } - else - { - if (sez_conto == "2") - { - saldo = -saldo; - saldo_raf = -saldo_raf; - } - if (conto_dettagliato) - riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,saldo,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); - - saldo_conto += saldo; - saldo_conto_raf += saldo_raf; - no_sez_opposta = TRUE; - } - } - else - { - sez_opp = pconti.get(PCN_SEZIVDOPP); - if (sez_opp != "0") - { - let_opp = pconti.get(PCN_LETTIVDOPP); - numr_opp = pconti.get(PCN_NUMRIVDOPP); - num_opp = pconti.get_int(PCN_NUMIVDOPP); - - if (sez == "1" && saldo < ZERO) //|| (sez == "2" && saldo > ZERO) ) - { - saldo = -saldo; - rec_es_corr = TRUE; - } - if (sez == "1" && saldo_raf < ZERO) //|| (sez == "2" && saldo_raf > ZERO) ) - { - saldo_raf = -saldo_raf; - rec_es_prec = TRUE; - } - if (sez == "2" && saldo > ZERO) - { - rec_es_corr = TRUE; - } - if (sez == "2" && saldo_raf > ZERO) - { - rec_es_prec = TRUE; - } - - if (rec_es_corr && rec_es_prec) - riempi_record(sez_opp,let_opp,numr_opp,num_opp,g,c,s,saldo,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); - else - if (rec_es_corr) - { - riempi_record(sez_opp,let_opp,numr_opp,num_opp,g,c,s,saldo,ZERO,ZERO,ZERO,ZERO,ZERO,tmcf); - if (saldo_raf != ZERO) - { - if (sez == "2") - if (saldo_raf < ZERO) - saldo_raf = -saldo_raf; - riempi_record(sez,let,numerorom,numero,g,c,s,ZERO,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); - } - } - else - if (rec_es_prec) - { - riempi_record(sez_opp,let_opp,numr_opp,num_opp,g,c,s,ZERO,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); - if (saldo != ZERO) - { - if (sez == "2") - if (saldo < ZERO) - saldo = -saldo; - riempi_record(sez,let,numerorom,numero,g,c,s,saldo,ZERO,ZERO,ZERO,ZERO,ZERO,tmcf); - } - } - else - if (sez != "0") - { - if (sez == "2") - { - if (saldo < ZERO) - saldo = -saldo; - if (saldo_raf < ZERO) - saldo_raf = -saldo_raf; - } - riempi_record(sez,let,numerorom,numero,g,c,s,saldo,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); - } - } - else - if (sez != "0") - { - if (sez == "2") - { - saldo = -saldo; - saldo_raf = -saldo_raf; - } - riempi_record(sez,let,numerorom,numero,g,c,s,saldo,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); - } - } - } - } - - conto_prec = 0; - - if (classe_conto) - { - if (c != conto_prec && conto_prec != -1) - { - if (no_sez_opposta) - { - riempi_record(sez_conto,let_conto,numr_conto,num_conto,gruppo_prec,c,0,saldo_conto,saldo_conto_raf,ZERO,ZERO,ZERO,ZERO,tmcf,conto_dettagliato); - saldo_conto = ZERO; - saldo_conto_raf = ZERO; - classe_conto = FALSE; - no_sez_opposta = FALSE; - } - if (sez_opposta) - { - int items = _sezopps.items(); - _sezopps.restart(); - for (int i=0; isezione(); - TString let_opp = lriga->lettera(); - TString numr_opp = lriga->num_rom(); - if (numr_opp == " ") - numr_opp.ltrim(); - int num_opp = lriga->numero(); - real saldo_conto = lriga->saldo_conto(); - real saldo_conto_raf = lriga->saldo_conto_raf(); - riempi_record(sez_opp,let_opp,numr_opp,num_opp,gruppo_prec,conto_prec,0,saldo_conto,saldo_conto_raf,ZERO,ZERO,ZERO,ZERO,tmcf,conto_dettagliato); - } - sez_opposta = FALSE; - - _sezopps.destroy(); - } - } - } -} - -void CG1600_application::crea_sort_piano_conti_verifica() -{ - TLocalisamfile pconti(LF_PCON); - TString sez,let,numerorom; - TString sez_conto,let_conto,numr_conto; - int num_conto; - char sezione,lettera,tmcf; - int numero,g,c; - long s; - bool classe_conto = FALSE; - bool conto_dettagliato = FALSE; - bool stsottbil; - int gruppo_prec,conto_prec, indbil; - real saldo,sld_prg_dare,sld_prg_avere,mov_dare,mov_avere; - real saldo_conto,sld_prg_dare_conto,sld_prg_avere_conto,mov_dare_conto,mov_avere_conto; - - _sld->set_annoes(_anno_esercizio); - - saldo_conto = ZERO; - sld_prg_dare_conto = ZERO; - sld_prg_avere_conto = ZERO; - mov_dare_conto = ZERO; - mov_avere_conto = ZERO; - - indbil = 0; - gruppo_prec = -1; - conto_prec = -1; - c = 0; - num_conto = 0; - tmcf = ' '; - - for (pconti.first(); !pconti.eof(); pconti.next()) - { - _prog->addstatus(1); - g = pconti.get_int (PCN_GRUPPO); - c = pconti.get_int (PCN_CONTO); - s = pconti.get_long(PCN_SOTTOCONTO); - sez = pconti.get(PCN_SEZIVD); - let = pconti.get(PCN_LETTIVD); - sezione = sez[0]; - lettera = let[0]; - numerorom = pconti.get(PCN_NUMRIVD); - numero = pconti.get_int (PCN_NUMIVD); - real app; - - saldo = ZERO; - sld_prg_dare = ZERO; - sld_prg_avere = ZERO; - mov_dare = ZERO; - mov_avere = ZERO; - app = ZERO; - - if (classe_conto) - { - if (c != conto_prec && conto_prec != -1) - { - riempi_record(sez_conto,let_conto,numr_conto,num_conto,gruppo_prec,conto_prec,0,saldo_conto,ZERO,sld_prg_dare_conto,sld_prg_avere_conto,mov_dare_conto,mov_avere_conto,tmcf,conto_dettagliato); - saldo_conto = ZERO; - sld_prg_dare_conto = ZERO; - sld_prg_avere_conto = ZERO; - mov_dare_conto = ZERO; - mov_avere_conto = ZERO; - classe_conto = FALSE; - } - } - - //Senza questo controllo conto_prec quando viene letto un gruppo verrebbe - //settato a 0 (il conto non c'e'), quindi nella eventuale lettura del conto - //nel ciclo successivo, qualsiasi conto sarebbe diverso da quello precedente. - - if (g != gruppo_prec) - conto_prec = -1; - else - conto_prec = c; - - gruppo_prec = g; - - // Se si tratta di un conto e contiene la classe, allora lo passo al sort. - // Gli eventuali sottoconti avranno la stessa classe. - - if ((g != 0) && (c != 0) && (s == 0)) - { - stsottbil = pconti.get_bool(PCN_STSOTTBIL); - tmcf = pconti.get(PCN_TMCF)[0]; - indbil = pconti.get_int(PCN_INDBIL); - - //Se sono nello stesso gruppo, ma ho un conto diverso da quello precedentemente - //analizzato , se contiene la classe IV dir. CEE - //allora devo controllare se va dettagliato (STSOTTBIL) - - if (sez != "0") - { - if ((tmcf == 'C') || (tmcf == 'F')) - { - sottoc_clifo_verifica(g, c,_anno_esercizio, tmcf,sez,let,numerorom,numero,indbil,stsottbil); - continue; - } - else - if (!stsottbil) - conto_dettagliato = FALSE; - else - conto_dettagliato = TRUE; - - sez_conto = sez; - - if (let != "") - let_conto = let; - else - if ((sez == "1")||(sez == "2")) - let_conto = "Z"; - else - let_conto = let; - - numr_conto = numerorom; - num_conto = numero; - classe_conto = TRUE; - } - else - { - classe_conto = FALSE; // Metto conto dettagliato = TRUE perche' potrebbero esserci dei sottoconti - conto_dettagliato = TRUE; // di questo conto che hanno la classe e quindi vanno stampati. - } - } - // Se si tratta di un sottoconto e contiene la classe, allora lo passo al sort. - - if ((g != 0) && (c != 0) && (s != 0)) - { - // classe_conto indica se il conto precedentemente letto conteneva la classe, - // ma quest' ultima non era presente a livello di gruppo. In caso affermativo - // anche questo sottoconto appena letto avra' la stessa classe del conto. - - if (_tipo_stampa == 1) - { - if(!calcola(g,c,s,_data_fine_ese,_data_fine_ese_prec)) - continue; - - if (_dataini == _data_ini_ese) - { - sld_prg_dare = _saldo_ini_dare; - sld_prg_avere = _saldo_ini_avere; - mov_dare = _mov_periodo_dare; - mov_avere = _mov_periodo_avere; - saldo = sld_prg_dare-sld_prg_avere+mov_dare-mov_avere; - } - else if (_dataini > _data_ini_ese) - { - sld_prg_dare = _prg_prec_dare; - sld_prg_avere = _prg_prec_avere; - mov_dare = _mov_periodo_dare; - mov_avere = _mov_periodo_avere; - saldo = sld_prg_dare-sld_prg_avere+mov_dare-mov_avere; - } - } - else - if (_tipo_stampa == 2) - { - if (!_sld->ultima_immissione_verifica(_anno_esercizio,g,c,s,indbil)) - continue; - app = _sld->saldoini(); - if (app < ZERO) - { - app = -app; - sld_prg_dare = ZERO; - sld_prg_avere = app; - } - else - { - sld_prg_dare = app; - sld_prg_avere = ZERO; - } - mov_dare = _sld->prgdare(); - mov_avere = _sld->prgavere(); - saldo = sld_prg_dare-sld_prg_avere+mov_dare-mov_avere; - } - - if (classe_conto) - { - if (conto_dettagliato) - riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,saldo,ZERO,sld_prg_dare,sld_prg_avere,mov_dare,mov_avere,tmcf); - - saldo_conto += saldo; - sld_prg_dare_conto += sld_prg_dare; - sld_prg_avere_conto += sld_prg_avere; - mov_dare_conto += mov_dare; - mov_avere_conto += mov_avere; - } - else - { - if (sez != "0") - scrivi_record(sez,let,numerorom,numero,g,c,s,saldo,ZERO,sld_prg_dare,sld_prg_avere,mov_dare,mov_avere,tmcf); - } - } - } - - conto_prec = 0; - - if (classe_conto) - { - if (c != conto_prec && conto_prec != -1) - { - riempi_record(sez_conto,let_conto,numr_conto,num_conto,gruppo_prec,c,0,saldo_conto,ZERO,sld_prg_dare_conto,sld_prg_avere_conto,mov_dare_conto,mov_avere_conto,tmcf,conto_dettagliato); - saldo_conto = ZERO; - sld_prg_dare_conto = ZERO; - sld_prg_avere_conto = ZERO; - mov_dare_conto = ZERO; - mov_avere_conto = ZERO; - classe_conto = FALSE; - } - } -} - - -void CG1600_application::sottoc_clifo_verifica(int g,int c,int anno,char tipocf,TString& sez,TString& let,TString& numerorom,int numero,int indbil,bool stsottbil) -{ - long s; - _listasld = new TSaldi_list (g,c,anno); - real saldo,sld_prg_dare,sld_prg_avere,mov_dare,mov_avere; - real saldo_conto,sld_prg_dare_conto,sld_prg_avere_conto,mov_dare_conto,mov_avere_conto; - real app; - TString sez_conto,let_conto,numr_conto; - int num_conto; - - saldo_conto = ZERO; - sld_prg_dare_conto = ZERO; - sld_prg_avere_conto = ZERO; - mov_dare_conto = ZERO; - mov_avere_conto = ZERO; - - int items = _listasld->items(); - - sez_conto = sez; - - if (let != "") - let_conto = let; - else - if ((sez == "1")||(sez == "2")) - let_conto = "Z"; - else - let_conto = let; - - numr_conto = numerorom; - num_conto = numero; - - _listasld->restart(); - - for (int i=0 ; i < items; i++) - { - const TRectype* r=_listasld->saldi(); - if (r == NULL) break; - - s = r->get_long(SLD_SOTTOCONTO); - - saldo = ZERO; - sld_prg_dare = ZERO; - sld_prg_avere = ZERO; - mov_dare = ZERO; - mov_avere = ZERO; - app = ZERO; - - if (_tipo_stampa == 1) - { - if (!calcola(g,c,s,_data_fine_ese,_data_fine_ese_prec)) - continue; - - if (_dataini == _data_ini_ese) - { - sld_prg_dare = _saldo_ini_dare; - sld_prg_avere = _saldo_ini_avere; - mov_dare = _mov_periodo_dare; - mov_avere = _mov_periodo_avere; - saldo = sld_prg_dare-sld_prg_avere+mov_dare-mov_avere; - } - else if (_dataini > _data_ini_ese) - { - sld_prg_dare = _prg_prec_dare; - sld_prg_avere = _prg_prec_avere; - mov_dare = _mov_periodo_dare; - mov_avere = _mov_periodo_avere; - saldo = sld_prg_dare-sld_prg_avere+mov_dare-mov_avere; - } - } - else - if (_tipo_stampa == 2) - { - if (!_sld->ultima_immissione_bilancio(_anno_esercizio,g,c,s,indbil)) - continue; - app = _sld->saldoini(); - if (app < ZERO) - { - app = -app; - sld_prg_dare = ZERO; - sld_prg_avere = app; - } - else - { - sld_prg_dare = app; - sld_prg_avere = ZERO; - } - mov_dare = _sld->prgdare(); - mov_avere = _sld->prgavere(); - saldo = sld_prg_dare-sld_prg_avere+mov_dare-mov_avere; - } - - if (stsottbil) - riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,saldo,ZERO,sld_prg_dare,sld_prg_avere,mov_dare,mov_avere,tipocf); - saldo_conto += saldo; - sld_prg_dare_conto += sld_prg_dare; - sld_prg_avere_conto += sld_prg_avere; - mov_dare_conto += mov_dare; - mov_avere_conto += mov_avere; - } - if (items > 0) - riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,0,saldo_conto,ZERO,sld_prg_dare_conto,sld_prg_avere_conto,mov_dare_conto,mov_avere_conto,tipocf,stsottbil); - saldo_conto = ZERO; - sld_prg_dare_conto = ZERO; - sld_prg_avere_conto = ZERO; - mov_dare_conto = ZERO; - mov_avere_conto = ZERO; - - delete _listasld; -} - -bool CG1600_application::sottoc_clifo_scalare(int g,int c,int anno,int indbil,real& saldo_conto,real& saldo_conto_raf) -{ - long s; - int aep = 0; - if (anno) aep = anno-1; - _listasld = new TSaldi_list (g,c,anno,aep); - real saldo,saldo_raf; - bool trovato = FALSE; - - int items = _listasld->items(); - - for (int i=0 ; i < items; i++) - { - const TRectype* r=_listasld->saldi(); - if (r == NULL) break; - - s = r->get_long(SLD_SOTTOCONTO); - - saldo = ZERO; - saldo_raf = ZERO; - - if (!calcola_saldo(saldo,saldo_raf,g,c,s,indbil)) - continue; - - saldo_conto += saldo; - saldo_conto_raf += saldo_raf; - trovato = TRUE; - } - delete _listasld; - return trovato; -} - -//La funzione calcola_saldo calcola il saldo dell'esercizio in corso e di -//quello da raffrontare. Inoltre ritorna vero se il sottoconto e' movimentato -//e falso se non e' movimentato, e quindi non deve essere stampato. - -bool CG1600_application::calcola_saldo(real& saldo, real& saldo_raf,int g,int c,long s,int indbil) -{ - bool no_movimentato = TRUE; - bool no_movimentato_raf = TRUE; - bool esiste = FALSE; - TString saldostr,saldo_rafstr; - - _sld->set_annoes(_anno_esercizio); - - if (_tipo_bilancio == 1) - { - if (_tipo_stampa == 1) //bilancio per data limite - { - esiste = _sld->data_limite_bilancio(_tipo_stampa,g,c,s,_datai,_datalimite,indbil,_stampa_mov_prov); - saldo = _sld->saldo(); - - if (!esiste && (!_sld->esiste_saldo() || !_sld->significativo())) - no_movimentato = TRUE; - else - if (!_stampamov) - { - if (saldo == ZERO) - { - if (!_sld->esiste_saldo() || !_sld->significativo()) - no_movimentato = TRUE; - else - no_movimentato = FALSE; - } - else - no_movimentato = FALSE; - } - else - { - if (saldo == ZERO) - no_movimentato = TRUE; - else - no_movimentato = FALSE; - } - } - else if (_tipo_stampa == 2) - { - if (!_sld->ultima_immissione_bilancio(_anno_esercizio,g,c,s,indbil)) - { - if (!_sld->esiste_saldo() || !_sld->significativo()) - no_movimentato = TRUE; - else - no_movimentato = FALSE; - } - else - no_movimentato = FALSE; - - saldo = _sld->saldo(); - } - saldostr = saldo.string(); - - if (_annoeserafr != 0 || _databilrafr != botime) - { - _sld->set_annoes(_anno_esercizio_raf); - - if (_databilrafr != _data_fine_raf) //(_tipo_stampa == 1) bilancio per data limite - { -#ifdef DBG - TString16 datadep (_databilrafr.string()); - TString16 datadep2 (_datairaf.string()); -#endif - esiste = _sld->data_limite_bilancio(DataLimite,g,c,s,_datairaf,_databilrafr,indbil,_stampa_mov_prov); - saldo_raf = _sld->saldo(); - - if (!esiste && (!_sld->esiste_saldo() || !_sld->significativo())) - no_movimentato_raf = TRUE; - else - if (!_stampamov) - { - if (saldo_raf == ZERO) - { - if (!_sld->esiste_saldo() || !_sld->significativo()) - no_movimentato_raf = TRUE; - else - no_movimentato_raf = FALSE; - } - else - no_movimentato_raf = FALSE; - } - else - { - if (saldo_raf == ZERO) - no_movimentato_raf = TRUE; - else - no_movimentato_raf = FALSE; - } - } - else if (_databilrafr == _data_fine_raf) //(_tipo_stampa == 2) - { - if (!_sld->ultima_immissione_bilancio(_anno_esercizio_raf,g,c,s,indbil)) - { - if (!_sld->esiste_saldo() || !_sld->significativo()) - no_movimentato_raf = TRUE; - else - no_movimentato_raf = FALSE; - } - else - no_movimentato_raf = FALSE; - - saldo_raf = _sld->saldo(); - } - saldo_rafstr = saldo_raf.string(); - } - } - - if ((no_movimentato) && (no_movimentato_raf)) - return FALSE; - else - return TRUE; -} - -bool CG1600_application::calcola(int g, int c, long s, - const TDate& fine_es, const TDate& fine_es_prec) -{ - TString sezione; - real importo; - int annoe; - long num_reg; - TDate datareg, datacomp, data; - bool conto_mov = FALSE; - TLocalisamfile rmov(LF_RMOV); - TLocalisamfile mov (LF_MOV); - - _mov_periodo_dare = ZERO; - _mov_periodo_avere = ZERO; - _prg_prec_dare = ZERO; - _prg_prec_avere = ZERO; - _saldo_ini_dare = ZERO; - _saldo_ini_avere = ZERO; - - rmov.setkey(2); - rmov.zero(); - rmov.put(RMV_GRUPPO,g); - if (c != 0) - rmov.put(RMV_CONTO,c); - if (s != 0) - rmov.put(RMV_SOTTOCONTO,s); - TRectype rec(rmov.curr()); - - rmov.read(_isgteq); - for ( ; !rmov.eof(); rmov.next()) - { - if (rmov.curr() != rec) break; - - annoe = rmov.get_int(RMV_ANNOES); - datareg = rmov.get_date(RMV_DATAREG); - num_reg = rmov.get_long(RMV_NUMREG); - sezione = rmov.get(RMV_SEZIONE); - importo = rmov.get_real(RMV_IMPORTO); - - if (importo == ZERO) - continue; - - mov.setkey(1); - mov.zero(); - mov.put(MOV_NUMREG, num_reg); - mov.read(); - if (mov.bad()) mov.zero(); - const bool movprovv = mov.get(MOV_PROVVIS).not_empty(); - datacomp = mov.get_date(MOV_DATACOMP); - - if (!_stampa_mov_prov && movprovv) //se non richiesto - continue; //stampa mov provv. - //li scarto - const TString codcaus(mov.get(MOV_CODCAUS)); - - if (codcaus.not_empty()) - if (codcaus == causale_chiusura()) //la causale e' uguale a quella di chiusura - continue; - - if (_annoese == 0) - data = datareg; - if (_annoese != 0) - data = datacomp; - - //calcolo i movimenti del periodo - if ( (data >= _dataini) && (data <= _datafine) ) - if ((codcaus == causale_apertura() && _data_ini_ese != _dataini) || - (codcaus != causale_apertura())) - { - conto_mov = TRUE; - if (sezione == "D") - _mov_periodo_dare += importo; - else _mov_periodo_avere += importo; - } - - //il saldo inizio es. e' dato dall'importo dare - importo avere di quei movimenti che hanno causale == apertura e data reg >= data inizio es. e <= data limite sup. - - if (_dataini == _data_ini_ese) //calcolo il saldo iniziale - { - if (codcaus == causale_apertura()) - { - if (sezione == "D") - _saldo_ini_dare += importo; - else _saldo_ini_avere += importo; - conto_mov = TRUE; - } - } - else if (_dataini > _data_ini_ese) //calcolo i progressivi precedenti - if ( (data >= _data_ini_ese) && (data < _dataini) ) - { - if (sezione == "D") - _prg_prec_dare += importo; - else _prg_prec_avere += importo; - - conto_mov = TRUE; - } - } - return conto_mov; -} - -bool CG1600_application::set_print(int) -{ - KEY tasto; - -{ - TConfig conf(CONFIG_DITTA); - - _causale_ap = conf.get("CoCaCh"); - _causale_chi = conf.get("CoCaCh"); -} - -_msk->set_handler(F_DATALIM, data_limite); -_msk->set_handler(F_TIPOSTAMPA, tipo_stampa); -_msk->set_handler(F_TIPOBIL, tipo_bilancio); -_msk->set_handler(F_ANNOESE, anno_esercizio); -_msk->set_handler(F_DATAINI, data_inizio); -_msk->set_handler(F_DATAFINE, data_fine); -_msk->set_handler(F_DATABILRAF, data_bil_raff); -_msk->set_handler(F_ANNORAFFR, anno_ese_raff); - -tasto = _msk->run(); - -if (tasto == K_ENTER) -{ - _datastampa = (_msk->get(F_DATASTAMPA)); - _annoese = _msk->get_int(F_ANNOESE); - _annoeserafr = _msk->get_int(F_ANNORAFFR); - _intera_struttura = (bool)(_msk->get(F_STAMPAINT) == "X"); - _stampamov = (bool)(_msk->get(F_STAMPAMOV) == "X"); - _stampacod = (bool)(_msk->get(F_STAMPACOD) == "X"); - _stampa_modulo = (bool)(_msk->get(F_STAMPAMODULO) == "X"); - _tipo_bilancio = atoi(_msk->get(F_TIPOBIL)); - _stampa_mov_prov = (bool)(_msk->get(F_STAMPAMOVPROV) == "X"); - if (_tipo_bilancio == 1) - { - _tipo_stampa = atoi(_msk->get(F_TIPOSTAMPA)); - _prog = new TProgind(_pconti->items(),"Elaborazione in corso... prego attendere",FALSE); - } - else if (_tipo_bilancio == 2) - { - _tipo_stampa = atoi(_msk->get(F_TIPOSTAMPA1)); - _prog = new TProgind(_pconti->items(),"Elaborazione in corso... prego attendere",FALSE); - } - - _cont_let = 0; - _cont_numr = 0; - _cont_num = 0; - _cont_gcs = 0; - _reset_righe_stampa = TRUE; - - set_real_picture("###.###.###.###"); -// if (_stampamov) -// set_print_zero(FALSE); -// else - set_print_zero(TRUE); - - _totale_attivita_gia_stampato = FALSE; - _totale_passivita_gia_stampato = FALSE; - _statopatr_no_stamp = TRUE; - _diffprod_fatto = TRUE; - _risimp_fatto = TRUE; - _sbilancio_ordine = FALSE; - _sbilancio_patr_gia_stampato = FALSE; - _attivo_o_passivo = FALSE; - - _sez_stamp = ' '; - _let_stamp = ' '; - _numr_stamp = ""; - _num_stamp = ""; - _sez_tot = ' '; - _let_tot = ' '; - _numr_tot = ""; - _num_tot = ""; - - _sale = _salerafr = _totale_ordine = _totale_economico = ZERO; - _totale_ordine_raf = _totale_economico_raf = _totale_numero = ZERO; - _totale_numr = _totale_lettera = _totale_sezione = ZERO; - _totale_patrimoniale = _totale_attivita = _totale_passivita = ZERO; - _totale_num_raf = _totale_numr_raf = _totale_let_raf = ZERO; - _totale_sez_raf = _totale_patrim_raf = _totale_attiv_raf = ZERO; - _totale_passiv_raf = _totale_ordine_attivo = _totale_ordine_passivo = ZERO; - _totale_ordine_attivo_raf = _totale_ordine_passivo_raf = ZERO; - _mov_periodo_dare = _mov_periodo_avere = _prg_prec_dare = ZERO; - _prg_prec_avere = _saldo_ini_dare = _saldo_ini_avere = ZERO; - _sld_prg_dare = _sld_prg_avere = _mov_dare = _mov_avere = ZERO; - _tot_num_saldo = _tot_numr_saldo = _tot_let_saldo = _tot_gen_saldo = ZERO; - _tot_num_prg_d = _tot_numr_prg_d = _tot_let_prg_d = _tot_gen_prg_d = ZERO; - _tot_num_prg_a = _tot_numr_prg_a = _tot_let_prg_a = _tot_gen_prg_a = ZERO; - _tot_num_mov_d = _tot_numr_mov_d = _tot_let_mov_d = _tot_gen_mov_d = ZERO; - _tot_num_mov_a = _tot_numr_mov_a = _tot_let_mov_a = _tot_gen_mov_a = ZERO; - _tot_num_saldo_d = _tot_numr_saldo_d = _tot_let_saldo_d = ZERO; - _tot_gen_saldo_d = _tot_num_saldo_a = _tot_numr_saldo_a = ZERO; - _tot_let_saldo_a = _tot_gen_saldo_a = _totale_parziale = ZERO; - _totale_parziale_raf = _tot_parz_sld = _tot_parz_sld_d = ZERO; - _tot_parz_sld_a = _tot_parz_prg_d = _tot_parz_prg_a = ZERO; - _tot_parz_mov_d = _tot_parz_mov_a = ZERO; - - _datai = _data_ini_ese; - _datairaf = _data_ini_raf; - TString data1 = _data_ini_ese.string(); - TString data2 = _data_ini_raf.string(); - -// Se si tratta di stampa intera struttura allora passo al sort anche tutte -// le classi presenti sulla tabella IV dir. CEE, altrimenti passo solamente -// le classi associate ai conti/sottoconti del Piano dei conti. - - init_sort(); - if (_intera_struttura) - crea_sort_tabella(); - if (_tipo_bilancio == 1) - crea_sort_piano_conti_scalare(); - else if (_tipo_bilancio == 2) - crea_sort_piano_conti_verifica(); - _sort->endsort(); - - - crea_intestazione(); - delete _bil; - delete _prog; - return TRUE; -} -return FALSE; -} - -void CG1600_application::stampa_totali() -{ - bool gia_stampato_conto_ord = FALSE; - TString16 diff_prod; - TString16 ris_imp; - - diff_prod.format("%c%c",'9','B'); - ris_imp.format ("%c%c%8s%2s",'9','E',"","21"); - - TString16 classe; - classe.format("%c%c%8s%2s", _sez_da_stamp,_let_da_stamp,(const char*)_numr_da_stamp,(const char*)_num_da_stamp); - - _num = atoi(_num_tot); - _numr = _numr_tot; - _let = _let_tot; - - if (_buff == NULL) - { - _num_tot = ""; - _numr_tot = ""; - _let_tot = ' '; - _sez_tot = ' '; - } - - if ((_sez_stamp == '1' || _sez_stamp == '2') && _let_stamp != 'Z') - _attivo_o_passivo = TRUE; - - if (_num_da_stamp!=_num_tot) - { - if (_let_stamp != 'Z') - { - if (_sez_stamp != '5') - if (_cont_gcs != 0)//(_cont_gcs >= 2) - { - //Fai il totale del numero arabo e stampalo - if (_num != 0) - { - set_row (_i,"@18gTotale@25g%2d@27g)", _num); - set_row (_i++,"@86g%r", &_totale_numero); - } - } - } - if (_sez_stamp == '9') - { - if (classe > ris_imp && _risimp_fatto) - { - if (_num_tot == "20" || _num_tot == "21") - { - set_row (_i,"@4gTotale delle partite straordinarie"); - set_row (_i++,"@86g%r", &_totale_parziale); - set_row (_i,"@4gRisultato prima delle imposte"); - set_row (_i++,"@86g%r", &_totale_economico); - _risimp_fatto = FALSE; - } - } - } - - _cont_gcs = 0; - _totale_numero = 0; - } - if (_numr_da_stamp!=_numr_tot) - { - if (_let_stamp != 'Z') - { - if (_sez_stamp != '5') - { - if (_cont_gcs != 0)//(_cont_gcs >= 2) - { - //Fai il totale del numero arabo e stampalo - if (_num != 0) - { - set_row (_i,"@18gTotale@25g%2d@27g)", _num); - set_row (_i++,"@86g%r", &_totale_numero); - } - } - if (_cont_num != 0)//(_cont_num >= 2) - { - //Fai il totale del numero romano e stampalo - int numeror = atoi(_numr); - TString numrom = itor(numeror); - if (numrom != "") - { - set_row (_i,"@14gTotale@21g%s", (const char*) numrom); - set_row (_i++,"@86g%r", &_totale_numr); - } - } - } - } - _cont_gcs = 0; - _cont_num = 0; - _totale_numero = 0; - _totale_numr = 0; - } - if (_let_da_stamp!=_let_tot) - { - if (_sez_stamp == '9') - { - TString16 classe; - - classe.format("%c%c%8s%2s",_sez_stamp,_let_stamp,(const char*)_numr_stamp,(const char*)_num_stamp); - - if (_cont_gcs != 0)//(_cont_gcs >= 2) - { - //Fai il totale del numero arabo e stampalo - if (_num != 0) - { - set_row (_i,"@18gTotale@25g%2d@27g)", _num); - set_row (_i++,"@86g%r", &_totale_numero); - } - } - if (_cont_num != 0)//(_cont_num >= 2) - { - //Fai il totale del numero romano e stampalo - int numeror = atoi(_numr); - TString numrom = itor(numeror); - if (numrom != "") - { - set_row (_i,"@14gTotale@21g%s", (const char*) numrom); - set_row (_i++,"@86g%r", &_totale_numr); - } - } - if (_cont_numr != 0)//(_cont_numr >= 2) - { - //Fai il totale della lettera e stampalo - if (_let_stamp == 'D') - set_row (_i,"@4gTotale delle rettifiche"); - else - if (_let != ' ') - if (_sez_stamp == '9' && _let_stamp != 'E') - set_row (_i,"@3gTotale@10g%c@12g)", _let); - else - if (_sez_stamp != '9') - set_row (_i,"@3gTotale@10g%c@12g)", _let); - if (_let != ' ') - { - if (_sez_stamp == '9' && _let_stamp != 'E') - set_row (_i++,"@86g%r", &_totale_lettera); - else - if (_sez_stamp != '9') - set_row (_i++,"@86g%r", &_totale_lettera); - } - } - - if (classe > diff_prod && _diffprod_fatto) - { - if (_let_tot == 'A' || _let_tot == 'B') //Solo se esiste una delle due lettere - { - set_row (_i++,"@4gDifferenza tra valore e costi della produzione@86g%r", &_totale_economico); - _diffprod_fatto = FALSE; - } - } - } - else - { - if (_let_stamp != 'Z') - { - if (_sez_stamp != '5') - { - if (_cont_gcs != 0)//(_cont_gcs >= 2) - { - //Fai il totale del numero arabo e stampalo - if (_num != 0) - { - set_row (_i,"@18gTotale@25g%2d@27g)", _num); - set_row (_i++,"@86g%r", &_totale_numero); - } - } - if (_cont_num != 0)//(_cont_num >= 2) - { - //Fai il totale del numero romano e stampalo - int numeror = atoi(_numr); - TString numrom = itor(numeror); - if (numrom != "") - { - set_row (_i,"@14gTotale@21g%s", (const char*) numrom); - set_row (_i++,"@86g%r", &_totale_numr); - } - } - if (_cont_numr != 0)//(_cont_numr >= 2) - { - //Fai il totale della lettera e stampalo - if (_let != ' ') - { - set_row (_i,"@3gTotale@10g%c@12g)", _let); - set_row (_i++,"@86g%r", &_totale_lettera); - } - } - } - } - - if ((_sez_stamp == '1')&&(_let_da_stamp == 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE ATTIVO"); - set_row (_i++,"@86g%r", &_totale_sezione); - _totale_attivita = _totale_sezione; - _totale_sezione = ZERO; - _totale_attivita_gia_stampato = TRUE; - } - - if ((_sez_stamp == '2')&&(_let_da_stamp == 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE PASSIVO"); - set_row (_i++,"@86g%r", &_totale_sezione); - _totale_passivita = _totale_sezione; - _totale_sezione = ZERO; - _totale_passivita_gia_stampato = TRUE; - } - - if ((_sez_stamp == '1')&&(_let_stamp == 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE CONTI D' ORDINE ATTIVI"); - set_row (_i++,"@86g%r", &_totale_ordine_attivo); -// _totale_ordine_attivo = ZERO; - gia_stampato_conto_ord = TRUE; - } - - if ((_sez_stamp == '2')&&(_let_stamp == 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE CONTI D' ORDINE PASSIVI"); - set_row (_i++,"@86g%r", &_totale_ordine_passivo); - _i++; - - if (!_attivo_o_passivo) - { - real totale = _totale_ordine_attivo - _totale_ordine_passivo; - if (totale != ZERO) - { - set_row (_i++,"@0gSALDO CONTI D' ORDINE"); - set_row (_i,"@0gSBILANCIO"); - set_row (_i++,"@86g%r", &totale); - } - _totale_ordine_attivo = ZERO; - _totale_ordine_passivo = ZERO; - _sbilancio_ordine = TRUE; - } - gia_stampato_conto_ord = TRUE; - } - } - _cont_gcs = 0; - _cont_num = 0; - _cont_numr = 0; - _totale_numero = 0; - _totale_numr = 0; - _totale_lettera = 0; - } - if (_sez_da_stamp != _sez_tot) - { - if (_let_stamp != 'Z') - { - if (_sez_stamp != '5') - { - if (_cont_gcs != 0)//(_cont_gcs >= 2) - { - //Fai il totale del numero arabo e stampalo - if (_num != 0) - { - set_row (_i,"@18gTotale@25g%2d@27g)", _num); - set_row (_i++,"@86g%r", &_totale_numero); - } - } - if (_cont_num != 0)//(_cont_num >= 2) - { - //Fai il totale del numero romano e stampalo - int numeror = atoi(_numr); - TString numrom = itor(numeror); - if (numrom != "") - { - set_row (_i,"@14gTotale@21g%s", (const char*) numrom); - set_row (_i++,"@86g%r", &_totale_numr); - } - } - if (_cont_numr != 0)//(_cont_numr >= 2) - { - //Fai il totale della lettera e stampalo - if (_let != ' ') - { - if (_sez_stamp == '9' && _let_stamp != 'E') - { - set_row (_i,"@3gTotale@10g%c@12g)", _let); - set_row (_i++,"@86g%r", &_totale_lettera); - } - else - if (_sez_stamp != '9') - { - set_row (_i,"@3gTotale@10g%c@12g)", _let); - set_row (_i++,"@86g%r", &_totale_lettera); - } - } - } - } - } - - if (!_totale_attivita_gia_stampato) - if ((_sez_stamp == '1') && (_let_stamp != 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE ATTIVO"); - set_row (_i++,"@86g%r", &_totale_sezione); - _totale_attivita = _totale_sezione; - _totale_sezione = ZERO; - } - - if (!_totale_passivita_gia_stampato) - if ((_sez_stamp == '2') && (_let_stamp != 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE PASSIVO"); - set_row (_i++,"@86g%r", &_totale_sezione); - _totale_passivita = _totale_sezione; - _totale_sezione = ZERO; - } - - if (!gia_stampato_conto_ord) - { - if (_sez_stamp == '2') - { - if (!_sbilancio_patr_gia_stampato) - { - _totale_patrimoniale = _totale_attivita - _totale_passivita; - if (_totale_patrimoniale != ZERO) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i++,"@0gSALDO STATO PATRIMONIALE"); - set_row (_i,"@0gSBILANCIO (ATTIVO - PASSIVO)"); - //_totale_patrimoniale = _totale_attivita - _totale_passivita; - set_row (_i++,"@86g%r", &_totale_patrimoniale); - _totale_patrimoniale = ZERO; - } - _sbilancio_patr_gia_stampato = TRUE; - } - } - if ((_sez_stamp == '1')&&(_let_stamp == 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE CONTI D' ORDINE ATTIVI"); - set_row (_i++,"@86g%r", &_totale_ordine_attivo); - // _totale_ordine_attivo = ZERO; - } - if ((_sez_stamp == '2')&&(_let_stamp == 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE CONTI D' ORDINE PASSIVI"); - set_row (_i++,"@86g%r", &_totale_ordine_passivo); - _i++; - if (!_sbilancio_ordine) - { - real totale = _totale_ordine_attivo - _totale_ordine_passivo; - if (totale != ZERO) - { - set_row (_i++,"@0g%c", app); - set_row (_i++,"@0gSALDO CONTI D' ORDINE"); - set_row (_i,"@0gSBILANCIO"); - set_row (_i++,"@86g%r", &totale); - _sbilancio_ordine = TRUE; - } - _totale_ordine_passivo = ZERO; - _totale_ordine_attivo = ZERO; - } - } - } - - if (_sez_stamp == '2') - { - char app = ' '; - - if (!_sbilancio_patr_gia_stampato) - { - _totale_patrimoniale = _totale_attivita - _totale_passivita; - if (_totale_patrimoniale != ZERO) - { - set_row (_i++,"@0g%c", app); - set_row (_i++,"@0gSALDO STATO PATRIMONIALE"); - set_row (_i,"@0gSBILANCIO (ATTIVO - PASSIVO)"); - //_totale_patrimoniale = _totale_attivita - _totale_passivita; - set_row (_i++,"@86g%r", &_totale_patrimoniale); - _totale_patrimoniale = ZERO; - } - } - if (!_sbilancio_ordine) - { - real totale = _totale_ordine_attivo - _totale_ordine_passivo; - if (totale != ZERO && !_sbilancio_ordine) - { - set_row (_i++,"@0g%c", app); - set_row (_i++,"@0gSALDO CONTI D' ORDINE"); - set_row (_i,"@0gSBILANCIO"); - set_row (_i++,"@86g%r", &totale); - } - } - } - if (_sez_stamp == '5') - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE CONTI D' ORDINE"); - set_row (_i++,"@86g%r", &_totale_ordine); - _totale_ordine = ZERO; - } - if (_sez_stamp == '9') - { - if (_buff == NULL) - { - if ((_let_stamp == 'A' || _let_stamp == 'B') && _diffprod_fatto)//Solo se esiste una delle due lettere - { - set_row (_i++,"@4gDifferenza tra valore e costi della produzione@86g%r", &_totale_economico); - _diffprod_fatto = FALSE; - } - if (_risimp_fatto) - { - if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) - { - set_row (_i,"@4gTotale delle partite straordinarie"); - set_row (_i++,"@86g%r", &_totale_parziale); - set_row (_i,"@4gRisultato prima delle imposte"); - set_row (_i++,"@86g%r", &_totale_economico); - _risimp_fatto = FALSE; - } - } - } - - char app = ' '; - set_row (_i++,"@0g%c", app); - if (_totale_economico != ZERO) - { - set_row (_i,"@0gRISULTATO CONTO ECONOMICO"); - set_row (_i++,"@86g%r", &_totale_economico); - _totale_economico = ZERO; - } - } - _cont_gcs = 0; - _cont_num = 0; - _cont_numr = 0; - _cont_let = 0; - _totale_numero = 0; - _totale_numr = 0; - _totale_lettera = 0; - } -} - -void CG1600_application::stampa_totali_con_raffronto() -{ - bool gia_stampato_conto_ord = FALSE; - TString16 diff_prod; - TString16 ris_imp; - - diff_prod.format("%c%c",'9','B'); - ris_imp.format ("%c%c%8s%2s",'9','E',"","21"); - - TString16 classe; - classe.format("%c%c%8s%2s", _sez_da_stamp,_let_da_stamp,(const char*)_numr_da_stamp,(const char*)_num_da_stamp); - - _num = atoi(_num_tot); - _numr = _numr_tot; - _let = _let_tot; - - if (_buff == NULL) - { - _num_tot = ""; - _numr_tot = ""; - _let_tot = ' '; - _sez_tot = ' '; - } - - if ((_sez_stamp == '1' || _sez_stamp == '2') && _let_stamp != 'Z') - _attivo_o_passivo = TRUE; - - if (_num_da_stamp!=_num_tot) - { - - if (_let_stamp != 'Z') - { - if (_sez_stamp != '5') - if (_cont_gcs != 0)//(_cont_gcs >= 2) - { - //Fai il totale del numero arabo e stampalo - if (_num != 0) - { - set_row (_i,"@18gTotale@25g%2d@27g)", _num); - set_row (_i,"@86g%r", &_totale_numero); - set_row (_i++,"@112g%r", &_totale_num_raf); - } - } - } - if (_sez_stamp == '9') - { - if (classe > ris_imp && _risimp_fatto) - { - if (_num_tot == "20" || _num_tot == "21") - { - set_row (_i,"@4gTotale delle partite straordinarie"); - set_row (_i,"@86g%r", &_totale_parziale); - set_row (_i++,"@112g%r", &_totale_parziale_raf); - set_row (_i,"@4gRisultato prima delle imposte"); - set_row (_i,"@86g%r", &_totale_economico); - set_row (_i++,"@112g%r", &_totale_economico_raf); - _risimp_fatto = FALSE; - } - } - } - _cont_gcs = 0; - _totale_numero = 0; - _totale_num_raf = 0; - } - if (_numr_da_stamp!=_numr_tot) - { - if (_let_stamp != 'Z') - { - if (_sez_stamp != '5') - { - if (_cont_gcs != 0)//(_cont_gcs >= 2) - { - //Fai il totale del numero arabo e stampalo - if (_num != 0) - { - set_row (_i,"@18gTotale@25g%2d@27g)", _num); - set_row (_i,"@86g%r", &_totale_numero); - set_row (_i++,"@112g%r", &_totale_num_raf); - } - } - if (_cont_num != 0)//(_cont_num >= 2) - { - //Fai il totale del numero romano e stampalo - int numeror = atoi(_numr); - TString numrom = itor(numeror); - if (numrom != "") - { - set_row (_i,"@14gTotale@21g%s", (const char*) numrom); - set_row (_i,"@86g%r", &_totale_numr); - set_row (_i++,"@112g%r", &_totale_numr_raf); - } - } - } - } - _cont_gcs = 0; - _cont_num = 0; - _totale_numero = 0; - _totale_numr = 0; - _totale_num_raf = 0; - _totale_numr_raf = 0; - } - if (_let_da_stamp!=_let_tot) - { - if (_sez_stamp == '9') - { - TString16 classe; - - classe.format("%c%c%8s%2s",_sez_stamp,_let_stamp,(const char*)_numr_stamp,(const char*)_num_stamp); - - if (_cont_gcs != 0)//(_cont_gcs >= 2) - { - //Fai il totale del numero arabo e stampalo - if (_num != 0) - { - set_row (_i,"@18gTotale@25g%2d@27g)", _num); - set_row (_i++,"@86g%r", &_totale_numero); - } - } - if (_cont_num != 0)//(_cont_num >= 2) - { - //Fai il totale del numero romano e stampalo - int numeror = atoi(_numr); - TString numrom = itor(numeror); - if (numrom != "") - { - set_row (_i,"@14gTotale@21g%s", (const char*) numrom); - set_row (_i++,"@86g%r", &_totale_numr); - } - } - if (_cont_numr != 0)//(_cont_numr >= 2) - { - //Fai il totale della lettera e stampalo - if (_let_stamp == 'D') - set_row (_i,"@4gTotale delle rettifiche"); - else - if (_let != ' ') - if (_sez_stamp == '9' && _let_stamp != 'E') - set_row (_i,"@3gTotale@10g%c@12g)", _let); - else - if (_sez_stamp != '9') - set_row (_i,"@3gTotale@10g%c@12g)", _let); - if (_let != ' ') - { - if (_sez_stamp == '9' && _let_stamp != 'E') - { - set_row (_i,"@86g%r", &_totale_lettera); - set_row (_i++,"@112g%r", &_totale_let_raf); - } - else - if (_sez_stamp != '9') - { - set_row (_i,"@86g%r", &_totale_lettera); - set_row (_i++,"@112g%r", &_totale_let_raf); - } - } - } - if (classe > diff_prod && _diffprod_fatto) - { - if (_let_tot == 'A' || _let_tot == 'B') - { - set_row (_i++,"@4gDifferenza tra valore e costi della produzione@86g%r@112g%r", &_totale_economico,&_totale_economico_raf); - _diffprod_fatto = FALSE; - } - } - - } - else - { - if (_let_stamp != 'Z') - { - if (_sez_stamp != '5') - { - if (_cont_gcs != 0)//(_cont_gcs >= 2) - { - //Fai il totale del numero arabo e stampalo - if (_num != 0) - { - set_row (_i,"@18gTotale@25g%2d@27g)", _num); - set_row (_i,"@86g%r", &_totale_numero); - set_row (_i++,"@112g%r", &_totale_num_raf); - } - } - if (_cont_num != 0)//(_cont_num >= 2) - { - //Fai il totale del numero romano e stampalo - int numeror = atoi(_numr); - TString numrom = itor(numeror); - if (numrom != "") - { - set_row (_i,"@14gTotale@21g%s", (const char*) numrom); - set_row (_i,"@86g%r", &_totale_numr); - set_row (_i++,"@112g%r", &_totale_numr_raf); - } - } - if (_cont_numr != 0)//(_cont_numr >= 2) - { - //Fai il totale della lettera e stampalo - if (_let != ' ') - { - set_row (_i,"@3gTotale@10g%c@12g)", _let); - set_row (_i,"@86g%r", &_totale_lettera); - set_row (_i++,"@112g%r", &_totale_let_raf); - } - } - } - } - - if ((_sez_stamp == '1')&&(_let_da_stamp == 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE ATTIVO"); - set_row (_i,"@86g%r", &_totale_sezione); - set_row (_i++,"@112g%r", &_totale_sez_raf); - _totale_attivita = _totale_sezione; - _totale_attiv_raf = _totale_sez_raf; - _totale_sezione = ZERO; - _totale_sez_raf = ZERO; - _totale_attivita_gia_stampato = TRUE; - } - - if ((_sez_stamp == '2')&&(_let_da_stamp == 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE PASSIVO"); - set_row (_i,"@86g%r", &_totale_sezione); - set_row (_i++,"@112g%r", &_totale_sez_raf); - _totale_passivita = _totale_sezione; - _totale_passiv_raf = _totale_sez_raf; - _totale_sezione = ZERO; - _totale_sez_raf = ZERO; - _totale_passivita_gia_stampato = TRUE; - } - - if ((_sez_stamp == '1')&&(_let_stamp == 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE CONTI D' ORDINE ATTIVI"); - set_row (_i,"@86g%r", &_totale_ordine_attivo); - set_row (_i++,"@112g%r", &_totale_ordine_attivo_raf); - //_totale_ordine_attivo = ZERO; - //_totale_ordine_attivo_raf = ZERO; - gia_stampato_conto_ord = TRUE; - } - - if ((_sez_stamp == '2')&&(_let_stamp == 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE CONTI D' ORDINE PASSIVI"); - set_row (_i,"@86g%r", &_totale_ordine_passivo); - set_row (_i++,"@112g%r", &_totale_ordine_passivo_raf); - _i++; - gia_stampato_conto_ord = TRUE; - if (!_attivo_o_passivo) - { - real totale = _totale_ordine_attivo - _totale_ordine_passivo; - real tot_raf = _totale_ordine_attivo_raf - _totale_ordine_passivo_raf; - if (totale != ZERO || tot_raf != ZERO) - { - set_row (_i++,"@0gSALDO CONTI D' ORDINE"); - set_row (_i,"@0gSBILANCIO"); - set_row (_i,"@86g%r", &totale); - set_row (_i++,"@112g%r", &tot_raf); - } - _totale_ordine_attivo = ZERO; - _totale_ordine_attivo_raf = ZERO; - _totale_ordine_passivo = ZERO; - _totale_ordine_passivo_raf = ZERO; - _sbilancio_ordine = TRUE; - _sbilancio_patr_gia_stampato = TRUE; //Se passa di qui non ci sono ne attivi ne passivo - } - } - } - _cont_gcs = 0; - _cont_num = 0; - _cont_numr = 0; - _totale_numero = 0; - _totale_numr = 0; - _totale_lettera = 0; - _totale_num_raf = 0; - _totale_numr_raf = 0; - _totale_let_raf = 0; - } - if (_sez_da_stamp != _sez_tot) - { - if (_let_stamp != 'Z') - { - if (_sez_stamp != '5') - { - if (_cont_gcs != 0)//(_cont_gcs >= 2) - { - //Fai il totale del numero arabo e stampalo - if (_num != 0) - { - set_row (_i,"@18gTotale@25g%2d@27g)", _num); - set_row (_i,"@86g%r", &_totale_numero); - set_row (_i++,"@112g%r", &_totale_num_raf); - } - } - if (_cont_num != 0)//(_cont_num >= 2) - { - //Fai il totale del numero romano e stampalo - int numeror = atoi(_numr); - TString numrom = itor(numeror); - if (numrom != "") - { - set_row (_i,"@14gTotale@21g%s", (const char*) numrom); - set_row (_i++,"@86g%r", &_totale_numr); - set_row (_i++,"@112g%r", &_totale_numr_raf); - } - } - if (_cont_numr != 0)//(_cont_numr >= 2) - { - //Fai il totale della lettera e stampalo - if (_let != ' ') - { - if (_sez_stamp == '9' && _let_stamp != 'E') - { - set_row (_i,"@3gTotale@10g%c@12g)", _let); - set_row (_i++,"@86g%r", &_totale_lettera); - set_row (_i++,"@112g%r", &_totale_let_raf); - } - else - if (_sez_stamp != '9') - { - set_row (_i,"@3gTotale@10g%c@12g)", _let); - set_row (_i++,"@86g%r", &_totale_lettera); - set_row (_i++,"@112g%r", &_totale_let_raf); - } - } - } - } - } - - if (!_totale_attivita_gia_stampato) - if ((_sez_stamp == '1') && (_let_stamp != 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE ATTIVO"); - set_row (_i,"@86g%r", &_totale_sezione); - set_row (_i++,"@112g%r", &_totale_sez_raf); - _totale_attivita = _totale_sezione; - _totale_attiv_raf = _totale_sez_raf; - _totale_sezione = ZERO; - _totale_sez_raf = ZERO; - _totale_attivita_gia_stampato = TRUE; - } - - if (!_totale_passivita_gia_stampato) - if ((_sez_stamp == '2') && (_let_stamp != 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE PASSIVO"); - set_row (_i,"@86g%r", &_totale_sezione); - set_row (_i++,"@112g%r", &_totale_sez_raf); - _totale_passivita = _totale_sezione; - _totale_passiv_raf = _totale_sez_raf; - _totale_sezione = ZERO; - _totale_sez_raf = ZERO; - _totale_passivita_gia_stampato = TRUE; - } - - if (!gia_stampato_conto_ord) - { - if (_sez_stamp == '2') - { - if (!_sbilancio_patr_gia_stampato) - { - _totale_patrimoniale = _totale_attivita - _totale_passivita; - _totale_patrim_raf = _totale_attiv_raf - _totale_passiv_raf; - if (_totale_patrimoniale != ZERO || _totale_patrim_raf != ZERO) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i++,"@0gSALDO STATO PATRIMONIALE"); - set_row (_i,"@0gSBILANCIO (ATTIVO - PASSIVO)"); - //_totale_patrimoniale = _totale_attivita - _totale_passivita; - //_totale_patrim_raf = _totale_attiv_raf - _totale_passiv_raf; - set_row (_i,"@86g%r", &_totale_patrimoniale); - set_row (_i++,"@112g%r", &_totale_patrim_raf); - _totale_patrimoniale = 0; - _totale_patrim_raf = 0; - } - _sbilancio_patr_gia_stampato = TRUE; - } - } - if ((_sez_stamp == '1')&&(_let_stamp == 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE CONTI D' ORDINE ATTIVI"); - set_row (_i,"@86g%r", &_totale_ordine_attivo); - set_row (_i++,"@112g%r", &_totale_ordine_attivo_raf); - //_totale_ordine_attivo = ZERO; - //_totale_ordine_attivo_raf = ZERO; - } - - if ((_sez_stamp == '2')&&(_let_stamp == 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE CONTI D' ORDINE PASSIVI"); - set_row (_i,"@86g%r", &_totale_ordine_passivo); - set_row (_i++,"@112g%r", &_totale_ordine_passivo_raf); - _i++; - if (!_sbilancio_ordine) - { - real totale = _totale_ordine_attivo - _totale_ordine_passivo; - real tot_raf = _totale_ordine_attivo_raf - _totale_ordine_passivo_raf; - if (totale != ZERO || tot_raf != ZERO) - { - set_row (_i++,"@0g%c", app); - set_row (_i++,"@0gSALDO CONTI D' ORDINE"); - set_row (_i,"@0gSBILANCIO"); - set_row (_i,"@86g%r", &totale); - set_row (_i++,"@112g%r", &tot_raf); - _sbilancio_ordine = TRUE; - } - _totale_ordine_attivo = ZERO; - _totale_ordine_attivo_raf = ZERO; - _totale_ordine_passivo = ZERO; - _totale_ordine_passivo_raf = ZERO; - _sbilancio_ordine = TRUE; - } - } - } - - if (_sez_stamp == '2') - { - char app = ' '; - if (!_sbilancio_patr_gia_stampato) - { - _totale_patrimoniale = _totale_attivita - _totale_passivita; - _totale_patrim_raf = _totale_attiv_raf - _totale_passiv_raf; - if (_totale_patrimoniale != ZERO || _totale_patrim_raf != ZERO) - { - set_row (_i++,"@0g%c", app); - set_row (_i++,"@0gSALDO STATO PATRIMONIALE"); - set_row (_i,"@0gSBILANCIO (ATTIVO - PASSIVO)"); - //_totale_patrimoniale = _totale_attivita - _totale_passivita; - //_totale_patrim_raf = _totale_attiv_raf - _totale_passiv_raf; - set_row (_i,"@86g%r", &_totale_patrimoniale); - set_row (_i++,"@112g%r", &_totale_patrim_raf); - _totale_patrimoniale = 0; - _totale_patrim_raf = 0; - } - } - if (!_sbilancio_ordine) - { - real totale = _totale_ordine_attivo - _totale_ordine_passivo; - real tot_raf = _totale_ordine_attivo_raf - _totale_ordine_passivo_raf; - if ((totale != ZERO || tot_raf != ZERO) && !_sbilancio_ordine) - { - set_row (_i++,"@0g%c", app); - set_row (_i++,"@0gSALDO CONTI D' ORDINE"); - set_row (_i,"@0gSBILANCIO"); - set_row (_i,"@86g%r", &totale); - set_row (_i++,"@112g%r", &tot_raf); - } - } - } - if (_sez_stamp == '5') - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i,"@0gTOTALE CONTI D' ORDINE"); - set_row (_i,"@86g%r", &_totale_ordine); - set_row (_i++,"@112g%r", &_totale_ordine_raf); - _totale_ordine = 0; - _totale_ordine_raf = 0; - } - if (_sez_stamp == '9') - { - if (_buff == NULL) - { - if ((_let_stamp == 'A' || _let_stamp == 'B') && _diffprod_fatto) - { - set_row (_i++,"@4gDifferenza tra valore e costi della produzione@86g%r@112g%r", &_totale_economico,&_totale_economico_raf); - _diffprod_fatto = FALSE; - } - if (_risimp_fatto) - { - if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) - { - set_row (_i,"@4gTotale delle partite straordinarie"); - set_row (_i,"@86g%r", &_totale_parziale); - set_row (_i++,"@112g%r", &_totale_parziale_raf); - set_row (_i,"@4gRisultato prima delle imposte"); - set_row (_i,"@86g%r", &_totale_economico); - set_row (_i++,"@112g%r", &_totale_economico_raf); - _risimp_fatto = FALSE; - } - } - } - char app = ' '; - set_row (_i++,"@0g%c", app); - if (_totale_economico != ZERO || _totale_economico_raf != ZERO) - { - set_row (_i,"@0gRISULTATO CONTO ECONOMICO"); - set_row (_i,"@86g%r", &_totale_economico); - set_row (_i++,"@112g%r", &_totale_economico_raf); - _totale_economico = 0; - _totale_economico_raf = 0; - } - } - _cont_gcs = 0; - _cont_num = 0; - _cont_numr = 0; - _cont_let = 0; - _totale_numero = 0; - _totale_numr = 0; - _totale_lettera = 0; - _totale_num_raf = 0; - _totale_numr_raf = 0; - _totale_let_raf = 0; - } -} - -void CG1600_application::stampa_totali_verifica() -{ - TString16 ris_imp; - - ris_imp.format ("%c%c%8s%2s",'9','E',"","21"); - - _num = atoi(_num_tot); - _numr = _numr_tot; - _let = _let_tot; - _sez = _sez_tot; - - if (_buff == NULL) - { - _num_tot = ""; - _numr_tot = ""; - _let_tot = ' '; - _sez_tot = ' '; - } - - if (_num_da_stamp!=_num_tot) - { - if (_cont_gcs != 0)//(_cont_gcs >= 2) - { - //Fai il totale del numero arabo e stampalo - if (((_sez == '1')||(_sez == '2')||(_sez == '9'))&&(_let != 'Z')) - { - if (_num != 0) - set_row (_i,"@8gTotale@15g%2d@17g)",_num); - } - else - if (_num != 0) - set_row (_i,"@8gTotale"); - - if (_num != 0) - { - set_row (_i,"@49g%r", &_tot_num_prg_d); - set_row (_i,"@65g%r", &_tot_num_prg_a); - set_row (_i,"@82g%r", &_tot_num_mov_d); - set_row (_i,"@98g%r", &_tot_num_mov_a); - } - - if (!_stampa_modulo) - { - if (_tot_num_saldo < ZERO) - { - _tot_num_saldo = -_tot_num_saldo; - _tot_sez_saldo = 'A'; - } - else - _tot_sez_saldo = 'D'; - - if (_num != 0) - stampa_saldo_132(_tot_num_saldo); - } - else - { - if (_num != 0) - stampa_saldo_198(_tot_num_saldo_d,_tot_num_saldo_a); - // _tot_num_saldo_d = 0; - // _tot_num_saldo_a = 0; - } - if (_sez_stamp == '9') - { - TString16 classe; - - classe.format("%c%c%8s%2s", _sez_da_stamp,_let_da_stamp,(const char*)_numr_da_stamp,(const char*)_num_da_stamp); - - if (classe > ris_imp && _risimp_fatto) - { - if (_num_tot == "20" || _num_tot == "21") - { - set_row (_i,"@4gTotale delle partite straordinarie"); - set_row (_i,"@49g%r", &_tot_parz_prg_d); - set_row (_i,"@65g%r", &_tot_parz_prg_a); - set_row (_i,"@82g%r", &_tot_parz_mov_d); - set_row (_i,"@98g%r", &_tot_parz_mov_a); - _risimp_fatto = FALSE; - if (!_stampa_modulo) - { - if (_tot_parz_sld < ZERO) - { - _tot_parz_sld = -_tot_parz_sld; - _tot_sez_saldo = 'A'; - } - else - _tot_sez_saldo = 'D'; - - if (_num != 0) - stampa_saldo_132(_tot_parz_sld); - } - else - { - if (_num != 0) - stampa_saldo_198(_tot_parz_sld_d,_tot_parz_sld_a); - } - } - } - } - } - _cont_gcs = 0; - _tot_num_prg_d = ZERO; - _tot_num_prg_a = ZERO; - _tot_num_mov_d = ZERO; - _tot_num_mov_a = ZERO; - _tot_num_saldo = ZERO; - } - if (_numr_da_stamp!=_numr_tot) - { - if (_cont_gcs != 0)//(_cont_gcs >= 2) - { - //Fai il totale del numero arabo e stampalo - if (((_sez == '1')||(_sez == '2')||(_sez == '9'))&&(_let != 'Z')) - { - if (_num != 0) - set_row (_i,"@8gTotale@15g%2d@17g)", _num); - } - else - if (_num != 0) - set_row (_i,"@8gTotale"); - - if (_num != 0) - { - set_row (_i,"@49g%r", &_tot_num_prg_d); - set_row (_i,"@65g%r", &_tot_num_prg_a); - set_row (_i,"@82g%r", &_tot_num_mov_d); - set_row (_i,"@98g%r", &_tot_num_mov_a); - } - - if (!_stampa_modulo) - { - if (_tot_num_saldo < ZERO) - { - _tot_num_saldo = -_tot_num_saldo; - _tot_sez_saldo = 'A'; - } - else - _tot_sez_saldo = 'D'; - - if (_num != 0) - stampa_saldo_132(_tot_num_saldo); - } - else - { - if (_num != 0) - stampa_saldo_198(_tot_num_saldo_d,_tot_num_saldo_a); - //_tot_num_saldo_d = 0; - //_tot_num_saldo_a = 0; - } - } - if (_cont_num != 0)//(_cont_num >= 2) - { - //Fai il totale del numero romano e stampalo - int numeror = atoi(_numr); - TString numrom = itor(numeror); - if (numrom != "") - { - set_row (_i,"@8gTotale@15g%s", (const char*) numrom); - set_row (_i,"@49g%r", &_tot_numr_prg_d); - set_row (_i,"@65g%r", &_tot_numr_prg_a); - set_row (_i,"@82g%r", &_tot_numr_mov_d); - set_row (_i,"@98g%r", &_tot_numr_mov_a); - } - - if (!_stampa_modulo) - { - if (_tot_numr_saldo < ZERO) - { - _tot_numr_saldo = -_tot_numr_saldo; - _tot_sez_saldo = 'A'; - } - else - _tot_sez_saldo = 'D'; - - if (numrom != "") - stampa_saldo_132(_tot_numr_saldo); - } - else - { - if (numrom != "") - stampa_saldo_198(_tot_numr_saldo_d,_tot_numr_saldo_a); - // _tot_numr_saldo_d = 0; - // _tot_numr_saldo_a = 0; - } - } - _cont_gcs = 0; - _cont_num = 0; - _tot_num_prg_d = ZERO; - _tot_num_prg_a = ZERO; - _tot_num_mov_d = ZERO; - _tot_num_mov_a = ZERO; - _tot_num_saldo = ZERO; - _tot_numr_prg_d = ZERO; - _tot_numr_prg_a = ZERO; - _tot_numr_mov_d = ZERO; - _tot_numr_mov_a = ZERO; - _tot_numr_saldo = ZERO; - } - if ((_let_da_stamp!=_let_tot) || (_sez_da_stamp != _sez_tot)) - { - if (_cont_gcs != 0)//(_cont_gcs >= 2) - { - //Fai il totale del numero arabo e stampalo - if (((_sez == '1')||(_sez == '2')||(_sez == '9'))&&(_let != 'Z')) - { - if (_num != 0) - set_row (_i,"@8gTotale@15g%2d@17g)",_num); - } - else - if (_num != 0) - set_row (_i,"@8gTotale"); - - if (_num != 0) - { - set_row (_i,"@49g%r", &_tot_num_prg_d); - set_row (_i,"@65g%r", &_tot_num_prg_a); - set_row (_i,"@82g%r", &_tot_num_mov_d); - set_row (_i,"@98g%r", &_tot_num_mov_a); - } - - if (!_stampa_modulo) - { - if (_tot_num_saldo < ZERO) - { - _tot_num_saldo = -_tot_num_saldo; - _tot_sez_saldo = 'A'; - } - else - _tot_sez_saldo = 'D'; - - if (_num != 0) - stampa_saldo_132(_tot_num_saldo); - } - else - { - if (_num != 0) - stampa_saldo_198(_tot_num_saldo_d,_tot_num_saldo_a); - // _tot_num_saldo_d = 0; - // _tot_num_saldo_a = 0; - } - } - if (_cont_num != 0)//(_cont_num >= 2) - { - //Fai il totale del numero romano e stampalo - int numeror = atoi(_numr); - TString numrom = itor(numeror); - if (numrom != "") - { - set_row (_i,"@8gTotale@15g%s", (const char*) numrom); - set_row (_i,"@49g%r", &_tot_numr_prg_d); - set_row (_i,"@65g%r", &_tot_numr_prg_a); - set_row (_i,"@82g%r", &_tot_numr_mov_d); - set_row (_i,"@98g%r", &_tot_numr_mov_a); - } - - if (!_stampa_modulo) - { - if (_tot_numr_saldo < ZERO) - { - _tot_numr_saldo = -_tot_numr_saldo; - _tot_sez_saldo = 'A'; - } - else - _tot_sez_saldo = 'D'; - - if (numrom != "") - stampa_saldo_132(_tot_numr_saldo); - } - else - { - if (numrom != "") - stampa_saldo_198(_tot_numr_saldo_d,_tot_numr_saldo_a); - // _tot_numr_saldo_d = 0; - // _tot_numr_saldo_a = 0; - } - } - if (_cont_numr != 0)//(_cont_numr >= 2) - { - //Fai il totale della lettera e stampalo - if (_let != ' ') - { - if (_sez_stamp == '9' && _let_stamp != 'E') - { - set_row (_i,"@8gTotale@15g%c@16g)", _let); - set_row (_i,"@49g%r", &_tot_let_prg_d); - set_row (_i,"@65g%r", &_tot_let_prg_a); - set_row (_i,"@82g%r", &_tot_let_mov_d); - set_row (_i,"@98g%r", &_tot_let_mov_a); - } - else - if (_sez_stamp != '9') - { - set_row (_i,"@8gTotale@15g%c@16g)", _let); - set_row (_i,"@49g%r", &_tot_let_prg_d); - set_row (_i,"@65g%r", &_tot_let_prg_a); - set_row (_i,"@82g%r", &_tot_let_mov_d); - set_row (_i,"@98g%r", &_tot_let_mov_a); - } - } - - if (!_stampa_modulo) - { - if (_tot_let_saldo < ZERO) - { - _tot_let_saldo = -_tot_let_saldo; - _tot_sez_saldo = 'A'; - } - else - _tot_sez_saldo = 'D'; - - if (_let != ' ') - if (_sez_stamp == '9' && _let_stamp != 'E') - stampa_saldo_132(_tot_let_saldo); - else - if (_sez_stamp != '9') - stampa_saldo_132(_tot_let_saldo); - } - else - { - if (_let != ' ') - if (_sez_stamp == '9' && _let_stamp != 'E') - stampa_saldo_198(_tot_let_saldo_d,_tot_let_saldo_a); - else - stampa_saldo_198(_tot_let_saldo_d,_tot_let_saldo_a); - // _tot_let_saldo_d = 0; - // _tot_let_saldo_a = 0; - } - } - _cont_gcs = 0; - _cont_num = 0; - _cont_numr = 0; - _tot_num_prg_d = ZERO; - _tot_num_prg_a = ZERO; - _tot_num_mov_d = ZERO; - _tot_num_mov_a = ZERO; - _tot_num_saldo = ZERO; - _tot_numr_prg_d = ZERO; - _tot_numr_prg_a = ZERO; - _tot_numr_mov_d = ZERO; - _tot_numr_mov_a = ZERO; - _tot_numr_saldo = ZERO; - _tot_let_prg_d = ZERO; - _tot_let_prg_a = ZERO; - _tot_let_mov_d = ZERO; - _tot_let_mov_a = ZERO; - _tot_let_saldo = ZERO; - } -} - -void CG1600_application::stampa_saldo_198(real& saldo_d,real& saldo_a) -{ - set_row (_i,"@115g%r", &saldo_d); - set_row (_i,"@48g!@81g!@114g!@131g!"); - set_row (_i,"@133g%r", &saldo_a); - set_row (_i++,"@48g!@81g!@114g!@131g!"); - saldo_d = real(ZERO); - saldo_a = real(ZERO); -} - -void CG1600_application::stampa_saldo_132(const real& saldo) -{ - set_row (_i,"@115g%r", &saldo); - set_row (_i,"@48g!@81g!@114g!"); - set_row (_i++,"@131g%c", _tot_sez_saldo); -} - -print_action CG1600_application::postprocess_page(int file, int counter) -{ - struct bil_ivd* bil = (struct bil_ivd*) _buff; - - bil = (struct bil_ivd*) _buff; - - if (_tipo_bilancio == 1) - { - if (_sez_da_stamp != _sez_stamp) - { - if (_sez_da_stamp == '5') - { - if (!_intera_struttura) - { - if (bil->gruppo[0] != 'Z') - { - reset_print(); - _i = 1; - setta_righe("CONTI D' ORDINE"); - _reset_righe_stampa = FALSE; - } - } - else - { - reset_print(); - _i = 1; - setta_righe("CONTI D' ORDINE"); - _reset_righe_stampa = FALSE; - } - } - if (_sez_da_stamp == '9') - { - if (!_intera_struttura) - { - if (bil->gruppo[0] != 'Z') - { - reset_print(); - _i = 1; - setta_righe("CONTO ECONOMICO"); - _reset_righe_stampa = FALSE; - } - } - else - { - reset_print(); - _i = 1; - setta_righe("CONTO ECONOMICO"); - _reset_righe_stampa = FALSE; - } - } - } - - set_auto_ff(FALSE); - } - - if (_buff == NULL) - return NEXT_PAGE; - - _sale = 0; - _salerafr = 0; - - return REPEAT_PAGE; -} - -bool CG1600_application::preprocess_page(int file, int counter) -{ - if (_tipo_bilancio == 1) - { - if (preprocess_stampa_scalare(counter)) - return TRUE; - else - return FALSE; - } - else if (_tipo_bilancio == 2) - { - if (preprocess_stampa_verifica(counter)) - return TRUE; - else - return FALSE; - } - - return TRUE; -} - -bool CG1600_application::preprocess_stampa_scalare(int counter) -{ - struct bil_ivd* bil = (struct bil_ivd*) _buff; - int g,c; - long s; - bool fai = TRUE; - TString saldostr,saldo_rafstr; - bool conto_dettagliato = TRUE; - - if (!counter) - { - reset_print(); - _i = 1; - } - - if (_reset_righe_stampa) - { - reset_print(); - _i = 1; - } - else - _reset_righe_stampa = TRUE; - - if (counter) - { - if (!_intera_struttura) - { - if (bil->gruppo[0] != 'Z') - { - _sez_stamp = bil->sez; - _let_stamp = bil->let; - _numr_stamp = bil->numr; - _numr_stamp.ltrim(); - _num_stamp = bil->num; - _num_stamp.ltrim(); - _sez_tot = bil->sez; - _let_tot = bil->let; - _numr_tot = bil->numr; - _numr_tot.ltrim(); - _num_tot = bil->num; - _num_tot.ltrim(); - } - } - else - { - _classe_stampata = format ("%1c%1c%8s%2d",bil->sez,bil->let,(const char*) bil->numr,bil->num); - _sez_stamp = bil->sez; - _let_stamp = bil->let; - _numr_stamp = bil->numr; - _numr_stamp.ltrim(); - _num_stamp = bil->num; - _num_stamp.ltrim(); - _sez_tot = bil->sez; - _let_tot = bil->let; - _numr_tot = bil->numr; - _numr_tot.ltrim(); - _num_tot = bil->num; - _num_tot.ltrim(); - } - } - - _buff = _sort->retrieve(); - - if (_buff == NULL) - { - if (_annoeserafr == 0 && _databilrafr == botime) - stampa_totali(); - else - stampa_totali_con_raffronto(); - _sez_da_stamp = ' '; - _sez_stamp = ' '; - return TRUE; - } - - if (_buff != NULL) - { - bil = (struct bil_ivd*) _buff; - _classe_da_stampare = format ("%1c%1c%8s%2d",bil->sez,bil->let,(const char*) bil->numr,bil->num); - _sez_da_stamp = bil->sez; - _let_da_stamp = bil->let; - _numr_da_stamp = bil->numr; - _numr_da_stamp.ltrim(); - _num_da_stamp = bil->num; - _num_da_stamp.ltrim(); - g = atoi(bil->gruppo); - c = atoi(bil->conto); - s = atol(bil->sottoc); - conto_dettagliato = bil->conto_dettagliato; - - if (_intera_struttura) - fai = TRUE; - else - { - if (bil->gruppo[0] != 'Z') - fai = TRUE; - else - fai = FALSE; - } - - if (counter) - { - if (fai) - if (_annoeserafr == 0 && _databilrafr == botime) - stampa_totali(); - else - stampa_totali_con_raffronto(); - } - - //Fare ricerca di dataregmov - - if (!_intera_struttura) - { - if (bil->gruppo[0]=='Z') - return FALSE; - - _sale = bil->saldo; - if (_annoeserafr != 0 || _databilrafr != botime) - _salerafr = bil->saldorafr; -/*** - if (_stampamov) - { - if (_annoeserafr != 0 || _databilrafr != botime) - { - if ((_sale.is_zero()) && (_salerafr.is_zero())) - return FALSE; - } - else - if (_sale.is_zero()) - return FALSE; - } -***/ - } - else - { - if (bil->gruppo[0]=='Z') -// { - if (_classe_da_stampare == _classe_stampata) -// { -// sprintf (bil->gruppo,"%s", " "); -// sprintf (bil->conto ,"%s", " "); -// sprintf (bil->sottoc,"%s", " "); -// } -// else - return FALSE; -// } - - _sale = bil->saldo; - if (_annoeserafr != 0 || _databilrafr != botime) - _salerafr = bil->saldorafr; -/*** - if (_stampamov) - { - if (_annoeserafr != 0 || _databilrafr != botime) - { - if ((_sale.is_zero()) && (_salerafr.is_zero())) - return FALSE; - } - else - { - if (_sale.is_zero()) - return FALSE; - } - } -***/ - } - - saldostr = _sale.string(); - saldo_rafstr = _salerafr.string(); - - // Faccio passare solo i sottoconti o i conti non dettagliati (che non hanno sottoconti) - // perchè l' importo dei conti dettagliati non è altri che il totale degli importi di - // tutti i suoi sottoconti; dunque se li sommassi anche loro, sommerei l'importo due volte. - // Pero' devo ricordarmi di cambiare ugualmente segno ai conti che vanno dettagliati. - - if (g != 0 && c != 0 && s == 0 && conto_dettagliato) - if (_sez_da_stamp == '9') - { - _sale = -_sale; - if (_annoeserafr != 0 || _databilrafr != botime) - _salerafr = -_salerafr; - } - - - if ((g != 0 && c != 0 && s != 0)||(g != 0 && c != 0 && s == 0 && !conto_dettagliato)) - { - // if (_sez_da_stamp == '5') - // if (_sale < ZERO) - // _sale = -_sale; - - if (_sez_da_stamp == '9') - // if (_sale> ZERO) - _sale = -_sale; - - _totale_numero += _sale; - _totale_numr += _sale; - _totale_lettera += _sale; - if ((_sez_da_stamp == '1')||(_sez_da_stamp == '2')) - { - if (_let_da_stamp != 'Z') - _totale_sezione += _sale; - else - { - if (_sez_da_stamp == '1') - _totale_ordine_attivo += _sale; - else - if (_sez_da_stamp == '2') - _totale_ordine_passivo += _sale; - } - } - - if (_sez_da_stamp == '5') - _totale_ordine += _sale; - - if (_sez_da_stamp == '9') - { - _totale_economico += _sale; - if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) - _totale_parziale += _sale; - } - - if (_annoeserafr != 0 || _databilrafr != botime) - { - //if (_sez_da_stamp == '5') - // if (_salerafr < ZERO) - // _salerafr = -_salerafr; - if (_sez_da_stamp == '9') - //if (_salerafr> ZERO) - _salerafr = -_salerafr; - - _totale_num_raf += _salerafr; - _totale_numr_raf += _salerafr; - _totale_let_raf += _salerafr; - if ((_sez_da_stamp == '1')||(_sez_da_stamp == '2')) - { - if (_let_da_stamp != 'Z') - _totale_sez_raf += _salerafr; - else - { - if (_sez_da_stamp == '1') - _totale_ordine_attivo_raf += _salerafr; - else - if (_sez_da_stamp == '2') - _totale_ordine_passivo_raf += _salerafr; - } - } - - if (_sez_da_stamp == '5') - _totale_ordine_raf += _salerafr; - - if (_sez_da_stamp == '9') - { - _totale_economico_raf += _salerafr; - if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) - _totale_parziale_raf += _salerafr; - } - } - } - return TRUE; - } - else - return FALSE; -} - -bool CG1600_application::preprocess_stampa_verifica(int counter) -{ - struct bil_ivd* bil = (struct bil_ivd*) _buff; - int g,c; - long s; - bool fai = TRUE; - bool conto_dettagliato = TRUE; - - if (!counter) - { - reset_print(); - _i = 1; - } - - if (_reset_righe_stampa) - { - reset_print(); - _i = 1; - } - else - _reset_righe_stampa = TRUE; - - if (counter) - { - if (!_intera_struttura) - { - if (bil->gruppo[0] != 'Z') - { - _sez_stamp = bil->sez; - _let_stamp = bil->let; - _numr_stamp = bil->numr; - _numr_stamp.ltrim(); - _num_stamp = bil->num; - _num_stamp.ltrim(); - _sez_tot = bil->sez; - _let_tot = bil->let; - _numr_tot = bil->numr; - _numr_tot.ltrim(); - _num_tot = bil->num; - _num_tot.ltrim(); - } - } - else - { - _classe_stampata = format ("%1c%1c%8s%2d",bil->sez,bil->let,(const char*) bil->numr,bil->num); - _sez_stamp = bil->sez; - _let_stamp = bil->let; - _numr_stamp = bil->numr; - _numr_stamp.ltrim(); - _num_stamp = bil->num; - _num_stamp.ltrim(); - _sez_tot = bil->sez; - _let_tot = bil->let; - _numr_tot = bil->numr; - _numr_tot.ltrim(); - _num_tot = bil->num; - _num_tot.ltrim(); - } - } - - _buff = _sort->retrieve(); - - if (_buff == NULL) - { - stampa_totali_verifica(); - set_row (_i,"@0g****** ******** TOTALE GENERALE"); - set_row (_i,"@49g%r", &_tot_gen_prg_d); - set_row (_i,"@65g%r", &_tot_gen_prg_a); - set_row (_i,"@82g%r", &_tot_gen_mov_d); - set_row (_i,"@98g%r", &_tot_gen_mov_a); - - if (!_stampa_modulo) - { - if (_tot_gen_saldo < ZERO) - { - _tot_gen_saldo = -_tot_gen_saldo; - _tot_sez_saldo = 'A'; - } - else - _tot_sez_saldo = 'D'; - stampa_saldo_132(_tot_gen_saldo); - } - else - stampa_saldo_198(_tot_gen_saldo_d,_tot_gen_saldo_a); - - _sez_da_stamp = ' '; - _sez_stamp = ' '; - return TRUE; - } - - if (_buff != NULL) - { - bil = (struct bil_ivd*) _buff; - _classe_da_stampare = format ("%1c%1c%8s%2d",bil->sez,bil->let,(const char*) bil->numr,bil->num); - _sez_da_stamp = bil->sez; - _let_da_stamp = bil->let; - _numr_da_stamp = bil->numr; - _numr_da_stamp.ltrim(); - _num_da_stamp = bil->num; - _num_da_stamp.ltrim(); - g = atoi(bil->gruppo); - c = atoi(bil->conto); - s = atol(bil->sottoc); - conto_dettagliato = bil->conto_dettagliato; - - if (_intera_struttura) - fai = TRUE; - else - { - if (bil->gruppo[0] != 'Z') - fai = TRUE; - else - fai = FALSE; - } - - if (counter) - { - if (fai) - stampa_totali_verifica(); - } - - _sale = bil->saldo; - _sld_prg_dare = bil->sld_prg_dare; - _sld_prg_avere = bil->sld_prg_avere; - _mov_dare = bil->mov_dare; - _mov_avere = bil->mov_avere; - - if (!_intera_struttura) - { - if (bil->gruppo[0]=='Z') - return FALSE; - - if (_stampamov) - { - if (_sale.is_zero()) - return FALSE; - } - } - else - { - if (bil->gruppo[0]=='Z') -// { - if (_classe_da_stampare == _classe_stampata) -// { -// sprintf (bil->gruppo,"%s", " "); -// sprintf (bil->conto ,"%s", " "); -// sprintf (bil->sottoc,"%s", " "); -// } -// else - return FALSE; -// } - - if (_stampamov) - { - if (_sale.is_zero()) - return FALSE; - } - } - - if ((g != 0) && (c != 0) && (s == 0) && (conto_dettagliato)) - { - //if (_sld_prg_avere < ZERO) - // _sld_prg_avere = -_sld_prg_avere; - - //if (_mov_avere < ZERO) - // _mov_avere = -_mov_avere; - - if (_sale < ZERO) - { - _sale = -_sale; - _sez_saldo = 'A'; - } - else - _sez_saldo = 'D'; - } - - if ((g != 0 && c != 0 && s != 0)||(g != 0 && c != 0 && s == 0 && !conto_dettagliato)) - { - _tot_num_saldo += _sale; - _tot_numr_saldo += _sale; - _tot_let_saldo += _sale; - _tot_gen_saldo += _sale; - if (_sez_da_stamp == '9') - if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) - _tot_parz_sld += _sale; - - //if (_sld_prg_avere < ZERO) - // _sld_prg_avere = -_sld_prg_avere; - - //if (_mov_avere < ZERO) - // _mov_avere = -_mov_avere; - - if (_sale < ZERO) - { - _sale = -_sale; - _sez_saldo = 'A'; - if (_stampa_modulo) - { - _tot_num_saldo_a += _sale; - _tot_numr_saldo_a += _sale; - _tot_let_saldo_a += _sale; - _tot_gen_saldo_a += _sale; - if (_sez_da_stamp == '9') - if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) - _tot_parz_sld_a += _sale; - } - } - else - { - _sez_saldo = 'D'; - if (_stampa_modulo) - { - _tot_num_saldo_d += _sale; - _tot_numr_saldo_d += _sale; - _tot_let_saldo_d += _sale; - _tot_gen_saldo_d += _sale; - if (_sez_da_stamp == '9') - if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) - _tot_parz_sld_d += _sale; - - } - } - - _tot_num_prg_d += _sld_prg_dare; - _tot_numr_prg_d += _sld_prg_dare; - _tot_let_prg_d += _sld_prg_dare; - _tot_gen_prg_d += _sld_prg_dare; - _tot_num_prg_a += _sld_prg_avere; - _tot_numr_prg_a += _sld_prg_avere; - _tot_let_prg_a += _sld_prg_avere; - _tot_gen_prg_a += _sld_prg_avere; - _tot_num_mov_d += _mov_dare; - _tot_numr_mov_d += _mov_dare; - _tot_let_mov_d += _mov_dare; - _tot_gen_mov_d += _mov_dare; - _tot_num_mov_a += _mov_avere; - _tot_numr_mov_a += _mov_avere; - _tot_let_mov_a += _mov_avere; - _tot_gen_mov_a += _mov_avere; - if (_sez_da_stamp == '9') - if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) - { - _tot_parz_prg_d += _sld_prg_dare; - _tot_parz_prg_a += _sld_prg_avere; - _tot_parz_mov_d += _mov_dare; - _tot_parz_mov_a += _mov_avere; - } - } - return TRUE; - } - else - return FALSE; -} - -void CG1600_application::set_page(int file, int counter) -{ - if (_tipo_bilancio == 1) - { - if (_sez_da_stamp != _sez_stamp) - { - if ((_sez_da_stamp=='1')||((_sez_da_stamp=='2')&&(_statopatr_no_stamp))) - { - setta_righe ("STATO PATRIMONIALE"); - _statopatr_no_stamp = FALSE; - } - if (_sez_da_stamp == '2') - setta_righe(""); - if ((_sez_da_stamp == '5') || (_sez_da_stamp == '9')) - set_auto_ff(TRUE); - } - else - { - if (_buff != NULL) - setta_righe(""); - } - } - else if (_tipo_bilancio == 2) - { - if (_buff != NULL) - setta_righe_verifica(); - } -} - -void CG1600_application::setta_righe(const char * titolo) -{ - struct bil_ivd* bil = (struct bil_ivd*) _buff; - int numeror, numero, gruppo, conto; - char sezione,lettera; - long sottoc; - TString numrom,numr; - TString descr_let,descr_numr,descr_num,descr_sottoc,descr_classe; - bool stampa_classe = TRUE; - TString lettera1 = "@1g)@3g%s"; - TString lettera2 = "@3g%s"; - TString numr1 = "@12g-@14g%s"; - TString numr2 = "@14g%s"; - TString num = "@15g)@18g%s"; - TString num2 = "@18g%s"; - - _descr->set_width(40); - sezione = bil->sez; - lettera = bil->let; - numr = bil->numr; - // numr.ltrim(); - numeror = atoi(bil->numr); - numrom = itor(numeror); - numero = atoi(bil->num); -// num = bil->num; - gruppo = atoi(bil->gruppo); - conto = atoi(bil->conto); - sottoc = atoi(bil->sottoc); - descr_let = descrizione_lettera(sezione,lettera); - descr_numr = descrizione_numeroromano(sezione,lettera,numeror); - descr_num = descrizione_numero(sezione,lettera,numeror,numero); - descr_sottoc = descrizione_sottoconto(gruppo,conto,sottoc); - - //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 (_sez_da_stamp != _sez_stamp) - { - set_row (_i++,"@0g%s", titolo); - char app = ' '; - set_row(_i++,"@0g%c", app); - - if ((_sez_da_stamp == '1')&&(_let_da_stamp == 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i++,"@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++,"@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++,"@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++,"@0gPASSIVO"); - set_row(_i++,"@0g%c", app); - } - - if (stampa_classe) - { - if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp== '9')) - { - //set_row(_i++,"@0g%s", (const char*) _descr_sez); - if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) - { - _cont_let = 1; - _cont_numr = 1; - _cont_num = 1; - _cont_gcs = 0; - } - if (lettera != ' ') - { - set_row(_i,"@0g%c", bil->let); - *_descr = (const char*) descr_let; - setta_righe_descr(_descr,lettera1,lettera2); - //set_row(_i++,"@1g)@3g%s", (const char*) descr_let); - } - if (numrom != "") - { - set_row(_i,"@3g%8s", (const char*) numrom); - *_descr = (const char*) descr_numr; - setta_righe_descr(_descr,numr1,numr2); - //set_row(_i++,"@12g-@14g%s", (const char*) descr_numr); - } - if (numero != 0) - { - set_row(_i,"@13g%s", bil->num); - *_descr = (const char*) descr_num; - setta_righe_descr(_descr,num,num2); - //set_row(_i++,"@15g)@18g%s", (const char*) descr_num); - } - } - } - } - 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++,"@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++,"@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')) - { - set_row(_i,"@0g%c", bil->let); - *_descr = (const char*) descr_let; - setta_righe_descr(_descr,lettera1,lettera2); - //set_row(_i++,"@1g)@3g%s", (const char*) descr_let); - //_cont_let += 1; - if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) - { - _cont_numr = 1; - _cont_num = 1; - _cont_gcs = 0; - } - - if (numrom != "") - { - set_row(_i,"@3g%8s", (const char*) numrom); - *_descr = (const char*) descr_numr; - setta_righe_descr(_descr,numr1,numr2); - //set_row(_i++,"@12g-@14g%s", (const char*) descr_numr); - } - if (numero != 0) - { - set_row(_i,"@13g%s", bil->num); - *_descr = (const char*) descr_num; - setta_righe_descr(_descr,num,num2); - //set_row(_i++,"@15g)@18g%s", (const char*) descr_num); - } - } - } - } - else - if ((_numr_da_stamp!=_numr_stamp)&&(_sez_da_stamp==_sez_stamp)&&(_let_da_stamp==_let_stamp)) - { - if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp=='9')) - { - set_row(_i,"@3g%8s", (const char*) numrom); - *_descr = (const char*) descr_numr; - setta_righe_descr(_descr,numr1,numr2); - //set_row(_i++,"@12g-@14g%s", (const char*) descr_numr); - //_cont_numr += 1; - //_cont_numr = 1; - if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) - { - _cont_num = 1; - _cont_gcs = 0; - } - - if (numero != 0) - { - set_row(_i,"@13g%s", bil->num); - *_descr = (const char*) descr_num; - setta_righe_descr(_descr,num,num2); - //set_row(_i++,"@15g)@18g%s", (const char*) descr_num); - } - } - } - else - if ((_num_da_stamp!=_num_stamp)&&(_sez_da_stamp==_sez_stamp)&&(_let_da_stamp==_let_stamp)&&(_numr_da_stamp==_numr_stamp)) - { - if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp=='9')) - { - set_row(_i,"@13g%s", bil->num); - *_descr = (const char*) descr_num; - setta_righe_descr(_descr,num,num2); - //set_row(_i++,"@15g)@18g%s", (const char*) descr_num); - //_cont_num += 1; - if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) - _cont_gcs = 0; - } - } - if (bil->gruppo[0] != 'A') - { - if (!_stampacod) - { - if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) - { - _cont_gcs += 1; - set_row (_i,"@18g%s", bil->gruppo); - set_row (_i,"@22g%s", bil->conto); - set_row (_i,"@26g%s", bil->sottoc); - set_row (_i,"@33g%s", (const char*) descr_sottoc); - set_row (_i,"@86g%r", &_sale); - if (_annoeserafr != 0 || _databilrafr != botime) - set_row (_i,"@112g%r", &_salerafr); - _i++; - } - } - else - { - if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) - { - _cont_gcs += 1; - if ((sezione != '0')&&(lettera == ' ')&&(numrom == "")&&(numero == 0)) - descr_classe = _descr_sez; - if ((sezione != '0')&&(lettera != ' ')&&(numrom == "")&&(numero == 0)) - descr_classe = descr_let; - if ((sezione != '0')&&(lettera != ' ')&&(numrom != "")&&(numero == 0)) - descr_classe = descr_numr; - if ((sezione != '0')&&(lettera != ' ')&&(numrom != "")&&(numero != 0)) - descr_classe = descr_num; - if (descr_classe != descr_sottoc) - { - set_row (_i,"@20g%s", (const char*) descr_sottoc); - set_row (_i,"@86g%r", &_sale); - if (_annoeserafr != 0 || _databilrafr != botime) - set_row (_i,"@112g%r", &_salerafr); - _i++; - } - } - } - } -} - -void CG1600_application::setta_righe_verifica() -{ - struct bil_ivd* bil = (struct bil_ivd*) _buff; - int numeror, numero, gruppo, conto; - char sezione,lettera,tmcf; - long sottoc; - TString numrom,numr; - TString descr_let,descr_numr,descr_num,descr_sottoc,descr_classe; - TString lettera1 = "@1g)@3g%s"; - TString lettera2 = "@3g%s"; - TString numr1 = "@8g)@10g%s"; - TString numr2 = "@10g%s"; - TString num = "@2g)@4g%s"; - TString num2 = "@4g%s"; - - _descr->set_width(35); - - sezione = bil->sez; - lettera = bil->let; - numr = bil->numr; - numeror = atoi(bil->numr); - numrom = itor(numeror); - numero = atoi(bil->num); -// num = bil->num; - gruppo = atoi(bil->gruppo); - conto = atoi(bil->conto); - sottoc = atoi(bil->sottoc); - tmcf = bil->tipocf; - descr_let = descrizione_lettera(sezione,lettera); - descr_numr = descrizione_numeroromano(sezione,lettera,numeror); - descr_num = descrizione_numero(sezione,lettera,numeror,numero); - if ((tmcf == 'C') || (tmcf == 'F')) - { - if (gruppo != 0 && conto != 0 && sottoc != 0) - { - TConto tc (gruppo,conto,sottoc,tmcf); - descr_sottoc = tc.descrizione(); - } - else - descr_sottoc = descrizione_sottoconto(gruppo,conto,sottoc); - } - else - descr_sottoc = descrizione_sottoconto(gruppo,conto,sottoc); - - //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 (_sez_da_stamp != _sez_stamp) - { - char app = ' '; - set_row (_i,"@0g%c", app); - set_row (_i++,"@48g!@81g!@114g!"); - if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp== '9')) - { - if (_let_da_stamp != 'Z') - { - if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) - { - _cont_let = 1; - _cont_numr = 1; - _cont_num = 1; - _cont_gcs = 0; - } - if (lettera != '\0') - { - set_row(_i,"@0g%c", bil->let); - *_descr = (const char*) descr_let; - setta_righe_descr_verifica(_descr,lettera1,lettera2); - //set_row(_i,"@1g)@3g%s", (const char*) descr_let); - //set_row (_i++,"@48g!@81g!@114g!"); - } - if (numrom != "") - { - set_row(_i,"@0g%8s", (const char*) numrom); - *_descr = (const char*) descr_numr; - setta_righe_descr_verifica(_descr,numr1,numr2); - //set_row(_i,"@8g)@10g%s", (const char*) descr_numr); - //set_row (_i++,"@48g!@81g!@114g!"); - } - if (numero != 0) - { - set_row(_i,"@0g%s", bil->num); - *_descr = (const char*) descr_num; - setta_righe_descr_verifica(_descr,num,num2); - //set_row(_i,"@2g)@4g%s", (const char*) descr_num); - //set_row (_i++,"@48g!@81g!@114g!"); - } - } - } - } - else - if ((_let_da_stamp!=_let_stamp)&&(_sez_da_stamp==_sez_stamp)) - { - char app = ' '; - set_row (_i,"@0g%c", app); - set_row (_i++,"@48g!@81g!@114g!"); - if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp=='9')) - { - if (_let_da_stamp != 'Z') - { - set_row(_i,"@0g%c", bil->let); - *_descr = (const char*) descr_let; - setta_righe_descr_verifica(_descr,lettera1,lettera2); - //set_row(_i,"@1g)@3g%s", (const char*) descr_let); - //set_row (_i++,"@48g!@81g!@114g!"); - //_cont_let += 1; - if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) - { - _cont_numr = 1; - _cont_num = 1; - _cont_gcs = 0; - } - - if (numrom != "") - { - set_row(_i,"@0g%8s", (const char*) numrom); - *_descr = (const char*) descr_numr; - setta_righe_descr_verifica(_descr,numr1,numr2); - //set_row(_i,"@8g)@10g%s", (const char*) descr_numr); - //set_row (_i++,"@48g!@81g!@114g!"); - } - if (numero != 0) - { - set_row(_i,"@0g%s", bil->num); - *_descr = (const char*) descr_num; - setta_righe_descr_verifica(_descr,num,num2); - //set_row(_i,"@2g)@4g%s", (const char*) descr_num); - //set_row (_i++,"@48g!@81g!@114g!"); - } - } - } - } - else - if ((_numr_da_stamp!=_numr_stamp)&&(_sez_da_stamp==_sez_stamp)&&(_let_da_stamp==_let_stamp)) - { - char app = ' '; - set_row (_i,"@0g%c", app); - set_row (_i++,"@48g!@81g!@114g!"); - if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp=='9')) - { - if (_let_da_stamp != 'Z') - { - set_row(_i,"@0g%8s", (const char*) numrom); - *_descr = (const char*) descr_numr; - setta_righe_descr_verifica(_descr,numr1,numr2); - //set_row(_i,"@8g)@10g%s", (const char*) descr_numr); - //set_row (_i++,"@48g!@81g!@114g!"); - //_cont_numr += 1; - //_cont_numr = 1; - if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) - { - _cont_num = 1; - _cont_gcs = 0; - } - - if (numero != 0) - { - set_row(_i,"@0g%s", bil->num); - *_descr = (const char*) descr_num; - setta_righe_descr_verifica(_descr,num,num2); - //set_row(_i,"@2g)@4g%s", (const char*) descr_num); - //set_row (_i++,"@48g!@81g!@114g!"); - } - } - } - } - else - if ((_num_da_stamp!=_num_stamp)&&(_sez_da_stamp==_sez_stamp)&&(_let_da_stamp==_let_stamp)&&(_numr_da_stamp==_numr_stamp)) - { - char app = ' '; - set_row (_i,"@0g%c", app); - set_row (_i++,"@48g!@81g!@114g!"); - if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp=='9')) - { - if (_let_da_stamp != 'Z') - { - set_row(_i,"@0g%s", bil->num); - *_descr = (const char*) descr_num; - setta_righe_descr_verifica(_descr,num,num2); - //set_row(_i,"@2g)@4g%s", (const char*) descr_num); - //set_row (_i++,"@48g!@81g!@114g!"); - _cont_num += 1; - _cont_gcs = 0; - } - } - } - if (bil->gruppo[0] != 'A') - { - if (!_stampacod) - { - if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) - { - _cont_gcs += 1; - set_row (_i,"@0g%s", bil->gruppo); - set_row (_i,"@4g%s", bil->conto); - set_row (_i,"@8g%s", bil->sottoc); - set_row (_i,"@15g%s", (const char*) descr_sottoc); - set_row (_i,"@49g%r", &_sld_prg_dare); - set_row (_i,"@65g%r", &_sld_prg_avere); - set_row (_i,"@82g%r", &_mov_dare); - set_row (_i,"@98g%r", &_mov_avere); - if (_stampa_modulo) - { - if (_sez_saldo == 'D') - { - set_row (_i,"@115g%r", &_sale); - set_row (_i,"@48g!@81g!@114g!@131g!"); - } - else - if (_sez_saldo == 'A') - { - set_row (_i,"@133g%r", &_sale); - set_row (_i,"@48g!@81g!@114g!@131g!"); - } - } - else - { - set_row (_i,"@115g%r", &_sale); - set_row (_i,"@131g%c", _sez_saldo); - set_row (_i,"@48g!@81g!@114g!"); - } - } - } - else - { - if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) - { - _cont_gcs += 1; - if ((sezione != '0')&&(lettera == ' ')&&(numrom == "")&&(numero == 0)) - descr_classe = _descr_sez; - if ((sezione != '0')&&(lettera != ' ')&&(numrom == "")&&(numero == 0)) - descr_classe = descr_let; - if ((sezione != '0')&&(lettera != ' ')&&(numrom != "")&&(numero == 0)) - descr_classe = descr_numr; - if ((sezione != '0')&&(lettera != ' ')&&(numrom != "")&&(numero != 0)) - descr_classe = descr_num; - if (descr_classe != descr_sottoc) - { - set_row (_i,"@2g%s", (const char*) descr_sottoc); - set_row (_i,"@49g%r", &_sld_prg_dare); - set_row (_i,"@66g%r", &_sld_prg_avere); - set_row (_i,"@82g%r", &_mov_dare); - set_row (_i,"@99g%r", &_mov_avere); - if (_stampa_modulo) - { - if (_sez_saldo == 'D') - { - set_row (_i,"@115g%r", &_sale); - set_row (_i,"@48g!@81g!@114g!@131g!"); - } - else - if (_sez_saldo == 'A') - { - set_row (_i,"@133g%r", &_sale); - set_row (_i,"@48g!@81g!@114g!@131g!"); - } - } - else - { - set_row (_i,"@115g%r", &_sale); - set_row (_i,"@131g%c", _sez_saldo); - set_row (_i,"@48g!@81g!@114g!"); - } - } - } - } - } -} - -void CG1600_application::setta_righe_descr(TParagraph_string* str,const TString& formato,const TString& formato2) -{ - const char* r; - int i = 1; - - while ((r = str->get()) != NULL) - { - if (i == 1) - set_row (_i,formato, r); - else - if (i > 1) - set_row (_i,formato2,r); - _i++; - i++; - } -} - -void CG1600_application::setta_righe_descr_verifica(TParagraph_string* str,const TString& formato,const TString& formato2) -{ - const char* r; - int i = 1; - - while ((r = str->get()) != NULL) - { - if (i == 1) - set_row (_i,formato, r); - else - if (i > 1) - set_row (_i,formato2,r); - - set_row (_i,"@48g!@81g!@114g!"); - - _i++; - i++; - } -} - -const char* CG1600_application::descrizione_sezione(char sezione) -{ - TTable tabivd(TAB_IVD); - TString dep, dep2; - - tabivd.zero(); - dep = format("%1c", sezione); - tabivd.put("CODTAB", dep); - tabivd.read(); - dep2 = tabivd.get("CODTAB"); - if (dep == dep2) - tmp = tabivd.get("S0"); - else - tmp = ""; - return (__tmp); -} - -const char* CG1600_application::descrizione_lettera(char sezione, char lettera) -{ - TTable tabivd(TAB_IVD); - TString dep, dep2; - - tabivd.zero(); - dep = format("%1c%1c", sezione, lettera); - tabivd.put("CODTAB", dep); - tabivd.read(); - dep2 = tabivd.get("CODTAB"); - if (dep == dep2) - tmp = tabivd.get("S0"); - else - tmp = ""; - return (__tmp); -} - -const char* CG1600_application::descrizione_numeroromano(char sezione, char lettera, int numr) -{ - TTable tabivd(TAB_IVD); - TString dep, dep2; - - tabivd.zero(); - if (numr != 0) - dep = format("%1c%1c%04d", sezione, lettera, numr); - else - dep = format("%c%c ", sezione, lettera); - - tabivd.put("CODTAB", dep); - tabivd.read(); - dep2 = tabivd.get("CODTAB"); - if (dep == dep2) - tmp = tabivd.get("S0"); - else - tmp = ""; - return (__tmp); -} - -const char* CG1600_application::descrizione_numero(char sezione, char lettera, int numr, int numero) -{ - TTable tabivd(TAB_IVD); - TString dep,dep2; - - tabivd.zero(); - if (numr != 0) - dep = format("%1c%1c%04d%02d",sezione, lettera, numr, numero); - else - dep = format("%c%c %02d",sezione,lettera,numero); - tabivd.put("CODTAB", dep); - tabivd.read(); - dep2 = tabivd.get("CODTAB"); - if (dep == dep2) - tmp = tabivd.get("S0"); - else - tmp = ""; - return (__tmp); -} - -const char* CG1600_application::descrizione_sottoconto(int gruppo, int conto, long sottoc) -{ - TLocalisamfile pconti (LF_PCON); - - pconti.zero(); - pconti.put(PCN_GRUPPO , gruppo); - if (conto != 0) - pconti.put(PCN_CONTO , conto ); - if (sottoc != 0) - pconti.put(PCN_SOTTOCONTO, sottoc); - pconti.read(); - if (pconti.bad()) - pconti.zero(); - tmp = pconti.get(PCN_DESCR); - return (__tmp); -} - -const char* CG1600_application::descr_sottoc_clifo(char tipocf,long s) -{ - TLocalisamfile clifo (LF_CLIFO); - - clifo.zero(); - clifo.put(CLI_TIPOCF,tipocf); - if (s != 0) - clifo.put(CLI_CODCF, s); - clifo.read(); - if (clifo.bad()) - clifo.zero(); - tmp = clifo.get(CLI_RAGSOC); - return (__tmp); -} - -void CG1600_application::preprocess_header() -{ -} - -// Crea l'intestazione per la stampa a 132 e a 198 caratteri - -void CG1600_application::crea_intestazione() -{ - TString datastampastr; - TString sep(132),sep1(147); - - TString app(8); - TLocalisamfile nditte (LF_NDITTE); - TLocalisamfile comuni (LF_COMUNI); - TLocalisamfile unloc (LF_UNLOC); - TLocalisamfile anag (LF_ANAG); - TString codice_ditta,ragsoc,indulc,civulc,capulc,com,prov,comulc; - TString cofi,paiv,tipoa,codanagr; - - reset_header(); - - nditte.setkey(1); - codice_ditta << get_firm(); - nditte.curr().zero(); - nditte.curr().put(NDT_CODDITTA,codice_ditta); - nditte.read(); - app=nditte.curr().get(NDT_CODDITTA); - ragsoc=nditte.curr().get(NDT_RAGSOC); - tipoa =nditte.curr().get(NDT_TIPOA); - codanagr = nditte.get(NDT_CODANAGR); - - unloc.setkey(1); - unloc.curr().zero(); - unloc.curr().put(ULC_CODDITTA,app); - unloc.curr().put(ULC_CODULC,"1"); - unloc.read(); - indulc=unloc.curr().get(ULC_INDULC); - civulc=unloc.curr().get(ULC_CIVULC); - capulc=unloc.curr().get(ULC_CAPULC); - comulc=unloc.curr().get(ULC_COMULC); - - comuni.setkey(1); - comuni.curr().zero(); - comuni.curr().put(COM_COM,comulc); - comuni.read(); - com=comuni.curr().get(COM_DENCOM); - prov=comuni.curr().get(COM_PROVCOM); - - anag.setkey(2); - anag.curr().zero(); - anag.curr().put(ANA_TIPOA,tipoa); - anag.curr().put(ANA_CODANAGR,codanagr); - anag.read(); - cofi=anag.curr().get(ANA_COFI); - paiv=anag.curr().get(ANA_PAIV); - - set_header (1, "@0gDITTA@6g%-5s", (const char*) codice_ditta); - set_header (1, "@12g%-45s", (const char*) ragsoc); - set_header (1, "@59g%-25s", (const char*) indulc); - set_header (1, "@86g%-9s", (const char*) civulc); - set_header (1, "@97g%-5s", (const char*) capulc); - set_header (1, "@103g%-25s", (const char*) com); - set_header (1, "@129g%-3s", (const char*) prov); - - if (_stampa_modulo) - { - sep1 << "Pag. @#"; - sep1.right_just(139); - set_header(2,(const char*) sep1); - } - else - { - sep << "Pag. @#"; - sep.right_just(132); - set_header(2,(const char*) sep); - } - - datastampastr = _datastampa.string(); - - set_header (2,"@0gPartita iva@12g%-11s", (const char*) paiv); - set_header (2,"@30gCodice fiscale@45g%-16s", (const char*) cofi); - if (_stampa_modulo) - set_header (2,"@131gData@136g%s",(const char*) datastampastr); - else - set_header (2,"@105gData@110g%s",(const char*) datastampastr); - - if (_tipo_bilancio == 1) - { - intesta_scalare(); - } - else if (_tipo_bilancio == 2) - { - intesta_verifica(); - } - -} - -void CG1600_application::intesta_verifica_fissa() -{ - TString sep(132),app(32),sep1(147); - - if (_tipo_stampa == 1) - { - if (_dataini == _data_ini_ese) - set_header(5,"@57gSALDO INIZIALE@87gMOVIMENTI DEL PERIODO"); - else if (_dataini > _data_ini_ese) - set_header(5,"@54gPROGRESSIVI PRECEDENTI@87gMOVIMENTI DEL PERIODO"); - } - else if (_tipo_stampa == 2) - set_header(5,"@57gSALDO INIZIALE@87gMOVIMENTI DEL PERIODO"); - - if (_stampa_modulo) - set_header(5,"@129gSALDO"); - - set_header(5,"@48g!@81g!@114g!"); - - if (_stampa_modulo) - { - set_header(5,"@147g!"); - set_header(6,"@131g!@147g!"); - } - - set_header(6,"@48g!@81g!@114g!"); - app = "--------------------------------"; - if (_stampa_modulo) - { - set_header(6,"@49g%s@82g%s@115g%s", (const char*) app, (const char*) app,(const char*) app); - set_header(7,"@1gdescrizione voce@48g!@57gDare@65g!@72gAvere@81g!@90gDare@98g!@105gAvere@114g!@122gDare@131g!@138gAvere@147g!"); - sep1.fill('-'); //Stampa 132 - (sep(132)) - set_header (8, (const char *) sep1); - } - else - { - set_header(6,"@49g%s@82g%s@122gSALDO", (const char*) app, (const char*) app); - set_header(7,"@1gdescrizione voce@48g!@57gDare@65g!@72gAvere@81g!@90gDare@98g!@105gAvere@114g!"); - sep.fill('-'); //Stampa 132 - (sep(132)) - set_header (8, (const char *) sep); - } -} - -void CG1600_application::intesta_scalare() -{ - TString datalimitestr,databilrafrstr; - TString sep(132); - - set_header (3,"@0gSTAMPA BILANCIO CONFORME ALLA IV DIRETTIVA"); - set_header (3,"@89gEsercizio@99g%d", _anno_esercizio); - if (_annoeserafr != 0 || _databilrafr != botime) - { - set_header (3,"@115gEsercizio@125g%d", _anno_esercizio_raf); - databilrafrstr = _databilrafr.string(); - set_header (4,"@112galla data@122g%s", (const char*) databilrafrstr); - } - if (_tipo_stampa == 1) - { - datalimitestr = _datalimite.string(); - set_header (4,"@86galla data@96g%s", (const char*) datalimitestr); - } - else if (_tipo_stampa == 2) - set_header (4,"@90gall' ultima immissione"); - - sep.fill('-'); //Stampa 132 - (sep(132)) - set_header (5, (const char *) sep); -} - -void CG1600_application::intesta_verifica() -{ - TString sep(132),sep1(147); - - set_header (3,"@0gBILANCIO DI VERIFICA IV DIRETTIVA"); - if (_tipo_stampa == 1) - { - TString datainistr = _dataini.string(); - TString datafinestr = _datafine.string(); - set_header (3,"@43gdalla data@54g%s", (const char*) datainistr); - set_header (3,"@65galla data@75g%s", (const char*) datafinestr); - } - else if (_tipo_stampa == 2) - set_header (3,"@42gall' ultima immissione"); - - if (_stampa_modulo) - { - sep1.fill('-'); //Stampa 132 - (sep(132)) - set_header (4, (const char *) sep1); - } - else - { - sep.fill('-'); //Stampa 132 - (sep(132)) - set_header (4, (const char *) sep); - } - intesta_verifica_fissa(); -} - -void CG1600_application::init_sort() -{ - _bil = new bil_ivd; - _sort = new TSort (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),2); - _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); - _sort->init(); -} - -bool CG1600_application::user_create() -{ - _nditte = new TLocalisamfile (LF_NDITTE); - _comuni = new TLocalisamfile (LF_COMUNI); - _unloc = new TLocalisamfile (LF_UNLOC); - _anag = new TLocalisamfile (LF_ANAG); - _pconti = new TLocalisamfile (LF_PCON); - _clifo = new TLocalisamfile (LF_CLIFO); - _saldi = new TLocalisamfile (LF_SALDI); - _descr = new TParagraph_string ("",40); - - _tabivd = new TTable (TAB_IVD); - _tabesc = new TTable (TAB_ESC); - - _anni_es = new Anni_es(); - _sld = new Saldo(); - - _msk = new TMask("cg1600a"); - - return TRUE; -} - -bool CG1600_application::user_destroy() -{ - delete _msk; - - delete _tabivd; - delete _tabesc; - delete _nditte; - delete _comuni; - delete _unloc; - delete _anag; - delete _pconti; - delete _clifo; - delete _saldi; - delete _descr; - delete _anni_es; - delete _sld; - - return TRUE; -} - -int cg1600 (int argc, char* argv[]) -{ - - CG1600_application a; - - a.run(argc, argv, "Stampa Bilancio IV direttiva CEE"); - return 0; -} - - - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cglib.h" +#include "cg1.h" +#include "cg1600.h" + +extern char __tmp [MAXSTR]; +static TFixed_string tmp(__tmp, MAXSTR); + +bool our_handler (TMask_field & f,KEY k); + +class Anno_es : public TObject +{ + TDate _inizio, _fine; + TToken_string *_str; +public: + long anno(); + TDate inizio(); + TDate fine() ; + Anno_es(long anno, TDate& inizio, TDate& fine); + ~Anno_es() { delete _str; } +}; + +TDate Anno_es::inizio() +{ + _inizio = _str->get(1); + return _inizio; +} + +TDate Anno_es::fine() +{ + _fine = _str->get(2); + return _fine; +} + +long Anno_es::anno() +{ + return _str->get_int(0); +} + +Anno_es::Anno_es(long anno, TDate& inizio, TDate& fine) +{ + _str = new TToken_string(35); + _inizio = inizio; + _fine = fine; + _str->add(anno); _str->add(_inizio.string()); _str->add(_fine.string()); +} + +class Anni_es : public TAssoc_array +{ + TTable * _tabesc; +public: + void add(long anno, TDate& inizio, TDate& fine); + void aggiungi_anno(long anno, TDate& inizio, TDate& fine); + Anno_es * trova(long anno, TDate& inizio, TDate& fine); + Anni_es(); + ~Anni_es() { delete _tabesc; } +}; + +Anni_es::Anni_es() +{ + _tabesc = new TTable (TAB_ESC); +} + +void Anni_es::add(long annoe, TDate& in, TDate& fin) +{ + TString key = format("%04ld", annoe); + Anno_es anno(annoe, in, fin); + TAssoc_array::add(key, anno); +} + +Anno_es * Anni_es::trova(long annoe, TDate& in, TDate& fin) +{ + TString key = format("%04ld", annoe); + Anno_es *anno = (Anno_es*) objptr ((const char*) key); + if (anno == NULL) { + in = ""; fin = ""; + } + else { + in = anno->inizio(); + fin = anno->fine(); + } + return anno; +} + +void Anni_es::aggiungi_anno(long annoese, TDate& inizio, TDate& fine) +{ + TString dep; + TString key = format("%04ld", annoese); + Anno_es * anno; + + if (!is_key((const char *) key)) + { + _tabesc->curr().zero(); + dep = format ("%04d",annoese); + _tabesc->curr().put("CODTAB", (const char*) dep); + _tabesc->read(); + if (_tabesc->bad()) + _tabesc->curr().zero(); + inizio = _tabesc->curr().get_date("D0"); + fine = _tabesc->curr().get_date("D1"); + anno = new Anno_es(annoese, inizio, fine); + TAssoc_array::add(key, anno); + } + else + anno = trova (annoese, inizio, fine); +} + +class _riga_sez_opp : public TObject +{ + TToken_string * _str; +public: + int gruppo() { return atoi(_str->get(0)); } + int conto() { return atoi(_str->get(1)); } + int sottoc() { return atoi(_str->get(2)); } + const char * sezione () { return _str->get(3); } + const char * lettera () { return _str->get(4); } + const char * num_rom () { return _str->get(5); } + int numero () { return atoi(_str->get(6)); } + real saldo_conto (); + real saldo_conto_raf(); + void incrementa_saldo(real& nuovo_saldo,real& nuovo_saldo_raf); + _riga_sez_opp(int g, int c, long s, + const char * sezione, const char * lettera, + const char * num_rom, int num, real& saldo, real& saldo_raf); + ~_riga_sez_opp(); +}; + +real _riga_sez_opp::saldo_conto () +{ + real r(_str->get(7)); + return r; +} + +real _riga_sez_opp::saldo_conto_raf () +{ + real r(_str->get(8)); + return r; +} + +void _riga_sez_opp::incrementa_saldo(real& sld,real& sld_raf) +{ + real sld_prec = saldo_conto(); + real sld_prec_raf = saldo_conto_raf(); + sld_prec += sld; + sld_prec_raf += sld_raf; + _str->add(sld_prec.string(), 7); + _str->add(sld_prec_raf.string(), 8); +} + +_riga_sez_opp::_riga_sez_opp(int g, int c, long s, + const char * sezione, const char * lettera, + const char * num_rom, int num, real& saldo, real& saldo_raf) +{ + _str = new TToken_string(30); + _str->add(format("%d",g)); + _str->add(format("%d",c)); + _str->add(format("%ld",s)); + _str->add(sezione); + _str->add(lettera); + _str->add(num_rom); + _str->add(format("%d",num)); + _str->add(saldo.string()); + _str->add(saldo_raf.string()); +} + +_riga_sez_opp::~_riga_sez_opp() +{ + delete _str; +} + +class Righe_sez_opp : public TAssoc_array +{ +public: + _riga_sez_opp* riga() { return (_riga_sez_opp*) get(); } + int gruppo() { return riga()->gruppo(); } + int conto() { return riga()->conto(); } + int sottoc() { return riga()->sottoc(); } + const char * sezione () { return riga()->sezione(); } + const char * lettera () { return riga()->lettera(); } + const char * num_rom () { return riga()->num_rom(); } + int numero () { return riga()->numero(); } + real saldo_conto () { return riga()->saldo_conto(); } + real saldo_conto_raf () { return riga()->saldo_conto_raf(); } + + void add (int g, int c, long s, + const char * sezione, const char * lettera, + const char * num_rom, int num, real saldo, real saldo_raf); +}; + +void Righe_sez_opp::add(int g, int c, long s, + const char * sezione, const char * lettera, + const char * num_rom, int num, real saldo, real saldo_raf) +{ + _riga_sez_opp * riga; + TString key = format("%s%s%s%d",sezione,lettera,num_rom,num); + + if (!is_key((const char *) key)) + { + riga = new _riga_sez_opp (g, c, s, sezione, lettera, num_rom, num, saldo, saldo_raf); + TAssoc_array::add(key,riga); + } + else + { + riga = (_riga_sez_opp*) objptr ((const char*) key); + riga->incrementa_saldo(saldo,saldo_raf); + // add(key,riga,TRUE); + } +} + +int date2esc(const TDate& d, int* prevesc = NULL); + +class CG1600_application : public TPrintapp +{ + friend bool data_limite (TMask_field & f,KEY k); + friend bool tipo_stampa (TMask_field & f,KEY k); + friend bool data_bil_raff (TMask_field & f,KEY k); + friend bool tipo_bilancio (TMask_field & f,KEY k); + friend bool data_inizio (TMask_field & f,KEY k); + friend bool data_fine (TMask_field & f,KEY k); + friend bool anno_esercizio (TMask_field & f,KEY k); + + struct bil_ivd + { + char sez; + char let; + char numr[5]; + char num[4]; + char gruppo[4]; + char conto[4]; + char sottoc[8]; + real saldo; + real saldorafr; + real sld_prg_dare; + real sld_prg_avere; + real mov_dare; + real mov_avere; + char tipocf; + bool conto_dettagliato; + }; + + bil_ivd* _bil; + TMask* _msk; + TTable* _tabesc; + TTable* _tabivd; + TLocalisamfile* _nditte; + TLocalisamfile* _comuni; + TLocalisamfile* _unloc; + TLocalisamfile* _anag; + TLocalisamfile* _pconti; + TLocalisamfile* _clifo; + TLocalisamfile* _saldi; + const char* _buff; + TSort* _sort; + Anni_es* _anni_es; + Righe_sez_opp _sezopps; + TSaldi_list* _listasld; + TProgind* _prog; + TParagraph_string* _descr; + Saldo* _sld; + + TDate _data_fine_ese,_data_fine_ese_prec,_data_fine_raf,_data_fine_raf_prec; + TDate _datastampa,_datalimite,_databilrafr,_datai,_datairaf; + TDate _dataini,_datafine,_data_ini_ese,_data_ini_raf; + int _annoese,_annoeserafr,_anno_esercizio,_anno_esercizio_raf; + bool _competenza,_intera_struttura,_stampamov,_stampacod,_stampa_modulo; + bool _sbilancio_patr_gia_stampato,_attivo_o_passivo; + bool _stampa_mov_prov,_diffprod_fatto,_risimp_fatto; + TString _classe_stampata, _classe_da_stampare,_numr_tot,_num_tot,_numr; + char _sez_da_stamp,_let_da_stamp,_sez_stamp,_let_stamp,_sez_tot,_let_tot,_let,_sez_saldo,_sez,_tot_sez_saldo; + TString _numr_da_stamp,_num_da_stamp,_numr_stamp,_num_stamp,_descr_sez; + int _tipo_bilancio, _tipo_stampa; + int _cont_let,_cont_numr,_cont_num,_cont_gcs,_num; + real _sale,_salerafr,_totale_ordine,_totale_economico; + real _totale_ordine_raf,_totale_economico_raf; + real _totale_numero,_totale_numr,_totale_lettera,_totale_sezione; + real _totale_patrimoniale,_totale_attivita,_totale_passivita; + real _totale_num_raf,_totale_numr_raf,_totale_let_raf,_totale_sez_raf; + real _totale_patrim_raf,_totale_attiv_raf,_totale_passiv_raf; + real _totale_ordine_attivo,_totale_ordine_passivo,_totale_ordine_attivo_raf; + real _totale_ordine_passivo_raf; + real _mov_periodo_dare,_mov_periodo_avere,_prg_prec_dare,_prg_prec_avere,_saldo_ini_dare,_saldo_ini_avere; + real _sld_prg_dare,_sld_prg_avere,_mov_dare,_mov_avere; + real _tot_num_saldo,_tot_numr_saldo,_tot_let_saldo,_tot_gen_saldo; + real _tot_num_prg_d,_tot_numr_prg_d,_tot_let_prg_d,_tot_gen_prg_d; + real _tot_num_prg_a,_tot_numr_prg_a,_tot_let_prg_a,_tot_gen_prg_a; + real _tot_num_mov_d,_tot_numr_mov_d,_tot_let_mov_d,_tot_gen_mov_d; + real _tot_num_mov_a,_tot_numr_mov_a,_tot_let_mov_a,_tot_gen_mov_a; + real _tot_num_saldo_d,_tot_numr_saldo_d,_tot_let_saldo_d,_tot_gen_saldo_d; + real _tot_num_saldo_a,_tot_numr_saldo_a,_tot_let_saldo_a,_tot_gen_saldo_a; + real _totale_parziale,_totale_parziale_raf; + real _tot_parz_sld,_tot_parz_sld_d,_tot_parz_sld_a,_tot_parz_prg_d; + real _tot_parz_prg_a,_tot_parz_mov_d,_tot_parz_mov_a; + int _i; + bool _reset_righe_stampa,_totale_attivita_gia_stampato,_totale_passivita_gia_stampato,_statopatr_no_stamp; + bool _sbilancio_ordine; + TString _causale_ap, _causale_chi; + +public: + + TDate _inizioEs, _fineEs; + + bool menu (MENU_TAG m) { return TPrintapp::menu(m) ; } + virtual bool user_create() ; + virtual bool user_destroy(); + bool set_print(int); + + virtual bool preprocess_page (int,int); + virtual print_action postprocess_page (int,int); + virtual void postclose_print (); + + virtual void preprocess_header(); + virtual void set_page(int,int); + + bool preprocess_stampa_scalare(int); + bool preprocess_stampa_verifica(int); + void crea_intestazione(); + void intesta_scalare(); + void intesta_verifica(); + void intesta_verifica_fissa(); + void init_sort(); + void crea_sort_tabella(); + void crea_sort_piano_conti_scalare(); + void crea_sort_piano_conti_verifica(); + void setta_righe_descr(TParagraph_string*,const TString&,const TString&); + void setta_righe_descr_verifica(TParagraph_string*,const TString&,const TString&); + void scrivi_record(const TString&,const TString&,const TString&,int,int,int,long,const real&,const real&,const real&,const real&,const real&,const real&,char,bool conto_dettagliato = TRUE); + void riempi_record(const TString&,const TString&,const TString&,int,int,int,long,const real&,const real&,const real&,const real&,const real&,const real&,char,bool conto_dettagliato = TRUE); + const char* descrizione_sezione(char); + const char* descrizione_lettera(char, char); + const char* descrizione_numeroromano(char, char, int); + const char* descrizione_numero(char, char, int, int); + const char* descrizione_sottoconto(int, int, long); + const char* descr_sottoc_clifo(char,long); + void setta_righe(const char*); + void setta_righe_verifica(); + void stampa_totali(); + void stampa_totali_con_raffronto(); + void stampa_totali_verifica(); + bool calcola_saldo(real&, real&,int,int,long,int); + bool calcola(int,int,long,const TDate&,const TDate&); + bool sottoc_clifo_scalare (int,int,int,int,real&,real&); + void sottoc_clifo_verifica(int,int,int,char,TString&,TString&,TString&,int,int,bool); + const char* causale_apertura() { return _causale_ap;} + const char* causale_chiusura() { return _causale_chi;} + void stampa_saldo_132(const real&); + void stampa_saldo_198(real&, real&); + void set_bil_key(bil_ivd* b, char sezione, char lettera, + const char* numero_romano, int numero, + bool conti_ordine = TRUE, int conto = 0, + int gruppo = 0, long sottoconto = 0L, char tipocf = ' '); + void set_bil_val(bil_ivd* b, const real& saldo = ZERO, + const real& saldorafr = ZERO, + const real& sld_prg_dare = ZERO, + const real& sld_prg_avere = ZERO, + const real& mov_dare = ZERO, + const real& mov_avere = ZERO,bool conto_dettagliato = TRUE); + CG1600_application() {} +}; + +HIDDEN inline CG1600_application & a() {return (CG1600_application&) main_app(); } + +void CG1600_application::postclose_print() +{ + delete _sort; +} + +void CG1600_application::set_bil_key(bil_ivd* b, char sezione, char lettera, + const char* numero_romano, int numero, + bool conti_ordine, int gruppo, int conto, + long sottoconto, char tipocf) + +{ + b->sez = sezione; + + //Se esiste solamente la sezione,significa che e' un conto d'ordine + //Forzo la lettera della classe a Z, per ottenere, grazie + //all'ordinamento del sort, i record dei conti d'ordine per ultimi + + b->let = (conti_ordine && lettera == '\0' && sezione < '3') ? 'Z' : lettera; + strcpy(b->numr, numero_romano); + sprintf(b->num , "%2d", numero); + if (gruppo < 0) + { + strcpy(b->gruppo, "ZZZ"); + strcpy(b->conto, "ZZZ"); + strcpy(b->sottoc, "ZZZZZZ"); + b->tipocf = ' '; + } + else + if (gruppo == 0) + { + strcpy(b->gruppo, "AAA"); + strcpy(b->conto, "AAA"); + strcpy(b->sottoc, "AAAAAA"); + b->tipocf = ' '; + } + else + { + sprintf(b->gruppo , "%3d", gruppo); + sprintf(b->conto , "%3d", conto); + sprintf(b->sottoc , "%6ld", sottoconto); + b->tipocf = tipocf; + } +} + +void CG1600_application::set_bil_val(bil_ivd* b, const real& saldo, + const real& saldorafr, + const real& sld_prg_dare, + const real& sld_prg_avere, + const real& mov_dare, + const real& mov_avere,bool conto_dettagliato) +{ + b->saldo = saldo; + b->saldorafr = saldorafr; + b->sld_prg_dare = sld_prg_dare; + b->sld_prg_avere = sld_prg_avere; + b->mov_dare = mov_dare; + b->mov_avere = mov_avere; + b->conto_dettagliato = conto_dettagliato; +} + +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 + a()._inizioEs = ia; + a()._fineEs = fa; + const anno = esc.get_int("CODTAB"); + if (d >= ia && d <= fa) + return anno; + if (prevesc) *prevesc = anno; + } + return 0; +} + +bool data_limite (TMask_field& f, KEY key) +{ + if (key == K_ENTER) + { + TMask& m = f.mask(); + int tipobil,tipostampa; + TDate datalim; + TDate in="", fin=""; + // CG1600_application * a = (CG1600_application*) MainApp(); + + tipobil = m.get_int(F_TIPOBIL); + tipostampa = m.get_int(F_TIPOSTAMPA); + int annoese = m.get_int(F_ANNOESE); + + if ((tipobil == 1) && (tipostampa == 1)) + { + datalim = m.get(F_DATALIM); + + if (annoese != 0) + { + a()._anni_es->aggiungi_anno(annoese, in, fin); + a()._data_fine_ese = fin; + a()._data_ini_ese = in; + + a()._anno_esercizio = annoese; + + if (datalim == botime) + a()._datalimite = a()._data_fine_ese; + else + if ((datalim < in)||(datalim > fin)) + { + f.error_box("La data limite non appartiene all' esercizio indicato"); + return FALSE; + } + else + a()._datalimite = datalim; + } + else + if (annoese == 0) + { + if (datalim == botime) + { + f.error_box("La data limite deve essere indicata obbligatoriamente"); + return FALSE; + } + + int anno = date2esc(datalim); + + if (anno == 0) + { + f.error_box("La data limite indicata non appartiene ad alcun esercizio attivo della ditta"); + return FALSE; + } + + a()._data_ini_ese = a()._inizioEs; + a()._data_fine_ese = a()._fineEs; + + a()._datalimite = datalim; + a()._anno_esercizio = anno; + } + } + } + TString data1 = a()._datalimite.string(); + TString data2 = a()._data_ini_ese.string(); + TString data3 = a()._data_fine_ese.string(); + return TRUE; +} + +bool data_bil_raff (TMask_field& f, KEY key) +{ + TMask& m = f.mask(); + int tipobil,tipostampa; + TDate datalim, dataraf; + TDate in = "", fin = "", in_raf = "", fin_raf = ""; + + if (key == K_ENTER) + { + tipobil = atoi(m.get(F_TIPOBIL)); + tipostampa = atoi(m.get(F_TIPOSTAMPA)); + + int annoese = m.get_int(F_ANNOESE); + int annoraf = m.get_int(F_ANNORAFFR); + + if (tipobil == 1) //&& (tipostampa == 1)) + { + dataraf = m.get(F_DATABILRAF); + + datalim = m.get(F_DATALIM); + + if (annoraf == 0) + { + int anno; + + if (datalim != botime) + { + date2esc(datalim); + in = a()._inizioEs; + } + else + a()._anni_es->aggiungi_anno(annoese, in, fin); + + TString instr = in.string(); + if (dataraf != botime) + { + anno = date2esc(dataraf); + in_raf = a()._inizioEs; + fin_raf = a()._fineEs; + a()._anno_esercizio_raf = anno; + } + else + anno == 1; +/**** + if (dataraf == botime) + { + f.error_box("La data bilancio da raffrontare deve essere indicata obbligatoriamente"); + return FALSE; + } + else + { +********/ + if (dataraf > in) + { + f.error_box("La data bilancio da raffrontare non puo' essere maggiore o uguale alla data inizio esercizio in corso"); + return FALSE; + } + + if (anno == 0) + { + f.error_box("La data bilancio da raffrontare indicata non appartiene ad alcun esercizio attivo della ditta"); + return FALSE; + } + + a()._databilrafr = dataraf; + a()._data_ini_raf = in_raf; + a()._data_fine_raf = fin_raf; + //} + } + else + if (annoraf != 0) + { + a()._anni_es->aggiungi_anno(annoraf, in_raf, fin_raf); + a()._data_fine_raf = fin_raf; + a()._data_ini_raf = in_raf; + + if (dataraf == botime) + a()._databilrafr = fin_raf; + + else + if (dataraf < in_raf || dataraf > fin_raf) + { + f.error_box("La data bilancio da raffrontare deve appartenere all' esercizio da raffrontare"); + return FALSE; + } + else + a()._databilrafr = dataraf; + a()._anno_esercizio_raf = annoraf; + } + } + } // IF (key == K_ENTER) + TString data1 = in.string(); + TString data2 = in_raf.string(); + TString data3 = fin_raf.string(); + TString data4 = a()._databilrafr.string(); + TString data5 = a()._data_ini_raf.string(); + TString data6 = a()._data_fine_raf.string(); + return TRUE; +} + +bool anno_ese_raff (TMask_field& f, KEY key) +{ + int annoese, annoraf, anno; + TDate datalim; + + if (key == K_ENTER) + { + annoese = f.mask().get_int(F_ANNOESE); + annoraf = f.mask().get_int(F_ANNORAFFR); + + if (annoraf != 0) + { + if (annoese != 0) + { + if (annoraf >= annoese) + { + f.error_box("L' anno esercizio da raffrontare deve essere inferiore all' anno esercizio in corso"); + return FALSE; + } + } + else + if (annoese == 0) + { + datalim = f.mask().get(F_DATALIM); + + if (datalim != botime) + { + anno = date2esc(datalim); + + if (annoraf >= anno) + { + f.error_box("L' anno esercizio da raffrontare deve essere inferiore all' anno di esercizio di appartenenza della data limite"); + return FALSE; + } + } + } + } + } + return TRUE; +} + +bool tipo_bilancio (TMask_field& f, KEY key) +{ + int tipo_bil, anno; + + if (key == K_SPACE) + { + tipo_bil = f.mask().get_int(F_TIPOBIL); + anno = f.mask().get_int(F_ANNOESE); + if (tipo_bil == 1) + { + f.mask().hide (98); + f.mask().hide (99); + f.mask().hide(96); + f.mask().hide(97); + } + else + if (tipo_bil == 2) + { + if (anno != 0) + { + f.mask().show (96); + f.mask().show (97); + f.mask().hide (98); + f.mask().hide (99); + } + else + if (anno == 0) + { + f.mask().show(98); + f.mask().show(99); + f.mask().hide(96); + f.mask().hide(97); + } + } + } + return TRUE; +} + +bool anno_esercizio (TMask_field& f, KEY key) +{ + int tipo_bil, anno; + + if (key == K_TAB || f.focusdirty()) + { + tipo_bil = f.mask().get_int(F_TIPOBIL); + anno = f.mask().get_int(F_ANNOESE); + if (tipo_bil == 1) + { + f.mask().hide (98); + f.mask().hide (99); + f.mask().hide(96); + f.mask().hide(97); + } + else + if (tipo_bil == 2) + { + if (anno != 0) + { + f.mask().show (96); + f.mask().show (97); + f.mask().hide (98); + f.mask().hide (99); + } + else + if (anno == 0) + { + f.mask().show(98); + f.mask().show(99); + f.mask().hide(96); + f.mask().hide(97); + } + } + } + return TRUE; +} + +bool tipo_stampa(TMask_field& f,KEY k) +{ + int tipo_stampa; + + if (k == K_ENTER) + { + tipo_stampa = f.mask().get_int(F_TIPOSTAMPA); + + int anno = f.mask().get_int(F_ANNOESE); + + if (tipo_stampa == 2) + if (anno == 0) + { + error_box("Nella stampa all' ultima immissione l' anno esercizio e' obbligatorio"); + return FALSE; + } + + } + return TRUE; +} + +bool data_inizio(TMask_field& f, KEY k) +{ + int anno; + TDate data; + TDate in="", fin=""; + + anno = f.mask().get_int(F_ANNOESE); + data = f.mask().get (F_DATAINI); + a()._anno_esercizio = anno; + + if (k == K_ENTER) + { + if (anno != 0) + { + a()._anni_es->aggiungi_anno(anno, in, fin); + a()._data_ini_ese = in; + a()._data_fine_ese = fin; + a()._anno_esercizio = anno; + + if (data == botime) + a()._dataini = in; + else + if (data < in || data > fin) + { + f.error_box("La data non appartiene all' esercizio indicato"); + return FALSE; + } + else + a()._dataini = data; + } + else + if (anno == 0) + { + if (data == botime) + { + f.error_box("La data deve essere obbligatoriamente indicata"); + return FALSE; + } + + int anno = date2esc(data); + + if (anno == 0) + { + f.error_box("La data limite indicata non appartiene ad alcun esercizio attivo della ditta"); + return FALSE; + } + + a()._anno_esercizio = anno; + a()._dataini = data; + } + } + TString datastr = a()._dataini.string(); + TString data1 = a()._data_ini_ese.string(); + TString data2 = a()._data_fine_ese.string(); + return TRUE; +} + +bool data_fine(TMask_field& f, KEY k) +{ + int annoes; + TDate data, data_ini; + TDate in="", fin=""; + + annoes = f.mask().get_int(F_ANNOESE); + data = f.mask().get (F_DATAFINE); + data_ini = f.mask().get (F_DATAINI); + a()._anno_esercizio = annoes; + + if (k == K_ENTER) + { + if (annoes != 0) + { + a()._anni_es->aggiungi_anno(annoes, in, fin); + a()._data_ini_ese = in; + a()._data_fine_ese = fin; + + if (data == botime) + a()._datafine = fin; + else + if (data < in || data > fin) + { + f.error_box("La data non appartiene all' esercizio indicato"); + return FALSE; + } + else + a()._datafine = data; + } + else + if (annoes == 0) + { + if (data == botime) + { + f.error_box("La data deve essere obbligatoriamente indicata"); + return FALSE; + } + + date2esc(data_ini); + TString data3 = a()._inizioEs.string(); + TString data4 = a()._fineEs.string(); + + if (data < a()._inizioEs || data > a()._fineEs) + { + f.error_box("La data non appartiene all' esercizio indicato"); + return FALSE; + } + else + a()._datafine = data; + } + + if (data < data_ini) + { + f.error_box("La data finale non puo' essere inferiore alla data di partenza"); + return FALSE; + } + + + } + TString datastr = a()._datafine.string(); + TString data1 = a()._data_ini_ese.string(); + TString data2 = a()._data_fine_ese.string(); + return TRUE; +} + +void CG1600_application::scrivi_record(const TString& sez, + const TString& let, const TString& numerorom,int numero, + int g,int c,long s,const real& saldo,const real& saldorafr, + const real& sld_dare,const real& sld_avere, + const real& mov_dare,const real& mov_avere,char tipocf,bool conto_dettagliato) +{ + + //Se esiste solamente la sezione,significa che e' un conto d'ordine + //Forzo la lettera della classe a Z, per ottenere, grazie + //all'ordinamento del sort, i record dei conti d'ordine per ultimi + + set_bil_key(_bil, sez[0], let[0], numerorom, numero, TRUE, g, c, s, tipocf); + set_bil_val(_bil, saldo, saldorafr, sld_dare, sld_avere, mov_dare, mov_avere,conto_dettagliato); + _sort->sort ((const char*) _bil); +} + +void CG1600_application::riempi_record(const TString& sez, + const TString& let, const TString& numerorom,int numero, + int g,int c,long s,const real& saldo,const real& saldorafr, + const real& sld_dare,const real& sld_avere, + const real& mov_dare,const real& mov_avere,char tipocf,bool conto_dettagliato) +{ + set_bil_key(_bil, sez[0], let[0], numerorom, numero, FALSE, g, c, s, tipocf); + set_bil_val(_bil, saldo, saldorafr, sld_dare, sld_avere, mov_dare, mov_avere,conto_dettagliato); + _sort->sort ((const char*) _bil); +} + +void CG1600_application::crea_sort_tabella() +{ + TRecnotype recno_prec=0l, recno_curr=0l; + TString codtab_prec; + TTable tabivd(TAB_IVD); + TRecfield codtab_curr(tabivd.curr(),"CODTAB"); + TRecfield sezione (tabivd.curr(),"CODTAB",0,0); + TRecfield lettera (tabivd.curr(),"CODTAB",1,1); + TRecfield numerorom (tabivd.curr(),"CODTAB",2,5); + TRecfield numero (tabivd.curr(),"CODTAB",6,7); + int preclen; + bool FINITO=FALSE; + + tabivd.first(); + codtab_prec = tabivd.get("CODTAB"); + + // Compilo tanti record quante sono le classi IV direttiva trovate sulla + // tabella %IVD, usando dei gruppi, conti e sottoconti fittizi. Successivamente + // nel caso di stampa completa verranno stampati anche questi record; nel caso + // di stampa non completa non verranno stampati. + + do + { + recno_prec = tabivd.recno(); + tabivd.next(); + if (tabivd.eof()) + { + tabivd.zero(); + FINITO=TRUE; + } + recno_curr = tabivd.recno(); + preclen = codtab_prec.len(); + if (!strncmp(codtab_curr,codtab_prec,preclen)) + codtab_prec = (const char *)codtab_curr; + else + { + tabivd.readat(recno_prec); + const char sez = *((const char*) sezione); + const char let = *((const char*) lettera); + TString16 nrom((const char*)numerorom); + const int nu = (int) numero; + + set_bil_key(_bil, sez, let,(const char*)nrom, nu, FALSE,-1); + set_bil_val(_bil); + _sort->sort ((const char*) _bil); + tabivd.readat(recno_curr); + codtab_prec = (const char *)codtab_curr; + } + } while (!FINITO); +} + +// Passo al sort tutti i record presenti su piano dei conti, aventi la classe +// IV direttiva CEE. + +void CG1600_application::crea_sort_piano_conti_scalare() +{ + TLocalisamfile pconti(LF_PCON); + TString sez,let,numerorom; + TString sez_conto,let_conto,numr_conto,sez_opp,let_opp,numr_opp; + int num_conto, indbil; + char sezione,lettera,tmcf; + int numero,g,c,num_opp; + long s; + bool sez_opposta = FALSE; + bool no_sez_opposta = FALSE; + bool classe_conto = FALSE; + bool conto_dettagliato = FALSE; + bool stsottbil; + int gruppo_prec,conto_prec; + real saldo,saldo_raf,saldo_conto,saldo_conto_raf; + real saldo_conto_opp,saldo_conto_raf_opp; + TString saldostr,saldo_rafstr; + c = 0; + num_conto = 0; + tmcf = ' '; + indbil = 0; + + saldo_conto = ZERO; + saldo_conto_raf = ZERO; + saldo_conto_opp = ZERO; + saldo_conto_raf_opp = ZERO; + + gruppo_prec = -1; + conto_prec = -1; + + for (pconti.first(); !pconti.eof(); pconti.next()) + { + _prog->addstatus(1); + g = pconti.get_int (PCN_GRUPPO); + c = pconti.get_int (PCN_CONTO); + s = pconti.get_long(PCN_SOTTOCONTO); + sez = pconti.get(PCN_SEZIVD); + let = pconti.get(PCN_LETTIVD); + sezione = sez[0]; + lettera = let[0]; + numerorom = pconti.get(PCN_NUMRIVD); + numero = pconti.get_int (PCN_NUMIVD); + + saldo = ZERO; + saldo_raf = ZERO; + + //Anche se il conto non e' da dettagliare ma contiene la classe e' da + //mandare ugualmente in stampa con il totale di tutti i suoi sottoconti letti + + if (classe_conto) + { + if (c != conto_prec && conto_prec != -1) + { + if (no_sez_opposta) + { + TString saldo_contostr,saldo_conto_rafstr; + + saldo_contostr = saldo_conto.string(); + saldo_conto_rafstr = saldo_conto_raf.string(); + riempi_record(sez_conto,let_conto,numr_conto,num_conto,gruppo_prec,conto_prec,0,saldo_conto,saldo_conto_raf,ZERO,ZERO,ZERO,ZERO,tmcf,conto_dettagliato); + saldo_conto = ZERO; + saldo_conto_raf = ZERO; + classe_conto = FALSE; + no_sez_opposta = FALSE; + } + if (sez_opposta) + { + int items = _sezopps.items(); + _sezopps.restart(); + for (int i=0; isezione(); + TString let_opp = lriga->lettera(); + TString numr_opp = lriga->num_rom(); + if (numr_opp == " ") //Sembrerebbe che il metodo sezione() quando il numero romano non esiste, ritorni + numr_opp.ltrim(); //una TString contenente uno spazio e non un NULL, sconvolgendo l' ordinamento. + //Per evitare tutto cio' aggiungo il metodo ltrim(), che toglie gli spazi. + //Pero', essendo il numero romano un campo Zerofill, uso ltrim() solo se non c'e'. + int num_opp = lriga->numero(); + real saldo_conto = lriga->saldo_conto(); + real saldo_conto_raf = lriga->saldo_conto_raf(); + riempi_record(sez_opp,let_opp,numr_opp,num_opp,gruppo_prec,conto_prec,0,saldo_conto,saldo_conto_raf,ZERO,ZERO,ZERO,ZERO,tmcf,conto_dettagliato); + } + sez_opposta = FALSE; + + _sezopps.destroy(); + } + } + } + + //Senza questo controllo conto_prec quando viene letto un gruppo verrebbe + //settato a 0 (il conto non c'e'), quindi nella eventuale lettura del conto + //nel ciclo successivo, qualsiasi conto sarebbe diverso da quello precedente. + + if (g != gruppo_prec) + conto_prec = -1; + else + conto_prec = c; + + gruppo_prec = g; + + // Se si tratta di un conto e contiene la classe, allora lo passo al sort. + // Gli eventuali sottoconti avranno la stessa classe. + + if ((g != 0) && (c != 0) && (s == 0)) + { + stsottbil = pconti.get_bool(PCN_STSOTTBIL); + tmcf = pconti.get (PCN_TMCF)[0]; + indbil = pconti.get_int (PCN_INDBIL); + + //Se sono nello stesso gruppo, ma ho un conto diverso da quello precedentemente + //analizzato, e se questi contiene la classe IV dir. CEE, + //allore devo controllare se va dettagliato (STSOTTBIL) + + if (sez != "0") + { + if (!stsottbil || tmcf == 'C' || tmcf == 'F') + conto_dettagliato = FALSE; + else + conto_dettagliato = TRUE; + + sez_conto = sez; + + if (let != "") + let_conto = let; + else + if ((sez == "1")||(sez == "2")) + let_conto = "Z"; + else + let_conto = let; + + numr_conto = numerorom; + num_conto = numero; + classe_conto = TRUE; + + if (tmcf == 'C' || tmcf == 'F') + { + if (sottoc_clifo_scalare(g, c,_anno_esercizio,indbil,saldo_conto,saldo_conto_raf)) + { + if (sez == "2") //Se la sezione e 2 cambio segno comunque + { + //if (saldo_conto < ZERO) + saldo_conto = -saldo_conto; + //if (saldo_conto_raf < ZERO) + saldo_conto_raf = -saldo_conto_raf; + } + no_sez_opposta = TRUE; + } + } + } + else + { + classe_conto = FALSE; // Metto conto dettagliato = TRUE perche' potrebbero esserci dei sottoconti + conto_dettagliato = TRUE; // di questo conto che hanno la classe e quindi vanno stampati. + } + } + + // Se si tratta di un sottoconto e contiene la classe, allora lo passo al sort. + + if ((g != 0) && (c != 0) && (s != 0)) + { + bool rec_es_corr = FALSE; + bool rec_es_prec = FALSE; + + if (!calcola_saldo(saldo,saldo_raf,g,c,s,indbil)) + continue; + + // classe_conto indica se il conto precedentemente letto conteneva + // la classe. In caso affermativo anche questo sottoconto appena + // letto avra' la stessa classe del conto. + + saldostr = saldo.string(); + saldo_rafstr = saldo_raf.string(); + bool stessa_sezione = (saldo * saldo_raf) > ZERO; + + if (classe_conto) + { + sez_opp = pconti.get(PCN_SEZIVDOPP); + if (sez_opp != "0") + { + let_opp = pconti.get(PCN_LETTIVDOPP); + numr_opp = pconti.get(PCN_NUMRIVDOPP); + num_opp = pconti.get_int(PCN_NUMIVDOPP); + + if (sez_conto == "1" && saldo < ZERO)// || (sez_conto == "2" && saldo > ZERO) ) + { + saldo = -saldo; + rec_es_corr = TRUE; + } + if (sez_conto == "1" && saldo_raf < ZERO) //|| (sez_conto == "2" && saldo_raf > ZERO) ) + { + saldo_raf = -saldo_raf; + rec_es_prec = TRUE; + } + if (sez_conto == "2" && saldo > ZERO) + { + rec_es_corr = TRUE; + } + if (sez_conto == "2" && saldo_raf > ZERO) + { + rec_es_prec = TRUE; + } + + if (rec_es_corr && rec_es_prec) + { + if (conto_dettagliato) + { + _sezopps.add(g,c,s,sez_opp,let_opp,numr_opp,num_opp,saldo,saldo_raf); + riempi_record(sez_opp,let_opp,numr_opp,num_opp,g,c,s,saldo,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); + sez_opposta = TRUE; + } + else + sez_opposta = FALSE; + } + else + if (rec_es_corr) + { + if (conto_dettagliato) + { + _sezopps.add(g,c,s,sez_opp,let_opp,numr_opp,num_opp,saldo,ZERO); + riempi_record(sez_opp,let_opp,numr_opp,num_opp,g,c,s,saldo,ZERO,ZERO,ZERO,ZERO,ZERO,tmcf); + if (saldo_raf != ZERO) + { + if (sez_conto == "2") + if (saldo_raf < ZERO) + saldo_raf = -saldo_raf; + + riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,ZERO,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); + //saldo_conto += saldo; + saldo_conto_raf += saldo_raf; + no_sez_opposta = TRUE; + } + sez_opposta = TRUE; + } + else + sez_opposta = FALSE; + } + else + if (rec_es_prec) + { + if (conto_dettagliato) + { + _sezopps.add(g,c,s,sez_opp,let_opp,numr_opp,num_opp,ZERO,saldo_raf); + riempi_record(sez_opp,let_opp,numr_opp,num_opp,g,c,s,ZERO,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); + if (saldo != ZERO) + { + if (sez_conto == "2") + if (saldo < ZERO) + saldo = -saldo; + + riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,saldo,ZERO,ZERO,ZERO,ZERO,ZERO,tmcf); + saldo_conto += saldo; + //saldo_conto_raf += saldo_raf; + no_sez_opposta = TRUE; + } + sez_opposta = TRUE; + } + else + sez_opposta = FALSE; + } + else + { + if (sez_conto == "2") + { + if (saldo < ZERO) + saldo = -saldo; + if (saldo_raf < ZERO) + saldo_raf = -saldo_raf; + } + if (conto_dettagliato) + riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,saldo,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); + + saldo_conto += saldo; + saldo_conto_raf += saldo_raf; + no_sez_opposta = TRUE; + } + } + else + { + if (sez_conto == "2") + { + saldo = -saldo; + saldo_raf = -saldo_raf; + } + if (conto_dettagliato) + riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,saldo,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); + + saldo_conto += saldo; + saldo_conto_raf += saldo_raf; + no_sez_opposta = TRUE; + } + } + else + { + sez_opp = pconti.get(PCN_SEZIVDOPP); + if (sez_opp != "0") + { + let_opp = pconti.get(PCN_LETTIVDOPP); + numr_opp = pconti.get(PCN_NUMRIVDOPP); + num_opp = pconti.get_int(PCN_NUMIVDOPP); + + if (sez == "1" && saldo < ZERO) //|| (sez == "2" && saldo > ZERO) ) + { + saldo = -saldo; + rec_es_corr = TRUE; + } + if (sez == "1" && saldo_raf < ZERO) //|| (sez == "2" && saldo_raf > ZERO) ) + { + saldo_raf = -saldo_raf; + rec_es_prec = TRUE; + } + if (sez == "2" && saldo > ZERO) + { + rec_es_corr = TRUE; + } + if (sez == "2" && saldo_raf > ZERO) + { + rec_es_prec = TRUE; + } + + if (rec_es_corr && rec_es_prec) + riempi_record(sez_opp,let_opp,numr_opp,num_opp,g,c,s,saldo,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); + else + if (rec_es_corr) + { + riempi_record(sez_opp,let_opp,numr_opp,num_opp,g,c,s,saldo,ZERO,ZERO,ZERO,ZERO,ZERO,tmcf); + if (saldo_raf != ZERO) + { + if (sez == "2") + if (saldo_raf < ZERO) + saldo_raf = -saldo_raf; + riempi_record(sez,let,numerorom,numero,g,c,s,ZERO,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); + } + } + else + if (rec_es_prec) + { + riempi_record(sez_opp,let_opp,numr_opp,num_opp,g,c,s,ZERO,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); + if (saldo != ZERO) + { + if (sez == "2") + if (saldo < ZERO) + saldo = -saldo; + riempi_record(sez,let,numerorom,numero,g,c,s,saldo,ZERO,ZERO,ZERO,ZERO,ZERO,tmcf); + } + } + else + if (sez != "0") + { + if (sez == "2") + { + if (saldo < ZERO) + saldo = -saldo; + if (saldo_raf < ZERO) + saldo_raf = -saldo_raf; + } + riempi_record(sez,let,numerorom,numero,g,c,s,saldo,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); + } + } + else + if (sez != "0") + { + if (sez == "2") + { + saldo = -saldo; + saldo_raf = -saldo_raf; + } + riempi_record(sez,let,numerorom,numero,g,c,s,saldo,saldo_raf,ZERO,ZERO,ZERO,ZERO,tmcf); + } + } + } + } + + conto_prec = 0; + + if (classe_conto) + { + if (c != conto_prec && conto_prec != -1) + { + if (no_sez_opposta) + { + riempi_record(sez_conto,let_conto,numr_conto,num_conto,gruppo_prec,c,0,saldo_conto,saldo_conto_raf,ZERO,ZERO,ZERO,ZERO,tmcf,conto_dettagliato); + saldo_conto = ZERO; + saldo_conto_raf = ZERO; + classe_conto = FALSE; + no_sez_opposta = FALSE; + } + if (sez_opposta) + { + int items = _sezopps.items(); + _sezopps.restart(); + for (int i=0; isezione(); + TString let_opp = lriga->lettera(); + TString numr_opp = lriga->num_rom(); + if (numr_opp == " ") + numr_opp.ltrim(); + int num_opp = lriga->numero(); + real saldo_conto = lriga->saldo_conto(); + real saldo_conto_raf = lriga->saldo_conto_raf(); + riempi_record(sez_opp,let_opp,numr_opp,num_opp,gruppo_prec,conto_prec,0,saldo_conto,saldo_conto_raf,ZERO,ZERO,ZERO,ZERO,tmcf,conto_dettagliato); + } + sez_opposta = FALSE; + + _sezopps.destroy(); + } + } + } +} + +void CG1600_application::crea_sort_piano_conti_verifica() +{ + TLocalisamfile pconti(LF_PCON); + TString sez,let,numerorom; + TString sez_conto,let_conto,numr_conto; + int num_conto; + char sezione,lettera,tmcf; + int numero,g,c; + long s; + bool classe_conto = FALSE; + bool conto_dettagliato = FALSE; + bool stsottbil; + int gruppo_prec,conto_prec, indbil; + real saldo,sld_prg_dare,sld_prg_avere,mov_dare,mov_avere; + real saldo_conto,sld_prg_dare_conto,sld_prg_avere_conto,mov_dare_conto,mov_avere_conto; + + _sld->set_annoes(_anno_esercizio); + + saldo_conto = ZERO; + sld_prg_dare_conto = ZERO; + sld_prg_avere_conto = ZERO; + mov_dare_conto = ZERO; + mov_avere_conto = ZERO; + + indbil = 0; + gruppo_prec = -1; + conto_prec = -1; + c = 0; + num_conto = 0; + tmcf = ' '; + + for (pconti.first(); !pconti.eof(); pconti.next()) + { + _prog->addstatus(1); + g = pconti.get_int (PCN_GRUPPO); + c = pconti.get_int (PCN_CONTO); + s = pconti.get_long(PCN_SOTTOCONTO); + sez = pconti.get(PCN_SEZIVD); + let = pconti.get(PCN_LETTIVD); + sezione = sez[0]; + lettera = let[0]; + numerorom = pconti.get(PCN_NUMRIVD); + numero = pconti.get_int (PCN_NUMIVD); + real app; + + saldo = ZERO; + sld_prg_dare = ZERO; + sld_prg_avere = ZERO; + mov_dare = ZERO; + mov_avere = ZERO; + app = ZERO; + + if (classe_conto) + { + if (c != conto_prec && conto_prec != -1) + { + riempi_record(sez_conto,let_conto,numr_conto,num_conto,gruppo_prec,conto_prec,0,saldo_conto,ZERO,sld_prg_dare_conto,sld_prg_avere_conto,mov_dare_conto,mov_avere_conto,tmcf,conto_dettagliato); + saldo_conto = ZERO; + sld_prg_dare_conto = ZERO; + sld_prg_avere_conto = ZERO; + mov_dare_conto = ZERO; + mov_avere_conto = ZERO; + classe_conto = FALSE; + } + } + + //Senza questo controllo conto_prec quando viene letto un gruppo verrebbe + //settato a 0 (il conto non c'e'), quindi nella eventuale lettura del conto + //nel ciclo successivo, qualsiasi conto sarebbe diverso da quello precedente. + + if (g != gruppo_prec) + conto_prec = -1; + else + conto_prec = c; + + gruppo_prec = g; + + // Se si tratta di un conto e contiene la classe, allora lo passo al sort. + // Gli eventuali sottoconti avranno la stessa classe. + + if ((g != 0) && (c != 0) && (s == 0)) + { + stsottbil = pconti.get_bool(PCN_STSOTTBIL); + tmcf = pconti.get(PCN_TMCF)[0]; + indbil = pconti.get_int(PCN_INDBIL); + + //Se sono nello stesso gruppo, ma ho un conto diverso da quello precedentemente + //analizzato , se contiene la classe IV dir. CEE + //allora devo controllare se va dettagliato (STSOTTBIL) + + if (sez != "0") + { + if ((tmcf == 'C') || (tmcf == 'F')) + { + sottoc_clifo_verifica(g, c,_anno_esercizio, tmcf,sez,let,numerorom,numero,indbil,stsottbil); + continue; + } + else + if (!stsottbil) + conto_dettagliato = FALSE; + else + conto_dettagliato = TRUE; + + sez_conto = sez; + + if (let != "") + let_conto = let; + else + if ((sez == "1")||(sez == "2")) + let_conto = "Z"; + else + let_conto = let; + + numr_conto = numerorom; + num_conto = numero; + classe_conto = TRUE; + } + else + { + classe_conto = FALSE; // Metto conto dettagliato = TRUE perche' potrebbero esserci dei sottoconti + conto_dettagliato = TRUE; // di questo conto che hanno la classe e quindi vanno stampati. + } + } + // Se si tratta di un sottoconto e contiene la classe, allora lo passo al sort. + + if ((g != 0) && (c != 0) && (s != 0)) + { + // classe_conto indica se il conto precedentemente letto conteneva la classe, + // ma quest' ultima non era presente a livello di gruppo. In caso affermativo + // anche questo sottoconto appena letto avra' la stessa classe del conto. + + if (_tipo_stampa == 1) + { + if(!calcola(g,c,s,_data_fine_ese,_data_fine_ese_prec)) + continue; + + if (_dataini == _data_ini_ese) + { + sld_prg_dare = _saldo_ini_dare; + sld_prg_avere = _saldo_ini_avere; + mov_dare = _mov_periodo_dare; + mov_avere = _mov_periodo_avere; + saldo = sld_prg_dare-sld_prg_avere+mov_dare-mov_avere; + } + else if (_dataini > _data_ini_ese) + { + sld_prg_dare = _prg_prec_dare; + sld_prg_avere = _prg_prec_avere; + mov_dare = _mov_periodo_dare; + mov_avere = _mov_periodo_avere; + saldo = sld_prg_dare-sld_prg_avere+mov_dare-mov_avere; + } + } + else + if (_tipo_stampa == 2) + { + if (!_sld->ultima_immissione_verifica(_anno_esercizio,g,c,s,indbil)) + continue; + app = _sld->saldoini(); + if (app < ZERO) + { + app = -app; + sld_prg_dare = ZERO; + sld_prg_avere = app; + } + else + { + sld_prg_dare = app; + sld_prg_avere = ZERO; + } + mov_dare = _sld->prgdare(); + mov_avere = _sld->prgavere(); + saldo = sld_prg_dare-sld_prg_avere+mov_dare-mov_avere; + } + + if (classe_conto) + { + if (conto_dettagliato) + riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,saldo,ZERO,sld_prg_dare,sld_prg_avere,mov_dare,mov_avere,tmcf); + + saldo_conto += saldo; + sld_prg_dare_conto += sld_prg_dare; + sld_prg_avere_conto += sld_prg_avere; + mov_dare_conto += mov_dare; + mov_avere_conto += mov_avere; + } + else + { + if (sez != "0") + scrivi_record(sez,let,numerorom,numero,g,c,s,saldo,ZERO,sld_prg_dare,sld_prg_avere,mov_dare,mov_avere,tmcf); + } + } + } + + conto_prec = 0; + + if (classe_conto) + { + if (c != conto_prec && conto_prec != -1) + { + riempi_record(sez_conto,let_conto,numr_conto,num_conto,gruppo_prec,c,0,saldo_conto,ZERO,sld_prg_dare_conto,sld_prg_avere_conto,mov_dare_conto,mov_avere_conto,tmcf,conto_dettagliato); + saldo_conto = ZERO; + sld_prg_dare_conto = ZERO; + sld_prg_avere_conto = ZERO; + mov_dare_conto = ZERO; + mov_avere_conto = ZERO; + classe_conto = FALSE; + } + } +} + + +void CG1600_application::sottoc_clifo_verifica(int g,int c,int anno,char tipocf,TString& sez,TString& let,TString& numerorom,int numero,int indbil,bool stsottbil) +{ + long s; + _listasld = new TSaldi_list (g,c,anno); + real saldo,sld_prg_dare,sld_prg_avere,mov_dare,mov_avere; + real saldo_conto,sld_prg_dare_conto,sld_prg_avere_conto,mov_dare_conto,mov_avere_conto; + real app; + TString sez_conto,let_conto,numr_conto; + int num_conto; + + saldo_conto = ZERO; + sld_prg_dare_conto = ZERO; + sld_prg_avere_conto = ZERO; + mov_dare_conto = ZERO; + mov_avere_conto = ZERO; + + int items = _listasld->items(); + + sez_conto = sez; + + if (let != "") + let_conto = let; + else + if ((sez == "1")||(sez == "2")) + let_conto = "Z"; + else + let_conto = let; + + numr_conto = numerorom; + num_conto = numero; + + _listasld->restart(); + + for (int i=0 ; i < items; i++) + { + const TRectype* r=_listasld->saldi(); + if (r == NULL) break; + + s = r->get_long(SLD_SOTTOCONTO); + + saldo = ZERO; + sld_prg_dare = ZERO; + sld_prg_avere = ZERO; + mov_dare = ZERO; + mov_avere = ZERO; + app = ZERO; + + if (_tipo_stampa == 1) + { + if (!calcola(g,c,s,_data_fine_ese,_data_fine_ese_prec)) + continue; + + if (_dataini == _data_ini_ese) + { + sld_prg_dare = _saldo_ini_dare; + sld_prg_avere = _saldo_ini_avere; + mov_dare = _mov_periodo_dare; + mov_avere = _mov_periodo_avere; + saldo = sld_prg_dare-sld_prg_avere+mov_dare-mov_avere; + } + else if (_dataini > _data_ini_ese) + { + sld_prg_dare = _prg_prec_dare; + sld_prg_avere = _prg_prec_avere; + mov_dare = _mov_periodo_dare; + mov_avere = _mov_periodo_avere; + saldo = sld_prg_dare-sld_prg_avere+mov_dare-mov_avere; + } + } + else + if (_tipo_stampa == 2) + { + if (!_sld->ultima_immissione_bilancio(_anno_esercizio,g,c,s,indbil)) + continue; + app = _sld->saldoini(); + if (app < ZERO) + { + app = -app; + sld_prg_dare = ZERO; + sld_prg_avere = app; + } + else + { + sld_prg_dare = app; + sld_prg_avere = ZERO; + } + mov_dare = _sld->prgdare(); + mov_avere = _sld->prgavere(); + saldo = sld_prg_dare-sld_prg_avere+mov_dare-mov_avere; + } + + if (stsottbil) + riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,saldo,ZERO,sld_prg_dare,sld_prg_avere,mov_dare,mov_avere,tipocf); + saldo_conto += saldo; + sld_prg_dare_conto += sld_prg_dare; + sld_prg_avere_conto += sld_prg_avere; + mov_dare_conto += mov_dare; + mov_avere_conto += mov_avere; + } + if (items > 0) + riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,0,saldo_conto,ZERO,sld_prg_dare_conto,sld_prg_avere_conto,mov_dare_conto,mov_avere_conto,tipocf,stsottbil); + saldo_conto = ZERO; + sld_prg_dare_conto = ZERO; + sld_prg_avere_conto = ZERO; + mov_dare_conto = ZERO; + mov_avere_conto = ZERO; + + delete _listasld; +} + +bool CG1600_application::sottoc_clifo_scalare(int g,int c,int anno,int indbil,real& saldo_conto,real& saldo_conto_raf) +{ + long s; + int aep = 0; + if (anno) aep = anno-1; + _listasld = new TSaldi_list (g,c,anno,aep); + real saldo,saldo_raf; + bool trovato = FALSE; + + int items = _listasld->items(); + + for (int i=0 ; i < items; i++) + { + const TRectype* r=_listasld->saldi(); + if (r == NULL) break; + + s = r->get_long(SLD_SOTTOCONTO); + + saldo = ZERO; + saldo_raf = ZERO; + + if (!calcola_saldo(saldo,saldo_raf,g,c,s,indbil)) + continue; + + saldo_conto += saldo; + saldo_conto_raf += saldo_raf; + trovato = TRUE; + } + delete _listasld; + return trovato; +} + +//La funzione calcola_saldo calcola il saldo dell'esercizio in corso e di +//quello da raffrontare. Inoltre ritorna vero se il sottoconto e' movimentato +//e falso se non e' movimentato, e quindi non deve essere stampato. + +bool CG1600_application::calcola_saldo(real& saldo, real& saldo_raf,int g,int c,long s,int indbil) +{ + bool no_movimentato = TRUE; + bool no_movimentato_raf = TRUE; + bool esiste = FALSE; + TString saldostr,saldo_rafstr; + + _sld->set_annoes(_anno_esercizio); + + if (_tipo_bilancio == 1) + { + if (_tipo_stampa == 1) //bilancio per data limite + { + esiste = _sld->data_limite_bilancio(_tipo_stampa,g,c,s,_datai,_datalimite,indbil,_stampa_mov_prov); + saldo = _sld->saldo(); + + if (!esiste && (!_sld->esiste_saldo() || !_sld->significativo())) + no_movimentato = TRUE; + else + if (!_stampamov) + { + if (saldo == ZERO) + { + if (!_sld->esiste_saldo() || !_sld->significativo()) + no_movimentato = TRUE; + else + no_movimentato = FALSE; + } + else + no_movimentato = FALSE; + } + else + { + if (saldo == ZERO) + no_movimentato = TRUE; + else + no_movimentato = FALSE; + } + } + else if (_tipo_stampa == 2) + { + if (!_sld->ultima_immissione_bilancio(_anno_esercizio,g,c,s,indbil)) + { + if (!_sld->esiste_saldo() || !_sld->significativo()) + no_movimentato = TRUE; + else + no_movimentato = FALSE; + } + else + no_movimentato = FALSE; + + saldo = _sld->saldo(); + } + saldostr = saldo.string(); + + if (_annoeserafr != 0 || _databilrafr != botime) + { + _sld->set_annoes(_anno_esercizio_raf); + + if (_databilrafr != _data_fine_raf) //(_tipo_stampa == 1) bilancio per data limite + { +#ifdef DBG + TString16 datadep (_databilrafr.string()); + TString16 datadep2 (_datairaf.string()); +#endif + esiste = _sld->data_limite_bilancio(DataLimite,g,c,s,_datairaf,_databilrafr,indbil,_stampa_mov_prov); + saldo_raf = _sld->saldo(); + + if (!esiste && (!_sld->esiste_saldo() || !_sld->significativo())) + no_movimentato_raf = TRUE; + else + if (!_stampamov) + { + if (saldo_raf == ZERO) + { + if (!_sld->esiste_saldo() || !_sld->significativo()) + no_movimentato_raf = TRUE; + else + no_movimentato_raf = FALSE; + } + else + no_movimentato_raf = FALSE; + } + else + { + if (saldo_raf == ZERO) + no_movimentato_raf = TRUE; + else + no_movimentato_raf = FALSE; + } + } + else if (_databilrafr == _data_fine_raf) //(_tipo_stampa == 2) + { + if (!_sld->ultima_immissione_bilancio(_anno_esercizio_raf,g,c,s,indbil)) + { + if (!_sld->esiste_saldo() || !_sld->significativo()) + no_movimentato_raf = TRUE; + else + no_movimentato_raf = FALSE; + } + else + no_movimentato_raf = FALSE; + + saldo_raf = _sld->saldo(); + } + saldo_rafstr = saldo_raf.string(); + } + } + + if ((no_movimentato) && (no_movimentato_raf)) + return FALSE; + else + return TRUE; +} + +bool CG1600_application::calcola(int g, int c, long s, + const TDate& fine_es, const TDate& fine_es_prec) +{ + TString sezione; + real importo; + int annoe; + long num_reg; + TDate datareg, datacomp, data; + bool conto_mov = FALSE; + TLocalisamfile rmov(LF_RMOV); + TLocalisamfile mov (LF_MOV); + + _mov_periodo_dare = ZERO; + _mov_periodo_avere = ZERO; + _prg_prec_dare = ZERO; + _prg_prec_avere = ZERO; + _saldo_ini_dare = ZERO; + _saldo_ini_avere = ZERO; + + rmov.setkey(2); + rmov.zero(); + rmov.put(RMV_GRUPPO,g); + if (c != 0) + rmov.put(RMV_CONTO,c); + if (s != 0) + rmov.put(RMV_SOTTOCONTO,s); + TRectype rec(rmov.curr()); + + rmov.read(_isgteq); + for ( ; !rmov.eof(); rmov.next()) + { + if (rmov.curr() != rec) break; + + annoe = rmov.get_int(RMV_ANNOES); + datareg = rmov.get_date(RMV_DATAREG); + num_reg = rmov.get_long(RMV_NUMREG); + sezione = rmov.get(RMV_SEZIONE); + importo = rmov.get_real(RMV_IMPORTO); + + if (importo == ZERO) + continue; + + mov.setkey(1); + mov.zero(); + mov.put(MOV_NUMREG, num_reg); + mov.read(); + if (mov.bad()) mov.zero(); + const bool movprovv = mov.get(MOV_PROVVIS).not_empty(); + datacomp = mov.get_date(MOV_DATACOMP); + + if (!_stampa_mov_prov && movprovv) //se non richiesto + continue; //stampa mov provv. + //li scarto + const TString codcaus(mov.get(MOV_CODCAUS)); + + if (codcaus.not_empty()) + if (codcaus == causale_chiusura()) //la causale e' uguale a quella di chiusura + continue; + + if (_annoese == 0) + data = datareg; + if (_annoese != 0) + data = datacomp; + + //calcolo i movimenti del periodo + if ( (data >= _dataini) && (data <= _datafine) ) + if ((codcaus == causale_apertura() && _data_ini_ese != _dataini) || + (codcaus != causale_apertura())) + { + conto_mov = TRUE; + if (sezione == "D") + _mov_periodo_dare += importo; + else _mov_periodo_avere += importo; + } + + //il saldo inizio es. e' dato dall'importo dare - importo avere di quei movimenti che hanno causale == apertura e data reg >= data inizio es. e <= data limite sup. + + if (_dataini == _data_ini_ese) //calcolo il saldo iniziale + { + if (codcaus == causale_apertura()) + { + if (sezione == "D") + _saldo_ini_dare += importo; + else _saldo_ini_avere += importo; + conto_mov = TRUE; + } + } + else if (_dataini > _data_ini_ese) //calcolo i progressivi precedenti + if ( (data >= _data_ini_ese) && (data < _dataini) ) + { + if (sezione == "D") + _prg_prec_dare += importo; + else _prg_prec_avere += importo; + + conto_mov = TRUE; + } + } + return conto_mov; +} + +bool CG1600_application::set_print(int) +{ + KEY tasto; + +{ + TConfig conf(CONFIG_DITTA); + + _causale_ap = conf.get("CoCaCh"); + _causale_chi = conf.get("CoCaCh"); +} + +_msk->set_handler(F_DATALIM, data_limite); +_msk->set_handler(F_TIPOSTAMPA, tipo_stampa); +_msk->set_handler(F_TIPOBIL, tipo_bilancio); +_msk->set_handler(F_ANNOESE, anno_esercizio); +_msk->set_handler(F_DATAINI, data_inizio); +_msk->set_handler(F_DATAFINE, data_fine); +_msk->set_handler(F_DATABILRAF, data_bil_raff); +_msk->set_handler(F_ANNORAFFR, anno_ese_raff); + +tasto = _msk->run(); + +if (tasto == K_ENTER) +{ + _datastampa = (_msk->get(F_DATASTAMPA)); + _annoese = _msk->get_int(F_ANNOESE); + _annoeserafr = _msk->get_int(F_ANNORAFFR); + _intera_struttura = (bool)(_msk->get(F_STAMPAINT) == "X"); + _stampamov = (bool)(_msk->get(F_STAMPAMOV) == "X"); + _stampacod = (bool)(_msk->get(F_STAMPACOD) == "X"); + _stampa_modulo = (bool)(_msk->get(F_STAMPAMODULO) == "X"); + _tipo_bilancio = atoi(_msk->get(F_TIPOBIL)); + _stampa_mov_prov = (bool)(_msk->get(F_STAMPAMOVPROV) == "X"); + if (_tipo_bilancio == 1) + { + _tipo_stampa = atoi(_msk->get(F_TIPOSTAMPA)); + _prog = new TProgind(_pconti->items(),"Elaborazione in corso... prego attendere",FALSE); + } + else if (_tipo_bilancio == 2) + { + _tipo_stampa = atoi(_msk->get(F_TIPOSTAMPA1)); + _prog = new TProgind(_pconti->items(),"Elaborazione in corso... prego attendere",FALSE); + } + + _cont_let = 0; + _cont_numr = 0; + _cont_num = 0; + _cont_gcs = 0; + _reset_righe_stampa = TRUE; + + set_real_picture("###.###.###.###"); +// if (_stampamov) +// set_print_zero(FALSE); +// else + set_print_zero(TRUE); + + _totale_attivita_gia_stampato = FALSE; + _totale_passivita_gia_stampato = FALSE; + _statopatr_no_stamp = TRUE; + _diffprod_fatto = TRUE; + _risimp_fatto = TRUE; + _sbilancio_ordine = FALSE; + _sbilancio_patr_gia_stampato = FALSE; + _attivo_o_passivo = FALSE; + + _sez_stamp = ' '; + _let_stamp = ' '; + _numr_stamp = ""; + _num_stamp = ""; + _sez_tot = ' '; + _let_tot = ' '; + _numr_tot = ""; + _num_tot = ""; + + _sale = _salerafr = _totale_ordine = _totale_economico = ZERO; + _totale_ordine_raf = _totale_economico_raf = _totale_numero = ZERO; + _totale_numr = _totale_lettera = _totale_sezione = ZERO; + _totale_patrimoniale = _totale_attivita = _totale_passivita = ZERO; + _totale_num_raf = _totale_numr_raf = _totale_let_raf = ZERO; + _totale_sez_raf = _totale_patrim_raf = _totale_attiv_raf = ZERO; + _totale_passiv_raf = _totale_ordine_attivo = _totale_ordine_passivo = ZERO; + _totale_ordine_attivo_raf = _totale_ordine_passivo_raf = ZERO; + _mov_periodo_dare = _mov_periodo_avere = _prg_prec_dare = ZERO; + _prg_prec_avere = _saldo_ini_dare = _saldo_ini_avere = ZERO; + _sld_prg_dare = _sld_prg_avere = _mov_dare = _mov_avere = ZERO; + _tot_num_saldo = _tot_numr_saldo = _tot_let_saldo = _tot_gen_saldo = ZERO; + _tot_num_prg_d = _tot_numr_prg_d = _tot_let_prg_d = _tot_gen_prg_d = ZERO; + _tot_num_prg_a = _tot_numr_prg_a = _tot_let_prg_a = _tot_gen_prg_a = ZERO; + _tot_num_mov_d = _tot_numr_mov_d = _tot_let_mov_d = _tot_gen_mov_d = ZERO; + _tot_num_mov_a = _tot_numr_mov_a = _tot_let_mov_a = _tot_gen_mov_a = ZERO; + _tot_num_saldo_d = _tot_numr_saldo_d = _tot_let_saldo_d = ZERO; + _tot_gen_saldo_d = _tot_num_saldo_a = _tot_numr_saldo_a = ZERO; + _tot_let_saldo_a = _tot_gen_saldo_a = _totale_parziale = ZERO; + _totale_parziale_raf = _tot_parz_sld = _tot_parz_sld_d = ZERO; + _tot_parz_sld_a = _tot_parz_prg_d = _tot_parz_prg_a = ZERO; + _tot_parz_mov_d = _tot_parz_mov_a = ZERO; + + _datai = _data_ini_ese; + _datairaf = _data_ini_raf; + TString data1 = _data_ini_ese.string(); + TString data2 = _data_ini_raf.string(); + +// Se si tratta di stampa intera struttura allora passo al sort anche tutte +// le classi presenti sulla tabella IV dir. CEE, altrimenti passo solamente +// le classi associate ai conti/sottoconti del Piano dei conti. + + init_sort(); + if (_intera_struttura) + crea_sort_tabella(); + if (_tipo_bilancio == 1) + crea_sort_piano_conti_scalare(); + else if (_tipo_bilancio == 2) + crea_sort_piano_conti_verifica(); + _sort->endsort(); + + + crea_intestazione(); + delete _bil; + delete _prog; + return TRUE; +} +return FALSE; +} + +void CG1600_application::stampa_totali() +{ + bool gia_stampato_conto_ord = FALSE; + TString16 diff_prod; + TString16 ris_imp; + + diff_prod.format("%c%c",'9','B'); + ris_imp.format ("%c%c%8s%2s",'9','E',"","21"); + + TString16 classe; + classe.format("%c%c%8s%2s", _sez_da_stamp,_let_da_stamp,(const char*)_numr_da_stamp,(const char*)_num_da_stamp); + + _num = atoi(_num_tot); + _numr = _numr_tot; + _let = _let_tot; + + if (_buff == NULL) + { + _num_tot = ""; + _numr_tot = ""; + _let_tot = ' '; + _sez_tot = ' '; + } + + if ((_sez_stamp == '1' || _sez_stamp == '2') && _let_stamp != 'Z') + _attivo_o_passivo = TRUE; + + if (_num_da_stamp!=_num_tot) + { + if (_let_stamp != 'Z') + { + if (_sez_stamp != '5') + if (_cont_gcs != 0)//(_cont_gcs >= 2) + { + //Fai il totale del numero arabo e stampalo + if (_num != 0) + { + set_row (_i,"@18gTotale@25g%2d@27g)", _num); + set_row (_i++,"@86g%r", &_totale_numero); + } + } + } + if (_sez_stamp == '9') + { + if (classe > ris_imp && _risimp_fatto) + { + if (_num_tot == "20" || _num_tot == "21") + { + set_row (_i,"@4gTotale delle partite straordinarie"); + set_row (_i++,"@86g%r", &_totale_parziale); + set_row (_i,"@4gRisultato prima delle imposte"); + set_row (_i++,"@86g%r", &_totale_economico); + _risimp_fatto = FALSE; + } + } + } + + _cont_gcs = 0; + _totale_numero = 0; + } + if (_numr_da_stamp!=_numr_tot) + { + if (_let_stamp != 'Z') + { + if (_sez_stamp != '5') + { + if (_cont_gcs != 0)//(_cont_gcs >= 2) + { + //Fai il totale del numero arabo e stampalo + if (_num != 0) + { + set_row (_i,"@18gTotale@25g%2d@27g)", _num); + set_row (_i++,"@86g%r", &_totale_numero); + } + } + if (_cont_num != 0)//(_cont_num >= 2) + { + //Fai il totale del numero romano e stampalo + int numeror = atoi(_numr); + TString numrom = itor(numeror); + if (numrom != "") + { + set_row (_i,"@14gTotale@21g%s", (const char*) numrom); + set_row (_i++,"@86g%r", &_totale_numr); + } + } + } + } + _cont_gcs = 0; + _cont_num = 0; + _totale_numero = 0; + _totale_numr = 0; + } + if (_let_da_stamp!=_let_tot) + { + if (_sez_stamp == '9') + { + TString16 classe; + + classe.format("%c%c%8s%2s",_sez_stamp,_let_stamp,(const char*)_numr_stamp,(const char*)_num_stamp); + + if (_cont_gcs != 0)//(_cont_gcs >= 2) + { + //Fai il totale del numero arabo e stampalo + if (_num != 0) + { + set_row (_i,"@18gTotale@25g%2d@27g)", _num); + set_row (_i++,"@86g%r", &_totale_numero); + } + } + if (_cont_num != 0)//(_cont_num >= 2) + { + //Fai il totale del numero romano e stampalo + int numeror = atoi(_numr); + TString numrom = itor(numeror); + if (numrom != "") + { + set_row (_i,"@14gTotale@21g%s", (const char*) numrom); + set_row (_i++,"@86g%r", &_totale_numr); + } + } + if (_cont_numr != 0)//(_cont_numr >= 2) + { + //Fai il totale della lettera e stampalo + if (_let_stamp == 'D') + set_row (_i,"@4gTotale delle rettifiche"); + else + if (_let != ' ') + if (_sez_stamp == '9' && _let_stamp != 'E') + set_row (_i,"@3gTotale@10g%c@12g)", _let); + else + if (_sez_stamp != '9') + set_row (_i,"@3gTotale@10g%c@12g)", _let); + if (_let != ' ') + { + if (_sez_stamp == '9' && _let_stamp != 'E') + set_row (_i++,"@86g%r", &_totale_lettera); + else + if (_sez_stamp != '9') + set_row (_i++,"@86g%r", &_totale_lettera); + } + } + + if (classe > diff_prod && _diffprod_fatto) + { + if (_let_tot == 'A' || _let_tot == 'B') //Solo se esiste una delle due lettere + { + set_row (_i++,"@4gDifferenza tra valore e costi della produzione@86g%r", &_totale_economico); + _diffprod_fatto = FALSE; + } + } + } + else + { + if (_let_stamp != 'Z') + { + if (_sez_stamp != '5') + { + if (_cont_gcs != 0)//(_cont_gcs >= 2) + { + //Fai il totale del numero arabo e stampalo + if (_num != 0) + { + set_row (_i,"@18gTotale@25g%2d@27g)", _num); + set_row (_i++,"@86g%r", &_totale_numero); + } + } + if (_cont_num != 0)//(_cont_num >= 2) + { + //Fai il totale del numero romano e stampalo + int numeror = atoi(_numr); + TString numrom = itor(numeror); + if (numrom != "") + { + set_row (_i,"@14gTotale@21g%s", (const char*) numrom); + set_row (_i++,"@86g%r", &_totale_numr); + } + } + if (_cont_numr != 0)//(_cont_numr >= 2) + { + //Fai il totale della lettera e stampalo + if (_let != ' ') + { + set_row (_i,"@3gTotale@10g%c@12g)", _let); + set_row (_i++,"@86g%r", &_totale_lettera); + } + } + } + } + + if ((_sez_stamp == '1')&&(_let_da_stamp == 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE ATTIVO"); + set_row (_i++,"@86g%r", &_totale_sezione); + _totale_attivita = _totale_sezione; + _totale_sezione = ZERO; + _totale_attivita_gia_stampato = TRUE; + } + + if ((_sez_stamp == '2')&&(_let_da_stamp == 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE PASSIVO"); + set_row (_i++,"@86g%r", &_totale_sezione); + _totale_passivita = _totale_sezione; + _totale_sezione = ZERO; + _totale_passivita_gia_stampato = TRUE; + } + + if ((_sez_stamp == '1')&&(_let_stamp == 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE CONTI D' ORDINE ATTIVI"); + set_row (_i++,"@86g%r", &_totale_ordine_attivo); +// _totale_ordine_attivo = ZERO; + gia_stampato_conto_ord = TRUE; + } + + if ((_sez_stamp == '2')&&(_let_stamp == 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE CONTI D' ORDINE PASSIVI"); + set_row (_i++,"@86g%r", &_totale_ordine_passivo); + _i++; + + if (!_attivo_o_passivo) + { + real totale = _totale_ordine_attivo - _totale_ordine_passivo; + if (totale != ZERO) + { + set_row (_i++,"@0gSALDO CONTI D' ORDINE"); + set_row (_i,"@0gSBILANCIO"); + set_row (_i++,"@86g%r", &totale); + } + _totale_ordine_attivo = ZERO; + _totale_ordine_passivo = ZERO; + _sbilancio_ordine = TRUE; + } + gia_stampato_conto_ord = TRUE; + } + } + _cont_gcs = 0; + _cont_num = 0; + _cont_numr = 0; + _totale_numero = 0; + _totale_numr = 0; + _totale_lettera = 0; + } + if (_sez_da_stamp != _sez_tot) + { + if (_let_stamp != 'Z') + { + if (_sez_stamp != '5') + { + if (_cont_gcs != 0)//(_cont_gcs >= 2) + { + //Fai il totale del numero arabo e stampalo + if (_num != 0) + { + set_row (_i,"@18gTotale@25g%2d@27g)", _num); + set_row (_i++,"@86g%r", &_totale_numero); + } + } + if (_cont_num != 0)//(_cont_num >= 2) + { + //Fai il totale del numero romano e stampalo + int numeror = atoi(_numr); + TString numrom = itor(numeror); + if (numrom != "") + { + set_row (_i,"@14gTotale@21g%s", (const char*) numrom); + set_row (_i++,"@86g%r", &_totale_numr); + } + } + if (_cont_numr != 0)//(_cont_numr >= 2) + { + //Fai il totale della lettera e stampalo + if (_let != ' ') + { + if (_sez_stamp == '9' && _let_stamp != 'E') + { + set_row (_i,"@3gTotale@10g%c@12g)", _let); + set_row (_i++,"@86g%r", &_totale_lettera); + } + else + if (_sez_stamp != '9') + { + set_row (_i,"@3gTotale@10g%c@12g)", _let); + set_row (_i++,"@86g%r", &_totale_lettera); + } + } + } + } + } + + if (!_totale_attivita_gia_stampato) + if ((_sez_stamp == '1') && (_let_stamp != 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE ATTIVO"); + set_row (_i++,"@86g%r", &_totale_sezione); + _totale_attivita = _totale_sezione; + _totale_sezione = ZERO; + } + + if (!_totale_passivita_gia_stampato) + if ((_sez_stamp == '2') && (_let_stamp != 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE PASSIVO"); + set_row (_i++,"@86g%r", &_totale_sezione); + _totale_passivita = _totale_sezione; + _totale_sezione = ZERO; + } + + if (!gia_stampato_conto_ord) + { + if (_sez_stamp == '2') + { + if (!_sbilancio_patr_gia_stampato) + { + _totale_patrimoniale = _totale_attivita - _totale_passivita; + if (_totale_patrimoniale != ZERO) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i++,"@0gSALDO STATO PATRIMONIALE"); + set_row (_i,"@0gSBILANCIO (ATTIVO - PASSIVO)"); + //_totale_patrimoniale = _totale_attivita - _totale_passivita; + set_row (_i++,"@86g%r", &_totale_patrimoniale); + _totale_patrimoniale = ZERO; + } + _sbilancio_patr_gia_stampato = TRUE; + } + } + if ((_sez_stamp == '1')&&(_let_stamp == 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE CONTI D' ORDINE ATTIVI"); + set_row (_i++,"@86g%r", &_totale_ordine_attivo); + // _totale_ordine_attivo = ZERO; + } + if ((_sez_stamp == '2')&&(_let_stamp == 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE CONTI D' ORDINE PASSIVI"); + set_row (_i++,"@86g%r", &_totale_ordine_passivo); + _i++; + if (!_sbilancio_ordine) + { + real totale = _totale_ordine_attivo - _totale_ordine_passivo; + if (totale != ZERO) + { + set_row (_i++,"@0g%c", app); + set_row (_i++,"@0gSALDO CONTI D' ORDINE"); + set_row (_i,"@0gSBILANCIO"); + set_row (_i++,"@86g%r", &totale); + _sbilancio_ordine = TRUE; + } + _totale_ordine_passivo = ZERO; + _totale_ordine_attivo = ZERO; + } + } + } + + if (_sez_stamp == '2') + { + char app = ' '; + + if (!_sbilancio_patr_gia_stampato) + { + _totale_patrimoniale = _totale_attivita - _totale_passivita; + if (_totale_patrimoniale != ZERO) + { + set_row (_i++,"@0g%c", app); + set_row (_i++,"@0gSALDO STATO PATRIMONIALE"); + set_row (_i,"@0gSBILANCIO (ATTIVO - PASSIVO)"); + //_totale_patrimoniale = _totale_attivita - _totale_passivita; + set_row (_i++,"@86g%r", &_totale_patrimoniale); + _totale_patrimoniale = ZERO; + } + } + if (!_sbilancio_ordine) + { + real totale = _totale_ordine_attivo - _totale_ordine_passivo; + if (totale != ZERO && !_sbilancio_ordine) + { + set_row (_i++,"@0g%c", app); + set_row (_i++,"@0gSALDO CONTI D' ORDINE"); + set_row (_i,"@0gSBILANCIO"); + set_row (_i++,"@86g%r", &totale); + } + } + } + if (_sez_stamp == '5') + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE CONTI D' ORDINE"); + set_row (_i++,"@86g%r", &_totale_ordine); + _totale_ordine = ZERO; + } + if (_sez_stamp == '9') + { + if (_buff == NULL) + { + if ((_let_stamp == 'A' || _let_stamp == 'B') && _diffprod_fatto)//Solo se esiste una delle due lettere + { + set_row (_i++,"@4gDifferenza tra valore e costi della produzione@86g%r", &_totale_economico); + _diffprod_fatto = FALSE; + } + if (_risimp_fatto) + { + if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) + { + set_row (_i,"@4gTotale delle partite straordinarie"); + set_row (_i++,"@86g%r", &_totale_parziale); + set_row (_i,"@4gRisultato prima delle imposte"); + set_row (_i++,"@86g%r", &_totale_economico); + _risimp_fatto = FALSE; + } + } + } + + char app = ' '; + set_row (_i++,"@0g%c", app); + if (_totale_economico != ZERO) + { + set_row (_i,"@0gRISULTATO CONTO ECONOMICO"); + set_row (_i++,"@86g%r", &_totale_economico); + _totale_economico = ZERO; + } + } + _cont_gcs = 0; + _cont_num = 0; + _cont_numr = 0; + _cont_let = 0; + _totale_numero = 0; + _totale_numr = 0; + _totale_lettera = 0; + } +} + +void CG1600_application::stampa_totali_con_raffronto() +{ + bool gia_stampato_conto_ord = FALSE; + TString16 diff_prod; + TString16 ris_imp; + + diff_prod.format("%c%c",'9','B'); + ris_imp.format ("%c%c%8s%2s",'9','E',"","21"); + + TString16 classe; + classe.format("%c%c%8s%2s", _sez_da_stamp,_let_da_stamp,(const char*)_numr_da_stamp,(const char*)_num_da_stamp); + + _num = atoi(_num_tot); + _numr = _numr_tot; + _let = _let_tot; + + if (_buff == NULL) + { + _num_tot = ""; + _numr_tot = ""; + _let_tot = ' '; + _sez_tot = ' '; + } + + if ((_sez_stamp == '1' || _sez_stamp == '2') && _let_stamp != 'Z') + _attivo_o_passivo = TRUE; + + if (_num_da_stamp!=_num_tot) + { + + if (_let_stamp != 'Z') + { + if (_sez_stamp != '5') + if (_cont_gcs != 0)//(_cont_gcs >= 2) + { + //Fai il totale del numero arabo e stampalo + if (_num != 0) + { + set_row (_i,"@18gTotale@25g%2d@27g)", _num); + set_row (_i,"@86g%r", &_totale_numero); + set_row (_i++,"@112g%r", &_totale_num_raf); + } + } + } + if (_sez_stamp == '9') + { + if (classe > ris_imp && _risimp_fatto) + { + if (_num_tot == "20" || _num_tot == "21") + { + set_row (_i,"@4gTotale delle partite straordinarie"); + set_row (_i,"@86g%r", &_totale_parziale); + set_row (_i++,"@112g%r", &_totale_parziale_raf); + set_row (_i,"@4gRisultato prima delle imposte"); + set_row (_i,"@86g%r", &_totale_economico); + set_row (_i++,"@112g%r", &_totale_economico_raf); + _risimp_fatto = FALSE; + } + } + } + _cont_gcs = 0; + _totale_numero = 0; + _totale_num_raf = 0; + } + if (_numr_da_stamp!=_numr_tot) + { + if (_let_stamp != 'Z') + { + if (_sez_stamp != '5') + { + if (_cont_gcs != 0)//(_cont_gcs >= 2) + { + //Fai il totale del numero arabo e stampalo + if (_num != 0) + { + set_row (_i,"@18gTotale@25g%2d@27g)", _num); + set_row (_i,"@86g%r", &_totale_numero); + set_row (_i++,"@112g%r", &_totale_num_raf); + } + } + if (_cont_num != 0)//(_cont_num >= 2) + { + //Fai il totale del numero romano e stampalo + int numeror = atoi(_numr); + TString numrom = itor(numeror); + if (numrom != "") + { + set_row (_i,"@14gTotale@21g%s", (const char*) numrom); + set_row (_i,"@86g%r", &_totale_numr); + set_row (_i++,"@112g%r", &_totale_numr_raf); + } + } + } + } + _cont_gcs = 0; + _cont_num = 0; + _totale_numero = 0; + _totale_numr = 0; + _totale_num_raf = 0; + _totale_numr_raf = 0; + } + if (_let_da_stamp!=_let_tot) + { + if (_sez_stamp == '9') + { + TString16 classe; + + classe.format("%c%c%8s%2s",_sez_stamp,_let_stamp,(const char*)_numr_stamp,(const char*)_num_stamp); + + if (_cont_gcs != 0)//(_cont_gcs >= 2) + { + //Fai il totale del numero arabo e stampalo + if (_num != 0) + { + set_row (_i,"@18gTotale@25g%2d@27g)", _num); + set_row (_i++,"@86g%r", &_totale_numero); + } + } + if (_cont_num != 0)//(_cont_num >= 2) + { + //Fai il totale del numero romano e stampalo + int numeror = atoi(_numr); + TString numrom = itor(numeror); + if (numrom != "") + { + set_row (_i,"@14gTotale@21g%s", (const char*) numrom); + set_row (_i++,"@86g%r", &_totale_numr); + } + } + if (_cont_numr != 0)//(_cont_numr >= 2) + { + //Fai il totale della lettera e stampalo + if (_let_stamp == 'D') + set_row (_i,"@4gTotale delle rettifiche"); + else + if (_let != ' ') + if (_sez_stamp == '9' && _let_stamp != 'E') + set_row (_i,"@3gTotale@10g%c@12g)", _let); + else + if (_sez_stamp != '9') + set_row (_i,"@3gTotale@10g%c@12g)", _let); + if (_let != ' ') + { + if (_sez_stamp == '9' && _let_stamp != 'E') + { + set_row (_i,"@86g%r", &_totale_lettera); + set_row (_i++,"@112g%r", &_totale_let_raf); + } + else + if (_sez_stamp != '9') + { + set_row (_i,"@86g%r", &_totale_lettera); + set_row (_i++,"@112g%r", &_totale_let_raf); + } + } + } + if (classe > diff_prod && _diffprod_fatto) + { + if (_let_tot == 'A' || _let_tot == 'B') + { + set_row (_i++,"@4gDifferenza tra valore e costi della produzione@86g%r@112g%r", &_totale_economico,&_totale_economico_raf); + _diffprod_fatto = FALSE; + } + } + + } + else + { + if (_let_stamp != 'Z') + { + if (_sez_stamp != '5') + { + if (_cont_gcs != 0)//(_cont_gcs >= 2) + { + //Fai il totale del numero arabo e stampalo + if (_num != 0) + { + set_row (_i,"@18gTotale@25g%2d@27g)", _num); + set_row (_i,"@86g%r", &_totale_numero); + set_row (_i++,"@112g%r", &_totale_num_raf); + } + } + if (_cont_num != 0)//(_cont_num >= 2) + { + //Fai il totale del numero romano e stampalo + int numeror = atoi(_numr); + TString numrom = itor(numeror); + if (numrom != "") + { + set_row (_i,"@14gTotale@21g%s", (const char*) numrom); + set_row (_i,"@86g%r", &_totale_numr); + set_row (_i++,"@112g%r", &_totale_numr_raf); + } + } + if (_cont_numr != 0)//(_cont_numr >= 2) + { + //Fai il totale della lettera e stampalo + if (_let != ' ') + { + set_row (_i,"@3gTotale@10g%c@12g)", _let); + set_row (_i,"@86g%r", &_totale_lettera); + set_row (_i++,"@112g%r", &_totale_let_raf); + } + } + } + } + + if ((_sez_stamp == '1')&&(_let_da_stamp == 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE ATTIVO"); + set_row (_i,"@86g%r", &_totale_sezione); + set_row (_i++,"@112g%r", &_totale_sez_raf); + _totale_attivita = _totale_sezione; + _totale_attiv_raf = _totale_sez_raf; + _totale_sezione = ZERO; + _totale_sez_raf = ZERO; + _totale_attivita_gia_stampato = TRUE; + } + + if ((_sez_stamp == '2')&&(_let_da_stamp == 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE PASSIVO"); + set_row (_i,"@86g%r", &_totale_sezione); + set_row (_i++,"@112g%r", &_totale_sez_raf); + _totale_passivita = _totale_sezione; + _totale_passiv_raf = _totale_sez_raf; + _totale_sezione = ZERO; + _totale_sez_raf = ZERO; + _totale_passivita_gia_stampato = TRUE; + } + + if ((_sez_stamp == '1')&&(_let_stamp == 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE CONTI D' ORDINE ATTIVI"); + set_row (_i,"@86g%r", &_totale_ordine_attivo); + set_row (_i++,"@112g%r", &_totale_ordine_attivo_raf); + //_totale_ordine_attivo = ZERO; + //_totale_ordine_attivo_raf = ZERO; + gia_stampato_conto_ord = TRUE; + } + + if ((_sez_stamp == '2')&&(_let_stamp == 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE CONTI D' ORDINE PASSIVI"); + set_row (_i,"@86g%r", &_totale_ordine_passivo); + set_row (_i++,"@112g%r", &_totale_ordine_passivo_raf); + _i++; + gia_stampato_conto_ord = TRUE; + if (!_attivo_o_passivo) + { + real totale = _totale_ordine_attivo - _totale_ordine_passivo; + real tot_raf = _totale_ordine_attivo_raf - _totale_ordine_passivo_raf; + if (totale != ZERO || tot_raf != ZERO) + { + set_row (_i++,"@0gSALDO CONTI D' ORDINE"); + set_row (_i,"@0gSBILANCIO"); + set_row (_i,"@86g%r", &totale); + set_row (_i++,"@112g%r", &tot_raf); + } + _totale_ordine_attivo = ZERO; + _totale_ordine_attivo_raf = ZERO; + _totale_ordine_passivo = ZERO; + _totale_ordine_passivo_raf = ZERO; + _sbilancio_ordine = TRUE; + _sbilancio_patr_gia_stampato = TRUE; //Se passa di qui non ci sono ne attivi ne passivo + } + } + } + _cont_gcs = 0; + _cont_num = 0; + _cont_numr = 0; + _totale_numero = 0; + _totale_numr = 0; + _totale_lettera = 0; + _totale_num_raf = 0; + _totale_numr_raf = 0; + _totale_let_raf = 0; + } + if (_sez_da_stamp != _sez_tot) + { + if (_let_stamp != 'Z') + { + if (_sez_stamp != '5') + { + if (_cont_gcs != 0)//(_cont_gcs >= 2) + { + //Fai il totale del numero arabo e stampalo + if (_num != 0) + { + set_row (_i,"@18gTotale@25g%2d@27g)", _num); + set_row (_i,"@86g%r", &_totale_numero); + set_row (_i++,"@112g%r", &_totale_num_raf); + } + } + if (_cont_num != 0)//(_cont_num >= 2) + { + //Fai il totale del numero romano e stampalo + int numeror = atoi(_numr); + TString numrom = itor(numeror); + if (numrom != "") + { + set_row (_i,"@14gTotale@21g%s", (const char*) numrom); + set_row (_i++,"@86g%r", &_totale_numr); + set_row (_i++,"@112g%r", &_totale_numr_raf); + } + } + if (_cont_numr != 0)//(_cont_numr >= 2) + { + //Fai il totale della lettera e stampalo + if (_let != ' ') + { + if (_sez_stamp == '9' && _let_stamp != 'E') + { + set_row (_i,"@3gTotale@10g%c@12g)", _let); + set_row (_i++,"@86g%r", &_totale_lettera); + set_row (_i++,"@112g%r", &_totale_let_raf); + } + else + if (_sez_stamp != '9') + { + set_row (_i,"@3gTotale@10g%c@12g)", _let); + set_row (_i++,"@86g%r", &_totale_lettera); + set_row (_i++,"@112g%r", &_totale_let_raf); + } + } + } + } + } + + if (!_totale_attivita_gia_stampato) + if ((_sez_stamp == '1') && (_let_stamp != 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE ATTIVO"); + set_row (_i,"@86g%r", &_totale_sezione); + set_row (_i++,"@112g%r", &_totale_sez_raf); + _totale_attivita = _totale_sezione; + _totale_attiv_raf = _totale_sez_raf; + _totale_sezione = ZERO; + _totale_sez_raf = ZERO; + _totale_attivita_gia_stampato = TRUE; + } + + if (!_totale_passivita_gia_stampato) + if ((_sez_stamp == '2') && (_let_stamp != 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE PASSIVO"); + set_row (_i,"@86g%r", &_totale_sezione); + set_row (_i++,"@112g%r", &_totale_sez_raf); + _totale_passivita = _totale_sezione; + _totale_passiv_raf = _totale_sez_raf; + _totale_sezione = ZERO; + _totale_sez_raf = ZERO; + _totale_passivita_gia_stampato = TRUE; + } + + if (!gia_stampato_conto_ord) + { + if (_sez_stamp == '2') + { + if (!_sbilancio_patr_gia_stampato) + { + _totale_patrimoniale = _totale_attivita - _totale_passivita; + _totale_patrim_raf = _totale_attiv_raf - _totale_passiv_raf; + if (_totale_patrimoniale != ZERO || _totale_patrim_raf != ZERO) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i++,"@0gSALDO STATO PATRIMONIALE"); + set_row (_i,"@0gSBILANCIO (ATTIVO - PASSIVO)"); + //_totale_patrimoniale = _totale_attivita - _totale_passivita; + //_totale_patrim_raf = _totale_attiv_raf - _totale_passiv_raf; + set_row (_i,"@86g%r", &_totale_patrimoniale); + set_row (_i++,"@112g%r", &_totale_patrim_raf); + _totale_patrimoniale = 0; + _totale_patrim_raf = 0; + } + _sbilancio_patr_gia_stampato = TRUE; + } + } + if ((_sez_stamp == '1')&&(_let_stamp == 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE CONTI D' ORDINE ATTIVI"); + set_row (_i,"@86g%r", &_totale_ordine_attivo); + set_row (_i++,"@112g%r", &_totale_ordine_attivo_raf); + //_totale_ordine_attivo = ZERO; + //_totale_ordine_attivo_raf = ZERO; + } + + if ((_sez_stamp == '2')&&(_let_stamp == 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE CONTI D' ORDINE PASSIVI"); + set_row (_i,"@86g%r", &_totale_ordine_passivo); + set_row (_i++,"@112g%r", &_totale_ordine_passivo_raf); + _i++; + if (!_sbilancio_ordine) + { + real totale = _totale_ordine_attivo - _totale_ordine_passivo; + real tot_raf = _totale_ordine_attivo_raf - _totale_ordine_passivo_raf; + if (totale != ZERO || tot_raf != ZERO) + { + set_row (_i++,"@0g%c", app); + set_row (_i++,"@0gSALDO CONTI D' ORDINE"); + set_row (_i,"@0gSBILANCIO"); + set_row (_i,"@86g%r", &totale); + set_row (_i++,"@112g%r", &tot_raf); + _sbilancio_ordine = TRUE; + } + _totale_ordine_attivo = ZERO; + _totale_ordine_attivo_raf = ZERO; + _totale_ordine_passivo = ZERO; + _totale_ordine_passivo_raf = ZERO; + _sbilancio_ordine = TRUE; + } + } + } + + if (_sez_stamp == '2') + { + char app = ' '; + if (!_sbilancio_patr_gia_stampato) + { + _totale_patrimoniale = _totale_attivita - _totale_passivita; + _totale_patrim_raf = _totale_attiv_raf - _totale_passiv_raf; + if (_totale_patrimoniale != ZERO || _totale_patrim_raf != ZERO) + { + set_row (_i++,"@0g%c", app); + set_row (_i++,"@0gSALDO STATO PATRIMONIALE"); + set_row (_i,"@0gSBILANCIO (ATTIVO - PASSIVO)"); + //_totale_patrimoniale = _totale_attivita - _totale_passivita; + //_totale_patrim_raf = _totale_attiv_raf - _totale_passiv_raf; + set_row (_i,"@86g%r", &_totale_patrimoniale); + set_row (_i++,"@112g%r", &_totale_patrim_raf); + _totale_patrimoniale = 0; + _totale_patrim_raf = 0; + } + } + if (!_sbilancio_ordine) + { + real totale = _totale_ordine_attivo - _totale_ordine_passivo; + real tot_raf = _totale_ordine_attivo_raf - _totale_ordine_passivo_raf; + if ((totale != ZERO || tot_raf != ZERO) && !_sbilancio_ordine) + { + set_row (_i++,"@0g%c", app); + set_row (_i++,"@0gSALDO CONTI D' ORDINE"); + set_row (_i,"@0gSBILANCIO"); + set_row (_i,"@86g%r", &totale); + set_row (_i++,"@112g%r", &tot_raf); + } + } + } + if (_sez_stamp == '5') + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i,"@0gTOTALE CONTI D' ORDINE"); + set_row (_i,"@86g%r", &_totale_ordine); + set_row (_i++,"@112g%r", &_totale_ordine_raf); + _totale_ordine = 0; + _totale_ordine_raf = 0; + } + if (_sez_stamp == '9') + { + if (_buff == NULL) + { + if ((_let_stamp == 'A' || _let_stamp == 'B') && _diffprod_fatto) + { + set_row (_i++,"@4gDifferenza tra valore e costi della produzione@86g%r@112g%r", &_totale_economico,&_totale_economico_raf); + _diffprod_fatto = FALSE; + } + if (_risimp_fatto) + { + if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) + { + set_row (_i,"@4gTotale delle partite straordinarie"); + set_row (_i,"@86g%r", &_totale_parziale); + set_row (_i++,"@112g%r", &_totale_parziale_raf); + set_row (_i,"@4gRisultato prima delle imposte"); + set_row (_i,"@86g%r", &_totale_economico); + set_row (_i++,"@112g%r", &_totale_economico_raf); + _risimp_fatto = FALSE; + } + } + } + char app = ' '; + set_row (_i++,"@0g%c", app); + if (_totale_economico != ZERO || _totale_economico_raf != ZERO) + { + set_row (_i,"@0gRISULTATO CONTO ECONOMICO"); + set_row (_i,"@86g%r", &_totale_economico); + set_row (_i++,"@112g%r", &_totale_economico_raf); + _totale_economico = 0; + _totale_economico_raf = 0; + } + } + _cont_gcs = 0; + _cont_num = 0; + _cont_numr = 0; + _cont_let = 0; + _totale_numero = 0; + _totale_numr = 0; + _totale_lettera = 0; + _totale_num_raf = 0; + _totale_numr_raf = 0; + _totale_let_raf = 0; + } +} + +void CG1600_application::stampa_totali_verifica() +{ + TString16 ris_imp; + + ris_imp.format ("%c%c%8s%2s",'9','E',"","21"); + + _num = atoi(_num_tot); + _numr = _numr_tot; + _let = _let_tot; + _sez = _sez_tot; + + if (_buff == NULL) + { + _num_tot = ""; + _numr_tot = ""; + _let_tot = ' '; + _sez_tot = ' '; + } + + if (_num_da_stamp!=_num_tot) + { + if (_cont_gcs != 0)//(_cont_gcs >= 2) + { + //Fai il totale del numero arabo e stampalo + if (((_sez == '1')||(_sez == '2')||(_sez == '9'))&&(_let != 'Z')) + { + if (_num != 0) + set_row (_i,"@8gTotale@15g%2d@17g)",_num); + } + else + if (_num != 0) + set_row (_i,"@8gTotale"); + + if (_num != 0) + { + set_row (_i,"@49g%r", &_tot_num_prg_d); + set_row (_i,"@65g%r", &_tot_num_prg_a); + set_row (_i,"@82g%r", &_tot_num_mov_d); + set_row (_i,"@98g%r", &_tot_num_mov_a); + } + + if (!_stampa_modulo) + { + if (_tot_num_saldo < ZERO) + { + _tot_num_saldo = -_tot_num_saldo; + _tot_sez_saldo = 'A'; + } + else + _tot_sez_saldo = 'D'; + + if (_num != 0) + stampa_saldo_132(_tot_num_saldo); + } + else + { + if (_num != 0) + stampa_saldo_198(_tot_num_saldo_d,_tot_num_saldo_a); + // _tot_num_saldo_d = 0; + // _tot_num_saldo_a = 0; + } + if (_sez_stamp == '9') + { + TString16 classe; + + classe.format("%c%c%8s%2s", _sez_da_stamp,_let_da_stamp,(const char*)_numr_da_stamp,(const char*)_num_da_stamp); + + if (classe > ris_imp && _risimp_fatto) + { + if (_num_tot == "20" || _num_tot == "21") + { + set_row (_i,"@4gTotale delle partite straordinarie"); + set_row (_i,"@49g%r", &_tot_parz_prg_d); + set_row (_i,"@65g%r", &_tot_parz_prg_a); + set_row (_i,"@82g%r", &_tot_parz_mov_d); + set_row (_i,"@98g%r", &_tot_parz_mov_a); + _risimp_fatto = FALSE; + if (!_stampa_modulo) + { + if (_tot_parz_sld < ZERO) + { + _tot_parz_sld = -_tot_parz_sld; + _tot_sez_saldo = 'A'; + } + else + _tot_sez_saldo = 'D'; + + if (_num != 0) + stampa_saldo_132(_tot_parz_sld); + } + else + { + if (_num != 0) + stampa_saldo_198(_tot_parz_sld_d,_tot_parz_sld_a); + } + } + } + } + } + _cont_gcs = 0; + _tot_num_prg_d = ZERO; + _tot_num_prg_a = ZERO; + _tot_num_mov_d = ZERO; + _tot_num_mov_a = ZERO; + _tot_num_saldo = ZERO; + } + if (_numr_da_stamp!=_numr_tot) + { + if (_cont_gcs != 0)//(_cont_gcs >= 2) + { + //Fai il totale del numero arabo e stampalo + if (((_sez == '1')||(_sez == '2')||(_sez == '9'))&&(_let != 'Z')) + { + if (_num != 0) + set_row (_i,"@8gTotale@15g%2d@17g)", _num); + } + else + if (_num != 0) + set_row (_i,"@8gTotale"); + + if (_num != 0) + { + set_row (_i,"@49g%r", &_tot_num_prg_d); + set_row (_i,"@65g%r", &_tot_num_prg_a); + set_row (_i,"@82g%r", &_tot_num_mov_d); + set_row (_i,"@98g%r", &_tot_num_mov_a); + } + + if (!_stampa_modulo) + { + if (_tot_num_saldo < ZERO) + { + _tot_num_saldo = -_tot_num_saldo; + _tot_sez_saldo = 'A'; + } + else + _tot_sez_saldo = 'D'; + + if (_num != 0) + stampa_saldo_132(_tot_num_saldo); + } + else + { + if (_num != 0) + stampa_saldo_198(_tot_num_saldo_d,_tot_num_saldo_a); + //_tot_num_saldo_d = 0; + //_tot_num_saldo_a = 0; + } + } + if (_cont_num != 0)//(_cont_num >= 2) + { + //Fai il totale del numero romano e stampalo + int numeror = atoi(_numr); + TString numrom = itor(numeror); + if (numrom != "") + { + set_row (_i,"@8gTotale@15g%s", (const char*) numrom); + set_row (_i,"@49g%r", &_tot_numr_prg_d); + set_row (_i,"@65g%r", &_tot_numr_prg_a); + set_row (_i,"@82g%r", &_tot_numr_mov_d); + set_row (_i,"@98g%r", &_tot_numr_mov_a); + } + + if (!_stampa_modulo) + { + if (_tot_numr_saldo < ZERO) + { + _tot_numr_saldo = -_tot_numr_saldo; + _tot_sez_saldo = 'A'; + } + else + _tot_sez_saldo = 'D'; + + if (numrom != "") + stampa_saldo_132(_tot_numr_saldo); + } + else + { + if (numrom != "") + stampa_saldo_198(_tot_numr_saldo_d,_tot_numr_saldo_a); + // _tot_numr_saldo_d = 0; + // _tot_numr_saldo_a = 0; + } + } + _cont_gcs = 0; + _cont_num = 0; + _tot_num_prg_d = ZERO; + _tot_num_prg_a = ZERO; + _tot_num_mov_d = ZERO; + _tot_num_mov_a = ZERO; + _tot_num_saldo = ZERO; + _tot_numr_prg_d = ZERO; + _tot_numr_prg_a = ZERO; + _tot_numr_mov_d = ZERO; + _tot_numr_mov_a = ZERO; + _tot_numr_saldo = ZERO; + } + if ((_let_da_stamp!=_let_tot) || (_sez_da_stamp != _sez_tot)) + { + if (_cont_gcs != 0)//(_cont_gcs >= 2) + { + //Fai il totale del numero arabo e stampalo + if (((_sez == '1')||(_sez == '2')||(_sez == '9'))&&(_let != 'Z')) + { + if (_num != 0) + set_row (_i,"@8gTotale@15g%2d@17g)",_num); + } + else + if (_num != 0) + set_row (_i,"@8gTotale"); + + if (_num != 0) + { + set_row (_i,"@49g%r", &_tot_num_prg_d); + set_row (_i,"@65g%r", &_tot_num_prg_a); + set_row (_i,"@82g%r", &_tot_num_mov_d); + set_row (_i,"@98g%r", &_tot_num_mov_a); + } + + if (!_stampa_modulo) + { + if (_tot_num_saldo < ZERO) + { + _tot_num_saldo = -_tot_num_saldo; + _tot_sez_saldo = 'A'; + } + else + _tot_sez_saldo = 'D'; + + if (_num != 0) + stampa_saldo_132(_tot_num_saldo); + } + else + { + if (_num != 0) + stampa_saldo_198(_tot_num_saldo_d,_tot_num_saldo_a); + // _tot_num_saldo_d = 0; + // _tot_num_saldo_a = 0; + } + } + if (_cont_num != 0)//(_cont_num >= 2) + { + //Fai il totale del numero romano e stampalo + int numeror = atoi(_numr); + TString numrom = itor(numeror); + if (numrom != "") + { + set_row (_i,"@8gTotale@15g%s", (const char*) numrom); + set_row (_i,"@49g%r", &_tot_numr_prg_d); + set_row (_i,"@65g%r", &_tot_numr_prg_a); + set_row (_i,"@82g%r", &_tot_numr_mov_d); + set_row (_i,"@98g%r", &_tot_numr_mov_a); + } + + if (!_stampa_modulo) + { + if (_tot_numr_saldo < ZERO) + { + _tot_numr_saldo = -_tot_numr_saldo; + _tot_sez_saldo = 'A'; + } + else + _tot_sez_saldo = 'D'; + + if (numrom != "") + stampa_saldo_132(_tot_numr_saldo); + } + else + { + if (numrom != "") + stampa_saldo_198(_tot_numr_saldo_d,_tot_numr_saldo_a); + // _tot_numr_saldo_d = 0; + // _tot_numr_saldo_a = 0; + } + } + if (_cont_numr != 0)//(_cont_numr >= 2) + { + //Fai il totale della lettera e stampalo + if (_let != ' ') + { + if (_sez_stamp == '9' && _let_stamp != 'E') + { + set_row (_i,"@8gTotale@15g%c@16g)", _let); + set_row (_i,"@49g%r", &_tot_let_prg_d); + set_row (_i,"@65g%r", &_tot_let_prg_a); + set_row (_i,"@82g%r", &_tot_let_mov_d); + set_row (_i,"@98g%r", &_tot_let_mov_a); + } + else + if (_sez_stamp != '9') + { + set_row (_i,"@8gTotale@15g%c@16g)", _let); + set_row (_i,"@49g%r", &_tot_let_prg_d); + set_row (_i,"@65g%r", &_tot_let_prg_a); + set_row (_i,"@82g%r", &_tot_let_mov_d); + set_row (_i,"@98g%r", &_tot_let_mov_a); + } + } + + if (!_stampa_modulo) + { + if (_tot_let_saldo < ZERO) + { + _tot_let_saldo = -_tot_let_saldo; + _tot_sez_saldo = 'A'; + } + else + _tot_sez_saldo = 'D'; + + if (_let != ' ') + if (_sez_stamp == '9' && _let_stamp != 'E') + stampa_saldo_132(_tot_let_saldo); + else + if (_sez_stamp != '9') + stampa_saldo_132(_tot_let_saldo); + } + else + { + if (_let != ' ') + if (_sez_stamp == '9' && _let_stamp != 'E') + stampa_saldo_198(_tot_let_saldo_d,_tot_let_saldo_a); + else + stampa_saldo_198(_tot_let_saldo_d,_tot_let_saldo_a); + // _tot_let_saldo_d = 0; + // _tot_let_saldo_a = 0; + } + } + _cont_gcs = 0; + _cont_num = 0; + _cont_numr = 0; + _tot_num_prg_d = ZERO; + _tot_num_prg_a = ZERO; + _tot_num_mov_d = ZERO; + _tot_num_mov_a = ZERO; + _tot_num_saldo = ZERO; + _tot_numr_prg_d = ZERO; + _tot_numr_prg_a = ZERO; + _tot_numr_mov_d = ZERO; + _tot_numr_mov_a = ZERO; + _tot_numr_saldo = ZERO; + _tot_let_prg_d = ZERO; + _tot_let_prg_a = ZERO; + _tot_let_mov_d = ZERO; + _tot_let_mov_a = ZERO; + _tot_let_saldo = ZERO; + } +} + +void CG1600_application::stampa_saldo_198(real& saldo_d,real& saldo_a) +{ + set_row (_i,"@115g%r", &saldo_d); + set_row (_i,"@48g!@81g!@114g!@131g!"); + set_row (_i,"@133g%r", &saldo_a); + set_row (_i++,"@48g!@81g!@114g!@131g!"); + saldo_d = real(ZERO); + saldo_a = real(ZERO); +} + +void CG1600_application::stampa_saldo_132(const real& saldo) +{ + set_row (_i,"@115g%r", &saldo); + set_row (_i,"@48g!@81g!@114g!"); + set_row (_i++,"@131g%c", _tot_sez_saldo); +} + +print_action CG1600_application::postprocess_page(int file, int counter) +{ + struct bil_ivd* bil = (struct bil_ivd*) _buff; + + bil = (struct bil_ivd*) _buff; + + if (_tipo_bilancio == 1) + { + if (_sez_da_stamp != _sez_stamp) + { + if (_sez_da_stamp == '5') + { + if (!_intera_struttura) + { + if (bil->gruppo[0] != 'Z') + { + reset_print(); + _i = 1; + setta_righe("CONTI D' ORDINE"); + _reset_righe_stampa = FALSE; + } + } + else + { + reset_print(); + _i = 1; + setta_righe("CONTI D' ORDINE"); + _reset_righe_stampa = FALSE; + } + } + if (_sez_da_stamp == '9') + { + if (!_intera_struttura) + { + if (bil->gruppo[0] != 'Z') + { + reset_print(); + _i = 1; + setta_righe("CONTO ECONOMICO"); + _reset_righe_stampa = FALSE; + } + } + else + { + reset_print(); + _i = 1; + setta_righe("CONTO ECONOMICO"); + _reset_righe_stampa = FALSE; + } + } + } + + set_auto_ff(FALSE); + } + + if (_buff == NULL) + return NEXT_PAGE; + + _sale = 0; + _salerafr = 0; + + return REPEAT_PAGE; +} + +bool CG1600_application::preprocess_page(int file, int counter) +{ + if (_tipo_bilancio == 1) + { + if (preprocess_stampa_scalare(counter)) + return TRUE; + else + return FALSE; + } + else if (_tipo_bilancio == 2) + { + if (preprocess_stampa_verifica(counter)) + return TRUE; + else + return FALSE; + } + + return TRUE; +} + +bool CG1600_application::preprocess_stampa_scalare(int counter) +{ + struct bil_ivd* bil = (struct bil_ivd*) _buff; + int g,c; + long s; + bool fai = TRUE; + TString saldostr,saldo_rafstr; + bool conto_dettagliato = TRUE; + + if (!counter) + { + reset_print(); + _i = 1; + } + + if (_reset_righe_stampa) + { + reset_print(); + _i = 1; + } + else + _reset_righe_stampa = TRUE; + + if (counter) + { + if (!_intera_struttura) + { + if (bil->gruppo[0] != 'Z') + { + _sez_stamp = bil->sez; + _let_stamp = bil->let; + _numr_stamp = bil->numr; + _numr_stamp.ltrim(); + _num_stamp = bil->num; + _num_stamp.ltrim(); + _sez_tot = bil->sez; + _let_tot = bil->let; + _numr_tot = bil->numr; + _numr_tot.ltrim(); + _num_tot = bil->num; + _num_tot.ltrim(); + } + } + else + { + _classe_stampata = format ("%1c%1c%8s%2d",bil->sez,bil->let,(const char*) bil->numr,bil->num); + _sez_stamp = bil->sez; + _let_stamp = bil->let; + _numr_stamp = bil->numr; + _numr_stamp.ltrim(); + _num_stamp = bil->num; + _num_stamp.ltrim(); + _sez_tot = bil->sez; + _let_tot = bil->let; + _numr_tot = bil->numr; + _numr_tot.ltrim(); + _num_tot = bil->num; + _num_tot.ltrim(); + } + } + + _buff = _sort->retrieve(); + + if (_buff == NULL) + { + if (_annoeserafr == 0 && _databilrafr == botime) + stampa_totali(); + else + stampa_totali_con_raffronto(); + _sez_da_stamp = ' '; + _sez_stamp = ' '; + return TRUE; + } + + if (_buff != NULL) + { + bil = (struct bil_ivd*) _buff; + _classe_da_stampare = format ("%1c%1c%8s%2d",bil->sez,bil->let,(const char*) bil->numr,bil->num); + _sez_da_stamp = bil->sez; + _let_da_stamp = bil->let; + _numr_da_stamp = bil->numr; + _numr_da_stamp.ltrim(); + _num_da_stamp = bil->num; + _num_da_stamp.ltrim(); + g = atoi(bil->gruppo); + c = atoi(bil->conto); + s = atol(bil->sottoc); + conto_dettagliato = bil->conto_dettagliato; + + if (_intera_struttura) + fai = TRUE; + else + { + if (bil->gruppo[0] != 'Z') + fai = TRUE; + else + fai = FALSE; + } + + if (counter) + { + if (fai) + if (_annoeserafr == 0 && _databilrafr == botime) + stampa_totali(); + else + stampa_totali_con_raffronto(); + } + + //Fare ricerca di dataregmov + + if (!_intera_struttura) + { + if (bil->gruppo[0]=='Z') + return FALSE; + + _sale = bil->saldo; + if (_annoeserafr != 0 || _databilrafr != botime) + _salerafr = bil->saldorafr; +/*** + if (_stampamov) + { + if (_annoeserafr != 0 || _databilrafr != botime) + { + if ((_sale.is_zero()) && (_salerafr.is_zero())) + return FALSE; + } + else + if (_sale.is_zero()) + return FALSE; + } +***/ + } + else + { + if (bil->gruppo[0]=='Z') +// { + if (_classe_da_stampare == _classe_stampata) +// { +// sprintf (bil->gruppo,"%s", " "); +// sprintf (bil->conto ,"%s", " "); +// sprintf (bil->sottoc,"%s", " "); +// } +// else + return FALSE; +// } + + _sale = bil->saldo; + if (_annoeserafr != 0 || _databilrafr != botime) + _salerafr = bil->saldorafr; +/*** + if (_stampamov) + { + if (_annoeserafr != 0 || _databilrafr != botime) + { + if ((_sale.is_zero()) && (_salerafr.is_zero())) + return FALSE; + } + else + { + if (_sale.is_zero()) + return FALSE; + } + } +***/ + } + + saldostr = _sale.string(); + saldo_rafstr = _salerafr.string(); + + // Faccio passare solo i sottoconti o i conti non dettagliati (che non hanno sottoconti) + // perchè l' importo dei conti dettagliati non è altri che il totale degli importi di + // tutti i suoi sottoconti; dunque se li sommassi anche loro, sommerei l'importo due volte. + // Pero' devo ricordarmi di cambiare ugualmente segno ai conti che vanno dettagliati. + + if (g != 0 && c != 0 && s == 0 && conto_dettagliato) + if (_sez_da_stamp == '9') + { + _sale = -_sale; + if (_annoeserafr != 0 || _databilrafr != botime) + _salerafr = -_salerafr; + } + + + if ((g != 0 && c != 0 && s != 0)||(g != 0 && c != 0 && s == 0 && !conto_dettagliato)) + { + // if (_sez_da_stamp == '5') + // if (_sale < ZERO) + // _sale = -_sale; + + if (_sez_da_stamp == '9') + // if (_sale> ZERO) + _sale = -_sale; + + _totale_numero += _sale; + _totale_numr += _sale; + _totale_lettera += _sale; + if ((_sez_da_stamp == '1')||(_sez_da_stamp == '2')) + { + if (_let_da_stamp != 'Z') + _totale_sezione += _sale; + else + { + if (_sez_da_stamp == '1') + _totale_ordine_attivo += _sale; + else + if (_sez_da_stamp == '2') + _totale_ordine_passivo += _sale; + } + } + + if (_sez_da_stamp == '5') + _totale_ordine += _sale; + + if (_sez_da_stamp == '9') + { + _totale_economico += _sale; + if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) + _totale_parziale += _sale; + } + + if (_annoeserafr != 0 || _databilrafr != botime) + { + //if (_sez_da_stamp == '5') + // if (_salerafr < ZERO) + // _salerafr = -_salerafr; + if (_sez_da_stamp == '9') + //if (_salerafr> ZERO) + _salerafr = -_salerafr; + + _totale_num_raf += _salerafr; + _totale_numr_raf += _salerafr; + _totale_let_raf += _salerafr; + if ((_sez_da_stamp == '1')||(_sez_da_stamp == '2')) + { + if (_let_da_stamp != 'Z') + _totale_sez_raf += _salerafr; + else + { + if (_sez_da_stamp == '1') + _totale_ordine_attivo_raf += _salerafr; + else + if (_sez_da_stamp == '2') + _totale_ordine_passivo_raf += _salerafr; + } + } + + if (_sez_da_stamp == '5') + _totale_ordine_raf += _salerafr; + + if (_sez_da_stamp == '9') + { + _totale_economico_raf += _salerafr; + if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) + _totale_parziale_raf += _salerafr; + } + } + } + return TRUE; + } + else + return FALSE; +} + +bool CG1600_application::preprocess_stampa_verifica(int counter) +{ + struct bil_ivd* bil = (struct bil_ivd*) _buff; + int g,c; + long s; + bool fai = TRUE; + bool conto_dettagliato = TRUE; + + if (!counter) + { + reset_print(); + _i = 1; + } + + if (_reset_righe_stampa) + { + reset_print(); + _i = 1; + } + else + _reset_righe_stampa = TRUE; + + if (counter) + { + if (!_intera_struttura) + { + if (bil->gruppo[0] != 'Z') + { + _sez_stamp = bil->sez; + _let_stamp = bil->let; + _numr_stamp = bil->numr; + _numr_stamp.ltrim(); + _num_stamp = bil->num; + _num_stamp.ltrim(); + _sez_tot = bil->sez; + _let_tot = bil->let; + _numr_tot = bil->numr; + _numr_tot.ltrim(); + _num_tot = bil->num; + _num_tot.ltrim(); + } + } + else + { + _classe_stampata = format ("%1c%1c%8s%2d",bil->sez,bil->let,(const char*) bil->numr,bil->num); + _sez_stamp = bil->sez; + _let_stamp = bil->let; + _numr_stamp = bil->numr; + _numr_stamp.ltrim(); + _num_stamp = bil->num; + _num_stamp.ltrim(); + _sez_tot = bil->sez; + _let_tot = bil->let; + _numr_tot = bil->numr; + _numr_tot.ltrim(); + _num_tot = bil->num; + _num_tot.ltrim(); + } + } + + _buff = _sort->retrieve(); + + if (_buff == NULL) + { + stampa_totali_verifica(); + set_row (_i,"@0g****** ******** TOTALE GENERALE"); + set_row (_i,"@49g%r", &_tot_gen_prg_d); + set_row (_i,"@65g%r", &_tot_gen_prg_a); + set_row (_i,"@82g%r", &_tot_gen_mov_d); + set_row (_i,"@98g%r", &_tot_gen_mov_a); + + if (!_stampa_modulo) + { + if (_tot_gen_saldo < ZERO) + { + _tot_gen_saldo = -_tot_gen_saldo; + _tot_sez_saldo = 'A'; + } + else + _tot_sez_saldo = 'D'; + stampa_saldo_132(_tot_gen_saldo); + } + else + stampa_saldo_198(_tot_gen_saldo_d,_tot_gen_saldo_a); + + _sez_da_stamp = ' '; + _sez_stamp = ' '; + return TRUE; + } + + if (_buff != NULL) + { + bil = (struct bil_ivd*) _buff; + _classe_da_stampare = format ("%1c%1c%8s%2d",bil->sez,bil->let,(const char*) bil->numr,bil->num); + _sez_da_stamp = bil->sez; + _let_da_stamp = bil->let; + _numr_da_stamp = bil->numr; + _numr_da_stamp.ltrim(); + _num_da_stamp = bil->num; + _num_da_stamp.ltrim(); + g = atoi(bil->gruppo); + c = atoi(bil->conto); + s = atol(bil->sottoc); + conto_dettagliato = bil->conto_dettagliato; + + if (_intera_struttura) + fai = TRUE; + else + { + if (bil->gruppo[0] != 'Z') + fai = TRUE; + else + fai = FALSE; + } + + if (counter) + { + if (fai) + stampa_totali_verifica(); + } + + _sale = bil->saldo; + _sld_prg_dare = bil->sld_prg_dare; + _sld_prg_avere = bil->sld_prg_avere; + _mov_dare = bil->mov_dare; + _mov_avere = bil->mov_avere; + + if (!_intera_struttura) + { + if (bil->gruppo[0]=='Z') + return FALSE; + + if (_stampamov) + { + if (_sale.is_zero()) + return FALSE; + } + } + else + { + if (bil->gruppo[0]=='Z') +// { + if (_classe_da_stampare == _classe_stampata) +// { +// sprintf (bil->gruppo,"%s", " "); +// sprintf (bil->conto ,"%s", " "); +// sprintf (bil->sottoc,"%s", " "); +// } +// else + return FALSE; +// } + + if (_stampamov) + { + if (_sale.is_zero()) + return FALSE; + } + } + + if ((g != 0) && (c != 0) && (s == 0) && (conto_dettagliato)) + { + //if (_sld_prg_avere < ZERO) + // _sld_prg_avere = -_sld_prg_avere; + + //if (_mov_avere < ZERO) + // _mov_avere = -_mov_avere; + + if (_sale < ZERO) + { + _sale = -_sale; + _sez_saldo = 'A'; + } + else + _sez_saldo = 'D'; + } + + if ((g != 0 && c != 0 && s != 0)||(g != 0 && c != 0 && s == 0 && !conto_dettagliato)) + { + _tot_num_saldo += _sale; + _tot_numr_saldo += _sale; + _tot_let_saldo += _sale; + _tot_gen_saldo += _sale; + if (_sez_da_stamp == '9') + if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) + _tot_parz_sld += _sale; + + //if (_sld_prg_avere < ZERO) + // _sld_prg_avere = -_sld_prg_avere; + + //if (_mov_avere < ZERO) + // _mov_avere = -_mov_avere; + + if (_sale < ZERO) + { + _sale = -_sale; + _sez_saldo = 'A'; + if (_stampa_modulo) + { + _tot_num_saldo_a += _sale; + _tot_numr_saldo_a += _sale; + _tot_let_saldo_a += _sale; + _tot_gen_saldo_a += _sale; + if (_sez_da_stamp == '9') + if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) + _tot_parz_sld_a += _sale; + } + } + else + { + _sez_saldo = 'D'; + if (_stampa_modulo) + { + _tot_num_saldo_d += _sale; + _tot_numr_saldo_d += _sale; + _tot_let_saldo_d += _sale; + _tot_gen_saldo_d += _sale; + if (_sez_da_stamp == '9') + if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) + _tot_parz_sld_d += _sale; + + } + } + + _tot_num_prg_d += _sld_prg_dare; + _tot_numr_prg_d += _sld_prg_dare; + _tot_let_prg_d += _sld_prg_dare; + _tot_gen_prg_d += _sld_prg_dare; + _tot_num_prg_a += _sld_prg_avere; + _tot_numr_prg_a += _sld_prg_avere; + _tot_let_prg_a += _sld_prg_avere; + _tot_gen_prg_a += _sld_prg_avere; + _tot_num_mov_d += _mov_dare; + _tot_numr_mov_d += _mov_dare; + _tot_let_mov_d += _mov_dare; + _tot_gen_mov_d += _mov_dare; + _tot_num_mov_a += _mov_avere; + _tot_numr_mov_a += _mov_avere; + _tot_let_mov_a += _mov_avere; + _tot_gen_mov_a += _mov_avere; + if (_sez_da_stamp == '9') + if (_let_da_stamp == 'E' && (_num_da_stamp == "20" || _num_da_stamp == "21")) + { + _tot_parz_prg_d += _sld_prg_dare; + _tot_parz_prg_a += _sld_prg_avere; + _tot_parz_mov_d += _mov_dare; + _tot_parz_mov_a += _mov_avere; + } + } + return TRUE; + } + else + return FALSE; +} + +void CG1600_application::set_page(int file, int counter) +{ + if (_tipo_bilancio == 1) + { + if (_sez_da_stamp != _sez_stamp) + { + if ((_sez_da_stamp=='1')||((_sez_da_stamp=='2')&&(_statopatr_no_stamp))) + { + setta_righe ("STATO PATRIMONIALE"); + _statopatr_no_stamp = FALSE; + } + if (_sez_da_stamp == '2') + setta_righe(""); + if ((_sez_da_stamp == '5') || (_sez_da_stamp == '9')) + set_auto_ff(TRUE); + } + else + { + if (_buff != NULL) + setta_righe(""); + } + } + else if (_tipo_bilancio == 2) + { + if (_buff != NULL) + setta_righe_verifica(); + } +} + +void CG1600_application::setta_righe(const char * titolo) +{ + struct bil_ivd* bil = (struct bil_ivd*) _buff; + int numeror, numero, gruppo, conto; + char sezione,lettera; + long sottoc; + TString numrom,numr; + TString descr_let,descr_numr,descr_num,descr_sottoc,descr_classe; + bool stampa_classe = TRUE; + TString lettera1 = "@1g)@3g%s"; + TString lettera2 = "@3g%s"; + TString numr1 = "@12g-@14g%s"; + TString numr2 = "@14g%s"; + TString num = "@15g)@18g%s"; + TString num2 = "@18g%s"; + + _descr->set_width(40); + sezione = bil->sez; + lettera = bil->let; + numr = bil->numr; + // numr.ltrim(); + numeror = atoi(bil->numr); + numrom = itor(numeror); + numero = atoi(bil->num); +// num = bil->num; + gruppo = atoi(bil->gruppo); + conto = atoi(bil->conto); + sottoc = atoi(bil->sottoc); + descr_let = descrizione_lettera(sezione,lettera); + descr_numr = descrizione_numeroromano(sezione,lettera,numeror); + descr_num = descrizione_numero(sezione,lettera,numeror,numero); + descr_sottoc = descrizione_sottoconto(gruppo,conto,sottoc); + + //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 (_sez_da_stamp != _sez_stamp) + { + set_row (_i++,"@0g%s", titolo); + char app = ' '; + set_row(_i++,"@0g%c", app); + + if ((_sez_da_stamp == '1')&&(_let_da_stamp == 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i++,"@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++,"@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++,"@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++,"@0gPASSIVO"); + set_row(_i++,"@0g%c", app); + } + + if (stampa_classe) + { + if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp== '9')) + { + //set_row(_i++,"@0g%s", (const char*) _descr_sez); + if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) + { + _cont_let = 1; + _cont_numr = 1; + _cont_num = 1; + _cont_gcs = 0; + } + if (lettera != ' ') + { + set_row(_i,"@0g%c", bil->let); + *_descr = (const char*) descr_let; + setta_righe_descr(_descr,lettera1,lettera2); + //set_row(_i++,"@1g)@3g%s", (const char*) descr_let); + } + if (numrom != "") + { + set_row(_i,"@3g%8s", (const char*) numrom); + *_descr = (const char*) descr_numr; + setta_righe_descr(_descr,numr1,numr2); + //set_row(_i++,"@12g-@14g%s", (const char*) descr_numr); + } + if (numero != 0) + { + set_row(_i,"@13g%s", bil->num); + *_descr = (const char*) descr_num; + setta_righe_descr(_descr,num,num2); + //set_row(_i++,"@15g)@18g%s", (const char*) descr_num); + } + } + } + } + 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++,"@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++,"@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')) + { + set_row(_i,"@0g%c", bil->let); + *_descr = (const char*) descr_let; + setta_righe_descr(_descr,lettera1,lettera2); + //set_row(_i++,"@1g)@3g%s", (const char*) descr_let); + //_cont_let += 1; + if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) + { + _cont_numr = 1; + _cont_num = 1; + _cont_gcs = 0; + } + + if (numrom != "") + { + set_row(_i,"@3g%8s", (const char*) numrom); + *_descr = (const char*) descr_numr; + setta_righe_descr(_descr,numr1,numr2); + //set_row(_i++,"@12g-@14g%s", (const char*) descr_numr); + } + if (numero != 0) + { + set_row(_i,"@13g%s", bil->num); + *_descr = (const char*) descr_num; + setta_righe_descr(_descr,num,num2); + //set_row(_i++,"@15g)@18g%s", (const char*) descr_num); + } + } + } + } + else + if ((_numr_da_stamp!=_numr_stamp)&&(_sez_da_stamp==_sez_stamp)&&(_let_da_stamp==_let_stamp)) + { + if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp=='9')) + { + set_row(_i,"@3g%8s", (const char*) numrom); + *_descr = (const char*) descr_numr; + setta_righe_descr(_descr,numr1,numr2); + //set_row(_i++,"@12g-@14g%s", (const char*) descr_numr); + //_cont_numr += 1; + //_cont_numr = 1; + if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) + { + _cont_num = 1; + _cont_gcs = 0; + } + + if (numero != 0) + { + set_row(_i,"@13g%s", bil->num); + *_descr = (const char*) descr_num; + setta_righe_descr(_descr,num,num2); + //set_row(_i++,"@15g)@18g%s", (const char*) descr_num); + } + } + } + else + if ((_num_da_stamp!=_num_stamp)&&(_sez_da_stamp==_sez_stamp)&&(_let_da_stamp==_let_stamp)&&(_numr_da_stamp==_numr_stamp)) + { + if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp=='9')) + { + set_row(_i,"@13g%s", bil->num); + *_descr = (const char*) descr_num; + setta_righe_descr(_descr,num,num2); + //set_row(_i++,"@15g)@18g%s", (const char*) descr_num); + //_cont_num += 1; + if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) + _cont_gcs = 0; + } + } + if (bil->gruppo[0] != 'A') + { + if (!_stampacod) + { + if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) + { + _cont_gcs += 1; + set_row (_i,"@18g%s", bil->gruppo); + set_row (_i,"@22g%s", bil->conto); + set_row (_i,"@26g%s", bil->sottoc); + set_row (_i,"@33g%s", (const char*) descr_sottoc); + set_row (_i,"@86g%r", &_sale); + if (_annoeserafr != 0 || _databilrafr != botime) + set_row (_i,"@112g%r", &_salerafr); + _i++; + } + } + else + { + if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) + { + _cont_gcs += 1; + if ((sezione != '0')&&(lettera == ' ')&&(numrom == "")&&(numero == 0)) + descr_classe = _descr_sez; + if ((sezione != '0')&&(lettera != ' ')&&(numrom == "")&&(numero == 0)) + descr_classe = descr_let; + if ((sezione != '0')&&(lettera != ' ')&&(numrom != "")&&(numero == 0)) + descr_classe = descr_numr; + if ((sezione != '0')&&(lettera != ' ')&&(numrom != "")&&(numero != 0)) + descr_classe = descr_num; + if (descr_classe != descr_sottoc) + { + set_row (_i,"@20g%s", (const char*) descr_sottoc); + set_row (_i,"@86g%r", &_sale); + if (_annoeserafr != 0 || _databilrafr != botime) + set_row (_i,"@112g%r", &_salerafr); + _i++; + } + } + } + } +} + +void CG1600_application::setta_righe_verifica() +{ + struct bil_ivd* bil = (struct bil_ivd*) _buff; + int numeror, numero, gruppo, conto; + char sezione,lettera,tmcf; + long sottoc; + TString numrom,numr; + TString descr_let,descr_numr,descr_num,descr_sottoc,descr_classe; + TString lettera1 = "@1g)@3g%s"; + TString lettera2 = "@3g%s"; + TString numr1 = "@8g)@10g%s"; + TString numr2 = "@10g%s"; + TString num = "@2g)@4g%s"; + TString num2 = "@4g%s"; + + _descr->set_width(35); + + sezione = bil->sez; + lettera = bil->let; + numr = bil->numr; + numeror = atoi(bil->numr); + numrom = itor(numeror); + numero = atoi(bil->num); +// num = bil->num; + gruppo = atoi(bil->gruppo); + conto = atoi(bil->conto); + sottoc = atoi(bil->sottoc); + tmcf = bil->tipocf; + descr_let = descrizione_lettera(sezione,lettera); + descr_numr = descrizione_numeroromano(sezione,lettera,numeror); + descr_num = descrizione_numero(sezione,lettera,numeror,numero); + if ((tmcf == 'C') || (tmcf == 'F')) + { + if (gruppo != 0 && conto != 0 && sottoc != 0) + { + TConto tc (gruppo,conto,sottoc,tmcf); + descr_sottoc = tc.descrizione(); + } + else + descr_sottoc = descrizione_sottoconto(gruppo,conto,sottoc); + } + else + descr_sottoc = descrizione_sottoconto(gruppo,conto,sottoc); + + //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 (_sez_da_stamp != _sez_stamp) + { + char app = ' '; + set_row (_i,"@0g%c", app); + set_row (_i++,"@48g!@81g!@114g!"); + if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp== '9')) + { + if (_let_da_stamp != 'Z') + { + if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) + { + _cont_let = 1; + _cont_numr = 1; + _cont_num = 1; + _cont_gcs = 0; + } + if (lettera != '\0') + { + set_row(_i,"@0g%c", bil->let); + *_descr = (const char*) descr_let; + setta_righe_descr_verifica(_descr,lettera1,lettera2); + //set_row(_i,"@1g)@3g%s", (const char*) descr_let); + //set_row (_i++,"@48g!@81g!@114g!"); + } + if (numrom != "") + { + set_row(_i,"@0g%8s", (const char*) numrom); + *_descr = (const char*) descr_numr; + setta_righe_descr_verifica(_descr,numr1,numr2); + //set_row(_i,"@8g)@10g%s", (const char*) descr_numr); + //set_row (_i++,"@48g!@81g!@114g!"); + } + if (numero != 0) + { + set_row(_i,"@0g%s", bil->num); + *_descr = (const char*) descr_num; + setta_righe_descr_verifica(_descr,num,num2); + //set_row(_i,"@2g)@4g%s", (const char*) descr_num); + //set_row (_i++,"@48g!@81g!@114g!"); + } + } + } + } + else + if ((_let_da_stamp!=_let_stamp)&&(_sez_da_stamp==_sez_stamp)) + { + char app = ' '; + set_row (_i,"@0g%c", app); + set_row (_i++,"@48g!@81g!@114g!"); + if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp=='9')) + { + if (_let_da_stamp != 'Z') + { + set_row(_i,"@0g%c", bil->let); + *_descr = (const char*) descr_let; + setta_righe_descr_verifica(_descr,lettera1,lettera2); + //set_row(_i,"@1g)@3g%s", (const char*) descr_let); + //set_row (_i++,"@48g!@81g!@114g!"); + //_cont_let += 1; + if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) + { + _cont_numr = 1; + _cont_num = 1; + _cont_gcs = 0; + } + + if (numrom != "") + { + set_row(_i,"@0g%8s", (const char*) numrom); + *_descr = (const char*) descr_numr; + setta_righe_descr_verifica(_descr,numr1,numr2); + //set_row(_i,"@8g)@10g%s", (const char*) descr_numr); + //set_row (_i++,"@48g!@81g!@114g!"); + } + if (numero != 0) + { + set_row(_i,"@0g%s", bil->num); + *_descr = (const char*) descr_num; + setta_righe_descr_verifica(_descr,num,num2); + //set_row(_i,"@2g)@4g%s", (const char*) descr_num); + //set_row (_i++,"@48g!@81g!@114g!"); + } + } + } + } + else + if ((_numr_da_stamp!=_numr_stamp)&&(_sez_da_stamp==_sez_stamp)&&(_let_da_stamp==_let_stamp)) + { + char app = ' '; + set_row (_i,"@0g%c", app); + set_row (_i++,"@48g!@81g!@114g!"); + if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp=='9')) + { + if (_let_da_stamp != 'Z') + { + set_row(_i,"@0g%8s", (const char*) numrom); + *_descr = (const char*) descr_numr; + setta_righe_descr_verifica(_descr,numr1,numr2); + //set_row(_i,"@8g)@10g%s", (const char*) descr_numr); + //set_row (_i++,"@48g!@81g!@114g!"); + //_cont_numr += 1; + //_cont_numr = 1; + if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) + { + _cont_num = 1; + _cont_gcs = 0; + } + + if (numero != 0) + { + set_row(_i,"@0g%s", bil->num); + *_descr = (const char*) descr_num; + setta_righe_descr_verifica(_descr,num,num2); + //set_row(_i,"@2g)@4g%s", (const char*) descr_num); + //set_row (_i++,"@48g!@81g!@114g!"); + } + } + } + } + else + if ((_num_da_stamp!=_num_stamp)&&(_sez_da_stamp==_sez_stamp)&&(_let_da_stamp==_let_stamp)&&(_numr_da_stamp==_numr_stamp)) + { + char app = ' '; + set_row (_i,"@0g%c", app); + set_row (_i++,"@48g!@81g!@114g!"); + if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp=='9')) + { + if (_let_da_stamp != 'Z') + { + set_row(_i,"@0g%s", bil->num); + *_descr = (const char*) descr_num; + setta_righe_descr_verifica(_descr,num,num2); + //set_row(_i,"@2g)@4g%s", (const char*) descr_num); + //set_row (_i++,"@48g!@81g!@114g!"); + _cont_num += 1; + _cont_gcs = 0; + } + } + } + if (bil->gruppo[0] != 'A') + { + if (!_stampacod) + { + if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) + { + _cont_gcs += 1; + set_row (_i,"@0g%s", bil->gruppo); + set_row (_i,"@4g%s", bil->conto); + set_row (_i,"@8g%s", bil->sottoc); + set_row (_i,"@15g%s", (const char*) descr_sottoc); + set_row (_i,"@49g%r", &_sld_prg_dare); + set_row (_i,"@65g%r", &_sld_prg_avere); + set_row (_i,"@82g%r", &_mov_dare); + set_row (_i,"@98g%r", &_mov_avere); + if (_stampa_modulo) + { + if (_sez_saldo == 'D') + { + set_row (_i,"@115g%r", &_sale); + set_row (_i,"@48g!@81g!@114g!@131g!"); + } + else + if (_sez_saldo == 'A') + { + set_row (_i,"@133g%r", &_sale); + set_row (_i,"@48g!@81g!@114g!@131g!"); + } + } + else + { + set_row (_i,"@115g%r", &_sale); + set_row (_i,"@131g%c", _sez_saldo); + set_row (_i,"@48g!@81g!@114g!"); + } + } + } + else + { + if (!_intera_struttura || (_intera_struttura && bil->gruppo[0] != 'Z')) + { + _cont_gcs += 1; + if ((sezione != '0')&&(lettera == ' ')&&(numrom == "")&&(numero == 0)) + descr_classe = _descr_sez; + if ((sezione != '0')&&(lettera != ' ')&&(numrom == "")&&(numero == 0)) + descr_classe = descr_let; + if ((sezione != '0')&&(lettera != ' ')&&(numrom != "")&&(numero == 0)) + descr_classe = descr_numr; + if ((sezione != '0')&&(lettera != ' ')&&(numrom != "")&&(numero != 0)) + descr_classe = descr_num; + if (descr_classe != descr_sottoc) + { + set_row (_i,"@2g%s", (const char*) descr_sottoc); + set_row (_i,"@49g%r", &_sld_prg_dare); + set_row (_i,"@66g%r", &_sld_prg_avere); + set_row (_i,"@82g%r", &_mov_dare); + set_row (_i,"@99g%r", &_mov_avere); + if (_stampa_modulo) + { + if (_sez_saldo == 'D') + { + set_row (_i,"@115g%r", &_sale); + set_row (_i,"@48g!@81g!@114g!@131g!"); + } + else + if (_sez_saldo == 'A') + { + set_row (_i,"@133g%r", &_sale); + set_row (_i,"@48g!@81g!@114g!@131g!"); + } + } + else + { + set_row (_i,"@115g%r", &_sale); + set_row (_i,"@131g%c", _sez_saldo); + set_row (_i,"@48g!@81g!@114g!"); + } + } + } + } + } +} + +void CG1600_application::setta_righe_descr(TParagraph_string* str,const TString& formato,const TString& formato2) +{ + const char* r; + int i = 1; + + while ((r = str->get()) != NULL) + { + if (i == 1) + set_row (_i,formato, r); + else + if (i > 1) + set_row (_i,formato2,r); + _i++; + i++; + } +} + +void CG1600_application::setta_righe_descr_verifica(TParagraph_string* str,const TString& formato,const TString& formato2) +{ + const char* r; + int i = 1; + + while ((r = str->get()) != NULL) + { + if (i == 1) + set_row (_i,formato, r); + else + if (i > 1) + set_row (_i,formato2,r); + + set_row (_i,"@48g!@81g!@114g!"); + + _i++; + i++; + } +} + +const char* CG1600_application::descrizione_sezione(char sezione) +{ + TTable tabivd(TAB_IVD); + TString dep, dep2; + + tabivd.zero(); + dep = format("%1c", sezione); + tabivd.put("CODTAB", dep); + tabivd.read(); + dep2 = tabivd.get("CODTAB"); + if (dep == dep2) + tmp = tabivd.get("S0"); + else + tmp = ""; + return (__tmp); +} + +const char* CG1600_application::descrizione_lettera(char sezione, char lettera) +{ + TTable tabivd(TAB_IVD); + TString dep, dep2; + + tabivd.zero(); + dep = format("%1c%1c", sezione, lettera); + tabivd.put("CODTAB", dep); + tabivd.read(); + dep2 = tabivd.get("CODTAB"); + if (dep == dep2) + tmp = tabivd.get("S0"); + else + tmp = ""; + return (__tmp); +} + +const char* CG1600_application::descrizione_numeroromano(char sezione, char lettera, int numr) +{ + TTable tabivd(TAB_IVD); + TString dep, dep2; + + tabivd.zero(); + if (numr != 0) + dep = format("%1c%1c%04d", sezione, lettera, numr); + else + dep = format("%c%c ", sezione, lettera); + + tabivd.put("CODTAB", dep); + tabivd.read(); + dep2 = tabivd.get("CODTAB"); + if (dep == dep2) + tmp = tabivd.get("S0"); + else + tmp = ""; + return (__tmp); +} + +const char* CG1600_application::descrizione_numero(char sezione, char lettera, int numr, int numero) +{ + TTable tabivd(TAB_IVD); + TString dep,dep2; + + tabivd.zero(); + if (numr != 0) + dep = format("%1c%1c%04d%02d",sezione, lettera, numr, numero); + else + dep = format("%c%c %02d",sezione,lettera,numero); + tabivd.put("CODTAB", dep); + tabivd.read(); + dep2 = tabivd.get("CODTAB"); + if (dep == dep2) + tmp = tabivd.get("S0"); + else + tmp = ""; + return (__tmp); +} + +const char* CG1600_application::descrizione_sottoconto(int gruppo, int conto, long sottoc) +{ + TLocalisamfile pconti (LF_PCON); + + pconti.zero(); + pconti.put(PCN_GRUPPO , gruppo); + if (conto != 0) + pconti.put(PCN_CONTO , conto ); + if (sottoc != 0) + pconti.put(PCN_SOTTOCONTO, sottoc); + pconti.read(); + if (pconti.bad()) + pconti.zero(); + tmp = pconti.get(PCN_DESCR); + return (__tmp); +} + +const char* CG1600_application::descr_sottoc_clifo(char tipocf,long s) +{ + TLocalisamfile clifo (LF_CLIFO); + + clifo.zero(); + clifo.put(CLI_TIPOCF,tipocf); + if (s != 0) + clifo.put(CLI_CODCF, s); + clifo.read(); + if (clifo.bad()) + clifo.zero(); + tmp = clifo.get(CLI_RAGSOC); + return (__tmp); +} + +void CG1600_application::preprocess_header() +{ +} + +// Crea l'intestazione per la stampa a 132 e a 198 caratteri + +void CG1600_application::crea_intestazione() +{ + TString datastampastr; + TString sep(132),sep1(147); + + TString app(8); + TLocalisamfile nditte (LF_NDITTE); + TLocalisamfile comuni (LF_COMUNI); + TLocalisamfile unloc (LF_UNLOC); + TLocalisamfile anag (LF_ANAG); + TString codice_ditta,ragsoc,indulc,civulc,capulc,com,prov,comulc; + TString cofi,paiv,tipoa,codanagr; + + reset_header(); + + nditte.setkey(1); + codice_ditta << get_firm(); + nditte.curr().zero(); + nditte.curr().put(NDT_CODDITTA,codice_ditta); + nditte.read(); + app=nditte.curr().get(NDT_CODDITTA); + ragsoc=nditte.curr().get(NDT_RAGSOC); + tipoa =nditte.curr().get(NDT_TIPOA); + codanagr = nditte.get(NDT_CODANAGR); + + unloc.setkey(1); + unloc.curr().zero(); + unloc.curr().put(ULC_CODDITTA,app); + unloc.curr().put(ULC_CODULC,"1"); + unloc.read(); + indulc=unloc.curr().get(ULC_INDULC); + civulc=unloc.curr().get(ULC_CIVULC); + capulc=unloc.curr().get(ULC_CAPULC); + comulc=unloc.curr().get(ULC_COMULC); + + comuni.setkey(1); + comuni.curr().zero(); + comuni.curr().put(COM_COM,comulc); + comuni.read(); + com=comuni.curr().get(COM_DENCOM); + prov=comuni.curr().get(COM_PROVCOM); + + anag.setkey(1); + anag.curr().zero(); + anag.curr().put(ANA_TIPOA,tipoa); + anag.curr().put(ANA_CODANAGR,codanagr); + anag.read(); + cofi=anag.curr().get(ANA_COFI); + paiv=anag.curr().get(ANA_PAIV); + + set_header (1, "@0gDITTA@6g%-5s", (const char*) codice_ditta); + set_header (1, "@12g%-45s", (const char*) ragsoc); + set_header (1, "@59g%-25s", (const char*) indulc); + set_header (1, "@86g%-9s", (const char*) civulc); + set_header (1, "@97g%-5s", (const char*) capulc); + set_header (1, "@103g%-25s", (const char*) com); + set_header (1, "@129g%-3s", (const char*) prov); + + if (_stampa_modulo) + { + sep1 << "Pag. @#"; + sep1.right_just(139); + set_header(2,(const char*) sep1); + } + else + { + sep << "Pag. @#"; + sep.right_just(132); + set_header(2,(const char*) sep); + } + + datastampastr = _datastampa.string(); + + set_header (2,"@0gPartita iva@12g%-11s", (const char*) paiv); + set_header (2,"@30gCodice fiscale@45g%-16s", (const char*) cofi); + if (_stampa_modulo) + set_header (2,"@131gData@136g%s",(const char*) datastampastr); + else + set_header (2,"@105gData@110g%s",(const char*) datastampastr); + + if (_tipo_bilancio == 1) + { + intesta_scalare(); + } + else if (_tipo_bilancio == 2) + { + intesta_verifica(); + } + +} + +void CG1600_application::intesta_verifica_fissa() +{ + TString sep(132),app(32),sep1(147); + + if (_tipo_stampa == 1) + { + if (_dataini == _data_ini_ese) + set_header(5,"@57gSALDO INIZIALE@87gMOVIMENTI DEL PERIODO"); + else if (_dataini > _data_ini_ese) + set_header(5,"@54gPROGRESSIVI PRECEDENTI@87gMOVIMENTI DEL PERIODO"); + } + else if (_tipo_stampa == 2) + set_header(5,"@57gSALDO INIZIALE@87gMOVIMENTI DEL PERIODO"); + + if (_stampa_modulo) + set_header(5,"@129gSALDO"); + + set_header(5,"@48g!@81g!@114g!"); + + if (_stampa_modulo) + { + set_header(5,"@147g!"); + set_header(6,"@131g!@147g!"); + } + + set_header(6,"@48g!@81g!@114g!"); + app = "--------------------------------"; + if (_stampa_modulo) + { + set_header(6,"@49g%s@82g%s@115g%s", (const char*) app, (const char*) app,(const char*) app); + set_header(7,"@1gdescrizione voce@48g!@57gDare@65g!@72gAvere@81g!@90gDare@98g!@105gAvere@114g!@122gDare@131g!@138gAvere@147g!"); + sep1.fill('-'); //Stampa 132 - (sep(132)) + set_header (8, (const char *) sep1); + } + else + { + set_header(6,"@49g%s@82g%s@122gSALDO", (const char*) app, (const char*) app); + set_header(7,"@1gdescrizione voce@48g!@57gDare@65g!@72gAvere@81g!@90gDare@98g!@105gAvere@114g!"); + sep.fill('-'); //Stampa 132 - (sep(132)) + set_header (8, (const char *) sep); + } +} + +void CG1600_application::intesta_scalare() +{ + TString datalimitestr,databilrafrstr; + TString sep(132); + + set_header (3,"@0gSTAMPA BILANCIO CONFORME ALLA IV DIRETTIVA"); + set_header (3,"@89gEsercizio@99g%d", _anno_esercizio); + if (_annoeserafr != 0 || _databilrafr != botime) + { + set_header (3,"@115gEsercizio@125g%d", _anno_esercizio_raf); + databilrafrstr = _databilrafr.string(); + set_header (4,"@112galla data@122g%s", (const char*) databilrafrstr); + } + if (_tipo_stampa == 1) + { + datalimitestr = _datalimite.string(); + set_header (4,"@86galla data@96g%s", (const char*) datalimitestr); + } + else if (_tipo_stampa == 2) + set_header (4,"@90gall' ultima immissione"); + + sep.fill('-'); //Stampa 132 - (sep(132)) + set_header (5, (const char *) sep); +} + +void CG1600_application::intesta_verifica() +{ + TString sep(132),sep1(147); + + set_header (3,"@0gBILANCIO DI VERIFICA IV DIRETTIVA"); + if (_tipo_stampa == 1) + { + TString datainistr = _dataini.string(); + TString datafinestr = _datafine.string(); + set_header (3,"@43gdalla data@54g%s", (const char*) datainistr); + set_header (3,"@65galla data@75g%s", (const char*) datafinestr); + } + else if (_tipo_stampa == 2) + set_header (3,"@42gall' ultima immissione"); + + if (_stampa_modulo) + { + sep1.fill('-'); //Stampa 132 - (sep(132)) + set_header (4, (const char *) sep1); + } + else + { + sep.fill('-'); //Stampa 132 - (sep(132)) + set_header (4, (const char *) sep); + } + intesta_verifica_fissa(); +} + +void CG1600_application::init_sort() +{ + _bil = new bil_ivd; + _sort = new TSort (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),2); + _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); + _sort->init(); +} + +bool CG1600_application::user_create() +{ + _nditte = new TLocalisamfile (LF_NDITTE); + _comuni = new TLocalisamfile (LF_COMUNI); + _unloc = new TLocalisamfile (LF_UNLOC); + _anag = new TLocalisamfile (LF_ANAG); + _pconti = new TLocalisamfile (LF_PCON); + _clifo = new TLocalisamfile (LF_CLIFO); + _saldi = new TLocalisamfile (LF_SALDI); + _descr = new TParagraph_string ("",40); + + _tabivd = new TTable (TAB_IVD); + _tabesc = new TTable (TAB_ESC); + + _anni_es = new Anni_es(); + _sld = new Saldo(); + + _msk = new TMask("cg1600a"); + + return TRUE; +} + +bool CG1600_application::user_destroy() +{ + delete _msk; + + delete _tabivd; + delete _tabesc; + delete _nditte; + delete _comuni; + delete _unloc; + delete _anag; + delete _pconti; + delete _clifo; + delete _saldi; + delete _descr; + delete _anni_es; + delete _sld; + + return TRUE; +} + +int cg1600 (int argc, char* argv[]) +{ + + CG1600_application a; + + a.run(argc, argv, "Stampa Bilancio IV direttiva CEE"); + return 0; +} + + + diff --git a/cg/cg3100b.uml b/cg/cg3100b.uml index 77417213a..02139198a 100755 --- a/cg/cg3100b.uml +++ b/cg/cg3100b.uml @@ -1,163 +1,218 @@ -#include "cg3100.h" - -PAGE "" -1 -1 73 16 - - -NUMBER F_CODDITTA 5 -BEGIN - PROMPT 2 1 "Ditta " - FLAGS "FRD" - USE LF_NDITTE KEY 1 - CHECKTYPE REQUIRED - INPUT CODDITTA F_CODDITTA - DISPLAY "Codice" CODDITTA - DISPLAY "Ragione sociale @50" RAGSOC - OUTPUT F_CODDITTA CODDITTA - OUTPUT F_RAGSOC RAGSOC -END - -STRING F_RAGSOC 50 -BEGIN - PROMPT 2 2 "Ragione sociale " - FLAGS "D" -END - -DATE F_DATASTAMPA -BEGIN - PROMPT 48 1 "Data stampa " - HELP "Data in cui viene effettuata la stampa" - FLAGS "A" -END - -NUMBER F_ANNO 4 -BEGIN - PROMPT 2 4 "Anno esercizio " - HELP "Anno d'esercizio di cui si vuole la stampa" - USE ESC KEY 1 - CHECKTYPE NORMAL - INPUT CODTAB F_ANNO - DISPLAY "Anno" CODTAB - DISPLAY "Data inizio esercizio" D0 - DISPLAY "Data fine esercizio" D1 - OUTPUT F_ANNO CODTAB - FLAGS "RZ" -END - -DATE F_DATAINI -BEGIN - PROMPT 2 6 "Stampa movimenti dalla data " - HELP "Data da cui iniziare la stampa" -END - -DATE F_DATAFIN -BEGIN - PROMPT 45 6 "alla data " - HELP "Data fino a cui eseguire la stampa" -END - - -LIST F_TIPOELENCO 8 -BEGIN - PROMPT 2 7 "Tipo elenco " - HELP "Indicare cosa includere nella stampa" - ITEM "C|Clienti" - MESSAGE HIDE,2@|SHOW,1@|RESET,1@ - ITEM "F|Fornitori" - MESSAGE HIDE,2@|SHOW,1@|RESET,1@ - ITEM "E|Entrambi" - MESSAGE HIDE,1@|SHOW,2@|RESET,2@ -END - -NUMBER F_CODICEINI 6 -BEGIN - PROMPT 2 8 "Stampa dal codice " - HELP "Indicare il codice da cui iniziare la stampa" - GROUP 1 - USE LF_CLIFO - INPUT TIPOCF F_TIPOELENCO SELECT - DISPLAY "Tipo" TIPOCF - DISPLAY "Codice" CODCF - DISPLAY "Ragione sociale@50" RAGSOC - OUTPUT F_CODICEINI CODCF - FLAGS "R" -END - -NUMBER F_CODICEFIN 6 -BEGIN - PROMPT 45 8 "al codice " - HELP "Indicare il codice a cui terminare la stampa" - GROUP 1 - COPY USE F_CODICEINI - INPUT TIPOCF F_TIPOELENCO SELECT - DISPLAY "Tipo" TIPOCF - DISPLAY "Codice" CODCF - DISPLAY "Ragione sociale@50" RAGSOC - OUTPUT F_CODICEFIN CODCF - NUM_EXPR {(#F_CODICEFIN==0)||(#F_CODICEFIN>=#F_CODICEINI)} - WARNING "Limite superiore errato" - FLAGS "R" -END - -NUMBER F_CODICEINI1 6 -BEGIN - PROMPT 2 8 "Stampa dal codice " - HELP "Indicare il codice da cui iniziare la stampa" - GROUP 2 - COPY USE F_CODICEINI - INPUT TIPOCF F_CODICEINI1 - DISPLAY "Tipo" TIPOCF - DISPLAY "Codice" CODCF - DISPLAY "Ragione sociale@50" RAGSOC - OUTPUT F_CODICEINI1 CODCF - FLAGS "R" -END - -NUMBER F_CODICEFIN1 6 -BEGIN - PROMPT 45 8 "al codice " - HELP "Indicare il codice a cui terminare la stampa" - GROUP 2 - COPY USE F_CODICEINI - INPUT TIPOCF F_CODICEFIN1 - DISPLAY "Tipo" TIPOCF - DISPLAY "Codice" CODCF - DISPLAY "Ragione sociale@50" RAGSOC - OUTPUT F_CODICEFIN1 CODCF - NUM_EXPR {(#F_CODICEFIN1==0)||(#F_CODICEFIN1>=#F_CODICEINI1)} - WARNING "Limite superiore errato" - FLAGS "R" -END - -BOOLEAN F_CAMBIO -BEGIN - //GROUP 2 - PROMPT 2 10 "Cambio pagina per cliente/fornitore " - HELP "Indicare se cambiare pagina nel passaggio da cliente/fornitore a cliente/fornitore" -END - -BOOLEAN F_STAMPAMOVP -BEGIN - PROMPT 2 11 "Stampa movimenti provvisori " - HELP "Indicare se stampare i movimenti provvisori" -END - -/* -TEXT DLG_NULL -BEGIN - PROMPT 3 15 "(N.B. se non indicato nessun valore stampa completa in ordine di data) " -END -*/ - -BUTTON DLG_OK 9 2 -BEGIN - PROMPT -12 -1 "" -END - -BUTTON DLG_QUIT 9 2 -BEGIN - PROMPT -22 -1 "" -END - -ENDPAGE - -ENDMASK +#include "cg3100.h" + +PAGE "" -1 -1 73 16 + + +NUMBER F_CODDITTA 5 +BEGIN + PROMPT 2 1 "Ditta " + FLAGS "FRD" + USE LF_NDITTE KEY 1 + CHECKTYPE REQUIRED + INPUT CODDITTA F_CODDITTA + DISPLAY "Codice" CODDITTA + DISPLAY "Ragione sociale @50" RAGSOC + OUTPUT F_CODDITTA CODDITTA + OUTPUT F_RAGSOC RAGSOC +END + +STRING F_RAGSOC 50 +BEGIN + PROMPT 2 2 "Ragione sociale " + FLAGS "D" +END + +DATE F_DATASTAMPA +BEGIN + PROMPT 48 1 "Data stampa " + HELP "Data in cui viene effettuata la stampa" + FLAGS "A" +END + +NUMBER F_ANNO 4 +BEGIN + PROMPT 2 4 "Anno esercizio " + HELP "Anno d'esercizio di cui si vuole la stampa" + USE ESC KEY 1 + CHECKTYPE NORMAL + INPUT CODTAB F_ANNO + DISPLAY "Anno" CODTAB + DISPLAY "Data inizio esercizio" D0 + DISPLAY "Data fine esercizio" D1 + OUTPUT F_ANNO CODTAB + FLAGS "RZ" +END + +DATE F_DATAINI +BEGIN + PROMPT 2 5 "Stampa movimenti dalla data " + HELP "Data da cui iniziare la stampa" +END + +DATE F_DATAFIN +BEGIN + PROMPT 45 5 "alla data " + HELP "Data fino a cui eseguire la stampa" +END + +LIST F_TIPOELENCO 9 +BEGIN + PROMPT 2 6 "Tipo elenco " + HELP "Indicare cosa includere nella stampa" + ITEM "C|Clienti" + MESSAGE HIDE,2@|SHOW,1@|RESET,1@ + ITEM "F|Fornitori" + MESSAGE HIDE,2@|SHOW,1@|RESET,1@ + ITEM "E|Entrambi" + MESSAGE HIDE,1@|SHOW,2@|RESET,2@ +END + +NUMBER F_CODICEINI 6 +BEGIN + PROMPT 2 7 "Stampa dal codice " + HELP "Indicare il codice da cui iniziare la stampa" + GROUP 1 + USE LF_CLIFO + INPUT TIPOCF F_TIPOELENCO SELECT + INPUT CODCF F_CODICEINI + DISPLAY "Tipo" TIPOCF + DISPLAY "Codice" CODCF + DISPLAY "Ragione sociale@50" RAGSOC + OUTPUT F_CODICEINI CODCF + OUTPUT F_RAGSOCINI RAGSOC + FLAGS "R" +END + +STRING F_RAGSOCINI 50 +BEGIN + PROMPT 2 8 "" + GROUP 1 + USE LF_CLIFO KEY 2 + INPUT TIPOCF F_TIPOELENCO SELECT + INPUT RAGSOC F_RAGSOCINI + DISPLAY "Tipo" TIPOCF + DISPLAY "Ragione sociale@50" RAGSOC + DISPLAY "Codice" CODCF + OUTPUT F_RAGSOCINI RAGSOC + OUTPUT F_CODICEINI CODCF +END + +NUMBER F_CODICEFIN 6 +BEGIN + PROMPT 2 9 "al codice " + HELP "Indicare il codice a cui terminare la stampa" + GROUP 1 + COPY USE F_CODICEINI + INPUT TIPOCF F_TIPOELENCO SELECT + INPUT CODCF F_CODICEFIN + DISPLAY "Tipo" TIPOCF + DISPLAY "Codice" CODCF + DISPLAY "Ragione sociale@50" RAGSOC + OUTPUT F_CODICEFIN CODCF + OUTPUT F_RAGSOCFIN RAGSOC + NUM_EXPR {(#F_CODICEFIN==0)||(#F_CODICEFIN>=#F_CODICEINI)} + WARNING "Limite superiore errato" + FLAGS "R" +END + +STRING F_RAGSOCFIN 50 +BEGIN + PROMPT 2 10 "" + GROUP 1 + USE LF_CLIFO KEY 2 + INPUT TIPOCF F_TIPOELENCO SELECT + INPUT RAGSOC F_RAGSOCFIN + DISPLAY "Tipo" TIPOCF + DISPLAY "Ragione sociale@50" RAGSOC + DISPLAY "Codice" CODCF + OUTPUT F_RAGSOCFIN RAGSOC + OUTPUT F_CODICEFIN CODCF +END + +NUMBER F_CODICEINI1 6 +BEGIN + PROMPT 2 7 "Stampa dal codice " + HELP "Indicare il codice da cui iniziare la stampa" + GROUP 2 + USE LF_CLIFO KEY 1 + INPUT TIPOCF "C" + INPUT CODCF F_CODICEINI1 + DISPLAY "Tipo" TIPOCF + DISPLAY "Codice" CODCF + DISPLAY "Ragione sociale@50" RAGSOC + OUTPUT F_CODICEINI1 CODCF + OUTPUT F_RAGSOCINI1 RAGSOC + FLAGS "R" +END + +STRING F_RAGSOCINI1 50 +BEGIN + PROMPT 2 8 "" + GROUP 2 + USE LF_CLIFO KEY 2 + INPUT TIPOCF "C" + INPUT RAGSOC F_RAGSOCINI1 + DISPLAY "Tipo" TIPOCF + DISPLAY "Ragione sociale@50" RAGSOC + DISPLAY "Codice" CODCF + OUTPUT F_RAGSOCINI1 RAGSOC + OUTPUT F_CODICEINI1 CODCF +END + +NUMBER F_CODICEFIN1 6 +BEGIN + PROMPT 2 9 "al codice " + HELP "Indicare il codice a cui terminare la stampa" + GROUP 2 + COPY USE F_CODICEINI1 + INPUT TIPOCF "F" + INPUT CODCF F_CODICEFIN1 + DISPLAY "Tipo" TIPOCF + DISPLAY "Codice" CODCF + DISPLAY "Ragione sociale@50" RAGSOC + OUTPUT F_CODICEFIN1 CODCF + OUTPUT F_RAGSOCFIN1 RAGSOC + NUM_EXPR {(#F_CODICEFIN1==0)||(#F_CODICEFIN1>=#F_CODICEINI1)} + WARNING "Limite superiore errato" + FLAGS "R" +END + +STRING F_RAGSOCFIN1 50 +BEGIN + PROMPT 2 10 "" + GROUP 2 + USE LF_CLIFO KEY 2 + INPUT TIPOCF "F" + INPUT RAGSOC F_RAGSOCFIN1 + DISPLAY "Tipo" TIPOCF + DISPLAY "Ragione sociale@50" RAGSOC + DISPLAY "Codice" CODCF + OUTPUT F_RAGSOCFIN1 RAGSOC + OUTPUT F_CODICEFIN1 CODCF +END + +BOOLEAN F_CAMBIO +BEGIN + PROMPT 2 12 "Cambio pagina per cliente/fornitore " + HELP "Indicare se cambiare pagina nel passaggio da cliente/fornitore a cliente/fornitore" +END + +BOOLEAN F_STAMPAMOVP +BEGIN + PROMPT 2 13 "Stampa movimenti provvisori " + HELP "Indicare se stampare i movimenti provvisori" +END + +BUTTON DLG_OK 9 2 +BEGIN + PROMPT -12 -1 "" +END + +BUTTON DLG_QUIT 9 2 +BEGIN + PROMPT -22 -1 "" +END + +ENDPAGE + +ENDMASK diff --git a/cg/cg3200.cpp b/cg/cg3200.cpp index 7714e550c..a61bb7ece 100755 --- a/cg/cg3200.cpp +++ b/cg/cg3200.cpp @@ -1,1957 +1,2025 @@ -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cg3.h" -#include "cg3200.h" -#include "cglib.h" -#include "cglib03.h" - -static TString256 tmp; - -int date2esc(const TDate& d, int* prevesc = NULL); -bool sottoc_handler_ini (TMask_field& f, KEY k); -bool sottoc_handler_fine (TMask_field& f, KEY k); - -class TMastrini_application : public TPrintapp -{ - static bool data_inizio (TMask_field& f, KEY k); - static bool data_fine (TMask_field& f, KEY k); - friend bool sottoc_handler_ini (TMask_field& f, KEY k); - friend bool sottoc_handler_fine (TMask_field& f, KEY k); - - TDociva_array _b; - TRelation* _rel; - TMask* _msk; - TTable* _tabivd, * _tabtpd, * _tabreg, * _tabesc; - TLocalisamfile* _mov; - TLocalisamfile* _nditte; - TLocalisamfile* _unloc; - TLocalisamfile* _comuni; - TLocalisamfile* _clifo; - TLocalisamfile* _caus; - Saldo* _sld; - - TDate _data_ini,_data_fine,_data_finese,_data_finesesucc,_ultima_data_reg; - TDate _datareg,_datadoc,_data_inizioese,_datareg_stampa,_inizioes; - int _cur1,_gruppo,_conto,_numcarat,_stampanum,_numivd,_annoiva; - int _numrig,_natdoc,_tipo,_tipostampa,_g_prec,_c_prec,_numrivd_int; - real _progredare,_progreavere,_totprogre_dare_al,_totprogre_avere_al; - real _totprogre_dare,_totprogre_avere,_importo; - real _riporto_dare,_riporto_avere,_riporto_parziale_dare,_riporto_parziale_avere; - real _totale_periodo_dare,_totale_periodo_avere,_totale_prima_dare,_totale_prima_avere; - real _saldo_periodo,_saldo_progre,_saldo_progre_al,_saldo_progre_prec; - real _saldo_movimenti,_saldo_progressivi,_totale_saldo; - TString _ragsoc,_indulc,_civulc,_capulc,_com,_prov,_comulc; - long _codice_ditta,_s_prec; - TString _tipodoc,_codcaus,_descrcaus,_descrdociva,_regiva,_g_contr,_c_contr,_s_contr; - char _sezivd,_lettivd; - TString _descrizione,_sezione,_numdoc,_descrizionemov,_numrivd,_descr; - TString _dataregs, _datadocs; - int _gruppocontr,_contocontr; - long _sottocontocontr; - - bool _stampaprogre,_stampatotiva,_stampatot,_prima_volta,_stampa_mov_prov; - - int _annomsk,_annoesmsk,_annoes,_annomsksucc,_tipo_mask,_anno_ghost; - int _anno_corrente,_anno_precedente,_indbil; - long _sottoc,_numreg,_numgio,_protiva; - bool _stampa_progressivi_si,_competenza,_inizio_stampa,_puoi_stampare; - char _tmcf,_tipo_contr; - - TDate _dataregrmov; - int _gruppof,_contof; - long _sottocf; - TString _dataregrmovstring,_importo_str,_saldo_movimenti_str,_saldo_progressivi_str; - -protected: - virtual bool user_create() ; - virtual bool user_destroy(); - virtual bool set_print(int m); - - virtual bool preprocess_print(int file, int counter); - virtual bool preprocess_page (int,int); - virtual print_action postprocess_page (int,int); - virtual void preprocess_header(); - virtual void set_page(int,int); - virtual void process_link(int id, const char* txt); - -public: - TDate _inizioEs,_fineEs; - void ricerca_clifo(); - void ricerca_gruppo(); - void calcola_progressivi(); - void calcola_progressivi_al(); - void stampa_progressivi(); - void stampa_progre_riporto(); - void documenti_iva(); - void ricerca_regiva(); - void descrizione_causale(); - void saldi_zero(); - void crea_intestazione(); - void fai_stampa132(); - void fai_stampa198(); - void stampa_totali132(); - void stampa_totali198(); - void stampa_totaliiva(); - void ricerca_classe_IV(bool scelta); - void data_fine_esercizio(int); - const char* descrizione_gruppo(); - const char* descrizione_conto(); - const char* descrizione_classe(char,char,int,int); - bool almeno_un_record(); - void ricerca_dati_ditta(); - void conto(int,int,bool); - - TMastrini_application() {} -}; - -HIDDEN TMastrini_application& app() { return (TMastrini_application&) main_app(); } - -void TMastrini_application::process_link(int id, const char* txt) -{ - const char* const app = "cg2 -0"; - TToken_string ss(10); - ss.add("1"); - ss.add(txt); - - TMessage fs(cmd2name(app), MSG_LN, ss); - fs.send(); - - TExternal_app pn(app); - pn.run(); -} - -bool sottoc_handler_ini(TMask_field& f, KEY key) -{ - const short id = f.dlg(); - const int gruppo = f.mask().get_int(F_GRUPPOINI); - const int conto = f.mask().get_int(F_CONTOINI_CONTO); - const long sottoconto = f.mask().get_long(id); - TString ds; - TString80 rs; - TLocalisamfile pconti (LF_PCON); - - if ( key == K_ENTER ) - { - if (sottoconto != 0 && conto == 0) - return f.warning_box("Manca il CONTO"); - - if (conto != 0 && gruppo == 0) - return f.warning_box("Manca il GRUPPO"); - } - - if ( key == K_TAB ) - { - if (id == F_SOTTOCINI_CONTO) - { - pconti.zero(); - pconti.put(PCN_GRUPPO, gruppo) ; - pconti.put(PCN_CONTO, conto); - pconti.put(PCN_SOTTOCONTO, sottoconto); - pconti.setkey(1); - pconti.read(_isequal, _nolock); - if (pconti.good()) - ds = pconti.get(PCN_DESCR); - else - ds = ""; - - f.mask().set(F_DESCRINI_CONTO, ds); - f.mask().set(F_DESCRINI_CLIENTE, ds); - f.mask().set(F_DESCRINI_FORN, ds); - } - if (id == F_SOTTOCINI_CLIENTE || id == F_SOTTOCINI_FORN) - { - char tipo = id == F_SOTTOCINI_CLIENTE ? 'C' : 'F'; - TLocalisamfile clifo (LF_CLIFO); - if (sottoconto != 0) - { - clifo.zero(); - clifo.put(CLI_TIPOCF,tipo); - clifo.put(CLI_CODCF, sottoconto) ; - clifo.setkey(1); - if (clifo.read(_isequal, _nolock) == NOERR) - { - rs = clifo.get(CLI_RAGSOC); - char tipoa = clifo.get_char("TIPOAPER"); - - if (tipoa == 'F') - { - TString80 cognome, nome; - cognome = rs.mid(0,30); - nome = rs.mid(30,20); - cognome.trim(); nome.trim(); - - rs = cognome; - rs << " " << nome; - } - } - else - rs = ""; - - f.mask().set(F_DESCRINI_CLIENTE, rs); - f.mask().set(F_DESCRINI_FORN, rs); - } - else - if (gruppo != 0 && conto != 0) - { - pconti.zero(); - pconti.put(PCN_GRUPPO, gruppo) ; - pconti.put(PCN_CONTO, conto); - pconti.setkey(1); - pconti.read(_isequal, _nolock); - if (pconti.good()) - ds = pconti.get(PCN_DESCR); - else - ds = ""; - - f.mask().set(F_DESCRINI_CLIENTE, ds); - f.mask().set(F_DESCRINI_FORN, ds); - f.mask().set(F_DESCRINI_CONTO, ds); - } - } - } - return TRUE; -} - -bool sottoc_handler_fine(TMask_field& f, KEY key) -{ - const short id = f.dlg(); - const int gruppo = f.mask().get_int(F_GRUPPOFINE); - const int conto = f.mask().get_int(F_CONTOFINE_CONTO); - const long sottoconto = f.mask().get_long(id); - TString ds; - TString80 rs; - TLocalisamfile pconti (LF_PCON); - - if ( key == K_ENTER ) - { - if (sottoconto != 0 && conto == 0) - return f.warning_box("Manca il CONTO"); - - if (conto != 0 && gruppo == 0) - return f.warning_box("Manca il GRUPPO"); - } - - if ( key == K_TAB ) - { -// if (!f.focusdirty() && gruppo == 0 && conto == 0) return TRUE; -/* - if (sottoconto != 0 && conto == 0) - { - f.warning_box("Manca il CONTO"); - return FALSE; - } - if (conto != 0 && gruppo == 0) - { - f.warning_box("Manca il GRUPPO"); - return FALSE; - } -*/ - if (id == F_SOTTOCFINE_CONTO) - { - pconti.zero(); - pconti.put(PCN_GRUPPO, gruppo) ; - pconti.put(PCN_CONTO, conto); - pconti.put(PCN_SOTTOCONTO, sottoconto); - pconti.setkey(1); - pconti.read(_isequal, _nolock); - if (pconti.good()) - ds = pconti.get(PCN_DESCR); - else - ds = ""; - - f.mask().set(F_DESCRFINE_CONTO, ds); - f.mask().set(F_DESCRFINE_CLIENTE, ds); - f.mask().set(F_DESCRFINE_FORN, ds); - } - if (id == F_SOTTOCFINE_CLIENTE || id == F_SOTTOCFINE_FORN) - { - char tipo = id == F_SOTTOCFINE_CLIENTE ? 'C' : 'F'; - TLocalisamfile clifo (LF_CLIFO); - if (sottoconto != 0) - { - clifo.zero(); - clifo.put(CLI_TIPOCF,tipo); - clifo.put(CLI_CODCF, sottoconto) ; - clifo.setkey(1); - if (clifo.read(_isequal, _nolock) == NOERR) - { - rs = clifo.get(CLI_RAGSOC); - char tipoa = clifo.get_char("TIPOAPER"); - - if (tipoa == 'F') - { - TString80 cognome, nome; - cognome = rs.mid(0,30); - nome = rs.mid(30,20); - cognome.trim(); nome.trim(); - - rs = cognome; - rs << " " << nome; - } - } - else - rs = ""; - - f.mask().set(F_DESCRFINE_CLIENTE, rs); - f.mask().set(F_DESCRFINE_FORN, rs); - } - else - if (gruppo != 0 && conto != 0) - { - pconti.zero(); - pconti.put(PCN_GRUPPO, gruppo) ; - pconti.put(PCN_CONTO, conto); - pconti.setkey(1); - pconti.read(_isequal, _nolock); - if (pconti.good()) - ds = pconti.get(PCN_DESCR); - else - ds = ""; - - f.mask().set(F_DESCRFINE_CLIENTE, ds); - f.mask().set(F_DESCRFINE_FORN, ds); - f.mask().set(F_DESCRFINE_CONTO, ds); - } - } - } - return TRUE; -} - -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; -} - -//Questa funzione restituisce vero se il record su piano dei conti ha almeno un -//record figlio (e che soddisfa la condizione riguardante la data di registr.). -//Viene successivamente utilizzata per stampare l'intestazione (e i totali) -//oppure no - -bool TMastrini_application::almeno_un_record() -{ - bool trovato=FALSE; - long record,sottoc; - int gruppo,conto; - TDate datareg, datacomp; - TLocalisamfile& rmov = current_cursor()->file(LF_RMOV); - - if (current_cursor()->is_first_match(LF_RMOV)) - { - record = rmov.recno(); - rmov.zero(); - rmov.put(RMV_GRUPPO, _gruppo); - rmov.put(RMV_CONTO, _conto); - rmov.put(RMV_SOTTOCONTO, _sottoc); - for (rmov.read(); !rmov.eof() ;rmov.next()) - { - int annoes = rmov.get_int (RMV_ANNOES); - long numreg = rmov.get_long(RMV_NUMREG); - - _mov->setkey(1); - _mov->curr().zero(); - _mov->curr().put(MOV_NUMREG,numreg); - _mov->read(); - if (_mov->bad()) - _mov->zero(); - datacomp = (_mov->curr().get(MOV_DATACOMP)); - - if (_annomsk == 0) - datareg = rmov.get_date(RMV_DATAREG); - else - if (_annomsk != 0) - datareg = datacomp; - - gruppo = rmov.get_int(RMV_GRUPPO); - conto = rmov.get_int(RMV_CONTO); - sottoc = rmov.get_long(RMV_SOTTOCONTO); - if ((gruppo != _gruppo)||(conto != _conto)||(sottoc != _sottoc)) - break; - else - if (((annoes==_annomsk)||(_annomsk==0))&&((datareg>=_data_ini)&&(datareg<=_data_fine))) - { - trovato = TRUE; - break; - } - } - rmov.readat(record); - } - return trovato; -} - -bool TMastrini_application::data_inizio(TMask_field& f, KEY k) -{ - int anno; - TDate data; - - anno = f.mask().get_int(F_ANNO); - data = f.mask().get (F_DATAINI); - app()._annomsk = anno; - - if (k == K_ENTER) - { - if (anno != 0) - { - app().data_fine_esercizio(anno); - - if (data == botime) - app()._data_ini = app()._data_inizioese; - else - if (data < app()._data_inizioese || data > app()._data_finese) - { - f.error_box("La data non appartiene all'esercizio indicato"); - return FALSE; - } - else - app()._data_ini = data; - } - else - if (anno == 0) - { - if (data == botime) - { - f.error_box("La data deve essere obbligatoriamente indicata"); - return FALSE; - } - else - app()._data_ini = data; - } - } - return TRUE; -} - -bool TMastrini_application::data_fine(TMask_field& f, KEY k) -{ - int annoes; - TDate data, data_ini; - - annoes = f.mask().get_int(F_ANNO); - data = f.mask().get (F_DATAFINE); - data_ini = f.mask().get (F_DATAINI); - app()._annomsk = annoes; - - if (k == K_ENTER) - { - if (annoes != 0) - { - app().data_fine_esercizio(annoes); - - if (data == botime) - app()._data_fine = app()._data_finese; - else - if (data < app()._data_inizioese || data > app()._data_finese) - { - f.error_box("La data non appartiene all'esercizio indicato"); - return FALSE; - } - else - app()._data_fine = data; - } - else - if (annoes == 0) - { - if (data == botime) - { - f.error_box("La data deve essere obbligatoriamente indicata"); - return FALSE; - } - - app()._anno_ghost = date2esc(data_ini); - - app()._inizioes = app()._inizioEs; - - if (data < app()._inizioEs || data > app()._fineEs) - { - f.error_box("La data non appartiene all'esercizio indicato"); - return FALSE; - } - else - app()._data_fine = data; - } - - if (data < data_ini) - { - f.error_box("La data finale non puo' essere inferiore alla data di partenza"); - return FALSE; - } - - - } - return TRUE; -} - -void TMastrini_application::saldi_zero() -{ - TLocalisamfile& rmov = current_cursor()->file(LF_RMOV); - real saldo_dare, saldo_avere; - long record; - - saldo_dare = saldo_avere = 0; - - if (current_cursor()->is_first_match(LF_RMOV)) - { - record = rmov.recno(); - - while (!rmov.eof()) - { - rmov.read(); - char sezione = rmov.curr().get(RMV_SEZIONE)[0]; - real importo = rmov.curr().get_real(RMV_IMPORTO); - int gruppo = atoi(rmov.get(RMV_GRUPPO)); - int conto = atoi(rmov.get(RMV_CONTO)); - long sottoc = atol(rmov.get(RMV_SOTTOCONTO)); - - if ((gruppo == _gruppo)&&(conto == _conto)&&(sottoc == _sottoc)) - { - if (sezione == 'D') - saldo_dare += importo; - else if (sezione == 'A') - saldo_avere += importo; - } - else break; - rmov.next(); - } - rmov.readat(record); - } - _totale_saldo = saldo_dare - saldo_avere; -} - -void TMastrini_application::fai_stampa132() -{ - set_row (1,"@0g#t", &_dataregs); - if (_stampanum == 1) - set_row (1,"@11g$[r]#7d$[n]", &_numreg); - else - if (_stampanum == 2) - { - set_row (1,"@11g#7d", &_numgio); - } - set_row (1,"@19g#t", &_datadocs); - set_row (1,"@30g#7t", &_numdoc); - set_row (1,"@38g#3t", &_codcaus); - - set_row (1,"@117g#3t", &_g_contr); - set_row (1,"@120g#3t", &_c_contr); - set_row (1,"@123g#6t", &_s_contr); -} - -void TMastrini_application::fai_stampa198() -{ - set_row (1,"@0g#t", &_dataregs); - if (_stampanum == 1) - set_row (1,"@11g$[r]#7d$[n]", &_numreg); - else if (_stampanum == 2) - set_row (1,"@11g#7d", &_numgio); - set_row (1,"@19g#t", &_datadocs); - set_row (1,"@30g#7t", &_numdoc); - set_row (1,"@38g#3t", &_codcaus); - -// Stampa saldo movimenti - - set_row (1,"@153g#t", &_saldo_movimenti_str); - - set_row (1,"@169g#3t", &_g_contr); - set_row (1,"@172g#3t", &_c_contr); - set_row (1,"@175g#6t", &_s_contr); -} - -void TMastrini_application::stampa_totali132() -{ - TString sep(132); - - sep.fill('-'); //Stampa 132 - (sep(132)) - set_row(2,"@0g%s", (const char *) sep); - - _totprogre_dare=_progredare+_totale_periodo_dare; - _totprogre_avere=_progreavere+_totale_periodo_avere; - _saldo_periodo = _totale_periodo_dare - _totale_periodo_avere; - _saldo_progre = _totprogre_dare - _totprogre_avere; - _saldo_progre_al = _totprogre_dare_al - _totprogre_avere_al; - set_row (3,"@32gTOTALI PERIODO@69g%15.0r", &_saldo_periodo); - set_row (3,"@85g%15.0r", &_totale_periodo_dare); - set_row (3,"@101g%15.0r", &_totale_periodo_avere); - set_row (4,"@32gTOTALI PROGRESSIVI@69g%15.0r", &_saldo_progre); - set_row (4,"@85g%15.0r", &_totprogre_dare); - set_row (4,"@101g%15.0r", &_totprogre_avere); - if (_stampaprogre) //Progressivi attuali - { - set_row (5,"@32gTOTALI PROGRESSIVI AL@55g%s",(const char*)_ultima_data_reg.string()); - set_row (5,"@69g%15.0r", &_saldo_progre_al); - set_row (5,"@85g%15.0r", &_totprogre_dare_al); - set_row (5,"@101g%15.0r", &_totprogre_avere_al); - } -} - -void TMastrini_application::stampa_totali198() -{ - TString sep(198); - - sep.fill('-'); //Stampa 132 - (sep(132)) - set_row(2,"@0g%s", (const char *) sep); - - _totprogre_dare=_progredare+_totale_periodo_dare; - _totprogre_avere=_progreavere+_totale_periodo_avere; - set_row (3,"@32gTOTALI PERIODO@102g%15.0r", &_totale_periodo_dare); - set_row (3,"@119g%15.0r", &_totale_periodo_avere); - set_row (3,"@153g%15.0r", &_saldo_movimenti); - set_row (4,"@32gTOTALI PROGRESSIVI@102g%15.0r", &_totprogre_dare); - set_row (4,"@119g%15.0r", &_totprogre_avere); - set_row (4,"@136g%15.0r", &_saldo_progressivi); - if (_stampaprogre) //Progressivi attuali - { - set_row(5,"@32gTOTALI PROGRESSIVI AL@55g%s",(const char*)_ultima_data_reg.string()); - set_row (5,"@102g%15.0r", &_totprogre_dare_al); - set_row (5,"@119g%15.0r", &_totprogre_avere_al); - set_row (5,"@136g%15.0r", &_saldo_progressivi); - } -} - -bool TMastrini_application::preprocess_page(int file, int counter) -{ - TLocalisamfile & rmov = current_cursor()->file(LF_RMOV); - long rec; - TDate datasucc; - TString datasuccstring,dataregrmovstring; - int gruppof,contof; - long sottocf; - TString provvis = ""; - int annoes; - - if (counter) - return TRUE; - - switch (file) - { - case LF_SALDI: - -// Usati in crea_intestazione() - - _gruppo = atoi(current_cursor()->curr(LF_SALDI).get(SLD_GRUPPO)); - _conto = atoi(current_cursor()->curr(LF_SALDI).get(SLD_CONTO)); - _sottoc = atol(current_cursor()->curr(LF_SALDI).get(SLD_SOTTOCONTO)); - annoes = atoi(current_cursor()->curr(LF_SALDI).get(SLD_ANNOES)); - conto(_gruppo,_conto,TRUE); - - if (annoes != _anno_corrente && annoes != _anno_precedente) - return FALSE; - - if (_g_prec == _gruppo && _c_prec == _conto && _s_prec == _sottoc) - return FALSE; - - _g_prec = _gruppo; - _c_prec = _conto; - _s_prec = _sottoc; - - _saldo_periodo = ZERO; - _totale_periodo_dare = ZERO; - _totale_periodo_avere = ZERO; - _saldo_progre = ZERO; - _totprogre_dare = ZERO; - _totprogre_avere = ZERO; - _saldo_progre_al = ZERO; - _totprogre_dare_al = ZERO; - _totprogre_avere_al = ZERO; - _progredare = ZERO; - _progreavere = ZERO; - _totale_prima_dare = ZERO; - _totale_prima_avere = ZERO; - _saldo_movimenti = ZERO; - _saldo_progressivi = ZERO; - _saldo_progre_prec = ZERO; - if (_tipostampa == 2) - saldi_zero(); - else - _totale_saldo = 1; - - if ((_tipostampa == 1) || (_tipostampa == 2)) - { - if ((almeno_un_record()) && (_totale_saldo != 0)) - { - _puoi_stampare = TRUE; - calcola_progressivi(); - _saldo_progressivi += _saldo_progre_prec; - stampa_progre_riporto(); - } - else - { - _puoi_stampare = FALSE; - return FALSE; - } - } - else - if (_tipostampa == 3) - { - calcola_progressivi(); - if (_progredare == ZERO && _progreavere == ZERO && !almeno_un_record()) - { - _puoi_stampare = FALSE; - return FALSE; - } - else - { - _puoi_stampare = TRUE; - _saldo_progressivi += _saldo_progre_prec; - stampa_progre_riporto(); - } - } - break; - - case LF_RMOV: - { - // Ricerca la contropartita di quel movimento - TLocalisamfile& rmov = current_cursor()->file(LF_RMOV); - - _numreg = atol (current_cursor()->curr(LF_RMOV).get(RMV_NUMREG)); - - _gruppocontr = rmov.get_int (RMV_GRUPPOC); - _contocontr = rmov.get_int (RMV_CONTOC); - _sottocontocontr = rmov.get_long(RMV_SOTTOCONTOC); - _g_contr = rmov.get(RMV_GRUPPOC); - _c_contr = rmov.get(RMV_CONTOC); - _s_contr = rmov.get(RMV_SOTTOCONTOC); - - // Stampa solo quelli che hanno anno esercizio uguale a quello specificato - // nella maschera. Se non viene specificato li stampa tutti - - _importo = current_cursor()->curr(LF_RMOV).get_real(RMV_IMPORTO); - _importo_str = _importo.string("###############"); - _mov->setkey(1); - _mov->curr().zero(); - _mov->curr().put(MOV_NUMREG,_numreg); - _mov->read(); - if (_mov->bad()) - _mov->zero(); - _annoes = _mov->get_int(MOV_ANNOES); - _regiva = _mov->curr().get(MOV_REG); - _annoiva = _mov->curr().get_int(MOV_ANNOIVA); - - // Controlla se saldo e' diverso da 0 - - if (((_annoes == _annomsk) || (_annomsk == 0)) && (_totale_saldo != 0)) - { - _sezione = current_cursor()->curr(LF_RMOV).get(RMV_SEZIONE); - - if (_annomsk == 0) - { - _datareg = (_mov->curr().get(MOV_DATAREG)); - _datareg_stampa = _datareg; - } - else - if (_annomsk != 0) - { - _datareg = _mov->curr().get(MOV_DATACOMP); - _datareg_stampa = _mov->curr().get(MOV_DATAREG); - } - - provvis = _mov->curr().get(MOV_PROVVIS); - - _dataregs = _datareg_stampa.string(); - - if ((_stampa_mov_prov)||((!_stampa_mov_prov)&&(provvis.trim().empty()))) - { - if ((_datareg >= _data_ini) && (_datareg <= _data_fine)) - { - // Determino l' anno di competenza dell' operazione in esame - - int anno = date2esc(_datareg_stampa); - if (anno != _annoes) - if (_numcarat == 1) - set_row (1, "@131g*"); - else - if (_numcarat == 2) - set_row (1, "@197g*"); - - _codcaus = _mov->curr().get(MOV_CODCAUS); - _tipodoc = _mov->curr().get(MOV_TIPODOC); - if (_stampatotiva && (_tmcf == 'C' || _tmcf == 'F')) - { - if (_tipodoc != "") - { - documenti_iva(); - _b.add_riga(_descrdociva,_importo, _natdoc); - } - } - _datadoc = (_mov->curr().get(MOV_DATADOC)); - _datadocs = _datadoc.string(); - _numdoc = _mov->curr().get(MOV_NUMDOC); - descrizione_causale(); - _descrizionemov = _mov->curr().get(MOV_DESCR); - _numgio = atol(_mov->curr().get(MOV_NUMGIO)); - - _descrizione = current_cursor()->curr(LF_RMOV).get(RMV_DESCR); - - if (_numcarat == 1) // Stampa 132 caratteri - { - if (_descrizione != "") - { - if (_descrizionemov != "") - { - set_row (1,"@42g%.18s", (const char*) _descrizionemov); - set_row (1,"@61g%.23s", (const char*) _descrizione); - } - else if (_descrizionemov == "") - { - set_row (1,"@42g%.18s", (const char*) _descrcaus); - set_row (1,"@61g%.23s", (const char*) _descrizione); - } - } - else if (_descrizione == "") - if (_descrizionemov != "") - { - set_row (1,"@42g%.18s", (const char*) _descrcaus); - set_row (1,"@61g%.23s", (const char*) _descrizionemov); - } - else - if (_descrizionemov == "") - { - conto(_gruppocontr,_contocontr,FALSE); - TConto tc (_gruppocontr,_contocontr,_sottocontocontr,_tipo_contr); - TString descr_contr = tc.descrizione(); - set_row (1,"@42g%.18s", (const char*) _descrcaus); - set_row (1,"@61g%.23s", (const char*) descr_contr); - } - } - else - if (_numcarat == 2) // Stampa 198 caratteri - { - if (_descrizione != "") - { - if (_descrizionemov != "") - { - set_row (1,"@42g%.25s", (const char*) _descrizionemov); - set_row (1,"@68g%.32s", (const char*) _descrizione); - } - else if (_descrizionemov == "") - { - set_row (1,"@42g%.25s", (const char*) _descrcaus); - set_row (1,"@68g%.32s", (const char*) _descrizione); - } - } - else if (_descrizione == "") - if (_descrizionemov != "") - { - set_row (1,"@42g%.25s", (const char*) _descrcaus); - set_row (1,"@68g%.32s", (const char*) _descrizionemov); - } - else - if (_descrizionemov == "") - { - conto(_gruppocontr,_contocontr,FALSE); - TConto tc (_gruppocontr,_contocontr,_sottocontocontr,_tipo_contr); - TString descr_contr = tc.descrizione(); - set_row (1,"@42g%.25s", (const char*) _descrcaus); - set_row (1,"@68g%.32s", (const char*) descr_contr); - } - } - - if (_sezione == "D") - { - _totale_periodo_dare += _importo; - _riporto_parziale_dare += _importo; - - if (_numcarat == 1) // Stampa 132 caratteri - set_row (1,"@85g%s", (const char*) _importo_str); - else - if (_numcarat == 2) // Stampa 198 caratteri - { - _saldo_progressivi += _importo; - _saldo_movimenti += _importo; - set_row (1,"@102g%s", (const char*) _importo_str); - } - } - else if (_sezione == "A") - { - _totale_periodo_avere += _importo; - _riporto_parziale_avere += _importo; - - if (_numcarat == 1) // Stampa 132 caratteri - set_row (1,"@101g%s", (const char*) _importo_str); - else - if (_numcarat == 2) // Stampa 198 caratteri - { - _saldo_progressivi -= _importo; - _saldo_movimenti -= _importo; - set_row (1,"@119g%s", (const char*) _importo_str); - } - } - - _saldo_progressivi_str=_saldo_progressivi.string("###############"); - _saldo_movimenti_str=_saldo_movimenti.string("###############"); - if (_numcarat == 2) - { - ricerca_regiva(); - _protiva = atol(_mov->curr().get(MOV_PROTIVA)); - if (_protiva != 0) - set_row (1,"@191g%5d", _protiva); - - if (_tipo < 3) - set_row (1,"@182g#t" , &_regiva); - _dataregrmov = current_cursor()->curr(LF_RMOV).get_date(RMV_DATAREG); - dataregrmovstring=_dataregrmov.string(); - -//Gestire la stampa di saldo_progressivi nella postprocess_page di RMOV - - rec = rmov.recno(); - rmov.next(); - gruppof = rmov.get_int(RMV_GRUPPO); - contof = rmov.get_int(RMV_CONTO); - sottocf = rmov.get_int(RMV_SOTTOCONTO); - datasucc = rmov.get_date(RMV_DATAREG); - datasuccstring=datasucc.string(); - if (((gruppof!=_gruppo)||(contof!=_conto)||(sottocf!=_sottoc))||(rmov.eof())) - datasucc = (""); - if (datasucc != _dataregrmov) - set_row (1,"@136g#t", &_saldo_progressivi_str); - rmov.readat(rec); - } - - return TRUE; - } - else - return FALSE; - } - } - else - return FALSE; - break; - } - default: - break; - } - return TRUE; -} - -void TMastrini_application::set_page(int file, int counter) -{ - switch (file) - { - case LF_SALDI: - reset_print(); - break; - - case LF_RMOV: - reset_print(); - if (_numcarat == 1) - fai_stampa132(); - else if (_numcarat == 2) - fai_stampa198(); - break; - default: - break; - } -} - -print_action TMastrini_application::postprocess_page(int file, int counter) -{ - if (counter) - { - printer().formfeed(); - reset_print(); // per evitare che stampi di nuovo il totale prec. - _stampa_progressivi_si = TRUE; - return NEXT_PAGE; - } - - switch (file) - { - case LF_SALDI: - if (_tipostampa == 3) - { - reset_print(); - if (_numcarat == 1) - stampa_totali132(); - else if (_numcarat == 2) - stampa_totali198(); - - if (_stampatotiva) - stampa_totaliiva(); - } - else if (_tipostampa == 2) - { - reset_print(); - if ((_totale_saldo != 0) && (_puoi_stampare)) - if (_numcarat == 1) - stampa_totali132(); - else if (_numcarat == 2) - stampa_totali198(); - if (_stampatotiva) - stampa_totaliiva(); - } - else if (_tipostampa == 1) - { - reset_print(); - if (_puoi_stampare) - if (_numcarat == 1) - stampa_totali132(); - else if (_numcarat == 2) - stampa_totali198(); - if (_stampatotiva) - stampa_totaliiva(); - } - _stampa_progressivi_si = TRUE; - _prima_volta = TRUE; - return REPEAT_PAGE; - case LF_RMOV: - force_setpage(); - break; - default: - break; - } - return NEXT_PAGE; -} - -// Stampa dei totali documenti iva se richiesta - -void TMastrini_application::stampa_totaliiva() -{ - - if (_stampatotiva) - for (int j = 0; j < _b.items(); j++) - { - TDociva& riga = (TDociva&)_b[j]; - set_row(7+j, "@0g%-50s",(const char*) riga._descrdoc); - set_row(7+j, "@61g%15.0r", &riga._totdociva); - } - _b.destroy(); -} - -// Ricerca della descrizione relativa al codice causale di MOV.dta -// sull'archivio CAUS.dta - -void TMastrini_application::descrizione_causale() -{ - _caus->setkey(1); - _caus->curr().zero(); - _caus->curr().put(CAU_CODCAUS, _codcaus); - _caus->read(); - if (_caus->bad()) - _caus->zero(); - _descrcaus = _caus->curr().get(CAU_DESCR); -} - -// Ricerca sulla tabella dei tipi documento, la descrizione e la natura del -// documento, accedendovi tramite il tipo documento trovato su MOV.dta - -void TMastrini_application::documenti_iva() -{ - TString dep; - - _tabtpd->curr().zero(); - dep << format ("%2s",(const char*) _tipodoc); - _tabtpd->curr().put("CODTAB", (const char*) dep); - _tabtpd->read(); - _descrdociva = _tabtpd->curr().get("S0"); - _natdoc = atoi(_tabtpd->curr().get("I0")); -} - -void TMastrini_application::ricerca_regiva() -{ - TString16 dep; - - _tabreg->curr().zero(); - dep << format("%04d", _annoiva); - dep << format("%3s" , (const char*) _regiva); - _tabreg->curr().put("CODTAB", (const char*) dep); - _tabreg->read(); - _tipo = _tabreg->get_int("I0"); -} - -bool TMastrini_application::preprocess_print(int file, int counter) -{ - if (file == LF_SALDI) - { - _g_prec = 0; - _c_prec = 0; - _s_prec = 0; - - _saldo_periodo = ZERO; - _totale_periodo_dare = ZERO; - _totale_periodo_avere = ZERO; - _saldo_progre = ZERO; - _totprogre_dare = ZERO; - _totprogre_avere = ZERO; - _saldo_progre_al = ZERO; - _totprogre_dare_al = ZERO; - _totprogre_avere_al = ZERO; - _progredare = ZERO; - _progreavere = ZERO; - _totale_prima_dare = ZERO; - _totale_prima_avere = ZERO; - _saldo_movimenti = ZERO; - _saldo_progressivi = ZERO; - _saldo_progre_prec = ZERO; - _protiva = 0; - - _prima_volta = TRUE; - - _stampa_progressivi_si = TRUE; - } - - return TRUE; -} - -bool TMastrini_application::set_print(int) -{ - KEY tasto; - int crt; - TLocalisamfile* fl; - TString data1,data2; - - _puoi_stampare = TRUE; - - _msk->set_handler (F_DATAINI , data_inizio); - _msk->set_handler (F_DATAFINE , data_fine); - - - tasto = _msk->run(); - - if (tasto == K_ENTER) - { - _annomsk = atoi(_msk->get(F_ANNO)); - - _stampaprogre = (bool)(_msk->get(F_STAMPAPROGRE) == "X"); - _stampatotiva = (bool)(_msk->get(F_STAMPATOTIVA) == "X"); - _stampanum = atoi(_msk->get(F_STAMPANUM)); - _stampa_mov_prov = (bool)(_msk->get(F_STAMPAMOVPROV) == "X"); - int gruppoini = atoi(_msk->get(F_GRUPPOINI)); - int contoini = atoi(_msk->get(F_CONTOINI_CONTO)); - long sottocontoini = atol(_msk->get(F_SOTTOCINI_CONTO)); - int gruppofine = atoi(_msk->get(F_GRUPPOFINE)); - int contofine = atoi(_msk->get(F_CONTOFINE_CONTO)); - long sottocontofine = atol(_msk->get(F_SOTTOCFINE_CONTO)); - _tipostampa = atoi(_msk->get(F_TIPOSTAMPA)); - _numcarat = atoi(_msk->get(F_NUMCARAT)); - int formato = atoi(_msk->get(F_FORMATO)); - int nummast = atoi(_msk->get(F_NUMMAST)); - _codice_ditta = get_firm(); - - ricerca_dati_ditta(); - - if (_annomsk != 0) - _anno_corrente = _annomsk; - else - if (_annomsk == 0) - _anno_corrente = _anno_ghost; - - _anno_precedente = _anno_corrente - 1; - -// Scelta del formato e del numero di mastrini per pagina 1 o 2 - - if (nummast == 1) - crt = formato; - else - crt = (formato / 2); - - printer().formlen(crt); - -//Crea il cursore su gruppo, conto e sottoconto del file RMOV - - reset_files(); //resetta l'albero di stampa - add_file(LF_SALDI); - add_file(LF_RMOV,LF_SALDI); - - select_cursor(_cur1); - fl = &(current_cursor()->file(LF_SALDI)); - TRectype da (fl->curr()); - TRectype a (fl->curr()); - - da.zero(); - a.zero(); - - da.put(SLD_GRUPPO,gruppoini); - da.put(SLD_CONTO,contoini); - da.put(SLD_SOTTOCONTO,sottocontoini); - - a.put(SLD_GRUPPO,gruppofine); - a.put(SLD_CONTO,contofine); - a.put(SLD_SOTTOCONTO,sottocontofine); - - current_cursor()->setregion(da, a); - - if (_stampatotiva) - _b.destroy(); - - switch (_tipostampa) - { - case 1: _totale_saldo = 1; - break; - case 2: _totale_saldo = 0; - break; - case 3: _totale_saldo = 1; - break; - default: break; - } - - enable_print_menu(); - - enable_link("Collegamento prima nota: ", 'r'); - - return TRUE; - } - else - return FALSE; -} - -void TMastrini_application::data_fine_esercizio(int anno) -{ - TString16 dep; - - _tabesc->curr().zero(); - dep << format ("%04d", anno); - _tabesc->curr().put("CODTAB", (const char*) dep); - _tabesc->read(); - _data_finese = _tabesc->curr().get("D1"); - _data_inizioese = _tabesc->curr().get("D0"); -} - -void TMastrini_application::preprocess_header() -{ - if (_tipostampa == 3) - crea_intestazione(); - else - if (_tipostampa == 2) - { - if ((_totale_saldo != 0) && (_puoi_stampare)) - crea_intestazione(); - } - else if (_tipostampa == 1) - if (_puoi_stampare) - crea_intestazione(); -} - -void TMastrini_application::conto(int gruppo, int conto, bool no_contropartita) -{ - TLocalisamfile pconti(LF_PCON); - - pconti.setkey(1); - pconti.zero(); - pconti.put(PCN_GRUPPO, gruppo); - pconti.put(PCN_CONTO , conto); - pconti.read(); - if (pconti.bad()) - pconti.zero(); - - if (no_contropartita) - { - _indbil = pconti.get_int(PCN_INDBIL); - _tmcf = pconti.get_char(PCN_TMCF); - } - else - _tipo_contr = pconti.get_char(PCN_TMCF); -} - -void TMastrini_application::ricerca_dati_ditta() -{ - long app; - - _nditte->setkey(1); - _nditte->curr().zero(); - _nditte->curr().put(NDT_CODDITTA,_codice_ditta); - _nditte->read(); - app=_nditte->curr().get_long(NDT_CODDITTA); - _ragsoc=_nditte->curr().get(NDT_RAGSOC); - - _unloc->setkey(1); - _unloc->curr().zero(); - _unloc->curr().put(ULC_CODDITTA,app); - _unloc->curr().put(ULC_CODULC,"1"); - _unloc->read(); - _indulc=_unloc->curr().get(ULC_INDULC); - _civulc=_unloc->curr().get(ULC_CIVULC); - _capulc=_unloc->curr().get(ULC_CAPULC); - _comulc=_unloc->curr().get(ULC_COMULC); - - _comuni->setkey(1); - _comuni->curr().zero(); - _comuni->curr().put(COM_COM,_comulc); - _comuni->read(); - _com=_comuni->curr().get(COM_DENCOM); - _prov=_comuni->curr().get(COM_PROVCOM); -} - -// Crea l'intestazione per la stampa a 132 e a 198 caratteri - -void TMastrini_application::crea_intestazione() -{ - TString sep(132),sep1(198); - - reset_header(); - - if (_numcarat == 1) - { - sep << "Pag. @#"; - sep.right_just(132); - set_header(1,(const char*) sep); - sep =""; - set_header(2,"@1g%s",(const char*) sep); - } - else if (_numcarat == 2) - { - sep1 << "Pagina @#"; - sep1.right_just(198); - set_header(1,(const char*) sep1); - sep1 =""; - set_header(2,"@1g%s",(const char*) sep1); - } - - set_header (1, "@0gDITTA@6g%5ld", _codice_ditta); - set_header (1, "@12g%-45s", (const char*) _ragsoc); - set_header (1, "@59g%-25s", (const char*) _indulc); - set_header (1, "@86g%-9s", (const char*) _civulc); - set_header (1, "@97g%-5s", (const char*) _capulc); - set_header (1, "@103g%-18s", (const char*) _com); - set_header (1, "@122g%-3s", (const char*) _prov); - - set_header (3, "@0gSottoconto@12g%d", _gruppo); - set_header (3, "@16g%d", _conto); - set_header (3, "@20g%ld", _sottoc); - - if (_tmcf == 'C') - _tipo_mask = 1; - else if (_tmcf == 'F') - _tipo_mask = 2; - else if (_tmcf == '\0') - _tipo_mask = 3; - switch (_tipo_mask) - { - case 1: ricerca_clifo(); - break; - case 2: ricerca_clifo(); - break; - case 3: ricerca_gruppo(); - break; - default: break; - } - - if (_numcarat == 1) - { - sep.fill('-'); //Stampa 132 - (sep(132)) - set_header (6, (const char *) sep); - set_header (7,"Operazione@19gDocumento@117gContro@131gA"); - set_header (8,"Data"); - if (_stampanum < 3) - set_header (8,"@11gnumero"); - set_header (8,"@19gData@30gNumero@38gCod.Causale@61gDescrizione@96gDare@111gAvere@117gPartita@131gC"); - sep.fill('-'); - set_header (9, (const char *) sep); - } - else if (_numcarat == 2) - { - sep1.fill('-'); //Stampa 198 - (sep1(198)) - set_header (6,"@1g%s", (const char *) sep1); - set_header (7,"Operazione@19gData@30gNumero@172gContro@182gReg@190gNumero@197gA"); - set_header (8,"Data"); - if (_stampanum < 3) - set_header (8,"@11gnumero"); - set_header (8,"@19gDocumento@38gCod.Causale@68gDescrizione@113gDare@129gAvere@136gSaldo progress.@156gSaldo movim.@172gPartita@182gIva@186gProtocollo@197gC"); - sep1.fill('-'); - set_header (9,"@1g%s", (const char *) sep1); - } -} - -void TMastrini_application::stampa_progre_riporto() -{ - TString sep(132),sep1(198); - - if (_stampa_progressivi_si) - { - stampa_progressivi(); - _riporto_dare = _progredare; - _riporto_avere = _progreavere; - _stampa_progressivi_si = FALSE; - } - else - { - _riporto_dare += _riporto_parziale_dare; - _riporto_avere += _riporto_parziale_avere; - if (_numcarat == 1) - { - TString string = _riporto_dare.string("###############"); - set_row (1,"@32gA RIPORTO@85g%15s",(const char*) string); - string = _riporto_avere.string("###############"); - set_row (1,"@101g%15s",(const char*) string); - } - if (_numcarat == 2) - { - TString string = _riporto_dare.string("###############"); - set_row (1,"@32gA RIPORTO@102g%15s",(const char*) string); - string = _riporto_avere.string("###############"); - set_row (1,"@119g%15s",(const char*) string); - } - _riporto_parziale_dare = 0; - _riporto_parziale_avere = 0; - } - if (_numcarat == 1) - { - sep =""; - set_row(2,"@1g%s",(const char*) sep); - } - else if (_numcarat == 2) - { - sep1 =""; - set_row(2,"@1g%s",(const char*) sep1); - } -} - -void TMastrini_application::calcola_progressivi_al() -{ - long record,sottoc,annoes; - int gruppo,conto; - TDate datareg, datacomp; - TLocalisamfile & rmov = current_cursor()->file(LF_RMOV); - char sezione; - real importo; - TDate data; - - - record = rmov.recno(); - rmov.zero(); - rmov.put(RMV_GRUPPO, _gruppo); - rmov.put(RMV_CONTO, _conto); - rmov.put(RMV_SOTTOCONTO, _sottoc); - for (rmov.read();!rmov.eof() ;rmov.next()) - { - annoes = rmov.get_int (RMV_ANNOES); - datareg = rmov.get_date(RMV_DATAREG); - sezione = rmov.get (RMV_SEZIONE)[0]; - importo = rmov.get_real(RMV_IMPORTO); - long numreg = rmov.get_long(RMV_NUMREG); - - _mov->setkey(1); - _mov->curr().zero(); - _mov->curr().put(MOV_NUMREG,numreg); - _mov->read(); - if (_mov->bad()) - _mov->zero(); - datacomp = (_mov->curr().get(MOV_DATACOMP)); - - if (_annomsk == 0) - { - datareg = rmov.get_date(RMV_DATAREG); - data = _inizioes; - } - else - if (_annomsk != 0) - { - datareg = datacomp; - data = _data_inizioese; - } - - gruppo = rmov.get_int(RMV_GRUPPO); - conto = rmov.get_int(RMV_CONTO); - sottoc = rmov.get_long(RMV_SOTTOCONTO); - if ((gruppo != _gruppo)||(conto != _conto)||(sottoc != _sottoc)) - break; - else if (((annoes==_annomsk)||(_annomsk == 0))&&(datareg >= data)&&(datareg < _data_ini)) //Legge movimenti con data < data iniziale - if (sezione == 'D') - _totale_prima_dare += importo; - else if (sezione == 'A') - _totale_prima_avere += importo; - } - rmov.readat(record); -} - -void TMastrini_application::calcola_progressivi() -{ - TLocalisamfile saldi(LF_SALDI, FALSE); - real pdaresca,paveresca,pdarescap,paverescap; - real progdare_attuale,progavere_attuale,progdare_prec,progavere_prec; - real saldo,progredare_eseprec,progreavere_eseprec,pdarep,paverep; - char salini; - - saldo = ZERO; - pdarep = ZERO; - paverep = ZERO; - pdaresca = ZERO; - paveresca = ZERO; - pdarescap = ZERO; - paverescap = ZERO; - -// Ricerca sull'archivio saldi dei record con gruppo,conto,sottoconto -// uguali a quelli di rmov per il calcolo dei progressivi precedenti - - TRectype record(saldi.curr()); - - record.zero(); - record.put(SLD_GRUPPO, _gruppo); - record.put(SLD_CONTO, _conto); - record.put(SLD_SOTTOCONTO, _sottoc); - - saldi.setkey(2); - - saldi.zero(); - saldi.put(SLD_GRUPPO, _gruppo); - saldi.put(SLD_CONTO, _conto); - saldi.put(SLD_SOTTOCONTO, _sottoc); - - for (saldi.read(_isgteq); saldi.good(); saldi.next()) - { - if (saldi.curr() != record) - break; - - int annoes_saldi = saldi.curr().get_int(SLD_ANNOES); - -//Calcola i progressivi dell'esercizio attuale - - if (annoes_saldi == _anno_corrente) - { - pdaresca = saldi.get_real(SLD_PDARESCA); - paveresca = saldi.get_real(SLD_PAVERESCA); - progdare_attuale = saldi.get_real(SLD_PDARE); - progavere_attuale = saldi.get_real(SLD_PAVERE); - saldo = saldi.get_real(SLD_SALDO); - salini = saldi.get(SLD_FLAGSALINI)[0]; - _ultima_data_reg = saldi.get_date(SLD_DATAULMOV); - } - -//Calcola i progressivi dell'esercizio precedente - - if (annoes_saldi == _anno_precedente) - { - pdarescap = saldi.get_real(SLD_PDARESCA); - pdarep = saldi.get_real(SLD_PDARE); - paverescap = saldi.get_real(SLD_PAVERESCA); - paverep = saldi.get_real(SLD_PAVERE); - } - -// Se il saldo dell'esercizio attuale e' diverso da 0 allora significa che -// quello corrisponde al saldo finale dell'esercizio precedente. Per ottenere -// i progressivi dell'esercizio precedente devo a questo punto sommare i -// progressivi dell'esercizio e i progressivi di quelli scaricati, tenendo -// conto del flag salini per sapere se il saldo e' dare oppure avere. - - - if (_annomsk != 0 && _anno_corrente == annoes_saldi) - { - if (saldo != ZERO) - { - if (salini == 'D') - { - progredare_eseprec = saldo;// + pdarescap + pdarep; - progdare_prec = saldo; - } - else if (salini == 'A') - { - progreavere_eseprec = saldo;// + paverescap + paverep; - progavere_prec = saldo; - } - } - } - } // FOR - -//Se il saldo dell'esercizio attuale non e' diverso da zero, allora il saldo -// finale dell'esercizio precedente devo calcolarmelo tenendo conto dell'indbil - - if (_annomsk != 0 && saldo == ZERO) - { - if ((_indbil == 1) || (_indbil == 2) || (_indbil == 5)) - { - const TRecnotype pos = saldi.recno(); - saldo = _sld->saldofin_esprec(_anno_corrente,_gruppo,_conto,_sottoc); - saldi.readat(pos); - - if (saldo> ZERO) - { - progredare_eseprec = saldo;// + pdarescap + pdarep; - progdare_prec = saldo; - } - else if (saldo < ZERO) - { - saldo = -saldo; - progreavere_eseprec = saldo;// + paverescap + paverep; - progavere_prec = saldo; - } - } - } - - calcola_progressivi_al(); - -//Calcolo dei progressivi precedenti: somma di tutti quei movimenti di rmov -//che hanno la data di registrazione inferiore alla data di inizio stampa, -//dei progressivi dell'anno esercizio precedente, e dei progressivi dei -//movimenti scaricati dell'esercizio attuale. - - _progredare = pdaresca + progredare_eseprec + _totale_prima_dare; - _progreavere = paveresca + progreavere_eseprec + _totale_prima_avere; - _saldo_progre_prec = _progredare - _progreavere; - -//Calcolo dei progressivi al - -//Se sulla maschera e' stato selezionato il controllo competenza esercizio -//Sommo i progressivi dell'esercizio precedente e quelli dell'esercizio attuale -//altrimenti solo quelli dell'esercizio attuale - - if (_annomsk != 0) - { - _totprogre_dare_al = progdare_attuale + progdare_prec; - _totprogre_avere_al = progavere_attuale + progavere_prec; - } - else - { - _totprogre_dare_al = progdare_attuale; - _totprogre_avere_al = progavere_attuale; - } -} - -void TMastrini_application::stampa_progressivi() -{ - if (_numcarat == 1) - { - TString string = _saldo_progre_prec.string("###############"); - set_row (1,"@32gPROGRESSIVI PRECEDENTI@69g%15s",(const char*) string); - string = _progredare.string("###############"); - set_row (1,"@85g%15s",(const char*) string); - string = _progreavere.string("###############"); - set_row (1,"@101g%15s",(const char*) string); - } - - if (_numcarat == 2) - { - TString string = _progredare.string("###############"); - set_row (1,"@32gPROGRESSIVI PRECEDENTI@102g%15s",(const char*)string); - string = _progreavere.string("###############"); - set_row (1,"@119g%15s",(const char*) string); - string = _saldo_progre_prec.string("###############"); - set_row (1,"@136g%15s",(const char*) string); - } -} - -// Se la ricerca selezionata nella maschera e' per clienti, oppure fornitori, // allora ricerco su CLIFO i relativi dati, e su PCON il relativo gruppo,conto,// sottoconto e IV direttiva CEE - -void TMastrini_application::ricerca_clifo() -{ - TString ragsoc,paiv,cofi,indcf,capcf,ptel,tel,statocf,comcf,dencom,provcom,dep; - TLocalisamfile clifo(LF_CLIFO); - TLocalisamfile pconti(LF_PCON); - TString16 dataini,datafine; - TString descriz,descriz2; - int numrivd; - - clifo.setkey(1); - clifo.zero(); - clifo.put(CLI_TIPOCF, _tmcf); - clifo.put(CLI_CODCF, _sottoc); - clifo.read(); - if (clifo.bad()) - clifo.zero(); - TConto tc (_gruppo,_conto,_sottoc,_tmcf); - - ragsoc = tc.descrizione(); - paiv = clifo.get(CLI_PAIV); - cofi = clifo.get(CLI_COFI); - indcf = clifo.get(CLI_INDCF); - capcf = clifo.get(CLI_CAPCF); - ptel = clifo.get(CLI_PTEL); - tel = clifo.get(CLI_TEL); - statocf = clifo.get(CLI_STATOCF); - comcf = clifo.get(CLI_COMCF); - - _comuni->setkey(1); - _comuni->curr().zero(); - _comuni->curr().put(COM_STATO, statocf); - _comuni->curr().put(COM_COM, comcf); - _comuni->read(); - dencom = _comuni->curr().get(COM_DENCOM); - provcom = _comuni->curr().get(COM_PROVCOM); - - pconti.setkey(1); - pconti.zero(); - pconti.put(PCN_GRUPPO, _gruppo); - pconti.put(PCN_CONTO, _conto); - pconti.read(); - _sezivd = pconti.get_char(PCN_SEZIVD); - _lettivd = pconti.get_char(PCN_LETTIVD); - numrivd = pconti.get_int(PCN_NUMRIVD); - _numrivd = itor(numrivd); - _numivd = pconti.get_int(PCN_NUMIVD); - - descriz = descrizione_classe(_sezivd,_lettivd,numrivd,_numivd); - - if (_numivd != 0) //Ora devo stampare la descrizione del livello della - { //classe immediatamente precedente a quello appena - if (_numrivd != "") //stampato - descriz2 = descrizione_classe(_sezivd,_lettivd,_numrivd_int,0); - else - descriz2 = descrizione_classe(_sezivd,_lettivd,0,0); - } - else - if (_numrivd != "") - descriz2 = descrizione_classe(_sezivd,_lettivd,0,0); - else - descriz2 = ""; - - set_header(3,"@27g%-30s",(const char*) descrizione_gruppo()); - set_header(3,"@59g%-30s",(const char*) descrizione_conto()); - set_header(3, "@91g%-30s",(const char*) ragsoc); - set_header(4, "Classe@8g%c", _lettivd); - set_header(4, "@10g%-8s", (const char*) _numrivd); - if (_numivd != 0) - set_header(4, "@19g%2d", _numivd); - if (descriz2 != "") - { - set_header(4,"@23g%-50s",(const char*) descriz2); - set_header(4,"@80g%-50s",(const char*) descriz); - } - else - set_header(4,"@23g%-50s",(const char*) descriz); - - dataini = _data_ini.string(); - datafine = _data_fine.string(); - - if (_annomsk == 0) - { - set_header (5, "Periodo@10g%s", (const char*) dataini); - set_header (5, "@22g%s", (const char*) datafine); - } - else - { - set_header (5, "Comp. da@9g%s", (const char*) dataini); - set_header (5, "@20ga@22g%s", (const char*) datafine); - } - - set_header (5, "@33gP.I.@37g%-11s",(const char*) paiv); - set_header (5, "@49gCF@52g%-16s",(const char*) cofi); - set_header (5, "@69g%-25s",(const char*) indcf); - set_header (5, "@95g%-5s",(const char*) capcf); - set_header (5, "@101g%-24s",(const char*) dencom); - set_header (5,"@126g%-5s",(const char*) provcom); - - if (_numcarat == 2) - { - set_header (5,"@134g%-4s",(const char*) ptel); - set_header (5,"@138g/@139g%-10s",(const char*) tel); - } -} - -// Se la ricerca selezionata sulla maschera e' per gruppo, conto, sottoconto -// ricerca i corrispondenti su PCON, con relativa IV direttiva CEE - -void TMastrini_application::ricerca_classe_IV(bool scelta) -{ - TLocalisamfile pconti(LF_PCON); - - pconti.setkey(1); - pconti.zero(); - pconti.put(PCN_GRUPPO, _gruppo); - pconti.put(PCN_CONTO, _conto); - if (scelta) - pconti.put(PCN_SOTTOCONTO, _sottoc); - pconti.read(); - _sezivd = pconti.get_char(PCN_SEZIVD); - _lettivd = pconti.get_char(PCN_LETTIVD); - _numrivd_int = pconti.get_int (PCN_NUMRIVD); - _numrivd = itor(_numrivd_int); - _numivd = pconti.get_int (PCN_NUMIVD); - _descr = pconti.get (PCN_DESCR); -} - -void TMastrini_application::ricerca_gruppo() -{ - TString80 descr,descriz,descriz2,dep; - TString dataini,datafine; - - ricerca_classe_IV (TRUE); //Esiste a livello di sottoconto - - if (_sezivd == '0') //Non esiste a livello di sottoconto - ricerca_classe_IV (FALSE); //Allora la cerco a livello di conto - - descriz = descrizione_classe(_sezivd,_lettivd,_numrivd_int,_numivd); - if (_numivd != 0) //Ora devo stampare la descrizione del livello della - { //classe immediatamente precedente a quello appena - if (_numrivd != "") //stampato - descriz2 = descrizione_classe(_sezivd,_lettivd,_numrivd_int,0); - else - descriz2 = descrizione_classe(_sezivd,_lettivd,0,0); - } - else - if (_numrivd != "") - descriz2 = descrizione_classe(_sezivd,_lettivd,0,0); - else - descriz2 = ""; - - set_header(3,"@27g%-30s",(const char*) descrizione_gruppo()); - set_header(3,"@59g%-30s",(const char*) descrizione_conto()); - - set_header(3,"@91g%-30s",(const char*) _descr); - set_header(4, "@0gClasse@12g%c", _lettivd); - set_header(4, "@14g%-8s",(const char*) _numrivd); - if (_numivd != 0) - set_header(4, "@23g%d", _numivd); - if (descriz2 != "") - { - set_header(4,"@27g%-50s",(const char*) descriz2); - set_header(4,"@80g%-50s",(const char*) descriz); - } - else - set_header(4,"@27g%-50s",(const char*) descriz); - - dataini = _data_ini.string(); - datafine = _data_fine.string(); - - if (_annomsk == 0) - { - set_header (5, "Periodo@12g%s", (const char*) dataini); - set_header (5, "@24g%s", (const char*) datafine); - } - else - { - set_header (5, "Periodo di competenza@23g%s", (const char*) dataini); - set_header (5, "@35g%s", (const char*) datafine); - } -} - -const char* TMastrini_application::descrizione_classe(char sezione, char lettera, int numr, int numero) -{ - TTable tabivd(TAB_IVD); - TString dep,dep2; - - tabivd.zero(); - if (numr == 0 && numero == 0) - dep = format("%c%c",sezione,lettera); - else - if (numero == 0) - { - if (numr != 0) - dep = format("%1c%1c%04d",sezione, lettera, numr); - else - dep = format("%c%c ",sezione,lettera); - } - else - { - if (numr != 0) - dep = format("%1c%1c%04d%02d",sezione, lettera, numr,numero); - else - dep = format("%c%c %02d",sezione,lettera,numero); - } - - tabivd.put("CODTAB", dep); - tabivd.read(); - dep2 = tabivd.get("CODTAB"); - if (dep == dep2) - tmp = tabivd.get("S0"); - else - tmp = ""; - return (tmp); -} - -//Ricerca la descrizione relativa al gruppo da stampare - -const char* TMastrini_application::descrizione_gruppo() -{ - TLocalisamfile pconti(LF_PCON); - - pconti.zero(); - pconti.put(PCN_GRUPPO,_gruppo); - if (pconti.read() != NOERR) pconti.zero(); - tmp = pconti.get(PCN_DESCR); - return tmp; -} - -// Ricerca la descrizione relativa al conto da stampare - -const char* TMastrini_application::descrizione_conto() -{ - TLocalisamfile pconti(LF_PCON); - - pconti.zero(); - pconti.put(PCN_GRUPPO,_gruppo); - pconti.put(PCN_CONTO,_conto); - if (pconti.read() != NOERR) pconti.zero(); - tmp = pconti.get(PCN_DESCR); - return tmp; -} - -bool TMastrini_application::user_create() -{ - TToken_string exp; - - _rel = new TRelation (LF_SALDI); - - exp.add("GRUPPO=GRUPPO"); - exp.add("CONTO=CONTO"); - exp.add("SOTTOCONTO=SOTTOCONTO"); - _rel->add(LF_RMOV,exp,2,LF_SALDI); - - _cur1=add_cursor(new TCursor(_rel,"",2)); - - _nditte = new TLocalisamfile (LF_NDITTE); - _unloc = new TLocalisamfile (LF_UNLOC); - _comuni = new TLocalisamfile (LF_COMUNI); - _mov = new TLocalisamfile (LF_MOV); - _clifo = new TLocalisamfile (LF_CLIFO); - _caus = new TLocalisamfile (LF_CAUSALI); - _tabivd = new TTable (TAB_IVD); - _tabtpd = new TTable (TAB_TPD); - _tabreg = new TTable (TAB_REG); - _tabesc = new TTable (TAB_ESC); - _sld = new TSaldo (); - - _msk = new TMask("cg3200a"); - _msk->set_handler(F_SOTTOCINI_CONTO, sottoc_handler_ini); - _msk->set_handler(F_SOTTOCINI_CLIENTE, sottoc_handler_ini); - _msk->set_handler(F_SOTTOCINI_FORN, sottoc_handler_ini); - _msk->set_handler(F_SOTTOCFINE_CONTO, sottoc_handler_fine); - _msk->set_handler(F_SOTTOCFINE_CLIENTE, sottoc_handler_fine); - _msk->set_handler(F_SOTTOCFINE_FORN, sottoc_handler_fine); - - _inizio_stampa = TRUE; - return TRUE; -} - -bool TMastrini_application::user_destroy() -{ - delete _msk; - delete _rel; - delete _mov; - delete _nditte; - delete _unloc; - delete _comuni; - delete _clifo; - delete _caus; - delete _tabivd; - delete _tabtpd; - delete _tabreg; - delete _tabesc; - delete _sld; - - return TRUE; - -} - -int cg3200(int argc, char* argv[]) -{ - - TMastrini_application a; - - a.run(argc, argv, "Stampa Mastrini"); - - return 0; -} - +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cg3.h" +#include "cg3200.h" +#include "cglib.h" +#include "cglib03.h" + +static TString256 tmp; + +int date2esc(const TDate& d, int* prevesc = NULL); +bool sottoc_handler_ini (TMask_field& f, KEY k); +bool sottoc_handler_fine (TMask_field& f, KEY k); + +class TMastrini_application : public TPrintapp +{ + static bool data_inizio (TMask_field& f, KEY k); + static bool data_fine (TMask_field& f, KEY k); + static bool gruppo_hnd (TMask_field& f, KEY k); + static bool conto_hnd (TMask_field& f, KEY k); + static bool sottoc_hnd (TMask_field& f, KEY k); + friend bool sottoc_handler_ini (TMask_field& f, KEY k); + friend bool sottoc_handler_fine (TMask_field& f, KEY k); + + TDociva_array _b; + TRelation* _rel; + TMask* _msk; + TTable* _tabivd, * _tabtpd, * _tabreg, * _tabesc; + TLocalisamfile* _mov; + TLocalisamfile* _nditte; + TLocalisamfile* _unloc; + TLocalisamfile* _comuni; + TLocalisamfile* _clifo; + TLocalisamfile* _caus; + Saldo* _sld; + + TDate _data_ini,_data_fine,_data_finese,_data_finesesucc,_ultima_data_reg; + TDate _datareg,_datadoc,_data_inizioese,_datareg_stampa,_inizioes; + int _cur1,_gruppo,_conto,_numcarat,_stampanum,_numivd,_annoiva; + int _numrig,_natdoc,_tipo,_tipostampa,_g_prec,_c_prec,_numrivd_int; + real _progredare,_progreavere,_totprogre_dare_al,_totprogre_avere_al; + real _totprogre_dare,_totprogre_avere,_importo; + real _riporto_dare,_riporto_avere,_riporto_parziale_dare,_riporto_parziale_avere; + real _totale_periodo_dare,_totale_periodo_avere,_totale_prima_dare,_totale_prima_avere; + real _saldo_periodo,_saldo_progre,_saldo_progre_al,_saldo_progre_prec; + real _saldo_movimenti,_saldo_progressivi,_totale_saldo; + TString _ragsoc,_indulc,_civulc,_capulc,_com,_prov,_comulc; + long _codice_ditta,_s_prec; + TString _tipodoc,_codcaus,_descrcaus,_descrdociva,_regiva,_g_contr,_c_contr,_s_contr; + char _sezivd,_lettivd; + TString _descrizione,_sezione,_numdoc,_descrizionemov,_numrivd,_descr; + TString _dataregs, _datadocs; + int _gruppocontr,_contocontr; + long _sottocontocontr; + + bool _stampaprogre,_stampatotiva,_stampatot,_prima_volta,_stampa_mov_prov; + + int _annomsk,_annoesmsk,_annoes,_annomsksucc,_tipo_mask,_anno_ghost; + int _anno_corrente,_anno_precedente,_indbil; + long _sottoc,_numreg,_numgio,_protiva; + bool _stampa_progressivi_si,_competenza,_inizio_stampa,_puoi_stampare; + char _tmcf,_tipo_contr; + + TDate _dataregrmov; + int _gruppof,_contof; + long _sottocf; + TString _dataregrmovstring,_importo_str,_saldo_movimenti_str,_saldo_progressivi_str; + +protected: + virtual bool user_create() ; + virtual bool user_destroy(); + virtual bool set_print(int m); + + virtual bool preprocess_print(int file, int counter); + virtual bool preprocess_page (int,int); + virtual print_action postprocess_page (int,int); + virtual print_action postprocess_print(int,int); + virtual void preprocess_header(); + virtual void set_page(int,int); + virtual void process_link(int id, const char* txt); + +public: + TDate _inizioEs,_fineEs; + void ricerca_clifo(); + void ricerca_gruppo(); + void calcola_progressivi(); + void calcola_progressivi_al(); + void stampa_progressivi(); + void stampa_progre_riporto(); + void documenti_iva(); + void ricerca_regiva(); + void descrizione_causale(); + void saldi_zero(); + void crea_intestazione(); + void fai_stampa132(); + void fai_stampa198(); + void stampa_totali132(); + void stampa_totali198(); + void stampa_totaliiva(); + void ricerca_classe_IV(bool scelta); + void data_fine_esercizio(int); + const char* descrizione_gruppo(); + const char* descrizione_conto(); + const char* descrizione_classe(char,char,int,int); + bool almeno_un_record(); + void ricerca_dati_ditta(); + void conto(int,int,bool); + + TMastrini_application() {} +}; + +HIDDEN TMastrini_application& app() { return (TMastrini_application&) main_app(); } + +void TMastrini_application::process_link(int id, const char* txt) +{ + const char* const app = "cg2 -0"; + TToken_string ss(10); + ss.add("1"); + ss.add(txt); + + TMessage fs(cmd2name(app), MSG_LN, ss); + fs.send(); + + TExternal_app pn(app); + pn.run(); +} + +bool sottoc_handler_ini(TMask_field& f, KEY key) +{ + const short id = f.dlg(); + const int gruppo = f.mask().get_int(F_GRUPPOINI); + const int conto = f.mask().get_int(F_CONTOINI_CONTO); + const long sottoconto = f.mask().get_long(id); + TString ds; + TString80 rs; + TLocalisamfile pconti (LF_PCON); + + if ( key == K_ENTER ) + { + if (sottoconto != 0 && conto == 0) + return f.warning_box("Manca il CONTO"); + + if (conto != 0 && gruppo == 0) + return f.warning_box("Manca il GRUPPO"); + } + + if ( key == K_TAB ) + { + if (id == F_SOTTOCINI_CONTO) + { + pconti.zero(); + pconti.put(PCN_GRUPPO, gruppo) ; + pconti.put(PCN_CONTO, conto); + pconti.put(PCN_SOTTOCONTO, sottoconto); + pconti.setkey(1); + pconti.read(_isequal, _nolock); + if (pconti.good()) + ds = pconti.get(PCN_DESCR); + else + ds = ""; + + f.mask().set(F_DESCRINI_CONTO, ds); + f.mask().set(F_DESCRINI_CLIENTE, ds); + f.mask().set(F_DESCRINI_FORN, ds); + } + if (id == F_SOTTOCINI_CLIENTE || id == F_SOTTOCINI_FORN) + { + char tipo = id == F_SOTTOCINI_CLIENTE ? 'C' : 'F'; + TLocalisamfile clifo (LF_CLIFO); + if (sottoconto != 0) + { + clifo.zero(); + clifo.put(CLI_TIPOCF,tipo); + clifo.put(CLI_CODCF, sottoconto) ; + clifo.setkey(1); + if (clifo.read(_isequal, _nolock) == NOERR) + rs = clifo.get(CLI_RAGSOC); + else + rs = ""; + + f.mask().set(F_DESCRINI_CLIENTE, rs); + f.mask().set(F_DESCRINI_FORN, rs); + } + else + if (gruppo != 0 && conto != 0) + { + pconti.zero(); + pconti.put(PCN_GRUPPO, gruppo) ; + pconti.put(PCN_CONTO, conto); + pconti.setkey(1); + pconti.read(_isequal, _nolock); + if (pconti.good()) + ds = pconti.get(PCN_DESCR); + else + ds = ""; + + f.mask().set(F_DESCRINI_CLIENTE, ds); + f.mask().set(F_DESCRINI_FORN, ds); + f.mask().set(F_DESCRINI_CONTO, ds); + } + } + } + return TRUE; +} + +bool sottoc_handler_fine(TMask_field& f, KEY key) +{ + const short id = f.dlg(); + const int gruppo = f.mask().get_int(F_GRUPPOFINE); + const int conto = f.mask().get_int(F_CONTOFINE_CONTO); + const long sottoconto = f.mask().get_long(id); + TString ds; + TString80 rs; + TLocalisamfile pconti (LF_PCON); + + if ( key == K_ENTER ) + { + if (sottoconto != 0 && conto == 0) + return f.warning_box("Manca il CONTO"); + + if (conto != 0 && gruppo == 0) + return f.warning_box("Manca il GRUPPO"); + } + + if ( key == K_TAB ) + { + if (id == F_SOTTOCFINE_CONTO) + { + pconti.zero(); + pconti.put(PCN_GRUPPO, gruppo) ; + pconti.put(PCN_CONTO, conto); + pconti.put(PCN_SOTTOCONTO, sottoconto); + pconti.setkey(1); + pconti.read(_isequal, _nolock); + if (pconti.good()) + ds = pconti.get(PCN_DESCR); + else + ds = ""; + + f.mask().set(F_DESCRFINE_CONTO, ds); + f.mask().set(F_DESCRFINE_CLIENTE, ds); + f.mask().set(F_DESCRFINE_FORN, ds); + } + if (id == F_SOTTOCFINE_CLIENTE || id == F_SOTTOCFINE_FORN) + { + char tipo = id == F_SOTTOCFINE_CLIENTE ? 'C' : 'F'; + TLocalisamfile clifo (LF_CLIFO); + if (sottoconto != 0) + { + clifo.zero(); + clifo.put(CLI_TIPOCF,tipo); + clifo.put(CLI_CODCF, sottoconto) ; + clifo.setkey(1); + if (clifo.read(_isequal, _nolock) == NOERR) + rs = clifo.get(CLI_RAGSOC); + else + rs = ""; + + f.mask().set(F_DESCRFINE_CLIENTE, rs); + f.mask().set(F_DESCRFINE_FORN, rs); + } + else + if (gruppo != 0 && conto != 0) + { + pconti.zero(); + pconti.put(PCN_GRUPPO, gruppo) ; + pconti.put(PCN_CONTO, conto); + pconti.setkey(1); + pconti.read(_isequal, _nolock); + if (pconti.good()) + ds = pconti.get(PCN_DESCR); + else + ds = ""; + + f.mask().set(F_DESCRFINE_CLIENTE, ds); + f.mask().set(F_DESCRFINE_FORN, ds); + f.mask().set(F_DESCRFINE_CONTO, ds); + } + } + } + return TRUE; +} + +bool TMastrini_application::gruppo_hnd (TMask_field& f, KEY k) +{ + if (k == K_ENTER) + { + int gruppof = f.mask().get_int(F_GRUPPOFINE); + + if (gruppof == 0) + return TRUE; + + int gruppoi = f.mask().get_int(F_GRUPPOINI); + + if (gruppoi > gruppof) + return f.error_box("Il gruppo di partenza deve essere inferiore o uguale al gruppo di arrivo"); + } + + return TRUE; +} + +bool TMastrini_application::conto_hnd (TMask_field& f, KEY k) +{ + if (k == K_ENTER) + { + int gruppof = f.mask().get_int(F_GRUPPOFINE); + + if (gruppof == 0) + return TRUE; + + int gruppoi = f.mask().get_int(F_GRUPPOINI); + + if (gruppoi < gruppof) + return TRUE; + + int contof = f.mask().get_int(F_CONTOFINE_CONTO); + int contoi = f.mask().get_int(F_CONTOINI_CONTO); + + if (contoi > contof) + return f.error_box("Il conto di partenza deve essere inferiore o uguale al conto di arrivo"); + } + + return TRUE; +} + +bool TMastrini_application::sottoc_hnd (TMask_field& f, KEY k) +{ + if (k == K_ENTER) + { + int gruppof = f.mask().get_int(F_GRUPPOFINE); + + if (gruppof == 0) + return TRUE; + + int gruppoi = f.mask().get_int(F_GRUPPOINI); + + if (gruppoi < gruppof) + return TRUE; + + int contof = f.mask().get_int(F_CONTOFINE_CONTO); + int contoi = f.mask().get_int(F_CONTOINI_CONTO); + + if (contoi < contof) + return TRUE; + + long sottocf = f.mask().get_long(F_SOTTOCFINE_CONTO); + long sottoci = f.mask().get_long(F_SOTTOCINI_CONTO); + + if (sottoci > sottocf) + return f.error_box("Il sottoconto di partenza deve essere inferiore o uguale al sottoconto di arrivo"); + } + + return TRUE; +} +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; +} + +//Questa funzione restituisce vero se il record su piano dei conti ha almeno un +//record figlio (e che soddisfa la condizione riguardante la data di registr.). +//Viene successivamente utilizzata per stampare l'intestazione (e i totali) +//oppure no + +bool TMastrini_application::almeno_un_record() +{ + bool trovato=FALSE; + long record,sottoc; + int gruppo,conto; + TDate datareg, datacomp; + TLocalisamfile& rmov = current_cursor()->file(LF_RMOV); + + if (current_cursor()->is_first_match(LF_RMOV)) + { + record = rmov.recno(); + rmov.zero(); + rmov.put(RMV_GRUPPO, _gruppo); + rmov.put(RMV_CONTO, _conto); + rmov.put(RMV_SOTTOCONTO, _sottoc); + for (rmov.read(); !rmov.eof() ;rmov.next()) + { + int annoes = rmov.get_int (RMV_ANNOES); + long numreg = rmov.get_long(RMV_NUMREG); + + _mov->setkey(1); + _mov->curr().zero(); + _mov->curr().put(MOV_NUMREG,numreg); + _mov->read(); + if (_mov->bad()) + _mov->zero(); + datacomp = (_mov->curr().get(MOV_DATACOMP)); + + if (_annomsk == 0) + datareg = rmov.get_date(RMV_DATAREG); + else + if (_annomsk != 0) + datareg = datacomp; + + gruppo = rmov.get_int(RMV_GRUPPO); + conto = rmov.get_int(RMV_CONTO); + sottoc = rmov.get_long(RMV_SOTTOCONTO); + if ((gruppo != _gruppo)||(conto != _conto)||(sottoc != _sottoc)) + break; + else + if (((annoes==_annomsk)||(_annomsk==0))&&((datareg>=_data_ini)&&(datareg<=_data_fine))) + { + trovato = TRUE; + break; + } + } + rmov.readat(record); + } + return trovato; +} + +bool TMastrini_application::data_inizio(TMask_field& f, KEY k) +{ + int anno; + TDate data; + + anno = f.mask().get_int(F_ANNO); + data = f.mask().get (F_DATAINI); + app()._annomsk = anno; + + if (k == K_ENTER) + { + if (anno != 0) + { + app().data_fine_esercizio(anno); + + if (data == botime) + app()._data_ini = app()._data_inizioese; + else + if (data < app()._data_inizioese || data > app()._data_finese) + { + f.error_box("La data non appartiene all'esercizio indicato"); + return FALSE; + } + else + app()._data_ini = data; + } + else + if (anno == 0) + { + if (data == botime) + { + f.error_box("La data deve essere obbligatoriamente indicata"); + return FALSE; + } + else + app()._data_ini = data; + } + } + return TRUE; +} + +bool TMastrini_application::data_fine(TMask_field& f, KEY k) +{ + int annoes; + TDate data, data_ini; + + annoes = f.mask().get_int(F_ANNO); + data = f.mask().get (F_DATAFINE); + data_ini = f.mask().get (F_DATAINI); + app()._annomsk = annoes; + + if (k == K_ENTER) + { + if (annoes != 0) + { + app().data_fine_esercizio(annoes); + + if (data == botime) + app()._data_fine = app()._data_finese; + else + if (data < app()._data_inizioese || data > app()._data_finese) + { + f.error_box("La data non appartiene all'esercizio indicato"); + return FALSE; + } + else + app()._data_fine = data; + } + else + if (annoes == 0) + { + if (data == botime) + { + f.error_box("La data deve essere obbligatoriamente indicata"); + return FALSE; + } + + app()._anno_ghost = date2esc(data_ini); + + app()._inizioes = app()._inizioEs; + + if (data < app()._inizioEs || data > app()._fineEs) + { + f.error_box("La data non appartiene all'esercizio indicato"); + return FALSE; + } + else + app()._data_fine = data; + } + + if (data < data_ini) + { + f.error_box("La data finale non puo' essere inferiore alla data di partenza"); + return FALSE; + } + + + } + return TRUE; +} + +void TMastrini_application::saldi_zero() +{ + TLocalisamfile& rmov = current_cursor()->file(LF_RMOV); + real saldo_dare, saldo_avere; + long record; + + saldo_dare = saldo_avere = 0; + + if (current_cursor()->is_first_match(LF_RMOV)) + { + record = rmov.recno(); + + while (!rmov.eof()) + { + rmov.read(); + char sezione = rmov.curr().get(RMV_SEZIONE)[0]; + real importo = rmov.curr().get_real(RMV_IMPORTO); + int gruppo = atoi(rmov.get(RMV_GRUPPO)); + int conto = atoi(rmov.get(RMV_CONTO)); + long sottoc = atol(rmov.get(RMV_SOTTOCONTO)); + + if ((gruppo == _gruppo)&&(conto == _conto)&&(sottoc == _sottoc)) + { + if (sezione == 'D') + saldo_dare += importo; + else if (sezione == 'A') + saldo_avere += importo; + } + else break; + rmov.next(); + } + rmov.readat(record); + } + _totale_saldo = saldo_dare - saldo_avere; +} + +void TMastrini_application::fai_stampa132() +{ + set_row (1,"@0g#t", &_dataregs); + if (_stampanum == 1) + set_row (1,"@11g$[r]#7d$[n]", &_numreg); + else + if (_stampanum == 2) + { + set_row (1,"@11g#7d", &_numgio); + } + set_row (1,"@19g#t", &_datadocs); + set_row (1,"@30g#7t", &_numdoc); + set_row (1,"@38g#3t", &_codcaus); + + set_row (1,"@117g#3t", &_g_contr); + set_row (1,"@120g#3t", &_c_contr); + set_row (1,"@123g#6t", &_s_contr); +} + +void TMastrini_application::fai_stampa198() +{ + set_row (1,"@0g#t", &_dataregs); + if (_stampanum == 1) + set_row (1,"@11g$[r]#7d$[n]", &_numreg); + else if (_stampanum == 2) + set_row (1,"@11g#7d", &_numgio); + set_row (1,"@19g#t", &_datadocs); + set_row (1,"@30g#7t", &_numdoc); + set_row (1,"@38g#3t", &_codcaus); + +// Stampa saldo movimenti + + set_row (1,"@153g#t", &_saldo_movimenti_str); + + set_row (1,"@169g#3t", &_g_contr); + set_row (1,"@172g#3t", &_c_contr); + set_row (1,"@175g#6t", &_s_contr); +} + +void TMastrini_application::stampa_totali132() +{ + TString sep(132); + + sep.fill('-'); //Stampa 132 - (sep(132)) + set_row(2,"@0g%s", (const char *) sep); + + _totprogre_dare=_progredare+_totale_periodo_dare; + _totprogre_avere=_progreavere+_totale_periodo_avere; + _saldo_periodo = _totale_periodo_dare - _totale_periodo_avere; + _saldo_progre = _totprogre_dare - _totprogre_avere; + _saldo_progre_al = _totprogre_dare_al - _totprogre_avere_al; + set_row (3,"@32gTOTALI PERIODO@69g%15.0r", &_saldo_periodo); + set_row (3,"@85g%15.0r", &_totale_periodo_dare); + set_row (3,"@101g%15.0r", &_totale_periodo_avere); + set_row (4,"@32gTOTALI PROGRESSIVI@69g%15.0r", &_saldo_progre); + set_row (4,"@85g%15.0r", &_totprogre_dare); + set_row (4,"@101g%15.0r", &_totprogre_avere); + if (_stampaprogre) //Progressivi attuali + { + set_row (5,"@32gTOTALI PROGRESSIVI AL@55g%s",(const char*)_ultima_data_reg.string()); + set_row (5,"@69g%15.0r", &_saldo_progre_al); + set_row (5,"@85g%15.0r", &_totprogre_dare_al); + set_row (5,"@101g%15.0r", &_totprogre_avere_al); + } +} + +void TMastrini_application::stampa_totali198() +{ + TString sep(198); + + sep.fill('-'); //Stampa 132 - (sep(132)) + set_row(2,"@0g%s", (const char *) sep); + + _totprogre_dare=_progredare+_totale_periodo_dare; + _totprogre_avere=_progreavere+_totale_periodo_avere; + set_row (3,"@32gTOTALI PERIODO@102g%15.0r", &_totale_periodo_dare); + set_row (3,"@119g%15.0r", &_totale_periodo_avere); + set_row (3,"@153g%15.0r", &_saldo_movimenti); + set_row (4,"@32gTOTALI PROGRESSIVI@102g%15.0r", &_totprogre_dare); + set_row (4,"@119g%15.0r", &_totprogre_avere); + set_row (4,"@136g%15.0r", &_saldo_progressivi); + if (_stampaprogre) //Progressivi attuali + { + set_row(5,"@32gTOTALI PROGRESSIVI AL@55g%s",(const char*)_ultima_data_reg.string()); + set_row (5,"@102g%15.0r", &_totprogre_dare_al); + set_row (5,"@119g%15.0r", &_totprogre_avere_al); + set_row (5,"@136g%15.0r", &_saldo_progressivi); + } +} + +bool TMastrini_application::preprocess_page(int file, int counter) +{ + TLocalisamfile & rmov = current_cursor()->file(LF_RMOV); + long rec; + TDate datasucc; + TString datasuccstring,dataregrmovstring; + int gruppof,contof; + long sottocf; + TString provvis = ""; + int annoes; + + if (counter) + return TRUE; + + switch (file) + { + case LF_SALDI: + +// Usati in crea_intestazione() + + _gruppo = atoi(current_cursor()->curr(LF_SALDI).get(SLD_GRUPPO)); + _conto = atoi(current_cursor()->curr(LF_SALDI).get(SLD_CONTO)); + _sottoc = atol(current_cursor()->curr(LF_SALDI).get(SLD_SOTTOCONTO)); + annoes = atoi(current_cursor()->curr(LF_SALDI).get(SLD_ANNOES)); + conto(_gruppo,_conto,TRUE); + + if (annoes != _anno_corrente && annoes != _anno_precedente) + return FALSE; + + if (_g_prec == _gruppo && _c_prec == _conto && _s_prec == _sottoc) + return FALSE; + + _g_prec = _gruppo; + _c_prec = _conto; + _s_prec = _sottoc; + + _saldo_periodo = ZERO; + _totale_periodo_dare = ZERO; + _totale_periodo_avere = ZERO; + _saldo_progre = ZERO; + _totprogre_dare = ZERO; + _totprogre_avere = ZERO; + _saldo_progre_al = ZERO; + _totprogre_dare_al = ZERO; + _totprogre_avere_al = ZERO; + _progredare = ZERO; + _progreavere = ZERO; + _totale_prima_dare = ZERO; + _totale_prima_avere = ZERO; + _saldo_movimenti = ZERO; + _saldo_progressivi = ZERO; + _saldo_progre_prec = ZERO; + if (_tipostampa == 2) + saldi_zero(); + else + _totale_saldo = 1; + + if ((_tipostampa == 1) || (_tipostampa == 2)) + { + if ((almeno_un_record()) && (_totale_saldo != 0)) + { + _puoi_stampare = TRUE; + calcola_progressivi(); + _saldo_progressivi += _saldo_progre_prec; + stampa_progre_riporto(); + } + else + { + _puoi_stampare = FALSE; + return FALSE; + } + } + else + if (_tipostampa == 3) + { + calcola_progressivi(); + if (_progredare == ZERO && _progreavere == ZERO && !almeno_un_record()) + { + _puoi_stampare = FALSE; + return FALSE; + } + else + { + _puoi_stampare = TRUE; + _saldo_progressivi += _saldo_progre_prec; + stampa_progre_riporto(); + } + } + break; + + case LF_RMOV: + { + // Ricerca la contropartita di quel movimento + TLocalisamfile& rmov = current_cursor()->file(LF_RMOV); + + _numreg = atol (current_cursor()->curr(LF_RMOV).get(RMV_NUMREG)); + + _gruppocontr = rmov.get_int (RMV_GRUPPOC); + _contocontr = rmov.get_int (RMV_CONTOC); + _sottocontocontr = rmov.get_long(RMV_SOTTOCONTOC); + _g_contr = rmov.get(RMV_GRUPPOC); + _c_contr = rmov.get(RMV_CONTOC); + _s_contr = rmov.get(RMV_SOTTOCONTOC); + + // Stampa solo quelli che hanno anno esercizio uguale a quello specificato + // nella maschera. Se non viene specificato li stampa tutti + + _importo = current_cursor()->curr(LF_RMOV).get_real(RMV_IMPORTO); + _importo_str = _importo.string("###############"); + _mov->setkey(1); + _mov->curr().zero(); + _mov->curr().put(MOV_NUMREG,_numreg); + _mov->read(); + if (_mov->bad()) + _mov->zero(); + _annoes = _mov->get_int(MOV_ANNOES); + _regiva = _mov->curr().get(MOV_REG); + _annoiva = _mov->curr().get_int(MOV_ANNOIVA); + + // Controlla se saldo e' diverso da 0 + + if (((_annoes == _annomsk) || (_annomsk == 0)) && (_totale_saldo != 0)) + { + _sezione = current_cursor()->curr(LF_RMOV).get(RMV_SEZIONE); + + if (_annomsk == 0) + { + _datareg = (_mov->curr().get(MOV_DATAREG)); + _datareg_stampa = _datareg; + } + else + if (_annomsk != 0) + { + _datareg = _mov->curr().get(MOV_DATACOMP); + _datareg_stampa = _mov->curr().get(MOV_DATAREG); + } + + provvis = _mov->curr().get(MOV_PROVVIS); + + _dataregs = _datareg_stampa.string(); + + if ((_stampa_mov_prov)||((!_stampa_mov_prov)&&(provvis.trim().empty()))) + { + if ((_datareg >= _data_ini) && (_datareg <= _data_fine)) + { + // Determino l' anno di competenza dell' operazione in esame + + int anno = date2esc(_datareg_stampa); + if (anno != _annoes) + if (_numcarat == 1) + set_row (1, "@131g*"); + else + if (_numcarat == 2) + set_row (1, "@197g*"); + + _codcaus = _mov->curr().get(MOV_CODCAUS); + _tipodoc = _mov->curr().get(MOV_TIPODOC); + if (_stampatotiva && (_tmcf == 'C' || _tmcf == 'F')) + { + if (_tipodoc != "") + { + documenti_iva(); + _b.add_riga(_descrdociva,_importo, _natdoc); + } + } + _datadoc = (_mov->curr().get(MOV_DATADOC)); + _datadocs = _datadoc.string(); + _numdoc = _mov->curr().get(MOV_NUMDOC); + descrizione_causale(); + _descrizionemov = _mov->curr().get(MOV_DESCR); + _numgio = atol(_mov->curr().get(MOV_NUMGIO)); + + _descrizione = current_cursor()->curr(LF_RMOV).get(RMV_DESCR); + + if (_numcarat == 1) // Stampa 132 caratteri + { + if (_descrizione != "") + { + if (_descrizionemov != "") + { + set_row (1,"@42g%.18s", (const char*) _descrizionemov); + set_row (1,"@61g%.23s", (const char*) _descrizione); + } + else if (_descrizionemov == "") + { + set_row (1,"@42g%.18s", (const char*) _descrcaus); + set_row (1,"@61g%.23s", (const char*) _descrizione); + } + } + else if (_descrizione == "") + if (_descrizionemov != "") + { + set_row (1,"@42g%.18s", (const char*) _descrcaus); + set_row (1,"@61g%.23s", (const char*) _descrizionemov); + } + else + if (_descrizionemov == "") + { + conto(_gruppocontr,_contocontr,FALSE); + TConto tc (_gruppocontr,_contocontr,_sottocontocontr,_tipo_contr); + TString descr_contr = tc.descrizione(); + set_row (1,"@42g%.18s", (const char*) _descrcaus); + set_row (1,"@61g%.23s", (const char*) descr_contr); + } + } + else + if (_numcarat == 2) // Stampa 198 caratteri + { + if (_descrizione != "") + { + if (_descrizionemov != "") + { + set_row (1,"@42g%.25s", (const char*) _descrizionemov); + set_row (1,"@68g%.32s", (const char*) _descrizione); + } + else if (_descrizionemov == "") + { + set_row (1,"@42g%.25s", (const char*) _descrcaus); + set_row (1,"@68g%.32s", (const char*) _descrizione); + } + } + else if (_descrizione == "") + if (_descrizionemov != "") + { + set_row (1,"@42g%.25s", (const char*) _descrcaus); + set_row (1,"@68g%.32s", (const char*) _descrizionemov); + } + else + if (_descrizionemov == "") + { + conto(_gruppocontr,_contocontr,FALSE); + TConto tc (_gruppocontr,_contocontr,_sottocontocontr,_tipo_contr); + TString descr_contr = tc.descrizione(); + set_row (1,"@42g%.25s", (const char*) _descrcaus); + set_row (1,"@68g%.32s", (const char*) descr_contr); + } + } + + if (_sezione == "D") + { + _totale_periodo_dare += _importo; + _riporto_parziale_dare += _importo; + + if (_numcarat == 1) // Stampa 132 caratteri + set_row (1,"@85g%s", (const char*) _importo_str); + else + if (_numcarat == 2) // Stampa 198 caratteri + { + _saldo_progressivi += _importo; + _saldo_movimenti += _importo; + set_row (1,"@102g%s", (const char*) _importo_str); + } + } + else if (_sezione == "A") + { + _totale_periodo_avere += _importo; + _riporto_parziale_avere += _importo; + + if (_numcarat == 1) // Stampa 132 caratteri + set_row (1,"@101g%s", (const char*) _importo_str); + else + if (_numcarat == 2) // Stampa 198 caratteri + { + _saldo_progressivi -= _importo; + _saldo_movimenti -= _importo; + set_row (1,"@119g%s", (const char*) _importo_str); + } + } + + _saldo_progressivi_str=_saldo_progressivi.string("###############"); + _saldo_movimenti_str=_saldo_movimenti.string("###############"); + if (_numcarat == 2) + { + ricerca_regiva(); + _protiva = atol(_mov->curr().get(MOV_PROTIVA)); + if (_protiva != 0) + set_row (1,"@191g%5d", _protiva); + + if (_tipo < 3) + set_row (1,"@182g#t" , &_regiva); + _dataregrmov = current_cursor()->curr(LF_RMOV).get_date(RMV_DATAREG); + dataregrmovstring=_dataregrmov.string(); + +//Gestire la stampa di saldo_progressivi nella postprocess_page di RMOV + + rec = rmov.recno(); + rmov.next(); + gruppof = rmov.get_int(RMV_GRUPPO); + contof = rmov.get_int(RMV_CONTO); + sottocf = rmov.get_int(RMV_SOTTOCONTO); + datasucc = rmov.get_date(RMV_DATAREG); + datasuccstring=datasucc.string(); + if (((gruppof!=_gruppo)||(contof!=_conto)||(sottocf!=_sottoc))||(rmov.eof())) + datasucc = (""); + if (datasucc != _dataregrmov) + set_row (1,"@136g#t", &_saldo_progressivi_str); + rmov.readat(rec); + } + + return TRUE; + } + else + return FALSE; + } + } + else + return FALSE; + break; + } + default: + break; + } + return TRUE; +} + +void TMastrini_application::set_page(int file, int counter) +{ + switch (file) + { + case LF_SALDI: + reset_print(); + break; + + case LF_RMOV: + reset_print(); + if (_numcarat == 1) + fai_stampa132(); + else if (_numcarat == 2) + fai_stampa198(); + break; + default: + break; + } +} + +print_action TMastrini_application::postprocess_page(int file, int counter) +{ + if (counter) + { + printer().formfeed(); + reset_print(); // per evitare che stampi di nuovo il totale prec. + _stampa_progressivi_si = TRUE; + return NEXT_PAGE; + } + + switch (file) + { + case LF_SALDI: + if (_tipostampa == 3) + { + reset_print(); + if (_numcarat == 1) + stampa_totali132(); + else if (_numcarat == 2) + stampa_totali198(); + + if (_stampatotiva) + stampa_totaliiva(); + } + else if (_tipostampa == 2) + { + reset_print(); + if ((_totale_saldo != 0) && (_puoi_stampare)) + if (_numcarat == 1) + stampa_totali132(); + else if (_numcarat == 2) + stampa_totali198(); + if (_stampatotiva) + stampa_totaliiva(); + } + else if (_tipostampa == 1) + { + reset_print(); + if (_puoi_stampare) + if (_numcarat == 1) + stampa_totali132(); + else if (_numcarat == 2) + stampa_totali198(); + if (_stampatotiva) + stampa_totaliiva(); + } + _stampa_progressivi_si = TRUE; + _prima_volta = TRUE; + return REPEAT_PAGE; + case LF_RMOV: + force_setpage(); + break; + default: + break; + } + return NEXT_PAGE; +} + +print_action TMastrini_application::postprocess_print(int file, int counter) +{ + if (file == LF_SALDI) + { + _msk->reset(F_GRUPPOINI); + + _msk->reset(F_CONTOINI_CONTO); + _msk->reset(F_CONTOINI_CLIENTE); + _msk->reset(F_CONTOINI_FORN); + + _msk->reset(F_SOTTOCINI_CONTO); + _msk->reset(F_SOTTOCINI_CLIENTE); + _msk->reset(F_SOTTOCINI_FORN); + + _msk->reset(F_GRUPPOFINE); + + _msk->reset(F_CONTOFINE_CONTO); + _msk->reset(F_CONTOFINE_CLIENTE); + _msk->reset(F_CONTOFINE_FORN); + + _msk->reset(F_SOTTOCFINE_CONTO); + _msk->reset(F_SOTTOCFINE_CLIENTE); + _msk->reset(F_SOTTOCFINE_FORN); + } + return NEXT_PAGE; +} +// Stampa dei totali documenti iva se richiesta + +void TMastrini_application::stampa_totaliiva() +{ + + if (_stampatotiva) + for (int j = 0; j < _b.items(); j++) + { + TDociva& riga = (TDociva&)_b[j]; + set_row(7+j, "@0g%-50s",(const char*) riga._descrdoc); + set_row(7+j, "@61g%15.0r", &riga._totdociva); + } + _b.destroy(); +} + +// Ricerca della descrizione relativa al codice causale di MOV.dta +// sull'archivio CAUS.dta + +void TMastrini_application::descrizione_causale() +{ + _caus->setkey(1); + _caus->curr().zero(); + _caus->curr().put(CAU_CODCAUS, _codcaus); + _caus->read(); + if (_caus->bad()) + _caus->zero(); + _descrcaus = _caus->curr().get(CAU_DESCR); +} + +// Ricerca sulla tabella dei tipi documento, la descrizione e la natura del +// documento, accedendovi tramite il tipo documento trovato su MOV.dta + +void TMastrini_application::documenti_iva() +{ + TString dep; + + _tabtpd->curr().zero(); + dep << format ("%2s",(const char*) _tipodoc); + _tabtpd->curr().put("CODTAB", (const char*) dep); + _tabtpd->read(); + _descrdociva = _tabtpd->curr().get("S0"); + _natdoc = atoi(_tabtpd->curr().get("I0")); +} + +void TMastrini_application::ricerca_regiva() +{ + TString16 dep; + + _tabreg->curr().zero(); + dep << format("%04d", _annoiva); + dep << format("%3s" , (const char*) _regiva); + _tabreg->curr().put("CODTAB", (const char*) dep); + _tabreg->read(); + _tipo = _tabreg->get_int("I0"); +} + +bool TMastrini_application::preprocess_print(int file, int counter) +{ + if (file == LF_SALDI) + { + _g_prec = 0; + _c_prec = 0; + _s_prec = 0; + + _saldo_periodo = ZERO; + _totale_periodo_dare = ZERO; + _totale_periodo_avere = ZERO; + _saldo_progre = ZERO; + _totprogre_dare = ZERO; + _totprogre_avere = ZERO; + _saldo_progre_al = ZERO; + _totprogre_dare_al = ZERO; + _totprogre_avere_al = ZERO; + _progredare = ZERO; + _progreavere = ZERO; + _totale_prima_dare = ZERO; + _totale_prima_avere = ZERO; + _saldo_movimenti = ZERO; + _saldo_progressivi = ZERO; + _saldo_progre_prec = ZERO; + _protiva = 0; + + _prima_volta = TRUE; + + _stampa_progressivi_si = TRUE; + } + + return TRUE; +} + +bool TMastrini_application::set_print(int) +{ + KEY tasto; + int crt; + TLocalisamfile* fl; + TString data1,data2; + + _puoi_stampare = TRUE; + + _msk->set_handler (F_DATAINI ,data_inizio); + _msk->set_handler (F_DATAFINE ,data_fine); + + tasto = _msk->run(); + + if (tasto == K_ENTER) + { + _annomsk = atoi(_msk->get(F_ANNO)); + + _stampaprogre = (bool)(_msk->get(F_STAMPAPROGRE) == "X"); + _stampatotiva = (bool)(_msk->get(F_STAMPATOTIVA) == "X"); + _stampanum = atoi(_msk->get(F_STAMPANUM)); + _stampa_mov_prov = (bool)(_msk->get(F_STAMPAMOVPROV) == "X"); + int gruppoini = atoi(_msk->get(F_GRUPPOINI)); + int contoini = atoi(_msk->get(F_CONTOINI_CONTO)); + long sottocontoini = atol(_msk->get(F_SOTTOCINI_CONTO)); + int gruppofine = atoi(_msk->get(F_GRUPPOFINE)); + int contofine = atoi(_msk->get(F_CONTOFINE_CONTO)); + long sottocontofine = atol(_msk->get(F_SOTTOCFINE_CONTO)); + _tipostampa = atoi(_msk->get(F_TIPOSTAMPA)); + _numcarat = atoi(_msk->get(F_NUMCARAT)); + int formato = atoi(_msk->get(F_FORMATO)); + int nummast = atoi(_msk->get(F_NUMMAST)); + _codice_ditta = get_firm(); + + ricerca_dati_ditta(); + + if (_annomsk != 0) + _anno_corrente = _annomsk; + else + if (_annomsk == 0) + _anno_corrente = _anno_ghost; + + _anno_precedente = _anno_corrente - 1; + +// Scelta del formato e del numero di mastrini per pagina 1 o 2 + + if (nummast == 1) + crt = formato; + else + crt = (formato / 2); + + printer().formlen(crt); + +//Crea il cursore su gruppo, conto e sottoconto del file RMOV + + reset_files(); //resetta l'albero di stampa + add_file(LF_SALDI); + add_file(LF_RMOV,LF_SALDI); + + select_cursor(_cur1); + fl = &(current_cursor()->file(LF_SALDI)); + TRectype da (fl->curr()); + TRectype a (fl->curr()); + + da.zero(); + a.zero(); + + da.put(SLD_GRUPPO,gruppoini); + da.put(SLD_CONTO,contoini); + da.put(SLD_SOTTOCONTO,sottocontoini); + + a.put(SLD_GRUPPO,gruppofine); + a.put(SLD_CONTO,contofine); + a.put(SLD_SOTTOCONTO,sottocontofine); + + current_cursor()->setregion(da, a); + + if (_stampatotiva) + _b.destroy(); + + switch (_tipostampa) + { + case 1: _totale_saldo = 1; + break; + case 2: _totale_saldo = 0; + break; + case 3: _totale_saldo = 1; + break; + default: break; + } + + enable_print_menu(); + + enable_link("Collegamento prima nota: ", 'r'); + + return TRUE; + } + else + return FALSE; +} + +void TMastrini_application::data_fine_esercizio(int anno) +{ + TString16 dep; + + _tabesc->curr().zero(); + dep << format ("%04d", anno); + _tabesc->curr().put("CODTAB", (const char*) dep); + _tabesc->read(); + _data_finese = _tabesc->curr().get("D1"); + _data_inizioese = _tabesc->curr().get("D0"); +} + +void TMastrini_application::preprocess_header() +{ + if (_tipostampa == 3) + crea_intestazione(); + else + if (_tipostampa == 2) + { + if ((_totale_saldo != 0) && (_puoi_stampare)) + crea_intestazione(); + } + else if (_tipostampa == 1) + if (_puoi_stampare) + crea_intestazione(); +} + +void TMastrini_application::conto(int gruppo, int conto, bool no_contropartita) +{ + TLocalisamfile pconti(LF_PCON); + + pconti.setkey(1); + pconti.zero(); + pconti.put(PCN_GRUPPO, gruppo); + pconti.put(PCN_CONTO , conto); + pconti.read(); + if (pconti.bad()) + pconti.zero(); + + if (no_contropartita) + { + _indbil = pconti.get_int(PCN_INDBIL); + _tmcf = pconti.get_char(PCN_TMCF); + } + else + _tipo_contr = pconti.get_char(PCN_TMCF); +} + +void TMastrini_application::ricerca_dati_ditta() +{ + long app; + + _nditte->setkey(1); + _nditte->curr().zero(); + _nditte->curr().put(NDT_CODDITTA,_codice_ditta); + _nditte->read(); + app=_nditte->curr().get_long(NDT_CODDITTA); + _ragsoc=_nditte->curr().get(NDT_RAGSOC); + + _unloc->setkey(1); + _unloc->curr().zero(); + _unloc->curr().put(ULC_CODDITTA,app); + _unloc->curr().put(ULC_CODULC,"1"); + _unloc->read(); + _indulc=_unloc->curr().get(ULC_INDULC); + _civulc=_unloc->curr().get(ULC_CIVULC); + _capulc=_unloc->curr().get(ULC_CAPULC); + _comulc=_unloc->curr().get(ULC_COMULC); + + _comuni->setkey(1); + _comuni->curr().zero(); + _comuni->curr().put(COM_COM,_comulc); + _comuni->read(); + _com=_comuni->curr().get(COM_DENCOM); + _prov=_comuni->curr().get(COM_PROVCOM); +} + +// Crea l'intestazione per la stampa a 132 e a 198 caratteri + +void TMastrini_application::crea_intestazione() +{ + TString sep(132),sep1(198); + + reset_header(); + + if (_numcarat == 1) + { + sep << "Pag. @#"; + sep.right_just(132); + set_header(1,(const char*) sep); + sep =""; + set_header(2,"@1g%s",(const char*) sep); + } + else if (_numcarat == 2) + { + sep1 << "Pagina @#"; + sep1.right_just(198); + set_header(1,(const char*) sep1); + sep1 =""; + set_header(2,"@1g%s",(const char*) sep1); + } + + set_header (1, "@0gDITTA@6g%5ld", _codice_ditta); + set_header (1, "@12g%-45s", (const char*) _ragsoc); + set_header (1, "@59g%-25s", (const char*) _indulc); + set_header (1, "@86g%-9s", (const char*) _civulc); + set_header (1, "@97g%-5s", (const char*) _capulc); + set_header (1, "@103g%-18s", (const char*) _com); + set_header (1, "@122g%-3s", (const char*) _prov); + + set_header (3, "@0gSottoconto@12g%d", _gruppo); + set_header (3, "@16g%d", _conto); + set_header (3, "@20g%ld", _sottoc); + + if (_tmcf == 'C') + _tipo_mask = 1; + else if (_tmcf == 'F') + _tipo_mask = 2; + else if (_tmcf == '\0') + _tipo_mask = 3; + switch (_tipo_mask) + { + case 1: ricerca_clifo(); + break; + case 2: ricerca_clifo(); + break; + case 3: ricerca_gruppo(); + break; + default: break; + } + + if (_numcarat == 1) + { + sep.fill('-'); //Stampa 132 - (sep(132)) + set_header (6, (const char *) sep); + set_header (7,"Operazione@19gDocumento@117gContro@131gA"); + set_header (8,"Data"); + if (_stampanum < 3) + set_header (8,"@11gnumero"); + set_header (8,"@19gData@30gNumero@38gCod.Causale@61gDescrizione@96gDare@111gAvere@117gPartita@131gC"); + sep.fill('-'); + set_header (9, (const char *) sep); + } + else if (_numcarat == 2) + { + sep1.fill('-'); //Stampa 198 - (sep1(198)) + set_header (6,"@1g%s", (const char *) sep1); + set_header (7,"Operazione@19gData@30gNumero@172gContro@182gReg@190gNumero@197gA"); + set_header (8,"Data"); + if (_stampanum < 3) + set_header (8,"@11gnumero"); + set_header (8,"@19gDocumento@38gCod.Causale@68gDescrizione@113gDare@129gAvere@136gSaldo progress.@156gSaldo movim.@172gPartita@182gIva@186gProtocollo@197gC"); + sep1.fill('-'); + set_header (9,"@1g%s", (const char *) sep1); + } +} + +void TMastrini_application::stampa_progre_riporto() +{ + TString sep(132),sep1(198); + + if (_stampa_progressivi_si) + { + stampa_progressivi(); + _riporto_dare = _progredare; + _riporto_avere = _progreavere; + _stampa_progressivi_si = FALSE; + } + else + { + _riporto_dare += _riporto_parziale_dare; + _riporto_avere += _riporto_parziale_avere; + if (_numcarat == 1) + { + TString string = _riporto_dare.string("###############"); + set_row (1,"@32gA RIPORTO@85g%15s",(const char*) string); + string = _riporto_avere.string("###############"); + set_row (1,"@101g%15s",(const char*) string); + } + if (_numcarat == 2) + { + TString string = _riporto_dare.string("###############"); + set_row (1,"@32gA RIPORTO@102g%15s",(const char*) string); + string = _riporto_avere.string("###############"); + set_row (1,"@119g%15s",(const char*) string); + } + _riporto_parziale_dare = 0; + _riporto_parziale_avere = 0; + } + if (_numcarat == 1) + { + sep =""; + set_row(2,"@1g%s",(const char*) sep); + } + else if (_numcarat == 2) + { + sep1 =""; + set_row(2,"@1g%s",(const char*) sep1); + } +} + +void TMastrini_application::calcola_progressivi_al() +{ + long record,sottoc,annoes; + int gruppo,conto; + TDate datareg, datacomp; + TLocalisamfile & rmov = current_cursor()->file(LF_RMOV); + char sezione; + real importo; + TDate data; + + + record = rmov.recno(); + rmov.zero(); + rmov.put(RMV_GRUPPO, _gruppo); + rmov.put(RMV_CONTO, _conto); + rmov.put(RMV_SOTTOCONTO, _sottoc); + for (rmov.read();!rmov.eof() ;rmov.next()) + { + annoes = rmov.get_int (RMV_ANNOES); + datareg = rmov.get_date(RMV_DATAREG); + sezione = rmov.get (RMV_SEZIONE)[0]; + importo = rmov.get_real(RMV_IMPORTO); + long numreg = rmov.get_long(RMV_NUMREG); + + _mov->setkey(1); + _mov->curr().zero(); + _mov->curr().put(MOV_NUMREG,numreg); + _mov->read(); + if (_mov->bad()) + _mov->zero(); + datacomp = (_mov->curr().get(MOV_DATACOMP)); + + if (_annomsk == 0) + { + datareg = rmov.get_date(RMV_DATAREG); + data = _inizioes; + } + else + if (_annomsk != 0) + { + datareg = datacomp; + data = _data_inizioese; + } + + gruppo = rmov.get_int(RMV_GRUPPO); + conto = rmov.get_int(RMV_CONTO); + sottoc = rmov.get_long(RMV_SOTTOCONTO); + if ((gruppo != _gruppo)||(conto != _conto)||(sottoc != _sottoc)) + break; + else if (((annoes==_annomsk)||(_annomsk == 0))&&(datareg >= data)&&(datareg < _data_ini)) //Legge movimenti con data < data iniziale + if (sezione == 'D') + _totale_prima_dare += importo; + else if (sezione == 'A') + _totale_prima_avere += importo; + } + rmov.readat(record); +} + +void TMastrini_application::calcola_progressivi() +{ + TLocalisamfile saldi(LF_SALDI, FALSE); + real pdaresca,paveresca,pdarescap,paverescap; + real progdare_attuale,progavere_attuale,progdare_prec,progavere_prec; + real saldo,progredare_eseprec,progreavere_eseprec,pdarep,paverep; + char salini; + + saldo = ZERO; + pdarep = ZERO; + paverep = ZERO; + pdaresca = ZERO; + paveresca = ZERO; + pdarescap = ZERO; + paverescap = ZERO; + +// Ricerca sull'archivio saldi dei record con gruppo,conto,sottoconto +// uguali a quelli di rmov per il calcolo dei progressivi precedenti + + TRectype record(saldi.curr()); + + record.zero(); + record.put(SLD_GRUPPO, _gruppo); + record.put(SLD_CONTO, _conto); + record.put(SLD_SOTTOCONTO, _sottoc); + + saldi.setkey(2); + + saldi.zero(); + saldi.put(SLD_GRUPPO, _gruppo); + saldi.put(SLD_CONTO, _conto); + saldi.put(SLD_SOTTOCONTO, _sottoc); + + for (saldi.read(_isgteq); saldi.good(); saldi.next()) + { + if (saldi.curr() != record) + break; + + int annoes_saldi = saldi.curr().get_int(SLD_ANNOES); + +//Calcola i progressivi dell'esercizio attuale + + if (annoes_saldi == _anno_corrente) + { + pdaresca = saldi.get_real(SLD_PDARESCA); + paveresca = saldi.get_real(SLD_PAVERESCA); + progdare_attuale = saldi.get_real(SLD_PDARE); + progavere_attuale = saldi.get_real(SLD_PAVERE); + saldo = saldi.get_real(SLD_SALDO); + salini = saldi.get(SLD_FLAGSALINI)[0]; + _ultima_data_reg = saldi.get_date(SLD_DATAULMOV); + } + +//Calcola i progressivi dell'esercizio precedente + + if (annoes_saldi == _anno_precedente) + { + pdarescap = saldi.get_real(SLD_PDARESCA); + pdarep = saldi.get_real(SLD_PDARE); + paverescap = saldi.get_real(SLD_PAVERESCA); + paverep = saldi.get_real(SLD_PAVERE); + } + +// Se il saldo dell'esercizio attuale e' diverso da 0 allora significa che +// quello corrisponde al saldo finale dell'esercizio precedente. Per ottenere +// i progressivi dell'esercizio precedente devo a questo punto sommare i +// progressivi dell'esercizio e i progressivi di quelli scaricati, tenendo +// conto del flag salini per sapere se il saldo e' dare oppure avere. + + + if (_annomsk != 0 && _anno_corrente == annoes_saldi) + { + if (saldo != ZERO) + { + if (salini == 'D') + { + progredare_eseprec = saldo;// + pdarescap + pdarep; + progdare_prec = saldo; + } + else if (salini == 'A') + { + progreavere_eseprec = saldo;// + paverescap + paverep; + progavere_prec = saldo; + } + } + } + } // FOR + +//Se il saldo dell'esercizio attuale non e' diverso da zero, allora il saldo +// finale dell'esercizio precedente devo calcolarmelo tenendo conto dell'indbil + + if (_annomsk != 0 && saldo == ZERO) + { + if ((_indbil == 1) || (_indbil == 2) || (_indbil == 5)) + { + const TRecnotype pos = saldi.recno(); + saldo = _sld->saldofin_esprec(_anno_corrente,_gruppo,_conto,_sottoc); + saldi.readat(pos); + + if (saldo> ZERO) + { + progredare_eseprec = saldo;// + pdarescap + pdarep; + progdare_prec = saldo; + } + else if (saldo < ZERO) + { + saldo = -saldo; + progreavere_eseprec = saldo;// + paverescap + paverep; + progavere_prec = saldo; + } + } + } + + calcola_progressivi_al(); + +//Calcolo dei progressivi precedenti: somma di tutti quei movimenti di rmov +//che hanno la data di registrazione inferiore alla data di inizio stampa, +//dei progressivi dell'anno esercizio precedente, e dei progressivi dei +//movimenti scaricati dell'esercizio attuale. + + _progredare = pdaresca + progredare_eseprec + _totale_prima_dare; + _progreavere = paveresca + progreavere_eseprec + _totale_prima_avere; + _saldo_progre_prec = _progredare - _progreavere; + +//Calcolo dei progressivi al + +//Se sulla maschera e' stato selezionato il controllo competenza esercizio +//Sommo i progressivi dell'esercizio precedente e quelli dell'esercizio attuale +//altrimenti solo quelli dell'esercizio attuale + + if (_annomsk != 0) + { + _totprogre_dare_al = progdare_attuale + progdare_prec; + _totprogre_avere_al = progavere_attuale + progavere_prec; + } + else + { + _totprogre_dare_al = progdare_attuale; + _totprogre_avere_al = progavere_attuale; + } +} + +void TMastrini_application::stampa_progressivi() +{ + if (_numcarat == 1) + { + TString string = _saldo_progre_prec.string("###############"); + set_row (1,"@32gPROGRESSIVI PRECEDENTI@69g%15s",(const char*) string); + string = _progredare.string("###############"); + set_row (1,"@85g%15s",(const char*) string); + string = _progreavere.string("###############"); + set_row (1,"@101g%15s",(const char*) string); + } + + if (_numcarat == 2) + { + TString string = _progredare.string("###############"); + set_row (1,"@32gPROGRESSIVI PRECEDENTI@102g%15s",(const char*)string); + string = _progreavere.string("###############"); + set_row (1,"@119g%15s",(const char*) string); + string = _saldo_progre_prec.string("###############"); + set_row (1,"@136g%15s",(const char*) string); + } +} + +// Se la ricerca selezionata nella maschera e' per clienti, oppure fornitori, // allora ricerco su CLIFO i relativi dati, e su PCON il relativo gruppo,conto,// sottoconto e IV direttiva CEE + +void TMastrini_application::ricerca_clifo() +{ + TString ragsoc,paiv,cofi,indcf,capcf,ptel,tel,statocf,comcf,dencom,provcom,dep; + TLocalisamfile clifo(LF_CLIFO); + TLocalisamfile pconti(LF_PCON); + TString16 dataini,datafine; + TString descriz,descriz2; + int numrivd; + + clifo.setkey(1); + clifo.zero(); + clifo.put(CLI_TIPOCF, _tmcf); + clifo.put(CLI_CODCF, _sottoc); + clifo.read(); + if (clifo.bad()) + clifo.zero(); + TConto tc (_gruppo,_conto,_sottoc,_tmcf); + + ragsoc = tc.descrizione(); + paiv = clifo.get(CLI_PAIV); + cofi = clifo.get(CLI_COFI); + indcf = clifo.get(CLI_INDCF); + capcf = clifo.get(CLI_CAPCF); + ptel = clifo.get(CLI_PTEL); + tel = clifo.get(CLI_TEL); + statocf = clifo.get(CLI_STATOCF); + comcf = clifo.get(CLI_COMCF); + + _comuni->setkey(1); + _comuni->curr().zero(); + _comuni->curr().put(COM_STATO, statocf); + _comuni->curr().put(COM_COM, comcf); + _comuni->read(); + dencom = _comuni->curr().get(COM_DENCOM); + provcom = _comuni->curr().get(COM_PROVCOM); + + pconti.setkey(1); + pconti.zero(); + pconti.put(PCN_GRUPPO, _gruppo); + pconti.put(PCN_CONTO, _conto); + pconti.read(); + _sezivd = pconti.get_char(PCN_SEZIVD); + _lettivd = pconti.get_char(PCN_LETTIVD); + numrivd = pconti.get_int(PCN_NUMRIVD); + _numrivd = itor(numrivd); + _numivd = pconti.get_int(PCN_NUMIVD); + + descriz = descrizione_classe(_sezivd,_lettivd,numrivd,_numivd); + + if (_numivd != 0) //Ora devo stampare la descrizione del livello della + { //classe immediatamente precedente a quello appena + if (_numrivd != "") //stampato + descriz2 = descrizione_classe(_sezivd,_lettivd,_numrivd_int,0); + else + descriz2 = descrizione_classe(_sezivd,_lettivd,0,0); + } + else + if (_numrivd != "") + descriz2 = descrizione_classe(_sezivd,_lettivd,0,0); + else + descriz2 = ""; + + set_header(3,"@27g%-30s",(const char*) descrizione_gruppo()); + set_header(3,"@59g%-30s",(const char*) descrizione_conto()); + set_header(3, "@91g%-30s",(const char*) ragsoc); + set_header(4, "Classe@8g%c", _lettivd); + set_header(4, "@10g%-8s", (const char*) _numrivd); + if (_numivd != 0) + set_header(4, "@19g%2d", _numivd); + if (descriz2 != "") + { + set_header(4,"@23g%-50s",(const char*) descriz2); + set_header(4,"@80g%-50s",(const char*) descriz); + } + else + set_header(4,"@23g%-50s",(const char*) descriz); + + dataini = _data_ini.string(); + datafine = _data_fine.string(); + + if (_annomsk == 0) + { + set_header (5, "Periodo@10g%s", (const char*) dataini); + set_header (5, "@22g%s", (const char*) datafine); + } + else + { + set_header (5, "Comp. da@9g%s", (const char*) dataini); + set_header (5, "@20ga@22g%s", (const char*) datafine); + } + + set_header (5, "@33gP.I.@37g%-11s",(const char*) paiv); + set_header (5, "@49gCF@52g%-16s",(const char*) cofi); + set_header (5, "@69g%-25s",(const char*) indcf); + set_header (5, "@95g%-5s",(const char*) capcf); + set_header (5, "@101g%-24s",(const char*) dencom); + set_header (5,"@126g%-5s",(const char*) provcom); + + if (_numcarat == 2) + { + set_header (5,"@134g%-4s",(const char*) ptel); + set_header (5,"@138g/@139g%-10s",(const char*) tel); + } +} + +// Se la ricerca selezionata sulla maschera e' per gruppo, conto, sottoconto +// ricerca i corrispondenti su PCON, con relativa IV direttiva CEE + +void TMastrini_application::ricerca_classe_IV(bool scelta) +{ + TLocalisamfile pconti(LF_PCON); + + pconti.setkey(1); + pconti.zero(); + pconti.put(PCN_GRUPPO, _gruppo); + pconti.put(PCN_CONTO, _conto); + if (scelta) + pconti.put(PCN_SOTTOCONTO, _sottoc); + pconti.read(); + _sezivd = pconti.get_char(PCN_SEZIVD); + _lettivd = pconti.get_char(PCN_LETTIVD); + _numrivd_int = pconti.get_int (PCN_NUMRIVD); + _numrivd = itor(_numrivd_int); + _numivd = pconti.get_int (PCN_NUMIVD); + _descr = pconti.get (PCN_DESCR); +} + +void TMastrini_application::ricerca_gruppo() +{ + TString80 descr,descriz,descriz2,dep; + TString dataini,datafine; + + ricerca_classe_IV (TRUE); //Esiste a livello di sottoconto + + if (_sezivd == '0') //Non esiste a livello di sottoconto + ricerca_classe_IV (FALSE); //Allora la cerco a livello di conto + + descriz = descrizione_classe(_sezivd,_lettivd,_numrivd_int,_numivd); + if (_numivd != 0) //Ora devo stampare la descrizione del livello della + { //classe immediatamente precedente a quello appena + if (_numrivd != "") //stampato + descriz2 = descrizione_classe(_sezivd,_lettivd,_numrivd_int,0); + else + descriz2 = descrizione_classe(_sezivd,_lettivd,0,0); + } + else + if (_numrivd != "") + descriz2 = descrizione_classe(_sezivd,_lettivd,0,0); + else + descriz2 = ""; + + set_header(3,"@27g%-30s",(const char*) descrizione_gruppo()); + set_header(3,"@59g%-30s",(const char*) descrizione_conto()); + + set_header(3,"@91g%-30s",(const char*) _descr); + set_header(4, "@0gClasse@12g%c", _lettivd); + set_header(4, "@14g%-8s",(const char*) _numrivd); + if (_numivd != 0) + set_header(4, "@23g%d", _numivd); + if (descriz2 != "") + { + set_header(4,"@27g%-50s",(const char*) descriz2); + set_header(4,"@80g%-50s",(const char*) descriz); + } + else + set_header(4,"@27g%-50s",(const char*) descriz); + + dataini = _data_ini.string(); + datafine = _data_fine.string(); + + if (_annomsk == 0) + { + set_header (5, "Periodo@12g%s", (const char*) dataini); + set_header (5, "@24g%s", (const char*) datafine); + } + else + { + set_header (5, "Periodo di competenza@23g%s", (const char*) dataini); + set_header (5, "@35g%s", (const char*) datafine); + } +} + +const char* TMastrini_application::descrizione_classe(char sezione, char lettera, int numr, int numero) +{ + TTable tabivd(TAB_IVD); + TString dep,dep2; + + tabivd.zero(); + if (numr == 0 && numero == 0) + dep = format("%c%c",sezione,lettera); + else + if (numero == 0) + { + if (numr != 0) + dep = format("%1c%1c%04d",sezione, lettera, numr); + else + dep = format("%c%c ",sezione,lettera); + } + else + { + if (numr != 0) + dep = format("%1c%1c%04d%02d",sezione, lettera, numr,numero); + else + dep = format("%c%c %02d",sezione,lettera,numero); + } + + tabivd.put("CODTAB", dep); + tabivd.read(); + dep2 = tabivd.get("CODTAB"); + if (dep == dep2) + tmp = tabivd.get("S0"); + else + tmp = ""; + return (tmp); +} + +//Ricerca la descrizione relativa al gruppo da stampare + +const char* TMastrini_application::descrizione_gruppo() +{ + TLocalisamfile pconti(LF_PCON); + + pconti.zero(); + pconti.put(PCN_GRUPPO,_gruppo); + if (pconti.read() != NOERR) pconti.zero(); + tmp = pconti.get(PCN_DESCR); + return tmp; +} + +// Ricerca la descrizione relativa al conto da stampare + +const char* TMastrini_application::descrizione_conto() +{ + TLocalisamfile pconti(LF_PCON); + + pconti.zero(); + pconti.put(PCN_GRUPPO,_gruppo); + pconti.put(PCN_CONTO,_conto); + if (pconti.read() != NOERR) pconti.zero(); + tmp = pconti.get(PCN_DESCR); + return tmp; +} + +bool TMastrini_application::user_create() +{ + TToken_string exp; + + _rel = new TRelation (LF_SALDI); + + exp.add("GRUPPO=GRUPPO"); + exp.add("CONTO=CONTO"); + exp.add("SOTTOCONTO=SOTTOCONTO"); + _rel->add(LF_RMOV,exp,2,LF_SALDI); + + _cur1=add_cursor(new TCursor(_rel,"",2)); + + _nditte = new TLocalisamfile (LF_NDITTE); + _unloc = new TLocalisamfile (LF_UNLOC); + _comuni = new TLocalisamfile (LF_COMUNI); + _mov = new TLocalisamfile (LF_MOV); + _clifo = new TLocalisamfile (LF_CLIFO); + _caus = new TLocalisamfile (LF_CAUSALI); + _tabivd = new TTable (TAB_IVD); + _tabtpd = new TTable (TAB_TPD); + _tabreg = new TTable (TAB_REG); + _tabesc = new TTable (TAB_ESC); + _sld = new TSaldo (); + + _msk = new TMask("cg3200a"); + _msk->set_handler(F_SOTTOCINI_CONTO, sottoc_handler_ini); + _msk->set_handler(F_SOTTOCINI_CLIENTE, sottoc_handler_ini); + _msk->set_handler(F_SOTTOCINI_FORN, sottoc_handler_ini); + _msk->set_handler(F_SOTTOCFINE_CONTO, sottoc_handler_fine); + _msk->set_handler(F_SOTTOCFINE_CLIENTE, sottoc_handler_fine); + _msk->set_handler(F_SOTTOCFINE_FORN, sottoc_handler_fine); + + _msk->set_handler (F_GRUPPOFINE ,gruppo_hnd); + _msk->set_handler (F_CONTOFINE_CONTO ,conto_hnd); + _msk->set_handler (F_CONTOFINE_CLIENTE ,conto_hnd); + _msk->set_handler (F_CONTOFINE_FORN ,conto_hnd); + + _msk->set_handler (F_SOTTOCFINE_CONTO ,sottoc_hnd); + _msk->set_handler (F_SOTTOCFINE_CLIENTE ,sottoc_hnd); + _msk->set_handler (F_SOTTOCFINE_FORN ,sottoc_hnd); + + _inizio_stampa = TRUE; + return TRUE; +} + +bool TMastrini_application::user_destroy() +{ + delete _msk; + delete _rel; + delete _mov; + delete _nditte; + delete _unloc; + delete _comuni; + delete _clifo; + delete _caus; + delete _tabivd; + delete _tabtpd; + delete _tabreg; + delete _tabesc; + delete _sld; + + return TRUE; + +} + +int cg3200(int argc, char* argv[]) +{ + + TMastrini_application a; + + a.run(argc, argv, "Stampa Mastrini"); + + return 0; +} + diff --git a/cg/cg3200a.uml b/cg/cg3200a.uml index b0226023a..fd05c84b7 100755 --- a/cg/cg3200a.uml +++ b/cg/cg3200a.uml @@ -1,553 +1,553 @@ -#include "cg3200.h" - -PAGE "Stampa Mastrini" -1 -1 78 20 - - -NUMBER F_CODDITTA 5 -BEGIN - PROMPT 4 1 "Ditta " - FLAGS "FRD" - USE LF_NDITTE KEY 1 - CHECKTYPE REQUIRED - INPUT CODDITTA F_CODDITTA - DISPLAY "Codice" CODDITTA - DISPLAY "Ragione sociale @50" RAGSOC - OUTPUT F_CODDITTA CODDITTA - OUTPUT F_RAGSOC RAGSOC -END - -STRING F_RAGSOC 50 -BEGIN - PROMPT 4 2 "Ragione sociale " - FLAGS "D" -END - -TEXT 96 -BEGIN - PROMPT 4 11 "Dalla data competenza" -END - -TEXT 97 -BEGIN - PROMPT 40 11 "Alla data competenza " -END - -TEXT 98 -BEGIN - PROMPT 4 11 "Dalla data operazione " -END - -TEXT 99 -BEGIN - PROMPT 40 11 "Alla data operazione " -END - -NUMBER F_ANNO 4 -BEGIN - PROMPT 47 1 "Anno esercizio " - HELP "Anno esercizio di cui stampare i mastrini" - USE ESC - INPUT CODTAB F_ANNO - DISPLAY "Anno Esercizio" CODTAB - DISPLAY "Data inizio esercizio" D0 - DISPLAY "Data fine esercizio " D1 - OUTPUT F_ANNO CODTAB - CHECKTYPE NORMAL - MESSAGE HIDE,98|HIDE,99|SHOW,96|SHOW,97 - MESSAGE EMPTY HIDE,96|HIDE,97|SHOW,98|SHOW,99 - FLAGS "RZ" -END - -LIST F_TIPOCF_INI 25 -BEGIN - PROMPT 4 4 "Ricerca " - HELP "Indicare il tipo di mastrini da stamapare" - ITEM " |Gruppo/conto/sottoconto" - MESSAGE HIDE,2@|HIDE,3@|RESET,2@|RESET,3@|SHOW,1@ - ITEM "C|Clienti" - MESSAGE HIDE,1@|HIDE,3@|RESET,1@|RESET,3@|SHOW,2@ - ITEM "F|Fornitori" - MESSAGE HIDE,1@|HIDE,2@|RESET,1@|RESET,2@|SHOW,3@ -END - -NUMBER F_GRUPPOINI 3 -BEGIN - PROMPT 4 5 "Da Gruppo - Conto - Sottoconto " - HELP "Codice conto da cui iniziare la stampa" -END - -NUMBER F_CONTOINI_CONTO 3 -BEGIN - PROMPT 41 5 "" - HELP "Codice conto da cui iniziare la stampa" - USE LF_PCON SELECT (CONTO!="") && (SOTTOCONTO="") && (TMCF="") - INPUT GRUPPO F_GRUPPOINI - INPUT CONTO F_CONTOINI_CONTO - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Descrizione@50" DESCR - //OUTPUT F_TIPOCF TMCF - OUTPUT F_GRUPPOINI GRUPPO - OUTPUT F_CONTOINI_CONTO CONTO - //OUTPUT F_SOTTOCINI_CONTO SOTTOCONTO - //OUTPUT F_DESCRINI_CONTO DESCR - FLAGS "R" - //CHECKTYPE NORMAL - //WARNING "Conto inesistente o mancante" - //MESSAGE DIRTY,F_SOTTOCINI_CONTO|DIRTY,F_SOTTOCINI_CLIENTE|DIRTY,F_SOTTOCINI_FORN - GROUP 1 -END - -NUMBER F_CONTOINI_CLIENTE 3 -BEGIN - PROMPT 41 5 "" - HELP "Codice conto da cui iniziare la stampa" - USE LF_PCON SELECT (CONTO!="") && (SOTTOCONTO="") && (TMCF="C") - INPUT GRUPPO F_GRUPPOINI - INPUT CONTO F_CONTOINI_CLIENTE - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Descrizione@50" DESCR - //OUTPUT F_TIPOCF TMCF - OUTPUT F_GRUPPOINI GRUPPO - OUTPUT F_CONTOINI_CLIENTE CONTO - //OUTPUT F_SOTTOCINI_CLIENTE SOTTOCONTO - //OUTPUT F_DESCRINI_CLIENTE DESCR - FLAGS "R" - //CHECKTYPE NORMAL - //WARNING "Conto inesistente o mancante" - //MESSAGE DIRTY,F_SOTTOCINI_CONTO|DIRTY,F_SOTTOCINI_CLIENTE|DIRTY,F_SOTTOCINI_FORN - GROUP 2 - MESSAGE COPY,F_CONTOINI_CONTO -END - -NUMBER F_CONTOINI_FORN 3 -BEGIN - PROMPT 41 5 "" - HELP "Codice conto da cui iniziare la stampa" - USE LF_PCON SELECT (CONTO!="") && (SOTTOCONTO="") && (TMCF="F") - INPUT GRUPPO F_GRUPPOINI - INPUT CONTO F_CONTOINI_FORN - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Descrizione@50" DESCR - //OUTPUT F_TIPOCF TMCF - OUTPUT F_GRUPPOINI GRUPPO - OUTPUT F_CONTOINI_FORN CONTO - //OUTPUT F_SOTTOCINI_FORN SOTTOCONTO - //OUTPUT F_DESCRINI_FORN DESCR - FLAGS "R" - //CHECKTYPE NORMAL - //WARNING "Conto inesistente o mancante" - //MESSAGE DIRTY,F_SOTTOCINI_CONTO|DIRTY,F_SOTTOCINI_CLIENTE|DIRTY,F_SOTTOCINI_FORN - GROUP 3 - MESSAGE COPY,F_CONTOINI_CONTO -END - -NUMBER F_SOTTOCINI_CONTO 6 -BEGIN - PROMPT 48 5 "" - HELP "Codice conto da cui iniziare la stampa" - USE LF_PCON //SELECT SOTTOCONTO!="" - INPUT GRUPPO F_GRUPPOINI - INPUT CONTO F_CONTOINI_CONTO - INPUT SOTTOCONTO F_SOTTOCINI_CONTO - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Sottoconto" SOTTOCONTO - DISPLAY "Descrizione@50" DESCR - OUTPUT F_GRUPPOINI GRUPPO - OUTPUT F_CONTOINI_CONTO CONTO - OUTPUT F_SOTTOCINI_CONTO SOTTOCONTO - //OUTPUT F_DESCRINI_CONTO DESCR - FLAGS "R" - //CHECKTYPE NORMAL - GROUP 1 -END - -STRING F_DESCRINI_CONTO 50 -BEGIN - PROMPT 4 6 "Descrizione " - USE LF_PCON KEY 2 - CHECKTYPE NORMAL - INPUT DESCR F_DESCRINI_CONTO - DISPLAY "Descrizione@50" DESCR - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Sottoconto" SOTTOCONTO - COPY OUTPUT F_SOTTOCINI_CONTO - GROUP 1 -END - -NUMBER F_SOTTOCINI_CLIENTE 6 -BEGIN - PROMPT 48 5 "" - HELP "Codice conto da cui iniziare la stampa" - USE LF_CLIFO - //CHECKTYPE NORMAL - INPUT TIPOCF "C" - INPUT CODCF F_SOTTOCINI_CLIENTE - DISPLAY "Codice" CODCF - DISPLAY "Ragione Sociale@50" RAGSOC - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - OUTPUT F_SOTTOCINI_CLIENTE CODCF - //OUTPUT F_DESCRINI_CLIENTE RAGSOC - MESSAGE COPY,F_SOTTOCINI_CONTO - FLAGS "R" - GROUP 2 -END - -STRING F_DESCRINI_CLIENTE 50 -BEGIN - PROMPT 4 6 "Ragione sociale C " - HELP "Codice conto da cui iniziare la stampa" - FIELD LF_CLIFO->RAGSOC - USE LF_CLIFO KEY 2 - INPUT TIPOCF "C" - INPUT RAGSOC F_DESCRINI_CLIENTE - DISPLAY "Ragione Sociale Cliente@50" RAGSOC - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Codice" CODCF - COPY OUTPUT F_SOTTOCINI_CLIENTE - MESSAGE COPY,F_DESCRINI_CONTO - CHECKTYPE NORMAL - GROUP 2 -END - -NUMBER F_SOTTOCINI_FORN 6 -BEGIN - PROMPT 48 5 "" - HELP "Codice conto da cui iniziare la stampa" - USE LF_CLIFO - //CHECKTYPE NORMAL - INPUT TIPOCF "F" - INPUT CODCF F_SOTTOCINI_FORN - DISPLAY "Codice" CODCF - DISPLAY "Ragione Sociale@50" RAGSOC - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - OUTPUT F_SOTTOCINI_FORN CODCF - //OUTPUT F_DESCRINI_FORN RAGSOC - FLAGS "R" - GROUP 3 - MESSAGE COPY,F_SOTTOCINI_CONTO -END - -STRING F_DESCRINI_FORN 50 -BEGIN - PROMPT 4 6 "Ragione Sociale F " - HELP "Codice conto da cui iniziare la stampa" - USE LF_CLIFO KEY 2 - INPUT TIPOCF "F" - INPUT RAGSOC F_DESCRINI_FORN - DISPLAY "Ragione Sociale Fornitore@50" RAGSOC - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Codice" CODCF - COPY OUTPUT F_DESCRINI_CONTO - MESSAGE COPY,F_DESCRINI_CONTO - CHECKTYPE NORMAL - GROUP 3 -END - -LIST F_TIPOCF_FINE 25 -BEGIN - PROMPT 4 7 "Ricerca " - HELP "Indicare il tipo di mastrini da stamapare" - ITEM " |Gruppo/conto/sottoconto" - MESSAGE HIDE,5@|HIDE,6@|RESET,5@|RESET,6@|SHOW,4@ - ITEM "C|Clienti" - MESSAGE HIDE,4@|HIDE,6@|RESET,4@|RESET,6@|SHOW,5@ - ITEM "F|Fornitori" - MESSAGE HIDE,4@|HIDE,5@|RESET,4@|RESET,5@|SHOW,6@ -END - -NUMBER F_GRUPPOFINE 3 -BEGIN - PROMPT 4 8 "A Gruppo - Conto - Sottoconto " -END - -NUMBER F_CONTOFINE_CONTO 3 -BEGIN - PROMPT 41 8 "" - HELP "Codice conto a cui terminare la stampa" - USE LF_PCON SELECT (CONTO!="") && (SOTTOCONTO="") && (TMCF="") - INPUT GRUPPO F_GRUPPOFINE - INPUT CONTO F_CONTOFINE_CONTO - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Descrizione@50" DESCR - //OUTPUT F_TIPOCF TMCF - OUTPUT F_GRUPPOFINE GRUPPO - OUTPUT F_CONTOFINE_CONTO CONTO - //OUTPUT F_DESCRFINE_CONTO DESCR - FLAGS "R" - //CHECKTYPE NORMAL - //WARNING "Conto inesistente o mancante" - //MESSAGE DIRTY,F_SOTTOCFINE_CONTO|DIRTY,F_SOTTOCFINE_CLIENTE|DIRTY,F_SOTTOCFINE_FORN - GROUP 4 -END - -NUMBER F_CONTOFINE_CLIENTE 3 -BEGIN - PROMPT 41 8 "" - HELP "Codice conto a cui terminare la stampa" - USE LF_PCON SELECT (CONTO!="") && (SOTTOCONTO="") && (TMCF="C") - INPUT GRUPPO F_GRUPPOFINE - INPUT CONTO F_CONTOFINE_CLIENTE - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Descrizione@50" DESCR - //OUTPUT F_TIPOCF TMCF - OUTPUT F_GRUPPOFINE GRUPPO - OUTPUT F_CONTOFINE_CLIENTE CONTO - //OUTPUT F_DESCRFINE_CLIENTE DESCR - FLAGS "R" - //CHECKTYPE NORMAL - //WARNING "Conto inesistente o mancante" - //MESSAGE DIRTY,F_SOTTOCFINE_CONTO|DIRTY,F_SOTTOCFINE_CLIENTE|DIRTY,F_SOTTOCFINE_FORN - MESSAGE COPY,F_CONTOFINE_CONTO - GROUP 5 -END - -NUMBER F_CONTOFINE_FORN 3 -BEGIN - PROMPT 41 8 "" - HELP "Codice conto a cui terminare la stampa" - USE LF_PCON SELECT (CONTO!="") && (SOTTOCONTO="") && (TMCF="F") - INPUT GRUPPO F_GRUPPOFINE - INPUT CONTO F_CONTOFINE_FORN - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Descrizione@50" DESCR - //OUTPUT F_TIPOCF TMCF - OUTPUT F_GRUPPOFINE GRUPPO - OUTPUT F_CONTOFINE_FORN CONTO - //OUTPUT F_DESCRFINE_FORN DESCR - FLAGS "R" - //CHECKTYPE NORMAL - //WARNING "Conto inesistente o mancante" - //MESSAGE DIRTY,F_SOTTOCFINE_CONTO|DIRTY,F_SOTTOCFINE_CLIENTE|DIRTY,F_SOTTOCFINE_FORN - MESSAGE COPY,F_CONTOFINE_CONTO - GROUP 6 -END - -NUMBER F_SOTTOCFINE_CONTO 6 -BEGIN - PROMPT 48 8 "" - HELP "Codice conto a cui terminare la stampa" - USE LF_PCON SELECT SOTTOCONTO!="" - INPUT GRUPPO F_GRUPPOFINE - INPUT CONTO F_CONTOFINE_CONTO - INPUT SOTTOCONTO F_SOTTOCFINE_CONTO - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Sottoconto" SOTTOCONTO - DISPLAY "Descrizione@50" DESCR - OUTPUT F_GRUPPOFINE GRUPPO - OUTPUT F_CONTOFINE_CONTO CONTO - OUTPUT F_SOTTOCFINE_CONTO SOTTOCONTO - //OUTPUT F_DESCRFINE_CONTO DESCR - FLAGS "R" - //CHECKTYPE NORMAL - GROUP 4 -END - -STRING F_DESCRFINE_CONTO 50 -BEGIN - PROMPT 4 9 "Descrizione " - HELP "Codice conto a cui terminare la stampa" - USE LF_PCON KEY 2 - CHECKTYPE NORMAL - INPUT DESCR F_DESCRINI_CONTO - DISPLAY "Descrizione@50" DESCR - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Sottoconto" SOTTOCONTO - COPY OUTPUT F_SOTTOCFINE_CONTO - GROUP 4 -END - -NUMBER F_SOTTOCFINE_CLIENTE 6 -BEGIN - PROMPT 48 8 "" - HELP "Codice conto a cui terminare la stampa" - USE LF_CLIFO - //CHECKTYPE NORMAL - INPUT TIPOCF "C" - INPUT CODCF F_SOTTOCFINE_CLIENTE - DISPLAY "Codice" CODCF - DISPLAY "Ragione Sociale@50" RAGSOC - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - OUTPUT F_SOTTOCFINE_CLIENTE CODCF - //OUTPUT F_DESCRFINE_CLIENTE RAGSOC - MESSAGE COPY,F_SOTTOCFINE_CONTO - FLAGS "R" - GROUP 5 -END - -STRING F_DESCRFINE_CLIENTE 50 -BEGIN - PROMPT 4 9 "Ragione sociale " - HELP "Codice conto a cui terminare la stampa" - FIELD LF_CLIFO->RAGSOC - CHECKTYPE NORMAL - USE LF_CLIFO KEY 2 - INPUT TIPOCF "C" - INPUT RAGSOC F_DESCRFINE_CLIENTE - DISPLAY "Ragione Sociale Cliente@50" RAGSOC - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Codice" CODCF - COPY OUTPUT F_SOTTOCFINE_CLIENTE - MESSAGE COPY,F_DESCRFINE_CONTO - GROUP 5 -END - -NUMBER F_SOTTOCFINE_FORN 6 -BEGIN - PROMPT 48 8 "" - HELP "Codice conto a cui terminare la stampa" - USE LF_CLIFO - //CHECKTYPE NORMAL - INPUT TIPOCF "F" - INPUT CODCF F_SOTTOCFINE_FORN - DISPLAY "Codice" CODCF - DISPLAY "Ragione Sociale@50" RAGSOC - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - OUTPUT F_SOTTOCFINE_FORN CODCF - //OUTPUT F_DESCRFINE_FORN RAGSOC - FLAGS "R" - GROUP 6 - MESSAGE COPY,F_SOTTOCFINE_CONTO -END - -STRING F_DESCRFINE_FORN 50 -BEGIN - PROMPT 4 9 "Ragione Sociale " - HELP "Codice conto a cui terminare la stampa" - USE LF_CLIFO KEY 2 - CHECKTYPE NORMAL - INPUT TIPOCF "F" - INPUT RAGSOC F_DESCRFINE_FORN - DISPLAY "Ragione Sociale Fornitore@50" RAGSOC - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Codice" CODCF - COPY OUTPUT F_DESCRFINE_CONTO - MESSAGE COPY,F_DESCRFINE_CONTO - GROUP 6 -END - -DATE F_DATAINI -BEGIN - PROMPT 26 11 "" - HELP "Data da cui iniziare la stampa" -END - -DATE F_DATAFINE -BEGIN - PROMPT 62 11 "" - HELP "Data a cui terminare la stampa" -END - -BOOLEAN F_STAMPATOTIVA -BEGIN - PROMPT 4 12 "Stampa totali documenti IVA" - HELP "Inidcare se stampare un totale per ogni tipo di doc. IVA" -END - -BOOLEAN F_STAMPAPROGRE -BEGIN - PROMPT 44 12 "Stampa progressivi attuali" - HELP "Indcare se stampare dati attuali a fondo pagina" -END - -BOOLEAN F_STAMPAMOVPROV -BEGIN - PROMPT 4 13 "Stampa movimenti provvisori" - HELP "Indicare se stampare movimenti provvisori" -END - -LIST F_STAMPANUM 15 -BEGIN - PROMPT 4 15 "Stampa numerazione " - HELP "Indicare il tipo di numerazione da stampare" - ITEM "1|Operazione" - ITEM "2|Riga giornale" - ITEM "3|Nessuna" -END - -LIST F_TIPOSTAMPA 34 -BEGIN - PROMPT 4 16 "Tipo stampa " - HELP "Indicare il tipo di stampa da ottenere" - ITEM "1|Mastrini movimentati nel periodo" - ITEM "2|Mastrini con saldi diversi da 0" - ITEM "3|Completa" -END - - -BOOLEAN F_MEMORIZZA -BEGIN - PROMPT 4 17 "Memorizza scelte" - HELP "Indicare se riproporre le scelte effettuate" -END - -BUTTON DLG_OK 9 2 -BEGIN - PROMPT -12 -1 "" -END - -BUTTON DLG_QUIT 9 2 -BEGIN - PROMPT -22 -1 "" -END - -ENDPAGE - -PAGE "Stampa Mastrini" -1 -1 60 10 - -LIST F_NUMCARAT 10 -BEGIN - PROMPT 4 2 "Numero caratteri " - HELP "Indicare il numero di caratteri del foglio di stampa (larghezza)" - ITEM "1|132 crt." - ITEM "2|198 crt." -END - -LIST F_FORMATO 23 -BEGIN - PROMPT 4 4 "Formato modulo di stampa " - HELP "Indicare l'altezza del modulo di stampa" - ITEM "66|11 pollici (27,94 cm)" - ITEM "72|12 pollici (30,48 cm)" -END - -LIST F_NUMMAST 5 -BEGIN - PROMPT 4 6 "Numero mastrini per pagina " - HELP "Indicare il numero di mastrini contenuti in una pagina" - ITEM "1|Uno" - ITEM "2|Due" -END - -BUTTON DLG_PRINT 9 2 -BEGIN - PROMPT -12 -1 "~Stampa" - MESSAGE EXIT,K_ENTER -END - -BUTTON DLG_QUIT 9 2 -BEGIN - PROMPT -22 -1 "" -END - - -ENDPAGE - -ENDMASK +#include "cg3200.h" + +PAGE "Stampa Mastrini" -1 -1 78 20 + + +NUMBER F_CODDITTA 5 +BEGIN + PROMPT 4 1 "Ditta " + FLAGS "FRD" + USE LF_NDITTE KEY 1 + CHECKTYPE REQUIRED + INPUT CODDITTA F_CODDITTA + DISPLAY "Codice" CODDITTA + DISPLAY "Ragione sociale @50" RAGSOC + OUTPUT F_CODDITTA CODDITTA + OUTPUT F_RAGSOC RAGSOC +END + +STRING F_RAGSOC 50 +BEGIN + PROMPT 4 2 "Ragione sociale " + FLAGS "D" +END + +TEXT 96 +BEGIN + PROMPT 4 11 "Dalla data competenza" +END + +TEXT 97 +BEGIN + PROMPT 40 11 "Alla data competenza " +END + +TEXT 98 +BEGIN + PROMPT 4 11 "Dalla data operazione " +END + +TEXT 99 +BEGIN + PROMPT 40 11 "Alla data operazione " +END + +NUMBER F_ANNO 4 +BEGIN + PROMPT 47 1 "Anno esercizio " + HELP "Anno esercizio di cui stampare i mastrini" + USE ESC + INPUT CODTAB F_ANNO + DISPLAY "Anno Esercizio" CODTAB + DISPLAY "Data inizio esercizio" D0 + DISPLAY "Data fine esercizio " D1 + OUTPUT F_ANNO CODTAB + CHECKTYPE NORMAL + MESSAGE HIDE,98|HIDE,99|SHOW,96|SHOW,97 + MESSAGE EMPTY HIDE,96|HIDE,97|SHOW,98|SHOW,99 + FLAGS "RZ" +END + +LIST F_TIPOCF_INI 25 +BEGIN + PROMPT 4 4 "Ricerca " + HELP "Indicare il tipo di mastrini da stamapare" + ITEM " |Gruppo/conto/sottoconto" + MESSAGE HIDE,2@|HIDE,3@|RESET,2@|RESET,3@|SHOW,1@ + ITEM "C|Clienti" + MESSAGE HIDE,1@|HIDE,3@|RESET,1@|RESET,3@|SHOW,2@ + ITEM "F|Fornitori" + MESSAGE HIDE,1@|HIDE,2@|RESET,1@|RESET,2@|SHOW,3@ +END + +NUMBER F_GRUPPOINI 3 +BEGIN + PROMPT 4 5 "Da Gruppo - Conto - Sottoconto " + HELP "Codice conto da cui iniziare la stampa" +END + +NUMBER F_CONTOINI_CONTO 3 +BEGIN + PROMPT 41 5 "" + HELP "Codice conto da cui iniziare la stampa" + USE LF_PCON SELECT (CONTO!="") && (SOTTOCONTO="") && (TMCF="") + INPUT GRUPPO F_GRUPPOINI + INPUT CONTO F_CONTOINI_CONTO + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Descrizione@50" DESCR + //OUTPUT F_TIPOCF TMCF + OUTPUT F_GRUPPOINI GRUPPO + OUTPUT F_CONTOINI_CONTO CONTO + //OUTPUT F_SOTTOCINI_CONTO SOTTOCONTO + //OUTPUT F_DESCRINI_CONTO DESCR + FLAGS "R" + //CHECKTYPE NORMAL + //WARNING "Conto inesistente o mancante" + //MESSAGE DIRTY,F_SOTTOCINI_CONTO|DIRTY,F_SOTTOCINI_CLIENTE|DIRTY,F_SOTTOCINI_FORN + GROUP 1 +END + +NUMBER F_CONTOINI_CLIENTE 3 +BEGIN + PROMPT 41 5 "" + HELP "Codice conto da cui iniziare la stampa" + USE LF_PCON SELECT (CONTO!="") && (SOTTOCONTO="") && (TMCF="C") + INPUT GRUPPO F_GRUPPOINI + INPUT CONTO F_CONTOINI_CLIENTE + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Descrizione@50" DESCR + //OUTPUT F_TIPOCF TMCF + OUTPUT F_GRUPPOINI GRUPPO + OUTPUT F_CONTOINI_CLIENTE CONTO + //OUTPUT F_SOTTOCINI_CLIENTE SOTTOCONTO + //OUTPUT F_DESCRINI_CLIENTE DESCR + FLAGS "R" + //CHECKTYPE NORMAL + //WARNING "Conto inesistente o mancante" + //MESSAGE DIRTY,F_SOTTOCINI_CONTO|DIRTY,F_SOTTOCINI_CLIENTE|DIRTY,F_SOTTOCINI_FORN + GROUP 2 + MESSAGE COPY,F_CONTOINI_CONTO +END + +NUMBER F_CONTOINI_FORN 3 +BEGIN + PROMPT 41 5 "" + HELP "Codice conto da cui iniziare la stampa" + USE LF_PCON SELECT (CONTO!="") && (SOTTOCONTO="") && (TMCF="F") + INPUT GRUPPO F_GRUPPOINI + INPUT CONTO F_CONTOINI_FORN + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Descrizione@50" DESCR + //OUTPUT F_TIPOCF TMCF + OUTPUT F_GRUPPOINI GRUPPO + OUTPUT F_CONTOINI_FORN CONTO + //OUTPUT F_SOTTOCINI_FORN SOTTOCONTO + //OUTPUT F_DESCRINI_FORN DESCR + FLAGS "R" + //CHECKTYPE NORMAL + //WARNING "Conto inesistente o mancante" + //MESSAGE DIRTY,F_SOTTOCINI_CONTO|DIRTY,F_SOTTOCINI_CLIENTE|DIRTY,F_SOTTOCINI_FORN + GROUP 3 + MESSAGE COPY,F_CONTOINI_CONTO +END + +NUMBER F_SOTTOCINI_CONTO 6 +BEGIN + PROMPT 48 5 "" + HELP "Codice conto da cui iniziare la stampa" + USE LF_PCON //SELECT SOTTOCONTO!="" + INPUT GRUPPO F_GRUPPOINI + INPUT CONTO F_CONTOINI_CONTO + INPUT SOTTOCONTO F_SOTTOCINI_CONTO + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Sottoconto" SOTTOCONTO + DISPLAY "Descrizione@50" DESCR + OUTPUT F_GRUPPOINI GRUPPO + OUTPUT F_CONTOINI_CONTO CONTO + OUTPUT F_SOTTOCINI_CONTO SOTTOCONTO + //OUTPUT F_DESCRINI_CONTO DESCR + FLAGS "R" + //CHECKTYPE NORMAL + GROUP 1 +END + +STRING F_DESCRINI_CONTO 50 +BEGIN + PROMPT 4 6 "Descrizione " + USE LF_PCON KEY 2 + CHECKTYPE NORMAL + INPUT DESCR F_DESCRINI_CONTO + DISPLAY "Descrizione@50" DESCR + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Sottoconto" SOTTOCONTO + COPY OUTPUT F_SOTTOCINI_CONTO + GROUP 1 +END + +NUMBER F_SOTTOCINI_CLIENTE 6 +BEGIN + PROMPT 48 5 "" + HELP "Codice conto da cui iniziare la stampa" + USE LF_CLIFO + //CHECKTYPE NORMAL + INPUT TIPOCF "C" + INPUT CODCF F_SOTTOCINI_CLIENTE + DISPLAY "Codice" CODCF + DISPLAY "Ragione Sociale@50" RAGSOC + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + OUTPUT F_SOTTOCINI_CLIENTE CODCF + //OUTPUT F_DESCRINI_CLIENTE RAGSOC + MESSAGE COPY,F_SOTTOCINI_CONTO + FLAGS "R" + GROUP 2 +END + +STRING F_DESCRINI_CLIENTE 50 +BEGIN + PROMPT 4 6 "Ragione sociale C " + HELP "Codice conto da cui iniziare la stampa" + FIELD LF_CLIFO->RAGSOC + USE LF_CLIFO KEY 2 + INPUT TIPOCF "C" + INPUT RAGSOC F_DESCRINI_CLIENTE + DISPLAY "Ragione Sociale Cliente@50" RAGSOC + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Codice" CODCF + COPY OUTPUT F_SOTTOCINI_CLIENTE + MESSAGE COPY,F_DESCRINI_CONTO + CHECKTYPE NORMAL + GROUP 2 +END + +NUMBER F_SOTTOCINI_FORN 6 +BEGIN + PROMPT 48 5 "" + HELP "Codice conto da cui iniziare la stampa" + USE LF_CLIFO + //CHECKTYPE NORMAL + INPUT TIPOCF "F" + INPUT CODCF F_SOTTOCINI_FORN + DISPLAY "Codice" CODCF + DISPLAY "Ragione Sociale@50" RAGSOC + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + OUTPUT F_SOTTOCINI_FORN CODCF + //OUTPUT F_DESCRINI_FORN RAGSOC + FLAGS "R" + GROUP 3 + MESSAGE COPY,F_SOTTOCINI_CONTO +END + +STRING F_DESCRINI_FORN 50 +BEGIN + PROMPT 4 6 "Ragione Sociale F " + HELP "Codice conto da cui iniziare la stampa" + USE LF_CLIFO KEY 2 + INPUT TIPOCF "F" + INPUT RAGSOC F_DESCRINI_FORN + DISPLAY "Ragione Sociale Fornitore@50" RAGSOC + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Codice" CODCF + COPY OUTPUT F_SOTTOCINI_FORN + MESSAGE COPY,F_DESCRINI_CONTO + CHECKTYPE NORMAL + GROUP 3 +END + +LIST F_TIPOCF_FINE 25 +BEGIN + PROMPT 4 7 "Ricerca " + HELP "Indicare il tipo di mastrini da stamapare" + ITEM " |Gruppo/conto/sottoconto" + MESSAGE HIDE,5@|HIDE,6@|RESET,5@|RESET,6@|SHOW,4@ + ITEM "C|Clienti" + MESSAGE HIDE,4@|HIDE,6@|RESET,4@|RESET,6@|SHOW,5@ + ITEM "F|Fornitori" + MESSAGE HIDE,4@|HIDE,5@|RESET,4@|RESET,5@|SHOW,6@ +END + +NUMBER F_GRUPPOFINE 3 +BEGIN + PROMPT 4 8 "A Gruppo - Conto - Sottoconto " +END + +NUMBER F_CONTOFINE_CONTO 3 +BEGIN + PROMPT 41 8 "" + HELP "Codice conto a cui terminare la stampa" + USE LF_PCON SELECT (CONTO!="") && (SOTTOCONTO="") && (TMCF="") + INPUT GRUPPO F_GRUPPOFINE + INPUT CONTO F_CONTOFINE_CONTO + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Descrizione@50" DESCR + //OUTPUT F_TIPOCF TMCF + OUTPUT F_GRUPPOFINE GRUPPO + OUTPUT F_CONTOFINE_CONTO CONTO + //OUTPUT F_DESCRFINE_CONTO DESCR + FLAGS "R" + //CHECKTYPE NORMAL + //WARNING "Conto inesistente o mancante" + //MESSAGE DIRTY,F_SOTTOCFINE_CONTO|DIRTY,F_SOTTOCFINE_CLIENTE|DIRTY,F_SOTTOCFINE_FORN + GROUP 4 +END + +NUMBER F_CONTOFINE_CLIENTE 3 +BEGIN + PROMPT 41 8 "" + HELP "Codice conto a cui terminare la stampa" + USE LF_PCON SELECT (CONTO!="") && (SOTTOCONTO="") && (TMCF="C") + INPUT GRUPPO F_GRUPPOFINE + INPUT CONTO F_CONTOFINE_CLIENTE + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Descrizione@50" DESCR + //OUTPUT F_TIPOCF TMCF + OUTPUT F_GRUPPOFINE GRUPPO + OUTPUT F_CONTOFINE_CLIENTE CONTO + //OUTPUT F_DESCRFINE_CLIENTE DESCR + FLAGS "R" + //CHECKTYPE NORMAL + //WARNING "Conto inesistente o mancante" + //MESSAGE DIRTY,F_SOTTOCFINE_CONTO|DIRTY,F_SOTTOCFINE_CLIENTE|DIRTY,F_SOTTOCFINE_FORN + MESSAGE COPY,F_CONTOFINE_CONTO + GROUP 5 +END + +NUMBER F_CONTOFINE_FORN 3 +BEGIN + PROMPT 41 8 "" + HELP "Codice conto a cui terminare la stampa" + USE LF_PCON SELECT (CONTO!="") && (SOTTOCONTO="") && (TMCF="F") + INPUT GRUPPO F_GRUPPOFINE + INPUT CONTO F_CONTOFINE_FORN + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Descrizione@50" DESCR + //OUTPUT F_TIPOCF TMCF + OUTPUT F_GRUPPOFINE GRUPPO + OUTPUT F_CONTOFINE_FORN CONTO + //OUTPUT F_DESCRFINE_FORN DESCR + FLAGS "R" + //CHECKTYPE NORMAL + //WARNING "Conto inesistente o mancante" + //MESSAGE DIRTY,F_SOTTOCFINE_CONTO|DIRTY,F_SOTTOCFINE_CLIENTE|DIRTY,F_SOTTOCFINE_FORN + MESSAGE COPY,F_CONTOFINE_CONTO + GROUP 6 +END + +NUMBER F_SOTTOCFINE_CONTO 6 +BEGIN + PROMPT 48 8 "" + HELP "Codice conto a cui terminare la stampa" + USE LF_PCON SELECT SOTTOCONTO!="" + INPUT GRUPPO F_GRUPPOFINE + INPUT CONTO F_CONTOFINE_CONTO + INPUT SOTTOCONTO F_SOTTOCFINE_CONTO + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Sottoconto" SOTTOCONTO + DISPLAY "Descrizione@50" DESCR + OUTPUT F_GRUPPOFINE GRUPPO + OUTPUT F_CONTOFINE_CONTO CONTO + OUTPUT F_SOTTOCFINE_CONTO SOTTOCONTO + //OUTPUT F_DESCRFINE_CONTO DESCR + FLAGS "R" + //CHECKTYPE NORMAL + GROUP 4 +END + +STRING F_DESCRFINE_CONTO 50 +BEGIN + PROMPT 4 9 "Descrizione " + HELP "Codice conto a cui terminare la stampa" + USE LF_PCON KEY 2 + CHECKTYPE NORMAL + INPUT DESCR F_DESCRINI_CONTO + DISPLAY "Descrizione@50" DESCR + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Sottoconto" SOTTOCONTO + COPY OUTPUT F_SOTTOCFINE_CONTO + GROUP 4 +END + +NUMBER F_SOTTOCFINE_CLIENTE 6 +BEGIN + PROMPT 48 8 "" + HELP "Codice conto a cui terminare la stampa" + USE LF_CLIFO + //CHECKTYPE NORMAL + INPUT TIPOCF "C" + INPUT CODCF F_SOTTOCFINE_CLIENTE + DISPLAY "Codice" CODCF + DISPLAY "Ragione Sociale@50" RAGSOC + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + OUTPUT F_SOTTOCFINE_CLIENTE CODCF + //OUTPUT F_DESCRFINE_CLIENTE RAGSOC + MESSAGE COPY,F_SOTTOCFINE_CONTO + FLAGS "R" + GROUP 5 +END + +STRING F_DESCRFINE_CLIENTE 50 +BEGIN + PROMPT 4 9 "Ragione sociale " + HELP "Codice conto a cui terminare la stampa" + FIELD LF_CLIFO->RAGSOC + CHECKTYPE NORMAL + USE LF_CLIFO KEY 2 + INPUT TIPOCF "C" + INPUT RAGSOC F_DESCRFINE_CLIENTE + DISPLAY "Ragione Sociale Cliente@50" RAGSOC + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Codice" CODCF + COPY OUTPUT F_SOTTOCFINE_CLIENTE + MESSAGE COPY,F_DESCRFINE_CONTO + GROUP 5 +END + +NUMBER F_SOTTOCFINE_FORN 6 +BEGIN + PROMPT 48 8 "" + HELP "Codice conto a cui terminare la stampa" + USE LF_CLIFO + //CHECKTYPE NORMAL + INPUT TIPOCF "F" + INPUT CODCF F_SOTTOCFINE_FORN + DISPLAY "Codice" CODCF + DISPLAY "Ragione Sociale@50" RAGSOC + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + OUTPUT F_SOTTOCFINE_FORN CODCF + //OUTPUT F_DESCRFINE_FORN RAGSOC + FLAGS "R" + GROUP 6 + MESSAGE COPY,F_SOTTOCFINE_CONTO +END + +STRING F_DESCRFINE_FORN 50 +BEGIN + PROMPT 4 9 "Ragione Sociale " + HELP "Codice conto a cui terminare la stampa" + USE LF_CLIFO KEY 2 + CHECKTYPE NORMAL + INPUT TIPOCF "F" + INPUT RAGSOC F_DESCRFINE_FORN + DISPLAY "Ragione Sociale Fornitore@50" RAGSOC + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Codice" CODCF + COPY OUTPUT F_SOTTOCFINE_FORN + MESSAGE COPY,F_DESCRFINE_CONTO + GROUP 6 +END + +DATE F_DATAINI +BEGIN + PROMPT 26 11 "" + HELP "Data da cui iniziare la stampa" +END + +DATE F_DATAFINE +BEGIN + PROMPT 62 11 "" + HELP "Data a cui terminare la stampa" +END + +BOOLEAN F_STAMPATOTIVA +BEGIN + PROMPT 4 12 "Stampa totali documenti IVA" + HELP "Inidcare se stampare un totale per ogni tipo di doc. IVA" +END + +BOOLEAN F_STAMPAPROGRE +BEGIN + PROMPT 44 12 "Stampa progressivi attuali" + HELP "Indcare se stampare dati attuali a fondo pagina" +END + +BOOLEAN F_STAMPAMOVPROV +BEGIN + PROMPT 4 13 "Stampa movimenti provvisori" + HELP "Indicare se stampare movimenti provvisori" +END + +LIST F_STAMPANUM 15 +BEGIN + PROMPT 4 15 "Stampa numerazione " + HELP "Indicare il tipo di numerazione da stampare" + ITEM "1|Operazione" + ITEM "2|Riga giornale" + ITEM "3|Nessuna" +END + +LIST F_TIPOSTAMPA 34 +BEGIN + PROMPT 4 16 "Tipo stampa " + HELP "Indicare il tipo di stampa da ottenere" + ITEM "1|Mastrini movimentati nel periodo" + ITEM "2|Mastrini con saldi diversi da 0" + ITEM "3|Completa" +END + + +BOOLEAN F_MEMORIZZA +BEGIN + PROMPT 4 17 "Memorizza scelte" + HELP "Indicare se riproporre le scelte effettuate" +END + +BUTTON DLG_OK 9 2 +BEGIN + PROMPT -12 -1 "" +END + +BUTTON DLG_QUIT 9 2 +BEGIN + PROMPT -22 -1 "" +END + +ENDPAGE + +PAGE "Stampa Mastrini" -1 -1 60 10 + +LIST F_NUMCARAT 10 +BEGIN + PROMPT 4 2 "Numero caratteri " + HELP "Indicare il numero di caratteri del foglio di stampa (larghezza)" + ITEM "1|132 crt." + ITEM "2|198 crt." +END + +LIST F_FORMATO 23 +BEGIN + PROMPT 4 4 "Formato modulo di stampa " + HELP "Indicare l'altezza del modulo di stampa" + ITEM "66|11 pollici (27,94 cm)" + ITEM "72|12 pollici (30,48 cm)" +END + +LIST F_NUMMAST 5 +BEGIN + PROMPT 4 6 "Numero mastrini per pagina " + HELP "Indicare il numero di mastrini contenuti in una pagina" + ITEM "1|Uno" + ITEM "2|Due" +END + +BUTTON DLG_PRINT 9 2 +BEGIN + PROMPT -12 -1 "~Stampa" + MESSAGE EXIT,K_ENTER +END + +BUTTON DLG_QUIT 9 2 +BEGIN + PROMPT -22 -1 "" +END + + +ENDPAGE + +ENDMASK diff --git a/cg/cg3500.cpp b/cg/cg3500.cpp index 03e69521b..97efd3b99 100755 --- a/cg/cg3500.cpp +++ b/cg/cg3500.cpp @@ -1,928 +1,931 @@ -//Stampa riepilogo gruppi/conti - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "cglib.h" -#include "cg3.h" -#include "cg3500.h" - -typedef enum {stampagruppo, stampaconto, stampasottoconto, fine} tipo; - -class CG3500_application : public TPrintapp -{ - TProgind * _prog; - TSaldi_list* _lista; - TLocalisamfile* _com, * _pcn, * _clifo, * _saldi, * _nditte,* _anag; - TIsamtempfile * _tmp_saldi; - tipo _tp; - real _prg_dare,_prg_avere,_saldo_dare,_saldo_avere,_prg_dare_tot,_prg_avere_tot,_saldo_tot; - real _prg_dare_gruppo,_prg_avere_gruppo,_saldo_dare_gruppo,_saldo_avere_gruppo,_prg_dare_conto,_prg_avere_conto,_saldo_dare_conto,_saldo_avere_conto; - int _ggruppo,_gconto,_cgruppo,_cconto,_gcorr,_ccorr,_gprec,_cprec,_scelta,_richiesta,_annoese,_eof; - long _scorr; - char _tipo; - TDate _ultima_data,_data,_udata_max; - TString _descr,_descrconto,_descrgruppo,_cofi,_cap,_paiva,_ragsoc,_comunefis,_provfis,_viafis,_g_descr,_c_descr; - -public: - - bool menu (MENU_TAG m) { return TPrintapp::menu(m) ; } - bool user_create() ; - bool user_destroy(); - bool set_print(int); - - virtual bool preprocess_print(int,int); - virtual void preprocess_header(); - virtual bool preprocess_page(int,int); - virtual print_action postprocess_page(int,int); - virtual void postclose_print(); - - bool riepilogo(); - bool ricerca_cf(TConto&,int,real&,real&); - tipo leggi_conti(int); - tipo leggi_gruppi(int); - bool CercaConto(int,int); - bool CercaGruppo(int); - void setta_riga_conto(); - void setta_riga_gruppo(); - void setta_riga_sottoconto(); - void setta_riga_totale(); - void get_dati_ditta(); - int stampa_intestazione_ditta(); - TDate UltimaData(int,int,long); - - CG3500_application() {} -}; - -bool CG3500_application::riepilogo() -{ - Saldo sld; - int g, c, gp, cp, indbil; - long s; - char tipo_conto = ' '; - bool esiste_conto = FALSE, esiste_sc = FALSE; - real saldo_conto,prg_conto_dare,prg_conto_avere,saldo_gruppo,prg_gruppo_dare,prg_gruppo_avere,prg_dare,prg_avere,saldo; - - _tmp_saldi->open("cg01"); - - gp=-1; - cp=-1; - _udata_max = 0l; - - for (_pcn->first(); !_pcn->eof(); _pcn->next()) - { - _prog->addstatus(1); - g = _pcn->get_int (PCN_GRUPPO); - c = _pcn->get_int (PCN_CONTO); - s = _pcn->get_long(PCN_SOTTOCONTO); - tipo_conto = _pcn->get_char(PCN_TMCF); - - TConto conto (g,c,s,tipo_conto); - - //il "conto" e' cambiato anche se e' rimasto invariato il conto ma e' cambiato il gruppo - if ( (((cp != -1) && (conto.conto() != cp)) || ((gp != -1) && (conto.gruppo() != gp))) - && esiste_sc ) - { - saldo_conto = prg_conto_dare - prg_conto_avere; - prg_gruppo_dare += prg_conto_dare; - prg_gruppo_avere += prg_conto_avere; - - //scrivo il record del conto; - _tmp_saldi->zero(); - _tmp_saldi->put(SLD_GRUPPO,gp); - _tmp_saldi->put(SLD_CONTO,cp); - _tmp_saldi->put(SLD_SOTTOCONTO,0L); - _tmp_saldi->put(SLD_ANNOES,_annoese); - _tmp_saldi->put(SLD_DATAULMOV,_udata_max); - _tmp_saldi->put(SLD_PDARE,prg_conto_dare); - _tmp_saldi->put(SLD_PAVERE,prg_conto_avere); - if (saldo_conto > 0.00) //va stampato in Dare - _tmp_saldi->put(SLD_PDARESCA,saldo_conto); - else - { - saldo_conto = saldo_conto * (-1.00); - _tmp_saldi->put(SLD_PAVERESCA,saldo_conto); - } - _tmp_saldi->write(); - esiste_conto = TRUE; - esiste_sc = FALSE; - cp = conto.conto(); - prg_conto_dare = 0.00; - prg_conto_avere = 0.00; - } - if ( ((gp != -1) && (conto.gruppo() != gp)) && esiste_conto ) - { - saldo_gruppo = prg_gruppo_dare - prg_gruppo_avere; - - //scrivo il record del gruppo - _tmp_saldi->zero(); - _tmp_saldi->put(SLD_GRUPPO,gp); - _tmp_saldi->put(SLD_CONTO,0); - _tmp_saldi->put(SLD_SOTTOCONTO,0L); - _tmp_saldi->put(SLD_ANNOES,_annoese); - _tmp_saldi->put(SLD_PDARE,prg_gruppo_dare); - _tmp_saldi->put(SLD_PAVERE,prg_gruppo_avere); - if (saldo_gruppo > 0.00) //va stampato in Dare - _tmp_saldi->put(SLD_PDARESCA,saldo_gruppo); - else - { - saldo_gruppo = saldo_gruppo * (-1.00); - _tmp_saldi->put(SLD_PAVERESCA,saldo_gruppo); - } - _tmp_saldi->write(); - gp = conto.gruppo(); - esiste_conto = FALSE; - prg_gruppo_dare = 0.00; - prg_gruppo_avere = 0.00; - } - if ( (conto.sottoconto() == 0) && (conto.conto() != 0) ) //si tratta di un conto - { - if ( (tipo_conto == 'C') || (tipo_conto == 'F') ) //si tratta di un conto cliente/fornitore - { - _udata_max = 0l; - indbil = _pcn->get_int(PCN_INDBIL); - esiste_sc = ricerca_cf(conto,indbil,prg_conto_dare,prg_conto_avere); - if (esiste_sc) - { - gp = conto.gruppo(); - cp = conto.conto(); - } - TRecnotype recnum = _pcn->recno(); - _pcn->next(); - if (_pcn->eof()) - { - saldo_conto = prg_conto_dare - prg_conto_avere; - prg_gruppo_dare += prg_conto_dare; - prg_gruppo_avere += prg_conto_avere; - if (esiste_sc) - { - //scrivo il record del conto; - _tmp_saldi->zero(); - _tmp_saldi->put(SLD_GRUPPO,gp); - _tmp_saldi->put(SLD_CONTO,cp); - _tmp_saldi->put(SLD_SOTTOCONTO,0L); - _tmp_saldi->put(SLD_ANNOES,_annoese); - _tmp_saldi->put(SLD_DATAULMOV,_udata_max); - _tmp_saldi->put(SLD_PDARE,prg_conto_dare); - _tmp_saldi->put(SLD_PAVERE,prg_conto_avere); - if (saldo_conto > 0.00) //va stampato in Dare - _tmp_saldi->put(SLD_PDARESCA,saldo_conto); - else - { - saldo_conto = saldo_conto * (-1.00); - _tmp_saldi->put(SLD_PAVERESCA,saldo_conto); - } - _tmp_saldi->write(); - esiste_conto = TRUE; - esiste_sc = FALSE; - } - if (esiste_conto) - { - saldo_gruppo = prg_gruppo_dare - prg_gruppo_avere; - //scrivo il record del gruppo - _tmp_saldi->zero(); - _tmp_saldi->put(SLD_GRUPPO,gp); - _tmp_saldi->put(SLD_CONTO,0); - _tmp_saldi->put(SLD_SOTTOCONTO,0L); - _tmp_saldi->put(SLD_ANNOES,_annoese); - _tmp_saldi->put(SLD_PDARE,prg_gruppo_dare); - _tmp_saldi->put(SLD_PAVERE,prg_gruppo_avere); - if (saldo_gruppo > 0.00) //va stampato in Dare - _tmp_saldi->put(SLD_PDARESCA,saldo_gruppo); - else - { - saldo_gruppo = saldo_gruppo * (-1.00); - _tmp_saldi->put(SLD_PAVERESCA,saldo_gruppo); - } - _tmp_saldi->write(); - } - } - _pcn->readat(recnum); - - continue; - } - } - - if (conto.conto() == 0) - indbil = _pcn->get_int(PCN_INDBIL); - - if ( (conto.conto() == 0) || (conto.sottoconto() == 0) ) //e' un gruppo o un conto - { - _udata_max = 0l; - esiste_sc = FALSE; - continue; - } - // ho trovato un sottoconto - //esiste_sc = TRUE; - prg_dare = 0.00; - prg_avere = 0.00; - if (_richiesta == 1) - sld.prg_attuali(_annoese,conto,prg_dare,prg_avere); - else sld.prg_mov_eliminati(_annoese,conto,prg_dare,prg_avere); - - saldo = prg_dare - prg_avere; - - prg_conto_dare += prg_dare; - prg_conto_avere += prg_avere; - - if (prg_dare != ZERO || prg_avere != ZERO) - { - esiste_sc = TRUE; - if (_scelta == 1) //riepilogo conti - { - _tmp_saldi->zero(); - _tmp_saldi->put(SLD_GRUPPO,conto.gruppo()); - _tmp_saldi->put(SLD_CONTO,conto.conto()); - _tmp_saldi->put(SLD_SOTTOCONTO,conto.sottoconto()); - _tmp_saldi->put(SLD_ANNOES,_annoese); - _tmp_saldi->put(SLD_FLAGSALINI,tipo_conto); - _tmp_saldi->put(SLD_PDARE,prg_dare); - _tmp_saldi->put(SLD_PAVERE,prg_avere); - if (saldo > 0.00) //va stampato in Dare - _tmp_saldi->put(SLD_PDARESCA,saldo); - else - { - saldo = saldo * (-1.00); - _tmp_saldi->put(SLD_PAVERESCA,saldo); - } - _tmp_saldi->write(); - } - if (_scelta == 2) - { - _ultima_data = UltimaData(conto.gruppo(),conto.conto(),conto.sottoconto()); - _udata_max = fnc_max(_udata_max,_ultima_data); - } - - gp = conto.gruppo(); - cp = conto.conto(); - } - - TRecnotype recnum = _pcn->recno(); - _pcn->next(); - if (_pcn->eof()) - { - saldo_conto = prg_conto_dare - prg_conto_avere; - prg_gruppo_dare += prg_conto_dare; - prg_gruppo_avere += prg_conto_avere; - if (esiste_sc) - { - esiste_conto = TRUE; - //scrivo il record del conto; - _tmp_saldi->zero(); - _tmp_saldi->put(SLD_GRUPPO,gp); - _tmp_saldi->put(SLD_CONTO,cp); - _tmp_saldi->put(SLD_SOTTOCONTO,0L); - _tmp_saldi->put(SLD_ANNOES,_annoese); - _tmp_saldi->put(SLD_DATAULMOV,_udata_max); - _tmp_saldi->put(SLD_PDARE,prg_conto_dare); - _tmp_saldi->put(SLD_PAVERE,prg_conto_avere); - if (saldo_conto > 0.00) //va stampato in Dare - _tmp_saldi->put(SLD_PDARESCA,saldo_conto); - else - { - saldo_conto = saldo_conto * (-1.00); - _tmp_saldi->put(SLD_PAVERESCA,saldo_conto); - } - _tmp_saldi->write(); - } - saldo_gruppo = prg_gruppo_dare - prg_gruppo_avere; - if (esiste_conto) - { - //scrivo il record del gruppo - _tmp_saldi->zero(); - _tmp_saldi->put(SLD_GRUPPO,gp); - _tmp_saldi->put(SLD_CONTO,0); - _tmp_saldi->put(SLD_SOTTOCONTO,0L); - _tmp_saldi->put(SLD_ANNOES,_annoese); - _tmp_saldi->put(SLD_PDARE,prg_gruppo_dare); - _tmp_saldi->put(SLD_PAVERE,prg_gruppo_avere); - if (saldo_gruppo > 0.00) //va stampato in Dare - _tmp_saldi->put(SLD_PDARESCA,saldo_gruppo); - else - { - saldo_gruppo = saldo_gruppo * (-1.00); - _tmp_saldi->put(SLD_PAVERESCA,saldo_gruppo); - } - _tmp_saldi->write(); - } - } - _pcn->readat(recnum); - } - return TRUE; -} - -bool CG3500_application::ricerca_cf(TConto& conto,int indbil,real& prg_conto_dare,real& prg_conto_avere) -{ - Saldo sld; - bool esiste_sc = FALSE; - int g = conto.gruppo(); - int c = conto.conto(); - char tipo = conto.tipo(); - long s; - - real prg_dare, prg_avere, saldo; - _lista = new TSaldi_list (g,c,_annoese); - TRecnotype items = _lista->items(); - prg_conto_dare = 0.00; - prg_conto_avere = 0.00; - for (int i = 0; i < items; i++) - { - _prog->addstatus(1); - const TRectype* r = _lista->saldi(); - s = r->get_long(SLD_SOTTOCONTO); - prg_dare = 0.00; - prg_avere = 0.00; - conto.set(g, c, s, tipo); //aggiunge a conto s - if (_richiesta == 1) - sld.prg_attuali(_annoese,conto,prg_dare,prg_avere); - else sld.prg_mov_eliminati(_annoese,conto,prg_dare,prg_avere); - - saldo = prg_dare - prg_avere; - prg_conto_dare += prg_dare; - prg_conto_avere += prg_avere; - - if (prg_dare != ZERO || prg_avere != ZERO) - { - esiste_sc = TRUE; - if (_scelta == 1) - { - _tmp_saldi->zero(); - _tmp_saldi->put(SLD_GRUPPO,g); - _tmp_saldi->put(SLD_CONTO,c); - _tmp_saldi->put(SLD_SOTTOCONTO,s); - _tmp_saldi->put(SLD_ANNOES,_annoese); - _tmp_saldi->put(SLD_FLAGSALINI,tipo); - _tmp_saldi->put(SLD_PDARE,prg_dare); - _tmp_saldi->put(SLD_PAVERE,prg_avere); - if (saldo > 0.00) //va stampato in Dare - _tmp_saldi->put(SLD_PDARESCA,saldo); - else - { - saldo = saldo * (-1.00); - _tmp_saldi->put(SLD_PAVERESCA,saldo); - } - _tmp_saldi->write(); - } - if (_scelta == 2) - { - _ultima_data = UltimaData(conto.gruppo(),conto.conto(),conto.sottoconto()); - _udata_max = fnc_max(_udata_max,_ultima_data); - } - } - } - delete _lista; - return esiste_sc; -} - -bool CG3500_application::preprocess_print(int file, int counter) -{ - set_real_picture ("###.###.###.###"); - set_print_zero(FALSE); - _tmp_saldi->setkey(2); - _prg_dare_tot = 0.00; - _prg_avere_tot = 0.00; - _gprec = -1; - _cprec = -1; - - return TRUE; -} - -tipo CG3500_application::leggi_conti(int counter) -{ - TRecnotype pos; - - if (counter == 0) - { - _eof = _tmp_saldi->first(); - if (_eof) - return fine; - } - - do - { - _gcorr = _tmp_saldi->get_int(SLD_GRUPPO); - _ccorr = _tmp_saldi->get_int(SLD_CONTO); - _scorr = _tmp_saldi->get_long(SLD_SOTTOCONTO); - pos = _tmp_saldi->recno(); - _eof = _tmp_saldi->next(); - } while ( (_scorr == 0l) && (!_eof) ); - - if ( (_gprec != _gcorr) && (_gprec != -1) ) - { - CercaConto(_gprec,_cprec); - CercaGruppo(_gprec); - _cprec = _ccorr; - _gprec = _gcorr; - _tmp_saldi->readat(pos); - - return stampagruppo; - } - - if ( (_cprec != _ccorr)&&(_cprec != -1) ) - { - CercaConto(_gprec,_cprec); - _cprec = _ccorr; - _tmp_saldi->readat(pos); - - return stampaconto; - } - - if (_eof) - { - _ultima_data = UltimaData(_gcorr,_ccorr,_scorr); - _tmp_saldi->readat(pos); - _tipo = _tmp_saldi->get_char(SLD_FLAGSALINI); - if (_tipo != 'C' && _tipo != 'F') - _tipo = ' '; - TConto conto (_gcorr,_ccorr,_scorr,_tipo); - _descr = conto.descrizione(); - _prg_dare = _tmp_saldi->get_real(SLD_PDARE); - _prg_avere = _tmp_saldi->get_real(SLD_PAVERE); - _saldo_dare = _tmp_saldi->get_real(SLD_PDARESCA); - _saldo_avere = _tmp_saldi->get_real(SLD_PAVERESCA); - - CercaConto(_gcorr,_ccorr); - CercaGruppo(_gcorr); - - return fine; - } - - if ( (_gprec == -1) && (_cprec == -1) ) - { - _gprec = _gcorr; - _cprec = _ccorr; - } - - _ultima_data = UltimaData(_gcorr,_ccorr,_scorr); - _tmp_saldi->readat(pos); - _tipo = _tmp_saldi->get_char(SLD_FLAGSALINI); - if (_tipo != 'C' && _tipo != 'F') - _tipo = ' '; - TConto conto (_gcorr,_ccorr,_scorr,_tipo); - _descr = conto.descrizione(); - _prg_dare = _tmp_saldi->get_real(SLD_PDARE); - _prg_avere = _tmp_saldi->get_real(SLD_PAVERE); - _saldo_dare = _tmp_saldi->get_real(SLD_PDARESCA); - _saldo_avere = _tmp_saldi->get_real(SLD_PAVERESCA); - _tmp_saldi->next(); - - return stampasottoconto; -} - -tipo CG3500_application::leggi_gruppi(int counter) -{ - TRecnotype pos; - - if (counter == 0) - { - _eof = _tmp_saldi->first(); - if (_eof) - return fine; - } - - do - { - _gcorr = _tmp_saldi->get_int(SLD_GRUPPO); - _ccorr = _tmp_saldi->get_int(SLD_CONTO); - pos = _tmp_saldi->recno(); - _eof = _tmp_saldi->next(); - } while ( (_ccorr == 0l) && (!_eof) ); //esco dal ciclo quando ho trovato un gruppo oppure quando e' finito il file - - if ( (_gprec != _gcorr) && (_gprec != -1) ) - { - CercaGruppo(_gprec); - _gprec = _gcorr; - _tmp_saldi->readat(pos); - - return stampagruppo; - } - - if (_eof) - { - _tmp_saldi->readat(pos); - _ultima_data = _tmp_saldi->get_date(SLD_DATAULMOV); - _tipo = _tmp_saldi->get_char(SLD_FLAGSALINI); - if (_tipo != 'C' && _tipo != 'F') - _tipo = ' '; - TConto conto (_gcorr,_ccorr,0l,_tipo); - _descrconto = conto.descrizione(); - _prg_dare_conto = _tmp_saldi->get_real(SLD_PDARE); - _prg_avere_conto = _tmp_saldi->get_real(SLD_PAVERE); - _saldo_dare_conto = _tmp_saldi->get_real(SLD_PDARESCA); - _saldo_avere_conto = _tmp_saldi->get_real(SLD_PAVERESCA); - - CercaGruppo(_gcorr); - - return fine; - } - - if (_gprec == -1) - _gprec = _gcorr; - - _tmp_saldi->readat(pos); - _ultima_data = _tmp_saldi->get_date(SLD_DATAULMOV); - _tipo = _tmp_saldi->get_char(SLD_FLAGSALINI); - if (_tipo != 'C' && _tipo != 'F') - _tipo = ' '; - TConto conto (_gcorr,_ccorr,0l,_tipo); - _descrconto = conto.descrizione(); - _prg_dare_conto = _tmp_saldi->get_real(SLD_PDARE); - _prg_avere_conto = _tmp_saldi->get_real(SLD_PAVERE); - _saldo_dare_conto = _tmp_saldi->get_real(SLD_PDARESCA); - _saldo_avere_conto = _tmp_saldi->get_real(SLD_PAVERESCA); - _tmp_saldi->next(); - - return stampaconto; -} - - -bool CG3500_application::CercaConto(int g, int c) -{ - _tmp_saldi->zero(); - _tmp_saldi->put(SLD_GRUPPO,g); - _tmp_saldi->put(SLD_CONTO,c); - _tmp_saldi->put(SLD_SOTTOCONTO,0l); - _tmp_saldi->put(SLD_ANNOES,_annoese); - if (_tmp_saldi->read() == NOERR) - { - _gconto = _tmp_saldi->get_int(SLD_GRUPPO); - _cconto = _tmp_saldi->get_int(SLD_CONTO); - _tipo = _tmp_saldi->get_char(SLD_FLAGSALINI); - if (_tipo != 'C' && _tipo != 'F') - _tipo = ' '; - if (_scelta == 2) - _ultima_data = _tmp_saldi->get_date(SLD_DATAULMOV); - TConto conto (_gconto,_cconto,0l,_tipo); - _descrconto = conto.descrizione(); - _prg_dare_conto = _tmp_saldi->get_real(SLD_PDARE); - _prg_avere_conto = _tmp_saldi->get_real(SLD_PAVERE); - _saldo_dare_conto = _tmp_saldi->get_real(SLD_PDARESCA); - _saldo_avere_conto = _tmp_saldi->get_real(SLD_PAVERESCA); - - return TRUE; - } - return FALSE; -} - -bool CG3500_application::CercaGruppo(int g) -{ - _tmp_saldi->zero(); - _tmp_saldi->put(SLD_GRUPPO,g); - _tmp_saldi->put(SLD_CONTO,0); - _tmp_saldi->put(SLD_SOTTOCONTO,0l); - _tmp_saldi->put(SLD_ANNOES,_annoese); - if (_tmp_saldi->read() == NOERR) - { - _ggruppo = _tmp_saldi->get_int(SLD_GRUPPO); - _tipo = _tmp_saldi->get_char(SLD_FLAGSALINI); - if (_tipo != 'C' && _tipo != 'F') - _tipo = ' '; - TConto conto (_ggruppo,0,0l,_tipo); - _descrgruppo = conto.descrizione(); - _prg_dare_gruppo = _tmp_saldi->get_real(SLD_PDARE); - _prg_avere_gruppo = _tmp_saldi->get_real(SLD_PAVERE); - _saldo_dare_gruppo = _tmp_saldi->get_real(SLD_PDARESCA); - _saldo_avere_gruppo = _tmp_saldi->get_real(SLD_PAVERESCA); - _prg_dare_tot += _prg_dare_gruppo; - _prg_avere_tot += _prg_avere_gruppo; - - return TRUE; - } - return FALSE; -} - -bool CG3500_application::preprocess_page(int file, int counter) -{ - reset_print(); - - if (_scelta == 1) - _tp = leggi_conti(counter); - if (_scelta == 2) - _tp = leggi_gruppi(counter); - - if (_tp == fine && counter == 0) - return FALSE; - - if (_tp == fine) - { - if (_scelta == 1) - setta_riga_sottoconto(); - setta_riga_conto(); - setta_riga_gruppo(); - setta_riga_totale(); - } - if (_tp == stampagruppo) - { - if ( _scelta == 1) setta_riga_conto(); - setta_riga_gruppo(); - } - if (_tp == stampaconto) - setta_riga_conto(); - if (_tp == stampasottoconto) - setta_riga_sottoconto(); - - return TRUE; -} - -void CG3500_application::postclose_print() -{ - _tmp_saldi->close(); - - //return NEXT_PAGE; -} - -print_action CG3500_application::postprocess_page(int file, int counter) -{ - if (_tp == fine) - return NEXT_PAGE; - - return REPEAT_PAGE; -} - -void CG3500_application::setta_riga_sottoconto() -{ - TString udata = _ultima_data.string(); - - set_row(1,"%06ld", _scorr); - //set_row(1,"@i %.32s@r",(const char*) _descr); - set_row(1," %.32s@r",(const char*) _descr); - set_row(1,"@42g%s",(const char*) udata); - set_row(1,"@57g%r@77g%r@97g%r@117g%r",&_prg_dare,&_prg_avere,&_saldo_dare,&_saldo_avere); -} - -void CG3500_application::setta_riga_conto() -{ - TString riga (132); - TString udata = _ultima_data.string(); - int r; - - riga = ""; - if ( (_tp == fine) && (_scelta == 1) ) r = 2; - else r = 1; - if (_scelta == 1) - { - set_row(r++,"%s",(const char*)riga); - set_row(r,"**** Totali conto %03d.%03d",_gconto,_cconto); - // set_row(r,"@i %.27s@r",(const char*)_descrconto); - set_row(r," %.27s@r",(const char*)_descrconto); - - } - if (_scelta == 2) - { - set_row(r,"%03d", _ccorr); - //set_row(r,"@i %.32s@r",(const char*)_descrconto); - set_row(r," %.32s@r",(const char*)_descrconto); - set_row(r,"@42g%s",(const char*)udata); - } - set_row(r++,"@57g%r@77g%r@97g%r@117g%r",&_prg_dare_conto,&_prg_avere_conto,&_saldo_dare_conto,&_saldo_avere_conto); - if ( (_scelta == 1) || ((_scelta == 2) && (_tp == fine)) ) - set_row(r,"%s",(const char*)riga); -} - -void CG3500_application::setta_riga_gruppo() -{ - TString riga (132); - int r = 0; - - riga.fill('-'); - if (_scelta == 1) - if (_tp == fine) r = 5; - else r = 4; - if (_scelta == 2) - if (_tp == fine) r = 3; - else r = 2; - set_row(r,"**** TOTALI GRUPPO %03d-",_ggruppo); - //set_row(r,"@i %.30s@r",(const char*)_descrgruppo); - set_row(r," %.30s@r",(const char*)_descrgruppo); - set_row(r++,"@57g%r@77g%r@97g%r@117g%r",&_prg_dare_gruppo,&_prg_avere_gruppo,&_saldo_dare_gruppo,&_saldo_avere_gruppo); - set_row(r++,"%s",(const char*)riga); - riga = ""; - set_row(r,"%s",(const char*)riga); -} - -void CG3500_application::setta_riga_totale() -{ - int r; - - _saldo_tot = _prg_dare_tot - _prg_avere_tot; - if (_scelta == 1) r = 8; - else r = 6; - set_row(r,"**** TOTALE GENERALE @57g%r@77g%r",&_prg_dare_tot,&_prg_avere_tot); - if (_saldo_tot > 0.00) - set_row(r,"@97g%r",&_saldo_tot); - else - { - _saldo_tot = _saldo_tot * (-1.00); - set_row(r,"@117g%r",&_saldo_tot); - } -} - -TDate CG3500_application::UltimaData(int g, int c, long s) -{ - TLocalisamfile saldi(LF_SALDI, FALSE); //il parametro a false permette di usare un record corrente del file saldi differente a quello del file temporaneo - TDate uldata; - - saldi.zero(); - if (_annoese != 0) - saldi.put(SLD_ANNOES, _annoese); - saldi.put(SLD_GRUPPO,g); - if (c != 0) - saldi.put(SLD_CONTO, c); - if (s != 0) - saldi.put(SLD_SOTTOCONTO, s); - saldi.read(); - if (saldi.bad()) - saldi.zero(); - uldata = saldi.get(SLD_DATAULMOV); - - return uldata; -} - -bool CG3500_application::user_create() -{ - _clifo = new TLocalisamfile(LF_CLIFO); - _com = new TLocalisamfile(LF_COMUNI); - _pcn = new TLocalisamfile(LF_PCON); - _saldi = new TLocalisamfile(LF_SALDI); - _nditte = new TLocalisamfile(LF_NDITTE); - _anag = new TLocalisamfile(LF_ANAG); - _tmp_saldi = new TIsamtempfile (LF_SALDI); - return TRUE; -} - -bool CG3500_application::user_destroy() -{ - delete _com; - delete _pcn; - delete _clifo; - delete _saldi; - delete _nditte; - delete _anag; - delete _tmp_saldi; - return TRUE; -} - -bool CG3500_application::set_print(int) -{ - TMask m ("cg3500a"); - KEY tasto; - - tasto = m.run(); - if (tasto == K_ENTER) - { - _annoese = atoi(m.get(F_ANNO)); - _scelta = atoi(m.get(F_STAMPA)); - _richiesta = atoi(m.get(F_RICHIESTA)); - _data = m.get(F_DATASTAMPA); - _prog = new TProgind(_pcn->items(),"Elaborazione in corso... prego attendere",FALSE); - - riepilogo(); - - delete _prog; - return TRUE; - } - return FALSE; -} - -TRectype& cerca_com (const char * cod, TLocalisamfile *comuni) -{ - comuni->zero(); - comuni->put(COM_COM, cod); - comuni->read(); - if (comuni->bad()) - comuni->zero(); - - return comuni->curr(); -} - -void CG3500_application::get_dati_ditta() -{ - TLocalisamfile nditte(LF_NDITTE); - TLocalisamfile anag(LF_ANAG); - 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 = cerca_com (_comunefis, _com); - - _comunefis = dep.get(COM_DENCOM); - _provfis = dep.get(COM_PROVCOM); - _cap = dep.get(COM_CAPCOM); - if (_comunefis.empty()) - { - _viafis = anag.get(ANA_INDRF); - _viafis.rtrim(); - _viafis << " " << anag.get (ANA_CIVRF); - } - else - { - _viafis = anag.get(ANA_INDRES); - _viafis.rtrim(); - _viafis << " " << anag.get (ANA_CIVRES); - } -} - -int CG3500_application::stampa_intestazione_ditta() -{ - int r = 1; - TString codice_ditta; - TString riga(132); - - 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); - riga = "Data @< Pag. @#"; - riga.right_just(127); - riga.overwrite (format ("Partita iva %s Codice fiscale %s", (const char*)_paiva, (const char*)_cofi)); - set_header (r, "%s", (const char*) riga); - r++; - - return r; -} - -void CG3500_application::preprocess_header() -{ - int r; - reset_header(); - r = stampa_intestazione_ditta(); - TString riga (132); - - r++; - if (_scelta == 1) //stampa riepilogo conti - set_header(r,"*** MASTRO DI CONTO ***"); - else set_header(r,"*** MASTRO DI GRUPPO ***"); - set_header(r,"@33gAnno esercizio %d", _annoese); - if (_richiesta == 1) - set_header(r,"@70gPROGRESSIVI ATTUALI@114gSALDO ATTUALE"); - else set_header(r,"@70gPROG. MOV. ELIMINATI@110gSALDO MOV. ELIMINATI"); - - r++; - r++; - if (_scelta == 1) - set_header(r,"SOTTOC DESCRIZIONE"); - else set_header(r,"CONTO DESCRIZIONE"); - set_header(r++,"@40gDATA ULT.MOV@68gDARE@87gAVERE@108gDARE@127gAVERE"); - riga.fill('-'); - set_header(r,"%s",(const char*)riga); - r++; - riga = ""; - set_header(r,"%s",(const char*)riga); -} - -int cg3500 (int argc, char* argv[]) -{ - - CG3500_application a; - - a.run(argc, argv, "Stampa riepilogo gruppi/conti"); - - return 0; -} - - - - - - +//Stampa riepilogo gruppi/conti + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "cglib.h" +#include "cg3.h" +#include "cg3500.h" + +typedef enum {stampagruppo, stampaconto, stampasottoconto, fine} tipo; + +class CG3500_application : public TPrintapp +{ + TProgind * _prog; + TSaldi_list* _lista; + TLocalisamfile* _com, * _pcn, * _clifo, * _saldi, * _nditte,* _anag; + TIsamtempfile * _tmp_saldi; + tipo _tp; + real _prg_dare,_prg_avere,_saldo_dare,_saldo_avere,_prg_dare_tot,_prg_avere_tot,_saldo_tot; + real _prg_dare_gruppo,_prg_avere_gruppo,_saldo_dare_gruppo,_saldo_avere_gruppo,_prg_dare_conto,_prg_avere_conto,_saldo_dare_conto,_saldo_avere_conto; + int _ggruppo,_gconto,_cgruppo,_cconto,_gcorr,_ccorr,_gprec,_cprec,_scelta,_richiesta,_annoese,_eof; + long _scorr; + char _tipo; + TDate _ultima_data,_data,_udata_max; + TString _descr,_descrconto,_descrgruppo,_cofi,_cap,_paiva,_ragsoc,_comunefis,_provfis,_viafis,_g_descr,_c_descr; + +public: + + bool menu (MENU_TAG m) { return TPrintapp::menu(m) ; } + bool user_create() ; + bool user_destroy(); + bool set_print(int); + + virtual bool preprocess_print(int,int); + virtual void preprocess_header(); + virtual bool preprocess_page(int,int); + virtual print_action postprocess_page(int,int); + virtual void postclose_print(); + + bool riepilogo(); + bool ricerca_cf(TConto&,int,real&,real&); + tipo leggi_conti(int); + tipo leggi_gruppi(int); + bool CercaConto(int,int); + bool CercaGruppo(int); + void setta_riga_conto(); + void setta_riga_gruppo(); + void setta_riga_sottoconto(); + void setta_riga_totale(); + void get_dati_ditta(); + int stampa_intestazione_ditta(); + TDate UltimaData(int,int,long); + + CG3500_application() {} +}; + +bool CG3500_application::riepilogo() +{ + Saldo sld; + int g, c, gp, cp, indbil; + long s; + char tipo_conto = ' '; + bool esiste_conto = FALSE, esiste_sc = FALSE; + real saldo_conto,prg_conto_dare,prg_conto_avere,saldo_gruppo,prg_gruppo_dare,prg_gruppo_avere,prg_dare,prg_avere,saldo; + + _tmp_saldi->open("cg01"); + + gp=-1; + cp=-1; + _udata_max = 0l; + + for (_pcn->first(); !_pcn->eof(); _pcn->next()) + { + _prog->addstatus(1); + g = _pcn->get_int (PCN_GRUPPO); + c = _pcn->get_int (PCN_CONTO); + s = _pcn->get_long(PCN_SOTTOCONTO); + tipo_conto = _pcn->get_char(PCN_TMCF); + + TConto conto (g,c,s,tipo_conto); + + //il "conto" e' cambiato anche se e' rimasto invariato il conto ma e' cambiato il gruppo + if ( (((cp != -1) && (conto.conto() != cp)) || ((gp != -1) && (conto.gruppo() != gp))) + && esiste_sc ) + { + saldo_conto = prg_conto_dare - prg_conto_avere; + prg_gruppo_dare += prg_conto_dare; + prg_gruppo_avere += prg_conto_avere; + + //scrivo il record del conto; + _tmp_saldi->zero(); + _tmp_saldi->put(SLD_GRUPPO,gp); + _tmp_saldi->put(SLD_CONTO,cp); + _tmp_saldi->put(SLD_SOTTOCONTO,0L); + _tmp_saldi->put(SLD_ANNOES,_annoese); + _tmp_saldi->put(SLD_DATAULMOV,_udata_max); + _tmp_saldi->put(SLD_PDARE,prg_conto_dare); + _tmp_saldi->put(SLD_PAVERE,prg_conto_avere); + if (saldo_conto > 0.00) //va stampato in Dare + _tmp_saldi->put(SLD_PDARESCA,saldo_conto); + else + { + saldo_conto = saldo_conto * (-1.00); + _tmp_saldi->put(SLD_PAVERESCA,saldo_conto); + } + _tmp_saldi->write(); + esiste_conto = TRUE; + esiste_sc = FALSE; + cp = conto.conto(); + prg_conto_dare = 0.00; + prg_conto_avere = 0.00; + } + if ( ((gp != -1) && (conto.gruppo() != gp)) && esiste_conto ) + { + saldo_gruppo = prg_gruppo_dare - prg_gruppo_avere; + + //scrivo il record del gruppo + _tmp_saldi->zero(); + _tmp_saldi->put(SLD_GRUPPO,gp); + _tmp_saldi->put(SLD_CONTO,0); + _tmp_saldi->put(SLD_SOTTOCONTO,0L); + _tmp_saldi->put(SLD_ANNOES,_annoese); + _tmp_saldi->put(SLD_PDARE,prg_gruppo_dare); + _tmp_saldi->put(SLD_PAVERE,prg_gruppo_avere); + if (saldo_gruppo > 0.00) //va stampato in Dare + _tmp_saldi->put(SLD_PDARESCA,saldo_gruppo); + else + { + saldo_gruppo = saldo_gruppo * (-1.00); + _tmp_saldi->put(SLD_PAVERESCA,saldo_gruppo); + } + _tmp_saldi->write(); + gp = conto.gruppo(); + esiste_conto = FALSE; + prg_gruppo_dare = 0.00; + prg_gruppo_avere = 0.00; + } + if ( (conto.sottoconto() == 0) && (conto.conto() != 0) ) //si tratta di un conto + { + if ( (tipo_conto == 'C') || (tipo_conto == 'F') ) //si tratta di un conto cliente/fornitore + { + _udata_max = 0l; + indbil = _pcn->get_int(PCN_INDBIL); + esiste_sc = ricerca_cf(conto,indbil,prg_conto_dare,prg_conto_avere); + if (esiste_sc) + { + gp = conto.gruppo(); + cp = conto.conto(); + } + TRecnotype recnum = _pcn->recno(); + _pcn->next(); + if (_pcn->eof()) + { + saldo_conto = prg_conto_dare - prg_conto_avere; + prg_gruppo_dare += prg_conto_dare; + prg_gruppo_avere += prg_conto_avere; + if (esiste_sc) + { + //scrivo il record del conto; + _tmp_saldi->zero(); + _tmp_saldi->put(SLD_GRUPPO,gp); + _tmp_saldi->put(SLD_CONTO,cp); + _tmp_saldi->put(SLD_SOTTOCONTO,0L); + _tmp_saldi->put(SLD_ANNOES,_annoese); + _tmp_saldi->put(SLD_DATAULMOV,_udata_max); + _tmp_saldi->put(SLD_PDARE,prg_conto_dare); + _tmp_saldi->put(SLD_PAVERE,prg_conto_avere); + if (saldo_conto > 0.00) //va stampato in Dare + _tmp_saldi->put(SLD_PDARESCA,saldo_conto); + else + { + saldo_conto = saldo_conto * (-1.00); + _tmp_saldi->put(SLD_PAVERESCA,saldo_conto); + } + _tmp_saldi->write(); + esiste_conto = TRUE; + esiste_sc = FALSE; + } + if (esiste_conto) + { + saldo_gruppo = prg_gruppo_dare - prg_gruppo_avere; + //scrivo il record del gruppo + _tmp_saldi->zero(); + _tmp_saldi->put(SLD_GRUPPO,gp); + _tmp_saldi->put(SLD_CONTO,0); + _tmp_saldi->put(SLD_SOTTOCONTO,0L); + _tmp_saldi->put(SLD_ANNOES,_annoese); + _tmp_saldi->put(SLD_PDARE,prg_gruppo_dare); + _tmp_saldi->put(SLD_PAVERE,prg_gruppo_avere); + if (saldo_gruppo > 0.00) //va stampato in Dare + _tmp_saldi->put(SLD_PDARESCA,saldo_gruppo); + else + { + saldo_gruppo = saldo_gruppo * (-1.00); + _tmp_saldi->put(SLD_PAVERESCA,saldo_gruppo); + } + _tmp_saldi->write(); + } + } + _pcn->readat(recnum); + + continue; + } + } + + if (conto.conto() == 0) + indbil = _pcn->get_int(PCN_INDBIL); + + if ( (conto.conto() == 0) || (conto.sottoconto() == 0) ) //e' un gruppo o un conto + { + _udata_max = 0l; + esiste_sc = FALSE; + continue; + } + // ho trovato un sottoconto + //esiste_sc = TRUE; + prg_dare = 0.00; + prg_avere = 0.00; + if (_richiesta == 1) + sld.prg_attuali(_annoese,conto,prg_dare,prg_avere); + else sld.prg_mov_eliminati(_annoese,conto,prg_dare,prg_avere); + + saldo = prg_dare - prg_avere; + + prg_conto_dare += prg_dare; + prg_conto_avere += prg_avere; + + if (prg_dare != ZERO || prg_avere != ZERO) + { + esiste_sc = TRUE; + if (_scelta == 1) //riepilogo conti + { + _tmp_saldi->zero(); + _tmp_saldi->put(SLD_GRUPPO,conto.gruppo()); + _tmp_saldi->put(SLD_CONTO,conto.conto()); + _tmp_saldi->put(SLD_SOTTOCONTO,conto.sottoconto()); + _tmp_saldi->put(SLD_ANNOES,_annoese); + _tmp_saldi->put(SLD_FLAGSALINI,tipo_conto); + _tmp_saldi->put(SLD_PDARE,prg_dare); + _tmp_saldi->put(SLD_PAVERE,prg_avere); + if (saldo > 0.00) //va stampato in Dare + _tmp_saldi->put(SLD_PDARESCA,saldo); + else + { + saldo = saldo * (-1.00); + _tmp_saldi->put(SLD_PAVERESCA,saldo); + } + _tmp_saldi->write(); + } + if (_scelta == 2) + { + _ultima_data = UltimaData(conto.gruppo(),conto.conto(),conto.sottoconto()); + _udata_max = fnc_max(_udata_max,_ultima_data); + } + + gp = conto.gruppo(); + cp = conto.conto(); + } + + TRecnotype recnum = _pcn->recno(); + _pcn->next(); + if (_pcn->eof()) + { + saldo_conto = prg_conto_dare - prg_conto_avere; + prg_gruppo_dare += prg_conto_dare; + prg_gruppo_avere += prg_conto_avere; + if (esiste_sc) + { + esiste_conto = TRUE; + //scrivo il record del conto; + _tmp_saldi->zero(); + _tmp_saldi->put(SLD_GRUPPO,gp); + _tmp_saldi->put(SLD_CONTO,cp); + _tmp_saldi->put(SLD_SOTTOCONTO,0L); + _tmp_saldi->put(SLD_ANNOES,_annoese); + _tmp_saldi->put(SLD_DATAULMOV,_udata_max); + _tmp_saldi->put(SLD_PDARE,prg_conto_dare); + _tmp_saldi->put(SLD_PAVERE,prg_conto_avere); + if (saldo_conto > 0.00) //va stampato in Dare + _tmp_saldi->put(SLD_PDARESCA,saldo_conto); + else + { + saldo_conto = saldo_conto * (-1.00); + _tmp_saldi->put(SLD_PAVERESCA,saldo_conto); + } + _tmp_saldi->write(); + } + saldo_gruppo = prg_gruppo_dare - prg_gruppo_avere; + if (esiste_conto) + { + //scrivo il record del gruppo + _tmp_saldi->zero(); + _tmp_saldi->put(SLD_GRUPPO,gp); + _tmp_saldi->put(SLD_CONTO,0); + _tmp_saldi->put(SLD_SOTTOCONTO,0L); + _tmp_saldi->put(SLD_ANNOES,_annoese); + _tmp_saldi->put(SLD_PDARE,prg_gruppo_dare); + _tmp_saldi->put(SLD_PAVERE,prg_gruppo_avere); + if (saldo_gruppo > 0.00) //va stampato in Dare + _tmp_saldi->put(SLD_PDARESCA,saldo_gruppo); + else + { + saldo_gruppo = saldo_gruppo * (-1.00); + _tmp_saldi->put(SLD_PAVERESCA,saldo_gruppo); + } + _tmp_saldi->write(); + } + } + _pcn->readat(recnum); + } + return TRUE; +} + +bool CG3500_application::ricerca_cf(TConto& conto,int indbil,real& prg_conto_dare,real& prg_conto_avere) +{ + Saldo sld; + bool esiste_sc = FALSE; + int g = conto.gruppo(); + int c = conto.conto(); + char tipo = conto.tipo(); + long s; + + real prg_dare, prg_avere, saldo; + _lista = new TSaldi_list (g,c,_annoese); + TRecnotype items = _lista->items(); + prg_conto_dare = 0.00; + prg_conto_avere = 0.00; + for (int i = 0; i < items; i++) + { + _prog->addstatus(1); + const TRectype* r = _lista->saldi(); + s = r->get_long(SLD_SOTTOCONTO); + prg_dare = 0.00; + prg_avere = 0.00; + conto.set(g, c, s, tipo); //aggiunge a conto s + if (_richiesta == 1) + sld.prg_attuali(_annoese,conto,prg_dare,prg_avere); + else sld.prg_mov_eliminati(_annoese,conto,prg_dare,prg_avere); + + saldo = prg_dare - prg_avere; + prg_conto_dare += prg_dare; + prg_conto_avere += prg_avere; + + if (prg_dare != ZERO || prg_avere != ZERO) + { + esiste_sc = TRUE; + if (_scelta == 1) + { + _tmp_saldi->zero(); + _tmp_saldi->put(SLD_GRUPPO,g); + _tmp_saldi->put(SLD_CONTO,c); + _tmp_saldi->put(SLD_SOTTOCONTO,s); + _tmp_saldi->put(SLD_ANNOES,_annoese); + _tmp_saldi->put(SLD_FLAGSALINI,tipo); + _tmp_saldi->put(SLD_PDARE,prg_dare); + _tmp_saldi->put(SLD_PAVERE,prg_avere); + if (saldo > 0.00) //va stampato in Dare + _tmp_saldi->put(SLD_PDARESCA,saldo); + else + { + saldo = saldo * (-1.00); + _tmp_saldi->put(SLD_PAVERESCA,saldo); + } + _tmp_saldi->write(); + } + if (_scelta == 2) + { + _ultima_data = UltimaData(conto.gruppo(),conto.conto(),conto.sottoconto()); + _udata_max = fnc_max(_udata_max,_ultima_data); + } + } + } + delete _lista; + return esiste_sc; +} + +bool CG3500_application::preprocess_print(int file, int counter) +{ + set_real_picture ("###.###.###.###"); + set_print_zero(FALSE); + _tmp_saldi->setkey(2); + _prg_dare_tot = 0.00; + _prg_avere_tot = 0.00; + _gprec = -1; + _cprec = -1; + + return TRUE; +} + +tipo CG3500_application::leggi_conti(int counter) +{ + TRecnotype pos; + + if (counter == 0) + { + _eof = _tmp_saldi->first(); + if (_eof) + return fine; + } + + do + { + _gcorr = _tmp_saldi->get_int(SLD_GRUPPO); + _ccorr = _tmp_saldi->get_int(SLD_CONTO); + _scorr = _tmp_saldi->get_long(SLD_SOTTOCONTO); + pos = _tmp_saldi->recno(); + _eof = _tmp_saldi->next(); + } while ( (_scorr == 0l) && (!_eof) ); + + if ( (_gprec != _gcorr) && (_gprec != -1) ) + { + CercaConto(_gprec,_cprec); + CercaGruppo(_gprec); + _cprec = _ccorr; + _gprec = _gcorr; + _tmp_saldi->readat(pos); + + return stampagruppo; + } + + if ( (_cprec != _ccorr)&&(_cprec != -1) ) + { + CercaConto(_gprec,_cprec); + _cprec = _ccorr; + _tmp_saldi->readat(pos); + + return stampaconto; + } + + if (_eof) + { + _ultima_data = UltimaData(_gcorr,_ccorr,_scorr); + _tmp_saldi->readat(pos); + _tipo = _tmp_saldi->get_char(SLD_FLAGSALINI); + if (_tipo != 'C' && _tipo != 'F') + _tipo = ' '; + TConto conto (_gcorr,_ccorr,_scorr,_tipo); + _descr = conto.descrizione(); + _prg_dare = _tmp_saldi->get_real(SLD_PDARE); + _prg_avere = _tmp_saldi->get_real(SLD_PAVERE); + _saldo_dare = _tmp_saldi->get_real(SLD_PDARESCA); + _saldo_avere = _tmp_saldi->get_real(SLD_PAVERESCA); + + CercaConto(_gcorr,_ccorr); + CercaGruppo(_gcorr); + + return fine; + } + + if ( (_gprec == -1) && (_cprec == -1) ) + { + _gprec = _gcorr; + _cprec = _ccorr; + } + + _ultima_data = UltimaData(_gcorr,_ccorr,_scorr); + _tmp_saldi->readat(pos); + _tipo = _tmp_saldi->get_char(SLD_FLAGSALINI); + if (_tipo != 'C' && _tipo != 'F') + _tipo = ' '; + TConto conto (_gcorr,_ccorr,_scorr,_tipo); + _descr = conto.descrizione(); + _prg_dare = _tmp_saldi->get_real(SLD_PDARE); + _prg_avere = _tmp_saldi->get_real(SLD_PAVERE); + _saldo_dare = _tmp_saldi->get_real(SLD_PDARESCA); + _saldo_avere = _tmp_saldi->get_real(SLD_PAVERESCA); + _tmp_saldi->next(); + + return stampasottoconto; +} + +tipo CG3500_application::leggi_gruppi(int counter) +{ + TRecnotype pos; + + if (counter == 0) + { + _eof = _tmp_saldi->first(); + if (_eof) + return fine; + } + + do + { + _gcorr = _tmp_saldi->get_int(SLD_GRUPPO); + _ccorr = _tmp_saldi->get_int(SLD_CONTO); + pos = _tmp_saldi->recno(); + _eof = _tmp_saldi->next(); + } while ( (_ccorr == 0l) && (!_eof) ); //esco dal ciclo quando ho trovato un gruppo oppure quando e' finito il file + + if ( (_gprec != _gcorr) && (_gprec != -1) ) + { + CercaGruppo(_gprec); + _gprec = _gcorr; + _tmp_saldi->readat(pos); + + return stampagruppo; + } + + if (_eof) + { + _tmp_saldi->readat(pos); + _ultima_data = _tmp_saldi->get_date(SLD_DATAULMOV); + _tipo = _tmp_saldi->get_char(SLD_FLAGSALINI); + if (_tipo != 'C' && _tipo != 'F') + _tipo = ' '; + TConto conto (_gcorr,_ccorr,0l,_tipo); + _descrconto = conto.descrizione(); + _prg_dare_conto = _tmp_saldi->get_real(SLD_PDARE); + _prg_avere_conto = _tmp_saldi->get_real(SLD_PAVERE); + _saldo_dare_conto = _tmp_saldi->get_real(SLD_PDARESCA); + _saldo_avere_conto = _tmp_saldi->get_real(SLD_PAVERESCA); + + CercaGruppo(_gcorr); + + return fine; + } + + if (_gprec == -1) + _gprec = _gcorr; + + _tmp_saldi->readat(pos); + _ultima_data = _tmp_saldi->get_date(SLD_DATAULMOV); + _tipo = _tmp_saldi->get_char(SLD_FLAGSALINI); + if (_tipo != 'C' && _tipo != 'F') + _tipo = ' '; + TConto conto (_gcorr,_ccorr,0l,_tipo); + _descrconto = conto.descrizione(); + _prg_dare_conto = _tmp_saldi->get_real(SLD_PDARE); + _prg_avere_conto = _tmp_saldi->get_real(SLD_PAVERE); + _saldo_dare_conto = _tmp_saldi->get_real(SLD_PDARESCA); + _saldo_avere_conto = _tmp_saldi->get_real(SLD_PAVERESCA); + _tmp_saldi->next(); + + return stampaconto; +} + + +bool CG3500_application::CercaConto(int g, int c) +{ + _tmp_saldi->zero(); + _tmp_saldi->put(SLD_GRUPPO,g); + _tmp_saldi->put(SLD_CONTO,c); + _tmp_saldi->put(SLD_SOTTOCONTO,0l); + _tmp_saldi->put(SLD_ANNOES,_annoese); + if (_tmp_saldi->read() == NOERR) + { + _gconto = _tmp_saldi->get_int(SLD_GRUPPO); + _cconto = _tmp_saldi->get_int(SLD_CONTO); + _tipo = _tmp_saldi->get_char(SLD_FLAGSALINI); + if (_tipo != 'C' && _tipo != 'F') + _tipo = ' '; + if (_scelta == 2) + _ultima_data = _tmp_saldi->get_date(SLD_DATAULMOV); + TConto conto (_gconto,_cconto,0l,_tipo); + _descrconto = conto.descrizione(); + _prg_dare_conto = _tmp_saldi->get_real(SLD_PDARE); + _prg_avere_conto = _tmp_saldi->get_real(SLD_PAVERE); + _saldo_dare_conto = _tmp_saldi->get_real(SLD_PDARESCA); + _saldo_avere_conto = _tmp_saldi->get_real(SLD_PAVERESCA); + + return TRUE; + } + return FALSE; +} + +bool CG3500_application::CercaGruppo(int g) +{ + _tmp_saldi->zero(); + _tmp_saldi->put(SLD_GRUPPO,g); + _tmp_saldi->put(SLD_CONTO,0); + _tmp_saldi->put(SLD_SOTTOCONTO,0l); + _tmp_saldi->put(SLD_ANNOES,_annoese); + if (_tmp_saldi->read() == NOERR) + { + _ggruppo = _tmp_saldi->get_int(SLD_GRUPPO); + _tipo = _tmp_saldi->get_char(SLD_FLAGSALINI); + if (_tipo != 'C' && _tipo != 'F') + _tipo = ' '; + TConto conto (_ggruppo,0,0l,_tipo); + _descrgruppo = conto.descrizione(); + _prg_dare_gruppo = _tmp_saldi->get_real(SLD_PDARE); + _prg_avere_gruppo = _tmp_saldi->get_real(SLD_PAVERE); + _saldo_dare_gruppo = _tmp_saldi->get_real(SLD_PDARESCA); + _saldo_avere_gruppo = _tmp_saldi->get_real(SLD_PAVERESCA); + _prg_dare_tot += _prg_dare_gruppo; + _prg_avere_tot += _prg_avere_gruppo; + + return TRUE; + } + return FALSE; +} + +bool CG3500_application::preprocess_page(int file, int counter) +{ + reset_print(); + + if (_scelta == 1) + _tp = leggi_conti(counter); + if (_scelta == 2) + _tp = leggi_gruppi(counter); + + if (_tp == fine && counter == 0) + return FALSE; + + if (_tp == fine) + { + if (_scelta == 1) + setta_riga_sottoconto(); + setta_riga_conto(); + setta_riga_gruppo(); + setta_riga_totale(); + } + if (_tp == stampagruppo) + { + if ( _scelta == 1) setta_riga_conto(); + setta_riga_gruppo(); + } + if (_tp == stampaconto) + setta_riga_conto(); + if (_tp == stampasottoconto) + setta_riga_sottoconto(); + + return TRUE; +} + +void CG3500_application::postclose_print() +{ + _tmp_saldi->close(); + + //return NEXT_PAGE; +} + +print_action CG3500_application::postprocess_page(int file, int counter) +{ + if (_tp == fine) + return NEXT_PAGE; + + return REPEAT_PAGE; +} + +void CG3500_application::setta_riga_sottoconto() +{ + TString udata = _ultima_data.string(); + + //set_row(1,"%06ld", _scorr); + set_row(1,"%6ld", _scorr); + //set_row(1,"@i %.32s@r",(const char*) _descr); + set_row(1," %.32s@r",(const char*) _descr); + set_row(1,"@42g%s",(const char*) udata); + set_row(1,"@57g%r@77g%r@97g%r@117g%r",&_prg_dare,&_prg_avere,&_saldo_dare,&_saldo_avere); +} + +void CG3500_application::setta_riga_conto() +{ + TString riga (132); + TString udata = _ultima_data.string(); + int r; + + riga = ""; + if ( (_tp == fine) && (_scelta == 1) ) r = 2; + else r = 1; + if (_scelta == 1) + { + set_row(r++,"%s",(const char*)riga); + //set_row(r,"**** Totali conto %03d.%03d",_gconto,_cconto); + set_row(r,"**** Totali conto %3d %3d",_gconto,_cconto); + // set_row(r,"@i %.27s@r",(const char*)_descrconto); + set_row(r," %.27s@r",(const char*)_descrconto); + + } + if (_scelta == 2) + { + set_row(r,"%3d", _ccorr); + //set_row(r,"@i %.32s@r",(const char*)_descrconto); + set_row(r," %.32s@r",(const char*)_descrconto); + set_row(r,"@42g%s",(const char*)udata); + } + set_row(r++,"@57g%r@77g%r@97g%r@117g%r",&_prg_dare_conto,&_prg_avere_conto,&_saldo_dare_conto,&_saldo_avere_conto); + if ( (_scelta == 1) || ((_scelta == 2) && (_tp == fine)) ) + set_row(r,"%s",(const char*)riga); +} + +void CG3500_application::setta_riga_gruppo() +{ + TString riga (132); + int r = 0; + + riga.fill('-'); + if (_scelta == 1) + if (_tp == fine) r = 5; + else r = 4; + if (_scelta == 2) + if (_tp == fine) r = 3; + else r = 2; + //set_row(r,"**** TOTALI GRUPPO %3d-",_ggruppo); + set_row(r,"**** TOTALI GRUPPO %3d ",_ggruppo); + //set_row(r,"@i %.30s@r",(const char*)_descrgruppo); + set_row(r," %.30s@r",(const char*)_descrgruppo); + set_row(r++,"@57g%r@77g%r@97g%r@117g%r",&_prg_dare_gruppo,&_prg_avere_gruppo,&_saldo_dare_gruppo,&_saldo_avere_gruppo); + set_row(r++,"%s",(const char*)riga); + riga = ""; + set_row(r,"%s",(const char*)riga); +} + +void CG3500_application::setta_riga_totale() +{ + int r; + + _saldo_tot = _prg_dare_tot - _prg_avere_tot; + if (_scelta == 1) r = 8; + else r = 6; + set_row(r,"**** TOTALE GENERALE @57g%r@77g%r",&_prg_dare_tot,&_prg_avere_tot); + if (_saldo_tot > 0.00) + set_row(r,"@97g%r",&_saldo_tot); + else + { + _saldo_tot = _saldo_tot * (-1.00); + set_row(r,"@117g%r",&_saldo_tot); + } +} + +TDate CG3500_application::UltimaData(int g, int c, long s) +{ + TLocalisamfile saldi(LF_SALDI, FALSE); //il parametro a false permette di usare un record corrente del file saldi differente a quello del file temporaneo + TDate uldata; + + saldi.zero(); + if (_annoese != 0) + saldi.put(SLD_ANNOES, _annoese); + saldi.put(SLD_GRUPPO,g); + if (c != 0) + saldi.put(SLD_CONTO, c); + if (s != 0) + saldi.put(SLD_SOTTOCONTO, s); + saldi.read(); + if (saldi.bad()) + saldi.zero(); + uldata = saldi.get(SLD_DATAULMOV); + + return uldata; +} + +bool CG3500_application::user_create() +{ + _clifo = new TLocalisamfile(LF_CLIFO); + _com = new TLocalisamfile(LF_COMUNI); + _pcn = new TLocalisamfile(LF_PCON); + _saldi = new TLocalisamfile(LF_SALDI); + _nditte = new TLocalisamfile(LF_NDITTE); + _anag = new TLocalisamfile(LF_ANAG); + _tmp_saldi = new TIsamtempfile (LF_SALDI); + return TRUE; +} + +bool CG3500_application::user_destroy() +{ + delete _com; + delete _pcn; + delete _clifo; + delete _saldi; + delete _nditte; + delete _anag; + delete _tmp_saldi; + return TRUE; +} + +bool CG3500_application::set_print(int) +{ + TMask m ("cg3500a"); + KEY tasto; + + tasto = m.run(); + if (tasto == K_ENTER) + { + _annoese = atoi(m.get(F_ANNO)); + _scelta = atoi(m.get(F_STAMPA)); + _richiesta = atoi(m.get(F_RICHIESTA)); + _data = m.get(F_DATASTAMPA); + _prog = new TProgind(_pcn->items(),"Elaborazione in corso... prego attendere",FALSE); + + riepilogo(); + + delete _prog; + return TRUE; + } + return FALSE; +} + +TRectype& cerca_com (const char * cod, TLocalisamfile *comuni) +{ + comuni->zero(); + comuni->put(COM_COM, cod); + comuni->read(); + if (comuni->bad()) + comuni->zero(); + + return comuni->curr(); +} + +void CG3500_application::get_dati_ditta() +{ + TLocalisamfile nditte(LF_NDITTE); + TLocalisamfile anag(LF_ANAG); + 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 = cerca_com (_comunefis, _com); + + _comunefis = dep.get(COM_DENCOM); + _provfis = dep.get(COM_PROVCOM); + _cap = dep.get(COM_CAPCOM); + if (_comunefis.empty()) + { + _viafis = anag.get(ANA_INDRF); + _viafis.rtrim(); + _viafis << " " << anag.get (ANA_CIVRF); + } + else + { + _viafis = anag.get(ANA_INDRES); + _viafis.rtrim(); + _viafis << " " << anag.get (ANA_CIVRES); + } +} + +int CG3500_application::stampa_intestazione_ditta() +{ + int r = 1; + TString codice_ditta; + TString riga(132); + + 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); + riga = "Data @< Pag. @#"; + riga.right_just(127); + riga.overwrite (format ("Partita iva %s Codice fiscale %s", (const char*)_paiva, (const char*)_cofi)); + set_header (r, "%s", (const char*) riga); + r++; + + return r; +} + +void CG3500_application::preprocess_header() +{ + int r; + reset_header(); + r = stampa_intestazione_ditta(); + TString riga (132); + + r++; + if (_scelta == 1) //stampa riepilogo conti + set_header(r,"*** MASTRO DI CONTO ***"); + else set_header(r,"*** MASTRO DI GRUPPO ***"); + set_header(r,"@33gAnno esercizio %d", _annoese); + if (_richiesta == 1) + set_header(r,"@70gPROGRESSIVI ATTUALI@114gSALDO ATTUALE"); + else set_header(r,"@70gPROG. MOV. ELIMINATI@110gSALDO MOV. ELIMINATI"); + + r++; + r++; + if (_scelta == 1) + set_header(r,"SOTTOC DESCRIZIONE"); + else set_header(r,"CONTO DESCRIZIONE"); + set_header(r++,"@40gDATA ULT.MOV@68gDARE@87gAVERE@108gDARE@127gAVERE"); + riga.fill('-'); + set_header(r,"%s",(const char*)riga); + r++; + riga = ""; + set_header(r,"%s",(const char*)riga); +} + +int cg3500 (int argc, char* argv[]) +{ + + CG3500_application a; + + a.run(argc, argv, "Stampa riepilogo gruppi/conti"); + + return 0; +} + + + + + +