#ifndef _77STBA_H
#define _77STBA_H

#include "77stq.h"

HIDDEN const int BASE_FORMLEN = 73;
HIDDEN const int BASE_PAGINE  = 4;

class TBase1 : public TDicForm
{
  private:  
    long        _codditta;        
    TRelation*  r;  // usate per contare i soci
    TCursor*    c;
    bool				_bAllegSoci;
    long        iContaSoci();
    int					_base_formlen;
  protected:                  
    void compatta_depositario();
    void stampa_corpo(TPrinter& pr);  
    void stampa_soci(TPrinter& pr);
    bool	bAllegSoci() const { return _bAllegSoci; }
    virtual bool ultima_pagina() const { return FALSE; } // usato in fill_page per modulaser
    virtual int   dic_form_len() const;
    virtual void  next_page(TPrinter& pr) { fill_page(pr, -1); }
    virtual void  stampa_totali(TPrinter& pr) {}
    virtual void  aggiorna_totali(const char tipo) {}
    virtual void  set_body(TPrinter& pr, const char tipo) {}
    virtual int   prima_riga(PaginaQuadro p) const;
  public:                 
    bool	_GiaMessoStartDoc; // flag per modulaser 'inizio-documento'
    void set_formlen(const int formlen) { _base_formlen = formlen; }
    virtual bool  print(const long codditta, const long NumFis, const long NumNoFis);
    TBase1(const char* sNomeForm, const char* quadro);
    virtual ~TBase1();
};      

class TBase2 : public TDicForm
{
  private:  
    long  _codditta;        
  protected:                                                                           
    void stampa_corpo(TPrinter& pr);  
    virtual bool ultima_pagina() const { return FALSE; } // usato in fill_page per modulaser
    virtual int   dic_form_len() const { return BASE_FORMLEN; }
    virtual void  next_page(TPrinter& pr) { fill_page(pr, -1); }
    virtual void  set_body(TPrinter& pr, const char tipo) {}
    virtual int   prima_riga(PaginaQuadro p) const { return 4;}
  public:                 
    virtual bool  print(const long codditta, const long NumFis, const long NumNoFis);
    TBase2(const char* sNomeForm, const char* quadro) : TDicForm(sNomeForm, quadro)  {}
    virtual ~TBase2() {}
};      

class TBase3 : public TDicForm
{
  private:  
    bool	_bAggiuntivoL; // se necessario stampare aggiuntivo L
  protected:                          
    void stampa_testata(TPrinter& pr);                        
    void stampa_totali_L(TPrinter& pr);
    void  reset_totali_L();    
    bool aggiuntivoL() const { return _bAggiuntivoL; }
    int stampa_L(TPrinter& pr);  
    virtual bool ultima_pagina() const { return FALSE; } // usato in fill_page per modulaser
    virtual int   dic_form_len() const { return BASE_FORMLEN; }
    virtual void  next_page(TPrinter& pr) { fill_page(pr, -1); }
    virtual void  set_body(TPrinter& pr, const char tipo) {}
    virtual int   prima_riga(PaginaQuadro p) const { return 4;}
    virtual long filtra(const long codditta);
  public:                 
    virtual bool  print(const long codditta, const long NumFis, const long NumNoFis);
    TBase3(const char* sNomeForm, const char* quadro) : TDicForm(sNomeForm, quadro)  {}
    virtual ~TBase3() {}
};      

const int _RIGA_TOTALI_L = 65;

class TRigaN : public TSortable
{ 
  TRecnotype _pos;
  int    		_MeseRif,_AnnoRif; // periodo di riferimento
  real		 	_ImpRimb,_CompAss; // importi
  
public:  
  virtual int compare(const TSortable& s) const;
  TRecnotype pos() const { return _pos; }

  const char* sMeseRif() const;
  const char* sAnnoRif() const;
  const int iMeseRif() const { return _MeseRif; }   
  const int iAnnoRif() const { return _AnnoRif; }    
  const char* ImpRimb(const char* pic) const { return _ImpRimb.string(pic); } 
  const char* CompAss(const char* pic) const { return _CompAss.string(pic); }  
  TRigaN(const TLocalisamfile& qn);
  virtual ~TRigaN() { }
};

