Patch level : 12.0 476

Files correlati     : li
Commento            : 
- Aggiunta alla struttura del campo "PLAFOND" nei documenti anche la quantità già rimborsata da Nota Credito
- Trasformate funzioni che ritornano used in const TToken_string& per aumentare la facilità di utilizzo interno
- Sistemata funzione per incremento e consumo, tolti calcoli sbagliati
- Standardizzata funzione elabPlaRes e corretti calcoli

git-svn-id: svn://10.65.10.50/branches/R_10_00@24190 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
mtollari 2017-11-10 09:07:00 +00:00
parent 62fbf62417
commit ceb9797bfb
2 changed files with 75 additions and 62 deletions

View File

@ -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<TString,real>(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;
}

View File

@ -19,7 +19,7 @@
#include <map>
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);