#ifndef __CG6804_H
#define __CG6804_H

#include <mask.h>
#include <relation.h>
#include <tabutil.h>
#include <utility.h>
#include <config.h>
#include <mailbox.h>
#include <prefix.h> 
#include <urldefid.h> 
#include <msksheet.h>

#include <nditte.h>  
#include <mov.h>
#include <rmov.h>
#include <rmoviva.h>  
#include <pconti.h>
#include <occas.h>
#include <comuni.h>

class TVar_sc : public TApplication
{
  TIsamtempfile*   _tpart, *_tscad, *_tpagsca;
  TLocalisamfile*  _part, *_scad, *_pagsca;
  TTable*          _tab_reg;
  TRectype*        _rec_part,* _rec_scad,* _rec_pagsca;
  TTransfer_file   _tras_file;
  TMask*           _msk, *_mask;
                                                      
  bool     _registrato,_aperti;
  TString  _control_rec,_trasf,_std,_numpart,_tmcf;
  long     _dittaric,_sottoc;
  int      _gruppo,_conto,_anno,_nriga,_tm_caus;    
  char     _tipocf;                               
  bool     _dd_caus,_nd_caus,_movval;
                                                    
public:        
  virtual bool create();
  virtual bool destroy();
  virtual bool menu(MENU_TAG m);         
  bool    main_loop();
  void    apri_temp_file();
  bool    esegui_controlli();
  bool    leggi_trasfer();
  bool    controlli();
  void    leggi_record_controllo();
  bool    video_SC();  
  void    registra_partita(TMask& m);
  void    registra_scadenze(TMask& m);  
  void    registra_pagamenti(TMask& m);  
  void    setta_campi_maschera(TMask& m);                                  
  void    setta_parametri_record(const TString& sigla,const TString& flag);
  char    TipoConto (int g, int c);    
  void    ricerca_localita(TString& com, TString& den, TString& cap, TString& prov);

  static bool a_notify(TSheet_field& s, int r, KEY k);  
  
// HANDLER sulla riga di partita  
  static bool tipocf_handler      (TMask_field& f, KEY k);  
  static bool codcf_handler       (TMask_field& f, KEY k);  
  static bool rifpart_handler     (TMask_field& f, KEY k);  
  static bool datareg_handler     (TMask_field& f, KEY k);  
  static bool codcaus_handler     (TMask_field& f, KEY k);  
  static bool datadoc_handler     (TMask_field& f, KEY k);  
  static bool numdoc_handler      (TMask_field& f, KEY k);  
  static bool contocl_handler     (TMask_field& f, KEY k);  
  static bool tipomov_handler     (TMask_field& f, KEY k);  
  static bool sezione_handler     (TMask_field& f, KEY k);  
  static bool tipopag_handler     (TMask_field& f, KEY k);    
  static bool datapag_handler     (TMask_field& f, KEY k);
  static bool codval_handler      (TMask_field& f, KEY k);  
  static bool datacam_handler     (TMask_field& f, KEY k);  
  static bool cambio_handler      (TMask_field& f, KEY k);    
  static bool gestione_handler    (TMask_field& f, KEY k);  
  static bool registra_dati_comuni(TMask_field& f, KEY k);
  static bool elimina_partita     (TMask_field& f, KEY k);
                                
// HANDLER sulla riga di scadenza
  static bool nrata_handler    (TMask_field& f, KEY k);  
  static bool codpag_handler   (TMask_field& f, KEY k);  
  static bool tpscad_handler   (TMask_field& f, KEY k);  
  static bool ultclass_handler (TMask_field& f, KEY k);  
  static bool datascad_handler (TMask_field& f, KEY k);  
  static bool banca_handler    (TMask_field& f, KEY k);  
  static bool codag_handler    (TMask_field& f, KEY k);   
  static bool datasoll_handler (TMask_field& f, KEY k);   
  static bool importo_handler  (TMask_field& f, KEY k);   
  static bool impval_handler   (TMask_field& f, KEY k);   
  static bool elimina_scadenza (TMask_field& f, KEY k);

// HANDLER sulla riga di pagamento
  static bool rifpartita_handler   (TMask_field& f, KEY k);
  static bool accsal_handler       (TMask_field& f, KEY k);
  static bool passat_handler       (TMask_field& f, KEY k);
  static bool impvalp_handler      (TMask_field& f, KEY k);
  static bool abbuoni_handler      (TMask_field& f, KEY k);
  static bool contropartita_handler(TMask_field& f, KEY k);
  static bool elimina_pagamenti    (TMask_field& f, KEY k);
  static bool sezione_abb_handler  (TMask_field& f, KEY k);  
  static bool sezione_dc_handler   (TMask_field& f, KEY k);
  static bool diffcambio_handler   (TMask_field& f, KEY k);
  static bool ritenute_handler     (TMask_field& f, KEY k);
                                
  bool        descr_conto(const TString&,int,int,long,TString&);
  bool        descr_caus (const TString&,TString&);
  bool        descr_contocl(int,int,TString&);
  bool        tipo_contocl(int,int,TString&); 
  bool        codvaluta   (const TString& codval);           
  void        setta_mask_scad(char t,int g,int c,long s,int anno,const TString& np,int nr,TMask& m);
  void        setta_mask_pagsca(char t,int g,int c,long s,int anno,const TString& np,int nr,TMask& m); 
  char        sezione(char tipo,int g,int c,long s,int anno,const TString& npart,int nriga,TString& codval,TMask& m);
  int         tipo_movimento(char tipo,int g,int c,long s,int anno,const TString& npart,int nriga,TMask& m);  
  void        descr_condpag(const TString& codpag,int tipopag,const TString& ultclass,TString& d_condpag);
  bool        record_partite(char tipo,int g,int c,long s,int anno,TString& npart,int nrigp);
  bool        record_scadenze(char tipo,int g,int c,long s,int anno,TString& npart,int nrigp,int nrata);
  void        sgancia_pagamenti(char tipo,int g,int c,long s,int anno,TString& npart,int nriga,int nrata); 
  bool        cancella_partita(TMask_field& f);        
  bool        cancella_scadenza(TMask_field& f);
  bool        cancella_pagamenti(TMask_field& f);
  bool        controlla_abbuoni_diffcam(char tipo,int g,int c,long s,int anno,TString& npart,int nriga,int nrata);  
  
  TVar_sc();
};                                      

#endif  //__CG6804_H