#ifndef __CG2101_H
#define __CG2101_H

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

int date2esc(const TDate& d, int* prevesc = NULL);

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

  // @DPRIV
  TArray _cg, _iva;
  int _oldcg, _oldiva;
  real _balance;
  // @END

protected:
  // @FPROT
  int write_rec(bool re, const TRectype&r, TLocalisamfile& f);
  int cancella(TLocalisamfile& f, int da, int a);
  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.items(); }
  int iva_items() const { return _iva.items(); }
  void destroy_rows();
  
  char frequenza_versamenti(int year) const;   // Ritorna 'M'ensile o 'T'rimestrale
  bool controlla_liquidazione(const TDate& data, bool reset = FALSE) const;

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

#endif
