cg1600.cpp    Corretto MI3557 stampa solo conti movimentati
cg5200a.uml   Aggiustata dimensione di un groupbox
cg2101.cpp    Tolto TDate& dai metodi write, rewrite e remove
cg2101.h      Tolto TDate& dai metodi write, rewrite e remove
              ATTENZIONE: Da Giugno la prima nota non cancellava le
              righe iva e contabili!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
git-svn-id: svn://10.65.10.50/trunk@5602 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
	
			
		
			
				
	
	
		
			3993 lines
		
	
	
		
			118 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			3993 lines
		
	
	
		
			118 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| //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 <mask.h>
 | |
| #include <progind.h>
 | |
| #include <printapp.h>
 | |
| #include <sort.h>
 | |
| #include <tabutil.h>
 | |
| #include <utility.h>
 | |
| 
 | |
| #include <mov.h>
 | |
| #include <rmov.h>
 | |
| #include <rmoviva.h>
 | |
| #include <pconti.h>
 | |
| #include <comuni.h>
 | |
| #include <clifo.h> 
 | |
| #include <attiv.h>
 | |
| #include <causali.h>
 | |
| #include <saldi.h>
 | |
| #include <nditte.h>
 | |
| #include <anagr.h>
 | |
| 
 | |
| #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 my_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;
 | |
|   };
 | |
| 
 | |
|   cli_for* _cf;
 | |
|   TSort  * _sort;
 | |
| 
 | |
|   TRelation* _rel;
 | |
|   TCursor  * _cur;
 | |
|   TProgind * _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;
 | |
|   TTable* _esc;  
 | |
|   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;
 | |
|   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;
 | |
|   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; 
 | |
|   int  _stampa_mov_prov;
 | |
| 
 | |
|   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,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);
 | |
|   
 | |
|   TStampa_bilanci() {}
 | |
| };
 | |
| 
 | |
| HIDDEN inline TStampa_bilanci& app() { return (TStampa_bilanci&)main_app(); }
 | |
| 
 | |
| TDate InizioEsercizio(int anno)
 | |
| {
 | |
| /*
 | |
|   TTable TabEs ("ESC");
 | |
|   TString16 codtab;
 | |
|   TDate inizio_es;
 | |
| 
 | |
|   TabEs.zero();
 | |
|   codtab.format ("%04d", anno);
 | |
|   TabEs.put ("CODTAB", codtab);
 | |
|   TabEs.read();
 | |
|   if (TabEs.good())
 | |
|     inizio_es= TabEs.get_date ("D0");
 | |
| 
 | |
|   return inizio_es;
 | |
| */
 | |
|   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("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;
 | |
|   TMask& m = f.mask();
 | |
|   
 | |
|   if (k == K_SPACE)
 | |
|   {
 | |
|     int tipo_stampa;
 | |
|     int anno     = m.get_int(F_ANNO);
 | |
|     int bilancio = m.get_int(F_BILANCIO);
 | |
|     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 ( bilancio == 1 || bilancio ==2)
 | |
|       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);
 | |
|       }
 | |
| 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);
 | |
|     }
 | |
| }   
 | |
|     
 | |
|     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().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 ("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 ("La data limite e' obbligatoria");
 | |
|           return FALSE;
 | |
|         }
 | |
|         long anno = app().date2esc(datalim);
 | |
|         if (anno == 0)
 | |
|         { 
 | |
|           f.error_box ("La data limite deve appartenere ad un esercizio attivo della ditta");
 | |
|           return FALSE;
 | |
|         }
 | |
|         f.mask().set(F_ANNO,anno); 
 | |
|       }
 | |
|   }    
 | |
|   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().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("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("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("Le date devono appartenere ad uno stesso esercizio attivo della ditta"); 
 | |
|               return FALSE;
 | |
|             } 
 | |
|             if (from > data)
 | |
|             {
 | |
|               f.error_box("La data limite inferiore non puo' essere maggiore della data limite superiore");
 | |
|               return FALSE;
 | |
|             }
 | |
|             //f.mask().set(F_ANNO, anno);
 | |
|           }     
 | |
|         }   
 | |
|       }  
 | |
|     }
 | |
|   }         
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TStampa_bilanci::my_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);
 | |
|       //f.mask().show (F_STAMPAMPROV);
 | |
|     }
 | |
|     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);
 | |
|       //f.mask().show (F_STAMPAMPROV);
 | |
|     }    
 | |
|     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().hide (F_STAMPAMPROV);
 | |
|       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_STAMPAMPROV);
 | |
|       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, 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(PCN_TMCF)[0];
 | |
|       indbil_conto = _pcn->get_int (PCN_INDBIL);
 | |
|       
 | |
|       if (indbil_conto <= 0)  // Warning per Roberto!
 | |