class TRigheNR : public TObject
{ 
	  TArray _data;
	  
	protected:  
	  const TRigaN& rigaN(int i) const { return (const TRigaN&)_data[i]; }
	  
	public:    
	  const TRigaN& operator[](int i) const { return rigaN(i); }
	  
	  int fill(const long codditta,TLocalisamfile& qnr); 
	  int items() const { return _data.items(); }
    void destroy() { _data.destroy(); }	  
	  TRigheNR() { }
	  virtual ~TRigheNR() { }
};

class TRigaQT : public TSortable
{ 
  int    		_MesePag,_AnnoPag; // periodo di riferimento
  real		 	_ContVers,_ContRimb,_Interessi; // importi
  TString		_sCodReg;
  TRecnotype	_pos;  
public:  
  virtual int compare(const TSortable& s) const;
  TRecnotype pos() const { return _pos; }
  const char* sMesePag() const;
  const char* sAnnoPag() const;
  const int iMesePag() const { return _MesePag; }   
  const int iAnnoPag() const { return _AnnoPag; }    
  const char* ContVers(const char* pic) const { return _ContVers.string(pic); } 
  const char* ContRimb(const char* pic) const { return _ContRimb.string(pic); }   
  const char* Interessi(const char* pic) const { return _Interessi.string(pic); }    
  const char* CodReg() const { return (const char*)_sCodReg; }
  TRigaQT(const TLocalisamfile& qt);
  virtual ~TRigaQT() { }
};

class TRigheQT : public TObject
{ 
	  TArray _data;
	  
	protected:  
	  const TRigaQT& rigaQT(int i) const { return (const TRigaQT&)_data[i]; }
	  
	public:    
	  const TRigaQT& operator[](int i) const { return rigaQT(i); }
    void destroy() { _data.destroy(); }	  	  
	  int fill(const long codditta,TLocalisamfile& qt); 
	  int items() const { return _data.items(); }
	  
	  TRigheQT() {}
	  virtual ~TRigheQT() {}
};

class TRigaPS : public TSortable
{ 
	  TDate    	_dDv; // data vers.
	  real		 	_rImp,_rIntDip,_rIntDat; // importi
	  TString		_sTipoV,_sCodTrib,_sSerie,_sNumero;
	  TRecnotype	_pos;
	public:  
	  virtual int compare(const TSortable& s) const;
    TRecnotype pos() const { return _pos; }	  
    TDate dDataVers() const { return _dDv; }	
    const char* sDataVers() const { return _dDv.string(); }    
	  const char* sImposta() const;
	  const char* sIntDip()  const;
	  const char* sIntDat()  const;
	  const char* sImposta(const char* pic) const { return _rImp.string(pic); } 
	  const char* sIntDip(const char* pic) const { return _rIntDip.string(pic); }   
	  const char* sIntDat(const char* pic) const { return _rIntDat.string(pic); }  	  
	  const char* sTipoVers() const { return (const char*)_sTipoV; }
	  const char* sCodTrib() const { return (const char*)_sCodTrib; }
	  const char* sSerie()  const { return (const char*)_sSerie; }
	  const char* sNumero() const { return (const char*)_sNumero; }	  	  	  
	  TRigaPS(const TLocalisamfile& qt);
	  virtual ~TRigaPS() { }
};

class TRighePS : public TObject
{ 
	  TArray _data;
	  
	protected:  
	  const TRigaPS& rigaPS(int i) const { return (const TRigaPS&)_data[i]; }
	  
	public:    
	  const TRigaPS& operator[](int i) const { return rigaPS(i); }
	  int fill(const long codditta,TLocalisamfile& ps); 
    void destroy() { _data.destroy(); }	  	  
    int items() const { return _data.items(); }
	  TRighePS() {}
	  virtual ~TRighePS() {}
};

