diff --git a/cg/cg2102.h b/cg/cg2102.h index 5a8f5da7a..35c438cf3 100755 --- a/cg/cg2102.h +++ b/cg/cg2102.h @@ -122,7 +122,6 @@ class TPrimanota_application : public TRelation_application static bool ratalit_handler(TMask_field& f, KEY key); static bool rataval_handler(TMask_field& f, KEY key); - static bool iva_notify(TSheet_field& s, int r, KEY key); static bool iva_handler(TMask_field& f, KEY key); static bool cg_notify(TSheet_field& s, int r, KEY key); @@ -226,7 +225,7 @@ protected: void set_pagamento(const char* c, const char* d); void set_totale_pagamento(); - void reset_pagamento(TMask& m); + void reset_pagamento(); void set_scadenze(TMask& m); bool read_scadenze(TMask& m); void write_scadenze(const TMask& m); diff --git a/cg/cg2104.cpp b/cg/cg2104.cpp index 10ea86f75..805c0d1ac 100755 --- a/cg/cg2104.cpp +++ b/cg/cg2104.cpp @@ -23,6 +23,7 @@ TPagamento& TPrimanota_application::pagamento() const CHECK(_pag, "Pagamento nullo"); return *_pag; } + bool TPrimanota_application::pag_notify(TSheet_field& ps, int r, KEY k) { TPagamento& pag = app().pagamento(); @@ -484,7 +485,7 @@ bool TPrimanota_application::reset_handler(TMask_field& f, KEY key) if (key == K_SPACE) { TMask& m = f.mask(); - app().reset_pagamento(m); + app().reset_pagamento(); app().set_scadenze(m); } return TRUE; @@ -494,12 +495,66 @@ bool TPrimanota_application::recalc_handler(TMask_field& f, KEY key) { if (key == K_SPACE) { - const bool recalc_aut = f.get().not_empty(); - const TMask& m = f.mask(); + // disclaimer: aver bisogno di mangiare significa anche fare + // cose come quella che segue + // ---------------------------------------------------- + // sembra dunque intollerabile che non si sia gia' pensato + // a questo: se c'era il ricalcolo e lo si toglie, il pagamento + // di tipo > 3 diventa del corrispondente tipo > 1 e < 3, in quanto + // cosi' la modifica della percentuale sulla prima rata puo' + // essere correttamente eseguita + // cio' implica, evidentemente, che si memorizzi non solo il + // nuovo tpr ma anche il fatto che lo si e' cambiato, in quanto + // se si riattiva il ricalcolo occorre rimetterlo come era + // in precedenza, aggiungendo (su conferma) un pompino + // di emergenza salvaguai al gentile cliente + // --------------------------------------------------------- + TMask& m = f.mask(); TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET); + TPagamento& pag = app().pagamento(); + + const bool recalc_aut = f.get().not_empty(); + + if (!recalc_aut && pag.tipo_prima_rata() > 3) + { + // SE CAMBIANO I SIGNIFICATI DEL TIPO PRIMA RATA BISOGNA RIFARE TUTTO + pag.set_tipo_prima_rata(pag.tipo_prima_rata() - 3); + m.set(FS_TIPOPR, pag.desc_tpr()); + pag.set_tpr4(TRUE); + } + else if (recalc_aut && pag.was_tpr4()) + { + // SE CAMBIANO I SIGNIFICATI DEL TIPO PRIMA RATA BISOGNA RIFARE TUTTO + pag.set_tpr4(FALSE); + bool yak = pag.tpay_rata(0) != pag.importo_da_non_dividere(); + if (yak) + { + if (yesno_box("L'importo della prima rata e' stato modificato. " + "Con il ricalcolo automatico esso non sara' piu'" + " modificabile. Si desidera " +#ifdef DBG + "un sapiente pompino?")) +#else + "riportare le rate alle condizioni iniziali?")) +#endif + { + pag.set_tipo_prima_rata(pag.tipo_prima_rata() + 3); + m.set(FS_TIPOPR, pag.desc_tpr()); + app().reset_pagamento(); + app().set_scadenze(m); + } + else warning_box("Il tipo prima rata rimane modificato in %s", + pag.desc_tpr()); + } + else + { + pag.set_tipo_prima_rata(pag.tipo_prima_rata() + 3); + m.set(FS_TIPOPR, pag.desc_tpr()); + } + } + ps.enable_column(3, recalc_aut); ps.sheet_mask().enable(DLG_DELREC, !recalc_aut); - TPagamento& pag = app().pagamento(); const bool on = pag.tipo_prima_rata() < 4 || !recalc_aut; ps.enable_cell(0, 1, on); ps.enable_cell(0, 2, on); @@ -582,7 +637,7 @@ bool TPrimanota_application::rataval_handler(TMask_field& f, KEY key) return TRUE; } -void TPrimanota_application::reset_pagamento(TMask&) +void TPrimanota_application::reset_pagamento() { TPagamento& pag = pagamento(); pag.read(); diff --git a/cg/pagament.cpp b/cg/pagament.cpp index ab65abf4e..cf94bc783 100755 --- a/cg/pagament.cpp +++ b/cg/pagament.cpp @@ -126,19 +126,20 @@ void TPagamento::set_tipo_prima_rata(int v, int sscad) _dirty = FALSE; if (_tpr == v) return; - if (v < 4 && _tpr > 3) + if (!_inited) { - for (int i = n_rate() - 1; i > 0; i--) + if (v < 4 && _tpr > 3) { - TToken_string& tt = rata(i); - tt.add(scad_rata(i-1),0); - tt.add(tipo_rata(i-1),2); - tt.add(ulc_rata(i-1),5); + for (int i = n_rate() - 1; i > 0; i--) + { + TToken_string& tt = rata(i); + tt.add(scad_rata(i-1),0); + tt.add(tipo_rata(i-1),2); + tt.add(ulc_rata(i-1),5); + } + _rate.destroy(0, TRUE); } - _rate.destroy(0, TRUE); - } - else - if ( _tpr < 4 && v > 3) + else if ( _tpr < 4 && v > 3) { TToken_string* ttn = new TToken_string(32); ttn->add(0, 0); @@ -146,7 +147,7 @@ void TPagamento::set_tipo_prima_rata(int v, int sscad) ttn->add(1, 2); ttn->add("", 3); ttn->add("", 4); - ttn->add("", 5); + ttn->add("", 5); _rate.insert(ttn,0); for (int i = 0; i < (n_rate()-1); i++) { @@ -161,7 +162,18 @@ void TPagamento::set_tipo_prima_rata(int v, int sscad) TToken_string& tt = rata(1); tt.add(_int_rate, 0); } - } + } + } + else + { + if ((_tpr > 3 && (v > 0 && v < 3)) || (v > 3 && (_tpr > 0 && _tpr < 3))) + { + // swap _firstr and _secndr + real tmp(_firstr); + _firstr = _secndr; + _secndr = tmp; + } + } _tpr = v; _dirty = TRUE; } @@ -1573,7 +1585,17 @@ void TPagamento::set_rate_auto() main_app().end_wait(); } +const real& TPagamento::importo_da_dividere() const +{ + if (_tpr < 4) return _firstr; + else return _secndr; +} +const real& TPagamento::importo_da_non_dividere() const +{ + if (_tpr < 4) return _secndr; + else return _firstr; +} void TPagamento::set_total(const real& imponibile, const real& imposta, const real& spese) { @@ -1761,7 +1783,8 @@ void TPagamento::adjust_fixed_scad() TPagamento::TPagamento(const char* codtab, const char* data) : _slicer(0.0,0), _new(FALSE), _mcomm(FALSE), _imponibile(0.0), _imposta(0.0), _spese(0.0), _cambio(1.0), _code(codtab), _dirty(FALSE), _inited(FALSE), -_def_tpr(1), _def_ulc(""), _round(0), _int_rate(30), _tpr(0), _rdiff(FALSE) +_def_tpr(1), _def_ulc(""), _round(0), _int_rate(30), _tpr(0), _rdiff(FALSE), +_was_tpr4(FALSE) { _fixd[0] = _fixd[1] = _fixd[2] = 0; if (data != NULL && *data) diff --git a/cg/pagament.h b/cg/pagament.h index f2be1d9eb..4a38fa37b 100755 --- a/cg/pagament.h +++ b/cg/pagament.h @@ -63,6 +63,8 @@ class TPagamento : public TObject int _def_tpr; // tipo rata default TString16 _def_ulc; // ulteriore classificazione default + bool _was_tpr4; // chiederne ragione ai responsabili morali (bonazzi, gabriella) + protected: // gestione casino se si modificano importi o percentuali rate word change_value(int rata, real new_val, int rdiff, bool is_perc, bool mcomm); @@ -89,10 +91,13 @@ public: bool is_new() const { return _new; } bool dirty() const { return _dirty; } - real imponibile() const { return _imponibile; } - real imposta() const { return _imposta; } - real spese() const { return _spese; } - + const real& imponibile() const { return _imponibile; } + const real& imposta() const { return _imposta; } + const real& spese() const { return _spese; } + + const real& importo_da_dividere() const; + const real& importo_da_non_dividere() const; + const int round() const { return _round; } int scad_rata(int n) const { return _rata_ifield(n,0);} @@ -200,8 +205,11 @@ public: void adjust_fixed_scad(); // determina la prossima scadenza void next_scad(TDate& d, int scad, bool mcomm, int rata); - - + + // folies bergeres pretese, delle quali non rispondo a nessuno + bool was_tpr4() const { return _was_tpr4; } + void set_tpr4(bool b) { _was_tpr4 = b; } + // se codtab non e' NULL legge da file (e da' errore se non c'e') // se si vuole fare un pagamento nuovo si da' il codice con set_code TPagamento(const char* codtab = NULL, const char* data = NULL);