From 2fa6b69c434216d8681d4c9171ee0a72ec21f8d5 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 12 Sep 1995 07:58:03 +0000 Subject: [PATCH] Gestione saldaconto in valuta git-svn-id: svn://10.65.10.50/trunk@1813 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- cg/cg2100.cpp | 32 +++++------- cg/cg2100s.uml | 39 ++------------ cg/cg2102.cpp | 69 ++++++++++++------------ cg/cg2102.h | 6 +-- cg/cg2105.cpp | 136 +++++++++++++++++++++++++++++++++++------------- cg/saldacon.cpp | 66 ++++++++++++----------- cg/saldacon.h | 13 +++-- 7 files changed, 200 insertions(+), 161 deletions(-) diff --git a/cg/cg2100.cpp b/cg/cg2100.cpp index d40982544..210d0c19e 100755 --- a/cg/cg2100.cpp +++ b/cg/cg2100.cpp @@ -5,7 +5,7 @@ #include #include -#include "pagament.h" +#include "pagament.h" #include "cg2100.h" #include "cg2102.h" @@ -98,7 +98,6 @@ TMask* TPrimanota_application::load_mask(int n) m->set_handler(FS_RESET, reset_handler); m->set_handler(FS_NRATE, nrate_handler); } - _iva_showed = FALSE; case 1: if (m) { @@ -126,6 +125,7 @@ TMask* TPrimanota_application::load_mask(int n) cgm.set_handler(213, sheet_clifo_handler); cgm.set_handler(313, sheet_clifo_handler); } + _sheet_shown = FALSE; break; case 3: m->set_handler(O_CODICE, occas_code_handler); @@ -347,23 +347,19 @@ bool TPrimanota_application::changing_mask(int mode) if (mode == MODE_QUERY) { const bool flag = _mode != MODE_QUERY; - #if XVT_OS == XVT_OS_WIN - if (flag && _iva != nessuna_iva && !_iva_showed) - { - WINDOW w = ivas().parent(); -#if XVT_OS == 400 - xvt_vobj_set_visible(w, TRUE); - xvt_vobj_raise(w); - xvt_app_process_pending_events(); - xvt_vobj_set_visible(w, FALSE); -#else - show_window(w, TRUE); - set_front_window(w); - process_events(); - show_window(w, FALSE); -#endif - _iva_showed = TRUE; + if (flag && !_sheet_shown) + { + /* + if (iva() != nessuna_iva) + { + curr_mask().show_page(2); + do_events(); + } + */ + curr_mask().show_page(1); + do_events(); + _sheet_shown = TRUE; } #endif return flag; diff --git a/cg/cg2100s.uml b/cg/cg2100s.uml index 40bcadf0c..3b599c40e 100755 --- a/cg/cg2100s.uml +++ b/cg/cg2100s.uml @@ -134,6 +134,7 @@ BEGIN PICTURE "." FIELD IMPORTO VALIDATE REQIF_FUNC 1 S_IMPORTOVAL + WARNING "L'importo deve essere specificato" END NUMBER S_IMPORTOVAL 15 2 @@ -143,6 +144,7 @@ BEGIN FIELD IMPORTOVAL GROUP 3 VALIDATE REQIF_FUNC 1 S_IMPORTO + WARNING "L'importo in valuta deve essere specificato" END NUMBER S_RITENUTE 15 @@ -176,35 +178,6 @@ BEGIN FIELD TIPOPAG END -/* -STRING S_CODPAG 4 -BEGIN - PROMPT 2 11 "Pagamento " - FLAGS "UZ" - USE %CPG - INPUT CODTAB S_CODPAG - DISPLAY "Codice" CODTAB - DISPLAY "Descrizione@50" S0 - DISPLAY "Tipo" I0 - OUTPUT S_CODPAG CODTAB - OUTPUT S_DESPAG S0 - OUTPUT S_TIPOPAG I0 - CHECKTYPE REQUIRED -END - -STRING S_DESPAG 50 -BEGIN - PROMPT 24 11 "" - USE CPG KEY 2 - INPUT S0 S_DESPAG - DISPLAY "Descrizione@50" S0 - DISPLAY "Codice" CODTAB - DISPLAY "Tipo" I0 - COPY OUTPUT S_CODPAG - CHECKTYPE REQUIRED -END -*/ - TEXT DLG_NULL BEGIN PROMPT 2 12 "@bContropartita" @@ -224,16 +197,12 @@ NUMBER S_GRUPPO 3 BEGIN PROMPT 24 12 "Gruppo " FIELD GRUPPOC - CHECKTYPE REQUIRED - FLAGS "R" END NUMBER S_CONTO 3 BEGIN PROMPT 42 12 "Conto " FIELD CONTOC - CHECKTYPE REQUIRED - FLAGS "R" END NUMBER S_SOTTOCONTO 6 @@ -252,8 +221,8 @@ BEGIN OUTPUT S_CONTO CONTO OUTPUT S_SOTTOCONTO SOTTOCONTO OUTPUT S_DESCRCONTO DESCR - CHECKTYPE REQUIRED - FLAGS "R" + CHECKTYPE NORMAL + VALIDATE REQIF_FUNC 1 S_IMPORTO END STRING S_DESCRCONTO 50 diff --git a/cg/cg2102.cpp b/cg/cg2102.cpp index cb8ed48cd..b050c386c 100755 --- a/cg/cg2102.cpp +++ b/cg/cg2102.cpp @@ -210,29 +210,6 @@ int TPrimanota_application::bill_used(const TBill& conto) const return users; } -/* - // Controlla se e' stato usata l'IVA detraibile o indetraibile nelle righe IVA - // Certified 90% - int TPrimanota_application::det_used(char det) const - { - int users = 0; - - const bool detraib = det == 'D'; - TString_array& arr = ivas().rows_array(); - for (int i = 0; i < arr.items(); i++) - { - TToken_string& row = arr.row(i); - if (!row.empty_items()) - { - const bool d = detraibile(row); - if (detraib == d) users++; - } - } - - return users; - } - */ - /////////////////////////////////////////////////////////// // Gestione sheet CG /////////////////////////////////////////////////////////// @@ -518,7 +495,11 @@ bool TPrimanota_application::cg_handler(TMask_field& f, KEY k) const char* ss = saldo.string("."); return f.error_box("Il movimento e' sbilanciato di %s lire.", ss); } - + + const long numreg = f.mask().get_long(F_NUMREG); + const bool paga = app().is_saldaconto() && app().iva() == nessuna_iva ; + TImporto saldaconto; + TSheet_field& cg = app().cgs(); bool empty = TRUE; for (int i = 0; i < cg.items(); i++) @@ -536,25 +517,39 @@ bool TPrimanota_application::cg_handler(TMask_field& f, KEY k) return f.error_box("La contropartita della riga %d non e' completa", i+1); empty = FALSE; - const char tipo = row_type(r); - if (tipo == 'K' && app().iva() == nessuna_iva && app().is_saldaconto()) - { - const long numreg = f.mask().get_long(F_NUMREG); - const int currig = i+1; - 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" - "Si desidera correggerlo?", currig, speso.sezione(), speso.valore().string(".")); - if (ok) app().set_cgs_imp(i, speso); - else return FALSE; + if (paga) + { + const char tipo = row_type(r); + if (tipo == 'K') + { + const int currig = i+1; + const TImporto speso = app().partite().importo_speso(numreg, currig, TRUE); + if (importo != speso) + { + const char* ss = speso.valore().string("."); + return f.error_box("L'importo della riga %d deve essere %s %c", + currig, ss, speso.sezione()); + } } + if (strchr("ACGKP", tipo) != NULL) + saldaconto += importo; } } } + if (paga) + { + real t(f.mask().get(F_TOTALE)); + t -= saldaconto.valore(); + if (!t.is_zero()) + { + const char* ss = saldaconto.valore().string("."); + return f.error_box("Il totale documento deve essere %s", ss); + } + } + if (empty) - return error_box("Il movimento non ha nessuna riga contabile con un importo"); + return f.error_box("Il movimento non ha nessuna riga contabile con un importo"); } return TRUE; } diff --git a/cg/cg2102.h b/cg/cg2102.h index 9c2e898c3..ca1218378 100755 --- a/cg/cg2102.h +++ b/cg/cg2102.h @@ -58,7 +58,7 @@ class TPrimanota_application : public TRelation_application bool _savenew; // Registra e nuovo short _firstfocus; // Primo campo della maschera a prendere il focus - bool _iva_showed; // Lo sheet IVA e' gia' stato visualizzato una volta? + bool _sheet_shown; // Lo sheet IVA e' gia' stato visualizzato una volta? bool _is_saldaconto; // saldaconto si/no (vede parametri e causale) @@ -179,7 +179,6 @@ protected: bool IVA2bill(const TCodiceIVA& iva, TBill& bill); int bill2contr(const TBill& c, char sezione) const; int bill_used(const TBill& conto) const; - int det_used(char detraib) const; TBill& ivas_bill(TBill& tc); bool read_caus(const char* cod, int year); @@ -223,7 +222,6 @@ 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, int deleting = -1); long calcola_m770(int tipo_coll, real& spese, real& compenso, real& iva, real& ritfis); bool link_m770(); @@ -234,6 +232,8 @@ public: TPartite_array& partite() { return _partite; } // Partite editate int nuovo_pagamento(TPartita& p, int nriga, int rata, int rmov); bool edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp); + bool notify_edit_pagamento(TPartita& partita, TRectype& new_pag, + const TValuta& valuta, int deleting = -1); TSheet_field& cgs() const; TSheet_field& ivas() const; diff --git a/cg/cg2105.cpp b/cg/cg2105.cpp index d5842441f..8610f14f4 100755 --- a/cg/cg2105.cpp +++ b/cg/cg2105.cpp @@ -30,17 +30,19 @@ protected: static bool scambio_handler(TMask_field& f, KEY k); static bool edit_scadenza_handler(TMask_field& f, KEY k); 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, int dec = 0); TImporto get_importo(TToken_string& s, int pos) const; - void fill_partite(bool all) const; + void fill_partite() const; real aggiorna_residuo(); void update_partita(const TPartita& game, int prow) const; void update_saldo_clifo() const; bool cerca_valuta(TValuta& val) const; + void aggiorna_valuta(const TValuta& val) const; public: TSheet_field& partite() const { return (TSheet_field&)field(P_PARTITE); } @@ -79,6 +81,7 @@ TGame_mask::TGame_mask(const TBill& bill, long numreg, int riga) set_handler(P_SHOWALL, show_all_handler); set_handler(P_SCAMBIO, scambio_handler); set_handler(P_NUOVO, nuovo_handler); + set_handler(P_CAMBIO, cambio_handler); partite().set_notify(partite_notify); scadenze().sheet_mask().set_handler(100, edit_scadenza_handler); @@ -135,8 +138,7 @@ bool TGame_mask::show_all_handler(TMask_field& f, KEY k) if (k == K_SPACE) { const TGame_mask& gm = (const TGame_mask&)f.mask(); - const bool all = f.get().not_empty(); - gm.fill_partite(all); + gm.fill_partite(); } return TRUE; } @@ -153,6 +155,22 @@ bool TGame_mask::scambio_handler(TMask_field& f, KEY k) return TRUE; } +bool TGame_mask::cambio_handler(TMask_field& f, KEY k) +{ + if (k == K_TAB && f.focusdirty() && + yesno_box("Aggiornare gli importi dei pagamenti?")) + { + const TGame_mask& gm = (const TGame_mask&)f.mask(); + TValuta val; val.get(gm, P_VALUTA, P_DATACAMBIO, P_CAMBIO); + gm.aggiorna_valuta(val); + } + return TRUE; +} + +/////////////////////////////////////////////////////////// +// Metodi dei campi e della maschera principale +/////////////////////////////////////////////////////////// + real TGame_mask::aggiorna_residuo() { TImporto residuo(app().get_cgs_imp(_numrig-1)); @@ -179,6 +197,41 @@ bool TGame_mask::cerca_valuta(TValuta& val) const return found; } +void TGame_mask::aggiorna_valuta(const TValuta& val) const +{ + bool found = FALSE; + + TPartite_array& pa = app().partite(); + for (TPartita* game = pa.first(); game; game = pa.next()) + { + for (int r = game->last(); r > 0; r = game->pred(r)) + { + const TRiga_partite& riga = game->riga(r); + for (int s = riga.rate(); s > 0; s--) + { + const TRiga_scadenze& scad = riga.rata(s); + for (int p = scad.last(); p > 0; p = scad.pred(p)) + { + TRiga_partite& sum = game->riga(p); + if (sum.get_long(PART_NREG) == _numreg && + sum.get_int(PART_NUMRIG) == _numrig) + { + found = TRUE; + TRectype pag(scad.row(p)); + real imp(pag.get(PAGSCA_IMPORTOVAL)); + val.val2lit(imp); + pag.put(PAGSCA_IMPORTO, imp); // Converte in lire l'importo in valuta + app().notify_edit_pagamento(*game, pag, val); + } + } + } + } + } + + if (found) + fill_partite(); +} + bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k) { if (k == K_TAB) @@ -531,8 +584,10 @@ void TGame_mask::update_saldo_clifo() const r << "fornitore"; } -void TGame_mask::fill_partite(bool all) const +void TGame_mask::fill_partite() const { + const bool all = get(P_SHOWALL).not_empty(); + TString_array& a = partite().rows_array(); a.destroy(); @@ -596,6 +651,7 @@ class TPay_mask : public TMask { bool _in_valuta; real _da_pagare; + TValuta _valuta; protected: static bool importo_handler(TMask_field& f, KEY k); @@ -603,6 +659,7 @@ protected: public: void set_pag(const TRectype& oldpag, const TRiga_scadenze& scad); void get_pag(TRectype& oldpag) const; + const TValuta& valuta() const { return _valuta; } TPay_mask(); virtual ~TPay_mask() {} @@ -615,14 +672,14 @@ TPay_mask::TPay_mask() : TMask("cg2100s") void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad) { TRelation rel(LF_PAGSCA); // Working relation - rel.lfile().curr() = oldpag; + rel.curr() = oldpag; autoload(&rel); // Load current record on mask - const TRiga_partite& parbas = scad.riga(); - set(S_NUMDOC, parbas.get(PART_NUMDOC)); // Numero documento - set(S_DATADOC, parbas.get(PART_DATADOC)); // Data documento - set(S_NUMPROT, parbas.get(PART_PROTIVA)); // Protocollo IVA - set(S_DESCR, parbas.get(PART_DESCR)); // Descrizione documento + const TRiga_partite& fatt = scad.riga(); + 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, fatt.get(PART_DESCR)); // Descrizione documento set(S_DATASCAD, scad.get(SCAD_DATASCAD)); // Data della scadenza set(S_SEZIONE_SCAD, scad.riga().sezione()); // Sezione della rata @@ -644,14 +701,17 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad) // Attiva campi relativi alla valuta show(-3, _in_valuta); + const TPartita& p = scad.partita(); + const int nrigp = oldpag.get_int(PAGSCA_NRIGP); + const TRiga_partite& sum = p.riga(nrigp); + + _valuta.get(sum); + // Il flag di saldo/acconto e' attivo solo se non ci sono acconti bool sa = oldpag.get_int(PAGSCA_NRIGA) != TPartita::UNASSIGNED; if (sa) { - const TPartita& p = scad.partita(); - const int nrigp = oldpag.get_int(PAGSCA_NRIGP); - const TRiga_partite& sum = p.riga(nrigp); - const TDate datasca(parbas.get(PART_DATADOC)); + const TDate datasca(fatt.get(PART_DATADOC)); const TDate datapag(sum.get(PART_DATADOC)); sa = datapag >= datasca; } @@ -661,9 +721,9 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad) void TPay_mask::get_pag(TRectype& newpag) const { TRelation rel(LF_PAGSCA); // Working relation - rel.lfile().curr() = newpag; + rel.curr() = newpag; autosave(&rel); // Load current record from mask - newpag = rel.lfile().curr(); + newpag = rel.curr(); } bool TPay_mask::importo_handler(TMask_field& f, KEY k) @@ -684,6 +744,12 @@ bool TPay_mask::importo_handler(TMask_field& f, KEY k) const real residuo(m._da_pagare - i); m.set(S_RESIDUORATA, residuo.string()); + + if (f.dlg() == S_IMPORTOVAL) + { + const real lit = m.valuta().val2lit(i); + m.set(S_IMPORTO, lit.string()); + } } return TRUE; @@ -718,12 +784,10 @@ bool TPrimanota_application::showpartite_handler(TMask_field& f, KEY k) 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); + { + const char* ss = speso.valore().string("."); + return f.error_box("L'importo deve essere %s %c", ss, speso.sezione()); } } } @@ -857,7 +921,7 @@ int TPrimanota_application::nuovo_pagamento(TPartita& partita, int nriga, int ra { TRelation cliforel(LF_CLIFO); cliforel.add(LF_CFVEN, "TIPOCF=TIPOCF|CODCF=CODCF"); - TRectype& clifo = cliforel.lfile().curr(); + TRectype& clifo = cliforel.curr(); clifo.put(CLI_TIPOCF, conto.tipo()); clifo.put(CLI_CODCF, conto.codclifo()); @@ -873,7 +937,8 @@ int TPrimanota_application::nuovo_pagamento(TPartita& partita, int nriga, int ra } -bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pag, int deleting) +bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pag, + const TValuta& valuta, int deleting) { if (deleting != 0) { @@ -936,7 +1001,7 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa char old_ap, new_ap; TImporto old_abbuono, new_abbuono, old_diffcam, new_diffcam; - const bool empty = p.modifica_pagamento(new_pag, + const bool empty = p.modifica_pagamento(new_pag, valuta, old_ap, old_abbuono, old_diffcam, new_ap, new_abbuono, new_diffcam); @@ -985,7 +1050,9 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa if (old_diffcam != new_diffcam) { const int riga_diffcam = type2pos('C'); - TImporto grow_diffcam(new_diffcam); grow_diffcam -= old_diffcam; + TImporto grow_diffcam(new_diffcam); + grow_diffcam -= old_diffcam; + grow_diffcam.normalize(); if (riga_diffcam < 0) { @@ -1044,16 +1111,14 @@ bool TPrimanota_application::edit_pagamento(TPartita& p, int nriga, int nrata, i m.reset(S_RITENUTE); // Azzera ritenute } else -{ somma.put(PART_DESCR, m.get(S_DESCAGG)); // Aggiorna descrizione (comune ai pagamenti) -} -TRectype new_pag(oldpag); -m.get_pag(new_pag); -notify_edit_pagamento(p, new_pag); -} - -return key != K_ESC; + TRectype new_pag(oldpag); + m.get_pag(new_pag); + const TValuta val; // Non cambiare valuta! + notify_edit_pagamento(p, new_pag, val); + } + return key != K_ESC; } @@ -1080,8 +1145,9 @@ bool TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg TRectype pag(scad.row(s)); pag.zero(PAGSCA_IMPORTO); pag.zero(PAGSCA_IMPORTOVAL); - pag.zero(PAGSCA_RITENUTE); - notify_edit_pagamento(partita, pag, numrig); + pag.zero(PAGSCA_RITENUTE); + const TValuta val; // Non cambiare valuta + notify_edit_pagamento(partita, pag, val, numrig); found = TRUE; } } diff --git a/cg/saldacon.cpp b/cg/saldacon.cpp index 41390ad79..0fa2d4fc6 100755 --- a/cg/saldacon.cpp +++ b/cg/saldacon.cpp @@ -122,6 +122,14 @@ void TValuta::adjust() _cam = 1.0; } +int TValuta::compare(const TSortable& s) const +{ + const TValuta& v = (const TValuta&)s; + real c(_cam); c -= v._cam; + return c.sign(); +} + + void TValuta::get(const TRectype& rec) { _cod = rec.get("CODVAL"); @@ -258,8 +266,8 @@ TImporto TRiga_scadenze::importo_pagato(bool val, int mode) const TImporto TRiga_scadenze::importo_da_pagare(bool val) const { const char* imp_field = (val && in_valuta()) ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO; - const TRiga_partite& r = riga(); // Riga fattura - const TImporto totale(r.sezione(), get_real(imp_field)); + const TRiga_partite& fatt = riga(); // Riga fattura + const TImporto totale(fatt.sezione(), get_real(imp_field)); return totale; } @@ -313,11 +321,13 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(int p, bool update) diffcam = importo_da_pagare(FALSE); diffcam += importo_pagato(FALSE, 0x3); // Conta anche gli abbuoni diffcam.normalize(sez); - pag.put(PAGSCA_DIFFCAM, diffcam.valore()); + + const TImporto gir(sez, -diffcam.valore()); + pag.put(PAGSCA_DIFFCAM, gir.valore()); } else - { - diffcam.set(sez, pag.get_real(PAGSCA_DIFFCAM)); + { + diffcam.set(sez, -pag.get_real(PAGSCA_DIFFCAM)); } } else @@ -336,10 +346,11 @@ TImporto TRiga_scadenze::residuo(bool val, int mode) const } -bool TRiga_scadenze::modifica_pagamento(const TRectype& new_pag, +bool TRiga_scadenze::modifica_pagamento(const TRectype& new_pag, const TValuta& valuta, char& old_ap, TImporto& old_abb, TImporto& old_diffcam, char& new_ap, TImporto& new_abb, TImporto& new_diffcam) { + const bool in_val = in_valuta(); const int nrigp = new_pag.get_int(PAGSCA_NRIGP); const TRectype old_pag(row(nrigp)); TRiga_partite& sum = partita().riga(nrigp); @@ -347,14 +358,16 @@ bool TRiga_scadenze::modifica_pagamento(const TRectype& new_pag, TImporto old_abbuono; old_ap = calcola_abbuono(nrigp, old_abbuono); // Vecchio abbuono in valuta old_abb = old_abbuono; // Vecchio abbuono in lire - if (in_valuta()) + if (in_val) { old_abb.valore() *= sum.get_real(PART_CAMBIO); old_abb.valore().round(); } - old_diffcam = calcola_differenza_cambio(nrigp, FALSE); + if (in_val && !valuta.in_lire()) + valuta.put(sum); + row(nrigp) = new_pag; row(nrigp).zero(PAGSCA_ABBUONI); // Azzera abbuoni per ricalcolo row(nrigp).zero(PAGSCA_DIFFCAM); // Azzera differenza cambio per ricalcolo @@ -390,8 +403,8 @@ bool TRiga_scadenze::modifica_pagamento(const TRectype& new_pag, partita().chiusa(TRUE); // Aggiorna flag di chiusura - const bool empty = new_pag.get(PAGSCA_IMPORTO).empty() || - new_pag.get(PAGSCA_ABBUONI).empty() || + const bool empty = new_pag.get(PAGSCA_IMPORTO).empty() && + new_pag.get(PAGSCA_ABBUONI).empty() && new_pag.get(PAGSCA_DIFFCAM).empty(); if (empty) rows_array().destroy_row(nrigp); @@ -403,7 +416,8 @@ bool TPartita::modifica_pagamento(const TRectype& new_pag) { char old_ap, new_ap; TImporto old_abbuono, new_abbuono, old_diffcam, new_diffcam; - return modifica_pagamento(new_pag, + TValuta valuta; + return modifica_pagamento(new_pag, valuta, old_ap, old_abbuono, old_diffcam, new_ap, new_abbuono, new_diffcam); } @@ -621,25 +635,19 @@ TImporto TPartita::importo_speso(long nreg, int numrig, bool extra) const for (int r = last(); r > 0; r = pred(r)) { const TRiga_partite& part = riga(r); - const long reg = part.get_long(PART_NREG); - if (reg == nreg) + if (nreg == part.get_long(PART_NREG) && numrig == part.get_int(PART_NUMRIG)) { - const int num = part.get_int(PART_NUMRIG); - if (num == numrig) - { - imp += TImporto(part.sezione(), part.get_real(PART_IMPORTO)); - - if (extra) + imp += TImporto(part.sezione(), part.get_real(PART_IMPORTO)); + if (extra) + { + TImporto abbuoni(part.get_char(PART_SEZABB), part.get_real(PART_ABBUONI)); + if (part.in_valuta()) { - TImporto abbuoni(part.get_char(PART_SEZABB), part.get_real(PART_ABBUONI)); - if (part.in_valuta()) - { - abbuoni.valore() *= part.get_real(PART_CAMBIO); - abbuoni.valore().round(); - } - imp += abbuoni; + abbuoni.valore() *= part.get_real(PART_CAMBIO); + abbuoni.valore().round(); imp += TImporto(part.get_char(PART_SEZDIFCAM), part.get_real(PART_DIFFCAM)); - } + } + imp += abbuoni; } } } @@ -777,7 +785,7 @@ bool TPartita::utilizzata(int nrigp) const return _unassigned.exist(nrigp); } -bool TPartita::modifica_pagamento(const TRectype& new_pag, +bool TPartita::modifica_pagamento(const TRectype& new_pag, const TValuta& valuta, char& old_ap, TImporto& old_abb, TImporto& old_diffcam, char& new_ap, TImporto& new_abb, TImporto& new_diffcam) { @@ -790,7 +798,7 @@ bool TPartita::modifica_pagamento(const TRectype& new_pag, if (nriga != UNASSIGNED) { TRiga_scadenze& scaden = rata(nriga, nrata); - empty = scaden.modifica_pagamento(new_pag, + empty = scaden.modifica_pagamento(new_pag, valuta, old_ap, old_abb, old_diffcam, new_ap, new_abb, new_diffcam); } diff --git a/cg/saldacon.h b/cg/saldacon.h index f98071aa0..5c2209b70 100755 --- a/cg/saldacon.h +++ b/cg/saldacon.h @@ -63,7 +63,7 @@ public: // Valuta /////////////////////////////////////////////////////////// -class TValuta : public TObject +class TValuta : public TSortable { TString16 _cod; TDate _dat; @@ -71,7 +71,10 @@ class TValuta : public TObject protected: void adjust(); // Controlla il cambio per le lire - + +protected: // TSortable + virtual int compare(const TSortable& s) const; + public: const TString& codice() const { return _cod; } const TDate& data() const { return _dat; } @@ -81,6 +84,7 @@ public: real val2lit(const real& val) const; void val2lit(real& val) const; void val2lit(TImporto& imp) const; + bool in_lire() const { return _cam == 1.0; } void get(const TRectype& rec); void put(TRectype& rec) const; @@ -90,6 +94,7 @@ public: TValuta(); TValuta(const char* cod, const TDate& dat, const real& cam); + TValuta(const TRectype& rec) { get(rec); } virtual ~TValuta() {} }; @@ -110,7 +115,7 @@ protected: char calcola_abbuono(int p, TImporto& abbuono) const; TImporto calcola_differenza_cambio(int p, bool update); - bool modifica_pagamento(const TRectype& new_pag, + bool modifica_pagamento(const TRectype& new_pag, const TValuta& valuta, char& old_ap, TImporto& old_abb, TImporto& old_diffcam, char& new_ap, TImporto& new_abb, TImporto& new_diffcam); @@ -213,7 +218,7 @@ public: void update_reg(long nreg, const TRectype& mov); void calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImporto& imp) const; - bool modifica_pagamento(const TRectype& new_pag, + bool modifica_pagamento(const TRectype& new_pag, const TValuta& valuta, char& old_ap, TImporto& old_abb, TImporto& old_diffcam, char& new_ap, TImporto& new_abb, TImporto& new_diffcam); bool modifica_pagamento(const TRectype& new_pag);