|       {
 | |
|         yesnofatal_box("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
 | |
|       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;
 | |
| 
 | |
|     //error_box ("saldo = %s", saldo.string()); 
 | |
| 
 | |
|     if (saldo != ZERO)
 | |
|       saldo = compensazione(compensa, indbil_conto, saldo);    
 | |
|     
 | |
|     if (_indbil == 1 || _indbil == 2)
 | |
|     {
 | |
|       //real app = sld.saldoini(); 
 | |
|       //bool flag = sld.flagprec(); 
 | |
|       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
 | |
|       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;
 | |
| 
 | |
|   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 ( (((_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
 | |
|           {
 | |
|            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(PCN_TMCF)[0];
 | |
|       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) )
 | |
|           if (saldo_conto == 0)
 | |
|             continue; 
 | |
|         if (esiste_sc)
 | |
|         {
 | |
|           _gp = g;
 | |
|           _cp = c;
 | |
|           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; 
 | |
|       }   
 | |
|     }
 | |
|     
 | |
|     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)                  
 | |
|            {
 | |
|             real ss = saldi.get_real(SLD_SALDO);
 | |
|             if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5)
 | |
|               if (ss == ZERO && _annoes != 0)
 | |
|               {
 | |
|                 saldo_iniziale += sld.saldofin_esprec(_annoes,g,c,s);
 | |
|                 //modifica del 21/11/95
 | |
|                 if (saldo_iniziale > ZERO)
 | |
|                   _saldo_ini_dare = saldo_iniziale;
 | |
|                 else _saldo_ini_avere = -saldo_iniziale;
 | |
|                 //fine
 | |
|               }  
 | |
|            }
 | |
|           } 
 | |
|         }
 | |
|         if (!movimentato)  //_mov_ap e' di sicuro FALSE
 | |
|           if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5)
 | |
|             if (_annoes != 0)
 | |
|             {      
 | |
|               saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s);
 | |
|               //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)
 | |
|       //  saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere;
 | |
|       //movimentato = calcola(g,c,s);
 | |
| 
 | |
|       if (movimentato || _stampav != 1)
 | |
|       { 
 | |
|         //saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere;
 | |
|         
 | |
|         _nuovo_tot_saldo_d += _mov_periodo_dare;
 | |
|         _nuovo_tot_saldo_a += _mov_periodo_avere;
 | |
|         //modifica del 21/11/1995
 | |
|         /*
 | |
|         if (saldo_iniziale > ZERO)
 | |
|           _nuovo_tot_saldo_d += saldo_iniziale;
 | |
|         else
 | |
|         {
 | |
|           real app = -saldo_iniziale;
 | |
|           _nuovo_tot_saldo_a += app;
 | |
|         }
 | |
|         */
 | |
|         _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
 | |
| { 
 | |
|   movimentato = sld.ultima_immissione_verifica(_annoes,g,c,s,indbil_conto,_stampa_mov_prov);
 | |
|   
 | |
|   //modifica del 31/03/95
 | |
|   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);
 | |
|         if (_stampav == 1 && sld.significativo())
 | |
|           movimentato = TRUE;
 | |
|       }       
 | |
|     }                       
 | |
|   }  
 | |
|   //fine modifica
 | |
|   
 | |
|   if (movimentato || _stampav != 1)
 | |
|   {
 | |
|     _mov_periodo_dare  = sld.prgdare();
 | |
|     _mov_periodo_avere = sld.prgavere();
 | |
|     _prg_prec_dare     = ZERO;
 | |
|     _prg_prec_avere    = ZERO;
 | |
|     
 | |
|     saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere;
 | |
|   }  
 | |
| }
 | |
| 
 | |
| if (movimentato || _stampav != 1)
 | |
|   if (!(saldo_finale == 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 (saldo_iniziale < ZERO) 
 | |
|     _saldo_ini_conto_avere += saldo_iniziale;
 | |
|   else
 | |
|     _saldo_ini_conto_dare  += saldo_iniziale;
 | |
|   */
 | |
|   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_PDARESCA,_saldo_ini_dare);
 | |
|       //_tmp_saldi_att->put(SLD_PAVERESCA,_saldo_ini_avere); 
 | |
|       _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
 | |
|         //_tmp_saldi_att->put(SLD_PDARESCA,saldo_iniziale);
 | |
|       else if (saldo_iniziale < ZERO)
 | |
|       {
 | |
|         saldo_iniziale = -saldo_iniziale; 
 | |
|         //_tmp_saldi_att->put(SLD_PAVERESCA,saldo_iniziale);
 | |
|         _tmp_saldi_att->put(SLD_PAVEREPRO,saldo_iniziale);     // W96SALDI del 05-06-96
 | |
|       }
 | |
|      } 
 | |
|     }
 | |
|     else if (_datada > _dataini)
 | |
|     {
 | |
|       //_tmp_saldi_att->put(SLD_PDARESCA,_prg_prec_dare);
 | |
|       //_tmp_saldi_att->put(SLD_PAVERESCA,_prg_prec_avere);
 | |
|       _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
 | |
| bool TStampa_bilanci::calcola(int g, int c, long s) 
 | |
| {
 | |
|   char sezione, provvis;
 | |
|   real    importo;
 | |
|   int     annoe;
 | |
|   long    num_reg;
 | |
|   TDate   data_reg, data, datacomp;
 | |
|   bool    conto_mov = FALSE;
 | |
|   TLocalisamfile rmov(LF_RMOV);
 | |
|   TLocalisamfile mov(LF_MOV);
 | |
|   
 | |
|   TDecoder causali(LF_CAUSALI, CAU_MOVAP);
 | |
|   
 | |
|   _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;
 | |
|   
 | |
|   rmov.setkey(2);
 | |
|   rmov.zero();
 | |
|   rmov.put(RMV_GRUPPO,g);
 | |
|   if (c != 0)
 | |
|     rmov.put(RMV_CONTO,c);
 | |
|   if (s != 0)
 | |
|     rmov.put(RMV_SOTTOCONTO,s);
 | |
|   const TRectype rec(rmov.curr());
 | |
| 
 | |
|   for (int err = rmov.read(_isgteq); err == NOERR; err = rmov.next())
 | |
|   {
 | |
|     if (rmov.curr() != rec) 
 | |
|       break;
 | |
|     
 | |
|     annoe    = rmov.get_int(RMV_ANNOES);
 | |
|     data     = rmov.get_date(RMV_DATAREG);
 | |
|     num_reg  = rmov.get_long(RMV_NUMREG);
 | |
|     
 | |
|     mov.setkey(1);
 | |
|     mov.put(MOV_NUMREG, num_reg);
 | |
|     if (mov.read() != NOERR)
 | |
|       mov.zero();
 | |
| 
 | |
|     provvis = mov.get_char(MOV_PROVVIS);
 | |
|     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;
 | |
|     }
 | |
|     
 | |
|     sezione   = rmov.get_char(RMV_SEZIONE);
 | |
|     importo   = rmov.get_real(RMV_IMPORTO);
 | |
|     
 | |
|     if (_annoes == 0)
 | |
|       data_reg = data;
 | |
|     else 
 | |
|       data_reg = datacomp;
 | |
|     
 | |
|     if (importo == 0)
 | |
|       continue;
 | |
|     
 | |
|     //calcolo i movimenti del periodo
 | |
|     if ( data_reg >= _datada && data_reg <= _dataa)
 | |
|       if ((causap == 'A' && _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);
 | |
|       }      
 | |
|     
 | |
|     //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 >= _dataini) && (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;
 | |
|       }
 | |
|   }
 | |