class TBase4 : public TDicForm
{
  private:  
    long   	_codditta; 
    bool		_bAggN,_bAggP,_bAggR,_bAggQ,_bAggS,_bAggT;                     
  protected:                               
    int		_IdFirma;
    TRigheNR		_righeR;  // array dei record N e R
    TRigheNR	 	_righeN;
    TRigheQT		_righeQ; 
    TRigheQT		_righeT;    
    TRighePS		_righeP; 
    TRighePS		_righeS;    
    void stampa_righe_vuote(TPrinter& pr,const int righe);
    void fill_riga_QT(TPrint_section& sec,const int num,const char quadro);     
    void fill_riga_PS(TPrint_section& sec,const int num,const char quadro);
    void fill_riga_NR(TPrint_section& sec,const int num, const int side,const char quadro);
    void stampa_testata(TPrinter& pr);
    void stampa_fine(TPrinter& pr);
    void stampa_N(TPrinter& pr);   
    void stampa_P(TPrinter& pr);       
    void stampa_Q(TPrinter& pr);      
    void stampa_R(TPrinter& pr);      
    void stampa_S(TPrinter& pr);                  
    void stampa_T(TPrinter& pr);                                     
    virtual int   dic_form_len() const { return BASE_FORMLEN; }
    virtual void  next_page(TPrinter& pr) { fill_page(pr, -1); }
    virtual void  set_body(TPrinter& pr, const char tipo) {}
    virtual int   prima_riga(PaginaQuadro p) const { return 4;}
    int calcola_firma();
  public:                 
    void set_last_ditta(const bool last_ditta) { _LastDitta = last_ditta; }
    virtual bool ultima_pagina() const { return TRUE; } // usato in fill_page per modulaser
    virtual bool  print(const long codditta, const long NumFis, const long NumNoFis);
    TBase4(const char* sNomeForm, const char* quadro) : _IdFirma(824), TDicForm(sNomeForm, quadro)  {}
    virtual ~TBase4() {}
};      

const int _FIELD_L = 740;

class TStampaBase : public TStampaQuadro
{
  private:
    TBase1*     _fBase1;
    TBase2*     _fBase2;                 
    TBase3*     _fBase3;
    TBase4*     _fBase4;    
    TRelation*  _rel;
  protected:    
    virtual bool user_create();
    virtual bool user_destroy();
    virtual bool conta_tipi_per() const { return FALSE; }
    virtual TDicForm* get_form()  const { return _fBase1; }
    virtual TCursor* get_cursor() const { return NULL; }    
    virtual bool print_quadro(const int OffsetDitta, const bool modulaser);
  public:
    TStampaBase(char livel) : TStampaQuadro("Base", livel) { }
};

///////////////////////////////////////////////////////////////////////////////////////////
//
// Quadro L aggiuntivo
//
///////////////////////////////////////////////////////////////////////////////////////////
class TQuadroL : public TDicForm
{
  private:  
    long  _codditta;                              
    real	_rTotEff, _rTotVer;
    int 	_num_foglio;
    void  reset_totali_L();
    void  calcola_totali_precedenti();
  protected:                          
    void stampa_testata(TPrinter& pr);                        
    void stampa_totali_L(TPrinter& pr);
    bool stampa_L(TPrinter& pr,long& lStartRec,const int iRecL);
    virtual void  next_page(TPrinter& pr) { fill_page(pr, -1); }
    virtual void  set_body(TPrinter& pr, const char tipo) {}
    virtual int   prima_riga(PaginaQuadro p) const;
    virtual long filtra(const long codditta);
    int calcola_firma();
  public:                 
    virtual bool  print(const long codditta, const long NumFis, const long NumNoFis);
    TQuadroL(const char* sNomeForm, const char* quadro) : _rTotEff(ZERO),_rTotVer(ZERO),TDicForm(sNomeForm, quadro)  {_num_foglio=0;}
    virtual ~TQuadroL() {}
};      

class TStampaQuadroAggL : public TStampaQuadro
{
    TQuadroL* _form;                                 
    TCursor*  _cur;       
  protected:   
    virtual bool  user_create();
    virtual bool  user_destroy();
    virtual TDicForm* get_form() const   { return _form; }
    virtual TCursor* get_cursor() const { return _cur; }            
    virtual bool conta_tipi_per() const { return FALSE; }      
  public:
    TStampaQuadroAggL(const char* quadro, char liv):TStampaQuadro(quadro, liv) {}
    virtual ~TStampaQuadroAggL() { }
};

