Patch level :
Files correlati : Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/trunk@20378 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
c1684f3396
commit
6e4e1bf87e
239
ps/ps1001300.cpp
239
ps/ps1001300.cpp
@ -21,6 +21,9 @@
|
||||
class TVariazione_budget_mask : public TAutomask
|
||||
{
|
||||
bool _dirty;
|
||||
//posizioni dei vari campi dello sheet: vengono assegnati nel costruttore
|
||||
int _pos_check, _pos_cdc, _pos_fase, _pos_conto, _pos_datacomp, _pos_autofcomp, _pos_datafcomp,
|
||||
_pos_cosric, _pos_imp, _pos_prev, _pos_mat, _pos_descr, _pos_numreg, _pos_numrig, _pos_tipomov;
|
||||
|
||||
protected:
|
||||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||||
@ -28,6 +31,9 @@ protected:
|
||||
int carica_rmovana();
|
||||
bool one_checked() const; //(on_field) controlla se nella colonna dei check ce ne è almeno 1 checkato
|
||||
void check_all(const bool checked); //(on_field) checka-dechecka la colonna dei check
|
||||
int find_sister_rows(const int curr_sister, int& first_sister, int& last_sister); //
|
||||
void build_key(int i, TToken_string& key); //
|
||||
void aggiorna_saldi_preventivi(TSheet_field& sf_righe, const int curr_riga); //(carica_rmovana) crea i saldi preventivi in base agli importi
|
||||
void save_commessa(); //(on_field) salva i cambiamenti di date della commessa esaminata
|
||||
|
||||
public:
|
||||
@ -40,6 +46,24 @@ TVariazione_budget_mask::TVariazione_budget_mask() :TAutomask ("ps1001300a")
|
||||
//carica la causale che trova nel ditta.ini
|
||||
TConfig ditta_ini(CONFIG_DITTA, "ps1001");
|
||||
set(F_CODCAUS, ditta_ini.get("CodCaus"));
|
||||
|
||||
//setta le posizioni dei campi dello sheet
|
||||
TSheet_field& sf_righe = sfield(F_RIGHE);
|
||||
_pos_check = sf_righe.cid2index(S_CHECK);
|
||||
_pos_cdc = sf_righe.cid2index(S_CDC);
|
||||
_pos_fase = sf_righe.cid2index(S_FASE);
|
||||
_pos_conto = sf_righe.cid2index(S_CONTO);
|
||||
_pos_datacomp = sf_righe.cid2index(S_DATACOMP);
|
||||
_pos_autofcomp = sf_righe.cid2index(S_AUTOFCOMP);
|
||||
_pos_datafcomp = sf_righe.cid2index(S_DATAFCOMP);
|
||||
_pos_cosric = sf_righe.cid2index(S_COSRIC);
|
||||
_pos_imp = sf_righe.cid2index(S_IMPORTO);
|
||||
_pos_prev = sf_righe.cid2index(S_PREVENTIVO);
|
||||
_pos_mat = sf_righe.cid2index(S_MATURATO);
|
||||
_pos_descr = sf_righe.cid2index(S_DESCR);
|
||||
_pos_numreg = sf_righe.cid2index(S_NUMREG);
|
||||
_pos_numrig = sf_righe.cid2index(S_NUMRIG);
|
||||
_pos_tipomov = sf_righe.cid2index(S_TIPOMOV);
|
||||
}
|
||||
|
||||
TVariazione_budget_mask::~TVariazione_budget_mask()
|
||||
@ -49,10 +73,55 @@ TVariazione_budget_mask::~TVariazione_budget_mask()
|
||||
ditta_ini.set("CodCaus", get(F_CODCAUS));
|
||||
}
|
||||
|
||||
void TVariazione_budget_mask::build_key(int i, TToken_string& key)
|
||||
{
|
||||
TSheet_field& sf_righe = sfield(F_RIGHE);
|
||||
TToken_string curr_riga = sf_righe.row(i);
|
||||
//chiave della riga sorella originale
|
||||
key.cut(0);
|
||||
key.add(curr_riga.get(_pos_cdc));
|
||||
key.add(curr_riga.get(_pos_fase));
|
||||
key.add(curr_riga.get(_pos_conto));
|
||||
}
|
||||
|
||||
int TVariazione_budget_mask::find_sister_rows(const int curr_sister, int& first_sister, int& last_sister)
|
||||
{
|
||||
first_sister = last_sister = curr_sister;
|
||||
|
||||
TToken_string key;
|
||||
build_key(curr_sister, key);
|
||||
|
||||
TToken_string key_iesima;
|
||||
|
||||
for (int i = curr_sister - 1; i >= 0; i--)
|
||||
{
|
||||
build_key(i, key_iesima);
|
||||
if (key == key_iesima)
|
||||
first_sister = i;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
TSheet_field& sf_righe = sfield(F_RIGHE);
|
||||
const long items = sf_righe.items();
|
||||
for (int i = curr_sister + 1; i < items; i++)
|
||||
{
|
||||
build_key(i, key_iesima);
|
||||
if (key == key_iesima)
|
||||
last_sister = i;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return last_sister - first_sister + 1;
|
||||
}
|
||||
|
||||
|
||||
bool TVariazione_budget_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||||
{
|
||||
switch (o.dlg())
|
||||
{
|
||||
//maschera
|
||||
case F_CODCMS:
|
||||
if (e == fe_modify)
|
||||
{
|
||||
@ -65,6 +134,20 @@ bool TVariazione_budget_mask::on_field_event(TOperable_field& o, TField_event e,
|
||||
case F_DATAFINECMS:
|
||||
_dirty = true;
|
||||
break;
|
||||
//sheet
|
||||
case S_CHECK:
|
||||
if (e == fe_modify)
|
||||
{
|
||||
//se viene checkata una riga deve uncheckare le sue sorelle di chiave
|
||||
TSheet_field& sf_righe = sfield(F_RIGHE);
|
||||
int curr = sf_righe.selected(), first, last;
|
||||
const int sisters = find_sister_rows(curr, first, last);
|
||||
for (int i = first; i <= last; i++)
|
||||
sf_righe.row(i).add(i == curr ? "X" : "", _pos_check);
|
||||
|
||||
sf_righe.force_update();
|
||||
}
|
||||
break;
|
||||
case S_DATACOMP:
|
||||
case S_DATAFCOMP:
|
||||
if (e == fe_modify)
|
||||
@ -80,6 +163,20 @@ bool TVariazione_budget_mask::on_field_event(TOperable_field& o, TField_event e,
|
||||
_dirty = true;
|
||||
}
|
||||
break;
|
||||
case S_IMPORTO:
|
||||
if (e == fe_modify)
|
||||
{
|
||||
//se viene cambiato a mano un importo, deve aggiornare i saldi preventivi
|
||||
TSheet_field& sf_righe = sfield(F_RIGHE);
|
||||
const int curr_riga = sf_righe.selected();
|
||||
sf_righe.row(curr_riga).add(o.get(), _pos_imp);
|
||||
aggiorna_saldi_preventivi(sf_righe, curr_riga);
|
||||
o.mask().set(S_PREVENTIVO, sf_righe.cell(curr_riga, _pos_prev));
|
||||
sf_righe.force_update();
|
||||
_dirty = true;
|
||||
}
|
||||
break;
|
||||
//bottoni
|
||||
case DLG_CANCEL:
|
||||
if (e == fe_button)
|
||||
{
|
||||
@ -105,9 +202,8 @@ bool TVariazione_budget_mask::on_field_event(TOperable_field& o, TField_event e,
|
||||
{
|
||||
const TString& datainicms = get(F_DATAINICMS);
|
||||
TSheet_field& sf_righe = sfield(F_RIGHE);
|
||||
const int pos = sf_righe.cid2index(S_DATACOMP);
|
||||
FOR_EACH_SHEET_ROW(sf_righe, i, riga) if (riga->get_char(0) > ' ') //solo le righe checked!!
|
||||
riga->add(datainicms, pos);
|
||||
riga->add(datainicms, _pos_datacomp);
|
||||
|
||||
sf_righe.force_update();
|
||||
}
|
||||
@ -119,9 +215,8 @@ bool TVariazione_budget_mask::on_field_event(TOperable_field& o, TField_event e,
|
||||
if (!datafinecms.ok())
|
||||
datafinecms = get(F_DATAFINECMS);
|
||||
TSheet_field& sf_righe = sfield(F_RIGHE);
|
||||
const int pos = sf_righe.cid2index(S_DATAFCOMP);
|
||||
FOR_EACH_SHEET_ROW(sf_righe, i, riga) if (riga->get_char(0) > ' ') //solo le righe checked!!
|
||||
riga->add(datafinecms, pos);
|
||||
riga->add(datafinecms, _pos_datafcomp);
|
||||
|
||||
sf_righe.force_update();
|
||||
}
|
||||
@ -130,10 +225,51 @@ bool TVariazione_budget_mask::on_field_event(TOperable_field& o, TField_event e,
|
||||
if (e == fe_button)
|
||||
{
|
||||
TSheet_field& sf_righe = sfield(F_RIGHE);
|
||||
const int pos_imp = sf_righe.cid2index(S_IMPORTO);
|
||||
const int pos_mat = sf_righe.cid2index(S_MATURATO);
|
||||
//calcola la differenza tra
|
||||
FOR_EACH_SHEET_ROW(sf_righe, i, riga) if (riga->get_char(0) > ' ') //solo le righe checked!!
|
||||
riga->add(riga->get(pos_mat), pos_imp);
|
||||
{
|
||||
int first, last;
|
||||
const int sisters = find_sister_rows(i, first, last);
|
||||
|
||||
TString80 str_mat = riga->get(_pos_mat);
|
||||
const real mat = real(str_mat);
|
||||
TString80 str_prev = riga->get(_pos_prev);
|
||||
const real prev = real(str_prev);
|
||||
real sbilancio = mat - prev;
|
||||
TString80 str_imp = riga->get(_pos_imp);
|
||||
real imp = real(str_imp);
|
||||
if (sbilancio >= -imp || sisters == 1)
|
||||
{
|
||||
imp += sbilancio;
|
||||
sbilancio = ZERO;
|
||||
riga->add(imp.string(), _pos_imp);
|
||||
}
|
||||
else
|
||||
{
|
||||
riga->add("", _pos_imp);
|
||||
sbilancio += imp;
|
||||
for (int j = last; j >= first && !sbilancio.is_zero(); j--)
|
||||
{
|
||||
imp = sf_righe.cell(j, _pos_imp);
|
||||
if (j == first)
|
||||
{
|
||||
imp += sbilancio;
|
||||
sbilancio = ZERO;
|
||||
sf_righe.row(j).add(imp.string(), _pos_imp);
|
||||
}
|
||||
else
|
||||
{
|
||||
const real k = min(imp, -sbilancio);
|
||||
imp += k;
|
||||
sbilancio += k;
|
||||
sf_righe.row(j).add(imp.string(), _pos_imp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//al termine deve aggiornare la colonna con i preventivi
|
||||
aggiorna_saldi_preventivi(sf_righe, i);
|
||||
}
|
||||
|
||||
sf_righe.force_update();
|
||||
}
|
||||
@ -190,11 +326,37 @@ void TVariazione_budget_mask::check_all(const bool checked)
|
||||
TSheet_field& sf_righe = sfield(F_RIGHE);
|
||||
|
||||
FOR_EACH_SHEET_ROW(sf_righe, i, riga)
|
||||
riga->add(checked ? "X" : "", 0);
|
||||
{
|
||||
int first, last;
|
||||
find_sister_rows(i, first, last);
|
||||
for (int j = first; j <= last; j++)
|
||||
sf_righe.row(j).add(j == last ? "X" : "", _pos_check);
|
||||
i = last;
|
||||
}
|
||||
|
||||
sf_righe.force_update();
|
||||
}
|
||||
|
||||
//aggiorna la colonna con i saldi preventivi sullo sheet
|
||||
void TVariazione_budget_mask::aggiorna_saldi_preventivi(TSheet_field& sf_righe, const int curr_riga)
|
||||
{
|
||||
int first, last;
|
||||
const int sisters = find_sister_rows(curr_riga, first, last);
|
||||
//calcola il totale degli importi delle righe sorelle in modo da avere il saldo
|
||||
real saldo_prev;
|
||||
for (int j = first; j <= last; j++)
|
||||
{
|
||||
TString80 str_imp = sf_righe.row(j).get(_pos_imp);
|
||||
saldo_prev += real(str_imp);
|
||||
}
|
||||
//mette il saldo in tutte le righe sorelle
|
||||
for (int j = first; j <= last; j++)
|
||||
{
|
||||
TToken_string& row = sf_righe.row(j);
|
||||
row.add(saldo_prev.string(), _pos_prev);
|
||||
}
|
||||
}
|
||||
|
||||
//ordina per numreg/numrig (long+int)
|
||||
static int compare_by_numrig(TSheet_field & s, int r1, int r2)
|
||||
{
|
||||
@ -202,21 +364,22 @@ static int compare_by_numrig(TSheet_field & s, int r1, int r2)
|
||||
TToken_string& s2 = s.row(r2);
|
||||
|
||||
//prima guarda il numreg..
|
||||
long c10 = s1.get_long(11);
|
||||
long c20 = s2.get_long(11);
|
||||
long c10 = s1.get_long(12);
|
||||
long c20 = s2.get_long(12);
|
||||
int cmp = c10 - c20;
|
||||
//..poi il numrig
|
||||
if (cmp == 0)
|
||||
{
|
||||
int c11 = s1.get_int(12);
|
||||
int c21 = s2.get_int(12);
|
||||
int c11 = s1.get_int(13);
|
||||
int c21 = s2.get_int(13);
|
||||
cmp = c11 - c21;
|
||||
}
|
||||
|
||||
return cmp;
|
||||
}
|
||||
|
||||
//ordina le righe per sede/fase (string+string)
|
||||
//nota: nelle ststic non si possono usare i _pos_quel, perchè sono di maschera
|
||||
//ordina le righe per sede/fase/conto (string+string+string)
|
||||
static int compare_by_fase(TSheet_field & s, int r1, int r2)
|
||||
{
|
||||
TToken_string& s1 = s.row(r1);
|
||||
@ -225,10 +388,12 @@ static int compare_by_fase(TSheet_field & s, int r1, int r2)
|
||||
TToken_string c1;
|
||||
c1.add(s1.get(1));
|
||||
c1.add(s1.get(2));
|
||||
c1.add(s1.get(3));
|
||||
|
||||
TToken_string c2;
|
||||
c2.add(s2.get(1));
|
||||
c2.add(s2.get(2));
|
||||
c2.add(s2.get(3));
|
||||
|
||||
int cmp = c1.compare(c2);
|
||||
|
||||
@ -269,11 +434,11 @@ int TVariazione_budget_mask::carica_rmovana()
|
||||
|
||||
//chiave iniziale di riga
|
||||
const TString& cdc = rmovana.get(RMOVANA_CODCCOSTO).as_string();
|
||||
row.add(cdc, 1);
|
||||
row.add(cdc, _pos_cdc);
|
||||
const TString& fase = rmovana.get(RMOVANA_CODFASE).as_string();
|
||||
row.add(fase, 2);
|
||||
row.add(fase, _pos_fase);
|
||||
const TString& conto = rmovana.get(RMOVANA_CODCONTO).as_string();
|
||||
row.add(conto, 3);
|
||||
row.add(conto, _pos_conto);
|
||||
|
||||
//date competenza iniziale e finale
|
||||
const TDate datacomp = rmovana.get("MOVANA."MOVANA_DATACOMP).as_date();
|
||||
@ -290,41 +455,53 @@ int TVariazione_budget_mask::carica_rmovana()
|
||||
if (!datafcomp.ok())
|
||||
datafcomp = datacomp;
|
||||
|
||||
row.add(datacomp, 4);
|
||||
row.add(autofcomp ? "X" : "", 5);
|
||||
row.add(datafcomp, 6);
|
||||
row.add(datacomp, _pos_datacomp);
|
||||
row.add(autofcomp ? "X" : "", _pos_autofcomp);
|
||||
row.add(datafcomp, _pos_datafcomp);
|
||||
|
||||
//costo o ricavo? all'indbil l'ardua sentenza!
|
||||
TAnal_bill bill(conto, cdc, cms, fase);
|
||||
const int indbil = bill.indicatore_bilancio();
|
||||
const char* str_indbil = indbil == 3 ? "C" : "R";
|
||||
row.add(str_indbil, 7);
|
||||
row.add(str_indbil, _pos_cosric);
|
||||
|
||||
real valore = rmovana.get(RMOVANA_IMPORTO).as_real();
|
||||
const char sezione = rmovana.get(RMOVANA_SEZIONE).as_string()[0];
|
||||
TImporto importo(sezione, valore);
|
||||
importo.normalize(indbil == 3 ? 'D' : 'A');
|
||||
valore = importo.valore();
|
||||
row.add(valore.string(), 8);
|
||||
row.add(valore.string(), _pos_imp);
|
||||
|
||||
//recupera il saldo finale consuntivo! in base alla chiave cms/cdc/fase/conto e lo mette nel campo consuntivo
|
||||
const TDate dataini, datafin;
|
||||
const TSaldanal& saldanal = ca_saldo(bill, dataini, datafin, _saldanal_consuntivo | _saldanal_ultima_imm);
|
||||
TImporto saldo_finale = saldanal._fin;
|
||||
saldo_finale.normalize(indbil == 3 ? 'D' : 'A');
|
||||
const real saldo_finale_valore = saldo_finale.valore();
|
||||
row.add(saldo_finale_valore.string(), 9);
|
||||
//recupera il saldo finale consuntivo! in base alla chiave cms/cdc/fase/conto e lo mette nel campo consuntivo
|
||||
const TSaldanal& saldanal_cons = ca_saldo(bill, dataini, datafin, _saldanal_consuntivo | _saldanal_ultima_imm);
|
||||
TImporto saldo_cons = saldanal_cons._fin;
|
||||
saldo_cons.normalize(indbil == 3 ? 'D' : 'A');
|
||||
const real saldo_cons_valore = saldo_cons.valore();
|
||||
row.add(saldo_cons_valore.string(), _pos_mat);
|
||||
|
||||
//completa la riga
|
||||
row.add(rmovana.get(RMOVANA_DESCR).as_string(), 10);
|
||||
row.add(rmovana.get(RMOVANA_NUMREG).as_int(), 11);
|
||||
row.add(rmovana.get(RMOVANA_NUMRIG).as_int(), 12);
|
||||
row.add(rmovana.get(RMOVANA_DESCR).as_string(), _pos_descr);
|
||||
row.add(rmovana.get(RMOVANA_NUMREG).as_int(), _pos_numreg);
|
||||
row.add(rmovana.get(RMOVANA_NUMRIG).as_int(), _pos_numrig);
|
||||
const TString& tipomov = rmovana.get("MOVANA."MOVANA_TIPOMOV).as_string();
|
||||
row.add(tipomov, 13);
|
||||
row.add(tipomov, _pos_tipomov);
|
||||
} //for(bool ok.move....
|
||||
|
||||
//prima di riempire lo sheet a video ordina le righe per sede/fase/numreg/numrig
|
||||
sf_righe.sort(compare_by_fase);
|
||||
|
||||
//in base alle righe caricate ricava i saldi preventivi
|
||||
FOR_EACH_SHEET_ROW(sf_righe, i, riga)
|
||||
{
|
||||
//solo le righe a saldo preventivo nullo vanno considerate
|
||||
const TString& str_saldo_prev = riga->get(_pos_prev);
|
||||
if (str_saldo_prev == "")
|
||||
{
|
||||
aggiorna_saldi_preventivi(sf_righe, i);
|
||||
}
|
||||
}
|
||||
|
||||
//e poi aggiorna il video!
|
||||
sf_righe.force_update();
|
||||
|
||||
|
@ -27,9 +27,10 @@
|
||||
#define S_DATAFCOMP 107
|
||||
#define S_COSRIC 108
|
||||
#define S_IMPORTO 109
|
||||
#define S_MATURATO 110
|
||||
#define S_DESCR 111
|
||||
#define S_NUMREG 112
|
||||
#define S_NUMRIG 113
|
||||
#define S_TIPOMOV 114
|
||||
#define S_PREVENTIVO 110
|
||||
#define S_MATURATO 111
|
||||
#define S_DESCR 112
|
||||
#define S_NUMREG 113
|
||||
#define S_NUMRIG 114
|
||||
#define S_TIPOMOV 115
|
||||
|
||||
|
@ -159,14 +159,15 @@ BEGIN
|
||||
ITEM "Sede@4"
|
||||
ITEM "Fase@5"
|
||||
ITEM "Conto@12"
|
||||
ITEM "Iniz comp."
|
||||
ITEM "Inizio\nCompetenza@10"
|
||||
ITEM "AC@C"
|
||||
ITEM "Fine comp."
|
||||
ITEM "Fine\nCompetenza@10"
|
||||
ITEM "C/R"
|
||||
ITEM "Importo@15"
|
||||
ITEM "Maturato@15"
|
||||
ITEM "Saldo\nPreventivo@15"
|
||||
ITEM "Saldo\nMaturato@15"
|
||||
ITEM "Descrizione riga@50"
|
||||
ITEM "N. Reg."
|
||||
ITEM "Numero\nRegistr@7"
|
||||
ITEM "Riga"
|
||||
ITEM "Tipo"
|
||||
END
|
||||
@ -228,32 +229,38 @@ BEGIN
|
||||
PROMPT 1 9 "Importo "
|
||||
END
|
||||
|
||||
NUMBER S_PREVENTIVO 15 2
|
||||
BEGIN
|
||||
PROMPT 1 10 "Preventivo "
|
||||
FLAGS "L"
|
||||
END
|
||||
|
||||
NUMBER S_MATURATO 15 2
|
||||
BEGIN
|
||||
PROMPT 1 10 "Maturato "
|
||||
PROMPT 1 11 "Maturato "
|
||||
FLAGS "L"
|
||||
END
|
||||
|
||||
STRING S_DESCR 50
|
||||
BEGIN
|
||||
PROMPT 1 11 "Descr. "
|
||||
PROMPT 1 12 "Descr. "
|
||||
END
|
||||
|
||||
NUMBER S_NUMREG 7
|
||||
BEGIN
|
||||
PROMPT 1 12 "N. reg. "
|
||||
PROMPT 1 13 "N. reg. "
|
||||
FLAGS "L"
|
||||
END
|
||||
|
||||
NUMBER S_NUMRIG 3
|
||||
BEGIN
|
||||
PROMPT 1 13 "N. riga "
|
||||
PROMPT 1 14 "N. riga "
|
||||
FLAGS "L"
|
||||
END
|
||||
|
||||
STRING S_TIPOMOV 1
|
||||
BEGIN
|
||||
PROMPT 1 14 "Tipo "
|
||||
PROMPT 1 15 "Tipo "
|
||||
FLAGS "L"
|
||||
END
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user