Fantastica gestione valuta nel saldaconto

git-svn-id: svn://10.65.10.50/trunk@1887 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1995-09-25 11:38:25 +00:00
parent 052c79fa4d
commit efcac010b2
12 changed files with 153 additions and 104 deletions

View File

@ -80,6 +80,7 @@ TMask* TPrimanota_application::load_mask(int n)
m->set_handler(F_SOLAIVA, solaiva_handler);
m->set_handler(F_SHEETIVA, iva_handler);
m->set_handler(F_CODPAG, codpag_handler);
m->set_handler(S_CAMBIO, cambio_handler);
TSheet_field& is = (TSheet_field&)m->field(F_SHEETIVA);
is.set_notify(iva_notify);

View File

@ -201,7 +201,7 @@ BEGIN
PROMPT 22 11 "Data cambio "
FIELD DATACAM
FLAGS "R"
USE CAM SELECT CODTAB[1,3]==#S_VALUTA
USE CAM
INPUT CODTAB[1,3] S_VALUTA
INPUT CODTAB[4,11] S_DATACAMBIO
DISPLAY "Valuta" CODTAB[1,3]

View File

@ -436,7 +436,7 @@ BEGIN
PROMPT 28 12 "Data cambio "
FIELD DATACAM
FLAGS "R"
USE CAM SELECT CODTAB[1,3]==#S_VALUTA
USE CAM
INPUT CODTAB[1,3] S_VALUTA
INPUT CODTAB[4,11] S_DATACAMBIO
DISPLAY "Valuta" CODTAB[1,3]

View File

@ -62,7 +62,7 @@ DATE P_DATACAMBIO
BEGIN
PROMPT 21 2 "Data cambio "
FLAGS "DR"
USE CAM SELECT CODTAB[1,3]=#P_VALUTA
USE CAM
INPUT CODTAB[1,3] P_VALUTA
INPUT CODTAB[4,11] P_DATACAMBIO
DISPLAY "Valuta" CODTAB[1,3]

View File

