#include <applicat.h>
#include <prefix.h>
#include <utility.h>

#include "baeur.h"
#include "../mg/mglib.h"  
#include "../mg/mg3500a.h"  


///////////////////////////////////////////////////////////
// Main app
///////////////////////////////////////////////////////////

class TStampa_storico_euro : public TStampa_storgiac
{          
  bool get_aree_dati(TFilename& lit, TFilename& eur) const;
  bool goto_lire(long ditta = -1);
  virtual bool create();
  virtual void set_def_valuta(TForm_storgiac & f);
public:                                                       
  TStampa_storico_euro() {}
};
  
bool TStampa_storico_euro::get_aree_dati(TFilename& lit, TFilename& eur) const
{
  TConfig prassis(CONFIG_STUDIO, "Euro");
  lit = prassis.get("DatiLire");
  eur = prassis.get("DatiEuro");
  if (lit.blank())
  {
    lit = prefix().get_studio();
    lit.rtrim(1);
  }
  bool ok = eur.exist();
  return ok;
}

bool TStampa_storico_euro::goto_lire(long ditta)
{
  TFilename lit, eur; 
  get_aree_dati(lit, eur);

  bool ok = !lit.blank() && fexist(lit);
  if (ok)
  {
    TFilename cur = prefix().get_studio(); cur.rtrim(1);
    if (ditta < 0)
      ditta = get_firm();
    if (!dir_equal(cur, lit))
      ok = prefix().set_studio(lit, ditta);
    else
      prefix().set_codditta(ditta);
  }
  if (!ok)
    error_box("Impossibile utilizzare lo studio in lire '%s'", (const char*)lit);
  return ok;
}

bool TStampa_storico_euro::create()
{
  goto_lire();
  return TStampa_storgiac:: create();
}

void TStampa_storico_euro::set_def_valuta(TForm_storgiac & f)
{
  f.set_output_exchange("EUR", EURO, _exchange_base);
}

int baeur08(int argc, char* argv[])
{  
  TStampa_storico_euro ma;
  ma.run(argc, argv, "Stampa storico in Euro");
  
  return 0;
}