//
// cg4400.h
// 
#include <isam.h>
#include <printapp.h>
#include <mask.h>
#include <tabutil.h>
#include <utility.h>
#include <urldefid.h>
#include <text.h>
#include <mailbox.h>
#include <execp.h>
#include <sheet.h>
#include <config.h> 
#include <prefix.h>
#include <progind.h>
#include <nditte.h>
#include <anagr.h>
#include <comuni.h>
#include <unloc.h>
#include <mov.h>
#include <rmoviva.h>
#include <clifo.h>
#include <occas.h>
#include <causali.h>
#include "cglib03.h" 
#include "cglib04.h" 
#include "conto.h"

enum messaggio {
  no_liquidazione,
  B0_settato,
  non_proseguire,
  prosegui_stampa,
  prosegui_cal_stampa  
  };

class CG4400_application : public TPrintapp
{
  TCursor        * _cur;
  TRelation      *_rel, *_nditte;
  TLocalisamfile *_clifo, *_occas, *_tab, *_tabcom, *_com, *_anag, *_unloc, *_attiv, *_indlib;
  TTable         *_tabreg, *_tablbu, *_tablim, *_tabpim, *_tablia, *_tabiva; 
  TTable         *_tabpla, *_tabppa, *_tabvid;
  TRigaiva_array _iva_array, _riga_rmi;
  TTipodoc_array _doc_array;     
  TRiga_array    _tot_iva_array;
  TBit_array     _selected;
  TArray_sheet   *_ditte;   
  TArray         _nomiditte;
  bool           _st_liq[13]; 
  bool           _test;
  TRecnotype     _nrec;
  bool           _mov_empty, _stampa_ind_ditta, _stampa_tutti_i_registri, _auto_intraf, _stampa;
  bool           _corrispettivi, _liquidazione, _riep_liq, _stampa_ind_comp, _esiste_riga_iva, _stampa_cred_pre; 
  bool           _rif_vid, _intesta_vidi, _intesta_liq, _stampa_data_reg, _ok_vidi;
  bool           _sosp_imposta;
  char           _frequiva, _tipo_riepilogativo;
  TDate          _data_da, _data_a, _data_stampa, _dataregp, _dataregs, _datareg;
  TDate          _u_data;
  long           _n_ditte, _u_stampata, _primast, __firm, _uprotivap, _ditta;
  long           _numini, _pagine_stampate;
  int            _fino_a_mese, _tipo_reg, _tipo_stampa, _cod_un_loc;
  int            _annoes, _r, _stampa_width, _mese_ultima_liq, _mese_credito; 
  int            _stampa_len, _stampa_mese, _size_header;
  real           _totale_doc, _credito;
  TString        _codreg, _desc_lib, _codatt, _attivita, _tipoatt;
  TString        _tipodoc, _descr_doc, _codlib, _codice_vidi;
  TString        _cofi,_cap,_paiva,_ragsoc,_comunefis,_provfis,_viafis; 
  TFilename      _t, _pippo;

  TParagraph_string* _desc27;
  messaggio      _scelta;
  
protected:

  static bool filter_func (const TRelation * r);
  static bool mask_tipo_stampa (TMask_field&, KEY);
  static bool to_ditt_handler  (TMask_field&, KEY);
  static bool fr_ditt_handler  (TMask_field&, KEY);
  static bool to_butt_handler  (TMask_field&, KEY);
  static bool fr_butt_handler  (TMask_field&, KEY);
  static bool mask_cod         (TMask_field&, KEY);
  static bool mask_libun       (TMask_field&, KEY);
  static bool mask_data        (TMask_field&, KEY);
  static bool mask_mese        (TMask_field&, KEY);
  static bool mask_fino_a_mese (TMask_field&, KEY); 
  static bool mask_select      (TMask_field&, KEY);
  static bool mask_azzera      (TMask_field&, KEY);
  static bool year_handler     (TMask_field&, KEY);

public:
  
  const char*   desc_attivita ();
  const char*   tipo_attivita ();
  const char*   descr_doc ();
  const char*   descr_iva (const char *);     
  TRectype&     ricerca_occ(const char*);
  TRectype&     ricerca_cf (char, long);
  TRectype&     look_comuni(const char*);
  TArray_sheet* get_ditte_sheet() { return _ditte; }
  int           setta_riga (int, const TRigaiva&, real&, real&, real&, real&);
  int           riga_rmoviva();
  bool          set_print(int);
  bool          set_ditte(TMask&);
  bool          compila_reg(const TMask&);
  bool          compila_lib();
  messaggio     controlla_liquidazione();
  messaggio     controlla_b0();
  bool          controlla_mov();
  bool          stampo_liquidazione(int); 
  bool          ventilazione(const char*);
  bool          cerca_libro_gio(TString&, bool*);
  bool          look_reg (int, int, TString&, int, const char*, int*, long);
  bool          look_regs(int, TString&, int, int*, long, TProgind*);
  bool          stampa_totali_finali();     
  bool          stampa_datareg();
  bool          stampa_registri_IVA(const TMask&);
  bool          look_lia(long ditta = 0l);
  bool          ricerca_mese(TString&,TString&,int,int,TMask_field&); 
  void          set_choice_limits(TMask&);
  void          build_ditte_sheet(); 
  void          cerca_reg(const TString&, byte*);
  void          set_page_tot_reg();
  void          send_message(char, const TFilename&,int);
  void          aggiorna_reg(const bool aggiorna_vidi);
  void          aggiorna_lib();
  void          calcola_progressivi(); 
  void          stampa_liq_mesi_succ();
  void          look_reg();  
  void          no_movimenti();
  void          liq_b0_settato();
  void          liq_other_case();
  bool          setta_mask(long);
  bool          preprocess_page(int, int);
  int           stampa_intestazione();
  int           stampa_prospetto(); 
  long          select_firm_range(long,long);
  void          stampa_plafonds(int);
  void          get_dati_ditta();
  void          stampa_vidi();
  void          scrivi_reg(const TDate&);
  int           stampa_acquisti(int);
  real          stampa_valori_plafonds(const real&, const int, TTable&, const char*);
  void          build_nomiditte(TProgind* pnd = NULL);
  void          set_year(int y) { _annoes = y; }
  void          clear_stliq();  
  virtual bool  preprocess_print(int, int);
  virtual bool  user_create();
  virtual bool  user_destroy();
  virtual print_action postprocess_page (int, int);
  virtual void  preprocess_header();  
  
  CG4400_application() : TPrintapp(), _ditte(NULL), _selected(10000), _nomiditte(100), _test(FALSE) {}
  virtual ~CG4400_application() {}
};