|   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;
 | |
|   long s;
 | |
|   int anno;
 | |
|   
 | |
|   if (_tipo_stampa1 == 1)
 | |
|     anno = _annoapp;
 | |
|   else anno = _annoes;   
 | |
| 
 | |
|   _lista = new TSaldi_list(g, c, anno);
 | |
|   TRecnotype items = _lista->items();
 | |
|   
 | |
|   for (int i = 0; i < items; i++)
 | |
|   {
 | |
|     const TRectype* r = _lista->saldi();
 | |
|     if (r == NULL) break;
 | |
|     
 | |
|     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
 | |
|     { 
 | |
|       /*
 | |
|          if ( !calcola(g,c,s) ) //il conto non e' movimentato
 | |
|          if (_stampav == 1 || _stampav == 3) //per i C/F anche se seleziono -tutti i conti, voglio solo quelli movimentati
 | |
|          continue;                         
 | |
|       */
 | |
|       //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)    
 | |
|         {
 | |
|          //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);    
 | |
|           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
 | |
|             real ss = saldi.get_real(SLD_SALDO); 
 | |
|             if (ib == 1 || ib == 2 || ib == 5)
 | |
|               if (ss == ZERO && _annoes != 0) //competenza!!!
 | |
|               {
 | |
|                 saldo_iniziale += sld.saldofin_esprec(_annoes,g,c,s);
 | |
|                 //modifica del 21/11/1995
 | |
|                 if (saldo_iniziale > ZERO)
 | |
|                   _saldo_ini_dare = saldo_iniziale;
 | |
|                 else _saldo_ini_avere = -saldo_iniziale;  
 | |
|                 //fine
 | |
|               }  
 | |
|           }
 | |
|          }        
 | |
|         }
 | |
|         if (!movimentato)
 | |
|           if (ib == 1 || ib == 2 || ib == 5)
 | |
|             if (_annoes != 0) //cioe' se sto ragionando per competenza      
 | |
|             {
 | |
|               saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s);
 | |
|               //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
 | |
|       /*
 | |
|       if (saldo_iniziale > ZERO)
 | |
|         _nuovo_tot_saldo_d += saldo_iniziale;
 | |
|       else
 | |
|       {
 | |
|         real app = -saldo_iniziale;
 | |
|         _nuovo_tot_saldo_a += app;
 | |
|       }                        
 | |
|       */ 
 | |
|       _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
 | |
|       { 
 | |
|         //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)
 | |
|           {
 | |
|             //if (_stampav == 1)
 | |
|             //  continue;   
 | |
|             //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);
 | |
|               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;
 | |
|         
 | |
|         saldo_finale       = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere;
 | |
|         
 | |
|         if (saldo_finale == ZERO)
 | |
|           if (_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)
 | |
|     {
 | |
|       _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_PDARESCA,_saldo_ini_dare);
 | |
|          //_tmp_saldi_att->put(SLD_PAVERESCA,_saldo_ini_avere);
 | |
|          _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
 | |
|            //_tmp_saldi_att->put(SLD_PDARESCA,saldo_iniziale);
 | |
|          else if (saldo_iniziale < ZERO)
 | |
|          {
 | |
|           saldo_iniziale = -saldo_iniziale; 
 | |
|           //_tmp_saldi_att->put(SLD_PAVERESCA,saldo_iniziale);
 | |
|           _tmp_saldi_att->put(SLD_PAVEREPRO,saldo_iniziale);     // W96SALDI del 05-06-96
 | |
|          } 
 | |
|         }
 | |
|       }
 | |
|       else if (_datada > _dataini)
 | |
|       {
 | |
|         //_tmp_saldi_att->put(SLD_PDARESCA,_prg_prec_dare);
 | |
|         //_tmp_saldi_att->put(SLD_PAVERESCA,_prg_prec_avere);
 | |
|         _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()
 | |
| {
 | |
|   _cf   = new cli_for;
 | |
|   _sort = new TSort(sizeof(cli_for));
 | |
|   
 | |
|   if (_ordinamento == 1)
 | |
|   {
 | |
|     _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);
 | |
|     _sort->addsortkey ((char*)&(_cf->codcf)-(char*)&(_cf->tipocf),6);
 | |
|   }
 | |
|   else if (_ordinamento == 2)
 | |
|   {
 | |
|     _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);
 | |
|     _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)
 | |
