//
// cg4400.h
// 
#include <isam.h>
#include <printapp.h>
#include <mask.h>
#include <tabutil.h>
#include <utility.h>
#include <urldefid.h>
#include <sheet.h>
#include <config.h> 

#include <nditte.h>
#include <anagr.h>
#include <comuni.h>
#include <mov.h>
#include <rmoviva.h>
#include <clifo.h>
#include <occas.h>
#include <causali.h>

#include "cglib03.h"

const int       TABREG = (int)TTable::name2log("REG");

class CG4400_application : public TPrintapp
{
  TCursor            * _cur;
  TRelation          *_rel;
  TLocalisamfile *_clifo, *_nditte, *_occas, *_tab, *_tabcom, *_com, *_anag;
  TTable         *_tabreg, *_tablbu, *_tabinl, *_tablim, *_tabpim, *_tablia, *_tabiva; 
  TRigaiva_array _iva_array, _riga_rmi;
  TTipodoc_array _doc_array;     
  TRiga_array    _tot_iva_array;

  TBit_array _selected;
  TArray_sheet   *_ditte;

  TRecnotype     _nrec;
  bool               _mov_empty, _stampa_ind_ditta, _stampa_tutti_i_registri, _auto_intraf;
  bool           _corrispettivi; 
  char           _frequiva;
  TDate              _data_da, _data_a, _data_stampa, _dataregp, _dataregs, _datareg;
  long               _n_ditte, _u_stampata, _primast;
  int                _fino_a_mese, _tipo_reg, _tipo_stampa, _pagine_stampate;
  int                _annoes, _r, _stampa_width; // riga corrente di stampa
  real           _totale_doc;
  TString            _codreg, _desc_lib, _codatt, _attivita;
  TString        _tipodoc, _descr_doc, _codlib;
  TString        _cofi,_cap,_paiva,_ragsoc,_comunefis,_provfis,_viafis;

protected:  
  const char*   desc_attivita (const char * codatt);
  const char*   descr_doc (const char * tipo);
  const char*   descr_iva (const char * cod);     
  const char*   ricerca_cf (char tipocf, long codcf);
  const char*   ricerca_occ(const char * occ);
  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();
  bool          controlla_liquidazione();
  bool          controlla_mov();
  bool          ventilazione(const char*); 
  void          cerca_reg(const TString&, byte&, TDate&);
  //void        leggi_movimenti(const TDate&, const TString&, bool&);
  void          stampa_registri_IVA(const TMask&);
  void                  set_page_tot_reg();
  void          aggiorna_reg();
  void          aggiorna_lib();
  void          calcola_progressivi(real&, real&, const char*, const int); 
  bool          user_create();
  bool          user_destroy();
  bool          preprocess_page(int, int);
  int           stampa_intestazione();
  int           stampa_prospetto();
  void          get_dati_ditta();
  void          stampa_acquisti(int);
  bool          preprocess_print(int, int);
  print_action  postprocess_print(int, int);
  print_action  postprocess_page (int, int);
  void          preprocess_header();  

  static bool filter_func (const TRelation * r);
  
  static bool tipostampa_handler       (TMask_field&, KEY);
  static bool mask_firm_to     (TMask_field&, KEY);
  static bool mask_cod         (TMask_field&, KEY);
  static bool mask_data        (TMask_field&, KEY);
  static bool mask_tipo        (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);

public:
  
  CG4400_application() : TPrintapp(), _ditte(NULL) {}
  virtual ~CG4400_application() {}
};




