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
|
// Determina se un codice sospeso o no
|
||||||
// Certified 99%
|
// Certified 99%
|
||||||
bool TPrimanota_application::suspended_handler(TMask_field& f, KEY k)
|
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%
|
// Certified 100%
|
||||||
TImporto TPrimanota_application::get_cgs_imp(int n)
|
TImporto TPrimanota_application::get_cgs_imp(int n)
|
||||||
{
|
{
|
||||||
|
TSheet_field& s = cgs();
|
||||||
|
|
||||||
TImporto importo;
|
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;
|
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 long numreg = f.mask().get_long(F_NUMREG);
|
||||||
const int currig = i+1;
|
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)
|
if (importo != speso)
|
||||||
{
|
{
|
||||||
bool ok = yesno_box("L'importo della riga %d dovrebbe essere %c %s\n"
|
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);
|
void add_cgs_tot(TMask& m);
|
||||||
int set_cgs_row(int n, const TImporto& importo, TBill& conto, const char* desc, char tipo);
|
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);
|
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 add_cgs_imp(int n, const TImporto& importo);
|
||||||
bool sub_cgs_imp(int n, const TImporto& importo);
|
bool sub_cgs_imp(int n, const TImporto& importo);
|
||||||
void disable_cgs_cells(int n, char tipo);
|
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(TPartita& partita, long nreg, int numrig);
|
||||||
bool notify_cgline_deletion(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);
|
long calcola_m770(int tipo_coll, real& spese, real& compenso, real& iva, real& ritfis);
|
||||||
bool link_m770();
|
bool link_m770();
|
||||||
@ -235,6 +234,7 @@ public:
|
|||||||
TSheet_field& ivas() const;
|
TSheet_field& ivas() const;
|
||||||
TSheet_field& pags() const;
|
TSheet_field& pags() const;
|
||||||
TString_array& pag_rows() { return _pag_rows; }
|
TString_array& pag_rows() { return _pag_rows; }
|
||||||
|
TImporto get_cgs_imp(int n);
|
||||||
|
|
||||||
TPrimanota_application();
|
TPrimanota_application();
|
||||||
};
|
};
|
||||||
|
363
cg/cg2105.cpp
363
cg/cg2105.cpp
@ -27,6 +27,8 @@ protected:
|
|||||||
|
|
||||||
void add_importo(TToken_string& s, const TImporto& i) const;
|
void add_importo(TToken_string& s, const TImporto& i) const;
|
||||||
void fill_partite(bool all) const;
|
void fill_partite(bool all) const;
|
||||||
|
real aggiorna_residuo();
|
||||||
|
void update_partita(const TPartita& game, int prow, bool all) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TSheet_field& partite() const { return (TSheet_field&)field(P_PARTITE); }
|
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);
|
partite().set_notify(partite_notify);
|
||||||
scadenze().sheet_mask().set_handler(100, edit_scadenza_handler);
|
scadenze().sheet_mask().set_handler(100, edit_scadenza_handler);
|
||||||
|
|
||||||
|
aggiorna_residuo();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TGame_mask::annopart_handler(TMask_field& f, KEY k)
|
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);
|
TMask_field& n = f.mask().field(P_NUMERO);
|
||||||
n.set_dirty();
|
n.set_dirty();
|
||||||
@ -119,6 +123,20 @@ bool TGame_mask::scambio_handler(TMask_field& f, KEY k)
|
|||||||
return TRUE;
|
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)
|
bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
|
||||||
{
|
{
|
||||||
if (k == K_TAB)
|
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_NUMDOC));
|
||||||
row.add(riga.get(PART_PROTIVA));
|
row.add(riga.get(PART_PROTIVA));
|
||||||
|
|
||||||
const TRecord_array& ap = scad.rows_array();
|
const int lastp = scad.last();
|
||||||
const int lastp = ap.last_row();
|
for (int pa = scad.first(); pa <= lastp; pa = scad.succ(pa))
|
||||||
for (int pa = ap.first_row(); pa <= lastp; pa = ap.succ_row(pa))
|
|
||||||
{
|
{
|
||||||
const TRiga_partite& rigp = game->riga(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);
|
TToken_string& row = scadenze.row(-1);
|
||||||
row.add(ri);
|
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);
|
const bool dirty = app().edit_pagamento(game, nriga, nrata, nrigp);
|
||||||
|
|
||||||
if (dirty)
|
if (dirty)
|
||||||
|
{
|
||||||
|
gm.update_partita(game, gm._riga_partite, TRUE);
|
||||||
partite_notify(gm.partite(), gm._riga_partite, K_TAB);
|
partite_notify(gm.partite(), gm._riga_partite, K_TAB);
|
||||||
|
gm.aggiorna_residuo();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return TRUE;
|
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
|
void TGame_mask::fill_partite(bool all) const
|
||||||
{
|
{
|
||||||
TString_array& a = partite().rows_array();
|
TString_array& a = partite().rows_array();
|
||||||
@ -282,30 +328,7 @@ void TGame_mask::fill_partite(bool all) const
|
|||||||
should_delete_game = TRUE;
|
should_delete_game = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
TImporto saldo, doc, pag, imp;
|
update_partita(*game, -1, all);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (should_delete_game)
|
if (should_delete_game)
|
||||||
delete game;
|
delete game;
|
||||||
@ -328,6 +351,44 @@ void TGame_mask::fill_partite(bool all) const
|
|||||||
// Metodi di prima nota
|
// 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)
|
bool TPrimanota_application::edit_partite(int riga)
|
||||||
{
|
{
|
||||||
TToken_string& cgr = cgs().row(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_DATADOC, curr_mask().get(F_DATADOC));
|
||||||
part.put(PART_NUMDOC, curr_mask().get(F_NUMDOC));
|
part.put(PART_NUMDOC, curr_mask().get(F_NUMDOC));
|
||||||
part.put(PART_DESCR, curr_mask().get(F_DESCR));
|
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
|
// Copia dati causale corrente
|
||||||
const int tipomov = causale().tipomov();
|
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
|
sezione = (sezione == 'D') ? 'A' : 'D'; // scambia segno
|
||||||
}
|
}
|
||||||
part.put(PART_SEZ, sezione); // Memorizza solo la sezione (importi nulli)
|
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
|
int caus = 2; // Calcola riga causale per la contropartita in base al tipo pagamento
|
||||||
switch (riga_scad.get_int(SCAD_TIPOPAG))
|
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
|
causale().bill(caus = 1, contro); // ... prende il primo
|
||||||
contro.put(pagamento, TRUE); // Scrive conto contropartita
|
contro.put(pagamento, TRUE); // Scrive conto contropartita
|
||||||
|
|
||||||
|
// Da regalare a Ferdinando
|
||||||
if (conto.tipo() > ' ') // Se cliente o fornitore cerca sua banca
|
if (conto.tipo() > ' ') // Se cliente o fornitore cerca sua banca
|
||||||
{
|
{
|
||||||
TRelation cliforel(LF_CLIFO);
|
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_CODCAB, clifo.get(CLI_CODCAB));
|
||||||
pagamento.put(PAGSCA_CODAG, cliforel.lfile(LF_CFVEN).get(CLI_CODAG));
|
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_CODABIPR, riga_scad.get(SCAD_CODABIPR));
|
||||||
pagamento.put(PAGSCA_CODCABPR, riga_scad.get(SCAD_CODCABPR));
|
pagamento.put(PAGSCA_CODCABPR, riga_scad.get(SCAD_CODCABPR));
|
||||||
|
|
||||||
@ -468,67 +540,71 @@ 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)
|
||||||
{
|
{
|
||||||
const int nriga = new_pag.get_int(PAGSCA_NRIGA); // Riga fattura
|
if (deleting != 0)
|
||||||
const TRiga_partite& parbas = p.riga(nriga);
|
|
||||||
|
|
||||||
const int nrata = new_pag.get_int(PAGSCA_NRATA); // Numero rata
|
|
||||||
TRiga_scadenze& scaden = parbas.rata(nrata);
|
|
||||||
|
|
||||||
const int nrigp = new_pag.get_int(PAGSCA_NRIGP); // Riga pagamento
|
|
||||||
const TRectype& old_pag = scaden.row(nrigp);
|
|
||||||
const TRiga_partite& somma = p.riga(nrigp);
|
|
||||||
|
|
||||||
const char sez = somma.sezione(); // Sezione importo e ritenute
|
|
||||||
const char controsez = sez == 'A' ? 'D' : 'A'; // Sezione contropartita
|
|
||||||
|
|
||||||
// Aggiornamento contopartita
|
|
||||||
const TImporto old_importo(controsez, old_pag.get_real(PAGSCA_IMPORTO));
|
|
||||||
TBill old_conto; old_conto.get(old_pag, TRUE);
|
|
||||||
|
|
||||||
const TImporto new_importo(controsez, new_pag.get_real(PAGSCA_IMPORTO));
|
|
||||||
TBill new_conto; new_conto.get(new_pag, TRUE);
|
|
||||||
|
|
||||||
if (old_importo != new_importo || old_conto != new_conto)
|
|
||||||
{
|
{
|
||||||
const int old_riga = bill2pos(old_conto, 'I');
|
const int nriga = new_pag.get_int(PAGSCA_NRIGA); // Riga fattura
|
||||||
if (old_riga >= 0)
|
const TRiga_partite& parbas = p.riga(nriga);
|
||||||
|
|
||||||
|
const int nrata = new_pag.get_int(PAGSCA_NRATA); // Numero rata
|
||||||
|
TRiga_scadenze& scaden = parbas.rata(nrata);
|
||||||
|
|
||||||
|
const int nrigp = new_pag.get_int(PAGSCA_NRIGP); // Riga pagamento
|
||||||
|
const TRectype& old_pag = scaden.row(nrigp);
|
||||||
|
const TRiga_partite& somma = p.riga(nrigp);
|
||||||
|
|
||||||
|
const char sez = somma.sezione(); // Sezione importo e ritenute
|
||||||
|
const char controsez = sez == 'A' ? 'D' : 'A'; // Sezione contropartita
|
||||||
|
|
||||||
|
// Aggiornamento contopartita
|
||||||
|
const TImporto old_importo(controsez, old_pag.get_real(PAGSCA_IMPORTO));
|
||||||
|
TBill old_conto; old_conto.get(old_pag, TRUE);
|
||||||
|
|
||||||
|
const TImporto new_importo(controsez, new_pag.get_real(PAGSCA_IMPORTO));
|
||||||
|
TBill new_conto; new_conto.get(new_pag, TRUE);
|
||||||
|
|
||||||
|
if (old_importo != new_importo || old_conto != new_conto)
|
||||||
{
|
{
|
||||||
const bool empty = sub_cgs_imp(old_riga, old_importo);
|
const int old_riga = bill2pos(old_conto, 'I');
|
||||||
if (empty && (new_importo.is_zero() || new_conto != old_conto))
|
if (old_riga >= 0)
|
||||||
reset_cgs_row(old_riga);
|
{
|
||||||
|
const bool empty = sub_cgs_imp(old_riga, old_importo);
|
||||||
|
if (empty && (new_importo.is_zero() || new_conto != old_conto))
|
||||||
|
reset_cgs_row(old_riga);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Importo della contropartita
|
||||||
|
if (!new_importo.is_zero())
|
||||||
|
{
|
||||||
|
const int new_riga = bill2pos(new_conto, 'I');
|
||||||
|
if (new_riga < 0)
|
||||||
|
set_cgs_row(new_riga, new_importo, new_conto, "", 'I');
|
||||||
|
else
|
||||||
|
add_cgs_imp(new_riga, new_importo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Importo della contropartita
|
|
||||||
if (!new_importo.is_zero())
|
// Aggiornamento ritenute
|
||||||
|
const real old_ritenute(old_pag.get(PAGSCA_RITENUTE));
|
||||||
|
const real new_ritenute(new_pag.get(PAGSCA_RITENUTE));
|
||||||
|
if (old_ritenute != new_ritenute)
|
||||||
{
|
{
|
||||||
const int new_riga = bill2pos(new_conto, 'I');
|
const TImporto grow_ritenute(controsez, new_ritenute-old_ritenute);
|
||||||
if (new_riga < 0)
|
const riga = type2pos('F');
|
||||||
set_cgs_row(new_riga, new_importo, new_conto, "", 'I');
|
if (riga < 0)
|
||||||
|
{
|
||||||
|
TBill conto_rit; causale().bill(11, conto_rit);
|
||||||
|
set_cgs_row(riga, grow_ritenute, conto_rit, "", 'F');
|
||||||
|
}
|
||||||
else
|
else
|
||||||
add_cgs_imp(new_riga, new_importo);
|
{
|
||||||
|
const bool empty = add_cgs_imp(riga, grow_ritenute);
|
||||||
|
if (empty) reset_cgs_row(riga);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} // if (deleting != 0)
|
||||||
|
|
||||||
// Aggiornamento ritenute
|
|
||||||
const real old_ritenute(old_pag.get(PAGSCA_RITENUTE));
|
|
||||||
const real new_ritenute(new_pag.get(PAGSCA_RITENUTE));
|
|
||||||
if (old_ritenute != new_ritenute)
|
|
||||||
{
|
|
||||||
const TImporto grow_ritenute(controsez, new_ritenute-old_ritenute);
|
|
||||||
const riga = type2pos('F');
|
|
||||||
if (riga < 0)
|
|
||||||
{
|
|
||||||
TBill conto_rit; causale().bill(11, conto_rit);
|
|
||||||
set_cgs_row(riga, grow_ritenute, conto_rit, "", 'F');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const bool empty = add_cgs_imp(riga, grow_ritenute);
|
|
||||||
if (empty) reset_cgs_row(riga);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char old_ap, new_ap;
|
char old_ap, new_ap;
|
||||||
TImporto old_abbuono, new_abbuono, old_diffcam, new_diffcam;
|
TImporto old_abbuono, new_abbuono, old_diffcam, new_diffcam;
|
||||||
@ -536,55 +612,70 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa
|
|||||||
old_ap, old_abbuono, old_diffcam,
|
old_ap, old_abbuono, old_diffcam,
|
||||||
new_ap, new_abbuono, new_diffcam);
|
new_ap, new_abbuono, new_diffcam);
|
||||||
|
|
||||||
const int riga_contabile = app().cgs().selected();
|
if (deleting != 0)
|
||||||
|
|
||||||
// Se c'e' differenza negli abbuoni
|
|
||||||
if (old_abbuono != new_abbuono || old_ap != new_ap)
|
|
||||||
{
|
{
|
||||||
if (old_ap != ' ') // Se c'era un abbuono ...
|
const int riga_contabile = app().cgs().selected();
|
||||||
{
|
|
||||||
const int riga_abb = type2pos(old_ap);
|
|
||||||
CHECK(riga_abb >= 0, "Chiss'e' fregato gli abbuoni?");
|
|
||||||
const bool empty = sub_cgs_imp(riga_abb, old_abbuono);
|
|
||||||
if (empty && new_ap != old_ap)
|
|
||||||
reset_cgs_row(riga_abb);
|
|
||||||
|
|
||||||
// Sottrae l'abbuono con la sezione invertita dalla riga contabile
|
// Se c'e' differenza negli abbuoni
|
||||||
add_cgs_imp(riga_contabile, old_abbuono);
|
if (old_abbuono != new_abbuono || old_ap != new_ap)
|
||||||
}
|
|
||||||
if (new_ap != ' ') // Se ci sono abbuoni
|
|
||||||
{
|
{
|
||||||
const riga_abb = type2pos(new_ap);
|
if (old_ap != ' ') // Se c'era un abbuono ...
|
||||||
if (riga_abb < 0)
|
|
||||||
{
|
{
|
||||||
TBill conto_abb; causale().bill(new_ap == 'A' ? 9 : 8, conto_abb);
|
const int riga_abb = type2pos(old_ap);
|
||||||
app().set_cgs_row(riga_abb, new_abbuono, conto_abb, "", new_ap);
|
CHECK(riga_abb >= 0, "Chiss'e' fregato gli abbuoni?");
|
||||||
|
const bool empty = sub_cgs_imp(riga_abb, old_abbuono);
|
||||||
|
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);
|
||||||
|
if (riga_abb < 0)
|
||||||
|
{
|
||||||
|
TBill conto_abb; causale().bill(new_ap == 'A' ? 9 : 8, conto_abb);
|
||||||
|
app().set_cgs_row(riga_abb, new_abbuono, conto_abb, "", new_ap);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
add_cgs_imp(riga_abb, new_abbuono);
|
||||||
|
|
||||||
|
if (deleting != riga_contabile)
|
||||||
|
{
|
||||||
|
// Aggiunge l'abbuono con la sezione invertita
|
||||||
|
sub_cgs_imp(riga_contabile, new_abbuono);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Se c'e' variazione nella differenza cambi
|
||||||
|
if (old_diffcam != new_diffcam)
|
||||||
|
{
|
||||||
|
const int riga_diffcam = type2pos('C');
|
||||||
|
TImporto grow_diffcam(new_diffcam); grow_diffcam -= old_diffcam;
|
||||||
|
|
||||||
|
if (riga_diffcam < 0)
|
||||||
|
{
|
||||||
|
TBill conto_diffcam; causale().bill(12, conto_diffcam);
|
||||||
|
set_cgs_row(riga_diffcam, grow_diffcam, conto_diffcam, "", 'C');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
add_cgs_imp(riga_abb, new_abbuono);
|
{
|
||||||
|
const bool empty = add_cgs_imp(riga_diffcam, grow_diffcam);
|
||||||
|
if (empty) reset_cgs_row(riga_diffcam);
|
||||||
|
}
|
||||||
|
|
||||||
sub_cgs_imp(riga_contabile, new_abbuono); // Aggiunge l'abbuono 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)
|
||||||
|
|
||||||
// Se c'e' variazione nella differenza cambi
|
|
||||||
if (old_diffcam != new_diffcam)
|
|
||||||
{
|
|
||||||
const int riga_diffcam = type2pos('C');
|
|
||||||
TImporto grow_diffcam(new_diffcam); grow_diffcam -= old_diffcam;
|
|
||||||
|
|
||||||
if (riga_diffcam < 0)
|
|
||||||
{
|
|
||||||
TBill conto_diffcam; causale().bill(12, conto_diffcam);
|
|
||||||
set_cgs_row(riga_diffcam, grow_diffcam, conto_diffcam, "", 'C');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
@ -619,10 +710,10 @@ bool TPrimanota_application::edit_pagamento(TPartita& p, int nriga, int nrata, i
|
|||||||
// Dati della scadenza che ha generato la partita
|
// Dati della scadenza che ha generato la partita
|
||||||
TReal_field& residuo = (TReal_field&)m.field(S_RESIDUO);
|
TReal_field& residuo = (TReal_field&)m.field(S_RESIDUO);
|
||||||
residuo.set_decimals(in_valuta ? 2 : 0);
|
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_DATASCAD, scaden.get(SCAD_DATASCAD)); // Data della scadenza
|
||||||
m.set(S_SEZIONE_SCAD, parbas.get(PART_SEZ)); // Sezione della rata
|
m.set(S_SEZIONE_SCAD, parbas.get(PART_SEZ)); // Sezione della rata
|
||||||
m.set(S_RATA, scaden.get(SCAD_NRATA));
|
m.set(S_RATA, scaden.get(SCAD_NRATA));
|
||||||
m.set(S_IMPORTO_SCAD, scaden.get(SCAD_IMPORTO)); // Importo della rata
|
m.set(S_IMPORTO_SCAD, scaden.get(SCAD_IMPORTO)); // Importo della rata
|
||||||
m.set(S_IMPORTOVAL_SCAD, scaden.get(SCAD_IMPORTOVAL)); // Importo in valuta
|
m.set(S_IMPORTOVAL_SCAD, scaden.get(SCAD_IMPORTOVAL)); // Importo in valuta
|
||||||
|
|
||||||
@ -648,13 +739,16 @@ bool TPrimanota_application::edit_pagamento(TPartita& p, int nriga, int nrata, i
|
|||||||
return key != K_ESC;
|
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 TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg, int numrig)
|
||||||
{
|
{
|
||||||
bool found = FALSE;
|
bool found = FALSE;
|
||||||
|
|
||||||
for (int p = partita.last(); p > 0; p = partita.pred(p))
|
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)
|
if (part.get_int(PART_TIPOMOV) == 1)
|
||||||
{
|
{
|
||||||
for (int r = part.rate(); r > 0; r--)
|
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_IMPORTO);
|
||||||
pag.zero(PAGSCA_IMPORTOVAL);
|
pag.zero(PAGSCA_IMPORTOVAL);
|
||||||
pag.zero(PAGSCA_RITENUTE);
|
pag.zero(PAGSCA_RITENUTE);
|
||||||
notify_edit_pagamento(partita, pag);
|
notify_edit_pagamento(partita, pag, numrig);
|
||||||
found = TRUE;
|
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;
|
return found;
|
||||||
@ -685,7 +784,7 @@ bool TPrimanota_application::notify_cgline_deletion(int numrig)
|
|||||||
{
|
{
|
||||||
bool found = FALSE;
|
bool found = FALSE;
|
||||||
const long nreg = curr_mask().get_long(F_NUMREG);
|
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())
|
for (TPartita* game = _partite.first(); game; game = _partite.next())
|
||||||
found |= notify_cgline_deletion(*game, nreg, numrig);
|
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();
|
return riga().partita();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Controlla se la fattura della rata e' in valuta
|
||||||
// Controlla se la rata e' in valuta
|
|
||||||
bool TRiga_scadenze::in_valuta() const
|
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
|
// Controlla se la rata e' stata completamente pagata
|
||||||
int TRiga_scadenze::pagata() const
|
int TRiga_scadenze::pagata() const
|
||||||
{
|
{
|
||||||
const TRecord_array& a = rows_array();
|
for (int p = last(); p > 0; p = pred(p))
|
||||||
for (int p = a.last_row(); p > 0; p = a.pred_row(p))
|
|
||||||
{
|
{
|
||||||
const TRectype& pag = a.row(p);
|
const TRectype& pag = row(p);
|
||||||
if (pag.get_char("ACCSAL") == 'S')
|
if (pag.get_char("ACCSAL") == 'S')
|
||||||
return p;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcola il totale dei pagamenti (eventualmente in valuta)
|
// Calcola il totale dei pagamenti (eventualmente in valuta)
|
||||||
TImporto TRiga_scadenze::importo_pagato(bool val) const
|
TImporto TRiga_scadenze::importo_pagato(bool val) const
|
||||||
{
|
{
|
||||||
|
const char* imp_field = val && in_valuta() ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
||||||
const TPartita& game = partita();
|
const TPartita& game = partita();
|
||||||
const char* imp_field = in_valuta() && val ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
|
||||||
TImporto totale;
|
TImporto totale;
|
||||||
const TRecord_array& a = rows_array();
|
for (int p = last(); p > 0; p = pred(p))
|
||||||
for (int p = a.last_row(); p > 0; p = a.pred_row(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 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;
|
totale += imp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,9 +162,9 @@ TImporto TRiga_scadenze::importo_pagato(bool val) const
|
|||||||
// Calcola l'importo da pagare (eventualmente in valuta)
|
// Calcola l'importo da pagare (eventualmente in valuta)
|
||||||
TImporto TRiga_scadenze::importo_da_pagare(bool val) const
|
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 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;
|
return totale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +190,7 @@ char TRiga_scadenze::calcola_abbuono(TImporto& abbuono, bool val) const
|
|||||||
|
|
||||||
if (val && in_valuta())
|
if (val && in_valuta())
|
||||||
{
|
{
|
||||||
abbuono.valore() *= get_real(SCAD_CAMBIO);
|
abbuono.valore() *= riga().get_real(PART_CAMBIO);
|
||||||
abbuono.valore().round();
|
abbuono.valore().round();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,7 +210,7 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(bool update)
|
|||||||
const int riga_saldo = pagata();
|
const int riga_saldo = pagata();
|
||||||
if (riga_saldo > 0)
|
if (riga_saldo > 0)
|
||||||
{
|
{
|
||||||
TRectype& pag = row(riga_saldo, FALSE);
|
TRectype& pag = row(riga_saldo);
|
||||||
const TRiga_partite& sum = partita().riga(riga_saldo);
|
const TRiga_partite& sum = partita().riga(riga_saldo);
|
||||||
const char sez = sum.sezione();
|
const char sez = sum.sezione();
|
||||||
|
|
||||||
@ -225,7 +222,7 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(bool update)
|
|||||||
real a = pag.get_real(PAGSCA_ABBUONI);
|
real a = pag.get_real(PAGSCA_ABBUONI);
|
||||||
if (in_valuta())
|
if (in_valuta())
|
||||||
{
|
{
|
||||||
a *= get_real(SCAD_CAMBIO);
|
a *= riga().get_real(PART_CAMBIO);
|
||||||
a.round();
|
a.round();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +241,7 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(bool update)
|
|||||||
{
|
{
|
||||||
for (int p = last(); p > 0; p = pred(p))
|
for (int p = last(); p > 0; p = pred(p))
|
||||||
{
|
{
|
||||||
TRectype& pag = row(p, FALSE);
|
TRectype& pag = row(p);
|
||||||
pag.zero(PAGSCA_DIFFCAM);
|
pag.zero(PAGSCA_DIFFCAM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,13 +250,11 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(bool update)
|
|||||||
return diffcam;
|
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;
|
TImporto residuo(importo_da_pagare(val));
|
||||||
const real da_pagare(get(imp_field));
|
residuo -= importo_pagato(val);
|
||||||
const real pagato(get(SCAD_IMPORTOPAG));
|
return residuo.valore();
|
||||||
const real residuo = da_pagare - pagato;
|
|
||||||
return residuo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -271,47 +266,57 @@ bool TRiga_scadenze::modifica_pagamento(const TRectype& new_pag,
|
|||||||
const TRectype old_pag(row(nrigp));
|
const TRectype old_pag(row(nrigp));
|
||||||
TRiga_partite& sum = partita().riga(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);
|
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 real importo(new_pag.get(imp_field));
|
||||||
const bool empty = importo.is_zero();
|
const bool empty = importo.is_zero();
|
||||||
if (empty)
|
if (empty)
|
||||||
rows_array().destroy_row(nrigp);
|
rows_array().destroy_row(nrigp);
|
||||||
else
|
else
|
||||||
row(nrigp, FALSE) = new_pag;
|
row(nrigp) = new_pag;
|
||||||
|
|
||||||
TImporto abbuono;
|
TImporto new_abbuono;
|
||||||
new_ap = calcola_abbuono(abbuono, TRUE); // Calcolo abbuono in valuta
|
new_ap = calcola_abbuono(new_abbuono, TRUE); // Calcolo abbuono in valuta
|
||||||
|
|
||||||
TImporto imp(abbuono); imp.swap_section();
|
new_abb = new_abbuono; // Calcola nuovo abbuono in lire
|
||||||
imp.normalize(sum.sezione());
|
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 != ' ')
|
if (new_ap != ' ')
|
||||||
{
|
{
|
||||||
CHECK(nrigp == pagata(), "Aggiornamento abbuoni inconsistente");
|
CHECK(nrigp == pagata(), "Aggiornamento abbuoni inconsistente");
|
||||||
TRectype& pag = row(nrigp, FALSE);
|
TRectype& pag = row(nrigp);
|
||||||
pag.put(PAGSCA_ABBUONI, imp.valore());
|
pag.put(PAGSCA_ABBUONI, new_abbuono.valore());
|
||||||
|
|
||||||
new_abb = abbuono;
|
|
||||||
if (in_valuta())
|
|
||||||
{
|
|
||||||
new_abb.valore() *= get_real(SCAD_CAMBIO);
|
|
||||||
new_abb.valore().round();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
sum.update(old_abbuono, new_abbuono, PART_SEZABB, PART_ABBUONI);
|
||||||
new_abb.valore() = ZERO;
|
|
||||||
|
|
||||||
sum.update(old_abb, new_abb, PART_SEZABB, PART_ABBUONI);
|
|
||||||
|
|
||||||
new_diffcam = calcola_differenza_cambio(TRUE);
|
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_IMPORTO);
|
||||||
sum.update(old_pag, new_pag, PART_IMPORTOVAL);
|
sum.update(old_pag, new_pag, PART_IMPORTOVAL);
|
||||||
sum.update(old_pag, new_pag, PART_RITENUTE);
|
sum.update(old_pag, new_pag, PART_RITENUTE);
|
||||||
|
|
||||||
|
partita().chiusa(TRUE); // Aggiorna flag di chiusura
|
||||||
|
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,7 +358,7 @@ int TRiga_partite::read(TBaseisamfile& f, word op)
|
|||||||
int TRiga_partite::ultimo_pagamento(int r) const
|
int TRiga_partite::ultimo_pagamento(int r) const
|
||||||
{
|
{
|
||||||
const TRiga_scadenze& s = rata(r);
|
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)
|
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
|
totale.set(sezione, get_real(val)); // ... inizializza il totale
|
||||||
else
|
else
|
||||||
CHECKS(vec.is_zero(), "Sezione errata per l'importo ", val);
|
CHECKS(vec.is_zero(), "Sezione errata per l'importo ", val);
|
||||||
|
|
||||||
totale += grow; // incrementa il totale
|
totale += grow; // incrementa il totale
|
||||||
totale.normalize();
|
totale.normalize();
|
||||||
put(sez, totale.sezione()); // Aggiorna il totale sul record
|
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
|
partita->put(PART_NUMPART, num); // Numero partita
|
||||||
_part.read(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
|
TRectype unas(LF_PAGSCA); // Record campione pagamenti non assegnati
|
||||||
unas.zero();
|
unas.zero();
|
||||||
unas.put(PART_TIPOCF, partita->get(PART_TIPOCF)); // Copia chiave partite
|
unas.put(PART_TIPOCF, partita->get(PART_TIPOCF)); // Copia chiave partite
|
||||||
@ -457,11 +458,17 @@ bool TPartita::write(bool re)
|
|||||||
return ok;
|
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;
|
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 TRectype& part = riga(r);
|
||||||
const long reg = part.get_long(PART_NREG);
|
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);
|
const int num = part.get_int(PART_NUMRIG);
|
||||||
if (num == numrig)
|
if (num == numrig)
|
||||||
{
|
{
|
||||||
const char sez = part.get_char(PART_SEZ); // Deve essere valido per forza!
|
const char sez = part.get_char(PART_SEZ); // Deve essere valida per forza!
|
||||||
imp.set(sez, part.get_real(PART_IMPORTO));
|
imp += TImporto(sez, part.get_real(PART_IMPORTO));
|
||||||
|
|
||||||
const char sezabb = part.get_char(PART_SEZABB); // Puo' essere nullo
|
if (extra)
|
||||||
if (sezabb > ' ')
|
{
|
||||||
imp += TImporto(sezabb, part.get_real(PART_ABBUONI));
|
TImporto abbuoni(part.get_char(PART_SEZABB), part.get_real(PART_ABBUONI));
|
||||||
|
if (part.get(PART_CODVAL).not_empty()) // Se e' in valuta
|
||||||
const char sezdifcam = part.get_char(PART_SEZDIFCAM); // Puo' essere nullo
|
{
|
||||||
if (sezdifcam > ' ')
|
abbuoni.valore() *= part.get_real(PART_CAMBIO);
|
||||||
imp += TImporto(sezdifcam, part.get_real(PART_DIFFCAM));
|
abbuoni.valore().round();
|
||||||
break;
|
}
|
||||||
|
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)
|
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);
|
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
|
// Calcola la riga di partita relativa a una riga movimento
|
||||||
int TPartita::mov2rig(long numreg, int rm) const
|
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);
|
const TRiga_partite& row = riga(r);
|
||||||
if (row.get_long(PART_NREG) == numreg && row.get_int(PART_NUMRIG) == rm)
|
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);
|
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);
|
const TRiga_partite& row = riga(r);
|
||||||
TImporto i(row.get_char(PART_SEZ), row.get_real(PART_IMPORTO));
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
i.set(row.get_char(PART_SEZ), row.get_real(PART_ABBUONI));
|
TImporto abbuoni(row.get_char(PART_SEZABB), row.get_real(PART_ABBUONI));
|
||||||
imp += i;
|
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 += TImporto(row.get_char(PART_SEZDIFCAM), row.get_real(PART_DIFFCAM));
|
||||||
imp += i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
saldo = doc;
|
saldo = doc;
|
||||||
@ -576,7 +590,7 @@ void TPartita::calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImp
|
|||||||
|
|
||||||
bool TPartita::utilizzata(int nrigp) const
|
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 TRiga_partite& fatt = riga(p);
|
||||||
const int tipomov = fatt.get_int(PART_TIPOMOV);
|
const int tipomov = fatt.get_int(PART_TIPOMOV);
|
||||||
@ -616,6 +630,45 @@ bool TPartita::modifica_pagamento(const TRectype& new_pag,
|
|||||||
return empty;
|
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
|
// TPartite_array
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
@ -710,12 +763,12 @@ int TPartite_array::add_reg_num(long nreg, int numrig)
|
|||||||
return (int)cur.items();
|
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;
|
TImporto imp;
|
||||||
add_reg_num(nreg, numrig);
|
add_reg_num(nreg, numrig);
|
||||||
for (TPartita* game = first(); game; game = next())
|
for (TPartita* game = first(); game; game = next())
|
||||||
imp += game->importo_speso(nreg, numrig);
|
imp += game->importo_speso(nreg, numrig, extra);
|
||||||
return imp;
|
return imp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,14 +34,18 @@ protected: // TRectype
|
|||||||
virtual int rewrite(TBaseisamfile& f) const;
|
virtual int rewrite(TBaseisamfile& f) const;
|
||||||
virtual int remove(TBaseisamfile& f);
|
virtual int remove(TBaseisamfile& f);
|
||||||
|
|
||||||
public:
|
|
||||||
const TRecord_array& rows_array() const { return _recarr; }
|
const TRecord_array& rows_array() const { return _recarr; }
|
||||||
TRecord_array& rows_array() { 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 last() const { return _recarr.last_row(); }
|
||||||
int pred(int r) const { return _recarr.pred_row(r); }
|
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(const TRectype& testata, const TRectype& riga, const char* num);
|
||||||
TTree_rectype(int testata, int riga, const char* num);
|
TTree_rectype(int testata, int riga, const char* num);
|
||||||
@ -71,7 +75,6 @@ protected: // TRecord_tree
|
|||||||
public:
|
public:
|
||||||
int pagata() const; // Riga che chiude la rata o 0 se non pagata completamente
|
int pagata() const; // Riga che chiude la rata o 0 se non pagata completamente
|
||||||
|
|
||||||
real residuo() const;
|
|
||||||
|
|
||||||
bool in_valuta() const;
|
bool in_valuta() const;
|
||||||
|
|
||||||
@ -80,6 +83,7 @@ public:
|
|||||||
|
|
||||||
TImporto importo_pagato(bool val) const;
|
TImporto importo_pagato(bool val) const;
|
||||||
TImporto importo_da_pagare(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(TRiga_partite* riga);
|
||||||
TRiga_scadenze(const TRiga_scadenze& s);
|
TRiga_scadenze(const TRiga_scadenze& s);
|
||||||
@ -135,18 +139,21 @@ public:
|
|||||||
bool read(const TBill& clifo, int anno, const char* num);
|
bool read(const TBill& clifo, int anno, const char* num);
|
||||||
bool write(bool re = FALSE);
|
bool write(bool re = FALSE);
|
||||||
bool rewrite() { return write(TRUE); }
|
bool rewrite() { return write(TRUE); }
|
||||||
|
bool remove();
|
||||||
|
|
||||||
int mov2rig(long nreg, int rmov) const;
|
int mov2rig(long nreg, int rmov) const;
|
||||||
int rig2mov(int rmov) const;
|
int rig2mov(int rmov) const;
|
||||||
int prima_fattura() const;
|
int prima_fattura() const;
|
||||||
bool utilizzata(int r) const; // Controlla se esistono pagamenti sommati alla riga r
|
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()); }
|
void conto(TBill& c) const { c.get(_part.key()); }
|
||||||
int anno() const { return _part.key().get_int(PART_ANNO); }
|
int anno() const { return _part.key().get_int(PART_ANNO); }
|
||||||
const TString& numero() const { return _part.key().get(PART_NUMPART); }
|
const TString& numero() const { return _part.key().get(PART_NUMPART); }
|
||||||
const TString& descrizione() const { return _part.key().get(PART_DESCR); }
|
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 update_reg_num(long nreg, const TRectype& mov);
|
||||||
void calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImporto& imp) const;
|
void calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImporto& imp) const;
|
||||||
|
|
||||||
@ -185,7 +192,7 @@ public:
|
|||||||
bool rewrite() { return write(TRUE); }
|
bool rewrite() { return write(TRUE); }
|
||||||
|
|
||||||
int add_reg_num(long numreg, int numrig);
|
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);
|
void update_reg_num(long nreg, const TRectype& mov);
|
||||||
|
|
||||||
TPartita* first() { restart(); return next(); }
|
TPartita* first() { restart(); return next(); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user