@ -1551,8 +1551,6 @@ bool TPrimanota_application::doc_handler(TMask_field& f, KEY key)
return TRUE;
}
bool TPrimanota_application::occas_code_handler(TMask_field& f, KEY key)
{
if (key == K_TAB)

View File

@ -111,6 +111,7 @@ class TPrimanota_application : public TRelation_application
static bool dareavere_handler(TMask_field& f, KEY k);
static bool cg_conto_handler(TMask_field& f, KEY key);
static bool codpag_handler(TMask_field& f, KEY key);
static bool cambio_handler(TMask_field& f, KEY key);
static bool reset_handler(TMask_field& f, KEY key);
static bool nrate_handler(TMask_field& f, KEY key);
static bool codcab_handler(TMask_field& f, KEY key);

View File

@ -17,13 +17,19 @@
#include <scadenze.h>
bool TPrimanota_application::pag_notify(TSheet_field&, int r, KEY k)
{
TPagamento& pag = *(app().pagamento());
{
TPagamento* pg = app().pagamento();
if (pg == NULL)
return TRUE;
TPagamento& pag = *pg;
TSheet_field& ps = app().pags();
TMask* msk = &(app().curr_mask());
TString_array& rws = app().pag_rows();
int rdiff = atoi(msk->get(FS_RDIFFER));
const int rdiff = atoi(msk->get(FS_RDIFFER));
const bool in_valuta = pag.in_valuta();
const int impos = in_valuta ? 2 : 1;
// ts contiene la vecchia riga, ns la nuova
TToken_string ts(36), ns(36);
@ -33,7 +39,7 @@ bool TPrimanota_application::pag_notify(TSheet_field&, int r, KEY k)
bool m_scad = FALSE, m_tipo = FALSE, mod = FALSE;
word ahiahi = P_OK;
TString news(15), newi(15), newp(15), newt(2);
TString news(10), newi(15), newp(15), newt(2);
bool recalc = msk->get_bool(FS_RECALC);
bool mcomm = msk->get_bool(FS_MCOMM);
@ -44,37 +50,24 @@ bool TPrimanota_application::pag_notify(TSheet_field&, int r, KEY k)
ns = ps.row(r);
ts = rws.row(r);
news = ns.get(0);
newi = ns.get();
newp = ns.get();
newt = ns.get();
news = ns.get(0); // Data scadenza
newi = ns.get(impos); // Imponibile (lire o valuta)
newp = ns.get(3); // Percentuale
newt = ns.get(4); // Tipo pagamento
// qui viene il bello, si fa per dire
if (news != ts.get(0)) // modificata data scadenza
{
mod = m_scad = TRUE;
}
if (newp != ts.get(2)) // modificata percentuale
{
mod = m_perc = TRUE;
}
if (newi != ts.get(1)) // modificato importo
if (news != ts.get(3)) // modificata data scadenza
mod = m_scad = TRUE;
if (newp != ts.get(1)) // modificata percentuale
mod = m_perc = TRUE;
if (newi != ts.get(4)) // modificato importo
{
// se si modifica la percentuale l'importo non viene cagato
if ((recalc && !m_perc) || (!recalc))
{
mod = m_imp = TRUE;
}
mod = m_imp = TRUE;
}
if (newt != ts.get(3)) // modificato tipo pagamento
{
if (newt != ts.get(2)) // modificato tipo pagamento
mod = m_tipo = TRUE;
}
banca = ns.get(5); ts.add(banca, 6);
banca = ns.get(6); ts.add(banca, 7);
banca = ns.get(7); ts.add(banca, 8);
banca = ns.get(8); ts.add(banca, 9);
break;
case K_DEL:
case K_INS:
@ -111,10 +104,10 @@ bool TPrimanota_application::pag_notify(TSheet_field&, int r, KEY k)
// put data as they are
TToken_string& trw = pag.rata(r);
TToken_string srw = trw;
if (m_perc) trw.add(newp,1);
if (m_tipo) trw.add(newt,2);
if (m_scad) trw.add(news,3);
if (m_imp) trw.add(newi,4);
if (m_perc) trw.add(newp,1);
if (m_tipo) trw.add(newt,2);
if (m_scad) trw.add(news,3);
if (m_imp) trw.add(newi,4);
// validate the payment
if ((ahiahi = pag.validate()) != P_OK)
pag.rata(r) = srw;
@ -159,6 +152,20 @@ bool TPrimanota_application::codpag_handler(TMask_field& f, KEY key)
return TRUE;
}
bool TPrimanota_application::cambio_handler(TMask_field& f, KEY key)
{
if (key == K_TAB && f.focusdirty())
{
TPagamento* pag = app().pagamento();
if (pag != NULL)
{
const real ex(f.get());
pag->set_cambio(ex);
}
}
return TRUE;
}
bool TPrimanota_application::reset_handler(TMask_field& f, KEY key)
{
TMask& m = f.mask();
@ -173,18 +180,20 @@ bool TPrimanota_application::reset_handler(TMask_field& f, KEY key)
bool TPrimanota_application::nrate_handler(TMask_field& f, KEY key)
{
TMask& m = f.mask();
const TMask& m = f.mask();
if (key == K_TAB && m.is_running() && app().is_saldaconto())
{
TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
if (app().pagamento() != NULL)
TPagamento* pag = app().pagamento();
if (pag != NULL)
{
app().pagamento()->set_numero_rate(atoi(f.get()), /*TBI*/-1);
if (app().pagamento()->dirty())
app().pagamento()->set_sheet(ps);
pag->set_numero_rate(atoi(f.get()));
if (pag->dirty())
{
TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
pag->set_sheet(ps);
}
}
else f.set("");
else f.reset();
}
return TRUE;
}
@ -195,10 +204,9 @@ bool TPrimanota_application::codcab_handler(TMask_field& f, KEY key)
{
const TMask& m = f.mask();
const short id = f.dlg() == FS_NSCAB ? FS_NSABI : FS_VSABI;
const int pos = id == FS_NSABI ? 5 : 7;
const int pos = id == FS_NSABI ? 6 : 8;
const TString16 abi = m.get(id);
const TString16 cab = m.get(id+1);
TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
for (int i = ps.items()-1; i >= 0; i--)
{
@ -230,60 +238,43 @@ void TPrimanota_application::set_pagamento(const char* c, const char* d)
void TPrimanota_application::set_scadenze(TMask& m)
{
const real imponibile(m.get(F_IMPONIBILI));
const real imposta(m.get(F_IMPOSTE));
real imponibile, imposta;
const real spese(0.0);
const real cambio(m.get(S_CAMBIO));
const real cambio(m.get(S_CAMBIO));
TPagamento& pag = *pagamento();
pag.set_cambio(cambio);
if (cambio.is_zero())
{
imponibile = real(m.get(F_IMPONIBILI));
imposta = real(m.get(F_IMPOSTE));
}
else
{
pag.set_cambio(cambio);
imponibile = real(m.get(S_TOTDOCVAL));
imposta = ZERO;
}
pag.set_total(imponibile, imposta, spese);
pag.set_rate_auto();
m.set(FS_RDIFFER, pag.rate_differenziate() ? "1" : "2");
m.set(FS_NAMEPAG, pag.name());
m.set(FS_TIPOPR, pag.desc_tpr());
m.set(FS_MCOMM, pag.mese_commerciale() ? "X" : "");
m.set(FS_RECALC, "X", TRUE);
m.set(FS_NRATE, pag.n_rate());
pag.set_total(imponibile, imposta, spese);
pag.set_rate_auto();
bool new_part = TRUE;
TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
// prepara lo sheet
pag.set_sheet(ps);
_pag_rows = ps.rows_array();
m.set(FS_NRATE, pag.n_rate());
// se la prima rata e' fissa non si tocca
if (pag.tipo_prima_rata() > 3)
{
ps.disable_cell(0,0);
ps.disable_cell(0,1);
ps.disable_cell(0,2);
ps.disable_cell(0,3);
}
pag.set_sheet(ps); // prepara lo sheet
_pag_rows = ps.rows_array(); // copia sheet
}
bool TPrimanota_application::read_scadenze(TMask& m)
{
// should never happen but it doesn't hurt
if (_rel->cg(0).empty()) return FALSE;
const real imponibile(m.get(F_IMPONIBILI));
const real imposta(m.get(F_IMPOSTE));
const real spese(0.0);
TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
m.set(FS_RECALC, "X");
TPagamento& pag = *pagamento();
pag.set_total(imponibile, imposta, spese);
const TRectype& testa = _rel->lfile().curr();
const TRectype& testa = _rel->curr();
const long nreg = testa.get_long("NUMREG");
const TString16 ndoc(testa.get("NUMDOC"));
const int tmov = testa.get_int("TIPOMOV");
@ -294,7 +285,25 @@ bool TPrimanota_application::read_scadenze(TMask& m)
const TString16 codcaus(testa.get("CODCAUS"));
const TString16 codval (testa.get("CODVAL"));
const real cambio(testa.get("CAMBIO"));
TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
real imponibile, imposta;
const real spese(0.0);
TPagamento& pag = *pagamento();
if (cambio.sign() > 0)
{
pag.set_cambio(cambio);
imponibile = real(m.get(S_TOTDOCVAL));
imposta = ZERO;
}
else
{
imponibile = real(m.get(F_IMPONIBILI));
imposta = real(m.get(F_IMPOSTE));
}
pag.set_total(imponibile, imposta, spese);
const TRectype& prima = _rel->cg(0);
const char sezione = prima.get_char("SEZIONE"); // Dare/Avere
const int nriga = 1;
@ -308,12 +317,13 @@ bool TPrimanota_application::read_scadenze(TMask& m)
int npart = part.prima_fattura(nreg);
bool fromscratch = FALSE;
bool scad_locked = FALSE;
if (npart > 0) // la gh'e'
{
const TRiga_partite& partita = part.riga(npart);
const TRiga_scadenze& primarata = partita.rata(1);
scad_locked = partita.ultima_ratapagata() > 0;
// se si e' specificato un codice pagamento diverso si rifa' da capo
// la follia e' che e' sulle SCADENZE, non sulle partite, naturalmente
@ -382,6 +392,21 @@ bool TPrimanota_application::read_scadenze(TMask& m)
// se la prima rata e' fissa non si tocca
if (pag.tipo_prima_rata() > 3)
ps.disable_cell(0,-1);
if (scad_locked)
{
m.disable(-1); // Disabilita cliente
m.disable(-2); // Disabilita fornitore
m.disable(-3); // Disabilita cambio
m.disable(F_CODPAG); // Disabilita codice pagamento
m.disable(F_ANNORIF); // Disabilita anno partita
m.disable(F_NUMRIF); // Disabilita numero partita
m.disable(FS_RESET); // Disabilita tasto di reset
m.set(FS_RECALC, "", TRUE); // Disabilita ricalcolo automatico
m.disable(FS_RECALC);
}
else
m.set(FS_RECALC, "X");
return TRUE;
}

View File

@ -99,8 +99,8 @@ BEGIN
INPUT CODTAB[1,5] 109
INPUT CODTAB[6,10] 110
COPY DISPLAY 107
OUTPUT 108 CODTAB[1,5]
OUTPUT 109 CODTAB[6,10]
OUTPUT 109 CODTAB[1,5]
OUTPUT 110 CODTAB[6,10]
OUTPUT 128 S0
CHECKTYPE NORMAL
END

View File

@ -230,6 +230,20 @@ void TPagamento::set_cambio(const real& cambio)
else
_cambio = cambio;
set_round(_cambio == 1.0 ? 0 : 2);
const bool in_valuta = _cambio != 1.0;
real lit;
for (int i = _rate.items()-1; i >= 0; i--)
{
TToken_string& row = (TToken_string&)_rate[i];
if (in_valuta)
{
lit = tpay_rata(i) * _cambio;
row.add(lit.string(), 7);
}
else
row.add("", 7);
}
}
@ -385,7 +399,7 @@ TToken_string& TPagamento::set_rata (int index, real perc, int day, int type,
return *tt;
}
void TPagamento::set_imprata(int i, real r)
void TPagamento::set_imprata(int i, const real& r)
{
TToken_string& tt = (TToken_string&)_rate[i];
TDate d = _inizio;
@ -395,6 +409,13 @@ void TPagamento::set_imprata(int i, real r)
tt.add((const char*)d, 3);
tt.add(r.string(), 4);
if (_cambio != 1.0)
{
const real lit = r * _cambio;
tt.add(lit.string(), 7);
}
else
tt.add("", 7);
}
void TPagamento::set_percrata(int i, real r)
@ -1282,12 +1303,9 @@ void TPagamento::set_sheet(TSheet_field& sf, int sscad)
// 6,7,8,9 - Banche
const bool paid = ratapagata(i);
ts.add(paid ? "X" : "", 10); // 10 - Pagaya
if (paid)
{
sf.disable_cell(i,1); // importo
sf.disable_cell(i,2); // in valuta
sf.disable_cell(i,3); // percentuale
}
sf.enable_cell(i,1,!paid); // importo
sf.enable_cell(i,2,!paid); // in valuta
sf.enable_cell(i,3,!paid); // percentuale
}
for (; i < sf.items(); i++)
sf.destroy(i);
@ -1335,7 +1353,8 @@ void TPagamento::set_sheet(TSheet_field& sf, int sscad)
if (_inited)
{
sf.disable_cell(0,1); // importo
sf.disable_cell(0,2); // percentuale
sf.disable_cell(0,2); // in valuta
sf.disable_cell(0,3); // percentuale
}
else
{

View File

@ -104,6 +104,7 @@ public:
void set_code(const char* c) { _code = c; }
void set_round(int n) { _round = n; }
void set_cambio(const real& ex);
bool in_valuta() const { return _cambio != 1.0; }
// check consistency: returns word with errors flagged, 0 if ok
word validate() const;
@ -140,7 +141,7 @@ public:
void set_rate_auto();
// data una rata esistente, riaggiusta gli importi usando lo slicer e
// le scadenze usando la data di inizio
void set_imprata(int i, real r);
void set_imprata(int i, const real& r);
// slicer interface
void set_total(const real& ib, const real& im, const real& sp);

View File

@ -477,6 +477,13 @@ void TRiga_partite::elimina_rate()
}
}
int TRiga_partite::ultima_ratapagata() const
{
for (int r = rate(); r > 0; r--)
if (rata(r).chiusa()) break;
return r;
}
int TRiga_partite::read(TBaseisamfile& f, word op)
{
int err = TRectype::read(f, op);
@ -922,13 +929,9 @@ void TPartita::rimuovi_riga(int r)
{
TRiga_partite& row = riga(r);
if (row.rate() > 0)
{
row.elimina_rate();
}
else
{
CHECKD(!utilizzata(r), "Can't remove still referenced row ", r);
}
_part.destroy_row(r);
}

View File

@ -157,6 +157,7 @@ public:
void elimina_rate();
TRiga_scadenze& new_row(int r = 0);
int ultima_ratapagata() const;
int ultimo_pagamento(int rata) const;
char sezione() const { return get_char(PART_SEZ); }
bool in_valuta() const { return get(PART_CODVAL).not_empty(); }