From 25fa8d82c08a88138b30c57369d986be60ee1926 Mon Sep 17 00:00:00 2001 From: bonazzi Date: Mon, 9 Jan 2017 22:00:26 +0000 Subject: [PATCH] Patch level : 12.0 324 Files correlati : np0.exe np0300a.uml np0400a.uml np0500a.uml np0600a.uml np0600b.uml npmenu.men MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Aggiornato tutto il modulo Contabilità Separata. Le modifiche di contabilità sono sui define per NP e non necessitano di patch. I programmi cg1 e cg3 si compilano correttamente. git-svn-id: svn://10.65.10.50/branches/R_10_00@23504 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- src/cg/cg1500.cpp | 8186 ++++++++++++++++++++++---------------------- src/cg/cg1500.h | 3 +- src/cg/cg1500a.uml | 24 +- src/cg/cg3100.cpp | 4989 +++++++++++++-------------- src/cg/cg3100a.uml | 4 + src/cg/cg3100b.uml | 4 + src/cg/cg3200.cpp | 7482 ++++++++++++++++++++-------------------- src/cg/cg3200.h | 2 +- src/cg/cg3200a.uml | 12 +- src/cg/cg3600.cpp | 5382 +++++++++++++++-------------- src/cg/cg3600a.uml | 12 +- src/cg/cg3600b.uml | 4 + 12 files changed, 13052 insertions(+), 13052 deletions(-) diff --git a/src/cg/cg1500.cpp b/src/cg/cg1500.cpp index 041f6738a..cefd3b185 100755 --- a/src/cg/cg1500.cpp +++ b/src/cg/cg1500.cpp @@ -1,4094 +1,4092 @@ -// Stampa bilanci - -// W96SALDI e' la sigla di tutte le modifiche effettuate riguardo il cambiamento dell' archivio -// SALDI. L' archivio e' cambiato nel seguente modo: -// - Non esistono piu' i progressivi dei movimenti scaricati PDARESCA e PAVERESCA; -// - Ora esistono un record per i movimenti normali e un record per i movimenti scaricati; la -// distinzione e' resa possibile dall' introduzione in chiave di un flag FLSCA (vedi tracciato) -// che e' un booleano. Il record con FLSCA = FALSE contiene la somma dei saldi dei movimenti -// normali e dei movimenti scaricati, mentre il record con FLSCA = TRUE, contiene solo i saldi -// dei movimenti scaricati. -// Tutti i progressivi che nel programma venivano memorizzati nei campi PDARESCA e PAVERESCA dei -// file temporanei ora sono memorizzati in PDAREPRO e PAVEREPRO. -// Le funzioni che sono state modificate sono: -// - bil_verifica(); -// - ricerca_cf(...); -// - scrivi_record_gruppo(); -// - scrivi_record_conto(); -// - leggi_clifo(); -// - leggi_file_tmp(); -// - UltimaData(); - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cg1.h" -#include "cg1500.h" -#include "cglib01.h" -#include "cglib02.h" - -class TStampa_bilanci : public TPrintapp -{ - static bool mask_anno (TMask_field& f, KEY k); - static bool mask_datalim (TMask_field& f, KEY k); - static bool verifica_handler(TMask_field& f, KEY k); - static bool mask_date (TMask_field& f, KEY k); - static bool mask_bilancio(TMask_field& f, KEY k); - static bool mask_tipost (TMask_field& f, KEY k); - - struct cli_for - { - char tipocf; - char gruppo[4]; - char conto[4]; - char codcf[7]; - char ragsoc[51]; - real saldodare; - real saldoavere; - real movdare; - real movavere; - real saldofinale; - TDate udata; - }; - - TSort * _sort; - - TRelation* _rel; - TCursor * _cur; - TProgress_monitor * _prog; - TSaldi_list* _listacf, * _lista; - TLocalisamfile* _com, * _pcn, * _mov, * _rmov, * _clifo, * _saldi, * _nditte,* _anag,* _caus; - TIsamtempfile * _tmp_saldi_att, * _tmp_saldi_pass, * _tmp_saldi_conti_uno; - TIsamtempfile * _tmp_saldi_costi, * _tmp_saldi_ricavi,* _tmp_saldi_conti_due; - TParagraph_string* _d; - const char* _buff; - bool _noseparator; // Usa separatore delle migliaia o no? -#ifdef CONT_SEP - bool _fl_cont_sep; -#endif - - TString _cofi,_cap,_paiva,_ragsoc,_comunefis,_provfis,_viafis; - TString _descr_dare, _descr_avere, _gc_corr_dare, _gc_corr_avere, _descr; - TString _gc_prec_dare, _gc_prec_avere, _situazione, _descr_succ; - TString _tmp; -#ifdef CONT_SEP - TString _cont_sep; -#endif - char _tipo_conto, _tipoc_succ; - - int _annoes, _bilancio, _tipo_stampa, _tipo_stampa1,_stampa_width,_gp,_cp,_i; - int _eof1, _eof2, _gruppo_dare, _gruppo_avere, _conto_dare, _conto_avere; - int _add_file_da, _add_file_a, _indbil_dare, _indbil_avere, _indbil; - int _eof3, _eof4, _eof5, _eof6, _verifica, _stampac, _stampav, _ordinamento, _print_full_code; - int _gruppo, _conto, _gruppo_succ, _conto_succ, _annoapp; - long _sottoconto_dare, _sottoconto_avere, _sottoconto, _sottoconto_succ; - - real _saldo_dare, _saldo_avere, _gruppo_a, _gruppo_da, _conto_a; - real _conto_da, _tot_dare, _tot_avere, _mov_periodo_dare, _saldo_ini_dare; - real _mov_periodo_avere, _saldo_ini_avere, _prg_prec_dare, _prg_prec_avere; - real _saldo_ini_conto_dare, _saldo_ini_conto_avere, _saldoini_dare; - real _saldoini_avere, _mov_dare, _mov_avere, _saldofinale; - real _saldoini_dare_succ, _saldoini_avere_succ, _mov_dare_succ; - real _mov_avere_succ, _saldofinale_succ; - real _saldo_dare_tot, _saldo_avere_tot, _mov_dare_tot, _mov_avere_tot; - real _saldo_finale_tot, _saldo_ini_gruppo_dare, _saldo_ini_gruppo_avere; - real _gruppo_da_ordine, _gruppo_a_ordine; - real _prg_saldoini_dare, _prg_saldoini_avere, _prg_inidare_ord, _prg_iniavere_ord; - real _nuovo_tot_saldo_d, _nuovo_tot_saldo_a; - - TDate _datalim, _data, _datada, _dataa, _dataini, _ultima_data, _u_max; - bool _cambiato_conto_1, _cambiato_conto_2, _add_file_avere; - bool _add_file_dare, _prima_volta, _seconda_volta, _totali, _codici, _saldo; - bool _add_dare, _add_avere, _controlla, _salto_pagina, _flag, _stampato; - bool _sottoc_dare, _sottoc_avere, _salto_pagina1, _livello_conto; - bool _mov_ap,_quadratura; - bool _print_exercise, _hide_clifo; - int _stampa_mov_prov; - TBill _bill_from, _bill_to; - TArray _clienti, _fornitori; - -public: - TDate _inizioEs, _fineEs; - - int date2esc(const TDate& d, int* prevesc = NULL); - - bool menu (MENU_TAG m) { return TPrintapp::menu(m) ; } - virtual bool user_create() ; - virtual bool user_destroy(); - bool set_print(int); - - void next_c(); - - 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(); - virtual void set_page(int,int); - real compensazione(bool compensa, int indbil_conto, real& saldo); - //const char* causale_chiusura() { return _causale_chi;} - //const char* causale_apertura() { return _causale_ap;} - bool bil_sez_contr(); - bool bil_verifica(); - bool ricerca_sottoc_clifo(int,int,bool,int,real&); - bool ricerca_cf(int,int,char,int,real&,real&,real&,real&,real&,real&,real&); - bool calcola(int,int,long); - void leggi_pcon(); // Inizializza i TArray C/F - void crea_sort_clifo(); - void leggi_clifo(const TArray&); - void init_sort(); - void leggi_sort(); - void riempi_record(char,int,int,long,const char*,const real&, - const real&,const real&,const real&,const real&); - void get_dati_ditta(); - void scrivi_record_conto(const real&,const real&,const real&, - const real&, const real&); - void scrivi_record_gruppo(const real&,const real&,const real&, - const real&, const real&); - int stampa_record_conto(int,int,const TString&,const real&,const real&, - const real&,const real&,const real&,const char); - int stampa_intestazione_ditta(); - int cerca_indbil(int,int); - void scrivig_file_temp(); - void scrivic_file_temp(); - void scrivis_file_temp(int,int,long,const real&); - void leggi_files_dare (TIsamtempfile*); - void leggi_files_avere(TIsamtempfile*); - void leggi_file_tmp(); - void stampa_riga_totali(int); - void stampa_prima_colonna(int,int,long,const char*,const real&); - void stampa_seconda_colonna(int,int,long,const char*,const real&); - void stampa_totali(); - void stampa_totali_uno(const real&, const real&); - void controlla_conto(int,int); - const char* DescrizioneConto(int,int,long,char); //chiama quella di TConto - TDate UltimaData(int,int,long,int); - void stampa_un_bilancio(const TMask& m); - - TStampa_bilanci() {} -}; - -HIDDEN inline TStampa_bilanci& app() { return (TStampa_bilanci&)main_app(); } - -TDate InizioEsercizio(int anno) -{ - TEsercizi_contabili esc; - TDate inizio_es; - if (esc.exist(anno)) - inizio_es = esc[anno].inizio(); - return inizio_es; -} - -TDate FineEsercizio(int anno) -{ - TEsercizi_contabili esc; - TDate fine_es; - if (esc.exist(anno)) - fine_es = esc[anno].fine(); - return fine_es; -} - -bool IsEsercizio (const TDate& datalim, int anno_eser) -{ - TEsercizi_contabili esc; - bool yes = esc.date2esc(datalim) == anno_eser; - return yes; -} - -int TStampa_bilanci::date2esc(const TDate& d, int* prevesc) -{ - TEsercizi_contabili esc; - int anno = esc.date2esc(d); - if (prevesc) - *prevesc = esc.pred(anno); - return anno; -} - -bool TStampa_bilanci::mask_anno(TMask_field& f, KEY k) -{ - if (k == K_ENTER) - { - int tipo_stampa; - int anno = f.mask().get_int(F_ANNO); - int bilancio = f.mask().get_int(F_BILANCIO); - if (bilancio == 1) - tipo_stampa = f.mask().get_int(F_STAMPA); - else - tipo_stampa = f.mask().get_int(F_STAMPA1); - if (tipo_stampa == 2) - if (anno == 0) - { - f.error_box(TR("Indicare l'anno di esercizio")); - return FALSE; - } - } - if ( k == K_TAB || f.focusdirty()) - { - int tipo_stampa; - int anno = f.mask().get_int(F_ANNO); - int bilancio = f.mask().get_int(F_BILANCIO); - if (bilancio == 1) - tipo_stampa = f.mask().get_int(F_STAMPA); - else - tipo_stampa = f.mask().get_int(F_STAMPA1); - - if ((bilancio == 2) && (tipo_stampa == 1)) - if (anno != 0) - { - f.mask().show(F_DATADA); - f.mask().show(F_DATAA); - //f.mask().show(F_STAMPAMPROV); - f.mask().show(96); - f.mask().show(97); - f.mask().hide(98); - f.mask().hide(99); - } - else - { - f.mask().show(F_DATADA); - f.mask().show(F_DATAA); - //f.mask().show(F_STAMPAMPROV); - f.mask().show(98); - f.mask().show(99); - f.mask().hide(96); - f.mask().hide(97); - } - } - if (k == K_TAB) - { - int tipo_bil, tipo_stp; - tipo_bil = f.mask().get_int(F_BILANCIO); - if (tipo_bil == 1) - tipo_stp = f.mask().get_int(F_STAMPA); - else - tipo_stp = f.mask().get_int(F_STAMPA1); - if (tipo_bil == 2 && tipo_stp == 1 /* && f.mask().get_int(F_ANNO) == 0 */) - f.mask().show(F_QUADRATURA); - else - { - f.mask().set (F_QUADRATURA,""); - f.mask().hide(F_QUADRATURA); - } - } - return TRUE; -} - -bool TStampa_bilanci::mask_bilancio(TMask_field& f, KEY k) -{ - int tipo_bil, tipo_stp; - - if (k == K_SPACE) - { - TMask& m = f.mask(); - const int anno = m.get_int(F_ANNO); - const int bilancio = m.get_int(F_BILANCIO); - int tipo_stampa; - if (bilancio == 1) //bilancio a sezioni contrapposte - { - tipo_stampa = m.get_int(F_STAMPA); - m.disable_page(1); - } - else - { - tipo_stampa = m.get_int(F_STAMPA1); - m.enable_page(1); - } - - if (tipo_stampa == 2) //all'ultima immissione - { - m.hide(F_DATADA); - m.hide(F_DATAA); - //m.hide(F_STAMPAMPROV); - m.hide(98); - m.hide(99); - m.hide(96); - m.hide(97); - - // Disabilito le commesse nelle stampe all'ultima immissione - m.hide(-4); - m.reset(-4); - } - else - { - if (bilancio == 2) - if (anno != 0) - { - m.show(F_DATADA); - m.show(F_DATAA); - //m.show(F_STAMPAMPROV); - m.show(96); - m.show(97); - m.hide(98); - m.hide(99); - } - else - { - m.show(F_DATADA); - m.show(F_DATAA); - //m.show(F_STAMPAMPROV); - m.show(98); - m.show(99); - m.hide(96); - m.hide(97); - } - - // Abilito eventualmente le commesse - if (main_app().has_module(CMAUT)) - m.show(-4); - else - { - m.hide(-4); - m.reset(-4); - } - } - - tipo_bil = f.mask().get_int(F_BILANCIO); - if (tipo_bil == 1) - tipo_stp = f.mask().get_int(F_STAMPA); - else - tipo_stp = f.mask().get_int(F_STAMPA1); - if (tipo_bil == 2 && tipo_stp == 1 /* && f.mask().get_int(F_ANNO) == 0 */) - f.mask().show(F_QUADRATURA); - else - { - f.mask().set (F_QUADRATURA,""); - f.mask().hide(F_QUADRATURA); - } - } - return TRUE; -} - -bool TStampa_bilanci::mask_datalim (TMask_field& f, KEY k) -{ - if (k == K_ENTER) - { - int anno = f.mask().get_int(F_ANNO); - int bilancio = f.mask().get_int(F_BILANCIO); - TDate datalim(f.mask().get(F_DATALIM)); - if (bilancio == 1) - if (anno != 0) - { - if ( datalim.ok() ) - { - if (!IsEsercizio(datalim,anno)) - { - f.error_box (TR("La data limite deve appartenere all'esercizio indicato")); - return FALSE; - } - } - else - f.mask().field(F_DATALIM).set(FineEsercizio(anno)); - } - else //anno == 0 - { - if (!datalim.ok()) - { - f.error_box (TR("La data limite e' obbligatoria")); - return FALSE; - } - long anno = app().date2esc(datalim); - if (anno == 0) - { - f.error_box (TR("La data limite deve appartenere ad un esercizio attivo della ditta")); - return FALSE; - } - } - } - return TRUE; -} - -bool TStampa_bilanci::mask_date(TMask_field& f, KEY k) -{ - if (k == K_TAB) - { - const short id = f.dlg(); - - if (id == F_DATAA) - { - TDate data (f.get()); - int bil = f.mask().get_int(F_BILANCIO); - TEsercizi_contabili esc; - int anno = esc.date2esc(data); - if (anno) - { - TDate dataini = esc[anno].fine(); - if (data == dataini && bil == 2 /*&& f.mask().get_int(F_ANNO) == 0*/) - f.mask().show(F_QUADRATURA); - else - { - f.mask().reset(F_QUADRATURA); - f.mask().hide(F_QUADRATURA); - } - } - } - } - - if (k == K_ENTER) - { - const short id = f.dlg(); - int anno = f.mask().get_int(F_ANNO); - int bilancio = f.mask().get_int(F_BILANCIO); - if (bilancio == 2) - { - TDate data (f.mask().get(id)); - if (anno != 0) - { - if (data.ok()) - { - if (!IsEsercizio(data,anno)) - { - f.error_box(TR("La data indicata deve essere all'interno dell'esercizio")); - return FALSE; - } - } - if (!data.ok()) - { - if (id == F_DATADA) - f.mask().field(F_DATADA).set(InizioEsercizio(anno)); - else if (id == F_DATAA) - f.mask().field(F_DATAA).set(FineEsercizio(anno)); - } - app()._annoapp = anno; - } - else - { - if ( !data.ok() ) - { - f.error_box(TR("Indicare una data appartenente ad un esercizio attivo della ditta")); - return FALSE; - } - else - { - if (id == F_DATAA) - { - TDate from (f.mask().get(id - 1)); - app()._annoapp = app().date2esc(from); - if ( app()._annoapp != app().date2esc(data) ) - { - f.error_box(TR("Le date devono appartenere ad uno stesso esercizio attivo della ditta")); - return FALSE; - } - if (from > data) - { - f.error_box(TR("La data limite inferiore non puo' essere maggiore della data limite superiore")); - return FALSE; - } - } - } - } - } - } - return TRUE; -} - -bool TStampa_bilanci::verifica_handler(TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - int tipo_stampa = atoi(f.mask().get(F_STAMPA1)); - int verifica = atoi(f.mask().get(F_VERIFICA)); - if ( (tipo_stampa == 1) && ((verifica == 1) || (verifica == 2)) ) - { - f.mask().hide (F_SITUAZIONE); - f.mask().hide (F_STAMPAC); - f.mask().hide (F_ORDINAMENTO); - f.mask().show (F_STAMPAV); - f.mask().show (F_DATADA); - f.mask().show (F_DATAA); - } - if ( (tipo_stampa == 1) && (verifica == 3) ) - { - f.mask().show (F_SITUAZIONE); - f.mask().show (F_STAMPAC); - f.mask().show (F_ORDINAMENTO); - f.mask().show (F_DATADA); - f.mask().show (F_DATAA); - f.mask().hide (F_STAMPAV); - } - if ( (tipo_stampa == 2) && ((verifica == 1)||(verifica == 2)) ) - { - f.mask().hide (F_SITUAZIONE); - f.mask().hide (F_STAMPAC); - f.mask().hide (F_ORDINAMENTO); - f.mask().hide (F_DATADA); - f.mask().hide (F_DATAA); - f.mask().show (F_STAMPAV); - } - if ( (tipo_stampa == 2) && (verifica == 3) ) - { - f.mask().show (F_SITUAZIONE); - f.mask().show (F_STAMPAC); - f.mask().show (F_ORDINAMENTO); - f.mask().hide (F_DATADA); - f.mask().hide (F_DATAA); - f.mask().hide (F_STAMPAV); - } - } - return TRUE; -} - -void TStampa_bilanci::scrivig_file_temp() -{ - TIsamtempfile* tmp = NULL; - TString nome_campo(12); - real valore; - - if (!_totali) - { - if (_add_dare) - { - nome_campo = SLD_PDARE; - valore = _gruppo_da; - switch (_indbil) - { - case 1: - case 2: - tmp = _tmp_saldi_att; - break; - case 3: - case 4: - tmp = _tmp_saldi_costi; - break; - case 5: - tmp = _tmp_saldi_conti_uno; - valore = _gruppo_da_ordine; - break; - default: - break; - } - - tmp->zero(); - tmp->put(SLD_GRUPPO,_gp); - tmp->put(SLD_CONTO,0); - tmp->put(SLD_SOTTOCONTO,0L); - tmp->put(SLD_ANNOES,0); // W96SALDI del 07-06-96 - tmp->put(SLD_FLSCA,FALSE); - if (tmp->read() == NOERR) - { - tmp->put(SLD_CONTO,0); - tmp->put(SLD_SOTTOCONTO,0L); - tmp->put(nome_campo, valore); - tmp->rewrite(); - } - else - { - tmp->put(SLD_GRUPPO,_gp); - tmp->put(SLD_CONTO,0); - tmp->put(SLD_SOTTOCONTO,0L); - tmp->put(SLD_ANNOES,0); // W96SALDI del 07-06-96 - tmp->put(SLD_FLSCA,FALSE); - tmp->put(nome_campo, valore); - tmp->write(); - } - } - if (_add_avere) - { - nome_campo = SLD_PAVERE; - valore = _gruppo_a; - switch (_indbil) - { - case 1: - case 2: - tmp = _tmp_saldi_pass; - break; - case 3: - case 4: - tmp = _tmp_saldi_ricavi; - break; - case 5: - tmp = _tmp_saldi_conti_due; - valore = _gruppo_a_ordine; - break; - default: - break; - } - - tmp->zero(); - tmp->put(SLD_GRUPPO,_gp); - tmp->put(SLD_CONTO,0); - tmp->put(SLD_SOTTOCONTO,0L); - tmp->put(SLD_ANNOES,0); // W96SALDI del 07-06-96 - tmp->put(SLD_FLSCA,FALSE); - if (tmp->read() == NOERR) - { - tmp->put(SLD_CONTO,0); - tmp->put(SLD_SOTTOCONTO,0L); - tmp->put(nome_campo, valore); - tmp->rewrite(); - } - else - { - tmp->put(SLD_GRUPPO,_gp); - tmp->put(SLD_CONTO,0); - tmp->put(SLD_SOTTOCONTO,0L); - tmp->put(SLD_ANNOES,0); // W96SALDI del 07-06-96 - tmp->put(SLD_FLSCA,FALSE); - tmp->put(nome_campo, valore); - tmp->write(); - } - } - } - _add_dare = _add_avere = FALSE; -} - -void TStampa_bilanci::scrivic_file_temp() -{ - TIsamtempfile* tmp = NULL; - TString nome_campo(12); - real valore; - - if (_add_file_dare) - { - _add_dare = TRUE; - nome_campo = SLD_PDARE; - valore = _conto_da; - if (_indbil == 1 || _indbil==2) tmp = _tmp_saldi_att; // da stampare a sx - else - if (_indbil==3 || _indbil==4) tmp = _tmp_saldi_costi; //da stampare a sx - else - if (_indbil==5) tmp = _tmp_saldi_conti_uno; - else return; - tmp->zero(); - tmp->put(SLD_GRUPPO,_gp); - tmp->put(SLD_CONTO,_cp); - tmp->put(SLD_SOTTOCONTO,0L); - tmp->put(nome_campo, valore); - tmp->write(); - } - if (_add_file_avere) - { - _add_avere = TRUE; - nome_campo = SLD_PAVERE; - valore = _conto_a; - if (_indbil==2 || _indbil==1) tmp = _tmp_saldi_pass; //da stampare a dx - else - if (_indbil==4 || _indbil==3) tmp = _tmp_saldi_ricavi;//da stampare a dx - else - if (_indbil==5) tmp = _tmp_saldi_conti_due; - else return; - tmp->zero(); - tmp->put(SLD_GRUPPO,_gp); - tmp->put(SLD_CONTO,_cp); - tmp->put(SLD_SOTTOCONTO,0L); - tmp->put(nome_campo, valore); - tmp->write(); - } -} - -void TStampa_bilanci::scrivis_file_temp(int g, int c, long s, const real& saldo) -{ - TIsamtempfile* tmp = NULL; - TString16 nome_campo; - - if (_indbil==1) - { - tmp = _tmp_saldi_att; - nome_campo = SLD_PDARE; - } - else - if (_indbil==2) - { - tmp = _tmp_saldi_pass; - nome_campo = SLD_PAVERE; - } - else - if (_indbil==3) - { - tmp = _tmp_saldi_costi; - nome_campo = SLD_PDARE; - } - else - if (_indbil==4) - { - tmp = _tmp_saldi_ricavi; - nome_campo = SLD_PAVERE; - } - else - if (_sottoc_dare) - { - tmp = _tmp_saldi_conti_uno; - nome_campo = SLD_PDARE; - } - else - if (_sottoc_avere) - { - tmp = _tmp_saldi_conti_due; - nome_campo = SLD_PAVERE; - } - CHECKD(tmp, "Null tmp file: indbil = ", _indbil); - tmp->zero(); - tmp->put(SLD_GRUPPO,g); - tmp->put(SLD_CONTO,c); - tmp->put(SLD_SOTTOCONTO,s); - tmp->put(nome_campo, saldo); - tmp->write(); -} - -real TStampa_bilanci::compensazione(bool compensa, int indbil_conto, real& sld) -{ - real saldo = sld; - - if (!compensa) - { - switch (indbil_conto) - { - case 1: - if (saldo > ZERO) - _indbil = indbil_conto; - else - { - _indbil = 2; - saldo = -saldo; - } - break; - - case 3: - if (saldo > ZERO) - _indbil = indbil_conto; - else - { - _indbil = 4; - saldo = -saldo; - } - break; - - case 2: - if (saldo < ZERO) - { - _indbil = indbil_conto; - saldo = -saldo; - } - else - _indbil = 1; - break; - - case 4: - if (saldo < ZERO) - { - _indbil = indbil_conto; - saldo = -saldo; - } - else - _indbil = 3; - break; - case 5: - default: break; - } - } - else //e' richiesta la compensazione - if ( indbil_conto==2 || indbil_conto==4) - saldo = -saldo; - - return saldo; -} - -void TStampa_bilanci::next_c() -{ - TRecnotype recnum = _pcn->recno(); - _pcn->next(); - if (_pcn->eof()) - { - scrivic_file_temp(); - scrivig_file_temp(); - } - _pcn->readat(recnum); -} - -bool TStampa_bilanci::bil_sez_contr() -{ - TSaldo sld; - int indbil_conto=0; - int g, c; - long s; - char tipo_conto = ' '; - real saldo; - bool compensa=FALSE, dettaglio=FALSE, cambiato=FALSE; - bool esiste_conto=FALSE, esiste_sc = FALSE; - bool movimentato = FALSE; - - CHECK(_tmp_saldi_att == NULL, "Non posso riaprire cg01"); - _tmp_saldi_att = new TIsamtempfile(LF_SALDI, "cg01", TRUE, TRUE); - _prog->addstatus(1); - _tmp_saldi_pass = new TIsamtempfile(LF_SALDI, "cg02", TRUE, TRUE); - _prog->addstatus(1); - _tmp_saldi_costi = new TIsamtempfile(LF_SALDI, "cg03", TRUE, TRUE); - _prog->addstatus(1); - _tmp_saldi_ricavi = new TIsamtempfile(LF_SALDI, "cg04", TRUE, TRUE); - _prog->addstatus(1); - _tmp_saldi_conti_uno = new TIsamtempfile(LF_SALDI, "cg05", TRUE, TRUE); - _prog->addstatus(1); - _tmp_saldi_conti_due = new TIsamtempfile(LF_SALDI, "cg06", TRUE, TRUE); - _prog->addstatus(1); - - _gp=-1; - _cp=-1; - _gruppo_a = ZERO; - _gruppo_da = ZERO; - _gruppo_da_ordine = ZERO; - _gruppo_a_ordine = ZERO; - _prg_saldoini_dare = ZERO; - _prg_saldoini_avere = ZERO; - _prg_inidare_ord = ZERO; - _prg_iniavere_ord = ZERO; - _conto_a = ZERO; - _conto_da = ZERO; - _add_dare = FALSE; - _add_avere = FALSE; - - sld.set_annoes(_annoes); - - 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); - - if (c != _cp) - cambiato = TRUE; - - if ( (((_cp != -1) && (c != _cp)) || ((_gp != -1) && (g != _gp))) && - esiste_sc ) - { - scrivic_file_temp(); - scrivig_file_temp(); - _cp = c; - esiste_conto = TRUE; - _conto_da = ZERO; - _conto_a = ZERO; - } - - if ( ((_gp != -1) && (g != _gp)) && esiste_conto ) - { - scrivig_file_temp(); - esiste_conto = FALSE; - _gp = g; - _gruppo_da = ZERO; - _gruppo_a = ZERO; - _gruppo_da_ordine = ZERO; - _gruppo_a_ordine = ZERO; - } - - if (cambiato) - { - _add_file_avere = FALSE; - _add_file_dare = FALSE; - cambiato = FALSE; - } - - if ( (s == 0) && (c != 0) ) //si tratta di un conto - { - compensa = _pcn->get_bool(PCN_COMPENS); - dettaglio = !_pcn->get_bool(PCN_STSOTTBIL); - tipo_conto = _pcn->get_char(PCN_TMCF); - indbil_conto = _pcn->get_int(PCN_INDBIL); - - if (indbil_conto <= 0) // Warning per Roberto! - { - yesnofatal_box(FR("Indicatore di bilancio %d nel conto %03d %03d"), indbil_conto, - _pcn->get_int (PCN_GRUPPO), _pcn->get_int (PCN_CONTO)); - indbil_conto = 1; - } - - if ( (tipo_conto == 'C') || (tipo_conto == 'F') ) - { - saldo = ZERO; - esiste_sc = ricerca_sottoc_clifo(g, c, compensa, indbil_conto, saldo); - if (esiste_sc) - { - _gp = g; - _cp = c; - } - TRecnotype recnum = _pcn->recno(); - _pcn->next(); - if (_pcn->eof()) - { - if (esiste_sc) - { - scrivic_file_temp(); - scrivig_file_temp(); - } - else if (esiste_conto) - scrivig_file_temp(); - } - _pcn->readat(recnum); - - continue; - } - } - - if ( (c == 0) || (s == 0) ) //si tratta di un conto o di un gruppo - { - esiste_sc = FALSE; - continue; - } - - if (_tipo_stampa == 1) //bil. a sez. contrapposte per data limite - { -#ifdef CONT_SEP - if (_fl_cont_sep) - movimentato = sld.saldo_cont_sep(g, c, s, _annoes, _datalim, indbil_conto, _cont_sep, _stampa_mov_prov) ; - else -#endif - movimentato = sld.data_limite_bilancio(_bilancio, g, c, s, _dataini, _datalim, indbil_conto, _stampa_mov_prov); - } - else - { - if (_tipo_stampa == 2) //bil. a sez. contrapposte all'ultima immissione es. in corso - movimentato = sld.ultima_immissione_bilancio(_annoes,g,c,s,indbil_conto,_stampa_mov_prov); - } - - if (!movimentato) - if (!sld.esiste_saldo() || !sld.significativo()) - { - next_c(); - continue; - } - - saldo = sld.saldo(); - real app = sld.saldoini(); - bool flag = sld.flagprec(); - - if (_saldo) //se richiesto di NON stampare i conti con saldo a zero - if (saldo == ZERO) - { - //modifica del 06/07/1995 - if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) - { - //real app = sld.saldoini(); - //bool flag = sld.flagprec(); - if (flag) - { - if (app > ZERO) - { - if (indbil_conto == 5) - _prg_inidare_ord += app; - else _prg_saldoini_dare += app; - } - else if (app < ZERO) - { - app = -app; - if (indbil_conto == 5) - _prg_iniavere_ord += app; - else _prg_saldoini_avere += app; - } - } - } - //fine - next_c(); - continue; - } - - esiste_sc = TRUE; - _indbil = indbil_conto; - - //i due flag seguenti servono solo per i conti d'ordine - _sottoc_dare = FALSE; - _sottoc_avere = FALSE; - - if (saldo != ZERO) - saldo = compensazione(compensa, indbil_conto, saldo); - - if (_indbil == 1 || _indbil == 2) - { - if (flag) - { - if (app > ZERO) - _prg_saldoini_dare += app; - else if (app < ZERO) - { - app = -app; - _prg_saldoini_avere += app; - } - } - } - - if (_indbil == 5) - { - //real app = sld.saldoini(); - if (flag) - { - if (app > ZERO) - _prg_inidare_ord += app; - else if (app < ZERO) - { - app = -app; - _prg_iniavere_ord += app; - } - } - } - - if ( _indbil==1 || _indbil==3 ) - { - _gruppo_da += saldo; - _conto_da += saldo; - _add_file_dare = TRUE; - } - - if ( _indbil==2 || _indbil==4 ) - { - _gruppo_a += saldo; - _conto_a += saldo; - _add_file_avere = TRUE; - } - - if (_indbil==5) - { - if ( saldo >= ZERO || compensa ) - { - _gruppo_da_ordine += saldo; - _conto_da += saldo; - _add_file_dare = TRUE; - _sottoc_dare = TRUE; - } - else - { - saldo = -saldo; - _gruppo_a_ordine += saldo; - _conto_a += saldo; - _add_file_avere = TRUE; - _sottoc_avere = TRUE; - } - scrivig_file_temp(); - } - if ( (dettaglio) && ( (tipo_conto != 'C') && (tipo_conto != 'F') ) ) - scrivis_file_temp(g, c, s, saldo); - - _gp = g; - _cp = c; - // } // da_considerare - - TRecnotype recnum = _pcn->recno(); - _pcn->next(); - if (_pcn->eof()) - { - scrivic_file_temp(); - scrivig_file_temp(); - } - _pcn->readat(recnum); - } - - return TRUE; -} - -bool TStampa_bilanci::ricerca_sottoc_clifo(int g,int c, bool compensa, int indbil_conto,real& saldo) -{ - TSaldo sld; - int aep=0; - long s, items; - bool esiste_sc = FALSE; - bool movimentato = FALSE; - - if (_annoes) - { - TEsercizi_contabili ese; - aep = ese.pred(_annoes); - } - sld.set_annoes(_annoes); - _listacf = new TSaldi_list(g, c, _annoes, aep); - - items = _listacf->items(); - - for (int i = 0; i < items; i++) - { - const TRectype* r = _listacf->saldi(); - - if (r == NULL) break; - - s = r->get_long(SLD_SOTTOCONTO); - - if (_tipo_stampa == 1) //bil. a sez. contrapposte per data limite - { -#ifdef CONT_SEP - if (_fl_cont_sep) - movimentato = sld.saldo_cont_sep(g, c, s, _annoes, _datalim, indbil_conto, _cont_sep, _stampa_mov_prov); - else -#endif - movimentato = sld.data_limite_bilancio(_bilancio,g,c,s,_dataini,_datalim,indbil_conto,_stampa_mov_prov); - } - else - if (_tipo_stampa == 2) //bil. a sez. contrapposte all'ultima immissione es. in corso - movimentato = sld.ultima_immissione_bilancio(_annoes, g, c, s, indbil_conto, _stampa_mov_prov); - - if (!movimentato) - if (!sld.esiste_saldo() || !sld.significativo()) - continue; - - saldo = sld.saldo(); - real app = sld.saldoini(); - bool flag = sld.flagprec(); - - if (_saldo) //se richiesto di non stampare i conti con saldo a zero - if (saldo == ZERO) - { - //modifica del 06/07/1995 - if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) - { - //real app = sld.saldoini(); - if (flag) - { - if (app > ZERO) - { - if (indbil_conto == 5) - _prg_inidare_ord += app; - else _prg_saldoini_dare += app; - } - else if (app < ZERO) - { - app = -app; - if (indbil_conto == 5) - _prg_iniavere_ord += app; - else _prg_saldoini_avere += app; - } - } - } - //fine - continue; - } - - esiste_sc = TRUE; - _indbil = indbil_conto; - - //i due flag seguenti servono solo per i conti d'ordine - _sottoc_dare = FALSE; - _sottoc_avere = FALSE; - - if (saldo != ZERO) - saldo = compensazione(compensa, indbil_conto, saldo); - - if (_indbil == 1 || _indbil == 2) - { - if (flag) - { - if (app > ZERO) - _prg_saldoini_dare += app; - else if (app < ZERO) - { - app = -app; - _prg_saldoini_avere += app; - } - } - } - - if (_indbil == 5) - { - //real app = sld.saldoini(); - if (flag) - { - if (app > ZERO) - _prg_inidare_ord += app; - else if (app < ZERO) - { - app = -app; - _prg_iniavere_ord += app; - } - } - } - - if ( (_indbil==1) || (_indbil==3) ) - { - _gruppo_da += saldo; - _conto_da += saldo; - _add_file_dare = TRUE; - } - - if ( (_indbil==2) || (_indbil==4) ) - { - _gruppo_a += saldo; - _conto_a += saldo; - _add_file_avere = TRUE; - } - - if (_indbil==5) - { - if ( (saldo >= ZERO) || (compensa) ) // il sottoconto ha saldo in dare - { - _gruppo_da_ordine += saldo; - _conto_da += saldo; - _add_file_dare = TRUE; - _sottoc_dare = TRUE; - } - else //il sottoconto ha saldo in avere - { - saldo = -saldo; - _gruppo_a_ordine += saldo; - _conto_a += saldo; - _add_file_avere = TRUE; - _sottoc_avere = TRUE; - } - scrivig_file_temp(); - } - } - delete _listacf; - return esiste_sc; -} - -bool TStampa_bilanci::bil_verifica() -{ - TSaldo sld; - int g, c, indbil_conto = 0; - long s; - char tipo_conto = ' '; - real saldo_finale, saldo_conto, saldo_gruppo, saldo_iniziale; - real mov_conto_dare, mov_conto_avere, prg_conto_dare, prg_conto_avere; - real mov_gruppo_dare, mov_gruppo_avere, prg_gruppo_dare, prg_gruppo_avere; - bool esiste_conto = FALSE, esiste_sc = FALSE, movimentato = FALSE; - - CHECK(_tmp_saldi_att == NULL, "Non posso riaprire cg01"); - _tmp_saldi_att = new TIsamtempfile(LF_SALDI, "cg01", TRUE, TRUE); - - _gp=-1; - _cp=-1; - - _saldo_ini_conto_dare = ZERO; - _saldo_ini_conto_avere = ZERO; - _saldo_ini_gruppo_dare = ZERO; - _saldo_ini_gruppo_avere = ZERO; - _nuovo_tot_saldo_d = ZERO; - _nuovo_tot_saldo_a = ZERO; - saldo_conto = ZERO; - mov_conto_dare = ZERO; - mov_conto_avere = ZERO; - prg_conto_dare = ZERO; - prg_conto_avere = ZERO; - saldo_gruppo = ZERO; - mov_gruppo_dare = ZERO; - mov_gruppo_avere = ZERO; - prg_gruppo_dare = ZERO; - prg_gruppo_avere = ZERO; - _u_max = 0l; - - //controllo sui gr/co/sc selezionati - if (_bill_from.gruppo() > 0) //se ho un gruppo iniziale valido... - { - if (_bill_from.sottoconto() > 0L) - { - _pcn->zero(); - _pcn->put(PCN_GRUPPO,_bill_from.gruppo()); //lo metto nel file del pianodeiconticorrente.. - _pcn->put(PCN_CONTO,_bill_from.conto()); //un valore alla volta - if (_pcn->read(_isequal) == NOERR) - { - indbil_conto = _pcn->get_int(PCN_INDBIL); - tipo_conto = _pcn->get_char(PCN_TMCF); - } - } - - _pcn->zero(); - _pcn->put(PCN_GRUPPO,_bill_from.gruppo()); //lo metto nel file del pianodeiconticorrente.. - _pcn->put(PCN_CONTO,_bill_from.conto()); //un valore alla volta - _pcn->put(PCN_SOTTOCONTO,_bill_from.sottoconto()); - _pcn->read(_isgteq); //..e la scansione del file _pcn parte da questo - } - else - _pcn->first(); //..se non e' stato selezionato nessun gruppo parto dal primo - - for ( ; !_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); - - if ( (((_cp != -1) && (c != _cp)) || ((_gp != -1) && (g != _gp))) && esiste_sc ) - { - if (_verifica == 2) - if (!((_stampav == 2) && (saldo_conto == 0))) - { - //modifica del 21/11/1995 - if (_tipo_stampa1 == 1 && _datada == _dataini) - { - _saldo_ini_gruppo_dare += _saldo_ini_conto_dare; - _saldo_ini_gruppo_avere += _saldo_ini_conto_avere; - } - else - //fine - { - const real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; - if (app < ZERO) - _saldo_ini_gruppo_avere += app; - else - _saldo_ini_gruppo_dare += app; - } - mov_gruppo_dare += mov_conto_dare; - mov_gruppo_avere += mov_conto_avere; - prg_gruppo_dare += prg_conto_dare; - prg_gruppo_avere += prg_conto_avere; - saldo_gruppo += saldo_conto; - } - //scrivo il record del conto; - if ( (_verifica == 1)||( (_verifica == 2)&& - (!((_stampav == 2)&&(saldo_conto == 0))) ) ) - { - scrivi_record_conto(prg_conto_dare,prg_conto_avere,mov_conto_dare, - mov_conto_avere,saldo_conto); - esiste_conto = TRUE; - } - _cp = c; - _saldo_ini_conto_dare = ZERO; - _saldo_ini_conto_avere = ZERO; - saldo_conto = ZERO; - mov_conto_dare = ZERO; - mov_conto_avere = ZERO; - prg_conto_dare = ZERO; - prg_conto_avere = ZERO; - } - if (_verifica == 2) - if ( ((_gp != -1) && (g != _gp)) && (!esiste_conto) ) - { - _gp = g; - _saldo_ini_gruppo_dare = ZERO; - _saldo_ini_gruppo_avere = ZERO; - saldo_gruppo = ZERO; - mov_gruppo_dare = ZERO; - mov_gruppo_avere = ZERO; - prg_gruppo_dare = ZERO; - prg_gruppo_avere = ZERO; - } - if (_verifica == 2) - if ( ((_gp != -1) && (g != _gp)) && esiste_conto ) - { - //scrivo il record del gruppo - scrivi_record_gruppo(prg_gruppo_dare,prg_gruppo_avere,mov_gruppo_dare, - mov_gruppo_avere,saldo_gruppo); - _gp = g; - esiste_conto = FALSE; - _saldo_ini_gruppo_dare = ZERO; - _saldo_ini_gruppo_avere = ZERO; - saldo_gruppo = ZERO; - mov_gruppo_dare = ZERO; - mov_gruppo_avere = ZERO; - prg_gruppo_dare = ZERO; - prg_gruppo_avere = ZERO; - } - if ( (s == 0) && (c != 0) ) //si tratta di un conto - { - tipo_conto = _pcn->get_char(PCN_TMCF); - indbil_conto = _pcn->get_int(PCN_INDBIL); - if ( (tipo_conto == 'C') || (tipo_conto == 'F') ) - { - esiste_sc = ricerca_cf(g,c,tipo_conto,indbil_conto,saldo_finale,saldo_iniziale, - mov_conto_dare,mov_conto_avere,prg_conto_dare,prg_conto_avere, - saldo_conto); - if (_verifica == 2 && _stampav == 2 && saldo_conto.is_zero()) - continue; - if (esiste_sc) - { - _gp = g; - _cp = c; - const TRecnotype recnum = _pcn->recno(); - _pcn->next(); - if (_pcn->eof()) - { - if (_verifica == 2) - { - //modifica del 21/11/1995 - if (_tipo_stampa1 == 1 && _datada == _dataini) - { - _saldo_ini_gruppo_dare += _saldo_ini_conto_dare; - _saldo_ini_gruppo_avere += _saldo_ini_conto_avere; - } - else - //fine - { - real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; - if (app < ZERO) - _saldo_ini_gruppo_avere += app; - else - _saldo_ini_gruppo_dare += app; - } - mov_gruppo_dare += mov_conto_dare; - mov_gruppo_avere += mov_conto_avere; - prg_gruppo_dare += prg_conto_dare; - prg_gruppo_avere += prg_conto_avere; - saldo_gruppo += saldo_conto; - - scrivi_record_gruppo(prg_gruppo_dare,prg_gruppo_avere, - mov_gruppo_dare,mov_gruppo_avere,saldo_gruppo); - } - scrivi_record_conto(prg_conto_dare,prg_conto_avere,mov_conto_dare, - mov_conto_avere,saldo_conto); - } - _pcn->readat(recnum); - } - continue; - } - } - - //controlla se e' arrivato all'ultimo gruppo/conto/sottoconto selezionato - const TBill curr_bill(g,c,s); - if (curr_bill > _bill_to) - break; - - if ( (c == 0) || (s == 0) ) - { - esiste_sc = FALSE; - continue; - } - - saldo_finale = saldo_iniziale = ZERO; //saldi relativi a ciascun sottoconto - _indbil = indbil_conto; - if (_tipo_stampa1 == 1) //bil. di verifica per data limite - { - //modifica del 21/11/95 - _mov_ap = FALSE; - //modifica del 19/06/95 - movimentato = calcola(g,c,s); - if (_stampa_mov_prov != 3) - { - if (movimentato) - { - //modifica del 21/11/95 - if (_mov_ap) - saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; - else //discorso flag "movimentato" (video) - { - TLocalisamfile saldi(LF_SALDI); // W96SALDI - saldi.zero(); // Modifica SALDI per movimenti - saldi.put(SLD_ANNOES, _annoes); // scaricati del 05-06-96 - saldi.put(SLD_FLSCA, FALSE); // Ho aggiunto saldi.put(SLD_FLSCA, FALSE); - saldi.put(SLD_GRUPPO, g); // In questo modo considero il record con - saldi.put(SLD_CONTO, c); // la somma fra progressivi normali e scaricati - saldi.put(SLD_SOTTOCONTO, s); - if (saldi.read() == NOERR) - { - const real ss = saldi.get_real(SLD_SALDO); - if (ss.is_zero()) - { - if (_annoes != 0 && (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5)) - { - saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s,false,_stampa_mov_prov == 2); - //modifica del 21/11/95 - if (saldo_iniziale > ZERO) - _saldo_ini_dare = saldo_iniziale; - else - _saldo_ini_avere = -saldo_iniziale; - //fine - } - } - else - { - const char fsi = saldi.get_char(SLD_FLAGSALINI); - if (fsi == 'D') - { - saldo_iniziale = ss; - _saldo_ini_dare = ss; - } - else - { - saldo_iniziale = -ss; - _saldo_ini_avere = ss; - } - } - } - } - } - else // !movimentato -> _mov_ap e' di sicuro FALSE - { - if (_annoes != 0 && (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5)) - { - saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s,false,_stampa_mov_prov == 2); - //modifica del 21/11/95 - if (saldo_iniziale > ZERO) - _saldo_ini_dare = saldo_iniziale; - else _saldo_ini_avere = -saldo_iniziale; - //fine - if (_stampav == 1 && sld.significativo()) - movimentato = TRUE; - } - } - } - - - if (movimentato || _stampav != 1) - { - - _nuovo_tot_saldo_d += _mov_periodo_dare; - _nuovo_tot_saldo_a += _mov_periodo_avere; - _nuovo_tot_saldo_d += _saldo_ini_dare; - _nuovo_tot_saldo_a += _saldo_ini_avere; - - if (_datada == _dataini) - saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; - else if (_datada > _dataini) - { - if (saldo_iniziale > 0) - _prg_prec_dare += saldo_iniziale; - else _prg_prec_avere -= saldo_iniziale; - saldo_finale = _prg_prec_dare-_prg_prec_avere+_mov_periodo_dare-_mov_periodo_avere; - - } - //if (saldo_finale == ZERO) - // if (_stampav == 2) - // continue; - } - //se saldo_finale < 0 verra' stampato con una A, se no con una D - } - else - { - movimentato = sld.ultima_immissione_verifica(_annoes,g,c,s,indbil_conto,_stampa_mov_prov); - - if (_stampa_mov_prov != 3) - { - if (movimentato) - saldo_iniziale = sld.saldoini(); - if (!movimentato) - { - if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) - { - saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s,FALSE,_stampa_mov_prov == 2); - if (_stampav == 1 && sld.significativo()) - movimentato = TRUE; - } - } - } - - if (movimentato || _stampav != 1) - { - _mov_periodo_dare = sld.prgdare(); - _mov_periodo_avere = sld.prgavere(); - _prg_prec_dare = ZERO; - _prg_prec_avere = ZERO; - - if (sld.sezsf() == 'A') - _mov_periodo_avere -= sld.saldofin(); - else - _mov_periodo_dare += sld.saldofin(); - - saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; - } - } - - if ((movimentato || _stampav != 1) && !(saldo_finale.is_zero() && _stampav == 2)) - { - esiste_sc = TRUE; - esiste_conto = TRUE; - - if (_tipo_stampa1 == 2) - { - _nuovo_tot_saldo_d += _mov_periodo_dare; - _nuovo_tot_saldo_a += _mov_periodo_avere; - real nuovo = sld.saldoinisusaldi(); - if (nuovo > ZERO) - _nuovo_tot_saldo_d += nuovo; - else - { - nuovo = -nuovo; - _nuovo_tot_saldo_a += nuovo; - } - } - //modifica del 21/11/1995 - if (_tipo_stampa1 == 1 && _datada == _dataini) - { - _saldo_ini_conto_dare += _saldo_ini_dare; - _saldo_ini_conto_avere += _saldo_ini_avere; - } - else //_tipo_stampa1 == 1 || _tipo_stampa1 == 2 - { - if (saldo_iniziale < ZERO) - _saldo_ini_conto_avere += saldo_iniziale; - else - _saldo_ini_conto_dare += saldo_iniziale; - } - - mov_conto_dare += _mov_periodo_dare; - mov_conto_avere += _mov_periodo_avere; - prg_conto_dare += _prg_prec_dare; - prg_conto_avere += _prg_prec_avere; - saldo_conto += saldo_finale; // somma pitagorica - - //scrivo il record relat. al sottoconto se non e' richiesto saldi di mastro - if (_verifica != 2) - { - _tmp_saldi_att->zero(); - _tmp_saldi_att->put(SLD_GRUPPO,g); - _tmp_saldi_att->put(SLD_CONTO,c); - _tmp_saldi_att->put(SLD_SOTTOCONTO,s); - _tmp_saldi_att->put(SLD_FLAGSALINI,tipo_conto); - - if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) - { - //modifica del 21/11/1995 - if (_datada == _dataini && _tipo_stampa1 == 1) - { - _tmp_saldi_att->put(SLD_PDAREPRO,_saldo_ini_dare); // W96SALDI del 05-06-96 - _tmp_saldi_att->put(SLD_PAVEREPRO,_saldo_ini_avere); - } - else - { - if (saldo_iniziale > ZERO) //va stampato in Dare - _tmp_saldi_att->put(SLD_PDAREPRO,saldo_iniziale); // W96SALDI del 05-06-96 - else if (saldo_iniziale < ZERO) - { - saldo_iniziale = -saldo_iniziale; - _tmp_saldi_att->put(SLD_PAVEREPRO,saldo_iniziale); // W96SALDI del 05-06-96 - } - } - } - else if (_datada > _dataini) - { - _tmp_saldi_att->put(SLD_PDAREPRO,_prg_prec_dare); // W96SALDI del 05-06-96 - _tmp_saldi_att->put(SLD_PAVEREPRO,_prg_prec_avere); - } - _tmp_saldi_att->put(SLD_PDARE,_mov_periodo_dare); - _tmp_saldi_att->put(SLD_PAVERE,_mov_periodo_avere); - _tmp_saldi_att->put(SLD_SALDO,saldo_finale); - _tmp_saldi_att->put(SLD_DATAULMOV,_u_max); - _tmp_saldi_att->write(); - } - _gp = g; - _cp = c; - } - - TRecnotype recnum = _pcn->recno(); - _pcn->next(); - if (_pcn->eof()) - { - if ( (_verifica == 2) && esiste_conto ) - { - //modifica del 21/11/1995 - if (_tipo_stampa1 == 1 && _datada == _dataini) - { - _saldo_ini_gruppo_dare += _saldo_ini_conto_dare; - _saldo_ini_gruppo_avere += _saldo_ini_conto_avere; - } - else - //fine - { - real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; - if (app < ZERO) - _saldo_ini_gruppo_avere += app; - else - _saldo_ini_gruppo_dare += app; - } - mov_gruppo_dare += mov_conto_dare; - mov_gruppo_avere += mov_conto_avere; - prg_gruppo_dare += prg_conto_dare; - prg_gruppo_avere += prg_conto_avere; - saldo_gruppo += saldo_conto; - - scrivi_record_gruppo(prg_gruppo_dare,prg_gruppo_avere, - mov_gruppo_dare,mov_gruppo_avere,saldo_gruppo); - } - if (esiste_sc) - if ( (_verifica == 1)||( (_verifica == 2)&& - (!((_stampav == 2)&&(saldo_conto == 0))) ) ) - scrivi_record_conto(prg_conto_dare,prg_conto_avere,mov_conto_dare, - mov_conto_avere,saldo_conto); - } - _pcn->readat(recnum); - } -return TRUE; -} - -// bilancio di verifica per data limite -// Calcola totali delle righe relative al g,c,s -bool TStampa_bilanci::calcola(int g, int c, long s) -{ - int annoe; - long num_reg; - TDate data_reg, data; - bool conto_mov = FALSE; - - TDecoder causali(LF_CAUSALI, CAU_MOVAP); - - TRelation rel(LF_RMOV); - rel.add(LF_MOV, "NUMREG==NUMREG"); - - TRectype& rmov = rel.curr(); - const TRectype& mov = rel.curr(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; - _u_max = 0l; - - TDate data_start = _dataini; - // Calcolo progressivi precedenti: - // e non è indicato l'anno esercizio, prende il primo giorno dell'anno indicato da _datada - if (_annoes == 0) - { - data_start = _datada; - data_start.set_day(1); - data_start.set_month(1); - } - - rmov.zero(); - rmov.put(RMV_GRUPPO,g); - if (c != 0) - { - rmov.put(RMV_CONTO,c); - if (s != 0) - rmov.put(RMV_SOTTOCONTO,s); - } - - TCursor cur(&rel, "", 2, &rmov, &rmov); - const long items = cur.items(); - cur.freeze(); - - for (cur = 0L; cur.pos() < items; ++cur) - { - annoe = rmov.get_int(RMV_ANNOES); - data = rmov.get_date(RMV_DATAREG); - num_reg = rmov.get_long(RMV_NUMREG); - - const char provvis = mov.get_char(MOV_PROVVIS); - const TDate datacomp = mov.get_date(MOV_DATACOMP); - - if (_stampa_mov_prov == 1 && provvis != '\0') //bilancio normale (non comprende i provvisori) - continue; - - if (_stampa_mov_prov == 3 && provvis == '\0') //bilancio dei soli provvisori - continue; - - const TString& codcaus = mov.get(MOV_CODCAUS); - const char causap = causali.decode(codcaus)[0]; - - if (!_quadratura && causap == 'C') - { - // Si tratta di causale di chiusura: - // Non e' richiesta la quadratura con il Libro Giornale (Modifica - // del 18-06-96 richiesta da Patrizia in seguito alla modifica dei SALDI) - continue; - } - - const char sezione = rmov.get_char(RMV_SEZIONE); - const real importo = rmov.get_real(RMV_IMPORTO); - - if (_annoes == 0) - data_reg = data; - else - data_reg = datacomp; - - if (importo.is_zero()) - continue; - - //calcolo i movimenti del periodo - if ( data_reg >= _datada && data_reg <= _dataa) - if ((causap == 'A' && _dataini.ok() && _dataini != _datada) || (causap != 'A')) - { - conto_mov = TRUE; - if (sezione == 'D') - _mov_periodo_dare += importo; - else - _mov_periodo_avere += importo; - _u_max = fnc_max(_u_max, data); - if (causap == 'A') - _mov_ap = TRUE; - } - - //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 (_datada == _dataini) //calcolo il saldo iniziale - { - if (causap == 'A') - { - if ( (data_reg >= _dataini) && (data_reg <= _dataa) ) - { - if (sezione == 'D') - _saldo_ini_dare += importo; - else - _saldo_ini_avere += importo; - _u_max = fnc_max(_u_max, data); - conto_mov = _mov_ap = TRUE; - } - } - } - else if (_datada > _dataini) //calcolo i progressivi precedenti - if ( (data_reg >= data_start) && (data_reg < _datada) ) - { - if (sezione == 'D') - _prg_prec_dare += importo; - else - _prg_prec_avere += importo; - _u_max = fnc_max(_u_max, data); - conto_mov = TRUE; - if (causap == 'A') - _mov_ap = TRUE; - } - } - return conto_mov; -} - -bool TStampa_bilanci::ricerca_cf(int g,int c,char tipocf,int ib, real& saldo_finale,real& saldo_iniziale, - real& mov_conto_dare,real& mov_conto_avere,real& prg_conto_dare,real& prg_conto_avere,real& saldo_conto) -{ - TSaldo sld; - bool esiste_sc = FALSE; - const int anno = _tipo_stampa1 == 1 ? _annoapp : _annoes; - - _lista = new TSaldi_list(g, c, anno); - const TRecnotype items = _lista->items(); - - for (TRecnotype i = 0; i < items; i++) - { - const TRectype* r = _lista->saldi(); - if (r == NULL) break; - - const long s = r->get_long(SLD_SOTTOCONTO); - - saldo_finale = saldo_iniziale = ZERO; //saldi relativi a ciascun sottoconto - - if (_tipo_stampa1 == 1) //bil. di verifica per data limite - { - //modifica del 21/11/1995 - _mov_ap = FALSE; - //modifica del 19/06. Vedi appunti per capire - bool movimentato = calcola(g,c,s); - - if (_stampa_mov_prov != 3) - { - if (movimentato) - { - if (_mov_ap) - { - saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; - } - else - { - TLocalisamfile saldi(LF_SALDI); - saldi.zero(); - saldi.put(SLD_ANNOES,_annoes); - saldi.put(SLD_FLSCA, FALSE); // W96SALDI del 05-06-96 - saldi.put(SLD_GRUPPO,g); // Ho aggiunto in chiave saldi.put(SLD_FLSCA, FALSE); - saldi.put(SLD_CONTO,c); // in questa maniera reperisco il record dei saldi - saldi.put(SLD_SOTTOCONTO,s); // contenente la somma degli scaricati e non scaricati - if (saldi.read() == NOERR) - { - //se il saldo iniziale e' diverso da zero non lo devo considerare - //perche' l'ho gia' considerato nella funzione calcola - const real ss = saldi.get_real(SLD_SALDO); - if (ss.is_zero()) - { - if (_annoes != 0 && (ib == 1 || ib == 2 || ib == 5)) - { - saldo_iniziale += sld.saldofin_esprec(_annoes,g,c,s,false,_stampa_mov_prov==2); - //modifica del 21/11/1995 - if (saldo_iniziale > ZERO) - _saldo_ini_dare = saldo_iniziale; - else - _saldo_ini_avere = -saldo_iniziale; - //fine - } - } - else - { - const char fsi = saldi.get_char(SLD_FLAGSALINI); - if (fsi == 'D') - { - saldo_iniziale = ss; - _saldo_ini_dare = ss; - } - else - { - saldo_iniziale = -ss; - _saldo_ini_avere = ss; - } - } - } - } - } - else - { - if (_annoes != 0 && (ib == 1 || ib == 2 || ib == 5)) - { - saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s,false,_stampa_mov_prov==2); - //modifica del 21/11/1995 - if (saldo_iniziale > ZERO) - _saldo_ini_dare = saldo_iniziale; - else - _saldo_ini_avere = -saldo_iniziale; - //fine - movimentato = sld.significativo(); - } - } - } - - if (!movimentato) - continue; - //fine modifica - - _nuovo_tot_saldo_d += _mov_periodo_dare; - _nuovo_tot_saldo_a += _mov_periodo_avere; - //modifica del 21/11/1995 - _nuovo_tot_saldo_d += _saldo_ini_dare; - _nuovo_tot_saldo_a += _saldo_ini_avere; - //fine - - if (_datada == _dataini) - saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; - else if (_datada > _dataini) - { - if (saldo_iniziale > 0) - _prg_prec_dare += saldo_iniziale; - else - _prg_prec_avere -= saldo_iniziale; - saldo_finale = _prg_prec_dare-_prg_prec_avere+_mov_periodo_dare- - _mov_periodo_avere; - } - if (saldo_finale == ZERO) - if (_stampav == 2) - continue; - - //se saldo_finale < 0 verra' stampato con una A, se no con una D - } - else // Bilancio di verifica all'ultima immissione - { - //Attenzione! Nel caso di "tutti i conti" devono scendere solo i cli/for movimentati!!! - - //modifica del 31/03/1995 - bool movimentato = sld.ultima_immissione_verifica(_annoes,g,c,s,ib,_stampa_mov_prov); - - if (_stampa_mov_prov != 3) - { - saldo_iniziale = sld.saldoini(); - if (!movimentato) - { - //vado sui saldi con l'anno precedente e calcolo saldo_finale es.prec - //se esiste tale record e almeno un valore e' significativo (indipendentemente dal valore - //del saldo iniziale calcolato, allora metto a TRUE il flag movimentato - //solo se e' un conto patrimoniale - if (ib == 1 || ib == 2 || ib == 5) - { - saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s,false,_stampa_mov_prov==2); - movimentato = sld.significativo(); - } - } - } - - if (!movimentato) - continue; - //fine modifica 31/03/1995 - - _mov_periodo_dare = sld.prgdare(); - _mov_periodo_avere = sld.prgavere(); - _prg_prec_dare = ZERO; - _prg_prec_avere = ZERO; - - if (sld.sezsf() == 'A') - _mov_periodo_avere -= sld.saldofin(); - else - _mov_periodo_dare += sld.saldofin(); - - saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; - if (saldo_finale.is_zero() && _stampav == 2) - continue; - - _nuovo_tot_saldo_d += _mov_periodo_dare; - _nuovo_tot_saldo_a += _mov_periodo_avere; - real nuovo = sld.saldoinisusaldi(); - if (nuovo > ZERO) - _nuovo_tot_saldo_d += nuovo; - else - { - nuovo = -nuovo; - _nuovo_tot_saldo_a += nuovo; - } - } - - esiste_sc = TRUE; - - //modifica del 21/11/1995 - if (_tipo_stampa1 == 1 && _datada == _dataini) - { - _saldo_ini_conto_dare += _saldo_ini_dare; - _saldo_ini_conto_avere += _saldo_ini_avere; - } - else - //fine - { - if (saldo_iniziale < ZERO) - _saldo_ini_conto_avere += saldo_iniziale; - else - _saldo_ini_conto_dare += saldo_iniziale; - } - - mov_conto_dare += _mov_periodo_dare; - mov_conto_avere += _mov_periodo_avere; - prg_conto_dare += _prg_prec_dare; - prg_conto_avere += _prg_prec_avere; - saldo_conto += saldo_finale; // somma algebrica!!! - - //scrivo il record relat. al sottoconto se non e' richiesto saldi di mastro - if (_verifica != 2 && !_hide_clifo) - { - _tmp_saldi_att->zero(); - _tmp_saldi_att->put(SLD_GRUPPO,g); - _tmp_saldi_att->put(SLD_CONTO,c); - _tmp_saldi_att->put(SLD_SOTTOCONTO,s); - _tmp_saldi_att->put(SLD_FLAGSALINI,tipocf); - if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) - { - //modifica del 21/11/1995 - if (_tipo_stampa1 == 1 && _datada == _dataini) - { - _tmp_saldi_att->put(SLD_PDAREPRO,_saldo_ini_dare); // W96SALDI del 05-06-96 - _tmp_saldi_att->put(SLD_PAVEREPRO,_saldo_ini_avere); - } - else - { - if (saldo_iniziale > ZERO) //va stampato in Dare - _tmp_saldi_att->put(SLD_PDAREPRO,saldo_iniziale); // W96SALDI del 05-06-96 - else if (saldo_iniziale < ZERO) - { - saldo_iniziale = -saldo_iniziale; - _tmp_saldi_att->put(SLD_PAVEREPRO,saldo_iniziale); // W96SALDI del 05-06-96 - } - } - } - else if (_datada > _dataini) - { - _tmp_saldi_att->put(SLD_PDAREPRO,_prg_prec_dare); // W96SALDI del 05-06-96 - _tmp_saldi_att->put(SLD_PAVEREPRO,_prg_prec_avere); - } - _tmp_saldi_att->put(SLD_PDARE,_mov_periodo_dare); - _tmp_saldi_att->put(SLD_PAVERE,_mov_periodo_avere); - _tmp_saldi_att->put(SLD_SALDO,saldo_finale); - _tmp_saldi_att->put(SLD_DATAULMOV, _u_max); - - _tmp_saldi_att->write(); - } - } - delete _lista; - return esiste_sc; -} - -void TStampa_bilanci::scrivi_record_gruppo(const real& prg_da, - const real& prg_a,const real& mov_da,const real& mov_a,const real& s) -{ - _tmp_saldi_att->zero(); - _tmp_saldi_att->put(SLD_GRUPPO,_gp); - _tmp_saldi_att->put(SLD_CONTO,0); - _tmp_saldi_att->put(SLD_SOTTOCONTO,0L); - if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) - { - //modifica del 21/11/1995 - if (_datada == _dataini && _tipo_stampa1 == 1) - { - _tmp_saldi_att->put(SLD_PDAREPRO,_saldo_ini_gruppo_dare); // W96SALDI del 05-06-96 - _tmp_saldi_att->put(SLD_PAVEREPRO,_saldo_ini_gruppo_avere); - } - else - { - real app = _saldo_ini_gruppo_dare + _saldo_ini_gruppo_avere; - if (app > ZERO) //va stampato in Dare - _tmp_saldi_att->put(SLD_PDAREPRO,app); // W96SALDI del 05-06-96 - else if (app < ZERO) - { - app = -app; - _tmp_saldi_att->put(SLD_PAVEREPRO,app); // W96SALDI del 05-06-96 - } - } - } - else if (_datada > _dataini) - { - _tmp_saldi_att->put(SLD_PDAREPRO,prg_da); // W96SALDI del 05-06-96 - _tmp_saldi_att->put(SLD_PAVEREPRO,prg_a); - } - _tmp_saldi_att->put(SLD_PDARE,mov_da); - _tmp_saldi_att->put(SLD_PAVERE,mov_a); - _tmp_saldi_att->put(SLD_SALDO,s); - _tmp_saldi_att->write(); -} - -void TStampa_bilanci::scrivi_record_conto(const real& prg_da, const real& prg_a, - const real& mov_da,const real& mov_a, const real& s) -{ - _tmp_saldi_att->zero(); - _tmp_saldi_att->put(SLD_GRUPPO,_gp); - _tmp_saldi_att->put(SLD_CONTO,_cp); - _tmp_saldi_att->put(SLD_SOTTOCONTO,0L); - if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) - { - //modifica del 21/11/1995 - if (_datada == _dataini && _tipo_stampa1 == 1) - { - _tmp_saldi_att->put(SLD_PDAREPRO,_saldo_ini_conto_dare); // W96SALDI del 05-06-96 - _tmp_saldi_att->put(SLD_PAVEREPRO,_saldo_ini_conto_avere); - } - else - { - real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; - if (app > ZERO) //va stampato in Dare - _tmp_saldi_att->put(SLD_PDAREPRO,app); // W96SALDI del 05-06-96 - else if (app < ZERO) - { - app = -app; - _tmp_saldi_att->put(SLD_PAVEREPRO,app); // W96SALDI del 05-06-96 - } - } - } - else if (_datada > _dataini) - { - _tmp_saldi_att->put(SLD_PDAREPRO,prg_da); // W96SALDI del 05-06-96 - _tmp_saldi_att->put(SLD_PAVEREPRO,prg_a); - } - _tmp_saldi_att->put(SLD_PDARE,mov_da); - _tmp_saldi_att->put(SLD_PAVERE,mov_a); - _tmp_saldi_att->put(SLD_SALDO,s); - _tmp_saldi_att->write(); -} - -void TStampa_bilanci::init_sort() -{ - cli_for cf; - - _sort = new TSort(sizeof(cli_for)); - _sort->addsortkey ((char*)&(cf.tipocf)-(char*)&(cf.tipocf),1); - _sort->addsortkey ((char*)&(cf.gruppo)-(char*)&(cf.tipocf),3); - _sort->addsortkey ((char*)&(cf.conto)-(char*)&(cf.tipocf),3); - if (_ordinamento == 1) - _sort->addsortkey ((char*)&(cf.codcf)-(char*)&(cf.tipocf),6); - else if (_ordinamento == 2) - _sort->addsortkey ((char*)&(cf.ragsoc)-(char*)&(cf.tipocf),50); - - _sort->init(); -} - -void TStampa_bilanci::riempi_record(char t,int g,int c,long s, - const char* rs,const real& sd,const real& sa, - const real& md,const real& ma,const real& sf) -{ - cli_for cf; - cf.tipocf = t; - sprintf(cf.gruppo, "%03d", g); - sprintf(cf.conto, "%03d", c); - sprintf(cf.codcf, "%06ld", s); - sprintf(cf.ragsoc, "%s", rs); - if ( s == 999999L ) - { - if ( (_datada == _dataini)||(_tipo_stampa1 != 1) ) - { - //modifica del 21/11/1995 - if (_tipo_stampa1 == 1 && _datada == _dataini) - { - cf.saldodare = _saldo_ini_conto_dare; - cf.saldoavere = _saldo_ini_conto_avere; - } - else - //fine - { - real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; - if (app > ZERO) //va stampato in Dare - { - cf.saldoavere = ZERO; - cf.saldodare = app; - } - else if (app < ZERO) - { - app = -app; - cf.saldodare = ZERO; - cf.saldoavere = app; - } - } - } - else if (_datada > _dataini) - { - cf.saldodare = sd; - cf.saldoavere = sa; - } - } - else - { - cf.saldodare = sd; - cf.saldoavere = sa; - } - cf.movdare = md; - cf.movavere = ma; - cf.saldofinale = sf; - cf.udata = _u_max; - _sort->sort((const char*)&cf); -} - -void TStampa_bilanci::leggi_clifo(const TArray& gccf) -{ - TEsercizi_contabili ese; - - TSaldo sld; - TLocalisamfile saldi(LF_SALDI); -// int g = 0, c=0; - long codcf=0l; - TString80 ragsoc; - char tipocf,tipocfp,tipoa; - real saldo_finale, saldo_conto, saldo_iniziale, saldodare, saldoavere, - movdare, movavere; - real mov_conto_dare, mov_conto_avere, prg_conto_dare, prg_conto_avere; - bool esiste_sc = FALSE, movimentato = FALSE; - TRecnotype items = _cur->items(); - - _gp=-1; - _cp=-1; - tipocfp = ' '; - - _saldo_ini_conto_dare = ZERO; - _saldo_ini_conto_avere = ZERO; - saldo_conto = ZERO; - mov_conto_dare = ZERO; - mov_conto_avere = ZERO; - prg_conto_dare = ZERO; - prg_conto_avere = ZERO; - _u_max = 0l; - - const int anno = _tipo_stampa1 == 1 ? _annoapp : _annoes; - for (int i=0; i < gccf.items(); i++) - { - int g = ((TToken_string&)gccf[i]).get_int(0); - int c = ((TToken_string&)gccf[i]).get_int(1); - - *_cur = 0l; - for (int i = 0; i < items; i++,++(*_cur)) - { - _prog->addstatus(1); - codcf = _cur->curr().get_long(CLI_CODCF); - tipocf = _cur->curr().get(CLI_TIPOCF)[0]; - ragsoc = _cur->curr().get(CLI_RAGSOC); - tipoa = _cur->curr().get_char(CLI_TIPOAPER); - if (tipoa == 'F') //persona fisica - { - TString80 cognome, nome; - cognome = ragsoc.mid(0,30); - nome = ragsoc.mid(30,20); - cognome.trim(); nome.trim(); - ragsoc = cognome; - ragsoc << ' ' << nome; - } - - int aprec = ese.pred(anno); - saldi.zero(); - saldi.put(SLD_ANNOES, anno); // W96SALDI del 05-06-96 - saldi.put(SLD_FLSCA, FALSE); - saldi.put(SLD_GRUPPO, g); - saldi.put(SLD_CONTO, c); - saldi.put(SLD_SOTTOCONTO, codcf); - if (saldi.read() != NOERR) - { - //if (_tipo_stampa1 == 1) //bilancio per data limite - // continue; - //else - if (_stampac == 2) //se sono richiesti i conti movimentati - { //esco, se no... - _indbil = cerca_indbil(g,c); - if (_indbil == 1 || _indbil == 2 || _indbil == 5) - { - saldi.zero(); - saldi.put(SLD_ANNOES, aprec); // W96SALDI del 05-06-96 - saldi.put(SLD_FLSCA, FALSE); - saldi.put(SLD_GRUPPO, g); - saldi.put(SLD_CONTO, c); - saldi.put(SLD_SOTTOCONTO, codcf); - if (saldi.read() != NOERR) - continue; - } - } - } - if ( (((_cp != -1) && (c != _cp)) || ((_gp != -1) && (g != _gp))) && - esiste_sc ) - { - //scrivo il record del conto; - riempi_record(tipocfp,_gp,_cp,999999L,"zzzz",prg_conto_dare, - prg_conto_avere,mov_conto_dare,mov_conto_avere,saldo_conto); - tipocfp = tipocf; - _cp = c; - esiste_sc = FALSE; - _saldo_ini_conto_dare = ZERO; - _saldo_ini_conto_avere = ZERO; - saldo_conto = ZERO; - mov_conto_dare = ZERO; - mov_conto_avere = ZERO; - prg_conto_dare = ZERO; - prg_conto_avere = ZERO; - } - - saldo_finale = ZERO; - saldodare = ZERO; - saldoavere = ZERO; - movdare = ZERO; - movavere = ZERO; - saldo_iniziale = ZERO; - - if (_tipo_stampa1 == 1) //bilancio di verifica per data limite - { - //modifica del 21/11/1995 - _mov_ap = FALSE; - - //modifica del 19/06/95 - _indbil = cerca_indbil(g,c); - movimentato = calcola(g,c,codcf); - if (_stampa_mov_prov != 3) - if (!movimentato) - if (_indbil == 1 || _indbil == 2 || _indbil == 5) - if (_annoes != 0) //cioe' se sto ragionando per competenza - { - saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,codcf,false,_stampa_mov_prov==2); - if (saldo_iniziale > ZERO) - _saldo_ini_dare = saldo_iniziale; - else _saldo_ini_avere = -saldo_iniziale; - } - - if (movimentato) - { - //modifica del 21/11/1995 - if (_mov_ap) - saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; - else - { - TLocalisamfile saldi(LF_SALDI); - saldi.zero(); - saldi.put(SLD_ANNOES, _annoes); // W96SALDI del 05-06-96 - saldi.put(SLD_FLSCA, FALSE); - saldi.put(SLD_GRUPPO, g); - saldi.put(SLD_CONTO, c); - saldi.put(SLD_SOTTOCONTO, codcf); - if (saldi.read() == NOERR) - { - const real s = saldi.get_real(SLD_SALDO); - if (_stampa_mov_prov != 3) - if (_indbil == 1 || _indbil == 2 || _indbil == 5) - if (s.is_zero() && _annoes != 0) //competenza!!! - { - saldo_iniziale += sld.saldofin_esprec(_annoes,g,c,codcf,false,_stampa_mov_prov==2); - //modifica del 21/11/1995 - if (saldo_iniziale > ZERO) - _saldo_ini_dare = saldo_iniziale; - else _saldo_ini_avere = -saldo_iniziale; - //fine - } - } - } - } - //fine modifica del 19/06/95 - //movimentato = calcola(g,c,codcf); - if (movimentato || _stampac != 1 || saldo_iniziale != ZERO) - { - if (_datada == _dataini) - saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; - else if (_datada > _dataini) - { - //modifica del 19/06 - if (saldo_iniziale > 0) - _prg_prec_dare += saldo_iniziale; - else _prg_prec_avere -= saldo_iniziale; - //fine modifica - saldo_finale = _prg_prec_dare-_prg_prec_avere+_mov_periodo_dare - -_mov_periodo_avere; - } - } - - //se saldo_finale < 0 verra' stampato con una A, se no con una D - } - else //bilancio di verifica all'ultima immissione - { - _indbil = cerca_indbil(g,c); - movimentato = sld.ultima_immissione_verifica(anno,g,c,codcf,_indbil,_stampa_mov_prov); - - if (_stampa_mov_prov != 3) - if (!movimentato /* && _stampac!=1 */ ) - if (_indbil == 1 || _indbil == 2 || _indbil == 5) - saldo_iniziale = sld.saldofin_esprec(anno,g,c,codcf,false,_stampa_mov_prov==2); - - if (movimentato) - saldo_iniziale = sld.saldoini(); - - if (movimentato || _stampac != 1 || saldo_iniziale != ZERO) - { - _mov_periodo_dare = sld.prgdare(); - _mov_periodo_avere = sld.prgavere(); - _prg_prec_dare = ZERO; - _prg_prec_avere = ZERO; - - if (sld.sezsf() == 'A') - _mov_periodo_avere -= sld.saldofin(); - else - _mov_periodo_dare += sld.saldofin(); - - saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; - } - } - if (movimentato || _stampac != 1 || saldo_iniziale != ZERO) - if (!(saldo_finale.is_zero() && _stampac == 2)) - { - esiste_sc = TRUE; - - //modifica del 21/11/1995 - if (_tipo_stampa1 == 1 && _datada == _dataini) - { - _saldo_ini_conto_dare += _saldo_ini_dare; - _saldo_ini_conto_avere += _saldo_ini_avere; - } - else - { - if (saldo_iniziale < ZERO) - _saldo_ini_conto_avere += saldo_iniziale; - else - _saldo_ini_conto_dare += saldo_iniziale; - } - //fine - - mov_conto_dare += _mov_periodo_dare; - mov_conto_avere += _mov_periodo_avere; - prg_conto_dare += _prg_prec_dare; - prg_conto_avere += _prg_prec_avere; - saldo_conto += saldo_finale; // somma algebrica!!! - - if ( (_datada == _dataini)||(_tipo_stampa1 != 1) ) - { - //modifica del 21/11/1995 - if (_tipo_stampa1 == 1 && _datada == _dataini) - { - saldodare = _saldo_ini_dare; - saldoavere = _saldo_ini_avere; - } - else - // - { - if (saldo_iniziale > ZERO) //va stampato in Dare - saldodare = saldo_iniziale; - else if (saldo_iniziale < ZERO) - { - saldo_iniziale = -saldo_iniziale; - saldoavere = saldo_iniziale; - } - } - } - else if (_datada > _dataini) - { - saldodare = _prg_prec_dare; - saldoavere = _prg_prec_avere; - } - - movdare = _mov_periodo_dare; - movavere = _mov_periodo_avere; - - riempi_record(tipocf,g,c,codcf,ragsoc,saldodare,saldoavere,movdare, - movavere,saldo_finale); - tipocfp = tipocf; - _gp = g; - _cp = c; - } - } - } - if (esiste_sc) - riempi_record(tipocfp,_gp,_cp,999999L,"zzzz",prg_conto_dare,prg_conto_avere, - mov_conto_dare,mov_conto_avere,saldo_conto); -} - -void TStampa_bilanci::crea_sort_clifo() -{ - long ncur = _cur->items(); - //serve solo per la progind: stima alla meno peggio - if (_situazione.empty()) ncur /= 2; - long nitems = ncur*(_clienti.items()+_fornitori.items()); - _prog = new TProgress_monitor(nitems,TR("Elaborazione clienti/fornitori"),false); - _prog->addstatus(1); - init_sort(); - if (_situazione == "C") leggi_clifo(_clienti); - else if (_situazione == "F") leggi_clifo(_fornitori); - else - { - _cur->setfilter("TIPOCF = \"C\""); - leggi_clifo(_clienti); - _cur->setfilter("TIPOCF = \"F\""); - leggi_clifo(_fornitori); - } -} - -int TStampa_bilanci::cerca_indbil(int g, int c) -{ -/* - TLocalisamfile pconti(LF_PCON); - pconti.zero(); - pconti.put(PCN_GRUPPO,g); - if (c != 0) - pconti.put(PCN_CONTO,c); - pconti.put(PCN_SOTTOCONTO,0l); - - pconti.read(); - return pconti.get_int(PCN_INDBIL); -*/ - TString8 key; key.format("%d|%d", g, c); - const int indbil = atoi(cache().get(LF_PCON, key, PCN_INDBIL)); - CHECKD(indbil > 0, "Indicatore di bilancio strano: ", indbil); - return indbil; - -} - -void TStampa_bilanci::leggi_files_dare(TIsamtempfile* file) -{ - _gruppo_dare = file->get_int(SLD_GRUPPO); - _conto_dare = file->get_int(SLD_CONTO); - _sottoconto_dare = file->get_long(SLD_SOTTOCONTO); - _saldo_dare = file->get_real(SLD_PDARE); - - _descr_dare = DescrizioneConto(_gruppo_dare,_conto_dare,_sottoconto_dare,' '); - - _gc_corr_dare = format("%3d%3d", _gruppo_dare, _conto_dare); - - if (_gc_corr_dare != _gc_prec_dare) - { - _cambiato_conto_1 = TRUE; - _gc_prec_dare = _gc_corr_dare; - } - else if (_sottoconto_dare != 0l) - _cambiato_conto_1 = FALSE; -} - -void TStampa_bilanci::leggi_files_avere(TIsamtempfile* file) -{ - _gruppo_avere = file->get_int(SLD_GRUPPO); - _conto_avere = file->get_int(SLD_CONTO); - _sottoconto_avere = file->get_long(SLD_SOTTOCONTO); - _saldo_avere = file->get_real(SLD_PAVERE); - - _descr_avere = DescrizioneConto(_gruppo_avere,_conto_avere,_sottoconto_avere, - ' '); - _gc_corr_avere = format("%3d%3d", _gruppo_avere, _conto_avere); - - if (_gc_corr_avere != _gc_prec_avere) - { - _cambiato_conto_2 = TRUE; - _gc_prec_avere = _gc_corr_avere; - } - else if (_sottoconto_avere != 0l) - _cambiato_conto_2 = FALSE; -} - -#define TOTAL_PICTURE "###.###.###.###.###" - -HIDDEN void total2string(const real& tot, TString& str) -{ - TCurrency cur(tot); - str = cur.string(TRUE); - str.right_just(strlen(TOTAL_PICTURE)); -} - -bool TStampa_bilanci::preprocess_print(int file, int counter) -{ - if (_bilancio == 1) - { - set_real_picture ("##.###.###.###.###"); - set_print_zero(); - _tmp_saldi_att->setkey(2); - _tmp_saldi_pass->setkey(2); - _tmp_saldi_costi->setkey(2); - _tmp_saldi_ricavi->setkey(2); - _tmp_saldi_conti_uno->setkey(2); - _tmp_saldi_conti_due->setkey(2); - _gc_prec_avere = ""; - _prima_volta = _seconda_volta = TRUE; - _flag = _controlla = FALSE; - _salto_pagina = _salto_pagina1 = _stampato = FALSE; - _cambiato_conto_1 = TRUE; - _cambiato_conto_2 = TRUE; - _tot_dare = ZERO; - _tot_avere = ZERO; - } - else - { - if (_noseparator) - set_real_picture ("################"); - else - set_real_picture ("####.###.###.###"); - - set_print_zero(FALSE); - _cambiato_conto_1 = FALSE; - _livello_conto = TRUE; - _saldo_dare_tot = ZERO; - _saldo_avere_tot = ZERO; - _mov_dare_tot = ZERO; - _mov_avere_tot = ZERO; - _saldo_finale_tot = ZERO; - } - set_magic_currency(TRUE); - return TRUE; -} - -void TStampa_bilanci::leggi_file_tmp() -{ - if (_livello_conto) // era meglio chiamarla _livello_conto_oppure_gruppo, perche' nel caso dei saldi di mastro _livello_conto==TRUE <=> si tratta di un gruppo, mentre nel caso del bilancio _livello_conto==TRUE <=> si tratta di un conto - { - _gruppo = _tmp_saldi_att->get_int(SLD_GRUPPO); - _conto = _tmp_saldi_att->get_int(SLD_CONTO); - _sottoconto = _tmp_saldi_att->get_long(SLD_SOTTOCONTO); - _tipo_conto = _tmp_saldi_att->get_char(SLD_FLAGSALINI); - _descr = DescrizioneConto(_gruppo,_conto,_sottoconto,_tipo_conto); - _saldoini_dare = _tmp_saldi_att->get_real(SLD_PDAREPRO); // W96SALDI del 05-06-96 - _saldoini_avere = _tmp_saldi_att->get_real(SLD_PAVEREPRO); - _mov_dare = _tmp_saldi_att->get_real(SLD_PDARE); - _mov_avere = _tmp_saldi_att->get_real(SLD_PAVERE); - _saldofinale = _tmp_saldi_att->get_real(SLD_SALDO); - } - _eof1 = _tmp_saldi_att->next(); - if (!_eof1) - { - _gruppo_succ = _tmp_saldi_att->get_int(SLD_GRUPPO); - _conto_succ = _tmp_saldi_att->get_int(SLD_CONTO); - _sottoconto_succ = _tmp_saldi_att->get_long(SLD_SOTTOCONTO); - _tipoc_succ = _tmp_saldi_att->get_char(SLD_FLAGSALINI); - if ( (_verifica != 2) && (_sottoconto_succ != 0) ) - { - if (_tipo_stampa1 == 2) - _ultima_data = UltimaData(_gruppo_succ,_conto_succ, _sottoconto_succ,_annoes); - else - _ultima_data = _tmp_saldi_att->get_date(SLD_DATAULMOV); - } - _descr_succ = DescrizioneConto(_gruppo_succ,_conto_succ, - _sottoconto_succ,_tipoc_succ); - _saldoini_dare_succ = _tmp_saldi_att->get_real(SLD_PDAREPRO); // W96SALDI del 05-06-96 - _saldoini_avere_succ = _tmp_saldi_att->get_real(SLD_PAVEREPRO); - _mov_dare_succ = _tmp_saldi_att->get_real(SLD_PDARE); - _mov_avere_succ = _tmp_saldi_att->get_real(SLD_PAVERE); - _saldofinale_succ = _tmp_saldi_att->get_real(SLD_SALDO); - _livello_conto = FALSE; - if ( ((_verifica != 2)&&(_sottoconto_succ == 0)) || - ((_verifica == 2)&&(_conto_succ == 0)) ) - { - _livello_conto = TRUE; - _gruppo_succ = _gruppo; - _conto_succ = _conto; - _sottoconto_succ = _sottoconto; - _descr_succ = _descr; - _saldoini_dare_succ = _saldoini_dare; - _saldoini_avere_succ = _saldoini_avere; - _mov_dare_succ = _mov_dare; - _mov_avere_succ = _mov_avere; - _saldofinale_succ = _saldofinale; - } - } -} - -bool TStampa_bilanci::preprocess_page(int file, int counter) -{ - reset_print(); - - if (_bilancio == 1) //stampa bilancio a sez. contrapposte - { - if (counter) - { - if ( (!_eof1) && (_cambiato_conto_1) ) - _eof1 = _tmp_saldi_att->next(); - - if ( (!_eof2) && (_cambiato_conto_2) ) - _eof2 = _tmp_saldi_pass->next(); - - if (_eof1 && _eof2) - { - if (_prima_volta) - { - stampa_totali_uno(_prg_saldoini_dare,_prg_saldoini_avere); - _eof3 = _tmp_saldi_costi->first(); - _eof4 = _tmp_saldi_ricavi->first(); - } - else - { - _controlla = TRUE; - - if (_salto_pagina) - { - if ( (!_eof3) && (_cambiato_conto_1) ) - _eof3 = _tmp_saldi_costi->next(); - - if ( (!_eof4) && (_cambiato_conto_2) ) - _eof4 = _tmp_saldi_ricavi->next(); - } - } - - if ( (!_eof3) && (_cambiato_conto_1) ) - leggi_files_dare(_tmp_saldi_costi); - - if ( (!_eof4) && (_cambiato_conto_2) ) - leggi_files_avere(_tmp_saldi_ricavi); - - if (_eof3 && _eof4 && _salto_pagina) - { - if (_seconda_volta) - { - stampa_totali(); - _eof5 = _tmp_saldi_conti_uno->first(); - _eof6 = _tmp_saldi_conti_due->first(); - } - else - { - _flag = TRUE; - - if (_salto_pagina1) - { - if ( (!_eof5) && (_cambiato_conto_1) ) - _eof5 = _tmp_saldi_conti_uno->next(); - - if ( (!_eof6) && (_cambiato_conto_2) ) - _eof6 = _tmp_saldi_conti_due->next(); - } - } - - if ( (!_eof5) && (_cambiato_conto_1) ) - leggi_files_dare(_tmp_saldi_conti_uno); - - if ( (!_eof6) && (_cambiato_conto_2) ) - leggi_files_avere(_tmp_saldi_conti_due); - } - } - } - else //counter = 0 - { - _gc_prec_dare = _gc_corr_avere = ""; - _eof1 = _tmp_saldi_att->first(); - _eof2 = _tmp_saldi_pass->first(); - } - - if ( (!_eof1) && (_cambiato_conto_1) ) - leggi_files_dare(_tmp_saldi_att); - - if ( (!_eof2) && (_cambiato_conto_2) ) - leggi_files_avere(_tmp_saldi_pass); - } - else //stampa bilancio di verifica - { - if (_verifica == 3) - leggi_sort(); - else - { - if (counter) - { - if (!_eof1) - leggi_file_tmp(); - } - else - { - _eof1 = _tmp_saldi_att->first(); - if (_eof1) - return FALSE; - else - leggi_file_tmp(); - } - } - } - return TRUE; -} - -void TStampa_bilanci::leggi_sort() -{ - _buff = _sort->retrieve(); - if (_buff != NULL) - { - struct cli_for* cf = (struct cli_for*)_buff; - _tipo_conto = cf->tipocf; - _gruppo = atoi(cf->gruppo); - _conto = atoi(cf->conto); - _sottoconto = atol(cf->codcf); - _descr = cf->ragsoc; - if ( (_ordinamento == 2 && _descr != "zzzz") || (_ordinamento == 1 && _sottoconto != 999999L) ) - { - if (_tipo_stampa1 == 2) - _ultima_data = UltimaData(_gruppo,_conto,_sottoconto,_annoes); - else - _ultima_data = cf->udata; - } - _saldo_dare = cf->saldodare; - _saldo_avere = cf->saldoavere; - _mov_dare = cf->movdare; - _mov_avere = cf->movavere; - _saldofinale = cf->saldofinale; - } -} - -void TStampa_bilanci::controlla_conto(int file1,int file2) -{ - if (!file1) - if (_cambiato_conto_1) - { - set_row(_i,"@67g*"); - _cambiato_conto_1 = FALSE; - } - else - { - stampa_prima_colonna(_gruppo_dare, _conto_dare, _sottoconto_dare, - _descr_dare,_saldo_dare); - _cambiato_conto_1 = TRUE; - if (!_totali) - if ( (_conto_dare == 0) && (_sottoconto_dare == 0) ) - _tot_dare += _saldo_dare; - if (_totali) - if (_sottoconto_dare == 0) - _tot_dare += _saldo_dare; - } - - if (!file2) - if (_cambiato_conto_2) - { - set_row(_i,"@67g*"); - _cambiato_conto_2 = FALSE; - } - else - { - stampa_seconda_colonna(_gruppo_avere, _conto_avere, _sottoconto_avere, - _descr_avere, _saldo_avere); - _cambiato_conto_2 = TRUE; - if (!_totali) - if ( (_conto_avere == 0) && (_sottoconto_avere == 0) ) - _tot_avere += _saldo_avere; - if (_totali) - if (_sottoconto_avere == 0) - _tot_avere += _saldo_avere; - } -} - -void TStampa_bilanci::postclose_print() -{ - if (_bilancio == 1) - { - delete _tmp_saldi_att; _tmp_saldi_att = NULL; - delete _tmp_saldi_pass; _tmp_saldi_pass = NULL; - delete _tmp_saldi_costi; _tmp_saldi_costi = NULL; - delete _tmp_saldi_ricavi; _tmp_saldi_ricavi = NULL; - delete _tmp_saldi_conti_uno; _tmp_saldi_conti_uno = NULL; - delete _tmp_saldi_conti_due; _tmp_saldi_conti_due = NULL; - } - else - { - if (_verifica == 3) - { - delete _sort; _sort = NULL; - } - else - { - delete _tmp_saldi_att; _tmp_saldi_att = NULL; - } - } -} - -void TStampa_bilanci::set_page(int file, int counter) -{ - const TString16 dep; - - if (_bilancio == 1) //stampa bilancio a sezioni contrapposte - { - _i = 1; - - if (!counter) - { - set_row(_i++,FR("@29gATTIVITA'@98gPASSIVITA'")); - set_row(_i++,"@29g---------@98g----------"); - set_row(_i++, dep); - } - - controlla_conto(_eof1,_eof2); //stampo una riga vuota tra un gruppo e un conto altrimenti no - - if ( _eof1 && _eof2 && (!_prima_volta) && _controlla ) - if (!_salto_pagina) - { - printer().formfeed(); - set_row(_i++,FR("@29gCOSTI@98gRICAVI")); - set_row(_i++,"@29g-----@98g------"); - set_row(_i++, dep); - _salto_pagina = TRUE; - - } - - if (_eof1 && _eof2 && _controlla) - { - controlla_conto(_eof3,_eof4); - - if ( _eof3 && _eof4 && (!_seconda_volta) && _flag ) - if (!_salto_pagina1) - { - if (!_tmp_saldi_conti_uno->empty() || !_tmp_saldi_conti_due->empty()) - { - printer().formfeed(); - set_row(_i++,FR("@59gCONTI D'ORDINE")); - set_row(_i++,"@59g--------------"); - set_row(_i++, dep); - if (_eof5 && _eof6) - { - _stampato = TRUE; - stampa_totali_uno(_prg_inidare_ord,_prg_iniavere_ord); - } - } - _salto_pagina1 = TRUE; - } - - if (_eof3 && _eof4 && _flag) - { - if (!_tmp_saldi_conti_uno->empty() || !_tmp_saldi_conti_due->empty()) - { - controlla_conto(_eof5,_eof6); - if (_eof5 && _eof6) - if (!_stampato) - stampa_totali_uno(_prg_inidare_ord,_prg_iniavere_ord); - } - } - } - } - else //stampa bilancio di verifica - { - const TString16 udata = _ultima_data.string(brief,'/'); - char app; - int r = 1; - - if (_verifica == 3) - { - if (_buff != NULL) - { - *_d = (const char*) _descr; - if (_saldofinale > 0) - app = 'D'; - else if (_saldofinale < 0) - { - _saldofinale = -_saldofinale; - app = 'A'; - } - if ( (_ordinamento == 2 && _descr == "zzzz") || - (_ordinamento == 1 && _sottoconto == 999999L) ) //devo stampare il conto - { - _descr = DescrizioneConto(_gruppo,_conto,0L,' '); - stampa_record_conto(_gruppo,_conto,_descr,_saldo_dare,_saldo_avere, - _mov_dare,_mov_avere,_saldofinale,app); - } - else - { - if (_stampa_width == 132) - { - set_row(r,"@1g%6ld", _sottoconto); - if ((_saldo_dare != ZERO) || (_saldo_avere != ZERO) || (_mov_dare != ZERO) || - (_mov_avere != ZERO) || (_saldofinale != ZERO)) - set_row(r," %s",(const char*)udata); - set_row(r,"@17g#a@46g!%r@64g%r@80g!%r@98g%r@114g!@115g%r",_d,&_saldo_dare, - &_saldo_avere,&_mov_dare,&_mov_avere,&_saldofinale); - if (_saldofinale != ZERO) - set_row(r,"@131g%c", app); - if (_descr.len() > 30) - set_row(++r, "@46g!@80g!@114g!"); - } - else if (app == 'D') - { - set_row(r,"@1g%6ld", _sottoconto); - if ((_saldo_dare != ZERO) || (_saldo_avere != ZERO) || (_mov_dare != ZERO) || - (_mov_avere != ZERO) || (_saldofinale != ZERO)) - set_row(r," %s",(const char*)udata); - set_row(r,"@17g#a@46g!%r@64g%r@80g!%r@98g%r@114g!%r@148g!",_d, - &_saldo_dare,&_saldo_avere,&_mov_dare,&_mov_avere,&_saldofinale); - if (_descr.len() > 30) - set_row(++r, "@46g!@80g!@114g!@148g!"); - } - else - { - set_row(r,"@1g%6ld", _sottoconto); - if ((_saldo_dare != ZERO) || (_saldo_avere != ZERO) || (_mov_dare != ZERO) || - (_mov_avere != ZERO) || (_saldofinale != ZERO)) - set_row(r," %s",(const char*)udata); - set_row(r,"@17g#a@46g!%r@64g%r@80g!%r@100g%r@114g!@132g%r@148g!", - _d,&_saldo_dare,&_saldo_avere,&_mov_dare,&_mov_avere,&_saldofinale); - if (_descr.len() > 30) - set_row(++r, "@46g!@80g!@114g!@148g!"); - } - } - } - } - else //_verifica != 3 - { - if (!_eof1) - { - if (_saldofinale_succ >= ZERO) - app = 'D'; - else - { - _saldofinale_succ = -_saldofinale_succ; - app = 'A'; - } - - if (_livello_conto) //sto stampando un conto/gruppo - r = stampa_record_conto(_gruppo_succ,_conto_succ,_descr_succ, - _saldoini_dare_succ,_saldoini_avere_succ,_mov_dare_succ, - _mov_avere_succ,_saldofinale_succ,app); - - else //sto stampando un sottoconto/conto - { - if (_verifica == 2) - { - if (_stampa_width == 132) - { - set_row(r,"%3d",_conto_succ); - set_row(r," @8g%-.40s@46g!%r@64g%r@80g!%r@98g%r@114g!@115g%r", - (const char*)_descr_succ,&_saldoini_dare_succ,&_saldoini_avere_succ, - &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); - if (_saldofinale_succ != ZERO) - set_row(r,"@131g%c", app); - } - else if (app == 'D') - { - set_row(r,"%3d",_conto_succ); - set_row(r," @8g%-.40s@46g!%r@64g%r@80g!%r@98g%r@114g!%r@148g!", - (const char*)_descr_succ,&_saldoini_dare_succ,&_saldoini_avere_succ, - &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); - } - else - { - set_row(r,"%3d",_conto_succ); - set_row(r," @8g%-.40s@46g!%r@64g%r@80g!%r@98g%r@114g!@132g%r@148g!", - (const char*)_descr_succ,&_saldoini_dare_succ,&_saldoini_avere_succ, - &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); - } - } // _verifica != 2 - else - { - *_d = (const char*) _descr_succ; - if (_print_full_code) - set_row(r,"@1g%3d %3d %6ld", _gruppo_succ, _conto_succ, _sottoconto_succ); - else - { - set_row(r,"@1g%6ld", _sottoconto_succ); - if ((_saldoini_dare_succ != ZERO) || (_saldoini_avere_succ != ZERO) || - (_mov_dare_succ != ZERO) || (_mov_avere_succ != ZERO) || - (_saldofinale_succ != ZERO)) - set_row(r," %s",(const char*)udata); - } - - if (_stampa_width == 132) - { -// set_row(r,"@1g%6ld",(const char*)_sottoconto_succ); -// if ((_saldoini_dare_succ != ZERO) || (_saldoini_avere_succ != ZERO) || -// (_mov_dare_succ != ZERO) || (_mov_avere_succ != ZERO) || -// (_saldofinale_succ != ZERO)) -// set_row(r," %s",(const char*)udata); - set_row(r,"@17g#a@46g!%r@64g%r@80g!%r@98g%r@114g!@115g%r", - _d,&_saldoini_dare_succ,&_saldoini_avere_succ, - &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); - if (_saldofinale_succ != ZERO) - set_row(r,"@131g%c", app); - if (_descr_succ.len() > 30) - set_row(++r, "@46g!@80g!@114g!"); - } - else // Stampa estesa - { -// set_row(r,"@1g%6ld",(const char*)_sottoconto_succ); -// if ((_saldoini_dare_succ != ZERO) || (_saldoini_avere_succ != ZERO) || -// (_mov_dare_succ != ZERO) || (_mov_avere_succ != ZERO) || -// (_saldofinale_succ != ZERO)) -// set_row(r," %s",(const char*)udata); - if (app == 'D') - { - set_row(r,"@17g#a@46g!%r@64g%r@80g!%r@98g%r@114g!%r@148g!", - _d,&_saldoini_dare_succ,&_saldoini_avere_succ, - &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); - } - else - { - set_row(r,"@17g#a@46g!%r@64g%r@80g!%r@98g%r@114g!@132g%r@148g!", - _d,&_saldoini_dare_succ,&_saldoini_avere_succ, - &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); - } - if (_descr_succ.len() > 30) - set_row(++r, "@46g!@80g!@114g!@148g!"); - } - } - } - } - else - { - if (_saldofinale >= ZERO) - app = 'D'; - else - { - app = 'A'; - _saldofinale = -_saldofinale; - } - r = stampa_record_conto(_gruppo,_conto,_descr,_saldoini_dare, - _saldoini_avere,_mov_dare,_mov_avere,_saldofinale,app);//per stampare l'ultimo conto - - stampa_riga_totali(r); - } - } - } -} - -int TStampa_bilanci::stampa_record_conto(int g,int c,const TString& d, - const real& r1,const real& r2,const real& r3,const real& r4,const real& r5, - const char app) -{ - int r = 1; - - if (_stampa_width != 132) - set_row(r,"@46g!@80g!@114g!@148g!"); //stampo una riga vuota - else - set_row(r,"@46g!@80g!@114g!"); //stampo una riga vuota - r++; - if (_verifica == 2) - { - if (_stampa_width == 132) - { - set_row(r,"%3d-",g); - set_row(r,"@8g%-.40s",(const char*)d); - set_row(r,"@46g!%r@64g%r@80g!%r@98g%r@114g!@115g%r",&r1,&r2,&r3,&r4,&r5); - if (r5 != ZERO) - set_row(r,"@131g%c", app); - r++; - } - else - if (app == 'D') - { - set_row(r,"%3d-",g); - set_row(r,"@8g%-.40s",(const char*)d); - set_row(r++,"@46g!%r@64g%r@80g!%r@98g%r@114g!%r@148g!",&r1,&r2,&r3,&r4,&r5); - } - else - { - set_row(r,"%3d-",g); - set_row(r,"@8g%-.40s",(const char*)d); - set_row(r++,"@46g!%r@64g%r@80g!%r@98g%r@114g!@132g%r@148g!",&r1,&r2,&r3,&r4,&r5); - } - } - else - { - *_d = (const char*) d; - - if (_stampa_width == 132) - { - set_row(r,"%3d-",g); - set_row(r,"%3d ********",c); - set_row(r,"@17g#a",_d); - set_row(r,"@46g!%r@64g%r@80g!%r@98g%r@114g!@115g%r",&r1,&r2,&r3,&r4,&r5); - if (r5 != ZERO) - set_row(r,"@131g%c", app); - r++; - if (d.len() > 30) - set_row(r+1, "@46g!@80g!@114g!"); - } - else if (app == 'D') - { - set_row(r,"%3d-",g); - set_row(r,"%3d ********",c); - set_row(r,"@17g#a",_d); - set_row(r++,"@46g!%r@64g%r@80g!%r@98g%r@114g!%r@148g!",&r1,&r2,&r3,&r4,&r5); - if (d.len() > 30) - set_row(r+1, "@46g!@80g!@114g!@148g!"); - } - else - { - set_row(r,"%3d-",g); - set_row(r,"%3d ********",c); - set_row(r,"@17g#a",_d); - set_row(r++,"@46g!%r@64g%r@80g!%r@98g%r@114g!@132g%r@148g!",&r1,&r2,&r3,&r4,&r5); - if (d.len() > 30) - set_row(r+1, "@46g!@80g!@114g!@148g!"); - } - } - - set_row(r,"@46g!@80g!@114g!"); - if (_stampa_width != 132) - set_row(r,"@148g!"); - r++; - - set_row(r,"@46g!@80g!@114g!"); - if (_stampa_width != 132) - set_row(r,"@148g!"); - r++; - - if (app == 'D') - _saldo_finale_tot += r5; - else _saldo_finale_tot -= r5; - - _saldo_dare_tot += r1; - _saldo_avere_tot += r2; - _mov_dare_tot += r3; - _mov_avere_tot += r4; - - return r; -} - -void TStampa_bilanci::stampa_riga_totali(int r) -{ - const TString16 dep; - char app = ' '; - - if (_saldo_finale_tot > 0) - app = 'D'; - else if (_saldo_finale_tot < 0) - { - _saldo_finale_tot = -_saldo_finale_tot; - app = 'A'; - } - - //modifica del 21/11/1995 - if (_tipo_stampa1 == 2) - { - real r = _saldo_dare_tot - _saldo_avere_tot; - if (r > ZERO) - { - _saldo_dare_tot = r; - _saldo_avere_tot = ZERO; - } - else - { - _saldo_avere_tot = -r; - _saldo_dare_tot = ZERO; - } - } - - set_row(r, "@46g!@80g!@114g!"); - if (_stampa_width != 132) - set_row(r, "@148g!"); - r++; - - if (_verifica == 2) - { - if (_stampa_width == 132) - { - set_row(r,FR("***@8gTOTALE GENERALE@46g!%r@64g%r@80g!%r@98g%r@114g!@115g%r"),&_saldo_dare_tot,&_saldo_avere_tot,&_mov_dare_tot, - &_mov_avere_tot,&_saldo_finale_tot); - if (_saldo_finale_tot != ZERO) - set_row(r,"@131g%c", app); - } - else - { - if (app == 'D') - set_row(r,FR("***@8gTOTALE GENERALE@46g!%r@64g%r@80g!%r@98g%r@114g!%r@148g!"),&_saldo_dare_tot,&_saldo_avere_tot, - &_mov_dare_tot,&_mov_avere_tot,&_saldo_finale_tot); - else - set_row(r,FR("***@8gTOTALE GENERALE@46g!%r@64g%r@80g!%r@98g%r@114g!@132g%r@148g!"),&_saldo_dare_tot,&_saldo_avere_tot, - &_mov_dare_tot,&_mov_avere_tot,&_saldo_finale_tot); - } - } - else - { - if (_stampa_width == 132) - { - set_row(r,FR("@1g****** ********@17gTOTALE GENERALE@46g!%r@64g%r@80g!%r@98g%r@114g!@115g%r"),&_saldo_dare_tot,&_saldo_avere_tot, - &_mov_dare_tot,&_mov_avere_tot,&_saldo_finale_tot); - if (_saldo_finale_tot != ZERO) - set_row(r,"@131g%c", app); - r++; - - if ((_tipo_stampa1 == 1 && _datada == _dataini) || _tipo_stampa1 == 2) - { - //modifica del 21/11/1995 - if (_tipo_stampa1 == 2) - set_row(r,FR("@1g****** ********@17gTOTALE CON SALDI INIZIALI@46g!@80g!%r@98g%r@114g!"),&_nuovo_tot_saldo_d,&_nuovo_tot_saldo_a); - else - set_row(r,FR("@1g****** ********@17gTOTALE CON MOVIM. DI APERTURA@46g!@80g!%r@98g%r@114g!"),&_nuovo_tot_saldo_d,&_nuovo_tot_saldo_a); - //fine - } - } - else - { - if (app == 'D') - { - set_row(r++,FR("@1g****** ********@17gTOTALE GENERALE@46g!%r@64g%r@80g!%r@98g%r@114g!%r@148g!"),&_saldo_dare_tot, - &_saldo_avere_tot,&_mov_dare_tot,&_mov_avere_tot, &_saldo_finale_tot); - } - else - { - set_row(r++,FR("@1g****** ********@17gTOTALE GENERALE@46g!%r@64g%r@80g!%r@98g%r@114g!@132g%r@148g!"),&_saldo_dare_tot, - &_saldo_avere_tot,&_mov_dare_tot,&_mov_avere_tot, &_saldo_finale_tot); - } - - if ((_tipo_stampa1 == 1 && _datada == _dataini) || _tipo_stampa1 == 2) - { - if (_tipo_stampa1 == 2) - set_row(r,FR("@1g****** ********@17gTOTALE CON SALDI INIZIALI@46g!@80g!%r@98g%r@114g!@148g!"),&_nuovo_tot_saldo_d,&_nuovo_tot_saldo_a); - else - set_row(r,FR("@1g****** ********@17gTOTALE CON MOVIM. DI APERTURA@46g!@80g!%r@98g%r@114g!@148g!"),&_nuovo_tot_saldo_d,&_nuovo_tot_saldo_a); - } - } - } -} - -void TStampa_bilanci::stampa_totali() -{ - const TString16 dep = ""; - real pareggio; - real sbilancio = _tot_dare - _tot_avere; - if (sbilancio > ZERO) //_tot_dare > _tot_avere - pareggio = _tot_avere + sbilancio; - else - { - sbilancio = -sbilancio; - pareggio = _tot_dare + sbilancio; - } - if (_prima_volta) //ho finito di stampare le attivita'/passivita' - _prima_volta = FALSE; - else - _seconda_volta = FALSE; - const bool stato_patrimoniale = _seconda_volta; // cosa mi tocca fare - _gc_prec_dare = _gc_corr_avere = ""; - _cambiato_conto_1 = TRUE; - _cambiato_conto_2 = TRUE; - - set_row(_i++, (const char*)dep); - set_row(_i++, (const char*)dep); - set_row(_i++, (const char*)dep); - set_row(_i++, (const char*)dep); - TString pal; total2string(_tot_dare, pal); - TString bal; total2string(_tot_avere, bal); - set_row(_i++, FR("@39gTOTALE@48g%s@102gTOTALE@113g%s"), - (const char*)pal, (const char*)bal); - TString sb; total2string(sbilancio, sb); - TString pa; total2string(pareggio, pa); - if (_tot_dare > _tot_avere) - { - if (stato_patrimoniale) - set_row(_i++, FR("@79gUTILE DELL'ESERCIZIO IN CORSO@113g%s"), (const char*)sb); - else - set_row(_i++, FR("@77gPERDITA DELL'ESERCIZIO IN CORSO@113g%s"), (const char*)sb); - set_row(_i++, FR("@91gTOTALE A PAREGGIO@113g%s"),(const char*)pa); - } - if (_tot_dare < _tot_avere) - { - if (stato_patrimoniale) - set_row(_i++, FR("@14gPERDITA DELL'ESERCIZIO IN CORSO@48g%s"), (const char*)sb); - else - set_row(_i++, FR("@16gUTILE DELL'ESERCIZIO IN CORSO@48g%s"), (const char*)sb); - set_row(_i++, FR("@28gTOTALE A PAREGGIO@48g%s"),(const char*)pa); - } - _tot_dare = ZERO; - _tot_avere = ZERO; -} - -//per i conti patrimoniali stampo anche lo sbilancio es. precedente -void TStampa_bilanci::stampa_totali_uno(const real& r1,const real& r2) -{ - real pareggio; - real sbilancio = _tot_dare - r1 - (_tot_avere - r2); - real sbilprec = r2 - r1; - - if (_prima_volta) //ho finito di stampare le attivita'/passivita' - _prima_volta = FALSE; - else - _seconda_volta = FALSE; - const bool stato_patrimoniale = _seconda_volta; // cosa mi tocca fare - _gc_prec_dare = _gc_corr_avere = ""; - _cambiato_conto_1 = TRUE; - _cambiato_conto_2 = TRUE; - - const char* dep = ""; - set_row(_i++, (const char*)dep); - set_row(_i++, (const char*)dep); - set_row(_i++, (const char*)dep); - set_row(_i++, (const char*)dep); - TString pal; total2string(_tot_dare, pal); - TString bal; total2string(_tot_avere, bal); - set_row(_i++, FR("@39gTOTALE@48g%s@102gTOTALE@113g%s"), - (const char*)pal, (const char*)bal); - if (sbilancio > ZERO) //ho un utile => va stampato tra le passivita' - { - sbilprec = -sbilprec; - pareggio = _tot_avere + sbilancio + sbilprec; - if (sbilprec != ZERO) - { - TString sb; total2string(sbilprec, sb); - set_row(_i++, FR("@83gSBILANCIO ESERCIZIO PRECEDENTE@113g%s"), - (const char*)sb); - } - TString pal; total2string(sbilancio, pal); - TString bal; total2string(pareggio, bal); - if (stato_patrimoniale) - set_row(_i++, FR("@79gUTILE DELL'ESERCIZIO IN CORSO@113g%s"), (const char*)pal); - else - set_row(_i++, FR("@77gPERDITA DELL'ESERCIZIO IN CORSO@113g%s"), (const char*)pal); - set_row(_i++, FR("@91gTOTALE A PAREGGIO@113g%s"),(const char*)bal); - } - else if (sbilancio < ZERO) //ho una perdita => va stampato tra le attivita' - { - sbilancio = -sbilancio; - pareggio = _tot_dare + sbilancio + sbilprec; - if (sbilprec != ZERO) - { - TString sb; total2string(sbilprec, sb); - set_row(_i++, FR("@15gSBILANCIO ESERCIZIO PRECEDENTE@48g%s"), - (const char*)sb); - } - - TString pal; total2string(sbilancio, pal); - TString bal; total2string(pareggio, bal); - if (stato_patrimoniale) - set_row(_i++, FR("@14gPERDITA DELL'ESERCIZIO IN CORSO@48g%s"), (const char*)pal); - else - set_row(_i++, FR("@16gUTILE DELL'ESERCIZIO IN CORSO@48g%s"), (const char*)pal); - set_row(_i++, FR("@28gTOTALE A PAREGGIO@48g%s"),(const char*)bal); - } - else //sbilancio es. in corso == 0 - { - sbilprec = -sbilprec; - if (sbilprec > ZERO) //va stampato sotto le passivita' - { - TString pal; total2string(sbilprec, pal); - pareggio = _tot_avere + sbilprec; - TString bal; total2string(pareggio, bal); - set_row(_i++, FR("@83gSBILANCIO ESERCIZIO PRECEDENTE@113g%s"), - (const char*)pal); - set_row(_i++, FR("@96gTOTALE A PAREGGIO@113g%s"), (const char*)bal); - } - else if (sbilprec < ZERO) - { - sbilprec = -sbilprec; - pareggio = _tot_dare + sbilprec; - TString pal; total2string(sbilprec, pal); - TString bal; total2string(pareggio, bal); - set_row(_i++, FR("@15gSBILANCIO ESERCIZIO PRECEDENTE@48g%s"), (const char*)pal); - set_row(_i++, FR("@28gTOTALE A PAREGGIO@48g%s"), (const char*)bal); - } - } - _tot_dare = ZERO; - _tot_avere = ZERO; -} - -// Guy: stampa la prima colonna del bilancio di raffronto -void TStampa_bilanci::stampa_prima_colonna(int g, int c, long s, - const char* desc, const real& saldo) -{ - if (_codici) //sono stampate solo le descrizioni dei conti - { - if (!_totali) - { - if (c != 0 && s == 0) - set_row(_i, "%-.44s @44g @48g%r", desc, &saldo); - else - set_row(_i, "%-.48s @48g%r", desc, &saldo); - } - else if ( !(c == 0 && s == 0) ) //se cioe' non e' un gruppo - { - if (s == 0) //se e' un conto - set_row(_i, "%-.44s @44g @48g%r", desc, &saldo); - else - set_row(_i, "%-.48s @48g%r", desc, &saldo); - } - } - else - { - if (_totali && c == 0 && s == 0l) - return; - - set_row(_i, "@0g%3d", g); - if (c > 0) - { - set_row(_i, "@4g%3d", c); - if (s > 0) - set_row(_i, "@8g%6ld", s); - } - set_row(_i, "@15g%-.31s @48g%r", desc, &saldo); - } - set_row(_i, "@67g*"); -} - - -// Guy: stampa la seconda colonna del bilancio di raffronto -void TStampa_bilanci::stampa_seconda_colonna(int g, int c, long s, const char* desc, const real& saldo) -{ - if (_codici) //sono stampate solo le descrizioni dei conti - { - if (!_totali) - { - set_row(_i, "@67g*@69g%-.47s @114g%r", desc, &saldo); - } - else - { - if ( !(c == 0 && s == 0) ) - set_row(_i, "@67g*@69g%-.47s @114g%r", desc, &saldo); - } - } - else - { - if (_totali && c == 0 && s == 0l) - return; - - set_row(_i, "@67g*@69g%3d ", g); - if (c > 0) - { - set_row(_i, "@73g%3d", c); - if (s > 0) - set_row(_i, "@77g%6ld", s); - } - set_row(_i, "@84g%-.30s @114g%r", desc, &saldo); - } -} - -print_action TStampa_bilanci::postprocess_page(int file, int counter) -{ - if (_bilancio == 1) - { - if ( _eof1 && _eof2 && _eof3 && _eof4 && _eof5 && _eof6 && _salto_pagina1 ) - return NEXT_PAGE; - } - else //bilancio di verifica - { - if (_verifica == 3) - { - if (_buff == NULL) - return NEXT_PAGE; - } - else if (_eof1) - return NEXT_PAGE; - } - return REPEAT_PAGE; -} - -TDate TStampa_bilanci::UltimaData(int g, int c, long s, int anno) -{ - TDate uldata; - TLocalisamfile saldi(LF_SALDI); - - saldi.zero(); - if (_annoes != 0) - saldi.put(SLD_ANNOES, anno); - saldi.put(SLD_FLSCA, FALSE); // W96SALDI del 05-06-96 - 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; -} - -// Non ho potuto usare quella di TConto!!! Chiedere a me! -// Guy: E tu chi sei? -const char* TStampa_bilanci::DescrizioneConto(int g, int c, long s, char tipocf) -{ -/* - static TString80 ragsoc; - const char* desc = NULL; - - TString80 key; key << g; - if (c != 0) - { - key << "|" << c ; - if (s != 0) - key << "|" << s; - } - const TRectype & pconti = cache().get(LF_PCON, key); - if (!pconti.empty()) - _tmp = pconti.get(PCN_DESCR); - else - { - key.format("%c|%ld", tipocf, s); - const TRectype & clifo = cache().get(LF_CLIFO, key); - - if (!clifo.empty()) - { - char tipoa = clifo.get_char(CLI_TIPOAPER); - if (tipoa == 'F') //persona fisica - { - TString80 cognome, nome; - ragsoc = clifo.get(CLI_RAGSOC); - cognome = ragsoc.mid(0,30); - nome = ragsoc.mid(30,20); - cognome.trim(); nome.trim(); - ragsoc = cognome; - ragsoc << " " << nome; - desc = ragsoc; - } - else - desc = clifo.get(CLI_RAGSOC); - _tmp = desc; - } - else - _tmp = ""; - - } - return _tmp; -*/ - const TBill bill(g, c, s, tipocf); - _tmp = bill.descrizione(); - return _tmp; -} - -bool TStampa_bilanci::user_create() -{ - open_files(LF_TAB, 0); - - _stampa_width = 132; - _rel = new TRelation(LF_CLIFO); - _cur = new TCursor (_rel,"",3); - _mov = new TLocalisamfile(LF_MOV); - _rmov = new TLocalisamfile(LF_RMOV); - _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); - _caus = new TLocalisamfile(LF_CAUSALI); - _d = new TParagraph_string("",29); - _sort = NULL; - _tmp_saldi_att = NULL; - _tmp_saldi_pass = NULL; - _tmp_saldi_costi = NULL; - _tmp_saldi_ricavi = NULL; - _tmp_saldi_conti_uno = NULL; - _tmp_saldi_conti_due = NULL; - return TRUE; -} - -bool TStampa_bilanci::user_destroy() -{ - delete _rel; - delete _cur; - delete _com; - delete _pcn; - delete _mov; - delete _rmov; - delete _clifo; - delete _saldi; - delete _nditte; - delete _anag; - delete _caus; - delete _d; - - if (_tmp_saldi_att) delete _tmp_saldi_att; - if (_tmp_saldi_pass) delete _tmp_saldi_pass; - if (_tmp_saldi_costi) delete _tmp_saldi_costi; - if (_tmp_saldi_ricavi) delete _tmp_saldi_ricavi; - if (_tmp_saldi_conti_uno) delete _tmp_saldi_conti_uno; - if (_tmp_saldi_conti_due) delete _tmp_saldi_conti_due; - return TRUE; -} - -void TStampa_bilanci::leggi_pcon() -{ - TRelation rel(LF_PCON); - TCursor cur(&rel); - const TRectype& pconti = rel.curr(); - - const long items = cur.items(); - cur.freeze(); - - TToken_string gc(10); - for (cur = 0L; cur.pos() < items; ++cur) - { - const int gruppo = pconti.get_int(PCN_GRUPPO); - const int conto = pconti.get_int(PCN_CONTO); - const long sottoconto = pconti.get_long(PCN_SOTTOCONTO); - if ( (sottoconto == 0l) && (conto != 0) ) //si tratta di un conto - { - const char tipocf = pconti.get_char(PCN_TMCF); - if ( tipocf == 'C' && (_situazione.empty() || _situazione == "C")) - { - gc.add(gruppo,0); - gc.add(conto,1); - _clienti.add(gc); - } - else if ( tipocf == 'F' && (_situazione.empty() || _situazione == "F")) - { - gc.add(gruppo,0); - gc.add(conto,1); - _fornitori.add(gc); - } - } - } -} - -void TStampa_bilanci::stampa_un_bilancio(const TMask& m) -{ - _prog = NULL; - if (_bilancio == 1) //bilancio a sezioni contrapposte - { - printer().footerlen(3); - _prog = new TProgress_monitor(_pcn->items(),TR("Elaborazione conti"), false); - _totali = m.get_bool(F_TOTALI); - _codici = m.get_bool(F_CODICI); - _saldo = m.get_bool(F_SALDO); - _tipo_stampa = m.get_int(F_STAMPA); - - if (_tipo_stampa == 1) - { - _datalim = m.get(F_DATALIM); - _print_exercise = TRUE; - if (_annoes == 0) - { - _print_exercise = FALSE; - _annoes = date2esc(_datalim); - } - - if (_annoes != 0) - _dataini = InizioEsercizio(_annoes); - else - _dataini = _inizioEs; - } - bil_sez_contr(); - } - else //bilancio di verifica (tipo 1,2,3) - { - printer().footerlen(5); - _stampa_width = (m.get_int(F_MODULO) == 1) ? 132 : 148; //perche' questo e' in realta' il margine dx (vedi es. di stampa AS/400) - - _verifica = m.get_int(F_VERIFICA); //tipo di bilancio di verifica da stampare - _print_full_code = _verifica == 1 && m.get_bool(F_PRINT_FULL_CODE); - if ( (_verifica == 1)||(_verifica == 2) ) - _prog = new TProgress_monitor(_pcn->items(),TR("Elaborazione conti"),false); - _tipo_stampa1 = m.get_int(F_STAMPA1); - if (_tipo_stampa1 == 1) - { - if (_annoes != 0) - _dataini = InizioEsercizio(_annoes); - else - _dataini = _inizioEs; - _datada = m.get(F_DATADA); - _dataa = m.get(F_DATAA); - } - if ((_verifica == 1)||(_verifica == 2)) //bilancio di verifica:1bilancio,2saldi mastro - { - _stampav = atoi(m.get(F_STAMPAV)); - bil_verifica(); - } - else - { - _situazione = m.get(F_SITUAZIONE); - _stampac = atoi(m.get(F_STAMPAC)); - _ordinamento = atoi(m.get(F_ORDINAMENTO)); - - if (_situazione.not_empty()) - _cur->setfilter(format("TIPOCF=\"%s\"",(const char*)_situazione)); - else - _cur->setfilter(""); - - _clienti.destroy(); - _fornitori.destroy(); - leggi_pcon(); - crea_sort_clifo(); // Crea la sua _prog - _sort->endsort(); - } - } - if (_prog) - delete _prog; - print(); -} - -bool TStampa_bilanci::set_print(int) -{ - TMask m ("cg1500a"); - m.set_handler (F_VERIFICA, verifica_handler); - m.set_handler (F_BILANCIO, mask_bilancio); - m.set_handler (F_STAMPA1, mask_bilancio); - m.set_handler (F_STAMPA, mask_bilancio); - m.set_handler (F_DATALIM, mask_datalim); - m.set_handler (F_DATADA, mask_date); - m.set_handler (F_DATAA, mask_date); - m.set_handler (F_ANNO, mask_anno); - - while (m.run() == K_ENTER) - { - _annoes = m.get_int(F_ANNO); - _bilancio = m.get_int(F_BILANCIO); - _data = m.get(F_DATASTAMPA); - _stampa_mov_prov = m.get_int(F_STAMPAMPROV); - _quadratura = m.get_bool(F_QUADRATURA); - _hide_clifo = m.get_bool(F_HIDE_CLIFO); - _noseparator = m.get_bool(F_SEPARATOR); -#ifdef CONT_SEP - _fl_cont_sep = m.get_bool(F_ST_CONTSEP); - _cont_sep = m.get(F_CONTSEP); -#endif - - //qui getti le terne dei 2 conti da mettere in bill_from e bill_to con un metodo dei TBill - _bill_from.get(m, F_DA_GRUPPO, F_DA_CONTO, F_DA_SOTTOCONTO); - _bill_to.get(m, F_A_GRUPPO, F_A_CONTO, F_A_SOTTOCONTO); - - //se non e' stato riempito il gruppo TO, si mette di default il max del gr/co/so - if (_bill_to.gruppo() == 0) - _bill_to.set(999, 999, 999999L); - else - { //se invece il gruppo c'e' ma il conto no... - if (_bill_to.conto() == 0) - _bill_to.set(_bill_to.gruppo(), 999, 999999L); //il gruppo e' quello selezionato - else - { - if (_bill_to.sottoconto() == 0) //se mancasse solo il sottoconto.. - _bill_to.set(_bill_to.gruppo(), _bill_to.conto(), 999999L); - } - } - - stampa_un_bilancio(m); - } - return FALSE; -} - -TRectype& look_com (const char* cod, TLocalisamfile *comuni) -{ - comuni->zero(); - comuni->put(COM_COM, cod); - comuni->read(); - if (comuni->bad()) - comuni->zero(); - - return comuni->curr(); -} - -void TStampa_bilanci::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 = look_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 TStampa_bilanci::stampa_intestazione_ditta() -{ - int r = 1; - TString codice_ditta; - TString riga(_stampa_width); - - get_dati_ditta(); - codice_ditta << get_firm(); - - set_header (r++, "%s %s %s %s %s %s %s", TR("Ditta"), (const char*)codice_ditta, - (const char*)_ragsoc, (const char*)_viafis, - (const char*)_cap, (const char*)_comunefis, - (const char*)_provfis); - printer().setdate(_data); - riga = TR("Data") ; riga << " @> " << TR("Pag.") << " @#"; - riga.right_just(_stampa_width-10); - - //_stampa_mov_provv(1=normale,2=globale,3=solo provvisori) - const char* tipoprovv = ""; - if (_stampa_mov_prov == 2) - tipoprovv = TR("GLOBALE"); - if (_stampa_mov_prov == 3) - tipoprovv = TR("PROVVISORIO"); - //l'uso della overwrite e' una vera vaccata! - riga.overwrite (format("%s %s %s %s", TR("Partita iva"), (const char*)_paiva, TR("Codice fiscale"), (const char*)_cofi)); - riga.overwrite (tipoprovv, 85); - - set_header (r++, "%s", (const char*) riga); - - return r; -} - -void TStampa_bilanci::preprocess_header() -{ - int r; - - reset_header(); - r = stampa_intestazione_ditta(); - - if (_bilancio == 1) //bilancio a sezioni contrapposte - { - TString riga (132); - TDate data_da; - TString data; - TString data_lim = _datalim.string(); - - set_header(r, TR("STAMPA BILANCIO A SEZIONI CONTRAPPOSTE")); - if (_tipo_stampa == 1) - { - data_da = _dataini.string(); - data = _datalim.string(); - set_header(r,"@41g%s %s %s %s", TR("dalla data"), (const char*) data_da, TR("alla data"), - (const char*) data); - } - else if (_tipo_stampa == 2) - set_header(r,FR("@41gall'ultima immissione Es. %d"), _annoes); - - //modifica del 20/04/1995 - if (_print_exercise) - { - const TString16 d1(InizioEsercizio(_annoes).string()); - const TString16 d2(FineEsercizio(_annoes).string()); - set_header(r, "@84g%s %s %s", TR("Esercizio"), (const char*)d1, (const char*)d2); /**/ - } - riga.fill('_'); - set_header(++r, (const char*)riga); - riga = ""; - set_header(++r, (const char*)riga); - } - else // bilancio di verifica - { - TString riga (_stampa_width); - TString16 datada = _datada.string(); - TString16 dataa = _dataa.string(); - if (_verifica == 1) - set_header(r, TR("STAMPA BILANCIO DI VERIFICA")); - else if (_verifica == 2) - set_header(r, TR("STAMPA SALDI DI MASTRO")); - else - { - if (_situazione == "C") - set_header(r, TR("SITUAZIONE CONTABILE CLIENTI")); - else if (_situazione == "F") - set_header(r, TR("SITUAZIONE CONTABILE FORNITORI")); - else set_header(r,TR("SITUAZIONE CLIENTI/FORNITORI")); - } - - if (_tipo_stampa1 == 1) - { - set_header(r,"@30g%s %s %s %s", TR("dalla data"), (const char*) datada, TR("alla data"), - (const char*) dataa); - //modifica del 20/04/1995 - if (_annoes != 0) //se l'anno e' 0 non si considera la competenza - { - TString16 d1(InizioEsercizio(_annoes).string()); - TString16 d2(FineEsercizio(_annoes).string()); - - set_header(r,"@74g%s %s %s", TR("Esercizio"), (const char*)d1, (const char*)d2); /**/ - } - } - else if (_tipo_stampa1 == 2) - { - set_header(r,FR("@36gall'ultima immissione Es. %d"), _annoes); - //modifica del 20/04/1995 - TString16 d1(InizioEsercizio(_annoes).string()); - TString16 d2(FineEsercizio(_annoes).string()); - - set_header(r,"@72g%s %s %s", TR("Esercizio"), (const char*)d1, (const char*)d2); /**/ - } - - if ( (_verifica == 1)||(_verifica == 2) ) - { - if (_stampav == 1) - set_header(r, "@107g%s", TR("Tutti i conti movimentati")); - else if (_stampav == 2) - set_header(r, "@107g%s", TR("Conti con saldo <> 0")); - else - set_header(r, "@107g%s", TR("Tutti i conti")); - } - else - { - if (_stampac == 1) - set_header(r, "@107g%s", TR("Tutti i conti movimentati")); - else - set_header(r, "@107g%s", TR("Conti con saldo <> 0")); - } - riga.fill('_'); - set_header(++r, (const char*)riga); - r++; - - TString h; - - if (_print_full_code) - h << "@46g!@55g"; - else - h << "@7g!@46g!@55g"; - - if ( ((_datada == _dataini)&&(_tipo_stampa1 == 1))||(_tipo_stampa1 != 1) ) - { - if (_tipo_stampa1 == 1 && _datada == _dataini) - h << TR("MOVIMENTI DI APERTURA"); - else - h << TR(" SALDO INIZIALE"); - } - else - if (_tipo_stampa1 == 1) - h << TR("PROGRESSIVI PRECEDENTI"); - h << "@80g!@88g"; - h << TR("MOVIMENTI DEL PERIODO"); - set_header(r, h); - if ( (_verifica == 1)||(_verifica == 3) ) - set_header(r,"@16g!"); - - set_header(r,"@114g!"); - if (_stampa_width != 132) - { - h = "@129g" ; - h << TR("SALDO"); - h << "@148g!"; - set_header(r, h); - } - r++; - - if ( (_verifica == 1)||(_verifica == 3)) - { - if (_print_full_code) - set_header(r,FR("@2gcodice conto !@46g!@47g%.67s@80g!@83g@114g!"),(const char*)riga); - else - set_header(r,FR("@2gcod. ! ultima !@46g!@47g%.67s@80g!@83g@114g!"),(const char*)riga); - if (_stampa_width == 132) - set_header(r,FR("@121gSALDO")); - else - set_header(r,"%.33s@148g!",(const char*)riga); - r++; - - if (_print_full_code) - set_header(r,FR("@2g ! denominazione@46g!@53gDare@63g!@69gAvere@80g!@87gDare@97g!@103gAvere@114g!")); - else - set_header(r,FR("@2gconto! data ! denominazione@46g!@53gDare@63g!@69gAvere@80g!@87gDare@97g!@103gAvere@114g!")); - if (_stampa_width != 132) - set_header(r,FR("@121gDare@131g!@137gAvere@148g!")); - r++; - } - else - { - set_header(r,FR("@2gcod. !@46g!@47g%.67s@80g!@83g@114g!"),(const char*)riga); - if (_stampa_width == 132) - set_header(r,FR("@121gSALDO")); - else - set_header(r,"%.33s@148g!",(const char*)riga); - r++; - - set_header(r,FR("@1gmastro!descrizione@46g!@53gDare@63g!@69gAvere@80g!@87gDare@97g!@103gAvere@114g!")); - if (_stampa_width != 132) - set_header(r, FR("@121gDare@131g!@137gAvere@148g!")); - r++; - } - set_header(r, (const char*)riga); - if (_stampa_width != 132) - set_header(r,"@148g!"); - } -} - -int cg1500 (int argc, char* argv[]) -{ - TStampa_bilanci a; - a.run(argc, argv, TR("Stampa bilanci")); - return 0; -} +// Stampa bilanci + +// W96SALDI e' la sigla di tutte le modifiche effettuate riguardo il cambiamento dell' archivio +// SALDI. L' archivio e' cambiato nel seguente modo: +// - Non esistono piu' i progressivi dei movimenti scaricati PDARESCA e PAVERESCA; +// - Ora esistono un record per i movimenti normali e un record per i movimenti scaricati; la +// distinzione e' resa possibile dall' introduzione in chiave di un flag FLSCA (vedi tracciato) +// che e' un booleano. Il record con FLSCA = FALSE contiene la somma dei saldi dei movimenti +// normali e dei movimenti scaricati, mentre il record con FLSCA = TRUE, contiene solo i saldi +// dei movimenti scaricati. +// Tutti i progressivi che nel programma venivano memorizzati nei campi PDARESCA e PAVERESCA dei +// file temporanei ora sono memorizzati in PDAREPRO e PAVEREPRO. +// Le funzioni che sono state modificate sono: +// - bil_verifica(); +// - ricerca_cf(...); +// - scrivi_record_gruppo(); +// - scrivi_record_conto(); +// - leggi_clifo(); +// - leggi_file_tmp(); +// - UltimaData(); + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cg1.h" +#include "cg1500.h" +#include "cglib01.h" +#include "cglib02.h" + +class TStampa_bilanci : public TPrintapp +{ + static bool mask_anno (TMask_field& f, KEY k); + static bool mask_datalim (TMask_field& f, KEY k); + static bool verifica_handler(TMask_field& f, KEY k); + static bool mask_date (TMask_field& f, KEY k); + static bool mask_bilancio(TMask_field& f, KEY k); + static bool mask_tipost (TMask_field& f, KEY k); + + struct cli_for + { + char tipocf; + char gruppo[4]; + char conto[4]; + char codcf[7]; + char ragsoc[51]; + real saldodare; + real saldoavere; + real movdare; + real movavere; + real saldofinale; + TDate udata; + }; + + TSort * _sort; + + TRelation* _rel; + TCursor * _cur; + TProgress_monitor * _prog; + TSaldi_list* _listacf, * _lista; + TLocalisamfile* _com, * _pcn, * _mov, * _rmov, * _clifo, * _saldi, * _nditte,* _anag,* _caus; + TIsamtempfile * _tmp_saldi_att, * _tmp_saldi_pass, * _tmp_saldi_conti_uno; + TIsamtempfile * _tmp_saldi_costi, * _tmp_saldi_ricavi,* _tmp_saldi_conti_due; + TParagraph_string* _d; + const char* _buff; + bool _noseparator; // Usa separatore delle migliaia o no? + + TString _cofi,_cap,_paiva,_ragsoc,_comunefis,_provfis,_viafis; + TString _descr_dare, _descr_avere, _gc_corr_dare, _gc_corr_avere, _descr; + TString _gc_prec_dare, _gc_prec_avere, _situazione, _descr_succ; + TString _tmp; +#ifdef CONT_SEP + TString _cont_sep; +#endif + char _tipo_conto, _tipoc_succ; + + int _annoes, _bilancio, _tipo_stampa, _tipo_stampa1,_stampa_width,_gp,_cp,_i; + int _eof1, _eof2, _gruppo_dare, _gruppo_avere, _conto_dare, _conto_avere; + int _add_file_da, _add_file_a, _indbil_dare, _indbil_avere, _indbil; + int _eof3, _eof4, _eof5, _eof6, _verifica, _stampac, _stampav, _ordinamento, _print_full_code; + int _gruppo, _conto, _gruppo_succ, _conto_succ, _annoapp; + long _sottoconto_dare, _sottoconto_avere, _sottoconto, _sottoconto_succ; + + real _saldo_dare, _saldo_avere, _gruppo_a, _gruppo_da, _conto_a; + real _conto_da, _tot_dare, _tot_avere, _mov_periodo_dare, _saldo_ini_dare; + real _mov_periodo_avere, _saldo_ini_avere, _prg_prec_dare, _prg_prec_avere; + real _saldo_ini_conto_dare, _saldo_ini_conto_avere, _saldoini_dare; + real _saldoini_avere, _mov_dare, _mov_avere, _saldofinale; + real _saldoini_dare_succ, _saldoini_avere_succ, _mov_dare_succ; + real _mov_avere_succ, _saldofinale_succ; + real _saldo_dare_tot, _saldo_avere_tot, _mov_dare_tot, _mov_avere_tot; + real _saldo_finale_tot, _saldo_ini_gruppo_dare, _saldo_ini_gruppo_avere; + real _gruppo_da_ordine, _gruppo_a_ordine; + real _prg_saldoini_dare, _prg_saldoini_avere, _prg_inidare_ord, _prg_iniavere_ord; + real _nuovo_tot_saldo_d, _nuovo_tot_saldo_a; + + TDate _datalim, _data, _datada, _dataa, _dataini, _ultima_data, _u_max; + bool _cambiato_conto_1, _cambiato_conto_2, _add_file_avere; + bool _add_file_dare, _prima_volta, _seconda_volta, _totali, _codici, _saldo; + bool _add_dare, _add_avere, _controlla, _salto_pagina, _flag, _stampato; + bool _sottoc_dare, _sottoc_avere, _salto_pagina1, _livello_conto; + bool _mov_ap,_quadratura; + bool _print_exercise, _hide_clifo; + int _stampa_mov_prov; + TBill _bill_from, _bill_to; + TArray _clienti, _fornitori; + +public: + TDate _inizioEs, _fineEs; + + int date2esc(const TDate& d, int* prevesc = NULL); + + bool menu (MENU_TAG m) { return TPrintapp::menu(m) ; } + virtual bool user_create() ; + virtual bool user_destroy(); + bool set_print(int); + + void next_c(); + + 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(); + virtual void set_page(int,int); + real compensazione(bool compensa, int indbil_conto, real& saldo); + //const char* causale_chiusura() { return _causale_chi;} + //const char* causale_apertura() { return _causale_ap;} + bool bil_sez_contr(); + bool bil_verifica(); + bool ricerca_sottoc_clifo(int,int,bool,int,real&); + bool ricerca_cf(int,int,char,int,real&,real&,real&,real&,real&,real&,real&); + bool calcola(int,int,long); + void leggi_pcon(); // Inizializza i TArray C/F + void crea_sort_clifo(); + void leggi_clifo(const TArray&); + void init_sort(); + void leggi_sort(); + void riempi_record(char,int,int,long,const char*,const real&, + const real&,const real&,const real&,const real&); + void get_dati_ditta(); + void scrivi_record_conto(const real&,const real&,const real&, + const real&, const real&); + void scrivi_record_gruppo(const real&,const real&,const real&, + const real&, const real&); + int stampa_record_conto(int,int,const TString&,const real&,const real&, + const real&,const real&,const real&,const char); + int stampa_intestazione_ditta(); + int cerca_indbil(int,int); + void scrivig_file_temp(); + void scrivic_file_temp(); + void scrivis_file_temp(int,int,long,const real&); + void leggi_files_dare (TIsamtempfile*); + void leggi_files_avere(TIsamtempfile*); + void leggi_file_tmp(); + void stampa_riga_totali(int); + void stampa_prima_colonna(int,int,long,const char*,const real&); + void stampa_seconda_colonna(int,int,long,const char*,const real&); + void stampa_totali(); + void stampa_totali_uno(const real&, const real&); + void controlla_conto(int,int); + const char* DescrizioneConto(int,int,long,char); //chiama quella di TConto + TDate UltimaData(int,int,long,int); + void stampa_un_bilancio(const TMask& m); + + TStampa_bilanci() {} +}; + +HIDDEN inline TStampa_bilanci& app() { return (TStampa_bilanci&)main_app(); } + +TDate InizioEsercizio(int anno) +{ + TEsercizi_contabili esc; + TDate inizio_es; + if (esc.exist(anno)) + inizio_es = esc[anno].inizio(); + return inizio_es; +} + +TDate FineEsercizio(int anno) +{ + TEsercizi_contabili esc; + TDate fine_es; + if (esc.exist(anno)) + fine_es = esc[anno].fine(); + return fine_es; +} + +bool IsEsercizio (const TDate& datalim, int anno_eser) +{ + TEsercizi_contabili esc; + bool yes = esc.date2esc(datalim) == anno_eser; + return yes; +} + +int TStampa_bilanci::date2esc(const TDate& d, int* prevesc) +{ + TEsercizi_contabili esc; + int anno = esc.date2esc(d); + if (prevesc) + *prevesc = esc.pred(anno); + return anno; +} + +bool TStampa_bilanci::mask_anno(TMask_field& f, KEY k) +{ + if (k == K_ENTER) + { + int tipo_stampa; + int anno = f.mask().get_int(F_ANNO); + int bilancio = f.mask().get_int(F_BILANCIO); + if (bilancio == 1) + tipo_stampa = f.mask().get_int(F_STAMPA); + else + tipo_stampa = f.mask().get_int(F_STAMPA1); + if (tipo_stampa == 2) + if (anno == 0) + { + f.error_box(TR("Indicare l'anno di esercizio")); + return FALSE; + } + } + if ( k == K_TAB || f.focusdirty()) + { + int tipo_stampa; + int anno = f.mask().get_int(F_ANNO); + int bilancio = f.mask().get_int(F_BILANCIO); + if (bilancio == 1) + tipo_stampa = f.mask().get_int(F_STAMPA); + else + tipo_stampa = f.mask().get_int(F_STAMPA1); + + if ((bilancio == 2) && (tipo_stampa == 1)) + if (anno != 0) + { + f.mask().show(F_DATADA); + f.mask().show(F_DATAA); + //f.mask().show(F_STAMPAMPROV); + f.mask().show(96); + f.mask().show(97); + f.mask().hide(98); + f.mask().hide(99); + } + else + { + f.mask().show(F_DATADA); + f.mask().show(F_DATAA); + //f.mask().show(F_STAMPAMPROV); + f.mask().show(98); + f.mask().show(99); + f.mask().hide(96); + f.mask().hide(97); + } + } + if (k == K_TAB) + { + int tipo_bil, tipo_stp; + tipo_bil = f.mask().get_int(F_BILANCIO); + if (tipo_bil == 1) + tipo_stp = f.mask().get_int(F_STAMPA); + else + tipo_stp = f.mask().get_int(F_STAMPA1); + if (tipo_bil == 2 && tipo_stp == 1 /* && f.mask().get_int(F_ANNO) == 0 */) + f.mask().show(F_QUADRATURA); + else + { + f.mask().set (F_QUADRATURA,""); + f.mask().hide(F_QUADRATURA); + } + } + return TRUE; +} + +bool TStampa_bilanci::mask_bilancio(TMask_field& f, KEY k) +{ + int tipo_bil, tipo_stp; + + if (k == K_SPACE) + { + TMask& m = f.mask(); + const int anno = m.get_int(F_ANNO); + const int bilancio = m.get_int(F_BILANCIO); + int tipo_stampa; + if (bilancio == 1) //bilancio a sezioni contrapposte + { + tipo_stampa = m.get_int(F_STAMPA); + m.disable_page(1); + } + else + { + tipo_stampa = m.get_int(F_STAMPA1); + m.enable_page(1); + } + + if (tipo_stampa == 2) //all'ultima immissione + { + m.hide(F_DATADA); + m.hide(F_DATAA); + //m.hide(F_STAMPAMPROV); + m.hide(98); + m.hide(99); + m.hide(96); + m.hide(97); + + // Disabilito le commesse nelle stampe all'ultima immissione + m.hide(-4); + m.reset(-4); + } + else + { + if (bilancio == 2) + if (anno != 0) + { + m.show(F_DATADA); + m.show(F_DATAA); + //m.show(F_STAMPAMPROV); + m.show(96); + m.show(97); + m.hide(98); + m.hide(99); + } + else + { + m.show(F_DATADA); + m.show(F_DATAA); + //m.show(F_STAMPAMPROV); + m.show(98); + m.show(99); + m.hide(96); + m.hide(97); + } + + // Abilito eventualmente le commesse + if (main_app().has_module(CMAUT)) + m.show(-4); + else + { + m.hide(-4); + m.reset(-4); + } + } + + tipo_bil = f.mask().get_int(F_BILANCIO); + if (tipo_bil == 1) + tipo_stp = f.mask().get_int(F_STAMPA); + else + tipo_stp = f.mask().get_int(F_STAMPA1); + if (tipo_bil == 2 && tipo_stp == 1 /* && f.mask().get_int(F_ANNO) == 0 */) + f.mask().show(F_QUADRATURA); + else + { + f.mask().set (F_QUADRATURA,""); + f.mask().hide(F_QUADRATURA); + } + } + return TRUE; +} + +bool TStampa_bilanci::mask_datalim (TMask_field& f, KEY k) +{ + if (k == K_ENTER) + { + int anno = f.mask().get_int(F_ANNO); + int bilancio = f.mask().get_int(F_BILANCIO); + TDate datalim(f.mask().get(F_DATALIM)); + if (bilancio == 1) + if (anno != 0) + { + if ( datalim.ok() ) + { + if (!IsEsercizio(datalim,anno)) + { + f.error_box (TR("La data limite deve appartenere all'esercizio indicato")); + return FALSE; + } + } + else + f.mask().field(F_DATALIM).set(FineEsercizio(anno)); + } + else //anno == 0 + { + if (!datalim.ok()) + { + f.error_box (TR("La data limite e' obbligatoria")); + return FALSE; + } + long anno = app().date2esc(datalim); + if (anno == 0) + { + f.error_box (TR("La data limite deve appartenere ad un esercizio attivo della ditta")); + return FALSE; + } + } + } + return TRUE; +} + +bool TStampa_bilanci::mask_date(TMask_field& f, KEY k) +{ + if (k == K_TAB) + { + const short id = f.dlg(); + + if (id == F_DATAA) + { + TDate data (f.get()); + int bil = f.mask().get_int(F_BILANCIO); + TEsercizi_contabili esc; + int anno = esc.date2esc(data); + if (anno) + { + TDate dataini = esc[anno].fine(); + if (data == dataini && bil == 2 /*&& f.mask().get_int(F_ANNO) == 0*/) + f.mask().show(F_QUADRATURA); + else + { + f.mask().reset(F_QUADRATURA); + f.mask().hide(F_QUADRATURA); + } + } + } + } + + if (k == K_ENTER) + { + const short id = f.dlg(); + int anno = f.mask().get_int(F_ANNO); + int bilancio = f.mask().get_int(F_BILANCIO); + if (bilancio == 2) + { + TDate data (f.mask().get(id)); + if (anno != 0) + { + if (data.ok()) + { + if (!IsEsercizio(data,anno)) + { + f.error_box(TR("La data indicata deve essere all'interno dell'esercizio")); + return FALSE; + } + } + if (!data.ok()) + { + if (id == F_DATADA) + f.mask().field(F_DATADA).set(InizioEsercizio(anno)); + else if (id == F_DATAA) + f.mask().field(F_DATAA).set(FineEsercizio(anno)); + } + app()._annoapp = anno; + } + else + { + if ( !data.ok() ) + { + f.error_box(TR("Indicare una data appartenente ad un esercizio attivo della ditta")); + return FALSE; + } + else + { + if (id == F_DATAA) + { + TDate from (f.mask().get(id - 1)); + app()._annoapp = app().date2esc(from); + if ( app()._annoapp != app().date2esc(data) ) + { + f.error_box(TR("Le date devono appartenere ad uno stesso esercizio attivo della ditta")); + return FALSE; + } + if (from > data) + { + f.error_box(TR("La data limite inferiore non puo' essere maggiore della data limite superiore")); + return FALSE; + } + } + } + } + } + } + return TRUE; +} + +bool TStampa_bilanci::verifica_handler(TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + int tipo_stampa = atoi(f.mask().get(F_STAMPA1)); + int verifica = atoi(f.mask().get(F_VERIFICA)); + if ( (tipo_stampa == 1) && ((verifica == 1) || (verifica == 2)) ) + { + f.mask().hide (F_SITUAZIONE); + f.mask().hide (F_STAMPAC); + f.mask().hide (F_ORDINAMENTO); + f.mask().show (F_STAMPAV); + f.mask().show (F_DATADA); + f.mask().show (F_DATAA); + } + if ( (tipo_stampa == 1) && (verifica == 3) ) + { + f.mask().show (F_SITUAZIONE); + f.mask().show (F_STAMPAC); + f.mask().show (F_ORDINAMENTO); + f.mask().show (F_DATADA); + f.mask().show (F_DATAA); + f.mask().hide (F_STAMPAV); + } + if ( (tipo_stampa == 2) && ((verifica == 1)||(verifica == 2)) ) + { + f.mask().hide (F_SITUAZIONE); + f.mask().hide (F_STAMPAC); + f.mask().hide (F_ORDINAMENTO); + f.mask().hide (F_DATADA); + f.mask().hide (F_DATAA); + f.mask().show (F_STAMPAV); + } + if ( (tipo_stampa == 2) && (verifica == 3) ) + { + f.mask().show (F_SITUAZIONE); + f.mask().show (F_STAMPAC); + f.mask().show (F_ORDINAMENTO); + f.mask().hide (F_DATADA); + f.mask().hide (F_DATAA); + f.mask().hide (F_STAMPAV); + } + } + return TRUE; +} + +void TStampa_bilanci::scrivig_file_temp() +{ + TIsamtempfile* tmp = NULL; + TString nome_campo(12); + real valore; + + if (!_totali) + { + if (_add_dare) + { + nome_campo = SLD_PDARE; + valore = _gruppo_da; + switch (_indbil) + { + case 1: + case 2: + tmp = _tmp_saldi_att; + break; + case 3: + case 4: + tmp = _tmp_saldi_costi; + break; + case 5: + tmp = _tmp_saldi_conti_uno; + valore = _gruppo_da_ordine; + break; + default: + break; + } + + tmp->zero(); + tmp->put(SLD_GRUPPO,_gp); + tmp->put(SLD_CONTO,0); + tmp->put(SLD_SOTTOCONTO,0L); + tmp->put(SLD_ANNOES,0); // W96SALDI del 07-06-96 + tmp->put(SLD_FLSCA,FALSE); + if (tmp->read() == NOERR) + { + tmp->put(SLD_CONTO,0); + tmp->put(SLD_SOTTOCONTO,0L); + tmp->put(nome_campo, valore); + tmp->rewrite(); + } + else + { + tmp->put(SLD_GRUPPO,_gp); + tmp->put(SLD_CONTO,0); + tmp->put(SLD_SOTTOCONTO,0L); + tmp->put(SLD_ANNOES,0); // W96SALDI del 07-06-96 + tmp->put(SLD_FLSCA,FALSE); + tmp->put(nome_campo, valore); + tmp->write(); + } + } + if (_add_avere) + { + nome_campo = SLD_PAVERE; + valore = _gruppo_a; + switch (_indbil) + { + case 1: + case 2: + tmp = _tmp_saldi_pass; + break; + case 3: + case 4: + tmp = _tmp_saldi_ricavi; + break; + case 5: + tmp = _tmp_saldi_conti_due; + valore = _gruppo_a_ordine; + break; + default: + break; + } + + tmp->zero(); + tmp->put(SLD_GRUPPO,_gp); + tmp->put(SLD_CONTO,0); + tmp->put(SLD_SOTTOCONTO,0L); + tmp->put(SLD_ANNOES,0); // W96SALDI del 07-06-96 + tmp->put(SLD_FLSCA,FALSE); + if (tmp->read() == NOERR) + { + tmp->put(SLD_CONTO,0); + tmp->put(SLD_SOTTOCONTO,0L); + tmp->put(nome_campo, valore); + tmp->rewrite(); + } + else + { + tmp->put(SLD_GRUPPO,_gp); + tmp->put(SLD_CONTO,0); + tmp->put(SLD_SOTTOCONTO,0L); + tmp->put(SLD_ANNOES,0); // W96SALDI del 07-06-96 + tmp->put(SLD_FLSCA,FALSE); + tmp->put(nome_campo, valore); + tmp->write(); + } + } + } + _add_dare = _add_avere = FALSE; +} + +void TStampa_bilanci::scrivic_file_temp() +{ + TIsamtempfile* tmp = NULL; + TString nome_campo(12); + real valore; + + if (_add_file_dare) + { + _add_dare = TRUE; + nome_campo = SLD_PDARE; + valore = _conto_da; + if (_indbil == 1 || _indbil==2) tmp = _tmp_saldi_att; // da stampare a sx + else + if (_indbil==3 || _indbil==4) tmp = _tmp_saldi_costi; //da stampare a sx + else + if (_indbil==5) tmp = _tmp_saldi_conti_uno; + else return; + tmp->zero(); + tmp->put(SLD_GRUPPO,_gp); + tmp->put(SLD_CONTO,_cp); + tmp->put(SLD_SOTTOCONTO,0L); + tmp->put(nome_campo, valore); + tmp->write(); + } + if (_add_file_avere) + { + _add_avere = TRUE; + nome_campo = SLD_PAVERE; + valore = _conto_a; + if (_indbil==2 || _indbil==1) tmp = _tmp_saldi_pass; //da stampare a dx + else + if (_indbil==4 || _indbil==3) tmp = _tmp_saldi_ricavi;//da stampare a dx + else + if (_indbil==5) tmp = _tmp_saldi_conti_due; + else return; + tmp->zero(); + tmp->put(SLD_GRUPPO,_gp); + tmp->put(SLD_CONTO,_cp); + tmp->put(SLD_SOTTOCONTO,0L); + tmp->put(nome_campo, valore); + tmp->write(); + } +} + +void TStampa_bilanci::scrivis_file_temp(int g, int c, long s, const real& saldo) +{ + TIsamtempfile* tmp = NULL; + TString16 nome_campo; + + if (_indbil==1) + { + tmp = _tmp_saldi_att; + nome_campo = SLD_PDARE; + } + else + if (_indbil==2) + { + tmp = _tmp_saldi_pass; + nome_campo = SLD_PAVERE; + } + else + if (_indbil==3) + { + tmp = _tmp_saldi_costi; + nome_campo = SLD_PDARE; + } + else + if (_indbil==4) + { + tmp = _tmp_saldi_ricavi; + nome_campo = SLD_PAVERE; + } + else + if (_sottoc_dare) + { + tmp = _tmp_saldi_conti_uno; + nome_campo = SLD_PDARE; + } + else + if (_sottoc_avere) + { + tmp = _tmp_saldi_conti_due; + nome_campo = SLD_PAVERE; + } + CHECKD(tmp, "Null tmp file: indbil = ", _indbil); + tmp->zero(); + tmp->put(SLD_GRUPPO,g); + tmp->put(SLD_CONTO,c); + tmp->put(SLD_SOTTOCONTO,s); + tmp->put(nome_campo, saldo); + tmp->write(); +} + +real TStampa_bilanci::compensazione(bool compensa, int indbil_conto, real& sld) +{ + real saldo = sld; + + if (!compensa) + { + switch (indbil_conto) + { + case 1: + if (saldo > ZERO) + _indbil = indbil_conto; + else + { + _indbil = 2; + saldo = -saldo; + } + break; + + case 3: + if (saldo > ZERO) + _indbil = indbil_conto; + else + { + _indbil = 4; + saldo = -saldo; + } + break; + + case 2: + if (saldo < ZERO) + { + _indbil = indbil_conto; + saldo = -saldo; + } + else + _indbil = 1; + break; + + case 4: + if (saldo < ZERO) + { + _indbil = indbil_conto; + saldo = -saldo; + } + else + _indbil = 3; + break; + case 5: + default: break; + } + } + else //e' richiesta la compensazione + if ( indbil_conto==2 || indbil_conto==4) + saldo = -saldo; + + return saldo; +} + +void TStampa_bilanci::next_c() +{ + TRecnotype recnum = _pcn->recno(); + _pcn->next(); + if (_pcn->eof()) + { + scrivic_file_temp(); + scrivig_file_temp(); + } + _pcn->readat(recnum); +} + +bool TStampa_bilanci::bil_sez_contr() +{ + TSaldo sld; + int indbil_conto=0; + int g, c; + long s; + char tipo_conto = ' '; + real saldo; + bool compensa=FALSE, dettaglio=FALSE, cambiato=FALSE; + bool esiste_conto=FALSE, esiste_sc = FALSE; + bool movimentato = FALSE; + + CHECK(_tmp_saldi_att == NULL, "Non posso riaprire cg01"); + _tmp_saldi_att = new TIsamtempfile(LF_SALDI, "cg01", TRUE, TRUE); + _prog->addstatus(1); + _tmp_saldi_pass = new TIsamtempfile(LF_SALDI, "cg02", TRUE, TRUE); + _prog->addstatus(1); + _tmp_saldi_costi = new TIsamtempfile(LF_SALDI, "cg03", TRUE, TRUE); + _prog->addstatus(1); + _tmp_saldi_ricavi = new TIsamtempfile(LF_SALDI, "cg04", TRUE, TRUE); + _prog->addstatus(1); + _tmp_saldi_conti_uno = new TIsamtempfile(LF_SALDI, "cg05", TRUE, TRUE); + _prog->addstatus(1); + _tmp_saldi_conti_due = new TIsamtempfile(LF_SALDI, "cg06", TRUE, TRUE); + _prog->addstatus(1); + + _gp=-1; + _cp=-1; + _gruppo_a = ZERO; + _gruppo_da = ZERO; + _gruppo_da_ordine = ZERO; + _gruppo_a_ordine = ZERO; + _prg_saldoini_dare = ZERO; + _prg_saldoini_avere = ZERO; + _prg_inidare_ord = ZERO; + _prg_iniavere_ord = ZERO; + _conto_a = ZERO; + _conto_da = ZERO; + _add_dare = FALSE; + _add_avere = FALSE; + + sld.set_annoes(_annoes); + + 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); + + if (c != _cp) + cambiato = TRUE; + + if ( (((_cp != -1) && (c != _cp)) || ((_gp != -1) && (g != _gp))) && + esiste_sc ) + { + scrivic_file_temp(); + scrivig_file_temp(); + _cp = c; + esiste_conto = TRUE; + _conto_da = ZERO; + _conto_a = ZERO; + } + + if ( ((_gp != -1) && (g != _gp)) && esiste_conto ) + { + scrivig_file_temp(); + esiste_conto = FALSE; + _gp = g; + _gruppo_da = ZERO; + _gruppo_a = ZERO; + _gruppo_da_ordine = ZERO; + _gruppo_a_ordine = ZERO; + } + + if (cambiato) + { + _add_file_avere = FALSE; + _add_file_dare = FALSE; + cambiato = FALSE; + } + + if ( (s == 0) && (c != 0) ) //si tratta di un conto + { + compensa = _pcn->get_bool(PCN_COMPENS); + dettaglio = !_pcn->get_bool(PCN_STSOTTBIL); + tipo_conto = _pcn->get_char(PCN_TMCF); + indbil_conto = _pcn->get_int(PCN_INDBIL); + + if (indbil_conto <= 0) // Warning per Roberto! + { + yesnofatal_box(FR("Indicatore di bilancio %d nel conto %03d %03d"), indbil_conto, + _pcn->get_int (PCN_GRUPPO), _pcn->get_int (PCN_CONTO)); + indbil_conto = 1; + } + + if ( (tipo_conto == 'C') || (tipo_conto == 'F') ) + { + saldo = ZERO; + esiste_sc = ricerca_sottoc_clifo(g, c, compensa, indbil_conto, saldo); + if (esiste_sc) + { + _gp = g; + _cp = c; + } + TRecnotype recnum = _pcn->recno(); + _pcn->next(); + if (_pcn->eof()) + { + if (esiste_sc) + { + scrivic_file_temp(); + scrivig_file_temp(); + } + else if (esiste_conto) + scrivig_file_temp(); + } + _pcn->readat(recnum); + + continue; + } + } + + if ( (c == 0) || (s == 0) ) //si tratta di un conto o di un gruppo + { + esiste_sc = FALSE; + continue; + } + + if (_tipo_stampa == 1) //bil. a sez. contrapposte per data limite + { +#ifdef CONT_SEP + movimentato = sld.saldo_cont_sep(g, c, s, _annoes, _datalim, indbil_conto, _cont_sep, _stampa_mov_prov) ; +#else + movimentato = sld.data_limite_bilancio(_bilancio, g, c, s, _dataini, _datalim, indbil_conto, _stampa_mov_prov); +#endif + } + else + { + if (_tipo_stampa == 2) //bil. a sez. contrapposte all'ultima immissione es. in corso + movimentato = sld.ultima_immissione_bilancio(_annoes,g,c,s,indbil_conto,_stampa_mov_prov); + } + + if (!movimentato) + if (!sld.esiste_saldo() || !sld.significativo()) + { + next_c(); + continue; + } + + saldo = sld.saldo(); + real app = sld.saldoini(); + bool flag = sld.flagprec(); + + if (_saldo) //se richiesto di NON stampare i conti con saldo a zero + if (saldo == ZERO) + { + //modifica del 06/07/1995 + if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) + { + //real app = sld.saldoini(); + //bool flag = sld.flagprec(); + if (flag) + { + if (app > ZERO) + { + if (indbil_conto == 5) + _prg_inidare_ord += app; + else _prg_saldoini_dare += app; + } + else if (app < ZERO) + { + app = -app; + if (indbil_conto == 5) + _prg_iniavere_ord += app; + else _prg_saldoini_avere += app; + } + } + } + //fine + next_c(); + continue; + } + + esiste_sc = TRUE; + _indbil = indbil_conto; + + //i due flag seguenti servono solo per i conti d'ordine + _sottoc_dare = FALSE; + _sottoc_avere = FALSE; + + if (saldo != ZERO) + saldo = compensazione(compensa, indbil_conto, saldo); + + if (_indbil == 1 || _indbil == 2) + { + if (flag) + { + if (app > ZERO) + _prg_saldoini_dare += app; + else if (app < ZERO) + { + app = -app; + _prg_saldoini_avere += app; + } + } + } + + if (_indbil == 5) + { + //real app = sld.saldoini(); + if (flag) + { + if (app > ZERO) + _prg_inidare_ord += app; + else if (app < ZERO) + { + app = -app; + _prg_iniavere_ord += app; + } + } + } + + if ( _indbil==1 || _indbil==3 ) + { + _gruppo_da += saldo; + _conto_da += saldo; + _add_file_dare = TRUE; + } + + if ( _indbil==2 || _indbil==4 ) + { + _gruppo_a += saldo; + _conto_a += saldo; + _add_file_avere = TRUE; + } + + if (_indbil==5) + { + if ( saldo >= ZERO || compensa ) + { + _gruppo_da_ordine += saldo; + _conto_da += saldo; + _add_file_dare = TRUE; + _sottoc_dare = TRUE; + } + else + { + saldo = -saldo; + _gruppo_a_ordine += saldo; + _conto_a += saldo; + _add_file_avere = TRUE; + _sottoc_avere = TRUE; + } + scrivig_file_temp(); + } + if ( (dettaglio) && ( (tipo_conto != 'C') && (tipo_conto != 'F') ) ) + scrivis_file_temp(g, c, s, saldo); + + _gp = g; + _cp = c; + // } // da_considerare + + TRecnotype recnum = _pcn->recno(); + _pcn->next(); + if (_pcn->eof()) + { + scrivic_file_temp(); + scrivig_file_temp(); + } + _pcn->readat(recnum); + } + + return TRUE; +} + +bool TStampa_bilanci::ricerca_sottoc_clifo(int g,int c, bool compensa, int indbil_conto,real& saldo) +{ + TSaldo sld; + int aep=0; + long s, items; + bool esiste_sc = FALSE; + bool movimentato = FALSE; + + if (_annoes) + { + TEsercizi_contabili ese; + aep = ese.pred(_annoes); + } + sld.set_annoes(_annoes); + _listacf = new TSaldi_list(g, c, _annoes, aep); + + items = _listacf->items(); + + for (int i = 0; i < items; i++) + { + const TRectype* r = _listacf->saldi(); + + if (r == NULL) break; + + s = r->get_long(SLD_SOTTOCONTO); + + if (_tipo_stampa == 1) //bil. a sez. contrapposte per data limite + { +#ifdef CONT_SEP + movimentato = sld.saldo_cont_sep(g, c, s, _annoes, _datalim, indbil_conto, _cont_sep, _stampa_mov_prov); +#else + movimentato = sld.data_limite_bilancio(_bilancio,g,c,s,_dataini,_datalim,indbil_conto,_stampa_mov_prov); +#endif + } + else + if (_tipo_stampa == 2) //bil. a sez. contrapposte all'ultima immissione es. in corso + movimentato = sld.ultima_immissione_bilancio(_annoes, g, c, s, indbil_conto, _stampa_mov_prov); + + if (!movimentato) + if (!sld.esiste_saldo() || !sld.significativo()) + continue; + + saldo = sld.saldo(); + real app = sld.saldoini(); + bool flag = sld.flagprec(); + + if (_saldo) //se richiesto di non stampare i conti con saldo a zero + if (saldo == ZERO) + { + //modifica del 06/07/1995 + if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) + { + //real app = sld.saldoini(); + if (flag) + { + if (app > ZERO) + { + if (indbil_conto == 5) + _prg_inidare_ord += app; + else _prg_saldoini_dare += app; + } + else if (app < ZERO) + { + app = -app; + if (indbil_conto == 5) + _prg_iniavere_ord += app; + else _prg_saldoini_avere += app; + } + } + } + //fine + continue; + } + + esiste_sc = TRUE; + _indbil = indbil_conto; + + //i due flag seguenti servono solo per i conti d'ordine + _sottoc_dare = FALSE; + _sottoc_avere = FALSE; + + if (saldo != ZERO) + saldo = compensazione(compensa, indbil_conto, saldo); + + if (_indbil == 1 || _indbil == 2) + { + if (flag) + { + if (app > ZERO) + _prg_saldoini_dare += app; + else if (app < ZERO) + { + app = -app; + _prg_saldoini_avere += app; + } + } + } + + if (_indbil == 5) + { + //real app = sld.saldoini(); + if (flag) + { + if (app > ZERO) + _prg_inidare_ord += app; + else if (app < ZERO) + { + app = -app; + _prg_iniavere_ord += app; + } + } + } + + if ( (_indbil==1) || (_indbil==3) ) + { + _gruppo_da += saldo; + _conto_da += saldo; + _add_file_dare = TRUE; + } + + if ( (_indbil==2) || (_indbil==4) ) + { + _gruppo_a += saldo; + _conto_a += saldo; + _add_file_avere = TRUE; + } + + if (_indbil==5) + { + if ( (saldo >= ZERO) || (compensa) ) // il sottoconto ha saldo in dare + { + _gruppo_da_ordine += saldo; + _conto_da += saldo; + _add_file_dare = TRUE; + _sottoc_dare = TRUE; + } + else //il sottoconto ha saldo in avere + { + saldo = -saldo; + _gruppo_a_ordine += saldo; + _conto_a += saldo; + _add_file_avere = TRUE; + _sottoc_avere = TRUE; + } + scrivig_file_temp(); + } + } + delete _listacf; + return esiste_sc; +} + +bool TStampa_bilanci::bil_verifica() +{ + TSaldo sld; + int g, c, indbil_conto = 0; + long s; + char tipo_conto = ' '; + real saldo_finale, saldo_conto, saldo_gruppo, saldo_iniziale; + real mov_conto_dare, mov_conto_avere, prg_conto_dare, prg_conto_avere; + real mov_gruppo_dare, mov_gruppo_avere, prg_gruppo_dare, prg_gruppo_avere; + bool esiste_conto = FALSE, esiste_sc = FALSE, movimentato = FALSE; + + CHECK(_tmp_saldi_att == NULL, "Non posso riaprire cg01"); + _tmp_saldi_att = new TIsamtempfile(LF_SALDI, "cg01", TRUE, TRUE); + + _gp=-1; + _cp=-1; + + _saldo_ini_conto_dare = ZERO; + _saldo_ini_conto_avere = ZERO; + _saldo_ini_gruppo_dare = ZERO; + _saldo_ini_gruppo_avere = ZERO; + _nuovo_tot_saldo_d = ZERO; + _nuovo_tot_saldo_a = ZERO; + saldo_conto = ZERO; + mov_conto_dare = ZERO; + mov_conto_avere = ZERO; + prg_conto_dare = ZERO; + prg_conto_avere = ZERO; + saldo_gruppo = ZERO; + mov_gruppo_dare = ZERO; + mov_gruppo_avere = ZERO; + prg_gruppo_dare = ZERO; + prg_gruppo_avere = ZERO; + _u_max = 0l; + + //controllo sui gr/co/sc selezionati + if (_bill_from.gruppo() > 0) //se ho un gruppo iniziale valido... + { + if (_bill_from.sottoconto() > 0L) + { + _pcn->zero(); + _pcn->put(PCN_GRUPPO,_bill_from.gruppo()); //lo metto nel file del pianodeiconticorrente.. + _pcn->put(PCN_CONTO,_bill_from.conto()); //un valore alla volta + if (_pcn->read(_isequal) == NOERR) + { + indbil_conto = _pcn->get_int(PCN_INDBIL); + tipo_conto = _pcn->get_char(PCN_TMCF); + } + } + + _pcn->zero(); + _pcn->put(PCN_GRUPPO,_bill_from.gruppo()); //lo metto nel file del pianodeiconticorrente.. + _pcn->put(PCN_CONTO,_bill_from.conto()); //un valore alla volta + _pcn->put(PCN_SOTTOCONTO,_bill_from.sottoconto()); + _pcn->read(_isgteq); //..e la scansione del file _pcn parte da questo + } + else + _pcn->first(); //..se non e' stato selezionato nessun gruppo parto dal primo + + for ( ; !_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); + + if ( (((_cp != -1) && (c != _cp)) || ((_gp != -1) && (g != _gp))) && esiste_sc ) + { + if (_verifica == 2) + if (!((_stampav == 2) && (saldo_conto == 0))) + { + //modifica del 21/11/1995 + if (_tipo_stampa1 == 1 && _datada == _dataini) + { + _saldo_ini_gruppo_dare += _saldo_ini_conto_dare; + _saldo_ini_gruppo_avere += _saldo_ini_conto_avere; + } + else + //fine + { + const real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; + if (app < ZERO) + _saldo_ini_gruppo_avere += app; + else + _saldo_ini_gruppo_dare += app; + } + mov_gruppo_dare += mov_conto_dare; + mov_gruppo_avere += mov_conto_avere; + prg_gruppo_dare += prg_conto_dare; + prg_gruppo_avere += prg_conto_avere; + saldo_gruppo += saldo_conto; + } + //scrivo il record del conto; + if ( (_verifica == 1)||( (_verifica == 2)&& + (!((_stampav == 2)&&(saldo_conto == 0))) ) ) + { + scrivi_record_conto(prg_conto_dare,prg_conto_avere,mov_conto_dare, + mov_conto_avere,saldo_conto); + esiste_conto = TRUE; + } + _cp = c; + _saldo_ini_conto_dare = ZERO; + _saldo_ini_conto_avere = ZERO; + saldo_conto = ZERO; + mov_conto_dare = ZERO; + mov_conto_avere = ZERO; + prg_conto_dare = ZERO; + prg_conto_avere = ZERO; + } + if (_verifica == 2) + if ( ((_gp != -1) && (g != _gp)) && (!esiste_conto) ) + { + _gp = g; + _saldo_ini_gruppo_dare = ZERO; + _saldo_ini_gruppo_avere = ZERO; + saldo_gruppo = ZERO; + mov_gruppo_dare = ZERO; + mov_gruppo_avere = ZERO; + prg_gruppo_dare = ZERO; + prg_gruppo_avere = ZERO; + } + if (_verifica == 2) + if ( ((_gp != -1) && (g != _gp)) && esiste_conto ) + { + //scrivo il record del gruppo + scrivi_record_gruppo(prg_gruppo_dare,prg_gruppo_avere,mov_gruppo_dare, + mov_gruppo_avere,saldo_gruppo); + _gp = g; + esiste_conto = FALSE; + _saldo_ini_gruppo_dare = ZERO; + _saldo_ini_gruppo_avere = ZERO; + saldo_gruppo = ZERO; + mov_gruppo_dare = ZERO; + mov_gruppo_avere = ZERO; + prg_gruppo_dare = ZERO; + prg_gruppo_avere = ZERO; + } + if ( (s == 0) && (c != 0) ) //si tratta di un conto + { + tipo_conto = _pcn->get_char(PCN_TMCF); + indbil_conto = _pcn->get_int(PCN_INDBIL); + if ( (tipo_conto == 'C') || (tipo_conto == 'F') ) + { + esiste_sc = ricerca_cf(g,c,tipo_conto,indbil_conto,saldo_finale,saldo_iniziale, + mov_conto_dare,mov_conto_avere,prg_conto_dare,prg_conto_avere, + saldo_conto); + if (_verifica == 2 && _stampav == 2 && saldo_conto.is_zero()) + continue; + if (esiste_sc) + { + _gp = g; + _cp = c; + const TRecnotype recnum = _pcn->recno(); + _pcn->next(); + if (_pcn->eof()) + { + if (_verifica == 2) + { + //modifica del 21/11/1995 + if (_tipo_stampa1 == 1 && _datada == _dataini) + { + _saldo_ini_gruppo_dare += _saldo_ini_conto_dare; + _saldo_ini_gruppo_avere += _saldo_ini_conto_avere; + } + else + //fine + { + real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; + if (app < ZERO) + _saldo_ini_gruppo_avere += app; + else + _saldo_ini_gruppo_dare += app; + } + mov_gruppo_dare += mov_conto_dare; + mov_gruppo_avere += mov_conto_avere; + prg_gruppo_dare += prg_conto_dare; + prg_gruppo_avere += prg_conto_avere; + saldo_gruppo += saldo_conto; + + scrivi_record_gruppo(prg_gruppo_dare,prg_gruppo_avere, + mov_gruppo_dare,mov_gruppo_avere,saldo_gruppo); + } + scrivi_record_conto(prg_conto_dare,prg_conto_avere,mov_conto_dare, + mov_conto_avere,saldo_conto); + } + _pcn->readat(recnum); + } + continue; + } + } + + //controlla se e' arrivato all'ultimo gruppo/conto/sottoconto selezionato + const TBill curr_bill(g,c,s); + if (curr_bill > _bill_to) + break; + + if ( (c == 0) || (s == 0) ) + { + esiste_sc = FALSE; + continue; + } + + saldo_finale = saldo_iniziale = ZERO; //saldi relativi a ciascun sottoconto + _indbil = indbil_conto; + if (_tipo_stampa1 == 1) //bil. di verifica per data limite + { + //modifica del 21/11/95 + _mov_ap = FALSE; + //modifica del 19/06/95 + movimentato = calcola(g,c,s); + if (_stampa_mov_prov != 3) + { + if (movimentato) + { + //modifica del 21/11/95 + if (_mov_ap) + saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; + else //discorso flag "movimentato" (video) + { + TLocalisamfile saldi(LF_SALDI); // W96SALDI + saldi.zero(); // Modifica SALDI per movimenti + saldi.put(SLD_ANNOES, _annoes); // scaricati del 05-06-96 + saldi.put(SLD_FLSCA, FALSE); // Ho aggiunto saldi.put(SLD_FLSCA, FALSE); + saldi.put(SLD_GRUPPO, g); // In questo modo considero il record con + saldi.put(SLD_CONTO, c); // la somma fra progressivi normali e scaricati + saldi.put(SLD_SOTTOCONTO, s); + if (saldi.read() == NOERR) + { + const real ss = saldi.get_real(SLD_SALDO); + if (ss.is_zero()) + { + if (_annoes != 0 && (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5)) + { + saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s,false,_stampa_mov_prov == 2); + //modifica del 21/11/95 + if (saldo_iniziale > ZERO) + _saldo_ini_dare = saldo_iniziale; + else + _saldo_ini_avere = -saldo_iniziale; + //fine + } + } + else + { + const char fsi = saldi.get_char(SLD_FLAGSALINI); + if (fsi == 'D') + { + saldo_iniziale = ss; + _saldo_ini_dare = ss; + } + else + { + saldo_iniziale = -ss; + _saldo_ini_avere = ss; + } + } + } + } + } + else // !movimentato -> _mov_ap e' di sicuro FALSE + { + if (_annoes != 0 && (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5)) + { + saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s,false,_stampa_mov_prov == 2); + //modifica del 21/11/95 + if (saldo_iniziale > ZERO) + _saldo_ini_dare = saldo_iniziale; + else _saldo_ini_avere = -saldo_iniziale; + //fine + if (_stampav == 1 && sld.significativo()) + movimentato = TRUE; + } + } + } + + + if (movimentato || _stampav != 1) + { + + _nuovo_tot_saldo_d += _mov_periodo_dare; + _nuovo_tot_saldo_a += _mov_periodo_avere; + _nuovo_tot_saldo_d += _saldo_ini_dare; + _nuovo_tot_saldo_a += _saldo_ini_avere; + + if (_datada == _dataini) + saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; + else if (_datada > _dataini) + { + if (saldo_iniziale > 0) + _prg_prec_dare += saldo_iniziale; + else _prg_prec_avere -= saldo_iniziale; + saldo_finale = _prg_prec_dare-_prg_prec_avere+_mov_periodo_dare-_mov_periodo_avere; + + } + //if (saldo_finale == ZERO) + // if (_stampav == 2) + // continue; + } + //se saldo_finale < 0 verra' stampato con una A, se no con una D + } + else + { + movimentato = sld.ultima_immissione_verifica(_annoes,g,c,s,indbil_conto,_stampa_mov_prov); + + if (_stampa_mov_prov != 3) + { + if (movimentato) + saldo_iniziale = sld.saldoini(); + if (!movimentato) + { + if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) + { + saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s,FALSE,_stampa_mov_prov == 2); + if (_stampav == 1 && sld.significativo()) + movimentato = TRUE; + } + } + } + + if (movimentato || _stampav != 1) + { + _mov_periodo_dare = sld.prgdare(); + _mov_periodo_avere = sld.prgavere(); + _prg_prec_dare = ZERO; + _prg_prec_avere = ZERO; + + if (sld.sezsf() == 'A') + _mov_periodo_avere -= sld.saldofin(); + else + _mov_periodo_dare += sld.saldofin(); + + saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; + } + } + + if ((movimentato || _stampav != 1) && !(saldo_finale.is_zero() && _stampav == 2)) + { + esiste_sc = TRUE; + esiste_conto = TRUE; + + if (_tipo_stampa1 == 2) + { + _nuovo_tot_saldo_d += _mov_periodo_dare; + _nuovo_tot_saldo_a += _mov_periodo_avere; + real nuovo = sld.saldoinisusaldi(); + if (nuovo > ZERO) + _nuovo_tot_saldo_d += nuovo; + else + { + nuovo = -nuovo; + _nuovo_tot_saldo_a += nuovo; + } + } + //modifica del 21/11/1995 + if (_tipo_stampa1 == 1 && _datada == _dataini) + { + _saldo_ini_conto_dare += _saldo_ini_dare; + _saldo_ini_conto_avere += _saldo_ini_avere; + } + else //_tipo_stampa1 == 1 || _tipo_stampa1 == 2 + { + if (saldo_iniziale < ZERO) + _saldo_ini_conto_avere += saldo_iniziale; + else + _saldo_ini_conto_dare += saldo_iniziale; + } + + mov_conto_dare += _mov_periodo_dare; + mov_conto_avere += _mov_periodo_avere; + prg_conto_dare += _prg_prec_dare; + prg_conto_avere += _prg_prec_avere; + saldo_conto += saldo_finale; // somma pitagorica + + //scrivo il record relat. al sottoconto se non e' richiesto saldi di mastro + if (_verifica != 2) + { + _tmp_saldi_att->zero(); + _tmp_saldi_att->put(SLD_GRUPPO,g); + _tmp_saldi_att->put(SLD_CONTO,c); + _tmp_saldi_att->put(SLD_SOTTOCONTO,s); + _tmp_saldi_att->put(SLD_FLAGSALINI,tipo_conto); + + if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) + { + //modifica del 21/11/1995 + if (_datada == _dataini && _tipo_stampa1 == 1) + { + _tmp_saldi_att->put(SLD_PDAREPRO,_saldo_ini_dare); // W96SALDI del 05-06-96 + _tmp_saldi_att->put(SLD_PAVEREPRO,_saldo_ini_avere); + } + else + { + if (saldo_iniziale > ZERO) //va stampato in Dare + _tmp_saldi_att->put(SLD_PDAREPRO,saldo_iniziale); // W96SALDI del 05-06-96 + else if (saldo_iniziale < ZERO) + { + saldo_iniziale = -saldo_iniziale; + _tmp_saldi_att->put(SLD_PAVEREPRO,saldo_iniziale); // W96SALDI del 05-06-96 + } + } + } + else if (_datada > _dataini) + { + _tmp_saldi_att->put(SLD_PDAREPRO,_prg_prec_dare); // W96SALDI del 05-06-96 + _tmp_saldi_att->put(SLD_PAVEREPRO,_prg_prec_avere); + } + _tmp_saldi_att->put(SLD_PDARE,_mov_periodo_dare); + _tmp_saldi_att->put(SLD_PAVERE,_mov_periodo_avere); + _tmp_saldi_att->put(SLD_SALDO,saldo_finale); + _tmp_saldi_att->put(SLD_DATAULMOV,_u_max); + _tmp_saldi_att->write(); + } + _gp = g; + _cp = c; + } + + TRecnotype recnum = _pcn->recno(); + _pcn->next(); + if (_pcn->eof()) + { + if ( (_verifica == 2) && esiste_conto ) + { + //modifica del 21/11/1995 + if (_tipo_stampa1 == 1 && _datada == _dataini) + { + _saldo_ini_gruppo_dare += _saldo_ini_conto_dare; + _saldo_ini_gruppo_avere += _saldo_ini_conto_avere; + } + else + //fine + { + real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; + if (app < ZERO) + _saldo_ini_gruppo_avere += app; + else + _saldo_ini_gruppo_dare += app; + } + mov_gruppo_dare += mov_conto_dare; + mov_gruppo_avere += mov_conto_avere; + prg_gruppo_dare += prg_conto_dare; + prg_gruppo_avere += prg_conto_avere; + saldo_gruppo += saldo_conto; + + scrivi_record_gruppo(prg_gruppo_dare,prg_gruppo_avere, + mov_gruppo_dare,mov_gruppo_avere,saldo_gruppo); + } + if (esiste_sc) + if ( (_verifica == 1)||( (_verifica == 2)&& + (!((_stampav == 2)&&(saldo_conto == 0))) ) ) + scrivi_record_conto(prg_conto_dare,prg_conto_avere,mov_conto_dare, + mov_conto_avere,saldo_conto); + } + _pcn->readat(recnum); + } +return TRUE; +} + +// bilancio di verifica per data limite +// Calcola totali delle righe relative al g,c,s +bool TStampa_bilanci::calcola(int g, int c, long s) +{ + int annoe; + long num_reg; + TDate data_reg, data; + bool conto_mov = FALSE; + + TDecoder causali(LF_CAUSALI, CAU_MOVAP); + + TRelation rel(LF_RMOV); + rel.add(LF_MOV, "NUMREG==NUMREG"); + + TRectype& rmov = rel.curr(); + const TRectype& mov = rel.curr(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; + _u_max = 0l; + + TDate data_start = _dataini; + // Calcolo progressivi precedenti: + // e non è indicato l'anno esercizio, prende il primo giorno dell'anno indicato da _datada + if (_annoes == 0) + { + data_start = _datada; + data_start.set_day(1); + data_start.set_month(1); + } + + rmov.zero(); + rmov.put(RMV_GRUPPO,g); + if (c != 0) + { + rmov.put(RMV_CONTO,c); + if (s != 0) + rmov.put(RMV_SOTTOCONTO,s); + } + + TCursor cur(&rel, "", 2, &rmov, &rmov); + const long items = cur.items(); + cur.freeze(); + + for (cur = 0L; cur.pos() < items; ++cur) + { + annoe = rmov.get_int(RMV_ANNOES); + data = rmov.get_date(RMV_DATAREG); + num_reg = rmov.get_long(RMV_NUMREG); + + const char provvis = mov.get_char(MOV_PROVVIS); + const TDate datacomp = mov.get_date(MOV_DATACOMP); + + if (_stampa_mov_prov == 1 && provvis != '\0') //bilancio normale (non comprende i provvisori) + continue; + + if (_stampa_mov_prov == 3 && provvis == '\0') //bilancio dei soli provvisori + continue; + + const TString& codcaus = mov.get(MOV_CODCAUS); + const char causap = causali.decode(codcaus)[0]; + + if (!_quadratura && causap == 'C') + { + // Si tratta di causale di chiusura: + // Non e' richiesta la quadratura con il Libro Giornale (Modifica + // del 18-06-96 richiesta da Patrizia in seguito alla modifica dei SALDI) + continue; + } + + const char sezione = rmov.get_char(RMV_SEZIONE); + const real importo = rmov.get_real(RMV_IMPORTO); + + if (_annoes == 0) + data_reg = data; + else + data_reg = datacomp; + + if (importo.is_zero()) + continue; + + //calcolo i movimenti del periodo + if ( data_reg >= _datada && data_reg <= _dataa) + if ((causap == 'A' && _dataini.ok() && _dataini != _datada) || (causap != 'A')) + { + conto_mov = TRUE; + if (sezione == 'D') + _mov_periodo_dare += importo; + else + _mov_periodo_avere += importo; + _u_max = fnc_max(_u_max, data); + if (causap == 'A') + _mov_ap = TRUE; + } + + //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 (_datada == _dataini) //calcolo il saldo iniziale + { + if (causap == 'A') + { + if ( (data_reg >= _dataini) && (data_reg <= _dataa) ) + { + if (sezione == 'D') + _saldo_ini_dare += importo; + else + _saldo_ini_avere += importo; + _u_max = fnc_max(_u_max, data); + conto_mov = _mov_ap = TRUE; + } + } + } + else if (_datada > _dataini) //calcolo i progressivi precedenti + if ( (data_reg >= data_start) && (data_reg < _datada) ) + { + if (sezione == 'D') + _prg_prec_dare += importo; + else + _prg_prec_avere += importo; + _u_max = fnc_max(_u_max, data); + conto_mov = TRUE; + if (causap == 'A') + _mov_ap = TRUE; + } + } + return conto_mov; +} + +bool TStampa_bilanci::ricerca_cf(int g,int c,char tipocf,int ib, real& saldo_finale,real& saldo_iniziale, + real& mov_conto_dare,real& mov_conto_avere,real& prg_conto_dare,real& prg_conto_avere,real& saldo_conto) +{ + TSaldo sld; + bool esiste_sc = FALSE; + const int anno = _tipo_stampa1 == 1 ? _annoapp : _annoes; + + _lista = new TSaldi_list(g, c, anno); + const TRecnotype items = _lista->items(); + + for (TRecnotype i = 0; i < items; i++) + { + const TRectype* r = _lista->saldi(); + if (r == NULL) break; + + const long s = r->get_long(SLD_SOTTOCONTO); + + saldo_finale = saldo_iniziale = ZERO; //saldi relativi a ciascun sottoconto + + if (_tipo_stampa1 == 1) //bil. di verifica per data limite + { + //modifica del 21/11/1995 + _mov_ap = FALSE; + //modifica del 19/06. Vedi appunti per capire + bool movimentato = calcola(g,c,s); + + if (_stampa_mov_prov != 3) + { + if (movimentato) + { + if (_mov_ap) + { + saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; + } + else + { + TLocalisamfile saldi(LF_SALDI); + saldi.zero(); + saldi.put(SLD_ANNOES,_annoes); + saldi.put(SLD_FLSCA, FALSE); // W96SALDI del 05-06-96 + saldi.put(SLD_GRUPPO,g); // Ho aggiunto in chiave saldi.put(SLD_FLSCA, FALSE); + saldi.put(SLD_CONTO,c); // in questa maniera reperisco il record dei saldi + saldi.put(SLD_SOTTOCONTO,s); // contenente la somma degli scaricati e non scaricati + if (saldi.read() == NOERR) + { + //se il saldo iniziale e' diverso da zero non lo devo considerare + //perche' l'ho gia' considerato nella funzione calcola + const real ss = saldi.get_real(SLD_SALDO); + if (ss.is_zero()) + { + if (_annoes != 0 && (ib == 1 || ib == 2 || ib == 5)) + { + saldo_iniziale += sld.saldofin_esprec(_annoes,g,c,s,false,_stampa_mov_prov==2); + //modifica del 21/11/1995 + if (saldo_iniziale > ZERO) + _saldo_ini_dare = saldo_iniziale; + else + _saldo_ini_avere = -saldo_iniziale; + //fine + } + } + else + { + const char fsi = saldi.get_char(SLD_FLAGSALINI); + if (fsi == 'D') + { + saldo_iniziale = ss; + _saldo_ini_dare = ss; + } + else + { + saldo_iniziale = -ss; + _saldo_ini_avere = ss; + } + } + } + } + } + else + { + if (_annoes != 0 && (ib == 1 || ib == 2 || ib == 5)) + { + saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s,false,_stampa_mov_prov==2); + //modifica del 21/11/1995 + if (saldo_iniziale > ZERO) + _saldo_ini_dare = saldo_iniziale; + else + _saldo_ini_avere = -saldo_iniziale; + //fine + movimentato = sld.significativo(); + } + } + } + + if (!movimentato) + continue; + //fine modifica + + _nuovo_tot_saldo_d += _mov_periodo_dare; + _nuovo_tot_saldo_a += _mov_periodo_avere; + //modifica del 21/11/1995 + _nuovo_tot_saldo_d += _saldo_ini_dare; + _nuovo_tot_saldo_a += _saldo_ini_avere; + //fine + + if (_datada == _dataini) + saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; + else if (_datada > _dataini) + { + if (saldo_iniziale > 0) + _prg_prec_dare += saldo_iniziale; + else + _prg_prec_avere -= saldo_iniziale; + saldo_finale = _prg_prec_dare-_prg_prec_avere+_mov_periodo_dare- + _mov_periodo_avere; + } + if (saldo_finale == ZERO) + if (_stampav == 2) + continue; + + //se saldo_finale < 0 verra' stampato con una A, se no con una D + } + else // Bilancio di verifica all'ultima immissione + { + //Attenzione! Nel caso di "tutti i conti" devono scendere solo i cli/for movimentati!!! + + //modifica del 31/03/1995 + bool movimentato = sld.ultima_immissione_verifica(_annoes,g,c,s,ib,_stampa_mov_prov); + + if (_stampa_mov_prov != 3) + { + saldo_iniziale = sld.saldoini(); + if (!movimentato) + { + //vado sui saldi con l'anno precedente e calcolo saldo_finale es.prec + //se esiste tale record e almeno un valore e' significativo (indipendentemente dal valore + //del saldo iniziale calcolato, allora metto a TRUE il flag movimentato + //solo se e' un conto patrimoniale + if (ib == 1 || ib == 2 || ib == 5) + { + saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s,false,_stampa_mov_prov==2); + movimentato = sld.significativo(); + } + } + } + + if (!movimentato) + continue; + //fine modifica 31/03/1995 + + _mov_periodo_dare = sld.prgdare(); + _mov_periodo_avere = sld.prgavere(); + _prg_prec_dare = ZERO; + _prg_prec_avere = ZERO; + + if (sld.sezsf() == 'A') + _mov_periodo_avere -= sld.saldofin(); + else + _mov_periodo_dare += sld.saldofin(); + + saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; + if (saldo_finale.is_zero() && _stampav == 2) + continue; + + _nuovo_tot_saldo_d += _mov_periodo_dare; + _nuovo_tot_saldo_a += _mov_periodo_avere; + real nuovo = sld.saldoinisusaldi(); + if (nuovo > ZERO) + _nuovo_tot_saldo_d += nuovo; + else + { + nuovo = -nuovo; + _nuovo_tot_saldo_a += nuovo; + } + } + + esiste_sc = TRUE; + + //modifica del 21/11/1995 + if (_tipo_stampa1 == 1 && _datada == _dataini) + { + _saldo_ini_conto_dare += _saldo_ini_dare; + _saldo_ini_conto_avere += _saldo_ini_avere; + } + else + //fine + { + if (saldo_iniziale < ZERO) + _saldo_ini_conto_avere += saldo_iniziale; + else + _saldo_ini_conto_dare += saldo_iniziale; + } + + mov_conto_dare += _mov_periodo_dare; + mov_conto_avere += _mov_periodo_avere; + prg_conto_dare += _prg_prec_dare; + prg_conto_avere += _prg_prec_avere; + saldo_conto += saldo_finale; // somma algebrica!!! + + //scrivo il record relat. al sottoconto se non e' richiesto saldi di mastro + if (_verifica != 2 && !_hide_clifo) + { + _tmp_saldi_att->zero(); + _tmp_saldi_att->put(SLD_GRUPPO,g); + _tmp_saldi_att->put(SLD_CONTO,c); + _tmp_saldi_att->put(SLD_SOTTOCONTO,s); + _tmp_saldi_att->put(SLD_FLAGSALINI,tipocf); + if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) + { + //modifica del 21/11/1995 + if (_tipo_stampa1 == 1 && _datada == _dataini) + { + _tmp_saldi_att->put(SLD_PDAREPRO,_saldo_ini_dare); // W96SALDI del 05-06-96 + _tmp_saldi_att->put(SLD_PAVEREPRO,_saldo_ini_avere); + } + else + { + if (saldo_iniziale > ZERO) //va stampato in Dare + _tmp_saldi_att->put(SLD_PDAREPRO,saldo_iniziale); // W96SALDI del 05-06-96 + else if (saldo_iniziale < ZERO) + { + saldo_iniziale = -saldo_iniziale; + _tmp_saldi_att->put(SLD_PAVEREPRO,saldo_iniziale); // W96SALDI del 05-06-96 + } + } + } + else if (_datada > _dataini) + { + _tmp_saldi_att->put(SLD_PDAREPRO,_prg_prec_dare); // W96SALDI del 05-06-96 + _tmp_saldi_att->put(SLD_PAVEREPRO,_prg_prec_avere); + } + _tmp_saldi_att->put(SLD_PDARE,_mov_periodo_dare); + _tmp_saldi_att->put(SLD_PAVERE,_mov_periodo_avere); + _tmp_saldi_att->put(SLD_SALDO,saldo_finale); + _tmp_saldi_att->put(SLD_DATAULMOV, _u_max); + + _tmp_saldi_att->write(); + } + } + delete _lista; + return esiste_sc; +} + +void TStampa_bilanci::scrivi_record_gruppo(const real& prg_da, + const real& prg_a,const real& mov_da,const real& mov_a,const real& s) +{ + _tmp_saldi_att->zero(); + _tmp_saldi_att->put(SLD_GRUPPO,_gp); + _tmp_saldi_att->put(SLD_CONTO,0); + _tmp_saldi_att->put(SLD_SOTTOCONTO,0L); + if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) + { + //modifica del 21/11/1995 + if (_datada == _dataini && _tipo_stampa1 == 1) + { + _tmp_saldi_att->put(SLD_PDAREPRO,_saldo_ini_gruppo_dare); // W96SALDI del 05-06-96 + _tmp_saldi_att->put(SLD_PAVEREPRO,_saldo_ini_gruppo_avere); + } + else + { + real app = _saldo_ini_gruppo_dare + _saldo_ini_gruppo_avere; + if (app > ZERO) //va stampato in Dare + _tmp_saldi_att->put(SLD_PDAREPRO,app); // W96SALDI del 05-06-96 + else if (app < ZERO) + { + app = -app; + _tmp_saldi_att->put(SLD_PAVEREPRO,app); // W96SALDI del 05-06-96 + } + } + } + else if (_datada > _dataini) + { + _tmp_saldi_att->put(SLD_PDAREPRO,prg_da); // W96SALDI del 05-06-96 + _tmp_saldi_att->put(SLD_PAVEREPRO,prg_a); + } + _tmp_saldi_att->put(SLD_PDARE,mov_da); + _tmp_saldi_att->put(SLD_PAVERE,mov_a); + _tmp_saldi_att->put(SLD_SALDO,s); + _tmp_saldi_att->write(); +} + +void TStampa_bilanci::scrivi_record_conto(const real& prg_da, const real& prg_a, + const real& mov_da,const real& mov_a, const real& s) +{ + _tmp_saldi_att->zero(); + _tmp_saldi_att->put(SLD_GRUPPO,_gp); + _tmp_saldi_att->put(SLD_CONTO,_cp); + _tmp_saldi_att->put(SLD_SOTTOCONTO,0L); + if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) + { + //modifica del 21/11/1995 + if (_datada == _dataini && _tipo_stampa1 == 1) + { + _tmp_saldi_att->put(SLD_PDAREPRO,_saldo_ini_conto_dare); // W96SALDI del 05-06-96 + _tmp_saldi_att->put(SLD_PAVEREPRO,_saldo_ini_conto_avere); + } + else + { + real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; + if (app > ZERO) //va stampato in Dare + _tmp_saldi_att->put(SLD_PDAREPRO,app); // W96SALDI del 05-06-96 + else if (app < ZERO) + { + app = -app; + _tmp_saldi_att->put(SLD_PAVEREPRO,app); // W96SALDI del 05-06-96 + } + } + } + else if (_datada > _dataini) + { + _tmp_saldi_att->put(SLD_PDAREPRO,prg_da); // W96SALDI del 05-06-96 + _tmp_saldi_att->put(SLD_PAVEREPRO,prg_a); + } + _tmp_saldi_att->put(SLD_PDARE,mov_da); + _tmp_saldi_att->put(SLD_PAVERE,mov_a); + _tmp_saldi_att->put(SLD_SALDO,s); + _tmp_saldi_att->write(); +} + +void TStampa_bilanci::init_sort() +{ + cli_for cf; + + _sort = new TSort(sizeof(cli_for)); + _sort->addsortkey ((char*)&(cf.tipocf)-(char*)&(cf.tipocf),1); + _sort->addsortkey ((char*)&(cf.gruppo)-(char*)&(cf.tipocf),3); + _sort->addsortkey ((char*)&(cf.conto)-(char*)&(cf.tipocf),3); + if (_ordinamento == 1) + _sort->addsortkey ((char*)&(cf.codcf)-(char*)&(cf.tipocf),6); + else if (_ordinamento == 2) + _sort->addsortkey ((char*)&(cf.ragsoc)-(char*)&(cf.tipocf),50); + + _sort->init(); +} + +void TStampa_bilanci::riempi_record(char t,int g,int c,long s, + const char* rs,const real& sd,const real& sa, + const real& md,const real& ma,const real& sf) +{ + cli_for cf; + cf.tipocf = t; + sprintf(cf.gruppo, "%03d", g); + sprintf(cf.conto, "%03d", c); + sprintf(cf.codcf, "%06ld", s); + sprintf(cf.ragsoc, "%s", rs); + if ( s == 999999L ) + { + if ( (_datada == _dataini)||(_tipo_stampa1 != 1) ) + { + //modifica del 21/11/1995 + if (_tipo_stampa1 == 1 && _datada == _dataini) + { + cf.saldodare = _saldo_ini_conto_dare; + cf.saldoavere = _saldo_ini_conto_avere; + } + else + //fine + { + real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; + if (app > ZERO) //va stampato in Dare + { + cf.saldoavere = ZERO; + cf.saldodare = app; + } + else if (app < ZERO) + { + app = -app; + cf.saldodare = ZERO; + cf.saldoavere = app; + } + } + } + else if (_datada > _dataini) + { + cf.saldodare = sd; + cf.saldoavere = sa; + } + } + else + { + cf.saldodare = sd; + cf.saldoavere = sa; + } + cf.movdare = md; + cf.movavere = ma; + cf.saldofinale = sf; + cf.udata = _u_max; + _sort->sort((const char*)&cf); +} + +void TStampa_bilanci::leggi_clifo(const TArray& gccf) +{ + TEsercizi_contabili ese; + + TSaldo sld; + TLocalisamfile saldi(LF_SALDI); +// int g = 0, c=0; + long codcf=0l; + TString80 ragsoc; + char tipocf,tipocfp,tipoa; + real saldo_finale, saldo_conto, saldo_iniziale, saldodare, saldoavere, + movdare, movavere; + real mov_conto_dare, mov_conto_avere, prg_conto_dare, prg_conto_avere; + bool esiste_sc = FALSE, movimentato = FALSE; + TRecnotype items = _cur->items(); + + _gp=-1; + _cp=-1; + tipocfp = ' '; + + _saldo_ini_conto_dare = ZERO; + _saldo_ini_conto_avere = ZERO; + saldo_conto = ZERO; + mov_conto_dare = ZERO; + mov_conto_avere = ZERO; + prg_conto_dare = ZERO; + prg_conto_avere = ZERO; + _u_max = 0l; + + const int anno = _tipo_stampa1 == 1 ? _annoapp : _annoes; + for (int i=0; i < gccf.items(); i++) + { + int g = ((TToken_string&)gccf[i]).get_int(0); + int c = ((TToken_string&)gccf[i]).get_int(1); + + *_cur = 0l; + for (int i = 0; i < items; i++,++(*_cur)) + { + _prog->addstatus(1); + codcf = _cur->curr().get_long(CLI_CODCF); + tipocf = _cur->curr().get(CLI_TIPOCF)[0]; + ragsoc = _cur->curr().get(CLI_RAGSOC); + tipoa = _cur->curr().get_char(CLI_TIPOAPER); + if (tipoa == 'F') //persona fisica + { + TString80 cognome, nome; + cognome = ragsoc.mid(0,30); + nome = ragsoc.mid(30,20); + cognome.trim(); nome.trim(); + ragsoc = cognome; + ragsoc << ' ' << nome; + } + + int aprec = ese.pred(anno); + saldi.zero(); + saldi.put(SLD_ANNOES, anno); // W96SALDI del 05-06-96 + saldi.put(SLD_FLSCA, FALSE); + saldi.put(SLD_GRUPPO, g); + saldi.put(SLD_CONTO, c); + saldi.put(SLD_SOTTOCONTO, codcf); + if (saldi.read() != NOERR) + { + //if (_tipo_stampa1 == 1) //bilancio per data limite + // continue; + //else + if (_stampac == 2) //se sono richiesti i conti movimentati + { //esco, se no... + _indbil = cerca_indbil(g,c); + if (_indbil == 1 || _indbil == 2 || _indbil == 5) + { + saldi.zero(); + saldi.put(SLD_ANNOES, aprec); // W96SALDI del 05-06-96 + saldi.put(SLD_FLSCA, FALSE); + saldi.put(SLD_GRUPPO, g); + saldi.put(SLD_CONTO, c); + saldi.put(SLD_SOTTOCONTO, codcf); + if (saldi.read() != NOERR) + continue; + } + } + } + if ( (((_cp != -1) && (c != _cp)) || ((_gp != -1) && (g != _gp))) && + esiste_sc ) + { + //scrivo il record del conto; + riempi_record(tipocfp,_gp,_cp,999999L,"zzzz",prg_conto_dare, + prg_conto_avere,mov_conto_dare,mov_conto_avere,saldo_conto); + tipocfp = tipocf; + _cp = c; + esiste_sc = FALSE; + _saldo_ini_conto_dare = ZERO; + _saldo_ini_conto_avere = ZERO; + saldo_conto = ZERO; + mov_conto_dare = ZERO; + mov_conto_avere = ZERO; + prg_conto_dare = ZERO; + prg_conto_avere = ZERO; + } + + saldo_finale = ZERO; + saldodare = ZERO; + saldoavere = ZERO; + movdare = ZERO; + movavere = ZERO; + saldo_iniziale = ZERO; + + if (_tipo_stampa1 == 1) //bilancio di verifica per data limite + { + //modifica del 21/11/1995 + _mov_ap = FALSE; + + //modifica del 19/06/95 + _indbil = cerca_indbil(g,c); + movimentato = calcola(g,c,codcf); + if (_stampa_mov_prov != 3) + if (!movimentato) + if (_indbil == 1 || _indbil == 2 || _indbil == 5) + if (_annoes != 0) //cioe' se sto ragionando per competenza + { + saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,codcf,false,_stampa_mov_prov==2); + if (saldo_iniziale > ZERO) + _saldo_ini_dare = saldo_iniziale; + else _saldo_ini_avere = -saldo_iniziale; + } + + if (movimentato) + { + //modifica del 21/11/1995 + if (_mov_ap) + saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; + else + { + TLocalisamfile saldi(LF_SALDI); + saldi.zero(); + saldi.put(SLD_ANNOES, _annoes); // W96SALDI del 05-06-96 + saldi.put(SLD_FLSCA, FALSE); + saldi.put(SLD_GRUPPO, g); + saldi.put(SLD_CONTO, c); + saldi.put(SLD_SOTTOCONTO, codcf); + if (saldi.read() == NOERR) + { + const real s = saldi.get_real(SLD_SALDO); + if (_stampa_mov_prov != 3) + if (_indbil == 1 || _indbil == 2 || _indbil == 5) + if (s.is_zero() && _annoes != 0) //competenza!!! + { + saldo_iniziale += sld.saldofin_esprec(_annoes,g,c,codcf,false,_stampa_mov_prov==2); + //modifica del 21/11/1995 + if (saldo_iniziale > ZERO) + _saldo_ini_dare = saldo_iniziale; + else _saldo_ini_avere = -saldo_iniziale; + //fine + } + } + } + } + //fine modifica del 19/06/95 + //movimentato = calcola(g,c,codcf); + if (movimentato || _stampac != 1 || saldo_iniziale != ZERO) + { + if (_datada == _dataini) + saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; + else if (_datada > _dataini) + { + //modifica del 19/06 + if (saldo_iniziale > 0) + _prg_prec_dare += saldo_iniziale; + else _prg_prec_avere -= saldo_iniziale; + //fine modifica + saldo_finale = _prg_prec_dare-_prg_prec_avere+_mov_periodo_dare + -_mov_periodo_avere; + } + } + + //se saldo_finale < 0 verra' stampato con una A, se no con una D + } + else //bilancio di verifica all'ultima immissione + { + _indbil = cerca_indbil(g,c); + movimentato = sld.ultima_immissione_verifica(anno,g,c,codcf,_indbil,_stampa_mov_prov); + + if (_stampa_mov_prov != 3) + if (!movimentato /* && _stampac!=1 */ ) + if (_indbil == 1 || _indbil == 2 || _indbil == 5) + saldo_iniziale = sld.saldofin_esprec(anno,g,c,codcf,false,_stampa_mov_prov==2); + + if (movimentato) + saldo_iniziale = sld.saldoini(); + + if (movimentato || _stampac != 1 || saldo_iniziale != ZERO) + { + _mov_periodo_dare = sld.prgdare(); + _mov_periodo_avere = sld.prgavere(); + _prg_prec_dare = ZERO; + _prg_prec_avere = ZERO; + + if (sld.sezsf() == 'A') + _mov_periodo_avere -= sld.saldofin(); + else + _mov_periodo_dare += sld.saldofin(); + + saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; + } + } + if (movimentato || _stampac != 1 || saldo_iniziale != ZERO) + if (!(saldo_finale.is_zero() && _stampac == 2)) + { + esiste_sc = TRUE; + + //modifica del 21/11/1995 + if (_tipo_stampa1 == 1 && _datada == _dataini) + { + _saldo_ini_conto_dare += _saldo_ini_dare; + _saldo_ini_conto_avere += _saldo_ini_avere; + } + else + { + if (saldo_iniziale < ZERO) + _saldo_ini_conto_avere += saldo_iniziale; + else + _saldo_ini_conto_dare += saldo_iniziale; + } + //fine + + mov_conto_dare += _mov_periodo_dare; + mov_conto_avere += _mov_periodo_avere; + prg_conto_dare += _prg_prec_dare; + prg_conto_avere += _prg_prec_avere; + saldo_conto += saldo_finale; // somma algebrica!!! + + if ( (_datada == _dataini)||(_tipo_stampa1 != 1) ) + { + //modifica del 21/11/1995 + if (_tipo_stampa1 == 1 && _datada == _dataini) + { + saldodare = _saldo_ini_dare; + saldoavere = _saldo_ini_avere; + } + else + // + { + if (saldo_iniziale > ZERO) //va stampato in Dare + saldodare = saldo_iniziale; + else if (saldo_iniziale < ZERO) + { + saldo_iniziale = -saldo_iniziale; + saldoavere = saldo_iniziale; + } + } + } + else if (_datada > _dataini) + { + saldodare = _prg_prec_dare; + saldoavere = _prg_prec_avere; + } + + movdare = _mov_periodo_dare; + movavere = _mov_periodo_avere; + + riempi_record(tipocf,g,c,codcf,ragsoc,saldodare,saldoavere,movdare, + movavere,saldo_finale); + tipocfp = tipocf; + _gp = g; + _cp = c; + } + } + } + if (esiste_sc) + riempi_record(tipocfp,_gp,_cp,999999L,"zzzz",prg_conto_dare,prg_conto_avere, + mov_conto_dare,mov_conto_avere,saldo_conto); +} + +void TStampa_bilanci::crea_sort_clifo() +{ + long ncur = _cur->items(); + //serve solo per la progind: stima alla meno peggio + if (_situazione.empty()) ncur /= 2; + long nitems = ncur*(_clienti.items()+_fornitori.items()); + _prog = new TProgress_monitor(nitems,TR("Elaborazione clienti/fornitori"),false); + _prog->addstatus(1); + init_sort(); + if (_situazione == "C") leggi_clifo(_clienti); + else if (_situazione == "F") leggi_clifo(_fornitori); + else + { + _cur->setfilter("TIPOCF = \"C\""); + leggi_clifo(_clienti); + _cur->setfilter("TIPOCF = \"F\""); + leggi_clifo(_fornitori); + } +} + +int TStampa_bilanci::cerca_indbil(int g, int c) +{ +/* + TLocalisamfile pconti(LF_PCON); + pconti.zero(); + pconti.put(PCN_GRUPPO,g); + if (c != 0) + pconti.put(PCN_CONTO,c); + pconti.put(PCN_SOTTOCONTO,0l); + + pconti.read(); + return pconti.get_int(PCN_INDBIL); +*/ + TString8 key; key.format("%d|%d", g, c); + const int indbil = atoi(cache().get(LF_PCON, key, PCN_INDBIL)); + CHECKD(indbil > 0, "Indicatore di bilancio strano: ", indbil); + return indbil; + +} + +void TStampa_bilanci::leggi_files_dare(TIsamtempfile* file) +{ + _gruppo_dare = file->get_int(SLD_GRUPPO); + _conto_dare = file->get_int(SLD_CONTO); + _sottoconto_dare = file->get_long(SLD_SOTTOCONTO); + _saldo_dare = file->get_real(SLD_PDARE); + + _descr_dare = DescrizioneConto(_gruppo_dare,_conto_dare,_sottoconto_dare,' '); + + _gc_corr_dare = format("%3d%3d", _gruppo_dare, _conto_dare); + + if (_gc_corr_dare != _gc_prec_dare) + { + _cambiato_conto_1 = TRUE; + _gc_prec_dare = _gc_corr_dare; + } + else if (_sottoconto_dare != 0l) + _cambiato_conto_1 = FALSE; +} + +void TStampa_bilanci::leggi_files_avere(TIsamtempfile* file) +{ + _gruppo_avere = file->get_int(SLD_GRUPPO); + _conto_avere = file->get_int(SLD_CONTO); + _sottoconto_avere = file->get_long(SLD_SOTTOCONTO); + _saldo_avere = file->get_real(SLD_PAVERE); + + _descr_avere = DescrizioneConto(_gruppo_avere,_conto_avere,_sottoconto_avere, + ' '); + _gc_corr_avere = format("%3d%3d", _gruppo_avere, _conto_avere); + + if (_gc_corr_avere != _gc_prec_avere) + { + _cambiato_conto_2 = TRUE; + _gc_prec_avere = _gc_corr_avere; + } + else if (_sottoconto_avere != 0l) + _cambiato_conto_2 = FALSE; +} + +#define TOTAL_PICTURE "###.###.###.###.###" + +HIDDEN void total2string(const real& tot, TString& str) +{ + TCurrency cur(tot); + str = cur.string(TRUE); + str.right_just(strlen(TOTAL_PICTURE)); +} + +bool TStampa_bilanci::preprocess_print(int file, int counter) +{ + if (_bilancio == 1) + { + set_real_picture ("##.###.###.###.###"); + set_print_zero(); + _tmp_saldi_att->setkey(2); + _tmp_saldi_pass->setkey(2); + _tmp_saldi_costi->setkey(2); + _tmp_saldi_ricavi->setkey(2); + _tmp_saldi_conti_uno->setkey(2); + _tmp_saldi_conti_due->setkey(2); + _gc_prec_avere = ""; + _prima_volta = _seconda_volta = TRUE; + _flag = _controlla = FALSE; + _salto_pagina = _salto_pagina1 = _stampato = FALSE; + _cambiato_conto_1 = TRUE; + _cambiato_conto_2 = TRUE; + _tot_dare = ZERO; + _tot_avere = ZERO; + } + else + { + if (_noseparator) + set_real_picture ("################"); + else + set_real_picture ("####.###.###.###"); + + set_print_zero(FALSE); + _cambiato_conto_1 = FALSE; + _livello_conto = TRUE; + _saldo_dare_tot = ZERO; + _saldo_avere_tot = ZERO; + _mov_dare_tot = ZERO; + _mov_avere_tot = ZERO; + _saldo_finale_tot = ZERO; + } + set_magic_currency(TRUE); + return TRUE; +} + +void TStampa_bilanci::leggi_file_tmp() +{ + if (_livello_conto) // era meglio chiamarla _livello_conto_oppure_gruppo, perche' nel caso dei saldi di mastro _livello_conto==TRUE <=> si tratta di un gruppo, mentre nel caso del bilancio _livello_conto==TRUE <=> si tratta di un conto + { + _gruppo = _tmp_saldi_att->get_int(SLD_GRUPPO); + _conto = _tmp_saldi_att->get_int(SLD_CONTO); + _sottoconto = _tmp_saldi_att->get_long(SLD_SOTTOCONTO); + _tipo_conto = _tmp_saldi_att->get_char(SLD_FLAGSALINI); + _descr = DescrizioneConto(_gruppo,_conto,_sottoconto,_tipo_conto); + _saldoini_dare = _tmp_saldi_att->get_real(SLD_PDAREPRO); // W96SALDI del 05-06-96 + _saldoini_avere = _tmp_saldi_att->get_real(SLD_PAVEREPRO); + _mov_dare = _tmp_saldi_att->get_real(SLD_PDARE); + _mov_avere = _tmp_saldi_att->get_real(SLD_PAVERE); + _saldofinale = _tmp_saldi_att->get_real(SLD_SALDO); + } + _eof1 = _tmp_saldi_att->next(); + if (!_eof1) + { + _gruppo_succ = _tmp_saldi_att->get_int(SLD_GRUPPO); + _conto_succ = _tmp_saldi_att->get_int(SLD_CONTO); + _sottoconto_succ = _tmp_saldi_att->get_long(SLD_SOTTOCONTO); + _tipoc_succ = _tmp_saldi_att->get_char(SLD_FLAGSALINI); + if ( (_verifica != 2) && (_sottoconto_succ != 0) ) + { + if (_tipo_stampa1 == 2) + _ultima_data = UltimaData(_gruppo_succ,_conto_succ, _sottoconto_succ,_annoes); + else + _ultima_data = _tmp_saldi_att->get_date(SLD_DATAULMOV); + } + _descr_succ = DescrizioneConto(_gruppo_succ,_conto_succ, + _sottoconto_succ,_tipoc_succ); + _saldoini_dare_succ = _tmp_saldi_att->get_real(SLD_PDAREPRO); // W96SALDI del 05-06-96 + _saldoini_avere_succ = _tmp_saldi_att->get_real(SLD_PAVEREPRO); + _mov_dare_succ = _tmp_saldi_att->get_real(SLD_PDARE); + _mov_avere_succ = _tmp_saldi_att->get_real(SLD_PAVERE); + _saldofinale_succ = _tmp_saldi_att->get_real(SLD_SALDO); + _livello_conto = FALSE; + if ( ((_verifica != 2)&&(_sottoconto_succ == 0)) || + ((_verifica == 2)&&(_conto_succ == 0)) ) + { + _livello_conto = TRUE; + _gruppo_succ = _gruppo; + _conto_succ = _conto; + _sottoconto_succ = _sottoconto; + _descr_succ = _descr; + _saldoini_dare_succ = _saldoini_dare; + _saldoini_avere_succ = _saldoini_avere; + _mov_dare_succ = _mov_dare; + _mov_avere_succ = _mov_avere; + _saldofinale_succ = _saldofinale; + } + } +} + +bool TStampa_bilanci::preprocess_page(int file, int counter) +{ + reset_print(); + + if (_bilancio == 1) //stampa bilancio a sez. contrapposte + { + if (counter) + { + if ( (!_eof1) && (_cambiato_conto_1) ) + _eof1 = _tmp_saldi_att->next(); + + if ( (!_eof2) && (_cambiato_conto_2) ) + _eof2 = _tmp_saldi_pass->next(); + + if (_eof1 && _eof2) + { + if (_prima_volta) + { + stampa_totali_uno(_prg_saldoini_dare,_prg_saldoini_avere); + _eof3 = _tmp_saldi_costi->first(); + _eof4 = _tmp_saldi_ricavi->first(); + } + else + { + _controlla = TRUE; + + if (_salto_pagina) + { + if ( (!_eof3) && (_cambiato_conto_1) ) + _eof3 = _tmp_saldi_costi->next(); + + if ( (!_eof4) && (_cambiato_conto_2) ) + _eof4 = _tmp_saldi_ricavi->next(); + } + } + + if ( (!_eof3) && (_cambiato_conto_1) ) + leggi_files_dare(_tmp_saldi_costi); + + if ( (!_eof4) && (_cambiato_conto_2) ) + leggi_files_avere(_tmp_saldi_ricavi); + + if (_eof3 && _eof4 && _salto_pagina) + { + if (_seconda_volta) + { + stampa_totali(); + _eof5 = _tmp_saldi_conti_uno->first(); + _eof6 = _tmp_saldi_conti_due->first(); + } + else + { + _flag = TRUE; + + if (_salto_pagina1) + { + if ( (!_eof5) && (_cambiato_conto_1) ) + _eof5 = _tmp_saldi_conti_uno->next(); + + if ( (!_eof6) && (_cambiato_conto_2) ) + _eof6 = _tmp_saldi_conti_due->next(); + } + } + + if ( (!_eof5) && (_cambiato_conto_1) ) + leggi_files_dare(_tmp_saldi_conti_uno); + + if ( (!_eof6) && (_cambiato_conto_2) ) + leggi_files_avere(_tmp_saldi_conti_due); + } + } + } + else //counter = 0 + { + _gc_prec_dare = _gc_corr_avere = ""; + _eof1 = _tmp_saldi_att->first(); + _eof2 = _tmp_saldi_pass->first(); + } + + if ( (!_eof1) && (_cambiato_conto_1) ) + leggi_files_dare(_tmp_saldi_att); + + if ( (!_eof2) && (_cambiato_conto_2) ) + leggi_files_avere(_tmp_saldi_pass); + } + else //stampa bilancio di verifica + { + if (_verifica == 3) + leggi_sort(); + else + { + if (counter) + { + if (!_eof1) + leggi_file_tmp(); + } + else + { + _eof1 = _tmp_saldi_att->first(); + if (_eof1) + return FALSE; + else + leggi_file_tmp(); + } + } + } + return TRUE; +} + +void TStampa_bilanci::leggi_sort() +{ + _buff = _sort->retrieve(); + if (_buff != NULL) + { + struct cli_for* cf = (struct cli_for*)_buff; + _tipo_conto = cf->tipocf; + _gruppo = atoi(cf->gruppo); + _conto = atoi(cf->conto); + _sottoconto = atol(cf->codcf); + _descr = cf->ragsoc; + if ( (_ordinamento == 2 && _descr != "zzzz") || (_ordinamento == 1 && _sottoconto != 999999L) ) + { + if (_tipo_stampa1 == 2) + _ultima_data = UltimaData(_gruppo,_conto,_sottoconto,_annoes); + else + _ultima_data = cf->udata; + } + _saldo_dare = cf->saldodare; + _saldo_avere = cf->saldoavere; + _mov_dare = cf->movdare; + _mov_avere = cf->movavere; + _saldofinale = cf->saldofinale; + } +} + +void TStampa_bilanci::controlla_conto(int file1,int file2) +{ + if (!file1) + if (_cambiato_conto_1) + { + set_row(_i,"@67g*"); + _cambiato_conto_1 = FALSE; + } + else + { + stampa_prima_colonna(_gruppo_dare, _conto_dare, _sottoconto_dare, + _descr_dare,_saldo_dare); + _cambiato_conto_1 = TRUE; + if (!_totali) + if ( (_conto_dare == 0) && (_sottoconto_dare == 0) ) + _tot_dare += _saldo_dare; + if (_totali) + if (_sottoconto_dare == 0) + _tot_dare += _saldo_dare; + } + + if (!file2) + if (_cambiato_conto_2) + { + set_row(_i,"@67g*"); + _cambiato_conto_2 = FALSE; + } + else + { + stampa_seconda_colonna(_gruppo_avere, _conto_avere, _sottoconto_avere, + _descr_avere, _saldo_avere); + _cambiato_conto_2 = TRUE; + if (!_totali) + if ( (_conto_avere == 0) && (_sottoconto_avere == 0) ) + _tot_avere += _saldo_avere; + if (_totali) + if (_sottoconto_avere == 0) + _tot_avere += _saldo_avere; + } +} + +void TStampa_bilanci::postclose_print() +{ + if (_bilancio == 1) + { + delete _tmp_saldi_att; _tmp_saldi_att = NULL; + delete _tmp_saldi_pass; _tmp_saldi_pass = NULL; + delete _tmp_saldi_costi; _tmp_saldi_costi = NULL; + delete _tmp_saldi_ricavi; _tmp_saldi_ricavi = NULL; + delete _tmp_saldi_conti_uno; _tmp_saldi_conti_uno = NULL; + delete _tmp_saldi_conti_due; _tmp_saldi_conti_due = NULL; + } + else + { + if (_verifica == 3) + { + delete _sort; _sort = NULL; + } + else + { + delete _tmp_saldi_att; _tmp_saldi_att = NULL; + } + } +} + +void TStampa_bilanci::set_page(int file, int counter) +{ + const TString16 dep; + + if (_bilancio == 1) //stampa bilancio a sezioni contrapposte + { + _i = 1; + + if (!counter) + { + set_row(_i++,FR("@29gATTIVITA'@98gPASSIVITA'")); + set_row(_i++,"@29g---------@98g----------"); + set_row(_i++, dep); + } + + controlla_conto(_eof1,_eof2); //stampo una riga vuota tra un gruppo e un conto altrimenti no + + if ( _eof1 && _eof2 && (!_prima_volta) && _controlla ) + if (!_salto_pagina) + { + printer().formfeed(); + set_row(_i++,FR("@29gCOSTI@98gRICAVI")); + set_row(_i++,"@29g-----@98g------"); + set_row(_i++, dep); + _salto_pagina = TRUE; + + } + + if (_eof1 && _eof2 && _controlla) + { + controlla_conto(_eof3,_eof4); + + if ( _eof3 && _eof4 && (!_seconda_volta) && _flag ) + if (!_salto_pagina1) + { + if (!_tmp_saldi_conti_uno->empty() || !_tmp_saldi_conti_due->empty()) + { + printer().formfeed(); + set_row(_i++,FR("@59gCONTI D'ORDINE")); + set_row(_i++,"@59g--------------"); + set_row(_i++, dep); + if (_eof5 && _eof6) + { + _stampato = TRUE; + stampa_totali_uno(_prg_inidare_ord,_prg_iniavere_ord); + } + } + _salto_pagina1 = TRUE; + } + + if (_eof3 && _eof4 && _flag) + { + if (!_tmp_saldi_conti_uno->empty() || !_tmp_saldi_conti_due->empty()) + { + controlla_conto(_eof5,_eof6); + if (_eof5 && _eof6) + if (!_stampato) + stampa_totali_uno(_prg_inidare_ord,_prg_iniavere_ord); + } + } + } + } + else //stampa bilancio di verifica + { + const TString16 udata = _ultima_data.string(brief,'/'); + char app; + int r = 1; + + if (_verifica == 3) + { + if (_buff != NULL) + { + *_d = (const char*) _descr; + if (_saldofinale > 0) + app = 'D'; + else if (_saldofinale < 0) + { + _saldofinale = -_saldofinale; + app = 'A'; + } + if ( (_ordinamento == 2 && _descr == "zzzz") || + (_ordinamento == 1 && _sottoconto == 999999L) ) //devo stampare il conto + { + _descr = DescrizioneConto(_gruppo,_conto,0L,' '); + stampa_record_conto(_gruppo,_conto,_descr,_saldo_dare,_saldo_avere, + _mov_dare,_mov_avere,_saldofinale,app); + } + else + { + if (_stampa_width == 132) + { + set_row(r,"@1g%6ld", _sottoconto); + if ((_saldo_dare != ZERO) || (_saldo_avere != ZERO) || (_mov_dare != ZERO) || + (_mov_avere != ZERO) || (_saldofinale != ZERO)) + set_row(r," %s",(const char*)udata); + set_row(r,"@17g#a@46g!%r@64g%r@80g!%r@98g%r@114g!@115g%r",_d,&_saldo_dare, + &_saldo_avere,&_mov_dare,&_mov_avere,&_saldofinale); + if (_saldofinale != ZERO) + set_row(r,"@131g%c", app); + if (_descr.len() > 30) + set_row(++r, "@46g!@80g!@114g!"); + } + else if (app == 'D') + { + set_row(r,"@1g%6ld", _sottoconto); + if ((_saldo_dare != ZERO) || (_saldo_avere != ZERO) || (_mov_dare != ZERO) || + (_mov_avere != ZERO) || (_saldofinale != ZERO)) + set_row(r," %s",(const char*)udata); + set_row(r,"@17g#a@46g!%r@64g%r@80g!%r@98g%r@114g!%r@148g!",_d, + &_saldo_dare,&_saldo_avere,&_mov_dare,&_mov_avere,&_saldofinale); + if (_descr.len() > 30) + set_row(++r, "@46g!@80g!@114g!@148g!"); + } + else + { + set_row(r,"@1g%6ld", _sottoconto); + if ((_saldo_dare != ZERO) || (_saldo_avere != ZERO) || (_mov_dare != ZERO) || + (_mov_avere != ZERO) || (_saldofinale != ZERO)) + set_row(r," %s",(const char*)udata); + set_row(r,"@17g#a@46g!%r@64g%r@80g!%r@100g%r@114g!@132g%r@148g!", + _d,&_saldo_dare,&_saldo_avere,&_mov_dare,&_mov_avere,&_saldofinale); + if (_descr.len() > 30) + set_row(++r, "@46g!@80g!@114g!@148g!"); + } + } + } + } + else //_verifica != 3 + { + if (!_eof1) + { + if (_saldofinale_succ >= ZERO) + app = 'D'; + else + { + _saldofinale_succ = -_saldofinale_succ; + app = 'A'; + } + + if (_livello_conto) //sto stampando un conto/gruppo + r = stampa_record_conto(_gruppo_succ,_conto_succ,_descr_succ, + _saldoini_dare_succ,_saldoini_avere_succ,_mov_dare_succ, + _mov_avere_succ,_saldofinale_succ,app); + + else //sto stampando un sottoconto/conto + { + if (_verifica == 2) + { + if (_stampa_width == 132) + { + set_row(r,"%3d",_conto_succ); + set_row(r," @8g%-.40s@46g!%r@64g%r@80g!%r@98g%r@114g!@115g%r", + (const char*)_descr_succ,&_saldoini_dare_succ,&_saldoini_avere_succ, + &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); + if (_saldofinale_succ != ZERO) + set_row(r,"@131g%c", app); + } + else if (app == 'D') + { + set_row(r,"%3d",_conto_succ); + set_row(r," @8g%-.40s@46g!%r@64g%r@80g!%r@98g%r@114g!%r@148g!", + (const char*)_descr_succ,&_saldoini_dare_succ,&_saldoini_avere_succ, + &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); + } + else + { + set_row(r,"%3d",_conto_succ); + set_row(r," @8g%-.40s@46g!%r@64g%r@80g!%r@98g%r@114g!@132g%r@148g!", + (const char*)_descr_succ,&_saldoini_dare_succ,&_saldoini_avere_succ, + &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); + } + } // _verifica != 2 + else + { + *_d = (const char*) _descr_succ; + if (_print_full_code) + set_row(r,"@1g%3d %3d %6ld", _gruppo_succ, _conto_succ, _sottoconto_succ); + else + { + set_row(r,"@1g%6ld", _sottoconto_succ); + if ((_saldoini_dare_succ != ZERO) || (_saldoini_avere_succ != ZERO) || + (_mov_dare_succ != ZERO) || (_mov_avere_succ != ZERO) || + (_saldofinale_succ != ZERO)) + set_row(r," %s",(const char*)udata); + } + + if (_stampa_width == 132) + { +// set_row(r,"@1g%6ld",(const char*)_sottoconto_succ); +// if ((_saldoini_dare_succ != ZERO) || (_saldoini_avere_succ != ZERO) || +// (_mov_dare_succ != ZERO) || (_mov_avere_succ != ZERO) || +// (_saldofinale_succ != ZERO)) +// set_row(r," %s",(const char*)udata); + set_row(r,"@17g#a@46g!%r@64g%r@80g!%r@98g%r@114g!@115g%r", + _d,&_saldoini_dare_succ,&_saldoini_avere_succ, + &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); + if (_saldofinale_succ != ZERO) + set_row(r,"@131g%c", app); + if (_descr_succ.len() > 30) + set_row(++r, "@46g!@80g!@114g!"); + } + else // Stampa estesa + { +// set_row(r,"@1g%6ld",(const char*)_sottoconto_succ); +// if ((_saldoini_dare_succ != ZERO) || (_saldoini_avere_succ != ZERO) || +// (_mov_dare_succ != ZERO) || (_mov_avere_succ != ZERO) || +// (_saldofinale_succ != ZERO)) +// set_row(r," %s",(const char*)udata); + if (app == 'D') + { + set_row(r,"@17g#a@46g!%r@64g%r@80g!%r@98g%r@114g!%r@148g!", + _d,&_saldoini_dare_succ,&_saldoini_avere_succ, + &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); + } + else + { + set_row(r,"@17g#a@46g!%r@64g%r@80g!%r@98g%r@114g!@132g%r@148g!", + _d,&_saldoini_dare_succ,&_saldoini_avere_succ, + &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); + } + if (_descr_succ.len() > 30) + set_row(++r, "@46g!@80g!@114g!@148g!"); + } + } + } + } + else + { + if (_saldofinale >= ZERO) + app = 'D'; + else + { + app = 'A'; + _saldofinale = -_saldofinale; + } + r = stampa_record_conto(_gruppo,_conto,_descr,_saldoini_dare, + _saldoini_avere,_mov_dare,_mov_avere,_saldofinale,app);//per stampare l'ultimo conto + + stampa_riga_totali(r); + } + } + } +} + +int TStampa_bilanci::stampa_record_conto(int g,int c,const TString& d, + const real& r1,const real& r2,const real& r3,const real& r4,const real& r5, + const char app) +{ + int r = 1; + + if (_stampa_width != 132) + set_row(r,"@46g!@80g!@114g!@148g!"); //stampo una riga vuota + else + set_row(r,"@46g!@80g!@114g!"); //stampo una riga vuota + r++; + if (_verifica == 2) + { + if (_stampa_width == 132) + { + set_row(r,"%3d-",g); + set_row(r,"@8g%-.40s",(const char*)d); + set_row(r,"@46g!%r@64g%r@80g!%r@98g%r@114g!@115g%r",&r1,&r2,&r3,&r4,&r5); + if (r5 != ZERO) + set_row(r,"@131g%c", app); + r++; + } + else + if (app == 'D') + { + set_row(r,"%3d-",g); + set_row(r,"@8g%-.40s",(const char*)d); + set_row(r++,"@46g!%r@64g%r@80g!%r@98g%r@114g!%r@148g!",&r1,&r2,&r3,&r4,&r5); + } + else + { + set_row(r,"%3d-",g); + set_row(r,"@8g%-.40s",(const char*)d); + set_row(r++,"@46g!%r@64g%r@80g!%r@98g%r@114g!@132g%r@148g!",&r1,&r2,&r3,&r4,&r5); + } + } + else + { + *_d = (const char*) d; + + if (_stampa_width == 132) + { + set_row(r,"%3d-",g); + set_row(r,"%3d ********",c); + set_row(r,"@17g#a",_d); + set_row(r,"@46g!%r@64g%r@80g!%r@98g%r@114g!@115g%r",&r1,&r2,&r3,&r4,&r5); + if (r5 != ZERO) + set_row(r,"@131g%c", app); + r++; + if (d.len() > 30) + set_row(r+1, "@46g!@80g!@114g!"); + } + else if (app == 'D') + { + set_row(r,"%3d-",g); + set_row(r,"%3d ********",c); + set_row(r,"@17g#a",_d); + set_row(r++,"@46g!%r@64g%r@80g!%r@98g%r@114g!%r@148g!",&r1,&r2,&r3,&r4,&r5); + if (d.len() > 30) + set_row(r+1, "@46g!@80g!@114g!@148g!"); + } + else + { + set_row(r,"%3d-",g); + set_row(r,"%3d ********",c); + set_row(r,"@17g#a",_d); + set_row(r++,"@46g!%r@64g%r@80g!%r@98g%r@114g!@132g%r@148g!",&r1,&r2,&r3,&r4,&r5); + if (d.len() > 30) + set_row(r+1, "@46g!@80g!@114g!@148g!"); + } + } + + set_row(r,"@46g!@80g!@114g!"); + if (_stampa_width != 132) + set_row(r,"@148g!"); + r++; + + set_row(r,"@46g!@80g!@114g!"); + if (_stampa_width != 132) + set_row(r,"@148g!"); + r++; + + if (app == 'D') + _saldo_finale_tot += r5; + else _saldo_finale_tot -= r5; + + _saldo_dare_tot += r1; + _saldo_avere_tot += r2; + _mov_dare_tot += r3; + _mov_avere_tot += r4; + + return r; +} + +void TStampa_bilanci::stampa_riga_totali(int r) +{ + const TString16 dep; + char app = ' '; + + if (_saldo_finale_tot > 0) + app = 'D'; + else if (_saldo_finale_tot < 0) + { + _saldo_finale_tot = -_saldo_finale_tot; + app = 'A'; + } + + //modifica del 21/11/1995 + if (_tipo_stampa1 == 2) + { + real r = _saldo_dare_tot - _saldo_avere_tot; + if (r > ZERO) + { + _saldo_dare_tot = r; + _saldo_avere_tot = ZERO; + } + else + { + _saldo_avere_tot = -r; + _saldo_dare_tot = ZERO; + } + } + + set_row(r, "@46g!@80g!@114g!"); + if (_stampa_width != 132) + set_row(r, "@148g!"); + r++; + + if (_verifica == 2) + { + if (_stampa_width == 132) + { + set_row(r,FR("***@8gTOTALE GENERALE@46g!%r@64g%r@80g!%r@98g%r@114g!@115g%r"),&_saldo_dare_tot,&_saldo_avere_tot,&_mov_dare_tot, + &_mov_avere_tot,&_saldo_finale_tot); + if (_saldo_finale_tot != ZERO) + set_row(r,"@131g%c", app); + } + else + { + if (app == 'D') + set_row(r,FR("***@8gTOTALE GENERALE@46g!%r@64g%r@80g!%r@98g%r@114g!%r@148g!"),&_saldo_dare_tot,&_saldo_avere_tot, + &_mov_dare_tot,&_mov_avere_tot,&_saldo_finale_tot); + else + set_row(r,FR("***@8gTOTALE GENERALE@46g!%r@64g%r@80g!%r@98g%r@114g!@132g%r@148g!"),&_saldo_dare_tot,&_saldo_avere_tot, + &_mov_dare_tot,&_mov_avere_tot,&_saldo_finale_tot); + } + } + else + { + if (_stampa_width == 132) + { + set_row(r,FR("@1g****** ********@17gTOTALE GENERALE@46g!%r@64g%r@80g!%r@98g%r@114g!@115g%r"),&_saldo_dare_tot,&_saldo_avere_tot, + &_mov_dare_tot,&_mov_avere_tot,&_saldo_finale_tot); + if (_saldo_finale_tot != ZERO) + set_row(r,"@131g%c", app); + r++; + + if ((_tipo_stampa1 == 1 && _datada == _dataini) || _tipo_stampa1 == 2) + { + //modifica del 21/11/1995 + if (_tipo_stampa1 == 2) + set_row(r,FR("@1g****** ********@17gTOTALE CON SALDI INIZIALI@46g!@80g!%r@98g%r@114g!"),&_nuovo_tot_saldo_d,&_nuovo_tot_saldo_a); + else + set_row(r,FR("@1g****** ********@17gTOTALE CON MOVIM. DI APERTURA@46g!@80g!%r@98g%r@114g!"),&_nuovo_tot_saldo_d,&_nuovo_tot_saldo_a); + //fine + } + } + else + { + if (app == 'D') + { + set_row(r++,FR("@1g****** ********@17gTOTALE GENERALE@46g!%r@64g%r@80g!%r@98g%r@114g!%r@148g!"),&_saldo_dare_tot, + &_saldo_avere_tot,&_mov_dare_tot,&_mov_avere_tot, &_saldo_finale_tot); + } + else + { + set_row(r++,FR("@1g****** ********@17gTOTALE GENERALE@46g!%r@64g%r@80g!%r@98g%r@114g!@132g%r@148g!"),&_saldo_dare_tot, + &_saldo_avere_tot,&_mov_dare_tot,&_mov_avere_tot, &_saldo_finale_tot); + } + + if ((_tipo_stampa1 == 1 && _datada == _dataini) || _tipo_stampa1 == 2) + { + if (_tipo_stampa1 == 2) + set_row(r,FR("@1g****** ********@17gTOTALE CON SALDI INIZIALI@46g!@80g!%r@98g%r@114g!@148g!"),&_nuovo_tot_saldo_d,&_nuovo_tot_saldo_a); + else + set_row(r,FR("@1g****** ********@17gTOTALE CON MOVIM. DI APERTURA@46g!@80g!%r@98g%r@114g!@148g!"),&_nuovo_tot_saldo_d,&_nuovo_tot_saldo_a); + } + } + } +} + +void TStampa_bilanci::stampa_totali() +{ + const TString16 dep = ""; + real pareggio; + real sbilancio = _tot_dare - _tot_avere; + if (sbilancio > ZERO) //_tot_dare > _tot_avere + pareggio = _tot_avere + sbilancio; + else + { + sbilancio = -sbilancio; + pareggio = _tot_dare + sbilancio; + } + if (_prima_volta) //ho finito di stampare le attivita'/passivita' + _prima_volta = FALSE; + else + _seconda_volta = FALSE; + const bool stato_patrimoniale = _seconda_volta; // cosa mi tocca fare + _gc_prec_dare = _gc_corr_avere = ""; + _cambiato_conto_1 = TRUE; + _cambiato_conto_2 = TRUE; + + set_row(_i++, (const char*)dep); + set_row(_i++, (const char*)dep); + set_row(_i++, (const char*)dep); + set_row(_i++, (const char*)dep); + TString pal; total2string(_tot_dare, pal); + TString bal; total2string(_tot_avere, bal); + set_row(_i++, FR("@39gTOTALE@48g%s@102gTOTALE@113g%s"), + (const char*)pal, (const char*)bal); + TString sb; total2string(sbilancio, sb); + TString pa; total2string(pareggio, pa); + if (_tot_dare > _tot_avere) + { + if (stato_patrimoniale) + set_row(_i++, FR("@79gUTILE DELL'ESERCIZIO IN CORSO@113g%s"), (const char*)sb); + else + set_row(_i++, FR("@77gPERDITA DELL'ESERCIZIO IN CORSO@113g%s"), (const char*)sb); + set_row(_i++, FR("@91gTOTALE A PAREGGIO@113g%s"),(const char*)pa); + } + if (_tot_dare < _tot_avere) + { + if (stato_patrimoniale) + set_row(_i++, FR("@14gPERDITA DELL'ESERCIZIO IN CORSO@48g%s"), (const char*)sb); + else + set_row(_i++, FR("@16gUTILE DELL'ESERCIZIO IN CORSO@48g%s"), (const char*)sb); + set_row(_i++, FR("@28gTOTALE A PAREGGIO@48g%s"),(const char*)pa); + } + _tot_dare = ZERO; + _tot_avere = ZERO; +} + +//per i conti patrimoniali stampo anche lo sbilancio es. precedente +void TStampa_bilanci::stampa_totali_uno(const real& r1,const real& r2) +{ + real pareggio; + real sbilancio = _tot_dare - r1 - (_tot_avere - r2); + real sbilprec = r2 - r1; + + if (_prima_volta) //ho finito di stampare le attivita'/passivita' + _prima_volta = FALSE; + else + _seconda_volta = FALSE; + const bool stato_patrimoniale = _seconda_volta; // cosa mi tocca fare + _gc_prec_dare = _gc_corr_avere = ""; + _cambiato_conto_1 = TRUE; + _cambiato_conto_2 = TRUE; + + const char* dep = ""; + set_row(_i++, (const char*)dep); + set_row(_i++, (const char*)dep); + set_row(_i++, (const char*)dep); + set_row(_i++, (const char*)dep); + TString pal; total2string(_tot_dare, pal); + TString bal; total2string(_tot_avere, bal); + set_row(_i++, FR("@39gTOTALE@48g%s@102gTOTALE@113g%s"), + (const char*)pal, (const char*)bal); + if (sbilancio > ZERO) //ho un utile => va stampato tra le passivita' + { + sbilprec = -sbilprec; + pareggio = _tot_avere + sbilancio + sbilprec; + if (sbilprec != ZERO) + { + TString sb; total2string(sbilprec, sb); + set_row(_i++, FR("@83gSBILANCIO ESERCIZIO PRECEDENTE@113g%s"), + (const char*)sb); + } + TString pal; total2string(sbilancio, pal); + TString bal; total2string(pareggio, bal); + if (stato_patrimoniale) + set_row(_i++, FR("@79gUTILE DELL'ESERCIZIO IN CORSO@113g%s"), (const char*)pal); + else + set_row(_i++, FR("@77gPERDITA DELL'ESERCIZIO IN CORSO@113g%s"), (const char*)pal); + set_row(_i++, FR("@91gTOTALE A PAREGGIO@113g%s"),(const char*)bal); + } + else if (sbilancio < ZERO) //ho una perdita => va stampato tra le attivita' + { + sbilancio = -sbilancio; + pareggio = _tot_dare + sbilancio + sbilprec; + if (sbilprec != ZERO) + { + TString sb; total2string(sbilprec, sb); + set_row(_i++, FR("@15gSBILANCIO ESERCIZIO PRECEDENTE@48g%s"), + (const char*)sb); + } + + TString pal; total2string(sbilancio, pal); + TString bal; total2string(pareggio, bal); + if (stato_patrimoniale) + set_row(_i++, FR("@14gPERDITA DELL'ESERCIZIO IN CORSO@48g%s"), (const char*)pal); + else + set_row(_i++, FR("@16gUTILE DELL'ESERCIZIO IN CORSO@48g%s"), (const char*)pal); + set_row(_i++, FR("@28gTOTALE A PAREGGIO@48g%s"),(const char*)bal); + } + else //sbilancio es. in corso == 0 + { + sbilprec = -sbilprec; + if (sbilprec > ZERO) //va stampato sotto le passivita' + { + TString pal; total2string(sbilprec, pal); + pareggio = _tot_avere + sbilprec; + TString bal; total2string(pareggio, bal); + set_row(_i++, FR("@83gSBILANCIO ESERCIZIO PRECEDENTE@113g%s"), + (const char*)pal); + set_row(_i++, FR("@96gTOTALE A PAREGGIO@113g%s"), (const char*)bal); + } + else if (sbilprec < ZERO) + { + sbilprec = -sbilprec; + pareggio = _tot_dare + sbilprec; + TString pal; total2string(sbilprec, pal); + TString bal; total2string(pareggio, bal); + set_row(_i++, FR("@15gSBILANCIO ESERCIZIO PRECEDENTE@48g%s"), (const char*)pal); + set_row(_i++, FR("@28gTOTALE A PAREGGIO@48g%s"), (const char*)bal); + } + } + _tot_dare = ZERO; + _tot_avere = ZERO; +} + +// Guy: stampa la prima colonna del bilancio di raffronto +void TStampa_bilanci::stampa_prima_colonna(int g, int c, long s, + const char* desc, const real& saldo) +{ + if (_codici) //sono stampate solo le descrizioni dei conti + { + if (!_totali) + { + if (c != 0 && s == 0) + set_row(_i, "%-.44s @44g @48g%r", desc, &saldo); + else + set_row(_i, "%-.48s @48g%r", desc, &saldo); + } + else if ( !(c == 0 && s == 0) ) //se cioe' non e' un gruppo + { + if (s == 0) //se e' un conto + set_row(_i, "%-.44s @44g @48g%r", desc, &saldo); + else + set_row(_i, "%-.48s @48g%r", desc, &saldo); + } + } + else + { + if (_totali && c == 0 && s == 0l) + return; + + set_row(_i, "@0g%3d", g); + if (c > 0) + { + set_row(_i, "@4g%3d", c); + if (s > 0) + set_row(_i, "@8g%6ld", s); + } + set_row(_i, "@15g%-.31s @48g%r", desc, &saldo); + } + set_row(_i, "@67g*"); +} + + +// Guy: stampa la seconda colonna del bilancio di raffronto +void TStampa_bilanci::stampa_seconda_colonna(int g, int c, long s, const char* desc, const real& saldo) +{ + if (_codici) //sono stampate solo le descrizioni dei conti + { + if (!_totali) + { + set_row(_i, "@67g*@69g%-.47s @114g%r", desc, &saldo); + } + else + { + if ( !(c == 0 && s == 0) ) + set_row(_i, "@67g*@69g%-.47s @114g%r", desc, &saldo); + } + } + else + { + if (_totali && c == 0 && s == 0l) + return; + + set_row(_i, "@67g*@69g%3d ", g); + if (c > 0) + { + set_row(_i, "@73g%3d", c); + if (s > 0) + set_row(_i, "@77g%6ld", s); + } + set_row(_i, "@84g%-.30s @114g%r", desc, &saldo); + } +} + +print_action TStampa_bilanci::postprocess_page(int file, int counter) +{ + if (_bilancio == 1) + { + if ( _eof1 && _eof2 && _eof3 && _eof4 && _eof5 && _eof6 && _salto_pagina1 ) + return NEXT_PAGE; + } + else //bilancio di verifica + { + if (_verifica == 3) + { + if (_buff == NULL) + return NEXT_PAGE; + } + else if (_eof1) + return NEXT_PAGE; + } + return REPEAT_PAGE; +} + +TDate TStampa_bilanci::UltimaData(int g, int c, long s, int anno) +{ + TDate uldata; + TLocalisamfile saldi(LF_SALDI); + + saldi.zero(); + if (_annoes != 0) + saldi.put(SLD_ANNOES, anno); + saldi.put(SLD_FLSCA, FALSE); // W96SALDI del 05-06-96 + 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; +} + +// Non ho potuto usare quella di TConto!!! Chiedere a me! +// Guy: E tu chi sei? +const char* TStampa_bilanci::DescrizioneConto(int g, int c, long s, char tipocf) +{ +/* + static TString80 ragsoc; + const char* desc = NULL; + + TString80 key; key << g; + if (c != 0) + { + key << "|" << c ; + if (s != 0) + key << "|" << s; + } + const TRectype & pconti = cache().get(LF_PCON, key); + if (!pconti.empty()) + _tmp = pconti.get(PCN_DESCR); + else + { + key.format("%c|%ld", tipocf, s); + const TRectype & clifo = cache().get(LF_CLIFO, key); + + if (!clifo.empty()) + { + char tipoa = clifo.get_char(CLI_TIPOAPER); + if (tipoa == 'F') //persona fisica + { + TString80 cognome, nome; + ragsoc = clifo.get(CLI_RAGSOC); + cognome = ragsoc.mid(0,30); + nome = ragsoc.mid(30,20); + cognome.trim(); nome.trim(); + ragsoc = cognome; + ragsoc << " " << nome; + desc = ragsoc; + } + else + desc = clifo.get(CLI_RAGSOC); + _tmp = desc; + } + else + _tmp = ""; + + } + return _tmp; +*/ + const TBill bill(g, c, s, tipocf); + _tmp = bill.descrizione(); + return _tmp; +} + +bool TStampa_bilanci::user_create() +{ + open_files(LF_TAB, 0); + + _stampa_width = 132; + _rel = new TRelation(LF_CLIFO); + _cur = new TCursor (_rel,"",3); + _mov = new TLocalisamfile(LF_MOV); + _rmov = new TLocalisamfile(LF_RMOV); + _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); + _caus = new TLocalisamfile(LF_CAUSALI); + _d = new TParagraph_string("",29); + _sort = NULL; + _tmp_saldi_att = NULL; + _tmp_saldi_pass = NULL; + _tmp_saldi_costi = NULL; + _tmp_saldi_ricavi = NULL; + _tmp_saldi_conti_uno = NULL; + _tmp_saldi_conti_due = NULL; + return TRUE; +} + +bool TStampa_bilanci::user_destroy() +{ + delete _rel; + delete _cur; + delete _com; + delete _pcn; + delete _mov; + delete _rmov; + delete _clifo; + delete _saldi; + delete _nditte; + delete _anag; + delete _caus; + delete _d; + + if (_tmp_saldi_att) delete _tmp_saldi_att; + if (_tmp_saldi_pass) delete _tmp_saldi_pass; + if (_tmp_saldi_costi) delete _tmp_saldi_costi; + if (_tmp_saldi_ricavi) delete _tmp_saldi_ricavi; + if (_tmp_saldi_conti_uno) delete _tmp_saldi_conti_uno; + if (_tmp_saldi_conti_due) delete _tmp_saldi_conti_due; + return TRUE; +} + +void TStampa_bilanci::leggi_pcon() +{ + TRelation rel(LF_PCON); + TCursor cur(&rel); + const TRectype& pconti = rel.curr(); + + const long items = cur.items(); + cur.freeze(); + + TToken_string gc(10); + for (cur = 0L; cur.pos() < items; ++cur) + { + const int gruppo = pconti.get_int(PCN_GRUPPO); + const int conto = pconti.get_int(PCN_CONTO); + const long sottoconto = pconti.get_long(PCN_SOTTOCONTO); + if ( (sottoconto == 0l) && (conto != 0) ) //si tratta di un conto + { + const char tipocf = pconti.get_char(PCN_TMCF); + if ( tipocf == 'C' && (_situazione.empty() || _situazione == "C")) + { + gc.add(gruppo,0); + gc.add(conto,1); + _clienti.add(gc); + } + else if ( tipocf == 'F' && (_situazione.empty() || _situazione == "F")) + { + gc.add(gruppo,0); + gc.add(conto,1); + _fornitori.add(gc); + } + } + } +} + +void TStampa_bilanci::stampa_un_bilancio(const TMask& m) +{ + _prog = NULL; + if (_bilancio == 1) //bilancio a sezioni contrapposte + { + printer().footerlen(3); + _prog = new TProgress_monitor(_pcn->items(),TR("Elaborazione conti"), false); + _totali = m.get_bool(F_TOTALI); + _codici = m.get_bool(F_CODICI); + _saldo = m.get_bool(F_SALDO); + _tipo_stampa = m.get_int(F_STAMPA); + + if (_tipo_stampa == 1) + { + _datalim = m.get(F_DATALIM); + _print_exercise = TRUE; + if (_annoes == 0) + { + _print_exercise = FALSE; + _annoes = date2esc(_datalim); + } + + if (_annoes != 0) + _dataini = InizioEsercizio(_annoes); + else + _dataini = _inizioEs; + } + bil_sez_contr(); + } + else //bilancio di verifica (tipo 1,2,3) + { + printer().footerlen(5); + _stampa_width = (m.get_int(F_MODULO) == 1) ? 132 : 148; //perche' questo e' in realta' il margine dx (vedi es. di stampa AS/400) + + _verifica = m.get_int(F_VERIFICA); //tipo di bilancio di verifica da stampare + _print_full_code = _verifica == 1 && m.get_bool(F_PRINT_FULL_CODE); + if ( (_verifica == 1)||(_verifica == 2) ) + _prog = new TProgress_monitor(_pcn->items(),TR("Elaborazione conti"),false); + _tipo_stampa1 = m.get_int(F_STAMPA1); + if (_tipo_stampa1 == 1) + { + if (_annoes != 0) + _dataini = InizioEsercizio(_annoes); + else + _dataini = _inizioEs; + _datada = m.get(F_DATADA); + _dataa = m.get(F_DATAA); + } + if ((_verifica == 1)||(_verifica == 2)) //bilancio di verifica:1bilancio,2saldi mastro + { + _stampav = atoi(m.get(F_STAMPAV)); + bil_verifica(); + } + else + { + _situazione = m.get(F_SITUAZIONE); + _stampac = atoi(m.get(F_STAMPAC)); + _ordinamento = atoi(m.get(F_ORDINAMENTO)); + + if (_situazione.not_empty()) + _cur->setfilter(format("TIPOCF=\"%s\"",(const char*)_situazione)); + else + _cur->setfilter(""); + + _clienti.destroy(); + _fornitori.destroy(); + leggi_pcon(); + crea_sort_clifo(); // Crea la sua _prog + _sort->endsort(); + } + } + if (_prog) + delete _prog; + print(); +} + +bool TStampa_bilanci::set_print(int) +{ + TMask m ("cg1500a"); + m.set_handler (F_VERIFICA, verifica_handler); + m.set_handler (F_BILANCIO, mask_bilancio); + m.set_handler (F_STAMPA1, mask_bilancio); + m.set_handler (F_STAMPA, mask_bilancio); + m.set_handler (F_DATALIM, mask_datalim); + m.set_handler (F_DATADA, mask_date); + m.set_handler (F_DATAA, mask_date); + m.set_handler (F_ANNO, mask_anno); + + while (m.run() == K_ENTER) + { + _annoes = m.get_int(F_ANNO); + _bilancio = m.get_int(F_BILANCIO); + _data = m.get(F_DATASTAMPA); + _stampa_mov_prov = m.get_int(F_STAMPAMPROV); + _quadratura = m.get_bool(F_QUADRATURA); + _hide_clifo = m.get_bool(F_HIDE_CLIFO); + _noseparator = m.get_bool(F_SEPARATOR); +#ifdef CONT_SEP + _cont_sep = m.get(F_CONTSEP); +#endif + + //qui getti le terne dei 2 conti da mettere in bill_from e bill_to con un metodo dei TBill + _bill_from.get(m, F_DA_GRUPPO, F_DA_CONTO, F_DA_SOTTOCONTO); + _bill_to.get(m, F_A_GRUPPO, F_A_CONTO, F_A_SOTTOCONTO); + + //se non e' stato riempito il gruppo TO, si mette di default il max del gr/co/so + if (_bill_to.gruppo() == 0) + _bill_to.set(999, 999, 999999L); + else + { //se invece il gruppo c'e' ma il conto no... + if (_bill_to.conto() == 0) + _bill_to.set(_bill_to.gruppo(), 999, 999999L); //il gruppo e' quello selezionato + else + { + if (_bill_to.sottoconto() == 0) //se mancasse solo il sottoconto.. + _bill_to.set(_bill_to.gruppo(), _bill_to.conto(), 999999L); + } + } + + stampa_un_bilancio(m); + } + return FALSE; +} + +TRectype& look_com (const char* cod, TLocalisamfile *comuni) +{ + comuni->zero(); + comuni->put(COM_COM, cod); + comuni->read(); + if (comuni->bad()) + comuni->zero(); + + return comuni->curr(); +} + +void TStampa_bilanci::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 = look_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 TStampa_bilanci::stampa_intestazione_ditta() +{ + int r = 1; + TString codice_ditta; + TString riga(_stampa_width); + + get_dati_ditta(); + codice_ditta << get_firm(); + + set_header (r++, "%s %s %s %s %s %s %s", TR("Ditta"), (const char*)codice_ditta, + (const char*)_ragsoc, (const char*)_viafis, + (const char*)_cap, (const char*)_comunefis, + (const char*)_provfis); + printer().setdate(_data); + riga = TR("Data") ; riga << " @> " << TR("Pag.") << " @#"; + riga.right_just(_stampa_width-10); + + //_stampa_mov_provv(1=normale,2=globale,3=solo provvisori) + const char* tipoprovv = ""; + if (_stampa_mov_prov == 2) + tipoprovv = TR("GLOBALE"); + if (_stampa_mov_prov == 3) + tipoprovv = TR("PROVVISORIO"); + //l'uso della overwrite e' una vera vaccata! + riga.overwrite (format("%s %s %s %s", TR("Partita iva"), (const char*)_paiva, TR("Codice fiscale"), (const char*)_cofi)); + riga.overwrite (tipoprovv, 85); + + set_header (r++, "%s", (const char*) riga); + + return r; +} + +void TStampa_bilanci::preprocess_header() +{ + int r; + + reset_header(); + r = stampa_intestazione_ditta(); + + if (_bilancio == 1) //bilancio a sezioni contrapposte + { + TString riga (132); + TDate data_da; + TString data; + TString data_lim = _datalim.string(); + + set_header(r, TR("STAMPA BILANCIO A SEZIONI CONTRAPPOSTE")); + if (_tipo_stampa == 1) + { + data_da = _dataini.string(); + data = _datalim.string(); + set_header(r,"@41g%s %s %s %s", TR("dalla data"), (const char*) data_da, TR("alla data"), + (const char*) data); + } + else if (_tipo_stampa == 2) + set_header(r,FR("@41gall'ultima immissione Es. %d"), _annoes); + + //modifica del 20/04/1995 + if (_print_exercise) + { + const TString16 d1(InizioEsercizio(_annoes).string()); + const TString16 d2(FineEsercizio(_annoes).string()); + set_header(r, "@84g%s %s %s", TR("Esercizio"), (const char*)d1, (const char*)d2); /**/ + } + riga.fill('_'); + set_header(++r, (const char*)riga); + riga = ""; + set_header(++r, (const char*)riga); + } + else // bilancio di verifica + { + TString riga (_stampa_width); + TString16 datada = _datada.string(); + TString16 dataa = _dataa.string(); + if (_verifica == 1) + set_header(r, TR("STAMPA BILANCIO DI VERIFICA")); + else if (_verifica == 2) + set_header(r, TR("STAMPA SALDI DI MASTRO")); + else + { + if (_situazione == "C") + set_header(r, TR("SITUAZIONE CONTABILE CLIENTI")); + else if (_situazione == "F") + set_header(r, TR("SITUAZIONE CONTABILE FORNITORI")); + else set_header(r,TR("SITUAZIONE CLIENTI/FORNITORI")); + } + + if (_tipo_stampa1 == 1) + { + set_header(r,"@30g%s %s %s %s", TR("dalla data"), (const char*) datada, TR("alla data"), + (const char*) dataa); + //modifica del 20/04/1995 + if (_annoes != 0) //se l'anno e' 0 non si considera la competenza + { + TString16 d1(InizioEsercizio(_annoes).string()); + TString16 d2(FineEsercizio(_annoes).string()); + + set_header(r,"@74g%s %s %s", TR("Esercizio"), (const char*)d1, (const char*)d2); /**/ + } + } + else if (_tipo_stampa1 == 2) + { + set_header(r,FR("@36gall'ultima immissione Es. %d"), _annoes); + //modifica del 20/04/1995 + TString16 d1(InizioEsercizio(_annoes).string()); + TString16 d2(FineEsercizio(_annoes).string()); + + set_header(r,"@72g%s %s %s", TR("Esercizio"), (const char*)d1, (const char*)d2); /**/ + } + + if ( (_verifica == 1)||(_verifica == 2) ) + { + if (_stampav == 1) + set_header(r, "@107g%s", TR("Tutti i conti movimentati")); + else if (_stampav == 2) + set_header(r, "@107g%s", TR("Conti con saldo <> 0")); + else + set_header(r, "@107g%s", TR("Tutti i conti")); + } + else + { + if (_stampac == 1) + set_header(r, "@107g%s", TR("Tutti i conti movimentati")); + else + set_header(r, "@107g%s", TR("Conti con saldo <> 0")); + } + riga.fill('_'); + set_header(++r, (const char*)riga); + r++; + + TString h; + + if (_print_full_code) + h << "@46g!@55g"; + else + h << "@7g!@46g!@55g"; + + if ( ((_datada == _dataini)&&(_tipo_stampa1 == 1))||(_tipo_stampa1 != 1) ) + { + if (_tipo_stampa1 == 1 && _datada == _dataini) + h << TR("MOVIMENTI DI APERTURA"); + else + h << TR(" SALDO INIZIALE"); + } + else + if (_tipo_stampa1 == 1) + h << TR("PROGRESSIVI PRECEDENTI"); + h << "@80g!@88g"; + h << TR("MOVIMENTI DEL PERIODO"); + set_header(r, h); + if ( (_verifica == 1)||(_verifica == 3) ) + set_header(r,"@16g!"); + + set_header(r,"@114g!"); + if (_stampa_width != 132) + { + h = "@129g" ; + h << TR("SALDO"); + h << "@148g!"; + set_header(r, h); + } + r++; + + if ( (_verifica == 1)||(_verifica == 3)) + { + if (_print_full_code) + set_header(r,FR("@2gcodice conto !@46g!@47g%.67s@80g!@83g@114g!"),(const char*)riga); + else + set_header(r,FR("@2gcod. ! ultima !@46g!@47g%.67s@80g!@83g@114g!"),(const char*)riga); + if (_stampa_width == 132) + set_header(r,FR("@121gSALDO")); + else + set_header(r,"%.33s@148g!",(const char*)riga); + r++; + + if (_print_full_code) + set_header(r,FR("@2g ! denominazione@46g!@53gDare@63g!@69gAvere@80g!@87gDare@97g!@103gAvere@114g!")); + else + set_header(r,FR("@2gconto! data ! denominazione@46g!@53gDare@63g!@69gAvere@80g!@87gDare@97g!@103gAvere@114g!")); + if (_stampa_width != 132) + set_header(r,FR("@121gDare@131g!@137gAvere@148g!")); + r++; + } + else + { + set_header(r,FR("@2gcod. !@46g!@47g%.67s@80g!@83g@114g!"),(const char*)riga); + if (_stampa_width == 132) + set_header(r,FR("@121gSALDO")); + else + set_header(r,"%.33s@148g!",(const char*)riga); + r++; + + set_header(r,FR("@1gmastro!descrizione@46g!@53gDare@63g!@69gAvere@80g!@87gDare@97g!@103gAvere@114g!")); + if (_stampa_width != 132) + set_header(r, FR("@121gDare@131g!@137gAvere@148g!")); + r++; + } + set_header(r, (const char*)riga); + if (_stampa_width != 132) + set_header(r,"@148g!"); + } +} + +#ifdef CONT_SEP +int np0300(int argc, char* argv[]) +#else +int cg1500(int argc, char* argv[]) +#endif +{ + TStampa_bilanci a; + a.run(argc, argv, TR("Stampa bilanci")); + return 0; +} diff --git a/src/cg/cg1500.h b/src/cg/cg1500.h index 2874d1cd0..edf4fec29 100755 --- a/src/cg/cg1500.h +++ b/src/cg/cg1500.h @@ -35,8 +35,7 @@ #define F_A_DESCRIZIONE 139 #define F_PRINT_FULL_CODE 140 #ifdef CONT_SEP -#define F_ST_CONTSEP 141 -#define F_CONTSEP 142 +#define F_CONTSEP 14 #endif #endif // __CG1500_H diff --git a/src/cg/cg1500a.uml b/src/cg/cg1500a.uml index 74b2ec0d1..cff918374 100755 --- a/src/cg/cg1500a.uml +++ b/src/cg/cg1500a.uml @@ -4,7 +4,11 @@ TOOLBAR "topbar" 0 0 0 2 #include ENDPAGE +#ifdef CONT_SEP +PAGE "Stampa bilancio Contabilità separata" -1 -1 76 16 +#else PAGE "Stampa bilancio" -1 -1 76 16 +#endif NUMBER F_CODDITTA 5 BEGIN @@ -79,13 +83,13 @@ BEGIN ITEM "1|Per date limite" MESSAGE SHOW,F_DATALIM|SHOW,F_TOTALI|SHOW,F_CODICI|SHOW,F_SALDO #ifdef CONT_SEP - MESSAGE SHOW,F_ST_CONTSEP + MESSAGE SHOW,F_CONTSEP #endif ITEM "2|All'ultima immissione" MESSAGE HIDE,F_DATALIM|RESET,F_DATALIM MESSAGE SHOW,F_TOTALI|SHOW,F_CODICI|SHOW,F_SALDO #ifdef CONT_SEP - MESSAGE HIDE,F_ST_CONTSEP + MESSAGE HIDE,F_CONTSEP #endif END @@ -97,13 +101,13 @@ BEGIN ITEM "1|Per date limite" MESSAGE SHOW,F_VERIFICA|SHOW,F_MODULO|SHOW,F_STAMPAMPROV #ifdef CONT_SEP - MESSAGE SHOW,F_ST_CONTSEP + MESSAGE SHOW,F_CONTSEP #endif ITEM "2|All'ultima immissione" MESSAGE SHOW,F_VERIFICA|SHOW,F_MODULO|SHOW,F_STAMPAMPROV MESSAGE COPY,F_STAMPA #ifdef CONT_SEP - MESSAGE HIDE,F_ST_CONTSEP + MESSAGE HIDE,F_CONTSEP #endif END @@ -185,23 +189,15 @@ BEGIN END #ifdef CONT_SEP -BOOLEAN F_ST_CONTSEP -BEGIN - PROMPT 2 14 "Bilancio a contabilità separata" - MODULE NP - MESSAGE FALSE HIDE,F_CONTSEP - MESSAGE TRUE SHOW,F_CONTSEP -END - STRING F_CONTSEP 6 BEGIN - PROMPT 40 14 "Contabilità separata " + PROMPT 2 14 "Contabilità separata " USE &NPENT INPUT CODTAB F_CONTSEP DISPLAY "Codice@6" CODTAB DISPLAY "Descrizione@50" S0 OUTPUT F_CONTSEP CODTAB - CHECKTYPE NORMAL + CHECKTYPE REQUIRED MODULE NP END #endif diff --git a/src/cg/cg3100.cpp b/src/cg/cg3100.cpp index 8f9368c0f..48435d9a8 100755 --- a/src/cg/cg3100.cpp +++ b/src/cg/cg3100.cpp @@ -1,2487 +1,2502 @@ -// -//Lista movimenti -// - -#include "cg3.h" -#include "cg3100.h" - -#include "cglib01.h" -#include "cglib03.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -enum liste { movimenti=1, fatture=2, }; - -class TListaMov_application : public TPrintapp -{ - static bool filter_func (const TRelation *); - static bool filter_func_fatture (const TRelation *); - static bool annoes_handler(TMask_field&, KEY); - static bool data_inizio (TMask_field&, KEY); - static bool data_fine (TMask_field&, KEY); - - TRigaiva_array _c; - TRelation * _relmov1,* _relmov2,* _relmov3; - TCursor * _curr1, * _curr2, * _curr3; - TBit_array _err; - TDate _data_ini, _data_fin, _datareg, _data_prec, _datacomp; - TString _descr, _descr_doc, _descr_causale; - TString _tipo_ini, _causale, _app; - TString4 _causale_ini, _causale_fin, _registro,_registro_ini, _registro_fin; - TString _tipoatt, _tipo_elenco,_tipo_clifo_prec,_tipoelsucc; - char _appoggio; - TString4 _tipodoc, _tipodocumento; - TString _ragsoc, _indcf, _civcf, _paiv, _codcaus, _dencom, _provcom, _cofi; - TString _capcf, _codval, _simbolo, _statocf, _comcf, _tipo_fin, _reg_causale; - long _documenti, _codice_ini, _codice_fin, _numero_reg, _codcf; - long _gen_documenti; - long _numreg, _numreg_fin, _numreg_ini, _codalleg, _numeroregp,_codclifosucc; - long _codcf_prec, _numr, _numero; - int _ae, _anno, _annoes, _annoeser; - bool _noseparator, _competence_only; - real _totdocumenti, _totdoc, _totimponibile, _totimposta, _importo; - real _totritenute, _ritenute, _gen_totritenute; // Aggiunte 11/02/2013 - real _gen_totdocumenti, _gen_totimponibile, _gen_totimposta, _gen_op_esenti, _gen_op_non_imp; - real _op_esenti, _op_non_imp; //, _impo, _impos; - - real _tot_dare, _tot_avere, _tot_avere_giornaliero; - real _tot_dare_giornaliero, _tot_dare_generale, _tot_avere_generale; - bool _no_preprocess_page, _salto_pagina, _stampa_anno_comp,_esiste_riga_iva,_nonesiste_riga_iva; - bool _stampa_parte_iva,_alleg_causale,_stampa_mess_alleg_iva,_allegb; - int _ricser; - bool _settata_prima_riga, _causale_gia_stampata,_mov_di_sola_iva; - int _cur1,_cur2,_cur2b,_cur3,_cur4,_decidi,/*_tipod,*/_controllo_mov_errati; - int _numero_riga, _alleg, _tiporegistro, _scelta_stampa, _nr, _n; - int _provvis; - liste _tipo_lista; - word _flags; - char _tipoc; - TString4 _dacodiva, _acodiva; - -protected: - virtual void preprocess_header(); - virtual bool preprocess_page(int,int); - virtual print_action postprocess_page(int,int); - virtual print_action postprocess_print(int,int); - virtual void set_page(int,int); - virtual bool set_print(int m); - void init_print(const TMask& m); - - void print_intra(int& rr); - - void filtra_cursore_provvisori(TCursor* cur) const; - void imposta_parametri_stampa(const TMask& msk); - - bool codiva_filter(const TRelation* rel) const; - bool rmoviva_filter(const TRectype& rmoviva) const; - -public: - bool user_create(); - bool user_destroy(); - bool segnala_errori_primariga(); - bool segnala_errori_ogniriga(); - bool segnala_errori_iva(); - bool contropartita(int, int, long, char); - void stampa_errori_rmov(); - void stampa_errori_mov(); - void stampa_errori_iva(int* r, const TRigaiva& riva); - void stampa_errori_contropartita(int, int, long, char); - void stampa_intestazione(); - void incrementa_totali(); - void compila_clifo(); - void compila_comuni(); - const char * get_error(int error) const; - - bool RicercaDoc(const char* cod) const; - const TString& SimboloValuta (const char* cod) const; - const TString& DescrDoc(const char* cod) const; - const TString& AttivitaRegistro(const char * cod, int anno) const; - - TListaMov_application(char tipost); - virtual ~TListaMov_application() {} -}; - - -HIDDEN inline TListaMov_application& app() -{ return (TListaMov_application&)main_app();} - -bool TListaMov_application::annoes_handler(TMask_field& f, KEY k) -{ - if (k == K_TAB && f.focusdirty() && !f.empty()) - { - const int anno = atoi(f.get()); - TDate dataini, datafin; - TEsercizi_contabili esc; - if (esc.code2range(anno, dataini, datafin)) - { - f.mask().set(F_DATAINI, dataini); - const int prossimo = esc.next(anno); - if (prossimo > 0) - datafin = esc[prossimo].fine(); - f.mask().set(F_DATAFIN, datafin); - } - } - return true; -} - -bool TListaMov_application::data_inizio(TMask_field& f, KEY k) -{ - if (k == K_ENTER) - { - int decidi; - int anno = f.mask().get_int (F_ANNO); - TDate data = f.mask().get_date(F_DATAINI); - if (app()._tipo_lista == movimenti) - decidi = f.mask().get_int (F_DECIDI); - - TEsercizi_contabili esc; - if (esc.exist(anno) && ( (app()._tipo_lista == fatture) || - ((app()._tipo_lista == movimenti ) && (decidi == 2)) ) ) - { - const TDate inizio = esc[anno].inizio(); - if (data.ok()) - { - if (data < inizio) - { - f.error_box(TR("La data indicata non deve essere inferiore alla data di inizio esercizio")); - return FALSE; - } - } - else //se la data e' vuota - f.mask().field(F_DATAINI).set(inizio); - } - } - return TRUE; -} - -bool TListaMov_application::data_fine(TMask_field& f, KEY k) -{ - if (k == K_ENTER) - { - int decidi = 0; - int anno = f.mask().get_int (F_ANNO); - TDate dataini = f.mask().get_date(F_DATAINI); - TDate datafin = f.mask().get_date(F_DATAFIN); - if (app()._tipo_lista == movimenti) - decidi = f.mask().get_int (F_DECIDI); - if ( (app()._tipo_lista == fatture) || - ((app()._tipo_lista == movimenti) && (decidi == 2)) ) - if ( dataini.ok() && datafin.ok() ) - if (dataini > datafin) - { - f.error_box(TR("La data iniziale non deve essere superiore alla data finale")); - return FALSE; - } - - TEsercizi_contabili esc; - if (esc.exist(anno) && ( (app()._tipo_lista == fatture) || ((app()._tipo_lista == movimenti) && (decidi == 2)) ) ) - { - const int prossimo = esc.next(anno); - const TDate fine = esc[prossimo > 0 ? prossimo : anno].fine(); - if (datafin.ok()) - { - if (datafin > fine) - { - f.error_box(TR("La data indicata non deve essere superiore alla data di fine esercizio successivo, oppure, in caso questo non esista, dell'esercizio indicato")); - return FALSE; - } - } - else //se la data e' vuota - f.mask().set(F_DATAFIN, fine); - } - } - return TRUE; -} - -bool TListaMov_application::RicercaDoc(const char* tipo) const -{ - const TRectype& tab_tpd = cache().get(TAB_TPD, tipo); - return !tab_tpd.empty(); -} - -void TListaMov_application::compila_clifo() -{ - TToken_string key; - key.add(_tipo_elenco); - key.add(_codcf); - const TRectype& clifo = cache().get(LF_CLIFO, key); - - char tipoa = clifo.get_char(CLI_TIPOAPER); - _alleg = clifo.get_int(CLI_ALLEG); - _statocf = clifo.get(CLI_STATOCF); - _comcf = clifo.get(CLI_COMCF); - _ragsoc = clifo.get(CLI_RAGSOC); - if (tipoa == 'F') - { - TString80 cognome, nome; - cognome = _ragsoc.mid(0, 30); cognome.trim(); - nome = _ragsoc.mid(30,20); nome.trim(); - _ragsoc = cognome; - _ragsoc << ' ' << nome; - } - _indcf = clifo.get(CLI_INDCF); - _civcf = clifo.get(CLI_CIVCF); - _paiv = clifo.get(CLI_PAIV); - _capcf = clifo.get(CLI_CAPCF); - _dencom = clifo.get(CLI_LOCCF); - _cofi = clifo.get(CLI_COFI); - _codalleg = clifo.get_long(CLI_CODALLEG); -} - -void TListaMov_application::compila_comuni() -{ - TToken_string key; - key.add(_statocf); - key.add(_comcf); - const TRectype & comuni = cache().get(LF_COMUNI, key); - //modifica del 26/04/1995 - _dencom = comuni.get(COM_DENCOM); - if (!_dencom.empty()) - _app = "Com"; - else _app = "Loc"; - //fine modifica - _provcom = comuni.get(COM_PROVCOM); -} - -const char * TListaMov_application::get_error(int err) const -{ - switch (err) - { - case 0: - return TR("La data operazione non appartiene a nessun esercizio"); - break; - case 1: - return TR("Anno IVA non compatibile con data operazione"); - break; - case 2: - return TR("Data operazione successiva all'esercizio di competenza"); - break; - case 3: - return TR("Movimento con competenza anno precedente"); - break; - case 4: - return TR("La data di competenza non appartiene a nessun esercizio"); - break; - case 5: - return TR("Data competenza incompatibile con data operazione"); - break; - case 6: - return TR("Esercizio incompatibile con data competenza"); - break; - case 7: - return TR("Codice causale non presente in tabella"); - break; - case 8: - return TR("Codice causale sospeso"); - break; - case 9: - return TR("Nella causale e' stato attivato il segnale non va in allegato"); - break; - case 10: - return TR("Tipo documento non corrisponde a quello indicato in causale"); - break; - case 11: - return TR("Tipo documento non presente in tabella"); - break; - case 12: - return TR("Codice registro non corrisponde a quello indicato in causale"); - break; - case 13: - return TR("Codice registro non presente in tabella"); - break; - case 14: - return TR("Codice registro sospeso"); - break; - case 15: - return TR("Tipo registro incompatibile con tipo documento"); - break; - case 16: - return TR("Non indicato codice cliente/fornitore"); - break; - case 17: - return TR("Tipo cliente/fornitore non compatibile con tipo registro"); - break; - case 18: - return TR("Codice cliente/fornitore sospeso"); - break; - case 19: - return TR("Nel cliente/fornitore e' stato attivato il segnale: non va in allegato"); - break; - case 20: - return TR("Indicato codice C/F per allegato che richiama se stesso"); - break; - case 21: - return TR("Indicato codice C/F per allegato sospeso"); - break; - case 22: - return TR("C/F per allegato riporta un altro C/F per allegato"); - break; - case 23: - return TR("Indicato codice C/F per allegato con segnale: non va in allegato"); - break; - case 24: - return TR("Indicato codice C/F per allegato non presente in anagrafica"); - break; - case 25: - return TR("Codice cliente/fornitore non presente in anagrafica"); - break; - case 26: - return TR("Movimento con data competenza diversa da data operazione"); - break; - default: - return ""; - break; - } -} - -const int AllegClifo (int gruppo, int conto, long sottoconto) -{ - int alleg = 0; - - TLocalisamfile clifo(LF_CLIFO); - clifo.setkey(3); - clifo.zero(); - clifo.put(CLI_GRUPPO, gruppo); - clifo.put(CLI_CONTO, conto); - clifo.put(CLI_CODCF, sottoconto); - if (clifo.read() == NOERR) - alleg = clifo.get_int(CLI_ALLEG); - - return alleg; -} - -const char* DescrConto (int gruppo, int conto, long sottoconto, char tipocf) -{ - TString& tmp = get_tmp_string(50); -/* - TString16 key; - key << gruppo; - if (conto != 0) - key << '|' << conto; - if (sottoconto != 0) - key << '|' << sottoconto; - tmp = cache().get(LF_PCON, key, PCN_DESCR); - - if (tmp.empty()) - { - key.format("%c|%ld", tipocf , sottoconto); - - const TRectype & clifo = cache().get(LF_CLIFO, key); - if (!clifo.empty()) - { - char tipoa = clifo.get_char("TIPOAPER"); - if (tipoa == 'F') //persona fisica - { - const TString& ragsoc = clifo.get("RAGSOC"); - tmp = ragsoc.mid(0,30); - tmp.trim(); - tmp << ' ' << ragsoc.mid(30); - } - else - tmp = clifo.get("RAGSOC"); - } - } -*/ - const TBill bill(gruppo, conto, sottoconto, tipocf); - tmp = bill.descrizione(); - return tmp; -} - -bool CausAlleg (const char * cod) -{ - const TRectype& caus = cache().get(LF_CAUSALI, cod); - const bool allegb = caus.get_bool(CAU_ALLEG); - return allegb; -} - -const char* TipoAttivita (const char* attreg, long codice_ditta) -{ - TString16 key; key.format("%ld|%s", codice_ditta, attreg); - return cache().get(LF_ATTIV, key, ATT_TIPOATT); -} - -const TString& TListaMov_application::SimboloValuta(const char* cod) const -{ return cache().get(TAB_VAL, cod, "S7"); } - -const TString& TListaMov_application::DescrDoc(const char* tipo) const -{ return cache().get(TAB_TPD, tipo, "S0"); } - -const TString& TListaMov_application::AttivitaRegistro(const char* cod, int anno) const -{ - TString8 key; key.format("%04d%-3s", anno, cod); - return cache().get("REG", key, "S8"); -} - -HIDDEN int tipo_registro(const char* cod, int anno) -{ - TString8 codtab; codtab.format("%4d%-3s", anno, cod); - const TString& tipo_reg = cache().get("REG", codtab, "I0"); - return atoi(tipo_reg); -} - -static bool between(const TString& code, const TString& mini, const TString& maxi) -{ - if (mini.full() && code < mini) - return false; - if (maxi.full() && code > maxi) - return false; - return true; -} - -static bool between(const TDate& code, const TDate& mini, const TDate& maxi) -{ - if (mini.ok() && code < mini) - return false; - if (maxi.ok() && code > maxi) - return false; - return true; -} - -static bool between(long code, long mini, long maxi) -{ - if (mini > 0 && code < mini) - return false; - if (maxi > 0 && code > maxi) - return false; - return true; -} - -bool TListaMov_application::rmoviva_filter(const TRectype& rmoviva) const -{ - const TString& codiva = rmoviva.get(RMI_CODIVA); - return between(codiva, _dacodiva, _acodiva); -} - -bool TListaMov_application::codiva_filter(const TRelation* rel) const -{ - bool ok = _dacodiva.empty() && _acodiva.empty(); // Test su range codici iva - if (!ok) - { - const TRectype& mov = rel->curr(LF_MOV); - TRectype rmoviva(LF_RMOVIVA); - rmoviva.put(RMI_NUMREG, mov.get(MOV_NUMREG)); - TRecord_array righe(rmoviva, RMI_NUMRIG); - for (int i = 1; !ok && i <= righe.rows(); i++) - ok = rmoviva_filter(righe[i]); - } - return ok; -} - -bool TListaMov_application::filter_func_fatture (const TRelation* rel) -{ - const TRectype& mov = rel->curr(LF_MOV); - - // Altrimenti stampa anche i corrispettivi! Pseudo errore MI2396 - const long codcf = mov.get_long(MOV_CODCF); - if (codcf <= 0) - return FALSE; - - const TString& causale = mov.get(MOV_CODCAUS); - if (!between(causale, app()._causale_ini, app()._causale_fin)) - return false; - - const int ann_reg = mov.get_int(MOV_ANNOIVA); - const TString4 cod_reg = mov.get(MOV_REG); - const int tipo_reg = tipo_registro(cod_reg, ann_reg); - - // Considera solo iva acquisti o vendite - if (tipo_reg != 1 && tipo_reg != 2) - return FALSE; - - if (app()._annoes > 0) //anno esercizio specificato nella maschera - { - const int annoes = mov.get_int(MOV_ANNOES); - if (annoes != app()._annoes) - return false; - } - - if (!between(mov.get_date(MOV_DATAREG), app()._data_ini, app()._data_fin)) - return false; - - if (!between(mov.get(MOV_TIPO), app()._tipo_ini, app()._tipo_fin)) - return false; - - if (!between(mov.get_long(MOV_CODCF), app()._codice_ini, app()._codice_fin)) - return false; - - return app().codiva_filter(rel); -} - -bool TListaMov_application::filter_func (const TRelation * rel) -{ - const TRectype& mov = rel->curr(LF_MOV); - - if ( (app()._decidi == 2) && (app()._annoes != 0) ) - { - const int annoes = mov.get_int(MOV_ANNOES); - if (annoes != app()._annoes) - return false; - } - - const TString& causale = mov.get(MOV_CODCAUS); - if (!between(causale, app()._causale_ini, app()._causale_fin)) - return false; - - if (app()._scelta_stampa == 0) // Lista movimenti - { - const TString& codreg = mov.get(MOV_REG); - if (!between(codreg, app()._registro_ini, app()._registro_fin)) - return false; - } - else // Lista movimenti sola prima nota - { - const TString& cod_reg = mov.get(MOV_REG); - const int ann_reg = mov.get_int(MOV_ANNOIVA); - const int tipo_reg = tipo_registro(cod_reg, ann_reg); - if (tipo_reg == 1 || tipo_reg == 2) - return false; - } - - if (app()._competence_only && app()._annoes == 0) - { - const TDate datareg = mov.get_date(MOV_DATAREG); - const int annoes = mov.get_int(MOV_ANNOES); - TEsercizi_contabili esc; - // La data di registrazione appartiene allo stesso esercizio della data di competenza - if (esc.date2esc(datareg) == annoes) - return false; - } - - return true; -} - -void TListaMov_application::stampa_errori_rmov() -{ - const TRectype& rec = current_cursor()->curr(LF_RMOV); - int gruppo = rec.get_int(RMV_GRUPPO); - int conto = rec.get_int(RMV_CONTO); - long sottoconto = rec.get_long(RMV_SOTTOCONTO); - int anno = rec.get_int(RMV_ANNOES); - TDate datareg = rec.get_date(RMV_DATAREG); - char sez = rec.get_char(RMV_SEZIONE); - char tipo = rec.get_char(RMV_TIPOC); - int gruppoc = rec.get_int(RMV_GRUPPOC); - int contoc = rec.get_int(RMV_CONTOC); - long sottocontoc = rec.get_long(RMV_SOTTOCONTOC); - char tipoc = rec.get_char(RMV_TIPOCC); - - bool g = FALSE; - - TBill tc (gruppo,conto,sottoconto); - - _nr++; - - if (anno != _annoeser || datareg != _datareg) - set_row(_nr++, FR("@11gUno o piu' campi non sono costanti nella riga dell' operazione")); - if (sez != 'D' && sez != 'A') - set_row(_nr++, FR("@11gIndicato tipo movimento Dare/Avere errato")); - if (tc.empty()) - set_row(_nr++, FR("@11gNon presente codice gruppo/conto/sottoconto")); - if (!tc.ok()) - set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto non corrisponde ad un sottoconto")); - - TRectype pc (LF_PCON); - tc.set(gruppo,0,0l); - if (!tc.read(pc)) - g = TRUE; - tc.set(gruppo,conto,0l); - if (!tc.read(pc)) - set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto non presente in Piano dei Conti")); - else - { - const char t = pc.get_char(PCN_TMCF); - if (t != tipo) - set_row(_nr++, FR("@11gIl tipo C/F indicato non corrisponde a quello presente su Piano dei Conti")); - else - { - tc.set(gruppo,conto,sottoconto); - if (t != 'C' && t != 'F') - { - if (!tc.read(pc) || g ) - set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto non presente in Piano dei Conti")); - else - { - bool sosp = tc.sospeso(); - if (sosp) - set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto sospeso in Piano dei Conti")); - } - } - else - { - TToken_string key; - key.add(t); - key.add(sottoconto); - const TRectype & clifo = cache().get(LF_CLIFO, key); - - if (!clifo.empty()) - { - bool sosp = clifo.get_bool(CLI_SOSPESO); - if (sosp) - set_row(_nr++, FR("@11gCodice C/F sospeso in Anagrafica")); - } - else set_row(_nr++, FR("@11gCodice C/F non presente in Anagrafica")); - if (_registro.not_empty()) //se su mov e' indicato il codice registro - { - TRegistro rg (_registro, _ae); - const int tiporeg = rg.tipo(); - if ((tiporeg == 1 && t != 'C') || (tiporeg == 2 && t != 'F')) - set_row(_nr++, FR("@11gTipo C/F non compatibile con tipo registro")); - } - } - } - } - TString key(30); - - key.format("%d||%d|%d|%ld", anno, gruppo, conto, sottoconto); - - const TRectype & saldi = cache().get(LF_SALDI, key); - - if (saldi.empty()) - set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto non presente in Saldi p.d.c.")); - - if (gruppoc != 0 || contoc != 0 || sottocontoc != 0l) - stampa_errori_contropartita(gruppoc, contoc, sottocontoc, tipoc); -} - -void TListaMov_application::stampa_errori_contropartita(int gruppo, int conto, long sottoconto, char t) -{ - bool g = FALSE; - - TBill tc; - TRectype pc (LF_PCON); - tc.set(gruppo,0,0l); - if (!tc.read(pc)) - g = TRUE; - tc.set(gruppo,conto,0l); - if (!tc.read(pc)) - set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto di contropartita non presente in Piano dei Conti")); - else - { - //t = pc.get_char(PCN_TMCF); - tc.set(gruppo,conto,sottoconto); - if (t != 'C' && t != 'F') - { - if (!tc.read(pc) || g ) - set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto di contropartita non presente in Piano dei Conti")); - else - { - bool sosp = tc.sospeso(); - if (sosp) - set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto di contropartita sospeso in Piano dei Conti")); - } - } - else if (sottoconto != 0l) - { - TToken_string key; - key.add(t); - key.add(sottoconto); - const TRectype & clifo = cache().get(LF_CLIFO, key); - - if (!clifo.empty()) - { - bool sosp = clifo.get_bool(CLI_SOSPESO); - if (sosp) - set_row(_nr++, FR("@11gCodice C/F di contropartita sospeso in Anagrafica")); - } - else set_row(_nr++, FR("@11gCodice C/F di contropartita non presente in Anagrafica")); - } - } -} - -void TListaMov_application::stampa_errori_iva(int* nr, const TRigaiva& riva) -{ - const TRectype& tab_iva = cache().get("%IVA", riva._codiva); - if (!tab_iva.empty()) - { - const bool sosp = tab_iva.get_bool("B2"); - if (sosp) - set_row(++(*nr), FR("@11gCodice IVA sospeso")); - if (_stampa_mess_alleg_iva) - { - const int allc = tab_iva.get_int("S7"); - const int allf = tab_iva.get_int("S8"); - if (allc == 0 || allf == 0) - set_row(++(*nr), FR("@11gSul Codice IVA non e' stato indicato un valore per allegato")); - } - } - else - set_row(++(*nr), FR("@11gCodice IVA non presente in tabella")); - - const int tipodet = riva._tipodet; - const int tipocr = riva._tipocr; - - if (tipodet == 1 || tipodet == 3 || tipodet == 5 || tipodet == 9) - if (_tiporegistro != 2) - set_row(++(*nr), FR("@11gCodice di indetraibilita' errato")); - - if (_tiporegistro == 1) - if (tipocr != 0 && tipocr != 1 && tipocr != 4 && tipocr != 9) - set_row(++(*nr), FR("@11gTipo costo/ricavo non valido")); - - if (_tiporegistro == 2) - if (tipocr != 0 && tipocr != 1 && tipocr != 2 && tipocr != 3 && tipocr != 5 && tipocr != 8 && tipocr != 9) - set_row(++(*nr), FR("@11gTipo costo/ricavo non valido")); -} - -void TListaMov_application::stampa_errori_mov() -{ - long i = _err.first_one(); - if (i != -1) - { - for (; i <= _err.last_one(); i++) - if (_err[i]) - set_row(++_n, "@11g%s", (const char*) get_error(i)); - } -} - -void TListaMov_application::set_page(int file, int count) -{ - switch (_tipo_lista) - { - case movimenti: - if (file == LF_RMOVIVA) - break; - if (file == LF_RMOV) - { - _nr = 1; - const TRectype& rec = current_cursor()->curr(LF_RMOV); - - set_row(_nr,"@3n",FLD(LF_RMOV,RMV_NUMRIG)); - set_row(_nr,"@30g@22s",FLD(LF_RMOV,RMV_DESCR)); - set_row(_nr,"@54g@3,rn",FLD(LF_RMOV,RMV_GRUPPO)); - set_row(_nr,"@58g@3,rn",FLD(LF_RMOV,RMV_CONTO)); - set_row(_nr,"@62g@6,rn",FLD(LF_RMOV,RMV_SOTTOCONTO)); - set_row(_nr,"@69g#.20t",&_descr); - _appoggio = toupper(current_cursor()->curr(LF_RMOV).get_char(RMV_SEZIONE)); - if (_appoggio=='D') - set_row(_nr,"@90g@n",FLD(LF_RMOV,RMV_IMPORTO)); - else - set_row(_nr,"@110g@n",FLD(LF_RMOV,RMV_IMPORTO)); - } - else if (file == LF_MOV) - { - _n = 1; - set_row (_n++,""); - set_row (_n, FR("Operazione n. @14g@7n"), FLD(LF_MOV,MOV_NUMREG)); - set_row (_n, FR("@22gdel@26g@d"),FLD(LF_MOV,MOV_DATAREG)); - set_row (_n, "@37g@36s",FLD(LF_MOV,MOV_DESCR)); - set_row (_n, FR("@75gdoc. @7s"),FLD(LF_MOV,MOV_NUMDOC)); - set_row (_n, FR("@88gdel@92g@d"), FLD(LF_MOV,MOV_DATADOC)); - current_cursor()->curr(LF_MOV).get_int(MOV_ANNOES); // qui verificare - TDate data = current_cursor()->curr(LF_MOV).get_date(MOV_DATAREG); - TDate dcomp = current_cursor()->curr(LF_MOV).get_date(MOV_DATACOMP); - TString16 reg = current_cursor()->curr(LF_MOV).get(MOV_REG); - int anno = current_cursor()->curr(LF_MOV).get_int(MOV_ANNOIVA); - char prov = current_cursor()->curr(LF_MOV).get_char(MOV_PROVVIS); - int tipo = tipo_registro(reg, anno); - - TEsercizi_contabili esc; - esc.date2esc(data); // qui verificare - if ( (tipo == 1) || (tipo == 2) ) - { - set_row (_n, FR("@103greg @3s"),FLD(LF_MOV,MOV_REG)); - set_row (_n, FR("@111gpr @5n"),FLD(LF_MOV,MOV_PROTIVA)); - } - else if (_provvis == 2 && prov >= ' ') - set_row (_n, FR("@103gMov.Provvisorio")); - if (data != dcomp) - set_row (_n, "@119gc.%s", (const char*)dcomp.string(brief, '-')); - //fine - set_row (_n, "@130g@f", FLD(LF_MOV,MOV_STAMPATO)); - } - break; - - default: - break; - } -} - -void TListaMov_application::stampa_intestazione() -{ - set_row (1,""); - if (_tipo_elenco == "C") - set_row (2, FR("@bCliente@8g@6n"), FLD(LF_MOV,MOV_CODCF)); - else - set_row (2, FR("@bFornitore@10g@6n"), FLD(LF_MOV,MOV_CODCF)); - set_row (2, "@b@18g#.35t", &_ragsoc); - set_row (2, FR("@b@54gInd #-.29t #-.10t"), &_indcf, &_civcf); - set_row (2, FR("@b@98gP.I. #11t"), &_paiv); - if (_alleg == 0) - set_row (2, FR("@b@121gAllegato SI")); - else - set_row (2, FR("@b@121gAllegato NO")); - set_row (3, FR("@b@54gCap #5t"), &_capcf); - set_row (3,"@b@64g%s #-.20t Pr #-.5t", - (const char*)_app, &_dencom, &_provcom); - set_row (3, FR("@b@98gC.F. #-16t"), &_cofi); - if (_alleg == 0) - set_row (3, FR("@b@120gRifer@126g#6d"), &_codalleg); -} - -bool TListaMov_application::preprocess_page(int file,int counter) -{ - if (counter) - return TRUE; - - TCursor* cur = current_cursor(); - - switch (_tipo_lista) - { - case movimenti: - if (_scelta_stampa == 0) - { - if (file == LF_MOV) - { - const TRectype& curmov = cur->curr(LF_MOV); - - _tot_avere = 0; - _tot_dare = 0; - _c.destroy(); - _no_preprocess_page = FALSE; - _esiste_riga_iva = FALSE; - _nonesiste_riga_iva = FALSE; - _annoeser = curmov.get_int(MOV_ANNOES); - _datacomp = curmov.get_date(MOV_DATACOMP); - _causale = curmov.get(MOV_CODCAUS); - _registro = curmov.get(MOV_REG); - _anno = curmov.get_int(MOV_ANNOIVA); - _tipodoc = curmov.get(MOV_TIPODOC); - _datareg = curmov.get_date(MOV_DATAREG); - _tipo_elenco = curmov.get(MOV_TIPO); - _codcf = curmov.get_long(MOV_CODCF); - _numero = curmov.get_long(MOV_NUMREG); - _codval = curmov.get(MOV_CODVALI); - _tiporegistro = tipo_registro(_registro, _anno); - - _causale_gia_stampata = FALSE; - TEsercizi_contabili esc; - _ae = esc.date2esc(_datareg); - - if (_registro.not_empty()) //si tratta di fattura - _mov_di_sola_iva = !cur->is_first_match(LF_RMOV); - - _descr_doc = DescrDoc(_tipodoc); - - TRectype da (LF_MOV); - TRectype a (LF_MOV); - if (_annoes != 0) - { - da.put(MOV_ANNOES, _annoes); - a.put(MOV_ANNOES, _annoes); - } - da.put(MOV_CODCAUS, _causale_ini); - da.put(MOV_REG, _registro_ini); - a.put(MOV_CODCAUS, _causale_fin); - a.put(MOV_REG, _registro_fin); - - if ((curmov >= da) && (curmov <= a)) - { - const TRectype& caus = cache().get(LF_CAUSALI, _causale); - - _reg_causale = caus.get(CAU_REG); - _descr_causale = caus.get(CAU_DESCR); - _alleg_causale = caus.get_bool(CAU_ALLEG); - _tipodocumento = caus.get(CAU_TIPODOC); - - if (_controllo_mov_errati == 1 || _controllo_mov_errati == 2) - { - bool controlla = segnala_errori_primariga(); - bool verifica = (_stampa_parte_iva && segnala_errori_iva()) || segnala_errori_ogniriga(); - - if ((_controllo_mov_errati == 1 && controlla) - || _controllo_mov_errati == 2 ) - { - stampa_errori_mov(); - return TRUE; - } - else if (_controllo_mov_errati == 1 && !verifica) - return FALSE; - else return TRUE; - } - else return TRUE; - } - } - else if (file == LF_RMOV) - { - if (!_causale_gia_stampata) - { - set_row(_nr,"@4g%3s", (const char*) _causale); - set_row(_nr,"@8g%-.20s", (const char*) _descr_causale); - _causale_gia_stampata = true; - } - const TRectype& currig = cur->curr(LF_RMOV); - const int gruppo = currig.get_int(RMV_GRUPPO); - const int conto = currig.get_int(RMV_CONTO); - const long sottoconto = currig.get_long(RMV_SOTTOCONTO); - const char tipoc = currig.get_char(RMV_TIPOC); - _descr = DescrConto(gruppo, conto, sottoconto, tipoc); - _alleg = AllegClifo(gruppo, conto, sottoconto); - _importo = currig.get_real(RMV_IMPORTO); - _appoggio = currig.get_char(RMV_SEZIONE); - if (!_no_preprocess_page) - { - if (_appoggio=='D') - { - _tot_dare_generale += _importo; - _tot_dare += _importo; - } - else - { - _tot_avere += _importo; - _tot_avere_generale += _importo; - } - if (_controllo_mov_errati != 3) - stampa_errori_rmov(); - } - return TRUE; - } - else if ( _stampa_parte_iva && file == LF_RMOVIVA) - { - const TRectype& iva = cur->curr(LF_RMOVIVA); - _c.add_riga(iva); - return TRUE; - } - } - else //_scelta_stampa == 1 - { - if (file == LF_MOV) - { - _tot_avere = 0; - _tot_dare = 0; - _no_preprocess_page = FALSE; - - const TRectype& curmov = cur->curr(LF_MOV); - _causale = curmov.get(MOV_CODCAUS); - _registro = curmov.get(MOV_REG); - _anno = curmov.get_int(MOV_ANNOES); - _tipodoc = curmov.get(MOV_TIPODOC); - - _causale_gia_stampata = FALSE; - - TRectype da (LF_MOV); - TRectype a (LF_MOV); - if (_annoes != 0) - { - da.put(MOV_ANNOES, _annoes); - a.put(MOV_ANNOES, _annoes); - } - da.put(MOV_CODCAUS, _causale_ini); - a.put(MOV_CODCAUS, _causale_fin); - - if ((curmov >= da) && (curmov <= a)) - { - const TRectype & caus = cache().get(LF_CAUSALI, _causale); - - _descr_causale = caus.get(CAU_DESCR); - _alleg_causale = caus.get_bool(CAU_ALLEG); - _tipodocumento = caus.get(CAU_TIPODOC); - - _tiporegistro = tipo_registro (_registro, _anno); - - if ((_tiporegistro != 1)&&(_tiporegistro != 2))//se si tratta di un movimento di sola prima nota - return TRUE; - } - } - else if (file == LF_RMOV) - { - if (!_causale_gia_stampata) - { - set_row(_nr,"@4g%3s", (const char*) _causale); - set_row(_nr,"@8g%-.20s", (const char*) _descr_causale); - _causale_gia_stampata = TRUE; - } - const TRectype& rmov = current_cursor()->curr(LF_RMOV); - const int gruppo = rmov.get_int(RMV_GRUPPO); - const int conto = rmov.get_int(RMV_CONTO); - const long sottoconto = rmov.get_long(RMV_SOTTOCONTO); - const char tipoc = rmov.get_char(RMV_TIPOC); - _descr = DescrConto(gruppo, conto, sottoconto, tipoc); - _importo = rmov.get_real(RMV_IMPORTO); - _appoggio = toupper(rmov.get_char(RMV_SEZIONE)); - if (!_no_preprocess_page) - { - if (_appoggio=='D') - { - _tot_dare_generale += _importo; - _tot_dare += _importo; - } - else - { - _tot_avere += _importo; - _tot_avere_generale += _importo; - } - } - return TRUE; - } - } - break; - - case fatture: - { - if (file == LF_MOV) - { - const TRectype& curmov = current_cursor()->curr(LF_MOV); - const int anno = curmov.get_int(MOV_ANNOIVA); - const TString4 codreg = curmov.get(MOV_REG); - _numr = curmov.get_long(MOV_NUMREG); - _tipo_elenco = curmov.get(MOV_TIPO); - _codcf = curmov.get_long(MOV_CODCF); - const int tiporeg = tipo_registro (codreg, anno); - const TString8 attreg = AttivitaRegistro (codreg, anno); - - if (tiporeg == 1 || tiporeg == 2)//se si tratta di un movimento iva - { - _tipoatt = TipoAttivita(attreg, get_firm()); - _tipo_elenco = curmov.get(MOV_TIPO); - _codcf = curmov.get_long(MOV_CODCF); - _codcaus = curmov.get(MOV_CODCAUS); - _tipodoc = curmov.get(MOV_TIPODOC); - _codval = curmov.get(MOV_CODVALI); - _totdoc = curmov.get_real(MOV_TOTDOC); - _ritenute = curmov.get_real(MOV_RITFIS) + curmov.get_real(MOV_RITSOC); - - if (_tipo_elenco != _tipo_clifo_prec && _tipo_clifo_prec != "") - printer().formfeed(); - - TRectype da (LF_MOV); - TRectype a (LF_MOV); - - if (_annoes != 0) //anno specificato nella maschera - { - da.put(MOV_ANNOES, _annoes); - a.put(MOV_ANNOES, _annoes); - } - - da.put(MOV_CODCAUS, _causale_ini); - a.put(MOV_CODCAUS, _causale_fin); - - if (_data_ini.ok()) - da.put(MOV_DATAREG, _data_ini); - da.put(MOV_TIPO, _tipo_ini); - if (_codice_ini != 0) - da.put(MOV_CODCF, _codice_ini); - if (_data_fin.ok()) - a.put(MOV_DATAREG, _data_fin); - a.put(MOV_TIPO, _tipo_fin); - if (_codice_fin != 0) - a.put(MOV_CODCF, _codice_fin); - - if ((curmov >= da) && (curmov <= a)) - { - compila_clifo(); - compila_comuni(); - - if ((_tipo_clifo_prec == "")&&(_codcf_prec == 0l)) - { - _tipo_clifo_prec = _tipo_elenco; - _codcf_prec = _codcf; - stampa_intestazione(); - } - else - if (_tipo_clifo_prec == _tipo_elenco && _codcf_prec == _codcf) - _settata_prima_riga = FALSE; - else - { - if ( _salto_pagina && _tipo_clifo_prec == _tipo_elenco ) - printer().formfeed(); - stampa_intestazione(); - _tipo_clifo_prec = _tipo_elenco; - _codcf_prec = _codcf; - _settata_prima_riga = FALSE; - } - return TRUE; - } - } - } - else if (file == LF_RMOVIVA) - { - const TRectype& rmov = current_cursor()->curr(LF_RMOV); - int gruppo = rmov.get_int(RMV_GRUPPO); - int conto = rmov.get_int(RMV_CONTO); - - TToken_string key; - key.add(gruppo); - key.add(conto); - key.add(""); - const TRectype & pcon = cache().get(LF_PCON, key); - - _ricser = pcon.get_int(PCN_RICSER); - - _simbolo = SimboloValuta(_codval); - _allegb = CausAlleg(_codcaus); - _descr_doc = DescrDoc(_tipodoc); - //_intra = cur->curr(LF_RMOVIVA).get_bool(RMI_INTRA); - - if (!_settata_prima_riga) - { - reset_print(); - set_row(1, ""); - set_row(2,"@7,rn",FLD(LF_MOV,MOV_NUMREG)); - set_row(2,"@8g@d",FLD(LF_MOV,MOV_DATAREG)); - set_row(2,"@17g@3,rs",FLD(LF_MOV,MOV_REG)); - set_row(2,"@20g@5,rn",FLD(LF_MOV,MOV_PROTIVA)); - set_row(2,"@26g@2,rn",FLD(LF_MOV,MOV_MESELIQ)); - - const TString8 protiva = cur->curr(LF_MOV).get(MOV_PROTIVA); - TString8 uprotiva = cur->curr(LF_MOV).get(MOV_UPROTIVA); - - if (uprotiva.full()) - { - int i; - for (i = 0; protiva[i] && (protiva[i] == uprotiva[i]); i++); - uprotiva = uprotiva.mid(i); - set_row(2, "@24g/@25g%s", (const char*) uprotiva); - } - set_row(2, "@31g@d", FLD(LF_MOV,MOV_DATADOC)); - set_row(2,"@40g@7,rs",FLD(LF_MOV,MOV_NUMDOC)); - set_row(2,"@48g@3s",FLD(LF_MOV,MOV_CODCAUS)); - set_row(2,"@52g@2s",FLD(LF_MOV,MOV_TIPODOC)); - set_row(2,"@55g%-.12s", (const char *)_descr_doc); - set_row(2,"@67g@n",FLD(LF_MOV,MOV_TOTDOC)); - set_row(2,"@84g@n",FLD(LF_RMOVIVA,RMI_IMPONIBILE)); - set_row(2,"@101g@4s",FLD(LF_RMOVIVA,RMI_CODIVA)); - set_row(2,"@105g@1s",FLD(LF_RMOVIVA,RMI_TIPODET)); - if (_tipoatt == "E") - { - if (_ricser == 1) - set_row(2,"@109g1"); - else if (_ricser == 2) - set_row(2,"@109g2"); - } - set_row(2,"@111g@f",FLD(LF_RMOVIVA,RMI_INTRA)); - set_row(2,"@114g@n",FLD(LF_RMOVIVA,RMI_IMPOSTA)); - if (_allegb) - set_row(2,"@131g*"); - - incrementa_totali(); - _settata_prima_riga = TRUE; - ++_documenti; - } - else if (_settata_prima_riga) - { - reset_print(); - set_row(1,"@84g@n", FLD(LF_RMOVIVA,RMI_IMPONIBILE)); - set_row(1,"@101g@4s", FLD(LF_RMOVIVA,RMI_CODIVA)); - set_row(1,"@105g@1s",FLD(LF_RMOVIVA,RMI_TIPODET)); - set_row(1,"@114g@n", FLD(LF_RMOVIVA,RMI_IMPOSTA)); - incrementa_totali(); - } - return TRUE; - } - } - break; - - default: - break; - } - return FALSE; -} - -void TListaMov_application::print_intra(int& rr) -{ - const TRectype& mov = current_cursor()->curr(LF_MOV); - const real corrval = mov.get_real(MOV_CORRVALUTA); - if (corrval != ZERO) - { - const TString16 codval = mov.get(MOV_CODVALI); - TString80 str; - - rr++; - - const TCurrency cl(mov.get_real(MOV_CORRLIRE)); - str = cl.string(TRUE); str.right_just(19); - set_row(rr,FR("Corrispettivo@14g%s"), (const char*)str); - - const TCurrency cv(corrval, codval); - str = cv.string(TRUE); str.right_just(19); - set_row(rr,FR("@34gCorr.in valuta@49g%s"), (const char*)str); - - set_row(rr,"@70g%-3s", (const char*)codval); - } -} - -print_action TListaMov_application::postprocess_page(int file,int count) -{ - if (count) - { - reset_print(); - return NEXT_PAGE; - } - - switch (_tipo_lista) - { - case movimenti: - if (file == LF_RMOV) - { - force_setpage(); - break; - } - if (file == LF_MOV) - { - reset_print(); - _err.reset(); - int n = 1; - int r = 0; - if (_scelta_stampa == 0) - if (_registro.not_empty() && _mov_di_sola_iva) - { - compila_clifo(); - set_row(++r, "@1g%3s %-50s %6ld %-50s", (const char*)_causale, (const char*)_descr_causale, _codcf, (const char*)_ragsoc); - } - if ( _scelta_stampa == 0 && _stampa_parte_iva ) - { - for (int j = 0; j < _c.items(); j++) - { - const TRigaiva& riga = (const TRigaiva&)_c[j]; - //r = j+1; - r++; - set_row(r, FR("Imponibile@11g%r"), &riga._imponibile); - set_row(r, FR("@31gImposta@38g%r"), &riga._imposta); - set_row(r, FR("@58gCodice Iva@69g%3s"), (const char*)riga._codiva); - set_row(r, "@76g%s", (const char*)riga.descr_det()); - - if (j == 0) // Se e' la prima riga che stampa - { - const int meseliq = current_cursor()->file(LF_MOV).get_int(MOV_MESELIQ); - if (meseliq > 0) // Stampa il mese liquidazione - set_row(r,FR(" Mese liq. %2d"), meseliq); - } - if (riga._intra) - set_row(r, FR("@111gOper.intrac.")); - if (_controllo_mov_errati != 3) - if (!_esiste_riga_iva && ! _nonesiste_riga_iva) - stampa_errori_iva(&r, riga); - } - - print_intra(r); - if (_esiste_riga_iva) - set_row(++r, FR("@11gPresenti righe IVA in una registrazione senza IVA")); - if (_nonesiste_riga_iva) - set_row(++r, FR("@11gNon presente alcuna riga IVA in una registrazione con IVA")); - _c.destroy(); - } //if(_scelta_stampa==0... - - if (r > 0) - n = ++r; - - TRecnotype pos, items; - bool FINITO = FALSE; - if ((_scelta_stampa == 0)&&(_controllo_mov_errati != 3)&&(_tot_dare != _tot_avere)) - set_row(n++, FR("@11gIl movimento risulta sbilanciato")); - - pos = current_cursor()->pos(); - items = current_cursor()->items(); - - FINITO = (pos == items-1); - - _datareg = current_cursor()->file(LF_MOV).get_date(MOV_DATAREG); - _numreg = current_cursor()->file(LF_MOV).get_long(MOV_NUMREG); - - TDate datarec (_datareg); - if (!FINITO) - { - TCursor * cur = current_cursor(); - cur->save_status(); - ++(*cur); - datarec = cur->file(LF_MOV).get_date(MOV_DATAREG); - --(*cur); - cur->restore_status(); - } - - _tot_avere_giornaliero += _tot_avere; - _tot_dare_giornaliero += _tot_dare; - - //stampa i totali giornalieri - if ( FINITO || - (_datareg != datarec)||(_numreg == _numreg_fin)) - { - if (( _scelta_stampa == 0 && _controllo_mov_errati != 1 && _decidi == 2) || (_scelta_stampa == 1 && _decidi == 2)) - { - set_row(n, FR("@b@60gTotali del giorno %s"), _datareg.string()); - set_row(n++, "@b@90g%r %r", &_tot_dare_giornaliero, &_tot_avere_giornaliero); - _tot_avere_giornaliero = 0; - _tot_dare_giornaliero = 0; - } - if ((_scelta_stampa == 0 && _controllo_mov_errati != 1 && FINITO) || (_scelta_stampa == 1 && FINITO)) - - { - set_row(n++,""); - set_row(n, FR("@b@60gTotale generale")); - set_row(n++, "@b@90g%r %r", &_tot_dare_generale, &_tot_avere_generale); - } - } - - - if (n == 1) - { - force_setpage(); //probabilmente e' inutile - return NEXT_PAGE; - } - else - { - _no_preprocess_page = TRUE; - force_setpage(FALSE); - return REPEAT_PAGE; - } - } - break; - case fatture: - if (file == LF_MOV) - { - reset_print(); - TCursor* cur = current_cursor(); - int rr = 1; - print_intra(rr); - _totdocumenti += _totdoc; - _totritenute += _ritenute; - TRecnotype pos, items; - bool FINITO = FALSE; - - pos = current_cursor()->pos(); - items = current_cursor()->items(); - - FINITO = (pos == items-1); - - if (!FINITO) - { - cur->save_status(); - ++(*cur); - // long numrsucc = cur->file(LF_MOV).get_long(MOV_NUMREG); - _tipoelsucc = cur->curr(LF_MOV).get(MOV_TIPO); - _codclifosucc = cur->curr(LF_MOV).get_long(MOV_CODCF); - --(*cur); - cur->restore_status(); - } - - if (FINITO || (_tipo_elenco != _tipoelsucc)||(_codcf != _codclifosucc)) - { - set_row(rr++,""); - if (_tipo_elenco == "C") - set_row(rr++, FR("@bTotali Cliente@18gDocumenti Totale documenti@45gRitenute/IVA CEE@68gImponibile@86gImposta@102gop. esenti@119gop. non imp.")); - else - set_row(rr++, FR("@bTotali Fornitore@18gDocumenti Totale documenti@45gRitenute/IVA CEE@68gImponibile@86gImposta@102gop. esenti@119gop. non imp.")); - set_row(rr, "@b@18g%9d", _documenti); - set_row(rr, "@b@28g%r", &_totdocumenti); - set_row(rr, "@b@45g%r", &_totritenute); - set_row(rr, "@b@62g%r", &_totimponibile); - set_row(rr, "@b@79g%r", &_totimposta); - set_row(rr, "@b@96g%r", &_op_esenti); - set_row(rr, "@b@113g%r", &_op_non_imp); - - //incrementa i totali generali di stampa!!! - _gen_documenti += _documenti; - _gen_totdocumenti += _totdocumenti; - _gen_totritenute += _totritenute; - _gen_totimponibile += _totimponibile; - _gen_totimposta += _totimposta; - _gen_op_esenti += _op_esenti; - _gen_op_non_imp += _op_non_imp; - - _totimposta = 0; - _totimponibile = 0; - _op_esenti = 0; - _op_non_imp = 0; - _documenti = 0; - _totdocumenti = 0; - _totritenute = 0; - //return REPEAT_PAGE; - } - - if (FINITO) //ha veramente finito questa stupida stampa: stampa i totali generali! - { - const TString& blank = EMPTY_STRING; - set_row(rr++,(const char*)blank); - set_row(rr++,(const char*)blank); - set_row(rr++,(const char*)blank); - - set_row(rr++, FR("@bTOTALI GENERALI @18gDocumenti Totale documenti@45gRitenute/IVA CEE@68gImponibile@88gImposta@102gop. esenti@119gop. non imp.")); - - set_row(rr, "@b@18g%9d", _gen_documenti); - set_row(rr, "@b@28g%r", &_gen_totdocumenti); - set_row(rr, "@b@45g%r", &_gen_totritenute); - set_row(rr, "@b@62g%r", &_gen_totimponibile); - set_row(rr, "@b@79g%r", &_gen_totimposta); - set_row(rr, "@b@96g%r", &_gen_op_esenti); - set_row(rr, "@b@113g%r", &_gen_op_non_imp); - - //alla fine della stampa azzera i totali generali - _gen_documenti = 0; - _gen_totdocumenti = 0; - _gen_totritenute = 0; - _gen_totimponibile = 0; - _gen_totimposta = 0; - _gen_op_esenti = 0; - _gen_op_non_imp = 0; - } - - if (rr > 1) - return REPEAT_PAGE; - } - break; - default: - break; - } - - - return NEXT_PAGE; -} - -print_action TListaMov_application::postprocess_print(int file,int count) -{ - if (count) - { - reset_print(); - return NEXT_PAGE; - } - - switch (_tipo_lista) - { - case movimenti: - break; - - case fatture: - break; - - default: - break; - } - return NEXT_PAGE; -} - -//cerca errori sulla testata (MOV) -bool TListaMov_application::segnala_errori_primariga() -{ - TEsercizi_contabili esc; - const int ae = esc.date2esc(_datacomp); - - if (_ae == 0) - _err.set(0l); - - if (_registro.not_empty()) //si tratta di fattura - if (_datareg.year() != _anno) - _err.set(1); - - if ( _scelta_stampa == 0 && _stampa_anno_comp ) - if (_ae != _annoeser) - { - if (_annoes) //specificato l'anno nella maschera - _err.set(2); - else _err.set(3); - } - else - if (_datacomp != _datareg) // altrimenti se gli esercizi corrispondono controlla datacomp e dataop - _err.set(26); - - if (ae) - { - const int ar = esc.date2esc(_datareg); // Esercizio in corso - const int pr = esc.pred(ar); // Esercizio precedente - if (ae != ar && ae != pr) - _err.set(4); - } - else - _err.set(5); - - if (_annoeser != ae) - _err.set(6); - - if (_tipodoc != "") - if (!RicercaDoc(_tipodoc)) - _err.set(11); - - if (_causale.not_empty()) //se indicata la causale - { - const TRectype & caus = cache().get(LF_CAUSALI, _causale); - if (caus.empty()) - _err.set(7); - else - { - bool sos = caus.get_bool(CAU_SOSPESO); - if (sos) - _err.set(8); - if (_stampa_mess_alleg_iva && _alleg_causale) - _err.set(9); - } - if (_tipodoc != _tipodocumento) - _err.set(10); - if (_registro != _reg_causale) - _err.set(12); - - if (_registro.not_empty()) //movimento iva (fatture) - { - TRegistro rg (_registro, _datareg.year()); - if (rg.name().empty()) - _err.set(13); - else - { - const int tipo = rg.tipo(); -// TipoIVA i = nessuna_iva; - const TRectype& tabtpd = cache().get("%TPD", _tipodoc); - if (!tabtpd.empty()) - { - const bool cor = tabtpd.get_bool("B0"); - const int i = tabtpd.get_int("I0"); - if (i == 1 && tipo != 1) - _err.set(15); - if (i == 2 && tipo != 2) - _err.set(15); - if (i == 9 && (tipo != 1 && tipo != 2)) - _err.set(15); - if (cor && !rg.corrispettivi()) - _err.set(15); - if (!cor) - if (_codcf == 0l) - _err.set(16); - } - if (_codcf != 0l) - { - if ((tipo == 1 && _tipo_elenco != "C") || (tipo == 2 && _tipo_elenco != "F")) - _err.set(17); - - TToken_string key; - key.add(_tipo_elenco); - key.add(_codcf); - const TRectype & clifo = cache().get(LF_CLIFO, key); - - if (!clifo.empty()) - { - bool sosp = clifo.get_bool(CLI_SOSPESO); - if (sosp) - _err.set(18); - bool occ = clifo.get_bool(CLI_OCCAS); - char alleg = clifo.get_char(CLI_ALLEG); - long calleg = clifo.get_long(CLI_CODALLEG); - if (!occ) - { - if (_stampa_mess_alleg_iva && alleg == '1') - _err.set(19); - if (calleg != 0l) - { - if (calleg == _codcf) - _err.set(20); - TToken_string key; - key.add(_tipo_elenco); - key.add(calleg); - const TRectype & clifo = cache().get(LF_CLIFO, key); - if (!clifo.empty()) - { - bool sospall = clifo.get_bool(CLI_SOSPESO); - long codall = clifo.get_long(CLI_CODALLEG); - char alleg = clifo.get_char(CLI_ALLEG); - if (sospall) - _err.set(21); - if (codall != 0l) - _err.set(22); - if (_stampa_mess_alleg_iva && alleg == '1') - _err.set(23); - } - else _err.set(24); - } - } - } - else _err.set(25); - } - } - } - } - if (_err.ones()) - return TRUE; - - return FALSE; -} - -//controlli sulla contropartita -bool TListaMov_application::contropartita(int gruppo, int conto, long sottoconto, char t) -{ - TBill tc; - TRectype pc (LF_PCON); - tc.set(gruppo,0,0l); - if (!tc.read(pc)) - return TRUE; - tc.set(gruppo,conto,0l); - if (!tc.read(pc)) - return TRUE; - //else t = pc.get_char(PCN_TMCF); - tc.set(gruppo,conto,sottoconto); - if (t != 'C' && t != 'F') - { - if (!tc.read(pc)) - return TRUE; - else - { - bool sosp = tc.sospeso(); - if (sosp) - return TRUE; - } - } - else if (sottoconto != 0l) - { - TToken_string key; - key.add(t); - key.add(sottoconto); - const TRectype & clifo = cache().get(LF_CLIFO, key); - - if (!clifo.empty()) - { - bool sosp = clifo.get_bool(CLI_SOSPESO); - if (sosp) - return TRUE; - } - else - return TRUE; - } - return FALSE; -} - -//guarda se c'e' almeno un errore su almeno una riga (rmov) -bool TListaMov_application::segnala_errori_ogniriga() -{ - TLocalisamfile& rmov = current_cursor()->file(LF_RMOV); - int gruppo, conto, anno, gruppoc, contoc; - long sottoconto, sottocontoc; - TDate datareg; - char sez, tipo, t, tipoc; - real importo; - real dare, avere; - - if (current_cursor()->is_first_match(LF_RMOV)) - { - dare = avere = ZERO; - TRecnotype nrec = rmov.recno(); - rmov.zero(); - rmov.setkey(1); - rmov.put(RMV_NUMREG, _numero); - TRectype recc (rmov.curr()); - for (rmov.read(_isgteq); !rmov.eof() ;rmov.next()) - { - TRectype rec (rmov.curr()); - if (rec > recc) break; - gruppo = rec.get_int(RMV_GRUPPO); - conto = rec.get_int(RMV_CONTO); - sottoconto = rec.get_long(RMV_SOTTOCONTO); - gruppoc = rec.get_int(RMV_GRUPPOC); - contoc = rec.get_int(RMV_CONTOC); - sottocontoc = rec.get_long(RMV_SOTTOCONTOC); - tipoc = rec.get_char(RMV_TIPOCC); - anno = rec.get_int(RMV_ANNOES); - datareg = rec.get_date(RMV_DATAREG); - sez = rec.get_char(RMV_SEZIONE); - tipo = rec.get_char(RMV_TIPOC); - importo = rec.get_real(RMV_IMPORTO); - - if (sez == 'D') - dare += importo; - if (sez == 'A') - avere += importo; - - TBill tc (gruppo,conto,sottoconto); - - if (gruppoc != 0 || contoc != 0 || sottocontoc != 0l) - if (contropartita(gruppoc, contoc, sottocontoc, tipoc)) - { - rmov.readat(nrec); - return true; - } - - if (anno != _annoeser || datareg != _datareg) - { - rmov.readat(nrec); - return true; - } - if (sez != 'D' && sez != 'A') - { - rmov.readat(nrec); - return true; - } - if (tc.empty()) - { - rmov.readat(nrec); - return true; - } - if (!tc.ok()) - { - rmov.readat(nrec); - return true; - } - TRectype pc (LF_PCON); - tc.set(gruppo,0,0l); - - if (!tc.read(pc)) - { - rmov.readat(nrec); - return true; - } - tc.set(gruppo,conto,0l); - if (!tc.read(pc)) - { - rmov.readat(nrec); - return true; - } - else t = pc.get_char(PCN_TMCF); - if (t != tipo) - { - rmov.readat(nrec); - return true; - } - tc.set(gruppo,conto,sottoconto); - if (t != 'C' && t != 'F') - { - if (!tc.read(pc)) - { - rmov.readat(nrec); - return true; - } - else - { - bool sosp = tc.sospeso(); - if (sosp) - { - rmov.readat(nrec); - return true; - } - } - } - else - { - TToken_string key; - key.add(t); - key.add(sottoconto); - const TRectype & clifo = cache().get(LF_CLIFO, key); - - if (!clifo.empty()) - { - bool sosp = clifo.get_bool(CLI_SOSPESO); - if (sosp) - { - rmov.readat(nrec); - return true; - } - } - else - { - rmov.readat(nrec); - return true; - } - if (_registro.not_empty()) //se su mov e' indicato il codice registro - { - TRegistro rg (_registro, _ae); - const int tiporeg = rg.tipo(); - if ((tiporeg == 1 && t != 'C') || (tiporeg == 2 && t != 'F')) - { - rmov.readat(nrec); - return true; - } - } - } - TLocalisamfile saldi(LF_SALDI); - saldi.setkey(1); - saldi.zero(); - saldi.put(SLD_ANNOES,anno); - saldi.put(SLD_GRUPPO,gruppo); - saldi.put(SLD_CONTO, conto); - saldi.put(SLD_SOTTOCONTO,sottoconto); - saldi.put(SLD_FLSCA, ""); - - if (saldi.read() != NOERR) - { - rmov.readat(nrec); - return true; - } - } //for - if (dare != avere) - { - rmov.readat(nrec); - return true; - } - rmov.readat(nrec); - } - return false; -} - -bool TListaMov_application::segnala_errori_iva() -{ - TLocalisamfile& rmoviva = current_cursor()->file(LF_RMOVIVA); - const TRectype& mv = current_cursor()->curr(LF_RMOV); - - if (current_cursor()->is_first_match(LF_RMOVIVA)) - { - const TRecnotype nrec = rmoviva.recno(); - rmoviva.setkey(1); - rmoviva.zero(); - rmoviva.put(RMI_NUMREG, _numero); - const TRectype& rec = rmoviva.curr(); - const TRectype recc (rec); - for (rmoviva.read(_isgteq); !rmoviva.eof() ;rmoviva.next()) - { - if (rec > recc) - break; - if (_registro.empty()) - { - rmoviva.readat(nrec); - _esiste_riga_iva = true; - return true; - } - const TString4 cod = rec.get(RMI_CODIVA); - real percind; - const int tipodet = get_tipodet_from_rmi(rec, mv, percind); - const int tipocr = rec.get_int(RMI_TIPOCR); - const TRectype& tab_iva = cache().get("%IVA", cod); - if (!tab_iva.empty()) - { - int allc = tab_iva.get_int("S7"); - int allf = tab_iva.get_int("S8"); - bool s = tab_iva.get_bool("B2"); - if (s) - { - rmoviva.readat(nrec); - return true; - } - if (_stampa_mess_alleg_iva) - if (allc == 0 || allf == 0) - { - rmoviva.readat(nrec); - return true; - } - } - else - { - rmoviva.readat(nrec); - return true; - } - if (tipodet == 1 || tipodet == 3 || tipodet == 5 || tipodet == 9) - if (_tiporegistro != 2) - { - rmoviva.readat(nrec); - return true; - } - if (_tiporegistro == 1) - if (tipocr != 0 && tipocr != 1 && tipocr != 4 && tipocr != 9) - { - rmoviva.readat(nrec); - return true; - } - if (_tiporegistro == 2) - if (tipocr != 0 && tipocr != 1 && tipocr != 2 && tipocr != 3 && tipocr != 5 && tipocr != 8 && tipocr != 9) - { - rmoviva.readat(nrec); - return true; - } - } - rmoviva.readat(nrec); - } - else if (_registro.not_empty()) //cioe' si tratta di fattura - { - _nonesiste_riga_iva = true; - return true; - } - return false; -} - -void TListaMov_application::incrementa_totali() -{ - const TRectype& rmoviva = current_cursor()->curr(LF_RMOVIVA); - const real imponibile = rmoviva.get_real(RMI_IMPONIBILE); - const real imposta = rmoviva.get_real(RMI_IMPOSTA); - const TString4 codiva = rmoviva.get(RMI_CODIVA); - - const TRectype& tabiva = cache().get("%IVA", codiva); - if (_tipo_elenco == "C") - { - const int colonna = tabiva.get_int("S7"); - if ((colonna == 1)||(colonna == 3)) - _totimposta += imposta; - - if (colonna == 1) - _totimponibile += imponibile; - else - { - if (colonna == 3) - _op_esenti += imponibile; - else - { - TString msg; msg << TR("Codice IVA senza colonna allegato clienti '") << codiva << "' considerata non imponibile."; - xvtil_statbar_set(msg); - _op_non_imp += imponibile; // 14-02-2013 Il default è ora questo (Sile) - } - } - } - else - { - const int colonna = tabiva.get_int("S8"); - if ((colonna == 1)||(colonna == 3)||(colonna == 4)) - _totimposta += imposta; - switch (colonna) - { - case 1: _totimponibile += imponibile; break; - case 3: _op_esenti += imponibile; break; - case 4: _op_non_imp += imponibile; break; - default: - _op_non_imp += imponibile; // 14-02-2013 Il default è ora questo (Sile) - TString msg; msg << TR("Codice IVA senza colonna allegato fornitori '") << codiva << "' considerata non imponibile."; - xvtil_statbar_set(msg); - break; - } - } -} - -void TListaMov_application::filtra_cursore_provvisori(TCursor* cur) const -{ - TString filter; - switch (_provvis) - { - case 1: filter = "(PROVVIS=\"\")"; break; //normale - case 2: filter = ""; break; //globale - default: filter = "(PROVVIS!=\"\")"; break; //solo provvisori - } - cur->setfilter(filter); -} - -void TListaMov_application::imposta_parametri_stampa(const TMask& msk) -{ - set_magic_currency(TRUE); - - reset_files(); - _curr1->set_filterfunction (filter_func); - _curr2->set_filterfunction (filter_func); - _curr3->set_filterfunction (filter_func_fatture); - switch (_tipo_lista) - { - case movimenti: - { - _scelta_stampa = msk.get_int(F_MOVIMENTI); - _annoes = msk.get_int (F_ANNO); - _decidi = msk.get_int(F_DECIDI); - _causale_ini = msk.get(F_CAUSALEINI); - _causale_fin = msk.get(F_CAUSALEFIN); - if (_scelta_stampa == 0) - { - _registro_ini = msk.get(F_REGISTROINI); - _registro_fin = msk.get(F_REGISTROFIN); - } - _numreg_ini = msk.get_long(F_NUMEROINI); - _numreg_fin = msk.get_long(F_NUMEROFIN); - _data_ini = msk.get(F_DATAINI); - _data_fin = msk.get(F_DATAFIN); - _provvis = msk.get_int(F_STAMPAMOVP); - _competence_only = msk.get_bool(F_COMPETENZA); - - TRectype da (LF_MOV), a(LF_MOV); - if (_decidi == 1) - { - select_cursor(_cur1); - filtra_cursore_provvisori(_curr1); - - da.put(MOV_NUMREG, _numreg_ini); - a.put(MOV_NUMREG, _numreg_fin); - } - else - { - select_cursor(_cur2); - filtra_cursore_provvisori(_curr2); - - if (_data_ini.ok()) - da.put(MOV_DATAREG, _data_ini); - if (_data_fin.ok()) - a.put(MOV_DATAREG, _data_fin); - } - current_cursor()->setregion(da,a); - add_file(LF_MOV); - add_file(LF_RMOV,LF_MOV); - add_file(LF_RMOVIVA,LF_MOV); - } - break; - - case fatture: - { - _noseparator = msk.get_bool(F_SEPARATOR); - TString tipo = msk.get(F_TIPOELENCO); - - _data_ini = msk.get(F_DATAINI); - _data_fin = msk.get(F_DATAFIN); - _annoes = msk.get_int(F_ANNO); - _causale_ini = msk.get(F_DACODCAUS); - _causale_fin = msk.get(F_ACODCAUS); - _dacodiva = msk.get(F_DACODIVA); - _acodiva = msk.get(F_ACODIVA); - - if (tipo=="C" || tipo=="F") - { - _codice_ini = atol(msk.get(F_CODICEINI)); - _codice_fin = atol(msk.get(F_CODICEFIN)); - } - else - { - _codice_ini = atol(msk.get(F_CODICEINI1)); - _codice_fin = atol(msk.get(F_CODICEFIN1)); - } - - if (tipo == "E") - { - _tipo_ini = "C"; - _tipo_fin = "F"; - } - else - { - _tipo_ini = tipo; - _tipo_fin = tipo; - } - select_cursor(_cur3); - _curr3->setfilter(""); - TRectype da(LF_MOV), a(LF_MOV); - if (_codice_ini != 0) - da.put(MOV_CODCF, _codice_ini); - a.put(MOV_TIPO, _tipo_fin); - if (_codice_fin != 0) - a.put(MOV_CODCF, _codice_fin); - da.put(MOV_TIPO, _tipo_ini); - current_cursor()->setregion(da,a); - add_file(LF_MOV); - add_file(LF_RMOVIVA,LF_MOV); - } - break; - - default: - break; - } - init_print(msk); -} - -bool TListaMov_application::set_print(int) -{ - const char* masc; - switch(toupper(_tipoc)) - { - case 'C': - masc = "cg3100b"; - _tipo_lista = fatture; - break; - case 'M': - default : - masc = "cg3100a"; - _tipo_lista = movimenti; - break; - } - - TMask msk(masc); - if (main_app().has_module(CMAUT)) - msk.show(-4); - else - { - msk.hide(-4); - msk.reset(-4); - } - msk.set_handler(F_ANNO, annoes_handler); - msk.set_handler(F_DATAINI, data_inizio); - msk.set_handler(F_DATAFIN, data_fine); - - while (msk.run() == K_ENTER) - { - imposta_parametri_stampa(msk); - print(); - - msk.reset(-5); - } - return false; -} - - -bool TListaMov_application::user_create() -{ - _relmov1 = new TRelation (LF_MOV); - _relmov1->add(LF_RMOV, "NUMREG=NUMREG",1); - _relmov1->add(LF_RMOVIVA, "NUMREG=NUMREG",1); - _curr1 = new TCursor (_relmov1, "", 1); - _cur1 = add_cursor (_curr1); - - _relmov2 = new TRelation (LF_MOV); - _relmov2->add(LF_RMOV, "NUMREG=NUMREG",1); - _relmov2->add(LF_RMOVIVA, "NUMREG=NUMREG",1); - _curr2 = new TCursor (_relmov2, "", 2); - _cur2 = add_cursor (_curr2); - - _relmov3 = new TRelation (LF_MOV); - _relmov3->add(LF_RMOVIVA, "NUMREG==NUMREG",1); - _relmov3->add(LF_RMOV, "NUMREG==NUMREG",1); - _curr3 = new TCursor (_relmov3, "", 3); - _cur3 = add_cursor (_curr3); - - open_files(LF_TAB, LF_TABCOM, LF_CAUSALI, LF_CLIFO, LF_COMUNI, LF_ATTIV, - LF_PCON, LF_SALDI, LF_RMOVIVA, LF_NDITTE, 0); - - return true; -} - -bool TListaMov_application::user_destroy() // releasev e arrmask -{ - delete _relmov1; - delete _relmov2; - delete _relmov3; - - return true; - -} - -void TListaMov_application::init_print(const TMask& msk) -{ - const TDate data (msk.get(F_DATASTAMPA)); - printer().setdate(data); - printer().footerlen(5); - - set_magic_currency(TRUE); - - switch (_tipo_lista) - { - case movimenti: - { - set_real_picture("###.###.###.###.###"); - reset_print(); - _flags = 0; - _err.reset(); - _tot_dare_giornaliero = 0; - _tot_avere_giornaliero = 0; - _tot_dare_generale = 0; - _tot_avere_generale = 0; - if (_scelta_stampa == 0) - { - _annoes = msk.get_int(F_ANNO); - _stampa_parte_iva = msk.get_bool(F_STAMPA); - if (_stampa_parte_iva) - _flags |= ST_DATI_IVA; - _stampa_mess_alleg_iva = msk.get_bool(F_ALLEGATO); - if (_stampa_mess_alleg_iva) - _flags |= ST_MESS_ALLEG; - _stampa_anno_comp = msk.get_bool(F_ANNOC); - if (_stampa_anno_comp) - _flags |= ST_ANNO_COMP; - _controllo_mov_errati = msk.get_int(F_CONTROLLO); - if (_controllo_mov_errati == 1) - _flags |= ST_SOLO_MOVERR; - else if (_controllo_mov_errati == 2) - _flags |= ST_CONTROLLO; - else _flags |= ST_SENZA_CONTR; - if ((_numreg_ini != 0)&&(_decidi == 1)) - _flags |= ST_NUMERO; - if ((_data_ini.ok())&&(_decidi == 2)) - _flags |= ST_DATA; - _causale_ini = msk.get(F_CAUSALEINI); - if (_causale_ini != "") - _flags |= ST_CAUSALE; - _registro_ini = msk.get(F_REGISTROINI); - if (_registro_ini != "") - _flags |= ST_REGISTRO; - if ((_data_fin.ok())&&(_decidi == 2)) - _flags |= ST_DATA; - if ((_numreg_fin != 0)&&(_decidi == 2)) - _flags |= ST_NUMERO; - _causale_fin = msk.get(F_CAUSALEFIN); - if (_causale_fin != "") - _flags |= ST_CAUSALE; - _registro_fin = msk.get(F_REGISTROFIN); - if (_registro_fin != "") - _flags |= ST_REGISTRO; - } - else //_scelta_stampa == 1 - { - _annoes = msk.get_int(F_ANNO); - if (_numreg_ini != 0) - _flags |= ST_NUMERO; - if (_data_ini.ok()) - _flags |= ST_DATA; - _causale_ini = msk.get(F_CAUSALEINI); - if (_causale_ini != "") - _flags |= ST_CAUSALE; - if (_data_fin.ok()) - _flags |= ST_DATA; - if (_numreg_fin != 0) - _flags |= ST_NUMERO; - _causale_fin = msk.get(F_CAUSALEFIN); - if (_causale_fin != "") - _flags |= ST_CAUSALE; - } - } - break; - - case fatture: - { - if (_noseparator) - set_real_picture("################"); - else - set_real_picture("####.###.###.###"); - - //resettaggio di tutte le incasinatissime variabili membro...(membro stara' per cazzo?) - _flags = 0; - reset_print(); - _settata_prima_riga = FALSE; - _tipo_clifo_prec = ""; - _codcf_prec = 0l; - _numeroregp = 0; - _documenti = 0; - _totdocumenti = 0; - _totritenute = 0; - _totimponibile = 0; - _totimposta = 0; - _op_esenti = 0; - _op_non_imp = 0; - _gen_documenti = 0; - _gen_totdocumenti = 0; - _gen_totritenute = 0; - _gen_totimponibile = 0; - _gen_totimposta = 0; - _gen_op_esenti = 0; - _gen_op_non_imp = 0; - - //caricamento dati dalla maschera - _annoes = msk.get_int(F_ANNO); - _salto_pagina = (bool)(msk.get(F_CAMBIO)=="X"); - _data_ini = msk.get(F_DATAINI); - if (_data_ini.ok()) - _flags |= ST_DATA; - _data_fin = msk.get(F_DATAFIN); - _causale_ini = msk.get(F_DACODCAUS); - if (_causale_ini != "") - _flags |= ST_CAUSALE; - if (_data_fin.ok()) - _flags |= ST_DATA; - _causale_fin = msk.get(F_ACODCAUS); - if (_causale_fin != "") - _flags |= ST_CAUSALE; - TString tipo = msk.get(F_TIPOELENCO); - if ((tipo=="C")||(tipo=="F")) - { - _codice_ini = msk.get_long(F_CODICEINI); - _codice_fin = msk.get_long(F_CODICEFIN); - } - else - { - _codice_ini = msk.get_long(F_CODICEINI1); - _codice_fin = msk.get_long(F_CODICEFIN1); - } - if (_codice_ini != 0) - _flags |= ST_CODICE; - if (_codice_fin != 0) - _flags |= ST_CODICE; - if (tipo == "E") - { - _tipo_ini = "C"; - _tipo_fin = "F"; - } - else - { - _tipo_ini = tipo; - _tipo_fin = tipo; - } - } - break; - default: - break; - } -} - -void TListaMov_application::preprocess_header() -{ - int soh = 1; // riga d'inizio dell'intestazione - - TString sep(132); - TString key; key.format("%d", get_firm()); - const TString & ragsoc = cache().get(LF_NDITTE, key, NDT_RAGSOC); - - reset_header(); - sep << TR("Ditta ") << get_firm(); - sep << " " << ragsoc; - sep.left_just(132); - - set_header (soh++, (const char*) sep); - - sep.cut(0) << FR("Data @> Pag. @#"); - sep.right_just(122); - - switch (_tipo_lista) - { - case movimenti: - if (_scelta_stampa == 0) - { - sep.overwrite (TR("Lista movimenti")); - set_header (soh++, (const char*)sep); - if (_decidi == 2) // se _decidi e' 1 _annoes e' sempre uguale a zero - { - if (_annoes != 0) - { - set_header (soh, FR("Cod. eserc.%d"), _annoes); - if (_flags & ST_DATA) - { - set_header (soh, FR("@16gda@19g%s"),_data_ini.string()); - set_header (soh, FR("@30ga@32g%s"),_data_fin.string()); - } - } - else // _annoes == 0 - if (_flags & ST_DATA) - { - set_header (soh, FR("Dalla data@11g%s"),_data_ini.string()); - if (_data_fin.ok()) - set_header (soh, FR("@23galla data@33g%s"),_data_fin.string()); - } - else - set_header (soh, TR("Completa in ordine di data")); - } - else - if (_flags & ST_NUMERO) - { - set_header (soh, FR("dal numero@12g%ld"), _numreg_ini); - if (_numreg_fin != 0) - set_header (soh, FR("@20gal numero@30g%ld"), _numreg_fin); - } - else - set_header (soh, TR("Completa in ordine di numero")); - if (_flags & ST_CAUSALE) - { - set_header (soh, FR("@46gdalla causale@60g%s"),(const char*)_causale_ini); - set_header (soh++, FR("@64galla causale@77g%s"),(const char*)_causale_fin); - } - else - set_header (soh++, TR(" tutte le causali")); - if (_flags & ST_REGISTRO) - { - set_header (soh, FR("dal registro %s"),(const char*)_registro_ini); - set_header (soh, FR("@17gal registro %s"),(const char*)_registro_fin); - } - else - set_header (soh, TR("tutti i registri")); - if (_flags & ST_DATI_IVA) - set_header (soh, FR("@34gstampa dati iva")); - if (_flags & ST_CONTROLLO) - set_header (soh, FR("@50g(controllo movimenti)")); - else if (_flags & ST_SOLO_MOVERR) - set_header (soh, FR("@50g(solo movimenti errati)")); - else set_header (soh, FR("@50g(senza controllo movimenti)")); - if (_flags & ST_MESS_ALLEG) - { - if (_flags & ST_ANNO_COMP) - set_header (soh, FR("@78gcon messaggi: data competenza, allegato iva")); - else - set_header (soh, FR("@78gcon messaggio: allegato iva")); - } - else if (_flags & ST_ANNO_COMP) - { - if (_flags & ST_MESS_ALLEG) - set_header (soh, FR("@78gcon messaggi: data competenza, allegato iva")); - else - set_header (soh, FR("@78gcon messaggio: data competenza")); - } - sep.fill('_'); - set_header (++soh, (const char *) sep); - set_header (++soh, FR("Rg Cod Causale@30gDescrizione@56gCodice conto@71gDescrizione conto@103gDare@120gAvere@130gSB")); - } - else - { - sep.overwrite (TR("Lista movimenti di sola prima nota")); - set_header (soh++, (const char*)sep); - if (_decidi == 2) - { - if (_annoes != 0) - { - set_header (soh, FR("Cod. comp. %d"), _annoes); - if (_flags & ST_DATA) - { - set_header (soh, FR("@16gda@19g%s"), (const char*)_data_ini.string()); - set_header (soh, FR("@30ga@32g%s"), (const char*)_data_fin.string()); - } - } - else - if (_flags & ST_DATA) - { - set_header (soh, FR("Dalla data@11g%s"), (const char*)_data_ini.string()); - set_header (soh, FR("@23galla data@33g%s"), (const char*)_data_fin.string()); - } - else - set_header (soh, TR("Completa in ordine di data")); - } - else - if (_flags & ST_NUMERO) - { - set_header (soh, FR("@46gdal numero@57g%ld"), _numreg_ini); - set_header (soh, FR("@65gal numero@75g%ld"), _numreg_fin); - } - else - set_header (soh, FR("@46gCompleta in ordine di numero")); - if (_flags & ST_CAUSALE) - { - set_header(soh, FR("@86gdalla causale@100g%3s"),(const char*)_causale_ini); - set_header(soh,FR("@104galla causale@117g%3s"),(const char*)_causale_fin); - } - else - set_header (soh, TR("@86gtutte le causali")); - sep.fill('_'); - set_header (++soh, (const char *) sep); - set_header (++soh, FR("Rg Cod Causale@30gDescrizione@56gCodice conto@71gDescrizione conto@103gDare@120gAvere@130gSB")); - } - break; - - case fatture: - sep.overwrite (TR("Lista fatture")); - set_header (soh, (const char*)sep); - if (_annoes != 0) - { - set_header (soh, FR("@15gCod. comp %d"), _annoes); - if (_flags & ST_DATA) - { - set_header (soh, FR("@30gdalla data@41g%s"), (const char*)_data_ini.string()); - set_header (soh, FR("@52galla data@62g%s"), (const char*)_data_fin.string()); - } - } - else - if (_flags & ST_DATA) - { - set_header (soh, FR("@15gdalla data %s"), (const char*)_data_ini.string()); - set_header (soh, FR("@37galla data %s"), (const char*)_data_fin.string()); - } - else - set_header (soh, TR("@15gcompleta in ordine di data")); - if (_flags & ST_CODICE) - { - set_header (soh, FR("@74gdal codice %ld"), _codice_ini); - set_header (soh, FR("@92gal codice %ld"), _codice_fin); - } - sep.fill('_'); - set_header (++soh, sep); - set_header (++soh, FR("Numero Data Cod Prot. M Documento@48gCod Tp @75gTotale@101gCd Tp T O@129gNo")); - set_header (++soh, FR("Regis. Operaz. Reg Num. L Data@41gNumero@48gCau Dc @55gDescrizione@75gDocumento@90gImponibile@101gIv Det A I@121gImposta@129gAll")); - break; - default: - break; - } - - set_header (++soh, sep); -} - -TListaMov_application::TListaMov_application(char tipost) - : _err(80),_tipoc(tipost) -{ } - -int cg3100(int argc, char* argv[]) -{ - const char tipo = argc > 2 ? toupper(*argv[2]) : 'M'; - TListaMov_application a(tipo); - - const char* title = NULL; - switch (tipo) - { - case 'C': title = TR("Lista fatture clienti/fornitori"); break; - default : title = TR("Lista movimenti"); break; - } - a.run(argc, argv, title); - return TRUE; -} +// +//Lista movimenti +// + +#include "cg3.h" +#include "cg3100.h" + +#include "cglib01.h" +#include "cglib03.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum liste { movimenti=1, fatture=2, }; + +class TListaMov_application : public TPrintapp +{ + static bool filter_func (const TRelation *); + static bool filter_func_fatture (const TRelation *); + static bool annoes_handler(TMask_field&, KEY); + static bool data_inizio (TMask_field&, KEY); + static bool data_fine (TMask_field&, KEY); + + TRigaiva_array _c; + TRelation * _relmov1,* _relmov2,* _relmov3; + TCursor * _curr1, * _curr2, * _curr3; + TBit_array _err; + TDate _data_ini, _data_fin, _datareg, _data_prec, _datacomp; + TString _descr, _descr_doc, _descr_causale; +#ifdef CONT_SEP + TString _descr_cs; +#endif + TString _tipo_ini, _causale, _app; + TString4 _causale_ini, _causale_fin, _registro,_registro_ini, _registro_fin; + TString _tipoatt, _tipo_elenco,_tipo_clifo_prec,_tipoelsucc; + char _appoggio; + TString4 _tipodoc, _tipodocumento; + TString _ragsoc, _indcf, _civcf, _paiv, _codcaus, _dencom, _provcom, _cofi; + TString _capcf, _codval, _simbolo, _statocf, _comcf, _tipo_fin, _reg_causale; + long _documenti, _codice_ini, _codice_fin, _numero_reg, _codcf; + long _gen_documenti; + long _numreg, _numreg_fin, _numreg_ini, _codalleg, _numeroregp,_codclifosucc; + long _codcf_prec, _numr, _numero; + int _ae, _anno, _annoes, _annoeser; + bool _noseparator, _competence_only; + real _totdocumenti, _totdoc, _totimponibile, _totimposta, _importo; + real _totritenute, _ritenute, _gen_totritenute; // Aggiunte 11/02/2013 + real _gen_totdocumenti, _gen_totimponibile, _gen_totimposta, _gen_op_esenti, _gen_op_non_imp; + real _op_esenti, _op_non_imp; //, _impo, _impos; + + real _tot_dare, _tot_avere, _tot_avere_giornaliero; + real _tot_dare_giornaliero, _tot_dare_generale, _tot_avere_generale; + bool _no_preprocess_page, _salto_pagina, _stampa_anno_comp,_esiste_riga_iva,_nonesiste_riga_iva; + bool _stampa_parte_iva,_alleg_causale,_stampa_mess_alleg_iva,_allegb; + int _ricser; + bool _settata_prima_riga, _causale_gia_stampata,_mov_di_sola_iva; + int _cur1,_cur2,_cur2b,_cur3,_cur4,_decidi,/*_tipod,*/_controllo_mov_errati; + int _numero_riga, _alleg, _tiporegistro, _scelta_stampa, _nr, _n; + int _provvis; + liste _tipo_lista; + word _flags; + char _tipoc; + TString4 _dacodiva, _acodiva; + +protected: + virtual void preprocess_header(); + virtual bool preprocess_page(int,int); + virtual print_action postprocess_page(int,int); + virtual print_action postprocess_print(int,int); + virtual void set_page(int,int); + virtual bool set_print(int m); + void init_print(const TMask& m); + + void print_intra(int& rr); + + void filtra_cursore_provvisori(TCursor* cur) const; + void imposta_parametri_stampa(const TMask& msk); + + bool codiva_filter(const TRelation* rel) const; + bool rmoviva_filter(const TRectype& rmoviva) const; + +public: + bool user_create(); + bool user_destroy(); + bool segnala_errori_primariga(); + bool segnala_errori_ogniriga(); + bool segnala_errori_iva(); + bool contropartita(int, int, long, char); + void stampa_errori_rmov(); + void stampa_errori_mov(); + void stampa_errori_iva(int* r, const TRigaiva& riva); + void stampa_errori_contropartita(int, int, long, char); + void stampa_intestazione(); + void incrementa_totali(); + void compila_clifo(); + void compila_comuni(); + const char * get_error(int error) const; + + bool RicercaDoc(const char* cod) const; + const TString& SimboloValuta (const char* cod) const; + const TString& DescrDoc(const char* cod) const; + const TString& AttivitaRegistro(const char * cod, int anno) const; + + TListaMov_application(char tipost); + virtual ~TListaMov_application() {} +}; + + +HIDDEN inline TListaMov_application& app() +{ return (TListaMov_application&)main_app();} + +bool TListaMov_application::annoes_handler(TMask_field& f, KEY k) +{ + if (k == K_TAB && f.focusdirty() && !f.empty()) + { + const int anno = atoi(f.get()); + TDate dataini, datafin; + TEsercizi_contabili esc; + if (esc.code2range(anno, dataini, datafin)) + { + f.mask().set(F_DATAINI, dataini); + const int prossimo = esc.next(anno); + if (prossimo > 0) + datafin = esc[prossimo].fine(); + f.mask().set(F_DATAFIN, datafin); + } + } + return true; +} + +bool TListaMov_application::data_inizio(TMask_field& f, KEY k) +{ + if (k == K_ENTER) + { + int decidi; + int anno = f.mask().get_int (F_ANNO); + TDate data = f.mask().get_date(F_DATAINI); + if (app()._tipo_lista == movimenti) + decidi = f.mask().get_int (F_DECIDI); + + TEsercizi_contabili esc; + if (esc.exist(anno) && ( (app()._tipo_lista == fatture) || + ((app()._tipo_lista == movimenti ) && (decidi == 2)) ) ) + { + const TDate inizio = esc[anno].inizio(); + if (data.ok()) + { + if (data < inizio) + { + f.error_box(TR("La data indicata non deve essere inferiore alla data di inizio esercizio")); + return FALSE; + } + } + else //se la data e' vuota + f.mask().field(F_DATAINI).set(inizio); + } + } + return TRUE; +} + +bool TListaMov_application::data_fine(TMask_field& f, KEY k) +{ + if (k == K_ENTER) + { + int decidi = 0; + int anno = f.mask().get_int (F_ANNO); + TDate dataini = f.mask().get_date(F_DATAINI); + TDate datafin = f.mask().get_date(F_DATAFIN); + if (app()._tipo_lista == movimenti) + decidi = f.mask().get_int (F_DECIDI); + if ( (app()._tipo_lista == fatture) || + ((app()._tipo_lista == movimenti) && (decidi == 2)) ) + if ( dataini.ok() && datafin.ok() ) + if (dataini > datafin) + { + f.error_box(TR("La data iniziale non deve essere superiore alla data finale")); + return FALSE; + } + + TEsercizi_contabili esc; + if (esc.exist(anno) && ( (app()._tipo_lista == fatture) || ((app()._tipo_lista == movimenti) && (decidi == 2)) ) ) + { + const int prossimo = esc.next(anno); + const TDate fine = esc[prossimo > 0 ? prossimo : anno].fine(); + if (datafin.ok()) + { + if (datafin > fine) + { + f.error_box(TR("La data indicata non deve essere superiore alla data di fine esercizio successivo, oppure, in caso questo non esista, dell'esercizio indicato")); + return FALSE; + } + } + else //se la data e' vuota + f.mask().set(F_DATAFIN, fine); + } + } + return TRUE; +} + +bool TListaMov_application::RicercaDoc(const char* tipo) const +{ + const TRectype& tab_tpd = cache().get(TAB_TPD, tipo); + return !tab_tpd.empty(); +} + +void TListaMov_application::compila_clifo() +{ + TToken_string key; + key.add(_tipo_elenco); + key.add(_codcf); + const TRectype& clifo = cache().get(LF_CLIFO, key); + + char tipoa = clifo.get_char(CLI_TIPOAPER); + _alleg = clifo.get_int(CLI_ALLEG); + _statocf = clifo.get(CLI_STATOCF); + _comcf = clifo.get(CLI_COMCF); + _ragsoc = clifo.get(CLI_RAGSOC); + if (tipoa == 'F') + { + TString80 cognome, nome; + cognome = _ragsoc.mid(0, 30); cognome.trim(); + nome = _ragsoc.mid(30,20); nome.trim(); + _ragsoc = cognome; + _ragsoc << ' ' << nome; + } + _indcf = clifo.get(CLI_INDCF); + _civcf = clifo.get(CLI_CIVCF); + _paiv = clifo.get(CLI_PAIV); + _capcf = clifo.get(CLI_CAPCF); + _dencom = clifo.get(CLI_LOCCF); + _cofi = clifo.get(CLI_COFI); + _codalleg = clifo.get_long(CLI_CODALLEG); +} + +void TListaMov_application::compila_comuni() +{ + TToken_string key; + key.add(_statocf); + key.add(_comcf); + const TRectype & comuni = cache().get(LF_COMUNI, key); + //modifica del 26/04/1995 + _dencom = comuni.get(COM_DENCOM); + if (!_dencom.empty()) + _app = "Com"; + else _app = "Loc"; + //fine modifica + _provcom = comuni.get(COM_PROVCOM); +} + +const char * TListaMov_application::get_error(int err) const +{ + switch (err) + { + case 0: + return TR("La data operazione non appartiene a nessun esercizio"); + break; + case 1: + return TR("Anno IVA non compatibile con data operazione"); + break; + case 2: + return TR("Data operazione successiva all'esercizio di competenza"); + break; + case 3: + return TR("Movimento con competenza anno precedente"); + break; + case 4: + return TR("La data di competenza non appartiene a nessun esercizio"); + break; + case 5: + return TR("Data competenza incompatibile con data operazione"); + break; + case 6: + return TR("Esercizio incompatibile con data competenza"); + break; + case 7: + return TR("Codice causale non presente in tabella"); + break; + case 8: + return TR("Codice causale sospeso"); + break; + case 9: + return TR("Nella causale e' stato attivato il segnale non va in allegato"); + break; + case 10: + return TR("Tipo documento non corrisponde a quello indicato in causale"); + break; + case 11: + return TR("Tipo documento non presente in tabella"); + break; + case 12: + return TR("Codice registro non corrisponde a quello indicato in causale"); + break; + case 13: + return TR("Codice registro non presente in tabella"); + break; + case 14: + return TR("Codice registro sospeso"); + break; + case 15: + return TR("Tipo registro incompatibile con tipo documento"); + break; + case 16: + return TR("Non indicato codice cliente/fornitore"); + break; + case 17: + return TR("Tipo cliente/fornitore non compatibile con tipo registro"); + break; + case 18: + return TR("Codice cliente/fornitore sospeso"); + break; + case 19: + return TR("Nel cliente/fornitore e' stato attivato il segnale: non va in allegato"); + break; + case 20: + return TR("Indicato codice C/F per allegato che richiama se stesso"); + break; + case 21: + return TR("Indicato codice C/F per allegato sospeso"); + break; + case 22: + return TR("C/F per allegato riporta un altro C/F per allegato"); + break; + case 23: + return TR("Indicato codice C/F per allegato con segnale: non va in allegato"); + break; + case 24: + return TR("Indicato codice C/F per allegato non presente in anagrafica"); + break; + case 25: + return TR("Codice cliente/fornitore non presente in anagrafica"); + break; + case 26: + return TR("Movimento con data competenza diversa da data operazione"); + break; + default: + return ""; + break; + } +} + +const int AllegClifo (int gruppo, int conto, long sottoconto) +{ + int alleg = 0; + + TLocalisamfile clifo(LF_CLIFO); + clifo.setkey(3); + clifo.zero(); + clifo.put(CLI_GRUPPO, gruppo); + clifo.put(CLI_CONTO, conto); + clifo.put(CLI_CODCF, sottoconto); + if (clifo.read() == NOERR) + alleg = clifo.get_int(CLI_ALLEG); + + return alleg; +} + +const char* DescrConto (int gruppo, int conto, long sottoconto, char tipocf) +{ + TString& tmp = get_tmp_string(50); +/* + TString16 key; + key << gruppo; + if (conto != 0) + key << '|' << conto; + if (sottoconto != 0) + key << '|' << sottoconto; + tmp = cache().get(LF_PCON, key, PCN_DESCR); + + if (tmp.empty()) + { + key.format("%c|%ld", tipocf , sottoconto); + + const TRectype & clifo = cache().get(LF_CLIFO, key); + if (!clifo.empty()) + { + char tipoa = clifo.get_char("TIPOAPER"); + if (tipoa == 'F') //persona fisica + { + const TString& ragsoc = clifo.get("RAGSOC"); + tmp = ragsoc.mid(0,30); + tmp.trim(); + tmp << ' ' << ragsoc.mid(30); + } + else + tmp = clifo.get("RAGSOC"); + } + } +*/ + const TBill bill(gruppo, conto, sottoconto, tipocf); + tmp = bill.descrizione(); + return tmp; +} + +bool CausAlleg (const char * cod) +{ + const TRectype& caus = cache().get(LF_CAUSALI, cod); + const bool allegb = caus.get_bool(CAU_ALLEG); + return allegb; +} + +const char* TipoAttivita (const char* attreg, long codice_ditta) +{ + TString16 key; key.format("%ld|%s", codice_ditta, attreg); + return cache().get(LF_ATTIV, key, ATT_TIPOATT); +} + +const TString& TListaMov_application::SimboloValuta(const char* cod) const +{ return cache().get(TAB_VAL, cod, "S7"); } + +const TString& TListaMov_application::DescrDoc(const char* tipo) const +{ return cache().get(TAB_TPD, tipo, "S0"); } + +const TString& TListaMov_application::AttivitaRegistro(const char* cod, int anno) const +{ + TString8 key; key.format("%04d%-3s", anno, cod); + return cache().get("REG", key, "S8"); +} + +HIDDEN int tipo_registro(const char* cod, int anno) +{ + TString8 codtab; codtab.format("%4d%-3s", anno, cod); + const TString& tipo_reg = cache().get("REG", codtab, "I0"); + return atoi(tipo_reg); +} + +static bool between(const TString& code, const TString& mini, const TString& maxi) +{ + if (mini.full() && code < mini) + return false; + if (maxi.full() && code > maxi) + return false; + return true; +} + +static bool between(const TDate& code, const TDate& mini, const TDate& maxi) +{ + if (mini.ok() && code < mini) + return false; + if (maxi.ok() && code > maxi) + return false; + return true; +} + +static bool between(long code, long mini, long maxi) +{ + if (mini > 0 && code < mini) + return false; + if (maxi > 0 && code > maxi) + return false; + return true; +} + +bool TListaMov_application::rmoviva_filter(const TRectype& rmoviva) const +{ + const TString& codiva = rmoviva.get(RMI_CODIVA); + return between(codiva, _dacodiva, _acodiva); +} + +bool TListaMov_application::codiva_filter(const TRelation* rel) const +{ + bool ok = _dacodiva.empty() && _acodiva.empty(); // Test su range codici iva + if (!ok) + { + const TRectype& mov = rel->curr(LF_MOV); + TRectype rmoviva(LF_RMOVIVA); + rmoviva.put(RMI_NUMREG, mov.get(MOV_NUMREG)); + TRecord_array righe(rmoviva, RMI_NUMRIG); + for (int i = 1; !ok && i <= righe.rows(); i++) + ok = rmoviva_filter(righe[i]); + } + return ok; +} + +bool TListaMov_application::filter_func_fatture (const TRelation* rel) +{ + const TRectype& mov = rel->curr(LF_MOV); + + // Altrimenti stampa anche i corrispettivi! Pseudo errore MI2396 + const long codcf = mov.get_long(MOV_CODCF); + if (codcf <= 0) + return FALSE; + + const TString& causale = mov.get(MOV_CODCAUS); + if (!between(causale, app()._causale_ini, app()._causale_fin)) + return false; + + const int ann_reg = mov.get_int(MOV_ANNOIVA); + const TString4 cod_reg = mov.get(MOV_REG); + const int tipo_reg = tipo_registro(cod_reg, ann_reg); + + // Considera solo iva acquisti o vendite + if (tipo_reg != 1 && tipo_reg != 2) + return FALSE; + + if (app()._annoes > 0) //anno esercizio specificato nella maschera + { + const int annoes = mov.get_int(MOV_ANNOES); + if (annoes != app()._annoes) + return false; + } + + if (!between(mov.get_date(MOV_DATAREG), app()._data_ini, app()._data_fin)) + return false; + + if (!between(mov.get(MOV_TIPO), app()._tipo_ini, app()._tipo_fin)) + return false; + + if (!between(mov.get_long(MOV_CODCF), app()._codice_ini, app()._codice_fin)) + return false; + + return app().codiva_filter(rel); +} + +bool TListaMov_application::filter_func (const TRelation * rel) +{ + const TRectype& mov = rel->curr(LF_MOV); + + if ( (app()._decidi == 2) && (app()._annoes != 0) ) + { + const int annoes = mov.get_int(MOV_ANNOES); + if (annoes != app()._annoes) + return false; + } + + const TString& causale = mov.get(MOV_CODCAUS); + if (!between(causale, app()._causale_ini, app()._causale_fin)) + return false; + + if (app()._scelta_stampa == 0) // Lista movimenti + { + const TString& codreg = mov.get(MOV_REG); + if (!between(codreg, app()._registro_ini, app()._registro_fin)) + return false; + } + else // Lista movimenti sola prima nota + { + const TString& cod_reg = mov.get(MOV_REG); + const int ann_reg = mov.get_int(MOV_ANNOIVA); + const int tipo_reg = tipo_registro(cod_reg, ann_reg); + if (tipo_reg == 1 || tipo_reg == 2) + return false; + } + + if (app()._competence_only && app()._annoes == 0) + { + const TDate datareg = mov.get_date(MOV_DATAREG); + const int annoes = mov.get_int(MOV_ANNOES); + TEsercizi_contabili esc; + // La data di registrazione appartiene allo stesso esercizio della data di competenza + if (esc.date2esc(datareg) == annoes) + return false; + } + + return true; +} + +void TListaMov_application::stampa_errori_rmov() +{ + const TRectype& rec = current_cursor()->curr(LF_RMOV); + int gruppo = rec.get_int(RMV_GRUPPO); + int conto = rec.get_int(RMV_CONTO); + long sottoconto = rec.get_long(RMV_SOTTOCONTO); + int anno = rec.get_int(RMV_ANNOES); + TDate datareg = rec.get_date(RMV_DATAREG); + char sez = rec.get_char(RMV_SEZIONE); + char tipo = rec.get_char(RMV_TIPOC); + int gruppoc = rec.get_int(RMV_GRUPPOC); + int contoc = rec.get_int(RMV_CONTOC); + long sottocontoc = rec.get_long(RMV_SOTTOCONTOC); + char tipoc = rec.get_char(RMV_TIPOCC); + + bool g = FALSE; + + TBill tc (gruppo,conto,sottoconto); + + _nr++; + + if (anno != _annoeser || datareg != _datareg) + set_row(_nr++, FR("@11gUno o piu' campi non sono costanti nella riga dell' operazione")); + if (sez != 'D' && sez != 'A') + set_row(_nr++, FR("@11gIndicato tipo movimento Dare/Avere errato")); + if (tc.empty()) + set_row(_nr++, FR("@11gNon presente codice gruppo/conto/sottoconto")); + if (!tc.ok()) + set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto non corrisponde ad un sottoconto")); + + TRectype pc (LF_PCON); + tc.set(gruppo,0,0l); + if (!tc.read(pc)) + g = TRUE; + tc.set(gruppo,conto,0l); + if (!tc.read(pc)) + set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto non presente in Piano dei Conti")); + else + { + const char t = pc.get_char(PCN_TMCF); + if (t != tipo) + set_row(_nr++, FR("@11gIl tipo C/F indicato non corrisponde a quello presente su Piano dei Conti")); + else + { + tc.set(gruppo,conto,sottoconto); + if (t != 'C' && t != 'F') + { + if (!tc.read(pc) || g ) + set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto non presente in Piano dei Conti")); + else + { + bool sosp = tc.sospeso(); + if (sosp) + set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto sospeso in Piano dei Conti")); + } + } + else + { + TToken_string key; + key.add(t); + key.add(sottoconto); + const TRectype & clifo = cache().get(LF_CLIFO, key); + + if (!clifo.empty()) + { + bool sosp = clifo.get_bool(CLI_SOSPESO); + if (sosp) + set_row(_nr++, FR("@11gCodice C/F sospeso in Anagrafica")); + } + else set_row(_nr++, FR("@11gCodice C/F non presente in Anagrafica")); + if (_registro.not_empty()) //se su mov e' indicato il codice registro + { + TRegistro rg (_registro, _ae); + const int tiporeg = rg.tipo(); + if ((tiporeg == 1 && t != 'C') || (tiporeg == 2 && t != 'F')) + set_row(_nr++, FR("@11gTipo C/F non compatibile con tipo registro")); + } + } + } + } + TString key(30); + + key.format("%d||%d|%d|%ld", anno, gruppo, conto, sottoconto); + + const TRectype & saldi = cache().get(LF_SALDI, key); + + if (saldi.empty()) + set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto non presente in Saldi p.d.c.")); + + if (gruppoc != 0 || contoc != 0 || sottocontoc != 0l) + stampa_errori_contropartita(gruppoc, contoc, sottocontoc, tipoc); +} + +void TListaMov_application::stampa_errori_contropartita(int gruppo, int conto, long sottoconto, char t) +{ + bool g = FALSE; + + TBill tc; + TRectype pc (LF_PCON); + tc.set(gruppo,0,0l); + if (!tc.read(pc)) + g = TRUE; + tc.set(gruppo,conto,0l); + if (!tc.read(pc)) + set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto di contropartita non presente in Piano dei Conti")); + else + { + //t = pc.get_char(PCN_TMCF); + tc.set(gruppo,conto,sottoconto); + if (t != 'C' && t != 'F') + { + if (!tc.read(pc) || g ) + set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto di contropartita non presente in Piano dei Conti")); + else + { + bool sosp = tc.sospeso(); + if (sosp) + set_row(_nr++, FR("@11gCodice gruppo/conto/sottoconto di contropartita sospeso in Piano dei Conti")); + } + } + else if (sottoconto != 0l) + { + TToken_string key; + key.add(t); + key.add(sottoconto); + const TRectype & clifo = cache().get(LF_CLIFO, key); + + if (!clifo.empty()) + { + bool sosp = clifo.get_bool(CLI_SOSPESO); + if (sosp) + set_row(_nr++, FR("@11gCodice C/F di contropartita sospeso in Anagrafica")); + } + else set_row(_nr++, FR("@11gCodice C/F di contropartita non presente in Anagrafica")); + } + } +} + +void TListaMov_application::stampa_errori_iva(int* nr, const TRigaiva& riva) +{ + const TRectype& tab_iva = cache().get("%IVA", riva._codiva); + if (!tab_iva.empty()) + { + const bool sosp = tab_iva.get_bool("B2"); + if (sosp) + set_row(++(*nr), FR("@11gCodice IVA sospeso")); + if (_stampa_mess_alleg_iva) + { + const int allc = tab_iva.get_int("S7"); + const int allf = tab_iva.get_int("S8"); + if (allc == 0 || allf == 0) + set_row(++(*nr), FR("@11gSul Codice IVA non e' stato indicato un valore per allegato")); + } + } + else + set_row(++(*nr), FR("@11gCodice IVA non presente in tabella")); + + const int tipodet = riva._tipodet; + const int tipocr = riva._tipocr; + + if (tipodet == 1 || tipodet == 3 || tipodet == 5 || tipodet == 9) + if (_tiporegistro != 2) + set_row(++(*nr), FR("@11gCodice di indetraibilita' errato")); + + if (_tiporegistro == 1) + if (tipocr != 0 && tipocr != 1 && tipocr != 4 && tipocr != 9) + set_row(++(*nr), FR("@11gTipo costo/ricavo non valido")); + + if (_tiporegistro == 2) + if (tipocr != 0 && tipocr != 1 && tipocr != 2 && tipocr != 3 && tipocr != 5 && tipocr != 8 && tipocr != 9) + set_row(++(*nr), FR("@11gTipo costo/ricavo non valido")); +} + +void TListaMov_application::stampa_errori_mov() +{ + long i = _err.first_one(); + if (i != -1) + { + for (; i <= _err.last_one(); i++) + if (_err[i]) + set_row(++_n, "@11g%s", (const char*) get_error(i)); + } +} + +void TListaMov_application::set_page(int file, int count) +{ + switch (_tipo_lista) + { + case movimenti: + if (file == LF_RMOVIVA) + break; + if (file == LF_RMOV) + { + _nr = 1; + const TRectype& rec = current_cursor()->curr(LF_RMOV); + + set_row(_nr,"@3n",FLD(LF_RMOV,RMV_NUMRIG)); + + set_row(_nr,"@30g@22s",FLD(LF_RMOV,RMV_DESCR)); + set_row(_nr,"@54g@3,rn",FLD(LF_RMOV,RMV_GRUPPO)); + set_row(_nr,"@58g@3,rn",FLD(LF_RMOV,RMV_CONTO)); + set_row(_nr,"@62g@6,rn",FLD(LF_RMOV,RMV_SOTTOCONTO)); + set_row(_nr,"@69g#.20t",&_descr); + _appoggio = toupper(current_cursor()->curr(LF_RMOV).get_char(RMV_SEZIONE)); + if (_appoggio=='D') + set_row(_nr,"@90g@n",FLD(LF_RMOV,RMV_IMPORTO)); + else + set_row(_nr,"@110g@n",FLD(LF_RMOV,RMV_IMPORTO)); + } + else if (file == LF_MOV) + { + _n = 1; + set_row (_n++,""); + set_row (_n, FR("Operazione n. @14g@7n"), FLD(LF_MOV,MOV_NUMREG)); + set_row (_n, FR("@22gdel@26g@d"),FLD(LF_MOV,MOV_DATAREG)); + set_row (_n, "@37g@36s",FLD(LF_MOV,MOV_DESCR)); + set_row (_n, FR("@75gdoc. @7s"),FLD(LF_MOV,MOV_NUMDOC)); + set_row (_n, FR("@88gdel@92g@d"), FLD(LF_MOV,MOV_DATADOC)); +#ifdef CONT_SEP + set_row (_n, "@37g@36s", &_descr_cs); +#endif + + current_cursor()->curr(LF_MOV).get_int(MOV_ANNOES); // qui verificare + TDate data = current_cursor()->curr(LF_MOV).get_date(MOV_DATAREG); + TDate dcomp = current_cursor()->curr(LF_MOV).get_date(MOV_DATACOMP); + TString16 reg = current_cursor()->curr(LF_MOV).get(MOV_REG); + int anno = current_cursor()->curr(LF_MOV).get_int(MOV_ANNOIVA); + char prov = current_cursor()->curr(LF_MOV).get_char(MOV_PROVVIS); + int tipo = tipo_registro(reg, anno); + + TEsercizi_contabili esc; + esc.date2esc(data); // qui verificare + if ( (tipo == 1) || (tipo == 2) ) + { + set_row (_n, FR("@103greg @3s"),FLD(LF_MOV,MOV_REG)); + set_row (_n, FR("@111gpr @5n"),FLD(LF_MOV,MOV_PROTIVA)); + } + else if (_provvis == 2 && prov >= ' ') + set_row (_n, FR("@103gMov.Provvisorio")); + if (data != dcomp) + set_row (_n, "@119gc.%s", (const char*)dcomp.string(brief, '-')); + //fine + set_row (_n, "@130g@f", FLD(LF_MOV,MOV_STAMPATO)); + } + break; + + default: + break; + } +} + +void TListaMov_application::stampa_intestazione() +{ + set_row (1,""); + if (_tipo_elenco == "C") + set_row (2, FR("@bCliente@8g@6n"), FLD(LF_MOV,MOV_CODCF)); + else + set_row (2, FR("@bFornitore@10g@6n"), FLD(LF_MOV,MOV_CODCF)); + set_row (2, "@b@18g#.35t", &_ragsoc); + set_row (2, FR("@b@54gInd #-.29t #-.10t"), &_indcf, &_civcf); + set_row (2, FR("@b@98gP.I. #11t"), &_paiv); + if (_alleg == 0) + set_row (2, FR("@b@121gAllegato SI")); + else + set_row (2, FR("@b@121gAllegato NO")); + set_row (3, FR("@b@54gCap #5t"), &_capcf); + set_row (3,"@b@64g%s #-.20t Pr #-.5t", + (const char*)_app, &_dencom, &_provcom); + set_row (3, FR("@b@98gC.F. #-16t"), &_cofi); + if (_alleg == 0) + set_row (3, FR("@b@120gRifer@126g#6d"), &_codalleg); +} + +bool TListaMov_application::preprocess_page(int file,int counter) +{ + if (counter) + return TRUE; + + TCursor* cur = current_cursor(); + + switch (_tipo_lista) + { + case movimenti: + if (_scelta_stampa == 0) + { + if (file == LF_MOV) + { + const TRectype& curmov = cur->curr(LF_MOV); + + _tot_avere = 0; + _tot_dare = 0; + _c.destroy(); + _no_preprocess_page = FALSE; + _esiste_riga_iva = FALSE; + _nonesiste_riga_iva = FALSE; + _annoeser = curmov.get_int(MOV_ANNOES); + _datacomp = curmov.get_date(MOV_DATACOMP); + _causale = curmov.get(MOV_CODCAUS); + _registro = curmov.get(MOV_REG); + _anno = curmov.get_int(MOV_ANNOIVA); + _tipodoc = curmov.get(MOV_TIPODOC); + _datareg = curmov.get_date(MOV_DATAREG); + _tipo_elenco = curmov.get(MOV_TIPO); + _codcf = curmov.get_long(MOV_CODCF); + _numero = curmov.get_long(MOV_NUMREG); + _codval = curmov.get(MOV_CODVALI); + _tiporegistro = tipo_registro(_registro, _anno); + + _causale_gia_stampata = FALSE; + TEsercizi_contabili esc; + _ae = esc.date2esc(_datareg); + + if (_registro.not_empty()) //si tratta di fattura + _mov_di_sola_iva = !cur->is_first_match(LF_RMOV); + + _descr_doc = DescrDoc(_tipodoc); +#ifdef CONT_SEP + _descr_cs = cache().get("&NPENT", curmov.get(MOV_CONTSEP), "S0"); +#endif + + TRectype da (LF_MOV); + TRectype a (LF_MOV); + if (_annoes != 0) + { + da.put(MOV_ANNOES, _annoes); + a.put(MOV_ANNOES, _annoes); + } + da.put(MOV_CODCAUS, _causale_ini); + da.put(MOV_REG, _registro_ini); + a.put(MOV_CODCAUS, _causale_fin); + a.put(MOV_REG, _registro_fin); + + if ((curmov >= da) && (curmov <= a)) + { + const TRectype& caus = cache().get(LF_CAUSALI, _causale); + + _reg_causale = caus.get(CAU_REG); + _descr_causale = caus.get(CAU_DESCR); + _alleg_causale = caus.get_bool(CAU_ALLEG); + _tipodocumento = caus.get(CAU_TIPODOC); + + if (_controllo_mov_errati == 1 || _controllo_mov_errati == 2) + { + bool controlla = segnala_errori_primariga(); + bool verifica = (_stampa_parte_iva && segnala_errori_iva()) || segnala_errori_ogniriga(); + + if ((_controllo_mov_errati == 1 && controlla) + || _controllo_mov_errati == 2 ) + { + stampa_errori_mov(); + return TRUE; + } + else if (_controllo_mov_errati == 1 && !verifica) + return FALSE; + else return TRUE; + } + else return TRUE; + } + } + else if (file == LF_RMOV) + { + if (!_causale_gia_stampata) + { + set_row(_nr,"@4g%3s", (const char*) _causale); + set_row(_nr,"@8g%-.20s", (const char*) _descr_causale); + _causale_gia_stampata = true; + } + const TRectype& currig = cur->curr(LF_RMOV); + const int gruppo = currig.get_int(RMV_GRUPPO); + const int conto = currig.get_int(RMV_CONTO); + const long sottoconto = currig.get_long(RMV_SOTTOCONTO); + const char tipoc = currig.get_char(RMV_TIPOC); + _descr = DescrConto(gruppo, conto, sottoconto, tipoc); + _alleg = AllegClifo(gruppo, conto, sottoconto); + _importo = currig.get_real(RMV_IMPORTO); + _appoggio = currig.get_char(RMV_SEZIONE); + if (!_no_preprocess_page) + { + if (_appoggio=='D') + { + _tot_dare_generale += _importo; + _tot_dare += _importo; + } + else + { + _tot_avere += _importo; + _tot_avere_generale += _importo; + } + if (_controllo_mov_errati != 3) + stampa_errori_rmov(); + } + return TRUE; + } + else if ( _stampa_parte_iva && file == LF_RMOVIVA) + { + const TRectype& iva = cur->curr(LF_RMOVIVA); + _c.add_riga(iva); + return TRUE; + } + } + else //_scelta_stampa == 1 + { + if (file == LF_MOV) + { + _tot_avere = 0; + _tot_dare = 0; + _no_preprocess_page = FALSE; + + const TRectype& curmov = cur->curr(LF_MOV); + _causale = curmov.get(MOV_CODCAUS); + _registro = curmov.get(MOV_REG); + _anno = curmov.get_int(MOV_ANNOES); + _tipodoc = curmov.get(MOV_TIPODOC); + + _causale_gia_stampata = FALSE; + + TRectype da (LF_MOV); + TRectype a (LF_MOV); + if (_annoes != 0) + { + da.put(MOV_ANNOES, _annoes); + a.put(MOV_ANNOES, _annoes); + } + da.put(MOV_CODCAUS, _causale_ini); + a.put(MOV_CODCAUS, _causale_fin); + + if ((curmov >= da) && (curmov <= a)) + { + const TRectype & caus = cache().get(LF_CAUSALI, _causale); + + _descr_causale = caus.get(CAU_DESCR); + _alleg_causale = caus.get_bool(CAU_ALLEG); + _tipodocumento = caus.get(CAU_TIPODOC); + + _tiporegistro = tipo_registro (_registro, _anno); + + if ((_tiporegistro != 1)&&(_tiporegistro != 2))//se si tratta di un movimento di sola prima nota + return TRUE; + } + } + else if (file == LF_RMOV) + { + if (!_causale_gia_stampata) + { + set_row(_nr,"@4g%3s", (const char*) _causale); + set_row(_nr,"@8g%-.20s", (const char*) _descr_causale); + _causale_gia_stampata = TRUE; + } + const TRectype& rmov = current_cursor()->curr(LF_RMOV); + const int gruppo = rmov.get_int(RMV_GRUPPO); + const int conto = rmov.get_int(RMV_CONTO); + const long sottoconto = rmov.get_long(RMV_SOTTOCONTO); + const char tipoc = rmov.get_char(RMV_TIPOC); + _descr = DescrConto(gruppo, conto, sottoconto, tipoc); + _importo = rmov.get_real(RMV_IMPORTO); + _appoggio = toupper(rmov.get_char(RMV_SEZIONE)); + if (!_no_preprocess_page) + { + if (_appoggio=='D') + { + _tot_dare_generale += _importo; + _tot_dare += _importo; + } + else + { + _tot_avere += _importo; + _tot_avere_generale += _importo; + } + } + return TRUE; + } + } + break; + + case fatture: + { + if (file == LF_MOV) + { + const TRectype& curmov = current_cursor()->curr(LF_MOV); + const int anno = curmov.get_int(MOV_ANNOIVA); + const TString4 codreg = curmov.get(MOV_REG); + _numr = curmov.get_long(MOV_NUMREG); + _tipo_elenco = curmov.get(MOV_TIPO); + _codcf = curmov.get_long(MOV_CODCF); + const int tiporeg = tipo_registro (codreg, anno); + const TString8 attreg = AttivitaRegistro (codreg, anno); + + if (tiporeg == 1 || tiporeg == 2)//se si tratta di un movimento iva + { + _tipoatt = TipoAttivita(attreg, get_firm()); + _tipo_elenco = curmov.get(MOV_TIPO); + _codcf = curmov.get_long(MOV_CODCF); + _codcaus = curmov.get(MOV_CODCAUS); + _tipodoc = curmov.get(MOV_TIPODOC); + _codval = curmov.get(MOV_CODVALI); + _totdoc = curmov.get_real(MOV_TOTDOC); + _ritenute = curmov.get_real(MOV_RITFIS) + curmov.get_real(MOV_RITSOC); + + if (_tipo_elenco != _tipo_clifo_prec && _tipo_clifo_prec != "") + printer().formfeed(); + + TRectype da (LF_MOV); + TRectype a (LF_MOV); + + if (_annoes != 0) //anno specificato nella maschera + { + da.put(MOV_ANNOES, _annoes); + a.put(MOV_ANNOES, _annoes); + } + + da.put(MOV_CODCAUS, _causale_ini); + a.put(MOV_CODCAUS, _causale_fin); + + if (_data_ini.ok()) + da.put(MOV_DATAREG, _data_ini); + da.put(MOV_TIPO, _tipo_ini); + if (_codice_ini != 0) + da.put(MOV_CODCF, _codice_ini); + if (_data_fin.ok()) + a.put(MOV_DATAREG, _data_fin); + a.put(MOV_TIPO, _tipo_fin); + if (_codice_fin != 0) + a.put(MOV_CODCF, _codice_fin); + + if ((curmov >= da) && (curmov <= a)) + { + compila_clifo(); + compila_comuni(); + + if ((_tipo_clifo_prec == "")&&(_codcf_prec == 0l)) + { + _tipo_clifo_prec = _tipo_elenco; + _codcf_prec = _codcf; + stampa_intestazione(); + } + else + if (_tipo_clifo_prec == _tipo_elenco && _codcf_prec == _codcf) + _settata_prima_riga = FALSE; + else + { + if ( _salto_pagina && _tipo_clifo_prec == _tipo_elenco ) + printer().formfeed(); + stampa_intestazione(); + _tipo_clifo_prec = _tipo_elenco; + _codcf_prec = _codcf; + _settata_prima_riga = FALSE; + } + return TRUE; + } + } + } + else if (file == LF_RMOVIVA) + { + const TRectype& rmov = current_cursor()->curr(LF_RMOV); + int gruppo = rmov.get_int(RMV_GRUPPO); + int conto = rmov.get_int(RMV_CONTO); + + TToken_string key; + key.add(gruppo); + key.add(conto); + key.add(""); + const TRectype & pcon = cache().get(LF_PCON, key); + + _ricser = pcon.get_int(PCN_RICSER); + + _simbolo = SimboloValuta(_codval); + _allegb = CausAlleg(_codcaus); + _descr_doc = DescrDoc(_tipodoc); + //_intra = cur->curr(LF_RMOVIVA).get_bool(RMI_INTRA); + + if (!_settata_prima_riga) + { + reset_print(); + set_row(1, ""); + set_row(2,"@7,rn",FLD(LF_MOV,MOV_NUMREG)); + set_row(2,"@8g@d",FLD(LF_MOV,MOV_DATAREG)); + set_row(2,"@17g@3,rs",FLD(LF_MOV,MOV_REG)); + set_row(2,"@20g@5,rn",FLD(LF_MOV,MOV_PROTIVA)); + set_row(2,"@26g@2,rn",FLD(LF_MOV,MOV_MESELIQ)); + + const TString8 protiva = cur->curr(LF_MOV).get(MOV_PROTIVA); + TString8 uprotiva = cur->curr(LF_MOV).get(MOV_UPROTIVA); + + if (uprotiva.full()) + { + int i; + for (i = 0; protiva[i] && (protiva[i] == uprotiva[i]); i++); + uprotiva = uprotiva.mid(i); + set_row(2, "@24g/@25g%s", (const char*) uprotiva); + } + set_row(2, "@31g@d", FLD(LF_MOV,MOV_DATADOC)); + set_row(2,"@40g@7,rs",FLD(LF_MOV,MOV_NUMDOC)); + set_row(2,"@48g@3s",FLD(LF_MOV,MOV_CODCAUS)); + set_row(2,"@52g@2s",FLD(LF_MOV,MOV_TIPODOC)); + set_row(2,"@55g%-.12s", (const char *)_descr_doc); + set_row(2,"@67g@n",FLD(LF_MOV,MOV_TOTDOC)); + set_row(2,"@84g@n",FLD(LF_RMOVIVA,RMI_IMPONIBILE)); + set_row(2,"@101g@4s",FLD(LF_RMOVIVA,RMI_CODIVA)); + set_row(2,"@105g@1s",FLD(LF_RMOVIVA,RMI_TIPODET)); + if (_tipoatt == "E") + { + if (_ricser == 1) + set_row(2,"@109g1"); + else if (_ricser == 2) + set_row(2,"@109g2"); + } + set_row(2,"@111g@f",FLD(LF_RMOVIVA,RMI_INTRA)); + set_row(2,"@114g@n",FLD(LF_RMOVIVA,RMI_IMPOSTA)); + if (_allegb) + set_row(2,"@131g*"); + + incrementa_totali(); + _settata_prima_riga = TRUE; + ++_documenti; + } + else if (_settata_prima_riga) + { + reset_print(); + set_row(1,"@84g@n", FLD(LF_RMOVIVA,RMI_IMPONIBILE)); + set_row(1,"@101g@4s", FLD(LF_RMOVIVA,RMI_CODIVA)); + set_row(1,"@105g@1s",FLD(LF_RMOVIVA,RMI_TIPODET)); + set_row(1,"@114g@n", FLD(LF_RMOVIVA,RMI_IMPOSTA)); + incrementa_totali(); + } + return TRUE; + } + } + break; + + default: + break; + } + return FALSE; +} + +void TListaMov_application::print_intra(int& rr) +{ + const TRectype& mov = current_cursor()->curr(LF_MOV); + const real corrval = mov.get_real(MOV_CORRVALUTA); + if (corrval != ZERO) + { + const TString16 codval = mov.get(MOV_CODVALI); + TString80 str; + + rr++; + + const TCurrency cl(mov.get_real(MOV_CORRLIRE)); + str = cl.string(TRUE); str.right_just(19); + set_row(rr,FR("Corrispettivo@14g%s"), (const char*)str); + + const TCurrency cv(corrval, codval); + str = cv.string(TRUE); str.right_just(19); + set_row(rr,FR("@34gCorr.in valuta@49g%s"), (const char*)str); + + set_row(rr,"@70g%-3s", (const char*)codval); + } +} + +print_action TListaMov_application::postprocess_page(int file,int count) +{ + if (count) + { + reset_print(); + return NEXT_PAGE; + } + + switch (_tipo_lista) + { + case movimenti: + if (file == LF_RMOV) + { + force_setpage(); + break; + } + if (file == LF_MOV) + { + reset_print(); + _err.reset(); + int n = 1; + int r = 0; + if (_scelta_stampa == 0) + if (_registro.not_empty() && _mov_di_sola_iva) + { + compila_clifo(); + set_row(++r, "@1g%3s %-50s %6ld %-50s", (const char*)_causale, (const char*)_descr_causale, _codcf, (const char*)_ragsoc); + } + if ( _scelta_stampa == 0 && _stampa_parte_iva ) + { + for (int j = 0; j < _c.items(); j++) + { + const TRigaiva& riga = (const TRigaiva&)_c[j]; + //r = j+1; + r++; + set_row(r, FR("Imponibile@11g%r"), &riga._imponibile); + set_row(r, FR("@31gImposta@38g%r"), &riga._imposta); + set_row(r, FR("@58gCodice Iva@69g%3s"), (const char*)riga._codiva); + set_row(r, "@76g%s", (const char*)riga.descr_det()); + + if (j == 0) // Se e' la prima riga che stampa + { + const int meseliq = current_cursor()->file(LF_MOV).get_int(MOV_MESELIQ); + if (meseliq > 0) // Stampa il mese liquidazione + set_row(r,FR(" Mese liq. %2d"), meseliq); + } + if (riga._intra) + set_row(r, FR("@111gOper.intrac.")); + if (_controllo_mov_errati != 3) + if (!_esiste_riga_iva && ! _nonesiste_riga_iva) + stampa_errori_iva(&r, riga); + } + + print_intra(r); + if (_esiste_riga_iva) + set_row(++r, FR("@11gPresenti righe IVA in una registrazione senza IVA")); + if (_nonesiste_riga_iva) + set_row(++r, FR("@11gNon presente alcuna riga IVA in una registrazione con IVA")); + _c.destroy(); + } //if(_scelta_stampa==0... + + if (r > 0) + n = ++r; + + TRecnotype pos, items; + bool FINITO = FALSE; + if ((_scelta_stampa == 0)&&(_controllo_mov_errati != 3)&&(_tot_dare != _tot_avere)) + set_row(n++, FR("@11gIl movimento risulta sbilanciato")); + + pos = current_cursor()->pos(); + items = current_cursor()->items(); + + FINITO = (pos == items-1); + + _datareg = current_cursor()->file(LF_MOV).get_date(MOV_DATAREG); + _numreg = current_cursor()->file(LF_MOV).get_long(MOV_NUMREG); + + TDate datarec (_datareg); + if (!FINITO) + { + TCursor * cur = current_cursor(); + cur->save_status(); + ++(*cur); + datarec = cur->file(LF_MOV).get_date(MOV_DATAREG); + --(*cur); + cur->restore_status(); + } + + _tot_avere_giornaliero += _tot_avere; + _tot_dare_giornaliero += _tot_dare; + + //stampa i totali giornalieri + if ( FINITO || + (_datareg != datarec)||(_numreg == _numreg_fin)) + { + if (( _scelta_stampa == 0 && _controllo_mov_errati != 1 && _decidi == 2) || (_scelta_stampa == 1 && _decidi == 2)) + { + set_row(n, FR("@b@60gTotali del giorno %s"), _datareg.string()); + set_row(n++, "@b@90g%r %r", &_tot_dare_giornaliero, &_tot_avere_giornaliero); + _tot_avere_giornaliero = 0; + _tot_dare_giornaliero = 0; + } + if ((_scelta_stampa == 0 && _controllo_mov_errati != 1 && FINITO) || (_scelta_stampa == 1 && FINITO)) + + { + set_row(n++,""); + set_row(n, FR("@b@60gTotale generale")); + set_row(n++, "@b@90g%r %r", &_tot_dare_generale, &_tot_avere_generale); + } + } + + + if (n == 1) + { + force_setpage(); //probabilmente e' inutile + return NEXT_PAGE; + } + else + { + _no_preprocess_page = TRUE; + force_setpage(FALSE); + return REPEAT_PAGE; + } + } + break; + case fatture: + if (file == LF_MOV) + { + reset_print(); + TCursor* cur = current_cursor(); + int rr = 1; + print_intra(rr); + _totdocumenti += _totdoc; + _totritenute += _ritenute; + TRecnotype pos, items; + bool FINITO = FALSE; + + pos = current_cursor()->pos(); + items = current_cursor()->items(); + + FINITO = (pos == items-1); + + if (!FINITO) + { + cur->save_status(); + ++(*cur); + // long numrsucc = cur->file(LF_MOV).get_long(MOV_NUMREG); + _tipoelsucc = cur->curr(LF_MOV).get(MOV_TIPO); + _codclifosucc = cur->curr(LF_MOV).get_long(MOV_CODCF); + --(*cur); + cur->restore_status(); + } + + if (FINITO || (_tipo_elenco != _tipoelsucc)||(_codcf != _codclifosucc)) + { + set_row(rr++,""); + if (_tipo_elenco == "C") + set_row(rr++, FR("@bTotali Cliente@18gDocumenti Totale documenti@45gRitenute/IVA CEE@68gImponibile@86gImposta@102gop. esenti@119gop. non imp.")); + else + set_row(rr++, FR("@bTotali Fornitore@18gDocumenti Totale documenti@45gRitenute/IVA CEE@68gImponibile@86gImposta@102gop. esenti@119gop. non imp.")); + set_row(rr, "@b@18g%9d", _documenti); + set_row(rr, "@b@28g%r", &_totdocumenti); + set_row(rr, "@b@45g%r", &_totritenute); + set_row(rr, "@b@62g%r", &_totimponibile); + set_row(rr, "@b@79g%r", &_totimposta); + set_row(rr, "@b@96g%r", &_op_esenti); + set_row(rr, "@b@113g%r", &_op_non_imp); + + //incrementa i totali generali di stampa!!! + _gen_documenti += _documenti; + _gen_totdocumenti += _totdocumenti; + _gen_totritenute += _totritenute; + _gen_totimponibile += _totimponibile; + _gen_totimposta += _totimposta; + _gen_op_esenti += _op_esenti; + _gen_op_non_imp += _op_non_imp; + + _totimposta = 0; + _totimponibile = 0; + _op_esenti = 0; + _op_non_imp = 0; + _documenti = 0; + _totdocumenti = 0; + _totritenute = 0; + //return REPEAT_PAGE; + } + + if (FINITO) //ha veramente finito questa stupida stampa: stampa i totali generali! + { + const TString& blank = EMPTY_STRING; + set_row(rr++,(const char*)blank); + set_row(rr++,(const char*)blank); + set_row(rr++,(const char*)blank); + + set_row(rr++, FR("@bTOTALI GENERALI @18gDocumenti Totale documenti@45gRitenute/IVA CEE@68gImponibile@88gImposta@102gop. esenti@119gop. non imp.")); + + set_row(rr, "@b@18g%9d", _gen_documenti); + set_row(rr, "@b@28g%r", &_gen_totdocumenti); + set_row(rr, "@b@45g%r", &_gen_totritenute); + set_row(rr, "@b@62g%r", &_gen_totimponibile); + set_row(rr, "@b@79g%r", &_gen_totimposta); + set_row(rr, "@b@96g%r", &_gen_op_esenti); + set_row(rr, "@b@113g%r", &_gen_op_non_imp); + + //alla fine della stampa azzera i totali generali + _gen_documenti = 0; + _gen_totdocumenti = 0; + _gen_totritenute = 0; + _gen_totimponibile = 0; + _gen_totimposta = 0; + _gen_op_esenti = 0; + _gen_op_non_imp = 0; + } + + if (rr > 1) + return REPEAT_PAGE; + } + break; + default: + break; + } + + + return NEXT_PAGE; +} + +print_action TListaMov_application::postprocess_print(int file,int count) +{ + if (count) + { + reset_print(); + return NEXT_PAGE; + } + + switch (_tipo_lista) + { + case movimenti: + break; + + case fatture: + break; + + default: + break; + } + return NEXT_PAGE; +} + +//cerca errori sulla testata (MOV) +bool TListaMov_application::segnala_errori_primariga() +{ + TEsercizi_contabili esc; + const int ae = esc.date2esc(_datacomp); + + if (_ae == 0) + _err.set(0l); + + if (_registro.not_empty()) //si tratta di fattura + if (_datareg.year() != _anno) + _err.set(1); + + if ( _scelta_stampa == 0 && _stampa_anno_comp ) + if (_ae != _annoeser) + { + if (_annoes) //specificato l'anno nella maschera + _err.set(2); + else _err.set(3); + } + else + if (_datacomp != _datareg) // altrimenti se gli esercizi corrispondono controlla datacomp e dataop + _err.set(26); + + if (ae) + { + const int ar = esc.date2esc(_datareg); // Esercizio in corso + const int pr = esc.pred(ar); // Esercizio precedente + if (ae != ar && ae != pr) + _err.set(4); + } + else + _err.set(5); + + if (_annoeser != ae) + _err.set(6); + + if (_tipodoc != "") + if (!RicercaDoc(_tipodoc)) + _err.set(11); + + if (_causale.not_empty()) //se indicata la causale + { + const TRectype & caus = cache().get(LF_CAUSALI, _causale); + if (caus.empty()) + _err.set(7); + else + { + bool sos = caus.get_bool(CAU_SOSPESO); + if (sos) + _err.set(8); + if (_stampa_mess_alleg_iva && _alleg_causale) + _err.set(9); + } + if (_tipodoc != _tipodocumento) + _err.set(10); + if (_registro != _reg_causale) + _err.set(12); + + if (_registro.not_empty()) //movimento iva (fatture) + { + TRegistro rg (_registro, _datareg.year()); + if (rg.name().empty()) + _err.set(13); + else + { + const int tipo = rg.tipo(); +// TipoIVA i = nessuna_iva; + const TRectype& tabtpd = cache().get("%TPD", _tipodoc); + if (!tabtpd.empty()) + { + const bool cor = tabtpd.get_bool("B0"); + const int i = tabtpd.get_int("I0"); + if (i == 1 && tipo != 1) + _err.set(15); + if (i == 2 && tipo != 2) + _err.set(15); + if (i == 9 && (tipo != 1 && tipo != 2)) + _err.set(15); + if (cor && !rg.corrispettivi()) + _err.set(15); + if (!cor) + if (_codcf == 0l) + _err.set(16); + } + if (_codcf != 0l) + { + if ((tipo == 1 && _tipo_elenco != "C") || (tipo == 2 && _tipo_elenco != "F")) + _err.set(17); + + TToken_string key; + key.add(_tipo_elenco); + key.add(_codcf); + const TRectype & clifo = cache().get(LF_CLIFO, key); + + if (!clifo.empty()) + { + bool sosp = clifo.get_bool(CLI_SOSPESO); + if (sosp) + _err.set(18); + bool occ = clifo.get_bool(CLI_OCCAS); + char alleg = clifo.get_char(CLI_ALLEG); + long calleg = clifo.get_long(CLI_CODALLEG); + if (!occ) + { + if (_stampa_mess_alleg_iva && alleg == '1') + _err.set(19); + if (calleg != 0l) + { + if (calleg == _codcf) + _err.set(20); + TToken_string key; + key.add(_tipo_elenco); + key.add(calleg); + const TRectype & clifo = cache().get(LF_CLIFO, key); + if (!clifo.empty()) + { + bool sospall = clifo.get_bool(CLI_SOSPESO); + long codall = clifo.get_long(CLI_CODALLEG); + char alleg = clifo.get_char(CLI_ALLEG); + if (sospall) + _err.set(21); + if (codall != 0l) + _err.set(22); + if (_stampa_mess_alleg_iva && alleg == '1') + _err.set(23); + } + else _err.set(24); + } + } + } + else _err.set(25); + } + } + } + } + if (_err.ones()) + return TRUE; + + return FALSE; +} + +//controlli sulla contropartita +bool TListaMov_application::contropartita(int gruppo, int conto, long sottoconto, char t) +{ + TBill tc; + TRectype pc (LF_PCON); + tc.set(gruppo,0,0l); + if (!tc.read(pc)) + return TRUE; + tc.set(gruppo,conto,0l); + if (!tc.read(pc)) + return TRUE; + //else t = pc.get_char(PCN_TMCF); + tc.set(gruppo,conto,sottoconto); + if (t != 'C' && t != 'F') + { + if (!tc.read(pc)) + return TRUE; + else + { + bool sosp = tc.sospeso(); + if (sosp) + return TRUE; + } + } + else if (sottoconto != 0l) + { + TToken_string key; + key.add(t); + key.add(sottoconto); + const TRectype & clifo = cache().get(LF_CLIFO, key); + + if (!clifo.empty()) + { + bool sosp = clifo.get_bool(CLI_SOSPESO); + if (sosp) + return TRUE; + } + else + return TRUE; + } + return FALSE; +} + +//guarda se c'e' almeno un errore su almeno una riga (rmov) +bool TListaMov_application::segnala_errori_ogniriga() +{ + TLocalisamfile& rmov = current_cursor()->file(LF_RMOV); + int gruppo, conto, anno, gruppoc, contoc; + long sottoconto, sottocontoc; + TDate datareg; + char sez, tipo, t, tipoc; + real importo; + real dare, avere; + + if (current_cursor()->is_first_match(LF_RMOV)) + { + dare = avere = ZERO; + TRecnotype nrec = rmov.recno(); + rmov.zero(); + rmov.setkey(1); + rmov.put(RMV_NUMREG, _numero); + TRectype recc (rmov.curr()); + for (rmov.read(_isgteq); !rmov.eof() ;rmov.next()) + { + TRectype rec (rmov.curr()); + if (rec > recc) break; + gruppo = rec.get_int(RMV_GRUPPO); + conto = rec.get_int(RMV_CONTO); + sottoconto = rec.get_long(RMV_SOTTOCONTO); + gruppoc = rec.get_int(RMV_GRUPPOC); + contoc = rec.get_int(RMV_CONTOC); + sottocontoc = rec.get_long(RMV_SOTTOCONTOC); + tipoc = rec.get_char(RMV_TIPOCC); + anno = rec.get_int(RMV_ANNOES); + datareg = rec.get_date(RMV_DATAREG); + sez = rec.get_char(RMV_SEZIONE); + tipo = rec.get_char(RMV_TIPOC); + importo = rec.get_real(RMV_IMPORTO); + + if (sez == 'D') + dare += importo; + if (sez == 'A') + avere += importo; + + TBill tc (gruppo,conto,sottoconto); + + if (gruppoc != 0 || contoc != 0 || sottocontoc != 0l) + if (contropartita(gruppoc, contoc, sottocontoc, tipoc)) + { + rmov.readat(nrec); + return true; + } + + if (anno != _annoeser || datareg != _datareg) + { + rmov.readat(nrec); + return true; + } + if (sez != 'D' && sez != 'A') + { + rmov.readat(nrec); + return true; + } + if (tc.empty()) + { + rmov.readat(nrec); + return true; + } + if (!tc.ok()) + { + rmov.readat(nrec); + return true; + } + TRectype pc (LF_PCON); + tc.set(gruppo,0,0l); + + if (!tc.read(pc)) + { + rmov.readat(nrec); + return true; + } + tc.set(gruppo,conto,0l); + if (!tc.read(pc)) + { + rmov.readat(nrec); + return true; + } + else t = pc.get_char(PCN_TMCF); + if (t != tipo) + { + rmov.readat(nrec); + return true; + } + tc.set(gruppo,conto,sottoconto); + if (t != 'C' && t != 'F') + { + if (!tc.read(pc)) + { + rmov.readat(nrec); + return true; + } + else + { + bool sosp = tc.sospeso(); + if (sosp) + { + rmov.readat(nrec); + return true; + } + } + } + else + { + TToken_string key; + key.add(t); + key.add(sottoconto); + const TRectype & clifo = cache().get(LF_CLIFO, key); + + if (!clifo.empty()) + { + bool sosp = clifo.get_bool(CLI_SOSPESO); + if (sosp) + { + rmov.readat(nrec); + return true; + } + } + else + { + rmov.readat(nrec); + return true; + } + if (_registro.not_empty()) //se su mov e' indicato il codice registro + { + TRegistro rg (_registro, _ae); + const int tiporeg = rg.tipo(); + if ((tiporeg == 1 && t != 'C') || (tiporeg == 2 && t != 'F')) + { + rmov.readat(nrec); + return true; + } + } + } + TLocalisamfile saldi(LF_SALDI); + saldi.setkey(1); + saldi.zero(); + saldi.put(SLD_ANNOES,anno); + saldi.put(SLD_GRUPPO,gruppo); + saldi.put(SLD_CONTO, conto); + saldi.put(SLD_SOTTOCONTO,sottoconto); + saldi.put(SLD_FLSCA, ""); + + if (saldi.read() != NOERR) + { + rmov.readat(nrec); + return true; + } + } //for + if (dare != avere) + { + rmov.readat(nrec); + return true; + } + rmov.readat(nrec); + } + return false; +} + +bool TListaMov_application::segnala_errori_iva() +{ + TLocalisamfile& rmoviva = current_cursor()->file(LF_RMOVIVA); + const TRectype& mv = current_cursor()->curr(LF_RMOV); + + if (current_cursor()->is_first_match(LF_RMOVIVA)) + { + const TRecnotype nrec = rmoviva.recno(); + rmoviva.setkey(1); + rmoviva.zero(); + rmoviva.put(RMI_NUMREG, _numero); + const TRectype& rec = rmoviva.curr(); + const TRectype recc (rec); + for (rmoviva.read(_isgteq); !rmoviva.eof() ;rmoviva.next()) + { + if (rec > recc) + break; + if (_registro.empty()) + { + rmoviva.readat(nrec); + _esiste_riga_iva = true; + return true; + } + const TString4 cod = rec.get(RMI_CODIVA); + real percind; + const int tipodet = get_tipodet_from_rmi(rec, mv, percind); + const int tipocr = rec.get_int(RMI_TIPOCR); + const TRectype& tab_iva = cache().get("%IVA", cod); + if (!tab_iva.empty()) + { + int allc = tab_iva.get_int("S7"); + int allf = tab_iva.get_int("S8"); + bool s = tab_iva.get_bool("B2"); + if (s) + { + rmoviva.readat(nrec); + return true; + } + if (_stampa_mess_alleg_iva) + if (allc == 0 || allf == 0) + { + rmoviva.readat(nrec); + return true; + } + } + else + { + rmoviva.readat(nrec); + return true; + } + if (tipodet == 1 || tipodet == 3 || tipodet == 5 || tipodet == 9) + if (_tiporegistro != 2) + { + rmoviva.readat(nrec); + return true; + } + if (_tiporegistro == 1) + if (tipocr != 0 && tipocr != 1 && tipocr != 4 && tipocr != 9) + { + rmoviva.readat(nrec); + return true; + } + if (_tiporegistro == 2) + if (tipocr != 0 && tipocr != 1 && tipocr != 2 && tipocr != 3 && tipocr != 5 && tipocr != 8 && tipocr != 9) + { + rmoviva.readat(nrec); + return true; + } + } + rmoviva.readat(nrec); + } + else if (_registro.not_empty()) //cioe' si tratta di fattura + { + _nonesiste_riga_iva = true; + return true; + } + return false; +} + +void TListaMov_application::incrementa_totali() +{ + const TRectype& rmoviva = current_cursor()->curr(LF_RMOVIVA); + const real imponibile = rmoviva.get_real(RMI_IMPONIBILE); + const real imposta = rmoviva.get_real(RMI_IMPOSTA); + const TString4 codiva = rmoviva.get(RMI_CODIVA); + + const TRectype& tabiva = cache().get("%IVA", codiva); + if (_tipo_elenco == "C") + { + const int colonna = tabiva.get_int("S7"); + if ((colonna == 1)||(colonna == 3)) + _totimposta += imposta; + + if (colonna == 1) + _totimponibile += imponibile; + else + { + if (colonna == 3) + _op_esenti += imponibile; + else + { + TString msg; msg << TR("Codice IVA senza colonna allegato clienti '") << codiva << "' considerata non imponibile."; + xvtil_statbar_set(msg); + _op_non_imp += imponibile; // 14-02-2013 Il default è ora questo (Sile) + } + } + } + else + { + const int colonna = tabiva.get_int("S8"); + if ((colonna == 1)||(colonna == 3)||(colonna == 4)) + _totimposta += imposta; + switch (colonna) + { + case 1: _totimponibile += imponibile; break; + case 3: _op_esenti += imponibile; break; + case 4: _op_non_imp += imponibile; break; + default: + _op_non_imp += imponibile; // 14-02-2013 Il default è ora questo (Sile) + TString msg; msg << TR("Codice IVA senza colonna allegato fornitori '") << codiva << "' considerata non imponibile."; + xvtil_statbar_set(msg); + break; + } + } +} + +void TListaMov_application::filtra_cursore_provvisori(TCursor* cur) const +{ + TString filter; + switch (_provvis) + { + case 1: filter = "(PROVVIS=\"\")"; break; //normale + case 2: filter = ""; break; //globale + default: filter = "(PROVVIS!=\"\")"; break; //solo provvisori + } + cur->setfilter(filter); +} + +void TListaMov_application::imposta_parametri_stampa(const TMask& msk) +{ + set_magic_currency(TRUE); + + reset_files(); + _curr1->set_filterfunction (filter_func); + _curr2->set_filterfunction (filter_func); + _curr3->set_filterfunction (filter_func_fatture); + switch (_tipo_lista) + { + case movimenti: + { + _scelta_stampa = msk.get_int(F_MOVIMENTI); + _annoes = msk.get_int (F_ANNO); + _decidi = msk.get_int(F_DECIDI); + _causale_ini = msk.get(F_CAUSALEINI); + _causale_fin = msk.get(F_CAUSALEFIN); + if (_scelta_stampa == 0) + { + _registro_ini = msk.get(F_REGISTROINI); + _registro_fin = msk.get(F_REGISTROFIN); + } + _numreg_ini = msk.get_long(F_NUMEROINI); + _numreg_fin = msk.get_long(F_NUMEROFIN); + _data_ini = msk.get(F_DATAINI); + _data_fin = msk.get(F_DATAFIN); + _provvis = msk.get_int(F_STAMPAMOVP); + _competence_only = msk.get_bool(F_COMPETENZA); + + TRectype da (LF_MOV), a(LF_MOV); + if (_decidi == 1) + { + select_cursor(_cur1); + filtra_cursore_provvisori(_curr1); + + da.put(MOV_NUMREG, _numreg_ini); + a.put(MOV_NUMREG, _numreg_fin); + } + else + { + select_cursor(_cur2); + filtra_cursore_provvisori(_curr2); + + if (_data_ini.ok()) + da.put(MOV_DATAREG, _data_ini); + if (_data_fin.ok()) + a.put(MOV_DATAREG, _data_fin); + } + current_cursor()->setregion(da,a); + add_file(LF_MOV); + add_file(LF_RMOV,LF_MOV); + add_file(LF_RMOVIVA,LF_MOV); + } + break; + + case fatture: + { + _noseparator = msk.get_bool(F_SEPARATOR); + TString tipo = msk.get(F_TIPOELENCO); + + _data_ini = msk.get(F_DATAINI); + _data_fin = msk.get(F_DATAFIN); + _annoes = msk.get_int(F_ANNO); + _causale_ini = msk.get(F_DACODCAUS); + _causale_fin = msk.get(F_ACODCAUS); + _dacodiva = msk.get(F_DACODIVA); + _acodiva = msk.get(F_ACODIVA); + + if (tipo=="C" || tipo=="F") + { + _codice_ini = atol(msk.get(F_CODICEINI)); + _codice_fin = atol(msk.get(F_CODICEFIN)); + } + else + { + _codice_ini = atol(msk.get(F_CODICEINI1)); + _codice_fin = atol(msk.get(F_CODICEFIN1)); + } + + if (tipo == "E") + { + _tipo_ini = "C"; + _tipo_fin = "F"; + } + else + { + _tipo_ini = tipo; + _tipo_fin = tipo; + } + select_cursor(_cur3); + _curr3->setfilter(""); + TRectype da(LF_MOV), a(LF_MOV); + if (_codice_ini != 0) + da.put(MOV_CODCF, _codice_ini); + a.put(MOV_TIPO, _tipo_fin); + if (_codice_fin != 0) + a.put(MOV_CODCF, _codice_fin); + da.put(MOV_TIPO, _tipo_ini); + current_cursor()->setregion(da,a); + add_file(LF_MOV); + add_file(LF_RMOVIVA,LF_MOV); + } + break; + + default: + break; + } + init_print(msk); +} + +bool TListaMov_application::set_print(int) +{ + const char* masc; + switch(toupper(_tipoc)) + { + case 'C': + masc = "cg3100b"; + _tipo_lista = fatture; + break; + case 'M': + default : + masc = "cg3100a"; + _tipo_lista = movimenti; + break; + } + + TMask msk(masc); + if (main_app().has_module(CMAUT)) + msk.show(-4); + else + { + msk.hide(-4); + msk.reset(-4); + } + msk.set_handler(F_ANNO, annoes_handler); + msk.set_handler(F_DATAINI, data_inizio); + msk.set_handler(F_DATAFIN, data_fine); + + while (msk.run() == K_ENTER) + { + imposta_parametri_stampa(msk); + print(); + + msk.reset(-5); + } + return false; +} + + +bool TListaMov_application::user_create() +{ + _relmov1 = new TRelation (LF_MOV); + _relmov1->add(LF_RMOV, "NUMREG=NUMREG",1); + _relmov1->add(LF_RMOVIVA, "NUMREG=NUMREG",1); + _curr1 = new TCursor (_relmov1, "", 1); + _cur1 = add_cursor (_curr1); + + _relmov2 = new TRelation (LF_MOV); + _relmov2->add(LF_RMOV, "NUMREG=NUMREG",1); + _relmov2->add(LF_RMOVIVA, "NUMREG=NUMREG",1); + _curr2 = new TCursor (_relmov2, "", 2); + _cur2 = add_cursor (_curr2); + + _relmov3 = new TRelation (LF_MOV); + _relmov3->add(LF_RMOVIVA, "NUMREG==NUMREG",1); + _relmov3->add(LF_RMOV, "NUMREG==NUMREG",1); + _curr3 = new TCursor (_relmov3, "", 3); + _cur3 = add_cursor (_curr3); + + open_files(LF_TAB, LF_TABCOM, LF_CAUSALI, LF_CLIFO, LF_COMUNI, LF_ATTIV, + LF_PCON, LF_SALDI, LF_RMOVIVA, LF_NDITTE, 0); + + return true; +} + +bool TListaMov_application::user_destroy() // releasev e arrmask +{ + delete _relmov1; + delete _relmov2; + delete _relmov3; + + return true; + +} + +void TListaMov_application::init_print(const TMask& msk) +{ + const TDate data (msk.get(F_DATASTAMPA)); + printer().setdate(data); + printer().footerlen(5); + + set_magic_currency(TRUE); + + switch (_tipo_lista) + { + case movimenti: + { + set_real_picture("###.###.###.###.###"); + reset_print(); + _flags = 0; + _err.reset(); + _tot_dare_giornaliero = 0; + _tot_avere_giornaliero = 0; + _tot_dare_generale = 0; + _tot_avere_generale = 0; + if (_scelta_stampa == 0) + { + _annoes = msk.get_int(F_ANNO); + _stampa_parte_iva = msk.get_bool(F_STAMPA); + if (_stampa_parte_iva) + _flags |= ST_DATI_IVA; + _stampa_mess_alleg_iva = msk.get_bool(F_ALLEGATO); + if (_stampa_mess_alleg_iva) + _flags |= ST_MESS_ALLEG; + _stampa_anno_comp = msk.get_bool(F_ANNOC); + if (_stampa_anno_comp) + _flags |= ST_ANNO_COMP; + _controllo_mov_errati = msk.get_int(F_CONTROLLO); + if (_controllo_mov_errati == 1) + _flags |= ST_SOLO_MOVERR; + else if (_controllo_mov_errati == 2) + _flags |= ST_CONTROLLO; + else _flags |= ST_SENZA_CONTR; + if ((_numreg_ini != 0)&&(_decidi == 1)) + _flags |= ST_NUMERO; + if ((_data_ini.ok())&&(_decidi == 2)) + _flags |= ST_DATA; + _causale_ini = msk.get(F_CAUSALEINI); + if (_causale_ini != "") + _flags |= ST_CAUSALE; + _registro_ini = msk.get(F_REGISTROINI); + if (_registro_ini != "") + _flags |= ST_REGISTRO; + if ((_data_fin.ok())&&(_decidi == 2)) + _flags |= ST_DATA; + if ((_numreg_fin != 0)&&(_decidi == 2)) + _flags |= ST_NUMERO; + _causale_fin = msk.get(F_CAUSALEFIN); + if (_causale_fin != "") + _flags |= ST_CAUSALE; + _registro_fin = msk.get(F_REGISTROFIN); + if (_registro_fin != "") + _flags |= ST_REGISTRO; + } + else //_scelta_stampa == 1 + { + _annoes = msk.get_int(F_ANNO); + if (_numreg_ini != 0) + _flags |= ST_NUMERO; + if (_data_ini.ok()) + _flags |= ST_DATA; + _causale_ini = msk.get(F_CAUSALEINI); + if (_causale_ini != "") + _flags |= ST_CAUSALE; + if (_data_fin.ok()) + _flags |= ST_DATA; + if (_numreg_fin != 0) + _flags |= ST_NUMERO; + _causale_fin = msk.get(F_CAUSALEFIN); + if (_causale_fin != "") + _flags |= ST_CAUSALE; + } + } + break; + + case fatture: + { + if (_noseparator) + set_real_picture("################"); + else + set_real_picture("####.###.###.###"); + + //resettaggio di tutte le incasinatissime variabili membro...(membro stara' per cazzo?) + _flags = 0; + reset_print(); + _settata_prima_riga = FALSE; + _tipo_clifo_prec = ""; + _codcf_prec = 0l; + _numeroregp = 0; + _documenti = 0; + _totdocumenti = 0; + _totritenute = 0; + _totimponibile = 0; + _totimposta = 0; + _op_esenti = 0; + _op_non_imp = 0; + _gen_documenti = 0; + _gen_totdocumenti = 0; + _gen_totritenute = 0; + _gen_totimponibile = 0; + _gen_totimposta = 0; + _gen_op_esenti = 0; + _gen_op_non_imp = 0; + + //caricamento dati dalla maschera + _annoes = msk.get_int(F_ANNO); + _salto_pagina = (bool)(msk.get(F_CAMBIO)=="X"); + _data_ini = msk.get(F_DATAINI); + if (_data_ini.ok()) + _flags |= ST_DATA; + _data_fin = msk.get(F_DATAFIN); + _causale_ini = msk.get(F_DACODCAUS); + if (_causale_ini != "") + _flags |= ST_CAUSALE; + if (_data_fin.ok()) + _flags |= ST_DATA; + _causale_fin = msk.get(F_ACODCAUS); + if (_causale_fin != "") + _flags |= ST_CAUSALE; + TString tipo = msk.get(F_TIPOELENCO); + if ((tipo=="C")||(tipo=="F")) + { + _codice_ini = msk.get_long(F_CODICEINI); + _codice_fin = msk.get_long(F_CODICEFIN); + } + else + { + _codice_ini = msk.get_long(F_CODICEINI1); + _codice_fin = msk.get_long(F_CODICEFIN1); + } + if (_codice_ini != 0) + _flags |= ST_CODICE; + if (_codice_fin != 0) + _flags |= ST_CODICE; + if (tipo == "E") + { + _tipo_ini = "C"; + _tipo_fin = "F"; + } + else + { + _tipo_ini = tipo; + _tipo_fin = tipo; + } + } + break; + default: + break; + } +} + +void TListaMov_application::preprocess_header() +{ + int soh = 1; // riga d'inizio dell'intestazione + + TString sep(132); + TString key; key.format("%d", get_firm()); + const TString & ragsoc = cache().get(LF_NDITTE, key, NDT_RAGSOC); + + reset_header(); + sep << TR("Ditta ") << get_firm(); + sep << " " << ragsoc; + sep.left_just(132); + + set_header (soh++, (const char*) sep); + + sep.cut(0) << FR("Data @> Pag. @#"); + sep.right_just(122); + + switch (_tipo_lista) + { + case movimenti: + if (_scelta_stampa == 0) + { + sep.overwrite (TR("Lista movimenti")); + set_header (soh++, (const char*)sep); + if (_decidi == 2) // se _decidi e' 1 _annoes e' sempre uguale a zero + { + if (_annoes != 0) + { + set_header (soh, FR("Cod. eserc.%d"), _annoes); + if (_flags & ST_DATA) + { + set_header (soh, FR("@16gda@19g%s"),_data_ini.string()); + set_header (soh, FR("@30ga@32g%s"),_data_fin.string()); + } + } + else // _annoes == 0 + if (_flags & ST_DATA) + { + set_header (soh, FR("Dalla data@11g%s"),_data_ini.string()); + if (_data_fin.ok()) + set_header (soh, FR("@23galla data@33g%s"),_data_fin.string()); + } + else + set_header (soh, TR("Completa in ordine di data")); + } + else + if (_flags & ST_NUMERO) + { + set_header (soh, FR("dal numero@12g%ld"), _numreg_ini); + if (_numreg_fin != 0) + set_header (soh, FR("@20gal numero@30g%ld"), _numreg_fin); + } + else + set_header (soh, TR("Completa in ordine di numero")); + if (_flags & ST_CAUSALE) + { + set_header (soh, FR("@46gdalla causale@60g%s"),(const char*)_causale_ini); + set_header (soh++, FR("@64galla causale@77g%s"),(const char*)_causale_fin); + } + else + set_header (soh++, TR(" tutte le causali")); + if (_flags & ST_REGISTRO) + { + set_header (soh, FR("dal registro %s"),(const char*)_registro_ini); + set_header (soh, FR("@17gal registro %s"),(const char*)_registro_fin); + } + else + set_header (soh, TR("tutti i registri")); + if (_flags & ST_DATI_IVA) + set_header (soh, FR("@34gstampa dati iva")); + if (_flags & ST_CONTROLLO) + set_header (soh, FR("@50g(controllo movimenti)")); + else if (_flags & ST_SOLO_MOVERR) + set_header (soh, FR("@50g(solo movimenti errati)")); + else set_header (soh, FR("@50g(senza controllo movimenti)")); + if (_flags & ST_MESS_ALLEG) + { + if (_flags & ST_ANNO_COMP) + set_header (soh, FR("@78gcon messaggi: data competenza, allegato iva")); + else + set_header (soh, FR("@78gcon messaggio: allegato iva")); + } + else if (_flags & ST_ANNO_COMP) + { + if (_flags & ST_MESS_ALLEG) + set_header (soh, FR("@78gcon messaggi: data competenza, allegato iva")); + else + set_header (soh, FR("@78gcon messaggio: data competenza")); + } + sep.fill('_'); + set_header (++soh, (const char *) sep); + set_header (++soh, FR("Rg Cod Causale@30gDescrizione@56gCodice conto@71gDescrizione conto@103gDare@120gAvere@130gSB")); + } + else + { + sep.overwrite (TR("Lista movimenti di sola prima nota")); + set_header (soh++, (const char*)sep); + if (_decidi == 2) + { + if (_annoes != 0) + { + set_header (soh, FR("Cod. comp. %d"), _annoes); + if (_flags & ST_DATA) + { + set_header (soh, FR("@16gda@19g%s"), (const char*)_data_ini.string()); + set_header (soh, FR("@30ga@32g%s"), (const char*)_data_fin.string()); + } + } + else + if (_flags & ST_DATA) + { + set_header (soh, FR("Dalla data@11g%s"), (const char*)_data_ini.string()); + set_header (soh, FR("@23galla data@33g%s"), (const char*)_data_fin.string()); + } + else + set_header (soh, TR("Completa in ordine di data")); + } + else + if (_flags & ST_NUMERO) + { + set_header (soh, FR("@46gdal numero@57g%ld"), _numreg_ini); + set_header (soh, FR("@65gal numero@75g%ld"), _numreg_fin); + } + else + set_header (soh, FR("@46gCompleta in ordine di numero")); + if (_flags & ST_CAUSALE) + { + set_header(soh, FR("@86gdalla causale@100g%3s"),(const char*)_causale_ini); + set_header(soh,FR("@104galla causale@117g%3s"),(const char*)_causale_fin); + } + else + set_header (soh, TR("@86gtutte le causali")); + sep.fill('_'); + set_header (++soh, (const char *) sep); + set_header (++soh, FR("Rg Cod Causale@30gDescrizione@56gCodice conto@71gDescrizione conto@103gDare@120gAvere@130gSB")); + } + break; + + case fatture: + sep.overwrite (TR("Lista fatture")); + set_header (soh, (const char*)sep); + if (_annoes != 0) + { + set_header (soh, FR("@15gCod. comp %d"), _annoes); + if (_flags & ST_DATA) + { + set_header (soh, FR("@30gdalla data@41g%s"), (const char*)_data_ini.string()); + set_header (soh, FR("@52galla data@62g%s"), (const char*)_data_fin.string()); + } + } + else + if (_flags & ST_DATA) + { + set_header (soh, FR("@15gdalla data %s"), (const char*)_data_ini.string()); + set_header (soh, FR("@37galla data %s"), (const char*)_data_fin.string()); + } + else + set_header (soh, TR("@15gcompleta in ordine di data")); + if (_flags & ST_CODICE) + { + set_header (soh, FR("@74gdal codice %ld"), _codice_ini); + set_header (soh, FR("@92gal codice %ld"), _codice_fin); + } + sep.fill('_'); + set_header (++soh, sep); + set_header (++soh, FR("Numero Data Cod Prot. M Documento@48gCod Tp @75gTotale@101gCd Tp T O@129gNo")); + set_header (++soh, FR("Regis. Operaz. Reg Num. L Data@41gNumero@48gCau Dc @55gDescrizione@75gDocumento@90gImponibile@101gIv Det A I@121gImposta@129gAll")); + break; + default: + break; + } + + set_header (++soh, sep); +} + +TListaMov_application::TListaMov_application(char tipost) + : _err(80),_tipoc(tipost) +{ } + +#ifdef CONT_SEP +int np0600(int argc, char* argv[]) +#else +int cg3100(int argc, char* argv[]) +#endif +{ + const char tipo = argc > 2 ? toupper(*argv[2]) : 'M'; + TListaMov_application a(tipo); + + const char* title = NULL; + switch (tipo) + { + case 'C': title = TR("Lista fatture clienti/fornitori"); break; + default : title = TR("Lista movimenti"); break; + } + a.run(argc, argv, title); + return TRUE; +} diff --git a/src/cg/cg3100a.uml b/src/cg/cg3100a.uml index ef6576316..44e94a003 100755 --- a/src/cg/cg3100a.uml +++ b/src/cg/cg3100a.uml @@ -4,7 +4,11 @@ TOOLBAR "topbar" 0 0 0 2 #include ENDPAGE +#ifdef CONT_SEP +PAGE "Lista Movimenti Contabilità separata" 0 2 0 0 +#else PAGE "Lista Movimenti" 0 2 0 0 +#endif NUMBER F_CODDITTA 5 BEGIN diff --git a/src/cg/cg3100b.uml b/src/cg/cg3100b.uml index 4dffe327e..6497286fb 100755 --- a/src/cg/cg3100b.uml +++ b/src/cg/cg3100b.uml @@ -6,7 +6,11 @@ TOOLBAR "topbar" 0 0 0 2 ENDPAGE +#ifdef CONT_SEP +PAGE "Lista Fatture Contabilità separata" 0 2 0 0 +#else PAGE "Lista Fatture" 0 2 0 0 +#endif NUMBER F_CODDITTA 5 BEGIN diff --git a/src/cg/cg3200.cpp b/src/cg/cg3200.cpp index b1957fc4d..a16851386 100755 --- a/src/cg/cg3200.cpp +++ b/src/cg/cg3200.cpp @@ -1,3742 +1,3740 @@ -#include "cg3.h" -#include "cg3200.h" -#include "cglib02.h" -#include "cglib03.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class TMastrini_record : public TRectype -{ - TBill _bill; - -protected: - virtual const TString& get_str(const char* fieldname) const; - virtual int length(const char* fieldname) const; - virtual TFieldtypes type(const char* fieldname) const; - -public: - TMastrini_record() : TRectype(LF_SALDI) { } - virtual ~TMastrini_record() { } -}; - -const TString& TMastrini_record::get_str(const char* fieldname) const -{ - if (xvt_str_same(fieldname, RMV_DESCR)) - { - const int g = atoi(TRectype::get_str(RMV_GRUPPO)); - const int c = atoi(TRectype::get_str(RMV_CONTO)); - const long s = atol(TRectype::get_str(RMV_SOTTOCONTO)); - ((TBill&)_bill).set(g, c, s); - return _bill.descrizione(); - } - return TRectype::get_str(fieldname); -} - -int TMastrini_record::length(const char* fieldname) const -{ - if (xvt_str_same(fieldname, RMV_DESCR)) - return 50; - return TRectype::length(fieldname); -} - -TFieldtypes TMastrini_record::type(const char* fieldname) const -{ - if (xvt_str_same(fieldname, RMV_DESCR)) - return _alfafld; - return TRectype::type(fieldname); -} - -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 contoi_hnd (TMask_field& f, KEY k); - static bool contof_hnd (TMask_field& f, KEY k); - static bool sottoc_handler_ini (TMask_field& f, KEY k); - static bool sottoc_handler_fine (TMask_field& f, KEY k); - - static bool memorizza_handler(TMask_field& f, KEY k); - static bool scelte_notify(TSheet_field& s, int r, KEY k); - - TDociva_array _b; - TRelation* _rel; - TMask* _msk; - TTable* _tabivd, * _tabtpd, * _tabreg; - TSaldo* _sld; - TParagraph_string* _d18,* _d22,* _d30; - TArray _riga, _lista; - - TDate _data_ini,_data_fine,_data_finese,_data_finesesucc,_ultima_data_reg; - TDate _datareg,_datadoc,_data_inizioese,_datareg_stampa,_inizioes; - int _cur1,_cur2,_gruppo,_conto,_numcarat,_stampanum,_annoiva; - int _numrig,_natdoc,_tipo,_selez_mastrini,_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,_riporto_footer_dare,_riporto_footer_avere; - TString _ragsoc,_indulc,_civulc,_capulc,_com,_prov,_comulc; - long _codice_ditta,_s_prec; - TString4 _tipodoc,_codcaus,_regiva; - TString _descrcaus,_descrdociva,_g_contr,_c_contr,_s_contr,_descrcontr,_numivd; - char _sezivd,_lettivd; - TString _descrizione,_sezione,_numdoc,_descrizionemov,_numrivd,_descr; - TString _dataregs, _datadocs; - int _gruppocontr,_contocontr,_nummast,_pagina; -#ifdef CONT_SEP - bool _cont_sep; -#endif - long _sottocontocontr; - - bool _stampaprogre,_stampatotiva,_stampatot,_stampa_mov_prov, _stampa_cont; - bool _stampato,_devi_stampare_footer; - int _stampa_saldo_des; - - int _annomsk,_annoesmsk,_annoes,_annomsksucc,_tipo_mask,_anno_ghost; - int _anno_corrente,_anno_precedente,_indbil,_numero_pag; - long _sottoc,_numreg,_numgio,_protiva; - bool _stampa_progressivi_si,_competenza,/*_inizio_stampa,*/_puoi_stampare,_stampa_footer_si; - bool _cambia_mastrino,_gia_stampata_intestazione; - char _tmcf,_tipo_contr; - - bool _flag_del_cazzo; - - TDate _dataregrmov; - int _gruppof,_contof; - long _sottocf; - TString _dataregrmovstring,_importo_str,_saldo_movimenti_str; - - int _rw, _conta_mastrini, _indice_array, _item, _item_lista, _indice_lista; - int _ddociva_len; - - bool _noseparator; - TString _real_picture; - -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 preprocess_footer(); - virtual void set_page(int,int); - virtual bool process_link(int id, const char* txt); - - void set_handlers(TMask* msk) const; - bool mask2sheet(); - bool sheet2mask(); - - const char* real2str(const real& r) const; - -public: - - int date2esc(const TDate& d); - void ricerca_clifo(); - void ricerca_gruppo(); - int ricerca_clifo(int riga); - int ricerca_gruppo(int riga); - - void calcola_progressivi(bool finali = false); - void calcola_progressivi_al(const TDate& data); - int stampa_progressivi(int start_riga); - int stampa_progre_riporto(int start_riga); - void documenti_iva(); - void ricerca_regiva(); - void descrizione_causale(); - int crea_intestazione(int riga); - void crea_intestazione(); - void fai_stampa132(); - void fai_stampa198(); - void stampa_totali132(); - void stampa_totali198(); - void stampa_totali132_II(); - void stampa_totali198_II(); - void carica_array_totali132(); - void carica_array_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_sottoconto(); - const char* descrizione_classe(char,char,int,const char *); - bool almeno_un_record(); - void ricerca_dati_ditta(); - void conto(int,int,bool); - bool check_ordine(TMask_field& f, KEY k); - - void setta_riga (int r, const TString& riga); - int righe_rimaste_da_stampare(); - - TMastrini_application() {} - virtual ~TMastrini_application() {} -}; - -inline TMastrini_application& app() { return (TMastrini_application&)main_app(); } - -int TMastrini_application::righe_rimaste_da_stampare() -{ - int righe_rimaste = 0; - - if (_nummast == 2) - { - if (printer().rows_left() != 0) - { - if ( (_conta_mastrini % 2) != 0) - { - if ( (printer().formlen() % 2) != 0) - righe_rimaste = printer().rows_left() - (printer().formlen() / 2) + 1; //- 33; - else - righe_rimaste = printer().rows_left() - (printer().formlen() / 2); - } - else - righe_rimaste = printer().rows_left(); - } - else - { - if ( (_conta_mastrini % 2) != 0) - righe_rimaste = printer().formlen() / 2; //32; - else - { - if ( (printer().formlen() % 2) != 0) - righe_rimaste = (printer().formlen() / 2) + 1; //33; - else - righe_rimaste = printer().formlen() / 2; - } - } - } - - return righe_rimaste; -} - -bool TMastrini_application::process_link(int id, const char* txt) -{ - TRectype mov(LF_MOV); - mov.put(MOV_NUMREG, txt); - return mov.edit(); -} - -bool TMastrini_application::sottoc_handler_ini(TMask_field& f, KEY key) -{ - const TMask& m = f.mask(); - const short id = f.dlg(); - - const int gruppo = m.get_int(F_GRUPPOINI); - const int conto = m.get_int(F_CONTOINI_CONTO); - - const long sottoconto = m.get_long(id); - - if ( key == K_ENTER ) - { - if (sottoconto != 0 && conto == 0) - return f.warning_box(TR("Manca il CONTO")); - - if (conto != 0 && gruppo == 0) - return f.warning_box(TR("Manca il GRUPPO")); - } - - if (key == K_TAB && m.is_running()) - { - if (id == F_SOTTOCINI_CONTO && (gruppo != 0 || conto != 0 || sottoconto != 0L)) - { - TString16 key; - - key.format("%d|%d|%ld", gruppo, conto, sottoconto); - const TRectype & pconti = cache().get(LF_PCON, key); - - if (pconti.empty()) - return f.warning_box(TR("Sottoconto inesistente")); - - const TString & ds = pconti.get(PCN_DESCR); - - f.mask().set(F_DESCRINI_CONTO, ds); - f.mask().set(F_DESCRINI_CLIENTE, ds); - f.mask().set(F_DESCRINI_FORN, ds); - - } - else - if (id == F_SOTTOCINI_CLIENTE || id == F_SOTTOCINI_FORN) - { - char tipo = id == F_SOTTOCINI_CLIENTE ? 'C' : 'F'; - if (sottoconto != 0) - { - TString8 key; key.format("%c|%ld", tipo, sottoconto); - const TRectype & clifo = cache().get(LF_CLIFO, key); - if (clifo.empty()) - return f.warning_box(TR("Anagrafica inesistente")); - const TString & rs = clifo.get(CLI_RAGSOC); - - f.mask().set(F_DESCRINI_CLIENTE, rs); - f.mask().set(F_DESCRINI_FORN, rs); - - } - } - } - - return TRUE; -} - -bool TMastrini_application::sottoc_handler_fine(TMask_field& f, KEY key) -{ - const TMask& m = f.mask(); - const short id = f.dlg(); - TString ds; - TString80 rs; - - const int gruppo = m.get_int(F_GRUPPOFINE); - const int conto = m.get_int(F_CONTOFINE_CONTO); - - const long sottoconto = m.get_long(id); - - if ( key == K_ENTER ) - { - if (sottoconto != 0 && conto == 0) - return f.warning_box(TR("Manca il CONTO")); - - if (conto != 0 && gruppo == 0) - return f.warning_box(TR("Manca il GRUPPO")); - - if (!app().check_ordine(f,key)) - return FALSE; - } - - if ( key == K_TAB && m.is_running()) - { - if (id == F_SOTTOCFINE_CONTO && (gruppo != 0 || conto != 0 || sottoconto != 0L)) - { - TString16 key; - - key.format("%d|%d|%ld", gruppo, conto, sottoconto); - - const TRectype & pconti = cache().get(LF_PCON, key); - - if (pconti.empty()) - return f.warning_box(TR("Sottoconto inesistente")); - const TString & ds = pconti.get(PCN_DESCR); - - f.mask().set(F_DESCRFINE_CONTO, ds); - f.mask().set(F_DESCRFINE_CLIENTE, ds); - f.mask().set(F_DESCRFINE_FORN, ds); - - } - else - if (id == F_SOTTOCFINE_CLIENTE || id == F_SOTTOCFINE_FORN) - { - char tipo = id == F_SOTTOCFINE_CLIENTE ? 'C' : 'F'; - if (sottoconto != 0) - { - TString16 key; - - key.format("%c|%ld", tipo, sottoconto); - - const TRectype & clifo = cache().get(LF_CLIFO, key); - - if (clifo.empty()) - return f.warning_box(TR("Anagrafica inesistente")); - - const TString & rs = clifo.get(CLI_RAGSOC); - - f.mask().set(F_DESCRFINE_CLIENTE, rs); - f.mask().set(F_DESCRFINE_FORN, rs); - - } - } - } - return TRUE; -} - -bool TMastrini_application::gruppo_hnd (TMask_field& f, KEY k) -{ - if (k == K_ENTER) - { - const TMask& m = f.mask(); - int gruppof = m.get_int(F_GRUPPOFINE); - - if (gruppof == 0) - return TRUE; - - int gruppoi = m.get_int(F_GRUPPOINI); - - if (gruppoi > gruppof) - return f.error_box(TR("Il gruppo di partenza deve essere inferiore o uguale al gruppo di arrivo")); - } - - return TRUE; -} - -bool TMastrini_application::contoi_hnd (TMask_field& f, KEY k) -{ - if (k == K_TAB && f.focusdirty() && f.mask().is_running()) - { - TMask& m = f.mask(); - const short id = f.dlg(); - const int gruppo = m.get_int(F_GRUPPOINI); - const int conto = m.get_int(id); - - if (gruppo != 0 && conto != 0) - { - const char tipomsk = m.get(F_TIPOCF_INI)[0]; - - TString16 key; - key.format("%d|%d|", gruppo, conto); - - const TRectype & pconti = cache().get(LF_PCON, key); - - if (!pconti.empty()) - { - char tipo = pconti.get_char(PCN_TMCF); - if (tipomsk != tipo) - return f.warning_box(TR("Conto inesistente")); - } - - const TString& ds = pconti.get(PCN_DESCR); - m.set(F_DESCRINI_CLIENTE, ds); - m.set(F_DESCRINI_FORN, ds); - m.set(F_DESCRINI_CONTO, ds); - } - else - { - m.reset(F_DESCRINI_CLIENTE); - m.reset(F_DESCRINI_FORN); - m.reset(F_DESCRINI_CONTO); - } - } - - return TRUE; -} - -bool TMastrini_application::contof_hnd (TMask_field& f, KEY k) -{ - const short id = f.dlg(); - TMask& m = f.mask(); - - if (k == K_ENTER) - { - int gruppof = m.get_int(F_GRUPPOFINE); - - if (gruppof == 0) - return TRUE; - -// char tipo = m.get(F_TIPOCF_INI)[0]; - - int gruppoi = m.get_int(F_GRUPPOINI); - - if (gruppoi < gruppof) - return TRUE; - - int contof = m.get_int(id); - int contoi = m.get_int(F_CONTOINI_CONTO); - - if (contoi > contof) - return f.error_box(TR("Il conto di partenza deve essere inferiore o uguale al conto di arrivo")); - } - - if (k == K_TAB && f.focusdirty() && m.is_running()) - { - TString ds; - int gruppo = m.get_int(F_GRUPPOFINE); - int conto = m.get_int(id); - - if (gruppo != 0 && conto != 0 && m.field(F_DESCRFINE_CONTO).empty()) - { - char tipomsk = m.get(F_TIPOCF_FINE)[0]; - - TString16 key; - key.format("%d|%d|", gruppo, conto); - - const TRectype & pconti = cache().get(LF_PCON, key); - - if (pconti.empty()) - return f.warning_box(TR("Sottoconto inesistente")); - char tipo = pconti.get_char(PCN_TMCF); - if (tipomsk != tipo) - return f.warning_box(TR("Conto inesistente")); - - - const TString & ds = pconti.get(PCN_DESCR); - - m.set(F_DESCRFINE_CLIENTE, ds); - m.set(F_DESCRFINE_FORN, ds); - m.set(F_DESCRFINE_CONTO, ds); - - } - else - { - f.mask().reset(F_DESCRFINE_CLIENTE); - f.mask().reset(F_DESCRFINE_FORN); - f.mask().reset(F_DESCRFINE_CONTO); - } - } - - return TRUE; -} - -bool TMastrini_application::check_ordine(TMask_field& f, KEY k) -{ - const TMask& m = f.mask(); - const int gruppof = m.get_int(F_GRUPPOFINE); - - if (gruppof == 0) - return TRUE; - - const int gruppoi = m.get_int(F_GRUPPOINI); - - if (gruppoi < gruppof) - return TRUE; - - int contof = m.get_int(F_CONTOFINE_CONTO); - int contoi = m.get_int(F_CONTOINI_CONTO); - - if (contoi < contof) - return TRUE; - - long sottocf = m.get_long(F_SOTTOCFINE_CONTO); - long sottoci = m.get_long(F_SOTTOCINI_CONTO); - - if (sottoci > sottocf) - return f.error_box(TR("Il sottoconto di partenza deve essere inferiore o uguale al sottoconto di arrivo")); - - return TRUE; -} - -bool TMastrini_application::memorizza_handler(TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - if (app().mask2sheet()) - { - TMask& m = f.mask(); - m.reset(-9); - m.set_focus_field(F_TIPOCF_INI); - } - } - return TRUE; -} - -bool TMastrini_application::scelte_notify(TSheet_field& s, int r, KEY k) -{ - return k != K_INS; -} - -int TMastrini_application::date2esc(const TDate& d) -{ - TEsercizi_contabili esc; - return esc.date2esc(d); -} - -//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; - - if (current_cursor()->is_first_match(LF_RMOV)) - { - TLocalisamfile& rmov_file = current_cursor()->file(LF_RMOV); - const TRecnotype record = rmov_file.recno(); - - TRelation rel(LF_RMOV); - rel.add(LF_MOV, "NUMREG==NUMREG"); - TRectype& rmov = rel.curr(); - const TRectype& mov = rel.curr(LF_MOV); - - rmov.zero(); - rmov.put(RMV_GRUPPO, _gruppo); - rmov.put(RMV_CONTO, _conto); - rmov.put(RMV_SOTTOCONTO, _sottoc); - TCursor cur(&rel, "", 2, &rmov, &rmov); - const long items = cur.items(); - cur.freeze(); - for (cur = 0L; cur.pos() < items; ++cur) - { - const int annoes = rmov.get_int (RMV_ANNOES); - const TString4 provvis (mov.get(MOV_PROVVIS)); - const TDate datareg = _annomsk ? mov.get_date(MOV_DATACOMP) : rmov.get_date(RMV_DATAREG); - if ( ((annoes==_annomsk) || (_annomsk==0)) && ((datareg>=_data_ini) && (datareg<=_data_fine)) && (_stampa_mov_prov || provvis.blank())) - { - trovato = true; - break; - } - } - rmov_file.readat(record); - } - - return trovato; -} - -bool TMastrini_application::data_inizio(TMask_field& f, KEY k) -{ - const TDate data = f.mask().get_date(F_DATAINI); - const int anno = f.mask().get_int(F_ANNO); - app()._annomsk = anno; - - if (k == K_ENTER) - { - if (anno != 0) - { - app().data_fine_esercizio(anno); - - if (data.ok()) - { - if (data < app()._data_inizioese || data > app()._data_finese) - { - f.error_box(TR("La data non appartiene all'esercizio indicato")); - return FALSE; - } - else - app()._data_ini = data; - } - } - else - { - if (!data.ok()) - return f.error_box(TR("La data deve essere obbligatoriamente indicata")); - - if (app().date2esc(data) == 0) - return f.error_box(TR("La data indicata non appartiene ad alcun esercizio")); - else - app()._data_ini = data; - } - } - return TRUE; -} - -bool TMastrini_application::data_fine(TMask_field& f, KEY k) -{ - const TMask& m = f.mask(); - int annoes = m.get_int(F_ANNO); - TDate data = m.get_date(F_DATAFINE); - TDate data_ini = m.get_date(F_DATAINI); - app()._annomsk = annoes; - - if (k == K_ENTER) - { - if (annoes != 0) - { - app().data_fine_esercizio(annoes); - - if (data.ok()) - { - if (data < app()._data_inizioese || data > app()._data_finese) - { - f.error_box(TR("La data non appartiene all'esercizio indicato")); - return FALSE; - } - else - app()._data_fine = data; - } - } - else - { - if (data == botime) - return f.error_box(TR("La data deve essere obbligatoriamente indicata")); - - app()._anno_ghost = app().date2esc(data_ini); - - if (app()._anno_ghost == 0) - return f.error_box(TR("La data indicata non appartiene ad alcun esercizio")); - app()._data_fine = data; - } - - if (data < data_ini) - { - f.error_box(TR("La data finale non puo' essere inferiore alla data di partenza")); - return FALSE; - } - } - return TRUE; -} - -void TMastrini_application::fai_stampa132() -{ - if (_nummast == 1 || _nummast == 3) - _rw = 1; - else - if (_nummast == 2) - { - int riga; - - if ( (_conta_mastrini % 2) != 0 ) - riga = (printer().formlen() / 2); //-1 - else - riga = printer().formlen(); //-1; - - int app1 = printer().formlen(); - int app2 = printer().rows_left(); - int cur_row = (app1 - app2); - - if (cur_row == riga) - { - //_rw += 2; - _rw = crea_intestazione(_rw); - _rw = stampa_progre_riporto(_rw); - - if (_item != 0) - { - for (int i = _indice_array; i < _item; i++) - { - TString& data = (TString&)_riga[i]; - - int g1 = data.find("g",1); - int c1 = data.find("@",g1); - int g2 = data.find("g",c1); - - TString fmt1 = ""; - TString fmt2 = ""; - TString str1,str2; - - if (g1 != -1) - { - fmt1 = data.sub(0,g1+1); - fmt1 << "%s"; - str1 = data.sub(g1+1,c1); - } - if (c1 != -1) - { - fmt2 = data.sub(c1,g2+1); - fmt2 << "%s"; - str2 = data.sub(g2+1); - } - - if (fmt1 != "") - set_row (_rw,fmt1,(const char*) str1); - if (fmt2 != "") - set_row (_rw,fmt2,(const char*) str2); - - _rw++; - } - } - } - else - _rw = 1; - - if (_item != 0) - _riga.destroy(); - } - - set_row (_rw,"@0g#t", &_dataregs); - if (_stampanum == 1) - set_row (_rw,"@11g$[b]#7ld$[n]", &_numreg); - else - if (_stampanum == 2) - set_row (_rw,"@11g#7ld", &_numgio); - - set_row (_rw,"@19g#t", &_datadocs); - set_row (_rw,"@30g#7t", &_numdoc); - set_row (_rw,"@38g#3t", &_codcaus); - - if (_stampa_cont == 1) - set_row (_rw,"@117g#t #t #t", &_g_contr, &_c_contr, &_s_contr); -} - -void TMastrini_application::fai_stampa198() -{ - if (_nummast == 1 || _nummast == 3) - _rw = 1; - else - if (_nummast == 2) - { - int riga; - - if ( (_conta_mastrini % 2) != 0 ) - riga = (printer().formlen() / 2); //-1 - else - riga = printer().formlen(); //-1; - - int app1 = printer().formlen(); - int app2 = printer().rows_left(); - int cur_row = (app1 - app2); - - if (cur_row == riga) - { - //_rw += 2; - _rw = crea_intestazione(_rw); - _rw = stampa_progre_riporto(_rw); - - if (_item != 0) - { - for (int i = _indice_array; i < _item; i++) - { - TString& data = (TString&)_riga[i]; - - int g1 = data.find("g",1); - int c1 = data.find("@",g1); - int g2 = data.find("g",c1); - - TString fmt1 = ""; - TString fmt2 = ""; - TString str1,str2; - - if (g1 != -1) - { - fmt1 = data.sub(0,g1+1); - fmt1 << "%s"; - str1 = data.sub(g1+1,c1); - } - if (c1 != -1) - { - fmt2 = data.sub(c1,g2+1); - fmt2 << "%s"; - str2 = data.sub(g2+1); - } - - if (fmt1 != "") - set_row (_rw,fmt1,(const char*) str1); - if (fmt2 != "") - set_row (_rw,fmt2,(const char*) str2); - - _rw++; - } - } - } - else - _rw = 1; - - if (_item != 0) - _riga.destroy(); - } - - set_row (_rw,"@0g#t", &_dataregs); - if (_stampanum == 1) - { - set_row (_rw,"@11g$[b]#7ld$[n]", &_numreg); - set_row (_rw,"@18g/#3d", &_numrig); - } - else if (_stampanum == 2) - set_row (_rw,"@11g#7ld", &_numgio); - - set_row (_rw,"@23g#t", &_datadocs); - set_row (_rw,"@34g#7t", &_numdoc); - set_row (_rw,"@42g#3t", &_codcaus); - -// Stampa saldo movimenti / Descrizione contropartita - const TRectype& rmov = current_cursor()->curr(LF_RMOV); - _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); - - if (_stampa_saldo_des == 3) - { - if (_sottocontocontr > 0) - { - conto(_gruppocontr,_contocontr,FALSE); - TBill tc (_gruppocontr,_contocontr,_sottocontocontr,_tipo_contr); - _descrcontr.cut(0); - _descrcontr << _g_contr << ' ' << _c_contr << ' ' << _s_contr << ' ' << tc.descrizione(); - _descrcontr.cut(47); - set_row (_rw,"@135g%-48s", (const char*)_descrcontr); - } - else - { - _descrcontr.cut(0); - } - } - else - { - set_row (_rw,"@151g#t", &_saldo_movimenti_str); - set_row (_rw,"@168g#t #t #t", &_g_contr, &_c_contr, &_s_contr); - } -} - -void TMastrini_application::stampa_totali132() -{ - if (_nummast == 1 || _nummast == 3) - _rw = 2; - - const TString sep(132, '_'); //Stampa 132 - (sep(132)) - set_row(_rw++,"@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 (_rw,"@32g%s", TR("TOTALI PERIODO")); - set_row (_rw,"@66g%r", &_saldo_periodo); - set_row (_rw,"@83g%r", &_totale_periodo_dare); - set_row (_rw++,"@100g%r", &_totale_periodo_avere); - - set_row (_rw,"@32g%s", TR("TOTALI PROGRESSIVI")); - set_row (_rw,"@66g%r", &_saldo_progre); - set_row (_rw,"@83g%r", &_totprogre_dare); - set_row (_rw++,"@100g%r", &_totprogre_avere); - - if (_stampaprogre) //Progressivi attuali - { - set_row (_rw,"@32g%s %s", TR("TOTALI PROGRESSIVI AL"), _ultima_data_reg.string()); - set_row (_rw,"@66g%r", &_saldo_progre_al); - set_row (_rw,"@83g%r", &_totprogre_dare_al); - set_row (_rw,"@100g%r", &_totprogre_avere_al); - } - - _devi_stampare_footer = FALSE; -} - -const char* TMastrini_application::real2str(const real& r) const -{ - TString & str = get_tmp_string(30); - real2currency(str, r); - return str; -} - -void TMastrini_application::carica_array_totali132() -{ - TString sep(132); - TToken_string r(255); - - if (_nummast == 2) - _rw = 1; - - _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; - - sep.fill(' '); - r.add("@0g%s"); - r.add(sep); - _lista.add(r); - r = ""; - - sep.fill('_'); //Stampa 132 - (sep(132)) - r.add("@0g%s"); - r.add(sep); - _lista.add(r); - r = ""; - - r.add("@32g%s@66g%s@83g%s@100g%s"); - r.add(TR("TOTALI PERIODO")); - r.add(real2str(_saldo_periodo)); - r.add(real2str(_totale_periodo_dare)); - r.add(real2str(_totale_periodo_avere)); - _lista.add(r); - r = ""; - - r.add("@32g%s@66g%s@83g%s@100g%s"); - r.add(TR("TOTALI PROGRESSIVI")); - r.add(real2str(_saldo_progre)); - r.add(real2str(_totprogre_dare)); - r.add(real2str(_totprogre_avere)); - _lista.add(r); - r = ""; - - if (_stampaprogre) //Progressivi attuali - { - r.add("@32g%s@55g%s@66g%s@83g%s@100g%s"); - r.add(TR("TOTALI PROGRESSIVI AL")); - r.add(_ultima_data_reg.string()); - r.add(real2str(_saldo_progre_al)); - r.add(real2str(_totprogre_dare_al)); - r.add(real2str(_totprogre_avere_al)); - _lista.add(r); - r = ""; - } - - if (_stampatotiva) - { - real totale; - - sep.fill(' '); - r.add("@0g%s"); - r.add(sep); - _lista.add(r); - r = ""; - - TString fmt ("@0g%s"); - TString fmt1(format("@%dg", _ddociva_len)); - fmt << fmt1 << "%15s"; - - for (int j = 0; j < _b.items(); j++) - { - TDociva& riga = (TDociva&)_b[j]; - r.add(fmt); - r.add(riga._descrdoc); - totale = riga._totdociva; - r.add(real2str(totale)); - _lista.add(r); - r = ""; - } - - _b.destroy(); - } - - _indice_lista = 0; -} - -void TMastrini_application::stampa_totali132_II() -{ - int riga,cur_row,diff; - int lim = 0; - - _item_lista = _lista.items(); - - if ( (_conta_mastrini % 2) != 0 ) - { - riga = (printer().formlen() / 2); //- 1; - cur_row = printer().formlen() - printer().rows_left(); - diff = riga - cur_row; - } - else - { - riga = printer().formlen(); //- 1; - cur_row = printer().formlen() - printer().rows_left(); - diff = riga - cur_row; - } - - if (_indice_lista == 0 && diff != 0) - { - if (_item_lista > diff) - lim = diff; - else - lim = _item_lista; - } - else - { - lim = _item_lista; - _rw = 1; - _rw = crea_intestazione(_rw); - _rw = stampa_progre_riporto(_rw); - if ( (_conta_mastrini % 2) != 0 ) - { - riga = (printer().formlen() / 2); //- 1; - cur_row = _rw; - diff = riga - cur_row; - } - else - { - riga = printer().formlen(); //- 1; - cur_row = _rw + (printer().formlen() / 2); //32; - diff = riga - cur_row; - } - } - - for (int i = _indice_lista; i < lim; i++) - { - TToken_string& data = (TToken_string&)_lista[i]; - - TString fmt (data.get(0)); - TString arg1 (data.get(1)); - TString arg2 (data.get(2)); - TString arg3 (data.get(3)); - TString arg4 (data.get(4)); - - set_row(_rw++,fmt, (const char*) arg1, (const char*) arg2, (const char*) arg3, (const char*) arg4); - - _indice_lista++; - } - - if (_item_lista <= diff) - _lista.destroy(); - - _devi_stampare_footer = FALSE; -} - -void TMastrini_application::stampa_totali198() -{ - if (_nummast == 1 || _nummast == 3) - _rw = 1; - - const TString sep(198, '-'); //Stampa 198 - (sep(198)) - - set_row(_rw,"@0g%s", (const char*)sep); - - _totprogre_dare=_progredare+_totale_periodo_dare; - _totprogre_avere=_progreavere+_totale_periodo_avere; - - set_row (++_rw,"@32g%s@100g%r", TR("TOTALI PERIODO"), &_totale_periodo_dare); - set_row (_rw,"@117g%r", &_totale_periodo_avere); - - set_row (++_rw,"@32g%s@100g%r", TR("TOTALI PROGRESSIVI"), &_totprogre_dare); - set_row (_rw,"@117g%r", &_totprogre_avere); - - // il saldo totale movimenti non viene stampato se stampo le descrizioni delle contropartite - if (_stampa_saldo_des < 3) - { - set_row (_rw,"@135g%r", &_saldo_progressivi); - set_row (_rw,"@151g%r", &_saldo_movimenti); - } - - if (_stampaprogre) //Progressivi attuali - { - _saldo_progre_al = _totprogre_dare_al - _totprogre_avere_al; - set_row(++_rw,"@32g%s@55g%s", TR("TOTALI PROGRESSIVI AL"), _ultima_data_reg.string()); - set_row (_rw,"@100g%r", &_totprogre_dare_al); - set_row (_rw,"@117g%r", &_totprogre_avere_al); - if (_stampa_saldo_des < 3) - set_row (_rw,"@135g%r", &_saldo_progre_al); - } - - _devi_stampare_footer = FALSE; -} - -void TMastrini_application::carica_array_totali198() -{ - TString sep(198); - TToken_string r(255); - - if (_nummast == 2) - _rw = 1; - - sep.fill(' '); //Stampa 132 - (sep(132)) - r.add("@0g%s"); - r.add(sep); - _lista.add(r); - r = ""; - - sep.fill('_'); //Stampa 132 - (sep(132)) - r.add("@0g%s"); - r.add(sep); - _lista.add(r); - r = ""; - - _totprogre_dare=_progredare+_totale_periodo_dare; - _totprogre_avere=_progreavere+_totale_periodo_avere; - - if (_stampa_saldo_des == 3) - r.add("@32g%s@100g%s@117g%s"); - else - r.add("@32g%s@100g%s@117g%s@151g%s"); - r.add(TR("TOTALI PERIODO")); - r.add(real2str(_totale_periodo_dare)); - r.add(real2str(_totale_periodo_avere)); - r.add(real2str(_saldo_movimenti)); - _lista.add(r); - r = ""; - - if (_stampa_saldo_des == 3) - r.add("@32g%s@100g%s@117g%s"); - else - r.add("@32g%s@100g%s@117g%s@135g%s"); - r.add(TR("TOTALI PROGRESSIVI")); - r.add(real2str(_totprogre_dare)); - r.add(real2str(_totprogre_avere)); - r.add(real2str(_saldo_progressivi)); - _lista.add(r); - r = ""; - - if (_stampaprogre) //Progressivi attuali - { - _saldo_progre_al = _totprogre_dare_al - _totprogre_avere_al; - r.add("@32g%s@55g%s@100g%s@117g%s@135g%s"); - r.add(TR("TOTALI PROGRESSIVI AL")); - r.add(_ultima_data_reg.string()); - r.add(real2str(_totprogre_dare_al)); - r.add(real2str(_totprogre_avere_al)); - r.add(real2str(_saldo_progre_al)); - _lista.add(r); - r = ""; - } - - if (_stampatotiva) - { - real totale; - - sep.fill(' '); - r.add("@0g%s"); - r.add(sep); - _lista.add(r); - r = ""; - - TString16 fmt; - fmt << "@0g%s@" << _ddociva_len << "g%15s"; - - for (int j = 0; j < _b.items(); j++) - { - TDociva& riga = (TDociva&)_b[j]; - r.add(fmt); - r.add(riga._descrdoc); - totale = riga._totdociva; - r.add(real2str(totale)); - _lista.add(r); - r = ""; - } - - _b.destroy(); - } - - _indice_lista = 0; -} - -void TMastrini_application::stampa_totali198_II() -{ - int riga,cur_row,diff; - int lim = 0; - - _item_lista = _lista.items(); - - if ( (_conta_mastrini % 2) != 0 ) - { - riga = (printer().formlen() / 2); //- 1; - cur_row = printer().formlen() - printer().rows_left(); - diff = riga - cur_row; - } - else - { - riga = printer().formlen(); //- 1; - cur_row = printer().formlen() - printer().rows_left(); - diff = riga - cur_row; - } - - if (_indice_lista == 0 && diff != 0) - { - if (_item_lista > diff) - lim = diff; - else - lim = _item_lista; - } - else - { - lim = _item_lista; - _rw = 1; - _rw = crea_intestazione(_rw); - _rw = stampa_progre_riporto(_rw); - if ( (_conta_mastrini % 2) != 0 ) - { - riga = (printer().formlen() / 2); //- 1; - cur_row = _rw; - diff = riga - cur_row; - } - else - { - riga = printer().formlen(); //- 1; - cur_row = _rw + (printer().formlen() / 2); //32; - diff = riga - cur_row; - } - } - - for (int i = _indice_lista; i < lim; i++) - { - TToken_string& data = (TToken_string&)_lista[i]; - - TString fmt (data.get(0)); - TString arg1 (data.get(1)); - TString arg2 (data.get(2)); - TString arg3 (data.get(3)); - TString arg4 (data.get(4)); - TString arg5 (data.get(5)); - - set_row(_rw++,fmt, (const char*)arg1, (const char*)arg2, (const char*)arg3, - (const char*)arg4, (const char*)arg5); - - _indice_lista++; - } - - if (_item_lista <= diff) - _lista.destroy(); - - _devi_stampare_footer = FALSE; -} - -void TMastrini_application::setta_riga (int r, const TString& riga) -{ - TString* p = (TString*)_riga.objptr(r); - if (p == NULL) - _riga.add(riga); - else - *p << riga; -} - -bool TMastrini_application::preprocess_page(int file, int counter) -{ - if (counter) - return TRUE; - - switch (file) - { - case LF_SALDI: - { -// Usati in crea_intestazione() - - _devi_stampare_footer = TRUE; - - if (_nummast == 3 || _nummast == 2) - { - _rw = 0; - _rw++; - } - - const TRectype& saldi = current_cursor()->curr(LF_SALDI); - _gruppo = saldi.get_int(SLD_GRUPPO); - _conto = saldi.get_int(SLD_CONTO); - _sottoc = saldi.get_long(SLD_SOTTOCONTO); - - _cambia_mastrino = TRUE; - - const int annoes = saldi.get_int(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 (_selez_mastrini == 2) - { - calcola_progressivi(TRUE); - _totale_saldo = _saldo_progre_prec; - } - - if ((_selez_mastrini == 1) || (_selez_mastrini == 2)) - { - if ((_selez_mastrini == 1 && almeno_un_record()) || - (_selez_mastrini == 2 && _totale_saldo != ZERO)) - { - _puoi_stampare = TRUE; - - if (_nummast == 3 || _nummast == 2) - { - int cur_row = printer().formlen() - printer().rows_left(); - int diff = printer().formlen() - cur_row; - if (diff <= 13 && diff != 0) - printer().formfeed(); - - _rw = crea_intestazione(_rw); - calcola_progressivi(); - _saldo_progressivi += _saldo_progre_prec; - _rw = stampa_progre_riporto(_rw); - } - else - { - calcola_progressivi(); - _saldo_progressivi += _saldo_progre_prec; // Se trovo quel cazzone che ha scritto sto programma... - } - } - else - { - _puoi_stampare = FALSE; - return FALSE; - } - } - else - if (_selez_mastrini == 3) - { - calcola_progressivi(); - if (_progredare == ZERO && _progreavere == ZERO && !almeno_un_record()) - { - _puoi_stampare = FALSE; - return FALSE; - } - else - { - _puoi_stampare = TRUE; - - if (_nummast == 3 || _nummast == 2) - { - int cur_row = printer().formlen() - printer().rows_left(); - int diff = printer().formlen() - cur_row; - if (diff <= 13 && diff != 0) - printer().formfeed(); - - _rw = crea_intestazione(_rw); - _saldo_progressivi += _saldo_progre_prec; - _rw = stampa_progre_riporto(_rw); - } - } - } - } - break; - - case LF_RMOV: - { - TLocalisamfile& rmov = current_cursor()->file(LF_RMOV); - - //Il flag _gia_stampata_intestazione serve nella stampa in continuo, xche' - //sono costretto a richiamare l'intestazione sia nella preprocess_page (per - //i mastrini con intestazione a meta' pagina), sia nella preprocess_header - //per i mastrini che si trovano a cavallo fra una pagina e quella successiva. - //In quest'ultimo caso infatti quando vado a pagina nuova devo stampare l'intestazione - //ma senza il flag rischio di stamparla due volte. - if (_nummast == 3) - _gia_stampata_intestazione = FALSE; - - if (_nummast == 1 || _nummast == 3) - _rw = 1; - - // Ricerca la contropartita di quel movimento - - _numreg = rmov.get_long(RMV_NUMREG); - _numrig = rmov.get_int(RMV_NUMRIG); - - _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 = rmov.get_real(RMV_IMPORTO); - _importo_str = real2str(_importo); - const TRectype & mov = cache().get(LF_MOV, _numreg); - - _annoes = mov.get_int(MOV_ANNOES); - _regiva = mov.get(MOV_REG); - _annoiva = mov.get_int(MOV_ANNOIVA); - - - // Controlla se saldo e' diverso da 0 - - if (((_annoes == _annomsk) || (_annomsk == 0)) && (!_totale_saldo.is_zero())) - { - _sezione = rmov.get(RMV_SEZIONE); - - if (_annomsk == 0) - { - _datareg = mov.get(MOV_DATAREG); - - _datareg_stampa = _datareg; - } - else - if (_annomsk != 0) - { - _datareg = mov.get(MOV_DATACOMP); - _datareg_stampa = mov.get(MOV_DATAREG); - } - - - const TString4 provvis = mov.get(MOV_PROVVIS); - - - _dataregs = _datareg_stampa.string(); - - if ((_stampa_mov_prov)||((!_stampa_mov_prov)&&(provvis.blank()))) - { - 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 (_rw, "@132g*"); - else - set_row (_rw, "@197g*"); - - if (_stampa_mov_prov && !provvis.blank()) - if (_numcarat == 1) - set_row(_rw, "@130gP"); - else - set_row(_rw, "@195gP"); - - _codcaus = mov.get(MOV_CODCAUS); - _tipodoc = mov.get(MOV_TIPODOC); - - if (_stampatotiva && (_tmcf == 'C' || _tmcf == 'F')) - { - if (_tipodoc != "") - { - documenti_iva(); - _b.add_riga(_descrdociva,_importo, _natdoc); - if (_descrdociva.len() > _ddociva_len) - _ddociva_len = _descrdociva.len(); - } - } - _datadoc = (mov.get(MOV_DATADOC)); - - _datadocs = _datadoc.string(); - _numdoc = mov.get(MOV_NUMDOC); - - descrizione_causale(); - _descrizionemov = mov.get(MOV_DESCR); - -#ifdef CONT_SEP - if (_cont_sep ) - _descrizionemov << " " << cache().get("&NPENT", mov.get(MOV_CONTSEP), "S0"); -#endif - - _numgio = atol(mov.get(MOV_NUMGIO)); - - - _descrizione = rmov.get(RMV_DESCR); - - _d18->cut(0); _d22->cut(0); _d30->cut(0); - - if (_nummast == 1 || _nummast == 3) - { - if (_numcarat == 1) // Stampa 132 caratteri - { - if (_descrizione != "") - { - *_d22 = (const char*) _descrizione; - if (_descrizionemov != "") - { - *_d18 = (const char*) _descrizionemov; - set_row(_rw, "@42g#a", _d18); - set_row(_rw, "@61g#a", _d22); - } - else if (_descrizionemov == "") - { - *_d18 = (const char*) _descrcaus; - set_row(_rw, "@42g#a", _d18); - set_row(_rw, "@61g#a", _d22); - } - } - else if (_descrizione == "") - if (_descrizionemov != "") - { - *_d22 = (const char*) _descrizionemov; - *_d18 = (const char*) _descrcaus; - set_row (_rw,"@42g#a", _d18); - set_row (_rw,"@61g#a", _d22); - } - else - if (_descrizionemov == "") - { - conto(_gruppocontr,_contocontr,FALSE); - TBill tc (_gruppocontr,_contocontr,_sottocontocontr,_tipo_contr); - _descrcontr = tc.descrizione(); - *_d18 = (const char*) _descrcaus; - set_row (_rw,"@42g#a", _d18); - if (_descrcontr != "Sconosciuto") - { - *_d22 = (const char*) _descrcontr; - set_row (_rw,"@61g#a", _d22); - } - } - } - else - if (_numcarat == 2) // Stampa 198 caratteri - { - if (_descrizione != "") - { - *_d30 = (const char*) _descrizione; - if (_descrizionemov != "") - { - *_d22 = (const char*) _descrizionemov; - set_row (_rw,"@46g#a", _d22); - set_row (_rw,"@70g#a", _d30); - } - else if (_descrizionemov == "") - { - *_d22 = (const char*) _descrcaus; - set_row(_rw, "@46g#a", _d22); - set_row(_rw, "@70g#a", _d30); - } - } - else if (_descrizione == "") - if (_descrizionemov.not_empty()) - { - *_d30 = (const char*) _descrizionemov; - *_d22 = (const char*) _descrcaus; - set_row (_rw,"@46g#a", _d22); - set_row (_rw,"@70g#a", _d30); - } - else - { - conto(_gruppocontr,_contocontr,FALSE); - TBill tc (_gruppocontr,_contocontr,_sottocontocontr,_tipo_contr); - _descrcontr = tc.descrizione(); - *_d22 = (const char*) _descrcaus; - set_row (_rw,"@46g#a", _d22); - if (_descrcontr != "Sconosciuto") - { - *_d30 = (const char*)_descrcontr; - set_row (_rw,"@70g#a", _d30); - } - } - } - } //if (_nummast == 1 || _nummast == 3) - - if (_nummast == 2) - { - TString d18,d23,d30; - - if (_numcarat == 1) // Stampa 132 caratteri - { - if (_descrizione != "") - { - d23 = _descrizione; - if (_descrizionemov.not_empty()) - d18 = _descrizionemov; - else - d18 = _descrcaus; - } - else if (_descrizione.empty()) - { - if (_descrizionemov.not_empty()) - { - d23 = _descrizionemov; - d18 = _descrcaus; - } - else - { - conto(_gruppocontr,_contocontr,FALSE); - TBill tc (_gruppocontr,_contocontr,_sottocontocontr,_tipo_contr); - _descrcontr = tc.descrizione(); - d18 = _descrcaus; - if (_descrcontr != "Sconosciuto") - d23 = _descrcontr; - } - } - TParagraph_string d_18 (d18,18); - int i = 0; - const char* str; - while ( (str = d_18.get()) != NULL) - { - TString stringa; - stringa << "@42g" << str; - setta_riga(i,stringa); - i++; - } - - TParagraph_string d_23 (d23,23); - i = 0; - while ( (str = d_23.get()) != NULL) - { - TString stringa; - stringa << "@61g" << str; - setta_riga(i,stringa); - i++; - } - } - else - if (_numcarat == 2) // Stampa 198 caratteri - { - if (_descrizione.not_empty()) - { - d30 = _descrizione; - if (_descrizionemov != "") - d23 = _descrizionemov; - else if (_descrizionemov == "") - d23 = _descrcaus; - } - else - { - if (_descrizionemov.not_empty()) - { - d30 = _descrizionemov; - d23 = _descrcaus; - } - else - { - conto(_gruppocontr,_contocontr,FALSE); - TBill tc (_gruppocontr,_contocontr,_sottocontocontr,_tipo_contr); - _descrcontr = tc.descrizione(); - d23 = _descrcaus; - if (_descrcontr != "Sconosciuto") - d30 = _descrcontr; - } - } - TParagraph_string d_23 (d23,23); - int i = 0; - const char* str; - while ( (str = d_23.get()) != NULL) - { - TString stringa; - stringa << "@46g" << str; - setta_riga(i,stringa); - i++; - } - - TParagraph_string d_30 (d30,30); - i = 0; - while ( (str = d_30.get()) != NULL) - { - TString stringa; - stringa << "@70g" << str; - setta_riga(i,stringa); - i++; - } - } - - _item = _riga.items(); - int riga,cur_row,diff; - - if ( (_conta_mastrini % 2) != 0 ) - { - int app = 0; - riga = (printer().formlen() / 2); - if (printer().rows_left() == 0) - app = printer().formlen() - _rw; - else - app = printer().rows_left(); - cur_row = printer().formlen() - app; - diff = riga - cur_row; - } - else - { - riga = printer().formlen(); - cur_row = printer().formlen() - printer().rows_left(); - diff = riga - cur_row; - } - - bool stampa_riporti; - - int lim = 0; - if (_item >= diff) - { - lim = diff - 1; - stampa_riporti = TRUE; - } - else - { - lim = _item; - stampa_riporti = FALSE; - } - - _indice_array = 0; - - int k = _rw; - - for (int i = 0; i < lim; i++) - { - TString& data = (TString&)_riga[i]; - - int g1 = data.find("g",1); - int c1 = data.find("@",g1); - int g2 = data.find("g",c1); - - TString fmt1 = ""; - TString fmt2 = ""; - TString str1,str2; - - if (g1 != -1) - { - fmt1 = data.sub(0,g1+1); - fmt1 << "%s"; - str1 = data.sub(g1+1,c1); - } - if (c1 != -1) - { - fmt2 = data.sub(c1,g2+1); - fmt2 << "%s"; - str2 = data.sub(g2+1); - } - - if (fmt1 != "") - set_row (k,fmt1,(const char*) str1); - if (fmt2 != "") - set_row (k,fmt2,(const char*) str2); - - k++; - _indice_array++; - } - if (stampa_riporti) - { - _rw = k; - if (lim == 0) - { - if (_numcarat == 1) - { - TString app(132); - app.spaces(); - set_row (_rw, "@0g%s", (const char*)app); - } - else - { - TString app(198); - app.spaces(); - set_row (_rw, "@0g%s", (const char*)app); - } - } - real dep_dare,dep_avere; - if (_stampa_footer_si) - { - _riporto_footer_dare = _progredare + _riporto_parziale_dare; - _riporto_footer_avere = _progreavere + _riporto_parziale_avere; - - real imp_d,imp_a; - imp_d = _sezione == "D" ? _importo : ZERO; - imp_a = _sezione == "A" ? _importo : ZERO; - if (lim != 0) - { - _riporto_footer_dare += imp_d; - _riporto_footer_avere += imp_a; - } - dep_dare = _riporto_footer_dare; - dep_avere = _riporto_footer_avere; - - _stampa_footer_si = FALSE; - } - else - { - _riporto_footer_dare += _riporto_parziale_dare; - _riporto_footer_avere += _riporto_parziale_avere; - - real imp_d,imp_a; - imp_d = _sezione == "D" ? _importo : ZERO; - imp_a = _sezione == "A" ? _importo : ZERO; - if (lim != 0) - { - _riporto_footer_dare += imp_d; - _riporto_footer_avere += imp_a; - } - dep_dare = _riporto_footer_dare; - dep_avere = _riporto_footer_avere; - } - - if (_nummast != 3 || dep_dare != ZERO || dep_avere != ZERO) - { - TString dare (real2str(dep_dare)); - TString avere (real2str(dep_avere)); - if (_numcarat == 1) - { - set_row (_rw,FR("@32gA RIPORTO@83g%s"), (const char*) dare); - set_row (_rw,"@100g%s", (const char*) avere); - } - else - if (_numcarat == 2) - { - set_row (_rw,FR("@32gA RIPORTO@100g%s"), (const char*) dare); - set_row (_rw,"@117g%s", (const char*) avere); - } - } - if (lim == 0) - { - rmov.prev(); - _riga.destroy(); - _item = 0; - return TRUE; - } - _rw--; - } - //_riga.destroy(); - } - - if (_sezione == "D") - { - _totale_periodo_dare += _importo; - _riporto_parziale_dare += _importo; - - - if (_numcarat == 1) // Stampa 132 caratteri - set_row (_rw,"@83g%s", (const char*) _importo_str); - else // Stampa 198 caratteri - { - _saldo_progressivi += _importo; - _saldo_movimenti += _importo; - set_row (_rw,"@100g%s", (const char*) _importo_str); - } - } - else - { - _totale_periodo_avere += _importo; - _riporto_parziale_avere += _importo; - - - if (_numcarat == 1) // Stampa 132 caratteri - set_row (_rw,"@100g%s", (const char*) _importo_str); - else // Stampa 198 caratteri - { - _saldo_progressivi -= _importo; - _saldo_movimenti -= _importo; - set_row (_rw,"@117g%s", (const char*) _importo_str); - } - } - - const int righe_rimaste = printer().rows_left(); - _stampato = righe_rimaste >= 1; - - _saldo_movimenti_str=real2str(_saldo_movimenti); - if (_numcarat == 2) - { - ricerca_regiva(); - _protiva = mov.get_long(MOV_PROTIVA); - if (_protiva != 0) - set_row (_rw,"@191g%5d", _protiva); - - if (_tipo < 3) - set_row (_rw,"@183g#t" , &_regiva); - _dataregrmov = current_cursor()->curr(LF_RMOV).get_date(RMV_DATAREG); - -//Gestire la stampa di saldo_progressivi nella postprocess_page di RMOV - - if (_stampa_saldo_des < 3) // Stampa saldo (non descrizioni) - { - bool print_sald = true; - if (_stampa_saldo_des != 2) // come dire == 1 - { - const TRecnotype rec = rmov.recno(); - if (rmov.next() == NOERR) - { - const int gruppof = rmov.get_int(RMV_GRUPPO); - const int contof = rmov.get_int(RMV_CONTO); - const long sottocf = rmov.get_long(RMV_SOTTOCONTO); - if (gruppof==_gruppo && contof==_conto && sottocf==_sottoc) - { - const TDate datasucc = rmov.get_date(RMV_DATAREG); - print_sald = datasucc != _dataregrmov; - } - rmov.readat(rec); - } - } - if (print_sald) - { - // Nuovo mpode semplificato - set_row (_rw,"@135g%r", &_saldo_progressivi); - } - } - } - else - { - ricerca_regiva(); - _protiva = atol(mov.get(MOV_PROTIVA)); - if (_protiva != 0) - set_row (_rw,"@127g%5d", _protiva); - } - _rw = 1; - - return TRUE; - } - else - return FALSE; - } - 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 - fai_stampa198(); - break; - default: - break; - } -} - -print_action TMastrini_application::postprocess_page(int file, int counter) -{ - if (_nummast == 1 || _nummast == 3) - { - if (counter) - { - if (_nummast == 1) //Il salto pagina a rottura di mastrino viene - printer().formfeed(); //fatto solo quando seleziono un mastrino per pagina - - reset_print(); // per evitare che stampi di nuovo il totale prec. - _stampa_progressivi_si = TRUE; - _stampa_footer_si = TRUE; - _riporto_dare = ZERO; - _riporto_avere = ZERO; - _riporto_footer_dare = ZERO; - _riporto_footer_avere = ZERO; - _riporto_parziale_dare = ZERO; - _riporto_parziale_avere = ZERO; - _ddociva_len = 0; - - return NEXT_PAGE; - } - } - else - if (_nummast == 2) - { - int item_lista = _lista.items(); - - if (counter && item_lista == 0) - { - reset_print(); // per evitare che stampi di nuovo il totale prec. - _stampa_progressivi_si = TRUE; - _stampa_footer_si = TRUE; - _riporto_dare = ZERO; - _riporto_avere = ZERO; - _riporto_footer_dare = ZERO; - _riporto_footer_avere = ZERO; - _riporto_parziale_dare = ZERO; - _riporto_parziale_avere = ZERO; - _ddociva_len = 0; - - return NEXT_PAGE; - } - } - - switch (file) - { - case LF_SALDI: - { - if (_nummast == 1 || _nummast == 3) - { - if (_selez_mastrini == 3) - { - reset_print(); - if (_numcarat == 1) - stampa_totali132(); - else if (_numcarat == 2) - stampa_totali198(); - - if (_stampatotiva) - stampa_totaliiva(); - } - else if (_selez_mastrini == 2) - { - reset_print(); - if ((_totale_saldo != 0.0) && (_puoi_stampare)) - { - if (_numcarat == 1) - stampa_totali132(); - else - stampa_totali198(); - } - if (_stampatotiva) - stampa_totaliiva(); - } - else if (_selez_mastrini == 1) - { - reset_print(); - if (_puoi_stampare) - { - if (_numcarat == 1) - stampa_totali132(); - else if (_numcarat == 2) - stampa_totali198(); - } - - if (_stampatotiva) - stampa_totaliiva(); - } - } - else - if (_nummast == 2) - { - if (!counter) - { - if (_numcarat == 1) - carica_array_totali132(); - else - carica_array_totali198(); - } - - if (_selez_mastrini == 3) - { - reset_print(); - if (_numcarat == 1) - stampa_totali132_II(); - else - stampa_totali198_II(); - } - else if (_selez_mastrini == 2) - { - reset_print(); - if ((_totale_saldo != 0.0) && (_puoi_stampare)) - if (_numcarat == 1) - stampa_totali132_II(); - else - stampa_totali198_II(); - } - else if (_selez_mastrini == 1) - { - reset_print(); - if (_puoi_stampare) - if (_numcarat == 1) - stampa_totali132_II(); - else - stampa_totali198_II(); - } - - int item_lista = _lista.items(); - - if (item_lista == 0) - { - int righe_rimaste = righe_rimaste_da_stampare(); - - righe_rimaste = righe_rimaste - _rw; //_rw sono le righe dei totali gia' settate, mentre - //righe rimaste conteneva le righe senza quelle dei totali gia' settate - if (righe_rimaste > 0) - { - _rw++; //incremento la riga altrimenti copro l'ultimo totale settato con una riga bianca - for (int i = 0; i < righe_rimaste; i++) - set_row(_rw++,"@0g "); - } - } - } - -// _stampa_progressivi_si = 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) - { - reset_print(); - print_one(file); - //_msk->reset(-9); // commentato 25-03-2015 - } - - return NEXT_PAGE; -} -// Stampa dei totali documenti iva se richiesta - -void TMastrini_application::stampa_totaliiva() -{ - real totale; - - if (_nummast == 1 || _nummast == 3) - { - _rw = 7; - _ddociva_len++; - - if (_stampatotiva) - { - TString16 fmt; fmt.format("@%dg", _ddociva_len); - fmt << "%15s"; - for (int j = 0; j < _b.items(); j++) - { - TDociva& riga = (TDociva&)_b[j]; - set_row(_rw+j, "@0g%s",(const char*) riga._descrdoc); - totale = riga._totdociva; - TString string = real2str(totale); - set_row(_rw+j, fmt, (const char*)string); - } - } - _b.destroy(); - } -} - -// Ricerca della descrizione relativa al codice causale di MOV.dta -// sull'archivio CAUS.dta -void TMastrini_application::descrizione_causale() -{ - const TRectype& caus = cache().get(LF_CAUSALI, _codcaus); - _descrcaus = caus.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() -{ - _tabtpd->zero(); - if (_tipodoc.full()) - { - TString4 dep; - dep.format("%2s",(const char*) _tipodoc); - _tabtpd->put("CODTAB", dep); - _tabtpd->read(); - } - _descrdociva = _tabtpd->get("S0"); - _natdoc = atoi(_tabtpd->get("I0")); -} - -void TMastrini_application::ricerca_regiva() -{ - _tabreg->zero(); - _tipo = 0; - if (_annoiva > 0 && _regiva.full()) - { - TString8 dep; dep.format("%04d%3s", _annoiva, (const char*)_regiva); - _tabreg->put("CODTAB", dep); - if (_tabreg->read() == NOERR) - _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; - _riporto_parziale_dare = ZERO; - _riporto_parziale_avere = ZERO; - _protiva = 0; - - _flag_del_cazzo = _nummast == 1; - - _stampa_progressivi_si = TRUE; - _stampa_footer_si = TRUE; - } - - return TRUE; -} - -bool TMastrini_application::set_print(int m) -{ - KEY tasto = K_ENTER; - while (tasto == K_ENTER) - { - _puoi_stampare = true; - // Controlla se esistono impostazioni di stampa in coda - if (sheet2mask()) - { - // Simula l'immediata pressione del tasto stampa senza nemmeno lanciare la maschera - tasto = K_ENTER; - } - else - { - tasto = _msk->run(); - if (tasto == K_ENTER) - { - // Se lo sheet e' vuoto allora usa solo la maschera corrente per la stampa, - // altrimenti estrae il primo elemento sovrascrivendo la maschera corrente. - // Questa figata cerca di correggere gli errori MI6185 e MI3592 in una botta - TSheet_field& sht = _msk->sfield(F_SCELTE); - if (sht.items() != 0) - sheet2mask(); // Estrae la prima riga dalla coda di stampa - } - } - if (tasto != K_ENTER) - break; - - _noseparator = _msk->get_bool(F_SEPARATOR); - if (_noseparator) - _real_picture = "################"; - else - _real_picture = "####.###.###.###"; - set_real_picture(_real_picture); - set_magic_currency(true); - - _codice_ditta = get_firm(); - _annomsk = _msk->get_int(F_ANNO); - - int gruppoini = _msk->get_int(F_GRUPPOINI); - int contoini = _msk->get_int(F_CONTOINI_CONTO); - long sottocontoini = _msk->get_long(F_SOTTOCINI_CONTO); - int gruppofine = _msk->get_int(F_GRUPPOFINE); - int contofine = _msk->get_int(F_CONTOFINE_CONTO); - long sottocontofine = _msk->get_long(F_SOTTOCFINE_CONTO); - - _stampaprogre = _msk->get_bool(F_STAMPAPROGRE); - _stampatotiva = _msk->get_bool(F_STAMPATOTIVA); - _stampa_cont = !_msk->get_bool(F_NOT_STAMPA_CONT); - _stampanum = _msk->get_int(F_STAMPANUM); - _stampa_mov_prov = _msk->get_bool(F_STAMPAMOVPROV); - _selez_mastrini = _msk->get_int(F_SELEZ_STAMPA); - - _numcarat = _msk->get_int(F_NUMCARAT); - _stampa_saldo_des = _numcarat==2 ? _msk->get_int(F_SALDO_DES) : 0; - _nummast = _msk->get_int(F_NUMMAST); - _data_ini = _msk->get_date(F_DATAINI); - _data_fine = _msk->get_date(F_DATAFINE); -#ifdef CONT_SEP - _cont_sep = _msk->get_bool(F_ST_CONTSEP); -#endif - - - TEsercizi_contabili esc; - - if (_annomsk != 0) - _anno_corrente = _annomsk; - else - { - _anno_ghost = esc.date2esc(_data_ini); - _anno_corrente = _anno_ghost; - _inizioes = esc[_anno_ghost].inizio(); - } - - data_fine_esercizio(_anno_corrente); // Ricalcola _data_inizioese e _data_finese - if (!_data_ini.ok()) _data_ini = _data_inizioese; - if (!_data_fine.ok()) _data_fine = _data_finese; - - _anno_precedente = esc.pred(_anno_corrente); - - ricerca_dati_ditta(); - - if (_nummast == 1 || _nummast == 3) - printer().footerlen(4); - else - printer().footerlen(2); - -//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); - - if (_msk->get_bool(F_SORTDESC)) - select_cursor(_cur2); - else - select_cursor(_cur1); - - TRectype da(LF_SALDI), a(LF_SALDI); - 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(); - - //_inizio_stampa = TRUE; - _numero_pag = 1; - if (_nummast == 3) - _pagina = 0; - else - _pagina = 1; - _cambia_mastrino = FALSE; - _rw = 0; - _conta_mastrini = 0; - _indice_lista = 0; - _ddociva_len = 0; - - _riga.destroy(); - _lista.destroy(); - - switch (_selez_mastrini) - { - case 1: _totale_saldo = 1.0; break; - case 2: _totale_saldo = 0.0; break; - case 3: _totale_saldo = 1.0; break; - default: break; - } - - enable_print_menu(); - enable_link(TR("Collegamento prima nota: "), 'b'); - - do - print(); - while (need_to_repeat_print()); - _msk->reset(-8); - - } - return FALSE; -} - -void TMastrini_application::data_fine_esercizio(int anno) -{ - TEsercizi_contabili esc; - _data_inizioese = esc[anno].inizio(); - _data_finese = esc[anno].fine(); -} - -void TMastrini_application::preprocess_header() -{ - if (_nummast == 1) - { - if (_selez_mastrini == 3) // Tutti - crea_intestazione(); - else - if (_selez_mastrini == 2) // Con saldo non nullo - { - if ((!_totale_saldo.is_zero()) && (_puoi_stampare)) - crea_intestazione(); - } - else if (_selez_mastrini == 1) - if (_puoi_stampare) - crea_intestazione(); - } - else - if (_nummast == 3 && !_gia_stampata_intestazione) - { - if (_selez_mastrini == 3) // Tutti - crea_intestazione(); - else - if (_selez_mastrini == 2) // Con saldo non nullo - { - if ((!_totale_saldo.is_zero()) && (_puoi_stampare)) - crea_intestazione(); - } - else if (_selez_mastrini == 1) // Movimentati nel periodo - if (_puoi_stampare) - crea_intestazione(); - } -} - -void TMastrini_application::preprocess_footer() -{ - reset_footer(); - - if (_nummast != 1 && _nummast != 3) - return; - - if (_devi_stampare_footer) - { - real dep_dare,dep_avere; - - if (_stampa_footer_si) - { - _riporto_footer_dare = _progredare + _riporto_parziale_dare; - _riporto_footer_avere = _progreavere + _riporto_parziale_avere; - - real imp_d,imp_a; - imp_d = _sezione == "D" ? _importo : ZERO; - imp_a = _sezione == "A" ? _importo : ZERO; - dep_dare = _stampato ? _riporto_footer_dare : _riporto_footer_dare - imp_d; - dep_avere = _stampato ? _riporto_footer_avere : _riporto_footer_avere - imp_a; - - _stampa_footer_si = FALSE; - } - else - { - _riporto_footer_dare += _riporto_parziale_dare; - _riporto_footer_avere += _riporto_parziale_avere; - - real imp_d,imp_a; - imp_d = _sezione == "D" ? _importo : ZERO; - imp_a = _sezione == "A" ? _importo : ZERO; - dep_dare = _stampato ? _riporto_footer_dare : _riporto_footer_dare - imp_d; - dep_avere = _stampato ? _riporto_footer_avere : _riporto_footer_avere - imp_a; - } - - if (_nummast != 3 || dep_dare != ZERO || dep_avere != ZERO) - { - TString dare (real2str(dep_dare)); - TString avere (real2str(dep_avere)); - if (_numcarat == 1) - { - set_footer (2,FR("@32gA RIPORTO@83g%s"), (const char*) dare); - set_footer (2,"@100g%s", (const char*) avere); - } - else - if (_numcarat == 2) - { - set_footer (2,FR("@32gA RIPORTO@100g%s"), (const char*) dare); - set_footer (2,"@117g%s", (const char*) avere); - } - } - } -} - -void TMastrini_application::conto(int gruppo, int conto, bool no_contropartita) -{ - TString16 key; - - key.format("%d|%d|", gruppo, conto); - - const TRectype & pconti = cache().get(LF_PCON, key); - - - 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() -{ - const TRectype & nditte = cache().get(LF_NDITTE, _codice_ditta); - - const long app = nditte.get_long(NDT_CODDITTA); - _ragsoc = nditte.get(NDT_RAGSOC); - - TString16 key; - key.format("%ld|1", app); - const TRectype& unloc = cache().get(LF_UNLOC, key); - - _indulc= unloc.get(ULC_INDULC); - _civulc= unloc.get(ULC_CIVULC); - int len = _indulc.len(); - if (len <= 31) - { - if (len <= 26) - _indulc << ' ' << _civulc; - else - _indulc << ' ' << _civulc.mid(0,5); - } - else - { - _indulc = _indulc.mid(0,31); - _indulc << ' ' << _civulc.mid(0,5); - } - _capulc= unloc.get(ULC_CAPULC); - _comulc= unloc.get(ULC_COMULC); - - key.format("|%s", (const char *) _comulc); - const TRectype& comuni = cache().get(LF_COMUNI, key); - - _com = comuni.get(COM_DENCOM); - _prov = comuni.get(COM_PROVCOM); -} - -// Crea l'intestazione per la stampa a 132 e a 198 caratteri - -void TMastrini_application::crea_intestazione() -{ - TString sep(133),sep1(198); - reset_header(); - - int np = get_page_number(); - - if (_cambia_mastrino) - { - if (_nummast != 3) - _pagina = 1; - _cambia_mastrino = FALSE; - } - if (_numcarat == 1) - { - if (_nummast == 3) - { - if (_pagina != np) - sep << "Pag. @#"; - } - else - sep << "Pag. " << _pagina; - sep.right_just(132); - set_header(1,(const char*) sep); - } - else if (_numcarat == 2) - { - if (_nummast == 3) - { - if (_pagina != np) - sep1 << "Pagina @#"; - } - else - sep1 << "Pagina " << _pagina; - sep1.right_just(198); - set_header(1,(const char*) sep1); - } - if (_nummast != 3) - _pagina++; - - if (_nummast != 3 || _pagina != np) - { - set_header (1, "@0g%s@6g%5ld", TR("DITTA"), _codice_ditta); - set_header (1, "@12g%-.45s", (const char*) _ragsoc); - set_header (1, "@59g%s", (const char*) _indulc); - 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 (2, "@122g%s", (const char *) _msk->get(F_DATASTAMPA)); - - if (_nummast == 3) - set_header (3, "@0g%s@12g@b%3d %3d %6ld", TR("Sottoconto"), _gruppo, _conto, _sottoc); - else - set_header (3, "@0g%s@12g%3d %3d %6ld", TR("Sottoconto"), _gruppo, _conto, _sottoc); - - switch(_tmcf) - { - case 'C': _tipo_mask = 1; break; - case 'F': _tipo_mask = 2; break; - default : _tipo_mask = 3; break; - } - - 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,"%s@19g%s@117g%s@126g%s@132g%s", - TR("Operazione"), TR("Documento"), TR("Contro"), TR("Nr"), TR("A")); - if (_stampa_mov_prov) - set_header(7,"@130gM"); - set_header (8, TR("Data")); - if (_stampanum < 3) - set_header (8,"@11g%s", TR("Numero")); - set_header (8,"@19g%s@30g%s@38g%s@61g%s@95g%s@111g%s@117g%s@126g%s@132g%s", - TR("Data"), TR("Numero"), TR("Cod.Causale"), TR("Descrizione"), - TR("Dare"), TR("Avere"), TR("Partita"), TR("Pro"), TR("C")); - if (_stampa_mov_prov) - set_header(8,"@130g%s", TR("P")); - sep.fill('_'); - set_header (9, (const char *) sep); - } - else - { - sep1.fill('_'); //Stampa 198 - (sep1(198)) - set_header (6,"@0g%s", (const char*)sep1); - if (_stampa_saldo_des == 3) - { - set_header (7,"%s@23g%s@183g%s@190g%s@197g%s", - TR("Operazione"), TR("Documento"), - TR("Reg"), TR("Nr"), TR("A")); - } - else - { - set_header (7,"%s@23g%s@169g%s@183g%s@190g%s@197g%s", - TR("Operazione"), TR("Documento"), TR("Contro"), - TR("Reg"), TR("Nr"), TR("A")); - } - if (_stampa_mov_prov) - set_header(7,"@195g%s", TR("M")); - set_header (8,TR("Data")); - if (_stampanum < 3) - set_header (8,"@11g%s", TR("Numero")); - - switch (_stampa_saldo_des) - { - case 1: - set_header (8,"@23g%s@34g%s@42g%s@70g%s@112g%s@127g%s@135g%s@152g%s@169g%s@183g%s@189g%s@197g%s", - TR("Data"), TR("Numero"), TR("Cod.Causale"), TR("Descrizione"), TR("Dare"), TR("Avere"), - TR("Saldo progre."), TR("Saldo movim."), TR("Partita"), TR("Iva"), TR("Prot"), TR("C")); - break; - case 2: - set_header (8,"@23g%s@34g%s@42g%s@70g%s@112g%s@127g%s@135g%s@152g%s@169g%s@183g%s@189g%s@197g%s", - TR("Data"), TR("Numero"), TR("Cod.Causale"), TR("Descrizione"), TR("Dare"), TR("Avere"), - TR("Saldo scalare"), TR("Saldo movim."), TR("Partita"), TR("Iva"), TR("Prot"), TR("C")); - break; - case 3: - set_header (8,"@23g%s@34g%s@42g%s@70g%s@112g%s@127g%s@135g%s@183g%s@189g%s@197g%s", - TR("Data"), TR("Numero"), TR("Cod.Causale"), TR("Descrizione"), TR("Dare"), TR("Avere"), - TR("Contropartita"), TR("Iva"), TR("Prot"), TR("C")); - break; - default: - break; - } - - if (_stampa_mov_prov) - set_header(8,"@195g%s", TR("P")); - sep1.fill('_'); - set_header (9,"@0g%s", (const char*)sep1); - } - - calcola_progressivi(); -// _saldo_progressivi += _saldo_progre_prec; // Se trovo quel cazzone che ha scritto sto programma... - - if (_stampa_progressivi_si) - { - if (_numcarat == 1) - { - set_header (10,"@42g%s@66g%s", TR("PROGRESSIVI PRECEDENTI"), real2str(_saldo_progre_prec)); - set_header (10,"@83g%s", real2str(_progredare)); - set_header (10,"@100g%s", real2str(_progreavere)); - } - else - { - set_header (10,"@70g%s@100g%s", TR("PROGRESSIVI PRECEDENTI"), real2str(_progredare)); - set_header (10,"@117g%s", real2str(_progreavere)); - if (_stampa_saldo_des < 3) - set_header (10,"@135g%s", real2str(_saldo_progre_prec)); - } - _riporto_dare = _progredare; - _riporto_avere = _progreavere; - _stampa_progressivi_si = FALSE; - } - else - { - _riporto_dare += _riporto_parziale_dare; - _riporto_avere += _riporto_parziale_avere; - - real dep_dare,dep_avere,imp_d,imp_a; - imp_d = _sezione == "D" ? _importo : ZERO; - imp_a = _sezione == "A" ? _importo : ZERO; - dep_dare = _stampato ? _riporto_dare : _riporto_dare - imp_d; - dep_avere = _stampato ? _riporto_avere : _riporto_avere - imp_a; - - if (_nummast != 3 || dep_dare != ZERO || dep_avere != 0) - { - if (_numcarat == 1) - { - set_header (10,"@32g%s@83g%s", TR("A RIPORTO"), real2str(dep_dare)); - set_header (10,"@100g%s", real2str(dep_avere)); - } - else - { - set_header (10,"@32g%s@100g%s", TR("A RIPORTO"), real2str(dep_dare)); - set_header (10,"@117g%s", real2str(dep_avere)); - } - } - _riporto_parziale_dare = ZERO; - _riporto_parziale_avere = ZERO; - } - - if (_numcarat == 1) - { - sep =""; - set_header(11,"@0g%s",(const char*) sep); - } - else - { - sep1 =""; - set_header(11,"@0g%s",(const char*) sep1); - } - - if (_pagina != np && _nummast == 3) - _pagina = np; -} - -int TMastrini_application::crea_intestazione(int start_riga) -{ - TString sep(132),sep1(198); - int r = start_riga + 2; - sep = ""; - - reset_header(); - - int np = get_page_number(); - - _conta_mastrini++; - - if (_nummast == 3) - _gia_stampata_intestazione = TRUE; - - if (_nummast == 2) - if (_cambia_mastrino) - { - _numero_pag = 1; - _cambia_mastrino = FALSE; - } - if (_nummast == 3) - { - if (_pagina != np) - { - if (_numcarat == 1) - { - sep << FR("Pag. @#"); - set_row(r,"@126g%s", (const char*) sep); - } - else if (_numcarat == 2) - { - sep << FR("Pagina @#"); - set_row(r,"@190g%s", (const char*) sep); - } - } - } - else - { - if (_numcarat == 1) - set_row(r,"@126g%s %2d", TR("Pag."), _numero_pag++); - else if (_numcarat == 2) - set_row(r,"@190g%s %2d", TR("Pagina"),_numero_pag++); - } - if (_nummast != 3 || _pagina != np) - { - set_row (r, "@0g%s@6g%5ld", TR("DITTA"), _codice_ditta); - set_row (r, "@12g%-45s", (const char*) _ragsoc); - set_row (r, "@59g%s", (const char*) _indulc); - //set_row (r, "@86g%-9s", (const char*) _civulc); - set_row (r, "@97g%-5s", (const char*) _capulc); - set_row (r, "@103g%-18s", (const char*) _com); - set_row (r, "@122g%-3s", (const char*) _prov); - r += 2; - } - if (_nummast == 3) - set_row (r, "@0g%s@12g@b%3d %3d %6ld", TR("Sottoconto"), _gruppo, _conto, _sottoc); - else - set_row (r, "@0g%s@12g%3d %3d %6ld", TR("Sottoconto"), _gruppo, _conto, _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: r = ricerca_clifo(r); - break; - case 2: r = ricerca_clifo(r); - break; - case 3: r = ricerca_gruppo(r); - break; - default: break; - } - - r++; - - if (_numcarat == 1) - { - sep.fill('_'); //Stampa 132 - (sep(132)) - set_row (r++,"@0g%s", (const char *) sep); - set_row (r++,"%s@19g%s@117g%s@131g%s", TR("Operazione"), TR("Documento"), TR("Contro"), TR("A")); - if (_stampa_mov_prov) - set_header(r-1,"@130g%s", TR("M")); - set_row (r, TR("Data")); - if (_stampanum < 3) - set_row (r,"@11g%s", TR("Numero")); - set_row (r++,FR("@19gData@30gNumero@38gCod.Causale@61gDescrizione@95gDare@111gAvere@117gPartita@131gC")); - if (_stampa_mov_prov) - set_header(r-1,"@130gP"); - sep.fill('_'); - set_row (r++,"@0g%s", (const char*)sep); - } - else - { - sep1.fill('_'); //Stampa 198 - (sep1(198)) - set_row (r++,"@0g%s", (const char*)sep1); - if (_stampa_saldo_des == 2) - set_row (r++,FR("Operazione@23gDocumento@183gReg@190gNumero@197gA")); - else - set_row (r++,FR("Operazione@23gDocumento@169gContro@183gReg@190gNumero@197gA")); - if (_stampa_mov_prov) - set_row(r-1,"@195gM"); - set_row (r,"Data"); - if (_stampanum < 3) - set_row (r,"@11gNumero"); - set_row (r,FR("@23gData@34gNumero@42gCod.Causale@70gDescrizione@112gDare@127gAvere")); - if (_stampa_saldo_des == 2) - set_row (r++,FR("@135gContropartita@183gIva@189gProt@197gC")); - else - set_row (r++,FR("@135gSaldo progre.@152gSaldo movim.@169gPartita@183gIva@189gProt@197gC")); - if (_stampa_mov_prov) - set_row (r-1,"@195gP"); - sep1.fill('_'); - set_row (r++,"@0g%s", (const char*)sep1); - } - _pagina = np; - return r; -} - -int TMastrini_application::stampa_progre_riporto(int start_riga) -{ - TString sep(132),sep1(198); - int r = start_riga; - - if (_stampa_progressivi_si) - { - r = stampa_progressivi(r); - _riporto_dare = _progredare; - _riporto_avere = _progreavere; - _stampa_progressivi_si = FALSE; - } - else - { - _riporto_dare += _riporto_parziale_dare; - _riporto_avere += _riporto_parziale_avere; - - real dep_dare,dep_avere,imp_d,imp_a; - imp_d = _sezione == "D" ? _importo : ZERO; - imp_a = _sezione == "A" ? _importo : ZERO; - dep_dare = _stampato ? _riporto_dare : _riporto_dare - imp_d; - dep_avere = _stampato ? _riporto_avere : _riporto_avere - imp_a; - - if (_nummast != 3 || dep_dare != ZERO || dep_avere != ZERO) - { - if (_numcarat == 1) - { - set_row (r,"@32g%s@83g%r", TR("A RIPORTO"), &dep_dare); - set_row (r++,"@100g%r", &dep_avere); - } - if (_numcarat == 2) - { - set_row (r,"@32g%s@100g%r", TR("A RIPORTO"), &dep_dare); - set_row (r++,"@117g%r", &dep_avere); - } - } - _riporto_parziale_dare = ZERO; - _riporto_parziale_avere = ZERO; - } - if (_numcarat == 1) - { - sep =""; - set_row(r++,"@0g%s",(const char*) sep); - } - else - { - sep1 =""; - set_row(r++,"@0g%s",(const char*) sep1); - } - return r; -} - - -void TMastrini_application::calcola_progressivi_al(const TDate& data_fin) -{ - static TBill _last_bill; - static TDate _last_date, _last_inizio; - static int _last_year; - static bool _last_provv; - static real _last_dare, _last_avere; - - const TDate data_inizio = _annomsk ? _data_inizioese : _inizioes; - - if (_annomsk == _last_year && data_inizio == _last_inizio && data_fin == _last_date && - _last_provv == _stampa_mov_prov && _last_bill == TBill(_gruppo, _conto, _sottoc)) - { - _totale_prima_dare = _last_dare; - _totale_prima_avere = _last_avere; - return; - } - - TLocalisamfile& rmov_file = current_cursor()->file(LF_RMOV); - const TRecnotype record = rmov_file.recno(); - - TRelation rel(LF_RMOV); - rel.add(LF_MOV, "NUMREG==NUMREG"); - const TRectype& mov = rel.curr(LF_MOV); - - TRectype& rmov = rel.curr(); - - rmov.zero(); - rmov.put(RMV_GRUPPO, _gruppo); - rmov.put(RMV_CONTO, _conto); - rmov.put(RMV_SOTTOCONTO, _sottoc); - TCursor cur(&rel, "", 2, &rmov, &rmov); - const long items = cur.items(); - cur.freeze(); - - _totale_prima_dare = ZERO; - _totale_prima_avere = ZERO; - - for (cur = 0L; cur.pos() < items; ++cur) - { - if (_stampa_mov_prov || mov.get(MOV_PROVVIS).blank()) - { - const int annoes = rmov.get_int (RMV_ANNOES); - const TDate datareg = mov.get_date(_annomsk ? MOV_DATACOMP : RMV_DATAREG); - - //Legge movimenti con data > inizio esercizio e < data_fin - if (((annoes==_annomsk)||(_annomsk == 0))&&(datareg >= data_inizio)&&(datareg <= data_fin)) - { - const char sezione = rmov.get_char(RMV_SEZIONE); - const real importo = rmov.get_real(RMV_IMPORTO); - if (sezione == 'D') - _totale_prima_dare += importo; - else - _totale_prima_avere += importo; - } - } - } - - // Riposiziona rmov - rmov_file.readat(record); - - _last_year = _annomsk; - _last_date = data_fin; - _last_inizio = data_inizio; - _last_bill.set(_gruppo, _conto, _sottoc); - _last_provv = _stampa_mov_prov; - _last_dare = _totale_prima_dare; - _last_avere = _totale_prima_avere; -} - -void TMastrini_application::calcola_progressivi(bool finali) -{ - /* fv 20/3/96: aggiustato per nuova struttura saldi - modificata ricerca - * record scaricati e assegnazione dare/avere relativo - Controllare che - * non occorra considerare il saldo di chiusura (SALDOFIN) aggiunto al - * record */ - - TLocalisamfile saldi(LF_SALDI); - real progdare_attuale,progavere_attuale,progdare_prec,progavere_prec; - real saldo,progredare_eseprec,progreavere_eseprec,saldoini_attuale,saldofine_attuale; - char salini,salini_attuale,salfine_attuale; - - saldo = ZERO; // saldo = Saldo iniziale (Guy: Ovvio no?) - - // Ricerca sull'archivio saldi dei record con gruppo,conto,sottoconto - // uguali a quelli di rmov per il calcolo dei progressivi precedenti - - saldi.setkey(2); - saldi.zero(); - saldi.put(SLD_GRUPPO, _gruppo); - saldi.put(SLD_CONTO, _conto); - saldi.put(SLD_SOTTOCONTO, _sottoc); - const TRectype record(saldi.curr()); - - for (saldi.read(_isgteq); saldi.good() && saldi.curr() == record; saldi.next()) - { - if (!saldi.get_bool(SLD_FLSCA)) - { - const int annoes_saldi = saldi.curr().get_int(SLD_ANNOES); - - //Calcola i progressivi dell'esercizio attuale - if (annoes_saldi == _anno_corrente) - { - progdare_attuale = saldi.get_real(SLD_PDARE); - progavere_attuale = saldi.get_real(SLD_PAVERE); - if (_stampa_mov_prov) - { - progdare_attuale += saldi.get_real(SLD_PDAREPRO); - progavere_attuale += saldi.get_real(SLD_PAVEREPRO); - } - - saldo = saldi.get_real(SLD_SALDO); - salini = saldi.get(SLD_FLAGSALINI)[0]; - _ultima_data_reg = saldi.get_date(SLD_DATAULMOV); - saldoini_attuale = saldi.get_real(SLD_SALDO); - salini_attuale = saldi.get_char(SLD_FLAGSALINI); - saldofine_attuale = saldi.get_real(SLD_SALDOFIN); - salfine_attuale = saldi.get_char(SLD_FLAGSALFIN); - } - } // if (!saldi.get_bool(SLD_FLSCA)) - } // 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) - { - if ((_indbil == 1) || (_indbil == 2) || (_indbil == 5)) - { - const TRecnotype pos = saldi.recno(); - // W96SALDI del 18-07-96 saldofin_esprec usa il flag TRUE xche' deve - // considerare anche il saldo finale - saldo = _sld->saldofin_esprec(_anno_corrente,_gruppo,_conto,_sottoc,TRUE, _stampa_mov_prov); - saldi.readat(pos); - - if (saldo > ZERO) - { - progredare_eseprec = saldo; - progdare_prec = saldo; - } - else if (saldo < ZERO) - { - saldo = -saldo; - progreavere_eseprec = saldo; - progavere_prec = saldo; - } - } - } - - if (finali) - { - calcola_progressivi_al(_data_fine); - } - else - { - TDate giorno_prima = _data_ini; --giorno_prima; // CM500429 - calcola_progressivi_al(giorno_prima); - } - -//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 = progredare_eseprec + _totale_prima_dare; - _progreavere = 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; - - if (salini_attuale == 'D') - _totprogre_dare_al += saldoini_attuale; - else - _totprogre_avere_al += saldoini_attuale; - if (salfine_attuale == 'D') - _totprogre_dare_al += saldofine_attuale; - else - _totprogre_avere_al += saldofine_attuale; - } - else - { - _totprogre_dare_al = progdare_attuale; - _totprogre_avere_al = progavere_attuale; - - if (salini_attuale == 'D') - _totprogre_dare_al += saldoini_attuale; - else if (salini_attuale == 'A') - _totprogre_avere_al += saldoini_attuale; - if (salfine_attuale == 'D') - _totprogre_dare_al += saldofine_attuale; - else if (salfine_attuale == 'A') - _totprogre_avere_al += saldofine_attuale; - } -} - -int TMastrini_application::stampa_progressivi(int start_riga) -{ - int r = start_riga; - - if (_numcarat == 1) - { - set_row (r,FR("@42gPROGRESSIVI PRECEDENTI@66g%r"), &_saldo_progre_prec); - set_row (r,"@83g%r", &_progredare); - set_row (r++,"@100g%r", &_progreavere); - } - else - { - set_row (r,FR("@70g%s@100g%r"), TR("PROGRESSIVI PRECEDENTI"), &_progredare); - set_row (r,"@117g%r", &_progreavere); - if (_stampa_saldo_des < 3) - set_row (r++,"@135g%r", &_saldo_progre_prec); - } - - return r; -} - -// 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,indcf,capcf,ptel,tel,dencom,dep; - TString4 provcom; - TString16 dataini,datafine,paiv,cofi; - TString descriz,descriz2; - int numrivd; - - TString16 key; - key.format("%c|%ld", _tmcf, _sottoc); - const TRectype & clifo = cache().get(LF_CLIFO, key); - ragsoc = clifo.get(CLI_RAGSOC); ragsoc.strip_double_spaces(); - paiv = clifo.get(CLI_PAIV); - cofi = clifo.get(CLI_COFI); - indcf = clifo.get(CLI_INDCF); - indcf.trim(); - indcf << ' ' << clifo.get(CLI_CIVCF); - capcf = clifo.get(CLI_CAPCF); - ptel = clifo.get(CLI_PTEL); - tel = clifo.get(CLI_TEL); - - const TString4 statocf = clifo.get(CLI_STATOCF); - const TString4 comcf = clifo.get(CLI_COMCF); - key.format("%s|%s", (const char *) statocf, (const char *) comcf); - const TRectype & comuni = cache().get(LF_COMUNI, key); - - if (!comuni.empty()) - { - dencom = comuni.get(COM_DENCOM); - provcom = comuni.get(COM_PROVCOM); - } - else - { - dencom = clifo.get(CLI_LOCCF); - provcom=""; - } - - key.format("%d|%d|", _gruppo, _conto); - - const TRectype & pconti = cache().get(LF_PCON, key); - _sezivd = pconti.get_char(PCN_SEZIVD); - _lettivd = pconti.get_char(PCN_LETTIVD); - numrivd = pconti.get_int(PCN_NUMRIVD); - _numrivd = itor(numrivd); - _numivd = pconti.get(PCN_NUMIVD); - - descriz = descrizione_classe(_sezivd,_lettivd,numrivd, _numivd); - - if (_numivd.not_empty()) //Ora devo stampare la descrizione del livello della - { //classe immediatamente precedente a quello appena - if (_numrivd.not_empty()) //stampato - descriz2 = descrizione_classe(_sezivd,_lettivd,_numrivd_int,""); - else - descriz2 = descrizione_classe(_sezivd,_lettivd,0,""); - } - else - if (_numrivd.not_empty()) - descriz2 = descrizione_classe(_sezivd,_lettivd,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%-.41s",(const char*) ragsoc); - if (_nummast == 3) - set_header (4, "@r%s@8g@b%c", TR("Classe"), _lettivd); - else - set_header (4, "%s@8g%c", TR("Classe") , _lettivd); - set_header (4, "@10g%-8s", (const char*) _numrivd); - if (_numivd.not_empty()) - set_header (4, "@19g%s", num2str(_numivd)); - if (descriz2 != "") - { - set_header (4,"@30g%-50s",(const char*) descriz2); - set_header (4,"@82g%-50s",(const char*) descriz); - } - else - set_header (4,"@30g%-50s",(const char*) descriz); - - dataini = _data_ini.string(); - datafine = _data_fine.string(); - - if (_annomsk == 0) - { - if (_nummast == 3) - { - set_header (5, FR("@rPeriodo@10g@b%s"), (const char*) dataini); - set_header (5, "@22g@b%s@r", (const char*) datafine); - } - else - { - set_header (5, FR("Periodo@10g%s"), (const char*) dataini); - set_header (5, "@22g%s", (const char*) datafine); - } - } - else - { - if (_nummast == 3) - { - set_header (5, FR("@rComp. da@9g@b%s"), (const char*) dataini); - set_header (5, "@20g@ra@22g@b%s@r", (const char*) datafine); - } - else - { - set_header (5, FR("Comp. da@9g%s"), (const char*) dataini); - set_header (5, "@20ga@22g%s", (const char*) datafine); - } - } - - set_header (5, FR("@33gP.I.@37g%-11s"),(const char*) paiv); - set_header (5, FR("@49gCF@52g%-16s"),(const char*) cofi); - set_header (5, "@66g%-.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,"@135g%-4s",(const char*) ptel); - if (tel != "") - set_header (5,"@138g/@139g%-10s",(const char*) tel); - } -} - -int TMastrini_application::ricerca_clifo(int start) -{ - TString ragsoc,paiv,cofi,indcf,capcf,ptel,tel,statocf,comcf,dencom,provcom,dep; - TString16 dataini,datafine; - TString descriz,descriz2; - int numrivd; - int r = start; - - indcf = ""; - - TString16 key; - - key.format("%c|%ld", _tmcf, _sottoc); - - const TRectype & clifo = cache().get(LF_CLIFO, key); - - ragsoc = clifo.get(CLI_RAGSOC); ragsoc.strip_double_spaces(); - paiv = clifo.get(CLI_PAIV); - cofi = clifo.get(CLI_COFI); - indcf = clifo.get(CLI_INDCF); - indcf.trim(); - indcf << " " << clifo.get(CLI_CIVCF); - 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); - - key.format("%s|%s", (const char *) statocf, (const char *) comcf); - - const TRectype & comuni = cache().get(LF_COMUNI, key); - - if (!comuni.empty()) - { - dencom = comuni.get(COM_DENCOM); - provcom = comuni.get(COM_PROVCOM); - } - else - { - dencom=clifo.get(CLI_LOCCF); - provcom=""; - } - - key.format("%d|%d|", _gruppo, _conto); - - const TRectype & pconti = cache().get(LF_PCON, key); - _sezivd = pconti.get_char(PCN_SEZIVD); - _lettivd = pconti.get_char(PCN_LETTIVD); - numrivd = pconti.get_int(PCN_NUMRIVD); - _numrivd = itor(numrivd); - _numivd = pconti.get(PCN_NUMIVD); - - descriz = descrizione_classe(_sezivd,_lettivd,numrivd,_numivd); - - if (_numivd.not_empty()) //Ora devo stampare la descrizione del livello della - { //classe immediatamente precedente a quello appena - if (_numrivd.not_empty()) //stampato - descriz2 = descrizione_classe(_sezivd,_lettivd,_numrivd_int,""); - else - descriz2 = descrizione_classe(_sezivd,_lettivd,0,""); - } - else - if (_numrivd.not_empty()) - descriz2 = descrizione_classe(_sezivd,_lettivd,0,""); - else - descriz2 = ""; - - set_row (r,"@27g%-30s",(const char*) descrizione_gruppo()); - set_row (r,"@59g%-30s",(const char*) descrizione_conto()); - set_row(r++, "@91g%-30s",(const char*) ragsoc); - if (_nummast == 3) - set_row(r, "@r%s@8g@b%c", TR("Classe"), _lettivd); - else - set_row(r, "%s@8g%c", TR("Classe"), _lettivd); - set_row(r, "@10g%-8s", (const char*) _numrivd); - if (_numivd.not_empty()) - set_row(r, "@19g%s", num2str(_numivd)); - if (descriz2.not_empty()) - { - set_row(r,"@30g%-50s",(const char*) descriz2); - set_row(r++,"@82g%-50s",(const char*) descriz); - } - else - set_row(r++,"@30g%-50s",(const char*) descriz); - - dataini = _data_ini.string(); - datafine = _data_fine.string(); - - if (_annomsk == 0) - { - if (_nummast == 3) - { - set_row (r, "@r%s@10g@b%s", TR("Periodo"), (const char*) dataini); - set_row (r, "@22g%s@r", (const char*) datafine); - } - else - { - set_row (r, "%s@10g%s", TR("Periodo"), (const char*) dataini); - set_row (r, "@22g%s", (const char*) datafine); - } - } - else - { - if (_nummast == 3) - { - set_row (r, "@r%s@9g@b%s", TR("Comp.dal"), (const char*) dataini); - set_row (r, "@20g@r%s@22g@b%s@r", TR("al"), (const char*) datafine); - } - else - { - set_row (r, "%s@9g%s", TR("Comp.dal"), (const char*) dataini); - set_row (r, "@20g%s@22g%s", TR("al"), (const char*) datafine); - } - } - - set_row (r, FR("@33gP.I.@37g%-11s"),(const char*) paiv); - set_row (r, FR("@49gCF@52g%-16s"),(const char*) cofi); - set_row (r, "@66g%-.25s",(const char*) indcf); - set_row (r, "@95g%-5s",(const char*) capcf); - set_row (r, "@101g%-.24s",(const char*) dencom); - set_row (r, "@126g%-5s",(const char*) provcom); - - if (_numcarat == 2) - { - set_row (r,"@135g%-4s",(const char*) ptel); - if (tel != "") - set_row (r++,"@138g/@139g%-10s",(const char*) tel); - } - return r; -} - - -// 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) -{ - TString16 key; - - if (scelta) - key.format("%d|%d|%ld", _gruppo, _conto, _sottoc); - else - key.format("%d|%d|", _gruppo, _conto); - - const TRectype & pconti = cache().get(LF_PCON, key); - _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(PCN_NUMIVD); -} - -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.not_empty()) //Ora devo stampare la descrizione del livello della - { //classe immediatamente precedente a quello appena - if (_numrivd.not_empty()) //stampato - descriz2 = descrizione_classe(_sezivd,_lettivd,_numrivd_int,""); - else - descriz2 = descrizione_classe(_sezivd,_lettivd,0,""); - } - else - if (_numrivd.not_empty()) - descriz2 = descrizione_classe(_sezivd,_lettivd,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%-.41s",(const char*) descrizione_sottoconto()); - if (_nummast == 3) - set_header (4, "@0g@r%s@12g@b%c", TR("Classe"), _lettivd); - else - set_header (4, "@0g%s@12g%c", TR("Classe"), _lettivd); - set_header (4, "@14g%-8s",(const char*) _numrivd); - if (_numivd.not_empty()) - set_header (4, "@23g%s", num2str(_numivd)); - if (descriz2.not_empty()) - { - set_header (4,"@34g%-48s",(const char*) descriz2); - set_header (4,"@82g%-50s",(const char*) descriz); - } - else - set_header (4,"@34g%-50s",(const char*) descriz); - - dataini = _data_ini.string(); - datafine = _data_fine.string(); - - if (_annomsk == 0) - { - if (_nummast == 3) - { - set_header (5, "@r%s@12g@b%s", TR("Periodo"), (const char*) dataini); - set_header (5, "@24g@b%s@r", (const char*) datafine); - } - else - { - set_header (5, "%s@12g%s", TR("Periodo"), (const char*) dataini); - set_header (5, "@24g%s", (const char*) datafine); - } - } - else - { - if (_nummast == 3) - { - set_header (5, "@r%s@23g@b%s", TR("Periodo di competenza"), (const char*) dataini); - set_header (5, "@35g%s@r", (const char*) datafine); - } - else - { - set_header (5, "%s@23g%s", TR("Periodo di competenza"), (const char*) dataini); - set_header (5, "@35g%s", (const char*) datafine); - } - } -} - -int TMastrini_application::ricerca_gruppo(int start) -{ - TString80 descr,descriz,descriz2,dep; - TString dataini,datafine; - int r = start; - - 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.not_empty()) //Ora devo stampare la descrizione del livello della - { //classe immediatamente precedente a quello appena - if (_numrivd.not_empty()) //stampato - descriz2 = descrizione_classe(_sezivd,_lettivd,_numrivd_int,""); - else - descriz2 = descrizione_classe(_sezivd,_lettivd,0,""); - } - else - if (_numrivd.not_empty()) - descriz2 = descrizione_classe(_sezivd,_lettivd,0,""); - else - descriz2 = ""; - - set_row(r,"@27g%-.30s",(const char*) descrizione_gruppo()); - set_row(r,"@59g%-.30s",(const char*) descrizione_conto()); - - set_row(r++,"@91g%-.41s",(const char*) descrizione_sottoconto()); - if (_nummast == 3) - set_row(r, "@0g@r%s@12g@b%c", TR("Classe"), _lettivd); - else - set_row(r, "@0g%s@12g%c", TR("Classe"), _lettivd); - set_row(r, "@14g%-8s",(const char*) _numrivd); - if (_numivd.not_empty()) - set_row(r, "@23g%-4s", num2str(_numivd)); - if (descriz2 != "") - { - set_row(r,"@34g%-48s",(const char*) descriz2); - set_row(r++,"@82g%-50s",(const char*) descriz); - } - else - set_row(r++,"@34g%-50s",(const char*) descriz); - - dataini = _data_ini.string(); - datafine = _data_fine.string(); - - if (_annomsk == 0) - { - if (_nummast == 3) - { - set_row (r, "@r%s@12g@b%s", TR("Periodo"), (const char*) dataini); - set_row (r, "@24g%s@r", (const char*) datafine); - } - else - { - set_row (r, "%s@12g%s", TR("Periodo"), (const char*) dataini); - set_row (r, "@24g%s", (const char*) datafine); - } - } - else - { - if (_nummast == 3) - { - set_row (r, "@r%s@23g@b%s", TR("Periodo di competenza"), (const char*) dataini); - set_row (r, "@35g%s@r", (const char*) datafine); - - } - else - { - set_row (r, "%s@23g%s", TR("Periodo di competenza"), (const char*) dataini); - set_row (r, "@35g%s", (const char*) datafine); - } - } - return r; -} - -const char* TMastrini_application::descrizione_classe(char sezione, char lettera, int numr, const char * numero) -{ - TString16 key; - - if (numr == 0 && numero == 0) - key.format("%c%c",sezione,lettera); - else - if (numero == 0) - key.format("%c%c%04d",sezione, lettera, numr); - else - { - if (numr != 0) - key.format("%c%c%04d%-4s",sezione, lettera, numr,numero); - else - key.format("%c%c %-4s",sezione,lettera,numero); - } - - return cache().get("%IVD", key, "S0"); -} - -//Ricerca la descrizione relativa al gruppo da stampare - -const char* TMastrini_application::descrizione_gruppo() -{ - return cache().get(LF_PCON, _gruppo, PCN_DESCR); -} - -// Ricerca la descrizione relativa al conto da stampare - -const char* TMastrini_application::descrizione_conto() -{ - TString8 key; key.format("%d|%d", _gruppo, _conto); - return cache().get(LF_PCON, key, PCN_DESCR); -} - -const char* TMastrini_application::descrizione_sottoconto() -{ - TString16 key; key.format("%d|%d|%ld", _gruppo, _conto, _sottoc); - return cache().get(LF_PCON, key, PCN_DESCR); -} - -// Funzione per settare tutti gli handlers della maschera principale -// o di quella dello spreadsheet della seconda pagina -void TMastrini_application::set_handlers(TMask* msk) const -{ - msk->set_handler(F_DATAINI, data_inizio); - msk->set_handler(F_DATAFINE, data_fine); - msk->set_handler(F_GRUPPOFINE, gruppo_hnd); - msk->set_handler(F_CONTOINI_CONTO, contoi_hnd); - msk->set_handler(F_CONTOFINE_CONTO, contof_hnd); - - 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); -} - -// Copia i parametri della prima pagina in una nuova riga dello spreadsheet -// a meno che non ci siano gia' -bool TMastrini_application::mask2sheet() -{ - bool ok = _msk->check_fields(); - - if (ok) - { - TToken_string row(120); - short id = F_ANNO; - for (int pos = _msk->id2pos(id); pos >= 0; pos = _msk->id2pos(++id)) - row.add(_msk->fld(pos).get()); - - if (!row.empty_items()) - { - TSheet_field& sht = _msk->sfield(F_SCELTE); - TString_array& rows = sht.rows_array(); - ok = rows.find(row) < 0; // Aggiunge solo se non c'e' gia' - if (ok) - { - rows.add(row); - sht.force_update(); - } - } - } - - return ok; -} - -bool TMastrini_application::sheet2mask() -{ - TSheet_field& sht = _msk->sfield(F_SCELTE); - bool ok = sht.items() > 0; - if (ok) - { - TString_array& rows = sht.rows_array(); - TToken_string& row = rows.row(0); - - short id = F_ANNO; - FOR_EACH_TOKEN(row, val) - { - // Scarta i listbox perche' azzerano i conti! - if (id != F_TIPOCF_INI && id != F_TIPOCF_FINE) - _msk->set(id, val); - id++; - } - - rows.destroy(0, TRUE); - } - return ok; -} - -bool TMastrini_application::user_create() -{ - TToken_string exp; - - _rel = new TRelation(LF_SALDI); - _rel->lfile().set_curr(new TMastrini_record); - - exp.add("GRUPPO=GRUPPO"); - exp.add("CONTO=CONTO"); - exp.add("SOTTOCONTO=SOTTOCONTO"); - _rel->add(LF_RMOV,exp,2,LF_SALDI); - - _rel->add("CMS", "CODTAB==CODCMS", 1, LF_RMOV, 501); - _rel->add("FSC", "CODTAB==FASCMS", 1, LF_RMOV, 502); - - _cur1=add_cursor(new TCursor(_rel, "FLSCA<=\" \"",2)); - open_files(LF_TAB, LF_TABCOM,LF_NDITTE, LF_UNLOC, LF_COMUNI, LF_MOV, - LF_CLIFO, LF_CAUSALI, 0); - _cur2=add_cursor(new TSorted_cursor(_rel, "DESCR","FLSCA<=\" \"",2)); - - _tabivd = new TTable (TAB_IVD); - _tabtpd = new TTable (TAB_TPD); - _tabreg = new TTable (TAB_REG); - _sld = new TSaldo (); - - _d18 = new TParagraph_string ("",18); - _d22 = new TParagraph_string ("",22); - _d30 = new TParagraph_string ("",30); - - _msk = new TMask("cg3200a"); - set_handlers(_msk); - _msk->set_handler(F_MEMORIZZA, memorizza_handler); - - TSheet_field& sht = _msk->sfield(F_SCELTE); - sht.set_notify(scelte_notify); - TMask& sm = sht.sheet_mask(); - set_handlers(&sm); - - _gia_stampata_intestazione = FALSE; - - return TRUE; -} - -bool TMastrini_application::user_destroy() -{ - delete _msk; - delete _rel; - delete _tabivd; - delete _tabtpd; - delete _tabreg; - delete _sld; - delete _d18; - delete _d22; - delete _d30; - - return TRUE; -} - -int cg3200(int argc, char* argv[]) -{ - TMastrini_application a; - a.run(argc, argv, TR("Stampa Mastrini")); - return 0; -} +#include "cg3.h" +#include "cg3200.h" +#include "cglib02.h" +#include "cglib03.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class TMastrini_record : public TRectype +{ + TBill _bill; + +protected: + virtual const TString& get_str(const char* fieldname) const; + virtual int length(const char* fieldname) const; + virtual TFieldtypes type(const char* fieldname) const; + +public: + TMastrini_record() : TRectype(LF_SALDI) { } + virtual ~TMastrini_record() { } +}; + +const TString& TMastrini_record::get_str(const char* fieldname) const +{ + if (xvt_str_same(fieldname, RMV_DESCR)) + { + const int g = atoi(TRectype::get_str(RMV_GRUPPO)); + const int c = atoi(TRectype::get_str(RMV_CONTO)); + const long s = atol(TRectype::get_str(RMV_SOTTOCONTO)); + ((TBill&)_bill).set(g, c, s); + return _bill.descrizione(); + } + return TRectype::get_str(fieldname); +} + +int TMastrini_record::length(const char* fieldname) const +{ + if (xvt_str_same(fieldname, RMV_DESCR)) + return 50; + return TRectype::length(fieldname); +} + +TFieldtypes TMastrini_record::type(const char* fieldname) const +{ + if (xvt_str_same(fieldname, RMV_DESCR)) + return _alfafld; + return TRectype::type(fieldname); +} + +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 contoi_hnd (TMask_field& f, KEY k); + static bool contof_hnd (TMask_field& f, KEY k); + static bool sottoc_handler_ini (TMask_field& f, KEY k); + static bool sottoc_handler_fine (TMask_field& f, KEY k); + + static bool memorizza_handler(TMask_field& f, KEY k); + static bool scelte_notify(TSheet_field& s, int r, KEY k); + + TDociva_array _b; + TRelation* _rel; + TMask* _msk; + TTable* _tabivd, * _tabtpd, * _tabreg; + TSaldo* _sld; + TParagraph_string* _d18,* _d22,* _d30; + TArray _riga, _lista; + + TDate _data_ini,_data_fine,_data_finese,_data_finesesucc,_ultima_data_reg; + TDate _datareg,_datadoc,_data_inizioese,_datareg_stampa,_inizioes; + int _cur1,_cur2,_gruppo,_conto,_numcarat,_stampanum,_annoiva; + int _numrig,_natdoc,_tipo,_selez_mastrini,_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,_riporto_footer_dare,_riporto_footer_avere; + TString _ragsoc,_indulc,_civulc,_capulc,_com,_prov,_comulc; + long _codice_ditta,_s_prec; + TString4 _tipodoc,_codcaus,_regiva; + TString _descrcaus,_descrdociva,_g_contr,_c_contr,_s_contr,_descrcontr,_numivd; + char _sezivd,_lettivd; + TString _descrizione,_sezione,_numdoc,_descrizionemov,_numrivd,_descr; + TString _dataregs, _datadocs; + int _gruppocontr,_contocontr,_nummast,_pagina; + TString _cont_sep; + long _sottocontocontr; + + bool _stampaprogre,_stampatotiva,_stampatot,_stampa_mov_prov, _stampa_cont; + bool _stampato,_devi_stampare_footer; + int _stampa_saldo_des; + + int _annomsk,_annoesmsk,_annoes,_annomsksucc,_tipo_mask,_anno_ghost; + int _anno_corrente,_anno_precedente,_indbil,_numero_pag; + long _sottoc,_numreg,_numgio,_protiva; + bool _stampa_progressivi_si,_competenza,/*_inizio_stampa,*/_puoi_stampare,_stampa_footer_si; + bool _cambia_mastrino,_gia_stampata_intestazione; + char _tmcf,_tipo_contr; + + bool _flag_del_cazzo; + + TDate _dataregrmov; + int _gruppof,_contof; + long _sottocf; + TString _dataregrmovstring,_importo_str,_saldo_movimenti_str; + + int _rw, _conta_mastrini, _indice_array, _item, _item_lista, _indice_lista; + int _ddociva_len; + + bool _noseparator; + TString _real_picture; + +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 preprocess_footer(); + virtual void set_page(int,int); + virtual bool process_link(int id, const char* txt); + + void set_handlers(TMask* msk) const; + bool mask2sheet(); + bool sheet2mask(); + + const char* real2str(const real& r) const; + +public: + + int date2esc(const TDate& d); + void ricerca_clifo(); + void ricerca_gruppo(); + int ricerca_clifo(int riga); + int ricerca_gruppo(int riga); + + void calcola_progressivi(bool finali = false); + void calcola_progressivi_al(const TDate& data); + int stampa_progressivi(int start_riga); + int stampa_progre_riporto(int start_riga); + void documenti_iva(); + void ricerca_regiva(); + void descrizione_causale(); + int crea_intestazione(int riga); + void crea_intestazione(); + void fai_stampa132(); + void fai_stampa198(); + void stampa_totali132(); + void stampa_totali198(); + void stampa_totali132_II(); + void stampa_totali198_II(); + void carica_array_totali132(); + void carica_array_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_sottoconto(); + const char* descrizione_classe(char,char,int,const char *); + bool almeno_un_record(); + void ricerca_dati_ditta(); + void conto(int,int,bool); + bool check_ordine(TMask_field& f, KEY k); + + void setta_riga (int r, const TString& riga); + int righe_rimaste_da_stampare(); + + TMastrini_application() {} + virtual ~TMastrini_application() {} +}; + +inline TMastrini_application& app() { return (TMastrini_application&)main_app(); } + +int TMastrini_application::righe_rimaste_da_stampare() +{ + int righe_rimaste = 0; + + if (_nummast == 2) + { + if (printer().rows_left() != 0) + { + if ( (_conta_mastrini % 2) != 0) + { + if ( (printer().formlen() % 2) != 0) + righe_rimaste = printer().rows_left() - (printer().formlen() / 2) + 1; //- 33; + else + righe_rimaste = printer().rows_left() - (printer().formlen() / 2); + } + else + righe_rimaste = printer().rows_left(); + } + else + { + if ( (_conta_mastrini % 2) != 0) + righe_rimaste = printer().formlen() / 2; //32; + else + { + if ( (printer().formlen() % 2) != 0) + righe_rimaste = (printer().formlen() / 2) + 1; //33; + else + righe_rimaste = printer().formlen() / 2; + } + } + } + + return righe_rimaste; +} + +bool TMastrini_application::process_link(int id, const char* txt) +{ + TRectype mov(LF_MOV); + mov.put(MOV_NUMREG, txt); + return mov.edit(); +} + +bool TMastrini_application::sottoc_handler_ini(TMask_field& f, KEY key) +{ + const TMask& m = f.mask(); + const short id = f.dlg(); + + const int gruppo = m.get_int(F_GRUPPOINI); + const int conto = m.get_int(F_CONTOINI_CONTO); + + const long sottoconto = m.get_long(id); + + if ( key == K_ENTER ) + { + if (sottoconto != 0 && conto == 0) + return f.warning_box(TR("Manca il CONTO")); + + if (conto != 0 && gruppo == 0) + return f.warning_box(TR("Manca il GRUPPO")); + } + + if (key == K_TAB && m.is_running()) + { + if (id == F_SOTTOCINI_CONTO && (gruppo != 0 || conto != 0 || sottoconto != 0L)) + { + TString16 key; + + key.format("%d|%d|%ld", gruppo, conto, sottoconto); + const TRectype & pconti = cache().get(LF_PCON, key); + + if (pconti.empty()) + return f.warning_box(TR("Sottoconto inesistente")); + + const TString & ds = pconti.get(PCN_DESCR); + + f.mask().set(F_DESCRINI_CONTO, ds); + f.mask().set(F_DESCRINI_CLIENTE, ds); + f.mask().set(F_DESCRINI_FORN, ds); + + } + else + if (id == F_SOTTOCINI_CLIENTE || id == F_SOTTOCINI_FORN) + { + char tipo = id == F_SOTTOCINI_CLIENTE ? 'C' : 'F'; + if (sottoconto != 0) + { + TString8 key; key.format("%c|%ld", tipo, sottoconto); + const TRectype & clifo = cache().get(LF_CLIFO, key); + if (clifo.empty()) + return f.warning_box(TR("Anagrafica inesistente")); + const TString & rs = clifo.get(CLI_RAGSOC); + + f.mask().set(F_DESCRINI_CLIENTE, rs); + f.mask().set(F_DESCRINI_FORN, rs); + + } + } + } + + return TRUE; +} + +bool TMastrini_application::sottoc_handler_fine(TMask_field& f, KEY key) +{ + const TMask& m = f.mask(); + const short id = f.dlg(); + TString ds; + TString80 rs; + + const int gruppo = m.get_int(F_GRUPPOFINE); + const int conto = m.get_int(F_CONTOFINE_CONTO); + + const long sottoconto = m.get_long(id); + + if ( key == K_ENTER ) + { + if (sottoconto != 0 && conto == 0) + return f.warning_box(TR("Manca il CONTO")); + + if (conto != 0 && gruppo == 0) + return f.warning_box(TR("Manca il GRUPPO")); + + if (!app().check_ordine(f,key)) + return FALSE; + } + + if ( key == K_TAB && m.is_running()) + { + if (id == F_SOTTOCFINE_CONTO && (gruppo != 0 || conto != 0 || sottoconto != 0L)) + { + TString16 key; + + key.format("%d|%d|%ld", gruppo, conto, sottoconto); + + const TRectype & pconti = cache().get(LF_PCON, key); + + if (pconti.empty()) + return f.warning_box(TR("Sottoconto inesistente")); + const TString & ds = pconti.get(PCN_DESCR); + + f.mask().set(F_DESCRFINE_CONTO, ds); + f.mask().set(F_DESCRFINE_CLIENTE, ds); + f.mask().set(F_DESCRFINE_FORN, ds); + + } + else + if (id == F_SOTTOCFINE_CLIENTE || id == F_SOTTOCFINE_FORN) + { + char tipo = id == F_SOTTOCFINE_CLIENTE ? 'C' : 'F'; + if (sottoconto != 0) + { + TString16 key; + + key.format("%c|%ld", tipo, sottoconto); + + const TRectype & clifo = cache().get(LF_CLIFO, key); + + if (clifo.empty()) + return f.warning_box(TR("Anagrafica inesistente")); + + const TString & rs = clifo.get(CLI_RAGSOC); + + f.mask().set(F_DESCRFINE_CLIENTE, rs); + f.mask().set(F_DESCRFINE_FORN, rs); + + } + } + } + return TRUE; +} + +bool TMastrini_application::gruppo_hnd (TMask_field& f, KEY k) +{ + if (k == K_ENTER) + { + const TMask& m = f.mask(); + int gruppof = m.get_int(F_GRUPPOFINE); + + if (gruppof == 0) + return TRUE; + + int gruppoi = m.get_int(F_GRUPPOINI); + + if (gruppoi > gruppof) + return f.error_box(TR("Il gruppo di partenza deve essere inferiore o uguale al gruppo di arrivo")); + } + + return TRUE; +} + +bool TMastrini_application::contoi_hnd (TMask_field& f, KEY k) +{ + if (k == K_TAB && f.focusdirty() && f.mask().is_running()) + { + TMask& m = f.mask(); + const short id = f.dlg(); + const int gruppo = m.get_int(F_GRUPPOINI); + const int conto = m.get_int(id); + + if (gruppo != 0 && conto != 0) + { + const char tipomsk = m.get(F_TIPOCF_INI)[0]; + + TString16 key; + key.format("%d|%d|", gruppo, conto); + + const TRectype & pconti = cache().get(LF_PCON, key); + + if (!pconti.empty()) + { + char tipo = pconti.get_char(PCN_TMCF); + if (tipomsk != tipo) + return f.warning_box(TR("Conto inesistente")); + } + + const TString& ds = pconti.get(PCN_DESCR); + m.set(F_DESCRINI_CLIENTE, ds); + m.set(F_DESCRINI_FORN, ds); + m.set(F_DESCRINI_CONTO, ds); + } + else + { + m.reset(F_DESCRINI_CLIENTE); + m.reset(F_DESCRINI_FORN); + m.reset(F_DESCRINI_CONTO); + } + } + + return TRUE; +} + +bool TMastrini_application::contof_hnd (TMask_field& f, KEY k) +{ + const short id = f.dlg(); + TMask& m = f.mask(); + + if (k == K_ENTER) + { + int gruppof = m.get_int(F_GRUPPOFINE); + + if (gruppof == 0) + return TRUE; + +// char tipo = m.get(F_TIPOCF_INI)[0]; + + int gruppoi = m.get_int(F_GRUPPOINI); + + if (gruppoi < gruppof) + return TRUE; + + int contof = m.get_int(id); + int contoi = m.get_int(F_CONTOINI_CONTO); + + if (contoi > contof) + return f.error_box(TR("Il conto di partenza deve essere inferiore o uguale al conto di arrivo")); + } + + if (k == K_TAB && f.focusdirty() && m.is_running()) + { + TString ds; + int gruppo = m.get_int(F_GRUPPOFINE); + int conto = m.get_int(id); + + if (gruppo != 0 && conto != 0 && m.field(F_DESCRFINE_CONTO).empty()) + { + char tipomsk = m.get(F_TIPOCF_FINE)[0]; + + TString16 key; + key.format("%d|%d|", gruppo, conto); + + const TRectype & pconti = cache().get(LF_PCON, key); + + if (pconti.empty()) + return f.warning_box(TR("Sottoconto inesistente")); + char tipo = pconti.get_char(PCN_TMCF); + if (tipomsk != tipo) + return f.warning_box(TR("Conto inesistente")); + + + const TString & ds = pconti.get(PCN_DESCR); + + m.set(F_DESCRFINE_CLIENTE, ds); + m.set(F_DESCRFINE_FORN, ds); + m.set(F_DESCRFINE_CONTO, ds); + + } + else + { + f.mask().reset(F_DESCRFINE_CLIENTE); + f.mask().reset(F_DESCRFINE_FORN); + f.mask().reset(F_DESCRFINE_CONTO); + } + } + + return TRUE; +} + +bool TMastrini_application::check_ordine(TMask_field& f, KEY k) +{ + const TMask& m = f.mask(); + const int gruppof = m.get_int(F_GRUPPOFINE); + + if (gruppof == 0) + return TRUE; + + const int gruppoi = m.get_int(F_GRUPPOINI); + + if (gruppoi < gruppof) + return TRUE; + + int contof = m.get_int(F_CONTOFINE_CONTO); + int contoi = m.get_int(F_CONTOINI_CONTO); + + if (contoi < contof) + return TRUE; + + long sottocf = m.get_long(F_SOTTOCFINE_CONTO); + long sottoci = m.get_long(F_SOTTOCINI_CONTO); + + if (sottoci > sottocf) + return f.error_box(TR("Il sottoconto di partenza deve essere inferiore o uguale al sottoconto di arrivo")); + + return TRUE; +} + +bool TMastrini_application::memorizza_handler(TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + if (app().mask2sheet()) + { + TMask& m = f.mask(); + m.reset(-9); + m.set_focus_field(F_TIPOCF_INI); + } + } + return TRUE; +} + +bool TMastrini_application::scelte_notify(TSheet_field& s, int r, KEY k) +{ + return k != K_INS; +} + +int TMastrini_application::date2esc(const TDate& d) +{ + TEsercizi_contabili esc; + return esc.date2esc(d); +} + +//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; + + if (current_cursor()->is_first_match(LF_RMOV)) + { + TLocalisamfile& rmov_file = current_cursor()->file(LF_RMOV); + const TRecnotype record = rmov_file.recno(); + + TRelation rel(LF_RMOV); + rel.add(LF_MOV, "NUMREG==NUMREG"); + TRectype& rmov = rel.curr(); + const TRectype& mov = rel.curr(LF_MOV); + + rmov.zero(); + rmov.put(RMV_GRUPPO, _gruppo); + rmov.put(RMV_CONTO, _conto); + rmov.put(RMV_SOTTOCONTO, _sottoc); + TCursor cur(&rel, "", 2, &rmov, &rmov); + const long items = cur.items(); + cur.freeze(); + for (cur = 0L; cur.pos() < items; ++cur) + { + const int annoes = rmov.get_int (RMV_ANNOES); + const TString4 provvis (mov.get(MOV_PROVVIS)); + const TDate datareg = _annomsk ? mov.get_date(MOV_DATACOMP) : rmov.get_date(RMV_DATAREG); + if ( ((annoes==_annomsk) || (_annomsk==0)) && ((datareg>=_data_ini) && (datareg<=_data_fine)) && (_stampa_mov_prov || provvis.blank())) + { + trovato = true; + break; + } + } + rmov_file.readat(record); + } + + return trovato; +} + +bool TMastrini_application::data_inizio(TMask_field& f, KEY k) +{ + const TDate data = f.mask().get_date(F_DATAINI); + const int anno = f.mask().get_int(F_ANNO); + app()._annomsk = anno; + + if (k == K_ENTER) + { + if (anno != 0) + { + app().data_fine_esercizio(anno); + + if (data.ok()) + { + if (data < app()._data_inizioese || data > app()._data_finese) + { + f.error_box(TR("La data non appartiene all'esercizio indicato")); + return FALSE; + } + else + app()._data_ini = data; + } + } + else + { + if (!data.ok()) + return f.error_box(TR("La data deve essere obbligatoriamente indicata")); + + if (app().date2esc(data) == 0) + return f.error_box(TR("La data indicata non appartiene ad alcun esercizio")); + else + app()._data_ini = data; + } + } + return TRUE; +} + +bool TMastrini_application::data_fine(TMask_field& f, KEY k) +{ + const TMask& m = f.mask(); + int annoes = m.get_int(F_ANNO); + TDate data = m.get_date(F_DATAFINE); + TDate data_ini = m.get_date(F_DATAINI); + app()._annomsk = annoes; + + if (k == K_ENTER) + { + if (annoes != 0) + { + app().data_fine_esercizio(annoes); + + if (data.ok()) + { + if (data < app()._data_inizioese || data > app()._data_finese) + { + f.error_box(TR("La data non appartiene all'esercizio indicato")); + return FALSE; + } + else + app()._data_fine = data; + } + } + else + { + if (data == botime) + return f.error_box(TR("La data deve essere obbligatoriamente indicata")); + + app()._anno_ghost = app().date2esc(data_ini); + + if (app()._anno_ghost == 0) + return f.error_box(TR("La data indicata non appartiene ad alcun esercizio")); + app()._data_fine = data; + } + + if (data < data_ini) + { + f.error_box(TR("La data finale non puo' essere inferiore alla data di partenza")); + return FALSE; + } + } + return TRUE; +} + +void TMastrini_application::fai_stampa132() +{ + if (_nummast == 1 || _nummast == 3) + _rw = 1; + else + if (_nummast == 2) + { + int riga; + + if ( (_conta_mastrini % 2) != 0 ) + riga = (printer().formlen() / 2); //-1 + else + riga = printer().formlen(); //-1; + + int app1 = printer().formlen(); + int app2 = printer().rows_left(); + int cur_row = (app1 - app2); + + if (cur_row == riga) + { + //_rw += 2; + _rw = crea_intestazione(_rw); + _rw = stampa_progre_riporto(_rw); + + if (_item != 0) + { + for (int i = _indice_array; i < _item; i++) + { + TString& data = (TString&)_riga[i]; + + int g1 = data.find("g",1); + int c1 = data.find("@",g1); + int g2 = data.find("g",c1); + + TString fmt1 = ""; + TString fmt2 = ""; + TString str1,str2; + + if (g1 != -1) + { + fmt1 = data.sub(0,g1+1); + fmt1 << "%s"; + str1 = data.sub(g1+1,c1); + } + if (c1 != -1) + { + fmt2 = data.sub(c1,g2+1); + fmt2 << "%s"; + str2 = data.sub(g2+1); + } + + if (fmt1 != "") + set_row (_rw,fmt1,(const char*) str1); + if (fmt2 != "") + set_row (_rw,fmt2,(const char*) str2); + + _rw++; + } + } + } + else + _rw = 1; + + if (_item != 0) + _riga.destroy(); + } + + set_row (_rw,"@0g#t", &_dataregs); + if (_stampanum == 1) + set_row (_rw,"@11g$[b]#7ld$[n]", &_numreg); + else + if (_stampanum == 2) + set_row (_rw,"@11g#7ld", &_numgio); + + set_row (_rw,"@19g#t", &_datadocs); + set_row (_rw,"@30g#7t", &_numdoc); + set_row (_rw,"@38g#3t", &_codcaus); + + if (_stampa_cont == 1) + set_row (_rw,"@117g#t #t #t", &_g_contr, &_c_contr, &_s_contr); +} + +void TMastrini_application::fai_stampa198() +{ + if (_nummast == 1 || _nummast == 3) + _rw = 1; + else + if (_nummast == 2) + { + int riga; + + if ( (_conta_mastrini % 2) != 0 ) + riga = (printer().formlen() / 2); //-1 + else + riga = printer().formlen(); //-1; + + int app1 = printer().formlen(); + int app2 = printer().rows_left(); + int cur_row = (app1 - app2); + + if (cur_row == riga) + { + //_rw += 2; + _rw = crea_intestazione(_rw); + _rw = stampa_progre_riporto(_rw); + + if (_item != 0) + { + for (int i = _indice_array; i < _item; i++) + { + TString& data = (TString&)_riga[i]; + + int g1 = data.find("g",1); + int c1 = data.find("@",g1); + int g2 = data.find("g",c1); + + TString fmt1 = ""; + TString fmt2 = ""; + TString str1,str2; + + if (g1 != -1) + { + fmt1 = data.sub(0,g1+1); + fmt1 << "%s"; + str1 = data.sub(g1+1,c1); + } + if (c1 != -1) + { + fmt2 = data.sub(c1,g2+1); + fmt2 << "%s"; + str2 = data.sub(g2+1); + } + + if (fmt1 != "") + set_row (_rw,fmt1,(const char*) str1); + if (fmt2 != "") + set_row (_rw,fmt2,(const char*) str2); + + _rw++; + } + } + } + else + _rw = 1; + + if (_item != 0) + _riga.destroy(); + } + + set_row (_rw,"@0g#t", &_dataregs); + if (_stampanum == 1) + { + set_row (_rw,"@11g$[b]#7ld$[n]", &_numreg); + set_row (_rw,"@18g/#3d", &_numrig); + } + else if (_stampanum == 2) + set_row (_rw,"@11g#7ld", &_numgio); + + set_row (_rw,"@23g#t", &_datadocs); + set_row (_rw,"@34g#7t", &_numdoc); + set_row (_rw,"@42g#3t", &_codcaus); + +// Stampa saldo movimenti / Descrizione contropartita + const TRectype& rmov = current_cursor()->curr(LF_RMOV); + _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); + + if (_stampa_saldo_des == 3) + { + if (_sottocontocontr > 0) + { + conto(_gruppocontr,_contocontr,FALSE); + TBill tc (_gruppocontr,_contocontr,_sottocontocontr,_tipo_contr); + _descrcontr.cut(0); + _descrcontr << _g_contr << ' ' << _c_contr << ' ' << _s_contr << ' ' << tc.descrizione(); + _descrcontr.cut(47); + set_row (_rw,"@135g%-48s", (const char*)_descrcontr); + } + else + { + _descrcontr.cut(0); + } + } + else + { + set_row (_rw,"@151g#t", &_saldo_movimenti_str); + set_row (_rw,"@168g#t #t #t", &_g_contr, &_c_contr, &_s_contr); + } +} + +void TMastrini_application::stampa_totali132() +{ + if (_nummast == 1 || _nummast == 3) + _rw = 2; + + const TString sep(132, '_'); //Stampa 132 - (sep(132)) + set_row(_rw++,"@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 (_rw,"@32g%s", TR("TOTALI PERIODO")); + set_row (_rw,"@66g%r", &_saldo_periodo); + set_row (_rw,"@83g%r", &_totale_periodo_dare); + set_row (_rw++,"@100g%r", &_totale_periodo_avere); + + set_row (_rw,"@32g%s", TR("TOTALI PROGRESSIVI")); + set_row (_rw,"@66g%r", &_saldo_progre); + set_row (_rw,"@83g%r", &_totprogre_dare); + set_row (_rw++,"@100g%r", &_totprogre_avere); + + if (_stampaprogre) //Progressivi attuali + { + set_row (_rw,"@32g%s %s", TR("TOTALI PROGRESSIVI AL"), _ultima_data_reg.string()); + set_row (_rw,"@66g%r", &_saldo_progre_al); + set_row (_rw,"@83g%r", &_totprogre_dare_al); + set_row (_rw,"@100g%r", &_totprogre_avere_al); + } + + _devi_stampare_footer = FALSE; +} + +const char* TMastrini_application::real2str(const real& r) const +{ + TString & str = get_tmp_string(30); + real2currency(str, r); + return str; +} + +void TMastrini_application::carica_array_totali132() +{ + TString sep(132); + TToken_string r(255); + + if (_nummast == 2) + _rw = 1; + + _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; + + sep.fill(' '); + r.add("@0g%s"); + r.add(sep); + _lista.add(r); + r = ""; + + sep.fill('_'); //Stampa 132 - (sep(132)) + r.add("@0g%s"); + r.add(sep); + _lista.add(r); + r = ""; + + r.add("@32g%s@66g%s@83g%s@100g%s"); + r.add(TR("TOTALI PERIODO")); + r.add(real2str(_saldo_periodo)); + r.add(real2str(_totale_periodo_dare)); + r.add(real2str(_totale_periodo_avere)); + _lista.add(r); + r = ""; + + r.add("@32g%s@66g%s@83g%s@100g%s"); + r.add(TR("TOTALI PROGRESSIVI")); + r.add(real2str(_saldo_progre)); + r.add(real2str(_totprogre_dare)); + r.add(real2str(_totprogre_avere)); + _lista.add(r); + r = ""; + + if (_stampaprogre) //Progressivi attuali + { + r.add("@32g%s@55g%s@66g%s@83g%s@100g%s"); + r.add(TR("TOTALI PROGRESSIVI AL")); + r.add(_ultima_data_reg.string()); + r.add(real2str(_saldo_progre_al)); + r.add(real2str(_totprogre_dare_al)); + r.add(real2str(_totprogre_avere_al)); + _lista.add(r); + r = ""; + } + + if (_stampatotiva) + { + real totale; + + sep.fill(' '); + r.add("@0g%s"); + r.add(sep); + _lista.add(r); + r = ""; + + TString fmt ("@0g%s"); + TString fmt1(format("@%dg", _ddociva_len)); + fmt << fmt1 << "%15s"; + + for (int j = 0; j < _b.items(); j++) + { + TDociva& riga = (TDociva&)_b[j]; + r.add(fmt); + r.add(riga._descrdoc); + totale = riga._totdociva; + r.add(real2str(totale)); + _lista.add(r); + r = ""; + } + + _b.destroy(); + } + + _indice_lista = 0; +} + +void TMastrini_application::stampa_totali132_II() +{ + int riga,cur_row,diff; + int lim = 0; + + _item_lista = _lista.items(); + + if ( (_conta_mastrini % 2) != 0 ) + { + riga = (printer().formlen() / 2); //- 1; + cur_row = printer().formlen() - printer().rows_left(); + diff = riga - cur_row; + } + else + { + riga = printer().formlen(); //- 1; + cur_row = printer().formlen() - printer().rows_left(); + diff = riga - cur_row; + } + + if (_indice_lista == 0 && diff != 0) + { + if (_item_lista > diff) + lim = diff; + else + lim = _item_lista; + } + else + { + lim = _item_lista; + _rw = 1; + _rw = crea_intestazione(_rw); + _rw = stampa_progre_riporto(_rw); + if ( (_conta_mastrini % 2) != 0 ) + { + riga = (printer().formlen() / 2); //- 1; + cur_row = _rw; + diff = riga - cur_row; + } + else + { + riga = printer().formlen(); //- 1; + cur_row = _rw + (printer().formlen() / 2); //32; + diff = riga - cur_row; + } + } + + for (int i = _indice_lista; i < lim; i++) + { + TToken_string& data = (TToken_string&)_lista[i]; + + TString fmt (data.get(0)); + TString arg1 (data.get(1)); + TString arg2 (data.get(2)); + TString arg3 (data.get(3)); + TString arg4 (data.get(4)); + + set_row(_rw++,fmt, (const char*) arg1, (const char*) arg2, (const char*) arg3, (const char*) arg4); + + _indice_lista++; + } + + if (_item_lista <= diff) + _lista.destroy(); + + _devi_stampare_footer = FALSE; +} + +void TMastrini_application::stampa_totali198() +{ + if (_nummast == 1 || _nummast == 3) + _rw = 1; + + const TString sep(198, '-'); //Stampa 198 - (sep(198)) + + set_row(_rw,"@0g%s", (const char*)sep); + + _totprogre_dare=_progredare+_totale_periodo_dare; + _totprogre_avere=_progreavere+_totale_periodo_avere; + + set_row (++_rw,"@32g%s@100g%r", TR("TOTALI PERIODO"), &_totale_periodo_dare); + set_row (_rw,"@117g%r", &_totale_periodo_avere); + + set_row (++_rw,"@32g%s@100g%r", TR("TOTALI PROGRESSIVI"), &_totprogre_dare); + set_row (_rw,"@117g%r", &_totprogre_avere); + + // il saldo totale movimenti non viene stampato se stampo le descrizioni delle contropartite + if (_stampa_saldo_des < 3) + { + set_row (_rw,"@135g%r", &_saldo_progressivi); + set_row (_rw,"@151g%r", &_saldo_movimenti); + } + + if (_stampaprogre) //Progressivi attuali + { + _saldo_progre_al = _totprogre_dare_al - _totprogre_avere_al; + set_row(++_rw,"@32g%s@55g%s", TR("TOTALI PROGRESSIVI AL"), _ultima_data_reg.string()); + set_row (_rw,"@100g%r", &_totprogre_dare_al); + set_row (_rw,"@117g%r", &_totprogre_avere_al); + if (_stampa_saldo_des < 3) + set_row (_rw,"@135g%r", &_saldo_progre_al); + } + + _devi_stampare_footer = FALSE; +} + +void TMastrini_application::carica_array_totali198() +{ + TString sep(198); + TToken_string r(255); + + if (_nummast == 2) + _rw = 1; + + sep.fill(' '); //Stampa 132 - (sep(132)) + r.add("@0g%s"); + r.add(sep); + _lista.add(r); + r = ""; + + sep.fill('_'); //Stampa 132 - (sep(132)) + r.add("@0g%s"); + r.add(sep); + _lista.add(r); + r = ""; + + _totprogre_dare=_progredare+_totale_periodo_dare; + _totprogre_avere=_progreavere+_totale_periodo_avere; + + if (_stampa_saldo_des == 3) + r.add("@32g%s@100g%s@117g%s"); + else + r.add("@32g%s@100g%s@117g%s@151g%s"); + r.add(TR("TOTALI PERIODO")); + r.add(real2str(_totale_periodo_dare)); + r.add(real2str(_totale_periodo_avere)); + r.add(real2str(_saldo_movimenti)); + _lista.add(r); + r = ""; + + if (_stampa_saldo_des == 3) + r.add("@32g%s@100g%s@117g%s"); + else + r.add("@32g%s@100g%s@117g%s@135g%s"); + r.add(TR("TOTALI PROGRESSIVI")); + r.add(real2str(_totprogre_dare)); + r.add(real2str(_totprogre_avere)); + r.add(real2str(_saldo_progressivi)); + _lista.add(r); + r = ""; + + if (_stampaprogre) //Progressivi attuali + { + _saldo_progre_al = _totprogre_dare_al - _totprogre_avere_al; + r.add("@32g%s@55g%s@100g%s@117g%s@135g%s"); + r.add(TR("TOTALI PROGRESSIVI AL")); + r.add(_ultima_data_reg.string()); + r.add(real2str(_totprogre_dare_al)); + r.add(real2str(_totprogre_avere_al)); + r.add(real2str(_saldo_progre_al)); + _lista.add(r); + r = ""; + } + + if (_stampatotiva) + { + real totale; + + sep.fill(' '); + r.add("@0g%s"); + r.add(sep); + _lista.add(r); + r = ""; + + TString16 fmt; + fmt << "@0g%s@" << _ddociva_len << "g%15s"; + + for (int j = 0; j < _b.items(); j++) + { + TDociva& riga = (TDociva&)_b[j]; + r.add(fmt); + r.add(riga._descrdoc); + totale = riga._totdociva; + r.add(real2str(totale)); + _lista.add(r); + r = ""; + } + + _b.destroy(); + } + + _indice_lista = 0; +} + +void TMastrini_application::stampa_totali198_II() +{ + int riga,cur_row,diff; + int lim = 0; + + _item_lista = _lista.items(); + + if ( (_conta_mastrini % 2) != 0 ) + { + riga = (printer().formlen() / 2); //- 1; + cur_row = printer().formlen() - printer().rows_left(); + diff = riga - cur_row; + } + else + { + riga = printer().formlen(); //- 1; + cur_row = printer().formlen() - printer().rows_left(); + diff = riga - cur_row; + } + + if (_indice_lista == 0 && diff != 0) + { + if (_item_lista > diff) + lim = diff; + else + lim = _item_lista; + } + else + { + lim = _item_lista; + _rw = 1; + _rw = crea_intestazione(_rw); + _rw = stampa_progre_riporto(_rw); + if ( (_conta_mastrini % 2) != 0 ) + { + riga = (printer().formlen() / 2); //- 1; + cur_row = _rw; + diff = riga - cur_row; + } + else + { + riga = printer().formlen(); //- 1; + cur_row = _rw + (printer().formlen() / 2); //32; + diff = riga - cur_row; + } + } + + for (int i = _indice_lista; i < lim; i++) + { + TToken_string& data = (TToken_string&)_lista[i]; + + TString fmt (data.get(0)); + TString arg1 (data.get(1)); + TString arg2 (data.get(2)); + TString arg3 (data.get(3)); + TString arg4 (data.get(4)); + TString arg5 (data.get(5)); + + set_row(_rw++,fmt, (const char*)arg1, (const char*)arg2, (const char*)arg3, + (const char*)arg4, (const char*)arg5); + + _indice_lista++; + } + + if (_item_lista <= diff) + _lista.destroy(); + + _devi_stampare_footer = FALSE; +} + +void TMastrini_application::setta_riga (int r, const TString& riga) +{ + TString* p = (TString*)_riga.objptr(r); + if (p == NULL) + _riga.add(riga); + else + *p << riga; +} + +bool TMastrini_application::preprocess_page(int file, int counter) +{ + if (counter) + return TRUE; + + switch (file) + { + case LF_SALDI: + { +// Usati in crea_intestazione() + + _devi_stampare_footer = TRUE; + + if (_nummast == 3 || _nummast == 2) + { + _rw = 0; + _rw++; + } + + const TRectype& saldi = current_cursor()->curr(LF_SALDI); + _gruppo = saldi.get_int(SLD_GRUPPO); + _conto = saldi.get_int(SLD_CONTO); + _sottoc = saldi.get_long(SLD_SOTTOCONTO); + + _cambia_mastrino = TRUE; + + const int annoes = saldi.get_int(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 (_selez_mastrini == 2) + { + calcola_progressivi(TRUE); + _totale_saldo = _saldo_progre_prec; + } + + if ((_selez_mastrini == 1) || (_selez_mastrini == 2)) + { + if ((_selez_mastrini == 1 && almeno_un_record()) || + (_selez_mastrini == 2 && _totale_saldo != ZERO)) + { + _puoi_stampare = TRUE; + + if (_nummast == 3 || _nummast == 2) + { + int cur_row = printer().formlen() - printer().rows_left(); + int diff = printer().formlen() - cur_row; + if (diff <= 13 && diff != 0) + printer().formfeed(); + + _rw = crea_intestazione(_rw); + calcola_progressivi(); + _saldo_progressivi += _saldo_progre_prec; + _rw = stampa_progre_riporto(_rw); + } + else + { + calcola_progressivi(); + _saldo_progressivi += _saldo_progre_prec; // Se trovo quel cazzone che ha scritto sto programma... + } + } + else + { + _puoi_stampare = FALSE; + return FALSE; + } + } + else + if (_selez_mastrini == 3) + { + calcola_progressivi(); + if (_progredare == ZERO && _progreavere == ZERO && !almeno_un_record()) + { + _puoi_stampare = FALSE; + return FALSE; + } + else + { + _puoi_stampare = TRUE; + + if (_nummast == 3 || _nummast == 2) + { + int cur_row = printer().formlen() - printer().rows_left(); + int diff = printer().formlen() - cur_row; + if (diff <= 13 && diff != 0) + printer().formfeed(); + + _rw = crea_intestazione(_rw); + _saldo_progressivi += _saldo_progre_prec; + _rw = stampa_progre_riporto(_rw); + } + } + } + } + break; + + case LF_RMOV: + { + TLocalisamfile& rmov = current_cursor()->file(LF_RMOV); + + //Il flag _gia_stampata_intestazione serve nella stampa in continuo, xche' + //sono costretto a richiamare l'intestazione sia nella preprocess_page (per + //i mastrini con intestazione a meta' pagina), sia nella preprocess_header + //per i mastrini che si trovano a cavallo fra una pagina e quella successiva. + //In quest'ultimo caso infatti quando vado a pagina nuova devo stampare l'intestazione + //ma senza il flag rischio di stamparla due volte. + if (_nummast == 3) + _gia_stampata_intestazione = FALSE; + + if (_nummast == 1 || _nummast == 3) + _rw = 1; + + // Ricerca la contropartita di quel movimento + + _numreg = rmov.get_long(RMV_NUMREG); + _numrig = rmov.get_int(RMV_NUMRIG); + + _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 = rmov.get_real(RMV_IMPORTO); + _importo_str = real2str(_importo); + const TRectype & mov = cache().get(LF_MOV, _numreg); + + _annoes = mov.get_int(MOV_ANNOES); + _regiva = mov.get(MOV_REG); + _annoiva = mov.get_int(MOV_ANNOIVA); + + + // Controlla se saldo e' diverso da 0 + + if (((_annoes == _annomsk) || (_annomsk == 0)) && (!_totale_saldo.is_zero())) + { + _sezione = rmov.get(RMV_SEZIONE); + + if (_annomsk == 0) + { + _datareg = mov.get(MOV_DATAREG); + + _datareg_stampa = _datareg; + } + else + if (_annomsk != 0) + { + _datareg = mov.get(MOV_DATACOMP); + _datareg_stampa = mov.get(MOV_DATAREG); + } + + + const TString4 provvis = mov.get(MOV_PROVVIS); + + + _dataregs = _datareg_stampa.string(); + + if ((_stampa_mov_prov)||((!_stampa_mov_prov)&&(provvis.blank()))) + { + 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 (_rw, "@132g*"); + else + set_row (_rw, "@197g*"); + + if (_stampa_mov_prov && !provvis.blank()) + if (_numcarat == 1) + set_row(_rw, "@130gP"); + else + set_row(_rw, "@195gP"); + + _codcaus = mov.get(MOV_CODCAUS); + _tipodoc = mov.get(MOV_TIPODOC); + + if (_stampatotiva && (_tmcf == 'C' || _tmcf == 'F')) + { + if (_tipodoc != "") + { + documenti_iva(); + _b.add_riga(_descrdociva,_importo, _natdoc); + if (_descrdociva.len() > _ddociva_len) + _ddociva_len = _descrdociva.len(); + } + } + _datadoc = (mov.get(MOV_DATADOC)); + + _datadocs = _datadoc.string(); + _numdoc = mov.get(MOV_NUMDOC); + + descrizione_causale(); + _descrizionemov = mov.get(MOV_DESCR); + +#ifdef CONT_SEP + _descrizionemov << " " << cache().get("&NPENT", mov.get(MOV_CONTSEP), "S0"); +#endif + + _numgio = atol(mov.get(MOV_NUMGIO)); + + + _descrizione = rmov.get(RMV_DESCR); + + _d18->cut(0); _d22->cut(0); _d30->cut(0); + + if (_nummast == 1 || _nummast == 3) + { + if (_numcarat == 1) // Stampa 132 caratteri + { + if (_descrizione != "") + { + *_d22 = (const char*) _descrizione; + if (_descrizionemov != "") + { + *_d18 = (const char*) _descrizionemov; + set_row(_rw, "@42g#a", _d18); + set_row(_rw, "@61g#a", _d22); + } + else if (_descrizionemov == "") + { + *_d18 = (const char*) _descrcaus; + set_row(_rw, "@42g#a", _d18); + set_row(_rw, "@61g#a", _d22); + } + } + else if (_descrizione == "") + if (_descrizionemov != "") + { + *_d22 = (const char*) _descrizionemov; + *_d18 = (const char*) _descrcaus; + set_row (_rw,"@42g#a", _d18); + set_row (_rw,"@61g#a", _d22); + } + else + if (_descrizionemov == "") + { + conto(_gruppocontr,_contocontr,FALSE); + TBill tc (_gruppocontr,_contocontr,_sottocontocontr,_tipo_contr); + _descrcontr = tc.descrizione(); + *_d18 = (const char*) _descrcaus; + set_row (_rw,"@42g#a", _d18); + if (_descrcontr != "Sconosciuto") + { + *_d22 = (const char*) _descrcontr; + set_row (_rw,"@61g#a", _d22); + } + } + } + else + if (_numcarat == 2) // Stampa 198 caratteri + { + if (_descrizione != "") + { + *_d30 = (const char*) _descrizione; + if (_descrizionemov != "") + { + *_d22 = (const char*) _descrizionemov; + set_row (_rw,"@46g#a", _d22); + set_row (_rw,"@70g#a", _d30); + } + else if (_descrizionemov == "") + { + *_d22 = (const char*) _descrcaus; + set_row(_rw, "@46g#a", _d22); + set_row(_rw, "@70g#a", _d30); + } + } + else if (_descrizione == "") + if (_descrizionemov.not_empty()) + { + *_d30 = (const char*) _descrizionemov; + *_d22 = (const char*) _descrcaus; + set_row (_rw,"@46g#a", _d22); + set_row (_rw,"@70g#a", _d30); + } + else + { + conto(_gruppocontr,_contocontr,FALSE); + TBill tc (_gruppocontr,_contocontr,_sottocontocontr,_tipo_contr); + _descrcontr = tc.descrizione(); + *_d22 = (const char*) _descrcaus; + set_row (_rw,"@46g#a", _d22); + if (_descrcontr != "Sconosciuto") + { + *_d30 = (const char*)_descrcontr; + set_row (_rw,"@70g#a", _d30); + } + } + } + } //if (_nummast == 1 || _nummast == 3) + + if (_nummast == 2) + { + TString d18,d23,d30; + + if (_numcarat == 1) // Stampa 132 caratteri + { + if (_descrizione != "") + { + d23 = _descrizione; + if (_descrizionemov.not_empty()) + d18 = _descrizionemov; + else + d18 = _descrcaus; + } + else if (_descrizione.empty()) + { + if (_descrizionemov.not_empty()) + { + d23 = _descrizionemov; + d18 = _descrcaus; + } + else + { + conto(_gruppocontr,_contocontr,FALSE); + TBill tc (_gruppocontr,_contocontr,_sottocontocontr,_tipo_contr); + _descrcontr = tc.descrizione(); + d18 = _descrcaus; + if (_descrcontr != "Sconosciuto") + d23 = _descrcontr; + } + } + TParagraph_string d_18 (d18,18); + int i = 0; + const char* str; + while ( (str = d_18.get()) != NULL) + { + TString stringa; + stringa << "@42g" << str; + setta_riga(i,stringa); + i++; + } + + TParagraph_string d_23 (d23,23); + i = 0; + while ( (str = d_23.get()) != NULL) + { + TString stringa; + stringa << "@61g" << str; + setta_riga(i,stringa); + i++; + } + } + else + if (_numcarat == 2) // Stampa 198 caratteri + { + if (_descrizione.not_empty()) + { + d30 = _descrizione; + if (_descrizionemov != "") + d23 = _descrizionemov; + else if (_descrizionemov == "") + d23 = _descrcaus; + } + else + { + if (_descrizionemov.not_empty()) + { + d30 = _descrizionemov; + d23 = _descrcaus; + } + else + { + conto(_gruppocontr,_contocontr,FALSE); + TBill tc (_gruppocontr,_contocontr,_sottocontocontr,_tipo_contr); + _descrcontr = tc.descrizione(); + d23 = _descrcaus; + if (_descrcontr != "Sconosciuto") + d30 = _descrcontr; + } + } + TParagraph_string d_23 (d23,23); + int i = 0; + const char* str; + while ( (str = d_23.get()) != NULL) + { + TString stringa; + stringa << "@46g" << str; + setta_riga(i,stringa); + i++; + } + + TParagraph_string d_30 (d30,30); + i = 0; + while ( (str = d_30.get()) != NULL) + { + TString stringa; + stringa << "@70g" << str; + setta_riga(i,stringa); + i++; + } + } + + _item = _riga.items(); + int riga,cur_row,diff; + + if ( (_conta_mastrini % 2) != 0 ) + { + int app = 0; + riga = (printer().formlen() / 2); + if (printer().rows_left() == 0) + app = printer().formlen() - _rw; + else + app = printer().rows_left(); + cur_row = printer().formlen() - app; + diff = riga - cur_row; + } + else + { + riga = printer().formlen(); + cur_row = printer().formlen() - printer().rows_left(); + diff = riga - cur_row; + } + + bool stampa_riporti; + + int lim = 0; + if (_item >= diff) + { + lim = diff - 1; + stampa_riporti = TRUE; + } + else + { + lim = _item; + stampa_riporti = FALSE; + } + + _indice_array = 0; + + int k = _rw; + + for (int i = 0; i < lim; i++) + { + TString& data = (TString&)_riga[i]; + + int g1 = data.find("g",1); + int c1 = data.find("@",g1); + int g2 = data.find("g",c1); + + TString fmt1 = ""; + TString fmt2 = ""; + TString str1,str2; + + if (g1 != -1) + { + fmt1 = data.sub(0,g1+1); + fmt1 << "%s"; + str1 = data.sub(g1+1,c1); + } + if (c1 != -1) + { + fmt2 = data.sub(c1,g2+1); + fmt2 << "%s"; + str2 = data.sub(g2+1); + } + + if (fmt1 != "") + set_row (k,fmt1,(const char*) str1); + if (fmt2 != "") + set_row (k,fmt2,(const char*) str2); + + k++; + _indice_array++; + } + if (stampa_riporti) + { + _rw = k; + if (lim == 0) + { + if (_numcarat == 1) + { + TString app(132); + app.spaces(); + set_row (_rw, "@0g%s", (const char*)app); + } + else + { + TString app(198); + app.spaces(); + set_row (_rw, "@0g%s", (const char*)app); + } + } + real dep_dare,dep_avere; + if (_stampa_footer_si) + { + _riporto_footer_dare = _progredare + _riporto_parziale_dare; + _riporto_footer_avere = _progreavere + _riporto_parziale_avere; + + real imp_d,imp_a; + imp_d = _sezione == "D" ? _importo : ZERO; + imp_a = _sezione == "A" ? _importo : ZERO; + if (lim != 0) + { + _riporto_footer_dare += imp_d; + _riporto_footer_avere += imp_a; + } + dep_dare = _riporto_footer_dare; + dep_avere = _riporto_footer_avere; + + _stampa_footer_si = FALSE; + } + else + { + _riporto_footer_dare += _riporto_parziale_dare; + _riporto_footer_avere += _riporto_parziale_avere; + + real imp_d,imp_a; + imp_d = _sezione == "D" ? _importo : ZERO; + imp_a = _sezione == "A" ? _importo : ZERO; + if (lim != 0) + { + _riporto_footer_dare += imp_d; + _riporto_footer_avere += imp_a; + } + dep_dare = _riporto_footer_dare; + dep_avere = _riporto_footer_avere; + } + + if (_nummast != 3 || dep_dare != ZERO || dep_avere != ZERO) + { + TString dare (real2str(dep_dare)); + TString avere (real2str(dep_avere)); + if (_numcarat == 1) + { + set_row (_rw,FR("@32gA RIPORTO@83g%s"), (const char*) dare); + set_row (_rw,"@100g%s", (const char*) avere); + } + else + if (_numcarat == 2) + { + set_row (_rw,FR("@32gA RIPORTO@100g%s"), (const char*) dare); + set_row (_rw,"@117g%s", (const char*) avere); + } + } + if (lim == 0) + { + rmov.prev(); + _riga.destroy(); + _item = 0; + return TRUE; + } + _rw--; + } + //_riga.destroy(); + } + + if (_sezione == "D") + { + _totale_periodo_dare += _importo; + _riporto_parziale_dare += _importo; + + + if (_numcarat == 1) // Stampa 132 caratteri + set_row (_rw,"@83g%s", (const char*) _importo_str); + else // Stampa 198 caratteri + { + _saldo_progressivi += _importo; + _saldo_movimenti += _importo; + set_row (_rw,"@100g%s", (const char*) _importo_str); + } + } + else + { + _totale_periodo_avere += _importo; + _riporto_parziale_avere += _importo; + + + if (_numcarat == 1) // Stampa 132 caratteri + set_row (_rw,"@100g%s", (const char*) _importo_str); + else // Stampa 198 caratteri + { + _saldo_progressivi -= _importo; + _saldo_movimenti -= _importo; + set_row (_rw,"@117g%s", (const char*) _importo_str); + } + } + + const int righe_rimaste = printer().rows_left(); + _stampato = righe_rimaste >= 1; + + _saldo_movimenti_str=real2str(_saldo_movimenti); + if (_numcarat == 2) + { + ricerca_regiva(); + _protiva = mov.get_long(MOV_PROTIVA); + if (_protiva != 0) + set_row (_rw,"@191g%5d", _protiva); + + if (_tipo < 3) + set_row (_rw,"@183g#t" , &_regiva); + _dataregrmov = current_cursor()->curr(LF_RMOV).get_date(RMV_DATAREG); + +//Gestire la stampa di saldo_progressivi nella postprocess_page di RMOV + + if (_stampa_saldo_des < 3) // Stampa saldo (non descrizioni) + { + bool print_sald = true; + if (_stampa_saldo_des != 2) // come dire == 1 + { + const TRecnotype rec = rmov.recno(); + if (rmov.next() == NOERR) + { + const int gruppof = rmov.get_int(RMV_GRUPPO); + const int contof = rmov.get_int(RMV_CONTO); + const long sottocf = rmov.get_long(RMV_SOTTOCONTO); + if (gruppof==_gruppo && contof==_conto && sottocf==_sottoc) + { + const TDate datasucc = rmov.get_date(RMV_DATAREG); + print_sald = datasucc != _dataregrmov; + } + rmov.readat(rec); + } + } + if (print_sald) + { + // Nuovo mpode semplificato + set_row (_rw,"@135g%r", &_saldo_progressivi); + } + } + } + else + { + ricerca_regiva(); + _protiva = atol(mov.get(MOV_PROTIVA)); + if (_protiva != 0) + set_row (_rw,"@127g%5d", _protiva); + } + _rw = 1; + + return TRUE; + } + else + return FALSE; + } + 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 + fai_stampa198(); + break; + default: + break; + } +} + +print_action TMastrini_application::postprocess_page(int file, int counter) +{ + if (_nummast == 1 || _nummast == 3) + { + if (counter) + { + if (_nummast == 1) //Il salto pagina a rottura di mastrino viene + printer().formfeed(); //fatto solo quando seleziono un mastrino per pagina + + reset_print(); // per evitare che stampi di nuovo il totale prec. + _stampa_progressivi_si = TRUE; + _stampa_footer_si = TRUE; + _riporto_dare = ZERO; + _riporto_avere = ZERO; + _riporto_footer_dare = ZERO; + _riporto_footer_avere = ZERO; + _riporto_parziale_dare = ZERO; + _riporto_parziale_avere = ZERO; + _ddociva_len = 0; + + return NEXT_PAGE; + } + } + else + if (_nummast == 2) + { + int item_lista = _lista.items(); + + if (counter && item_lista == 0) + { + reset_print(); // per evitare che stampi di nuovo il totale prec. + _stampa_progressivi_si = TRUE; + _stampa_footer_si = TRUE; + _riporto_dare = ZERO; + _riporto_avere = ZERO; + _riporto_footer_dare = ZERO; + _riporto_footer_avere = ZERO; + _riporto_parziale_dare = ZERO; + _riporto_parziale_avere = ZERO; + _ddociva_len = 0; + + return NEXT_PAGE; + } + } + + switch (file) + { + case LF_SALDI: + { + if (_nummast == 1 || _nummast == 3) + { + if (_selez_mastrini == 3) + { + reset_print(); + if (_numcarat == 1) + stampa_totali132(); + else if (_numcarat == 2) + stampa_totali198(); + + if (_stampatotiva) + stampa_totaliiva(); + } + else if (_selez_mastrini == 2) + { + reset_print(); + if ((_totale_saldo != 0.0) && (_puoi_stampare)) + { + if (_numcarat == 1) + stampa_totali132(); + else + stampa_totali198(); + } + if (_stampatotiva) + stampa_totaliiva(); + } + else if (_selez_mastrini == 1) + { + reset_print(); + if (_puoi_stampare) + { + if (_numcarat == 1) + stampa_totali132(); + else if (_numcarat == 2) + stampa_totali198(); + } + + if (_stampatotiva) + stampa_totaliiva(); + } + } + else + if (_nummast == 2) + { + if (!counter) + { + if (_numcarat == 1) + carica_array_totali132(); + else + carica_array_totali198(); + } + + if (_selez_mastrini == 3) + { + reset_print(); + if (_numcarat == 1) + stampa_totali132_II(); + else + stampa_totali198_II(); + } + else if (_selez_mastrini == 2) + { + reset_print(); + if ((_totale_saldo != 0.0) && (_puoi_stampare)) + if (_numcarat == 1) + stampa_totali132_II(); + else + stampa_totali198_II(); + } + else if (_selez_mastrini == 1) + { + reset_print(); + if (_puoi_stampare) + if (_numcarat == 1) + stampa_totali132_II(); + else + stampa_totali198_II(); + } + + int item_lista = _lista.items(); + + if (item_lista == 0) + { + int righe_rimaste = righe_rimaste_da_stampare(); + + righe_rimaste = righe_rimaste - _rw; //_rw sono le righe dei totali gia' settate, mentre + //righe rimaste conteneva le righe senza quelle dei totali gia' settate + if (righe_rimaste > 0) + { + _rw++; //incremento la riga altrimenti copro l'ultimo totale settato con una riga bianca + for (int i = 0; i < righe_rimaste; i++) + set_row(_rw++,"@0g "); + } + } + } + +// _stampa_progressivi_si = 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) + { + reset_print(); + print_one(file); + //_msk->reset(-9); // commentato 25-03-2015 + } + + return NEXT_PAGE; +} +// Stampa dei totali documenti iva se richiesta + +void TMastrini_application::stampa_totaliiva() +{ + real totale; + + if (_nummast == 1 || _nummast == 3) + { + _rw = 7; + _ddociva_len++; + + if (_stampatotiva) + { + TString16 fmt; fmt.format("@%dg", _ddociva_len); + fmt << "%15s"; + for (int j = 0; j < _b.items(); j++) + { + TDociva& riga = (TDociva&)_b[j]; + set_row(_rw+j, "@0g%s",(const char*) riga._descrdoc); + totale = riga._totdociva; + TString string = real2str(totale); + set_row(_rw+j, fmt, (const char*)string); + } + } + _b.destroy(); + } +} + +// Ricerca della descrizione relativa al codice causale di MOV.dta +// sull'archivio CAUS.dta +void TMastrini_application::descrizione_causale() +{ + const TRectype& caus = cache().get(LF_CAUSALI, _codcaus); + _descrcaus = caus.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() +{ + _tabtpd->zero(); + if (_tipodoc.full()) + { + TString4 dep; + dep.format("%2s",(const char*) _tipodoc); + _tabtpd->put("CODTAB", dep); + _tabtpd->read(); + } + _descrdociva = _tabtpd->get("S0"); + _natdoc = atoi(_tabtpd->get("I0")); +} + +void TMastrini_application::ricerca_regiva() +{ + _tabreg->zero(); + _tipo = 0; + if (_annoiva > 0 && _regiva.full()) + { + TString8 dep; dep.format("%04d%3s", _annoiva, (const char*)_regiva); + _tabreg->put("CODTAB", dep); + if (_tabreg->read() == NOERR) + _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; + _riporto_parziale_dare = ZERO; + _riporto_parziale_avere = ZERO; + _protiva = 0; + + _flag_del_cazzo = _nummast == 1; + + _stampa_progressivi_si = TRUE; + _stampa_footer_si = TRUE; + } + + return TRUE; +} + +bool TMastrini_application::set_print(int m) +{ + KEY tasto = K_ENTER; + while (tasto == K_ENTER) + { + _puoi_stampare = true; + // Controlla se esistono impostazioni di stampa in coda + if (sheet2mask()) + { + // Simula l'immediata pressione del tasto stampa senza nemmeno lanciare la maschera + tasto = K_ENTER; + } + else + { + tasto = _msk->run(); + if (tasto == K_ENTER) + { + // Se lo sheet e' vuoto allora usa solo la maschera corrente per la stampa, + // altrimenti estrae il primo elemento sovrascrivendo la maschera corrente. + // Questa figata cerca di correggere gli errori MI6185 e MI3592 in una botta + TSheet_field& sht = _msk->sfield(F_SCELTE); + if (sht.items() != 0) + sheet2mask(); // Estrae la prima riga dalla coda di stampa + } + } + if (tasto != K_ENTER) + break; + + _noseparator = _msk->get_bool(F_SEPARATOR); + if (_noseparator) + _real_picture = "################"; + else + _real_picture = "####.###.###.###"; + set_real_picture(_real_picture); + set_magic_currency(true); + + _codice_ditta = get_firm(); + _annomsk = _msk->get_int(F_ANNO); + + int gruppoini = _msk->get_int(F_GRUPPOINI); + int contoini = _msk->get_int(F_CONTOINI_CONTO); + long sottocontoini = _msk->get_long(F_SOTTOCINI_CONTO); + int gruppofine = _msk->get_int(F_GRUPPOFINE); + int contofine = _msk->get_int(F_CONTOFINE_CONTO); + long sottocontofine = _msk->get_long(F_SOTTOCFINE_CONTO); + + _stampaprogre = _msk->get_bool(F_STAMPAPROGRE); + _stampatotiva = _msk->get_bool(F_STAMPATOTIVA); + _stampa_cont = !_msk->get_bool(F_NOT_STAMPA_CONT); + _stampanum = _msk->get_int(F_STAMPANUM); + _stampa_mov_prov = _msk->get_bool(F_STAMPAMOVPROV); + _selez_mastrini = _msk->get_int(F_SELEZ_STAMPA); + + _numcarat = _msk->get_int(F_NUMCARAT); + _stampa_saldo_des = _numcarat==2 ? _msk->get_int(F_SALDO_DES) : 0; + _nummast = _msk->get_int(F_NUMMAST); + _data_ini = _msk->get_date(F_DATAINI); + _data_fine = _msk->get_date(F_DATAFINE); + + + TEsercizi_contabili esc; + + if (_annomsk != 0) + _anno_corrente = _annomsk; + else + { + _anno_ghost = esc.date2esc(_data_ini); + _anno_corrente = _anno_ghost; + _inizioes = esc[_anno_ghost].inizio(); + } + + data_fine_esercizio(_anno_corrente); // Ricalcola _data_inizioese e _data_finese + if (!_data_ini.ok()) _data_ini = _data_inizioese; + if (!_data_fine.ok()) _data_fine = _data_finese; + + _anno_precedente = esc.pred(_anno_corrente); + + ricerca_dati_ditta(); + + if (_nummast == 1 || _nummast == 3) + printer().footerlen(4); + else + printer().footerlen(2); + +//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); + + if (_msk->get_bool(F_SORTDESC)) + select_cursor(_cur2); + else + select_cursor(_cur1); + + TRectype da(LF_SALDI), a(LF_SALDI); + 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(); + + //_inizio_stampa = TRUE; + _numero_pag = 1; + if (_nummast == 3) + _pagina = 0; + else + _pagina = 1; + _cambia_mastrino = FALSE; + _rw = 0; + _conta_mastrini = 0; + _indice_lista = 0; + _ddociva_len = 0; + + _riga.destroy(); + _lista.destroy(); + + switch (_selez_mastrini) + { + case 1: _totale_saldo = 1.0; break; + case 2: _totale_saldo = 0.0; break; + case 3: _totale_saldo = 1.0; break; + default: break; + } + + enable_print_menu(); + enable_link(TR("Collegamento prima nota: "), 'b'); + + do + print(); + while (need_to_repeat_print()); + _msk->reset(-8); + + } + return FALSE; +} + +void TMastrini_application::data_fine_esercizio(int anno) +{ + TEsercizi_contabili esc; + _data_inizioese = esc[anno].inizio(); + _data_finese = esc[anno].fine(); +} + +void TMastrini_application::preprocess_header() +{ + if (_nummast == 1) + { + if (_selez_mastrini == 3) // Tutti + crea_intestazione(); + else + if (_selez_mastrini == 2) // Con saldo non nullo + { + if ((!_totale_saldo.is_zero()) && (_puoi_stampare)) + crea_intestazione(); + } + else if (_selez_mastrini == 1) + if (_puoi_stampare) + crea_intestazione(); + } + else + if (_nummast == 3 && !_gia_stampata_intestazione) + { + if (_selez_mastrini == 3) // Tutti + crea_intestazione(); + else + if (_selez_mastrini == 2) // Con saldo non nullo + { + if ((!_totale_saldo.is_zero()) && (_puoi_stampare)) + crea_intestazione(); + } + else if (_selez_mastrini == 1) // Movimentati nel periodo + if (_puoi_stampare) + crea_intestazione(); + } +} + +void TMastrini_application::preprocess_footer() +{ + reset_footer(); + + if (_nummast != 1 && _nummast != 3) + return; + + if (_devi_stampare_footer) + { + real dep_dare,dep_avere; + + if (_stampa_footer_si) + { + _riporto_footer_dare = _progredare + _riporto_parziale_dare; + _riporto_footer_avere = _progreavere + _riporto_parziale_avere; + + real imp_d,imp_a; + imp_d = _sezione == "D" ? _importo : ZERO; + imp_a = _sezione == "A" ? _importo : ZERO; + dep_dare = _stampato ? _riporto_footer_dare : _riporto_footer_dare - imp_d; + dep_avere = _stampato ? _riporto_footer_avere : _riporto_footer_avere - imp_a; + + _stampa_footer_si = FALSE; + } + else + { + _riporto_footer_dare += _riporto_parziale_dare; + _riporto_footer_avere += _riporto_parziale_avere; + + real imp_d,imp_a; + imp_d = _sezione == "D" ? _importo : ZERO; + imp_a = _sezione == "A" ? _importo : ZERO; + dep_dare = _stampato ? _riporto_footer_dare : _riporto_footer_dare - imp_d; + dep_avere = _stampato ? _riporto_footer_avere : _riporto_footer_avere - imp_a; + } + + if (_nummast != 3 || dep_dare != ZERO || dep_avere != ZERO) + { + TString dare (real2str(dep_dare)); + TString avere (real2str(dep_avere)); + if (_numcarat == 1) + { + set_footer (2,FR("@32gA RIPORTO@83g%s"), (const char*) dare); + set_footer (2,"@100g%s", (const char*) avere); + } + else + if (_numcarat == 2) + { + set_footer (2,FR("@32gA RIPORTO@100g%s"), (const char*) dare); + set_footer (2,"@117g%s", (const char*) avere); + } + } + } +} + +void TMastrini_application::conto(int gruppo, int conto, bool no_contropartita) +{ + TString16 key; + + key.format("%d|%d|", gruppo, conto); + + const TRectype & pconti = cache().get(LF_PCON, key); + + + 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() +{ + const TRectype & nditte = cache().get(LF_NDITTE, _codice_ditta); + + const long app = nditte.get_long(NDT_CODDITTA); + _ragsoc = nditte.get(NDT_RAGSOC); + + TString16 key; + key.format("%ld|1", app); + const TRectype& unloc = cache().get(LF_UNLOC, key); + + _indulc= unloc.get(ULC_INDULC); + _civulc= unloc.get(ULC_CIVULC); + int len = _indulc.len(); + if (len <= 31) + { + if (len <= 26) + _indulc << ' ' << _civulc; + else + _indulc << ' ' << _civulc.mid(0,5); + } + else + { + _indulc = _indulc.mid(0,31); + _indulc << ' ' << _civulc.mid(0,5); + } + _capulc= unloc.get(ULC_CAPULC); + _comulc= unloc.get(ULC_COMULC); + + key.format("|%s", (const char *) _comulc); + const TRectype& comuni = cache().get(LF_COMUNI, key); + + _com = comuni.get(COM_DENCOM); + _prov = comuni.get(COM_PROVCOM); +} + +// Crea l'intestazione per la stampa a 132 e a 198 caratteri + +void TMastrini_application::crea_intestazione() +{ + TString sep(133),sep1(198); + reset_header(); + + int np = get_page_number(); + + if (_cambia_mastrino) + { + if (_nummast != 3) + _pagina = 1; + _cambia_mastrino = FALSE; + } + if (_numcarat == 1) + { + if (_nummast == 3) + { + if (_pagina != np) + sep << "Pag. @#"; + } + else + sep << "Pag. " << _pagina; + sep.right_just(132); + set_header(1,(const char*) sep); + } + else if (_numcarat == 2) + { + if (_nummast == 3) + { + if (_pagina != np) + sep1 << "Pagina @#"; + } + else + sep1 << "Pagina " << _pagina; + sep1.right_just(198); + set_header(1,(const char*) sep1); + } + if (_nummast != 3) + _pagina++; + + if (_nummast != 3 || _pagina != np) + { + set_header (1, "@0g%s@6g%5ld", TR("DITTA"), _codice_ditta); + set_header (1, "@12g%-.45s", (const char*) _ragsoc); + set_header (1, "@59g%s", (const char*) _indulc); + 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 (2, "@122g%s", (const char *) _msk->get(F_DATASTAMPA)); + + if (_nummast == 3) + set_header (3, "@0g%s@12g@b%3d %3d %6ld", TR("Sottoconto"), _gruppo, _conto, _sottoc); + else + set_header (3, "@0g%s@12g%3d %3d %6ld", TR("Sottoconto"), _gruppo, _conto, _sottoc); + + switch(_tmcf) + { + case 'C': _tipo_mask = 1; break; + case 'F': _tipo_mask = 2; break; + default : _tipo_mask = 3; break; + } + + 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,"%s@19g%s@117g%s@126g%s@132g%s", + TR("Operazione"), TR("Documento"), TR("Contro"), TR("Nr"), TR("A")); + if (_stampa_mov_prov) + set_header(7,"@130gM"); + set_header (8, TR("Data")); + if (_stampanum < 3) + set_header (8,"@11g%s", TR("Numero")); + set_header (8,"@19g%s@30g%s@38g%s@61g%s@95g%s@111g%s@117g%s@126g%s@132g%s", + TR("Data"), TR("Numero"), TR("Cod.Causale"), TR("Descrizione"), + TR("Dare"), TR("Avere"), TR("Partita"), TR("Pro"), TR("C")); + if (_stampa_mov_prov) + set_header(8,"@130g%s", TR("P")); + sep.fill('_'); + set_header (9, (const char *) sep); + } + else + { + sep1.fill('_'); //Stampa 198 - (sep1(198)) + set_header (6,"@0g%s", (const char*)sep1); + if (_stampa_saldo_des == 3) + { + set_header (7,"%s@23g%s@183g%s@190g%s@197g%s", + TR("Operazione"), TR("Documento"), + TR("Reg"), TR("Nr"), TR("A")); + } + else + { + set_header (7,"%s@23g%s@169g%s@183g%s@190g%s@197g%s", + TR("Operazione"), TR("Documento"), TR("Contro"), + TR("Reg"), TR("Nr"), TR("A")); + } + if (_stampa_mov_prov) + set_header(7,"@195g%s", TR("M")); + set_header (8,TR("Data")); + if (_stampanum < 3) + set_header (8,"@11g%s", TR("Numero")); + + switch (_stampa_saldo_des) + { + case 1: + set_header (8,"@23g%s@34g%s@42g%s@70g%s@112g%s@127g%s@135g%s@152g%s@169g%s@183g%s@189g%s@197g%s", + TR("Data"), TR("Numero"), TR("Cod.Causale"), TR("Descrizione"), TR("Dare"), TR("Avere"), + TR("Saldo progre."), TR("Saldo movim."), TR("Partita"), TR("Iva"), TR("Prot"), TR("C")); + break; + case 2: + set_header (8,"@23g%s@34g%s@42g%s@70g%s@112g%s@127g%s@135g%s@152g%s@169g%s@183g%s@189g%s@197g%s", + TR("Data"), TR("Numero"), TR("Cod.Causale"), TR("Descrizione"), TR("Dare"), TR("Avere"), + TR("Saldo scalare"), TR("Saldo movim."), TR("Partita"), TR("Iva"), TR("Prot"), TR("C")); + break; + case 3: + set_header (8,"@23g%s@34g%s@42g%s@70g%s@112g%s@127g%s@135g%s@183g%s@189g%s@197g%s", + TR("Data"), TR("Numero"), TR("Cod.Causale"), TR("Descrizione"), TR("Dare"), TR("Avere"), + TR("Contropartita"), TR("Iva"), TR("Prot"), TR("C")); + break; + default: + break; + } + + if (_stampa_mov_prov) + set_header(8,"@195g%s", TR("P")); + sep1.fill('_'); + set_header (9,"@0g%s", (const char*)sep1); + } + + calcola_progressivi(); +// _saldo_progressivi += _saldo_progre_prec; // Se trovo quel cazzone che ha scritto sto programma... + + if (_stampa_progressivi_si) + { + if (_numcarat == 1) + { + set_header (10,"@42g%s@66g%s", TR("PROGRESSIVI PRECEDENTI"), real2str(_saldo_progre_prec)); + set_header (10,"@83g%s", real2str(_progredare)); + set_header (10,"@100g%s", real2str(_progreavere)); + } + else + { + set_header (10,"@70g%s@100g%s", TR("PROGRESSIVI PRECEDENTI"), real2str(_progredare)); + set_header (10,"@117g%s", real2str(_progreavere)); + if (_stampa_saldo_des < 3) + set_header (10,"@135g%s", real2str(_saldo_progre_prec)); + } + _riporto_dare = _progredare; + _riporto_avere = _progreavere; + _stampa_progressivi_si = FALSE; + } + else + { + _riporto_dare += _riporto_parziale_dare; + _riporto_avere += _riporto_parziale_avere; + + real dep_dare,dep_avere,imp_d,imp_a; + imp_d = _sezione == "D" ? _importo : ZERO; + imp_a = _sezione == "A" ? _importo : ZERO; + dep_dare = _stampato ? _riporto_dare : _riporto_dare - imp_d; + dep_avere = _stampato ? _riporto_avere : _riporto_avere - imp_a; + + if (_nummast != 3 || dep_dare != ZERO || dep_avere != 0) + { + if (_numcarat == 1) + { + set_header (10,"@32g%s@83g%s", TR("A RIPORTO"), real2str(dep_dare)); + set_header (10,"@100g%s", real2str(dep_avere)); + } + else + { + set_header (10,"@32g%s@100g%s", TR("A RIPORTO"), real2str(dep_dare)); + set_header (10,"@117g%s", real2str(dep_avere)); + } + } + _riporto_parziale_dare = ZERO; + _riporto_parziale_avere = ZERO; + } + + if (_numcarat == 1) + { + sep =""; + set_header(11,"@0g%s",(const char*) sep); + } + else + { + sep1 =""; + set_header(11,"@0g%s",(const char*) sep1); + } + + if (_pagina != np && _nummast == 3) + _pagina = np; +} + +int TMastrini_application::crea_intestazione(int start_riga) +{ + TString sep(132),sep1(198); + int r = start_riga + 2; + sep = ""; + + reset_header(); + + int np = get_page_number(); + + _conta_mastrini++; + + if (_nummast == 3) + _gia_stampata_intestazione = TRUE; + + if (_nummast == 2) + if (_cambia_mastrino) + { + _numero_pag = 1; + _cambia_mastrino = FALSE; + } + if (_nummast == 3) + { + if (_pagina != np) + { + if (_numcarat == 1) + { + sep << FR("Pag. @#"); + set_row(r,"@126g%s", (const char*) sep); + } + else if (_numcarat == 2) + { + sep << FR("Pagina @#"); + set_row(r,"@190g%s", (const char*) sep); + } + } + } + else + { + if (_numcarat == 1) + set_row(r,"@126g%s %2d", TR("Pag."), _numero_pag++); + else if (_numcarat == 2) + set_row(r,"@190g%s %2d", TR("Pagina"),_numero_pag++); + } + if (_nummast != 3 || _pagina != np) + { + set_row (r, "@0g%s@6g%5ld", TR("DITTA"), _codice_ditta); + set_row (r, "@12g%-45s", (const char*) _ragsoc); + set_row (r, "@59g%s", (const char*) _indulc); + //set_row (r, "@86g%-9s", (const char*) _civulc); + set_row (r, "@97g%-5s", (const char*) _capulc); + set_row (r, "@103g%-18s", (const char*) _com); + set_row (r, "@122g%-3s", (const char*) _prov); + r += 2; + } + if (_nummast == 3) + set_row (r, "@0g%s@12g@b%3d %3d %6ld", TR("Sottoconto"), _gruppo, _conto, _sottoc); + else + set_row (r, "@0g%s@12g%3d %3d %6ld", TR("Sottoconto"), _gruppo, _conto, _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: r = ricerca_clifo(r); + break; + case 2: r = ricerca_clifo(r); + break; + case 3: r = ricerca_gruppo(r); + break; + default: break; + } + + r++; + + if (_numcarat == 1) + { + sep.fill('_'); //Stampa 132 - (sep(132)) + set_row (r++,"@0g%s", (const char *) sep); + set_row (r++,"%s@19g%s@117g%s@131g%s", TR("Operazione"), TR("Documento"), TR("Contro"), TR("A")); + if (_stampa_mov_prov) + set_header(r-1,"@130g%s", TR("M")); + set_row (r, TR("Data")); + if (_stampanum < 3) + set_row (r,"@11g%s", TR("Numero")); + set_row (r++,FR("@19gData@30gNumero@38gCod.Causale@61gDescrizione@95gDare@111gAvere@117gPartita@131gC")); + if (_stampa_mov_prov) + set_header(r-1,"@130gP"); + sep.fill('_'); + set_row (r++,"@0g%s", (const char*)sep); + } + else + { + sep1.fill('_'); //Stampa 198 - (sep1(198)) + set_row (r++,"@0g%s", (const char*)sep1); + if (_stampa_saldo_des == 2) + set_row (r++,FR("Operazione@23gDocumento@183gReg@190gNumero@197gA")); + else + set_row (r++,FR("Operazione@23gDocumento@169gContro@183gReg@190gNumero@197gA")); + if (_stampa_mov_prov) + set_row(r-1,"@195gM"); + set_row (r,"Data"); + if (_stampanum < 3) + set_row (r,"@11gNumero"); + set_row (r,FR("@23gData@34gNumero@42gCod.Causale@70gDescrizione@112gDare@127gAvere")); + if (_stampa_saldo_des == 2) + set_row (r++,FR("@135gContropartita@183gIva@189gProt@197gC")); + else + set_row (r++,FR("@135gSaldo progre.@152gSaldo movim.@169gPartita@183gIva@189gProt@197gC")); + if (_stampa_mov_prov) + set_row (r-1,"@195gP"); + sep1.fill('_'); + set_row (r++,"@0g%s", (const char*)sep1); + } + _pagina = np; + return r; +} + +int TMastrini_application::stampa_progre_riporto(int start_riga) +{ + TString sep(132),sep1(198); + int r = start_riga; + + if (_stampa_progressivi_si) + { + r = stampa_progressivi(r); + _riporto_dare = _progredare; + _riporto_avere = _progreavere; + _stampa_progressivi_si = FALSE; + } + else + { + _riporto_dare += _riporto_parziale_dare; + _riporto_avere += _riporto_parziale_avere; + + real dep_dare,dep_avere,imp_d,imp_a; + imp_d = _sezione == "D" ? _importo : ZERO; + imp_a = _sezione == "A" ? _importo : ZERO; + dep_dare = _stampato ? _riporto_dare : _riporto_dare - imp_d; + dep_avere = _stampato ? _riporto_avere : _riporto_avere - imp_a; + + if (_nummast != 3 || dep_dare != ZERO || dep_avere != ZERO) + { + if (_numcarat == 1) + { + set_row (r,"@32g%s@83g%r", TR("A RIPORTO"), &dep_dare); + set_row (r++,"@100g%r", &dep_avere); + } + if (_numcarat == 2) + { + set_row (r,"@32g%s@100g%r", TR("A RIPORTO"), &dep_dare); + set_row (r++,"@117g%r", &dep_avere); + } + } + _riporto_parziale_dare = ZERO; + _riporto_parziale_avere = ZERO; + } + if (_numcarat == 1) + { + sep =""; + set_row(r++,"@0g%s",(const char*) sep); + } + else + { + sep1 =""; + set_row(r++,"@0g%s",(const char*) sep1); + } + return r; +} + + +void TMastrini_application::calcola_progressivi_al(const TDate& data_fin) +{ + static TBill _last_bill; + static TDate _last_date, _last_inizio; + static int _last_year; + static bool _last_provv; + static real _last_dare, _last_avere; + + const TDate data_inizio = _annomsk ? _data_inizioese : _inizioes; + + if (_annomsk == _last_year && data_inizio == _last_inizio && data_fin == _last_date && + _last_provv == _stampa_mov_prov && _last_bill == TBill(_gruppo, _conto, _sottoc)) + { + _totale_prima_dare = _last_dare; + _totale_prima_avere = _last_avere; + return; + } + + TLocalisamfile& rmov_file = current_cursor()->file(LF_RMOV); + const TRecnotype record = rmov_file.recno(); + + TRelation rel(LF_RMOV); + rel.add(LF_MOV, "NUMREG==NUMREG"); + const TRectype& mov = rel.curr(LF_MOV); + + TRectype& rmov = rel.curr(); + + rmov.zero(); + rmov.put(RMV_GRUPPO, _gruppo); + rmov.put(RMV_CONTO, _conto); + rmov.put(RMV_SOTTOCONTO, _sottoc); + TCursor cur(&rel, "", 2, &rmov, &rmov); + const long items = cur.items(); + cur.freeze(); + + _totale_prima_dare = ZERO; + _totale_prima_avere = ZERO; + + for (cur = 0L; cur.pos() < items; ++cur) + { + if (_stampa_mov_prov || mov.get(MOV_PROVVIS).blank()) + { + const int annoes = rmov.get_int (RMV_ANNOES); + const TDate datareg = mov.get_date(_annomsk ? MOV_DATACOMP : RMV_DATAREG); + + //Legge movimenti con data > inizio esercizio e < data_fin + if (((annoes==_annomsk)||(_annomsk == 0))&&(datareg >= data_inizio)&&(datareg <= data_fin)) + { + const char sezione = rmov.get_char(RMV_SEZIONE); + const real importo = rmov.get_real(RMV_IMPORTO); + if (sezione == 'D') + _totale_prima_dare += importo; + else + _totale_prima_avere += importo; + } + } + } + + // Riposiziona rmov + rmov_file.readat(record); + + _last_year = _annomsk; + _last_date = data_fin; + _last_inizio = data_inizio; + _last_bill.set(_gruppo, _conto, _sottoc); + _last_provv = _stampa_mov_prov; + _last_dare = _totale_prima_dare; + _last_avere = _totale_prima_avere; +} + +void TMastrini_application::calcola_progressivi(bool finali) +{ + /* fv 20/3/96: aggiustato per nuova struttura saldi - modificata ricerca + * record scaricati e assegnazione dare/avere relativo - Controllare che + * non occorra considerare il saldo di chiusura (SALDOFIN) aggiunto al + * record */ + + TLocalisamfile saldi(LF_SALDI); + real progdare_attuale,progavere_attuale,progdare_prec,progavere_prec; + real saldo,progredare_eseprec,progreavere_eseprec,saldoini_attuale,saldofine_attuale; + char salini,salini_attuale,salfine_attuale; + + saldo = ZERO; // saldo = Saldo iniziale (Guy: Ovvio no?) + + // Ricerca sull'archivio saldi dei record con gruppo,conto,sottoconto + // uguali a quelli di rmov per il calcolo dei progressivi precedenti + + saldi.setkey(2); + saldi.zero(); + saldi.put(SLD_GRUPPO, _gruppo); + saldi.put(SLD_CONTO, _conto); + saldi.put(SLD_SOTTOCONTO, _sottoc); + const TRectype record(saldi.curr()); + + for (saldi.read(_isgteq); saldi.good() && saldi.curr() == record; saldi.next()) + { + if (!saldi.get_bool(SLD_FLSCA)) + { + const int annoes_saldi = saldi.curr().get_int(SLD_ANNOES); + + //Calcola i progressivi dell'esercizio attuale + if (annoes_saldi == _anno_corrente) + { + progdare_attuale = saldi.get_real(SLD_PDARE); + progavere_attuale = saldi.get_real(SLD_PAVERE); + if (_stampa_mov_prov) + { + progdare_attuale += saldi.get_real(SLD_PDAREPRO); + progavere_attuale += saldi.get_real(SLD_PAVEREPRO); + } + + saldo = saldi.get_real(SLD_SALDO); + salini = saldi.get(SLD_FLAGSALINI)[0]; + _ultima_data_reg = saldi.get_date(SLD_DATAULMOV); + saldoini_attuale = saldi.get_real(SLD_SALDO); + salini_attuale = saldi.get_char(SLD_FLAGSALINI); + saldofine_attuale = saldi.get_real(SLD_SALDOFIN); + salfine_attuale = saldi.get_char(SLD_FLAGSALFIN); + } + } // if (!saldi.get_bool(SLD_FLSCA)) + } // 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) + { + if ((_indbil == 1) || (_indbil == 2) || (_indbil == 5)) + { + const TRecnotype pos = saldi.recno(); + // W96SALDI del 18-07-96 saldofin_esprec usa il flag TRUE xche' deve + // considerare anche il saldo finale + saldo = _sld->saldofin_esprec(_anno_corrente,_gruppo,_conto,_sottoc,TRUE, _stampa_mov_prov); + saldi.readat(pos); + + if (saldo > ZERO) + { + progredare_eseprec = saldo; + progdare_prec = saldo; + } + else if (saldo < ZERO) + { + saldo = -saldo; + progreavere_eseprec = saldo; + progavere_prec = saldo; + } + } + } + + if (finali) + { + calcola_progressivi_al(_data_fine); + } + else + { + TDate giorno_prima = _data_ini; --giorno_prima; // CM500429 + calcola_progressivi_al(giorno_prima); + } + +//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 = progredare_eseprec + _totale_prima_dare; + _progreavere = 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; + + if (salini_attuale == 'D') + _totprogre_dare_al += saldoini_attuale; + else + _totprogre_avere_al += saldoini_attuale; + if (salfine_attuale == 'D') + _totprogre_dare_al += saldofine_attuale; + else + _totprogre_avere_al += saldofine_attuale; + } + else + { + _totprogre_dare_al = progdare_attuale; + _totprogre_avere_al = progavere_attuale; + + if (salini_attuale == 'D') + _totprogre_dare_al += saldoini_attuale; + else if (salini_attuale == 'A') + _totprogre_avere_al += saldoini_attuale; + if (salfine_attuale == 'D') + _totprogre_dare_al += saldofine_attuale; + else if (salfine_attuale == 'A') + _totprogre_avere_al += saldofine_attuale; + } +} + +int TMastrini_application::stampa_progressivi(int start_riga) +{ + int r = start_riga; + + if (_numcarat == 1) + { + set_row (r,FR("@42gPROGRESSIVI PRECEDENTI@66g%r"), &_saldo_progre_prec); + set_row (r,"@83g%r", &_progredare); + set_row (r++,"@100g%r", &_progreavere); + } + else + { + set_row (r,FR("@70g%s@100g%r"), TR("PROGRESSIVI PRECEDENTI"), &_progredare); + set_row (r,"@117g%r", &_progreavere); + if (_stampa_saldo_des < 3) + set_row (r++,"@135g%r", &_saldo_progre_prec); + } + + return r; +} + +// 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,indcf,capcf,ptel,tel,dencom,dep; + TString4 provcom; + TString16 dataini,datafine,paiv,cofi; + TString descriz,descriz2; + int numrivd; + + TString16 key; + key.format("%c|%ld", _tmcf, _sottoc); + const TRectype & clifo = cache().get(LF_CLIFO, key); + ragsoc = clifo.get(CLI_RAGSOC); ragsoc.strip_double_spaces(); + paiv = clifo.get(CLI_PAIV); + cofi = clifo.get(CLI_COFI); + indcf = clifo.get(CLI_INDCF); + indcf.trim(); + indcf << ' ' << clifo.get(CLI_CIVCF); + capcf = clifo.get(CLI_CAPCF); + ptel = clifo.get(CLI_PTEL); + tel = clifo.get(CLI_TEL); + + const TString4 statocf = clifo.get(CLI_STATOCF); + const TString4 comcf = clifo.get(CLI_COMCF); + key.format("%s|%s", (const char *) statocf, (const char *) comcf); + const TRectype & comuni = cache().get(LF_COMUNI, key); + + if (!comuni.empty()) + { + dencom = comuni.get(COM_DENCOM); + provcom = comuni.get(COM_PROVCOM); + } + else + { + dencom = clifo.get(CLI_LOCCF); + provcom=""; + } + + key.format("%d|%d|", _gruppo, _conto); + + const TRectype & pconti = cache().get(LF_PCON, key); + _sezivd = pconti.get_char(PCN_SEZIVD); + _lettivd = pconti.get_char(PCN_LETTIVD); + numrivd = pconti.get_int(PCN_NUMRIVD); + _numrivd = itor(numrivd); + _numivd = pconti.get(PCN_NUMIVD); + + descriz = descrizione_classe(_sezivd,_lettivd,numrivd, _numivd); + + if (_numivd.not_empty()) //Ora devo stampare la descrizione del livello della + { //classe immediatamente precedente a quello appena + if (_numrivd.not_empty()) //stampato + descriz2 = descrizione_classe(_sezivd,_lettivd,_numrivd_int,""); + else + descriz2 = descrizione_classe(_sezivd,_lettivd,0,""); + } + else + if (_numrivd.not_empty()) + descriz2 = descrizione_classe(_sezivd,_lettivd,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%-.41s",(const char*) ragsoc); + if (_nummast == 3) + set_header (4, "@r%s@8g@b%c", TR("Classe"), _lettivd); + else + set_header (4, "%s@8g%c", TR("Classe") , _lettivd); + set_header (4, "@10g%-8s", (const char*) _numrivd); + if (_numivd.not_empty()) + set_header (4, "@19g%s", num2str(_numivd)); + if (descriz2 != "") + { + set_header (4,"@30g%-50s",(const char*) descriz2); + set_header (4,"@82g%-50s",(const char*) descriz); + } + else + set_header (4,"@30g%-50s",(const char*) descriz); + + dataini = _data_ini.string(); + datafine = _data_fine.string(); + + if (_annomsk == 0) + { + if (_nummast == 3) + { + set_header (5, FR("@rPeriodo@10g@b%s"), (const char*) dataini); + set_header (5, "@22g@b%s@r", (const char*) datafine); + } + else + { + set_header (5, FR("Periodo@10g%s"), (const char*) dataini); + set_header (5, "@22g%s", (const char*) datafine); + } + } + else + { + if (_nummast == 3) + { + set_header (5, FR("@rComp. da@9g@b%s"), (const char*) dataini); + set_header (5, "@20g@ra@22g@b%s@r", (const char*) datafine); + } + else + { + set_header (5, FR("Comp. da@9g%s"), (const char*) dataini); + set_header (5, "@20ga@22g%s", (const char*) datafine); + } + } + + set_header (5, FR("@33gP.I.@37g%-11s"),(const char*) paiv); + set_header (5, FR("@49gCF@52g%-16s"),(const char*) cofi); + set_header (5, "@66g%-.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,"@135g%-4s",(const char*) ptel); + if (tel != "") + set_header (5,"@138g/@139g%-10s",(const char*) tel); + } +} + +int TMastrini_application::ricerca_clifo(int start) +{ + TString ragsoc,paiv,cofi,indcf,capcf,ptel,tel,statocf,comcf,dencom,provcom,dep; + TString16 dataini,datafine; + TString descriz,descriz2; + int numrivd; + int r = start; + + indcf = ""; + + TString16 key; + + key.format("%c|%ld", _tmcf, _sottoc); + + const TRectype & clifo = cache().get(LF_CLIFO, key); + + ragsoc = clifo.get(CLI_RAGSOC); ragsoc.strip_double_spaces(); + paiv = clifo.get(CLI_PAIV); + cofi = clifo.get(CLI_COFI); + indcf = clifo.get(CLI_INDCF); + indcf.trim(); + indcf << " " << clifo.get(CLI_CIVCF); + 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); + + key.format("%s|%s", (const char *) statocf, (const char *) comcf); + + const TRectype & comuni = cache().get(LF_COMUNI, key); + + if (!comuni.empty()) + { + dencom = comuni.get(COM_DENCOM); + provcom = comuni.get(COM_PROVCOM); + } + else + { + dencom=clifo.get(CLI_LOCCF); + provcom=""; + } + + key.format("%d|%d|", _gruppo, _conto); + + const TRectype & pconti = cache().get(LF_PCON, key); + _sezivd = pconti.get_char(PCN_SEZIVD); + _lettivd = pconti.get_char(PCN_LETTIVD); + numrivd = pconti.get_int(PCN_NUMRIVD); + _numrivd = itor(numrivd); + _numivd = pconti.get(PCN_NUMIVD); + + descriz = descrizione_classe(_sezivd,_lettivd,numrivd,_numivd); + + if (_numivd.not_empty()) //Ora devo stampare la descrizione del livello della + { //classe immediatamente precedente a quello appena + if (_numrivd.not_empty()) //stampato + descriz2 = descrizione_classe(_sezivd,_lettivd,_numrivd_int,""); + else + descriz2 = descrizione_classe(_sezivd,_lettivd,0,""); + } + else + if (_numrivd.not_empty()) + descriz2 = descrizione_classe(_sezivd,_lettivd,0,""); + else + descriz2 = ""; + + set_row (r,"@27g%-30s",(const char*) descrizione_gruppo()); + set_row (r,"@59g%-30s",(const char*) descrizione_conto()); + set_row(r++, "@91g%-30s",(const char*) ragsoc); + if (_nummast == 3) + set_row(r, "@r%s@8g@b%c", TR("Classe"), _lettivd); + else + set_row(r, "%s@8g%c", TR("Classe"), _lettivd); + set_row(r, "@10g%-8s", (const char*) _numrivd); + if (_numivd.not_empty()) + set_row(r, "@19g%s", num2str(_numivd)); + if (descriz2.not_empty()) + { + set_row(r,"@30g%-50s",(const char*) descriz2); + set_row(r++,"@82g%-50s",(const char*) descriz); + } + else + set_row(r++,"@30g%-50s",(const char*) descriz); + + dataini = _data_ini.string(); + datafine = _data_fine.string(); + + if (_annomsk == 0) + { + if (_nummast == 3) + { + set_row (r, "@r%s@10g@b%s", TR("Periodo"), (const char*) dataini); + set_row (r, "@22g%s@r", (const char*) datafine); + } + else + { + set_row (r, "%s@10g%s", TR("Periodo"), (const char*) dataini); + set_row (r, "@22g%s", (const char*) datafine); + } + } + else + { + if (_nummast == 3) + { + set_row (r, "@r%s@9g@b%s", TR("Comp.dal"), (const char*) dataini); + set_row (r, "@20g@r%s@22g@b%s@r", TR("al"), (const char*) datafine); + } + else + { + set_row (r, "%s@9g%s", TR("Comp.dal"), (const char*) dataini); + set_row (r, "@20g%s@22g%s", TR("al"), (const char*) datafine); + } + } + + set_row (r, FR("@33gP.I.@37g%-11s"),(const char*) paiv); + set_row (r, FR("@49gCF@52g%-16s"),(const char*) cofi); + set_row (r, "@66g%-.25s",(const char*) indcf); + set_row (r, "@95g%-5s",(const char*) capcf); + set_row (r, "@101g%-.24s",(const char*) dencom); + set_row (r, "@126g%-5s",(const char*) provcom); + + if (_numcarat == 2) + { + set_row (r,"@135g%-4s",(const char*) ptel); + if (tel != "") + set_row (r++,"@138g/@139g%-10s",(const char*) tel); + } + return r; +} + + +// 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) +{ + TString16 key; + + if (scelta) + key.format("%d|%d|%ld", _gruppo, _conto, _sottoc); + else + key.format("%d|%d|", _gruppo, _conto); + + const TRectype & pconti = cache().get(LF_PCON, key); + _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(PCN_NUMIVD); +} + +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.not_empty()) //Ora devo stampare la descrizione del livello della + { //classe immediatamente precedente a quello appena + if (_numrivd.not_empty()) //stampato + descriz2 = descrizione_classe(_sezivd,_lettivd,_numrivd_int,""); + else + descriz2 = descrizione_classe(_sezivd,_lettivd,0,""); + } + else + if (_numrivd.not_empty()) + descriz2 = descrizione_classe(_sezivd,_lettivd,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%-.41s",(const char*) descrizione_sottoconto()); + if (_nummast == 3) + set_header (4, "@0g@r%s@12g@b%c", TR("Classe"), _lettivd); + else + set_header (4, "@0g%s@12g%c", TR("Classe"), _lettivd); + set_header (4, "@14g%-8s",(const char*) _numrivd); + if (_numivd.not_empty()) + set_header (4, "@23g%s", num2str(_numivd)); + if (descriz2.not_empty()) + { + set_header (4,"@34g%-48s",(const char*) descriz2); + set_header (4,"@82g%-50s",(const char*) descriz); + } + else + set_header (4,"@34g%-50s",(const char*) descriz); + + dataini = _data_ini.string(); + datafine = _data_fine.string(); + + if (_annomsk == 0) + { + if (_nummast == 3) + { + set_header (5, "@r%s@12g@b%s", TR("Periodo"), (const char*) dataini); + set_header (5, "@24g@b%s@r", (const char*) datafine); + } + else + { + set_header (5, "%s@12g%s", TR("Periodo"), (const char*) dataini); + set_header (5, "@24g%s", (const char*) datafine); + } + } + else + { + if (_nummast == 3) + { + set_header (5, "@r%s@23g@b%s", TR("Periodo di competenza"), (const char*) dataini); + set_header (5, "@35g%s@r", (const char*) datafine); + } + else + { + set_header (5, "%s@23g%s", TR("Periodo di competenza"), (const char*) dataini); + set_header (5, "@35g%s", (const char*) datafine); + } + } +} + +int TMastrini_application::ricerca_gruppo(int start) +{ + TString80 descr,descriz,descriz2,dep; + TString dataini,datafine; + int r = start; + + 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.not_empty()) //Ora devo stampare la descrizione del livello della + { //classe immediatamente precedente a quello appena + if (_numrivd.not_empty()) //stampato + descriz2 = descrizione_classe(_sezivd,_lettivd,_numrivd_int,""); + else + descriz2 = descrizione_classe(_sezivd,_lettivd,0,""); + } + else + if (_numrivd.not_empty()) + descriz2 = descrizione_classe(_sezivd,_lettivd,0,""); + else + descriz2 = ""; + + set_row(r,"@27g%-.30s",(const char*) descrizione_gruppo()); + set_row(r,"@59g%-.30s",(const char*) descrizione_conto()); + + set_row(r++,"@91g%-.41s",(const char*) descrizione_sottoconto()); + if (_nummast == 3) + set_row(r, "@0g@r%s@12g@b%c", TR("Classe"), _lettivd); + else + set_row(r, "@0g%s@12g%c", TR("Classe"), _lettivd); + set_row(r, "@14g%-8s",(const char*) _numrivd); + if (_numivd.not_empty()) + set_row(r, "@23g%-4s", num2str(_numivd)); + if (descriz2 != "") + { + set_row(r,"@34g%-48s",(const char*) descriz2); + set_row(r++,"@82g%-50s",(const char*) descriz); + } + else + set_row(r++,"@34g%-50s",(const char*) descriz); + + dataini = _data_ini.string(); + datafine = _data_fine.string(); + + if (_annomsk == 0) + { + if (_nummast == 3) + { + set_row (r, "@r%s@12g@b%s", TR("Periodo"), (const char*) dataini); + set_row (r, "@24g%s@r", (const char*) datafine); + } + else + { + set_row (r, "%s@12g%s", TR("Periodo"), (const char*) dataini); + set_row (r, "@24g%s", (const char*) datafine); + } + } + else + { + if (_nummast == 3) + { + set_row (r, "@r%s@23g@b%s", TR("Periodo di competenza"), (const char*) dataini); + set_row (r, "@35g%s@r", (const char*) datafine); + + } + else + { + set_row (r, "%s@23g%s", TR("Periodo di competenza"), (const char*) dataini); + set_row (r, "@35g%s", (const char*) datafine); + } + } + return r; +} + +const char* TMastrini_application::descrizione_classe(char sezione, char lettera, int numr, const char * numero) +{ + TString16 key; + + if (numr == 0 && numero == 0) + key.format("%c%c",sezione,lettera); + else + if (numero == 0) + key.format("%c%c%04d",sezione, lettera, numr); + else + { + if (numr != 0) + key.format("%c%c%04d%-4s",sezione, lettera, numr,numero); + else + key.format("%c%c %-4s",sezione,lettera,numero); + } + + return cache().get("%IVD", key, "S0"); +} + +//Ricerca la descrizione relativa al gruppo da stampare + +const char* TMastrini_application::descrizione_gruppo() +{ + return cache().get(LF_PCON, _gruppo, PCN_DESCR); +} + +// Ricerca la descrizione relativa al conto da stampare + +const char* TMastrini_application::descrizione_conto() +{ + TString8 key; key.format("%d|%d", _gruppo, _conto); + return cache().get(LF_PCON, key, PCN_DESCR); +} + +const char* TMastrini_application::descrizione_sottoconto() +{ + TString16 key; key.format("%d|%d|%ld", _gruppo, _conto, _sottoc); + return cache().get(LF_PCON, key, PCN_DESCR); +} + +// Funzione per settare tutti gli handlers della maschera principale +// o di quella dello spreadsheet della seconda pagina +void TMastrini_application::set_handlers(TMask* msk) const +{ + msk->set_handler(F_DATAINI, data_inizio); + msk->set_handler(F_DATAFINE, data_fine); + msk->set_handler(F_GRUPPOFINE, gruppo_hnd); + msk->set_handler(F_CONTOINI_CONTO, contoi_hnd); + msk->set_handler(F_CONTOFINE_CONTO, contof_hnd); + + 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); +} + +// Copia i parametri della prima pagina in una nuova riga dello spreadsheet +// a meno che non ci siano gia' +bool TMastrini_application::mask2sheet() +{ + bool ok = _msk->check_fields(); + + if (ok) + { + TToken_string row(120); + short id = F_ANNO; + for (int pos = _msk->id2pos(id); pos >= 0; pos = _msk->id2pos(++id)) + row.add(_msk->fld(pos).get()); + + if (!row.empty_items()) + { + TSheet_field& sht = _msk->sfield(F_SCELTE); + TString_array& rows = sht.rows_array(); + ok = rows.find(row) < 0; // Aggiunge solo se non c'e' gia' + if (ok) + { + rows.add(row); + sht.force_update(); + } + } + } + + return ok; +} + +bool TMastrini_application::sheet2mask() +{ + TSheet_field& sht = _msk->sfield(F_SCELTE); + bool ok = sht.items() > 0; + if (ok) + { + TString_array& rows = sht.rows_array(); + TToken_string& row = rows.row(0); + + short id = F_ANNO; + FOR_EACH_TOKEN(row, val) + { + // Scarta i listbox perche' azzerano i conti! + if (id != F_TIPOCF_INI && id != F_TIPOCF_FINE) + _msk->set(id, val); + id++; + } + + rows.destroy(0, TRUE); + } + return ok; +} + +bool TMastrini_application::user_create() +{ + TToken_string exp; + + _rel = new TRelation(LF_SALDI); + _rel->lfile().set_curr(new TMastrini_record); + + exp.add("GRUPPO=GRUPPO"); + exp.add("CONTO=CONTO"); + exp.add("SOTTOCONTO=SOTTOCONTO"); + _rel->add(LF_RMOV,exp,2,LF_SALDI); + + _rel->add("CMS", "CODTAB==CODCMS", 1, LF_RMOV, 501); + _rel->add("FSC", "CODTAB==FASCMS", 1, LF_RMOV, 502); + + _cur1=add_cursor(new TCursor(_rel, "FLSCA<=\" \"",2)); + open_files(LF_TAB, LF_TABCOM,LF_NDITTE, LF_UNLOC, LF_COMUNI, LF_MOV, + LF_CLIFO, LF_CAUSALI, 0); + _cur2=add_cursor(new TSorted_cursor(_rel, "DESCR","FLSCA<=\" \"",2)); + + _tabivd = new TTable (TAB_IVD); + _tabtpd = new TTable (TAB_TPD); + _tabreg = new TTable (TAB_REG); + _sld = new TSaldo (); + + _d18 = new TParagraph_string ("",18); + _d22 = new TParagraph_string ("",22); + _d30 = new TParagraph_string ("",30); + + _msk = new TMask("cg3200a"); + set_handlers(_msk); + _msk->set_handler(F_MEMORIZZA, memorizza_handler); + + TSheet_field& sht = _msk->sfield(F_SCELTE); + sht.set_notify(scelte_notify); + TMask& sm = sht.sheet_mask(); + set_handlers(&sm); + + _gia_stampata_intestazione = FALSE; + + return TRUE; +} + +bool TMastrini_application::user_destroy() +{ + delete _msk; + delete _rel; + delete _tabivd; + delete _tabtpd; + delete _tabreg; + delete _sld; + delete _d18; + delete _d22; + delete _d30; + + return TRUE; +} + +#ifdef CONT_SEP +int np0400(int argc, char* argv[]) +#else +int cg3200(int argc, char* argv[]) +#endif +{ + TMastrini_application a; + a.run(argc, argv, TR("Stampa Mastrini")); + return 0; +} diff --git a/src/cg/cg3200.h b/src/cg/cg3200.h index 49bf4cdfb..bcc8b2640 100755 --- a/src/cg/cg3200.h +++ b/src/cg/cg3200.h @@ -44,7 +44,7 @@ #define F_STAMPAMOVPROV 116 #define F_NOT_STAMPA_CONT 117 #ifdef CONT_SEP -#define F_ST_CONTSEP 118 +#define F_CONTSEP 118 #endif #define F_SEPARATOR 150 diff --git a/src/cg/cg3200a.uml b/src/cg/cg3200a.uml index 089cf7f91..b7b83596d 100755 --- a/src/cg/cg3200a.uml +++ b/src/cg/cg3200a.uml @@ -6,7 +6,11 @@ TOOLBAR "topbar" 0 0 0 2 ENDPAGE +#ifdef CONT_SEP +PAGE "Stampa Mastrini Contabilità separata" -1 -1 76 16 +#else PAGE "Stampa Mastrini" 0 0 0 2 +#endif NUMBER F_CODDITTA 5 BEGIN @@ -505,14 +509,6 @@ BEGIN GROUP 8 END -#ifdef CONT_SEP -BOOLEAN F_ST_CONTSEP -BEGIN - PROMPT 1 19 "Stampa contabilità separata" - MODULE NP -END -#endif - BUTTON F_MEMORIZZA 18 2 BEGIN PROMPT -11 -1 "~Memorizza scelte" diff --git a/src/cg/cg3600.cpp b/src/cg/cg3600.cpp index 3ac096981..c1ae1d3c9 100755 --- a/src/cg/cg3600.cpp +++ b/src/cg/cg3600.cpp @@ -1,2696 +1,2686 @@ -#include - -#include "cg3.h" -#include "cglib02.h" -#include "cg3600.h" -#include "cg3601.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "../ca/movana.h" -#include "../ca/rmovana.h" - -class TGrid_mask; - -class TQuery_mask : public TAutomask -{ - TGrid_mask* _gm; - TString4 _last_tipo; - -protected: - virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); - -public: - void do_query(); - - TQuery_mask(TGrid_mask* gm); - virtual ~TQuery_mask() { } -}; - - -class TMastrini_video : public TSkeleton_application -{ - TQuery_mask* _qm; - TGrid_mask* _gm; - -protected: - virtual bool create(); - virtual void main_loop(); - virtual bool destroy(); - -public: - TQuery_mask & query_mask() { return *_qm; } - -}; -HIDDEN inline TMastrini_video& app() -{ return (TMastrini_video&)main_app();} - -/////////////////////////////////////////////////////////// -// TList -/////////////////////////////////////////////////////////// - -class TList : public TContainer -{ - TArray _data; - -protected: - // @cmember Ritorna un puntatore al primo oggetto del contenitore - virtual TObject* first_item( ) { return _data.first_item(); } - // @cmember Ritorna un puntatore all'ultimo oggetto del contenitore - virtual TObject* last_item( ) { return _data.last_item(); } - // @cmember Ritorna un puntatore all'oggetto successivo all'oggetto corrente - virtual TObject* succ_item( ) { return _data.succ_item(); } - // @cmember Ritorna un puntatore all'oggetto che precede l'oggetto corrente - virtual TObject* pred_item( ) { return _data.pred_item(); } - // @cmember Ritorna il numero di oggetti nel contenitore - virtual long objects( ) const { return _data.objects(); } - -public: - long items() const { return _data.items(); } - void destroy() { _data.destroy(); } - long insert(TObject* obj, long pos) { return _data.insert(obj, pos); } - long append(TObject* obj, long pos = -1); - bool remove(long pos) { _data.remove(pos, true); return true; } - - const TObject& obj(long index) const - { const TObject* o = _data.objptr(index); CHECK(o, "Null list item"); return *o; } -}; - -long TList::append(TObject* obj, long index) -{ - if (index < 0 || index >= items()) - index = items(); - else - index++; - return insert(obj, index); -} - -/////////////////////////////////////////////////////////// -// TMastrino -/////////////////////////////////////////////////////////// - -enum tipo_riga_mastrino { riga_mastrino, riga_contropartita }; - -class TRiga_mastrino : public TObject -{ - tipo_riga_mastrino _type; // Tipo della riga - TRecnotype _mov, _rmov; // Numero fisico di record movimento e riga movimento - real _dare, _avere; // Progressivi dare ed avere - TDate _data; // Data di registrazione (Ottimizzazione) - -public: - tipo_riga_mastrino tipo() const { return _type; } - TRecnotype rmov() const { return _rmov; } - TRecnotype mov() const { return _mov; } - - const TDate& data() const { return _data; } - const real& dare() const { return _dare; } - const real& avere() const { return _avere; } - TImporto saldo() const; // Dare-Avere normalizzato - - TRiga_mastrino(tipo_riga_mastrino trig, - TRecnotype rmov, TRecnotype mov, - const real& d, const real& a, - const TDate& datareg); - virtual ~TRiga_mastrino() { } -}; - -TRiga_mastrino::TRiga_mastrino(tipo_riga_mastrino trig, - TRecnotype rmov, TRecnotype mov, - const real& d, const real& a, - const TDate& datareg) - : _type(trig), _rmov(rmov), _mov(mov), - _dare(d), _avere(a), _data(datareg) -{ } - -TImporto TRiga_mastrino::saldo() const -{ - TImporto imp('D', _dare - _avere); - imp.normalize(); - return imp; -} - -class TMastrino : public TObject -{ - static long _instances; - static TCursor* _cur; - static TRelation* _rel; - static TLocalisamfile *_rmov; // File principale della relazione - static TLocalisamfile *_mov; // File secondario della relazione - - TBill _conto; // Conto del mastrino - int _esercizio; // Esercizio di riferimento (eventualmente 0) - TDate _da_data, _a_data; // Date limite - TString _da_caus, _a_caus; // Causali limite - bool _provvis; // Includi provvisori - - real _pdare_ini, _pavere_ini; - real _pdare_per, _pavere_per; - real _pdare_fin, _pavere_fin; - - TList _riga; // Righe del mastrino - -protected: - TCursor& cur() { return *_cur; } - TRelation& rel() { return *_rel; } - TLocalisamfile& rmov() { return *_rmov; } - TLocalisamfile& mov() { return *_mov; } - - void position_rel(long n); - TRiga_mastrino& row(long n) const { return (TRiga_mastrino&)_riga.obj(n); } - -public: - long items() const { return _riga.items(); } - - void read(const TBill& conto, - int annoes, const TDate& dd, const TDate& ad, - const TString& dc, const TString& ac, bool provvis); - void reread(); - - TRiga_mastrino& operator[](long n) const { return row(n); } - const TRectype& riga(long n); - const TRectype& testata(long n); - - long first(tipo_riga_mastrino tipo = riga_mastrino) const; - long pred(long rec, tipo_riga_mastrino tipo = riga_mastrino) const; - long succ(long rec, tipo_riga_mastrino tipo = riga_mastrino) const; - long last(tipo_riga_mastrino tipo = riga_mastrino) const; - - void destroy() { _riga.destroy(); } - - const real& progressivo_dare_iniziale() const { return _pdare_ini; } - const real& progressivo_avere_iniziale() const { return _pavere_ini; } - TImporto saldo_iniziale() const; - - const real& progressivo_dare_finale() const { return _pdare_fin; } - const real& progressivo_avere_finale() const { return _pavere_fin; } - TImporto saldo_finale() const; - - real progressivo_dare_periodo() const { return _pdare_ini + _pdare_per; } - real progressivo_avere_periodo() const { return _pavere_ini + _pavere_per; } - TImporto saldo_periodo() const; - - const TBill& conto() const { return _conto; } - int esercizio() const { return _esercizio; } - const TDate& inizio_periodo() const { return _da_data; } - const TDate& fine_periodo() const { return _a_data; } - void periodo(TDate& dd, TDate& ad) const { dd = _da_data; ad = _a_data; } - - bool expandable(long rec) const; - bool expand(long rec); - bool collapse(long rec); - - TMastrino(); - virtual ~TMastrino(); -}; - -long TMastrino::_instances = 0L; -TCursor* TMastrino::_cur = NULL; -TRelation* TMastrino::_rel = NULL; -TLocalisamfile* TMastrino::_rmov = NULL; // File principale della relazione -TLocalisamfile* TMastrino::_mov = NULL; // File secondario della relazione - -TMastrino::TMastrino() : _esercizio(0) -{ - if (_instances == 0L) - { - _rel = new TRelation(LF_RMOV); - _rel->add(LF_MOV, "NUMREG==NUMREG"); - _rmov = &_rel->lfile(); - _mov = &_rel->lfile(LF_MOV); - } - _instances++; -} - -TMastrino::~TMastrino() -{ - _instances--; - if (_instances == 0L) - { - delete _cur; _cur = NULL; - delete _rel; _rel = NULL; - _rmov = _mov = NULL; - } -} - -long TMastrino::succ(long rec, tipo_riga_mastrino tipo) const -{ - if (rec < 0) - rec = -1; - - const long ul = items(); - long i; - - for (i = rec+1; i < ul; i++) - { - if (row(i).tipo() == tipo) - break; - } - return i; -} - -long TMastrino::pred(long rec, tipo_riga_mastrino tipo) const -{ - if (rec > items()) rec = items(); - long i; - for (i = rec-1; i >= 0; i--) - { - if (row(i).tipo() == tipo) - break; - } - return i; -} - -long TMastrino::first(tipo_riga_mastrino tipo) const -{ - return succ(-1, tipo); -} - -long TMastrino::last(tipo_riga_mastrino tipo) const -{ - return pred(items(), tipo); -} - -void TMastrino::read(const TBill& conto, - int ae, const TDate& dd, const TDate& ad, - const TString& dc, const TString& ac, - bool provvis) -{ - TEsercizi_contabili esercizi; - - _conto = conto; - _esercizio = ae; - - _riga.destroy(); - - rmov().setkey(2); - TRectype& rmov_rec = rmov().curr(); - TRectype& mov_rec = mov().curr(); - - if (ae <= 0) - { - if (dd.ok()) - ae = esercizi.date2esc(dd); - else - ae = esercizi.date2esc(ad); - } - CHECKD(esercizi.exist(ae), "Anno di esercizio fantasioso: ", ae); - - const TDate& inizio_esercizio = esercizi[ae].inizio(); - _da_data = dd.ok() ? dd : inizio_esercizio; - _a_data = ad.ok() ? ad : esercizi[ae].fine(); - - const bool test_caus = !(dc.blank() && ac.blank()); - _da_caus = dc; - _a_caus = ac.blank() ? "zzz" : ac; // Se vuota sceglie la massima causale - _provvis = provvis; - - TDate max_data_reg = _a_data; - long num_giorni = _a_data - inizio_esercizio + 1; - if (_esercizio > 0) - { - const int succ = esercizi.next(ae); - if (succ > 0) - { - max_data_reg = esercizi[succ].fine(); - num_giorni += 30; - } - else - max_data_reg = esercizi[ae].fine(); - } - - // Valori dei saldi fino alla data di inizio stampa: - // Vengono inizializzati con i saldi iniziali dell'esercizio, - // poi verranno sommati gli importi dei movimenti che - // vanno dall'inizio dell'esercizio al giorno precedente - // la data di inizio stampa - - TBalance saldo(_conto, ae, true, provvis); - _pdare_ini = saldo.progressivo_dare_iniziale(); - _pavere_ini = saldo.progressivo_avere_iniziale(); - - // Valori dei saldi finali: - // Comprendono i movimenti di apertura, chiusura ed i progressivi attuali - saldo.read(_conto, ae, false, provvis); - _pdare_fin = saldo.progressivo_dare_finale(); - _pavere_fin = saldo.progressivo_avere_finale(); - - // Valori dei saldi del perido in esame: - // Vengono inizializzati a zero e poi si incrementa man mano - // coi valori degli importi dei movimenti compresi nei - // limiti della stampa - _pdare_per = _pavere_per = ZERO; - - const TRecfield rmov_datareg (rmov_rec, RMV_DATAREG); - const TRecfield rmov_numreg (rmov_rec, RMV_NUMREG); - const TRecfield rmov_gruppo (rmov_rec, RMV_GRUPPO); - const TRecfield rmov_conto (rmov_rec, RMV_CONTO); - const TRecfield rmov_sottoconto(rmov_rec, RMV_SOTTOCONTO); - const TRecfield rmov_sezione (rmov_rec, RMV_SEZIONE); - const TRecfield rmov_importo (rmov_rec, RMV_IMPORTO); - - const TRecfield mov_datacomp (mov_rec, MOV_DATACOMP); - const TRecfield mov_provvis (mov_rec, MOV_PROVVIS); - const TRecfield mov_codcaus (mov_rec, MOV_CODCAUS); - -#ifdef DBG - long num_rec = 0; - const clock_t clock_start = clock(); -#endif - - rmov_rec.zero(); - conto.put(rmov_rec); - TRectype darow(rmov_rec), arow(rmov_rec); - darow.put(RMV_DATAREG, inizio_esercizio); - arow.put(RMV_DATAREG, max_data_reg); - TCursor cur(&rel(), "", 2, &darow, &arow); - const TRecnotype totrows = cur.items(); - cur.freeze(); - - TString caption(80); - caption.format(FR("Caricamento mastrino %03d.%03d.%06ld"), - _conto.gruppo(), _conto.conto(), _conto.sottoconto()); - TProgind pi(totrows, caption, false, true); - - for (cur = 0L; cur.pos() < totrows; ++cur) - { - pi.addstatus(1); -#ifdef DBG - num_rec++; - if ((num_rec & 0x7F) == 0) - { - const double sec = (clock() - clock_start) / CLOCKS_PER_SEC; - if (sec > 0.0) - { - TString80 msg; - msg.format("%ld records at %ld rec/sec", num_rec, long(num_rec/sec)); - pi.set_text(msg); - } - } -#endif - - // Ignora eventualmente i movimenti provvisori - if (!_provvis) - { - const char is_provvis = *(const char*)mov_provvis; - if (is_provvis > ' ') - continue; - } - - const TDate data_corrente = _esercizio <= 0 ? rmov_datareg : TDate((const char*)mov_datacomp); - if (data_corrente > _a_data) - continue; - - const char sezione = *((const char*)rmov_sezione); - const real importo((const char*)rmov_importo); - - if (data_corrente < _da_data) - { - if (data_corrente >= inizio_esercizio) - { - if (sezione == 'D') - _pdare_ini += importo; - else - _pavere_ini += importo; - } - } - else - { - if (sezione == 'D') - _pdare_per += importo; - else - _pavere_per += importo; - - // Controlla che la causale sia nei limiti - if (test_caus) - { - const bool ok = _da_caus <= mov_codcaus && _a_caus >= mov_codcaus; - if (!ok) - continue; - } - - TRiga_mastrino* r = new TRiga_mastrino(riga_mastrino, - rmov().recno(), mov().recno(), - _pdare_per, _pavere_per, rmov_datareg); - _riga.append(r); - } - } - - // Mi sposto all'inizio per far funzionare bene da subito il metodo riga(0) - mov().first(); - rmov().first(); -} - -void TMastrino::reread() -{ - read(_conto, _esercizio, _da_data, _a_data, _da_caus, _a_caus, _provvis); -} - -void TMastrino::position_rel(long n) -{ - const TRiga_mastrino& r = row(n); - if (rmov().recno() != r.rmov()) - rmov().readat(r.rmov()); - if (mov().recno() != r.mov()) - mov().readat(r.mov()); -} - -const TRectype& TMastrino::riga(long n) -{ - position_rel(n); - return rmov().curr(); -} - -const TRectype& TMastrino::testata(long n) -{ - position_rel(n); - return mov().curr(); -} - -TImporto TMastrino::saldo_iniziale() const -{ - TImporto s('D', _pdare_ini - _pavere_ini); - return s.normalize(); -} - -TImporto TMastrino::saldo_finale() const -{ - TImporto s('D', _pdare_fin - _pavere_fin); - return s.normalize(); -} - -TImporto TMastrino::saldo_periodo() const -{ - TImporto s('D', progressivo_dare_periodo() - progressivo_avere_periodo()); - return s.normalize(); -} - -bool TMastrino::expandable(long rec) const -{ - bool e = false; - if (rec >= 0 && rec < items()) - { - if (row(rec).tipo() == riga_mastrino) - { - if (rec < items()-1) - e = row(rec+1).tipo() != riga_contropartita; - else - e = true; - } - } - return e; -} - -// Genera le righe di contropartita di una riga del mastrino -bool TMastrino::expand(long rec) -{ - bool ok = expandable(rec); - if (ok) - { - const TRectype& head = testata(rec); // Testata movimento - const long numreg = head.get_long(RMV_NUMREG); // Numero di registrazione - const int numrig = riga(rec).get_int(RMV_NUMRIG); // Numero riga contabile - const TDate datareg = head.get(MOV_DATAREG); // Data di registrazione - - rmov().setkey(1); // Usa chiave NUMREG+NUMRIG - TRectype& curr = rmov().curr(); // Record corrente - - const TRecfield rnumreg (curr, RMV_NUMREG); // Numero di registrazione corrente - const TRecfield rnumrig (curr, RMV_NUMRIG); // Numero di riga corrente - const TRecfield rsezione(curr, RMV_SEZIONE); // Sezione Dare/Avere - const TRecfield rimporto(curr, RMV_IMPORTO); // Importo della riga - - int err = NOERR; - if (numrig != 1) // Se non e' gia' posizionato grazie a riga(rec) - { - curr.zero(); // Azzera record corrente - curr.put(RMV_NUMREG, numreg); // Inizializza la chiave parziale - err = rmov().read(_isgteq); // Cerca la prima riga del movimento - } - for (; err == NOERR; err = rmov().next()) // Scandisce righe movimento - { - if (numreg != (long)rnumreg) // Controlla validita' numero - break; - - if (numrig != (int)rnumrig) // Ignora la riga gia' presente - { - real dare, avere; // Costruisce importo della riga - if (*(const char*)rsezione == 'D') - dare = rimporto; - else - avere = rimporto; - // Aggiunge una riga di contropartita al mastrino - TRiga_mastrino* r = new TRiga_mastrino(riga_contropartita, - rmov().recno(), mov().recno(), - dare, avere, datareg); - _riga.append(r, rec++); - } - } - } - return ok; -} - -// Elimina le righe di contropartita di una riga del mastrino -bool TMastrino::collapse(long rec) -{ - bool ok = true; // Posso eliminare? - - if (rec < 0) - { - for (long i = last(); i >= 0; i = pred(i)) - collapse(i); - } - else - { - if (row(rec).tipo() != riga_mastrino) // Se non sono su una riga mastrino ... - rec = pred(rec, riga_mastrino); // ... mi sposto sulla precedente riga mastrino - ok = !expandable(rec); // Controlla che sia possibile - if (ok) // Posso effetivamente procedere - { - rec++; // Elimino ogni riga contropartita successiva - while (rec < items() && row(rec).tipo() != riga_mastrino) - _riga.remove(rec); - } - } - - return ok; -} - -/////////////////////////////////////////////////////////// -// TGrid_control -/////////////////////////////////////////////////////////// - -class TGrid_control; - -class TGrid_cell : public TFixed_string -{ - XI_EVENT* _xiev; - -public: - TString& set(const char* txt); - TString& set(long num); - void set_icon(int id); - void show_button(bool on = true); - void hide_button() { show_button(false); } - void set_back_color(COLOR col); - void set_fore_color(COLOR col); - void set_colors(COLOR back, COLOR fore); - - short get_column() const { return _xiev->v.cell_request.col_nbr; } - - TString& operator = (const char* str) { return set(str); } - TString& operator = (const TString& str) { return set(str); } - - XI_EVENT* event() { return _xiev; } - - TGrid_cell(XI_EVENT* xiev); - virtual ~TGrid_cell() { } -}; - -class TGrid_field : public TOperable_field -{ -protected: // TMask_field - virtual void create(WINDOW parent); - virtual void parse_head(TScanner& scanner); - virtual bool parse_item(TScanner& scanner); - virtual word class_id() const; - -public: - TGrid_control& grid() const { return (TGrid_control&)*_ctl; } - - virtual bool handler(XI_EVENT* xiev); - virtual long items() const; - virtual void cell_request(long rec, short id, TGrid_cell& cell); - - virtual bool on_record(long rec) { return true; } - virtual bool off_record(long rec) { return true; } - virtual bool on_resize_column(short cid, int new_size) { return true; } - virtual void on_dbl_cell(long rec, short id) { } - virtual void on_grid_button() { } - virtual void on_record_button(long rec) { } - virtual void on_cell_button(long rec, short cid) { } - - long selected() const; - void update(long n = -1); - int visible_rows() const; - bool select(long rec); - - void reset_columns_order(); - void save_columns_order() const; - - TGrid_field(TMask* m); - virtual ~TGrid_field() { } -}; - -class TGrid_control : public TControl -{ - enum grid_control_constants { MAX_COL = 64 }; - - long _cur_rec; - bool _read_only; - - // @cmember:(INTERNAL) Tipo di ogni colonna - byte _type[MAX_COL]; - - TGrid_field* _grid; - - int _default_width[MAX_COL]; - int _columns_order; - -protected: // TControl - //@cmember Gestisce gli eventi delle celle - virtual bool event_handler(XI_OBJ* itf, XI_EVENT* xiev); - - //@cmember Chiama gli handlers opportuni per verificare il cambio record - bool try_to_select(long rec) const; - -protected: - //@cmember Ritorna il numero totale di righe - long items() const { return _grid->items(); } - - //@cmember Converte un record nella eventuale riga corrispondente a video - int rec2row(long rec) const; - - //@cmember Converte una riga a video nell'eventuale record corrispondente - long row2rec(int row) const; - - //@cmember Converte un indice di colonna nel corrispondente id - short int col2cid(int pos) const; - - void update_selection(XI_EVENT* xiev); - - void set_columns_order(TToken_string* order); - - XI_OBJ* find_column(const char* head) const; - -public: - long selected() const { return _cur_rec; } - bool select(long n); - - int visible_rows() const; - - XI_OBJ* find_column(short cid) const; - byte& column_type(int c) { CHECKD(c >= 0 && c < MAX_COL, "Bad column ", c); return _type[c]; } - void show_column(short cid, bool on); - - void update(long n = -1); - bool is_visible(long rec) const; - - void load_columns_order(); - void save_columns_order() const; - void reset_columns_order() { set_columns_order(NULL); } - - TGrid_control(WINDOW parent, short cid, - short x, short y, short dx, short dy, - const char* flags, const char* head, - TGrid_field* owner); - virtual ~TGrid_control() {} -}; - - -TGrid_control::TGrid_control( - WINDOW parent, // @parm Finestra alla quale appartiene lo spreadsheet - short cid, // @parm Identificatore - short x, // @parm Coordinata x (in caratteri) nel quale posizionare lo spreadsheet - short y, // @parm Coordinata y (in caratteri) nel quale posizionare lo spreadsheet - short dx, // @parm Larghezza (in caratteri) dello spreasheet - short dy, // @parm Lunghezza (in caratteri) dello spreasheet - const char* flags, // @parm Flags di abilitazione - const char* head, // @parm Titolo delle colonne - TGrid_field* owner) - : _grid(owner), _cur_rec(-1), _columns_order(0) -{ - _read_only = false; - bool auto_num = false; - bool multi_line = false; - int lines_in_cell = 1; - - for (const char* f = flags; *f; f++) - { - switch(*f) - { - case 'A': - auto_num = true; - break; - case 'D': - _read_only = true; - break; - case 'M': - multi_line = true; - lines_in_cell = (int)xi_get_pref(XI_PREF_DEFAULT_MAX_LINES_IN_CELL); - break; - case '2': - case '3': - case '4': - case '5': - if (multi_line) - lines_in_cell = *f - '0'; - break; - default: - break; - } - } - - const int NUMBER_WIDTH = auto_num ? 7 : 1; - short v_width[MAX_COL]; - short m_width[MAX_COL]; - int fixed_columns = 1; // Number of fixed columns - int lines_in_header = 1; // Number of header lines - - // Calcolo larghezza massima tabella - TToken_string header(head); - TToken_string new_header(256); - int i = 0; - int f_width = NUMBER_WIDTH; // Stima larghezza colonne fisse - int max_width = f_width; // Stima larghezza della colonna piu' grande - const char* h; - - for (h = header.get(); h; h = header.get(), i++) - { - CHECKD(i < MAX_COL, "Tu meni calumns in scit: ", i); - _type[i] = ' '; - - TFixed_string testa(esc(h)); - const bool multiple = testa.find('\n') > 0; - if (multiple) - lines_in_header = 2; - - const int at = testa.find('@'); - int v = testa.len(); // Video width - if (at >= 0) - { - const TString& wi = testa.mid(at+1); - const int video = atoi(wi); - if (video > 0) v = video; - if (wi.find('F') >= 0) - { - fixed_columns = i+2; - f_width += v+1; - } - if (wi.find('R') >= 0) - _type[i] = 'R'; - - testa.cut(at); - } - - v++; - // memory width of column - m_width[i] = v * lines_in_cell; - if (v > 64) v = 64; - v_width[i] = v; - if (v_width[i] > max_width) - max_width = v_width[i]; - new_header.add(testa); - } - - // Calcola rettangolo massimo per lo sheet - XI_OBJ* itf = get_interface(parent); - XI_RCT rct = coord2rct(itf, x, y, dx, dy); - rct.right -= 2*XI_FU_MULTIPLE; // toglie scroll-bar - - // Controlla se ci sono troppe colonne fisse - if ((f_width+max_width)*XI_FU_MULTIPLE > rct.right) - fixed_columns = 1; - - long list_attr = XI_ATR_ENABLED | XI_ATR_VISIBLE; - // if (_read_only) list_attr |= XI_ATR_NAVIGATE; - - XI_OBJ_DEF* listdef = xi_add_list_def(NULL, cid, - rct.top, rct.left, rct.bottom-rct.top, - list_attr, - NORMAL_COLOR, NORMAL_BACK_COLOR, // normal - DISABLED_COLOR, DISABLED_BACK_COLOR, // disabled - FOCUS_COLOR, // active - 0); - - listdef->app_data = (long)this; - - XI_LIST_DEF* l = listdef->v.list; - l->min_heading_height = xi_button_calc_height_font(xi_get_system_font()) * lines_in_header; - l->sizable_columns = true; - l->movable_columns = true; - l->fixed_columns = fixed_columns; - l->max_lines_in_cell = lines_in_cell; - l->scroll_bar = true; - l->scroll_bar_button = true; - l->white_space_color = MASK_DARK_COLOR; - l->rule_color = MASK_DARK_COLOR; - - if (_read_only) - { - l->single_select = true; - } - else - { - l->active_back_color = FOCUS_BACK_COLOR; - } - - // Definizione della prima colonna (numero di riga) - const long attr = XI_ATR_VISIBLE | XI_ATR_RJUST | XI_ATR_SELECTABLE; - XI_OBJ_DEF* coldef = xi_add_column_def(listdef, FIRST_FIELD+1000-1, attr, 0, - NUMBER_WIDTH * XI_FU_MULTIPLE, NUMBER_WIDTH , ""); - - coldef->app_data = (long)this; - XI_COLUMN_DEF* cd = coldef->v.column; - cd->heading_platform = true; - cd->column_platform = true; - - for (h = new_header.get(0), i = 0; h; h = new_header.get(), i++) - { - long attr = XI_ATR_VISIBLE | XI_ATR_ENABLED | XI_ATR_AUTOSCROLL; - if (_read_only) - attr |= XI_ATR_READONLY | XI_ATR_SELECTABLE; - if (_type[i] == 'R') - attr |= XI_ATR_RJUST; - coldef = xi_add_column_def(listdef, FIRST_FIELD+i+1000, attr, i+1, - v_width[i] * XI_FU_MULTIPLE, m_width[i], (char*)h); - - coldef->app_data = (long)this; - cd = coldef->v.column; - cd->heading_platform = true; - cd->center_heading = true; - if (multi_line) - cd->wrap_text = _type[i] != 'R'; - } - - XI_RCT rd; xi_get_def_rect(listdef, &rd); - if ((rd.right - rd.left) > (rct.right - rct.left)) - l->width = rct.right - rct.left; - - _obj = xi_create(itf, listdef); // Create the whole thing! - xi_dequeue(); // Flush events in XOL - xi_tree_free(listdef); // Free definitions - - CHECKD(_obj, "Can't create list control ", cid); - update_tab_cid(); - - int num = 0; - XI_OBJ** column = xi_get_member_list(_obj, &num); - for (i = 0; i < num; i++) - { - xi_get_rect(column[i], &rd); - _default_width[i] = rd.right - rd.left; - } -} - -// Converts a record number in the correspondig row number -int TGrid_control::rec2row(long record) const -{ - int rows; - const long* rec = xi_get_list_info(_obj, &rows); - int r = rows > 0 ? int(record - rec[0]) : -1; - if (r < 0 || r >= rows) - r = -1; - return r; -} - -// Converts a row number in the correspondig record number -long TGrid_control::row2rec(int row) const -{ - CHECK(row >= 0, "Negative grid row?"); - - int rows; - const long* handle = xi_get_list_info(_obj, &rows); - - long rec; - if (rows > 0) - { - if (row >= rows) - rec = handle[rows-1] + row - rows + 1; - else - rec = handle[row]; - } - else - rec = -1; - - if (rec < 0 || rec >= items()) - rec = -1; - - return rec; -} - -int TGrid_control::visible_rows() const -{ - return xi_get_visible_rows(_obj, NULL, NULL); -} - -bool TGrid_control::is_visible(long rec) const -{ - int first = 0, last = 0; - xi_get_visible_rows(_obj, &first, &last); - - int rows = 0; - const long* handle = xi_get_list_info(_obj, &rows); - - bool yes = rec >= handle[first] && rec <= handle[last]; - return yes; -} - - -void TGrid_control::update(long n) -{ - if (n >= 0) - { - const int riga = rec2row(n); - if (riga >= 0) - { - XI_OBJ row; - XI_MAKE_ROW(&row, _obj, riga); - xi_cell_request(&row); - } - } - else - { - int num = 0; - const long* handle = xi_get_list_info(_obj, &num); - - bool scroll_first = items() == 0; - if (!scroll_first) - { - int first = 0, last = 0; - xi_get_visible_rows(_obj, &first, &last); - n = handle[first]; - scroll_first = n > items(); - } - - if (scroll_first) - xi_scroll(_obj, XI_SCROLL_FIRST); - else - xi_scroll_rec(_obj, n, NORMAL_COLOR, XI_ATR_ENABLED, 0); - } -} - -bool TGrid_control::select(long rec) -{ - bool ok, sel; - if (rec >= 0) - { - ok = try_to_select(rec); - sel = ok; - } - else - { - ok = _cur_rec >= 0 && _cur_rec < items() && _grid->off_record(_cur_rec); - sel = false; - } - - if (ok) - { - if (sel) - { - int first, last; - xi_get_visible_rows(_obj, &first, &last); - // Controllo che la nuova riga sia completamente visibile - const int next_row = rec2row(rec); - if (next_row >= first && next_row <= last) - { - if (_read_only) - { - XI_OBJ riga; XI_MAKE_ROW(&riga, _obj, next_row); - long attr = xi_get_attrib(&riga); - attr |= XI_ATR_SELECTED; - xi_set_attrib(&riga, attr); - } - } - else - { - long attr = XI_ATR_ENABLED; - if (_read_only) - attr |= XI_ATR_SELECTED; - xi_scroll_rec(_obj, rec, NORMAL_COLOR, attr, 0); - } - - if (!_read_only) - { - const int next_row = rec2row(rec); - XI_OBJ cella; XI_MAKE_CELL(&cella, _obj, next_row, 1); - xi_set_focus(&cella); - } - } // end if (sel) - - // Deseleziona record precedente se ancora visibile - if (_read_only) - { - const int cur_row = rec2row(_cur_rec); - if (cur_row >= 0) - { - XI_OBJ riga; XI_MAKE_ROW(&riga, _obj, cur_row); - long attr = xi_get_attrib(&riga); - attr &= ~XI_ATR_SELECTED; - xi_set_attrib(&riga, attr); - } - xi_dequeue(); - } - - if (rec < 0 || rec >= items()) - rec = -1; - _cur_rec = rec; - } // end if (ok) - - return ok; -} - -short TGrid_control::col2cid(int pos) const -{ - int num; - XI_OBJ** column = xi_get_member_list(_obj, &num); - CHECKD(pos >= 0 && pos < num, "Bad column ", pos); - const short cid = column[pos]->cid - 1000; - return cid; -} - -bool TGrid_control::try_to_select(long rec) const -{ - bool ok = rec >= 0 && rec < items(); - if (ok && rec != _cur_rec) - { - if (_cur_rec >= 0 && _cur_rec < items()) - ok = _grid->off_record(_cur_rec); - if (ok) - ok = _grid->on_record(rec); - } - return ok; -} - -void TGrid_control::update_selection(XI_EVENT* xiev) -{ - const bool is_curr = xiev->v.rec_request.data_rec == _cur_rec; - if (_read_only) - { -/* - if (is_curr) - xiev->v.rec_request.attrib |= XI_ATR_SELECTED; - else - xiev->v.rec_request.attrib &= ~XI_ATR_SELECTED; -*/ - } - else - xiev->v.rec_request.has_focus = is_curr; -} - -// Certified 75% -bool TGrid_control::event_handler(XI_OBJ* itf, XI_EVENT *xiev) -{ - BOOLEAN& refused = xiev->refused; - - const bool handled = _grid->handler(xiev); - if (handled) - return !refused; - - switch (xiev->type) - { - case XIE_GET_FIRST: - if (items() > 0L) - { - long n = items() * (long)xiev->v.rec_request.percent / 100L; - if (n < 0L) n = 0L; - xiev->v.rec_request.data_rec = n; - update_selection(xiev); - } - else - refused = true; - break; - case XIE_GET_LAST: - xiev->v.rec_request.data_rec = items()-1; - update_selection(xiev); - break; - case XIE_GET_PREV: - case XIE_GET_NEXT: - { - const long n = xiev->v.rec_request.spec_rec + (xiev->type == XIE_GET_NEXT ? +1 : -1) ; - if (n >= 0 && n < items()) - { - xiev->v.rec_request.data_rec = n; - update_selection(xiev); - } - else - refused = true; - // Altrimenti sbaglia a ridisegnare le righe della DBService! - XI_RCT rct; xi_get_rect(_obj, &rct); - xi_invalidate_rect(xi_get_window(_obj), &rct); - } - break; - case XIE_GET_PERCENT: - { - const long rec = xiev->v.get_percent.record; - long n = items(); if (n <= 0) n = 1; - xiev->v.get_percent.percent = short(rec * 100L / n); - } - break; - case XIE_COL_MOVE: - // Rifiuta di spostare una colonna nelle o dalle colonne fisse - if (xiev->v.column.in_fixed || - xiev->v.column.col_nbr < xi_get_fixed_columns(xiev->v.column.list)) - refused = true; - else - _columns_order = 1; - break; - case XIE_COL_SIZE: - { - const short cid = col2cid(xiev->v.column.col_nbr); - if (_grid->on_resize_column(cid, xiev->v.column.new_col_width)) - _columns_order = 1; - else - refused = true; - } - break; - case XIE_SELECT: - if (xiev->v.select.xi_obj->type == XIT_ROW) // Considero solo le righe - { - if (xiev->v.select.selected) // Sto selezionando - { - const long rec = row2rec(xiev->v.select.xi_obj->v.row_data.row); - if (try_to_select(rec)) - { - if (xiev->v.select.column == 0) - { -// if (_read_only) // Commentato 8/11/2013 altrimenti non funziona più collegamento a cg2 -// refused = !select(rec); -// else - { - if (rec == _cur_rec) // Simulo intercettazione doppio click - _grid->on_record_button(rec); - } - } - else - { - if (_read_only && rec == _cur_rec) - { - const short cid = col2cid(xiev->v.select.column); - _grid->on_dbl_cell(rec, cid); - refused = true; - } - } - _cur_rec = rec; // Assegno solo ora il record corrente - } - else - refused = true; - } - } - break; - case XIE_CELL_REQUEST: - { - const long& rec = xiev->v.cell_request.rec; - if (rec >= 0 && rec < items()) - { - TGrid_cell cell(xiev); - const short cid = col2cid(cell.get_column()); - if (cid >= FIRST_FIELD) - { - _grid->cell_request(rec, cid, cell); - } - else - { - if (cell.size() > 2) - { - cell.set(rec+1); - // Setto il colore del testo altrimenti verrebbe grigio: - // non uso la set_color perche' ignora NORMAL_COLOR - xiev->v.cell_request.color = NORMAL_COLOR; - } - } - } - else - refused = true; // Ogni tanto succede - } - break; - case XIE_ON_ROW: - { // Qui ci passa solo se non e' _read_only - const long rec = row2rec(xiev->v.xi_obj->v.row); - if (rec >= 0) - { - if (_grid->on_record(rec)) - _cur_rec = rec; - else - refused = true; - } - else - { - NFCHECK("You are entering an invalid row: %d", xiev->v.xi_obj->v.row); - refused = true; - } - } - break; - case XIE_OFF_ROW: - // Qui ci passa solo se non e' _read_only - if (_cur_rec >= 0 && _cur_rec < items()) - refused = !_grid->off_record(_cur_rec); - break; - case XIE_ON_CELL: - break; - case XIE_DBL_CELL: - { - const long rec = row2rec(xiev->v.xi_obj->v.cell.row); - if (try_to_select(rec)) - { - const short cid = col2cid(xiev->v.xi_obj->v.cell.column); - _grid->on_dbl_cell(rec, cid); - } - } - break; - case XIE_BUTTON: - if (xiev->v.xi_obj->type == XIT_LIST) - { - _grid->on_grid_button(); - } - else - { - const XI_CELL_DATA& cell = xiev->v.xi_obj->v.cell; - const long rec = row2rec(cell.row); - if (try_to_select(rec)) - { - const short cid = col2cid(cell.column); - _grid->on_cell_button(rec, cid); - } - else - NFCHECK("You are clicking an invalid cell: %d", cell.row); - } - break; - default: - break; - } - - return !refused; -} - -XI_OBJ* TGrid_control::find_column(short cid) const -{ - int num = 0; - XI_OBJ** column = xi_get_member_list(_obj, &num); - int i; - for (i = num-1; i >= 0; i--) - { - if (column[i]->cid == cid) - break; - } - return i >= 0 ? column[i] : NULL; -} - -XI_OBJ* TGrid_control::find_column(const char* head) const -{ - int num = 0; - XI_OBJ** column = xi_get_member_list(_obj, &num); - - TString256 text; - int i; - for (i = num-1; i >= 0; i--) - { - xi_get_text(column[i], text.get_buffer(), text.size()); - if (text == head) - break; - } - return i >= 0 ? column[i] : NULL; -} - -void TGrid_control::show_column(short cid, bool on) -{ - XI_OBJ* column = find_column(cid); - if (column) - { -/* Useless - dword attr = xi_get_attrib(column); - if (on) attr |= XI_ATR_VISIBLE; - else attr &= ~XI_ATR_VISIBLE; - xi_set_attrib(column, attr); // Set new attributes - update(-1); -*/ - if (!on) - xi_delete(column); - } -} - -void TGrid_control::set_columns_order(TToken_string* order) -{ - XI_OBJ* itf = get_interface(); - XI_OBJ* focus = xi_get_focus(itf); - xi_set_focus(itf); - - int num_cols; - XI_OBJ** column = xi_get_member_list(_obj, &num_cols); - - // Costante da sottrarre nella xi_column_set_pixel_width altrimenti la somma due volte! - const int offset = 2 * (int)xi_get_pref(XI_PREF_COLUMN_OFFSET); - const int fixed = xi_get_fixed_columns(_obj); - if (fixed > 1) - xi_set_fixed_columns(_obj, 1); - - if (order == NULL) - { - for (int index = 1; index < num_cols; index++) - { - const short cid = FIRST_FIELD + 1000 + index - 1; - XI_OBJ* col = find_column(cid); - if (col) - { - xi_move_column(col, index); - RCT rct; xi_get_rect(col, (XinRect*)&rct); - if (_default_width[index] != rct.right - rct.left) - xi_column_set_pixel_width(col, _default_width[index]-offset); - } - } - _columns_order = 0x3; - } - else - { - TToken_string col(8, ','); - int pos = 0; - for (col = order->get(0); !col.blank(); col = order->get(), pos++) - { - const char* head = esc(col.get(0)); - const int width = col.get_int(); - XI_OBJ* column = find_column(head); - if (column) // Controlla che esista ancora - { - if (pos > 0 && pos < num_cols) - xi_move_column(column, pos); // Sposta la colonna se possibile - if (width > XI_FU_MULTIPLE) // Se ha una larghezza valida - xi_column_set_pixel_width(column, width - offset); - } - } - } - - if (fixed > 1) - xi_set_fixed_columns(_obj, fixed); - - if (focus) - xi_set_focus(focus); -} - -HIDDEN TFilename& field2parag(const TMask_field& f, TFilename& name) -{ - const TMask& m = f.mask(); - name = m.source_file(); - name.ext(""); // Nome della maschera senza estensione - const int index = m.number(); - CHECKD(index >= 0 && index <= 8, "Bad mask index:", index); - if (index > 0) // Aggiunge l'eventuale numero di sotto-maschera - name << '(' << index << ')'; - return name; -} - -void TGrid_control::load_columns_order() -{ - TFilename parag; field2parag(*_grid, parag); - TConfig config(CONFIG_USER, parag); - TToken_string order = config.get("Browse", NULL, id()); - if (order.empty_items()) - config.remove("Browse", id()); - else - set_columns_order(&order); - _columns_order = 0; -} - -void TGrid_control::save_columns_order() const -{ - if (_columns_order) - { - TFilename parag; field2parag(*_grid, parag); - TConfig config(CONFIG_USER, parag); // Apre il file di configurazione - - TToken_string order(127); // Nuovo ordine delle colonne - if (_columns_order == 1) // Se vale 3 devo solo resettare - { - int num; - XI_OBJ** column = xi_get_member_list(_obj, &num); - TString80 head; - for (int i = 0; i < num; i++) // Scorre tutte le colonne - { - xi_get_text(column[i], head.get_buffer(), head.size()); - const int acapo = head.find('\n'); - if (acapo > 0) - { - head[acapo] = '\\'; - head.insert("n", acapo+1); - } - order.add(head); - RCT rct; xi_get_rect(column[i], (XinRect*)&rct); - order << ',' << rct.right - rct.left; - } - config.set("Browse", order, NULL, true, id()); - } - else - config.remove("Browse", id()); - } -} - -/////////////////////////////////////////////////////////// -// TGrid_cell -/////////////////////////////////////////////////////////// - -TGrid_cell::TGrid_cell(XI_EVENT* xiev) - : TFixed_string(xiev->v.cell_request.s, xiev->v.cell_request.len), - _xiev(xiev) -{ } - - -// Setta il testo di una cella (Mai piu' testo troppo lungo!) -// Se c'e' gia' un'icona la elimina -TString& TGrid_cell::set(const char* txt) -{ - strncpy(txt, size()); - if (not_empty()) - { - int& icon = _xiev->v.cell_request.icon_rid; - if (icon) - icon = 0; - } - return *this; -} - -TString& TGrid_cell::set(long num) -{ - char buff[16]; - sprintf(buff, "%ld", num); - return set(buff); -} - -// Setta l'icona di una cella -// Se c'e' gia' un testo lo elimina -void TGrid_cell::set_icon(int id) -{ - _xiev->v.cell_request.icon_rid = id; - if (id) - _xiev->v.cell_request.s[0] = '\0'; -} - -void TGrid_cell::show_button(bool on) -{ - _xiev->v.cell_request.button = on; - _xiev->v.cell_request.button_on_focus = on; -} - -void TGrid_cell::set_back_color(COLOR col) -{ - if (col != NORMAL_BACK_COLOR) - _xiev->v.cell_request.back_color = col; -} - -void TGrid_cell::set_fore_color(COLOR col) -{ - if (col != NORMAL_COLOR) - _xiev->v.cell_request.color = col; -} - -void TGrid_cell::set_colors(COLOR back, COLOR fore) -{ - if (back != NORMAL_BACK_COLOR) - _xiev->v.cell_request.back_color = back; - if (fore != NORMAL_COLOR) - _xiev->v.cell_request.color = fore; -} - -/////////////////////////////////////////////////////////// -// TGrid_field -/////////////////////////////////////////////////////////// - -TGrid_field::TGrid_field(TMask* m) - : TOperable_field(m) -{ } - -word TGrid_field::class_id() const -{ - return CLASS_GRID_FIELD; -} - -void TGrid_field::update(long n) -{ grid().update(n); } - -void TGrid_field::parse_head(TScanner& scanner) -{ - _ctl_data._width = scanner.integer(); - _ctl_data._height = scanner.integer(); - if (_ctl_data._height == 0) - _ctl_data._height = -1; -} - -void TGrid_field::create(WINDOW parent) -{ - _ctl = new TGrid_control(parent, dlg(), - _ctl_data._x, _ctl_data._y, - _ctl_data._width, _ctl_data._height, - _ctl_data._flags, _ctl_data._park, - this); - grid().load_columns_order(); -} - -bool TGrid_field::parse_item(TScanner& scanner) -{ - if (scanner.key() == "IT") - { - _ctl_data._park.add(scanner.string()); - return true; - } - return TMask_field::parse_item(scanner); -} - - -bool TGrid_field::handler(XI_EVENT* xiev) -{ - return false; -} - -long TGrid_field::items() const -{ - return 100000L; -} - -int TGrid_field::visible_rows() const -{ - return grid().visible_rows(); -} - -void TGrid_field::cell_request(long rec, short id, TGrid_cell& cell) -{ - cell.set("Cell"); -} - -long TGrid_field::selected() const -{ return grid().selected(); } - -bool TGrid_field::select(long rec) -{ return grid().select(rec); } - -void TGrid_field::reset_columns_order() -{ - grid().reset_columns_order(); -} - -void TGrid_field::save_columns_order() const -{ - grid().save_columns_order(); -} - -/////////////////////////////////////////////////////////// -// Da qui in poi e' tutta roba specializzata del programma -/////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////// -// Maschera per colori -/////////////////////////////////////////////////////////// - -class TColor_mask : public TSelect_color_mask -{ -public: - void get_colors(COLOR& mb, COLOR& mf, COLOR& cb, COLOR& cf); - TColor_mask(); -}; - -void TColor_mask::get_colors(COLOR& mb, COLOR& mf, COLOR& cb, COLOR& cf) -{ - get_color("M", mb, mf); - get_color("C", cb, cf); -} - -TColor_mask::TColor_mask() : TSelect_color_mask("cg3600b") -{ - add_color_def("M", TR("Riga mastrino"), REQUIRED_BACK_COLOR, FOCUS_COLOR); - add_color_def("C", TR("Riga contropartita"), NORMAL_BACK_COLOR, NORMAL_COLOR); -} - -/////////////////////////////////////////////////////////// -// TMastrini_grid -/////////////////////////////////////////////////////////// - -class TMastrini_grid : public TGrid_field -{ - TMastrino _mastrino; - - TDecoder _causali; - TEsercizi_contabili _esercizi; - - TColor_mask _colmsk; - COLOR _mas_back, _mas_fore; - COLOR _con_back, _con_fore; - bool _primanoting; -#ifdef CONT_SEP - bool _contsep; -#endif - -protected: // TGrid_field - virtual bool on_record(long rec); - virtual void on_grid_button(); - virtual bool on_resize_column(short id, int new_size); - - void update_mask() const; - -public: - virtual void cell_request(long rec, short id, TGrid_cell& cell); - virtual void on_dbl_cell(long rec, short id); - virtual void on_record_button(long rec); - virtual long items() const { return _mastrino.items(); } - - void destroy(); - void read(const TBill& conto, - int annoes, const TDate& dd, const TDate& ad, - const TString& dc, const TString& ac, bool provv); - void reread(); - - TMastrino& mastrino() { return _mastrino; } - - void save_colors(); - void load_colors(); - void set_colors(); -#ifdef CONT_SEP - void set_contsep(bool cs) { _contsep = cs; } -#endif - - TMastrini_grid(TMask* m); - virtual ~TMastrini_grid() { } -}; - -TMastrini_grid::TMastrini_grid(TMask* m) - : TGrid_field(m), _causali(LF_CAUSALI, CAU_DESCR), _primanoting(false) -#ifdef CONT_SEP - , _contsep(false) -#endif -{ - load_colors(); -} - -void TMastrini_grid::destroy() -{ - _mastrino.destroy(); - grid().select(-1); -} - -HIDDEN const char* real2string(const real& r) -{ - const TCurrency cur(r); - return cur.string(true); -} - -HIDDEN void set_imp(TMask_field& f, const TImporto& imp) -{ - if (!imp.is_zero()) - { - TString80 str; - str.format("%s %c", real2string(imp.valore()), imp.sezione()); - f.set(str); - } - else - f.reset(); -} - -void TMastrini_grid::cell_request(long rec, short id, TGrid_cell& cell) -{ - if (rec < 0) // testate - { - XI_OBJ* col = grid().find_column(short(1000+id%1000)); - if (col != NULL) - { - TString256 str; - xi_get_text(col, str.get_buffer(), str.size()); - cell = str; - - } - return; - } - - const TRiga_mastrino& riga = _mastrino[rec]; - - switch (id) - { - case 101: - if (riga.tipo() == riga_mastrino) - { - const TRectype& mov = _mastrino.testata(rec); - cell = riga.data().string(); - cell << ' ' << mov.get(MOV_DATADOC); - } - break; - case 102: - if (riga.tipo() == riga_mastrino) - { - const TRectype& mov = _mastrino.testata(rec); - const int anno = _esercizi.date2esc(riga.data()); - const int eser = mov.get_int(MOV_ANNOES); - TString8 str; - if (anno != eser) - str = "C"; // Di competenza vecchia - if (mov.get(MOV_PROVVIS).not_empty()) - { - if (str.not_empty()) - str << '/'; - str << 'P'; - } - cell = str; - } - break; - case 103: - if (riga.tipo() == riga_mastrino) - { - const TRectype& mov = _mastrino.testata(rec); - cell.set(_causali.decode(mov.get(MOV_CODCAUS))); - } - else - { - const TRectype& rmov = _mastrino.riga(rec); - cell.format("%03d.%03d.%06ld", - rmov.get_int(RMV_GRUPPO), - rmov.get_int(RMV_CONTO), - rmov.get_long(RMV_SOTTOCONTO)); - } - break; - case 104: // Descrizione - { - const TRectype& rmov = _mastrino.riga(rec); - const TRectype& mov = _mastrino.testata(rec); - TString descr = rmov.get(RMV_DESCR); - if (riga.tipo() == riga_mastrino) - { - if (descr.empty()) - { - const TRectype& mov = _mastrino.testata(rec); - descr = mov.get(MOV_DESCR); - if (descr.empty()) - { - TBill uncle(rmov,true); - descr = uncle.descrizione(); - } - } - } - else - { - // Bug 0001748: ignora descrizioni generate da contabilizzazione - if (descr.empty() || descr == _mastrino.conto().descrizione()) - { - const TBill conto(rmov); - descr = conto.descrizione(); - } - } -#ifdef CONT_SEP - if (_contsep) - { - const TString16 cs = mov.get(MOV_CONTSEP); - if (cs.full()) - descr << "\n" << cache().get("&NPENT", cs, "S0"); - } -#endif - cell.set(descr); - } - break; - case 105: // Dare - { - const TRectype& rmov = _mastrino.riga(rec); - const char sez = rmov.get_char(RMV_SEZIONE); - if (sez == 'D') - cell = real2string(rmov.get_real(RMV_IMPORTO)); - } - break; - case 106: // Avere - { - const TRectype& rmov = _mastrino.riga(rec); - const char sez = rmov.get_char(RMV_SEZIONE); - if (sez == 'A') - cell = real2string(rmov.get_real(RMV_IMPORTO)); - } - break; - case 107: - if (riga.tipo() == riga_mastrino) - { - const TRectype& mov = _mastrino.testata(rec); - cell = mov.get(MOV_NUMDOC); cell.left_just(7); - cell << ' ' << mov.get(MOV_PROTIVA); - } - break; - case 108: - { - const TRectype& rmov = _mastrino.riga(rec); - cell = real2string(rmov.get_real(RMV_IMPORTO)); - cell << ' ' << rmov.get(RMV_SEZIONE); - } - break; - case 109: - if (riga.tipo() == riga_mastrino) - { - const long next_row = _mastrino.succ(rec, riga_mastrino); - bool stampa = next_row >= _mastrino.items(); - if (!stampa) - { - const TDate& data = _mastrino[next_row].data(); - stampa = riga.data() != data; - } - if (stampa) - { - TImporto imp = riga.saldo(); - imp += _mastrino.saldo_iniziale(); - imp.normalize(); - cell = real2string(imp.valore()); - cell << ' ' << imp.sezione(); - } - } - break; - case 110: - if (riga.tipo() == riga_mastrino) - { - const TRectype& mov = _mastrino.testata(rec); - TLocalisamfile movana(LF_MOVANA); - movana.setkey(3); - movana.put(MOVANA_NUMREGCG, mov.get(MOV_NUMREG)); - if (movana.read() == NOERR) - { - const TRectype& rmov = _mastrino.riga(rec); - const TBill bill(rmov); - const TString16 codconto = bill.string(0x8); // GGGCCCSSSSSS - const TRecord_array rmovana(movana.get(MOVANA_NUMREG), LF_RMOVANA); - const int last_rmovana = rmovana.last_row(); - const real target = rmov.get(RMV_IMPORTO); - - TBit_array hits; - - if (hits.first_one() < 0) - { - // Controllo se c'è corrispondenza biunivoca tra le righe di CG e CA - const int nriga = rmov.get_int(RMV_NUMRIG); - if (nriga <= last_rmovana && rmovana.exist(nriga)) - { - const TRectype& r = rmovana.row(nriga); - if (r.get(RMOVANA_CODCONTO) == codconto && r.get_real(RMOVANA_IMPORTO) == target) - hits.set(nriga); - } - } - - if (hits.first_one() < 0) - { - // Controllo se esiste una riga che corrisponda per importo e conto analitico/contabile - for (int i = rmovana.first_row(); i > 0 && i <= last_rmovana; i = rmovana.succ_row(i)) - { - const TRectype& r = rmovana.row(i); - if (r.get(RMOVANA_CODCONTO) == codconto) - { - const real imp = r.get(RMOVANA_IMPORTO); - if (imp == target) - { - hits.set(i); - break; - } - } - } - } - - if (hits.first_one() < 0) - { - // Faccio la somma delle righe che corrispondono per conto analitico/contabile - real total_hits; - for (int i = rmovana.first_row(); i > 0 && i <= last_rmovana; i = rmovana.succ_row(i)) - { - const TRectype& r = rmovana.row(i); - if (r.get(RMOVANA_CODCONTO) == codconto) - { - const real imp = r.get(RMOVANA_IMPORTO); - hits.set(i); - total_hits += imp; - if (total_hits >= target) - break; - } - } - } - - TString cms; - for (int h = hits.first_one(); h >= 0 && h <= last_rmovana; h++) if (hits[h]) - { - const TRectype& r = rmovana.row(h); - TString80 cod = r.get(RMOVANA_CODCMS); - if (cod.starts_with("00000")) - { - int i = 0; - for (i = 5; cod[i] == '0'; i++); - cod.ltrim(i); - } - if (cms.not_empty()) - cms << ' '; - cms << cod; - if (cms.len() >= cell.size()) - break; - } - if (cms.len() >= cell.size()) - cms.cut(cell.size()-1); - cell = cms; - } - } - break; - default: - break; - } - - if (riga.tipo() == riga_mastrino) - cell.set_colors(_mas_back, _mas_fore); - else - cell.set_colors(_con_back, _con_fore); -} - -bool TMastrini_grid::on_record(long rec) -{ - if (_mastrino[rec].tipo() != riga_mastrino) - rec = _mastrino.pred(rec, riga_mastrino); - - TRiga_mastrino& riga = _mastrino[rec]; - TMask& gm = mask(); - set_imp(gm.field(F_TOTRIG_SAL), riga.saldo()); - gm.set(F_TOTRIG_DAR, riga.dare()); - gm.set(F_TOTRIG_AVE, riga.avere()); - - return true; -} - -void TMastrini_grid::on_dbl_cell(long rec, short id) -{ - if (rec >= 0 && rec < items()) - { - if (_mastrino.expandable(rec)) - _mastrino.expand(rec); - else - _mastrino.collapse(rec); - update(); - } -} - -void TMastrini_grid::on_grid_button() -{ - const long total = _mastrino.items(); - if (total > 0) - { - TProgress_monitor pi(total, TR("Aggiornamento contropartite ..."), false); - - // Cerca l'ultima contropartita - const long last_con = _mastrino.last(riga_contropartita); - // Se non esistono contropartite devo espandere le righe - const bool expand = last_con < 0; - -#ifdef DBG - const clock_t clock_start = clock(); -#endif - - if (expand) - { - long step = 0; - for (long n = _mastrino.first(riga_mastrino); - n < _mastrino.items(); n = _mastrino.succ(n, riga_mastrino)) - { - if (_mastrino.expandable(n)) - _mastrino.expand(n); - pi.set_status(++step); -#ifdef DBG - if ((step & 0x7F) == 0) - { - const double sec = (clock() - clock_start) / CLOCKS_PER_SEC; - if (sec > 0.0) - { - TString80 msg; - msg.format(FR("%ld records at %ld rec/sec"), step, long(step/sec)); - pi.set_text(msg); - } - } -#endif - } - } - else - { - for (long n = last_con; n > 0; n = _mastrino.pred(n, riga_contropartita)) - { - _mastrino.collapse(n); - pi.set_status(total - n + 1); - } - } - - update(); - } -} - -void TMastrini_grid::on_record_button(long rec) -{ - if (!_primanoting) - { - _primanoting = true; - const TRectype& testata = _mastrino.testata(rec); - testata.edit(); - if (yesno_box(TR("Si desidera aggiornare il mastrino?"))) - reread(); - _primanoting = false; - } -} - -// Posso ridimensionare solo le descrizioni, le altre devono rimanere fisse per -// non perdere la formattazione su due righe -bool TMastrini_grid::on_resize_column(short cid, int new_size) -{ - return cid == 103 || cid == 104; -} - - -void TMastrini_grid::read(const TBill& conto, - int annoes, const TDate& dd, const TDate& ad, - const TString& dc, const TString& ac, bool provv) -{ - destroy(); - _mastrino.read(conto, annoes, dd, ad, dc, ac, provv); - update(); - update_mask(); -} - -void TMastrini_grid::reread() -{ - destroy(); - _mastrino.reread(); - update(); - update_mask(); -} - -void TMastrini_grid::update_mask() const -{ - TMask& gm = mask(); - - gm.set(F_ESERCIZIO, _mastrino.esercizio()); - gm.set(F_DADATA, _mastrino.inizio_periodo()); - gm.set(F_ADATA, _mastrino.fine_periodo()); - - set_imp(gm.field(F_TOTPRO_SAL), _mastrino.saldo_iniziale()); - gm.set(F_TOTPRO_DAR, _mastrino.progressivo_dare_iniziale()); - gm.set(F_TOTPRO_AVE, _mastrino.progressivo_avere_iniziale()); - - gm.reset(F_TOTRIG_SAL); - gm.reset(F_TOTRIG_DAR); - gm.reset(F_TOTRIG_AVE); - - set_imp(gm.field(F_TOTPER_SAL), _mastrino.saldo_periodo()); - gm.set(F_TOTPER_DAR, _mastrino.progressivo_dare_periodo()); - gm.set(F_TOTPER_AVE, _mastrino.progressivo_avere_periodo()); - - set_imp(gm.field(F_TOTATT_SAL), _mastrino.saldo_finale()); - gm.set(F_TOTATT_DAR, _mastrino.progressivo_dare_finale()); - gm.set(F_TOTATT_AVE, _mastrino.progressivo_avere_finale()); - - const bool can_link = main_app().argc() <= 2; // NON sono stato chiamato dalla prima nota - gm.enable(DLG_LINK, can_link && _mastrino.items() > 0); - gm.enable(DLG_NEWREC, can_link); -} - -void TMastrini_grid::load_colors() -{ - _colmsk.get_colors(_mas_back, _mas_fore, _con_back, _con_fore); -} - -void TMastrini_grid::set_colors() -{ - if (_colmsk.run() == K_ENTER) - load_colors(); -} - -/////////////////////////////////////////////////////////// -// TMastrino_set -/////////////////////////////////////////////////////////// - -class TMastrino_set : public TRecordset -{ - TMastrini_grid& _grid; - long _curr; - TArray _info; - -protected: - void add_field(TFieldtypes t, short id, int width, const char* name = NULL); - long cell_request(long rec, short column, TString& str) const; - const TString& query_text() const { return EMPTY_STRING; } - -public: - virtual TRecnotype items() const { return _grid.items(); } - virtual unsigned int columns() const { return _info.items(); } - virtual const TRecordset_column_info& column_info(unsigned int column) const; - virtual bool move_to(TRecnotype n); - virtual TRecnotype current_row() const { return _curr; } - virtual void requery() {} - virtual const TVariant& get(unsigned int column) const; - - TMastrino_set(TMastrini_grid& g); -}; - -const TRecordset_column_info& TMastrino_set::column_info(unsigned int column) const -{ - return (const TRecordset_column_info&)_info[column]; -} - -bool TMastrino_set::move_to(TRecnotype n) -{ - const bool ok = n >= 0 && n < items(); - _curr = n; - return ok; -} - -long TMastrino_set::cell_request(long rec, short column, TString& str) const -{ - XI_EVENT xiev; memset(&xiev, 0, sizeof(xiev)); - xiev.type = XIE_CELL_REQUEST; - xiev.v.cell_request.s = str.get_buffer(); - xiev.v.cell_request.len = str.size(); - TGrid_cell cell(&xiev); - _grid.cell_request(rec, column, cell); - return xiev.v.cell_request.attrib; -} - - -const TVariant& TMastrino_set::get(unsigned int column) const -{ - if (_curr >= 0 && _curr < items() && column >= 0 && column < columns()) - { - const TRecordset_column_info& info = column_info(column); - - TToken_string str; - cell_request(_curr, abs(info._pos), str); - if (str.full()) - { - //decide se il campo appartiene ad una sottocella (es. numdoc / prot) - bool divide = info._pos < 0; //è la prima parte di una sottocella - if (!divide && column < columns()-1) - divide = column_info(column+1)._pos < 0; //è la seconda parte di una sottocella - //se deve splittare cerca lo spazio come carattere di separazione tra le sottocelle - if (divide) - { - const int cr = str.find(' '); - if (cr >= 0) - { - if (info._pos > 0) - str.cut(cr); - else - str.ltrim(cr); - str.trim(); - } - } - - TVariant& tmp = get_tmp_var(); - switch (info._type) - { - case _realfld: - tmp = real(real::ita2eng(str)); - break; - case _longfld: - tmp = atol(str); - break; - case _datefld: - tmp = TDate(str); - break; - default: - if (info._width == 1) - tmp = str.right(1); - else - tmp = str; - break; - } - return tmp; - } - } - return NULL_VARIANT; -} - -void TMastrino_set::add_field(TFieldtypes tipo, short id, int width, const char* name) -{ - TRecordset_column_info* i = new TRecordset_column_info; - - TString& n = i->_name; - - if (name && *name) - n = name; - else - { - cell_request(-1, abs(id), n); - const int cr = n.find('\n'); - if (cr > 0) - { - if (id > 0) - n.cut(cr); - else - n.ltrim(cr+1); - n.trim(); - } - } - - i->_type = tipo; - i->_pos = id; - i->_width = width; - - _info.add(i); -} - -TMastrino_set::TMastrino_set(TMastrini_grid& g) - : _grid(g), _curr(-1) -{ - _grid.mastrino().collapse(-1);// Nascondo tutte le righe di contropartita - - add_field(_datefld, 101, 10); // Data reg - add_field(_datefld,-101, 10); // Data comp - add_field(_alfafld, 102, 1); // Movimento di competenza? - add_field(_alfafld, 103, 25); // Causale - add_field(_alfafld, 104, 50); // Descrizione - add_field(_realfld, 105, 13); // Dare - add_field(_realfld, 106, 13); // Avere - add_field(_alfafld, 107, 7); // Num doc - add_field(_longfld,-107, 7); // Num prot - add_field(_realfld, 108, 13); // Saldo - add_field(_alfafld,-108, 1, "Sezione"); // Sezione - add_field(_realfld, 109, 13); // Saldo giornaliero - add_field(_alfafld,-109, 1, "Sezione"); // Sezione giornaliera - - const bool show_cms = main_app().has_module(CMAUT) || main_app().has_module(CAAUT); - if (show_cms) - add_field(_alfafld, 110, 40); // Commessa -} - -/////////////////////////////////////////////////////////// -// TGrid_mask -/////////////////////////////////////////////////////////// - -class TGrid_mask : public TMask -{ - TMastrini_grid* _grid; - -protected: // TMask - virtual TMask_field* parse_field(TScanner& sc); - virtual bool on_key(KEY k); - virtual long handler(WINDOW win, EVENT* ep); - - static bool link_handler(TMask_field& f, KEY k); - static bool new_handler(TMask_field& f, KEY k); - //static bool edit_handler(TMask_field& f, KEY k); - static bool export_handler(TMask_field& f, KEY k); - static bool saldac_handler(TMask_field& f, KEY k); - -public: - TMastrini_grid& grid() { CHECK(_grid, "What's grid?"); return *_grid; } - - TGrid_mask(); - virtual ~TGrid_mask() { } -}; - -TGrid_mask::TGrid_mask() - : _grid(NULL) -{ - read_mask("cg3600b", 0, 0); - set_handler(DLG_LINK, link_handler); - set_handler(DLG_NEWREC, new_handler); - //set_handler(DLG_EDIT, edit_handler); - set_handler(DLG_EXPORT, export_handler); - set_handler(DLG_USER, saldac_handler); // implemented in cg3601.cpp - - const bool show_cms = main_app().has_module(CMAUT) || main_app().has_module(CAAUT); - if (!show_cms) - _grid->grid().show_column(1110, false); // Nasconde la commessa -} - -TMask_field* TGrid_mask::parse_field(TScanner& sc) -{ - TMask_field* f; - if (sc.key() == "SP") - f = _grid = new TMastrini_grid(this); - else - f = TMask::parse_field(sc); - return f; -} - -bool TGrid_mask::link_handler(TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - TGrid_mask& gm = (TGrid_mask&)f.mask(); - TMastrini_grid& grid = gm.grid(); - const long rec = grid.selected(); - if (rec >= 0 && rec < grid.items()) - grid.on_record_button(rec); - } - return true; -} - -bool TGrid_mask::new_handler(TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - TExternal_app app("cg2 -0"); - const bool refresh = app.run() == 0; - if (refresh && yesno_box(TR("Si desidera aggiornare il mastrino?"))) - { - TGrid_mask& gm = (TGrid_mask&)f.mask(); - TMastrini_grid& grid = gm.grid(); - grid.reread(); - } - } - return true; -} - -/* Useless -bool TGrid_mask::edit_handler(TMask_field& f, KEY k) -{ - bool ok = true; - if (k == K_SPACE) - { - TGrid_mask& gm = (TGrid_mask&)f.mask(); - TMastrini_grid& grid = gm.grid(); - TMastrino_set ms(grid); - - TFilename n; n.tempdir(); n.add("mastrino.xls"); - ms.save_as(n); - ok = xvt_sys_goto_url(n, "open") != FALSE; - if (!ok) - ok = export_handler(f, k); // Se non parte Excel salvo altrove - } - return ok; -}*/ - -bool TGrid_mask::export_handler(TMask_field& f, KEY k) -{ - bool ok = true; - if (k == K_SPACE) - { - TFilename n; n.tempdir(); n.add("mastrino.xls"); - FILE_SPEC fs; xvt_fsys_convert_str_to_fspec(n, &fs); - if (xvt_dm_post_file_save(&fs, f.prompt()) == FL_OK) - { - xvt_fsys_convert_fspec_to_str(&fs, n.get_buffer(), n.size()); - TGrid_mask& gm = (TGrid_mask&)f.mask(); - TMastrini_grid& grid = gm.grid(); - TMastrino_set ms(grid); - ms.save_as(n); - } - } - return ok; -} - -bool TGrid_mask::saldac_handler(TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - TBill zio; zio.get(f.mask(), F_GRUPPO, F_CONTO, F_SOTTOCONTO); - popup_games(zio); - } - return true; -} - -bool TGrid_mask::on_key(KEY k) -{ - switch (k) - { - case K_ENTER: - case K_CTRL+'+': - case K_CTRL+'-': - if (focus_field().dlg() == _grid->dlg()) - { - const long rec = grid().selected(); - _grid->on_dbl_cell(rec, DLG_USER); - } - break; - default: - break; - } - - return TMask::on_key(k); -} - -long TGrid_mask::handler(WINDOW win, EVENT* ep) -{ - static TGrid_field* _last_grid = NULL; - - if (ep->type == E_MOUSE_DOWN && ep->v.mouse.button == 1) - { - _last_grid = NULL; - - RCT rct; _grid->get_rect(rct); - if (xvt_rect_has_point(&rct, ep->v.mouse.where)) - _last_grid = _grid; - - if (_last_grid) - { - //TGrid_field& sht = (TGrid_field&)*_last_grid; - MENU_ITEM* menu = xvt_res_get_menu(BROWSE_BAR); - - if (menu != NULL) - { - const PNT& p = ep->v.mouse.where; - xvt_menu_popup(menu->child, win, p, XVT_POPUP_CENTER, 0); - xvt_res_free_menu_tree(menu); - } - return 0L; - } - } - if (ep->type == E_COMMAND) - { - if (_last_grid) - { - switch (ep->v.cmd.tag) - { - case BROWSE_BAR+1: _last_grid->save_columns_order(); break; - case BROWSE_BAR+2: _last_grid->reset_columns_order(); break; - case BROWSE_BAR+3: _last_grid->on_key(K_F11); break; - default: break; - } - return 0L; - } - } - return TMask::handler(win, ep); -} - -/////////////////////////////////////////////////////////// -// TQuery_mask -/////////////////////////////////////////////////////////// - -bool TQuery_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) -{ - switch (o.dlg()) - { - case F_TIPO: - if (e == fe_modify) - { - const TString& tipo = o.get(); - - if (tipo != _last_tipo) - { - _last_tipo = tipo; - if (tipo.full()) - { - // Controllo se il mastro corrente è già compatibile col tipo C/F - if (!field(F_CONTO).empty()) - { - TString8 key; key.format("%d|%d", get_int(F_GRUPPO), get_int(F_CONTO)); - const TString& tmcf = cache().get(LF_PCON, key, PCN_TMCF); - if (tmcf == tipo) - return true; - } - // Cerco il primo mastro conforme al tipo C/F selezionato - TWait_cursor hourglass; - TString80 query; - query << "USE " << LF_PCON << " SELECT " << PCN_TMCF << "=\"" << tipo << "\""; - TISAM_recordset conti(query); - if (conti.move_first()) - { - set(F_GRUPPO, conti.get(PCN_GRUPPO).as_int(), 0x2); - set(F_CONTO, conti.get(PCN_CONTO).as_int(), 0x2); - } - } - } - } - break; - case F_CLIENTE: - case F_FORNITORE: - if (e == fe_modify && !o.empty()) - { - const TRectype& rec = ((TEdit_field&)o).browse()->cursor()->curr(); - const int g = rec.get_int(CLI_GRUPPO); - const int c = rec.get_int(CLI_CONTO); - if (g > 0 && c > 0) - { - set(F_GRUPPO, g, 0x2); - set(F_CONTO, c, 0x2); - } - } - break; - case F_ESERCIZIO: - if (e == fe_modify || e == fe_close) - { - TEsercizi_contabili esc; - const int anno = atoi(o.get()); - if (esc.exist(anno)) - { - TDate dd = get(F_DADATA); - if (esc.date2esc(dd) != anno) - set(F_DADATA, esc[anno].inizio()); - dd = get(F_ADATA); - if (esc.date2esc(dd) != anno) - set(F_ADATA, esc[anno].fine()); - } - else - { - if (anno > 0) - return error_box(FR("Esercizio inesistente: %d"), anno); - } - } - break; - case F_DADATA: - case F_ADATA: - if (e == fe_close) - { - const TEsercizi_contabili esercizi; - int codice_esercizio = get_int(F_ESERCIZIO); - if (codice_esercizio <= 0) - { - const short id_altra_data = o.dlg() == F_DADATA ? F_ADATA : F_DADATA; - const TDate d = get(id_altra_data); - if (d.ok()) - codice_esercizio = esercizi.date2esc(d); - } - - if (o.empty()) - { - if (codice_esercizio == 0) - return error_box(TR("E' necessario specificare almeno una data.")); - return true; - } - - const TDate d = o.get(); - const int esercizio = esercizi.date2esc(d); - if (get_int(F_ESERCIZIO) != 0) - { - if (esercizio != codice_esercizio) - return error_box(FR("La data deve appartenere all'esercizio %d"), codice_esercizio); - } - else - { - if (esercizio == 0) - return error_box(TR("La data deve appartenere ad un esercizio contabile")); - } - } - break; - case DLG_FINDREC: - if (e == fe_button) - { - short id; - switch (get(F_TIPO)[0]) - { - case 'C': id = F_CLIENTE; break; - case 'F': id = F_FORNITORE; break; - default : id = F_SOTTOCONTO; break; - } - field(id).on_key(K_F9); - } - break; - case DLG_CONFIG: - if (e == fe_button) - _gm->grid().set_colors(); - break; - default: - break; - } - - return true; -} - -TQuery_mask::TQuery_mask(TGrid_mask* gm) : TAutomask("cg3600a"), _gm(gm), _last_tipo("") -{ } - -void TQuery_mask::do_query() -{ - const char t = get(F_TIPO)[0]; - const int g = get_int(F_GRUPPO); - const int c = get_int(F_CONTO); - const long s = get_long((t <= ' ') ? F_SOTTOCONTO : ((t == 'C') ? F_CLIENTE : F_FORNITORE)); - const TBill conto(g, c, s, t); - - const int annoes = get_int(F_ESERCIZIO); - const TDate da_data(get(F_DADATA)); - const TDate a_data(get(F_ADATA)); - - const TString& da_caus = get(F_DACAUSALE); - const TString& a_caus = get(F_ACAUSALE); - const bool provv = get_bool(F_PROVVIS); - - conto.set(*_gm, F_GRUPPO, F_CONTO, F_SOTTOCONTO, 0, F_DESSOTTOC); - TMastrini_grid& gf = _gm->grid(); - -#ifdef CONT_SEP - gf.set_contsep(get_bool(F_ST_CONTSEP)); -#endif - gf.read(conto, annoes, da_data, a_data, da_caus, a_caus, provv); - gf.select(get_bool(F_END) ? gf.items() -1 : 0); - - _gm->run(); -} - -/////////////////////////////////////////////////////////// -// TMastrini_video -/////////////////////////////////////////////////////////// - -bool TMastrini_video::create() -{ - xvtil_statbar_set("", TRUE); - open_files(LF_CAUSALI, LF_MOV, LF_PCON, LF_RMOV, LF_SALDI, 0); - if (has_module(CMAUT)) - open_files(LF_MOVANA, LF_RMOVANA, 0); - - _gm = new TGrid_mask; - _qm = new TQuery_mask(_gm); - - return TSkeleton_application::create(); -} - -bool TMastrini_video::destroy() -{ - delete _qm; - delete _gm; - return TSkeleton_application::destroy(); -} - -void TMastrini_video::main_loop() -{ - TQuery_mask& qm = *_qm; - - if (argc() > 2) - { - TFilename ininame = argv(2)+2; - if (ininame.exist()) - { - TConfig ini(ininame, "24"); - qm.set(F_ESERCIZIO, ini.get(RMV_ANNOES)); - qm.set(F_TIPO, ini.get(RMV_TIPOC)); - qm.set(F_GRUPPO, ini.get(RMV_GRUPPO)); - qm.set(F_CONTO, ini.get(RMV_CONTO)); - qm.set(F_SOTTOCONTO, ini.get(RMV_SOTTOCONTO)); - qm.set(F_CLIENTE, ini.get(RMV_SOTTOCONTO)); - qm.set(F_FORNITORE, ini.get(RMV_SOTTOCONTO)); - qm.send_key(K_SPACE, DLG_OK); - } - } - - const TEsercizi_contabili esercizi; - TDate inies, fines; - int codesc = qm.get_int(F_ESERCIZIO); - if (!esercizi.exist(codesc)) - codesc = esercizi.last(); - esercizi.code2range(codesc, inies, fines); - qm.set(F_ESERCIZIO, codesc); - qm.set(F_DADATA, inies); - qm.set(F_ADATA, fines); - - while (qm.run() == K_ENTER) - qm.do_query(); -} - -/////////////////////////////////////////////////////////// -// Main -/////////////////////////////////////////////////////////// - -int cg3600(int argc, char* argv[]) -{ - TMastrini_video mv; - mv.run(argc, argv, TR("Mastrini")); - return 0; -} +#include + +#include "cg3.h" +#include "cglib02.h" +#include "cg3600.h" +#include "cg3601.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "../ca/movana.h" +#include "../ca/rmovana.h" + +class TGrid_mask; + +class TQuery_mask : public TAutomask +{ + TGrid_mask* _gm; + TString4 _last_tipo; + +protected: + virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); + +public: + void do_query(); + + TQuery_mask(TGrid_mask* gm); + virtual ~TQuery_mask() { } +}; + + +class TMastrini_video : public TSkeleton_application +{ + TQuery_mask* _qm; + TGrid_mask* _gm; + +protected: + virtual bool create(); + virtual void main_loop(); + virtual bool destroy(); + +public: + TQuery_mask & query_mask() { return *_qm; } + +}; +HIDDEN inline TMastrini_video& app() +{ return (TMastrini_video&)main_app();} + +/////////////////////////////////////////////////////////// +// TList +/////////////////////////////////////////////////////////// + +class TList : public TContainer +{ + TArray _data; + +protected: + // @cmember Ritorna un puntatore al primo oggetto del contenitore + virtual TObject* first_item( ) { return _data.first_item(); } + // @cmember Ritorna un puntatore all'ultimo oggetto del contenitore + virtual TObject* last_item( ) { return _data.last_item(); } + // @cmember Ritorna un puntatore all'oggetto successivo all'oggetto corrente + virtual TObject* succ_item( ) { return _data.succ_item(); } + // @cmember Ritorna un puntatore all'oggetto che precede l'oggetto corrente + virtual TObject* pred_item( ) { return _data.pred_item(); } + // @cmember Ritorna il numero di oggetti nel contenitore + virtual long objects( ) const { return _data.objects(); } + +public: + long items() const { return _data.items(); } + void destroy() { _data.destroy(); } + long insert(TObject* obj, long pos) { return _data.insert(obj, pos); } + long append(TObject* obj, long pos = -1); + bool remove(long pos) { _data.remove(pos, true); return true; } + + const TObject& obj(long index) const + { const TObject* o = _data.objptr(index); CHECK(o, "Null list item"); return *o; } +}; + +long TList::append(TObject* obj, long index) +{ + if (index < 0 || index >= items()) + index = items(); + else + index++; + return insert(obj, index); +} + +/////////////////////////////////////////////////////////// +// TMastrino +/////////////////////////////////////////////////////////// + +enum tipo_riga_mastrino { riga_mastrino, riga_contropartita }; + +class TRiga_mastrino : public TObject +{ + tipo_riga_mastrino _type; // Tipo della riga + TRecnotype _mov, _rmov; // Numero fisico di record movimento e riga movimento + real _dare, _avere; // Progressivi dare ed avere + TDate _data; // Data di registrazione (Ottimizzazione) + +public: + tipo_riga_mastrino tipo() const { return _type; } + TRecnotype rmov() const { return _rmov; } + TRecnotype mov() const { return _mov; } + + const TDate& data() const { return _data; } + const real& dare() const { return _dare; } + const real& avere() const { return _avere; } + TImporto saldo() const; // Dare-Avere normalizzato + + TRiga_mastrino(tipo_riga_mastrino trig, + TRecnotype rmov, TRecnotype mov, + const real& d, const real& a, + const TDate& datareg); + virtual ~TRiga_mastrino() { } +}; + +TRiga_mastrino::TRiga_mastrino(tipo_riga_mastrino trig, + TRecnotype rmov, TRecnotype mov, + const real& d, const real& a, + const TDate& datareg) + : _type(trig), _rmov(rmov), _mov(mov), + _dare(d), _avere(a), _data(datareg) +{ } + +TImporto TRiga_mastrino::saldo() const +{ + TImporto imp('D', _dare - _avere); + imp.normalize(); + return imp; +} + +class TMastrino : public TObject +{ + static long _instances; + static TCursor* _cur; + static TRelation* _rel; + static TLocalisamfile *_rmov; // File principale della relazione + static TLocalisamfile *_mov; // File secondario della relazione + + TBill _conto; // Conto del mastrino + int _esercizio; // Esercizio di riferimento (eventualmente 0) + TDate _da_data, _a_data; // Date limite + TString _da_caus, _a_caus; // Causali limite + bool _provvis; // Includi provvisori + + real _pdare_ini, _pavere_ini; + real _pdare_per, _pavere_per; + real _pdare_fin, _pavere_fin; + + TList _riga; // Righe del mastrino + +protected: + TCursor& cur() { return *_cur; } + TRelation& rel() { return *_rel; } + TLocalisamfile& rmov() { return *_rmov; } + TLocalisamfile& mov() { return *_mov; } + + void position_rel(long n); + TRiga_mastrino& row(long n) const { return (TRiga_mastrino&)_riga.obj(n); } + +public: + long items() const { return _riga.items(); } + + void read(const TBill& conto, + int annoes, const TDate& dd, const TDate& ad, + const TString& dc, const TString& ac, bool provvis); + void reread(); + + TRiga_mastrino& operator[](long n) const { return row(n); } + const TRectype& riga(long n); + const TRectype& testata(long n); + + long first(tipo_riga_mastrino tipo = riga_mastrino) const; + long pred(long rec, tipo_riga_mastrino tipo = riga_mastrino) const; + long succ(long rec, tipo_riga_mastrino tipo = riga_mastrino) const; + long last(tipo_riga_mastrino tipo = riga_mastrino) const; + + void destroy() { _riga.destroy(); } + + const real& progressivo_dare_iniziale() const { return _pdare_ini; } + const real& progressivo_avere_iniziale() const { return _pavere_ini; } + TImporto saldo_iniziale() const; + + const real& progressivo_dare_finale() const { return _pdare_fin; } + const real& progressivo_avere_finale() const { return _pavere_fin; } + TImporto saldo_finale() const; + + real progressivo_dare_periodo() const { return _pdare_ini + _pdare_per; } + real progressivo_avere_periodo() const { return _pavere_ini + _pavere_per; } + TImporto saldo_periodo() const; + + const TBill& conto() const { return _conto; } + int esercizio() const { return _esercizio; } + const TDate& inizio_periodo() const { return _da_data; } + const TDate& fine_periodo() const { return _a_data; } + void periodo(TDate& dd, TDate& ad) const { dd = _da_data; ad = _a_data; } + + bool expandable(long rec) const; + bool expand(long rec); + bool collapse(long rec); + + TMastrino(); + virtual ~TMastrino(); +}; + +long TMastrino::_instances = 0L; +TCursor* TMastrino::_cur = NULL; +TRelation* TMastrino::_rel = NULL; +TLocalisamfile* TMastrino::_rmov = NULL; // File principale della relazione +TLocalisamfile* TMastrino::_mov = NULL; // File secondario della relazione + +TMastrino::TMastrino() : _esercizio(0) +{ + if (_instances == 0L) + { + _rel = new TRelation(LF_RMOV); + _rel->add(LF_MOV, "NUMREG==NUMREG"); + _rmov = &_rel->lfile(); + _mov = &_rel->lfile(LF_MOV); + } + _instances++; +} + +TMastrino::~TMastrino() +{ + _instances--; + if (_instances == 0L) + { + delete _cur; _cur = NULL; + delete _rel; _rel = NULL; + _rmov = _mov = NULL; + } +} + +long TMastrino::succ(long rec, tipo_riga_mastrino tipo) const +{ + if (rec < 0) + rec = -1; + + const long ul = items(); + long i; + + for (i = rec+1; i < ul; i++) + { + if (row(i).tipo() == tipo) + break; + } + return i; +} + +long TMastrino::pred(long rec, tipo_riga_mastrino tipo) const +{ + if (rec > items()) rec = items(); + long i; + for (i = rec-1; i >= 0; i--) + { + if (row(i).tipo() == tipo) + break; + } + return i; +} + +long TMastrino::first(tipo_riga_mastrino tipo) const +{ + return succ(-1, tipo); +} + +long TMastrino::last(tipo_riga_mastrino tipo) const +{ + return pred(items(), tipo); +} + +void TMastrino::read(const TBill& conto, + int ae, const TDate& dd, const TDate& ad, + const TString& dc, const TString& ac, + bool provvis) +{ + TEsercizi_contabili esercizi; + + _conto = conto; + _esercizio = ae; + + _riga.destroy(); + + rmov().setkey(2); + TRectype& rmov_rec = rmov().curr(); + TRectype& mov_rec = mov().curr(); + + if (ae <= 0) + { + if (dd.ok()) + ae = esercizi.date2esc(dd); + else + ae = esercizi.date2esc(ad); + } + CHECKD(esercizi.exist(ae), "Anno di esercizio fantasioso: ", ae); + + const TDate& inizio_esercizio = esercizi[ae].inizio(); + _da_data = dd.ok() ? dd : inizio_esercizio; + _a_data = ad.ok() ? ad : esercizi[ae].fine(); + + const bool test_caus = !(dc.blank() && ac.blank()); + _da_caus = dc; + _a_caus = ac.blank() ? "zzz" : ac; // Se vuota sceglie la massima causale + _provvis = provvis; + + TDate max_data_reg = _a_data; + long num_giorni = _a_data - inizio_esercizio + 1; + if (_esercizio > 0) + { + const int succ = esercizi.next(ae); + if (succ > 0) + { + max_data_reg = esercizi[succ].fine(); + num_giorni += 30; + } + else + max_data_reg = esercizi[ae].fine(); + } + + // Valori dei saldi fino alla data di inizio stampa: + // Vengono inizializzati con i saldi iniziali dell'esercizio, + // poi verranno sommati gli importi dei movimenti che + // vanno dall'inizio dell'esercizio al giorno precedente + // la data di inizio stampa + + TBalance saldo(_conto, ae, true, provvis); + _pdare_ini = saldo.progressivo_dare_iniziale(); + _pavere_ini = saldo.progressivo_avere_iniziale(); + + // Valori dei saldi finali: + // Comprendono i movimenti di apertura, chiusura ed i progressivi attuali + saldo.read(_conto, ae, false, provvis); + _pdare_fin = saldo.progressivo_dare_finale(); + _pavere_fin = saldo.progressivo_avere_finale(); + + // Valori dei saldi del perido in esame: + // Vengono inizializzati a zero e poi si incrementa man mano + // coi valori degli importi dei movimenti compresi nei + // limiti della stampa + _pdare_per = _pavere_per = ZERO; + + const TRecfield rmov_datareg (rmov_rec, RMV_DATAREG); + const TRecfield rmov_numreg (rmov_rec, RMV_NUMREG); + const TRecfield rmov_gruppo (rmov_rec, RMV_GRUPPO); + const TRecfield rmov_conto (rmov_rec, RMV_CONTO); + const TRecfield rmov_sottoconto(rmov_rec, RMV_SOTTOCONTO); + const TRecfield rmov_sezione (rmov_rec, RMV_SEZIONE); + const TRecfield rmov_importo (rmov_rec, RMV_IMPORTO); + + const TRecfield mov_datacomp (mov_rec, MOV_DATACOMP); + const TRecfield mov_provvis (mov_rec, MOV_PROVVIS); + const TRecfield mov_codcaus (mov_rec, MOV_CODCAUS); + +#ifdef DBG + long num_rec = 0; + const clock_t clock_start = clock(); +#endif + + rmov_rec.zero(); + conto.put(rmov_rec); + TRectype darow(rmov_rec), arow(rmov_rec); + darow.put(RMV_DATAREG, inizio_esercizio); + arow.put(RMV_DATAREG, max_data_reg); + TCursor cur(&rel(), "", 2, &darow, &arow); + const TRecnotype totrows = cur.items(); + cur.freeze(); + + TString caption(80); + caption.format(FR("Caricamento mastrino %03d.%03d.%06ld"), + _conto.gruppo(), _conto.conto(), _conto.sottoconto()); + TProgind pi(totrows, caption, false, true); + + for (cur = 0L; cur.pos() < totrows; ++cur) + { + pi.addstatus(1); +#ifdef DBG + num_rec++; + if ((num_rec & 0x7F) == 0) + { + const double sec = (clock() - clock_start) / CLOCKS_PER_SEC; + if (sec > 0.0) + { + TString80 msg; + msg.format("%ld records at %ld rec/sec", num_rec, long(num_rec/sec)); + pi.set_text(msg); + } + } +#endif + + // Ignora eventualmente i movimenti provvisori + if (!_provvis) + { + const char is_provvis = *(const char*)mov_provvis; + if (is_provvis > ' ') + continue; + } + + const TDate data_corrente = _esercizio <= 0 ? rmov_datareg : TDate((const char*)mov_datacomp); + if (data_corrente > _a_data) + continue; + + const char sezione = *((const char*)rmov_sezione); + const real importo((const char*)rmov_importo); + + if (data_corrente < _da_data) + { + if (data_corrente >= inizio_esercizio) + { + if (sezione == 'D') + _pdare_ini += importo; + else + _pavere_ini += importo; + } + } + else + { + if (sezione == 'D') + _pdare_per += importo; + else + _pavere_per += importo; + + // Controlla che la causale sia nei limiti + if (test_caus) + { + const bool ok = _da_caus <= mov_codcaus && _a_caus >= mov_codcaus; + if (!ok) + continue; + } + + TRiga_mastrino* r = new TRiga_mastrino(riga_mastrino, + rmov().recno(), mov().recno(), + _pdare_per, _pavere_per, rmov_datareg); + _riga.append(r); + } + } + + // Mi sposto all'inizio per far funzionare bene da subito il metodo riga(0) + mov().first(); + rmov().first(); +} + +void TMastrino::reread() +{ + read(_conto, _esercizio, _da_data, _a_data, _da_caus, _a_caus, _provvis); +} + +void TMastrino::position_rel(long n) +{ + const TRiga_mastrino& r = row(n); + if (rmov().recno() != r.rmov()) + rmov().readat(r.rmov()); + if (mov().recno() != r.mov()) + mov().readat(r.mov()); +} + +const TRectype& TMastrino::riga(long n) +{ + position_rel(n); + return rmov().curr(); +} + +const TRectype& TMastrino::testata(long n) +{ + position_rel(n); + return mov().curr(); +} + +TImporto TMastrino::saldo_iniziale() const +{ + TImporto s('D', _pdare_ini - _pavere_ini); + return s.normalize(); +} + +TImporto TMastrino::saldo_finale() const +{ + TImporto s('D', _pdare_fin - _pavere_fin); + return s.normalize(); +} + +TImporto TMastrino::saldo_periodo() const +{ + TImporto s('D', progressivo_dare_periodo() - progressivo_avere_periodo()); + return s.normalize(); +} + +bool TMastrino::expandable(long rec) const +{ + bool e = false; + if (rec >= 0 && rec < items()) + { + if (row(rec).tipo() == riga_mastrino) + { + if (rec < items()-1) + e = row(rec+1).tipo() != riga_contropartita; + else + e = true; + } + } + return e; +} + +// Genera le righe di contropartita di una riga del mastrino +bool TMastrino::expand(long rec) +{ + bool ok = expandable(rec); + if (ok) + { + const TRectype& head = testata(rec); // Testata movimento + const long numreg = head.get_long(RMV_NUMREG); // Numero di registrazione + const int numrig = riga(rec).get_int(RMV_NUMRIG); // Numero riga contabile + const TDate datareg = head.get(MOV_DATAREG); // Data di registrazione + + rmov().setkey(1); // Usa chiave NUMREG+NUMRIG + TRectype& curr = rmov().curr(); // Record corrente + + const TRecfield rnumreg (curr, RMV_NUMREG); // Numero di registrazione corrente + const TRecfield rnumrig (curr, RMV_NUMRIG); // Numero di riga corrente + const TRecfield rsezione(curr, RMV_SEZIONE); // Sezione Dare/Avere + const TRecfield rimporto(curr, RMV_IMPORTO); // Importo della riga + + int err = NOERR; + if (numrig != 1) // Se non e' gia' posizionato grazie a riga(rec) + { + curr.zero(); // Azzera record corrente + curr.put(RMV_NUMREG, numreg); // Inizializza la chiave parziale + err = rmov().read(_isgteq); // Cerca la prima riga del movimento + } + for (; err == NOERR; err = rmov().next()) // Scandisce righe movimento + { + if (numreg != (long)rnumreg) // Controlla validita' numero + break; + + if (numrig != (int)rnumrig) // Ignora la riga gia' presente + { + real dare, avere; // Costruisce importo della riga + if (*(const char*)rsezione == 'D') + dare = rimporto; + else + avere = rimporto; + // Aggiunge una riga di contropartita al mastrino + TRiga_mastrino* r = new TRiga_mastrino(riga_contropartita, + rmov().recno(), mov().recno(), + dare, avere, datareg); + _riga.append(r, rec++); + } + } + } + return ok; +} + +// Elimina le righe di contropartita di una riga del mastrino +bool TMastrino::collapse(long rec) +{ + bool ok = true; // Posso eliminare? + + if (rec < 0) + { + for (long i = last(); i >= 0; i = pred(i)) + collapse(i); + } + else + { + if (row(rec).tipo() != riga_mastrino) // Se non sono su una riga mastrino ... + rec = pred(rec, riga_mastrino); // ... mi sposto sulla precedente riga mastrino + ok = !expandable(rec); // Controlla che sia possibile + if (ok) // Posso effetivamente procedere + { + rec++; // Elimino ogni riga contropartita successiva + while (rec < items() && row(rec).tipo() != riga_mastrino) + _riga.remove(rec); + } + } + + return ok; +} + +/////////////////////////////////////////////////////////// +// TGrid_control +/////////////////////////////////////////////////////////// + +class TGrid_control; + +class TGrid_cell : public TFixed_string +{ + XI_EVENT* _xiev; + +public: + TString& set(const char* txt); + TString& set(long num); + void set_icon(int id); + void show_button(bool on = true); + void hide_button() { show_button(false); } + void set_back_color(COLOR col); + void set_fore_color(COLOR col); + void set_colors(COLOR back, COLOR fore); + + short get_column() const { return _xiev->v.cell_request.col_nbr; } + + TString& operator = (const char* str) { return set(str); } + TString& operator = (const TString& str) { return set(str); } + + XI_EVENT* event() { return _xiev; } + + TGrid_cell(XI_EVENT* xiev); + virtual ~TGrid_cell() { } +}; + +class TGrid_field : public TOperable_field +{ +protected: // TMask_field + virtual void create(WINDOW parent); + virtual void parse_head(TScanner& scanner); + virtual bool parse_item(TScanner& scanner); + virtual word class_id() const; + +public: + TGrid_control& grid() const { return (TGrid_control&)*_ctl; } + + virtual bool handler(XI_EVENT* xiev); + virtual long items() const; + virtual void cell_request(long rec, short id, TGrid_cell& cell); + + virtual bool on_record(long rec) { return true; } + virtual bool off_record(long rec) { return true; } + virtual bool on_resize_column(short cid, int new_size) { return true; } + virtual void on_dbl_cell(long rec, short id) { } + virtual void on_grid_button() { } + virtual void on_record_button(long rec) { } + virtual void on_cell_button(long rec, short cid) { } + + long selected() const; + void update(long n = -1); + int visible_rows() const; + bool select(long rec); + + void reset_columns_order(); + void save_columns_order() const; + + TGrid_field(TMask* m); + virtual ~TGrid_field() { } +}; + +class TGrid_control : public TControl +{ + enum grid_control_constants { MAX_COL = 64 }; + + long _cur_rec; + bool _read_only; + + // @cmember:(INTERNAL) Tipo di ogni colonna + byte _type[MAX_COL]; + + TGrid_field* _grid; + + int _default_width[MAX_COL]; + int _columns_order; + +protected: // TControl + //@cmember Gestisce gli eventi delle celle + virtual bool event_handler(XI_OBJ* itf, XI_EVENT* xiev); + + //@cmember Chiama gli handlers opportuni per verificare il cambio record + bool try_to_select(long rec) const; + +protected: + //@cmember Ritorna il numero totale di righe + long items() const { return _grid->items(); } + + //@cmember Converte un record nella eventuale riga corrispondente a video + int rec2row(long rec) const; + + //@cmember Converte una riga a video nell'eventuale record corrispondente + long row2rec(int row) const; + + //@cmember Converte un indice di colonna nel corrispondente id + short int col2cid(int pos) const; + + void update_selection(XI_EVENT* xiev); + + void set_columns_order(TToken_string* order); + + XI_OBJ* find_column(const char* head) const; + +public: + long selected() const { return _cur_rec; } + bool select(long n); + + int visible_rows() const; + + XI_OBJ* find_column(short cid) const; + byte& column_type(int c) { CHECKD(c >= 0 && c < MAX_COL, "Bad column ", c); return _type[c]; } + void show_column(short cid, bool on); + + void update(long n = -1); + bool is_visible(long rec) const; + + void load_columns_order(); + void save_columns_order() const; + void reset_columns_order() { set_columns_order(NULL); } + + TGrid_control(WINDOW parent, short cid, + short x, short y, short dx, short dy, + const char* flags, const char* head, + TGrid_field* owner); + virtual ~TGrid_control() {} +}; + + +TGrid_control::TGrid_control( + WINDOW parent, // @parm Finestra alla quale appartiene lo spreadsheet + short cid, // @parm Identificatore + short x, // @parm Coordinata x (in caratteri) nel quale posizionare lo spreadsheet + short y, // @parm Coordinata y (in caratteri) nel quale posizionare lo spreadsheet + short dx, // @parm Larghezza (in caratteri) dello spreasheet + short dy, // @parm Lunghezza (in caratteri) dello spreasheet + const char* flags, // @parm Flags di abilitazione + const char* head, // @parm Titolo delle colonne + TGrid_field* owner) + : _grid(owner), _cur_rec(-1), _columns_order(0) +{ + _read_only = false; + bool auto_num = false; + bool multi_line = false; + int lines_in_cell = 1; + + for (const char* f = flags; *f; f++) + { + switch(*f) + { + case 'A': + auto_num = true; + break; + case 'D': + _read_only = true; + break; + case 'M': + multi_line = true; + lines_in_cell = (int)xi_get_pref(XI_PREF_DEFAULT_MAX_LINES_IN_CELL); + break; + case '2': + case '3': + case '4': + case '5': + if (multi_line) + lines_in_cell = *f - '0'; + break; + default: + break; + } + } + + const int NUMBER_WIDTH = auto_num ? 7 : 1; + short v_width[MAX_COL]; + short m_width[MAX_COL]; + int fixed_columns = 1; // Number of fixed columns + int lines_in_header = 1; // Number of header lines + + // Calcolo larghezza massima tabella + TToken_string header(head); + TToken_string new_header(256); + int i = 0; + int f_width = NUMBER_WIDTH; // Stima larghezza colonne fisse + int max_width = f_width; // Stima larghezza della colonna piu' grande + const char* h; + + for (h = header.get(); h; h = header.get(), i++) + { + CHECKD(i < MAX_COL, "Tu meni calumns in scit: ", i); + _type[i] = ' '; + + TFixed_string testa(esc(h)); + const bool multiple = testa.find('\n') > 0; + if (multiple) + lines_in_header = 2; + + const int at = testa.find('@'); + int v = testa.len(); // Video width + if (at >= 0) + { + const TString& wi = testa.mid(at+1); + const int video = atoi(wi); + if (video > 0) v = video; + if (wi.find('F') >= 0) + { + fixed_columns = i+2; + f_width += v+1; + } + if (wi.find('R') >= 0) + _type[i] = 'R'; + + testa.cut(at); + } + + v++; + // memory width of column + m_width[i] = v * lines_in_cell; + if (v > 64) v = 64; + v_width[i] = v; + if (v_width[i] > max_width) + max_width = v_width[i]; + new_header.add(testa); + } + + // Calcola rettangolo massimo per lo sheet + XI_OBJ* itf = get_interface(parent); + XI_RCT rct = coord2rct(itf, x, y, dx, dy); + rct.right -= 2*XI_FU_MULTIPLE; // toglie scroll-bar + + // Controlla se ci sono troppe colonne fisse + if ((f_width+max_width)*XI_FU_MULTIPLE > rct.right) + fixed_columns = 1; + + long list_attr = XI_ATR_ENABLED | XI_ATR_VISIBLE; + // if (_read_only) list_attr |= XI_ATR_NAVIGATE; + + XI_OBJ_DEF* listdef = xi_add_list_def(NULL, cid, + rct.top, rct.left, rct.bottom-rct.top, + list_attr, + NORMAL_COLOR, NORMAL_BACK_COLOR, // normal + DISABLED_COLOR, DISABLED_BACK_COLOR, // disabled + FOCUS_COLOR, // active + 0); + + listdef->app_data = (long)this; + + XI_LIST_DEF* l = listdef->v.list; + l->min_heading_height = xi_button_calc_height_font(xi_get_system_font()) * lines_in_header; + l->sizable_columns = true; + l->movable_columns = true; + l->fixed_columns = fixed_columns; + l->max_lines_in_cell = lines_in_cell; + l->scroll_bar = true; + l->scroll_bar_button = true; + l->white_space_color = MASK_DARK_COLOR; + l->rule_color = MASK_DARK_COLOR; + + if (_read_only) + { + l->single_select = true; + } + else + { + l->active_back_color = FOCUS_BACK_COLOR; + } + + // Definizione della prima colonna (numero di riga) + const long attr = XI_ATR_VISIBLE | XI_ATR_RJUST | XI_ATR_SELECTABLE; + XI_OBJ_DEF* coldef = xi_add_column_def(listdef, FIRST_FIELD+1000-1, attr, 0, + NUMBER_WIDTH * XI_FU_MULTIPLE, NUMBER_WIDTH , ""); + + coldef->app_data = (long)this; + XI_COLUMN_DEF* cd = coldef->v.column; + cd->heading_platform = true; + cd->column_platform = true; + + for (h = new_header.get(0), i = 0; h; h = new_header.get(), i++) + { + long attr = XI_ATR_VISIBLE | XI_ATR_ENABLED | XI_ATR_AUTOSCROLL; + if (_read_only) + attr |= XI_ATR_READONLY | XI_ATR_SELECTABLE; + if (_type[i] == 'R') + attr |= XI_ATR_RJUST; + coldef = xi_add_column_def(listdef, FIRST_FIELD+i+1000, attr, i+1, + v_width[i] * XI_FU_MULTIPLE, m_width[i], (char*)h); + + coldef->app_data = (long)this; + cd = coldef->v.column; + cd->heading_platform = true; + cd->center_heading = true; + if (multi_line) + cd->wrap_text = _type[i] != 'R'; + } + + XI_RCT rd; xi_get_def_rect(listdef, &rd); + if ((rd.right - rd.left) > (rct.right - rct.left)) + l->width = rct.right - rct.left; + + _obj = xi_create(itf, listdef); // Create the whole thing! + xi_dequeue(); // Flush events in XOL + xi_tree_free(listdef); // Free definitions + + CHECKD(_obj, "Can't create list control ", cid); + update_tab_cid(); + + int num = 0; + XI_OBJ** column = xi_get_member_list(_obj, &num); + for (i = 0; i < num; i++) + { + xi_get_rect(column[i], &rd); + _default_width[i] = rd.right - rd.left; + } +} + +// Converts a record number in the correspondig row number +int TGrid_control::rec2row(long record) const +{ + int rows; + const long* rec = xi_get_list_info(_obj, &rows); + int r = rows > 0 ? int(record - rec[0]) : -1; + if (r < 0 || r >= rows) + r = -1; + return r; +} + +// Converts a row number in the correspondig record number +long TGrid_control::row2rec(int row) const +{ + CHECK(row >= 0, "Negative grid row?"); + + int rows; + const long* handle = xi_get_list_info(_obj, &rows); + + long rec; + if (rows > 0) + { + if (row >= rows) + rec = handle[rows-1] + row - rows + 1; + else + rec = handle[row]; + } + else + rec = -1; + + if (rec < 0 || rec >= items()) + rec = -1; + + return rec; +} + +int TGrid_control::visible_rows() const +{ + return xi_get_visible_rows(_obj, NULL, NULL); +} + +bool TGrid_control::is_visible(long rec) const +{ + int first = 0, last = 0; + xi_get_visible_rows(_obj, &first, &last); + + int rows = 0; + const long* handle = xi_get_list_info(_obj, &rows); + + bool yes = rec >= handle[first] && rec <= handle[last]; + return yes; +} + + +void TGrid_control::update(long n) +{ + if (n >= 0) + { + const int riga = rec2row(n); + if (riga >= 0) + { + XI_OBJ row; + XI_MAKE_ROW(&row, _obj, riga); + xi_cell_request(&row); + } + } + else + { + int num = 0; + const long* handle = xi_get_list_info(_obj, &num); + + bool scroll_first = items() == 0; + if (!scroll_first) + { + int first = 0, last = 0; + xi_get_visible_rows(_obj, &first, &last); + n = handle[first]; + scroll_first = n > items(); + } + + if (scroll_first) + xi_scroll(_obj, XI_SCROLL_FIRST); + else + xi_scroll_rec(_obj, n, NORMAL_COLOR, XI_ATR_ENABLED, 0); + } +} + +bool TGrid_control::select(long rec) +{ + bool ok, sel; + if (rec >= 0) + { + ok = try_to_select(rec); + sel = ok; + } + else + { + ok = _cur_rec >= 0 && _cur_rec < items() && _grid->off_record(_cur_rec); + sel = false; + } + + if (ok) + { + if (sel) + { + int first, last; + xi_get_visible_rows(_obj, &first, &last); + // Controllo che la nuova riga sia completamente visibile + const int next_row = rec2row(rec); + if (next_row >= first && next_row <= last) + { + if (_read_only) + { + XI_OBJ riga; XI_MAKE_ROW(&riga, _obj, next_row); + long attr = xi_get_attrib(&riga); + attr |= XI_ATR_SELECTED; + xi_set_attrib(&riga, attr); + } + } + else + { + long attr = XI_ATR_ENABLED; + if (_read_only) + attr |= XI_ATR_SELECTED; + xi_scroll_rec(_obj, rec, NORMAL_COLOR, attr, 0); + } + + if (!_read_only) + { + const int next_row = rec2row(rec); + XI_OBJ cella; XI_MAKE_CELL(&cella, _obj, next_row, 1); + xi_set_focus(&cella); + } + } // end if (sel) + + // Deseleziona record precedente se ancora visibile + if (_read_only) + { + const int cur_row = rec2row(_cur_rec); + if (cur_row >= 0) + { + XI_OBJ riga; XI_MAKE_ROW(&riga, _obj, cur_row); + long attr = xi_get_attrib(&riga); + attr &= ~XI_ATR_SELECTED; + xi_set_attrib(&riga, attr); + } + xi_dequeue(); + } + + if (rec < 0 || rec >= items()) + rec = -1; + _cur_rec = rec; + } // end if (ok) + + return ok; +} + +short TGrid_control::col2cid(int pos) const +{ + int num; + XI_OBJ** column = xi_get_member_list(_obj, &num); + CHECKD(pos >= 0 && pos < num, "Bad column ", pos); + const short cid = column[pos]->cid - 1000; + return cid; +} + +bool TGrid_control::try_to_select(long rec) const +{ + bool ok = rec >= 0 && rec < items(); + if (ok && rec != _cur_rec) + { + if (_cur_rec >= 0 && _cur_rec < items()) + ok = _grid->off_record(_cur_rec); + if (ok) + ok = _grid->on_record(rec); + } + return ok; +} + +void TGrid_control::update_selection(XI_EVENT* xiev) +{ + const bool is_curr = xiev->v.rec_request.data_rec == _cur_rec; + if (_read_only) + { +/* + if (is_curr) + xiev->v.rec_request.attrib |= XI_ATR_SELECTED; + else + xiev->v.rec_request.attrib &= ~XI_ATR_SELECTED; +*/ + } + else + xiev->v.rec_request.has_focus = is_curr; +} + +// Certified 75% +bool TGrid_control::event_handler(XI_OBJ* itf, XI_EVENT *xiev) +{ + BOOLEAN& refused = xiev->refused; + + const bool handled = _grid->handler(xiev); + if (handled) + return !refused; + + switch (xiev->type) + { + case XIE_GET_FIRST: + if (items() > 0L) + { + long n = items() * (long)xiev->v.rec_request.percent / 100L; + if (n < 0L) n = 0L; + xiev->v.rec_request.data_rec = n; + update_selection(xiev); + } + else + refused = true; + break; + case XIE_GET_LAST: + xiev->v.rec_request.data_rec = items()-1; + update_selection(xiev); + break; + case XIE_GET_PREV: + case XIE_GET_NEXT: + { + const long n = xiev->v.rec_request.spec_rec + (xiev->type == XIE_GET_NEXT ? +1 : -1) ; + if (n >= 0 && n < items()) + { + xiev->v.rec_request.data_rec = n; + update_selection(xiev); + } + else + refused = true; + // Altrimenti sbaglia a ridisegnare le righe della DBService! + XI_RCT rct; xi_get_rect(_obj, &rct); + xi_invalidate_rect(xi_get_window(_obj), &rct); + } + break; + case XIE_GET_PERCENT: + { + const long rec = xiev->v.get_percent.record; + long n = items(); if (n <= 0) n = 1; + xiev->v.get_percent.percent = short(rec * 100L / n); + } + break; + case XIE_COL_MOVE: + // Rifiuta di spostare una colonna nelle o dalle colonne fisse + if (xiev->v.column.in_fixed || + xiev->v.column.col_nbr < xi_get_fixed_columns(xiev->v.column.list)) + refused = true; + else + _columns_order = 1; + break; + case XIE_COL_SIZE: + { + const short cid = col2cid(xiev->v.column.col_nbr); + if (_grid->on_resize_column(cid, xiev->v.column.new_col_width)) + _columns_order = 1; + else + refused = true; + } + break; + case XIE_SELECT: + if (xiev->v.select.xi_obj->type == XIT_ROW) // Considero solo le righe + { + if (xiev->v.select.selected) // Sto selezionando + { + const long rec = row2rec(xiev->v.select.xi_obj->v.row_data.row); + if (try_to_select(rec)) + { + if (xiev->v.select.column == 0) + { +// if (_read_only) // Commentato 8/11/2013 altrimenti non funziona più collegamento a cg2 +// refused = !select(rec); +// else + { + if (rec == _cur_rec) // Simulo intercettazione doppio click + _grid->on_record_button(rec); + } + } + else + { + if (_read_only && rec == _cur_rec) + { + const short cid = col2cid(xiev->v.select.column); + _grid->on_dbl_cell(rec, cid); + refused = true; + } + } + _cur_rec = rec; // Assegno solo ora il record corrente + } + else + refused = true; + } + } + break; + case XIE_CELL_REQUEST: + { + const long& rec = xiev->v.cell_request.rec; + if (rec >= 0 && rec < items()) + { + TGrid_cell cell(xiev); + const short cid = col2cid(cell.get_column()); + if (cid >= FIRST_FIELD) + { + _grid->cell_request(rec, cid, cell); + } + else + { + if (cell.size() > 2) + { + cell.set(rec+1); + // Setto il colore del testo altrimenti verrebbe grigio: + // non uso la set_color perche' ignora NORMAL_COLOR + xiev->v.cell_request.color = NORMAL_COLOR; + } + } + } + else + refused = true; // Ogni tanto succede + } + break; + case XIE_ON_ROW: + { // Qui ci passa solo se non e' _read_only + const long rec = row2rec(xiev->v.xi_obj->v.row); + if (rec >= 0) + { + if (_grid->on_record(rec)) + _cur_rec = rec; + else + refused = true; + } + else + { + NFCHECK("You are entering an invalid row: %d", xiev->v.xi_obj->v.row); + refused = true; + } + } + break; + case XIE_OFF_ROW: + // Qui ci passa solo se non e' _read_only + if (_cur_rec >= 0 && _cur_rec < items()) + refused = !_grid->off_record(_cur_rec); + break; + case XIE_ON_CELL: + break; + case XIE_DBL_CELL: + { + const long rec = row2rec(xiev->v.xi_obj->v.cell.row); + if (try_to_select(rec)) + { + const short cid = col2cid(xiev->v.xi_obj->v.cell.column); + _grid->on_dbl_cell(rec, cid); + } + } + break; + case XIE_BUTTON: + if (xiev->v.xi_obj->type == XIT_LIST) + { + _grid->on_grid_button(); + } + else + { + const XI_CELL_DATA& cell = xiev->v.xi_obj->v.cell; + const long rec = row2rec(cell.row); + if (try_to_select(rec)) + { + const short cid = col2cid(cell.column); + _grid->on_cell_button(rec, cid); + } + else + NFCHECK("You are clicking an invalid cell: %d", cell.row); + } + break; + default: + break; + } + + return !refused; +} + +XI_OBJ* TGrid_control::find_column(short cid) const +{ + int num = 0; + XI_OBJ** column = xi_get_member_list(_obj, &num); + int i; + for (i = num-1; i >= 0; i--) + { + if (column[i]->cid == cid) + break; + } + return i >= 0 ? column[i] : NULL; +} + +XI_OBJ* TGrid_control::find_column(const char* head) const +{ + int num = 0; + XI_OBJ** column = xi_get_member_list(_obj, &num); + + TString256 text; + int i; + for (i = num-1; i >= 0; i--) + { + xi_get_text(column[i], text.get_buffer(), text.size()); + if (text == head) + break; + } + return i >= 0 ? column[i] : NULL; +} + +void TGrid_control::show_column(short cid, bool on) +{ + XI_OBJ* column = find_column(cid); + if (column) + { +/* Useless + dword attr = xi_get_attrib(column); + if (on) attr |= XI_ATR_VISIBLE; + else attr &= ~XI_ATR_VISIBLE; + xi_set_attrib(column, attr); // Set new attributes + update(-1); +*/ + if (!on) + xi_delete(column); + } +} + +void TGrid_control::set_columns_order(TToken_string* order) +{ + XI_OBJ* itf = get_interface(); + XI_OBJ* focus = xi_get_focus(itf); + xi_set_focus(itf); + + int num_cols; + XI_OBJ** column = xi_get_member_list(_obj, &num_cols); + + // Costante da sottrarre nella xi_column_set_pixel_width altrimenti la somma due volte! + const int offset = 2 * (int)xi_get_pref(XI_PREF_COLUMN_OFFSET); + const int fixed = xi_get_fixed_columns(_obj); + if (fixed > 1) + xi_set_fixed_columns(_obj, 1); + + if (order == NULL) + { + for (int index = 1; index < num_cols; index++) + { + const short cid = FIRST_FIELD + 1000 + index - 1; + XI_OBJ* col = find_column(cid); + if (col) + { + xi_move_column(col, index); + RCT rct; xi_get_rect(col, (XinRect*)&rct); + if (_default_width[index] != rct.right - rct.left) + xi_column_set_pixel_width(col, _default_width[index]-offset); + } + } + _columns_order = 0x3; + } + else + { + TToken_string col(8, ','); + int pos = 0; + for (col = order->get(0); !col.blank(); col = order->get(), pos++) + { + const char* head = esc(col.get(0)); + const int width = col.get_int(); + XI_OBJ* column = find_column(head); + if (column) // Controlla che esista ancora + { + if (pos > 0 && pos < num_cols) + xi_move_column(column, pos); // Sposta la colonna se possibile + if (width > XI_FU_MULTIPLE) // Se ha una larghezza valida + xi_column_set_pixel_width(column, width - offset); + } + } + } + + if (fixed > 1) + xi_set_fixed_columns(_obj, fixed); + + if (focus) + xi_set_focus(focus); +} + +HIDDEN TFilename& field2parag(const TMask_field& f, TFilename& name) +{ + const TMask& m = f.mask(); + name = m.source_file(); + name.ext(""); // Nome della maschera senza estensione + const int index = m.number(); + CHECKD(index >= 0 && index <= 8, "Bad mask index:", index); + if (index > 0) // Aggiunge l'eventuale numero di sotto-maschera + name << '(' << index << ')'; + return name; +} + +void TGrid_control::load_columns_order() +{ + TFilename parag; field2parag(*_grid, parag); + TConfig config(CONFIG_USER, parag); + TToken_string order = config.get("Browse", NULL, id()); + if (order.empty_items()) + config.remove("Browse", id()); + else + set_columns_order(&order); + _columns_order = 0; +} + +void TGrid_control::save_columns_order() const +{ + if (_columns_order) + { + TFilename parag; field2parag(*_grid, parag); + TConfig config(CONFIG_USER, parag); // Apre il file di configurazione + + TToken_string order(127); // Nuovo ordine delle colonne + if (_columns_order == 1) // Se vale 3 devo solo resettare + { + int num; + XI_OBJ** column = xi_get_member_list(_obj, &num); + TString80 head; + for (int i = 0; i < num; i++) // Scorre tutte le colonne + { + xi_get_text(column[i], head.get_buffer(), head.size()); + const int acapo = head.find('\n'); + if (acapo > 0) + { + head[acapo] = '\\'; + head.insert("n", acapo+1); + } + order.add(head); + RCT rct; xi_get_rect(column[i], (XinRect*)&rct); + order << ',' << rct.right - rct.left; + } + config.set("Browse", order, NULL, true, id()); + } + else + config.remove("Browse", id()); + } +} + +/////////////////////////////////////////////////////////// +// TGrid_cell +/////////////////////////////////////////////////////////// + +TGrid_cell::TGrid_cell(XI_EVENT* xiev) + : TFixed_string(xiev->v.cell_request.s, xiev->v.cell_request.len), + _xiev(xiev) +{ } + + +// Setta il testo di una cella (Mai piu' testo troppo lungo!) +// Se c'e' gia' un'icona la elimina +TString& TGrid_cell::set(const char* txt) +{ + strncpy(txt, size()); + if (not_empty()) + { + int& icon = _xiev->v.cell_request.icon_rid; + if (icon) + icon = 0; + } + return *this; +} + +TString& TGrid_cell::set(long num) +{ + char buff[16]; + sprintf(buff, "%ld", num); + return set(buff); +} + +// Setta l'icona di una cella +// Se c'e' gia' un testo lo elimina +void TGrid_cell::set_icon(int id) +{ + _xiev->v.cell_request.icon_rid = id; + if (id) + _xiev->v.cell_request.s[0] = '\0'; +} + +void TGrid_cell::show_button(bool on) +{ + _xiev->v.cell_request.button = on; + _xiev->v.cell_request.button_on_focus = on; +} + +void TGrid_cell::set_back_color(COLOR col) +{ + if (col != NORMAL_BACK_COLOR) + _xiev->v.cell_request.back_color = col; +} + +void TGrid_cell::set_fore_color(COLOR col) +{ + if (col != NORMAL_COLOR) + _xiev->v.cell_request.color = col; +} + +void TGrid_cell::set_colors(COLOR back, COLOR fore) +{ + if (back != NORMAL_BACK_COLOR) + _xiev->v.cell_request.back_color = back; + if (fore != NORMAL_COLOR) + _xiev->v.cell_request.color = fore; +} + +/////////////////////////////////////////////////////////// +// TGrid_field +/////////////////////////////////////////////////////////// + +TGrid_field::TGrid_field(TMask* m) + : TOperable_field(m) +{ } + +word TGrid_field::class_id() const +{ + return CLASS_GRID_FIELD; +} + +void TGrid_field::update(long n) +{ grid().update(n); } + +void TGrid_field::parse_head(TScanner& scanner) +{ + _ctl_data._width = scanner.integer(); + _ctl_data._height = scanner.integer(); + if (_ctl_data._height == 0) + _ctl_data._height = -1; +} + +void TGrid_field::create(WINDOW parent) +{ + _ctl = new TGrid_control(parent, dlg(), + _ctl_data._x, _ctl_data._y, + _ctl_data._width, _ctl_data._height, + _ctl_data._flags, _ctl_data._park, + this); + grid().load_columns_order(); +} + +bool TGrid_field::parse_item(TScanner& scanner) +{ + if (scanner.key() == "IT") + { + _ctl_data._park.add(scanner.string()); + return true; + } + return TMask_field::parse_item(scanner); +} + + +bool TGrid_field::handler(XI_EVENT* xiev) +{ + return false; +} + +long TGrid_field::items() const +{ + return 100000L; +} + +int TGrid_field::visible_rows() const +{ + return grid().visible_rows(); +} + +void TGrid_field::cell_request(long rec, short id, TGrid_cell& cell) +{ + cell.set("Cell"); +} + +long TGrid_field::selected() const +{ return grid().selected(); } + +bool TGrid_field::select(long rec) +{ return grid().select(rec); } + +void TGrid_field::reset_columns_order() +{ + grid().reset_columns_order(); +} + +void TGrid_field::save_columns_order() const +{ + grid().save_columns_order(); +} + +/////////////////////////////////////////////////////////// +// Da qui in poi e' tutta roba specializzata del programma +/////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////// +// Maschera per colori +/////////////////////////////////////////////////////////// + +class TColor_mask : public TSelect_color_mask +{ +public: + void get_colors(COLOR& mb, COLOR& mf, COLOR& cb, COLOR& cf); + TColor_mask(); +}; + +void TColor_mask::get_colors(COLOR& mb, COLOR& mf, COLOR& cb, COLOR& cf) +{ + get_color("M", mb, mf); + get_color("C", cb, cf); +} + +TColor_mask::TColor_mask() : TSelect_color_mask("cg3600b") +{ + add_color_def("M", TR("Riga mastrino"), REQUIRED_BACK_COLOR, FOCUS_COLOR); + add_color_def("C", TR("Riga contropartita"), NORMAL_BACK_COLOR, NORMAL_COLOR); +} + +/////////////////////////////////////////////////////////// +// TMastrini_grid +/////////////////////////////////////////////////////////// + +class TMastrini_grid : public TGrid_field +{ + TMastrino _mastrino; + + TDecoder _causali; + TEsercizi_contabili _esercizi; + + TColor_mask _colmsk; + COLOR _mas_back, _mas_fore; + COLOR _con_back, _con_fore; + bool _primanoting; + +protected: // TGrid_field + virtual bool on_record(long rec); + virtual void on_grid_button(); + virtual bool on_resize_column(short id, int new_size); + + void update_mask() const; + +public: + virtual void cell_request(long rec, short id, TGrid_cell& cell); + virtual void on_dbl_cell(long rec, short id); + virtual void on_record_button(long rec); + virtual long items() const { return _mastrino.items(); } + + void destroy(); + void read(const TBill& conto, + int annoes, const TDate& dd, const TDate& ad, + const TString& dc, const TString& ac, bool provv); + void reread(); + + TMastrino& mastrino() { return _mastrino; } + + void save_colors(); + void load_colors(); + void set_colors(); + + TMastrini_grid(TMask* m); + virtual ~TMastrini_grid() { } +}; + +TMastrini_grid::TMastrini_grid(TMask* m) + : TGrid_field(m), _causali(LF_CAUSALI, CAU_DESCR), _primanoting(false) +{ + load_colors(); +} + +void TMastrini_grid::destroy() +{ + _mastrino.destroy(); + grid().select(-1); +} + +HIDDEN const char* real2string(const real& r) +{ + const TCurrency cur(r); + return cur.string(true); +} + +HIDDEN void set_imp(TMask_field& f, const TImporto& imp) +{ + if (!imp.is_zero()) + { + TString80 str; + str.format("%s %c", real2string(imp.valore()), imp.sezione()); + f.set(str); + } + else + f.reset(); +} + +void TMastrini_grid::cell_request(long rec, short id, TGrid_cell& cell) +{ + if (rec < 0) // testate + { + XI_OBJ* col = grid().find_column(short(1000+id%1000)); + if (col != NULL) + { + TString256 str; + xi_get_text(col, str.get_buffer(), str.size()); + cell = str; + + } + return; + } + + const TRiga_mastrino& riga = _mastrino[rec]; + + switch (id) + { + case 101: + if (riga.tipo() == riga_mastrino) + { + const TRectype& mov = _mastrino.testata(rec); + cell = riga.data().string(); + cell << ' ' << mov.get(MOV_DATADOC); + } + break; + case 102: + if (riga.tipo() == riga_mastrino) + { + const TRectype& mov = _mastrino.testata(rec); + const int anno = _esercizi.date2esc(riga.data()); + const int eser = mov.get_int(MOV_ANNOES); + TString8 str; + if (anno != eser) + str = "C"; // Di competenza vecchia + if (mov.get(MOV_PROVVIS).not_empty()) + { + if (str.not_empty()) + str << '/'; + str << 'P'; + } + cell = str; + } + break; + case 103: + if (riga.tipo() == riga_mastrino) + { + const TRectype& mov = _mastrino.testata(rec); + cell.set(_causali.decode(mov.get(MOV_CODCAUS))); + } + else + { + const TRectype& rmov = _mastrino.riga(rec); + cell.format("%03d.%03d.%06ld", + rmov.get_int(RMV_GRUPPO), + rmov.get_int(RMV_CONTO), + rmov.get_long(RMV_SOTTOCONTO)); + } + break; + case 104: // Descrizione + { + const TRectype& rmov = _mastrino.riga(rec); + const TRectype& mov = _mastrino.testata(rec); + TString descr = rmov.get(RMV_DESCR); + if (riga.tipo() == riga_mastrino) + { + if (descr.empty()) + { + const TRectype& mov = _mastrino.testata(rec); + descr = mov.get(MOV_DESCR); + if (descr.empty()) + { + TBill uncle(rmov,true); + descr = uncle.descrizione(); + } + } + } + else + { + // Bug 0001748: ignora descrizioni generate da contabilizzazione + if (descr.empty() || descr == _mastrino.conto().descrizione()) + { + const TBill conto(rmov); + descr = conto.descrizione(); + } + } +#ifdef CONT_SEP + const TString16 cs = mov.get(MOV_CONTSEP); + + if (cs.full()) + descr << "\n" << cache().get("&NPENT", cs, "S0"); +#endif + cell.set(descr); + } + break; + case 105: // Dare + { + const TRectype& rmov = _mastrino.riga(rec); + const char sez = rmov.get_char(RMV_SEZIONE); + if (sez == 'D') + cell = real2string(rmov.get_real(RMV_IMPORTO)); + } + break; + case 106: // Avere + { + const TRectype& rmov = _mastrino.riga(rec); + const char sez = rmov.get_char(RMV_SEZIONE); + if (sez == 'A') + cell = real2string(rmov.get_real(RMV_IMPORTO)); + } + break; + case 107: + if (riga.tipo() == riga_mastrino) + { + const TRectype& mov = _mastrino.testata(rec); + cell = mov.get(MOV_NUMDOC); cell.left_just(7); + cell << ' ' << mov.get(MOV_PROTIVA); + } + break; + case 108: + { + const TRectype& rmov = _mastrino.riga(rec); + cell = real2string(rmov.get_real(RMV_IMPORTO)); + cell << ' ' << rmov.get(RMV_SEZIONE); + } + break; + case 109: + if (riga.tipo() == riga_mastrino) + { + const long next_row = _mastrino.succ(rec, riga_mastrino); + bool stampa = next_row >= _mastrino.items(); + if (!stampa) + { + const TDate& data = _mastrino[next_row].data(); + stampa = riga.data() != data; + } + if (stampa) + { + TImporto imp = riga.saldo(); + imp += _mastrino.saldo_iniziale(); + imp.normalize(); + cell = real2string(imp.valore()); + cell << ' ' << imp.sezione(); + } + } + break; + case 110: + if (riga.tipo() == riga_mastrino) + { + const TRectype& mov = _mastrino.testata(rec); + TLocalisamfile movana(LF_MOVANA); + movana.setkey(3); + movana.put(MOVANA_NUMREGCG, mov.get(MOV_NUMREG)); + if (movana.read() == NOERR) + { + const TRectype& rmov = _mastrino.riga(rec); + const TBill bill(rmov); + const TString16 codconto = bill.string(0x8); // GGGCCCSSSSSS + const TRecord_array rmovana(movana.get(MOVANA_NUMREG), LF_RMOVANA); + const int last_rmovana = rmovana.last_row(); + const real target = rmov.get(RMV_IMPORTO); + + TBit_array hits; + + if (hits.first_one() < 0) + { + // Controllo se c'è corrispondenza biunivoca tra le righe di CG e CA + const int nriga = rmov.get_int(RMV_NUMRIG); + if (nriga <= last_rmovana && rmovana.exist(nriga)) + { + const TRectype& r = rmovana.row(nriga); + if (r.get(RMOVANA_CODCONTO) == codconto && r.get_real(RMOVANA_IMPORTO) == target) + hits.set(nriga); + } + } + + if (hits.first_one() < 0) + { + // Controllo se esiste una riga che corrisponda per importo e conto analitico/contabile + for (int i = rmovana.first_row(); i > 0 && i <= last_rmovana; i = rmovana.succ_row(i)) + { + const TRectype& r = rmovana.row(i); + if (r.get(RMOVANA_CODCONTO) == codconto) + { + const real imp = r.get(RMOVANA_IMPORTO); + if (imp == target) + { + hits.set(i); + break; + } + } + } + } + + if (hits.first_one() < 0) + { + // Faccio la somma delle righe che corrispondono per conto analitico/contabile + real total_hits; + for (int i = rmovana.first_row(); i > 0 && i <= last_rmovana; i = rmovana.succ_row(i)) + { + const TRectype& r = rmovana.row(i); + if (r.get(RMOVANA_CODCONTO) == codconto) + { + const real imp = r.get(RMOVANA_IMPORTO); + hits.set(i); + total_hits += imp; + if (total_hits >= target) + break; + } + } + } + + TString cms; + for (int h = hits.first_one(); h >= 0 && h <= last_rmovana; h++) if (hits[h]) + { + const TRectype& r = rmovana.row(h); + TString80 cod = r.get(RMOVANA_CODCMS); + if (cod.starts_with("00000")) + { + int i = 0; + for (i = 5; cod[i] == '0'; i++); + cod.ltrim(i); + } + if (cms.not_empty()) + cms << ' '; + cms << cod; + if (cms.len() >= cell.size()) + break; + } + if (cms.len() >= cell.size()) + cms.cut(cell.size()-1); + cell = cms; + } + } + break; + default: + break; + } + + if (riga.tipo() == riga_mastrino) + cell.set_colors(_mas_back, _mas_fore); + else + cell.set_colors(_con_back, _con_fore); +} + +bool TMastrini_grid::on_record(long rec) +{ + if (_mastrino[rec].tipo() != riga_mastrino) + rec = _mastrino.pred(rec, riga_mastrino); + + TRiga_mastrino& riga = _mastrino[rec]; + TMask& gm = mask(); + set_imp(gm.field(F_TOTRIG_SAL), riga.saldo()); + gm.set(F_TOTRIG_DAR, riga.dare()); + gm.set(F_TOTRIG_AVE, riga.avere()); + + return true; +} + +void TMastrini_grid::on_dbl_cell(long rec, short id) +{ + if (rec >= 0 && rec < items()) + { + if (_mastrino.expandable(rec)) + _mastrino.expand(rec); + else + _mastrino.collapse(rec); + update(); + } +} + +void TMastrini_grid::on_grid_button() +{ + const long total = _mastrino.items(); + if (total > 0) + { + TProgress_monitor pi(total, TR("Aggiornamento contropartite ..."), false); + + // Cerca l'ultima contropartita + const long last_con = _mastrino.last(riga_contropartita); + // Se non esistono contropartite devo espandere le righe + const bool expand = last_con < 0; + +#ifdef DBG + const clock_t clock_start = clock(); +#endif + + if (expand) + { + long step = 0; + for (long n = _mastrino.first(riga_mastrino); + n < _mastrino.items(); n = _mastrino.succ(n, riga_mastrino)) + { + if (_mastrino.expandable(n)) + _mastrino.expand(n); + pi.set_status(++step); +#ifdef DBG + if ((step & 0x7F) == 0) + { + const double sec = (clock() - clock_start) / CLOCKS_PER_SEC; + if (sec > 0.0) + { + TString80 msg; + msg.format(FR("%ld records at %ld rec/sec"), step, long(step/sec)); + pi.set_text(msg); + } + } +#endif + } + } + else + { + for (long n = last_con; n > 0; n = _mastrino.pred(n, riga_contropartita)) + { + _mastrino.collapse(n); + pi.set_status(total - n + 1); + } + } + + update(); + } +} + +void TMastrini_grid::on_record_button(long rec) +{ + if (!_primanoting) + { + _primanoting = true; + const TRectype& testata = _mastrino.testata(rec); + testata.edit(); + if (yesno_box(TR("Si desidera aggiornare il mastrino?"))) + reread(); + _primanoting = false; + } +} + +// Posso ridimensionare solo le descrizioni, le altre devono rimanere fisse per +// non perdere la formattazione su due righe +bool TMastrini_grid::on_resize_column(short cid, int new_size) +{ + return cid == 103 || cid == 104; +} + + +void TMastrini_grid::read(const TBill& conto, + int annoes, const TDate& dd, const TDate& ad, + const TString& dc, const TString& ac, bool provv) +{ + destroy(); + _mastrino.read(conto, annoes, dd, ad, dc, ac, provv); + update(); + update_mask(); +} + +void TMastrini_grid::reread() +{ + destroy(); + _mastrino.reread(); + update(); + update_mask(); +} + +void TMastrini_grid::update_mask() const +{ + TMask& gm = mask(); + + gm.set(F_ESERCIZIO, _mastrino.esercizio()); + gm.set(F_DADATA, _mastrino.inizio_periodo()); + gm.set(F_ADATA, _mastrino.fine_periodo()); + + set_imp(gm.field(F_TOTPRO_SAL), _mastrino.saldo_iniziale()); + gm.set(F_TOTPRO_DAR, _mastrino.progressivo_dare_iniziale()); + gm.set(F_TOTPRO_AVE, _mastrino.progressivo_avere_iniziale()); + + gm.reset(F_TOTRIG_SAL); + gm.reset(F_TOTRIG_DAR); + gm.reset(F_TOTRIG_AVE); + + set_imp(gm.field(F_TOTPER_SAL), _mastrino.saldo_periodo()); + gm.set(F_TOTPER_DAR, _mastrino.progressivo_dare_periodo()); + gm.set(F_TOTPER_AVE, _mastrino.progressivo_avere_periodo()); + + set_imp(gm.field(F_TOTATT_SAL), _mastrino.saldo_finale()); + gm.set(F_TOTATT_DAR, _mastrino.progressivo_dare_finale()); + gm.set(F_TOTATT_AVE, _mastrino.progressivo_avere_finale()); + + const bool can_link = main_app().argc() <= 2; // NON sono stato chiamato dalla prima nota + gm.enable(DLG_LINK, can_link && _mastrino.items() > 0); + gm.enable(DLG_NEWREC, can_link); +} + +void TMastrini_grid::load_colors() +{ + _colmsk.get_colors(_mas_back, _mas_fore, _con_back, _con_fore); +} + +void TMastrini_grid::set_colors() +{ + if (_colmsk.run() == K_ENTER) + load_colors(); +} + +/////////////////////////////////////////////////////////// +// TMastrino_set +/////////////////////////////////////////////////////////// + +class TMastrino_set : public TRecordset +{ + TMastrini_grid& _grid; + long _curr; + TArray _info; + +protected: + void add_field(TFieldtypes t, short id, int width, const char* name = NULL); + long cell_request(long rec, short column, TString& str) const; + const TString& query_text() const { return EMPTY_STRING; } + +public: + virtual TRecnotype items() const { return _grid.items(); } + virtual unsigned int columns() const { return _info.items(); } + virtual const TRecordset_column_info& column_info(unsigned int column) const; + virtual bool move_to(TRecnotype n); + virtual TRecnotype current_row() const { return _curr; } + virtual void requery() {} + virtual const TVariant& get(unsigned int column) const; + + TMastrino_set(TMastrini_grid& g); +}; + +const TRecordset_column_info& TMastrino_set::column_info(unsigned int column) const +{ + return (const TRecordset_column_info&)_info[column]; +} + +bool TMastrino_set::move_to(TRecnotype n) +{ + const bool ok = n >= 0 && n < items(); + _curr = n; + return ok; +} + +long TMastrino_set::cell_request(long rec, short column, TString& str) const +{ + XI_EVENT xiev; memset(&xiev, 0, sizeof(xiev)); + xiev.type = XIE_CELL_REQUEST; + xiev.v.cell_request.s = str.get_buffer(); + xiev.v.cell_request.len = str.size(); + TGrid_cell cell(&xiev); + _grid.cell_request(rec, column, cell); + return xiev.v.cell_request.attrib; +} + + +const TVariant& TMastrino_set::get(unsigned int column) const +{ + if (_curr >= 0 && _curr < items() && column >= 0 && column < columns()) + { + const TRecordset_column_info& info = column_info(column); + + TToken_string str; + cell_request(_curr, abs(info._pos), str); + if (str.full()) + { + //decide se il campo appartiene ad una sottocella (es. numdoc / prot) + bool divide = info._pos < 0; //è la prima parte di una sottocella + if (!divide && column < columns()-1) + divide = column_info(column+1)._pos < 0; //è la seconda parte di una sottocella + //se deve splittare cerca lo spazio come carattere di separazione tra le sottocelle + if (divide) + { + const int cr = str.find(' '); + if (cr >= 0) + { + if (info._pos > 0) + str.cut(cr); + else + str.ltrim(cr); + str.trim(); + } + } + + TVariant& tmp = get_tmp_var(); + switch (info._type) + { + case _realfld: + tmp = real(real::ita2eng(str)); + break; + case _longfld: + tmp = atol(str); + break; + case _datefld: + tmp = TDate(str); + break; + default: + if (info._width == 1) + tmp = str.right(1); + else + tmp = str; + break; + } + return tmp; + } + } + return NULL_VARIANT; +} + +void TMastrino_set::add_field(TFieldtypes tipo, short id, int width, const char* name) +{ + TRecordset_column_info* i = new TRecordset_column_info; + + TString& n = i->_name; + + if (name && *name) + n = name; + else + { + cell_request(-1, abs(id), n); + const int cr = n.find('\n'); + if (cr > 0) + { + if (id > 0) + n.cut(cr); + else + n.ltrim(cr+1); + n.trim(); + } + } + + i->_type = tipo; + i->_pos = id; + i->_width = width; + + _info.add(i); +} + +TMastrino_set::TMastrino_set(TMastrini_grid& g) + : _grid(g), _curr(-1) +{ + _grid.mastrino().collapse(-1);// Nascondo tutte le righe di contropartita + + add_field(_datefld, 101, 10); // Data reg + add_field(_datefld,-101, 10); // Data comp + add_field(_alfafld, 102, 1); // Movimento di competenza? + add_field(_alfafld, 103, 25); // Causale + add_field(_alfafld, 104, 50); // Descrizione + add_field(_realfld, 105, 13); // Dare + add_field(_realfld, 106, 13); // Avere + add_field(_alfafld, 107, 7); // Num doc + add_field(_longfld,-107, 7); // Num prot + add_field(_realfld, 108, 13); // Saldo + add_field(_alfafld,-108, 1, "Sezione"); // Sezione + add_field(_realfld, 109, 13); // Saldo giornaliero + add_field(_alfafld,-109, 1, "Sezione"); // Sezione giornaliera + + const bool show_cms = main_app().has_module(CMAUT) || main_app().has_module(CAAUT); + if (show_cms) + add_field(_alfafld, 110, 40); // Commessa +} + +/////////////////////////////////////////////////////////// +// TGrid_mask +/////////////////////////////////////////////////////////// + +class TGrid_mask : public TMask +{ + TMastrini_grid* _grid; + +protected: // TMask + virtual TMask_field* parse_field(TScanner& sc); + virtual bool on_key(KEY k); + virtual long handler(WINDOW win, EVENT* ep); + + static bool link_handler(TMask_field& f, KEY k); + static bool new_handler(TMask_field& f, KEY k); + //static bool edit_handler(TMask_field& f, KEY k); + static bool export_handler(TMask_field& f, KEY k); + static bool saldac_handler(TMask_field& f, KEY k); + +public: + TMastrini_grid& grid() { CHECK(_grid, "What's grid?"); return *_grid; } + + TGrid_mask(); + virtual ~TGrid_mask() { } +}; + +TGrid_mask::TGrid_mask() + : _grid(NULL) +{ + read_mask("cg3600b", 0, 0); + set_handler(DLG_LINK, link_handler); + set_handler(DLG_NEWREC, new_handler); + //set_handler(DLG_EDIT, edit_handler); + set_handler(DLG_EXPORT, export_handler); + set_handler(DLG_USER, saldac_handler); // implemented in cg3601.cpp + + const bool show_cms = main_app().has_module(CMAUT) || main_app().has_module(CAAUT); + if (!show_cms) + _grid->grid().show_column(1110, false); // Nasconde la commessa +} + +TMask_field* TGrid_mask::parse_field(TScanner& sc) +{ + TMask_field* f; + if (sc.key() == "SP") + f = _grid = new TMastrini_grid(this); + else + f = TMask::parse_field(sc); + return f; +} + +bool TGrid_mask::link_handler(TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + TGrid_mask& gm = (TGrid_mask&)f.mask(); + TMastrini_grid& grid = gm.grid(); + const long rec = grid.selected(); + if (rec >= 0 && rec < grid.items()) + grid.on_record_button(rec); + } + return true; +} + +bool TGrid_mask::new_handler(TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + TExternal_app app("cg2 -0"); + const bool refresh = app.run() == 0; + if (refresh && yesno_box(TR("Si desidera aggiornare il mastrino?"))) + { + TGrid_mask& gm = (TGrid_mask&)f.mask(); + TMastrini_grid& grid = gm.grid(); + grid.reread(); + } + } + return true; +} + +/* Useless +bool TGrid_mask::edit_handler(TMask_field& f, KEY k) +{ + bool ok = true; + if (k == K_SPACE) + { + TGrid_mask& gm = (TGrid_mask&)f.mask(); + TMastrini_grid& grid = gm.grid(); + TMastrino_set ms(grid); + + TFilename n; n.tempdir(); n.add("mastrino.xls"); + ms.save_as(n); + ok = xvt_sys_goto_url(n, "open") != FALSE; + if (!ok) + ok = export_handler(f, k); // Se non parte Excel salvo altrove + } + return ok; +}*/ + +bool TGrid_mask::export_handler(TMask_field& f, KEY k) +{ + bool ok = true; + if (k == K_SPACE) + { + TFilename n; n.tempdir(); n.add("mastrino.xls"); + FILE_SPEC fs; xvt_fsys_convert_str_to_fspec(n, &fs); + if (xvt_dm_post_file_save(&fs, f.prompt()) == FL_OK) + { + xvt_fsys_convert_fspec_to_str(&fs, n.get_buffer(), n.size()); + TGrid_mask& gm = (TGrid_mask&)f.mask(); + TMastrini_grid& grid = gm.grid(); + TMastrino_set ms(grid); + ms.save_as(n); + } + } + return ok; +} + +bool TGrid_mask::saldac_handler(TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + TBill zio; zio.get(f.mask(), F_GRUPPO, F_CONTO, F_SOTTOCONTO); + popup_games(zio); + } + return true; +} + +bool TGrid_mask::on_key(KEY k) +{ + switch (k) + { + case K_ENTER: + case K_CTRL+'+': + case K_CTRL+'-': + if (focus_field().dlg() == _grid->dlg()) + { + const long rec = grid().selected(); + _grid->on_dbl_cell(rec, DLG_USER); + } + break; + default: + break; + } + + return TMask::on_key(k); +} + +long TGrid_mask::handler(WINDOW win, EVENT* ep) +{ + static TGrid_field* _last_grid = NULL; + + if (ep->type == E_MOUSE_DOWN && ep->v.mouse.button == 1) + { + _last_grid = NULL; + + RCT rct; _grid->get_rect(rct); + if (xvt_rect_has_point(&rct, ep->v.mouse.where)) + _last_grid = _grid; + + if (_last_grid) + { + //TGrid_field& sht = (TGrid_field&)*_last_grid; + MENU_ITEM* menu = xvt_res_get_menu(BROWSE_BAR); + + if (menu != NULL) + { + const PNT& p = ep->v.mouse.where; + xvt_menu_popup(menu->child, win, p, XVT_POPUP_CENTER, 0); + xvt_res_free_menu_tree(menu); + } + return 0L; + } + } + if (ep->type == E_COMMAND) + { + if (_last_grid) + { + switch (ep->v.cmd.tag) + { + case BROWSE_BAR+1: _last_grid->save_columns_order(); break; + case BROWSE_BAR+2: _last_grid->reset_columns_order(); break; + case BROWSE_BAR+3: _last_grid->on_key(K_F11); break; + default: break; + } + return 0L; + } + } + return TMask::handler(win, ep); +} + +/////////////////////////////////////////////////////////// +// TQuery_mask +/////////////////////////////////////////////////////////// + +bool TQuery_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) +{ + switch (o.dlg()) + { + case F_TIPO: + if (e == fe_modify) + { + const TString& tipo = o.get(); + + if (tipo != _last_tipo) + { + _last_tipo = tipo; + if (tipo.full()) + { + // Controllo se il mastro corrente è già compatibile col tipo C/F + if (!field(F_CONTO).empty()) + { + TString8 key; key.format("%d|%d", get_int(F_GRUPPO), get_int(F_CONTO)); + const TString& tmcf = cache().get(LF_PCON, key, PCN_TMCF); + if (tmcf == tipo) + return true; + } + // Cerco il primo mastro conforme al tipo C/F selezionato + TWait_cursor hourglass; + TString80 query; + query << "USE " << LF_PCON << " SELECT " << PCN_TMCF << "=\"" << tipo << "\""; + TISAM_recordset conti(query); + if (conti.move_first()) + { + set(F_GRUPPO, conti.get(PCN_GRUPPO).as_int(), 0x2); + set(F_CONTO, conti.get(PCN_CONTO).as_int(), 0x2); + } + } + } + } + break; + case F_CLIENTE: + case F_FORNITORE: + if (e == fe_modify && !o.empty()) + { + const TRectype& rec = ((TEdit_field&)o).browse()->cursor()->curr(); + const int g = rec.get_int(CLI_GRUPPO); + const int c = rec.get_int(CLI_CONTO); + if (g > 0 && c > 0) + { + set(F_GRUPPO, g, 0x2); + set(F_CONTO, c, 0x2); + } + } + break; + case F_ESERCIZIO: + if (e == fe_modify || e == fe_close) + { + TEsercizi_contabili esc; + const int anno = atoi(o.get()); + if (esc.exist(anno)) + { + TDate dd = get(F_DADATA); + if (esc.date2esc(dd) != anno) + set(F_DADATA, esc[anno].inizio()); + dd = get(F_ADATA); + if (esc.date2esc(dd) != anno) + set(F_ADATA, esc[anno].fine()); + } + else + { + if (anno > 0) + return error_box(FR("Esercizio inesistente: %d"), anno); + } + } + break; + case F_DADATA: + case F_ADATA: + if (e == fe_close) + { + const TEsercizi_contabili esercizi; + int codice_esercizio = get_int(F_ESERCIZIO); + if (codice_esercizio <= 0) + { + const short id_altra_data = o.dlg() == F_DADATA ? F_ADATA : F_DADATA; + const TDate d = get(id_altra_data); + if (d.ok()) + codice_esercizio = esercizi.date2esc(d); + } + + if (o.empty()) + { + if (codice_esercizio == 0) + return error_box(TR("E' necessario specificare almeno una data.")); + return true; + } + + const TDate d = o.get(); + const int esercizio = esercizi.date2esc(d); + if (get_int(F_ESERCIZIO) != 0) + { + if (esercizio != codice_esercizio) + return error_box(FR("La data deve appartenere all'esercizio %d"), codice_esercizio); + } + else + { + if (esercizio == 0) + return error_box(TR("La data deve appartenere ad un esercizio contabile")); + } + } + break; + case DLG_FINDREC: + if (e == fe_button) + { + short id; + switch (get(F_TIPO)[0]) + { + case 'C': id = F_CLIENTE; break; + case 'F': id = F_FORNITORE; break; + default : id = F_SOTTOCONTO; break; + } + field(id).on_key(K_F9); + } + break; + case DLG_CONFIG: + if (e == fe_button) + _gm->grid().set_colors(); + break; + default: + break; + } + + return true; +} + +TQuery_mask::TQuery_mask(TGrid_mask* gm) : TAutomask("cg3600a"), _gm(gm), _last_tipo("") +{ } + +void TQuery_mask::do_query() +{ + const char t = get(F_TIPO)[0]; + const int g = get_int(F_GRUPPO); + const int c = get_int(F_CONTO); + const long s = get_long((t <= ' ') ? F_SOTTOCONTO : ((t == 'C') ? F_CLIENTE : F_FORNITORE)); + const TBill conto(g, c, s, t); + + const int annoes = get_int(F_ESERCIZIO); + const TDate da_data(get(F_DADATA)); + const TDate a_data(get(F_ADATA)); + + const TString& da_caus = get(F_DACAUSALE); + const TString& a_caus = get(F_ACAUSALE); + const bool provv = get_bool(F_PROVVIS); + + conto.set(*_gm, F_GRUPPO, F_CONTO, F_SOTTOCONTO, 0, F_DESSOTTOC); + TMastrini_grid& gf = _gm->grid(); + + gf.read(conto, annoes, da_data, a_data, da_caus, a_caus, provv); + gf.select(get_bool(F_END) ? gf.items() -1 : 0); + + _gm->run(); +} + +/////////////////////////////////////////////////////////// +// TMastrini_video +/////////////////////////////////////////////////////////// + +bool TMastrini_video::create() +{ + xvtil_statbar_set("", TRUE); + open_files(LF_CAUSALI, LF_MOV, LF_PCON, LF_RMOV, LF_SALDI, 0); + if (has_module(CMAUT)) + open_files(LF_MOVANA, LF_RMOVANA, 0); + + _gm = new TGrid_mask; + _qm = new TQuery_mask(_gm); + + return TSkeleton_application::create(); +} + +bool TMastrini_video::destroy() +{ + delete _qm; + delete _gm; + return TSkeleton_application::destroy(); +} + +void TMastrini_video::main_loop() +{ + TQuery_mask& qm = *_qm; + + if (argc() > 2) + { + TFilename ininame = argv(2)+2; + if (ininame.exist()) + { + TConfig ini(ininame, "24"); + qm.set(F_ESERCIZIO, ini.get(RMV_ANNOES)); + qm.set(F_TIPO, ini.get(RMV_TIPOC)); + qm.set(F_GRUPPO, ini.get(RMV_GRUPPO)); + qm.set(F_CONTO, ini.get(RMV_CONTO)); + qm.set(F_SOTTOCONTO, ini.get(RMV_SOTTOCONTO)); + qm.set(F_CLIENTE, ini.get(RMV_SOTTOCONTO)); + qm.set(F_FORNITORE, ini.get(RMV_SOTTOCONTO)); + qm.send_key(K_SPACE, DLG_OK); + } + } + + const TEsercizi_contabili esercizi; + TDate inies, fines; + int codesc = qm.get_int(F_ESERCIZIO); + if (!esercizi.exist(codesc)) + codesc = esercizi.last(); + esercizi.code2range(codesc, inies, fines); + qm.set(F_ESERCIZIO, codesc); + qm.set(F_DADATA, inies); + qm.set(F_ADATA, fines); + + while (qm.run() == K_ENTER) + qm.do_query(); +} + +/////////////////////////////////////////////////////////// +// Main +/////////////////////////////////////////////////////////// + +#ifdef CONT_SEP +int np0500(int argc, char* argv[]) +#else +int cg3600(int argc, char* argv[]) +#endif +{ + TMastrini_video mv; + mv.run(argc, argv, TR("Mastrini")); + return 0; +} diff --git a/src/cg/cg3600a.uml b/src/cg/cg3600a.uml index 86908fa8d..6b593024c 100755 --- a/src/cg/cg3600a.uml +++ b/src/cg/cg3600a.uml @@ -23,7 +23,11 @@ END ENDPAGE +#ifdef CONT_SEP +PAGE "Mastrini cotabilità separata" 0 0 0 2 +#else PAGE "Mastrini" 0 0 0 2 +#endif GROUPBOX DLG_NULL 76 3 BEGIN @@ -374,14 +378,6 @@ BEGIN GROUP 5 END -#ifdef CONT_SEP -BOOLEAN F_ST_CONTSEP -BEGIN - PROMPT 2 18 "Visualizzare contabilità separata" - MODULE NP -END -#endif - ENDPAGE ENDMASK diff --git a/src/cg/cg3600b.uml b/src/cg/cg3600b.uml index aa4d3f58e..cb569b939 100755 --- a/src/cg/cg3600b.uml +++ b/src/cg/cg3600b.uml @@ -27,7 +27,11 @@ END ENDPAGE +#ifdef CONT_SEP +PAGE "Mastrini contabilità separata" 0 0 0 2 +#else PAGE "Mastrini" 0 0 0 2 +#endif NUMBER F_GRUPPO 3 BEGIN