Files correlati : pr0.exe pr1.exe pr1500a.msk Ricompilazione Demo : [ ] Commento : bug 0000137 Implementare la gestione multilingua git-svn-id: svn://10.65.10.50/trunk@12099 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			419 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			419 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						|
#include <automask.h>
 | 
						|
#include <currency.h>
 | 
						|
#include <defmask.h>
 | 
						|
#include <form.h>
 | 
						|
#include <printer.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <recarray.h>
 | 
						|
 | 
						|
#include <clifo.h>
 | 
						|
#include "provv.h"
 | 
						|
#include "agenti.h"
 | 
						|
 | 
						|
#include "pr1500a.h"
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Maschera principale
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TFirr_mask : public TAutomask
 | 
						|
{ 
 | 
						|
protected:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
 | 
						|
public:
 | 
						|
  void load_params();
 | 
						|
  void save_params();
 | 
						|
 | 
						|
  TFirr_mask();
 | 
						|
  virtual ~TFirr_mask();
 | 
						|
};
 | 
						|
 | 
						|
bool TFirr_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{ 
 | 
						|
  switch (o.dlg())
 | 
						|
  {         
 | 
						|
  case DLG_SAVEREC:
 | 
						|
    if (e == fe_button)
 | 
						|
    {
 | 
						|
      save_params();
 | 
						|
      return FALSE;
 | 
						|
    }
 | 
						|
    break;  
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  }            
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
void TFirr_mask::load_params()
 | 
						|
{ 
 | 
						|
 | 
						|
  const bool in_euro = is_euro_value(NULL);
 | 
						|
  
 | 
						|
  TConfig cfg(CONFIG_STUDIO, "pr");
 | 
						|
  set(F_PREVID, cfg.get("Previdenza", NULL, -1, "5.75"));
 | 
						|
  set(F_ASSIST, cfg.get("Assistenza", NULL, -1, "2.00"));
 | 
						|
  set(F_PREV_MIN,  cfg.get("PrevMin",  NULL, -1, in_euro ? "248" : "480000"));
 | 
						|
  set(F_PREV_MAX,  cfg.get("PrevMax",  NULL, -1, in_euro ? "2494" : "4830000"));
 | 
						|
  
 | 
						|
  for (int i = 0; i < 3; i++)
 | 
						|
  { 
 | 
						|
    set(F_FIRR_1+i, cfg.get_int("Firr", NULL, i, i+1));
 | 
						|
    const char* def;
 | 
						|
    if (i == 0) 
 | 
						|
      def = in_euro ? "12395" : "24000000";
 | 
						|
    else  
 | 
						|
      def = in_euro ? "18592" : "36000000";
 | 
						|
    set(F_LIMITE_1+i, cfg.get("FirrLimit", NULL, i, def));
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TFirr_mask::save_params()
 | 
						|
{
 | 
						|
  TConfig cfg(CONFIG_STUDIO, "pr");
 | 
						|
  cfg.set("Previdenza", get(F_PREVID));
 | 
						|
  cfg.set("Assistenza", get(F_ASSIST));
 | 
						|
  cfg.set("PrevMin",  get(F_PREV_MIN));
 | 
						|
  cfg.set("PrevMax",  get(F_PREV_MAX));
 | 
						|
  
 | 
						|
  for (int i = 0; i < 3; i++)
 | 
						|
  {
 | 
						|
    cfg.set("Firr", get(F_FIRR_1+i), NULL, TRUE, i);
 | 
						|
    cfg.set("FirrLimit", get(F_LIMITE_1+i), NULL, TRUE, i);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
TFirr_mask::TFirr_mask() : TAutomask("pr1500a") 
 | 
						|
{
 | 
						|
  load_params();
 | 
						|
}
 | 
						|
 | 
						|
TFirr_mask::~TFirr_mask() 
 | 
						|
{ }
 | 
						|
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Dati Agente
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TDati_agente : public TObject
 | 
						|
{ 
 | 
						|
  TString16 _codice;
 | 
						|
  TString16 _matricola; 
 | 
						|
  TString16 _codfisc;
 | 
						|
  TString   _ragsoc;
 | 
						|
  TDate     _datacess;
 | 
						|
  bool      _plurimandatario;
 | 
						|
  bool      _massimale;
 | 
						|
  real      _totale[5];
 | 
						|
  real      _previdenza[5];
 | 
						|
  real      _assistenza;
 | 
						|
  real      _firr;
 | 
						|
 | 
						|
public:
 | 
						|
  const TString& codice() const { return _codice; }
 | 
						|
  const TString& matricola() const { return _matricola; }
 | 
						|
  const TString& ragsoc() const { return _ragsoc; }      
 | 
						|
  const TString& codice_fiscale() const { return _codfisc; }      
 | 
						|
  const TDate& data_cessazione() const { return _datacess; }
 | 
						|
  bool massimale() const { return _massimale; }
 | 
						|
  const real& previdenza(int index) const;
 | 
						|
  const real& assistenza() const { return _assistenza; }
 | 
						|
  const real& firr() const { return _firr; }
 | 
						|
  
 | 
						|
  void add(const TRectype& provv, const TFirr_mask& m);
 | 
						|
  void crop(const TFirr_mask& m);
 | 
						|
 | 
						|
  TDati_agente(const char* codage);
 | 
						|
  virtual ~TDati_agente() { }
 | 
						|
};
 | 
						|
 | 
						|
void TDati_agente::add(const TRectype& prov, const TFirr_mask& m)
 | 
						|
{
 | 
						|
  const TDate data = prov.get(PROV_DATASCAD);
 | 
						|
  const int index = (data.month()-1) / 3 + 1;
 | 
						|
  
 | 
						|
  real imp = prov.get(PROV_PROVVPAG);
 | 
						|
  imp += prov.get_real(PROV_PROVVMAT);
 | 
						|
 | 
						|
  _totale[0] += imp;
 | 
						|
  _totale[index] += imp;
 | 
						|
}
 | 
						|
 | 
						|
void TDati_agente::crop(const TFirr_mask& m)
 | 
						|
{                                        
 | 
						|
  const real percprev = m.get(F_PREVID);
 | 
						|
  real prev_anno_min  = m.get(F_PREV_MIN);
 | 
						|
  real prev_anno_max  = m.get(F_PREV_MAX);
 | 
						|
  const real percassi = m.get(F_ASSIST);
 | 
						|
  const real firr1    = m.get(F_FIRR_1);
 | 
						|
  real limite1        = m.get(F_LIMITE_1);
 | 
						|
  const real firr2    = m.get(F_FIRR_2);
 | 
						|
  real limite2        = m.get(F_LIMITE_2);
 | 
						|
  const real firr3    = m.get(F_FIRR_3);
 | 
						|
  
 | 
						|
  if (_plurimandatario)
 | 
						|
  {
 | 
						|
    prev_anno_min /= 2.0;
 | 
						|
    prev_anno_max /= 2.0;
 | 
						|
    limite1 /= 2.0;
 | 
						|
    limite2 /= 2.0;
 | 
						|
  }
 | 
						|
 | 
						|
  // Calcolo previdenza
 | 
						|
  _previdenza[0] = ZERO;
 | 
						|
  _massimale = FALSE;
 | 
						|
  for (int t = 1; t <= 4; t++)
 | 
						|
  {
 | 
						|
    real prev = _totale[t] * percprev / 100.0;
 | 
						|
    const real sum = _previdenza[0] + prev;
 | 
						|
    if (sum  > prev_anno_max)
 | 
						|
    {
 | 
						|
      const real extra = sum - prev_anno_max;
 | 
						|
      prev -= extra;
 | 
						|
      _massimale = TRUE;
 | 
						|
    }
 | 
						|
    _previdenza[t] = prev;
 | 
						|
    _previdenza[0] += prev;
 | 
						|
  }                            
 | 
						|
  if (_previdenza[0] > ZERO && _previdenza[0] < prev_anno_min)
 | 
						|
  {
 | 
						|
    const real extra = prev_anno_min - _previdenza[0];
 | 
						|
    _previdenza[4] += extra;
 | 
						|
    _previdenza[0] = prev_anno_min;
 | 
						|
  }  
 | 
						|
    
 | 
						|
  // Calcolo assistenza
 | 
						|
  _assistenza = _totale[0] * percassi / 100.0;
 | 
						|
  
 | 
						|
  // Calcolo FIRR
 | 
						|
  real tot = _totale[0];
 | 
						|
  _firr = ZERO;
 | 
						|
  if (tot > limite2)
 | 
						|
  {
 | 
						|
    _firr += (tot-limite2) * firr3 / 100.0;
 | 
						|
    tot -= limite2;
 | 
						|
  }  
 | 
						|
  if (tot > limite1)
 | 
						|
  {
 | 
						|
    _firr += (tot-limite1) * firr2 / 100.0;
 | 
						|
    tot -= limite1;
 | 
						|
  }  
 | 
						|
  _firr += tot * firr1 / 100.0;
 | 
						|
}
 | 
						|
 | 
						|
const real& TDati_agente::previdenza(int index) const
 | 
						|
{
 | 
						|
  if (index >= 0 && index <= 4)
 | 
						|
    return _previdenza[index];
 | 
						|
  return _previdenza[0];
 | 
						|
}
 | 
						|
 | 
						|
TDati_agente::TDati_agente(const char* codage)
 | 
						|
{                     
 | 
						|
  _codice = codage;
 | 
						|
  const TRectype& rec = cache().get(LF_AGENTI, _codice);
 | 
						|
  
 | 
						|
  _matricola = rec.get(AGE_MATRICOLA);
 | 
						|
  if (_matricola.empty())
 | 
						|
    _matricola = _codice;
 | 
						|
  
 | 
						|
  _ragsoc = rec.get(AGE_RAGSOC);
 | 
						|
  _plurimandatario = rec.get_bool(AGE_PLURIMAND);
 | 
						|
  _datacess = rec.get(AGE_DATACESS);
 | 
						|
  
 | 
						|
  _codfisc = rec.get(AGE_CODFISC);
 | 
						|
  if (_codfisc.empty())
 | 
						|
  {
 | 
						|
    TString16 forn = rec.get(AGE_CODFORN);
 | 
						|
    if (forn.not_empty())
 | 
						|
    {
 | 
						|
      forn.insert("F|");
 | 
						|
      _codfisc = cache().get(LF_CLIFO, forn).get(CLI_COFI);
 | 
						|
    }  
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Form di stampa
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TFirr_form : public TForm
 | 
						|
{
 | 
						|
public:
 | 
						|
  void print_footer();
 | 
						|
 | 
						|
  TFirr_form(const TFirr_mask& m);
 | 
						|
  virtual ~TFirr_form() { }
 | 
						|
};
 | 
						|
 | 
						|
void TFirr_form::print_footer()
 | 
						|
{  
 | 
						|
  set_last_page(TRUE);
 | 
						|
  set_footer(0, TRUE);
 | 
						|
  printer().formfeed();
 | 
						|
}
 | 
						|
 | 
						|
TFirr_form::TFirr_form(const TFirr_mask& m) : TForm("pr1500a") 
 | 
						|
{ 
 | 
						|
  TPrint_section& head = section('H');
 | 
						|
  TPrint_section& body = section('B');
 | 
						|
  TPrint_section& foot = section('F');
 | 
						|
 | 
						|
  TString str;
 | 
						|
  str = TR("Stampa Contributi ");
 | 
						|
  const int periodo = m.get_int(F_PERIODO);
 | 
						|
  switch (periodo)
 | 
						|
  {
 | 
						|
  case 1 : str << TR("primo trimestre"); break;
 | 
						|
  case 2 : str << TR("secondo trimestre"); break;
 | 
						|
  case 3 : str << TR("terzo trimestre"); break;
 | 
						|
  case 4 : str << TR("quarto trimestre"); break;
 | 
						|
  default: str << TR("anno"); break;
 | 
						|
  }
 | 
						|
  str << ' ' << m.get_int(F_ANNO);
 | 
						|
  head.find_field(101).set(str);
 | 
						|
 | 
						|
  const int first   = head.height()-2;
 | 
						|
  const int last    = printer().formlen();
 | 
						|
  const int horiz[] = { first+2, last-foot.height()+1, 0 };
 | 
						|
  genera_fincatura(odd_page, first, last, horiz);
 | 
						|
  genera_intestazioni(odd_page, first+1);
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Applicazione di stampa versamenti per agenti
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TStampa_firr : public TSkeleton_application
 | 
						|
{ 
 | 
						|
  TArray _dati;
 | 
						|
     
 | 
						|
protected:
 | 
						|
  virtual void main_loop();
 | 
						|
 | 
						|
public:
 | 
						|
  void compute(const TFirr_mask& m);
 | 
						|
  void print(const TFirr_mask& m);
 | 
						|
};
 | 
						|
 | 
						|
void TStampa_firr::compute(const TFirr_mask& m)
 | 
						|
{ 
 | 
						|
  TRelation rel(LF_PROVV);
 | 
						|
  
 | 
						|
  TRectype filter_fr(LF_PROVV), filter_to(LF_PROVV);
 | 
						|
  filter_fr.put(PROV_CODAGE, m.get(F_DA_AGENTE));
 | 
						|
  filter_to.put(PROV_CODAGE, m.get(F_AD_AGENTE));
 | 
						|
  
 | 
						|
  const TDate data_fr( 1,  1, m.get_int(F_ANNO));
 | 
						|
  TDate data_to(31, 12, m.get_int(F_ANNO));
 | 
						|
  
 | 
						|
  switch (m.get_int(F_PERIODO))
 | 
						|
  {
 | 
						|
  case 1:
 | 
						|
    data_to.set_month(3);
 | 
						|
    break;
 | 
						|
  case 2:
 | 
						|
    data_to.set_day(30);
 | 
						|
    data_to.set_month(6);
 | 
						|
    break;
 | 
						|
  case 3:
 | 
						|
    data_to.set_day(30);
 | 
						|
    data_to.set_month(9);
 | 
						|
    break;
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  }
 | 
						|
  TString filter;
 | 
						|
  filter << "(ANSI(" << PROV_DATASCAD << ")>=\"" << data_fr.string(ANSI);
 | 
						|
  filter << "\")&&(ANSI(" << PROV_DATASCAD << ")<=\"" << data_to.string(ANSI) << "\")";
 | 
						|
  TCursor cur(&rel, filter, 2, &filter_fr, &filter_to);
 | 
						|
  
 | 
						|
  const long total = cur.items();
 | 
						|
  cur.freeze(TRUE);
 | 
						|
  const TRectype& cur_prov = cur.curr();
 | 
						|
  
 | 
						|
  TProgind pi(total, TR("Elaborazione in corso..."), TRUE, TRUE);
 | 
						|
  for (cur = 0L; cur.pos() < total; ++cur)
 | 
						|
  {
 | 
						|
    pi.addstatus(1);
 | 
						|
    if (pi.iscancelled())
 | 
						|
      break;
 | 
						|
      
 | 
						|
    const TString16 cod = cur_prov.get(PROV_CODAGE);
 | 
						|
    TDati_agente* agente = (TDati_agente*)_dati.objptr(_dati.last());
 | 
						|
    if (agente && cod != agente->codice())  
 | 
						|
      agente = NULL;
 | 
						|
    if (agente == NULL)
 | 
						|
    {
 | 
						|
      agente = new TDati_agente(cod);
 | 
						|
      _dati.add(agente);
 | 
						|
    }
 | 
						|
    agente->add(cur_prov, m);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TStampa_firr::print(const TFirr_mask& m)
 | 
						|
{ 
 | 
						|
  TFirr_form form(m);
 | 
						|
  
 | 
						|
  const int periodo = m.get_int(F_PERIODO);
 | 
						|
  
 | 
						|
  TForm_item& matricola  = form.find_field('B', odd_page, 101);
 | 
						|
  TForm_item& ragsoc     = form.find_field('B', odd_page, 102);
 | 
						|
  TForm_item& codfisc    = form.find_field('B', odd_page, 103);
 | 
						|
  TForm_item& datacess   = form.find_field('B', odd_page, 104);
 | 
						|
  TForm_item& percprovv  = form.find_field('B', odd_page, 105);
 | 
						|
  TForm_item& massimale  = form.find_field('B', odd_page, 106);
 | 
						|
  TForm_item& previdenza = form.find_field('B', odd_page, 107);
 | 
						|
  TForm_item& assistenza = form.find_field('B', odd_page, 108);
 | 
						|
  TForm_item& firr       = form.find_field('B', odd_page, 109);
 | 
						|
  
 | 
						|
  printer().open();
 | 
						|
  for (int i = 0; i < _dati.items(); i++)
 | 
						|
  {               
 | 
						|
    TDati_agente& agente = (TDati_agente&)_dati[i];
 | 
						|
    agente.crop(m); // Ricalcola rate trimestrali
 | 
						|
    
 | 
						|
    matricola.set(agente.matricola());
 | 
						|
    ragsoc.set(agente.ragsoc());         
 | 
						|
    codfisc.set(agente.codice_fiscale());         
 | 
						|
    datacess.set(agente.data_cessazione().string());
 | 
						|
    percprovv.set(m.get(F_PREVID));
 | 
						|
    previdenza.set(agente.previdenza(periodo).string());
 | 
						|
    massimale.set(agente.massimale() ? "X" : "");
 | 
						|
    if (periodo == 0 || periodo == 4)
 | 
						|
    {
 | 
						|
      assistenza.set(agente.assistenza().string());
 | 
						|
      firr.set(agente.firr().string());
 | 
						|
    }
 | 
						|
    
 | 
						|
    form.print(-1);
 | 
						|
  }
 | 
						|
  form.print_footer();
 | 
						|
  printer().close();
 | 
						|
}
 | 
						|
 | 
						|
void TStampa_firr::main_loop()
 | 
						|
{ 
 | 
						|
  open_files(LF_AGENTI, LF_PROVV, NULL);
 | 
						|
  
 | 
						|
  TFirr_mask m;
 | 
						|
  while (m.run() == K_ENTER)
 | 
						|
  {   
 | 
						|
    _dati.destroy();
 | 
						|
    compute(m);
 | 
						|
    if (_dati.items())
 | 
						|
      print(m);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
int pr1500(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TStampa_firr a;
 | 
						|
  a.run(argc, argv, TR("Distinta Versamento"));
 | 
						|
  return 0;
 | 
						|
}
 |