| {
 | |
|   _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)
 | |
| {
 | |
|   TSaldo sld;
 | |
|   TLocalisamfile saldi(LF_SALDI, FALSE);
 | |
|   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;
 | |
| 
 | |
|   int anno;
 | |
|   if (_tipo_stampa1 == 1)
 | |
|     anno = _annoapp;
 | |
|   else anno = _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;
 | |
|      }
 | |
|      
 | |
|      TEsercizi_contabili ese;
 | |
|      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 /* && _stampac!=1 */)
 | |
|             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);
 | |
|                   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)                  
 | |
|            {
 | |
|             real s = saldi.get_real(SLD_SALDO); 
 | |
|             if (_stampa_mov_prov != 3)
 | |
|               if (_indbil == 1 || _indbil == 2 || _indbil == 5)
 | |
|                 if (s == ZERO && _annoes != 0) //competenza!!!
 | |
|                 {
 | |
|                   saldo_iniziale += sld.saldofin_esprec(_annoes,g,c,codcf);
 | |
|                   //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;
 | |
|           }    
 | |
|         }
 | |
|         //if (saldo_finale == ZERO)
 | |
|         //   if (_stampac == 2)
 | |
|         //      continue;
 | |
|         
 | |
|         //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);
 | |
|         
 | |
|         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;
 | |
|           
 | |
|           saldo_finale       = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere;
 | |
|         }
 | |
|         //if (saldo_finale == ZERO)
 | |
|         //  if (_stampac == 2)
 | |
|         //     continue;
 | |
|        }
 | |
|        if (movimentato || _stampac != 1 || saldo_iniziale != ZERO)
 | |
|          if (!(saldo_finale == 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 TProgind(nitems,"Elaborazione in corso... prego attendere",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);
 | |
| }
 | |
| 
 | |
| 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 POINTLESS_PICTURE "###############"
 | |
| #define 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 ("####.###.###.###");
 | |
| 
 | |
|     //if ( (_verifica == 3) && (_ordinamento == 1) )
 | |
|     //   _tmp_saldi_att->setkey(2);
 | |
|     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;
 | |
|   }
 | |
|   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)
 | |
| {
 | |
|   char dep = '*';
 | |
|   
 | |
|   if (!file1)
 | |
|     if (_cambiato_conto_1)
 | |
|     {
 | |
|       set_row(_i,"@68g%c", dep);
 | |
|       _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,"@68g%c", dep);
 | |
|       _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;
 | |
|     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++,"@29gATTIVITA'@94gPASSIVITA'");
 | |
|       set_row(_i++,"@29g---------@94g----------");
 | |
|       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++,"@29gCOSTI@94gRICAVI");
 | |
|         set_row(_i++,"@29g-----@94g------");
 | |
|         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++,"@59gCONTI D'ORDINE");
 | |
|             set_row(_i++,"@59g--------------");
 | |
|             set_row(_i++, dep);
 | |
|             if (_eof5 && _eof6)
 | |
|             {
 | |
|               _stampato = TRUE;
 | |
|               //stampa_totali();
 | |
|               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();
 | |
|               stampa_totali_uno(_prg_inidare_ord,_prg_iniavere_ord); 
 | |
|         }   
 | |
|       }  
 | |
|     }
 | |
|   }
 | |
|   else //stampa bilancio di verifica
 | |
