Gestione saldaconto: corretto segno acconti e differenza cambio
git-svn-id: svn://10.65.10.50/trunk@1737 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
bfbdd47c8e
commit
5e8580ea89
@ -96,51 +96,6 @@ real TPrimanota_application::totale_documento()
|
||||
}
|
||||
|
||||
|
||||
bool TPrimanota_application::showpartite_handler(TMask_field& f, KEY k)
|
||||
{
|
||||
bool ok = TRUE;
|
||||
TMask& m = f.mask();
|
||||
|
||||
if (m.get(116) == "K")
|
||||
{
|
||||
TSheet_field& s = *m.get_sheet();
|
||||
const int riga = s.selected();
|
||||
if (k == K_SPACE)
|
||||
{
|
||||
const bool dirty = app().edit_partite(riga);
|
||||
if (dirty)
|
||||
{
|
||||
if (m.field(103).enabled())
|
||||
app().disable_cgs_cells(riga, 'K');
|
||||
k = K_ENTER;
|
||||
}
|
||||
}
|
||||
|
||||
if (k == K_ENTER)
|
||||
{
|
||||
const int currig = riga+1;
|
||||
const long curreg = app().curr_mask().get_long(F_NUMREG);
|
||||
TImporto importo;
|
||||
const TString& imp = m.get(101);
|
||||
if (imp.not_empty())
|
||||
importo.set('D', real(imp));
|
||||
else
|
||||
importo.set('A', real(m.get(102)));
|
||||
|
||||
const TImporto speso(app()._partite.importo_speso(curreg, currig));
|
||||
|
||||
if (importo != speso)
|
||||
{
|
||||
ok = yesno_box("L'importo della riga %d dovrebbe essere %c %s\n"
|
||||
"Si desidera correggerlo?", currig, speso.sezione(), speso.valore().string("."));
|
||||
if (ok) app().set_cgs_imp(riga, speso);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
// Determina se un codice sospeso o no
|
||||
// Certified 99%
|
||||
bool TPrimanota_application::suspended_handler(TMask_field& f, KEY k)
|
||||
@ -309,8 +264,22 @@ void TPrimanota_application::set_cgs_imp(int n, const TImporto& imp)
|
||||
// Certified 100%
|
||||
TImporto TPrimanota_application::get_cgs_imp(int n)
|
||||
{
|
||||
TSheet_field& s = cgs();
|
||||
|
||||
TImporto importo;
|
||||
importo = cgs().row(n);
|
||||
|
||||
const TMask& m = s.sheet_mask();
|
||||
if (m.is_running() && s.selected() == n)
|
||||
{
|
||||
const TString& imp = m.get(101);
|
||||
if (imp.not_empty())
|
||||
importo.set('D', real(imp));
|
||||
else
|
||||
importo.set('A', real(m.get(102)));
|
||||
}
|
||||
else
|
||||
importo = s.row(n);
|
||||
|
||||
return importo;
|
||||
}
|
||||
|
||||
@ -574,7 +543,7 @@ bool TPrimanota_application::cg_handler(TMask_field& f, KEY k)
|
||||
{
|
||||
const long numreg = f.mask().get_long(F_NUMREG);
|
||||
const int currig = i+1;
|
||||
const TImporto speso = app().partite().importo_speso(numreg, currig);
|
||||
const TImporto speso = app().partite().importo_speso(numreg, currig, TRUE);
|
||||
if (importo != speso)
|
||||
{
|
||||
bool ok = yesno_box("L'importo della riga %d dovrebbe essere %c %s\n"
|
||||
|
@ -197,7 +197,6 @@ protected:
|
||||
void add_cgs_tot(TMask& m);
|
||||
int set_cgs_row(int n, const TImporto& importo, TBill& conto, const char* desc, char tipo);
|
||||
void set_cgs_imp(int n, const TImporto& importo);
|
||||
TImporto get_cgs_imp(int n);
|
||||
bool add_cgs_imp(int n, const TImporto& importo);
|
||||
bool sub_cgs_imp(int n, const TImporto& importo);
|
||||
void disable_cgs_cells(int n, char tipo);
|
||||
@ -221,7 +220,7 @@ protected:
|
||||
bool notify_cgline_deletion(TPartita& partita, long nreg, int numrig);
|
||||
bool notify_cgline_deletion(int numrig);
|
||||
|
||||
bool notify_edit_pagamento(TPartita& partita, TRectype& new_pag);
|
||||
bool notify_edit_pagamento(TPartita& partita, TRectype& new_pag, int deleting = -1);
|
||||
|
||||
long calcola_m770(int tipo_coll, real& spese, real& compenso, real& iva, real& ritfis);
|
||||
bool link_m770();
|
||||
@ -235,6 +234,7 @@ public:
|
||||
TSheet_field& ivas() const;
|
||||
TSheet_field& pags() const;
|
||||
TString_array& pag_rows() { return _pag_rows; }
|
||||
TImporto get_cgs_imp(int n);
|
||||
|
||||
TPrimanota_application();
|
||||
};
|
||||
|
177
cg/cg2105.cpp
177
cg/cg2105.cpp
@ -27,6 +27,8 @@ protected:
|
||||
|
||||
void add_importo(TToken_string& s, const TImporto& i) const;
|
||||
void fill_partite(bool all) const;
|
||||
real aggiorna_residuo();
|
||||
void update_partita(const TPartita& game, int prow, bool all) const;
|
||||
|
||||
public:
|
||||
TSheet_field& partite() const { return (TSheet_field&)field(P_PARTITE); }
|
||||
@ -54,11 +56,13 @@ TGame_mask::TGame_mask(const TBill& bill)
|
||||
|
||||
partite().set_notify(partite_notify);
|
||||
scadenze().sheet_mask().set_handler(100, edit_scadenza_handler);
|
||||
|
||||
aggiorna_residuo();
|
||||
}
|
||||
|
||||
bool TGame_mask::annopart_handler(TMask_field& f, KEY k)
|
||||
{
|
||||
if (k == K_TAB && f.dirty() && f.get().not_empty())
|
||||
if (k == K_TAB && f.focusdirty() && f.get().not_empty())
|
||||
{
|
||||
TMask_field& n = f.mask().field(P_NUMERO);
|
||||
n.set_dirty();
|
||||
@ -119,6 +123,20 @@ bool TGame_mask::scambio_handler(TMask_field& f, KEY k)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
real TGame_mask::aggiorna_residuo()
|
||||
{
|
||||
const TMask& cm = app().curr_mask();
|
||||
const long cur_reg = cm.get_long(F_NUMREG);
|
||||
const int rmov = app().cgs().selected();
|
||||
|
||||
TImporto residuo(app().get_cgs_imp(rmov));
|
||||
residuo -= app().partite().importo_speso(cur_reg, rmov+1, TRUE);
|
||||
|
||||
set(P_RESIDUO, residuo.valore().string());
|
||||
|
||||
return residuo.valore();
|
||||
}
|
||||
|
||||
bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
|
||||
{
|
||||
if (k == K_TAB)
|
||||
@ -161,12 +179,11 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
|
||||
row.add(riga.get(PART_NUMDOC));
|
||||
row.add(riga.get(PART_PROTIVA));
|
||||
|
||||
const TRecord_array& ap = scad.rows_array();
|
||||
const int lastp = ap.last_row();
|
||||
for (int pa = ap.first_row(); pa <= lastp; pa = ap.succ_row(pa))
|
||||
const int lastp = scad.last();
|
||||
for (int pa = scad.first(); pa <= lastp; pa = scad.succ(pa))
|
||||
{
|
||||
const TRiga_partite& rigp = game->riga(pa);
|
||||
const TRectype& pag = ap.row(pa);
|
||||
const TRectype& pag = scad.row(pa);
|
||||
|
||||
TToken_string& row = scadenze.row(-1);
|
||||
row.add(ri);
|
||||
@ -230,7 +247,11 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k)
|
||||
const bool dirty = app().edit_pagamento(game, nriga, nrata, nrigp);
|
||||
|
||||
if (dirty)
|
||||
{
|
||||
gm.update_partita(game, gm._riga_partite, TRUE);
|
||||
partite_notify(gm.partite(), gm._riga_partite, K_TAB);
|
||||
gm.aggiorna_residuo();
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@ -247,6 +268,31 @@ void TGame_mask::add_importo(TToken_string& s, const TImporto& i) const
|
||||
}
|
||||
}
|
||||
|
||||
void TGame_mask::update_partita(const TPartita& game, int prow, bool all) const
|
||||
{
|
||||
TImporto saldo, doc, pag, imp;
|
||||
game.calcola_saldo(saldo, doc, pag, imp);
|
||||
|
||||
if (all || !saldo.is_zero())
|
||||
{
|
||||
int riga_fatt = game.prima_fattura();
|
||||
if (riga_fatt < 1) riga_fatt = game.first(); // E' un anticipo
|
||||
const TRiga_partite& riga = game.riga(riga_fatt);
|
||||
|
||||
TToken_string &r = partite().row(prow); // Stringa di lavoro per lo sheet
|
||||
r.cut(0);
|
||||
r.add(riga.get(PART_ANNO));
|
||||
r.add(riga.get(PART_NUMPART));
|
||||
r.add(riga.get(PART_DATADOC));
|
||||
r.add(riga.get(PART_NUMDOC));
|
||||
add_importo(r, saldo);
|
||||
add_importo(r, doc);
|
||||
add_importo(r, pag);
|
||||
add_importo(r, imp);
|
||||
r.add(riga.get(PART_DESCR));
|
||||
}
|
||||
}
|
||||
|
||||
void TGame_mask::fill_partite(bool all) const
|
||||
{
|
||||
TString_array& a = partite().rows_array();
|
||||
@ -282,30 +328,7 @@ void TGame_mask::fill_partite(bool all) const
|
||||
should_delete_game = TRUE;
|
||||
}
|
||||
|
||||
TImporto saldo, doc, pag, imp;
|
||||
game->calcola_saldo(saldo, doc, pag, imp);
|
||||
|
||||
if (all || !saldo.is_zero())
|
||||
{
|
||||
int riga_fatt = game->prima_fattura();
|
||||
if (riga_fatt < 1) riga_fatt = game->first(); // E' un anticipo
|
||||
|
||||
const TRiga_partite& riga = game->riga(riga_fatt);
|
||||
const TString16 data_doc = riga.get(PART_DATADOC);
|
||||
const TString16 num_doc = riga.get(PART_NUMDOC);
|
||||
const char*descr = riga.get(PART_DESCR);
|
||||
|
||||
TToken_string &r = partite().row(-1); // Stringa di lavoro per lo sheet
|
||||
r.add(anno);
|
||||
r.add(num);
|
||||
r.add(data_doc);
|
||||
r.add(num_doc);
|
||||
add_importo(r, saldo);
|
||||
add_importo(r, doc);
|
||||
add_importo(r, pag);
|
||||
add_importo(r, imp);
|
||||
r.add(descr);
|
||||
}
|
||||
update_partita(*game, -1, all);
|
||||
|
||||
if (should_delete_game)
|
||||
delete game;
|
||||
@ -328,6 +351,44 @@ void TGame_mask::fill_partite(bool all) const
|
||||
// Metodi di prima nota
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
bool TPrimanota_application::showpartite_handler(TMask_field& f, KEY k)
|
||||
{
|
||||
bool ok = TRUE;
|
||||
TMask& m = f.mask();
|
||||
|
||||
if (m.get(116) == "K")
|
||||
{
|
||||
TSheet_field& s = *m.get_sheet();
|
||||
const int riga = s.selected();
|
||||
if (k == K_SPACE)
|
||||
{
|
||||
const bool dirty = app().edit_partite(riga);
|
||||
if (dirty)
|
||||
{
|
||||
if (m.field(103).enabled())
|
||||
app().disable_cgs_cells(riga, 'K');
|
||||
k = K_ENTER;
|
||||
}
|
||||
}
|
||||
|
||||
if (k == K_ENTER)
|
||||
{
|
||||
const long curreg = app().curr_mask().get_long(F_NUMREG);
|
||||
const TImporto importo(app().get_cgs_imp(riga));
|
||||
const TImporto speso(app().partite().importo_speso(curreg, riga+1, TRUE));
|
||||
|
||||
if (importo != speso)
|
||||
{
|
||||
ok = yesno_box("L'importo della riga %d dovrebbe essere %c %s\n"
|
||||
"Si desidera correggerlo?", riga+1, speso.sezione(), speso.valore().string("."));
|
||||
if (ok) app().set_cgs_imp(riga, speso);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool TPrimanota_application::edit_partite(int riga)
|
||||
{
|
||||
TToken_string& cgr = cgs().row(riga);
|
||||
@ -367,8 +428,10 @@ int TPrimanota_application::nuovo_pagamento(TPartita& partita, int nriga, int ra
|
||||
part.put(PART_DATADOC, curr_mask().get(F_DATADOC));
|
||||
part.put(PART_NUMDOC, curr_mask().get(F_NUMDOC));
|
||||
part.put(PART_DESCR, curr_mask().get(F_DESCR));
|
||||
part.put(PART_CAMBIO, curr_mask().get(S_CAMBIO));
|
||||
part.put(PART_DATACAM, curr_mask().get(S_DATACAMBIO));
|
||||
|
||||
part.put(PART_CODVAL, riga_part.get(PART_CODVAL)); // Meglio prendere il cambio dalle scadenze
|
||||
part.put(PART_CAMBIO, riga_part.get(PART_CAMBIO)); // piuttosto che dal cangiante mondo delle
|
||||
part.put(PART_DATACAM, riga_part.get(PART_DATACAM)); // maschere interattive
|
||||
|
||||
// Copia dati causale corrente
|
||||
const int tipomov = causale().tipomov();
|
||||
@ -395,9 +458,11 @@ int TPrimanota_application::nuovo_pagamento(TPartita& partita, int nriga, int ra
|
||||
sezione = (sezione == 'D') ? 'A' : 'D'; // scambia segno
|
||||
}
|
||||
part.put(PART_SEZ, sezione); // Memorizza solo la sezione (importi nulli)
|
||||
part.put(PART_SEZABB, sezione);
|
||||
part.put(PART_SEZDIFCAM, sezione);
|
||||
}
|
||||
|
||||
TRectype& pagamento = riga_scad.row(nrigp, TRUE); // Crea nuovo pagamento
|
||||
TRectype& pagamento = riga_scad.new_row(nrigp); // Crea nuovo pagamento
|
||||
|
||||
int caus = 2; // Calcola riga causale per la contropartita in base al tipo pagamento
|
||||
switch (riga_scad.get_int(SCAD_TIPOPAG))
|
||||
@ -425,6 +490,7 @@ int TPrimanota_application::nuovo_pagamento(TPartita& partita, int nriga, int ra
|
||||
causale().bill(caus = 1, contro); // ... prende il primo
|
||||
contro.put(pagamento, TRUE); // Scrive conto contropartita
|
||||
|
||||
// Da regalare a Ferdinando
|
||||
if (conto.tipo() > ' ') // Se cliente o fornitore cerca sua banca
|
||||
{
|
||||
TRelation cliforel(LF_CLIFO);
|
||||
@ -440,6 +506,12 @@ int TPrimanota_application::nuovo_pagamento(TPartita& partita, int nriga, int ra
|
||||
pagamento.put(PAGSCA_CODCAB, clifo.get(CLI_CODCAB));
|
||||
pagamento.put(PAGSCA_CODAG, cliforel.lfile(LF_CFVEN).get(CLI_CODAG));
|
||||
}
|
||||
|
||||
/* Prossima implementazione
|
||||
pagamento.put(PAGSCA_CODABI, riga_scad.get(SCAD_CODABI));
|
||||
pagamento.put(PAGSCA_CODCAB, riga_scad.get(SCAD_CODCAB));
|
||||
pagamento.put(PAGSCA_CODAG, riga_scad.get(SCAD_CODAG));
|
||||
*/
|
||||
pagamento.put(PAGSCA_CODABIPR, riga_scad.get(SCAD_CODABIPR));
|
||||
pagamento.put(PAGSCA_CODCABPR, riga_scad.get(SCAD_CODCABPR));
|
||||
|
||||
@ -468,7 +540,9 @@ HIDDEN bool importo_handler(TMask_field& f, KEY k)
|
||||
}
|
||||
|
||||
|
||||
bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pag)
|
||||
bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pag, int deleting)
|
||||
{
|
||||
if (deleting != 0)
|
||||
{
|
||||
const int nriga = new_pag.get_int(PAGSCA_NRIGA); // Riga fattura
|
||||
const TRiga_partite& parbas = p.riga(nriga);
|
||||
@ -511,6 +585,7 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Aggiornamento ritenute
|
||||
const real old_ritenute(old_pag.get(PAGSCA_RITENUTE));
|
||||
const real new_ritenute(new_pag.get(PAGSCA_RITENUTE));
|
||||
@ -529,6 +604,7 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa
|
||||
if (empty) reset_cgs_row(riga);
|
||||
}
|
||||
}
|
||||
} // if (deleting != 0)
|
||||
|
||||
char old_ap, new_ap;
|
||||
TImporto old_abbuono, new_abbuono, old_diffcam, new_diffcam;
|
||||
@ -536,6 +612,8 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa
|
||||
old_ap, old_abbuono, old_diffcam,
|
||||
new_ap, new_abbuono, new_diffcam);
|
||||
|
||||
if (deleting != 0)
|
||||
{
|
||||
const int riga_contabile = app().cgs().selected();
|
||||
|
||||
// Se c'e' differenza negli abbuoni
|
||||
@ -549,9 +627,12 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa
|
||||
if (empty && new_ap != old_ap)
|
||||
reset_cgs_row(riga_abb);
|
||||
|
||||
if (deleting != riga_contabile)
|
||||
{
|
||||
// Sottrae l'abbuono con la sezione invertita dalla riga contabile
|
||||
add_cgs_imp(riga_contabile, old_abbuono);
|
||||
}
|
||||
}
|
||||
if (new_ap != ' ') // Se ci sono abbuoni
|
||||
{
|
||||
const riga_abb = type2pos(new_ap);
|
||||
@ -563,7 +644,11 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa
|
||||
else
|
||||
add_cgs_imp(riga_abb, new_abbuono);
|
||||
|
||||
sub_cgs_imp(riga_contabile, new_abbuono); // Aggiunge l'abbuono con la sezione invertita
|
||||
if (deleting != riga_contabile)
|
||||
{
|
||||
// Aggiunge l'abbuono con la sezione invertita
|
||||
sub_cgs_imp(riga_contabile, new_abbuono);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -583,8 +668,14 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa
|
||||
const bool empty = add_cgs_imp(riga_diffcam, grow_diffcam);
|
||||
if (empty) reset_cgs_row(riga_diffcam);
|
||||
}
|
||||
sub_cgs_imp(riga_contabile, grow_diffcam); // Aggiunge la differenza con la sezione invertita
|
||||
|
||||
if (deleting != riga_contabile)
|
||||
{
|
||||
// Aggiunge la differenza con la sezione invertita
|
||||
sub_cgs_imp(riga_contabile, grow_diffcam);
|
||||
}
|
||||
}
|
||||
} // if (deleting != 0)
|
||||
|
||||
return empty;
|
||||
}
|
||||
@ -619,7 +710,7 @@ bool TPrimanota_application::edit_pagamento(TPartita& p, int nriga, int nrata, i
|
||||
// Dati della scadenza che ha generato la partita
|
||||
TReal_field& residuo = (TReal_field&)m.field(S_RESIDUO);
|
||||
residuo.set_decimals(in_valuta ? 2 : 0);
|
||||
residuo.set(scaden.residuo().string()); // Residuo da pagare
|
||||
residuo.set(scaden.residuo(TRUE).string()); // Residuo da pagare
|
||||
m.set(S_DATASCAD, scaden.get(SCAD_DATASCAD)); // Data della scadenza
|
||||
m.set(S_SEZIONE_SCAD, parbas.get(PART_SEZ)); // Sezione della rata
|
||||
m.set(S_RATA, scaden.get(SCAD_NRATA));
|
||||
@ -648,13 +739,16 @@ bool TPrimanota_application::edit_pagamento(TPartita& p, int nriga, int nrata, i
|
||||
return key != K_ESC;
|
||||
}
|
||||
|
||||
|
||||
// Scorre tutte le righe della partita ed azzera i pagamenti relativi a alla riga contabile
|
||||
// cancellata e decrementa i numeri riga superiori a numrig
|
||||
bool TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg, int numrig)
|
||||
{
|
||||
bool found = FALSE;
|
||||
|
||||
for (int p = partita.last(); p > 0; p = partita.pred(p))
|
||||
{
|
||||
const TRiga_partite& part = partita.riga(p);
|
||||
TRiga_partite& part = partita.riga(p);
|
||||
if (part.get_int(PART_TIPOMOV) == 1)
|
||||
{
|
||||
for (int r = part.rate(); r > 0; r--)
|
||||
@ -670,12 +764,17 @@ bool TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg
|
||||
pag.zero(PAGSCA_IMPORTO);
|
||||
pag.zero(PAGSCA_IMPORTOVAL);
|
||||
pag.zero(PAGSCA_RITENUTE);
|
||||
notify_edit_pagamento(partita, pag);
|
||||
notify_edit_pagamento(partita, pag, numrig);
|
||||
found = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (numrig > 0 && part.get_long(PART_NREG) == nreg && part.get_int(PART_NUMRIG) > numrig)
|
||||
part.put(PART_NUMRIG, numrig-1);
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
@ -685,7 +784,7 @@ bool TPrimanota_application::notify_cgline_deletion(int numrig)
|
||||
{
|
||||
bool found = FALSE;
|
||||
const long nreg = curr_mask().get_long(F_NUMREG);
|
||||
_partite.add_reg_num(nreg, 0);
|
||||
_partite.add_reg_num(nreg, 0); // Carica tutte le partite interessate
|
||||
|
||||
for (TPartita* game = _partite.first(); game; game = _partite.next())
|
||||
found |= notify_cgline_deletion(*game, nreg, numrig);
|
||||
|
201
cg/saldacon.cpp
201
cg/saldacon.cpp
@ -124,38 +124,35 @@ TPartita& TRiga_scadenze::partita() const
|
||||
return riga().partita();
|
||||
}
|
||||
|
||||
|
||||
// Controlla se la rata e' in valuta
|
||||
// Controlla se la fattura della rata e' in valuta
|
||||
bool TRiga_scadenze::in_valuta() const
|
||||
{
|
||||
return get(SCAD_CODVAL).not_empty();
|
||||
return riga().get(PART_CODVAL).not_empty();
|
||||
}
|
||||
|
||||
// Controlla se la rata e' stata completamente pagata
|
||||
int TRiga_scadenze::pagata() const
|
||||
{
|
||||
const TRecord_array& a = rows_array();
|
||||
for (int p = a.last_row(); p > 0; p = a.pred_row(p))
|
||||
for (int p = last(); p > 0; p = pred(p))
|
||||
{
|
||||
const TRectype& pag = a.row(p);
|
||||
const TRectype& pag = row(p);
|
||||
if (pag.get_char("ACCSAL") == 'S')
|
||||
return p;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
// Calcola il totale dei pagamenti (eventualmente in valuta)
|
||||
TImporto TRiga_scadenze::importo_pagato(bool val) const
|
||||
{
|
||||
const char* imp_field = val && in_valuta() ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
||||
const TPartita& game = partita();
|
||||
const char* imp_field = in_valuta() && val ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
||||
TImporto totale;
|
||||
const TRecord_array& a = rows_array();
|
||||
for (int p = a.last_row(); p > 0; p = a.pred_row(p))
|
||||
for (int p = last(); p > 0; p = pred(p))
|
||||
{
|
||||
const TRectype& pag = a.row(p); // Riga pagamento
|
||||
const TRectype& pag = row(p); // Riga pagamento
|
||||
const TRiga_partite& sum = game.riga(p); // Riga partite
|
||||
const TImporto imp(sum.get_char(PART_SEZ), pag.get_real(imp_field));
|
||||
const TImporto imp(sum.sezione(), pag.get_real(imp_field));
|
||||
totale += imp;
|
||||
}
|
||||
|
||||
@ -165,9 +162,9 @@ TImporto TRiga_scadenze::importo_pagato(bool val) const
|
||||
// Calcola l'importo da pagare (eventualmente in valuta)
|
||||
TImporto TRiga_scadenze::importo_da_pagare(bool val) const
|
||||
{
|
||||
const char* imp_field = in_valuta() && val ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
||||
const char* imp_field = val && in_valuta() ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
||||
const TRiga_partite& r = riga(); // Riga fattura
|
||||
const TImporto totale(r.get_char(PART_SEZ), get_real(imp_field));
|
||||
const TImporto totale(r.sezione(), get_real(imp_field));
|
||||
return totale;
|
||||
}
|
||||
|
||||
@ -193,7 +190,7 @@ char TRiga_scadenze::calcola_abbuono(TImporto& abbuono, bool val) const
|
||||
|
||||
if (val && in_valuta())
|
||||
{
|
||||
abbuono.valore() *= get_real(SCAD_CAMBIO);
|
||||
abbuono.valore() *= riga().get_real(PART_CAMBIO);
|
||||
abbuono.valore().round();
|
||||
}
|
||||
}
|
||||
@ -213,7 +210,7 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(bool update)
|
||||
const int riga_saldo = pagata();
|
||||
if (riga_saldo > 0)
|
||||
{
|
||||
TRectype& pag = row(riga_saldo, FALSE);
|
||||
TRectype& pag = row(riga_saldo);
|
||||
const TRiga_partite& sum = partita().riga(riga_saldo);
|
||||
const char sez = sum.sezione();
|
||||
|
||||
@ -225,7 +222,7 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(bool update)
|
||||
real a = pag.get_real(PAGSCA_ABBUONI);
|
||||
if (in_valuta())
|
||||
{
|
||||
a *= get_real(SCAD_CAMBIO);
|
||||
a *= riga().get_real(PART_CAMBIO);
|
||||
a.round();
|
||||
}
|
||||
|
||||
@ -244,7 +241,7 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(bool update)
|
||||
{
|
||||
for (int p = last(); p > 0; p = pred(p))
|
||||
{
|
||||
TRectype& pag = row(p, FALSE);
|
||||
TRectype& pag = row(p);
|
||||
pag.zero(PAGSCA_DIFFCAM);
|
||||
}
|
||||
}
|
||||
@ -253,13 +250,11 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(bool update)
|
||||
return diffcam;
|
||||
}
|
||||
|
||||
real TRiga_scadenze::residuo() const
|
||||
real TRiga_scadenze::residuo(bool val) const
|
||||
{
|
||||
const char* imp_field = get(SCAD_CODVAL).not_empty() ? SCAD_IMPORTOVAL : SCAD_IMPORTO;
|
||||
const real da_pagare(get(imp_field));
|
||||
const real pagato(get(SCAD_IMPORTOPAG));
|
||||
const real residuo = da_pagare - pagato;
|
||||
return residuo;
|
||||
TImporto residuo(importo_da_pagare(val));
|
||||
residuo -= importo_pagato(val);
|
||||
return residuo.valore();
|
||||
}
|
||||
|
||||
|
||||
@ -271,47 +266,57 @@ bool TRiga_scadenze::modifica_pagamento(const TRectype& new_pag,
|
||||
const TRectype old_pag(row(nrigp));
|
||||
TRiga_partite& sum = partita().riga(nrigp);
|
||||
|
||||
old_ap = calcola_abbuono(old_abb, FALSE);
|
||||
TImporto old_abbuono;
|
||||
old_ap = calcola_abbuono(old_abbuono, TRUE); // Vecchio abbuono in valuta
|
||||
old_abb = old_abbuono; // Vecchio abbuono in lire
|
||||
if (in_valuta())
|
||||
{
|
||||
old_abb.valore() *= riga().get_real(PART_CAMBIO);
|
||||
old_abb.valore().round();
|
||||
}
|
||||
|
||||
old_diffcam = calcola_differenza_cambio(FALSE);
|
||||
|
||||
const char* imp_field = get(SCAD_CODVAL).not_empty() ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
||||
const char* imp_field = in_valuta() ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
||||
const real importo(new_pag.get(imp_field));
|
||||
const bool empty = importo.is_zero();
|
||||
if (empty)
|
||||
rows_array().destroy_row(nrigp);
|
||||
else
|
||||
row(nrigp, FALSE) = new_pag;
|
||||
row(nrigp) = new_pag;
|
||||
|
||||
TImporto abbuono;
|
||||
new_ap = calcola_abbuono(abbuono, TRUE); // Calcolo abbuono in valuta
|
||||
TImporto new_abbuono;
|
||||
new_ap = calcola_abbuono(new_abbuono, TRUE); // Calcolo abbuono in valuta
|
||||
|
||||
TImporto imp(abbuono); imp.swap_section();
|
||||
imp.normalize(sum.sezione());
|
||||
new_abb = new_abbuono; // Calcola nuovo abbuono in lire
|
||||
if (in_valuta())
|
||||
{
|
||||
new_abb.valore() *= riga().get_real(PART_CAMBIO);
|
||||
new_abb.valore().round();
|
||||
}
|
||||
|
||||
// Scambia sezione per registrazione contabile
|
||||
old_abbuono.swap_section();
|
||||
new_abbuono.swap_section();
|
||||
new_abbuono.normalize(sum.sezione());
|
||||
if (new_ap != ' ')
|
||||
{
|
||||
CHECK(nrigp == pagata(), "Aggiornamento abbuoni inconsistente");
|
||||
TRectype& pag = row(nrigp, FALSE);
|
||||
pag.put(PAGSCA_ABBUONI, imp.valore());
|
||||
|
||||
new_abb = abbuono;
|
||||
if (in_valuta())
|
||||
{
|
||||
new_abb.valore() *= get_real(SCAD_CAMBIO);
|
||||
new_abb.valore().round();
|
||||
TRectype& pag = row(nrigp);
|
||||
pag.put(PAGSCA_ABBUONI, new_abbuono.valore());
|
||||
}
|
||||
}
|
||||
else
|
||||
new_abb.valore() = ZERO;
|
||||
|
||||
sum.update(old_abb, new_abb, PART_SEZABB, PART_ABBUONI);
|
||||
sum.update(old_abbuono, new_abbuono, PART_SEZABB, PART_ABBUONI);
|
||||
|
||||
new_diffcam = calcola_differenza_cambio(TRUE);
|
||||
sum.update(old_diffcam, new_diffcam, PART_SEZDIFCAM, PART_DIFFCAM);
|
||||
// Memorizza differenza cambi invertita, mettendo new_diffcam prima di old_diffcam!
|
||||
sum.update(new_diffcam, old_diffcam, PART_SEZDIFCAM, PART_DIFFCAM);
|
||||
|
||||
sum.update(old_pag, new_pag, PART_IMPORTO);
|
||||
sum.update(old_pag, new_pag, PART_IMPORTOVAL);
|
||||
sum.update(old_pag, new_pag, PART_RITENUTE);
|
||||
|
||||
partita().chiusa(TRUE); // Aggiorna flag di chiusura
|
||||
|
||||
return empty;
|
||||
}
|
||||
|
||||
@ -353,7 +358,7 @@ int TRiga_partite::read(TBaseisamfile& f, word op)
|
||||
int TRiga_partite::ultimo_pagamento(int r) const
|
||||
{
|
||||
const TRiga_scadenze& s = rata(r);
|
||||
return s.rows_array().last_row();
|
||||
return s.last();
|
||||
}
|
||||
|
||||
bool TRiga_partite::update(const TRectype& vec, const TRectype& nuo, const char* field)
|
||||
@ -379,6 +384,7 @@ bool TRiga_partite::update(const TImporto& vec, const TImporto& nuo,
|
||||
totale.set(sezione, get_real(val)); // ... inizializza il totale
|
||||
else
|
||||
CHECKS(vec.is_zero(), "Sezione errata per l'importo ", val);
|
||||
|
||||
totale += grow; // incrementa il totale
|
||||
totale.normalize();
|
||||
put(sez, totale.sezione()); // Aggiorna il totale sul record
|
||||
@ -422,11 +428,6 @@ bool TPartita::read(const TBill& clifo, int anno, const char* num)
|
||||
partita->put(PART_NUMPART, num); // Numero partita
|
||||
_part.read(partita);
|
||||
|
||||
#ifdef DBG
|
||||
for (int p = last(); p > 0; p = pred(p))
|
||||
CHECKD(riga(p)._partita == this, "Riga partite inconsistente", p);
|
||||
#endif
|
||||
|
||||
TRectype unas(LF_PAGSCA); // Record campione pagamenti non assegnati
|
||||
unas.zero();
|
||||
unas.put(PART_TIPOCF, partita->get(PART_TIPOCF)); // Copia chiave partite
|
||||
@ -457,11 +458,17 @@ bool TPartita::write(bool re)
|
||||
return ok;
|
||||
}
|
||||
|
||||
TImporto TPartita::importo_speso(long nreg, int numrig) const
|
||||
bool TPartita::remove()
|
||||
{
|
||||
_part.destroy_rows();
|
||||
return rewrite();
|
||||
}
|
||||
|
||||
TImporto TPartita::importo_speso(long nreg, int numrig, bool extra) const
|
||||
{
|
||||
TImporto imp;
|
||||
|
||||
for (int r = _part.last_row(); r > 0; r = pred(r))
|
||||
for (int r = last(); r > 0; r = pred(r))
|
||||
{
|
||||
const TRectype& part = riga(r);
|
||||
const long reg = part.get_long(PART_NREG);
|
||||
@ -470,17 +477,20 @@ TImporto TPartita::importo_speso(long nreg, int numrig) const
|
||||
const int num = part.get_int(PART_NUMRIG);
|
||||
if (num == numrig)
|
||||
{
|
||||
const char sez = part.get_char(PART_SEZ); // Deve essere valido per forza!
|
||||
imp.set(sez, part.get_real(PART_IMPORTO));
|
||||
const char sez = part.get_char(PART_SEZ); // Deve essere valida per forza!
|
||||
imp += TImporto(sez, part.get_real(PART_IMPORTO));
|
||||
|
||||
const char sezabb = part.get_char(PART_SEZABB); // Puo' essere nullo
|
||||
if (sezabb > ' ')
|
||||
imp += TImporto(sezabb, part.get_real(PART_ABBUONI));
|
||||
|
||||
const char sezdifcam = part.get_char(PART_SEZDIFCAM); // Puo' essere nullo
|
||||
if (sezdifcam > ' ')
|
||||
imp += TImporto(sezdifcam, part.get_real(PART_DIFFCAM));
|
||||
break;
|
||||
if (extra)
|
||||
{
|
||||
TImporto abbuoni(part.get_char(PART_SEZABB), part.get_real(PART_ABBUONI));
|
||||
if (part.get(PART_CODVAL).not_empty()) // Se e' in valuta
|
||||
{
|
||||
abbuoni.valore() *= part.get_real(PART_CAMBIO);
|
||||
abbuoni.valore().round();
|
||||
}
|
||||
imp += abbuoni;
|
||||
imp += TImporto(part.get_char(PART_SEZDIFCAM), part.get_real(PART_DIFFCAM));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -491,7 +501,7 @@ TImporto TPartita::importo_speso(long nreg, int numrig) const
|
||||
|
||||
void TPartita::update_reg_num(long nreg, const TRectype& mov)
|
||||
{
|
||||
for (int r = _part.last_row(); r > 0; r = pred(r))
|
||||
for (int r = last(); r > 0; r = pred(r))
|
||||
{
|
||||
TRectype& pag = _part.row(r, FALSE);
|
||||
|
||||
@ -516,7 +526,7 @@ int TPartita::rig2mov(int rp) const
|
||||
// Calcola la riga di partita relativa a una riga movimento
|
||||
int TPartita::mov2rig(long numreg, int rm) const
|
||||
{
|
||||
for (int r = _part.last_row(); r > 0; r = pred(r))
|
||||
for (int r = last(); r > 0; r = pred(r))
|
||||
{
|
||||
const TRiga_partite& row = riga(r);
|
||||
if (row.get_long(PART_NREG) == numreg && row.get_int(PART_NUMRIG) == rm)
|
||||
@ -543,7 +553,7 @@ void TPartita::calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImp
|
||||
{
|
||||
doc = pag = imp = TImporto('D', ZERO);
|
||||
|
||||
for (int r = _part.last_row(); r > 0; r = pred(r))
|
||||
for (int r = last(); r > 0; r = pred(r))
|
||||
{
|
||||
const TRiga_partite& row = riga(r);
|
||||
TImporto i(row.get_char(PART_SEZ), row.get_real(PART_IMPORTO));
|
||||
@ -561,11 +571,15 @@ void TPartita::calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImp
|
||||
break;
|
||||
}
|
||||
|
||||
i.set(row.get_char(PART_SEZ), row.get_real(PART_ABBUONI));
|
||||
imp += i;
|
||||
TImporto abbuoni(row.get_char(PART_SEZABB), row.get_real(PART_ABBUONI));
|
||||
if (row.get(PART_CODVAL).not_empty())
|
||||
{
|
||||
abbuoni.valore() *= row.get_real(PART_CAMBIO);
|
||||
abbuoni.valore().round();
|
||||
}
|
||||
imp += abbuoni;
|
||||
|
||||
i.set(row.get_char(PART_SEZ), row.get_real(PART_DIFFCAM));
|
||||
imp += i;
|
||||
imp += TImporto(row.get_char(PART_SEZDIFCAM), row.get_real(PART_DIFFCAM));
|
||||
}
|
||||
|
||||
saldo = doc;
|
||||
@ -576,7 +590,7 @@ void TPartita::calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImp
|
||||
|
||||
bool TPartita::utilizzata(int nrigp) const
|
||||
{
|
||||
for (int p = _part.last_row(); p > 0; p = pred(p))
|
||||
for (int p = last(); p > 0; p = pred(p))
|
||||
{
|
||||
const TRiga_partite& fatt = riga(p);
|
||||
const int tipomov = fatt.get_int(PART_TIPOMOV);
|
||||
@ -616,6 +630,45 @@ bool TPartita::modifica_pagamento(const TRectype& new_pag,
|
||||
return empty;
|
||||
}
|
||||
|
||||
bool TPartita::chiusa(bool update)
|
||||
{
|
||||
const TRiga_partite& row = riga(first());
|
||||
bool chiusa = row.get_bool(PART_CHIUSA);
|
||||
|
||||
if (update)
|
||||
{
|
||||
bool forse_chiusa = TRUE;
|
||||
for (int p = last(); p > 0 && forse_chiusa; p = pred(p))
|
||||
{
|
||||
const TRiga_partite& part = riga(first());
|
||||
if (part.get_int(PART_TIPOMOV) == 1)
|
||||
{
|
||||
for (int r = part.last(); r > 0; r--)
|
||||
{
|
||||
const TRiga_scadenze& scad = part.rata(r);
|
||||
if (!scad.pagata())
|
||||
{
|
||||
forse_chiusa = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chiusa != forse_chiusa)
|
||||
{
|
||||
chiusa = forse_chiusa;
|
||||
for (p = last(); p > 0; p = pred(p))
|
||||
{
|
||||
TRiga_partite& part = riga(first());
|
||||
part.put(PART_CHIUSA, chiusa);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return chiusa;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TPartite_array
|
||||
///////////////////////////////////////////////////////////
|
||||
@ -710,12 +763,12 @@ int TPartite_array::add_reg_num(long nreg, int numrig)
|
||||
return (int)cur.items();
|
||||
}
|
||||
|
||||
TImporto TPartite_array::importo_speso(long nreg, int numrig)
|
||||
TImporto TPartite_array::importo_speso(long nreg, int numrig, bool extra)
|
||||
{
|
||||
TImporto imp;
|
||||
add_reg_num(nreg, numrig);
|
||||
for (TPartita* game = first(); game; game = next())
|
||||
imp += game->importo_speso(nreg, numrig);
|
||||
imp += game->importo_speso(nreg, numrig, extra);
|
||||
return imp;
|
||||
}
|
||||
|
||||
|
@ -34,14 +34,18 @@ protected: // TRectype
|
||||
virtual int rewrite(TBaseisamfile& f) const;
|
||||
virtual int remove(TBaseisamfile& f);
|
||||
|
||||
public:
|
||||
const TRecord_array& rows_array() const { return _recarr; }
|
||||
TRecord_array& rows_array() { return _recarr; }
|
||||
const TRectype& row(int r) const { return ((TRecord_array&)_recarr).row(r, FALSE); }
|
||||
TRectype& row(int r, bool create) { return _recarr.row(r, create); }
|
||||
|
||||
public:
|
||||
const TRectype& row(int r) const { return _recarr.row(r); }
|
||||
TRectype& row(int r) { return _recarr.row(r, FALSE); }
|
||||
TRectype& new_row(int r = -1) { return _recarr.row(r > 0 ? r : last()+1, TRUE); }
|
||||
|
||||
int first() const { return _recarr.first_row(); }
|
||||
int last() const { return _recarr.last_row(); }
|
||||
int pred(int r) const { return _recarr.pred_row(r); }
|
||||
int succ(int r) const { return _recarr.succ_row(r); }
|
||||
|
||||
TTree_rectype(const TRectype& testata, const TRectype& riga, const char* num);
|
||||
TTree_rectype(int testata, int riga, const char* num);
|
||||
@ -71,7 +75,6 @@ protected: // TRecord_tree
|
||||
public:
|
||||
int pagata() const; // Riga che chiude la rata o 0 se non pagata completamente
|
||||
|
||||
real residuo() const;
|
||||
|
||||
bool in_valuta() const;
|
||||
|
||||
@ -80,6 +83,7 @@ public:
|
||||
|
||||
TImporto importo_pagato(bool val) const;
|
||||
TImporto importo_da_pagare(bool val) const;
|
||||
real residuo(bool val) const; // Differenza delle due funzioni precedenti
|
||||
|
||||
TRiga_scadenze(TRiga_partite* riga);
|
||||
TRiga_scadenze(const TRiga_scadenze& s);
|
||||
@ -135,18 +139,21 @@ public:
|
||||
bool read(const TBill& clifo, int anno, const char* num);
|
||||
bool write(bool re = FALSE);
|
||||
bool rewrite() { return write(TRUE); }
|
||||
bool remove();
|
||||
|
||||
int mov2rig(long nreg, int rmov) const;
|
||||
int rig2mov(int rmov) const;
|
||||
int prima_fattura() const;
|
||||
bool utilizzata(int r) const; // Controlla se esistono pagamenti sommati alla riga r
|
||||
|
||||
bool chiusa(bool update = FALSE);
|
||||
|
||||
void conto(TBill& c) const { c.get(_part.key()); }
|
||||
int anno() const { return _part.key().get_int(PART_ANNO); }
|
||||
const TString& numero() const { return _part.key().get(PART_NUMPART); }
|
||||
const TString& descrizione() const { return _part.key().get(PART_DESCR); }
|
||||
|
||||
TImporto importo_speso(long numreg, int numrig) const;
|
||||
TImporto importo_speso(long numreg, int numrig, bool extra) const;
|
||||
void update_reg_num(long nreg, const TRectype& mov);
|
||||
void calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImporto& imp) const;
|
||||
|
||||
@ -185,7 +192,7 @@ public:
|
||||
bool rewrite() { return write(TRUE); }
|
||||
|
||||
int add_reg_num(long numreg, int numrig);
|
||||
TImporto importo_speso(long numreg, int numrig);
|
||||
TImporto importo_speso(long numreg, int numrig, bool extra);
|
||||
void update_reg_num(long nreg, const TRectype& mov);
|
||||
|
||||
TPartita* first() { restart(); return next(); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user