diff --git a/src/ve/ve0100.cpp b/src/ve/ve0100.cpp index 6384babef..0bb6bf8b9 100755 --- a/src/ve/ve0100.cpp +++ b/src/ve/ve0100.cpp @@ -1305,9 +1305,34 @@ int TMotore_application::checkPlafondAvailability(TDocumento& d, bool alreadyExi TAssoc_array tabIva = d.tabella_iva(true); TDocumento oldDoc; bool recalc = false; + + real plaUtil = ZERO; + + for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tabIva.get(); totali != NULL; totali = (TRiepilogo_iva *) tabIva.get()) + { + if(plafond.checkIva(totali->cod_iva().codice())) // Se l'iva del documento è diversa non mi interessa + { + plaUtil += totali->imp_orig(); + } + } + // Se il documento è già stato scritto nel DB sottraggo solo le modifiche if(alreadyExist) { + // Prima di tutto controllo che non stia salvando la stessa roba che ho già, confronto il totale dei plafond con il totale da calcolare + TToken_string lePlafs(d.get("PLAFOND"), ','); + real totPlaf = ZERO; + for(int i = 0; i < lePlafs.items(); i++) + { + // É + ottimizzato rispetto a farlo in una linea sola? + //static TToken_string thisPlaf; thisPlaf.cut(0) << lePlafs.get(i); + totPlaf += (real)((TToken_string)lePlafs.get(i)).get(_plimporto); + } + + // Se sono uguali esco + if(totPlaf == plaUtil) + return NOERR; + oldDoc = TDocumento('D', d.anno(), d.numerazione(), d.numero()); // Prima di tutto controllo che siano modificabili tutti i documenti dopo di lui // Visto che ho delle funzioni già pronti in TLi_manager gli passo il controllo @@ -1330,26 +1355,16 @@ int TMotore_application::checkPlafondAvailability(TDocumento& d, bool alreadyExi } } real plaRes = plafond.getPlaRes(); - TString asd = plaRes.string(); - real plaUtil = ZERO; - for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tabIva.get(); totali != NULL; totali = (TRiepilogo_iva *) tabIva.get()) - { - if(plafond.checkIva(totali->cod_iva().codice())) // Se l'iva del documento è diversa non mi interessa - { - plaUtil += totali->imp_orig();; - } - } - asd = plaUtil.string(); - TString used; + TToken_string used; if(d.tipo().nota_credito()) { - used << plafond.incrPlaf(d, plaUtil, true); + used = plafond.incrPlaf(d, plaUtil, true); } else if(plaRes - plaUtil >= ZERO) { // Il controllo è andato bene, adesso mi segno i plafond che ho utilizzato nel memo del documento - used << plafond.consPlaf(plaUtil, true); + used = plafond.consPlaf(plaUtil, true); } if(used.starts_with("ERRORE")) diff --git a/src/ve/velib03.cpp b/src/ve/velib03.cpp index 863378b07..ef18b0145 100755 --- a/src/ve/velib03.cpp +++ b/src/ve/velib03.cpp @@ -1004,12 +1004,15 @@ void TDocumento::set_riga_esenzione() TString16 v_data_esenzione; TString16 n_registrazione; TString16 n_data_registrazione; - - if (codes.codice().full()) + bool multiPlaf = c.use_lettere() && get("PLAFOND").full(); // Gestione multiplafond su documento + if (codes.codice().full() && !multiPlaf) + { get_protocolli_esenzione(v_esenzione, v_data_esenzione, n_registrazione, n_data_registrazione); - bool esente = codes.tipo().not_empty() && v_esenzione.not_empty() && + } + // Tradotto: se ha il cod. esenzione AND (i protocolli pieni OR multiplaf) + bool esente = codes.tipo().not_empty() && ((v_esenzione.not_empty() && v_data_esenzione.not_empty() && n_registrazione.not_empty() && - n_data_registrazione.not_empty(); + n_data_registrazione.not_empty()) || multiPlaf); if (esente) { esente = false; @@ -1049,11 +1052,27 @@ void TDocumento::set_riga_esenzione() } if (_esenzione == NULL) _esenzione = new TRiga_documento(this, _tipo_riga_es); - TString d(256); d = _des_esenz; - - d << format(" come da vostra dichiarazione n. %s del %s da noi annotata al n. %s il %s.", - (const char*)v_esenzione, (const char*)v_data_esenzione, - (const char*)n_registrazione, (const char*)n_data_registrazione); + TString d = _des_esenz; + + if(multiPlaf) + { + d << " come dalle vostre dichiarazioni:\n"; + TToken_string lePlafs(get("PLAFOND"), ','); + for(int i = 0; i < lePlafs.items(); i++) + { + static TToken_string thisPlaf; thisPlaf.cut(0) << lePlafs.get(i); + static TString key; key.cut(0) << thisPlaf.get(0) << "|" << thisPlaf.get(1); + TRectype plaf = cache().get(LF_LETINT, key); + d << "N. " << plaf.get(LETINT_VSPROT) << " del " << plaf.get(LETINT_VSDATA) + << " da noi annotata al n. " << plaf.get(LETINT_NUMPROT) << " il " << plaf.get(LETINT_DATAREG) << "\n"; + } + } + else + { + d << format(" come da vostra dichiarazione n. %s del %s da noi annotata al n. %s il %s.", + (const char*)v_esenzione, (const char*)v_data_esenzione, + (const char*)n_registrazione, (const char*)n_data_registrazione); + } _esenzione->set_descr(d); } }