|   {
 | |
|     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",(const char*)_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",(const char*)_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",(const char*)_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 > 0)
 | |
|           app = 'D';
 | |
|         else if (_saldofinale_succ < 0)
 | |
|         {
 | |
|           _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 (_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 if (app == 'D')
 | |
|             {
 | |
|               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!%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
 | |
|             {
 | |
|               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!@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 > 0)
 | |
|           app = 'D';
 | |
|         else if (_saldofinale < 0)
 | |
|         {
 | |
|           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 (_datada == _dataini) //colonna saldo iniziale
 | |
|   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,"***@8gTOTALE GENERALE@46g!%r@64g%r@80g!%r@96g%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,"***@8gTOTALE GENERALE@46g!%r@64g%r@80g!%r@100g%r@114g!%r@148g!",&_saldo_dare_tot,&_saldo_avere_tot,
 | |
|               &_mov_dare_tot,&_mov_avere_tot,&_saldo_finale_tot);
 | |
|     }
 | |
|     else 
 | |
|     {
 | |
|         set_row(r,"***@8gTOTALE GENERALE@46g!%r@64g%r@80g!%r@100g%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,"@1g****** ********@17gTOTALE GENERALE@46g!%r@64g%r@80g!%r@96g%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,"@1g****** ********@17gTOTALE CON SALDI INIZIALI@46g!@80g!%r@96g%r@114g!",&_nuovo_tot_saldo_d,&_nuovo_tot_saldo_a);
 | |
|          else set_row(r,"@1g****** ********@17gTOTALE CON MOVIM. DI APERTURA@46g!@80g!%r@96g%r@114g!",&_nuovo_tot_saldo_d,&_nuovo_tot_saldo_a);
 | |
|          //fine
 | |
|       }  
 | |
|     }
 | |
|     else
 | |
|     {
 | |
|       if (app == 'D')
 | |
|       {
 | |
|         set_row(r++,"@1g****** ********@17gTOTALE GENERALE@46g!%r@64g%r@80g!%r@100g%r@114g!%r@148g!",&_saldo_dare_tot,
 | |
|                 &_saldo_avere_tot,&_mov_dare_tot,&_mov_avere_tot,
 | |
|                 &_saldo_finale_tot);
 | |
|       }
 | |
|       else
 | |
|       {       
 | |
|         set_row(r++,"@1g****** ********@17gTOTALE GENERALE@46g!%r@64g%r@80g!%r@100g%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,"@1g****** ********@17gTOTALE CON SALDI INIZIALI@46g!@80g!%r@100g%r@114g!@148g!",&_nuovo_tot_saldo_d,&_nuovo_tot_saldo_a);
 | |
|          else 
 | |
|            set_row(r,"@1g****** ********@17gTOTALE CON MOVIM. DI APERTURA@46g!@80g!%r@100g%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; 
 | |
|   _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 (_tot_dare.string(TOTAL_PICTURE));
 | |
|   TString bal (_tot_avere.string(TOTAL_PICTURE));  
 | |
|   set_row(_i++, "@39gTOTALE@48g%s@102gTOTALE@112g%s", 
 | |
|           (const char*)pal, (const char*)bal);        
 | |
|   TString sb (sbilancio.string(TOTAL_PICTURE));     
 | |
|   TString pa (pareggio.string(TOTAL_PICTURE));        
 | |
|   if (_tot_dare > _tot_avere)
 | |
|   {
 | |
|     set_row(_i++, "@80gSBILANCIO ESERCIZIO IN CORSO@112g%s", (const char*)sb);
 | |
|     set_row(_i++, "@91gTOTALE A PAREGGIO@112g%s",(const char*)pa);
 | |
|   }
 | |
|   if (_tot_dare < _tot_avere)
 | |
|   {
 | |
|     set_row(_i++, "@17gSBILANCIO ESERCIZIO IN CORSO@48g%s", (const char*)sb);
 | |
|     set_row(_i++, "@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)
 | |
| {
 | |
|   const TString16 dep;
 | |
|   real pareggio;
 | |
|   real sbilancio = _tot_dare - r1 - (_tot_avere - r2);
 | |
|   real sbilprec = r2 - r1;
 | |
|   /*
 | |
|      if (sbilancio > ZERO)      //ho un utile => va stampato tra le passivita'
 | |
|      {
 | |
|      sbilprec = -sbilprec;
 | |
|      pareggio = _tot_avere + sbilancio + sbilprec; 
 | |
|      }  
 | |
|      else if (sbilancio < ZERO) //ho una perdita => va stampato tra le attivita' cambiato di segno
 | |
|      {
 | |
|      sbilancio = -sbilancio;
 | |
|      pareggio  = _tot_dare + sbilancio + sbilprec;
 | |
|      } 
 | |
|   */
 | |
|   if (_prima_volta) //ho finito di stampare le attivita'/passivita'
 | |
|     _prima_volta   = FALSE;
 | |
|   else
 | |
|     _seconda_volta = FALSE; 
 | |
|   _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 (_tot_dare.string(TOTAL_PICTURE));
 | |
|   TString bal (_tot_avere.string(TOTAL_PICTURE));    
 | |
|   set_row(_i++, "@39gTOTALE@48g%s@102gTOTALE@112g%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 (sbilprec.string(TOTAL_PICTURE));
 | |
|       set_row(_i++, "@83gSBILANCIO ESERCIZIO PRECEDENTE@112g%s", 
 | |
|               (const char*)sb);      
 | |
|     } 
 | |
|     TString pal (sbilancio.string(TOTAL_PICTURE));
 | |
|     TString bal (pareggio.string(TOTAL_PICTURE));
 | |
|     set_row(_i++, "@80gSBILANCIO ESERCIZIO IN CORSO@112g%s", 
 | |
|             (const char*)pal);
 | |
|     set_row(_i++, "@91gTOTALE A PAREGGIO@112g%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 (sbilprec.string(TOTAL_PICTURE));
 | |
|       set_row(_i++, "@15gSBILANCIO ESERCIZIO PRECEDENTE@48g%s", 
 | |
|              (const char*)sb);
 | |
|     }
 | |
| 
 | |
|     TString pal (sbilancio.string(TOTAL_PICTURE));
 | |
|     TString bal (pareggio.string(TOTAL_PICTURE));
 | |
|     set_row(_i++, "@17gSBILANCIO ESERCIZIO IN CORSO@48g%s", 
 | |
|            (const char*)pal);
 | |
|     set_row(_i++, "@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 (sbilprec.string(TOTAL_PICTURE));
 | |
|       pareggio = _tot_avere + sbilprec;
 | |
|       TString bal (pareggio.string(TOTAL_PICTURE));
 | |
|       set_row(_i++, "@83gSBILANCIO ESERCIZIO PRECEDENTE@112g%s", 
 | |
|               (const char*)pal);
 | |
|       set_row(_i++, "@96gTOTALE A PAREGGIO@112g%s", (const char*)bal);
 | |
|     }
 | |
|     else if (sbilprec < ZERO)
 | |
|     {
 | |
|      sbilprec = -sbilprec;
 | |
|      pareggio = _tot_dare + sbilprec;
 | |
|      TString pal (sbilprec.string(TOTAL_PICTURE));
 | |
|      TString bal (pareggio.string(TOTAL_PICTURE));
 | |
|      set_row(_i++, "@15gSBILANCIO ESERCIZIO PRECEDENTE@48g%s", (const char*)pal);
 | |
|      set_row(_i++, "@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)
 | |
| { 
 | |
|   char dep = '*';
 | |
|   
 | |
|   if (_codici) //sono stampate solo le descrizioni dei conti
 | |
|   {
 | |
|     if (!_totali)
 | |
|     {
 | |
|       if (c != 0 && s == 0)
 | |
|         set_row(_i, "%-.44s @44g *** @49g%r @68g%c", desc, &saldo, dep);
 | |
|       else 
 | |
|         set_row(_i, "%-.48s @49g%r @68g%c", desc, &saldo, dep);
 | |
|     }
 | |
|     else if ( !(c == 0 && s == 0) )  //se cioe' non e' un gruppo
 | |
|     {
 | |
|       if (s == 0)  //se e' un conto
 | |
|         set_row(_i, "%-.44s @44g *** @49g%r @68g%c", desc, &saldo, dep);
 | |
|       else 
 | |
|         set_row(_i, "%-.48s @49g%r @68g%c", desc, &saldo, dep);
 | |
|     }  
 | |
|   }
 | |
|   else
 | |
|   {
 | |
|     if (_totali && c == 0 && s == 0l)
 | |
|       return;
 | |
|     else if ( c == 0 && s == 0l )  
 | |
|     {
 | |
|       set_row(_i, "%3d ", g);
 | |
|       set_row(_i, "@15g%-.31s @49g%r @68g%c", desc, &saldo, dep); 
 | |
|     }
 | |
|     else if (s == 0l)
 | |
|     {
 | |
|       set_row(_i, "%3d ", g);
 | |
|       set_row(_i, "%3d ", c);
 | |
|       set_row(_i, "@15g%-.31s @49g%r @68g%c", desc, &saldo, dep);
 | |
|     }
 | |
|     else
 | |
|     {
 | |
|       set_row(_i, "%3d ", g);
 | |
|       set_row(_i, "%3d ", c);
 | |
|       set_row(_i, "%6ld ", s); 
 | |
|       set_row(_i, "@15g%-.31s @49g%r @68g%c", desc, &saldo, dep);
 | |
|     }
 | |
|   }
 | |
| }
 | |
| 
 | |
| 
 | |
| // 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)
 | |
| { 
 | |
|   char dep = '*';
 | |
|   
 | |
|   if (_codici) //sono stampate solo le descrizioni dei conti 
 | |
|   {
 | |
|     if (!_totali) 
 | |
|     {
 | |
| //      if (c != 0 && s == 0)
 | |
| //        set_row(_i, "@68g%c@69g%-.43s @114g%r", dep, desc, &saldo);
 | |
| //      else 
 | |
|         set_row(_i, "@68g%c@69g%-.47s @114g%r", dep, desc, &saldo);
 | |
|     }
 | |
|     else if ( !(c == 0 && s == 0) ) 
 | |
|     {
 | |
| //      if (s == 0)  //se e' un conto
 | |
| //        set_row(_i, "@68g%c @69g%-.43s @114g%r", dep, desc, &saldo); 
 | |
| //      else 
 | |
|         set_row(_i, "@68g%c @69g%-.47s @114g%r", dep, desc, &saldo); 
 | |
|     }  
 | |
|   }  
 | |
|   else
 | |
|   {
 | |
|     if (_totali && c == 0 && s == 0l)
 | |
|       return;
 | |
|     else if ( c == 0 && s == 0l )
 | |
|     {  
 | |
|       set_row(_i, "@68g%c@69g%3d ", dep, g);
 | |
|       set_row(_i, "@84g%-.30s @114g%r", desc, &saldo);
 | |
|     }
 | |
|     else if (s == 0l)
 | |
|     {
 | |
|       set_row(_i, "@68g%c@69g%3d ", dep, g);
 | |
|       set_row(_i, "%3d", c);
 | |
|       set_row(_i, "@84g%-.30s @114g%r", desc, &saldo);
 | |
|     }
 | |
|     else
 | |
|     {
 | |
|       set_row(_i, "@68g%c@69g%3d ", dep, g);
 | |
|       set_row(_i, "%3d ", c);
 | |
|       set_row(_i, "%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, FALSE); //il parametro a false permette di usare un record corrente del file saldi differente a quello del file tmp
 | |
| 
 | |
|   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!                
 | |
| const char* TStampa_bilanci::DescrizioneConto(int g, int c, long s, char tipocf)
 | |
| {       
 | |
|   TString80 ragsoc;
 | |
|   const char* desc = NULL;
 | |
|   TLocalisamfile pconti(LF_PCON,FALSE);
 | |
|   TLocalisamfile clifo (LF_CLIFO);
 | |
| 
 | |
|   pconti.zero();
 | |
|   pconti.put(PCN_GRUPPO, g);
 | |
|   if (c != 0)
 | |
|     pconti.put(PCN_CONTO, c);
 | |
|   if (s != 0)
 | |
|     pconti.put(PCN_SOTTOCONTO, s);
 | |
|   pconti.read();
 | |
|   if (pconti.good())
 | |
|     tmp = pconti.get(PCN_DESCR);
 | |
|   else
 | |
|   {
 | |
|     clifo.setkey(1); //occorre settare la chiave 1, anche se di solito e' di default, poiche' nella create il file clifo e' stato aperto con la chiave 3  
 | |
|     clifo.zero();
 | |
|     clifo.put(CLI_CODCF, s);
 | |
|     clifo.put(CLI_TIPOCF,tipocf);
 | |
|     if (clifo.read() == NOERR)
 | |
|     {
 | |
|       char tipoa = clifo.get_char("TIPOAPER");
 | |
|       if (tipoa == 'F')  //persona fisica
 | |
|       {
 | |
|         TString80 cognome, nome;
 | |
|         ragsoc = clifo.get("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("RAGSOC");
 | |
|       tmp = desc;
 | |
|     }   
 | |
|     else
 | |
|       tmp = "";
 | |
|   }
 | |
|   return tmp;
 | |
| }  
 | |
| 
 | |
| bool TStampa_bilanci::user_create()
 | |
| {
 | |
|   _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);
 | |
|   _esc                  = new TTable("ESC");
 | |
|   _d                    = new TParagraph_string("",29);  
 | |
|   _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 _esc;
 | |
|   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()
 | |
| {
 | |
|   TLocalisamfile pconti(LF_PCON);
 | |
|   TToken_string gc(10);
 | |
|   
 | |
|   for (pconti.first(); !pconti.eof(); pconti.next())
 | |
|   {
 | |
|     gc.restart();
 | |
|     int  gruppo = pconti.get_int(PCN_GRUPPO);
 | |
|     int  conto  = pconti.get_int(PCN_CONTO);
 | |
|     long sottoconto = pconti.get_long(PCN_SOTTOCONTO);
 | |
|     if ( (sottoconto == 0l) && (conto != 0) ) //si tratta di un conto
 | |
|     {
 | |
|       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);
 | |
|       }   
 | |
|     } 
 | |
|   } 
 | |
| }
 | |
| 
 | |
| bool TStampa_bilanci::set_print(int)
 | |
| {
 | |
|   TMask m ("cg1500a");
 | |
|   KEY tasto;
 | |
|   m.set_handler (F_VERIFICA,   my_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); 
 | |
| 
 | |
|   tasto = m.run();
 | |
|   if (tasto == 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);
 | |
|     _noseparator     = m.get_bool(F_SEPARATOR);
 | |
|     
 | |
|     if (_bilancio == 1)
 | |
|     {
 | |
|       _prog = new TProgind(_pcn->items(),"Elaborazione in corso... prego attendere",FALSE);
 | |
|       _totali      = m.get_bool(F_TOTALI);
 | |
|       _codici      = m.get_bool(F_CODICI);
 | |
|       _saldo       = m.get_bool(F_SALDO);
 | |
|       _tipo_stampa = atoi(m.get(F_STAMPA));
 | |
|       
 | |
|       if (_tipo_stampa == 1)
 | |
|       {
 | |
|         if (_annoes != 0)
 | |
|           _dataini = InizioEsercizio(_annoes);
 | |
|         else  
 | |
|           _dataini = _inizioEs;
 | |
|         _datalim = m.get(F_DATALIM);
 | |
|         //_stampa_mov_prov = (bool)(m.get(F_STAMPAMPROV) == "X");
 | |
|       }
 | |
|       bil_sez_contr();
 | |
|     }
 | |
|     else
 | |
|     {
 | |
|       printer().footerlen(5);
 | |
|       _stampa_width = atoi(m.get(F_MODULO));
 | |
|       if (_stampa_width == 1) 
 | |
|         _stampa_width = 132;
 | |
|       else _stampa_width = 148; //perche' questo e' in realta' il margine dx (vedi es. di stampa AS/400)
 | |
|       _verifica = atoi(m.get(F_VERIFICA));
 | |
|       if ( (_verifica == 1)||(_verifica == 2) )
 | |
|         _prog = new TProgind(_pcn->items(),"Elaborazione in corso... prego attendere",FALSE);
 | |
|       _tipo_stampa1 = atoi(m.get(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))
 | |
|       {
 | |
|         _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();
 | |
|         _sort->endsort();
 | |
|         delete _cf;
 | |
|       }
 | |
|     }
 | |
|     delete _prog;
 | |
|     return TRUE;
 | |
|   }
 | |
|   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, "Ditta %s %s %s %s %s %s", (const char*)codice_ditta,
 | |
|               (const char*)_ragsoc, (const char*)_viafis,
 | |
|               (const char*)_cap, (const char*)_comunefis,
 | |
|               (const char*)_provfis);
 | |
|   r++;
 | |
|   printer().setdate(_data);
 | |
|   riga = "Data @<  Pag. @#";
 | |
|   riga.right_just(_stampa_width-6);
 | |
| 
 | |
|   riga.overwrite (format ("Partita iva %s Codice fiscale %s", (const char*)_paiva, (const char*)_cofi));
 | |
|   set_header (r, "%s", (const char*) riga);
 | |
|   r++;
 | |
| 
 | |
|   return r; 
 | |
| }
 | |
| 
 | |
| void 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, "STAMPA BILANCIO A SEZIONI CONTRAPPOSTE");
 | |
|     if (_tipo_stampa == 1)
 | |
|     {
 | |
|       data_da   = _dataini.string();
 | |
|       data      = _datalim.string();     
 | |
|       set_header(r,"@41gdalla data %s alla data %s", (const char*) data_da, 
 | |
|                  (const char*) data);
 | |
|     } 
 | |
|     else if (_tipo_stampa == 2)
 | |
|       set_header(r,"@41gall'ultima immissione Es. %d", _annoes);
 | |
|     //else set_header(r, "@41gall'ultima immissione Es. Precedente"); 
 | |
|     
 | |
|     //modifica del 20/04/1995  
 | |
|     {
 | |
|       TString d1(InizioEsercizio(_annoes).string());
 | |
|       TString d2(FineEsercizio(_annoes).string());
 | |
|       set_header(r,"@84gEsercizio %s %s", (const char*)d1, (const char*)d2);   /**/  
 | |
|     }
 | |
|     r++;
 | |
|     riga.fill('-');
 | |
|     set_header(r, (const char*)riga);
 | |
|     r++;
 | |
|     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, "STAMPA BILANCIO DI VERIFICA");
 | |
|     else if (_verifica == 2)
 | |
|       set_header(r, "STAMPA SALDI DI MASTRO");
 | |
|     else
 | |
|     {
 | |
|       if (_situazione == "C")
 | |
|         set_header(r, "SITUAZIONE CONTABILE CLIENTI");
 | |
|       else if (_situazione == "F")
 | |
|         set_header(r, "SITUAZIONE CONTABILE FORNITORI");
 | |
|       else set_header(r,"SITUAZIONE CLIENTI/FORNITORI");
 | |
|     }
 | |
|     
 | |
|     if (_tipo_stampa1 == 1)
 | |
|     {
 | |
|       set_header(r,"@30gdalla data %s alla data %s", (const char*)datada,
 | |
|                  (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,"@74gEsercizio %s %s", (const char*)d1, (const char*)d2);   /**/  
 | |
|       }
 | |
|     }
 | |
|     else if (_tipo_stampa1 == 2)
 | |
|     {
 | |
|       set_header(r,"@36gall'ultima immissione Es. %d", _annoes);
 | |
|       //modifica del 20/04/1995
 | |
|       TString16 d1(InizioEsercizio(_annoes).string());
 | |
|       TString16 d2(FineEsercizio(_annoes).string());
 | |
|       set_header(r,"@72gEsercizio %s %s", (const char*)d1, (const char*)d2);   /**/  
 | |
|     }
 | |
|     
 | |
|     if ( (_verifica == 1)||(_verifica == 2) )
 | |
|     {
 | |
|       if (_stampav == 1)
 | |
|         set_header(r,"@107gTutti i conti movimentati");
 | |
|       else if (_stampav == 2)
 | |
|         set_header(r,"@107gConti con saldo <> 0");
 | |
|       else 
 | |
|         set_header(r,"@107gTutti i conti"); 
 | |
|     }
 | |
|     else 
 | |
|     {
 | |
|       if (_stampac == 1)
 | |
|         set_header(r,"@107gTutti i conti movimentati");
 | |
|       else 
 | |
|         set_header(r,"@107gConti con saldo <> 0");
 | |
|     }
 | |
|     r++;
 | |
| 
 | |
|     riga.fill('-');
 | |
|     set_header(r, (const char*)riga);
 | |
|     r++;
 | |
| 
 | |
|     if ( ((_datada == _dataini)&&(_tipo_stampa1 == 1))||(_tipo_stampa1 != 1) )
 | |
|     { 
 | |
|       if (_tipo_stampa1 == 1 && _datada == _dataini)
 | |
|         set_header(r,"@7g!@46g!@55gMOVIMENTI DI APERTURA@80g!@88gMOVIMENTI DEL PERIODO");  
 | |
|       else
 | |
|         set_header(r,"@7g!@46g!@58gSALDO INIZIALE@80g!@88gMOVIMENTI DEL PERIODO");
 | |
|     } 
 | |
|     else if (_tipo_stampa1 == 1)
 | |
|     {
 | |
|       set_header(r,"@7g!@46g!@55gPROGRESSIVI PRECEDENTI@80g!@88gMOVIMENTI DEL PERIODO");
 | |
|     }    
 | |
|     if ( (_verifica == 1)||(_verifica == 3) )
 | |
|       set_header(r,"@16g!");
 | |
| 
 | |
|     set_header(r,"@114g!");
 | |
|     if (_stampa_width != 132)          
 | |
|       set_header(r,"@129gSALDO@148g!");
 | |
|     r++;
 | |
|     
 | |
|     if ( (_verifica == 1)||(_verifica == 3) )
 | |
|     {   
 | |
|       set_header(r,"@2gcod. ! ultima !@46g!@47g%.67s@80g!@83g@114g!",(const char*)riga);
 | |
|       if (_stampa_width == 132)
 | |
|         set_header(r,"@121gSALDO");
 | |
|       else
 | |
|         set_header(r,"%.33s@148g!",(const char*)riga);
 | |
|       r++;  
 | |
|       
 | |
|       set_header(r,"@2gconto!  data  ! denominazione@46g!@53gDare@63g!@69gAvere@80g!@87gDare@97g!@103gAvere@114g!");
 | |
|       if (_stampa_width != 132)
 | |
|         set_header(r,"@121gDare@131g!@137gAvere@148g!");
 | |
|       r++;  
 | |
|     }
 | |
|     else
 | |
|     {                                                              
 | |
|       set_header(r,"@2gcod. !@46g!@47g%.67s@80g!@83g@114g!",(const char*)riga);
 | |
|       if (_stampa_width == 132)
 | |
|         set_header(r,"@121gSALDO");
 | |
|       else
 | |
|         set_header(r,"%.33s@148g!",(const char*)riga);
 | |
|       r++;
 | |
|       
 | |
|       set_header(r,"@1gmastro!descrizione@46g!@53gDare@63g!@69gAvere@80g!@87gDare@97g!@103gAvere@114g!");
 | |
|       if (_stampa_width != 132)
 | |
|         set_header(r, "@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, "Stampa bilanci");
 | |
|   return 0;
 | |
| }
 | |
| 
 |