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"
|
|
|
|
|
1996-02-07 11:51:14 +00:00
|
|
|
#include "cg2100.h"
|
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
#include <mov.h>
|
|
|
|
#include <partite.h>
|
|
|
|
#include <scadenze.h>
|
|
|
|
#include <pagsca.h>
|
|
|
|
|
1996-02-07 11:51:14 +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;
|
|
|
|
}
|
|
|
|
|
1996-02-15 14:15:31 +00:00
|
|
|
void TPagamento::set_inizio(const TDate& d, bool rispetta_date)
|
1996-01-09 18:50:34 +00:00
|
|
|
{
|
|
|
|
_datadoc = d;
|
1995-11-14 10:27:10 +00:00
|
|
|
_inizio = d;
|
1996-01-24 11:43:55 +00:00
|
|
|
_inited = TRUE;
|
1995-11-14 10:27:10 +00:00
|
|
|
// aggiusta _inizio secondo INSCAD; vedi mese commerciale etc.
|
|
|
|
if (_inscad == 'M')
|
1996-02-22 10:40:15 +00:00
|
|
|
_inizio.set_end_month();
|
1995-12-01 11:46:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_inscad == 'F' && _mcomm && _inizio.day() == 31)
|
|
|
|
_inizio.set_day(30);
|
|
|
|
}
|
1996-02-23 11:37:28 +00:00
|
|
|
|
1996-02-15 14:15:31 +00:00
|
|
|
TDate data(rispetta_date ? data_rata(0) : _inizio); // Aggiusta data iniziale con i gironi prima rata
|
1996-02-23 11:37:28 +00:00
|
|
|
if (!rispetta_date)
|
|
|
|
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;
|
1996-02-02 11:09:18 +00:00
|
|
|
recalc_rate(0, FALSE, NULL, 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
|
|
|
|
1996-01-30 11:46:19 +00:00
|
|
|
if (!_inited)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
1996-01-30 11:46:19 +00:00
|
|
|
if (v < 4 && _tpr > 3)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
1996-01-30 11:46:19 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
_rate.destroy(0, TRUE);
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
1996-01-30 11:46:19 +00:00
|
|
|
else if ( _tpr < 4 && v > 3)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
|
|
|
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);
|
1996-01-30 11:46:19 +00:00
|
|
|
ttn->add("", 5);
|
1995-11-03 07:47:20 +00:00
|
|
|
_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
|
|
|
}
|
1996-01-30 11:46:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((_tpr > 3 && (v > 0 && v < 3)) || (v > 3 && (_tpr > 0 && _tpr < 3)))
|
|
|
|
{
|
|
|
|
// swap _firstr and _secndr
|
|
|
|
real tmp(_firstr);
|
|
|
|
_firstr = _secndr;
|
|
|
|
_secndr = tmp;
|
1996-02-02 11:09:18 +00:00
|
|
|
tmp = _firstl;
|
|
|
|
_firstl = _secndl;
|
|
|
|
_secndl = tmp;
|
1996-01-30 11:46:19 +00:00
|
|
|
}
|
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
_tpr = v;
|
|
|
|
_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
void TPagamento::set_numero_rate(int n, int sscad, int rdiff)
|
|
|
|
{
|
1996-02-08 15:46:39 +00:00
|
|
|
if (n <= 0) return;
|
1995-11-03 07:47:20 +00:00
|
|
|
_dirty = FALSE;
|
|
|
|
|
|
|
|
const int nr = n_rate();
|
|
|
|
const int first = _tpr < 4 ? 0 : 1;
|
|
|
|
real sum = 0.0;
|
|
|
|
int i = 0;
|
1996-02-02 11:09:18 +00:00
|
|
|
bool inv = in_valuta();
|
1995-11-03 07:47:20 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
real tot = _inited ? importo_da_dividere(FALSE) : real(100.0);
|
|
|
|
real oot;
|
|
|
|
if (inv)
|
|
|
|
oot = importo_da_dividere(TRUE);
|
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
if (nact == 1)
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
if (_inited)
|
|
|
|
{
|
|
|
|
set_imprata(first, tot, FALSE);
|
|
|
|
if (inv) set_imprata(first, oot, TRUE);
|
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
set_percrata(first, real(100.0));
|
1996-02-02 11:09:18 +00:00
|
|
|
if (_inited && _tpr > 0 && _tpr < 4)
|
|
|
|
{
|
|
|
|
set_imprata(first, importo_rata(first,FALSE) + importo_da_non_dividere(FALSE), FALSE);
|
|
|
|
if (inv)
|
|
|
|
set_imprata(first, importo_rata(first,TRUE) + importo_da_non_dividere(TRUE), TRUE);
|
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
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);
|
1996-02-02 11:09:18 +00:00
|
|
|
real oiv;
|
|
|
|
if (inv)
|
|
|
|
oiv = oot/real(nact);
|
1995-12-22 15:33:27 +00:00
|
|
|
if (_inited)
|
1996-02-02 11:09:18 +00:00
|
|
|
{
|
|
|
|
div.round(_roundlit);
|
|
|
|
if (inv) oiv.round(_roundval);
|
|
|
|
}
|
1995-12-22 15:33:27 +00:00
|
|
|
real perc = (100.0 * div) / tot;
|
1996-02-02 11:09:18 +00:00
|
|
|
|
1995-12-22 15:33:27 +00:00
|
|
|
real rem(tot);
|
1996-02-02 11:09:18 +00:00
|
|
|
real oem(oot);
|
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);
|
1996-02-02 11:09:18 +00:00
|
|
|
|
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)
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
set_imprata (i, div, FALSE);
|
|
|
|
rem -= importo_rata(i,FALSE);
|
|
|
|
if (inv)
|
|
|
|
{
|
|
|
|
set_imprata (i, oiv, TRUE);
|
|
|
|
oem -= importo_rata(i,TRUE);
|
|
|
|
}
|
1996-01-03 09:50:01 +00:00
|
|
|
}
|
1996-02-02 11:09:18 +00:00
|
|
|
else
|
1996-01-03 09:50:01 +00:00
|
|
|
rem -= p;
|
1995-11-03 07:47:20 +00:00
|
|
|
set_percrata(i, perc);
|
|
|
|
}
|
1996-02-02 11:09:18 +00:00
|
|
|
if (_inited && _tpr > 0 && _tpr < 4)
|
|
|
|
{
|
|
|
|
set_imprata(0, importo_rata(0,FALSE) + importo_da_non_dividere(FALSE), FALSE);
|
|
|
|
if (inv)
|
|
|
|
set_imprata(0, importo_rata(0,TRUE) + importo_da_non_dividere(TRUE), TRUE);
|
|
|
|
}
|
|
|
|
if (rem != ZERO || oem != ZERO)
|
1995-12-22 15:33:27 +00:00
|
|
|
{
|
1996-01-03 09:50:01 +00:00
|
|
|
if (_inited)
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
real r(importo_rata(first,FALSE) + rem);
|
|
|
|
real or;
|
|
|
|
if (inv) or = importo_rata(first,TRUE) + oem;
|
|
|
|
set_imprata(first, r, FALSE);
|
|
|
|
if (inv) set_imprata(first, or, TRUE);
|
|
|
|
|
1996-01-03 09:50:01 +00:00
|
|
|
if (_inited && _tpr > 0 && _tpr < 4)
|
1996-02-02 11:09:18 +00:00
|
|
|
{
|
|
|
|
r -= importo_da_non_dividere(FALSE);
|
|
|
|
if (inv) or -= importo_da_non_dividere(TRUE);
|
|
|
|
}
|
1996-01-03 09:50:01 +00:00
|
|
|
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
|
1996-02-02 11:09:18 +00:00
|
|
|
real rfirst = _inited ? importo_rata(0,FALSE) : perc_rata(0);
|
|
|
|
real ofirst;
|
|
|
|
if (inv)
|
|
|
|
ofirst = importo_rata(0,TRUE);
|
|
|
|
if (_inited && _tpr > 0 && _tpr < 4)
|
|
|
|
{
|
|
|
|
rfirst -= importo_da_non_dividere(FALSE);
|
|
|
|
if (inv)
|
|
|
|
ofirst -= importo_da_non_dividere(TRUE);
|
|
|
|
}
|
1995-12-22 15:33:27 +00:00
|
|
|
real rest = tot - (_tpr >= 4 ? ZERO : rfirst);
|
1996-02-02 11:09:18 +00:00
|
|
|
real oest;
|
|
|
|
if (inv)
|
|
|
|
oest = oot - (_tpr >= 4 ? ZERO : ofirst);
|
1995-12-22 15:33:27 +00:00
|
|
|
real div = rest / real(nact - (first > 0 ? 0 : 1));
|
1996-02-02 11:09:18 +00:00
|
|
|
real oiv;
|
|
|
|
if (inv)
|
|
|
|
oiv = oest / real(nact - (first > 0 ? 0 : 1));
|
1995-12-22 15:33:27 +00:00
|
|
|
if (_inited)
|
1996-02-02 11:09:18 +00:00
|
|
|
{
|
|
|
|
div.round(_roundlit);
|
|
|
|
if (inv)
|
|
|
|
oiv.round(_roundval);
|
|
|
|
}
|
1995-12-22 15:33:27 +00:00
|
|
|
real perc = (100.0 * div)/tot;
|
|
|
|
real rem(rest);
|
1996-02-02 11:09:18 +00:00
|
|
|
real oem(oest);
|
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)
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
set_imprata (i, div, FALSE);
|
1996-02-07 10:31:25 +00:00
|
|
|
rem -= div;
|
1996-02-02 11:09:18 +00:00
|
|
|
if (inv)
|
|
|
|
{
|
|
|
|
set_imprata (i, oiv, TRUE);
|
1996-02-07 10:31:25 +00:00
|
|
|
oem -= oiv;
|
1996-02-02 11:09:18 +00:00
|
|
|
}
|
1995-12-22 15:33:27 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
real r(importo_rata(first,FALSE) + rem);
|
|
|
|
real or;
|
|
|
|
if (inv) or = importo_rata(first,TRUE) + oem;
|
|
|
|
set_imprata(first, r, FALSE);
|
|
|
|
if (inv) set_imprata(first, or, TRUE);
|
1996-01-03 09:50:01 +00:00
|
|
|
if (_inited && _tpr > 0 && _tpr < 4)
|
1996-02-02 11:09:18 +00:00
|
|
|
r -= importo_da_non_dividere(FALSE);
|
1996-01-03 09:50:01 +00:00
|
|
|
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
|
1996-02-02 11:09:18 +00:00
|
|
|
set_rata(i, real(p), scd, (i < nr ? tipo_rata(i) : tipo_rata(nr-1)), FALSE);
|
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
// erase remaining
|
1996-01-09 11:13:41 +00:00
|
|
|
remove_rate_from(i);
|
1996-01-29 10:18:18 +00:00
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
if (_inited)
|
1996-02-07 10:31:25 +00:00
|
|
|
{
|
1996-02-15 14:15:31 +00:00
|
|
|
set_inizio(_datadoc, TRUE);
|
1996-02-07 10:31:25 +00:00
|
|
|
adjust_perc(rdiff, inv);
|
|
|
|
}
|
|
|
|
|
1995-12-22 15:33:27 +00:00
|
|
|
adjust_fixed_scad();
|
1995-11-03 07:47:20 +00:00
|
|
|
_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
1996-02-07 11:51:14 +00:00
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
void TPagamento::next_scad(TDate& d, int scad, bool mcomm, int rata)
|
1996-01-25 08:47:50 +00:00
|
|
|
{
|
1996-02-23 11:37:28 +00:00
|
|
|
if (mcomm && (rata > 0 || (scad % 30) == 0))
|
1996-02-05 10:40:51 +00:00
|
|
|
{
|
1996-02-23 11:37:28 +00:00
|
|
|
int nm = scad / 30;
|
|
|
|
int ny = nm / 12;
|
|
|
|
nm %= 12;
|
1996-02-16 17:01:42 +00:00
|
|
|
|
1996-02-05 10:40:51 +00:00
|
|
|
int newm = d.month() + nm;
|
|
|
|
if (newm > 12) { newm -= 12; ny++; }
|
1996-02-16 17:01:42 +00:00
|
|
|
|
1996-02-23 11:37:28 +00:00
|
|
|
// bool last = d.is_end_month() && inizio_scadenza() == 'M';
|
|
|
|
const bool last = inizio_scadenza() == 'M' || _datadoc.is_end_month();
|
1996-02-16 17:01:42 +00:00
|
|
|
|
1996-02-05 10:40:51 +00:00
|
|
|
int dy = d.day();
|
1996-02-16 17:01:42 +00:00
|
|
|
|
1996-02-23 11:37:28 +00:00
|
|
|
// la palla del febbraio & c. ???
|
1996-02-05 10:40:51 +00:00
|
|
|
if (rata > 1)
|
|
|
|
{
|
1996-02-23 11:37:28 +00:00
|
|
|
const TDate oldd(data_rata(rata-2));
|
1996-02-05 10:40:51 +00:00
|
|
|
if (oldd.day() > dy) dy = oldd.day();
|
|
|
|
}
|
1996-02-16 17:01:42 +00:00
|
|
|
|
1996-02-23 11:37:28 +00:00
|
|
|
d.set_day(1); // il giorno 1 ce l'hanno tutti
|
1996-02-05 10:40:51 +00:00
|
|
|
d.set_month(newm);
|
|
|
|
d.set_year(d.year()+ny);
|
1996-02-23 11:37:28 +00:00
|
|
|
/*
|
1996-02-05 10:40:51 +00:00
|
|
|
d.set_end_month();
|
|
|
|
if (!last && dy < d.day())
|
|
|
|
d.set_day(dy);
|
1996-02-23 11:37:28 +00:00
|
|
|
*/
|
|
|
|
if (last)
|
|
|
|
d.set_end_month();
|
|
|
|
else
|
|
|
|
d.set_day(dy);
|
1996-02-06 10:54:37 +00:00
|
|
|
}
|
1996-02-16 17:01:42 +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
|
1996-02-02 11:09:18 +00:00
|
|
|
TToken_string* tt = new TToken_string("-1| | | | | | | ");
|
1996-01-08 09:55:34 +00:00
|
|
|
_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
|
1996-02-02 11:09:18 +00:00
|
|
|
tt->add(""); // importo valuta
|
1995-11-03 07:47:20 +00:00
|
|
|
tt->add(ulc); // ulc
|
1996-02-02 11:09:18 +00:00
|
|
|
tt->add(""); // ratapagata
|
|
|
|
tt->add(""); // importo lire
|
1995-11-03 07:47:20 +00:00
|
|
|
|
|
|
|
_rate.add(tt);
|
|
|
|
_dirty = TRUE;
|
|
|
|
return *tt;
|
|
|
|
}
|
|
|
|
|
|
|
|
TToken_string& TPagamento::set_rata (int index, real perc, int day, int type,
|
1996-02-02 11:09:18 +00:00
|
|
|
bool val, const char* ulc, const char* imp, const char* data)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
|
|
|
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);
|
1996-02-02 11:09:18 +00:00
|
|
|
tt->add(imp == NULL ? "" : imp, val ? 4 : 7);
|
1995-11-03 07:47:20 +00:00
|
|
|
tt->add(ulc == NULL ? "" : ulc, 5);
|
1996-02-02 11:09:18 +00:00
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
if (!nwr)
|
|
|
|
{
|
|
|
|
if (index > _rate.items())
|
|
|
|
{
|
|
|
|
error_box("Rate non contigue");
|
|
|
|
delete tt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_rate.add(tt,index);
|
|
|
|
_dirty = TRUE;
|
|
|
|
}
|
|
|
|
return *tt;
|
|
|
|
}
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
void TPagamento::set_imprata(int i, const real& r, bool v)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
|
|
|
TToken_string& tt = (TToken_string&)_rate[i];
|
1996-02-02 11:09:18 +00:00
|
|
|
tt.add(r.string(), v ? 4 : 7);
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
real TPagamento::recalc_percrata(int i, bool v)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
real hm(importo_da_dividere(v));
|
1996-01-23 11:54:34 +00:00
|
|
|
|
|
|
|
if (i == 0 && _tpr > 3) return ZERO;
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
real tpay(importo_rata(i,v));
|
1995-12-22 15:33:27 +00:00
|
|
|
if (i == 0 && _tpr > 0 && _tpr < 4)
|
1996-02-02 11:09:18 +00:00
|
|
|
tpay -= importo_da_non_dividere(v);
|
1995-12-22 15:33:27 +00:00
|
|
|
real perc = tpay * 100.0 / hm;
|
1995-11-03 07:47:20 +00:00
|
|
|
perc.round(2);
|
|
|
|
set_percrata(i, perc);
|
|
|
|
|
|
|
|
return perc;
|
|
|
|
}
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
TToken_string& TPagamento::set_rata(int index, const real& impval, const real& implit,
|
|
|
|
const TDate& date, int type,const char* ulc, bool pagato)
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
|
|
|
// calcola percentuali e scadenze a partire dagli importi
|
1996-05-17 16:42:01 +00:00
|
|
|
TToken_string* tt = _rate.rowptr(index);
|
1995-11-03 07:47:20 +00:00
|
|
|
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;
|
1996-02-02 11:09:18 +00:00
|
|
|
const long day = date - oldd;
|
|
|
|
|
|
|
|
const real toshare = importo_da_dividere(in_valuta());
|
1995-11-03 07:47:20 +00:00
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
real hm = in_valuta() ? impval : implit;
|
1995-11-03 07:47:20 +00:00
|
|
|
if (index == first && _tpr > 0 && _tpr < 4)
|
1996-02-02 11:09:18 +00:00
|
|
|
hm -= importo_da_non_dividere(in_valuta());
|
1995-11-03 07:47:20 +00:00
|
|
|
|
|
|
|
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
|
1996-02-02 11:09:18 +00:00
|
|
|
tt->add(impval.string()); // 4 - importo
|
1995-11-03 07:47:20 +00:00
|
|
|
tt->add(ulc); // 5 - ulc(era?)
|
|
|
|
tt->add(pagato ? "X" : " "); // 6 - pagata
|
1996-02-02 11:09:18 +00:00
|
|
|
tt->add(implit.string()); // 7 - Importo in lire
|
1995-11-03 07:47:20 +00:00
|
|
|
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;
|
1996-02-09 08:39:50 +00:00
|
|
|
int warnscad = 0;
|
1995-11-03 07:47:20 +00:00
|
|
|
real r(0.0);
|
|
|
|
|
|
|
|
int first = _tpr < 4 ? 0 : 1;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
for (int i = 0; i < n_rate(); i++)
|
1996-01-04 13:39:57 +00:00
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
const real tpay(tlit_rata(i));
|
1996-01-04 13:39:57 +00:00
|
|
|
|
|
|
|
if (tpay.is_zero())
|
1996-02-02 11:09:18 +00:00
|
|
|
res |= P_ZEROLIT;
|
1996-01-04 13:39:57 +00:00
|
|
|
tot += tpay;
|
|
|
|
}
|
1996-01-16 11:01:04 +00:00
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
tot.round(_roundlit);
|
1996-01-26 10:30:15 +00:00
|
|
|
// serve per fatture in valuta, onde evitare cazzi e canguri
|
1996-02-02 11:09:18 +00:00
|
|
|
real tmax = importo_da_dividere(FALSE) + importo_da_non_dividere(FALSE);
|
|
|
|
tmax.round(_roundlit);
|
1996-01-26 10:30:15 +00:00
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
if (tot != tmax) res |= P_TOTNCLIT;
|
|
|
|
|
1996-02-05 10:40:51 +00:00
|
|
|
if (in_valuta())
|
1996-02-02 11:09:18 +00:00
|
|
|
{
|
|
|
|
tot = 0.0;
|
|
|
|
for (int i = 0; i < n_rate(); i++)
|
|
|
|
{
|
|
|
|
const real tpay(tval_rata(i));
|
|
|
|
|
|
|
|
if (tpay.is_zero())
|
|
|
|
res |= P_ZEROVAL;
|
|
|
|
tot += tpay;
|
|
|
|
}
|
|
|
|
|
|
|
|
tot.round(_roundval);
|
|
|
|
// serve per fatture in valuta, onde evitare cazzi e canguri
|
|
|
|
real tmax = importo_da_dividere(TRUE) + importo_da_non_dividere(TRUE);
|
|
|
|
tmax.round(_roundval);
|
|
|
|
|
|
|
|
if (tot != tmax) res |= P_TOTNCVAL;
|
|
|
|
}
|
|
|
|
|
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++)
|
|
|
|
{
|
1996-02-09 08:39:50 +00:00
|
|
|
if (data_rata(i) < d)
|
|
|
|
{ res |= P_SCAD; break; }
|
|
|
|
if (data_rata(i) == d)
|
|
|
|
warnscad++;
|
1995-11-03 07:47:20 +00:00
|
|
|
d = data_rata(i);
|
|
|
|
}
|
1996-02-09 08:39:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (warnscad && !yesno_box("N. %d rate cadono nello stesso giorno. Si desidera proseguire?", warnscad+1))
|
|
|
|
res |= P_SCAD;
|
|
|
|
|
1995-11-03 07:47:20 +00:00
|
|
|
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";
|
1996-02-02 11:09:18 +00:00
|
|
|
if (err & P_TOTNCLIT)
|
1995-12-13 15:12:13 +00:00
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
const real tot = importo_da_dividere(FALSE) + importo_da_non_dividere(FALSE);
|
1995-12-13 15:12:13 +00:00
|
|
|
real imp;
|
|
|
|
for (int i = 0; i < n_rate(); i++)
|
1996-02-02 11:09:18 +00:00
|
|
|
imp += tlit_rata(i);
|
1996-01-18 09:23:11 +00:00
|
|
|
char pic[3] = ".0";
|
1996-02-02 11:09:18 +00:00
|
|
|
pic[1] += _roundlit;
|
|
|
|
s << "- la somma degli importi in lire (" << imp.string(pic);
|
1996-02-13 16:35:59 +00:00
|
|
|
s << ") e' diversa dal\ntotale del documento in lire(" << tot.string(pic) << ")\n";
|
1996-02-02 11:09:18 +00:00
|
|
|
}
|
|
|
|
if (err & P_TOTNCVAL)
|
|
|
|
{
|
|
|
|
const real tot = importo_da_dividere(TRUE) + importo_da_non_dividere(TRUE);
|
|
|
|
real imp;
|
|
|
|
for (int i = 0; i < n_rate(); i++)
|
|
|
|
imp += tval_rata(i);
|
|
|
|
char pic[3] = ".0";
|
|
|
|
pic[1] += _roundval;
|
|
|
|
s << "- la somma degli importi in valuta (" << imp.string(pic);
|
1996-02-13 16:35:59 +00:00
|
|
|
s << ") e' diversa dal\ntotale del documento in valuta(" << 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-02-02 11:09:18 +00:00
|
|
|
if (err & P_ZEROLIT)
|
|
|
|
s << "- almeno una rata ha importo in lire uguale a zero\n";
|
|
|
|
if (err & P_ZEROVAL)
|
|
|
|
s << "- almeno una rata ha importo in valuta uguale a 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 > ' ')
|
|
|
|
{
|
1996-02-21 09:00:03 +00:00
|
|
|
const char key[] = { tipo+'0', toupper(ulc), '\0' };
|
1995-11-03 13:56:08 +00:00
|
|
|
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,
|
1996-02-02 11:09:18 +00:00
|
|
|
const char* new_value, const char* new_lire,
|
|
|
|
const char* scad, const char* typ, const char* ulc,
|
|
|
|
int rdiff, bool mcomm, bool& need_recalc)
|
1995-11-03 07:47:20 +00:00
|
|
|
// 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.
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
CHECK(!(!is_perc_modified && (new_value != NULL || new_lire != NULL) && !_inited),
|
1995-11-03 07:47:20 +00:00
|
|
|
"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
|
1996-02-09 08:39:50 +00:00
|
|
|
int warnscad = 0;
|
1995-11-03 07:47:20 +00:00
|
|
|
|
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];
|
1996-02-07 10:31:25 +00:00
|
|
|
lastdate = scad;
|
|
|
|
int lastscad = oldscad;
|
1995-11-16 09:56:22 +00:00
|
|
|
// controlla errore sulla data scadenza
|
|
|
|
if (i > 0)
|
|
|
|
{
|
1996-02-09 08:39:50 +00:00
|
|
|
oldscad = lastscad = (int)(lastdate - data_rata(i-1));
|
|
|
|
if (oldscad < 0l) return P_SCAD;
|
1995-11-16 09:56:22 +00:00
|
|
|
}
|
1996-02-07 10:31:25 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (lastdate < _datadoc)
|
|
|
|
return P_INIZIO; // _inizio
|
|
|
|
lastscad = scad_rata(0);
|
|
|
|
}
|
|
|
|
tt.add(scad,3); tt.add(lastscad, 0);
|
|
|
|
ss.add(scad,3); ss.add(lastscad, 0);
|
1995-11-16 09:56:22 +00:00
|
|
|
// 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++)
|
|
|
|
{
|
1996-02-05 10:40:51 +00:00
|
|
|
TToken_string& ttt = rata(j);
|
|
|
|
TToken_string& sss = (TToken_string&)srate[j];
|
1996-01-08 09:55:34 +00:00
|
|
|
next_scad(ddd,scad_rata(j), mcomm,j);
|
1996-02-05 10:40:51 +00:00
|
|
|
ttt.add(ddd.string(),3);
|
|
|
|
sss.add(ddd.string(),3);
|
1995-11-16 09:56:22 +00:00
|
|
|
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-02-14 10:41:16 +00:00
|
|
|
if (sc < 0) return P_SCAD;
|
1996-02-09 08:39:50 +00:00
|
|
|
if (row > 0 && sc == 0 &&
|
|
|
|
!yesno_box("Due o piu' rate cadranno nello stesso giorno. Si conferma l'immissione?"))
|
|
|
|
return P_SCAD;
|
1996-01-09 18:50:34 +00:00
|
|
|
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
|
1996-02-02 11:09:18 +00:00
|
|
|
return change_value(row, real(new_value), rdiff, is_perc_modified, mcomm, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_lire != NULL)
|
|
|
|
{
|
|
|
|
need_recalc = TRUE;
|
|
|
|
// questa pure la subappaltiamo, sempre per evitare l'inferno
|
|
|
|
return change_value(row, real(new_lire), rdiff, is_perc_modified, mcomm, FALSE);
|
1996-01-08 09:55:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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-02-09 08:39:50 +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
|
|
|
}
|
|
|
|
}
|
1996-02-09 08:39:50 +00:00
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
adjust_fixed_scad();
|
|
|
|
return P_OK;
|
|
|
|
}
|
|
|
|
|
1996-01-22 10:38:53 +00:00
|
|
|
word TPagamento::change_value(int rata, real user_val, int rdiff, bool is_perc,
|
1996-02-02 11:09:18 +00:00
|
|
|
bool mcomm, bool valuta)
|
1996-01-08 09:55:34 +00:00
|
|
|
{
|
|
|
|
word err = 0;
|
|
|
|
|
|
|
|
switch (rdiff)
|
|
|
|
{
|
|
|
|
case 1:
|
1996-02-02 11:09:18 +00:00
|
|
|
err = change_value_differenziate(rata, user_val, is_perc, valuta);
|
1996-01-08 09:55:34 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
1996-02-02 11:09:18 +00:00
|
|
|
err = change_value_uguali(rata, user_val, is_perc, valuta);
|
1996-01-08 09:55:34 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
1996-02-02 11:09:18 +00:00
|
|
|
err = change_value_uguali_prossima(rata, user_val, is_perc, valuta);
|
1996-01-08 09:55:34 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
1996-02-02 11:09:18 +00:00
|
|
|
err = change_value_uguali_possible(rata, user_val, is_perc, valuta);
|
1996-01-08 09:55:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!err)
|
|
|
|
{
|
|
|
|
// riaggiusta gli altri parametri se si sono create rate nuove
|
1996-01-22 10:38:53 +00:00
|
|
|
adjust_parameters(mcomm);
|
1996-01-08 09:55:34 +00:00
|
|
|
// risistema scadenze fisse se necessario
|
|
|
|
adjust_fixed_scad();
|
|
|
|
// riaggiusta le percentuali o gli importi rispetto al dato modificato
|
1996-02-02 11:09:18 +00:00
|
|
|
if (_inited)
|
|
|
|
{
|
|
|
|
// questa aggiusta anche l'eventuale importo in lire se si e' in valuta
|
|
|
|
// e si e' modificato l'importo in valuta
|
|
|
|
adjust_perc_imp(is_perc, rdiff, valuta);
|
|
|
|
// se era in valuta e ho modificato le percentuali aggiustalo anche in lire
|
|
|
|
if (valuta && is_perc) adjust_perc_imp(is_perc, rdiff, FALSE);
|
|
|
|
}
|
1996-01-09 11:13:41 +00:00
|
|
|
_dirty = TRUE;
|
1996-01-08 09:55:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
1996-01-12 17:43:52 +00:00
|
|
|
// Sulla prima riga, se il tipo rata e > 0 il valore (importo o percentuale)
|
|
|
|
// puo' anche essere nullo, altrimenti deve essere positivo
|
|
|
|
bool TPagamento::sign_ok(const real& val, int row) const
|
|
|
|
{
|
|
|
|
const bool ok = val.sign() > (row == 0 && _tpr > 0 ? -1 : 0);
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
// 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
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
word TPagamento::change_value_differenziate(int row, real user_val, bool is_perc, bool v)
|
1996-01-08 09:55:34 +00:00
|
|
|
{
|
|
|
|
// importi totali, da non suddividere, da suddividere
|
1996-02-02 11:09:18 +00:00
|
|
|
real to_share = is_perc ? real(100.0) : importo_da_dividere(v);
|
1996-01-08 09:55:34 +00:00
|
|
|
real to_subtract = ZERO;
|
|
|
|
if (row == 0 && _tpr > 0 && _tpr < 4 && !is_perc)
|
1996-02-02 11:09:18 +00:00
|
|
|
to_subtract = importo_da_non_dividere(v);
|
1996-01-08 09:55:34 +00:00
|
|
|
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-12 17:43:52 +00:00
|
|
|
if (!sign_ok(user_div, row))
|
|
|
|
return P_NEG;
|
1996-01-09 11:13:41 +00:00
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
// togli rate gia' presenti
|
|
|
|
for (int i = first; i < row; i++)
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
to_share -= (is_perc ? perc_rata(i): importo_rata(i,v));
|
1996-01-08 09:55:34 +00:00
|
|
|
if (i == 0 && !is_perc && _tpr > 0 && _tpr < 4)
|
1996-02-02 11:09:18 +00:00
|
|
|
to_share += importo_da_non_dividere(v);
|
1996-01-08 09:55:34 +00:00
|
|
|
}
|
1996-02-02 11:09:18 +00:00
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
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-02-02 11:09:18 +00:00
|
|
|
const int tok_ind = is_perc ? 1 : (v ? 4 : 7);
|
1996-01-08 11:32:33 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
word TPagamento::change_value_uguali(int row, real user_val, bool is_perc, bool v)
|
1996-01-08 09:55:34 +00:00
|
|
|
{
|
|
|
|
// importi totali, da non suddividere, da suddividere
|
1996-02-02 11:09:18 +00:00
|
|
|
real to_share = is_perc ? real(100.0) : importo_da_dividere(v);
|
1996-01-08 09:55:34 +00:00
|
|
|
real to_subtract = ZERO;
|
|
|
|
if (row == 0 && _tpr > 0 && _tpr < 4 && !is_perc)
|
1996-02-02 11:09:18 +00:00
|
|
|
to_subtract = importo_da_non_dividere(v);
|
1996-01-08 09:55:34 +00:00
|
|
|
real user_div = user_val - to_subtract;
|
|
|
|
real remainder = to_share - user_div;
|
1996-02-02 11:09:18 +00:00
|
|
|
const int tok_ind = is_perc ? 1 : (v ? 4 : 7);
|
1996-01-08 11:32:33 +00:00
|
|
|
const int first = _tpr > 3 ? 1 : 0;
|
1996-01-08 09:55:34 +00:00
|
|
|
_rdiff = FALSE;
|
1996-01-12 17:43:52 +00:00
|
|
|
|
|
|
|
if (!sign_ok(user_div, row))
|
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())
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
real tp = is_perc ? perc_rata(first) : importo_rata(first,v);
|
1996-01-08 09:55:34 +00:00
|
|
|
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-02-02 11:09:18 +00:00
|
|
|
div.round(is_perc ? 2 : round(v));
|
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)
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
first_imp = is_perc ? perc_rata(0) : importo_rata(0,v);
|
|
|
|
if (_tpr > 0 && !is_perc) first_imp -= importo_da_non_dividere(v);
|
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())
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
real tp = is_perc ? perc_rata(first) : importo_rata(first,v);
|
1996-01-08 09:55:34 +00:00
|
|
|
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-02-02 11:09:18 +00:00
|
|
|
word TPagamento::change_value_uguali_prossima(int row, real user_val, bool is_perc, bool v)
|
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
|
1996-02-02 11:09:18 +00:00
|
|
|
real to_share = is_perc ? real(100.0) : importo_da_dividere(v);
|
1996-01-08 11:32:33 +00:00
|
|
|
real to_subtract = ZERO;
|
|
|
|
if (row == 0 && _tpr > 0 && _tpr < 4 && !is_perc)
|
1996-02-02 11:09:18 +00:00
|
|
|
to_subtract = importo_da_non_dividere(v);
|
1996-01-08 11:32:33 +00:00
|
|
|
real user_div = user_val - to_subtract;
|
1996-02-02 11:09:18 +00:00
|
|
|
const int tok_ind = is_perc ? 1 : (v ? 4 : 7);
|
1996-01-08 11:32:33 +00:00
|
|
|
const int first = _tpr > 3 ? 1 : 0;
|
1996-01-09 11:13:41 +00:00
|
|
|
|
1996-01-12 17:43:52 +00:00
|
|
|
if (!sign_ok(user_div, row))
|
1996-01-09 11:13:41 +00:00
|
|
|
return P_NEG;
|
1996-01-08 11:32:33 +00:00
|
|
|
|
|
|
|
// togli rate gia' presenti
|
|
|
|
for (int i = first; i < row; i++)
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
to_share -= (is_perc ? perc_rata(i): importo_rata(i,v));
|
1996-01-08 11:32:33 +00:00
|
|
|
if (i == 0 && !is_perc && _tpr > 0 && _tpr < 4)
|
1996-02-02 11:09:18 +00:00
|
|
|
to_share += importo_da_non_dividere(v);
|
1996-01-08 11:32:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
real r = is_perc ? perc_rata(first) : importo_rata(first,v);
|
1996-01-08 11:32:33 +00:00
|
|
|
r += delta;
|
|
|
|
rata(first).add(r.string(), tok_ind);
|
|
|
|
}
|
1996-01-08 09:55:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
word TPagamento::change_value_uguali_possible(int row, real user_val, bool is_perc, bool v)
|
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
|
1996-02-02 11:09:18 +00:00
|
|
|
real to_share = is_perc ? real(100.0) : importo_da_dividere(v);
|
1996-01-08 11:32:33 +00:00
|
|
|
real to_subtract = ZERO;
|
|
|
|
if (row == 0 && _tpr > 0 && _tpr < 4 && !is_perc)
|
1996-02-02 11:09:18 +00:00
|
|
|
to_subtract = importo_da_non_dividere(v);
|
1996-01-08 11:32:33 +00:00
|
|
|
real user_div = user_val - to_subtract;
|
1996-02-02 11:09:18 +00:00
|
|
|
const int tok_ind = is_perc ? 1 : (v ? 4 : 7);
|
1996-01-08 11:32:33 +00:00
|
|
|
const int first = _tpr > 3 ? 1 : 0;
|
|
|
|
|
1996-01-12 17:43:52 +00:00
|
|
|
if (!sign_ok(user_div, row))
|
1996-01-09 11:13:41 +00:00
|
|
|
return P_NEG;
|
|
|
|
|
1996-01-08 11:32:33 +00:00
|
|
|
// togli rate gia' presenti
|
|
|
|
for (int i = first; i < row; i++)
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
to_share -= (is_perc ? perc_rata(i): importo_rata(i,v));
|
1996-01-08 11:32:33 +00:00
|
|
|
if (i == 0 && !is_perc && _tpr > 0 && _tpr < 4)
|
1996-02-02 11:09:18 +00:00
|
|
|
to_share += importo_da_non_dividere(v);
|
1996-01-08 11:32:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1996-01-22 10:38:53 +00:00
|
|
|
void TPagamento::adjust_parameters(bool mcomm)
|
1996-01-08 09:55:34 +00:00
|
|
|
{
|
|
|
|
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
|
1996-01-22 10:38:53 +00:00
|
|
|
next_scad(last_date, last_scad == 0 ? _int_rate : last_scad, mcomm, i);
|
1996-01-08 09:55:34 +00:00
|
|
|
#else
|
1996-01-22 10:38:53 +00:00
|
|
|
next_scad(last_date, last_scad, mcomm, i);
|
1996-01-08 09:55:34 +00:00
|
|
|
#endif
|
|
|
|
r.add(last_date, 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
void TPagamento::adjust_perc(int rdiff, bool v)
|
1996-01-08 09:55:34 +00:00
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
real other = importo_da_dividere(v);
|
1996-01-08 09:55:34 +00:00
|
|
|
|
|
|
|
const int first = _tpr > 3 ? 1 : 0;
|
|
|
|
|
1996-01-12 18:08:48 +00:00
|
|
|
for (int j = first; j < _rate.items(); j++)
|
1996-01-08 09:55:34 +00:00
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
real rvl = importo_rata(j,v);
|
1996-01-17 10:58:03 +00:00
|
|
|
// togli pezzo di troppo
|
1996-01-12 18:08:48 +00:00
|
|
|
if (j == first && _tpr > 0 && _tpr < 4)
|
1996-02-02 11:09:18 +00:00
|
|
|
rvl -= importo_da_non_dividere(v);
|
1996-01-12 18:08:48 +00:00
|
|
|
real zpx = (rvl * 100.0)/other; // percentuale
|
|
|
|
zpx.round(2);
|
1996-02-02 11:09:18 +00:00
|
|
|
set_percrata(j, zpx);
|
|
|
|
}
|
|
|
|
if (in_valuta())
|
|
|
|
{
|
|
|
|
// riaggiusta l'importo rimanente
|
|
|
|
real tot = importo_da_dividere(!v);
|
|
|
|
TDistrib dt(tot); dt.set_dec(round(!v));
|
|
|
|
for (j = first; j < _rate.items(); j++)
|
|
|
|
{
|
|
|
|
real rvl = importo_rata(j,v);
|
|
|
|
// togli pezzo di troppo
|
|
|
|
if (j == first && _tpr > 0 && _tpr < 4)
|
|
|
|
rvl -= importo_da_non_dividere(v);
|
|
|
|
dt.add(rvl/other);
|
|
|
|
}
|
|
|
|
for (j = first; j < _rate.items(); j++)
|
|
|
|
{
|
|
|
|
real rvl = dt.get();
|
|
|
|
// aggiungi pezzo mancante
|
|
|
|
if (j == first && _tpr > 0 && _tpr < 4)
|
|
|
|
rvl += importo_da_non_dividere(!v);
|
|
|
|
set_imprata(j, rvl, !v);
|
1996-01-12 18:08:48 +00:00
|
|
|
}
|
1996-02-02 11:09:18 +00:00
|
|
|
}
|
1996-01-12 18:08:48 +00:00
|
|
|
}
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
void TPagamento::adjust_perc_imp(bool is_perc, int rdiff, bool v)
|
1996-01-12 18:08:48 +00:00
|
|
|
{
|
|
|
|
if (!is_perc)
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
adjust_perc(rdiff, v);
|
1996-01-12 18:08:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
real toshare(importo_da_dividere(v));
|
|
|
|
const real other(100.0);
|
|
|
|
bool inv = in_valuta();
|
|
|
|
|
|
|
|
TDistrib dt(toshare, round(v));
|
1996-01-12 18:08:48 +00:00
|
|
|
const int first = _tpr > 3 ? 1 : 0;
|
1996-02-02 11:09:18 +00:00
|
|
|
|
|
|
|
TDistrib ot(0.0, 0); // slicer per l'importo non modificato
|
|
|
|
if (inv)
|
|
|
|
{
|
|
|
|
ot.init(importo_da_dividere(!v));
|
|
|
|
ot.set_dec(round(v));
|
|
|
|
}
|
|
|
|
|
1996-01-12 18:08:48 +00:00
|
|
|
for (int j = _rate.items() - 1; j >= first ; j--)
|
|
|
|
{
|
|
|
|
real rvl = perc_rata(j);
|
|
|
|
// togli pezxo di troppo
|
1996-01-08 09:55:34 +00:00
|
|
|
real zpx = rvl/other; // percentuale
|
1996-02-02 11:09:18 +00:00
|
|
|
dt.add(zpx);
|
|
|
|
if (inv) ot.add(zpx);
|
1996-01-08 09:55:34 +00:00
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
|
1996-01-17 10:58:03 +00:00
|
|
|
real rem(toshare);
|
1996-02-02 11:09:18 +00:00
|
|
|
real oem(0.0);
|
|
|
|
if (inv) oem = importo_da_dividere(!v);
|
1996-01-15 19:02:17 +00:00
|
|
|
|
1996-01-12 18:08:48 +00:00
|
|
|
for (j = n_rate() - 1; j >= first ; j--)
|
1996-01-08 09:55:34 +00:00
|
|
|
{
|
|
|
|
real rfirst(0.0);
|
1996-02-02 11:09:18 +00:00
|
|
|
real ofirst(0.0);
|
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
TToken_string& tr = rata(j);
|
1995-11-03 07:47:20 +00:00
|
|
|
|
1996-01-15 19:02:17 +00:00
|
|
|
real rvl = dt.get();
|
|
|
|
rem -= rvl;
|
1996-02-02 11:09:18 +00:00
|
|
|
real ovl;
|
|
|
|
|
|
|
|
if (inv)
|
|
|
|
{
|
|
|
|
ovl = ot.get();
|
|
|
|
oem -= ovl;
|
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
|
1996-01-08 09:55:34 +00:00
|
|
|
if (j == first)
|
|
|
|
{
|
|
|
|
rfirst = rvl;
|
1996-01-17 10:58:03 +00:00
|
|
|
if (!rem.is_zero()) rfirst += rem;
|
1996-02-02 11:09:18 +00:00
|
|
|
|
|
|
|
if (inv)
|
|
|
|
{
|
|
|
|
ofirst = ovl;
|
|
|
|
if (!oem.is_zero()) ofirst += oem;
|
|
|
|
}
|
1996-01-08 09:55:34 +00:00
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
|
1996-01-12 18:08:48 +00:00
|
|
|
if (j == first && _tpr > 0 && _tpr < 4)
|
1996-01-08 09:55:34 +00:00
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
rfirst += importo_da_non_dividere(v);
|
|
|
|
if (inv)
|
|
|
|
ofirst += importo_da_non_dividere(!v);
|
|
|
|
}
|
|
|
|
tr.add((j == first ? rfirst.string() : rvl.string()), v ? 4 : 7);
|
|
|
|
if (inv)
|
|
|
|
tr.add((j == first ? ofirst.string() : ovl.string()), v ? 7 : 4);
|
1996-01-17 10:58:03 +00:00
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
_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')
|
1996-02-23 11:37:28 +00:00
|
|
|
_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
|
|
|
|
_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
|
1996-02-02 11:09:18 +00:00
|
|
|
|
1995-11-14 15:58:25 +00:00
|
|
|
if (n_rate() == 0 || !_inited || (_tpr > 3 && n_rate() == 1))
|
|
|
|
return;
|
1996-02-02 11:09:18 +00:00
|
|
|
int first = _tpr > 3 ? 1 : 0;
|
1995-11-14 15:58:25 +00:00
|
|
|
|
|
|
|
main_app().begin_wait();
|
1996-02-08 09:12:02 +00:00
|
|
|
set_inizio(_datadoc);
|
1996-02-02 11:09:18 +00:00
|
|
|
|
|
|
|
for (int v = 0; v < (in_valuta() ? 2 : 1); v++)
|
|
|
|
{
|
|
|
|
real toslice = importo_da_dividere(v);
|
|
|
|
if (_tpr > 3) set_imprata(0, importo_da_non_dividere(v), v);
|
|
|
|
|
|
|
|
real r1(0.0), ro(0.0);
|
|
|
|
if (!_rdiff)
|
1996-02-23 14:14:37 +00:00
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
const int rut = _tpr > 3 ? n_rate() - 1 : n_rate();
|
|
|
|
if (rut > 1) // Guy was here! Don't kill me for this
|
1996-01-12 17:43:52 +00:00
|
|
|
{
|
1996-02-23 14:14:37 +00:00
|
|
|
real refrata = real(100.0)/real(rut); refrata.round(2);
|
|
|
|
if (perc_rata(first+1) == refrata) // tutte uguali nonostante perc arrotondate
|
|
|
|
{
|
|
|
|
ro = toslice / real(rut);
|
|
|
|
ro.round(round(v));
|
|
|
|
r1 = toslice - (ro * real(rut-1));
|
|
|
|
}
|
|
|
|
else // la prima e' diversa
|
1996-02-02 11:09:18 +00:00
|
|
|
{
|
1996-02-23 14:14:37 +00:00
|
|
|
// usa la percentuale per la prima rata
|
|
|
|
r1 = (toslice * perc_rata(first))/real(100.0);
|
|
|
|
|
|
|
|
const real reminder = toslice - r1;
|
|
|
|
if (!reminder.is_zero())
|
|
|
|
{
|
|
|
|
ro = reminder/real(rut-1); ro.round(round(v));
|
|
|
|
r1 = (toslice - (ro*real(rut-1)));
|
|
|
|
}
|
1996-02-02 11:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
1996-02-13 09:37:14 +00:00
|
|
|
r1 = toslice;
|
|
|
|
r1.round(round(v));
|
1996-02-02 11:09:18 +00:00
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
|
1996-02-14 10:41:16 +00:00
|
|
|
real rdi, rdsum;
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
for (int i = first; i < n_rate(); i++)
|
|
|
|
// setta le fette e le date di scadenza
|
1996-02-14 10:41:16 +00:00
|
|
|
{
|
|
|
|
if (_rdiff)
|
|
|
|
{
|
|
|
|
rdi = toslice*(perc_rata(i)/real(100.0));
|
|
|
|
rdi.round(round(v));
|
|
|
|
if (i > first) rdsum += rdi;
|
|
|
|
}
|
|
|
|
set_imprata(i, _rdiff ? rdi : (i == first ? r1 : ro), v);
|
|
|
|
}
|
|
|
|
if (_rdiff)
|
|
|
|
set_imprata(first, toslice - rdsum, v);
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
// se e' nei primi tre casi, si somma l'importo da non dividere alla
|
|
|
|
// prima rata
|
|
|
|
if (_tpr > 0 && _tpr < 4)
|
|
|
|
set_imprata(0, importo_rata(0,v) + importo_da_non_dividere(v), v);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
const real& TPagamento::importo_da_dividere(bool v) const
|
1996-01-30 11:46:19 +00:00
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
if (_tpr < 4) return v ? _firstr : _firstl;
|
|
|
|
else return v ? _secndr : _secndl;
|
1996-01-30 11:46:19 +00:00
|
|
|
}
|
1995-11-03 07:47:20 +00:00
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
const real& TPagamento::importo_da_non_dividere(bool v) const
|
1996-01-30 11:46:19 +00:00
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
if (_tpr < 4) return v ? _secndr : _secndl;
|
|
|
|
else return v ? _firstr : _firstl;
|
1996-01-30 11:46:19 +00:00
|
|
|
}
|
1996-02-07 11:51:14 +00:00
|
|
|
|
|
|
|
void TPagamento::set_total(const real& ib, const real& im, const real& sp)
|
|
|
|
{
|
|
|
|
_in_valuta = FALSE;
|
|
|
|
_cambio = 1.0;
|
|
|
|
|
|
|
|
_firstr = _secndr = ZERO; // Azzera importi in valuta
|
|
|
|
init_total(ib, im, sp, FALSE); // setta regolarmente totali in lire
|
|
|
|
}
|
1996-02-02 11:09:18 +00:00
|
|
|
|
|
|
|
void TPagamento::set_total_valuta(const real& ib, const real& im, const real& sp, const real& c,
|
|
|
|
const real& ibl, const real& iml, const real& spl)
|
|
|
|
{
|
1996-02-07 11:51:14 +00:00
|
|
|
const bool era_valuta = _in_valuta;
|
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
_in_valuta = TRUE;
|
|
|
|
_cambio = c;
|
|
|
|
if (_cambio.sign() <= 0)
|
|
|
|
_cambio = real(1.0);
|
|
|
|
|
|
|
|
// setta regolarmente totali in lire
|
1996-02-07 11:51:14 +00:00
|
|
|
init_total(ibl, iml, spl, FALSE);
|
1996-02-02 11:09:18 +00:00
|
|
|
// ripeti tutto con la valuta
|
1996-02-07 11:51:14 +00:00
|
|
|
init_total(ib, im, sp, TRUE);
|
|
|
|
|
|
|
|
if (!era_valuta && _in_valuta)
|
|
|
|
adjust_perc_imp(TRUE, _rdiff, TRUE);
|
1996-02-02 11:09:18 +00:00
|
|
|
}
|
|
|
|
|
1996-02-07 11:51:14 +00:00
|
|
|
void TPagamento::init_total(const real& ib, const real& im, const real& sp, bool valuta)
|
1996-02-02 11:09:18 +00:00
|
|
|
{
|
1996-02-07 11:51:14 +00:00
|
|
|
const int round = valuta ? _roundval : _roundlit;
|
1996-02-02 11:09:18 +00:00
|
|
|
real& ibp = valuta ? _imponval : _imponlit;
|
|
|
|
real& imp = valuta ? _imposval : _imposlit;
|
|
|
|
real& spp = valuta ? _speseval : _speselit;
|
|
|
|
real& frs = valuta ? _firstr : _firstl;
|
|
|
|
real& scn = valuta ? _secndr : _secndl;
|
|
|
|
|
|
|
|
ibp = ib; ibp.round(round);
|
|
|
|
imp = im; imp.round(round);
|
|
|
|
spp = sp; spp.round(round);
|
|
|
|
_inited = TRUE;
|
1995-11-03 07:47:20 +00:00
|
|
|
|
|
|
|
// istanzia _firstr e _secndr a seconda di _tpr
|
|
|
|
switch(_tpr)
|
|
|
|
{
|
|
|
|
case 0:
|
1996-02-02 11:09:18 +00:00
|
|
|
frs = ibp + imp + spp;
|
|
|
|
scn = 0.0;
|
1995-11-03 07:47:20 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
1996-02-02 11:09:18 +00:00
|
|
|
scn = imp;
|
|
|
|
frs = ibp + spp;
|
1995-11-03 07:47:20 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
1996-02-02 11:09:18 +00:00
|
|
|
scn = spp;
|
|
|
|
frs = ibp + imp;
|
1995-11-03 07:47:20 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
1996-02-02 11:09:18 +00:00
|
|
|
scn = imp + spp;
|
|
|
|
frs = ibp;
|
1995-11-03 07:47:20 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
1996-02-02 11:09:18 +00:00
|
|
|
scn = spp + ibp;
|
|
|
|
frs = imp;
|
1995-11-03 07:47:20 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
1996-02-02 11:09:18 +00:00
|
|
|
scn = ibp + imp;
|
|
|
|
frs = spp;
|
1995-11-03 07:47:20 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
1996-02-02 11:09:18 +00:00
|
|
|
scn = ibp;
|
|
|
|
frs = imp + spp;
|
1995-11-03 07:47:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
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
|
|
|
|
1996-02-07 11:51:14 +00:00
|
|
|
ts.add(data_rata(i), 0); // 0 - Data scadenza
|
1996-02-02 11:09:18 +00:00
|
|
|
if (in_valuta())
|
1995-11-03 07:47:20 +00:00
|
|
|
{
|
|
|
|
ts.add(tlit_rata(i).string(), 1); // 1 - Importo in lire
|
1996-02-02 11:09:18 +00:00
|
|
|
ts.add(tval_rata(i).string(), 2); // 2 - Importo in valuta
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1996-02-02 11:09:18 +00:00
|
|
|
ts.add(tlit_rata(i).string(), 1); // 1 - Importo
|
1995-11-03 07:47:20 +00:00
|
|
|
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 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
|
|
|
|
1996-02-02 11:09:18 +00:00
|
|
|
sf.enable_column(2, in_valuta());
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
1996-01-22 10:10:43 +00:00
|
|
|
// sf.enable_cell(0, 1, abilita); // importo
|
|
|
|
// sf.enable_cell(0, 2, abilita); // in valuta
|
|
|
|
// sf.enable_cell(0, 3, abilita); // percentuale
|
1996-07-08 10:06:09 +00:00
|
|
|
sf.force_update();
|
1995-11-03 07:47:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sf.enable_cell(0, 1, abilita); // percentuale
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-02-14 10:41:16 +00:00
|
|
|
TPagamento::TPagamento(const char* codtab, const char* data) :
|
|
|
|
_new(FALSE), _mcomm(FALSE), _imponlit(0.0), _imposlit(0.0),
|
1996-02-07 11:51:14 +00:00
|
|
|
_speselit(0.0), _cambio(1.0), _in_valuta(FALSE),
|
|
|
|
_code(codtab), _dirty(FALSE), _inited(FALSE),
|
1996-02-02 11:09:18 +00:00
|
|
|
_def_tpr(1), _def_ulc(""), _roundval(3), _int_rate(30), _tpr(0), _rdiff(FALSE),
|
|
|
|
_was_tpr4(FALSE), _roundlit(0), _imponval(0.0), _imposval(0.0), _speseval(0.0)
|
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())
|
1996-01-24 11:43:55 +00:00
|
|
|
_new = TRUE;
|
1995-12-29 11:06:12 +00:00
|
|
|
}
|