Files correlati : ci1.exe Ricompilazione Demo : [ ] Commento : Corrette le stampe rilavazione ore selezionavano male per mese git-svn-id: svn://10.65.10.50/branches/R_10_00@22153 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			350 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			350 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						||
#include <automask.h>
 | 
						||
#include <progind.h>
 | 
						||
#include <recarray.h>
 | 
						||
#include <relation.h>
 | 
						||
#include <reprint.h>
 | 
						||
 | 
						||
#include "../ca/calib01.h"
 | 
						||
#include "../ca/commesse.h"
 | 
						||
 | 
						||
#include "rilore.h"
 | 
						||
#include "ci1350.h"
 | 
						||
#include "ci1400a.h"
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// Report
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TRil_ore_cms_report : public TReport
 | 
						||
{
 | 
						||
protected:
 | 
						||
  virtual bool use_mask() { return false; }
 | 
						||
 | 
						||
public:
 | 
						||
  TRil_ore_cms_report(const char tipostampa);
 | 
						||
};
 | 
						||
 | 
						||
TRil_ore_cms_report::TRil_ore_cms_report(const char tipostampa)
 | 
						||
{
 | 
						||
  if (tipostampa == 'M')
 | 
						||
    load("ci1400a");
 | 
						||
  else
 | 
						||
    load("ci1400b");
 | 
						||
 | 
						||
  TRil_ore_recordset* recset = new TRil_ore_recordset;
 | 
						||
  set_recordset(recset);
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// Maschera
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TRil_ore_cms_mask : public TAutomask
 | 
						||
{
 | 
						||
protected:
 | 
						||
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						||
 | 
						||
  bool elabora_commessa(const TString& curr_commessa, TReport& rep) const;
 | 
						||
	
 | 
						||
public:
 | 
						||
  void elabora() const;
 | 
						||
 | 
						||
  TRil_ore_cms_mask();
 | 
						||
  virtual ~TRil_ore_cms_mask() {}
 | 
						||
};
 | 
						||
 | 
						||
TRil_ore_cms_mask::TRil_ore_cms_mask() : TAutomask("ci1400a")
 | 
						||
{
 | 
						||
}
 | 
						||
 | 
						||
bool TRil_ore_cms_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						||
{
 | 
						||
  return true;
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
bool TRil_ore_cms_mask::elabora_commessa(const TString& curr_commessa, TReport& rep) const
 | 
						||
{
 | 
						||
  const TVariant tipo_cms_cdc = get(F_CMSOCDC);
 | 
						||
  const bool per_commessa = tipo_cms_cdc.as_string() == "C";
 | 
						||
  const char tipo_stampa = get(F_TIPOSTAMPA)[0];
 | 
						||
	const bool split = get_bool(F_RIPARTISCI);
 | 
						||
  const int anno = get_int(F_ANNO);
 | 
						||
  const int mese = tipo_stampa == 'M' ? get_int(F_MESE) : 0;
 | 
						||
 | 
						||
  //date del periodo
 | 
						||
  TDate inizio, fine;
 | 
						||
 | 
						||
  if (tipo_stampa == 'M')
 | 
						||
  {
 | 
						||
    TDate ini_mese(1, mese, anno);
 | 
						||
    TDate fine_mese = ini_mese;
 | 
						||
    fine_mese.set_end_month();
 | 
						||
    inizio = ini_mese;
 | 
						||
    fine = fine_mese;
 | 
						||
  }
 | 
						||
  else
 | 
						||
  {
 | 
						||
    TDate ini_anno(1, 1, anno);
 | 
						||
    TDate fine_anno(31, 12, anno);
 | 
						||
    inizio = ini_anno;
 | 
						||
    fine = fine_anno;
 | 
						||
  }
 | 
						||
 | 
						||
  TDate ini_cms, fine_cms;
 | 
						||
 | 
						||
  TAssoc_array righe;
 | 
						||
 | 
						||
  //query sul file delle ore in chiave 4 o 5, in base alla scelta di Cdc(4) o Cms(5): TIPO+CODCOSTO+... o TIPO+CODCMS+...
 | 
						||
  TString query;
 | 
						||
 | 
						||
  if (per_commessa)
 | 
						||
  {
 | 
						||
    const TRectype& rec_cms = cache().get(LF_COMMESSE, curr_commessa);
 | 
						||
    const int durata_cms = ca_durata_commessa(rec_cms, ini_cms, fine_cms);
 | 
						||
 | 
						||
    //se la commessa non "interseca" il periodo selezionato -> finisce qui
 | 
						||
//    if (split && (fine_cms < inizio || ini_cms > fine))
 | 
						||
//      return false;
 | 
						||
 | 
						||
    query << "USE RILORE KEY 6";
 | 
						||
    query << "\nFROM TIPO=#TIPO CODCMS=#CODICE";
 | 
						||
    query << "\nTO TIPO=#TIPO CODCMS=#CODICE";
 | 
						||
  }
 | 
						||
  else
 | 
						||
  {
 | 
						||
    query << "USE RILORE KEY 4";
 | 
						||
    query << "\nFROM TIPO=#TIPO CODCOSTO=#CODICE";
 | 
						||
    query << "\nTO TIPO=#TIPO CODCOSTO=#CODICE";
 | 
						||
  }
 | 
						||
 | 
						||
  TISAM_recordset rilore_recset(query);
 | 
						||
  rilore_recset.set_var("#CODICE", curr_commessa);
 | 
						||
 | 
						||
  //un giro con le ore a 'P'reventivo, uno con quelle a 'C'onsuntivo
 | 
						||
  for (int i = 0; i < 2; i++)
 | 
						||
  {
 | 
						||
    const TVariant tipo = i == 0 ? "P" : "C";
 | 
						||
    rilore_recset.set_var("#TIPO", tipo);
 | 
						||
 | 
						||
    const long rilore_recset_items = rilore_recset.items();
 | 
						||
 | 
						||
    for (bool ok = rilore_recset.move_first(); ok; ok = rilore_recset.move_next())
 | 
						||
    {
 | 
						||
      const TString16 risorsa = rilore_recset.get(RILORE_CODICE).as_string();
 | 
						||
      const char tipo_ris_att = rilore_recset.get(RILORE_TIPORA).as_string()[0];
 | 
						||
 | 
						||
			if (i == 1)
 | 
						||
			{
 | 
						||
					if (anno != rilore_recset.get(RILORE_ANNO).as_int())
 | 
						||
						continue;
 | 
						||
					if (tipo_stampa == 'M' && mese != rilore_recset.get(RILORE_MESE).as_int())
 | 
						||
						continue;
 | 
						||
			}
 | 
						||
			//date limite qta ore sul record del file LF_RILORE
 | 
						||
      TDate dataini = rilore_recset.get(RILORE_DADATA).as_date();
 | 
						||
      TDate datafine = rilore_recset.get(RILORE_ADATA).as_date();
 | 
						||
 | 
						||
      //se esiste la commessa nel record e sta stampando per cdc, la commessa va tenuta in considerazione per..
 | 
						||
      //..quanto riguarda l'intervallo di date
 | 
						||
			if (!per_commessa)
 | 
						||
			{
 | 
						||
				const TString& commessa = rilore_recset.get(RILORE_CODCMS).as_string();
 | 
						||
				const TRectype& rec_cms = cache().get(LF_COMMESSE, commessa);
 | 
						||
				const int durata_cms = ca_durata_commessa(rec_cms, ini_cms, fine_cms);
 | 
						||
					//se la commessa non "interseca" il mese selezionato -> finisce qui
 | 
						||
//					if (fine_cms < inizio || ini_cms > fine)
 | 
						||
//						continue;
 | 
						||
			}
 | 
						||
 | 
						||
			//adatta le date alla commessa se quest'ultima <20> contenuta nell'intervallo (pu<70> essere pi<70> breve..
 | 
						||
			//..dell'intervallo selezionato, oppure sovrapporsi solo parzialmente)
 | 
						||
			//se sta stampando per cdc -> fine_cms e ini_cms sono vuoti se non c'<27> la cms e non fa la trimmatura
 | 
						||
			if (fine_cms.ok() && fine_cms < datafine)
 | 
						||
				datafine = fine_cms;
 | 
						||
			if (ini_cms.ok() && ini_cms > dataini)
 | 
						||
				dataini = ini_cms;
 | 
						||
      //se la commessa fosse tutta nel futuro o nel passato -> lascia perdere
 | 
						||
			const long giorni_lavorativi = split ? ci_calcola_giorni_lavorativi(dataini, datafine) : 1L;
 | 
						||
      if (giorni_lavorativi <= 0)
 | 
						||
        continue;
 | 
						||
 | 
						||
      TDate ini_lav, fine_lav;
 | 
						||
      long giorni_lavorativi_cms = 0L;
 | 
						||
      //se lavora su commessa -> le date ini_cms e fine_cms sono ok
 | 
						||
      if (ini_cms.ok() && fine_cms.ok())
 | 
						||
        giorni_lavorativi_cms = ci_calcola_giorni_lavorativi_cms(anno, mese, ini_cms, fine_cms, dataini, datafine, ini_lav, fine_lav);
 | 
						||
      else  //se ci fosse solo il cdc nel record di rilore, non avendo una durata -> i suoi giorni lavorativi coincidono con quelli del periodo
 | 
						||
      {
 | 
						||
        giorni_lavorativi_cms = ci_calcola_giorni_lavorativi(inizio, fine);
 | 
						||
        ini_lav = inizio;
 | 
						||
        fine_lav = fine;
 | 
						||
      }
 | 
						||
 | 
						||
			if (giorni_lavorativi_cms == 0 && !split && i == 1)
 | 
						||
				giorni_lavorativi_cms = giorni_lavorativi;
 | 
						||
      if (giorni_lavorativi_cms > 0)
 | 
						||
      {
 | 
						||
        const real tot_ore = rilore_recset.get(RILORE_QTAORE).as_real();
 | 
						||
        const real tot_ore_uso_risorsa_nel_periodo_per_cms = tot_ore * giorni_lavorativi_cms / giorni_lavorativi;
 | 
						||
 | 
						||
        TToken_string key;
 | 
						||
        key << tipo_ris_att;
 | 
						||
        key.add(risorsa);
 | 
						||
 | 
						||
        TToken_string* record = (TToken_string*)righe.objptr(key);
 | 
						||
        if (record == NULL)
 | 
						||
        {
 | 
						||
          record = new TToken_string;
 | 
						||
          righe.add(key, record);
 | 
						||
        }
 | 
						||
        if (i == 0) //'P'reventivo (aggiorna solo il totale)
 | 
						||
        {
 | 
						||
          real prev = record->get(0);
 | 
						||
          prev += tot_ore_uso_risorsa_nel_periodo_per_cms;
 | 
						||
          record->add(prev.string(), 0);
 | 
						||
        }
 | 
						||
        else  //'C'onsuntivo (aggiorna tutte le caselle dei giorni lavorativi)
 | 
						||
        {
 | 
						||
					if (split)
 | 
						||
					{
 | 
						||
						const real ore_al_giorno = tot_ore / giorni_lavorativi;
 | 
						||
						for (TDate data = ini_lav; data <= fine_lav; ++data)
 | 
						||
						{
 | 
						||
							if (giorni_lavorativi == 1 || ci_is_ferial_day(data))
 | 
						||
							{
 | 
						||
								const int index = tipo_stampa == 'M' ? data.day() : data.month();
 | 
						||
								real prev = record->get(index);
 | 
						||
								prev += ore_al_giorno;
 | 
						||
								record->add(prev.string(), index);
 | 
						||
								real tot = record->get(32);
 | 
						||
								tot += ore_al_giorno;
 | 
						||
								record->add(tot.string(), 32);
 | 
						||
							}
 | 
						||
						}
 | 
						||
					}
 | 
						||
					else
 | 
						||
					{
 | 
						||
						const int index = tipo_stampa == 'M' ? rilore_recset.get(RILORE_GIORNO).as_int() : rilore_recset.get(RILORE_MESE).as_int();
 | 
						||
						real prev = record->get(index);
 | 
						||
						prev += tot_ore;
 | 
						||
						record->add(prev.string(), index);
 | 
						||
						real tot = record->get(32);
 | 
						||
						tot += tot_ore;
 | 
						||
						record->add(tot.string(), 32);
 | 
						||
					}
 | 
						||
        } //if(i==0)..
 | 
						||
 | 
						||
      } //if (giorni_lavorativi_cms > 0)..
 | 
						||
    } //for (bool ok = rilore_recset.move_first()...
 | 
						||
  } //for (int i = 0; i < 2; i++)..
 | 
						||
 | 
						||
  //setta un nuovo recset al report: se non lo facesse il recset sarebbe sempre il medesimo per ogni..
 | 
						||
  //..risorsa (ovvero assoc_array) e quindi si incrementerebbe all'ignoranza
 | 
						||
  TRil_ore_recordset* recset = new TRil_ore_recordset;
 | 
						||
  rep.set_recordset(recset);
 | 
						||
  //tenta la mask2report per far apparire sul report i campi di selezione della maschera
 | 
						||
  rep.mask2report(*this);
 | 
						||
  //finita l'elaborazione che ha riempito l'assoc_array, asegna il medesimo ad un..
 | 
						||
  //..csv_recordset e poi sbatte quest'ultimo (ordinato) nel report
 | 
						||
  ci_fill_recset_from_ass(righe, rep, split);
 | 
						||
  //campo a mano per fare scattare la mask2report()
 | 
						||
  rep.recordset()->set_var("#CODCMS", curr_commessa, true);
 | 
						||
 | 
						||
  return true;
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
void TRil_ore_cms_mask::elabora() const
 | 
						||
{
 | 
						||
  TReport_book book;
 | 
						||
  //stampa mensile o annuale?
 | 
						||
  const char tipostampa = get(F_TIPOSTAMPA)[0];
 | 
						||
  TRil_ore_cms_report rep(tipostampa);
 | 
						||
 | 
						||
  if (tipostampa == 'M')
 | 
						||
    format_report_month(get_int(F_ANNO), get_int(F_MESE), rep);
 | 
						||
 | 
						||
  //query sul file interessato (commessa o centro di costo)
 | 
						||
  TString16 da_cms_cdc, a_cms_cdc;
 | 
						||
  TString query_cms_cdc;
 | 
						||
  TString msg, code_name;
 | 
						||
  const char tipo_cms_cdc = get(F_CMSOCDC)[0];
 | 
						||
 | 
						||
  if (tipo_cms_cdc == 'C')
 | 
						||
  {
 | 
						||
    da_cms_cdc = get(F_DA_CODCMS);
 | 
						||
    a_cms_cdc = get(F_A_CODCMS);
 | 
						||
    query_cms_cdc << "USE COMMESSE";
 | 
						||
    query_cms_cdc << "\nFROM CODCMS=#DACODICE";
 | 
						||
    query_cms_cdc << "\nTO CODCMS=#ACODICE";
 | 
						||
    msg << "Scansione commesse...";
 | 
						||
    code_name = "CODCMS";
 | 
						||
  }
 | 
						||
  else
 | 
						||
  {
 | 
						||
    da_cms_cdc = get(F_DA_CODCDC);
 | 
						||
    a_cms_cdc = get(F_A_CODCDC);
 | 
						||
    query_cms_cdc << "USE CDC";
 | 
						||
    query_cms_cdc << "\nFROM CODCOSTO=#DACODICE";
 | 
						||
    query_cms_cdc << "\nTO CODCOSTO=#ACODICE";
 | 
						||
    msg << "Scansione centri di costo...";
 | 
						||
    code_name = "CODCOSTO";
 | 
						||
  }
 | 
						||
  
 | 
						||
  TISAM_recordset recset_cms_cdc(query_cms_cdc);
 | 
						||
  recset_cms_cdc.set_var("#DACODICE", da_cms_cdc);
 | 
						||
  recset_cms_cdc.set_var("#ACODICE", a_cms_cdc);
 | 
						||
  const long recset_cms_cdc_items = recset_cms_cdc.items();
 | 
						||
 | 
						||
  TProgind pi(recset_cms_cdc_items, msg, true, true);
 | 
						||
 | 
						||
  //per ogni cms/cdc dell'elenco genera un report singolo che viene riempito nella elabora_commessa e..
 | 
						||
  //..aggiunto al book per la stampa finale
 | 
						||
  for (bool ok = recset_cms_cdc.move_first(); ok; ok = recset_cms_cdc.move_next())
 | 
						||
  {
 | 
						||
    if (!pi.addstatus(1))
 | 
						||
      break;
 | 
						||
 | 
						||
    const TString80 curr_commessa = recset_cms_cdc.cursor()->curr().get(code_name);
 | 
						||
 | 
						||
    elabora_commessa(curr_commessa, rep);
 | 
						||
 | 
						||
    book.add(rep);
 | 
						||
  }
 | 
						||
 | 
						||
  //e alla fine stampa il book
 | 
						||
  book.preview();
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// Applicazione
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TRil_ore_cms : public TSkeleton_application
 | 
						||
{
 | 
						||
protected:
 | 
						||
 | 
						||
public:
 | 
						||
  virtual void main_loop();
 | 
						||
};
 | 
						||
 | 
						||
void TRil_ore_cms::main_loop()
 | 
						||
{
 | 
						||
  TRil_ore_cms_mask mask;
 | 
						||
  
 | 
						||
  while (mask.run() == K_ENTER)
 | 
						||
  {
 | 
						||
    mask.elabora();
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
int ci1400(int argc, char* argv[])
 | 
						||
{
 | 
						||
  TRil_ore_cms sd;
 | 
						||
  sd.run(argc, argv, "Rilevazione ore per Commessa - CdC");
 | 
						||
  return 0;
 | 
						||
}
 |