#ifndef __CG2101_H
#define __CG2101_H

#ifndef __RELATION_H
#include <relation.h>
#endif

#ifndef __CG2103_H
class TRegistro;
#endif

class TMovimentoPN : public TRelation
{
  // class TMovimentoPN : public TRelation
  // @END

  // @DPRIV
  TRecord_array _cg, _iva;
  TDate _olddate;
  // @END

protected:
  // @FPROT

  int registra(bool re, bool force);
  int read_mov_rows();
  // @END

public:
  // @FPUB
  virtual int next(TReclock lockop = _nolock) { return (file().next(lockop) || read_mov_rows()); }
  virtual int prev(TReclock lockop = _nolock) { return (file().prev(lockop) || read_mov_rows()); }
  virtual int first(TReclock lockop = _nolock) { return (file().first(lockop) || read_mov_rows()); }
  virtual int last(TReclock lockop = _nolock) { return (file().last(lockop) || read_mov_rows()); }
  virtual int skip(TRecnotype nrec, TReclock lockop = _nolock) { return (file().skip(nrec, lockop) || read_mov_rows()); }
  virtual int read(TIsamop op = _isgteq, TReclock lockop = _nolock, TDate& atdate = (TDate&)botime);
  virtual int write  (bool force = TRUE, TDate& atdate = (TDate&)botime);
  virtual int rewrite(bool force = TRUE, TDate& atdate = (TDate&)botime);
  virtual int remove (TDate& atdate = (TDate&)botime);

  TRectype& cg(int i);
  TRectype& iva(int i);
  int cg_items() const { return _cg.rows(); }
  int iva_items() const { return _iva.rows(); }
  void destroy_rows(long numreg);
  
  int date2liq(const TDate& data) const;       // Estrae dalla data il mese di liquidazione
  char frequenza_versamenti(int year) const;   // Ritorna 'M'ensile o 'T'rimestrale
  bool controlla_liquidazione(const TDate& data, TRegistro& reg, bool reset = FALSE) const;

  TMovimentoPN();
  virtual ~TMovimentoPN() {}
};

#endif
