diff --git a/ve/clifor.cpp b/ve/clifor.cpp index 8d38cf54b..aa0dd74c4 100755 --- a/ve/clifor.cpp +++ b/ve/clifor.cpp @@ -71,7 +71,7 @@ bool TCli_for::read_lettera(const TDate & data, bool extended) if (_use_lettere) { - if (data != _last_data) + if (data != _last_data || _extended != extended) { _letint.zero(); TRelation * r = new TRelation(LF_LETINT); @@ -128,6 +128,7 @@ bool TCli_for::read_lettera(const TDate & data, bool extended) _lettera_found = data <= al; } _last_data = data; + _extended = extended; } } return _lettera_found; @@ -295,7 +296,7 @@ void TCli_for::cli2doc(TDocumento & doc) TCli_for::TCli_for(char tipo, long codice) : TMultiple_rectype( LF_CLIFO ), _ven_rec(LF_CFVEN), - _letint(LF_LETINT), _use_lettere(false), _lettera_found(false) + _letint(LF_LETINT), _use_lettere(false), _lettera_found(false), _extended(false) { init(); add_file(LF_INDSP, IND_CODIND); @@ -304,7 +305,7 @@ TCli_for::TCli_for(char tipo, long codice) : TMultiple_rectype( LF_CLIFO ), _ven } TCli_for::TCli_for(const TRectype & rec) : TMultiple_rectype(rec), _ven_rec(LF_CFVEN), - _letint(LF_LETINT), _use_lettere(false), _lettera_found(false) + _letint(LF_LETINT), _use_lettere(false), _lettera_found(false), _extended(false) { init(); add_file(LF_INDSP, IND_CODIND); @@ -312,7 +313,7 @@ TCli_for::TCli_for(const TRectype & rec) : TMultiple_rectype(rec), _ven_rec(LF_C } TCli_for::TCli_for(const TCli_for & c) : TMultiple_rectype(c), _ven_rec(c._ven_rec), - _letint(LF_LETINT), _use_lettere(false), _lettera_found(false) + _letint(LF_LETINT), _use_lettere(false), _lettera_found(false), _extended(false) { init(); } diff --git a/ve/clifor.h b/ve/clifor.h index 6ee369217..8255709fd 100755 --- a/ve/clifor.h +++ b/ve/clifor.h @@ -47,6 +47,7 @@ class TCli_for : public TMultiple_rectype TRectype _letint; TDate _last_data; bool _use_lettere; + bool _extended; bool _lettera_found; diff --git a/ve/velib.h b/ve/velib.h index 7b6ce0583..32615bbdc 100755 --- a/ve/velib.h +++ b/ve/velib.h @@ -855,6 +855,7 @@ public: void copy_contents(const TDocumento& src, bool copy_header = true); void set_fields(TAuto_variable_rectype & rec); + void update_esenzione(); void set_riga_esenzione(); bool ha_riga_sconto() const { return _sconto != NULL; } bool ha_riga_esenzione() const { return _esenzione != NULL; } diff --git a/ve/velib03.cpp b/ve/velib03.cpp index 1bdbaf0a9..6359531fd 100755 --- a/ve/velib03.cpp +++ b/ve/velib03.cpp @@ -881,6 +881,76 @@ void TDocumento::set_riga_sconto() } } +void TDocumento::update_esenzione() +{ + if (clifor().use_lettere()) + { + bool to_update = false; + const TString8 codiva = codesiva(); + for (int i = physical_rows(); !to_update && i > 0; i--) + { + const TString & cod = row(i).get(RDOC_CODIVA); + + to_update = cod.full() && cod != codiva; + } + if (to_update) + for (int i = physical_rows(); i > 0; i--) + { + TRiga_documento & rdoc = row(i); + const TString & cod = rdoc.get(RDOC_CODIVA); + + if (cod.full()) + { + if (codiva.full()) + rdoc.put(RDOC_CODIVA, codiva); + else + { + TCodiceIVA i(cod); + const bool plafond = i.get_int("S3") > 0; + + if (plafond) + { + TString codivarow; + + if (rdoc.is_merce()) + codivarow =cached_article(rdoc.get(RDOC_CODARTMAG)).get(ANAMAG_CODIVA); + else + if (rdoc.is_spese()) + { + TSpesa_prest s(rdoc.get(RDOC_CODART)); + + codivarow = s.cod_iva(); + } + else + if (rdoc.is_prestazione()) + { + TSpesa_prest p(rdoc.get(RDOC_CODART), 'P'); + + codivarow = p.cod_iva(); + } + else + if (rdoc.is_risorsa()) + { + TSpesa_prest r(rdoc.get(RDOC_CODART), 'R'); + + codivarow = r.cod_iva(); + } + else + if (rdoc.is_attrezzatura()) + { + TSpesa_prest a(rdoc.get(RDOC_CODART), 'A'); + + codivarow = a.cod_iva(); + } + if (codivarow.full()) + rdoc.put(RDOC_CODIVA, codivarow); + } + } + } + } + } +} + void TDocumento::set_riga_esenzione() { TCli_for & c = clifor(); diff --git a/ve/velib04a.cpp b/ve/velib04a.cpp index 2e6995a70..75276a192 100755 --- a/ve/velib04a.cpp +++ b/ve/velib04a.cpp @@ -585,6 +585,12 @@ bool TFatturazione_bolle::elabora(TLista_documenti& doc_in, TLista_documenti& do else d.put("FATID", 0); } + for (int i = doc_out.items() - 1; i >=0; i--) // Aggiorna esenzione + { + TDocumento& d = doc_out[i]; + + d.update_esenzione(); + } return doc_out.items() > 0; }