Correzioni varie al calcolo delle scadenze + correzione della cancellazione di un pagamento
git-svn-id: svn://10.65.10.50/trunk@2363 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
2fbf4c8ad8
commit
80ee4b54fd
@ -210,7 +210,8 @@ void TPagamento::set_numero_rate(int n, int sscad, int rdiff)
|
||||
{
|
||||
set_imprata (i, div);
|
||||
rem -= tpay_rata(i);
|
||||
}
|
||||
}
|
||||
|
||||
set_percrata(i, perc);
|
||||
}
|
||||
if (_inited && _tpr > 0 && _tpr < 4)
|
||||
@ -466,7 +467,7 @@ void TPagamento::set_imprata(int i, const real& r)
|
||||
}
|
||||
|
||||
void TPagamento::set_percrata(int i, real r)
|
||||
{
|
||||
{
|
||||
TToken_string& tt = (TToken_string&)_rate[i];
|
||||
tt.add(r.string(), 1);
|
||||
}
|
||||
@ -544,8 +545,11 @@ word TPagamento::validate() const
|
||||
// check percentages & prepare slicer
|
||||
for (int i = first; i < n_rate(); i++)
|
||||
r += perc_rata(i);
|
||||
r.round(1);
|
||||
if (r != real(100.0))
|
||||
r -= real(100.0);
|
||||
real delta(0.005);
|
||||
delta = delta * real(n_rate());
|
||||
r = abs(r);
|
||||
if (r > delta)
|
||||
res |= P_RSUM;
|
||||
|
||||
|
||||
@ -700,7 +704,10 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified,
|
||||
{
|
||||
newv = new_value;
|
||||
rmax = is_perc_modified ? real(100.0) : (_tpr < 4 ? _firstr : _secndr);
|
||||
if (newv > rmax) return P_RSUM;
|
||||
real max_value(rmax);
|
||||
if (_tpr > 0 && _tpr < 4 && row == 0)
|
||||
max_value += _secndr;
|
||||
if (newv > max_value) return P_RSUM;
|
||||
}
|
||||
|
||||
bool exhausted = FALSE;
|
||||
@ -869,7 +876,8 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified,
|
||||
// ripartisci l'importo nel numero necessario di rate per
|
||||
// mantenere costante il valore
|
||||
real sum(0.0);
|
||||
if (_inited) lastdate = data_rata(rdiff == 2 ? first : row);
|
||||
if (_inited)
|
||||
lastdate = data_rata(rdiff == 2 ? first : row);
|
||||
|
||||
TDate dd(lastdate);
|
||||
int type = oldtype;
|
||||
@ -877,14 +885,14 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified,
|
||||
int nscd = oldscad;
|
||||
int frstd = scad_rata(0);
|
||||
|
||||
const int frs = (rdiff == 3 || rdiff == 4) ? row+1 : first;
|
||||
const int frs = (rdiff == 3 || rdiff == 4) ? row+1 : first ;
|
||||
const real mx = (rdiff == 3 || rdiff == 4) ? remainder : rmax;
|
||||
|
||||
// cancelliamo tutto, va'
|
||||
for (int j = srate.items()-1; j >= frs; j--) _rate.destroy(j);
|
||||
|
||||
const int n = srate.items(); // questo rimane per forza costante
|
||||
if (rdiff == 2 && n > 1+first)
|
||||
if (rdiff == 2 && n > 1 /*28/12/95 +first */)
|
||||
{
|
||||
// HERE
|
||||
real tot = is_perc_modified ? real(100.0) : (_tpr < 4 ? _firstr : _secndr);
|
||||
@ -894,7 +902,7 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified,
|
||||
|
||||
// se ho modificato la prima, divido il resto nelle successive
|
||||
// lasciando costante il numero rate
|
||||
if (row == first)
|
||||
if (row == 0 /* 28/12/95 first */)
|
||||
{
|
||||
if (!delta.is_zero()) nimp -= delta;
|
||||
// inferiore al minimo
|
||||
@ -929,16 +937,18 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified,
|
||||
// Dunque: prendo la prima, calcolo il resto, divido per quella nuova,
|
||||
// se resto lo sommo alla prima, e faccio quante rate servono
|
||||
|
||||
TToken_string& trt = (TToken_string&)srate[first];
|
||||
TToken_string& trt = (TToken_string&)srate[0 /* 28/12/95 first */];
|
||||
real rfirst(is_perc_modified ? trt.get(1) : trt.get(4));
|
||||
if (!delta.is_zero()) rfirst -= delta;
|
||||
if (_tpr >= 4) rfirst = ZERO;
|
||||
real rest = tot - rfirst;
|
||||
real div = rest / nimp;
|
||||
if (div < real(1.0)) { _rate = srate; return P_TROP; }
|
||||
|
||||
int nr = (int)div.integer() + (_tpr > 3 ? 2 : 1);
|
||||
real reminder = rest - (nimp * real(nr - 1 - first));
|
||||
int nr = (int)div.integer() + 1 /* 28/12/95 (_tpr > 3 ? 2 : 1) */;
|
||||
real reminder = rest - (nimp * real(nr - 1 /*28/12/95 - first */));
|
||||
rfirst += reminder;
|
||||
if (_tpr >= 4) rfirst += nimp;
|
||||
for (int k = first; k < nr; k++)
|
||||
{
|
||||
nscd = oldscad;
|
||||
@ -980,7 +990,7 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified,
|
||||
nscd = atoi(trt.get(0));
|
||||
if (type == 0) type = 1;
|
||||
if (j > 0 && nscd == 0) nscd = oldscad;
|
||||
if (_inited && dd == lastdate && j > frs)
|
||||
if (_inited && dd == lastdate && j > frs)
|
||||
next_scad(dd,nscd,mcomm,j);
|
||||
}
|
||||
else if (_inited)
|
||||
@ -990,8 +1000,9 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified,
|
||||
next_scad(dd,nscd,mcomm,j);
|
||||
}
|
||||
else nscd = _int_rate;
|
||||
|
||||
TToken_string& ttr = set_rata(j, is_perc_modified ? newv : ZERO,
|
||||
|
||||
real imp(newv);
|
||||
TToken_string& ttr = set_rata(j, is_perc_modified ? imp : ZERO,
|
||||
nscd, type);
|
||||
if (_inited)
|
||||
ttr.add(dd.string(), 3);
|
||||
@ -1002,17 +1013,19 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified,
|
||||
if ((mx - sum) < newv)
|
||||
{
|
||||
// add remainder on first rate
|
||||
newv += (mx - sum);
|
||||
imp += (mx - sum);
|
||||
if (rdiff == 3)
|
||||
{
|
||||
newv = is_perc_modified ? perc_rata(first) : tpay_rata(first);
|
||||
newv += (mx - sum);
|
||||
}
|
||||
imp = is_perc_modified ? perc_rata(first) : tpay_rata(first);
|
||||
imp += (mx - sum);
|
||||
}
|
||||
if (_inited && _tpr >0 && _tpr < 4)
|
||||
imp += _secndr;
|
||||
if (!is_perc_modified)
|
||||
set_imprata(first, newv);
|
||||
set_imprata(first, imp);
|
||||
else {
|
||||
TToken_string& t = rata(first);
|
||||
t.add(newv.string(), 1);
|
||||
t.add(imp.string(), 1);
|
||||
}
|
||||
remove_rata(j);
|
||||
break;
|
||||
@ -1296,7 +1309,7 @@ int TPagamento::remove(TTable& r)
|
||||
TString16 s; int err = NOERR;
|
||||
for (int i = 0 ; err == NOERR; i++)
|
||||
{
|
||||
r.zero(); s.format("%s%3d", _code, i);
|
||||
r.zero(); s.format("%s%3d", (const char*)_code, i);
|
||||
r.put("CODTAB", s);
|
||||
if (r.read() == NOERR)
|
||||
err = r.remove();
|
||||
@ -1555,4 +1568,4 @@ _def_tpr(1), _def_ulc(""), _round(0), _int_rate(30), _tpr(0), _rdiff(FALSE)
|
||||
|
||||
if (_code.blank() || !read())
|
||||
_new = TRUE;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user