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:
parent
62fbf62417
commit
ceb9797bfb
@ -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())
|
if(!validPlafond || plafUsed > getPlafond())
|
||||||
{
|
{
|
||||||
used << "ERRORE NEL CALCOLO DEL PLAFOND";
|
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
|
// 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
|
// Controllo di avere ancora plafond rimanente
|
||||||
if(plafond <= ZERO)
|
if(plafond <= ZERO)
|
||||||
@ -82,9 +86,9 @@ const TString& TLi_manager::consPlaf(real& plafUsed, const bool write)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Aggiungo al plafond quello che trovo */
|
/* 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
|
// 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
|
// 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"))
|
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;
|
return used;
|
||||||
|
|
||||||
// Controllo se non ho già ricevuto la quantità da stornare di plafond nella nota credito
|
// Controllo se non ho già ricevuto la quantità da stornare di plafond nella nota credito
|
||||||
if(impNC < ZERO)
|
if(impNC == ZERO)
|
||||||
{
|
|
||||||
impNC = -impNC;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// In caso negativo la calcolo
|
// In caso negativo la calcolo
|
||||||
TAssoc_array tabIva = d.tabella_iva(true);
|
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()))
|
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;
|
return used;
|
||||||
|
|
||||||
bool open = false;
|
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--)
|
for(int i = lePlafs.items() - 1; i >= 0 && impNC > ZERO; i--)
|
||||||
{
|
{
|
||||||
lePlafs.get(i, thisPlaf);
|
lePlafs.get(i, thisPlaf);
|
||||||
|
|
||||||
|
// Importo utilizzato del plafond
|
||||||
real importoPlaf = thisPlaf.get(_plimporto);
|
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
|
else
|
||||||
{
|
{
|
||||||
importoPlaf = impNC;
|
rimanente = impNC;
|
||||||
impNC = ZERO;
|
impNC = ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Salvo la quantità utilizzata nelle TToken_string
|
||||||
|
thisPlaf.add(rimanente, _plNC);
|
||||||
|
lePlafs.add(thisPlaf, i);
|
||||||
|
|
||||||
// Aggiungo a plafond
|
// Aggiungo a plafond
|
||||||
static TString key; key.cut(0) << thisPlaf.get(_planno) << "|" << thisPlaf.get(_plnumprot);
|
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
|
// 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;
|
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)
|
const real TLi_manager::elabPlaRes(TToken_string tipi, TToken_string stati, TDate ad)
|
||||||
{
|
{
|
||||||
|
plafond = -UNO;
|
||||||
if(!validPlafond)
|
if(!validPlafond)
|
||||||
return -UNO;
|
return plafond;
|
||||||
|
|
||||||
TLista_documenti din; // Legge tutti i documenti di input
|
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++)
|
for(int i = 0; i < din.items(); i++)
|
||||||
{
|
{
|
||||||
TToken_string plaf(din[i].get("PLAFOND"), ',');
|
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));
|
TToken_string thePla(plaf.get(j));
|
||||||
static TString key; key.cut(0) << "," << thePla.get(_planno) << "|" << thePla.get(_plnumprot);
|
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(din[i].tipo().nota_credito())
|
||||||
{
|
{
|
||||||
if(plafondi.find(key) != plafondi.end())
|
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);
|
plafondi[key] += (real)thePla.get(_plimporto);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Va aggiunto ex novo!
|
// 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
|
// Calcolo l'importo delle righe che rientrano nel plafond
|
||||||
plafondi.insert(std::pair<TString,real>(key, (real)thePla.get(_plimporto)));
|
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())
|
if(plafondi.find(key) != plafondi.end())
|
||||||
{
|
{
|
||||||
// La tolgo! Ma prima controllo che siano uguali
|
if(chiusura == "X")
|
||||||
if(DEBUG_ENABLED)
|
|
||||||
{
|
{
|
||||||
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)))
|
validPlafond = false;
|
||||||
{
|
return plafond;
|
||||||
plafond = -UNO;
|
|
||||||
validPlafond = false;
|
|
||||||
return plafond;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
plafondi.erase(key);
|
||||||
}
|
}
|
||||||
plafondi.erase(key);
|
else
|
||||||
}
|
|
||||||
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()))
|
|
||||||
{
|
|
||||||
{
|
{
|
||||||
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;
|
return plafond;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
enum plafStruct { _planno, _plnumprot, _plimporto, _plchiusura };
|
enum plafStruct { _planno, _plnumprot, _plimporto, _plchiusura, _plNC };
|
||||||
|
|
||||||
class TLi_manager : TObject
|
class TLi_manager : TObject
|
||||||
{
|
{
|
||||||
@ -51,9 +51,9 @@ public:
|
|||||||
bool isSoluzione() { return soluzione; }
|
bool isSoluzione() { return soluzione; }
|
||||||
|
|
||||||
// "Consuma" il plafond
|
// "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
|
// 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
|
// Storna un documento che riceve
|
||||||
void stornaDoc(TDocumento& d, const bool write = false);
|
void stornaDoc(TDocumento& d, const bool write = false);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user