From ceb9797bfb9e0a06e862dfef319af7d234d349f9 Mon Sep 17 00:00:00 2001 From: mtollari Date: Fri, 10 Nov 2017 09:07:00 +0000 Subject: [PATCH] =?UTF-8?q?Patch=20level=20=20=20=20=20=20=20=20=20:=2012.?= =?UTF-8?q?0=20476=20Files=20correlati=20=20=20=20=20:=20li=20Commento=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20=20=20:=20-=20Aggiunta=20alla=20stru?= =?UTF-8?q?ttura=20del=20campo=20"PLAFOND"=20nei=20documenti=20anche=20la?= =?UTF-8?q?=20quantit=C3=A0=20gi=C3=A0=20rimborsata=20da=20Nota=20Credito?= =?UTF-8?q?=20-=20Trasformate=20funzioni=20che=20ritornano=20used=20in=20c?= =?UTF-8?q?onst=20TToken=5Fstring&=20per=20aumentare=20la=20facilit=C3=A0?= =?UTF-8?q?=20di=20utilizzo=20interno=20-=20Sistemata=20funzione=20per=20i?= =?UTF-8?q?ncremento=20e=20consumo,=20tolti=20calcoli=20sbagliati=20-=20St?= =?UTF-8?q?andardizzata=20funzione=20elabPlaRes=20e=20corretti=20calcoli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://10.65.10.50/branches/R_10_00@24190 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- src/li/lilib01.cpp | 131 +++++++++++++++++++++++++-------------------- src/li/lilib01.h | 6 +-- 2 files changed, 75 insertions(+), 62 deletions(-) diff --git a/src/li/lilib01.cpp b/src/li/lilib01.cpp index 7f0566868..ef0d5cf90 100644 --- a/src/li/lilib01.cpp +++ b/src/li/lilib01.cpp @@ -20,9 +20,9 @@ void TLi_manager::elabTipiStati(TToken_string& tipi, TToken_string& stati) } } -const TString& TLi_manager::consPlaf(real& plafUsed, const bool write) +const TToken_string& TLi_manager::consPlaf(real& plafUsed, const bool write) { - TString& used = get_tmp_string(); + TToken_string& used(get_tmp_string()); used.separator(','); if(!validPlafond || plafUsed > getPlafond()) { used << "ERRORE NEL CALCOLO DEL PLAFOND"; @@ -69,7 +69,11 @@ const TString& TLi_manager::consPlaf(real& plafUsed, const bool write) } // Segno di aver usato il plafond - used << thisNumprot << "|" << thisUtilizzato.string() << "|" << (close? "X" : "") << ","; + static TToken_string u; u.cut(0); + u.add(thisNumprot, _planno); + u.add(thisUtilizzato.string(), _plimporto); + u.add(close? "X" : "", _plchiusura); + used.add(u); } // Controllo di avere ancora plafond rimanente if(plafond <= ZERO) @@ -82,9 +86,9 @@ const TString& TLi_manager::consPlaf(real& plafUsed, const bool write) } /* Aggiungo al plafond quello che trovo */ -const TString& TLi_manager::incrPlaf(TDocumento& d, real impNC, const bool write) +const TToken_string& TLi_manager::incrPlaf(TDocumento& d, real impNC, const bool write) { - TString& used = get_tmp_string(); + TToken_string& used = get_tmp_string(); used.separator(','); // Controllo se questa nota credito si riferisce a un singolo documento, in quel caso aggiorno faccio un aggiornamento sulle lettere di intento // Se si rifà a più documenti o non è specificato salta, meglio stare bassi if(d.get("NUMDOCRIF").blank() || d.get("CODNUMRIF").blank() || d.get("ANNORIF").blank() || iniDicInt.year() != d.get_int("ANNORIF")) @@ -101,11 +105,7 @@ const TString& TLi_manager::incrPlaf(TDocumento& d, real impNC, const bool write return used; // Controllo se non ho già ricevuto la quantità da stornare di plafond nella nota credito - if(impNC < ZERO) - { - impNC = -impNC; - } - else + if(impNC == ZERO) { // In caso negativo la calcolo TAssoc_array tabIva = d.tabella_iva(true); @@ -113,7 +113,8 @@ const TString& TLi_manager::incrPlaf(TDocumento& d, real impNC, const bool write { if(checkIva(totali->cod_iva().codice())) { - impNC += -totali->imp_orig(); // +-+-+-+-+-+- + impNC += totali->imp_orig(); + message_box("Hey guarda il mio segno e dillo a Tolla! %s", totali->imp_orig().string()); } } } @@ -123,22 +124,36 @@ const TString& TLi_manager::incrPlaf(TDocumento& d, real impNC, const bool write return used; bool open = false; - TToken_string thisPlaf("", ','); // Sono abbastanza sicuro che non serve inizializzarlo + TToken_string thisPlaf("", '|'); for(int i = lePlafs.items() - 1; i >= 0 && impNC > ZERO; i--) { lePlafs.get(i, thisPlaf); + // Importo utilizzato del plafond real importoPlaf = thisPlaf.get(_plimporto); - if(importoPlaf < impNC) + // Importo già riaccreditato da altre NC + real importoNC = thisPlaf.get(_plNC); + // Importo possibile di plafond da stornare + real rimanente = importoPlaf - importoNC; + + if(rimanente == ZERO) + // This isn't the plafond you're looking for + continue; + + if(rimanente < impNC) { - impNC -= importoPlaf; + impNC -= rimanente; } else { - importoPlaf = impNC; + rimanente = impNC; impNC = ZERO; } + // Salvo la quantità utilizzata nelle TToken_string + thisPlaf.add(rimanente, _plNC); + lePlafs.add(thisPlaf, i); + // Aggiungo a plafond static TString key; key.cut(0) << thisPlaf.get(_planno) << "|" << thisPlaf.get(_plnumprot); @@ -162,8 +177,20 @@ const TString& TLi_manager::incrPlaf(TDocumento& d, real impNC, const bool write } } // Segno di aver usato il plafond - used << key << "|" << importoPlaf.string() << "|" << (open? "X" : "") << ","; + static TToken_string u; u.cut(0); + u.add(key, _planno); + u.add(importoPlaf.string(), _plimporto); + u.add(open? "X" : "", _plchiusura); + used.add(u); } + + // Sovrascrivo il documento + ds.put("PLAFOND", lePlafs); + ds.rewrite(); + + // Tolgo la virgola finale + used.cut(used.len()-1); + return used; } @@ -308,8 +335,9 @@ const real TLi_manager::getPlaRes(TToken_string tipi, TToken_string stati) const real TLi_manager::elabPlaRes(TToken_string tipi, TToken_string stati, TDate ad) { + plafond = -UNO; if(!validPlafond) - return -UNO; + return plafond; TLista_documenti din; // Legge tutti i documenti di input @@ -319,76 +347,61 @@ const real TLi_manager::elabPlaRes(TToken_string tipi, TToken_string stati, TDat for(int i = 0; i < din.items(); i++) { TToken_string plaf(din[i].get("PLAFOND"), ','); - for(int i = 0; i < plaf.items(); i++) + for(int j = 0; j < plaf.items(); j++) { - TToken_string thePla(plaf.get(i)); - static TString key; key.cut(0) << "," << thePla.get(_planno) << "|" << thePla.get(_plnumprot); + TToken_string thePla(plaf.get(j)); + static TString key; key.cut(0) << thePla.get(_planno) << "|" << thePla.get(_plnumprot); + static TString chiusura; chiusura.cut(0) << thePla.get(_plchiusura); // La get ritorna un const char* if(din[i].tipo().nota_credito()) { if(plafondi.find(key) != plafondi.end()) { + if(DEBUG_ENABLED && chiusura == "X" && yesno_box("Attenzione! La lettera con codice %s riferito alla nota credito %s, %d l'ho trovata ma dovevo aprirla adesso!\n Che faccio, azzero?", key, din[i].numerazione(), din[i].numero())) + { + plafondi[key] = ZERO; + } plafondi[key] += (real)thePla.get(_plimporto); } else { // Va aggiunto ex novo! + if(DEBUG_ENABLED && chiusura != "X" && yesno_box("Attenzione! La lettera con codice %s riferito alla nota credito %s, %d non l'ho trovata ma doveva già essere aperta!\n Che faccio, annullo?", key, din[i].numerazione(), din[i].numero())) + { + validPlafond = false; + return plafond; + } // Calcolo l'importo delle righe che rientrano nel plafond plafondi.insert(std::pair(key, (real)thePla.get(_plimporto))); } } - if(!din[i].tipo().nota_credito()) // thePla.get(_plchiusura) != "X" + else { if(plafondi.find(key) != plafondi.end()) { - // La tolgo! Ma prima controllo che siano uguali - if(DEBUG_ENABLED) + if(chiusura == "X") { - if(plafondi[key] != (real)thePla.get(_plimporto)) + if(DEBUG_ENABLED && plafondi[key] != (real)thePla.get(_plimporto) && + !yesno_box(TR("Questa lettera di intento è incongruente,\nTotale attivo: %s\nTotale da disattivare: %s\nContinuare?"), plafondi[key].string(), thePla.get(_plimporto))) { - if(!yesno_box(TR("Questa lettera di intento è incongruente,\nTotale attivo: %s\nTotale da disattivare: %s\nContinuare?"), plafondi[key].string(), thePla.get(_plimporto))) - { - plafond = -UNO; - validPlafond = false; - return plafond; - } + validPlafond = false; + return plafond; } + plafondi.erase(key); } - plafondi.erase(key); - } - else - { - plafondi[key] -= (real)thePla.get(_plimporto); - } - } - } - /* - // Controllo se stiamo lavorando con una nota credito - if(din[i].tipo().nota_credito()) - { - incrPlaf(din[i]); - } - else - { - TAssoc_array tabIva = din[i].tabella_iva(true); - for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tabIva.get(); totali != NULL; totali = (TRiepilogo_iva *) tabIva.get()) - { - if(checkIva(totali->cod_iva().codice())) - { + else { - consPlaf(totali->imp_orig()); + plafondi[key] -= (real)thePla.get(_plimporto); } } } - // Nel caso il plafond trovato fosse una soluzione unica e ho già trovato dei documenti vuol dire che il plafond non è più valido - if(soluzione) - { - plafond = -UNO; - break; - } } - */ } + // Calcolo il totale da mappa scansionata + plafond = ZERO; + for(auto it = plafondi.begin(); it != plafondi.end(); ++it) + plafond += it->second; + return plafond; } diff --git a/src/li/lilib01.h b/src/li/lilib01.h index 6f199450b..8d03b5eef 100644 --- a/src/li/lilib01.h +++ b/src/li/lilib01.h @@ -19,7 +19,7 @@ #include -enum plafStruct { _planno, _plnumprot, _plimporto, _plchiusura }; +enum plafStruct { _planno, _plnumprot, _plimporto, _plchiusura, _plNC }; class TLi_manager : TObject { @@ -51,9 +51,9 @@ public: bool isSoluzione() { return soluzione; } // "Consuma" il plafond - const TString& consPlaf(real& plafUsed, const bool write = false); + const TToken_string& consPlaf(real& plafUsed, const bool write = false); // Da una nota credito passata incremento il plafond - const TString& incrPlaf(TDocumento& d, real impNC = ZERO, const bool write = false); + const TToken_string& incrPlaf(TDocumento& d, real impNC = ZERO, const bool write = false); // Storna un documento che riceve void stornaDoc(TDocumento& d, const bool write = false);