Arrotondamento cambio e aggiustamento per coerenza con totale doc in lire
git-svn-id: svn://10.65.10.50/trunk@2461 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
3538c1072f
commit
c0c3decdd2
@ -259,7 +259,7 @@ bool TPrimanota_application::pag_sheet_handler(TMask_field& f, KEY key)
|
||||
const TString is(imp.string("."));
|
||||
const TString ts(totlit.string("."));
|
||||
ok = error_box("Il totale in lire delle rate e' %s mentre\n"
|
||||
"il totale del documento e' %s.", (const char *)ts, (const char *)is);
|
||||
"il totale del documento e' %s.", (const char *)is, (const char *)ts);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -595,11 +595,13 @@ void TPrimanota_application::set_totale_pagamento()
|
||||
const TMask& m = curr_mask();
|
||||
TPagamento& pag = pagamento();
|
||||
pag.set_cambio(m.get_real(SK_CAMBIO));
|
||||
real implit;
|
||||
|
||||
if (pag.in_valuta())
|
||||
{
|
||||
imposta = m.get_real(F_IMPOSTE) / pag.cambio(); imposta.round(3);
|
||||
imponibile = m.get_real(SK_TOTDOCVAL) - imposta;
|
||||
implit = m.get_real(F_TOTALE);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -608,6 +610,7 @@ void TPrimanota_application::set_totale_pagamento()
|
||||
}
|
||||
|
||||
pag.set_total(imponibile, imposta, spese);
|
||||
pag.set_implit(implit);
|
||||
}
|
||||
|
||||
void TPrimanota_application::set_scadenze(TMask& m)
|
||||
|
@ -347,6 +347,7 @@ void TPagamento::set_numero_rate(int n, int sscad, int rdiff)
|
||||
|
||||
void TPagamento::set_cambio(const real& cambio)
|
||||
{
|
||||
const int first = _tpr < 4 ? 0 : 1;
|
||||
const bool era_valuta = _cambio != 1.0;
|
||||
|
||||
if (cambio.sign() <= 0)
|
||||
@ -360,14 +361,14 @@ void TPagamento::set_cambio(const real& cambio)
|
||||
real imp; // Importo di parcheggio
|
||||
|
||||
if (era_valuta)
|
||||
{
|
||||
{
|
||||
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);
|
||||
row.add(imp.string(), 7);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -388,7 +389,7 @@ void TPagamento::set_cambio(const real& cambio)
|
||||
else
|
||||
{
|
||||
if (in_valuta)
|
||||
{
|
||||
{
|
||||
for (int i = _rate.items()-1; i >= 0; i--)
|
||||
{
|
||||
TToken_string& row = (TToken_string&)_rate[i];
|
||||
@ -397,15 +398,36 @@ void TPagamento::set_cambio(const real& cambio)
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (in_valuta) adjust_importo_lire();
|
||||
}
|
||||
|
||||
void TPagamento::set_implit(const real & r)
|
||||
{
|
||||
_implit = r;
|
||||
}
|
||||
|
||||
void TPagamento::adjust_importo_lire()
|
||||
{
|
||||
if (_cambio == 1.0) return;
|
||||
const int first = _tpr < 4 ? 0 : 1;
|
||||
real totlit;
|
||||
for (int i = 0; i < n_rate(); i++)
|
||||
totlit += tlit_rata(i);
|
||||
real residuo = _implit - totlit;
|
||||
if (!residuo.is_zero())
|
||||
{
|
||||
real rs = tlit_rata(first) + residuo;
|
||||
rata(first).add(rs.string(), 7);
|
||||
}
|
||||
}
|
||||
|
||||
void TPagamento::next_scad(TDate& d, int scad, bool mcomm, int rata)
|
||||
{
|
||||
if (mcomm)
|
||||
@ -1269,7 +1291,7 @@ void TPagamento::adjust_perc(int rdiff)
|
||||
for (int j = first; j < _rate.items(); j++)
|
||||
{
|
||||
real rvl = tpay_rata(j);
|
||||
// togli pezxo di troppo
|
||||
// togli pezzo di troppo
|
||||
if (j == first && _tpr > 0 && _tpr < 4)
|
||||
rvl -= _secndr;
|
||||
real zpx = (rvl * 100.0)/other; // percentuale
|
||||
@ -1280,8 +1302,7 @@ void TPagamento::adjust_perc(int rdiff)
|
||||
real implit(tpay_rata(j));
|
||||
implit *= _cambio;
|
||||
implit.round();
|
||||
TToken_string& tr = rata(j);
|
||||
|
||||
TToken_string& tr = rata(j);
|
||||
tr.add(implit.string(), 7);
|
||||
}
|
||||
}
|
||||
@ -1300,7 +1321,6 @@ void TPagamento::adjust_perc_imp(bool is_perc, int rdiff)
|
||||
TDistrib dt(toshare, _round);
|
||||
const int first = _tpr > 3 ? 1 : 0;
|
||||
|
||||
// for (int j = first; j < _rate.items(); j++)
|
||||
for (int j = _rate.items() - 1; j >= first ; j--)
|
||||
{
|
||||
real rvl = perc_rata(j);
|
||||
@ -1309,8 +1329,7 @@ void TPagamento::adjust_perc_imp(bool is_perc, int rdiff)
|
||||
dt.add(zpx); // * cento???
|
||||
}
|
||||
|
||||
// for (j = first; j < n_rate(); j++)
|
||||
real rem(toshare);
|
||||
real rem(toshare);
|
||||
|
||||
for (j = n_rate() - 1; j >= first ; j--)
|
||||
{
|
||||
@ -1323,17 +1342,7 @@ void TPagamento::adjust_perc_imp(bool is_perc, int rdiff)
|
||||
if (j == first)
|
||||
{
|
||||
rfirst = rvl;
|
||||
// if (rdiff == 2 && !rem.is_zero())
|
||||
if (!rem.is_zero())
|
||||
{
|
||||
// real reminder = toshare - rfirst;
|
||||
// real rdiv = reminder.is_zero() ? real(0.0) :
|
||||
// (reminder / real(_rate.items() - (1+first)));
|
||||
// rdiv.round(_round);
|
||||
// rfirst += reminder - (rdiv * real(_rate.items() - (1+first)));
|
||||
// rvl = rdiv;
|
||||
rfirst += rem;
|
||||
}
|
||||
if (!rem.is_zero()) rfirst += rem;
|
||||
}
|
||||
|
||||
if (j == first && _tpr > 0 && _tpr < 4)
|
||||
@ -1346,9 +1355,9 @@ void TPagamento::adjust_perc_imp(bool is_perc, int rdiff)
|
||||
real implit(tpay_rata(j));
|
||||
implit *= _cambio;
|
||||
implit.round();
|
||||
tr.add(implit.string(), 7);
|
||||
tr.add(implit.string(), 7);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TPagamento::read(TTable* t, TTable* r)
|
||||
@ -1624,6 +1633,7 @@ void TPagamento::set_sheet(TSheet_field& sf, int sscad)
|
||||
if (_inited)
|
||||
{
|
||||
const bool in_valuta = _cambio != 1.0;
|
||||
if (in_valuta) adjust_importo_lire();
|
||||
|
||||
// si istanzia uno sheet di primanota
|
||||
for (int i = 0; i < n_rate(); i++)
|
||||
|
@ -35,6 +35,7 @@ class TPagamento : public TObject
|
||||
real _imposta; // imposta da affettare
|
||||
real _spese; // spese da affettare
|
||||
real _cambio; // cambio valuta
|
||||
real _implit; // imponibile in lire
|
||||
TDistrib _slicer; // affettatrice
|
||||
bool _new; // non letto da database
|
||||
TString_array _rate; // rate medesime
|
||||
@ -75,8 +76,9 @@ protected:
|
||||
// riaggiusta le percentuali o gli importi rispetto al dato modificato
|
||||
void adjust_perc_imp(bool is_perc, int rdiff);
|
||||
// riaggiusta le percentuali rispetto al dato modificato
|
||||
void TPagamento::adjust_perc(int rdiff);
|
||||
|
||||
void adjust_perc(int rdiff);
|
||||
// riaggiusta l'importo in lire per consistenza con il totale documento in lire
|
||||
void adjust_importo_lire();
|
||||
// controlla il segno di un valore in base a _tpr e row
|
||||
bool sign_ok(const real& val, int row) const;
|
||||
|
||||
@ -176,6 +178,8 @@ public:
|
||||
void set_imprata(int i, const real& r);
|
||||
// setta l'importo in lire di una rata
|
||||
void set_implit(int i, const real & r);
|
||||
// setta l'imponibile in lire totale
|
||||
void set_implit(const real & r);
|
||||
|
||||
// slicer interface
|
||||
void set_total(const real& ib, const real& im, const real& sp);
|
||||
|
Loading…
x
Reference in New Issue
Block a user