Corretta gestione importi e ritenute
git-svn-id: svn://10.65.10.50/trunk@2220 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
592b0ab7d2
commit
9885f6d317
@ -183,7 +183,7 @@ END
|
||||
DATE S_DATAPAG
|
||||
BEGIN
|
||||
PROMPT 2 11 "Data pag. "
|
||||
FIELD DATAPAG
|
||||
CHECKTYPE REQUIRED
|
||||
END
|
||||
|
||||
TEXT DLG_NULL
|
||||
|
@ -568,8 +568,8 @@ bool TPrimanota_application::cg_handler(TMask_field& f, KEY k)
|
||||
{
|
||||
const TString td(totdoc.string("."));
|
||||
const char* ss = valore.string(".");
|
||||
return f.error_box("Il totale documento inserito e' %s\n"
|
||||
"mentre i pagamenti ammontano a %s", (const char*)td, ss);
|
||||
return f.error_box("Il totale documento inserito e' %s mentre\n"
|
||||
"i pagamenti e le spese ammontano a %s", (const char*)td, ss);
|
||||
}
|
||||
}
|
||||
|
||||
@ -692,6 +692,16 @@ void TPrimanota_application::generazione_righe_cg(int r)
|
||||
}
|
||||
|
||||
|
||||
int TPrimanota_application::crea_somma_spese(TImporto& imp)
|
||||
{
|
||||
TConto cassa; causale().bill(2, cassa);
|
||||
const TString80 desc(causale().desc_agg(2));
|
||||
imp.swap_section(); imp.normalize();
|
||||
const int r = set_cgs_row(-1, imp, cassa, desc, 'L');
|
||||
cgs().force_update();
|
||||
return r;
|
||||
}
|
||||
|
||||
bool TPrimanota_application::cg_notify(TSheet_field& cg, int r, KEY k)
|
||||
{
|
||||
static TImporto old_spesa;
|
||||
@ -705,10 +715,10 @@ bool TPrimanota_application::cg_notify(TSheet_field& cg, int r, KEY k)
|
||||
case K_SPACE:
|
||||
if (tipo == 'G')
|
||||
old_spesa = row;
|
||||
break;
|
||||
break;
|
||||
case K_TAB:
|
||||
cg.sheet_mask().enable(DLG_DELREC, tipo <= ' ' || tipo == 'K' || tipo == 'G');
|
||||
cg.sheet_mask().enable(100, tipo == 'K');
|
||||
// cg.sheet_mask().enable(100, tipo == 'K');
|
||||
break;
|
||||
case K_DEL:
|
||||
if (tipo == 'G')
|
||||
@ -730,12 +740,7 @@ bool TPrimanota_application::cg_notify(TSheet_field& cg, int r, KEY k)
|
||||
{
|
||||
const int s = type2pos('L');
|
||||
if (s < 0)
|
||||
{
|
||||
TConto cassa; app().causale().bill(2, cassa);
|
||||
const TString desc(app().causale().desc_agg(2));
|
||||
growth.swap_section(); growth.normalize();
|
||||
app().set_cgs_row(s, growth, cassa, desc, 'L');
|
||||
}
|
||||
app().crea_somma_spese(growth);
|
||||
else
|
||||
app().sub_cgs_imp(s, growth);
|
||||
app().calcola_saldo();
|
||||
@ -775,6 +780,11 @@ bool TPrimanota_application::cg_notify(TSheet_field& cg, int r, KEY k)
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!imp.is_zero())
|
||||
app().crea_somma_spese(TImporto(sez, imp));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1722,7 +1732,7 @@ bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key)
|
||||
m.set(F_CODPAG, s, s.not_empty());
|
||||
}
|
||||
|
||||
if (app().is_saldaconto() && f.focusdirty())
|
||||
if (app().is_fattura() && f.focusdirty())
|
||||
{
|
||||
if (m.field(SK_VALUTA).active())
|
||||
{
|
||||
|
@ -120,6 +120,7 @@ class TPrimanota_application : public TRelation_application
|
||||
static bool pag_sheet_handler(TMask_field& f, KEY key);
|
||||
|
||||
void reset_sheet_row(TSheet_field& s, int n);
|
||||
int crea_somma_spese(TImporto& imp);
|
||||
|
||||
protected: // TApplication
|
||||
virtual void on_firm_change();
|
||||
|
102
cg/cg2105.cpp
102
cg/cg2105.cpp
@ -52,7 +52,9 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad,
|
||||
set(S_NUMDOC, fatt.get(PART_NUMDOC)); // Numero documento
|
||||
set(S_DATADOC, fatt.get(PART_DATADOC)); // Data documento
|
||||
set(S_NUMPROT, fatt.get(PART_PROTIVA)); // Protocollo IVA
|
||||
set(S_DESCR, sum.get(PART_DESCR)); // Descrizione documento
|
||||
|
||||
set(S_DESCR, sum.get(PART_DESCR)); // Descrizione documento
|
||||
set(S_DATAPAG, sum.get(PART_DATAPAG)); // Data pagamento
|
||||
|
||||
set(S_DATA_SCAD, scad.get(SCAD_DATASCAD)); // Data della scadenza
|
||||
set(S_SEZIONE_SCAD, scad.riga().sezione()); // Sezione della rata
|
||||
@ -94,7 +96,8 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad,
|
||||
|
||||
_pagabile += oldimp;
|
||||
|
||||
// Il flag di saldo/acconto e' attivo solo se non ci sono acconti
|
||||
// Il flag di saldo/acconto e' attivo solo se non ci sono acconti, cioe':
|
||||
// pagamento non assegnato o con data documento antecedente quella della fattura
|
||||
bool sa = oldpag.get_int(PAGSCA_NRIGA) != TPartita::UNASSIGNED;
|
||||
if (sa)
|
||||
{
|
||||
@ -104,7 +107,7 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad,
|
||||
}
|
||||
else
|
||||
{
|
||||
hide(S_RESIDUORATA);
|
||||
hide(S_RESIDUORATA); // Se non assegnato nascondi residuo rata
|
||||
}
|
||||
enable(S_SALDOACC, sa); // Mostra saldo solo se non e' un acconto
|
||||
|
||||
@ -207,6 +210,8 @@ class TGame_mask : public TMask
|
||||
TDate _datadoc;
|
||||
TString _codpag, _descr, _numdoc;
|
||||
|
||||
TDecoder _causali; // Decodificatore delle causali
|
||||
|
||||
protected:
|
||||
static bool annopart_handler(TMask_field& f, KEY k);
|
||||
static bool numpart_handler(TMask_field& f, KEY k);
|
||||
@ -217,7 +222,8 @@ protected:
|
||||
static bool nuovo_handler(TMask_field& f, KEY k);
|
||||
static bool cambio_handler(TMask_field& f, KEY k);
|
||||
|
||||
static void add_importo(TToken_string& s, const TImporto& i, bool val = FALSE, int pos = -1);
|
||||
void add_importo(TToken_string& s, const TImporto& i, bool val = FALSE, int pos = -1);
|
||||
void add_descrizione(TToken_string& s, const TRiga_partite& riga, int pos = -1);
|
||||
TImporto get_importo(TToken_string& s, int pos) const;
|
||||
|
||||
void fill_partite(int anno = 0, const char* numero = "");
|
||||
@ -252,8 +258,7 @@ public:
|
||||
|
||||
TGame_mask::TGame_mask(const TBill& bill, long numreg, int riga)
|
||||
: TMask("cg2100p"), _conto(bill), _numreg(numreg), _numrig(riga),
|
||||
_changed(FALSE)
|
||||
|
||||
_changed(FALSE), _causali(LF_CAUSALI, "CODCAUS", "DESCR")
|
||||
{
|
||||
const char tipocf[2] = { _conto.tipo(), '\0' };
|
||||
set(P_TIPOC, tipocf);
|
||||
@ -490,10 +495,10 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
|
||||
riga_fattura.add("");
|
||||
riga_fattura.add("");
|
||||
riga_fattura.add(riga.get(PART_DATADOC));
|
||||
riga_fattura.add(riga.get(PART_DESCR));
|
||||
add_importo(riga_fattura, TImporto(riga.sezione(), riga.get_real(SCAD_IMPORTO)));
|
||||
gm.add_descrizione(riga_fattura, riga);
|
||||
gm.add_importo(riga_fattura, TImporto(riga.sezione(), riga.get_real(SCAD_IMPORTO)));
|
||||
if (in_valuta)
|
||||
add_importo(riga_fattura, TImporto(riga.sezione(), riga.get_real(SCAD_IMPORTOVAL)), TRUE);
|
||||
gm.add_importo(riga_fattura, TImporto(riga.sezione(), riga.get_real(SCAD_IMPORTOVAL)), TRUE);
|
||||
else
|
||||
riga_fattura.add("");
|
||||
riga_fattura.add(riga.get(PART_NREG));
|
||||
@ -509,9 +514,9 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
|
||||
TToken_string& row = scadenze.row(scadenze.add(riga_fattura));
|
||||
row.add(ra, 1);
|
||||
row.add(scad.get(SCAD_DATASCAD), 2);
|
||||
add_importo(row, TImporto(riga.sezione(), scad.get_real(SCAD_IMPORTO)), FALSE, 5);
|
||||
gm.add_importo(row, TImporto(riga.sezione(), scad.get_real(SCAD_IMPORTO)), FALSE, 5);
|
||||
if (in_valuta)
|
||||
add_importo(row, TImporto(riga.sezione(), scad.get_real(SCAD_IMPORTOVAL)), TRUE, 6);
|
||||
gm.add_importo(row, TImporto(riga.sezione(), scad.get_real(SCAD_IMPORTOVAL)), TRUE, 6);
|
||||
|
||||
const int lastp = scad.last();
|
||||
for (int pa = scad.first(); pa <= lastp; pa = scad.succ(pa))
|
||||
@ -523,20 +528,19 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
|
||||
TToken_string& row = scadenze.row(scadenze.add(""));
|
||||
row.add(ri);
|
||||
row.add(ra);
|
||||
row.add(scad.get(SCAD_DATASCAD));
|
||||
row.add(sum.get(PART_DATAPAG));
|
||||
row.add(sum.get(PART_DATADOC));
|
||||
row.add(sum.get(PART_DESCR));
|
||||
|
||||
gm.add_descrizione(row, sum);
|
||||
TImporto imp(sez, pag.get_real(PAGSCA_IMPORTO));
|
||||
if (in_valuta)
|
||||
{
|
||||
add_importo(row, imp);
|
||||
add_importo(row, TImporto(sez, pag.get_real(PAGSCA_IMPORTOVAL)), 2);
|
||||
gm.add_importo(row, imp);
|
||||
gm.add_importo(row, TImporto(sez, pag.get_real(PAGSCA_IMPORTOVAL)), TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
imp.valore() += pag.get_real(PAGSCA_RITENUTE);
|
||||
add_importo(row, imp);
|
||||
gm.add_importo(row, imp);
|
||||
row.add("");
|
||||
}
|
||||
row.add(sum.get(PART_NREG));
|
||||
@ -553,12 +557,12 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
|
||||
rabb.add("Abbuoni rata ", 4); rabb << ra;
|
||||
if (in_valuta)
|
||||
{
|
||||
add_importo(rabb, scad.importo_pagato(FALSE, 0x2));
|
||||
add_importo(rabb, abb);
|
||||
gm.add_importo(rabb, scad.importo_pagato(FALSE, 0x2), FALSE);
|
||||
gm.add_importo(rabb, abb, TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
add_importo(rabb, abb, TRUE);
|
||||
gm.add_importo(rabb, abb, FALSE);
|
||||
rabb.add("");
|
||||
}
|
||||
}
|
||||
@ -570,7 +574,7 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
|
||||
{
|
||||
TToken_string& rdiff = scadenze.row(scadenze.add(""));
|
||||
rdiff.add("Differ. cambio rata ", 4); rdiff << ra;
|
||||
add_importo(rdiff, diff.normalize());
|
||||
gm.add_importo(rdiff, diff.normalize());
|
||||
}
|
||||
}
|
||||
|
||||
@ -578,16 +582,14 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
|
||||
rsal.add("Saldo rata ", 4); rsal << ra;
|
||||
if (!scad.chiusa())
|
||||
{
|
||||
TImporto sl(scad.residuo(FALSE, 0x7));
|
||||
sl.normalize();
|
||||
add_importo(rsal, sl);
|
||||
TImporto sl = scad.residuo(FALSE, 0x7);
|
||||
gm.add_importo(rsal, sl);
|
||||
tot_lit += sl;
|
||||
|
||||
if (in_valuta)
|
||||
{
|
||||
{
|
||||
sl = scad.residuo(TRUE, 0x3);
|
||||
sl.normalize();
|
||||
add_importo(rsal, sl, TRUE);
|
||||
gm.add_importo(rsal, sl, TRUE);
|
||||
tot_val += sl;
|
||||
}
|
||||
}
|
||||
@ -605,21 +607,21 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
|
||||
TToken_string& row = scadenze.row(scadenze.add(""));
|
||||
row.add(pag.get(PAGSCA_NRIGA));
|
||||
row.add(pag.get(PAGSCA_NRATA));
|
||||
row.add("");
|
||||
row.add(sum.get(PART_DATAPAG));
|
||||
row.add(sum.get(PART_DATADOC));
|
||||
row.add(sum.get(PART_DESCR));
|
||||
gm.add_descrizione(row, sum);
|
||||
TImporto i(sum.sezione(), pag.get_real(PAGSCA_IMPORTO));
|
||||
i.valore() += pag.get_real(PAGSCA_RITENUTE);
|
||||
i.normalize();
|
||||
add_importo(row, i);
|
||||
gm.add_importo(row, i);
|
||||
tot_lit += i;
|
||||
|
||||
const real& impval = pag.get_real(PAGSCA_IMPORTOVAL);
|
||||
if (!impval.is_zero())
|
||||
{
|
||||
i = TImporto(sum.sezione(), impval);
|
||||
i.set(sum.sezione(), impval);
|
||||
i.normalize();
|
||||
add_importo(row, i, TRUE);
|
||||
gm.add_importo(row, i, TRUE);
|
||||
tot_val += i;
|
||||
}
|
||||
else
|
||||
@ -635,8 +637,8 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
|
||||
{
|
||||
TToken_string& sp = scadenze.row(scadenze.add(""));
|
||||
sp.add("Saldo ", 4); sp << anno << ' ' << num;
|
||||
add_importo(sp, tot_lit.normalize());
|
||||
add_importo(sp, tot_val.normalize(), TRUE);
|
||||
gm.add_importo(sp, tot_lit.normalize());
|
||||
gm.add_importo(sp, tot_val.normalize(), TRUE);
|
||||
}
|
||||
|
||||
if (should_delete_game)
|
||||
@ -687,6 +689,7 @@ int TGame_mask::nuova_riga(TPartita& partita) const
|
||||
part.put(PART_DESCR, _descr);
|
||||
part.put(PART_NUMDOC, _numdoc);
|
||||
part.put(PART_DATADOC, _datadoc);
|
||||
part.put(PART_DATAPAG, _datadoc);
|
||||
part.put(PART_DATAREG, TDate(TODAY));
|
||||
part.put(PART_SEZ, _sezione);
|
||||
part.put(PART_SEZABB, _sezione);
|
||||
@ -709,6 +712,7 @@ int TGame_mask::nuova_riga(TPartita& partita) const
|
||||
part.put(PART_NUMDOC, cm.get(F_NUMDOC));
|
||||
part.put(PART_DATADOC, cm.get(F_DATADOC));
|
||||
part.put(PART_DATAREG, cm.get(F_DATAREG));
|
||||
part.put(PART_DATAPAG, cm.get(F_DATAREG));
|
||||
|
||||
// Copia dati causale corrente
|
||||
part.put(PART_CODCAUS, causale.codice());
|
||||
@ -792,7 +796,6 @@ int TGame_mask::nuovo_pagamento(TPartita& partita, int nriga, int rata) const
|
||||
pagamento.put(PAGSCA_CODABI, scad.get(SCAD_CODABI));
|
||||
pagamento.put(PAGSCA_CODCAB, scad.get(SCAD_CODCAB));
|
||||
pagamento.put(PAGSCA_CODAG, scad.get(SCAD_CODAG));
|
||||
pagamento.put(PAGSCA_DATAPAG, _datadoc);
|
||||
}
|
||||
|
||||
#ifndef __EXTRA__
|
||||
@ -914,7 +917,7 @@ bool TGame_mask::nuovo_handler(TMask_field& f, KEY k)
|
||||
gm._tipomov = app().causale().tipomov();
|
||||
new_game.set(P_NUOVO, gm._tipomov);
|
||||
new_game.set(P_SEZIONE, gm._importo.sezione());
|
||||
new_game.set(P_RESIDUO, gm._importo.valore());
|
||||
new_game.set(P_RESIDUO, gm.get(P_RESIDUO));
|
||||
new_game.set(P_DATADOC, cm.get(F_DATADOC));
|
||||
new_game.set(P_NUMDOC, cm.get(F_NUMDOC));
|
||||
new_game.set(P_DESCR, cm.get(F_DESCR));
|
||||
@ -943,11 +946,12 @@ bool TGame_mask::nuovo_handler(TMask_field& f, KEY k)
|
||||
if (k == K_ENTER)
|
||||
{
|
||||
TPartita& game = app().partite().partita(gm.conto(), anno, numero);
|
||||
if (game.ok())
|
||||
return error_box("La partita %d '%s' esiste gia'.", anno, (const char*)game.numero());
|
||||
|
||||
if (gm._tipomov > 1)
|
||||
{
|
||||
if (game.ok())
|
||||
return error_box("La partita %d '%s' esiste gia'.", anno, (const char*)game.numero());
|
||||
|
||||
const int nriga = TPartita::UNASSIGNED;
|
||||
const int nrata = TPartita::UNASSIGNED;
|
||||
const int nrigp = gm.nuovo_pagamento(game, nriga, nrata);
|
||||
@ -989,6 +993,22 @@ void TGame_mask::add_importo(TToken_string& s, const TImporto& i, bool valuta, i
|
||||
}
|
||||
}
|
||||
|
||||
void TGame_mask::add_descrizione(TToken_string& s, const TRiga_partite& riga, int pos)
|
||||
{
|
||||
const TString& desc = riga.get(PART_DESCR);
|
||||
if (desc.empty())
|
||||
{
|
||||
const TString& caus = riga.get(PART_CODCAUS);
|
||||
if (caus.not_empty())
|
||||
s.add(_causali.decode(caus), pos);
|
||||
else
|
||||
s.add("", pos);
|
||||
}
|
||||
else
|
||||
s.add(desc, pos);
|
||||
}
|
||||
|
||||
|
||||
TImporto TGame_mask::get_importo(TToken_string& s, int pos) const
|
||||
{
|
||||
const TFixed_string imp(s.get(pos));
|
||||
@ -1185,7 +1205,8 @@ bool TGame_mask::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) co
|
||||
m.set(S_DESCAGG, somma.get(PART_DESCR));
|
||||
|
||||
const bool nuovo = oldpag.get(PAGSCA_ACCSAL) != "S" &&
|
||||
oldpag.get_real(PAGSCA_IMPORTO).is_zero();
|
||||
oldpag.get_real(PAGSCA_IMPORTO).is_zero() &&
|
||||
oldpag.get_real(PAGSCA_RITENUTE).is_zero();
|
||||
|
||||
KEY key = m.run();
|
||||
|
||||
@ -1203,7 +1224,8 @@ bool TGame_mask::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) co
|
||||
}
|
||||
else
|
||||
{
|
||||
somma.put(PART_DESCR, m.get(S_DESCAGG)); // Aggiorna descrizione (comune ai pagamenti)
|
||||
somma.put(PART_DESCR, m.get(S_DESCAGG)); // Aggiorna descrizione (comune alla riga)
|
||||
somma.put(PART_DATAPAG, m.get(S_DATAPAG)); // Aggiorna data pagamento (comune alla riga)
|
||||
}
|
||||
TRectype newpag(oldpag);
|
||||
m.get_pag(newpag);
|
||||
|
@ -25,7 +25,7 @@ BEGIN
|
||||
PROMPT 31 1 "In valuta "
|
||||
PICTURE ".2"
|
||||
FLAGS "HU"
|
||||
VALIDATE REQIF_FUNC 1 FS_IMPONIBILI
|
||||
VALIDATE REQIF_FUNC 1 FS_VALUTA
|
||||
WARNING "Manca il totale documento in valuta"
|
||||
END
|
||||
|
||||
@ -104,7 +104,7 @@ BEGIN
|
||||
GROUP 3
|
||||
END
|
||||
|
||||
STRING FS_NAMEPAG 27
|
||||
STRING FS_NAMEPAG 50 27
|
||||
BEGIN
|
||||
PROMPT 36 3 "Pagamento "
|
||||
FLAGS "D"
|
||||
|
@ -47,7 +47,6 @@ const char* TPagamento::_rata_sfield(int n, int f) const
|
||||
|
||||
void TPagamento::set_inizio(const TDate& d)
|
||||
{
|
||||
bool dio;
|
||||
_inizio = d;
|
||||
// aggiusta _inizio secondo INSCAD; vedi mese commerciale etc.
|
||||
if (_inscad == 'M')
|
||||
@ -55,10 +54,17 @@ void TPagamento::set_inizio(const TDate& d)
|
||||
if (_mcomm) _inizio.set_day(_inizio.month() == 2 ? 28 : 30);
|
||||
else _inizio.set_end_month();
|
||||
}
|
||||
else if (_inscad == 'F' && _mcomm && _inizio.day() == 31)
|
||||
_inizio.set_day(30);
|
||||
else
|
||||
{
|
||||
if (_inscad == 'F' && _mcomm && _inizio.day() == 31)
|
||||
_inizio.set_day(30);
|
||||
}
|
||||
|
||||
TDate data(d); // Aggiusta data iniziale con i gironi prima rata
|
||||
next_scad(data, scad_rata(0), _mcomm, 0);
|
||||
|
||||
recalc_rate(0, FALSE, NULL, d.string(), NULL, NULL, _rdiff, _mcomm, dio);
|
||||
bool dummy;
|
||||
recalc_rate(0, FALSE, NULL, data.string(), NULL, NULL, _rdiff, _mcomm, dummy);
|
||||
}
|
||||
|
||||
void TPagamento::set_intervallo_rate(int in)
|
||||
@ -1505,7 +1511,7 @@ void TPagamento::adjust_fixed_scad()
|
||||
}
|
||||
|
||||
TPagamento::TPagamento(const char* codtab, const char* data) :
|
||||
_slicer(0.0,0), _new(FALSE), _imponibile(0.0), _imposta(0.0),
|
||||
_slicer(0.0,0), _new(FALSE), _mcomm(FALSE), _imponibile(0.0), _imposta(0.0),
|
||||
_spese(0.0), _cambio(1.0), _code(codtab), _dirty(FALSE), _inited(FALSE),
|
||||
_def_tpr(1), _def_ulc(""), _round(0), _int_rate(30), _tpr(0)
|
||||
{
|
||||
|
184
cg/saldacon.cpp
184
cg/saldacon.cpp
@ -1,5 +1,6 @@
|
||||
#include <config.h>
|
||||
#include <mask.h>
|
||||
#include <tabutil.h>
|
||||
|
||||
#include "saldacon.h"
|
||||
|
||||
@ -219,6 +220,39 @@ void TValuta::val2lit(TImporto& imp) const
|
||||
val2lit(imp.valore());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TDecoder
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
TDecoder::TDecoder(int num, const char* inf, const char* outf)
|
||||
: _file(new TLocalisamfile(num)), _if(inf), _of(outf)
|
||||
{ }
|
||||
|
||||
TDecoder::TDecoder(const char* tab)
|
||||
: _file(new TTable(tab)), _if("CODTAB"), _of("S0")
|
||||
{ }
|
||||
|
||||
TDecoder::~TDecoder()
|
||||
{
|
||||
delete _file;
|
||||
}
|
||||
|
||||
const TString& TDecoder::decode(const char* code)
|
||||
{
|
||||
TObject* obj = objptr(code);
|
||||
if (obj == NULL)
|
||||
{
|
||||
_file->setkey(1);
|
||||
_file->put(_if, code);
|
||||
const int err = _file->read();
|
||||
CHECKS(err == NOERR, "Can't decode ", code);
|
||||
obj = new TString(_file->get(_of));
|
||||
add(code, obj);
|
||||
}
|
||||
const TString& s = (const TString&)*obj;
|
||||
return s;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TRiga_scadenze
|
||||
///////////////////////////////////////////////////////////
|
||||
@ -257,7 +291,7 @@ bool TRiga_scadenze::chiusa(bool update) const
|
||||
bool chiusa;
|
||||
if (update)
|
||||
{
|
||||
TImporto imp(importo_da_pagare(TRUE));
|
||||
TImporto imp(importo(TRUE));
|
||||
imp += importo_pagato(TRUE);
|
||||
chiusa = imp.is_zero();
|
||||
((TRectype*)this)->put(SCAD_PAGATA, chiusa ? "X" : "");
|
||||
@ -312,12 +346,12 @@ TImporto TRiga_scadenze::importo_pagato(bool val, int mode) const
|
||||
}
|
||||
|
||||
// Calcola l'importo da pagare (eventualmente in valuta)
|
||||
TImporto TRiga_scadenze::importo_da_pagare(bool val) const
|
||||
{
|
||||
const char* imp_field = (val && in_valuta()) ? SCAD_IMPORTOVAL : SCAD_IMPORTO;
|
||||
TImporto TRiga_scadenze::importo(bool val) const
|
||||
{
|
||||
const TRiga_partite& fatt = riga(); // Riga fattura
|
||||
const TImporto totale(fatt.sezione(), get_real(imp_field));
|
||||
return totale;
|
||||
const char* const imp = val && in_valuta() ? SCAD_IMPORTOVAL : SCAD_IMPORTO;
|
||||
const TImporto i(fatt.sezione(), get_real(imp));
|
||||
return i;
|
||||
}
|
||||
|
||||
// Calcola l'abbuono in valuta della rata e ritorna il suo tipo:
|
||||
@ -333,7 +367,7 @@ char TRiga_scadenze::calcola_abbuono(int p, TImporto& abbuono, bool update)
|
||||
{
|
||||
if (pag.get_char(PAGSCA_ACCSAL) == 'S')
|
||||
{
|
||||
abbuono = importo_da_pagare(TRUE);
|
||||
abbuono = importo(TRUE);
|
||||
pag.zero(PAGSCA_ABBUONI);
|
||||
abbuono += importo_pagato(TRUE, 0x3); // Conta anche altri abbuoni
|
||||
abbuono.swap_section();
|
||||
@ -384,7 +418,7 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(int p, bool update)
|
||||
|
||||
if (update)
|
||||
{
|
||||
diffcam = importo_da_pagare(FALSE);
|
||||
diffcam = importo(FALSE);
|
||||
pag.zero(PAGSCA_DIFFCAM);
|
||||
diffcam += importo_pagato(FALSE); // Conta anche gli abbuoni e le altre diffcam
|
||||
diffcam.swap_section();
|
||||
@ -407,8 +441,9 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(int p, bool update)
|
||||
|
||||
TImporto TRiga_scadenze::residuo(bool val, int mode) const
|
||||
{
|
||||
TImporto residuo(importo_da_pagare(val));
|
||||
TImporto residuo(importo(val));
|
||||
residuo += importo_pagato(val, mode); // Somma con sezione opposta
|
||||
residuo.normalize();
|
||||
return residuo;
|
||||
}
|
||||
|
||||
@ -633,6 +668,56 @@ int TRiga_partite::rata_con_abbuoni_diffcam() const
|
||||
return found;
|
||||
}
|
||||
|
||||
// Calcola l'importo in lire o in valuta su di una riga di partita
|
||||
// E' possibile considerare o meno IMPORTO, ABBUONI e DIFFCAM
|
||||
TImporto TRiga_partite::importo(bool valuta, int mode) const
|
||||
{
|
||||
CHECKD(mode > 0 && mode < 8, "Bad importo mode ", mode);
|
||||
const bool in_lire = !in_valuta();
|
||||
if (valuta && in_lire)
|
||||
valuta = FALSE;
|
||||
|
||||
TImporto i;
|
||||
if (mode & 0x1)
|
||||
{
|
||||
const char* const field = valuta ? PART_IMPORTOVAL : PART_IMPORTO;
|
||||
i.set(sezione(), get_real(field));
|
||||
}
|
||||
|
||||
if (!is_fattura())
|
||||
{
|
||||
TImporto abbuoni(get_char(PART_SEZABB), get_real(PART_ABBUONI));
|
||||
if (valuta)
|
||||
{
|
||||
i += abbuoni;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (in_lire && (mode & 0x1))
|
||||
i.valore() += get_real(PART_RITENUTE);
|
||||
|
||||
if ((mode & 0x2) && !abbuoni.is_zero())
|
||||
{
|
||||
if (!in_lire)
|
||||
{
|
||||
const real cambio(get(PART_CAMBIO));
|
||||
abbuoni.valore() *= cambio;
|
||||
abbuoni.valore().round();
|
||||
}
|
||||
i += abbuoni;
|
||||
}
|
||||
|
||||
if (!in_lire && (mode & 0x4))
|
||||
{
|
||||
const TImporto diffcam(get_char(PART_SEZDIFCAM), get_real(PART_DIFFCAM));
|
||||
i += diffcam;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TPartita
|
||||
///////////////////////////////////////////////////////////
|
||||
@ -953,30 +1038,9 @@ TImporto TPartita::importo_speso(long nreg, int numrig) const
|
||||
|
||||
for (int r = last(); r > 0; r = pred(r))
|
||||
{
|
||||
const TRiga_partite& part = riga(r);
|
||||
if (nreg == part.get_long(PART_NREG) && numrig == part.get_int(PART_NUMRIG))
|
||||
{
|
||||
// Importo dei pagamenti
|
||||
imp += TImporto(part.sezione(), part.get_real(PART_IMPORTO));
|
||||
|
||||
// Abbuoni (in valuta)
|
||||
TImporto abbuoni(part.get_char(PART_SEZABB), part.get_real(PART_ABBUONI));
|
||||
const TValuta valuta(part);
|
||||
|
||||
if (valuta.in_lire())
|
||||
{
|
||||
// Se in lire ci possono essere le ritenute
|
||||
imp += TImporto(part.sezione(), part.get_real(PART_RITENUTE));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Se in valuta bisogna convertire in lire gli abbuoni ...
|
||||
valuta.val2lit(abbuoni);
|
||||
// ... e considerare le differenze cambio
|
||||
imp += TImporto(part.get_char(PART_SEZDIFCAM), part.get_real(PART_DIFFCAM));
|
||||
}
|
||||
imp += abbuoni;
|
||||
}
|
||||
const TRiga_partite& row = riga(r);
|
||||
if (nreg == row.get_long(PART_NREG) && numrig == row.get_int(PART_NUMRIG))
|
||||
imp += row.importo(FALSE); // Importo in lire
|
||||
}
|
||||
|
||||
return imp;
|
||||
@ -1060,12 +1124,9 @@ void TPartita::calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImp
|
||||
for (int r = last(); r > 0; r = pred(r))
|
||||
{
|
||||
const TRiga_partite& row = riga(r);
|
||||
const TImporto i(row.importo(FALSE, 0x1));
|
||||
|
||||
const int tipo = row.get_int(PART_TIPOMOV);
|
||||
|
||||
TImporto i(row.sezione(), row.get_real(PART_IMPORTO));
|
||||
if (tipo >= 3)
|
||||
i.valore() += row.get_real(PART_RITENUTE);
|
||||
|
||||
switch (tipo)
|
||||
{
|
||||
case 1:
|
||||
@ -1080,15 +1141,14 @@ void TPartita::calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImp
|
||||
break;
|
||||
}
|
||||
|
||||
TImporto abbuoni(row.get_char(PART_SEZABB), row.get_real(PART_ABBUONI));
|
||||
if (row.get(PART_CODVAL).not_empty())
|
||||
if (tipo >= 3)
|
||||
{
|
||||
abbuoni.valore() *= row.get_real(PART_CAMBIO);
|
||||
abbuoni.valore().round();
|
||||
}
|
||||
|
||||
imp += abbuoni;
|
||||
imp += TImporto(row.get_char(PART_SEZDIFCAM), row.get_real(PART_DIFFCAM));
|
||||
const TImporto abbuoni(row.importo(FALSE, 0x2));
|
||||
imp += abbuoni;
|
||||
|
||||
const TImporto diffcam(row.importo(FALSE, 0x4));
|
||||
imp += diffcam;
|
||||
}
|
||||
}
|
||||
|
||||
saldo = doc;
|
||||
@ -1101,6 +1161,31 @@ void TPartita::calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImp
|
||||
imp.normalize();
|
||||
}
|
||||
|
||||
TImporto TPartita::calcola_saldo(bool valuta) const
|
||||
{
|
||||
TImporto saldo;
|
||||
for (int r = last(); r > 0; r = pred(r))
|
||||
{
|
||||
const TRiga_partite& row = riga(r);
|
||||
saldo += row.importo(valuta);
|
||||
}
|
||||
return saldo;
|
||||
}
|
||||
|
||||
TImporto TPartita::calcola_saldo_al(const TDate& al, bool valuta) const
|
||||
{
|
||||
TImporto saldo;
|
||||
for (int r = last(); r > 0; r = pred(r))
|
||||
{
|
||||
const TRiga_partite& row = riga(r);
|
||||
const TDate data = row.get(row.is_fattura() ? PART_DATADOC : PART_DATAPAG);
|
||||
if (data < al)
|
||||
saldo += row.importo(valuta);
|
||||
}
|
||||
return saldo;
|
||||
}
|
||||
|
||||
|
||||
// Controlla se esistono pagamenti riferiti alla riga nrigp
|
||||
bool TPartita::utilizzata(int nrigp) const
|
||||
{
|
||||
@ -1184,9 +1269,7 @@ bool TPartita::chiusa(bool update)
|
||||
|
||||
if (update)
|
||||
{
|
||||
TImporto saldo, doc, pag, imp;
|
||||
calcola_saldo(saldo, doc, pag, imp);
|
||||
|
||||
const TImporto saldo = calcola_saldo(TRUE); // Saldo in valuta
|
||||
const bool ora_chiusa = saldo.is_zero();
|
||||
if (chiusa != ora_chiusa)
|
||||
{
|
||||
@ -1276,7 +1359,8 @@ void TPartita::sposta_riga(int r, TPartita& part)
|
||||
npg = part.pagamento(r, i, nrigp);
|
||||
CHECK(npg.get_char(PAGSCA_ACCSAL) != 'S', "Can't add to soldered payment");
|
||||
somma(pag, npg, PART_IMPORTO);
|
||||
somma(pag, npg, PART_IMPORTOVAL);
|
||||
somma(pag, npg, PART_IMPORTOVAL);
|
||||
somma(pag, npg, PART_RITENUTE);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -99,10 +99,25 @@ public:
|
||||
TValuta(const TRectype& rec) { get(rec); }
|
||||
TValuta(const TMask& m, short v, short d, short c) { get(m, v, d, c); }
|
||||
virtual ~TValuta() {}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TDecoder
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class TDecoder : private TAssoc_array
|
||||
{
|
||||
TLocalisamfile* _file;
|
||||
TString _if, _of;
|
||||
|
||||
public:
|
||||
const TString& decode(const char* code);
|
||||
|
||||
TDecoder(int num, const char* inf, const char* outf);
|
||||
TDecoder(const char* table);
|
||||
virtual ~TDecoder();
|
||||
};
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Riga scadenza
|
||||
///////////////////////////////////////////////////////////
|
||||
@ -135,7 +150,7 @@ public:
|
||||
TRiga_partite& riga() const { return *_riga; } // Riga partite
|
||||
|
||||
TImporto importo_pagato(bool val, int mode = 0x7) const;
|
||||
TImporto importo_da_pagare(bool val) const;
|
||||
TImporto importo(bool val) const;
|
||||
TImporto residuo(bool val, int mode = 0x7) const; // Differenza delle due funzioni precedenti
|
||||
|
||||
TRiga_scadenze(TRiga_partite* riga);
|
||||
@ -172,6 +187,8 @@ public:
|
||||
int rata_con_abbuoni_diffcam() const;
|
||||
|
||||
char sezione() const { return get_char(PART_SEZ); }
|
||||
TImporto importo(bool valuta, int mode = 0x7) const;
|
||||
|
||||
bool in_valuta() const { return get(PART_CODVAL).not_empty(); }
|
||||
|
||||
bool update(const TRectype& vec, const TRectype& nuo, const char* field);
|
||||
@ -253,6 +270,8 @@ public:
|
||||
TImporto importo_speso(long numreg, int numrig) const;
|
||||
void update_reg(long nreg, const TRectype& mov);
|
||||
void calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImporto& imp) const;
|
||||
TImporto calcola_saldo(bool valuta) const;
|
||||
TImporto calcola_saldo_al(const TDate& al, bool valuta) const;
|
||||
|
||||
bool modifica_pagamento(const TRectype& new_pag, const TValuta& valuta,
|
||||
char& old_ap, TImporto& old_abb, TImporto& old_diffcam,
|
||||
|
Loading…
x
Reference in New Issue
Block a user