Aggiornata pag_notify (non mi passa piu!)
git-svn-id: svn://10.65.10.50/trunk@2545 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
d6a1c66f1d
commit
a17eaa542a
315
sc/sc0101.cpp
315
sc/sc0101.cpp
@ -26,12 +26,14 @@ class TFattura_mask : public TMask
|
||||
protected:
|
||||
static bool totdoc_handler(TMask_field& f, KEY k);
|
||||
static bool totval_handler(TMask_field& f, KEY k);
|
||||
static bool valuta_handler(TMask_field& f, KEY key);
|
||||
static bool cambio_handler(TMask_field& f, KEY k);
|
||||
static bool pag_notify(TSheet_field& ps, int r, KEY k);
|
||||
static bool pag_handler(TMask_field& f, KEY key);
|
||||
static bool reset_handler(TMask_field& f, KEY key);
|
||||
static bool recalc_handler(TMask_field& f, KEY key);
|
||||
static bool nrate_handler(TMask_field& f, KEY key);
|
||||
static bool tipopag_handler(TMask_field& f, KEY key);
|
||||
static bool codcab_handler(TMask_field& f, KEY key);
|
||||
|
||||
TPagamento& pagamento() const { return *_pag; }
|
||||
@ -69,9 +71,14 @@ TFattura_mask::TFattura_mask(TRiga_partite& fattura, const TString& codpag)
|
||||
set_handler(FS_NRATE, nrate_handler);
|
||||
set_handler(FS_NSCAB, codcab_handler);
|
||||
set_handler(FS_VSCAB, codcab_handler);
|
||||
|
||||
pag_sheet().set_notify(pag_notify);
|
||||
pag_sheet().set_handler(pag_handler);
|
||||
|
||||
TSheet_field& sf = pag_sheet();
|
||||
sf.set_notify(pag_notify);
|
||||
sf.set_handler(pag_handler);
|
||||
|
||||
TMask& sm = sf.sheet_mask();
|
||||
sm.set_handler(105, tipopag_handler);
|
||||
sm.set_handler(106, tipopag_handler);
|
||||
|
||||
const TRiga_partite& partita = _fattura;
|
||||
const TString datadoc = partita.get(PART_DATADOC);
|
||||
@ -95,101 +102,172 @@ void TFattura_mask::pag2sheet()
|
||||
|
||||
bool TFattura_mask::pag_notify(TSheet_field& ps, int r, KEY k)
|
||||
{
|
||||
if (k == K_INS || k == K_DEL)
|
||||
return FALSE;
|
||||
if (k != K_ENTER)
|
||||
return TRUE;
|
||||
|
||||
TFattura_mask& fm = (TFattura_mask&)ps.mask();
|
||||
TPagamento& pag = *fm._pag;
|
||||
TString_array& rws = fm._pag_rows;
|
||||
|
||||
const int rdiff = fm.get_int(FS_RDIFFER);
|
||||
const bool in_valuta = pag.in_valuta();
|
||||
const int impos = in_valuta ? 2 : 1;
|
||||
|
||||
bool doit = TRUE, m_imp = FALSE, m_perc = FALSE, m_pag = FALSE;
|
||||
bool m_scad = FALSE, m_tipo = FALSE, m_ulc = FALSE, mod = FALSE;
|
||||
word ahiahi = P_OK;
|
||||
bool recalc = fm.get_bool(FS_RECALC); // Ricalcolo automatico attivo
|
||||
|
||||
const bool recalc = fm.get_bool(FS_RECALC);
|
||||
const bool mcomm = fm.get_bool(FS_MCOMM);
|
||||
|
||||
TToken_string ns = ps.row(r);
|
||||
TToken_string ts = rws.row(r);
|
||||
|
||||
const TString news = ns.get(0); // Data scadenza
|
||||
const TString newi = ns.get(impos); // Imponibile (lire o valuta)
|
||||
const TString newp = ns.get(3); // Percentuale
|
||||
const TString newt = ns.get(4); // Tipo pagamento
|
||||
const TString newu = ns.get(5); // Ulteriore classificazione
|
||||
|
||||
// qui viene il bello, si fa per dire
|
||||
if (news != ts.get(0)) // modificata data scadenza
|
||||
mod = m_scad = TRUE;
|
||||
if (newp != ts.get(3)) // modificata percentuale
|
||||
mod = m_perc = TRUE;
|
||||
if (newi != ts.get(impos)) // modificato importo
|
||||
{
|
||||
// se si modifica la percentuale l'importo non viene cagato
|
||||
if ((recalc && !m_perc) || (!recalc))
|
||||
mod = m_imp = TRUE;
|
||||
}
|
||||
if (newt != ts.get(4)) // modificato tipo pagamento
|
||||
mod = m_tipo = m_ulc = TRUE;
|
||||
if (newu != ts.get(5)) // modificato tipo pagamento
|
||||
mod = m_ulc = TRUE;
|
||||
bool doit = TRUE;
|
||||
|
||||
// settato da recalc_rate se occorre ridefinire lo sheet
|
||||
// aggiungendo o togliendo righe
|
||||
bool need_recalc = FALSE;
|
||||
|
||||
if (mod && recalc)
|
||||
TToken_string& ns = ps.row(r); // Nuova riga
|
||||
switch (k)
|
||||
{
|
||||
// ricalcola sheet come sai fare tu
|
||||
ahiahi = pag.recalc_rate(r, m_perc,
|
||||
((m_perc || m_imp) ?
|
||||
(m_perc ? (const char*)newp : (const char*)newi) :
|
||||
NULL),
|
||||
(m_scad ? (const char*)news : NULL),
|
||||
(m_tipo ? (const char*)newt : NULL),
|
||||
(m_ulc ? (const char*)newu : NULL),
|
||||
rdiff, mcomm, need_recalc);
|
||||
// see if rdiff changed
|
||||
fm.set(FS_RDIFFER, pag.rate_differenziate() ? "1" : "2");
|
||||
fm.set(FS_NRATE, pag.n_rate());
|
||||
}
|
||||
if (!recalc)
|
||||
{
|
||||
ahiahi = P_OK;
|
||||
// put data as they are
|
||||
TToken_string& trw = pag.rata(r);
|
||||
TToken_string srw = trw;
|
||||
if (m_tipo) trw.add(newt,2);
|
||||
if (m_scad) trw.add(news,3);
|
||||
if (m_imp)
|
||||
{
|
||||
trw.add(newi,4);
|
||||
const real p = pag.recalc_percrata(r);
|
||||
ps.row(r).add(p.string(), 3);
|
||||
rws.row(r) = ps.row(r);
|
||||
ps.force_update(r);
|
||||
case K_SPACE:
|
||||
{
|
||||
// Le rate possono essere cancellate solo quando non c'e' ricalcolo automatico,
|
||||
// ce ne sono almeno due e non sono protette dalla presenza di abbuoni.
|
||||
const bool can_delete = !recalc && pag.n_rate() > 1 && ns.get_char(13) != 'X';
|
||||
ps.sheet_mask().enable(DLG_DELREC, can_delete);
|
||||
}
|
||||
}
|
||||
if (ahiahi) // any error? Rimetti le righe com'erano prima
|
||||
{
|
||||
if (recalc)
|
||||
break;
|
||||
case K_ENTER:
|
||||
{
|
||||
const bool in_valuta = pag.in_valuta();
|
||||
const int impos = in_valuta ? 2 : 1;
|
||||
|
||||
bool mod = FALSE, m_imp = FALSE, m_perc = FALSE, m_pag = FALSE;
|
||||
bool m_scad = FALSE, m_tipo = FALSE, m_ulc = FALSE, m_implit = FALSE;
|
||||
word ahiahi = P_OK;
|
||||
|
||||
TToken_string& ts = rws.row(r); // Vecchia riga
|
||||
TString news = ns.get(0); // Data scadenza
|
||||
TString newp = ns.get(3); // Percentuale
|
||||
TString newt = ns.get(4); // Tipo pagamento
|
||||
TString newu = ns.get(5); // Ulteriore classificazione
|
||||
TString newi = ns.get(impos); // Importo (lire o valuta)
|
||||
TString newil; // Importo in lire
|
||||
if (in_valuta)
|
||||
{
|
||||
newil = ns.get(1);
|
||||
m_implit = real(newil) != real(ts.get(1));
|
||||
}
|
||||
if (news != ts.get(0)) // modificata data scadenza
|
||||
mod = m_scad = TRUE;
|
||||
if (real(newp) != real(ts.get(3))) // modificata percentuale
|
||||
mod = m_perc = TRUE;
|
||||
if (real(newi) != real(ts.get(impos))) // modificato importo
|
||||
{
|
||||
// se si modifica la percentuale l'importo non viene cagato
|
||||
if ((recalc && !m_perc) || (!recalc))
|
||||
mod = m_imp = TRUE;
|
||||
}
|
||||
if (newt != ts.get(4)) // modificato tipo pagamento
|
||||
mod = m_tipo = m_ulc = TRUE;
|
||||
|
||||
if (newu != ts.get(5)) // modificata ulteriore classificazione
|
||||
mod = m_ulc = TRUE;
|
||||
else if (m_tipo)
|
||||
{
|
||||
// forza reset di ulc se si e' modificato il tipo rata
|
||||
m_ulc = TRUE;
|
||||
newu = "";
|
||||
}
|
||||
|
||||
// settato da recalc_rate se occorre ridefinire lo sheet
|
||||
// aggiungendo o togliendo righe
|
||||
bool need_recalc = FALSE;
|
||||
|
||||
if (mod && recalc)
|
||||
{
|
||||
const bool rdiff = fm.get_bool(FS_RDIFFER);
|
||||
const bool mcomm = fm.get_bool(FS_MCOMM);
|
||||
|
||||
// ricalcola sheet come sai fare tu
|
||||
ahiahi = pag.recalc_rate(r, m_perc,
|
||||
((m_perc || m_imp) ?
|
||||
(m_perc ? (const char*)newp : (const char*)newi) :
|
||||
NULL),
|
||||
(m_scad ? (const char*)news : NULL),
|
||||
(m_tipo ? (const char*)newt : NULL),
|
||||
(m_ulc ? (const char*)newu : NULL),
|
||||
rdiff, mcomm, need_recalc);
|
||||
// see if rdiff changed
|
||||
fm.set(FS_RDIFFER, pag.rate_differenziate() ? "1" : "2");
|
||||
fm.set(FS_NRATE, pag.n_rate());
|
||||
}
|
||||
if (!recalc)
|
||||
{
|
||||
ahiahi = P_OK;
|
||||
// put data as they are
|
||||
TToken_string& trw = pag.rata(r);
|
||||
TToken_string srw = trw;
|
||||
if (m_tipo) trw.add(newt,2);
|
||||
if (m_scad)
|
||||
{
|
||||
trw.add(news,3);
|
||||
if (r > 0)
|
||||
{
|
||||
TDate d(news);
|
||||
int scd = (int)(d - pag.data_rata(r-1));
|
||||
if (pag.mese_commerciale() && (scd % 30) != 0)
|
||||
scd = 30 * ((scd/30)+1);
|
||||
trw.add(scd, 0);
|
||||
}
|
||||
}
|
||||
if (m_imp)
|
||||
{
|
||||
trw.add(newi,4);
|
||||
const real p = pag.recalc_percrata(r);
|
||||
ps.row(r).add(p.string(), 3);
|
||||
ps.force_update(r);
|
||||
}
|
||||
if (mod)
|
||||
rws.row(r) = ps.row(r);
|
||||
}
|
||||
if (in_valuta && m_implit)
|
||||
{
|
||||
pag.set_implit(r, real(newil));
|
||||
rws.row(r) = ps.row(r);
|
||||
}
|
||||
|
||||
if (ahiahi) // any error? Rimetti le righe com'erano prima
|
||||
{
|
||||
if (recalc)
|
||||
{
|
||||
TString err(80); pag.strerr(ahiahi,err);
|
||||
warning_box(err);
|
||||
ps.row(r) = rws.row(r);
|
||||
ps.force_update(r);
|
||||
}
|
||||
}
|
||||
else if (recalc && mod && need_recalc)
|
||||
{
|
||||
// ridefinisci lo sheet sulla base delle nuove rate
|
||||
fm.pag2sheet();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case K_DEL:
|
||||
doit = !recalc && pag.n_rate() > 1 && ps.row(r).get_char(13) != 'X';
|
||||
if (doit)
|
||||
{
|
||||
beep();
|
||||
ps.row(r) = rws.row(r);
|
||||
ps.force_update(r);
|
||||
pag.remove_rata(r);
|
||||
fm.set(FS_NRATE, pag.n_rate());
|
||||
}
|
||||
}
|
||||
else if (recalc && mod && need_recalc)
|
||||
{
|
||||
// ridefinisci lo sheet sulla base delle nuove rate
|
||||
fm.pag2sheet();
|
||||
}
|
||||
break;
|
||||
|
||||
case K_INS:
|
||||
// permette aggiunta e cancellazione solo se non c'e' ricalcolo automatico
|
||||
doit = !recalc;
|
||||
break;
|
||||
case K_CTRL+K_INS: // Post inserimento
|
||||
{
|
||||
const int prev = r - 1;
|
||||
const int gio_scad = pag.scad_rata(prev);
|
||||
TDate data_scad(pag.data_rata(prev));
|
||||
|
||||
pag.add_rata(ZERO, gio_scad, pag.tipo_rata(prev), pag.ulc_rata(prev));
|
||||
pag.next_scad(data_scad, gio_scad, pag.mese_commerciale(), r);
|
||||
pag.set_datarata(r, data_scad);
|
||||
pag.adjust_fixed_scad();
|
||||
fm.pag2sheet();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return doit;
|
||||
}
|
||||
@ -256,6 +334,40 @@ bool TFattura_mask::totval_handler(TMask_field& f, KEY key)
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool TFattura_mask::valuta_handler(TMask_field& f, KEY key)
|
||||
{
|
||||
if (key == K_TAB && f.to_check(key, TRUE))
|
||||
{
|
||||
TMask& m = f.mask();
|
||||
const TString val = f.get();
|
||||
const bool full = val.not_empty();
|
||||
|
||||
if (full)
|
||||
{
|
||||
TMask_field& dc = m.field(FS_DATACAMBIO);
|
||||
/*
|
||||
if (dc.get().empty()) // Inizializza data cambio se assente
|
||||
m.set(FS_DATACAMBIO, m.get(F_DATADOC), TRUE);
|
||||
else
|
||||
*/
|
||||
if (f.focusdirty())
|
||||
{
|
||||
dc.set_dirty();
|
||||
dc.check(RUNNING_CHECK); // Forza ricerca cambio
|
||||
dc.on_hit(); // Forza messaggi (eventuale copia a pag. 3)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m.set(FS_CAMBIO, "", TRUE);
|
||||
m.set(FS_TOTVAL, "", TRUE);
|
||||
}
|
||||
m.enable(FS_CAMBIO, full);
|
||||
m.enable(FS_TOTVAL, full);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool TFattura_mask::cambio_handler(TMask_field& f, KEY key)
|
||||
@ -265,7 +377,7 @@ bool TFattura_mask::cambio_handler(TMask_field& f, KEY key)
|
||||
TFattura_mask& fm = (TFattura_mask&)f.mask();
|
||||
TPagamento& pag = fm.pagamento();
|
||||
const real cambio(f.get());
|
||||
pag.set_cambio(cambio);
|
||||
pag.set_cambio(cambio, fm.get_bool(FS_RECALC));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@ -373,7 +485,7 @@ void TFattura_mask::read_scadenze()
|
||||
}
|
||||
|
||||
pag.set_total(imponibile, imposte, spese);
|
||||
pag.set_cambio(cambio);
|
||||
pag.set_cambio(cambio, FALSE);
|
||||
|
||||
if (partita.rate() > 0)
|
||||
{
|
||||
@ -426,8 +538,31 @@ void TFattura_mask::read_scadenze()
|
||||
ps.disable_cell(0,-1);
|
||||
|
||||
pag2sheet();
|
||||
}
|
||||
|
||||
bool TFattura_mask::tipopag_handler(TMask_field& f, KEY key)
|
||||
{
|
||||
if ((key == K_TAB || key == K_ENTER) && f.dirty())
|
||||
{
|
||||
TFattura_mask& m = (TFattura_mask&)f.mask();
|
||||
int t = m.get_int(105);
|
||||
if (t <= 0)
|
||||
{
|
||||
t = 1;
|
||||
f.set("1");
|
||||
}
|
||||
const char u = m.get(106)[0];
|
||||
const TPagamento& pag = m.pagamento();
|
||||
bool ok;
|
||||
const char* s = pag.desc_tipo(t, u, &ok);
|
||||
if (!ok) m.reset(106);
|
||||
m.set(107, s);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
void TFattura_mask::write_scadenze() const
|
||||
{
|
||||
CHECK(_pag, "Null pagament");
|
||||
|
Loading…
x
Reference in New Issue
Block a user