0e62628c38
Files correlati : Ricompilazione Demo : [ ] Commento : modificata la stampa per risorsa quando si hanno le commesse nello sheet git-svn-id: svn://10.65.10.50/branches/R_10_00@22353 c028cbd2-c16b-5b4b-a496-9718f37d4682
358 lines
11 KiB
C++
Executable File
358 lines
11 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 "../ca/cdc.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, const int curr_mese, 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)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
//se viene selezionata una commessa in particolare da stampare -> non ha piu' senso lo sheet..
|
||
//..con le commesse da escludere (group 3)
|
||
case F_CODCMS:
|
||
if (e == fe_init || e == fe_modify)
|
||
{
|
||
const TString& codcms = o.get();
|
||
if (codcms.full())
|
||
hide(-3);
|
||
else
|
||
show(-3);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
|
||
bool TRil_ore_cms_mask::elabora_commessa(const TString& curr_commessa, const int curr_mese, 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 int anno = get_int(F_ANNO);
|
||
const int mese = tipo_stampa == 'M' ? curr_mese : 0;
|
||
|
||
//date del periodo
|
||
TDate inizio_periodo, fine_periodo;
|
||
ci_inizio_fine_periodo(tipo_stampa, anno, mese, inizio_periodo, fine_periodo);
|
||
|
||
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)
|
||
{
|
||
query << "USE RILORE KEY 5";
|
||
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";
|
||
}
|
||
|
||
TRil_ore_cms_recordset rilore_recset(query);
|
||
if (curr_commessa == OTHER_ACTIVITIES)
|
||
{
|
||
rilore_recset.set_var("#CODICE", "");
|
||
const TSheet_field& lista = sfield(F_RIGHE);
|
||
rilore_recset.set_list(lista.rows_array(), true);
|
||
}
|
||
else
|
||
{
|
||
rilore_recset.set_var("#CODICE", curr_commessa);
|
||
TString_array lista_vuota;
|
||
rilore_recset.set_list(lista_vuota, true); //azzera la lista di ignoramento nel caso standard e la resetta!
|
||
}
|
||
|
||
//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";
|
||
const char tipo_ora = i == 0 ? 'P' : 'C'; //serve solo per rendere comprensibili gli if( che seguono
|
||
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
|
||
const TDate ini_rilore = rilore_recset.get(RILORE_DADATA).as_date();
|
||
const TDate fine_rilore = 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)
|
||
//se sta stampando per cdc -> fine_cms e ini_cms sono vuoti se non c'<27> la cms e non fa la trimmatura
|
||
TDate inizio_int, fine_int;
|
||
long giorni_lavorativi = ci_calcola_giorni_lavorativi_intersezione(ini_rilore, fine_rilore, inizio_periodo, fine_periodo,
|
||
inizio_int, fine_int);
|
||
//se i giorni lavorativi non ci sono <20> inutile procedere
|
||
if (giorni_lavorativi <= 0)
|
||
continue;
|
||
|
||
const long giorni_lavorativi_rilore = ci_calcola_giorni_lavorativi(ini_rilore, fine_rilore);
|
||
|
||
if (giorni_lavorativi_rilore > 0)
|
||
{
|
||
const real tot_ore = rilore_recset.get(RILORE_QTAORE).as_real();
|
||
|
||
const real tot_ore_uso_risorsa_nel_periodo = tot_ore * giorni_lavorativi / giorni_lavorativi_rilore;
|
||
|
||
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 (tipo_ora == 'P') //'P'reventivo (aggiorna solo il totale)
|
||
{
|
||
real prev = record->get(0);
|
||
prev += tot_ore_uso_risorsa_nel_periodo;
|
||
record->add(prev.string(), 0);
|
||
}
|
||
else //'C'onsuntivo (aggiorna tutte le caselle dei giorni lavorativi)
|
||
{
|
||
const real ore_al_giorno = tot_ore / giorni_lavorativi_rilore;
|
||
for (TDate data = inizio_int; data <= fine_int; ++data)
|
||
{
|
||
if (giorni_lavorativi_rilore == 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);
|
||
}
|
||
} //for (TDate...
|
||
} //if(tipo_ora == 'P'..
|
||
|
||
} //if (giorni_lavorativi_rilore > 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);
|
||
TString4 code;
|
||
code.format("%02d", curr_mese);
|
||
recset->set_var("#MESE", code, true);
|
||
//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);
|
||
//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
|
||
{
|
||
//book di stampa
|
||
TReport_book book;
|
||
//stampa mensile o annuale?
|
||
const char tipostampa = get(F_TIPOSTAMPA)[0];
|
||
TRil_ore_cms_report rep(tipostampa);
|
||
|
||
int da_mese = 1;
|
||
int a_mese = 1;
|
||
if (tipostampa == 'M')
|
||
{
|
||
da_mese = get_int(F_DA_MESE);
|
||
a_mese = get_int(F_A_MESE);
|
||
}
|
||
|
||
//giro su tutti i mesi; se stampa annuale o mese unico -> un giro solo
|
||
for (int m = da_mese; m <= a_mese; m++)
|
||
{
|
||
if (tipostampa == 'M')
|
||
format_report_month(get_int(F_ANNO), m, rep);
|
||
|
||
//query sul file interessato (commessa o centro di costo)
|
||
TString16 cms_cdc;
|
||
TString query_cms_cdc;
|
||
TString msg, code_name;
|
||
const char tipo_cms_cdc = get(F_CMSOCDC)[0];
|
||
|
||
if (tipo_cms_cdc == 'C')
|
||
{
|
||
cms_cdc = get(F_CODCMS);
|
||
query_cms_cdc << "USE COMMESSE";
|
||
query_cms_cdc << "\nFROM CODCMS=#CODICE";
|
||
query_cms_cdc << "\nTO CODCMS=#CODICE";
|
||
msg << "Scansione commesse...";
|
||
code_name = COMMESSE_CODCMS;
|
||
}
|
||
else
|
||
{
|
||
cms_cdc = get(F_CODCDC);
|
||
query_cms_cdc << "USE CDC";
|
||
query_cms_cdc << "\nFROM CODCOSTO=#CODICE";
|
||
query_cms_cdc << "\nTO CODCOSTO=#CODICE";
|
||
msg << "Scansione centri di costo...";
|
||
code_name = CDC_CODCOSTO;
|
||
}
|
||
|
||
TISAM_recordset recset_cms_cdc(query_cms_cdc);
|
||
|
||
//aggiunta Adolfica: lista di commesse da considerare separatamente pi<70> commessa borraccione..
|
||
//..con tutte le altre
|
||
// a) se la lista commesse da considerare separatamente ha elementi, lancia l'elaborazione..
|
||
//....di una commessa alla volta della lista, che generera' una pagina per commessa, poi considerera'...
|
||
//....una commessa virtuale finale in cui ricadono tutte le commesse che non sono nella lista
|
||
TSheet_field& lista = sfield(F_RIGHE);
|
||
const int lista_items = lista.items();
|
||
if (lista_items > 0 && cms_cdc.blank())
|
||
{
|
||
TProgind pi_lista(lista_items, msg, true, true);
|
||
|
||
FOR_EACH_SHEET_ROW(lista, r, riga)
|
||
{
|
||
if (!pi_lista.addstatus(1))
|
||
break;
|
||
|
||
const TString& curr_cms_cdc = riga->get(lista.cid2index(S_CODCMS));
|
||
recset_cms_cdc.set_var("#CODICE", curr_cms_cdc);
|
||
|
||
elabora_commessa(curr_cms_cdc, m, rep);
|
||
book.add(rep);
|
||
}
|
||
//commessa finale: <20> l'insieme di tutte le commesse che non rientrano nella lista
|
||
recset_cms_cdc.set_var("#CODICE", "");
|
||
elabora_commessa("_ALTRE_", m, rep);
|
||
book.add(rep);
|
||
}
|
||
else //programma standard senza lista commesse: genera una pagina per ogni commessa
|
||
{
|
||
recset_cms_cdc.set_var("#CODICE", 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 commesse (1 o tutte per ora) 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, m, rep);
|
||
|
||
book.add(rep);
|
||
} //for (bool ok = recset_cms_cdc.move_first()...
|
||
} //if (lista_items > 0)...
|
||
} //for (int i = da_mese; i <= a_mese; i++)...
|
||
//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;
|
||
}
|