Files correlati : Ricompilazione Demo : [ ] Commento : comincia a stampare qualcosa anche per commessa cdc git-svn-id: svn://10.65.10.50/branches/R_10_00@21681 c028cbd2-c16b-5b4b-a496-9718f37d4682
336 lines
9.5 KiB
C++
Executable File
336 lines
9.5 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <automask.h>
|
||
#include <progind.h>
|
||
#include <recarray.h>
|
||
#include <relation.h>
|
||
#include <reprint.h>
|
||
#include <textset.h>
|
||
|
||
#include "../ca/calib01.h"
|
||
#include "../ca/commesse.h"
|
||
|
||
#include "rilore.h"
|
||
#include "ci1350.h"
|
||
#include "ci1400a.h"
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Recordset
|
||
///////////////////////////////////////////////////////////
|
||
class TRil_ore_cms_recordset : public TCSV_recordset
|
||
{
|
||
public:
|
||
TRil_ore_cms_recordset();
|
||
};
|
||
|
||
TRil_ore_cms_recordset::TRil_ore_cms_recordset()
|
||
: TCSV_recordset("CSV(\"|\")")
|
||
{
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Report
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TRil_ore_cms_report : public TReport
|
||
{
|
||
protected:
|
||
virtual bool use_mask() { return false; }
|
||
|
||
public:
|
||
TRil_ore_cms_report() { load("ci1400a"); }
|
||
};
|
||
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Maschera
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TRil_ore_cms_mask : public TAutomask
|
||
{
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
||
void format_report(TReport& rep) const;
|
||
/*long calcola_giorni_lavorativi_cms(const TDate& ini_cms, const TDate& fine_cms,
|
||
const TDate& dataini, const TDate& datafine,
|
||
TDate& inizio_lav, TDate& fine_lav) const;*/
|
||
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);
|
||
|
||
//date del mese
|
||
const int anno = get_int(F_ANNO);
|
||
const int mese = get_int(F_MESE);
|
||
TDate ini_mese(1, mese, anno);
|
||
TDate fine_mese = ini_mese;
|
||
fine_mese.set_end_month();
|
||
|
||
TDate ini_cms, fine_cms;
|
||
|
||
//creare un assoc_array con chiave TToken_string risorsa/attr. in base ai parametri..
|
||
//..indicati sulla maschera
|
||
//il contenuto dell'assoc_array sar<61>: tot_Prev - 31 valori giornalieri Consuntivi - tot_Consuntivo
|
||
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 (tipo_cms_cdc.as_string() == "C")
|
||
{
|
||
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 mese selezionato -> finisce qui
|
||
if (fine_cms < ini_mese || ini_cms > fine_mese)
|
||
return false;
|
||
|
||
query << "USE RILORE KEY 5";
|
||
query << "\nFROM TIPO=#TIPO CODCMS=#CODICE";
|
||
query << "\nTO TIPO=#TIPO CODCMS=#CODICE";
|
||
}
|
||
else
|
||
{
|
||
ini_cms = ini_mese;
|
||
fine_cms = fine_mese;
|
||
|
||
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];
|
||
|
||
//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();
|
||
|
||
//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)
|
||
if (fine_cms < datafine)
|
||
datafine = fine_cms;
|
||
if (ini_cms > dataini)
|
||
dataini = ini_cms;
|
||
//se la commessa fosse tutta nel futuro o nel passato -> lascia perdere
|
||
const long giorni_lavorativi = ci_calcola_giorni_lavorativi(dataini, datafine);
|
||
if (giorni_lavorativi <= 0)
|
||
continue;
|
||
|
||
TDate ini_lav, fine_lav;
|
||
const long giorni_lavorativi_cms = ci_calcola_giorni_lavorativi_cms(anno, mese, ini_cms, fine_cms, dataini, datafine, ini_lav, fine_lav);
|
||
|
||
if (giorni_lavorativi_cms > 0)
|
||
{
|
||
const real tot_ore = rilore_recset.get(RILORE_QTAORE).as_real();
|
||
const real tot_ore_uso_risorsa_nel_mese_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_mese_per_cms;
|
||
record->add(prev.string(), 0);
|
||
}
|
||
else //'C'onsuntivo (aggiorna tutte le caselle dei giorni lavorativi)
|
||
{
|
||
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))
|
||
{
|
||
real prev = record->get(data.day());
|
||
prev += ore_al_giorno;
|
||
record->add(prev.string(), data.day());
|
||
real tot = record->get(32);
|
||
tot += ore_al_giorno;
|
||
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++)..
|
||
|
||
//finita l'elaborazione che ha riempito l'assoc_array, asegna il medesimo ad un..
|
||
//..csv_recordset e poi sbatte quest'ultimo (ordinato) nel report
|
||
TRil_ore_cms_recordset* righe_da_stampare = new TRil_ore_cms_recordset;
|
||
|
||
ci_fill_recset_from_ass(righe, *righe_da_stampare);
|
||
|
||
#ifdef DBG
|
||
righe_da_stampare->save_as_text("C:/temp/culone.txt");
|
||
#endif
|
||
|
||
//deve settare almeno un campo manualmente perche' funzioni la mask2report
|
||
righe_da_stampare->set_var("#CODCMSCDC", TVariant(curr_commessa), true);
|
||
|
||
//setta il recordset ordinato al report
|
||
rep.set_recordset(righe_da_stampare);
|
||
|
||
//tenta la mask2report per far apparire sul report i campi di selezione della maschera
|
||
rep.mask2report(*this);
|
||
|
||
return true;
|
||
}
|
||
|
||
|
||
void TRil_ore_cms_mask::format_report(TReport& rep) const
|
||
{
|
||
//maggico giro per formattare la testata del calendario di pagina nel report
|
||
const int anno = get_int(F_ANNO);
|
||
const int mese = get_int(F_MESE);
|
||
const TDate primo_del_mese(1, mese, anno);
|
||
TDate ultimo_del_mese = primo_del_mese;
|
||
ultimo_del_mese.set_end_month();
|
||
|
||
TString16 code;
|
||
|
||
for (TDate giorno = primo_del_mese; giorno <= ultimo_del_mese; ++giorno)
|
||
{
|
||
code.format("H0.%d", giorno.day() + 100);
|
||
TReport_field* rep_field = rep.field(code);
|
||
|
||
if (rep_field != NULL)
|
||
{
|
||
if (!ci_is_ferial_day(giorno))
|
||
rep_field->set_back_color(COLOR_LTGRAY);
|
||
|
||
code = itow(giorno.wday());
|
||
code.cut(3);
|
||
code << '\n' << giorno.day();
|
||
rep_field->set(code);
|
||
}
|
||
}
|
||
}
|
||
|
||
void TRil_ore_cms_mask::elabora() const
|
||
{
|
||
TReport_book book;
|
||
TRil_ore_cms_report rep;
|
||
|
||
format_report(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;
|
||
}
|