Pagament object
git-svn-id: svn://10.65.10.50/trunk@1691 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
b926f9d727
commit
34b33afa1e
234
cg/pagament.cpp
234
cg/pagament.cpp
@ -73,7 +73,7 @@ void TPagamento::set_rate_differenziate(int v)
|
||||
if (v == 2 && (100 % n_rate()) == 0)
|
||||
{
|
||||
int p = 100 / n_rate();
|
||||
for (int i = _tpr == 0 ? 0 : 1; i < n_rate(); i++)
|
||||
for (int i = _tpr < 4 ? 0 : 1; i < n_rate(); i++)
|
||||
{
|
||||
TToken_string& tt = rata(i);
|
||||
tt.add(p,1);
|
||||
@ -88,7 +88,7 @@ void TPagamento::set_tipo_prima_rata(int v, int sscad)
|
||||
_dirty = FALSE;
|
||||
if (_tpr == v) return;
|
||||
|
||||
if (v == 0 && _tpr > 0)
|
||||
if (v < 4 && _tpr > 3)
|
||||
{
|
||||
for (int i = n_rate() - 1; i > 0; i--)
|
||||
{
|
||||
@ -100,7 +100,7 @@ void TPagamento::set_tipo_prima_rata(int v, int sscad)
|
||||
_rate.add(NULL,0);
|
||||
_rate.pack();
|
||||
}
|
||||
else if ( _tpr == 0 && v > 0)
|
||||
else if ( _tpr < 4 && v > 3)
|
||||
{
|
||||
TToken_string* ttn = new TToken_string(32);
|
||||
ttn->add(0,0);
|
||||
@ -127,14 +127,28 @@ void TPagamento::set_numero_rate(int n, int sscad)
|
||||
_dirty = FALSE;
|
||||
if (n == 0 || n == n_rate()) return;
|
||||
|
||||
int p = 100 / n;
|
||||
real p = real(100) / real(n);
|
||||
p.round(2);
|
||||
int nr = n_rate();
|
||||
int first = _tpr == 0 ? 0 : 1;
|
||||
int first = _tpr < 4 ? 0 : 1;
|
||||
real sum = 0.0;
|
||||
|
||||
for (int i = first, sum = 0; sum < 100; i++)
|
||||
for (int i = first; sum < real(100.0); i++)
|
||||
{
|
||||
if ((100 - sum) < p) p = 100 - sum;
|
||||
sum += p;
|
||||
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;
|
||||
}
|
||||
|
||||
set_rata(i, real(p),
|
||||
i == 0 ? (i < nr ? scad_rata(0) : 0):
|
||||
@ -142,7 +156,7 @@ void TPagamento::set_numero_rate(int n, int sscad)
|
||||
(i < nr ? tipo_rata(i) : tipo_rata(nr-1)));
|
||||
}
|
||||
// erase remaining
|
||||
for (; i < n_rate(); i++)
|
||||
for (; i < nr; i++)
|
||||
_rate.add(NULL,i);
|
||||
_rate.pack();
|
||||
|
||||
@ -183,10 +197,63 @@ void TPagamento::next_scad(TDate& d, int scad, bool mcomm, int rata)
|
||||
else
|
||||
{
|
||||
d += scad;
|
||||
}
|
||||
|
||||
// riaggiusta la minchia se ci sono scadenze fissate
|
||||
if (_fixd[0] != 0 || _fixd[1] != 0 || _fixd[2] != 0)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if (_fixd[i] > d.day())
|
||||
{
|
||||
if (d.last_day(d.month(), d.year()) <= _fixd[i])
|
||||
d.set_day(_fixd[i]);
|
||||
else d.set_end_month();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == 3)
|
||||
{
|
||||
if (_fixd[0] > 0 && _fixd[0] < d.day())
|
||||
{
|
||||
d.set_day(_fixd[0]);
|
||||
d.set_month(d.month() == 12 ? 1 : d.month() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
// non fa nessun ricalcolo, si limita ad impacchettare se
|
||||
@ -196,7 +263,7 @@ void TPagamento::remove_rata(int i)
|
||||
_dirty = TRUE;
|
||||
}
|
||||
|
||||
TToken_string& TPagamento::add_rata(real perc, int day, int type)
|
||||
TToken_string& TPagamento::add_rata(real perc, int day, int type, const char* ulc)
|
||||
{
|
||||
TToken_string* tt = new TToken_string(16);
|
||||
tt->add(day); // scadenza
|
||||
@ -204,7 +271,7 @@ TToken_string& TPagamento::add_rata(real perc, int day, int type)
|
||||
tt->add(type); // tipo
|
||||
tt->add("");
|
||||
tt->add("");
|
||||
tt->add("");
|
||||
tt->add(ulc);
|
||||
_rate.add(tt);
|
||||
_dirty = TRUE;
|
||||
return *tt;
|
||||
@ -265,8 +332,8 @@ TToken_string& TPagamento::set_rata(int index, const real& howmuch,
|
||||
|
||||
TDate oldd = index > 0 ? data_rata(index -1) : _inizio;
|
||||
int day = date - oldd;
|
||||
real toshare(_tpr == 0 ? _firstr : _secndr);
|
||||
real perc = (_tpr > 0 && index == 0) ? ZERO : howmuch/toshare;
|
||||
real toshare(_tpr < 4 ? _firstr : _secndr);
|
||||
real perc = (_tpr > 3 && index == 0) ? ZERO : howmuch/toshare;
|
||||
perc *= real(100.0);
|
||||
perc.round(2);
|
||||
|
||||
@ -301,8 +368,8 @@ word TPagamento::validate() const
|
||||
word res = 0x0000;
|
||||
real r(0.0);
|
||||
|
||||
int first = _tpr == 0 ? 0 : 1;
|
||||
real toshare(_tpr == 0 ? _firstr : _secndr);
|
||||
int first = _tpr < 4 ? 0 : 1;
|
||||
real toshare(_tpr < 4 ? _firstr : _secndr);
|
||||
TDistrib ds(toshare,0);
|
||||
|
||||
// check percentages & prepare slicer
|
||||
@ -362,7 +429,7 @@ const char* TPagamento::desc_tpr() const
|
||||
const char* o;
|
||||
switch (_tpr)
|
||||
{
|
||||
case 0: o = "Totale su tutte le rate"; break;
|
||||
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;
|
||||
@ -378,14 +445,16 @@ const char* TPagamento::desc_tipo(int i) const
|
||||
const char* o;
|
||||
switch (i)
|
||||
{
|
||||
case 1: o = "Rimessa diretta o contanti"; break;
|
||||
case 2: o = "Tratta"; break;
|
||||
case 3: o = "Ricevuta bancaria"; break;
|
||||
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 = "Altro pagamento"; break;
|
||||
case 1: o = "Rimessa diretta o contanti"; break;
|
||||
case 2: o = "Tratta"; break;
|
||||
case 3: o = "Ricevuta bancaria"; break;
|
||||
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 interbancari diretti"; break;
|
||||
case 9: o = "Bonifici"; break;
|
||||
case 10: o = "Altro pagamento"; break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
@ -411,7 +480,7 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified,
|
||||
int oldtype = tipo_rata(0);
|
||||
int oldscad = scad_rata(0);
|
||||
TDate lastdate = data_rata(0);
|
||||
int first = _tpr == 0 ? 0 : 1;
|
||||
int first = _tpr < 4 ? 0 : 1;
|
||||
TArray srate(_rate); // rate come erano
|
||||
|
||||
|
||||
@ -428,7 +497,7 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified,
|
||||
if (new_value != NULL)
|
||||
{
|
||||
newv = new_value;
|
||||
rmax = is_perc_modified? (real) 100.0 : (_tpr == 0 ? _firstr : _secndr);
|
||||
rmax = is_perc_modified? (real) 100.0 : (_tpr < 4 ? _firstr : _secndr);
|
||||
if (newv > rmax) return P_RSUM;
|
||||
}
|
||||
|
||||
@ -644,7 +713,7 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified,
|
||||
// ricalcola il valore secondario (non modificato)
|
||||
real toshare(100.0);
|
||||
if (is_perc_modified)
|
||||
toshare = (_tpr == 0 ? _firstr : _secndr);
|
||||
toshare = (_tpr < 4 ? _firstr : _secndr);
|
||||
TDistrib dt(toshare,0);
|
||||
|
||||
for (int j = first; j < _rate.items(); j++)
|
||||
@ -664,31 +733,29 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified,
|
||||
need_recalc = TRUE;
|
||||
return P_OK;
|
||||
} // new_value != NULL
|
||||
|
||||
|
||||
}
|
||||
else // i != row modified
|
||||
{
|
||||
if (i > 0 && !((perc_rata(i-1) == perc_rata(i))))
|
||||
{
|
||||
if (rdiff == 2) rdiff = 1;
|
||||
_rdiff = FALSE;
|
||||
}
|
||||
if (is_perc_modified)
|
||||
rsum += perc_rata(i);
|
||||
else
|
||||
rsum += tpay_rata(i);
|
||||
if (i > 0 && !((perc_rata(i-1) == perc_rata(i))))
|
||||
{
|
||||
if (rdiff == 2) rdiff = 1;
|
||||
_rdiff = FALSE;
|
||||
}
|
||||
if (is_perc_modified)
|
||||
rsum += perc_rata(i);
|
||||
else
|
||||
rsum += tpay_rata(i);
|
||||
|
||||
lastdate = data_rata(i);
|
||||
oldtype = tipo_rata(i);
|
||||
oldscad = scad_rata(i);
|
||||
if (_inited && i > 0)
|
||||
{
|
||||
if (data_rata(i) <= data_rata(i-1))
|
||||
return P_SCAD;
|
||||
}
|
||||
else if (lastdate < _inizio)
|
||||
return P_INIZIO;
|
||||
if (_inited && i > 0)
|
||||
{
|
||||
if (data_rata(i) <= data_rata(i-1))
|
||||
return P_SCAD;
|
||||
}
|
||||
else if (lastdate < _inizio)
|
||||
return P_INIZIO;
|
||||
}
|
||||
}
|
||||
|
||||
@ -709,12 +776,15 @@ bool TPagamento::read(TTable* t, TTable* r)
|
||||
if (t->read() != NOERR) return FALSE;
|
||||
|
||||
// set everything
|
||||
_rdiff = t->get_bool("B1");
|
||||
_mcomm = t->get_bool("B0");
|
||||
_tpr = *((const char*)(t->get("S3")));
|
||||
_inscad = *((const char*)(t->get("S1")));
|
||||
_code = t->get("CODTAB");
|
||||
_name = t->get("S0");
|
||||
_rdiff = t->get_bool("B1");
|
||||
_mcomm = t->get_bool("B0");
|
||||
_tpr = *((const char*)(t->get("S3")));
|
||||
_inscad = *((const char*)(t->get("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");
|
||||
|
||||
// TBI aggiusta _inizio secondo INSCAD; vedi mese commerciale etc.
|
||||
if (_inscad == 'M')
|
||||
@ -828,7 +898,7 @@ void TPagamento::set_rate_auto()
|
||||
|
||||
real toslice = _firstr;
|
||||
|
||||
if (n_rate() == 0 || !_inited || (_tpr > 0 && n_rate() == 1)) return;
|
||||
if (n_rate() == 0 || !_inited || (_tpr > 3 && n_rate() == 1)) return;
|
||||
if (_tpr > 1) // ripartisci _firstr su tutte le rate
|
||||
{
|
||||
first = 1;
|
||||
@ -837,7 +907,7 @@ void TPagamento::set_rate_auto()
|
||||
|
||||
_slicer.init(toslice);
|
||||
|
||||
if (_tpr > 0)
|
||||
if (_tpr > 3)
|
||||
// prima rata obbligatoria
|
||||
set_imprata(0, _firstr);
|
||||
|
||||
@ -903,44 +973,44 @@ void TPagamento::set_total(const real& imponibile, const real& imposta, const re
|
||||
|
||||
void TPagamento::set_sheet(TSheet_field& sf, int sscad)
|
||||
{
|
||||
sf.reset();
|
||||
sf.destroy(-1);
|
||||
if (_inited && _rate.items() > 0)
|
||||
{
|
||||
// si istanzia uno sheet di primanota
|
||||
for (int i = 0; i < n_rate(); i++)
|
||||
{
|
||||
TToken_string& ts = sf.row(-1);
|
||||
// istanzia, o stronzo
|
||||
ts.add((const char*)data_rata(i));
|
||||
ts.add(perc_rata(i).string());
|
||||
ts.add(tpay_rata(i).string());
|
||||
ts.add(tipo_rata(i));
|
||||
ts.add(desc_tipo(tipo_rata(i)));
|
||||
if (ratapagata(i))
|
||||
{
|
||||
sf.disable_cell(1,1); // percentuale
|
||||
sf.disable_cell(1,2); // importo
|
||||
{
|
||||
TToken_string& ts = sf.row(-1);
|
||||
// istanzia, o stronzo
|
||||
ts.add((const char*)data_rata(i));
|
||||
ts.add(perc_rata(i).string());
|
||||
ts.add(tpay_rata(i).string());
|
||||
ts.add(tipo_rata(i));
|
||||
ts.add(desc_tipo(tipo_rata(i)));
|
||||
if (ratapagata(i))
|
||||
{
|
||||
sf.disable_cell(1,1); // percentuale
|
||||
sf.disable_cell(1,2); // importo
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (_rate.items() > 0) // not inited: set edit sheet
|
||||
{
|
||||
for (int i = 0, scr = 0; i < n_rate(); i++)
|
||||
{
|
||||
TToken_string& s = sf.row(-1);
|
||||
scr += scad_rata(i);
|
||||
s.add(scr);
|
||||
s.add(perc_rata(i).string());
|
||||
s.add(tipo_rata(i));
|
||||
s.add(desc_tipo(tipo_rata(i)));
|
||||
s.add(ulc_rata(i));
|
||||
}
|
||||
{
|
||||
TToken_string& s = sf.row(-1);
|
||||
scr += scad_rata(i);
|
||||
s.add(scr);
|
||||
s.add(perc_rata(i).string());
|
||||
s.add(tipo_rata(i));
|
||||
s.add(desc_tipo(tipo_rata(i)));
|
||||
s.add(ulc_rata(i));
|
||||
}
|
||||
}
|
||||
else // new: set with 1 or 2 rates according to tpr
|
||||
{
|
||||
if (_tpr > 0)
|
||||
add_rata(ZERO, sscad == -1 ? 0 : sscad, 1);
|
||||
add_rata(real(100.0), sscad == -1 ? (_tpr == 0 ? 0 :30) : sscad, 1);
|
||||
if (_tpr > 3)
|
||||
add_rata(ZERO, sscad == -1 ? 0 : sscad, _def_tpr, _def_ulc);
|
||||
add_rata(real(100.0), sscad == -1 ? (_tpr < 4 ? 0 : 30) : sscad, _def_tpr, _def_ulc);
|
||||
|
||||
_dirty = TRUE;
|
||||
|
||||
@ -955,7 +1025,7 @@ void TPagamento::set_sheet(TSheet_field& sf, int sscad)
|
||||
s.add(ulc_rata(i));
|
||||
}
|
||||
}
|
||||
if (_tpr > 0)
|
||||
if (_tpr > 3)
|
||||
{
|
||||
// disabilita campi da non toccare sulla prima rata
|
||||
if (_inited)
|
||||
@ -973,8 +1043,10 @@ void TPagamento::set_sheet(TSheet_field& sf, int sscad)
|
||||
|
||||
TPagamento::TPagamento(const char* codtab, const char* data) :
|
||||
_slicer(0.0,0), _new(FALSE), _imponibile(0.0), _imposta(0.0),
|
||||
_spese(0.0), _code(codtab), _dirty(FALSE), _inited(FALSE)
|
||||
_spese(0.0), _code(codtab), _dirty(FALSE), _inited(FALSE),
|
||||
_def_tpr(1), _def_ulc("")
|
||||
{
|
||||
_fixd[0] = _fixd[1] = _fixd[2] = 0;
|
||||
if (data != NULL)
|
||||
_inizio = data;
|
||||
if (_code.blank() || !read())
|
||||
|
@ -48,11 +48,16 @@ class TPagamento : public TObject
|
||||
real _firstr; // importo da pagare in prima rata (o distribuire se tpr == 0)
|
||||
real _secndr; // importo da distribuire
|
||||
|
||||
int _fixd[3]; // giorni scadenza fissa, se desiderati
|
||||
|
||||
int _rata_ifield(int n, int f) const;
|
||||
real _rata_rfield(int n, int f) const;
|
||||
TDate _rata_dfield(int n, int f) const;
|
||||
const char* _rata_sfield(int n, int f) const;
|
||||
|
||||
int _def_tpr; // tipo rata default
|
||||
TString16 _def_ulc; // ulteriore classificazione default
|
||||
|
||||
public:
|
||||
|
||||
// pregasi notare la straordinaria dovizia di const
|
||||
@ -83,6 +88,9 @@ public:
|
||||
const char* desc_tpr() const;
|
||||
const char* desc_tipo(int) const;
|
||||
|
||||
// giorni scadenza fissi, aggiunti poi
|
||||
void set_fixed_scad(int a, int ind) { _fixd[ind] = a; }
|
||||
|
||||
// queste vengono usate solo per movimenti editabili nella struttura
|
||||
// (da tabella pagamenti) e riaggiustano tutte le rate in accordo
|
||||
// con il parametro modificato
|
||||
@ -110,13 +118,18 @@ public:
|
||||
|
||||
// modifica rate manualmente o non
|
||||
TToken_string& rata(int r) { return (TToken_string&)_rate[r]; }
|
||||
TToken_string& add_rata (real perc, int day, int type);
|
||||
TToken_string& add_rata (real perc, int day, int type, const char* ulc = "");
|
||||
TToken_string& set_rata (int index, real perc, int day, int type,
|
||||
const char* ulc = NULL, const char* imp = NULL,
|
||||
const char* data = NULL);
|
||||
// questa calcola percentuali e scadenze a partire dagli importi
|
||||
TToken_string& set_rata (int index, const real& howmuch, const TDate& date, int type,
|
||||
const char* ulc, bool pagato);
|
||||
const char* ulc, bool pagato);
|
||||
|
||||
// settano tipo rata e ult. class default per le rate; se bool = TRUE
|
||||
// modificano anche le eventuali rate esistenti
|
||||
void set_default_type(int type, bool change_existing = TRUE);
|
||||
void set_default_ulc(const char* ulc, bool change_existing = TRUE);
|
||||
|
||||
void remove_rata(int r);
|
||||
void zap_rate () { _rate.destroy(); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user