class TQuadroN : public TBase4
{
    long	_codditta;
    int		_num_foglio;
  public:                             
    virtual int   dic_form_len() const;
    void stampa_fine(TPrinter& pr);
    int stampa_N(TPrinter& pr,const int ptr);   
    int stampa_P(TPrinter& pr,const int ptr);       
    int stampa_Q(TPrinter& pr,const int ptr);    
    int stampa_R(TPrinter& pr,const int ptr);
    int stampa_S(TPrinter& pr,const int ptr);
    int stampa_T(TPrinter& pr,const int ptr);
    void stampa_testata(TPrinter& pr);
    virtual int   prima_riga(PaginaQuadro p) const;             
    virtual void  next_page(TPrinter& pr) { fill_page(pr, -1); }    
    virtual bool  print(const long codditta, const long NumFis, const long NumNoFis);
    TQuadroN(const char* sNomeForm, const char* quadro) : TBase4(sNomeForm, quadro) { _IdFirma=2; _num_foglio=0;}
    virtual ~TQuadroN() {}
};

class TStampaQuadroAggN : public TStampaQuadro
{
    TQuadroN* _form;                                 
    TCursor*  _cur;       
  protected:   
    virtual bool  user_create();
    virtual bool  user_destroy();
    virtual TDicForm* get_form() const   { return _form; }
    virtual TCursor* get_cursor() const { return _cur; }            
    virtual bool conta_tipi_per() const { return FALSE; }      
  public:
    TStampaQuadroAggN(const char* quadro, char liv):TStampaQuadro(quadro, liv) {}
    virtual ~TStampaQuadroAggN() { }
};

class TAlleSoci : public TDicForm
{ 
		long _codditta;
		int _nprog;
	protected:		
    void stampa_corpo(TPrinter& pr);  
    void set_testata(TPrinter& pr);
    virtual long filtra(const long codditta);
  public:                 
    virtual bool  print(const long codditta, const long NumFis = 0, const long NumNoFis = 0);
    TAlleSoci(const char* sNomeForm, const char* quadro) : TDicForm(sNomeForm, quadro)  {}
    virtual ~TAlleSoci() {}
		
};

class TStampaAlleSoci : public TStampaQuadro
{
  private:
    TAlleSoci*  _form;
    TRelation*  _rel;
    TCursor*    _cur;
    
  protected:    
    virtual bool conta_tipi_per()    const { return FALSE; }
    
    virtual TDicForm* get_form()     const { return _form; }
    virtual TCursor*  get_cursor()   const { return _cur; }
    
    virtual bool user_create();
    virtual bool user_destroy();

  public:
    TStampaAlleSoci(const char* quadro, char liv):TStampaQuadro(quadro, liv) {}
    virtual ~TStampaAlleSoci() { }
};

class TQuadroGAgg : public TDicForm
{ 
		long _codditta;
  public:              
    bool EsisteAllegG(const long codditta);  
    virtual bool  print(const long codditta, const long NumFis = 0, const long NumNoFis = 0);
    TQuadroGAgg(const char* sNomeForm, const char* quadro) : TDicForm(sNomeForm, quadro)  {}
    virtual ~TQuadroGAgg() {}
		
};

class TStampaQuadroGAgg : public TStampaQuadro
{
  private:
    TQuadroGAgg*  _form;
    TRelation*    _rel;
    TCursor*      _cur;
    
  protected:    
    virtual bool conta_tipi_per()    const { return FALSE; }
    
    virtual TDicForm* get_form()     const { return _form; }
    virtual TCursor*  get_cursor()   const { return _cur; }
    
    virtual bool user_create();
    virtual bool user_destroy();

  public:
    TStampaQuadroGAgg(const char* quadro, char liv):TStampaQuadro(quadro, liv) {}
    virtual ~TStampaQuadroGAgg() { }
};

#endif
