#ifndef __SCONTI_H
#define __SCONTI_H

#ifndef __TCLIFOR_H
#include "clifor.h"
#endif

#ifndef __VELIB_H
#include "velib.h"
#endif

#ifndef __CONFIG_H
class TConfig;
#endif

class TCond_vendita : public TObject
{
  TString80 _sconto;
  TString16 _codiva;
  real _prezzo;
  real _provv;
  real _molt_sconto;

  TDocumento_mask* _testa;
  TMask* _riga; 
  TLocalisamfile _condv;
  TLocalisamfile _rcondv;
  TLocalisamfile _sconti;
  TLocalisamfile _anamag;
  TLocalisamfile _umart;

  bool _ivarid;
  bool _load_mask;

  bool cerca(int tiporicerca);    
  
  real normalize_valuta(const real & val, const char * val_rif = "");
  
protected:
  void set_prezzo(const real & prezzo, const char * val_rif = ""); 
  void set_provv(const real & provv);   
  void set_iva(const TString & codiva);
  void update_omaggi(bool full);

  TDocumento_mask & testa() const { CHECK(_testa, "Maschera testata non inizializzata"); return * _testa; }
  TMask & riga() const { CHECK(_riga, "Maschera riga non inizializzata"); return * _riga; }
  
public:
  TCli_for & clifo() const { return _testa->doc().clifor(); }
  bool set_sconto( const char * exp, bool signal = FALSE );
  const TString& get_sconto() const { return _sconto; }
  real sconto_val() const { return _molt_sconto;}
  real get_prezzo() const { return _prezzo; }
  real get_provv() const { return _provv; }
  real get_percprovv(char tipoprovv, const TString & codpr, TLocalisamfile & age) const;
  const TString & get_iva() const { return _codiva; }
  
//  void set_clifo( TCli_for * clifo) { _clifo = clifo; }
//  void set_config( TConfig * ditta) { _config_ditta = ditta; }
  void set_testa( TDocumento_mask * testa ){ _testa = testa; }
  void set_riga( TMask * riga ){ _riga = riga; }

  void ricerca(bool load_um_only = FALSE, bool load_scagl_only = FALSE);
  bool gestum() const { return _condv.get_bool("GESTUM"); }
  
  TCond_vendita(TDocumento_mask* testa, TMask* riga);
  virtual ~TCond_vendita() {}
};

#endif