1995-11-07 10:03:02 +00:00
|
|
|
#include <applicat.h>
|
1995-11-03 07:47:20 +00:00
|
|
|
#include <utility.h>
|
|
|
|
#include "pagament.h"
|
|
|
|
|
|
|
|
#include <mov.h>
|
|
|
|
#include <partite.h>
|
|
|
|
#include <scadenze.h>
|
|
|
|
#include <pagsca.h>
|
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
// se settato, si usa per rate nuove l'intervallo rate default (letto da
|
|
|
|
// tab. pagamenti)
|
1996-01-08 11:32:33 +00:00
|
|
|
#define USE_DEFAULT_INT_RATE 1
|
1996-01-08 09:55:34 +00:00
|
|
|
|
1995-11-07 11:37:38 +00:00
|
|
|
inline void swap(int& x, int& y) {int tmp = x; x = y; y = tmp; }
|
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
int TPagamento::_rata_ifield(int n, int f) const
|
|
|
|
{
|
|
|
|
TToken_string& t = (TToken_string&)_rate[n];
|
|
|
|
return t.get_int(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
long TPagamento::_rata_lfield(int n, int f) const
|
|
|
|
{
|
|
|
|
TToken_string& t = (TToken_string&)_rate[n];
|
|
|
|
return t.get_long(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
real TPagamento::_rata_rfield(int n, int f) const
|
|
|
|
{
|
|
|
|
TToken_string& t = (TToken_string&)_rate[n];
|
|
|
|
return real(t.get(f));
|
|
|
|
}
|
|
|
|
|
|
|
|
TDate TPagamento::_rata_dfield(int n, int f) const
|
|
|
|
{
|
|
|
|
TToken_string& t = (TToken_string&)_rate[n];
|
|
|
|
return TDate(t.get(f));
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* TPagamento::_rata_sfield(int n, int f) const
|
|
|
|
{
|
|
|
|
static char kak[16];
|
|
|
|
TToken_string& t = (TToken_string&)_rate[n];
|
|
|
|
const char* k = t.get(f);
|
|
|
|
if (k != NULL)
|
|
|
|
strncpy(kak, k, 16);
|
|
|
|
else
|
|
|
|
kak[0] = '\0';
|
|
|
|
return kak;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPagamento::set_inizio(const TDate& d)
|
1996-01-09 18:50:34 +00:00
|
|
|
{
|
|
|
|
_datadoc = d;
|
1995-11-14 10:27:10 +00:00
|
|
|
_inizio = d;
|
|
|
|
// aggiusta _inizio secondo INSCAD; vedi mese commerciale etc.
|
|
|
|
if (_inscad == 'M')
|
|
|
|
{
|
|
|
|
if (_mcomm) _inizio.set_day(_inizio.month() == 2 ? 28 : 30);
|
|
|
|
else _inizio.set_end_month();
|
|
|
|
}
|
1995-12-01 11:46:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_inscad == 'F' && _mcomm && _inizio.day() == 31)
|
|
|
|
_inizio.set_day(30);
|
|
|
|
}
|
|
|
|
|
|
|
|
TDate data(d); // Aggiusta data iniziale con i gironi prima rata
|
|
|
|
next_scad(data, scad_rata(0), _mcomm, 0);
|
1995-11-14 10:27:10 +00:00
|
|
|
|
1995-12-01 11:46:35 +00:00
|
|
|
bool dummy;
|
|
|
|
recalc_rate(0, FALSE, NULL, data.string(), NULL, NULL, _rdiff, _mcomm, dummy);
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TPagamento::set_intervallo_rate(int in)
|
|
|
|
{
|
|
|
|
if (_mcomm && (in % 30) != 0)
|
1995-11-07 11:37:38 +00:00
|
|
|
{
|
|
|
|
if (yesno_box("E' specificato \"mese commerciale\". Si desidera annullarlo?"))
|
|
|
|
_mcomm = FALSE;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int i = 1; i < n_rate(); i++)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
|
|
|
TToken_string& ts = rata(i);
|
1995-11-07 11:37:38 +00:00
|
|
|
ts.add(in, 0);
|
|
|
|
}
|
|
|
|
_int_rate = in;
|
|
|
|
_dirty = TRUE;
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TPagamento::set_mese_commerciale(bool v, int& sscad)
|
|
|
|
{
|
|
|
|
_dirty = FALSE;
|
|
|
|
if (_mcomm == v) return;
|
|
|
|
if (sscad < 0) sscad = 30;
|
|
|
|
|
|
|
|
if ((sscad % 30) != 0) sscad = 30 * ((sscad/30)+1);
|
|
|
|
set_intervallo_rate(sscad);
|
|
|
|
|
|
|
|
_mcomm = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPagamento::set_rate_differenziate(int v)
|
|
|
|
{
|
|
|
|
_dirty = FALSE;
|
|
|
|
if (_rdiff ^ v == 2) return;
|
|
|
|
|
|
|
|
if (v == 2 && (100 % n_rate()) == 0)
|
|
|
|
{
|
|
|
|
int p = 100 / n_rate();
|
|
|
|
for (int i = _tpr < 4 ? 0 : 1; i < n_rate(); i++)
|
|
|
|
{
|
|
|
|
TToken_string& tt = rata(i);
|
|
|
|
tt.add(p,1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_rdiff = (v != 2);
|
|
|
|
_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPagamento::set_tipo_prima_rata(int v, int sscad)
|
|
|
|
{
|
|
|
|
_dirty = FALSE;
|
1995-11-22 10:56:09 +00:00
|
|
|
if (_tpr == v) return;
|
1995-11-03 07:47:20 +00:00
|
|
|
|
|
|
|
if (v < 4 && _tpr > 3)
|
|
|
|
{
|
|
|
|
for (int i = n_rate() - 1; i > 0; i--)
|
|
|
|
{
|
|
|
|
TToken_string& tt = rata(i);
|
|
|
|
tt.add(scad_rata(i-1),0);
|
|
|
|
tt.add(tipo_rata(i-1),2);
|
|
|
|
tt.add(ulc_rata(i-1),5);
|
|
|
|
}
|
1996-01-11 15:44:06 +00:00
|
|
|
_rate.destroy(0, TRUE);
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if ( _tpr < 4 && v > 3)
|
|
|
|
{
|
|
|
|
TToken_string* ttn = new TToken_string(32);
|
|
|
|
ttn->add(0, 0);
|
|
|
|
ttn->add(0, 1);
|
|
|
|
ttn->add(1, 2);
|
|
|
|
ttn->add("", 3);
|
|
|
|
ttn->add("", 4);
|
|
|
|
ttn->add("", 5);
|
|
|
|
_rate.insert(ttn,0);
|
|
|
|
for (int i = 0; i < (n_rate()-1); i++)
|
|
|
|
{
|
|
|
|
TToken_string& tt = rata(i);
|
|
|
|
tt.add(scad_rata(i+1),0);
|
|
|
|
tt.add(tipo_rata(i+1),2);
|
|
|
|
tt.add(ulc_rata(i+1), 5);
|
1995-11-22 10:56:09 +00:00
|
|
|
}
|
|
|
|
if (n_rate() == 2 && scad_rata(1) == 0)
|
|
|
|
{
|
|
|
|
// l'unica rata aveva scadenza 0; ci mettiamo n.giorni default
|
|
|
|
TToken_string& tt = rata(1);
|
|
|
|
tt.add(_int_rate, 0);
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_tpr = v;
|
|
|
|
_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPagamento::set_numero_rate(int n, int sscad, int rdiff)
|
|
|
|
{
|
|
|
|
_dirty = FALSE;
|
|
|
|
if (n == 0 || n == n_rate()) return;
|
|
|
|
|
|
|
|
const int nr = n_rate();
|
|
|
|
const int first = _tpr < 4 ? 0 : 1;
|
|
|
|
real sum = 0.0;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
// diciamo che gli diciamo il numero giusto
|
|
|
|
if (first == 1 && n < 2) return;
|
|
|
|
|
1995-12-22 15:33:27 +00:00
|
|
|
int nact = first == 1 ? n - 1 : n;
|
1995-11-03 07:47:20 +00:00
|
|
|
|
|
|
|
real p = real(100) / real(nact);
|
|
|
|
p.round(2);
|
|
|
|
|
|
|
|
if (_inited || (!_inited && rdiff == 1)) // se e' inited rdiff e' 2 per forza
|
|
|
|
{
|
|
|
|
real tot = _inited ? (_tpr < 4 ? _firstr : _secndr) : real(100.0);
|
|
|
|
if (nact == 1)
|
|
|
|
{
|
|
|
|
if (_inited) set_imprata(first, tot);
|
|
|
|
set_percrata(first, real(100.0));
|
|
|
|
if (_inited && _tpr > 0 && _tpr < 4)
|
|
|
|
set_imprata(first, tpay_rata(first) + _secndr);
|
|
|
|
i = first + 1; // per rimozione successiva
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
if (nr == first + 1)
|
1995-12-22 15:33:27 +00:00
|
|
|
{
|
1995-11-03 07:47:20 +00:00
|
|
|
// suddividi equamente e riaggiusta la percentuale di conseguenza
|
1995-12-22 15:33:27 +00:00
|
|
|
real div = tot / real(nact);
|
|
|
|
if (_inited)
|
|
|
|
div.round(_round);
|
|
|
|
real perc = (100.0 * div) / tot;
|
|
|
|
real rem(tot);
|
1996-01-03 09:50:01 +00:00
|
|
|
real p(perc);
|
1995-12-22 15:33:27 +00:00
|
|
|
|
1996-01-03 09:50:01 +00:00
|
|
|
p.round(2);
|
1995-11-03 07:47:20 +00:00
|
|
|
for (i = first; i < n; i++)
|
|
|
|
{
|
1996-01-09 11:13:41 +00:00
|
|
|
if (i > first)
|
|
|
|
{
|
|
|
|
int scd = sscad == -1 ? scad_rata(first) : sscad;
|
|
|
|
#ifdef USE_DEFAULT_INT_RATE
|
|
|
|
if (scd == 0)
|
|
|
|
scd = _int_rate;
|
|
|
|
#endif
|
|
|
|
add_rata(perc, scd, tipo_rata(0));
|
|
|
|
}
|
1995-12-22 15:33:27 +00:00
|
|
|
if (_inited)
|
|
|
|
{
|
|
|
|
set_imprata (i, div);
|
|
|
|
rem -= tpay_rata(i);
|
1996-01-03 09:50:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
rem -= p;
|
1995-12-29 11:06:12 +00:00
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
set_percrata(i, perc);
|
|
|
|
}
|
|
|
|
if (_inited && _tpr > 0 && _tpr < 4)
|
|
|
|
set_imprata(0, tpay_rata(0) + _secndr);
|
1996-01-03 09:50:01 +00:00
|
|
|
if (rem != ZERO)
|
1995-12-22 15:33:27 +00:00
|
|
|
{
|
1996-01-03 09:50:01 +00:00
|
|
|
if (_inited)
|
|
|
|
{
|
|
|
|
real r(tpay_rata(first) + rem);
|
|
|
|
set_imprata(first, r);
|
|
|
|
if (_inited && _tpr > 0 && _tpr < 4)
|
|
|
|
r -= _secndr;
|
|
|
|
set_percrata(first, 100 * r / tot);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const real r(perc_rata(first) + rem);
|
|
|
|
|
|
|
|
set_percrata(first, r);
|
|
|
|
}
|
1995-12-22 15:33:27 +00:00
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
else if (nr > first + 1)
|
|
|
|
{
|
|
|
|
// dalla prima nota e' abilitato solo se rdiff == 2
|
|
|
|
// e' selezionato UGUALI: devo: lasciare la prima
|
|
|
|
// rata com'e' (a meno che non ce ne sia una sola) e
|
|
|
|
// suddividere il resto dell'importo tra le altre
|
1995-12-20 10:16:55 +00:00
|
|
|
real rfirst = _inited ? tpay_rata(0) : perc_rata(0);
|
1995-11-03 07:47:20 +00:00
|
|
|
if (_inited && _tpr > 0 && _tpr < 4) rfirst -= _secndr;
|
1995-12-22 15:33:27 +00:00
|
|
|
|
|
|
|
real rest = tot - (_tpr >= 4 ? ZERO : rfirst);
|
|
|
|
real div = rest / real(nact - (first > 0 ? 0 : 1));
|
|
|
|
if (_inited)
|
|
|
|
div.round(_round);
|
|
|
|
|
|
|
|
real perc = (100.0 * div)/tot;
|
|
|
|
real rem(rest);
|
1996-01-03 09:50:01 +00:00
|
|
|
real p(perc);
|
|
|
|
|
|
|
|
p.round(2);
|
1995-12-20 10:16:55 +00:00
|
|
|
for (i = 1; i < n; i++)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
1996-01-09 11:13:41 +00:00
|
|
|
if (i >= nr)
|
|
|
|
{
|
|
|
|
int scd = sscad == -1 ? scad_rata(first) : sscad;
|
|
|
|
#ifdef USE_DEFAULT_INT_RATE
|
|
|
|
if (scd == 0)
|
|
|
|
scd = _int_rate;
|
|
|
|
#endif
|
1995-12-22 15:33:27 +00:00
|
|
|
add_rata(perc, (sscad == -1 ? scad_rata(nr-1) : sscad),
|
1995-11-03 08:04:05 +00:00
|
|
|
tipo_rata(nr-1), ulc_rata(nr-1));
|
1996-01-09 11:13:41 +00:00
|
|
|
}
|
1995-12-22 15:33:27 +00:00
|
|
|
if (_inited)
|
|
|
|
{
|
|
|
|
set_imprata (i, div);
|
|
|
|
rem -= tpay_rata(i);
|
|
|
|
}
|
1996-01-03 09:50:01 +00:00
|
|
|
else
|
|
|
|
rem -= p;
|
1995-11-03 07:47:20 +00:00
|
|
|
set_percrata(i, perc);
|
|
|
|
}
|
1996-01-03 09:50:01 +00:00
|
|
|
if (rem != ZERO)
|
1995-12-22 15:33:27 +00:00
|
|
|
{
|
1996-01-03 09:50:01 +00:00
|
|
|
if (_inited)
|
|
|
|
{
|
|
|
|
real r(tpay_rata(first) + rem);
|
|
|
|
set_imprata(first, r);
|
|
|
|
if (_inited && _tpr > 0 && _tpr < 4)
|
|
|
|
r -= _secndr;
|
|
|
|
set_percrata(first, 100 * r / tot);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const real r(perc_rata(first) + rem);
|
|
|
|
|
|
|
|
set_percrata(first, r);
|
|
|
|
}
|
1995-12-22 15:33:27 +00:00
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
1996-01-03 09:50:01 +00:00
|
|
|
{
|
1995-11-03 07:47:20 +00:00
|
|
|
for (i = first; sum < real(100.0); i++)
|
|
|
|
{
|
|
|
|
if ((real(100.0) - sum) < p)
|
|
|
|
p = real(100.0) - sum;
|
|
|
|
|
|
|
|
sum += p;
|
|
|
|
|
|
|
|
// if necessary add remainder on first one
|
|
|
|
if ((real(100.0) - sum) /* still */ < p)
|
|
|
|
{
|
|
|
|
real prc = perc_rata(first);
|
|
|
|
prc += real(100.0) - sum;
|
|
|
|
TToken_string& rt = rata(first);
|
|
|
|
rt.add(prc.string(),1),
|
|
|
|
sum = 100;
|
|
|
|
}
|
|
|
|
|
1996-01-09 11:13:41 +00:00
|
|
|
int scd = i == 0 ? (i < nr ? scad_rata(0) : 0) :
|
|
|
|
(sscad == -1 ? (i < nr ? scad_rata(i) : scad_rata(nr-1)) : sscad);
|
|
|
|
#ifdef USE_DEFAULT_INT_RATE
|
|
|
|
if (i != 0 && scd == 0)
|
|
|
|
scd = _int_rate;
|
|
|
|
#endif
|
|
|
|
set_rata(i, real(p), scd,
|
1995-11-03 07:47:20 +00:00
|
|
|
(i < nr ? tipo_rata(i) : tipo_rata(nr-1)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// erase remaining
|
1996-01-09 11:13:41 +00:00
|
|
|
remove_rate_from(i);
|
1995-12-22 15:33:27 +00:00
|
|
|
adjust_fixed_scad();
|
1995-11-03 07:47:20 +00:00
|
|
|
|
|
|
|
_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPagamento::set_cambio(const real& cambio)
|
1996-01-05 15:17:50 +00:00
|
|
|
{
|
|
|
|
const bool era_valuta = _cambio != 1.0;
|
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
if (cambio.sign() <= 0)
|
|
|
|
_cambio = 1.0;
|
|
|
|
else
|
|
|
|
_cambio = cambio;
|
1996-01-05 15:17:50 +00:00
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
const bool in_valuta = _cambio != 1.0;
|
1996-01-05 15:17:50 +00:00
|
|
|
set_round(in_valuta ? 3 : 0); // Ricalcola arrotondamento
|
|
|
|
|
|
|
|
real imp; // Importo di parcheggio
|
|
|
|
|
|
|
|
if (era_valuta)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
1996-01-05 15:17:50 +00:00
|
|
|
for (int i = _rate.items()-1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
TToken_string& row = (TToken_string&)_rate[i];
|
|
|
|
if (in_valuta)
|
|
|
|
{
|
|
|
|
imp = tpay_rata(i) * _cambio; imp.round(0);
|
|
|
|
row.add(imp.string(), 7);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
imp = tlit_rata(i);
|
|
|
|
row.add(imp.string(), 4);
|
|
|
|
row.add("", 7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_valuta)
|
|
|
|
{
|
|
|
|
real imponibile = _imponibile * _cambio; imponibile.round(_round);
|
|
|
|
real imposta = _imposta * _cambio; imposta.round(_round);
|
|
|
|
real spese = _spese * _cambio; spese.round(_round);
|
|
|
|
set_total(imponibile, imposta, spese);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1995-11-03 07:47:20 +00:00
|
|
|
if (in_valuta)
|
|
|
|
{
|
1996-01-05 15:17:50 +00:00
|
|
|
for (int i = _rate.items()-1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
TToken_string& row = (TToken_string&)_rate[i];
|
|
|
|
imp = tpay_rata(i);
|
|
|
|
row.add(imp.string(), 7);
|
|
|
|
imp /= cambio; imp.round(_round);
|
|
|
|
row.add(imp.string() , 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
real imponibile = _imponibile / _cambio; imponibile.round(_round);
|
|
|
|
real imposta = _imposta / _cambio; imposta.round(_round);
|
|
|
|
real spese = _spese / _cambio; spese.round(_round);
|
|
|
|
set_total(imponibile, imposta, spese);
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPagamento::next_scad(TDate& d, int scad, bool mcomm, int rata)
|
|
|
|
{
|
|
|
|
if (mcomm)
|
|
|
|
{
|
|
|
|
int nm = scad / 30;
|
|
|
|
int ny = nm / 12;
|
|
|
|
nm %= 12;
|
|
|
|
|
|
|
|
int newm = d.month() + nm;
|
|
|
|
if (newm > 12) { newm -= 12; ny++; }
|
|
|
|
|
|
|
|
bool last = d.is_end_month() && inizio_scadenza() == 'M';
|
|
|
|
|
|
|
|
int dy = d.day();
|
|
|
|
|
|
|
|
// la palla del febbraio & c.
|
|
|
|
if (rata > 1)
|
|
|
|
{
|
|
|
|
TDate oldd(data_rata(rata-2));
|
|
|
|
if (oldd.day() > dy) dy = oldd.day();
|
|
|
|
}
|
|
|
|
|
|
|
|
d.set_day(1); // il giorno 1 ce l'hanno tutti
|
|
|
|
d.set_month(newm);
|
|
|
|
d.set_year(d.year()+ny);
|
|
|
|
|
|
|
|
d.set_end_month();
|
|
|
|
if (!last && dy < d.day())
|
|
|
|
d.set_day(dy);
|
|
|
|
}
|
1995-11-16 09:56:22 +00:00
|
|
|
else d += scad;
|
1995-11-03 07:47:20 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPagamento::set_default_type(int type, bool change_existing)
|
|
|
|
{
|
|
|
|
_def_tpr = type;
|
|
|
|
if (change_existing)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < n_rate(); i++)
|
|
|
|
{
|
|
|
|
TToken_string& tt = rata(i);
|
|
|
|
tt.add(type, 2);
|
|
|
|
}
|
|
|
|
_dirty = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPagamento::set_default_ulc(const char* ulc, bool change_existing)
|
|
|
|
{
|
|
|
|
_def_ulc = ulc;
|
|
|
|
if (change_existing)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < n_rate(); i++)
|
|
|
|
{
|
|
|
|
TToken_string& tt = rata(i);
|
|
|
|
tt.add(ulc, 5);
|
|
|
|
}
|
|
|
|
_dirty = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPagamento::remove_rata(int i)
|
|
|
|
{
|
1996-01-11 15:44:06 +00:00
|
|
|
// non fa nessun ricalcolo, si limita ad impacchettare se necessario
|
|
|
|
_rate.destroy(i, TRUE);
|
1995-11-03 07:47:20 +00:00
|
|
|
_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
void TPagamento::remove_rate_from(int i)
|
|
|
|
{
|
|
|
|
// elimina dall'ultima a quella indicata (compresa)
|
|
|
|
for (int j = n_rate() - 1; j >= i; j--)
|
|
|
|
_rate.destroy(j);
|
|
|
|
_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TToken_string& TPagamento::add_rata()
|
|
|
|
{
|
|
|
|
// rata vuota, con -1 sulla scadenza per segnalare
|
|
|
|
TToken_string* tt = new TToken_string("-1| | | | | | ");
|
|
|
|
_rate.add(tt);
|
|
|
|
_dirty = TRUE;
|
|
|
|
return *tt;
|
|
|
|
}
|
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
TToken_string& TPagamento::add_rata(real perc, int day, int type, const char* ulc)
|
|
|
|
{
|
|
|
|
TToken_string* tt = new TToken_string(64);
|
|
|
|
|
|
|
|
tt->add(day); // scadenza
|
|
|
|
tt->add(perc.string()); // percentuale
|
|
|
|
tt->add(type); // tipo
|
|
|
|
tt->add(""); // data
|
|
|
|
tt->add(""); // importo
|
|
|
|
tt->add(ulc); // ulc
|
|
|
|
|
|
|
|
_rate.add(tt);
|
|
|
|
_dirty = TRUE;
|
|
|
|
return *tt;
|
|
|
|
}
|
|
|
|
|
|
|
|
TToken_string& TPagamento::set_rata (int index, real perc, int day, int type,
|
|
|
|
const char* ulc, const char* imp, const char* data)
|
|
|
|
{
|
|
|
|
TToken_string* tt = (TToken_string*)_rate.objptr(index);
|
|
|
|
const bool nwr = (tt == NULL);
|
|
|
|
if (nwr) tt = new TToken_string(64);
|
|
|
|
|
|
|
|
tt->add(day,0); // scadenza
|
|
|
|
tt->add(perc.string(),1); // percentuale
|
|
|
|
tt->add(type,2); // tipo
|
|
|
|
tt->add(data == NULL ? "" : data, 3);
|
|
|
|
tt->add(imp == NULL ? "" : imp, 4);
|
|
|
|
tt->add(ulc == NULL ? "" : ulc, 5);
|
|
|
|
if (imp && *imp > ' ' && _cambio != 1.0)
|
|
|
|
{
|
|
|
|
real implit(imp);
|
|
|
|
implit *= _cambio;
|
|
|
|
implit.round();
|
|
|
|
tt->add(implit.string(), 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nwr)
|
|
|
|
{
|
|
|
|
if (index > _rate.items())
|
|
|
|
{
|
|
|
|
error_box("Rate non contigue");
|
|
|
|
delete tt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_rate.add(tt,index);
|
|
|
|
_dirty = TRUE;
|
|
|
|
}
|
|
|
|
return *tt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPagamento::set_imprata(int i, const real& r)
|
|
|
|
{
|
|
|
|
TToken_string& tt = (TToken_string&)_rate[i];
|
|
|
|
TDate d = _inizio;
|
|
|
|
|
|
|
|
for (int n = 0; n <= i; n++)
|
|
|
|
next_scad(d, scad_rata(n), _mcomm, n);
|
|
|
|
|
|
|
|
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)
|
1995-12-29 11:06:12 +00:00
|
|
|
{
|
1995-11-03 07:47:20 +00:00
|
|
|
TToken_string& tt = (TToken_string&)_rate[i];
|
|
|
|
tt.add(r.string(), 1);
|
|
|
|
}
|
|
|
|
|
1996-01-03 09:50:01 +00:00
|
|
|
void TPagamento::set_datarata(int i, const TDate & d)
|
|
|
|
{
|
|
|
|
TToken_string& tt = (TToken_string&)_rate[i];
|
|
|
|
tt.add((const char *) d, 3);
|
|
|
|
}
|
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
real TPagamento::recalc_percrata(int i)
|
|
|
|
{
|
|
|
|
real hm(_tpr < 4 ? _firstr : _secndr);
|
|
|
|
|
1995-12-22 15:33:27 +00:00
|
|
|
real tpay(tpay_rata(i));
|
|
|
|
if (i == 0 && _tpr > 0 && _tpr < 4)
|
|
|
|
tpay -= _secndr;
|
|
|
|
real perc = tpay * 100.0 / hm;
|
1995-11-03 07:47:20 +00:00
|
|
|
perc.round(2);
|
|
|
|
set_percrata(i, perc);
|
|
|
|
|
|
|
|
return perc;
|
|
|
|
}
|
|
|
|
|
|
|
|
TToken_string& TPagamento::set_rata(int index, const real& howmuch, const real& quanto,
|
|
|
|
const TDate& date, int type,const char* ulc, bool pagato)
|
|
|
|
{
|
|
|
|
// calcola percentuali e scadenze a partire dagli importi
|
|
|
|
TToken_string* tt = (TToken_string*)_rate.objptr(index);
|
|
|
|
const int first = _tpr < 4 ? 0 : 1;
|
|
|
|
|
|
|
|
const bool nwr = (tt == NULL); // nuova rata
|
|
|
|
|
|
|
|
if (nwr) tt = new TToken_string(64);
|
|
|
|
|
|
|
|
const TDate oldd = index > 0 ? data_rata(index -1) : _inizio;
|
|
|
|
const long day = date - oldd;
|
|
|
|
const real toshare(_tpr < 4 ? _firstr : _secndr);
|
|
|
|
|
|
|
|
real hm = howmuch;
|
|
|
|
if (index == first && _tpr > 0 && _tpr < 4)
|
|
|
|
hm -= _secndr;
|
|
|
|
|
|
|
|
real perc = (_tpr > 3 && index == 0) ? ZERO : hm/toshare;
|
|
|
|
perc *= real(100.0);
|
|
|
|
perc.round(2);
|
|
|
|
|
|
|
|
tt->cut(0);
|
|
|
|
tt->add(day); // 0 - scadenza
|
|
|
|
tt->add(perc.string()); // 1 - percentuale
|
|
|
|
tt->add(type); // 2 - tipo
|
|
|
|
tt->add(date.string()); // 3 - data
|
|
|
|
tt->add(howmuch.string()); // 4 - importo
|
|
|
|
tt->add(ulc); // 5 - ulc(era?)
|
|
|
|
tt->add(pagato ? "X" : " "); // 6 - pagata
|
|
|
|
tt->add(quanto.string()); // 7 - Importo in lire
|
|
|
|
if (!nwr)
|
|
|
|
{
|
|
|
|
if (index > _rate.items())
|
|
|
|
{
|
|
|
|
error_box("Rate non contigue");
|
|
|
|
delete tt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_rate.add(tt, index);
|
|
|
|
_dirty = TRUE;
|
|
|
|
}
|
|
|
|
return *tt;
|
|
|
|
}
|
|
|
|
|
|
|
|
word TPagamento::validate() const
|
|
|
|
{
|
|
|
|
word res = 0x0000;
|
|
|
|
real r(0.0);
|
|
|
|
|
|
|
|
int first = _tpr < 4 ? 0 : 1;
|
|
|
|
real toshare(_tpr < 4 ? _firstr : _secndr);
|
|
|
|
|
|
|
|
// check percentages & prepare slicer
|
|
|
|
for (int i = first; i < n_rate(); i++)
|
|
|
|
r += perc_rata(i);
|
1995-12-29 11:06:12 +00:00
|
|
|
r -= real(100.0);
|
|
|
|
real delta(0.005);
|
|
|
|
delta = delta * real(n_rate());
|
|
|
|
r = abs(r);
|
|
|
|
if (r > delta)
|
1995-11-03 07:47:20 +00:00
|
|
|
res |= P_RSUM;
|
|
|
|
|
|
|
|
|
|
|
|
if (_inited)
|
|
|
|
{
|
1996-01-04 13:39:57 +00:00
|
|
|
real tot;
|
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
for (int i = 0; i < n_rate(); i++)
|
1996-01-04 13:39:57 +00:00
|
|
|
{
|
|
|
|
const real tpay(tpay_rata(i));
|
|
|
|
|
|
|
|
if (tpay.is_zero())
|
|
|
|
res |= P_ZERO;
|
|
|
|
tot += tpay;
|
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
|
|
|
|
if (tot != _firstr+_secndr)
|
1996-01-04 13:39:57 +00:00
|
|
|
res |= P_TOTNC;
|
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
// check errori date scadenze (se istanziate)
|
|
|
|
TDate d(data_rata(0));
|
1996-01-09 18:50:34 +00:00
|
|
|
if (d < _datadoc) // _inizio
|
1995-11-16 09:56:22 +00:00
|
|
|
res |= P_INIZIO;
|
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
for (i = 1; i < n_rate(); i++)
|
|
|
|
{
|
|
|
|
if (data_rata(i) <= d)
|
|
|
|
{ res |= P_SCAD; break; }
|
|
|
|
d = data_rata(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TPagamento::strerr(word err, TString& s)
|
|
|
|
{
|
1995-12-13 15:12:13 +00:00
|
|
|
s = "Errore:\n";
|
1995-11-03 07:47:20 +00:00
|
|
|
if (err & P_RSUM)
|
1996-01-11 09:29:49 +00:00
|
|
|
s << "- le percentuali non sommano a 100\n";
|
1995-11-03 07:47:20 +00:00
|
|
|
if (err & P_IMPNC)
|
1996-01-11 09:29:49 +00:00
|
|
|
s << "- le percentuali sono inconsistenti con gli importi\n";
|
1995-11-03 07:47:20 +00:00
|
|
|
if (err & P_SCAD)
|
1996-01-11 09:29:49 +00:00
|
|
|
s << "- le scadenze non sono consecutive\n";
|
1995-11-03 07:47:20 +00:00
|
|
|
if (err & P_INIZIO)
|
1996-01-11 09:29:49 +00:00
|
|
|
s << "- la prima rata e' antecedente alla data del documento (" << _datadoc << ")\n"; // _inizio
|
1995-11-03 07:47:20 +00:00
|
|
|
if (err & P_NEG)
|
1996-01-11 09:29:49 +00:00
|
|
|
s << "- l'importo dato e' inferiore al minimo possibile\n";
|
1995-11-03 07:47:20 +00:00
|
|
|
if (err & P_TROP)
|
1996-01-11 09:29:49 +00:00
|
|
|
s << "- l'importo dato e' superiore al massimo possibile\n";
|
1995-11-03 07:47:20 +00:00
|
|
|
if (err & P_TOTNC)
|
1995-12-13 15:12:13 +00:00
|
|
|
{
|
|
|
|
const real tot = _firstr + _secndr;
|
|
|
|
real imp;
|
|
|
|
for (int i = 0; i < n_rate(); i++)
|
|
|
|
imp += tpay_rata(i);
|
1996-01-05 15:17:50 +00:00
|
|
|
const char pic[3] = { '.', _round, '\0' };
|
1996-01-11 09:29:49 +00:00
|
|
|
s << "- la somma degli importi (" << imp.string(pic);
|
1996-01-09 10:32:00 +00:00
|
|
|
s << ") e' diversa dal\ntotale del pagamento (" << tot.string(pic) << ")\n";
|
1995-12-13 15:12:13 +00:00
|
|
|
}
|
1995-11-07 11:37:38 +00:00
|
|
|
if (err & P_MCOMM)
|
1996-01-11 09:29:49 +00:00
|
|
|
s << "- scadenze incompatibili con il mese commerciale\n";
|
1996-01-04 13:39:57 +00:00
|
|
|
if (err & P_ZERO)
|
1996-01-11 09:29:49 +00:00
|
|
|
s << "- almeno una rata ha importo zero\n";
|
1996-01-09 18:50:34 +00:00
|
|
|
if (err & P_SCWIDE)
|
1996-01-11 09:29:49 +00:00
|
|
|
s << "- le scadenze sono troppo distanti\n";
|
|
|
|
if (err & P_TOOMANY)
|
|
|
|
s << "- il calcolo genera piu' di 999 rate!\n";
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* TPagamento::desc_tpr() const
|
|
|
|
{
|
|
|
|
const char* o;
|
|
|
|
switch (_tpr)
|
|
|
|
{
|
|
|
|
case 0: o = "Totale su tutte le rate"; break;
|
|
|
|
case 1: o = "Tutte le imposte su 1a"; break;
|
|
|
|
case 2: o = "Tutte le spese su 1a"; break;
|
|
|
|
case 3: o = "Imposte + spese su 1a"; break;
|
1995-11-08 15:43:11 +00:00
|
|
|
case 4: o = "Solo imposte"; break;
|
|
|
|
case 5: o = "Solo spese"; break;
|
|
|
|
case 6: o = "Imposte + spese"; break;
|
1995-11-03 07:47:20 +00:00
|
|
|
default: o = ""; break;
|
|
|
|
}
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
1996-01-12 11:28:43 +00:00
|
|
|
const char* TPagamento::desc_tipo(int tipo, char ulc, bool* ok) const
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
1996-01-12 11:28:43 +00:00
|
|
|
const char* o = "";
|
|
|
|
if (ok != NULL) *ok = TRUE;
|
1995-11-03 13:56:08 +00:00
|
|
|
if (ulc > ' ')
|
|
|
|
{
|
|
|
|
const char key[] = { tipo+'0', ulc, '\0' };
|
|
|
|
TTable clr("%CLR");
|
|
|
|
clr.put("CODTAB", key);
|
|
|
|
|
1995-12-20 16:16:14 +00:00
|
|
|
const int err = clr.read();
|
1996-01-12 11:28:43 +00:00
|
|
|
if (err == NOERR)
|
|
|
|
o = clr.get("S0");
|
|
|
|
else if (ok != NULL)
|
|
|
|
*ok = FALSE;
|
1995-11-03 13:56:08 +00:00
|
|
|
}
|
1996-01-12 11:28:43 +00:00
|
|
|
if (*o == '\0')
|
1995-11-03 13:56:08 +00:00
|
|
|
{
|
|
|
|
switch (tipo)
|
1995-12-20 16:16:14 +00:00
|
|
|
{
|
|
|
|
case 0: o = "Altro pagamento"; break;
|
1995-11-03 13:56:08 +00:00
|
|
|
case 1: o = "Rimessa diretta o contanti"; break;
|
|
|
|
case 2: o = "Tratta"; break;
|
1995-11-07 10:03:02 +00:00
|
|
|
case 3: o = "Ricevuta Bancaria"; break;
|
1995-11-03 13:56:08 +00:00
|
|
|
case 4: o = "Cessione"; break;
|
|
|
|
case 5: o = "Paghero'"; break;
|
|
|
|
case 6: o = "Lettera di credito"; break;
|
|
|
|
case 7: o = "Tratta accettata"; break;
|
|
|
|
case 8: o = "Rapporti interban. diretti"; break;
|
|
|
|
case 9: o = "Bonifici"; break;
|
1996-01-12 11:28:43 +00:00
|
|
|
default: o = ""; if (ok != NULL) *ok = FALSE; break;
|
1995-11-03 13:56:08 +00:00
|
|
|
}
|
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
word TPagamento::recalc_rate(int row, bool is_perc_modified,
|
|
|
|
const char* new_value, const char* scad,
|
1995-11-03 08:04:05 +00:00
|
|
|
const char* typ, const char* ulc,
|
|
|
|
int rdiff, bool mcomm,
|
1995-11-03 07:47:20 +00:00
|
|
|
bool& need_recalc)
|
|
|
|
// ricalcola le rate sulla base di parametri modificati sulla riga row
|
|
|
|
// parametri: tutti i const char* possono essere NULL, il che vuol dire
|
|
|
|
// che i dati corrispondenti non sono stati modificati;
|
|
|
|
// se new_value non e' NULL puo' essere la percentuale (e
|
|
|
|
// allora is_perc_modified e' TRUE) o l'importo. Non e'
|
|
|
|
// possibile modificare entrambi; se succede viene data
|
|
|
|
// priorita' alla percentuale.
|
|
|
|
{
|
|
|
|
CHECK(!(!is_perc_modified && new_value != NULL && !_inited),
|
|
|
|
"A'stronzo! E famme 'na pippa! Me dai n'importo che nun ce sta? Ma Vaffanculo!");
|
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
if (_rate.items() == 0) return P_OK;
|
1995-11-03 07:47:20 +00:00
|
|
|
|
|
|
|
real rsum(0.0), newv(0.0), rmax(0.0);
|
1996-01-03 09:50:01 +00:00
|
|
|
const int last_rata = _rate.items() - 1;
|
|
|
|
int oldtype = tipo_rata(last_rata);
|
|
|
|
TString oldulc = ulc_rata(last_rata);
|
|
|
|
int oldscad = scad_rata(last_rata);
|
1995-11-03 07:47:20 +00:00
|
|
|
TDate lastdate = data_rata(0);
|
|
|
|
int first = _tpr < 4 ? 0 : 1;
|
|
|
|
TString_array srate(_rate); // rate come erano
|
|
|
|
|
1995-12-06 09:08:35 +00:00
|
|
|
if (oldscad <= 0) oldscad = _int_rate;
|
|
|
|
if (oldtype <= 0) oldtype = _def_tpr;
|
1995-11-03 07:47:20 +00:00
|
|
|
|
|
|
|
bool exhausted = FALSE;
|
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
for (int i = 0; i < srate.items(); i++)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
|
|
|
if (i == row)
|
|
|
|
{
|
|
|
|
if (typ != NULL)
|
|
|
|
{
|
|
|
|
for (int k = 0; k < srate.items(); k++)
|
|
|
|
{
|
|
|
|
// deve farlo per tutte dalla 1 in poi se rdiff == 2,
|
|
|
|
// soltanto per row diversamente
|
|
|
|
if ((rdiff == 2 && row > 0 && k > 0) || k == row)
|
|
|
|
{
|
1995-11-16 09:56:22 +00:00
|
|
|
TToken_string& tt = rata(k);
|
|
|
|
TToken_string& ss = (TToken_string&)srate[k];
|
|
|
|
tt.add(typ,2);
|
|
|
|
ss.add(typ,2);
|
|
|
|
tt.add(ulc,5);
|
|
|
|
ss.add(ulc,5);
|
|
|
|
need_recalc = TRUE;
|
|
|
|
// no error is possible
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
|
1995-11-16 09:56:22 +00:00
|
|
|
if (ulc != NULL)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
1995-11-22 10:56:09 +00:00
|
|
|
for (int k = 0; k < srate.items(); k++)
|
|
|
|
{
|
|
|
|
// deve farlo per tutte dalla 1 in poi se rdiff == 2,
|
|
|
|
// soltanto per row diversamente
|
|
|
|
if ((rdiff == 2 && row > 0 && k > 0) || k == row)
|
|
|
|
{
|
|
|
|
TToken_string& tt = rata(k);
|
|
|
|
TToken_string& ss = (TToken_string&)srate[k];
|
|
|
|
tt.add(ulc,5);
|
|
|
|
ss.add(ulc,5);
|
|
|
|
need_recalc = TRUE;
|
|
|
|
// no error is possible
|
|
|
|
}
|
|
|
|
}
|
1995-11-16 09:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (scad != NULL)
|
|
|
|
{
|
|
|
|
// if !_inited scad e' il n. giorni, se no e' la rata
|
|
|
|
if (_inited)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
1995-11-16 09:56:22 +00:00
|
|
|
TToken_string& tt = rata(row);
|
|
|
|
TToken_string& ss = (TToken_string&)srate[row];
|
|
|
|
lastdate = scad;
|
|
|
|
// controlla errore sulla data scadenza
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
oldscad = (int)(lastdate - data_rata(i-1));
|
|
|
|
if (oldscad <= 0l) return P_SCAD;
|
|
|
|
}
|
1996-01-09 18:50:34 +00:00
|
|
|
else if (lastdate < _datadoc) return P_INIZIO; // _inizio
|
1995-11-16 09:56:22 +00:00
|
|
|
tt.add(scad,3);
|
|
|
|
ss.add(scad,3);
|
|
|
|
// ricalcola rate successive: se si vuole modificarne solo una
|
|
|
|
// ci si fotte e si disabilita il ricalcolo
|
|
|
|
TDate ddd (lastdate);
|
|
|
|
for (int j = row+1; j < srate.items(); j++)
|
|
|
|
{
|
|
|
|
TToken_string& tt = rata(j);
|
|
|
|
TToken_string& ss = (TToken_string&)srate[j];
|
1996-01-08 09:55:34 +00:00
|
|
|
next_scad(ddd,scad_rata(j), mcomm,j);
|
1995-11-16 09:56:22 +00:00
|
|
|
tt.add(ddd.string(),3);
|
|
|
|
ss.add(ddd.string(),3);
|
|
|
|
need_recalc = TRUE;
|
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
1995-11-16 09:56:22 +00:00
|
|
|
else
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
1995-11-16 09:56:22 +00:00
|
|
|
// nulla di speciale visto che si memorizza la derivata
|
1996-01-09 18:50:34 +00:00
|
|
|
long sc = atol(scad);
|
1995-11-16 09:56:22 +00:00
|
|
|
for (int i = 0; i < row; i ++)
|
|
|
|
sc -= scad_rata(i);
|
1996-01-09 18:50:34 +00:00
|
|
|
if (sc < 0 || (row > 0 && sc == 0)) return P_SCAD;
|
|
|
|
if (sc > 10000L) return P_SCWIDE;
|
1996-01-10 10:30:58 +00:00
|
|
|
if (_mcomm && row > 0 && (sc % 30) != 0)
|
1995-11-16 09:56:22 +00:00
|
|
|
return P_MCOMM;
|
|
|
|
TToken_string& tt = rata(row);
|
|
|
|
TToken_string& ss = (TToken_string&)srate[row];
|
|
|
|
tt.add(sc,0);
|
|
|
|
ss.add(sc,0);
|
|
|
|
need_recalc = TRUE;
|
|
|
|
}
|
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
if (new_value != NULL)
|
|
|
|
{
|
|
|
|
need_recalc = TRUE;
|
|
|
|
// questa la subappaltiamo, per evitare l'inferno
|
|
|
|
return change_value(row, real(new_value), rdiff, is_perc_modified);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // i != row modified
|
|
|
|
{
|
|
|
|
if (rdiff == 2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (scad != NULL)
|
|
|
|
{
|
|
|
|
// check sulle scadenze solo se si sono modificate
|
|
|
|
lastdate = data_rata(i);
|
|
|
|
|
|
|
|
if (_inited && i > 0)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
1996-01-08 09:55:34 +00:00
|
|
|
if (data_rata(i) <= data_rata(i-1))
|
|
|
|
return P_SCAD;
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
1996-01-08 09:55:34 +00:00
|
|
|
else if (_inited && lastdate < _inizio)
|
|
|
|
return P_INIZIO;
|
1995-11-07 11:37:38 +00:00
|
|
|
}
|
1996-01-08 09:55:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
adjust_fixed_scad();
|
|
|
|
return P_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
word TPagamento::change_value(int rata, real user_val, int rdiff, bool is_perc)
|
|
|
|
{
|
|
|
|
word err = 0;
|
|
|
|
|
|
|
|
switch (rdiff)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
err = change_value_differenziate(rata, user_val, is_perc);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
err = change_value_uguali(rata, user_val, is_perc);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
err = change_value_uguali_prossima(rata, user_val, is_perc);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
err = change_value_uguali_possible(rata, user_val, is_perc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!err)
|
|
|
|
{
|
|
|
|
// riaggiusta gli altri parametri se si sono create rate nuove
|
|
|
|
adjust_parameters();
|
|
|
|
// risistema scadenze fisse se necessario
|
|
|
|
adjust_fixed_scad();
|
|
|
|
// riaggiusta le percentuali o gli importi rispetto al dato modificato
|
1996-01-09 11:13:41 +00:00
|
|
|
if (_inited) adjust_perc_imp(is_perc, rdiff);
|
|
|
|
_dirty = TRUE;
|
1996-01-08 09:55:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
// le quattro che seguono modificano le rate (solo importi o percentuali), e
|
|
|
|
// lasciano in last_old l'indice dell'ultima rata rimasta dalle vecchie che
|
|
|
|
// hanno adoperato
|
|
|
|
|
|
|
|
word TPagamento::change_value_differenziate(int row, real user_val, bool is_perc)
|
|
|
|
{
|
|
|
|
// importi totali, da non suddividere, da suddividere
|
|
|
|
real to_share = is_perc ? real(100.0) : (_tpr < 4 ? _firstr : _secndr);
|
|
|
|
real to_subtract = ZERO;
|
|
|
|
if (row == 0 && _tpr > 0 && _tpr < 4 && !is_perc)
|
|
|
|
to_subtract = _secndr;
|
|
|
|
real user_div = user_val - to_subtract;
|
1996-01-08 11:32:33 +00:00
|
|
|
const int first = _tpr > 3 ? 1 : 0;
|
1996-01-08 09:55:34 +00:00
|
|
|
_rdiff = TRUE;
|
|
|
|
|
1996-01-09 11:13:41 +00:00
|
|
|
if (user_div.sign() <= 0) return P_NEG;
|
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
// togli rate gia' presenti
|
|
|
|
for (int i = first; i < row; i++)
|
|
|
|
{
|
|
|
|
to_share -= (is_perc ? perc_rata(i): tpay_rata(i));
|
|
|
|
if (i == 0 && !is_perc && _tpr > 0 && _tpr < 4)
|
|
|
|
to_share += _secndr;
|
|
|
|
}
|
|
|
|
real remainder = to_share - user_div;
|
1996-01-09 11:13:41 +00:00
|
|
|
if (remainder.sign() < 0) return P_TROP;
|
1996-01-08 09:55:34 +00:00
|
|
|
|
1996-01-08 11:32:33 +00:00
|
|
|
const int tok_ind = is_perc ? 1 : 4;
|
|
|
|
rata(row).add(user_val.string(), tok_ind);
|
1996-01-08 09:55:34 +00:00
|
|
|
|
|
|
|
if (!remainder.is_zero())
|
|
|
|
{
|
|
|
|
if (n_rate() <= row + 1) add_rata();
|
|
|
|
rata(row+1).add(remainder.string(), tok_ind);
|
|
|
|
}
|
|
|
|
|
|
|
|
// elimina rate successive
|
1996-01-09 11:13:41 +00:00
|
|
|
remove_rate_from(remainder.is_zero() ? row +1 : row+2);
|
1996-01-08 09:55:34 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
word TPagamento::change_value_uguali(int row, real user_val, bool is_perc)
|
|
|
|
{
|
|
|
|
// importi totali, da non suddividere, da suddividere
|
|
|
|
real to_share = is_perc ? real(100.0) : (_tpr < 4 ? _firstr : _secndr);
|
|
|
|
real to_subtract = ZERO;
|
|
|
|
if (row == 0 && _tpr > 0 && _tpr < 4 && !is_perc)
|
|
|
|
to_subtract = _secndr;
|
|
|
|
real user_div = user_val - to_subtract;
|
|
|
|
real remainder = to_share - user_div;
|
1996-01-08 11:32:33 +00:00
|
|
|
const int tok_ind = is_perc ? 1 : 4;
|
|
|
|
const int first = _tpr > 3 ? 1 : 0;
|
1996-01-08 09:55:34 +00:00
|
|
|
_rdiff = FALSE;
|
|
|
|
|
1996-01-09 11:13:41 +00:00
|
|
|
if (user_div.sign() <= 0)
|
1996-01-08 09:55:34 +00:00
|
|
|
return P_NEG;
|
|
|
|
|
|
|
|
// la prima viene mantenuta uguale (vale solo per la 0 anche se _tpr > 4)
|
|
|
|
|
|
|
|
// se si modifica la prima, si suddivide l'importo rimanente tra tutte le
|
|
|
|
// altre e si aggiunge il residuo alla prima; il n. rate viene mantenuto
|
|
|
|
if (row == 0)
|
|
|
|
{
|
|
|
|
if (n_rate() == 1)
|
|
|
|
{
|
|
|
|
// se il numero rate e' 1 si aggiungono rate uguali a coprire l'importo
|
|
|
|
if ((to_share - user_div) < user_div) return 0;
|
|
|
|
real div = to_share / user_div;
|
|
|
|
real delta = to_share - (user_div * div.integer());
|
1996-01-11 09:29:49 +00:00
|
|
|
if (div > real(999.0)) return P_TOOMANY;
|
1996-01-08 09:55:34 +00:00
|
|
|
for (int i = 0; i < div.integer(); i++)
|
|
|
|
{
|
|
|
|
if (n_rate() <= i) add_rata();
|
|
|
|
rata(i).add(i == 0 ? user_val.string() : user_div.string(), tok_ind);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add residuo
|
|
|
|
if (!delta.is_zero())
|
|
|
|
{
|
|
|
|
real tp = is_perc ? perc_rata(first) : tpay_rata(first);
|
|
|
|
tp += delta;
|
|
|
|
rata(first).add(tp.string(), tok_ind);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // n. rate > 1, modificata la rata 0: _tpr e' per forza < 4
|
|
|
|
{
|
|
|
|
real div = remainder / real(n_rate() - 1);
|
1996-01-10 16:50:07 +00:00
|
|
|
div.round(is_perc ? 2 : _round);
|
1996-01-08 09:55:34 +00:00
|
|
|
real delta = remainder - (div * real(n_rate() - 1));
|
|
|
|
|
|
|
|
rata(0).add(user_val.string(), tok_ind);
|
|
|
|
if (remainder.is_zero())
|
|
|
|
{
|
|
|
|
remove_rate_from(1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ripartisci il resto
|
|
|
|
for (int i = 1; i < n_rate(); i++)
|
|
|
|
rata(i).add(div.string(), tok_ind);
|
|
|
|
|
|
|
|
if (!delta.is_zero())
|
|
|
|
{
|
|
|
|
user_val += delta;
|
1996-01-09 18:50:34 +00:00
|
|
|
rata(0).add(user_val.string(), tok_ind);
|
1996-01-08 09:55:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// dalla seconda in poi, tutte le rate devono essere uguali a quella indicata
|
|
|
|
// (a meno dell'importo non suddivisibile se c'e' (to_subtract); il numero rate
|
|
|
|
// puo' cambiare. Si rispetta il valore della rata 0
|
|
|
|
// se c'e' un residuo lo metto sulla prima calcolabile (dipende da _tpr)
|
|
|
|
else
|
|
|
|
{
|
|
|
|
real first_imp;
|
|
|
|
if (_tpr < 4)
|
|
|
|
{
|
|
|
|
first_imp = is_perc ? perc_rata(0) : tpay_rata(0);
|
1996-01-12 09:14:23 +00:00
|
|
|
if (_tpr > 0 && !is_perc) first_imp -= _secndr;
|
1996-01-08 09:55:34 +00:00
|
|
|
}
|
|
|
|
real div = (to_share - first_imp)/user_val;
|
|
|
|
if (div < real(1.0)) return P_TROP;
|
1996-01-11 09:29:49 +00:00
|
|
|
if (div > real(999.0)) return P_TOOMANY;
|
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
real delta = (to_share - first_imp) - user_val * real(div.integer());
|
|
|
|
for (int i = 1; i < div.integer()+1l; i++)
|
|
|
|
{
|
|
|
|
if (n_rate() <= i) add_rata();
|
|
|
|
rata(i).add(user_val.string(), tok_ind);
|
|
|
|
}
|
|
|
|
|
|
|
|
remove_rate_from(i);
|
|
|
|
|
|
|
|
if (!delta.is_zero())
|
|
|
|
{
|
|
|
|
real tp = is_perc ? perc_rata(first) : tpay_rata(first);
|
|
|
|
tp += delta;
|
|
|
|
rata(first).add(tp.string(), tok_ind);
|
1996-01-08 11:32:33 +00:00
|
|
|
}
|
1996-01-08 09:55:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-01-08 11:32:33 +00:00
|
|
|
word TPagamento::change_value_uguali_prossima(int row, real user_val, bool is_perc)
|
1996-01-08 09:55:34 +00:00
|
|
|
{
|
1996-01-08 11:32:33 +00:00
|
|
|
_rdiff = TRUE;
|
|
|
|
// uguali finche' possibile da row in poi; residuo su first
|
|
|
|
// importi totali, da non suddividere, da suddividere
|
|
|
|
real to_share = is_perc ? real(100.0) : (_tpr < 4 ? _firstr : _secndr);
|
|
|
|
real to_subtract = ZERO;
|
|
|
|
if (row == 0 && _tpr > 0 && _tpr < 4 && !is_perc)
|
|
|
|
to_subtract = _secndr;
|
|
|
|
real user_div = user_val - to_subtract;
|
|
|
|
const int tok_ind = is_perc ? 1 : 4;
|
|
|
|
const int first = _tpr > 3 ? 1 : 0;
|
1996-01-09 11:13:41 +00:00
|
|
|
|
|
|
|
if (user_div.sign() <= 0)
|
|
|
|
return P_NEG;
|
1996-01-08 11:32:33 +00:00
|
|
|
|
|
|
|
// togli rate gia' presenti
|
|
|
|
for (int i = first; i < row; i++)
|
|
|
|
{
|
|
|
|
to_share -= (is_perc ? perc_rata(i): tpay_rata(i));
|
|
|
|
if (i == 0 && !is_perc && _tpr > 0 && _tpr < 4)
|
|
|
|
to_share += _secndr;
|
|
|
|
}
|
|
|
|
|
|
|
|
real div = to_share/user_div;
|
|
|
|
if (div < real(1.0)) return P_TROP;
|
1996-01-11 09:29:49 +00:00
|
|
|
if (div > real(999.0)) return P_TOOMANY;
|
1996-01-08 11:32:33 +00:00
|
|
|
|
|
|
|
real delta = to_share - (user_div * div.integer());
|
|
|
|
for (i = row; i < (row + div.integer()); i++)
|
|
|
|
{
|
|
|
|
if (n_rate() <= i) add_rata();
|
|
|
|
rata(i).add(user_div.string(), tok_ind);
|
|
|
|
}
|
|
|
|
remove_rate_from(i);
|
|
|
|
if (!delta.is_zero())
|
|
|
|
{
|
|
|
|
real r = is_perc ? perc_rata(first) : tpay_rata(first);
|
|
|
|
r += delta;
|
|
|
|
rata(first).add(r.string(), tok_ind);
|
|
|
|
}
|
1996-01-08 09:55:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-01-08 11:32:33 +00:00
|
|
|
word TPagamento::change_value_uguali_possible(int row, real user_val, bool is_perc)
|
1996-01-08 09:55:34 +00:00
|
|
|
{
|
|
|
|
_rdiff = TRUE;
|
1996-01-08 11:32:33 +00:00
|
|
|
// uguali finche' possibile da row in poi; residuo come rata a parte
|
|
|
|
real to_share = is_perc ? real(100.0) : (_tpr < 4 ? _firstr : _secndr);
|
|
|
|
real to_subtract = ZERO;
|
|
|
|
if (row == 0 && _tpr > 0 && _tpr < 4 && !is_perc)
|
|
|
|
to_subtract = _secndr;
|
|
|
|
real user_div = user_val - to_subtract;
|
|
|
|
const int tok_ind = is_perc ? 1 : 4;
|
|
|
|
const int first = _tpr > 3 ? 1 : 0;
|
|
|
|
|
1996-01-09 11:13:41 +00:00
|
|
|
if (user_div.sign() <= 0)
|
|
|
|
return P_NEG;
|
|
|
|
|
1996-01-08 11:32:33 +00:00
|
|
|
// togli rate gia' presenti
|
|
|
|
for (int i = first; i < row; i++)
|
|
|
|
{
|
|
|
|
to_share -= (is_perc ? perc_rata(i): tpay_rata(i));
|
|
|
|
if (i == 0 && !is_perc && _tpr > 0 && _tpr < 4)
|
|
|
|
to_share += _secndr;
|
|
|
|
}
|
|
|
|
|
|
|
|
real div = to_share/user_div;
|
|
|
|
if (div < real(1.0)) return P_TROP;
|
1996-01-11 09:29:49 +00:00
|
|
|
if (div > real(999.0)) return P_TOOMANY;
|
1996-01-08 11:32:33 +00:00
|
|
|
|
|
|
|
real delta = to_share - (user_div * div.integer());
|
|
|
|
for (i = row; i < (row + div.integer()); i++)
|
|
|
|
{
|
|
|
|
if (n_rate() <= i) add_rata();
|
|
|
|
rata(i).add(user_div.string(), tok_ind);
|
|
|
|
}
|
|
|
|
if (!delta.is_zero())
|
|
|
|
{
|
|
|
|
if (n_rate() <= i) add_rata();
|
1996-01-09 11:13:41 +00:00
|
|
|
rata(i++).add(delta.string(), tok_ind);
|
1996-01-08 11:32:33 +00:00
|
|
|
}
|
|
|
|
remove_rate_from(i);
|
1996-01-08 09:55:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPagamento::adjust_parameters()
|
|
|
|
{
|
|
|
|
TDate last_date;
|
|
|
|
int last_type;
|
|
|
|
TString16 last_ulc;
|
|
|
|
int last_scad;
|
|
|
|
|
|
|
|
for (int i = 0; i < n_rate(); i++)
|
|
|
|
{
|
|
|
|
if (scad_rata(i) != -1)
|
|
|
|
{
|
|
|
|
last_date = data_rata(i);
|
|
|
|
last_type = tipo_rata(i);
|
|
|
|
last_ulc = ulc_rata(i);
|
|
|
|
last_scad = scad_rata(i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TToken_string& r = rata(i);
|
1996-01-09 11:13:41 +00:00
|
|
|
#ifdef USE_DEFAULT_INT_RATE
|
|
|
|
r.add(last_scad == 0 ? _int_rate : last_scad, 0);
|
|
|
|
#else
|
1996-01-08 09:55:34 +00:00
|
|
|
r.add(last_scad, 0);
|
1996-01-09 11:13:41 +00:00
|
|
|
#endif
|
1996-01-08 09:55:34 +00:00
|
|
|
r.add(last_type, 2);
|
|
|
|
r.add(last_ulc, 5);
|
|
|
|
if (_inited)
|
|
|
|
{
|
|
|
|
#ifdef USE_DEFAULT_INT_RATE
|
|
|
|
next_scad(last_date, last_scad == 0 ? _int_rate : last_scad, _mcomm, i);
|
|
|
|
#else
|
|
|
|
next_scad(last_date, last_scad, _mcomm, i);
|
|
|
|
#endif
|
|
|
|
r.add(last_date, 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPagamento::adjust_perc_imp(bool is_perc, int rdiff)
|
|
|
|
{
|
|
|
|
real toshare(100.0); real other(100.0);
|
|
|
|
if (is_perc)
|
|
|
|
toshare = (_tpr < 4 ? _firstr : _secndr);
|
|
|
|
else
|
|
|
|
other = (_tpr < 4 ? _firstr : _secndr);
|
|
|
|
|
1996-01-10 16:50:07 +00:00
|
|
|
TDistrib dt(toshare, is_perc ? _round : 2);
|
1996-01-08 09:55:34 +00:00
|
|
|
const int first = _tpr > 3 ? 1 : 0;
|
|
|
|
|
1996-01-12 09:14:23 +00:00
|
|
|
// for (int j = first; j < _rate.items(); j++)
|
|
|
|
for (int j = _rate.items() - 1 ; j >= first; j--)
|
1996-01-08 09:55:34 +00:00
|
|
|
{
|
|
|
|
real rvl = is_perc ? perc_rata(j) : tpay_rata(j);
|
|
|
|
// togli pezxo di troppo
|
|
|
|
if (!is_perc && j == first && _tpr > 0 && _tpr < 4)
|
|
|
|
rvl -= _secndr;
|
|
|
|
real zpx = rvl/other; // percentuale
|
|
|
|
dt.add(zpx); // * cento???
|
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
|
1996-01-12 09:14:23 +00:00
|
|
|
// for (j = first; j < n_rate(); j++)
|
|
|
|
for (j = n_rate() - 1 ; j >= first; j--)
|
1996-01-08 09:55:34 +00:00
|
|
|
{
|
|
|
|
real rfirst(0.0);
|
|
|
|
TToken_string& tr = rata(j);
|
1995-11-03 07:47:20 +00:00
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
real rvl = dt.get();
|
1995-11-03 07:47:20 +00:00
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
if (j == first)
|
|
|
|
{
|
|
|
|
rfirst = rvl;
|
|
|
|
if (rdiff == 2)
|
|
|
|
{
|
|
|
|
real reminder = toshare - rfirst;
|
|
|
|
real rdiv = reminder.is_zero() ? real(0.0) :
|
|
|
|
(reminder / real(_rate.items() - (1+first)));
|
|
|
|
rdiv.round( is_perc ? _round : 2);
|
|
|
|
rfirst += reminder - (rdiv * real(_rate.items() - (1+first)));
|
|
|
|
rvl = rdiv;
|
|
|
|
}
|
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
if (is_perc && j == first && _tpr > 0 && _tpr < 4)
|
|
|
|
rfirst += _secndr;
|
1995-12-19 12:02:36 +00:00
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
tr.add((j == first ? rfirst.string() : rvl.string()), is_perc ? 4 : 1);
|
1995-11-03 07:47:20 +00:00
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
if (_cambio != 1.0)
|
|
|
|
{
|
|
|
|
real implit(tpay_rata(j));
|
|
|
|
implit *= _cambio;
|
|
|
|
implit.round();
|
|
|
|
tr.add(implit.string(), 7);
|
|
|
|
}
|
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TPagamento::read(TTable* t, TTable* r)
|
|
|
|
{
|
|
|
|
// puo' chiamarla chiunque
|
|
|
|
bool istnew = FALSE;
|
|
|
|
if (t == NULL)
|
|
|
|
{
|
|
|
|
t = new TTable("%CPG");
|
|
|
|
istnew = TRUE;
|
|
|
|
}
|
|
|
|
t->zero(); t->put("CODTAB", _code);
|
|
|
|
if (t->read() != NOERR) return FALSE;
|
|
|
|
|
|
|
|
_slicer.init(real(0.0), TRUE);
|
|
|
|
_rate.destroy();
|
|
|
|
|
|
|
|
// set everything
|
1996-01-08 09:55:34 +00:00
|
|
|
_rdiff = t->get_bool("B1");
|
|
|
|
_mcomm = t->get_bool("B0");
|
|
|
|
_tpr = t->get_int("S3");
|
|
|
|
_inscad = t->get_char("S1");
|
|
|
|
_code = t->get("CODTAB");
|
|
|
|
_name = t->get("S0");
|
|
|
|
_fixd[0] = t->get_int("I0");
|
|
|
|
_fixd[1] = t->get_int("I1");
|
|
|
|
_fixd[2] = t->get_int("I2");
|
|
|
|
_int_rate = t->get_int("I3");
|
1996-01-09 11:13:41 +00:00
|
|
|
|
|
|
|
#ifdef USE_DEFAULT_INT_RATE
|
1996-01-12 11:28:43 +00:00
|
|
|
// if (_int_rate == 0) _int_rate = 30;
|
1996-01-09 11:13:41 +00:00
|
|
|
#endif
|
|
|
|
|
1995-11-07 11:37:38 +00:00
|
|
|
// aggiusta _inizio secondo INSCAD; vedi mese commerciale etc.
|
1995-11-03 07:47:20 +00:00
|
|
|
if (_inscad == 'M')
|
|
|
|
{
|
1995-11-03 11:39:25 +00:00
|
|
|
if (_mcomm) _inizio.set_day(_inizio.month() == 2 ? 28 : 30);
|
1995-11-03 07:47:20 +00:00
|
|
|
else _inizio.set_end_month();
|
|
|
|
}
|
1995-11-03 11:39:25 +00:00
|
|
|
else if (_inscad == 'F' && _mcomm && _inizio.day() == 31)
|
|
|
|
_inizio.set_day(30);
|
1995-11-03 07:47:20 +00:00
|
|
|
|
|
|
|
// leggi rate e scadenze
|
|
|
|
bool isrnew = FALSE;
|
|
|
|
if (r == NULL)
|
|
|
|
{
|
|
|
|
r = new TTable("%RPG");
|
|
|
|
isrnew = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TString16 s;
|
|
|
|
for (int i = 0; ;i++)
|
|
|
|
{
|
|
|
|
r->zero(); s.format("%s%3d",(const char*)_code, i);
|
|
|
|
r->put("CODTAB", (const char*)s);
|
|
|
|
if (r->read() != NOERR)
|
|
|
|
break;
|
1995-12-13 15:12:13 +00:00
|
|
|
TToken_string* tt = new TToken_string(48);
|
1995-11-03 07:47:20 +00:00
|
|
|
tt->add((const char*)(r->get("I0"))); // scadenza
|
|
|
|
tt->add((const char*)(r->get("R0"))); // percentuale
|
|
|
|
tt->add((const char*)(r->get("I1"))); // tipo
|
|
|
|
// data e importo
|
|
|
|
TDate d = _inizio;
|
|
|
|
next_scad(d,(int)(r->get_long("I0")),_mcomm,i);
|
|
|
|
tt->add((const char*)d);
|
|
|
|
tt->add("");
|
|
|
|
tt->add(r->get("S1")); // ulteriore classificazione
|
|
|
|
_slicer.add((real)r->get("R0"));
|
|
|
|
_rate.add(tt);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (istnew) delete t;
|
|
|
|
if (isrnew) delete r;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TPagamento::write(TTable& r)
|
|
|
|
{
|
|
|
|
// Scrive soltanto le righe di pagamento; si assume sia stata chiamata da una
|
|
|
|
// relapp, che ha scritto il file principale
|
|
|
|
|
|
|
|
TString16 s;
|
|
|
|
int err = NOERR;
|
|
|
|
|
|
|
|
for (int i = 0; err == NOERR && i < n_rate(); i++)
|
|
|
|
{
|
|
|
|
r.zero(); s.format("%s%3d",(const char*)_code, i);
|
|
|
|
r.put("CODTAB", s);
|
|
|
|
r.put("I0", (long)scad_rata(i));
|
|
|
|
r.put("R0", perc_rata(i).string());
|
|
|
|
r.put("I1", (long)tipo_rata(i));
|
|
|
|
r.put("S1", ulc_rata(i));
|
|
|
|
err = r.write();
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TPagamento::rewrite(TTable& r)
|
|
|
|
{
|
|
|
|
TString16 s; int err = NOERR;
|
|
|
|
|
|
|
|
for (int i = 0; err == NOERR && i < n_rate(); i++)
|
|
|
|
{
|
|
|
|
r.zero(); s.format("%s%3d",(const char*)_code, i);
|
|
|
|
r.put("CODTAB", s);
|
|
|
|
bool was = (r.read() == NOERR);
|
|
|
|
r.zero(); s.format("%s%3d",(const char*)_code, i);
|
|
|
|
r.put("CODTAB", (const char*)s);
|
|
|
|
r.put("I0", (long)scad_rata(i));
|
|
|
|
r.put("R0", perc_rata(i).string());
|
|
|
|
r.put("I1", (long)tipo_rata(i));
|
|
|
|
r.put("S1", ulc_rata(i));
|
|
|
|
err = (was ? r.rewrite() : r.write());
|
|
|
|
}
|
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
// erase possible rate > current n. rate
|
1995-11-03 07:47:20 +00:00
|
|
|
for (;err == NOERR;i++)
|
|
|
|
{
|
|
|
|
r.zero(); s.format("%s%3d",(const char*)_code, i);
|
|
|
|
r.put("CODTAB", (const char*)s);
|
|
|
|
if (r.read() == NOERR) err = r.remove();
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TPagamento::remove(TTable& r)
|
|
|
|
{
|
1995-12-13 15:12:13 +00:00
|
|
|
TString16 s; int err = NOERR;
|
1995-11-03 07:47:20 +00:00
|
|
|
for (int i = 0 ; err == NOERR; i++)
|
|
|
|
{
|
1995-12-29 11:06:12 +00:00
|
|
|
r.zero(); s.format("%s%3d", (const char*)_code, i);
|
1995-12-13 15:12:13 +00:00
|
|
|
r.put("CODTAB", s);
|
|
|
|
if (r.read() == NOERR)
|
|
|
|
err = r.remove();
|
1995-11-03 07:47:20 +00:00
|
|
|
else break;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPagamento::set_rate_auto()
|
1995-11-07 10:03:02 +00:00
|
|
|
{
|
1995-11-03 07:47:20 +00:00
|
|
|
// vedi rate esistenti e tipo prima rata
|
|
|
|
// deve fare riferimento ad un tipo pagamento esistente
|
|
|
|
// e sensato
|
|
|
|
int first = 0;
|
|
|
|
|
|
|
|
real toslice = _firstr;
|
|
|
|
|
1995-11-14 15:58:25 +00:00
|
|
|
if (n_rate() == 0 || !_inited || (_tpr > 3 && n_rate() == 1))
|
|
|
|
return;
|
|
|
|
|
|
|
|
main_app().begin_wait();
|
1995-11-03 07:47:20 +00:00
|
|
|
|
|
|
|
if (_tpr > 3) // ripartisci _firstr su tutte le rate
|
|
|
|
{
|
|
|
|
first = 1;
|
|
|
|
toslice = _secndr;
|
|
|
|
}
|
|
|
|
|
|
|
|
_slicer.init(toslice);
|
|
|
|
|
|
|
|
if (_tpr > 3)
|
|
|
|
// prima rata obbligatoria
|
|
|
|
set_imprata(0, _firstr);
|
|
|
|
|
|
|
|
// se rate uguali dividi l'importo totale per il numero di rate
|
|
|
|
real r1(0.0), ro(0.0);
|
|
|
|
if (!_rdiff)
|
|
|
|
{
|
|
|
|
int rut = _tpr > 3 ? n_rate() - 1 : n_rate();
|
|
|
|
|
|
|
|
// usa la percentuale per la prima rata
|
|
|
|
r1 = (toslice * perc_rata(first))/real(100.0);
|
|
|
|
r1.round(_round);
|
|
|
|
real reminder = toslice - r1;
|
|
|
|
if (!reminder.is_zero())
|
|
|
|
{
|
|
|
|
ro = reminder/real(rut-1); ro.trunc(_round);
|
|
|
|
r1 = (toslice - (ro*real(rut-1)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = first; i < n_rate(); i++)
|
|
|
|
// setta le fette e le date di scadenza
|
|
|
|
set_imprata(i, _rdiff ? _slicer.get() : (i == first ? r1 : ro));
|
|
|
|
|
|
|
|
// se e' nei primi tre casi, si somma l'importo da non dividere alla
|
|
|
|
// prima rata
|
|
|
|
if (_tpr > 0 && _tpr < 4)
|
|
|
|
set_imprata(0, tpay_rata(0) + _secndr);
|
1995-11-16 09:56:22 +00:00
|
|
|
|
|
|
|
// risistema rate per scadenze fisse
|
|
|
|
adjust_fixed_scad();
|
1995-11-07 10:03:02 +00:00
|
|
|
|
|
|
|
main_app().end_wait();
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TPagamento::set_total(const real& imponibile, const real& imposta, const real& spese)
|
|
|
|
{
|
|
|
|
_imponibile = imponibile;
|
|
|
|
_imposta = imposta;
|
|
|
|
_spese = spese;
|
|
|
|
_inited = TRUE;
|
|
|
|
|
|
|
|
// istanzia _firstr e _secndr a seconda di _tpr
|
|
|
|
switch(_tpr)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
_firstr = _imponibile + _imposta + _spese;
|
|
|
|
_secndr = 0.0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
_secndr = _imposta;
|
|
|
|
_firstr = _imponibile + _spese;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
_secndr = _spese;
|
|
|
|
_firstr = _imposta + _imponibile;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
_secndr = _imposta + _spese;
|
|
|
|
_firstr = _imponibile;
|
|
|
|
break;
|
|
|
|
case 4:
|
1995-11-16 09:56:22 +00:00
|
|
|
_secndr = _spese + _imponibile;
|
|
|
|
_firstr = _imposta;
|
1995-11-03 07:47:20 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
1995-11-16 09:56:22 +00:00
|
|
|
_secndr = _imponibile + _imposta;
|
|
|
|
_firstr = _spese;
|
1995-11-03 07:47:20 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
1995-11-16 09:56:22 +00:00
|
|
|
_secndr = _imponibile;
|
|
|
|
_firstr = _imposta + _spese;
|
1995-11-03 07:47:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const real toslice = _tpr > 1 ? _secndr : _firstr;
|
|
|
|
_slicer.init(toslice, TRUE);
|
|
|
|
const int first = _tpr > 3 ? 1 : 0;
|
|
|
|
|
|
|
|
for (int i = first; i < _rate.items(); i++)
|
|
|
|
{
|
|
|
|
TToken_string& t = (TToken_string&)_rate[i];
|
|
|
|
const real rr(t.get(1));
|
|
|
|
_slicer.add(rr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TPagamento::set_sheet(TSheet_field& sf, int sscad)
|
1995-11-07 10:03:02 +00:00
|
|
|
{
|
|
|
|
main_app().begin_wait();
|
|
|
|
|
1995-12-20 16:16:14 +00:00
|
|
|
if (_rate.items() == 0)
|
|
|
|
{
|
|
|
|
if (_tpr > 3)
|
|
|
|
add_rata(ZERO, sscad <= 0 ? 0 : sscad, _def_tpr, _def_ulc);
|
|
|
|
add_rata(real(100.0), sscad <= 0 ? (_tpr < 4 ? 0 : 30) : sscad, _def_tpr, _def_ulc);
|
|
|
|
_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_inited)
|
|
|
|
{
|
1996-01-05 15:17:50 +00:00
|
|
|
const bool in_valuta = _cambio != 1.0;
|
1995-12-20 16:16:14 +00:00
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
// si istanzia uno sheet di primanota
|
|
|
|
for (int i = 0; i < n_rate(); i++)
|
|
|
|
{
|
|
|
|
TToken_string& ts = sf.row(i);
|
1995-12-20 16:16:14 +00:00
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
ts.add((const char*)data_rata(i), 0); // 0 - Data scadenza
|
|
|
|
if (in_valuta)
|
|
|
|
{
|
|
|
|
ts.add(tlit_rata(i).string(), 1); // 1 - Importo in lire
|
|
|
|
ts.add(tpay_rata(i).string(), 2); // 2 - Importo in valuta
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ts.add(tpay_rata(i).string(), 1); // 1 - Importo
|
|
|
|
ts.add("", 2);
|
|
|
|
}
|
|
|
|
ts.add(perc_rata(i).string(), 3); // 3 - Percentuale
|
1995-12-20 16:16:14 +00:00
|
|
|
|
1995-11-03 13:56:08 +00:00
|
|
|
const int tr = tipo_rata(i);
|
|
|
|
const char uc = ulc_rata(i)[0];
|
|
|
|
ts.add(tr, 4); // 4 - Tipo rata
|
|
|
|
ts.add(uc, 5); // 5 - Ulteriore classificazione
|
|
|
|
ts.add(desc_tipo(tr, uc), 6); // 6 - Descrizione tipo rata
|
1995-11-03 08:04:05 +00:00
|
|
|
// 7,8,9,10 - Banche
|
1995-11-03 07:47:20 +00:00
|
|
|
const bool paid = ratapagata(i);
|
1995-11-03 08:04:05 +00:00
|
|
|
ts.add(paid ? "X" : "", 11); // 11 - Pagaya
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
1995-12-20 16:16:14 +00:00
|
|
|
|
1995-11-08 15:43:11 +00:00
|
|
|
for (int d = sf.items()-1; d >= i; d--)
|
1996-01-11 11:38:53 +00:00
|
|
|
sf.destroy(d, FALSE);
|
1995-12-20 16:16:14 +00:00
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
sf.enable_column(2, in_valuta);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1996-01-09 18:50:34 +00:00
|
|
|
long scr = 0L;
|
|
|
|
for (int i = 0; i < n_rate(); i++)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
1996-01-09 18:50:34 +00:00
|
|
|
TToken_string& s = sf.row(i);
|
|
|
|
scr += scad_rata(i);
|
|
|
|
s = "";
|
1995-11-03 07:47:20 +00:00
|
|
|
s.add(scr);
|
|
|
|
s.add(perc_rata(i).string());
|
1995-12-20 16:16:14 +00:00
|
|
|
|
1995-11-03 13:56:08 +00:00
|
|
|
const int tr = tipo_rata(i);
|
|
|
|
const char uc = ulc_rata(i)[0];
|
|
|
|
s.add(tr);
|
|
|
|
s.add(uc);
|
|
|
|
s.add(desc_tipo(tr, uc));
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
1996-01-09 18:50:34 +00:00
|
|
|
|
|
|
|
for (int d = sf.items()-1; d >= i; d--)
|
1996-01-11 11:38:53 +00:00
|
|
|
sf.destroy(d, FALSE);
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const bool abilita = _tpr <= 3;
|
|
|
|
// disabilita campi da non toccare sulla prima rata
|
|
|
|
if (_inited)
|
|
|
|
{
|
|
|
|
sf.enable_cell(0, 1, abilita); // importo
|
|
|
|
sf.enable_cell(0, 2, abilita); // in valuta
|
|
|
|
sf.enable_cell(0, 3, abilita); // percentuale
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sf.enable_cell(0, 1, abilita); // percentuale
|
|
|
|
}
|
|
|
|
|
|
|
|
sf.force_update();
|
1995-11-07 10:03:02 +00:00
|
|
|
main_app().end_wait();
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
1995-11-16 09:56:22 +00:00
|
|
|
|
|
|
|
void TPagamento::adjust_fixed_scad()
|
|
|
|
{
|
|
|
|
if (!_inited) return;
|
|
|
|
|
|
|
|
for (int i = 0; i < n_rate(); i++)
|
|
|
|
{
|
|
|
|
TDate d = data_rata(i);
|
|
|
|
|
|
|
|
// riaggiusta se ci sono scadenze fissate
|
|
|
|
if (_fixd[0] != 0 || _fixd[1] != 0 || _fixd[2] != 0)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
1995-12-19 15:53:50 +00:00
|
|
|
if (_fixd[i] >= d.day())
|
1995-11-16 09:56:22 +00:00
|
|
|
{
|
|
|
|
if (d.last_day(d.month(), d.year()) >= _fixd[i])
|
|
|
|
d.set_day(_fixd[i]);
|
1995-12-19 15:53:50 +00:00
|
|
|
else
|
|
|
|
d.set_end_month();
|
1995-11-16 09:56:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 3)
|
|
|
|
{
|
|
|
|
if (_fixd[0] > 0 && _fixd[0] < d.day())
|
|
|
|
{
|
1995-12-06 10:14:29 +00:00
|
|
|
d.set_day(_fixd[0]);
|
1995-12-19 15:53:50 +00:00
|
|
|
const bool chyear = d.month() == 12;
|
|
|
|
d.set_month(chyear ? 1 : d.month() + 1);
|
1995-12-06 10:14:29 +00:00
|
|
|
if (chyear) d.set_year(d.year() + 1);
|
1995-11-16 09:56:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TToken_string& tt = rata(i);
|
|
|
|
tt.add(d.string(), 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
TPagamento::TPagamento(const char* codtab, const char* data) :
|
1995-12-01 11:46:35 +00:00
|
|
|
_slicer(0.0,0), _new(FALSE), _mcomm(FALSE), _imponibile(0.0), _imposta(0.0),
|
1995-11-03 07:47:20 +00:00
|
|
|
_spese(0.0), _cambio(1.0), _code(codtab), _dirty(FALSE), _inited(FALSE),
|
1995-12-20 16:16:14 +00:00
|
|
|
_def_tpr(1), _def_ulc(""), _round(0), _int_rate(30), _tpr(0), _rdiff(FALSE)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
|
|
|
_fixd[0] = _fixd[1] = _fixd[2] = 0;
|
|
|
|
if (data != NULL && *data)
|
|
|
|
_inizio = data;
|
|
|
|
else
|
|
|
|
_inizio = TDate(TODAY);
|
1996-01-09 18:50:34 +00:00
|
|
|
_datadoc = _inizio;
|
1995-11-03 07:47:20 +00:00
|
|
|
|
|
|
|
if (_code.blank() || !read())
|
|
|
|
_new = TRUE;
|
1995-12-29 11:06:12 +00:00
|
|
|
}
|