From 66f71504ffae142bd241732e5a7dc041d1c2bf6a Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 7 Feb 1996 11:51:14 +0000 Subject: [PATCH] Corretta gestione cambio git-svn-id: svn://10.65.10.50/trunk@2580 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- cg/cg2100.cpp | 3 +- cg/cg2100p.uml | 4 +- cg/cg2102.cpp | 8 +-- cg/cg2104.cpp | 71 ++++++++++++++++--------- cg/cg2105.cpp | 2 +- cg/cg21rata.uml | 1 + cg/pagament.cpp | 136 ++++++++++++++++++++++-------------------------- cg/pagament.h | 8 +-- cg/saldacon.cpp | 18 +++---- 9 files changed, 130 insertions(+), 121 deletions(-) diff --git a/cg/cg2100.cpp b/cg/cg2100.cpp index 2a355cb70..0f3aba58f 100755 --- a/cg/cg2100.cpp +++ b/cg/cg2100.cpp @@ -715,7 +715,8 @@ int TPrimanota_application::read(TMask& m) calcola_imp(); // Calcola totale imponibile ed imposte if (is_fattura()) // Ci dovrebbero essere delle scadenze - { + { + pags().reset(); // Azzera sheet rate if (!read_scadenze(m)) // Se non esiste fattura { const TString dd(m.get(F_DATADOC)); diff --git a/cg/cg2100p.uml b/cg/cg2100p.uml index ac494dd92..e8fbeaa43 100755 --- a/cg/cg2100p.uml +++ b/cg/cg2100p.uml @@ -112,8 +112,8 @@ BEGIN ITEM "Num. doc." ITEM "Prot. IVA" ITEM "Tipo" - ITEM "Pagamento" - ITEM "Bloccata" + ITEM "Riga pag." + ITEM "Blocc." FLAGS "D" END diff --git a/cg/cg2102.cpp b/cg/cg2102.cpp index 08b2a2b20..97407c73d 100755 --- a/cg/cg2102.cpp +++ b/cg/cg2102.cpp @@ -602,7 +602,7 @@ bool TPrimanota_application::cg_handler(TMask_field& f, KEY k) return FALSE; } } - if (strchr("ACGKP", tipo) != NULL) + if (strchr("ACGKPT", tipo) != NULL) { saldaconto += importo; if (in_valuta) @@ -616,7 +616,7 @@ bool TPrimanota_application::cg_handler(TMask_field& f, KEY k) return f.error_box("Il movimento non ha nessuna riga contabile con un importo"); - if (paga) + if (paga || nota) { const char sez(a.causale().sezione(2)); const TImporto totdoc(sez, m.get_real(F_TOTALE)); @@ -2393,10 +2393,6 @@ bool TPrimanota_application::activate_numrif(bool init_pag) const TString16 dt(m.get(F_DATADOC)); set_pagamento(NULL, dt); // Reset pagamento set_totale_pagamento(); - - TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET); - pagamento().set_sheet(ps); // Aggiorna lo sheet - pag_rows() = ps.rows_array(); // copia sheet } else set_scadenze(m); // Inizializza pagamento diff --git a/cg/cg2104.cpp b/cg/cg2104.cpp index cab251c0e..18bc862b5 100755 --- a/cg/cg2104.cpp +++ b/cg/cg2104.cpp @@ -486,8 +486,7 @@ bool TPrimanota_application::cambio_handler(TMask_field& f, KEY key) if (a.is_fattura()) { TPagamento& pag = a.pagamento(); - const real ex(f.get()); - pag.set_cambio(ex, m.get_bool(FS_RECALC)); // Aggiorna cambio sul pagamento +// pag.set_cambio(m, m.get_bool(FS_RECALC)); // Aggiorna cambio sul pagamento update = TRUE; TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET); @@ -629,12 +628,12 @@ bool TPrimanota_application::ratalit_handler(TMask_field& f, KEY key) { if (key == K_F8 || (key == K_TAB && f.get().empty())) { - TPagamento& pag = app().pagamento(); + const TPagamento& pag = app().pagamento(); if (pag.in_valuta()) { - TValuta v("VAL", TDate(), pag.cambio()); + const TValuta v(app().curr_mask(), FS_VALUTA, FS_DATACAMBIO, FS_CAMBIO); const real other(f.mask().get(103)); - TString16 s(v.val2lit(other).string()); + const char* s = v.val2lit(other).string(); f.set(s); } } @@ -648,7 +647,7 @@ bool TPrimanota_application::rataval_handler(TMask_field& f, KEY key) TPagamento& pag = app().pagamento(); if (pag.in_valuta()) { - TValuta v("VAL", TDate(), pag.cambio()); + const TValuta v(app().curr_mask(), FS_VALUTA, FS_DATACAMBIO, FS_CAMBIO); const real other(f.mask().get(102)); TString16 s(v.lit2val(other).string()); f.set(s); @@ -689,27 +688,32 @@ void TPrimanota_application::set_pagamento(const char* c, const char* d) void TPrimanota_application::set_totale_pagamento() { - real imponibile, imposta; - const real spese(0.0); - const TMask& m = curr_mask(); TPagamento& pag = pagamento(); - real cambio = m.get_real(SK_CAMBIO); - if (!cambio.is_zero()) - { - imposta = m.get_real(F_IMPOSTE); - real imposval = imposta/cambio; imposval.round(3); - real imponval = m.get_real(SK_TOTDOCVAL) - imposval; - imponibile = m.get_real(F_TOTALE) - imposta; - pag.set_total_valuta(imponval, imposval, spese, cambio, imponibile, imposta, spese); + const real imposta = m.get_real(F_IMPOSTE); + const real imponibile = m.get_real(F_TOTALE) - imposta; + const real spese = ZERO; + + const TValuta cambio(m, SK_VALUTA, SK_DATACAMBIO, SK_CAMBIO); + if (cambio.in_valuta()) + { + const real imposval = cambio.val2lit(imposta); + const real imponval = m.get_real(SK_TOTDOCVAL) - imposval; + pag.set_total_valuta(imponval, imposval, spese, cambio.cambio(), + imponibile, imposta, spese); } else { - imposta = m.get_real(F_IMPOSTE); - imponibile = m.get_real(F_TOTALE) - imposta; pag.set_total(imponibile, imposta, spese); } + + if (m.is_running()) + { + TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET); + pagamento().set_sheet(ps); // Aggiorna lo sheet + pag_rows() = ps.rows_array(); // copia sheet + } } void TPrimanota_application::set_scadenze(TMask& m) @@ -1182,7 +1186,8 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa bool TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg, int numrig) { bool found = FALSE; - + + // Al primo "giro" elimino i pagamenti dalla rate for (int p = partita.last(); p > 0; p = partita.pred(p)) { TRiga_partite& part = partita.riga(p); @@ -1209,13 +1214,9 @@ bool TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg } } } - else - { - if (numrig > 0 && part.get_long(PART_NREG) == nreg && part.get_int(PART_NUMRIG) > numrig) - part.put(PART_NUMRIG, numrig-1); - } } - + + // Alla fine del "giro" elimino i pagamenti non assegnati TRecord_array& unas = partita.unassigned(); for (int u = unas.last_row(); u > 0; u = unas.pred_row(u)) { @@ -1234,6 +1235,24 @@ bool TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg } } + // Al secondo "giro" decremento NRIGP dalle righe di pagamento + if (numrig > 0) + { + for (p = partita.last(); p > 0; p = partita.pred(p)) + { + TRiga_partite& part = partita.riga(p); + if (!part.is_fattura()) + { + if (part.get_long(PART_NREG) == nreg) + { + const int nr = part.get_int(PART_NUMRIG); + if (nr > numrig) + part.put(PART_NUMRIG, nr-1); + } + } + } + } + return found; } diff --git a/cg/cg2105.cpp b/cg/cg2105.cpp index d7668116d..a749daccb 100755 --- a/cg/cg2105.cpp +++ b/cg/cg2105.cpp @@ -1473,7 +1473,7 @@ void TGame_mask::fill_partite() const TRectype filter(curpar); // Record campione - for (int err = partita.read(_isgteq); + for (int err = partita.read(_isgreat); err == NOERR && curpar == filter; err = partita.read(_isgreat)) { diff --git a/cg/cg21rata.uml b/cg/cg21rata.uml index b5ed64754..e43f13baf 100755 --- a/cg/cg21rata.uml +++ b/cg/cg21rata.uml @@ -4,6 +4,7 @@ DATE 101 BEGIN PROMPT 1 1 "Scadenza " CHECKTYPE REQUIRED + WARNING "La data di scadenza e' obbligatoria" END NUMBER 102 15 diff --git a/cg/pagament.cpp b/cg/pagament.cpp index 0319490d8..8f0ef0a0a 100755 --- a/cg/pagament.cpp +++ b/cg/pagament.cpp @@ -2,13 +2,14 @@ #include #include "pagament.h" +#include "cg2100.h" + #include #include #include #include -// se settato, si usa per rate nuove l'intervallo rate default (letto da -// tab. pagamenti) +// se settato, si usa per rate nuove l'intervallo rate default (letto da tab. pagamenti) #define USE_DEFAULT_INT_RATE 1 inline void swap(int& x, int& y) {int tmp = x; x = y; y = tmp; } @@ -430,82 +431,65 @@ void TPagamento::set_numero_rate(int n, int sscad, int rdiff) _dirty = TRUE; } -void TPagamento::set_cambio(const real& cambio, bool recalc_lit) +void TPagamento::set_cambio(const TMask& m, bool recalc_lit) { const int first = _tpr < 4 ? 0 : 1; const bool era_valuta = in_valuta(); - - if (cambio.sign() <= 0) + + _cambio = m.get_real(SK_CAMBIO); + if (_cambio.sign() <= 0) _cambio = 1.0; - else - _cambio = cambio; - const bool in_valuta = _cambio != 1.0; + const bool in_val = m.get(SK_VALUTA).not_empty(); real imp; // Importo di parcheggio if (era_valuta) - { - for (int i = _rate.items()-1; i >= 0; i--) - { - TToken_string& row = (TToken_string&)_rate[i]; - if (in_valuta) - { - if (recalc_lit) - { - imp = tval_rata(i) * _cambio; imp.round(0); - row.add(imp.string(), 7); - } - } - else row.add("", 7); - } - - if (!in_valuta) + { + if (in_val) // Da valuta a valuta { - real imponibile = _imponval * _cambio; imponibile.round(_roundlit); - real imposta = _imposval * _cambio; imposta.round(_roundlit); - real spese = _speseval * _cambio; spese.round(_roundlit); - set_total(imponibile, imposta, spese); + if (recalc_lit) + adjust_perc_imp(TRUE, _rdiff, FALSE); + } + else // Da valuta a lire + { + _firstr = _secndr = ZERO; + for (int i = _rate.items()-1; i >= 0; i--) + set_imprata(i, ZERO, TRUE); } } else { - if (in_valuta) + if (in_val) // Da lire a valuta { - for (int i = _rate.items()-1; i >= 0; i--) - { - TToken_string& row = (TToken_string&)_rate[i]; - imp = tlit_rata(i); - imp /= cambio; imp.round(_roundval); - row.add(imp.string() , 4); - } - - real imponibile = _imponlit / _cambio; imponibile.round(_roundval); + real imponibile = m.get(SK_TOTDOCVAL); real imposta = _imposlit / _cambio; imposta.round(_roundval); real spese = _speselit / _cambio; spese.round(_roundval); - set_total(imponibile, imposta, spese, TRUE); + init_total(imponibile, imposta, spese, TRUE); + adjust_perc_imp(TRUE, _rdiff, TRUE); } } -// if (in_valuta) adjust_importo_lire(0); } - -//void TPagamento::adjust_importo_lire(int start) -//{ -// if (!in_valuta()) return; -// const int first = _tpr < 4 ? 0 : 1; -// if (start == 0) start = first; -// -// real totlit; -// real implit = importo_da_dividere(FALSE) + importo_da_non_dividere(FALSE); -// for (int i = 0; i < n_rate(); i++) -// totlit += tlit_rata(i); -// real residuo = implit - totlit; -// if (!residuo.is_zero()) -// { -// real rs = tlit_rata(start) + residuo; -// rata(start).add(rs.string(), 7); -// } -//} + +/* +void TPagamento::adjust_importo_lire(int start) +{ + if (!in_valuta()) return; + const int first = _tpr < 4 ? 0 : 1; + if (start == 0) start = first; + + real totlit; + real implit = importo_da_dividere(FALSE) + importo_da_non_dividere(FALSE); + for (int i = 0; i < n_rate(); i++) + totlit += tlit_rata(i); + real residuo = implit - totlit; + if (!residuo.is_zero()) + { + real rs = tlit_rata(start) + residuo; + rata(start).add(rs.string(), 7); + } +} +*/ void TPagamento::next_scad(TDate& d, int scad, bool mcomm, int rata) { @@ -1723,33 +1707,38 @@ const real& TPagamento::importo_da_non_dividere(bool v) const if (_tpr < 4) return v ? _secndr : _secndl; else return v ? _firstr : _firstl; } + +void TPagamento::set_total(const real& ib, const real& im, const real& sp) +{ + _in_valuta = FALSE; + _cambio = 1.0; + + _firstr = _secndr = ZERO; // Azzera importi in valuta + init_total(ib, im, sp, FALSE); // setta regolarmente totali in lire +} void TPagamento::set_total_valuta(const real& ib, const real& im, const real& sp, const real& c, const real& ibl, const real& iml, const real& spl) { + const bool era_valuta = _in_valuta; + _in_valuta = TRUE; _cambio = c; if (_cambio.sign() <= 0) _cambio = real(1.0); // setta regolarmente totali in lire - set_total(ibl, iml, spl); + init_total(ibl, iml, spl, FALSE); // ripeti tutto con la valuta - set_total(ib, im, sp, TRUE); + init_total(ib, im, sp, TRUE); + + if (!era_valuta && _in_valuta) + adjust_perc_imp(TRUE, _rdiff, TRUE); } - -bool TPagamento::in_valuta() const -{ - return _inited ? - (!(_firstr.is_zero() && _secndr.is_zero()) && !_firstl.is_zero()) : - FALSE; -} - - -void TPagamento::set_total(const real& ib, const real& im, const real& sp, bool valuta) +void TPagamento::init_total(const real& ib, const real& im, const real& sp, bool valuta) { - int round = valuta ? _roundval : _roundlit; + const int round = valuta ? _roundval : _roundlit; real& ibp = valuta ? _imponval : _imponlit; real& imp = valuta ? _imposval : _imposlit; real& spp = valuta ? _speseval : _speselit; @@ -1828,7 +1817,7 @@ void TPagamento::set_sheet(TSheet_field& sf, int sscad) { TToken_string& ts = sf.row(i); - ts.add((const char*)data_rata(i), 0); // 0 - Data scadenza + ts.add(data_rata(i), 0); // 0 - Data scadenza if (in_valuta()) { ts.add(tlit_rata(i).string(), 1); // 1 - Importo in lire @@ -1934,7 +1923,8 @@ void TPagamento::adjust_fixed_scad() TPagamento::TPagamento(const char* codtab, const char* data) : _slicerlit(0.0,0), _slicerval(0.0,0), _new(FALSE), _mcomm(FALSE), _imponlit(0.0), _imposlit(0.0), - _speselit(0.0), _cambio(1.0), _code(codtab), _dirty(FALSE), _inited(FALSE), + _speselit(0.0), _cambio(1.0), _in_valuta(FALSE), + _code(codtab), _dirty(FALSE), _inited(FALSE), _def_tpr(1), _def_ulc(""), _roundval(3), _int_rate(30), _tpr(0), _rdiff(FALSE), _was_tpr4(FALSE), _roundlit(0), _imponval(0.0), _imposval(0.0), _speseval(0.0) { diff --git a/cg/pagament.h b/cg/pagament.h index 06920e576..ab8bdc5be 100755 --- a/cg/pagament.h +++ b/cg/pagament.h @@ -85,6 +85,8 @@ protected: word change_value_uguali_prossima(int rata, real value, bool is_perc, bool v); word change_value_uguali_possible(int rata, real value, bool is_perc, bool v); + void init_total(const real& ib, const real& im, const real& sp, bool valuta); + // aggiusta parametri diversi da importo se si sono aggiunte rate void adjust_parameters(bool mcomm); // riaggiusta le percentuali o gli importi rispetto al dato modificato @@ -160,9 +162,9 @@ public: void set_inizio_scadenza(char v) { _inscad = v; } void set_code(const char* c) { _code = c; } void set_roundval(int n) { _roundval = n; } - void set_cambio(const real& ex, bool recalc_lit); + void set_cambio(const TMask& m, bool recalc_lit); - bool in_valuta() const; + bool in_valuta() const { return _in_valuta; } const real& cambio() const { return _cambio; } // check consistency: returns word with errors flagged, 0 if ok @@ -207,7 +209,7 @@ public: void set_imprata(int i, const real& r, bool val); // only one of these must be called - void set_total(const real& ib, const real& im, const real& sp, bool valuta = FALSE); + void set_total(const real& ib, const real& im, const real& sp); void set_total_valuta(const real& ib, const real& im, const real& sp, const real& cambio, const real& ibl, const real& iml, const real& spl); diff --git a/cg/saldacon.cpp b/cg/saldacon.cpp index 02f244601..5a00350b0 100755 --- a/cg/saldacon.cpp +++ b/cg/saldacon.cpp @@ -1673,18 +1673,18 @@ int TPartite_array::add_numreg(long nreg) { if (nreg != _numreg) { - TRelation rel(LF_PARTITE); + TLocalisamfile rel(LF_PARTITE); + rel.setkey(2); // Chiave per NREG + TRectype& part = rel.curr(); - - // Costruzione cursore filtrato - part.zero(); + part.zero(); part.put(PART_NREG, nreg); - const TRectype filter(part); - TCursor cur(&rel, "", 2, &filter, &filter); - - for (cur = 0; cur.ok(); ++cur) + for (int err = rel.read(_isgreat); + err == NOERR && part.get_long(PART_NREG) == nreg; + err = rel.next()) + { partita(part); // Aggiungi partita se non esiste gia' - + } _numreg = nreg; }