Migliorata consuntivazione ore straordinarie

git-svn-id: svn://10.65.10.50/branches/R_10_00@23037 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2015-02-24 08:27:05 +00:00
parent 848151dff5
commit 7a5a58dd5e
6 changed files with 344 additions and 64 deletions

View File

@ -1515,7 +1515,6 @@ TRilevamento_cons_msk::TRilevamento_cons_msk()
if (dett == "M")
{
TList_field & f = lfield(F_INTERVALLO);
f.delete_item("G");
hide(F_MESE);
}

View File

@ -11,6 +11,7 @@
#include "cilib.h"
#include "ci2.h"
#include "ci2401.h"
#include "ci2400a.h"
#include <causali.h>
@ -20,8 +21,7 @@
#include "../ca/rmovana.h"
#include "rilore.h"
#include <math.h>
#include "citbore.h"
///////////////////////////////////////////////////////////
// Utility
///////////////////////////////////////////////////////////
@ -197,9 +197,9 @@ inline bool is_red_day(const TDate& d)
COLOR TConsuntivazione_window::day2color(const TDate& d) const
{
const COLOR festivo = COLOR_RED;
const COLOR feriale = COLOR_BLUE;
const COLOR ponte = blend_colors(festivo, feriale);
static const COLOR festivo = COLOR_RED;
static const COLOR feriale = COLOR_BLUE;
static const COLOR ponte = blend_colors(festivo, feriale);
if (is_red_day(d))
return festivo;
@ -396,7 +396,9 @@ protected:
protected:
bool cerca_disponibilita(int riga) const;
int cerca_straordinario(int riga, const TString& tipo_ora) const;
int aggiungi_straordinario(int riga, const TString& tipo_ora, const real& prz, const real& qta) const;
real ore_totali(int riga, real& this_row) const;
real proponi_costo(TMask& msk) const;
void riempi_nuova_riga(int r);
bool add_ril_to_doc(TRectype& rilore, TDocumento& doc, TLog_report& log) const;
@ -412,7 +414,8 @@ public:
bool save_dirty_sheet();
bool load_sheet();
bool contabilizza();
bool esporta();
TConsuntivazione_msk();
};
@ -781,7 +784,7 @@ bool TConsuntivazione_msk::add_ril_to_doc(TRectype& rilore, TDocumento& doc, TLo
const TRectype& roa = cache().get(tipo_roa == 'A' ? "ATR" : "RSS", codice_roa);
const TString& tipo_ora = rilore.get(RILORE_TPORA);
const bool disponibilita = tipo_ora == roa.get("S9");
const bool disponibilita = tipo_roa == 'A' && tipo_ora == roa.get("S9");
TString80 codart = roa.get("S2");
if (disponibilita)
@ -799,10 +802,16 @@ bool TConsuntivazione_msk::add_ril_to_doc(TRectype& rilore, TDocumento& doc, TLo
return false;
}
const real ore = rilore.get(RILORE_QTAORE);
const real prezzo = rilore.get(RILORE_COSTO);
const TString80 cms = rilore.get(RILORE_CODCMS);
const TString16 fas = rilore.get(RILORE_CODFASE);
const real ore = rilore.get(RILORE_QTAORE);
const real prezzo = rilore.get(RILORE_COSTO);
const TCodice_cms cms = rilore.get(RILORE_CODCMS);
const TCodice_fas fas = rilore.get(RILORE_CODFASE);
if (cms.full() && doc.get(DOC_CODCMS) != cms)
{
doc.put(DOC_CODCMS, cms);
doc.put(DOC_FASCMS, fas);
}
int found = 0;
if (!ore.is_zero() && !prezzo.is_zero())
@ -827,6 +836,7 @@ bool TConsuntivazione_msk::add_ril_to_doc(TRectype& rilore, TDocumento& doc, TLo
riga.put(RDOC_CODCMS, cms);
riga.put(RDOC_FASCMS, fas);
riga.put(RDOC_CHECKED, "X");
riga.put(RDOC_GENERATA, "X");
riga.put(RDOC_DESCR, anamag.get(ANAMAG_DESCR));
riga.put(RDOC_PREZZO, prezzo);
riga.put(RDOC_DATACONS, doc.get(DOC_DATADOC));
@ -865,7 +875,7 @@ bool TConsuntivazione_msk::add_ril_to_mov(TRectype& rilore, TAnal_mov& mov, TLog
const TString& codice_roa = rilore.get(RILORE_CODICE);
const TRectype& roa = cache().get(tipo_roa == 'A' ? "ATR" : "RSS", codice_roa);
const TString80 conto = roa.get("S1");
const TCodice_con conto = roa.get("S1");
if (conto.blank())
{
TString msg; msg << TR("Impossibile associare un conto analitico a ") << codice_roa;
@ -873,10 +883,10 @@ bool TConsuntivazione_msk::add_ril_to_mov(TRectype& rilore, TAnal_mov& mov, TLog
return false;
}
const real ore = rilore.get(RILORE_QTAORE);
const real prezzo = rilore.get(RILORE_COSTO);
const TString80 cms = rilore.get(RILORE_CODCMS);
const TString16 fas = rilore.get(RILORE_CODFASE);
const real ore = rilore.get(RILORE_QTAORE);
const real prezzo = rilore.get(RILORE_COSTO);
const TCodice_cms cms = rilore.get(RILORE_CODCMS);
const TCodice_fas fas = rilore.get(RILORE_CODFASE);
bool done = !ore.is_zero() && !prezzo.is_zero();
if (done)
@ -901,7 +911,8 @@ bool TConsuntivazione_msk::add_ril_to_mov(TRectype& rilore, TAnal_mov& mov, TLog
// Incrementa importo
TRectype& row = mov.body()[i];
row.put(RMOVANA_SEZIONE, 'D');
row.add(RMOVANA_IMPORTO, ore*prezzo);
real imp = ore*prezzo; imp.round(2);
row.add(RMOVANA_IMPORTO, imp);
}
return done;
@ -960,6 +971,19 @@ long TConsuntivazione_msk::save_docs(TAssoc_array& docs, TAssoc_array& movs, TLo
TAnal_mov* mov = (TAnal_mov*)o;
msg.cut(0) << TR("Movimento analitico ") << mov->get(MOVANA_NUMREG);
TImporto tot;
for (int r = mov->body().last_row(); r > 0; r--)
{
const TRectype& rmov = mov->body()[r];
const char sez = rmov.get_char(RMOVANA_SEZIONE);
const real imp = rmov.get_real(RMOVANA_IMPORTO);
tot += TImporto(sez, imp);
}
tot.normalize();
mov->put(MOVANA_SEZIONE, tot.sezione());
mov->put(MOVANA_TOTDOC, tot.valore());
int err = NOERR;
if (mov->rows() > 0)
err = mov->write(movana);
@ -1200,6 +1224,13 @@ bool TConsuntivazione_msk::contabilizza()
return true;
}
bool TConsuntivazione_msk::esporta()
{
const int anno = get_int(F_ANNO);
const int mese = get_int(F_MESE);
return esportazione_paghe(anno, mese);
}
bool TConsuntivazione_msk::cerca_disponibilita(int riga) const
{
TSheet_field& s = sfield(F_SHEET);
@ -1226,36 +1257,88 @@ bool TConsuntivazione_msk::cerca_disponibilita(int riga) const
return false;
}
int TConsuntivazione_msk::cerca_straordinario(int riga, const TString& tipo_ora) const
int TConsuntivazione_msk::aggiungi_straordinario(int riga, const TString& tipo_ora, const real& prz, const real& add_qta) const
{
TSheet_field& s = sfield(F_SHEET);
const int col_att = s.cid2index(S_CODATT);
const int col_att = s.cid2index(S_CODRIS);
const int col_ora = s.cid2index(S_TPORA);
const int col_cms = s.cid2index(S_CDC1);
const TToken_string& r = s.row(riga);
TString80 cod_rss; r.get(col_att, cod_rss); cod_rss.trim();
TString80 cod_cms; r.get(col_cms, cod_cms); cod_cms.trim();
TCodice_articolo cod_rss; r.get(col_att, cod_rss); cod_rss.trim();
TCodice_cms cod_cms; r.get(col_cms, cod_cms); cod_cms.trim();
int nr = -1;
for (int i = riga-2; i <= riga+2; i++) if (i != riga)
{
if (i >= 0 && i < s.items())
{
const TToken_string& ri = s.row(i);
TString80 ca; ri.get(col_att, ca); ca.trim();
TString4 to; ri.get(col_ora, to); to.trim();
TString80 cc; ri.get(col_cms, cc); cc.trim();
TCodice_articolo ca; ri.get(col_att, ca); ca.trim();
TString4 to; ri.get(col_ora, to); to.trim();
TCodice_cms cc; ri.get(col_cms, cc); cc.trim();
if (ca == cod_rss && cc == cod_cms && to == tipo_ora)
return i;
{
nr = i;
break;
}
}
}
const int nr = s.insert(riga+1);
TToken_string& rowd = s.row(nr);
rowd = r;
rowd.add(tipo_ora, col_ora);
const int col_qta = s.cid2index(S_QTAORE);
if (nr < 0)
{
nr = s.insert(riga+1);
TToken_string& rowd = s.row(nr);
rowd = r; // Copia dati riga principale
rowd.add(tipo_ora, col_ora); // Modifica tipo ora
rowd.add(add_qta.string(0,2), col_qta);
rowd.add("", s.cid2index(S_ID)); // Azzera id per crearne uno nuovo
rowd.add(prz.string(0,2), s.cid2index(S_COSTO));
}
else
{
TToken_string& row = s.row(nr);
real qta = row.get(col_qta);
qta += add_qta;
row.add(qta.string(0,2), col_qta);
}
return nr;
}
real TConsuntivazione_msk::ore_totali(int riga, real& this_row) const
{
TSheet_field& s = sfield(F_SHEET);
const int col_ris = s.cid2index(S_CODRIS);
const int col_dta = s.cid2index(S_DATA);
const int col_qta = s.cid2index(S_QTAORE);
const TString16 cur_ris = s.cell(riga, col_ris);
const TString16 cur_dta = s.cell(riga, col_dta);
TString16 ris, ora, dta;
real qta;
real total;
total = this_row = ZERO;
FOR_EACH_SHEET_ROW(s, r, row)
{
row->get(col_ris, ris);
row->get(col_dta, dta);
if (ris == cur_ris && dta == cur_dta)
{
if (row->get(col_qta, qta))
{
total += qta;
if (r == riga)
this_row = qta;
}
}
}
return total;
}
bool TConsuntivazione_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
@ -1279,6 +1362,10 @@ bool TConsuntivazione_msk::on_field_event(TOperable_field& o, TField_event e, lo
load_sheet();
}
break;
case DLG_EXPORT:
if (e == fe_button && save_dirty_sheet())
esporta();
break;
case DLG_QUIT:
if (e == fe_button && !check_fields())
return false;
@ -1402,43 +1489,85 @@ bool TConsuntivazione_msk::on_field_event(TOperable_field& o, TField_event e, lo
} else
if (tipo == 'R' && cod.full() && ora.full())
{
const int col = sheet.cid2index(S_QTAORE);
const TRectype& rss = cache().get("RSS", cod);
int ore = row.get_int(col);
const int dopo_ora1 = rss.get_int("R5");
const TString4 ora1 = rss.get("S9");
const real prezzo1 = rss.get("R6");
const int dopo_ora2 = rss.get_int("R7");
const TString4 ora2 = rss.get("S10");
const real prezzo2 = rss.get("R8");
const TString& tpo = cache().get("&ORE", ora, "S6"); // tipo ora ordinaria
int ore1 = 0, ore2 = 0;
if (ore > dopo_ora2 && ora2.full()) // ultraordinario
if ((tpo.blank() || tpo == "O")) // ora ordinaria
{
ore2 = ore - dopo_ora2;
ore -= ore2;
}
if (ore > dopo_ora1 && ora1.full()) // straordinario
{
ore1 = ore - dopo_ora1;
ore = dopo_ora1;
}
if (ore1 > 0) // c'è straordinario?
{
const int prz = sheet.cid2index(S_COSTO);
row.add(ore, col); // Reimposta ore ordinarie
const int r1 = cerca_straordinario(jolly, ora1);
sheet.row(r1).add(ore1, col); // Ore straordinarie
sheet.row(r1).add(prezzo1.string(0, 2), prz);
if (ore2 > 0) // Ore ultraordianrie
real questa;
real ore_ord = ore_totali(jolly, questa);
real altre = ore_ord - questa;
if (questa > ZERO)
{
const int r2 = cerca_straordinario(r1, ora2);
sheet.row(r2).add(ore2, col);
sheet.row(r2).add(prezzo2.string(0, 2), prz);
const TRectype& rss = cache().get("RSS", cod);
const real dopo_ora1 = rss.get_real("R5");
const TString4 ora1 = rss.get("S9");
const real prezzo1 = rss.get("R6");
const real dopo_ora2 = rss.get_real("R7");
const TString4 ora2 = rss.get("S10");
const real prezzo2 = rss.get("R8");
real ore0 = questa, ore1, ore2;
if (ora2.full() && altre >= dopo_ora2) // tutte ultraordinarie
{
ore2 = ore0;
ore0 = ZERO;
} else
if (ora1.full() && altre >= dopo_ora1) // tutte straordinarie ed oltre
{
if (ora2.full() && ore_ord >= dopo_ora2)
{
ore2 = ore_ord - dopo_ora2;
if (ore2 > ore0) ore2 = ore0;
ore0 -= ore2;
}
ore1 = ore0;
ore0 = ZERO;
}
else // Fritto misto di ore
{
if (ore_ord > dopo_ora2 && ora2.full()) // ultraordinario
{
ore2 = ore_ord - dopo_ora2;
if (ore2 > ore0)
ore2 = ore0;
ore_ord -= ore2;
ore0 -= ore2;
}
if (ore_ord > dopo_ora1 && ora1.full()) // straordinario
{
ore1 = ore_ord - dopo_ora1;
if (ore1 > ore0)
ore1 = ore0;
ore0 -= ore1;
}
}
if (ore1 > ZERO || ore2 > ZERO) // c'è straordinario?
{
if (ore0.is_zero() && ore1.is_zero()) // tutto ultraordinario
{
row.add(ora2, sheet.cid2index(S_TPORA));
row.add(prezzo2.string(0,2), sheet.cid2index(S_COSTO));
} else
if (ore0.is_zero() && ore2.is_zero()) // tutto straordinario
{
row.add(ora1, sheet.cid2index(S_TPORA));
row.add(prezzo1.string(0,2), sheet.cid2index(S_COSTO));
}
else // fritto misto
{
if (ore2 > ZERO)
aggiungi_straordinario(jolly, ora2, prezzo2, ore2);
if (ore1 > ZERO)
aggiungi_straordinario(jolly, ora1, prezzo1, ore1);
if (ore0 <= ZERO)
sheet.destroy(jolly, false); // Elimina riga nulla
else
row.add(ore0.string(0, 2), sheet.cid2index(S_QTAORE)); // Reimposta ore ordinarie
}
sheet.force_update();
}
}
sheet.force_update();
}
}
}
@ -1668,3 +1797,4 @@ int ci2400(int argc, char *argv[])
a.run(argc, argv, TR("Consuntivazione Ore"));
return 0;
}

View File

@ -26,6 +26,12 @@ BEGIN
PICTURE TOOL_ELABORA
END
BUTTON DLG_EXPORT 2 2
BEGIN
PROMPT 5 1 "Esporta"
PICTURE TOOL_EXPORT
END
#include <helpbar.h>
ENDPAGE

133
ci/ci2400e.uml Normal file
View File

@ -0,0 +1,133 @@
#include "ci2400a.h"
TOOLBAR "topbar" 0 0 0 2
BUTTON DLG_SAVEREC 2 2
BEGIN
PROMPT 2 1 "Salva"
PICTURE TOOL_SAVEREC
FLAGS "D"
END
#include <navbar.h>
#include <helpbar.h>
ENDPAGE
PAGE "Esportazione ore" 0 2 0 0
NUMBER F_ANNO 4
BEGIN
PROMPT 1 0 "Anno "
FLAGS "AD"
END
LIST F_MESE 2 12
BEGIN
PROMPT 32 0 "Mese "
FLAGS "ADM"
END
NUMBER F_CODRIS 6
BEGIN
PROMPT 1 1 "Matricola "
FLAGS "BUZ"
END
STRING F_DESRIS 34
BEGIN
PROMPT 32 1 "Cognome "
FLAGS "B"
END
SPREADSHEET F_SHEET 78
BEGIN
PROMPT 1 2 ""
ITEM "Ord.@5"
ITEM "Tip1@5"
ITEM "Tip2@5"
ITEM "Tip3@5"
ITEM "Tip4@5"
ITEM "Tip5@5"
ITEM "Tip6@5"
ITEM "Tip7@5"
ITEM "Tip8@5"
ITEM "Tot.@5"
END
ENDPAGE
ENDMASK
PAGE "Riga consuntivo" -1 -1 42 6
NUMBER 101 5 2
BEGIN
PROMPT 1 0 "Ordinarie "
END
NUMBER 102 5 2
BEGIN
PROMPT 1 1 "Tipo 1 "
END
NUMBER 103 5 2
BEGIN
PROMPT 1 2 "Tipo 2 "
END
NUMBER 104 5 2
BEGIN
PROMPT 1 3 "Tipo 3 "
END
NUMBER 105 5 2
BEGIN
PROMPT 1 4 "Tipo 4 "
END
NUMBER 106 5 2
BEGIN
PROMPT 21 1 "Tipo 5 "
END
NUMBER 107 5 2
BEGIN
PROMPT 21 2 "Tipo 6 "
END
NUMBER 108 5 2
BEGIN
PROMPT 21 3 "Tipo 7 "
END
NUMBER 109 5 2
BEGIN
PROMPT 21 4 "Tipo 8 "
END
NUMBER 110 5 2
BEGIN
PROMPT 21 5 "@bTotale "
DRIVENBY 101 102 103 104 105 106 107 108 109
NUM_CALC #101+#102+#103+#104+#105+#106+#107+#108+#109
FLAGS "DG"
END
ENDPAGE
TOOLABAR "" 0 0 0 2
BUTTON DLG_OK 2 2
BEGIN
PROMPT 1 1 ""
END
BUTTON DLG_CANCEL 2 2
BEGIN
PROMPT 2 1 ""
END
ENDPAGE
ENDMASK

View File

@ -2,3 +2,4 @@
#define F_COD_ORA 101
#define F_DES_ORA 102
#define F_COD_EST 103
#define F_TIP_ORA 104

View File

@ -26,6 +26,17 @@ BEGIN
KEY 1
END
LIST F_TIP_ORA 1 16
BEGIN
PROMPT 42 2 "Tipologia "
ITEM "|Ordinaria"
ITEM "ST|Straordinaria"
ITEM "AS|Assenza"
ITEM "??|Altro"
FIELD S6
END
STRING F_DES_ORA 50
BEGIN
PROMPT 2 3 "Descrizione "