Patch level : 12.0 no-patch

Files correlati     : li, ve
Commento            : Tolte quelle porcherie che avevo scritto sul conai, passato da camelCase a underscore_case
This commit is contained in:
Mattia Tollari 2019-07-23 17:23:41 +02:00
parent 02998fe78a
commit 74cf43f735
6 changed files with 321 additions and 323 deletions

View File

@ -345,7 +345,7 @@ bool TVisLI_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
app.field(101).check_type(CHECK_REQUIRED);
// Lancio la maschera
if(app.run() == K_ENTER)
generaLiStorico(app.get_date(101));
genera_li_storico(app.get_date(101));
break;
}
case DLG_USER:

View File

@ -123,17 +123,17 @@ void TResDI_app::elab(TResDI_mask& m)
TRectype row_clifo(c_clifo.curr());
TLi_manager currentCli(row_clifo.get_char("TIPOCF"), row_clifo.get_long("CODCF"), aData); // Inizializzo l'oggetto per la gestione del plafond
if(currentCli.hasValidPlafond())
if(currentCli.has_valid_plafond())
{
real plafond = currentCli.getPlafond();
real resPlafond = plafond - currentCli.elabUtil(tipi, stati, aData) - currentCli.elabUtil(tipif, statif);
real plafond = currentCli.get_plafond();
real resPlafond = plafond - currentCli.elab_util(tipi, stati, aData) - currentCli.elab_util(tipif, statif);
TString msg;
msg << "\nDichiarazione di intento cliente N." << row_clifo.get_long("CODCF") << "\nRagione sociale: " << row_clifo.get("RAGSOC") << "\nPlafond totale: " << static_cast<TCurrency>(plafond).string() << "\n";
log.log(0, msg);
msg = TString("Plafond disponibile: ") << static_cast<TCurrency>((resPlafond > ZERO ? resPlafond : ZERO )).string() << "";
log.log(0, msg);
msg = TString("Tipo dichiarazione: ") << (currentCli.isSoluzione() ? "Singola\n" : "A concorrenza\n");
msg = TString("Tipo dichiarazione: ") << (currentCli.is_soluzione() ? "Singola\n" : "A concorrenza\n");
log.log(0, msg);
}
}

View File

@ -13,103 +13,102 @@ const TString make_key(const int anno, const int numplaf)
return key;
}
void TLi_manager::elabTipiStati()
void TLi_manager::elab_tipi_stati()
{
createTipiStati(tipi, stati);
create_tipi_stati(_tipi, _stati);
}
const TToken_string& TLi_manager::getUse(TDocumento& d, const bool write)
const TToken_string& TLi_manager::get_use(TDocumento& d, const bool write)
{
static TToken_string& ret = get_tmp_string();
TAssoc_array tabIva = d.tabella_iva(true);
TString4 numDoc = d.numerazione();
int nDoc = d.numero();
TAssoc_array tab_iva = d.tabella_iva(true);
TString4 num_doc = d.numerazione();
real plaUtil = ZERO;
real pla_util = ZERO;
for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tabIva.get(); totali != NULL; totali = (TRiepilogo_iva *) tabIva.get())
for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tab_iva.get(); totali != NULL; totali = (TRiepilogo_iva *) tab_iva.get())
{
if(checkIva(totali->cod_iva().codice())) // Se l'iva del documento è diversa non mi interessa
if(check_iva(totali->cod_iva().codice())) // Se l'iva del documento è diversa non mi interessa
{
plaUtil += totali->imp_orig();
pla_util += totali->imp_orig();
}
}
if(plaUtil > ZERO)
if(pla_util > ZERO)
{
if(d.is_nota_credito())
{
ret.cut(0) << incrPlaf(d, plaUtil, write);
ret.cut(0) << incr_plaf(d, pla_util, write);
}
else
{
ret.cut(0) << consPlaf(plaUtil, write);
ret.cut(0) << cons_plaf(pla_util, write);
if(ret.starts_with("ERRORE"))
ret << " al documento " << d.numerazione() << " n." << d.numero() << "\nTotale plafond da utilizzare: " << plaUtil.string() << "\nTotale rimasto: " << getPlafond().string();
ret << " al documento " << d.numerazione() << " n." << d.numero() << "\nTotale plafond da utilizzare: " << pla_util.string() << "\nTotale rimasto: " << get_plafond().string();
}
}
return ret;
}
const TToken_string& TLi_manager::consPlaf(real& plafUsed, const bool write)
const TToken_string& TLi_manager::cons_plaf(real& plaf_used, const bool write)
{
static TToken_string used("", ','); used.cut(0);
if(!validPlafond || plafUsed > getPlafond())
if(!_valid_plafond || plaf_used > get_plafond())
{
used << "ERRORE NEL CALCOLO DEL PLAFOND";
return used;
}
bool close = false;
TToken_string thisPlaf("", ',');
while(plafUsed > ZERO)
TToken_string this_plaf("", ',');
while(plaf_used > ZERO)
{
// Calcolo quanto plafond ho usato
TString thisNumprot = plafondi.begin()->first;
real thisAmount = plafondi.begin()->second;
TString this_numprot = _plafondi.begin()->first;
real this_amount = _plafondi.begin()->second;
real thisUtilizzato;
real this_utilizzato;
if(plafUsed >= thisAmount)
if(plaf_used >= this_amount)
{
close = true;
thisUtilizzato = thisAmount;
this_utilizzato = this_amount;
// Rimuovo il plafond dalla lista,
plafondi.erase(thisNumprot);
_plafondi.erase(this_numprot);
if(write)
{
// lo chiudo
changeStato(thisNumprot, true);
change_stato(this_numprot, true);
}
// e diminuisco tutto
plafond -= thisAmount;
plafUsed -= thisAmount;
_plafond -= this_amount;
plaf_used -= this_amount;
}
else
{
close = false;
thisUtilizzato = plafUsed;
this_utilizzato = plaf_used;
// e diminuisco tutto
plafond -= plafUsed;
plafondi[thisNumprot] -= plafUsed;
plafUsed = ZERO;
_plafond -= plaf_used;
_plafondi[this_numprot] -= plaf_used;
plaf_used = ZERO;
}
// Segno di aver usato il plafond
static TToken_string u; u.cut(0);
u.add(thisNumprot, _planno);
u.add(thisUtilizzato.string(), _plimporto);
u.add(this_numprot, _planno);
u.add(this_utilizzato.string(), _plimporto);
u.add(close? "X" : "", _plchiusura);
used.add(u);
}
// Controllo di avere ancora plafond rimanente
if(plafond <= ZERO)
validPlafond = false;
if(_plafond <= ZERO)
_valid_plafond = false;
// Tolgo la virgola finale
used.cut(used.len()-1);
@ -118,92 +117,92 @@ const TToken_string& TLi_manager::consPlaf(real& plafUsed, const bool write)
}
/* Aggiungo al plafond quello che trovo */
const TToken_string& TLi_manager::incrPlaf(TDocumento& d, real impNC, const bool write)
const TToken_string& TLi_manager::incr_plaf(TDocumento& d, real imp_nc, const bool write)
{
static TToken_string used("", ','); used.cut(0);
// 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"))
if(d.get("NUMDOCRIF").blank() || d.get("CODNUMRIF").blank() || d.get("ANNORIF").blank() || _ini_dic_int.year() != d.get_int("ANNORIF"))
{
return used;
}
TDocumento ds('D', d.get_int("ANNORIF"), d.get("CODNUMRIF"), d.get_int("NUMDOCRIF"));
TToken_string lePlafs(ds.get("PLAFOND"), ','); // [ANNO|NUMPROT|UTILIZZATO],...
TToken_string le_plafs(ds.get("PLAFOND"), ','); // [ANNO|NUMPROT|UTILIZZATO],...
// Se il documento di riferimento non ha nulla inserito nel plafond esco, non mi interessa
if(lePlafs.items() == 0)
if(le_plafs.items() == 0)
return used;
// Controllo se non ho già ricevuto la quantità da stornare di plafond nella nota credito
if(impNC == ZERO)
if(imp_nc == ZERO)
{
// In caso negativo la calcolo
TAssoc_array tabIva = d.tabella_iva(true);
for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tabIva.get(); totali != NULL; totali = (TRiepilogo_iva *) tabIva.get())
TAssoc_array tab_iva = d.tabella_iva(true);
for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tab_iva.get(); totali != NULL; totali = (TRiepilogo_iva *) tab_iva.get())
{
if(checkIva(totali->cod_iva().codice()))
if(check_iva(totali->cod_iva().codice()))
{
impNC += totali->imp_orig();
imp_nc += totali->imp_orig();
}
}
}
// Controllo se ho del plafond da stornare
if(impNC <= ZERO)
if(imp_nc <= ZERO)
return used;
bool open = false;
TToken_string thisPlaf("", '|');
for(int i = lePlafs.items() - 1; i >= 0 && impNC > ZERO; i--)
TToken_string this_plaf("", '|');
for(int i = le_plafs.items() - 1; i >= 0 && imp_nc > ZERO; i--)
{
lePlafs.get(i, thisPlaf);
le_plafs.get(i, this_plaf);
// Importo utilizzato del plafond
real importoPlaf = thisPlaf.get(_plimporto);
real importo_plaf = this_plaf.get(_plimporto);
// Importo già riaccreditato da altre NC
real importoNC = thisPlaf.get(_plNC);
real importo_nc = this_plaf.get(_plNC);
// Importo possibile di plafond da stornare
real rimanente = importoPlaf - importoNC;
real rimanente = importo_plaf - importo_nc;
if(rimanente == ZERO)
// This isn't the plafond you're looking for
continue;
if(rimanente < impNC)
if(rimanente < imp_nc)
{
impNC -= rimanente;
imp_nc -= rimanente;
}
else
{
rimanente = impNC;
impNC = ZERO;
rimanente = imp_nc;
imp_nc = ZERO;
}
// Salvo la quantità utilizzata nelle TToken_string
thisPlaf.add(rimanente, _plNC);
lePlafs.add(thisPlaf, i);
this_plaf.add(rimanente, _plNC);
le_plafs.add(this_plaf, i);
// Aggiungo a plafond
const TString key = make_key(thisPlaf.get_int(_planno), thisPlaf.get_int(_plnumprot));
const TString key = make_key(this_plaf.get_int(_planno), this_plaf.get_int(_plnumprot));
if(plafondi.find(key) != plafondi.end())
if(_plafondi.find(key) != _plafondi.end())
{
open = false;
// Incremento!
plafondi[key] += rimanente;
_plafondi[key] += rimanente;
}
else
{
// Va aggiunto ex novo!
// Calcolo l'importo delle righe che rientrano nel plafond
open = true;
plafondi.insert(std::pair<TString,real>(key, rimanente));
_plafondi.insert(std::pair<TString,real>(key, rimanente));
// Se devo scrivere abilito il plafond
if(write)
{
changeStato(key, false);
change_stato(key, false);
}
}
// Segno di aver usato il plafond
@ -215,19 +214,19 @@ const TToken_string& TLi_manager::incrPlaf(TDocumento& d, real impNC, const bool
}
// Rigiro used, nelle note credito sono invertiti i plafond
static TToken_string usedApp("", ','); usedApp.cut(0);
static TToken_string used_app("", ','); used_app.cut(0);
for(int i = used.items(); i > 0; i--)
usedApp.add(used.get(used.items()-i), i-1);
used_app.add(used.get(used.items()-i), i-1);
// Sovrascrivo il documento
ds.put("PLAFOND", lePlafs);
ds.put("PLAFOND", le_plafs);
ds.rewrite();
// Tolgo la virgola finale
used.cut(used.len()-1);
// Succedono cose in memoria, devo rimediare così
return usedApp;
return used_app;
}
/*
void TLi_manager::stornaDoc(const TDocumento& d, const bool write)
@ -291,7 +290,7 @@ void TLi_manager::stornaDocs(const TDocumento& d, const bool write)
TLista_documenti din; // Legge tutti i documenti di input
// Trovo tutti i documenti che mi interessano
din.read('D', tipocf, codcli, iniDicInt.year(), tipi, stati, d.data(), finDicInt);
din.read('D', _tipocf, _codcli, iniDicInt.year(), tipi, stati, d.data(), finDicInt);
for(int i = 0; i < din.items(); i++)
{
@ -302,49 +301,49 @@ void TLi_manager::stornaDocs(const TDocumento& d, const bool write)
}
}
*/
const TToken_string& TLi_manager::stornaDoc(const TDocumento& d, real impDC, const bool write)
const TToken_string& TLi_manager::storna_doc(const TDocumento& d, real imp_dc, const bool write)
{
static TToken_string used("", ','); used.cut(0);
// True se devo stornare tutto il Doc
bool totale = impDC.is_zero();
const bool totale = imp_dc.is_zero();
bool ok = true;
// Devo ricaricare le righe sui plafond che ho
TToken_string plafs(d.get("PLAFOND"), ',');
for(int i = 0; i < plafs.items() && impDC > ZERO; i++)
for(int i = 0; i < plafs.items() && imp_dc > ZERO; i++)
{
TToken_string thisPlafond = plafs.get(i);
const TString key = make_key(thisPlafond.get_int(_planno), thisPlafond.get_int(_plnumprot));
real thisImporto = thisPlafond.get(_plimporto);
TToken_string this_plafond = plafs.get(i);
const TString key = make_key(this_plafond.get_int(_planno), this_plafond.get_int(_plnumprot));
real this_importo = this_plafond.get(_plimporto);
if(totale)
{
if(thisImporto >= impDC)
if(this_importo >= imp_dc)
{
thisImporto = impDC;
this_importo = imp_dc;
// Controllo se vado a stornare solo una parte o tutto, nel primo caso cambio la Token, nel secondo elimino normalmente
if(thisImporto > impDC)
if(this_importo > imp_dc)
{
thisPlafond.add(impDC, _plimporto);
plafs.add(thisPlafond, i);
this_plafond.add(imp_dc, _plimporto);
plafs.add(this_plafond, i);
}
else
plafs.destroy(i);
impDC = ZERO;
imp_dc = ZERO;
}
else
{
impDC -= thisImporto;
imp_dc -= this_importo;
plafs.destroy(i);
}
}
TString asd = thisImporto.string();
TString asd = this_importo.string();
if(d.is_nota_credito())
{
if(plafondi.find(key) != plafondi.end())
if(_plafondi.find(key) != _plafondi.end())
{
if(thisImporto < plafondi[key])
if(this_importo < _plafondi[key])
{
// Sottraggo
plafondi[key] -= thisImporto;
_plafondi[key] -= this_importo;
}
else
{
@ -364,19 +363,19 @@ const TToken_string& TLi_manager::stornaDoc(const TDocumento& d, real impDC, con
}
else
{
if(plafondi.find(key) != plafondi.end())
if(_plafondi.find(key) != _plafondi.end())
{
//Sommo
plafondi[key] += thisImporto;
_plafondi[key] += this_importo;
}
else
{
// Aggiungo ai plafond
plafondi.insert(std::pair<TString, real>(key, thisImporto));
_plafondi.insert(std::pair<TString, real>(key, this_importo));
// Se devo scrivere abilito il plafond
if(write)
{
changeStato(key, false);
change_stato(key, false);
}
}
}
@ -394,7 +393,7 @@ bool TLi_manager::recalcAfter(const TDocumento& d, TLog_report& lerr)
bool ok = true;
int first = -1;
// Trovo tutti i documenti che mi interessano
din.read('D', tipocf, codcli, iniDicInt.year(), tipi, stati, d.data(), finDicInt);
din.read('D', _tipocf, _codcli, iniDicInt.year(), tipi, stati, d.data(), finDicInt);
for(int i = 0; i < din.items() && ok; i++)
{
@ -422,18 +421,18 @@ bool TLi_manager::recalcAfter(const TDocumento& d, TLog_report& lerr)
*/
/* Faccio un analisi di tutti i plafond aperti e li sommo salvandomeli in plafonds */
void TLi_manager::elabPlafond()
void TLi_manager::elab_plafond()
{
validPlafond = false;
_valid_plafond = false;
// Controllo preventivo per evitare di fare calcoli su anni precedenti al plafond
if(iniDicInt.year() < 2017)
if(_ini_dic_int.year() < 2017)
return;
TRelation letint(LF_LETINT);
TRectype filtro(letint.curr());
filtro.add("CODCLI", codcli);
filtro.add("ANNO", iniDicInt.year());
filtro.add("CODCLI", _codcli);
filtro.add("ANNO", _ini_dic_int.year());
// Creo un cursore ordinato e prelevo la prima riga non chiusa
TCursor c_dicint(&letint, "", 2, &filtro, &filtro);
@ -441,11 +440,11 @@ void TLi_manager::elabPlafond()
if(c_dicint.items() > 0)
{
// Cerco finchè non arrivo alla fine o non trovo una soluzione
for(c_dicint = 0; c_dicint.pos() < c_dicint.items() && !soluzione; ++c_dicint)
for(c_dicint = 0; c_dicint.pos() < c_dicint.items() && !_soluzione; ++c_dicint)
{
TRectype row = c_dicint.curr();
// Esco se raggiungo una data successiva al nostro documento
if(row.get_date("DAL") > finDicInt)
if(row.get_date("DAL") > _fin_dic_int)
break;
if(!row.get_bool("CHIUSA"))
@ -455,113 +454,113 @@ void TLi_manager::elabPlafond()
if(row.get_int("TIPOOP") == SOLUZIONE_UNICA)
{
// Faccio un controllo in più per bloccare un utente con plafond di diverso tipo
if(validPlafond)
if(_valid_plafond)
{
// ERRORE! Esiste già un plafond e ho trovato una soluzione unica!
validPlafond = false;
plafondi.clear();
plafond = -UNO;
_valid_plafond = false;
_plafondi.clear();
_plafond = -UNO;
return;
}
soluzione = true;
_soluzione = true;
}
if(!validPlafond)
iniDicInt = row.get_date("DAL");
if(!_valid_plafond)
_ini_dic_int = row.get_date("DAL");
// Aggiungo il plafond trovato all'elenco dei plafond
const TString key = make_key(row.get_int("ANNO"), row.get_int("NUMPROT"));
plafondi.insert(std::pair<TString,real>(key, row.get_real("IMPORTO")));
_plafondi.insert(std::pair<TString,real>(key, row.get_real("IMPORTO")));
// Aggiungo il valore del plafond al totale
plafond += row.get_real("IMPORTO");
validPlafond = true;
_plafond += row.get_real("IMPORTO");
_valid_plafond = true;
}
}
}
if(!validPlafond)
plafond = -UNO;
if(!_valid_plafond)
_plafond = -UNO;
}
const real TLi_manager::getPlaRes()
const real TLi_manager::get_pla_res()
{
return elabPlaRes();
return elab_pla_res();
}
const real TLi_manager::getPlaRes(TToken_string tipi, TToken_string stati)
const real TLi_manager::get_pla_res(TToken_string tipi, TToken_string stati)
{
return elabPlaRes(tipi, stati);
return elab_pla_res(tipi, stati);
}
const real TLi_manager::elabPlaRes(TToken_string t, TToken_string s, TDate ad)
const real TLi_manager::elab_pla_res(TToken_string t, TToken_string s, TDate ad)
{
if(elabPR)
return plafond;
if(_elab_pr)
return _plafond;
else
elabPR = true;
_elab_pr = true;
if(t.full() && s.full())
{
tipi = t;
stati = s;
_tipi = t;
_stati = s;
}
if(!ad.ok())
ad = finDicInt;
plafond = -UNO;
if(!validPlafond)
return plafond;
ad = _fin_dic_int;
_plafond = -UNO;
if(!_valid_plafond)
return _plafond;
TLista_documenti din; // Legge tutti i documenti di input
// Trovo tutti i documenti che mi interessano e sottraggo l'imponibile al plafond
din.read('D', tipocf, codcli, iniDicInt.year(), tipi, stati, iniDicInt, ad);
// Trovo tutti i documenti che mi interessano e sottraggo l'imponibile al _plafond
din.read('D', _tipocf, _codcli, _ini_dic_int.year(), _tipi, _stati, _ini_dic_int, ad);
for(int i = 0; i < din.items(); i++)
{
TToken_string plaf(din[i].get("PLAFOND"), ',');
for(int j = 0; j < plaf.items(); j++)
{
TToken_string thePla(plaf.get(j));
const TString key = make_key(thePla.get_int(_planno), thePla.get_int(_plnumprot));
static TString chiusura; chiusura.cut(0) << thePla.get(_plchiusura); // La get ritorna un const char*
TToken_string the_pla(plaf.get(j));
const TString key = make_key(the_pla.get_int(_planno), the_pla.get_int(_plnumprot));
static TString chiusura; chiusura.cut(0) << the_pla.get(_plchiusura); // La get ritorna un const char*
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] = ZERO;
}
plafondi[key] += static_cast<real>(thePla.get(_plimporto));
_plafondi[key] += static_cast<real>(the_pla.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;
_valid_plafond = false;
return _plafond;
}
// Calcolo l'importo delle righe che rientrano nel plafond
plafondi.insert(std::pair<TString,real>(key, static_cast<real>(thePla.get(_plimporto))));
_plafondi.insert(std::pair<TString,real>(key, static_cast<real>(the_pla.get(_plimporto))));
}
}
else
{
if(plafondi.find(key) != plafondi.end())
if(_plafondi.find(key) != _plafondi.end())
{
if(chiusura == "X")
{
if(DEBUG_ENABLED && plafondi[key] != static_cast<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(DEBUG_ENABLED && _plafondi[key] != static_cast<real>(the_pla.get(_plimporto)) &&
!yesno_box(TR("Questa lettera di intento è incongruente,\nTotale attivo: %s\nTotale da disattivare: %s\nContinuare?"), _plafondi[key].string(), the_pla.get(_plimporto)))
{
validPlafond = false;
return plafond;
_valid_plafond = false;
return _plafond;
}
plafondi.erase(key);
_plafondi.erase(key);
}
else
{
plafondi[key] -= static_cast<real>(thePla.get(_plimporto));
_plafondi[key] -= static_cast<real>(the_pla.get(_plimporto));
}
}
}
@ -569,18 +568,18 @@ const real TLi_manager::elabPlaRes(TToken_string t, TToken_string s, TDate ad)
}
// Calcolo il totale da mappa scansionata
plafond = ZERO;
for(auto it = plafondi.begin(); it != plafondi.end(); ++it)
plafond += it->second;
_plafond = ZERO;
for(auto it = _plafondi.begin(); it != _plafondi.end(); ++it)
_plafond += it->second;
return plafond;
return _plafond;
}
const real TLi_manager::elabUtil(TToken_string tipi, TToken_string stati, TDate ad)
const real TLi_manager::elab_util(TToken_string tipi, TToken_string stati, TDate ad)
{
if(!validPlafond)
if(!_valid_plafond)
return -UNO;
if(tipi.items() == 0)
return ZERO;
@ -590,21 +589,21 @@ const real TLi_manager::elabUtil(TToken_string tipi, TToken_string stati, TDate
TLista_documenti din; // Legge tutti i documenti di input
// Trovo tutti i documenti che mi interessano e sottraggo l'imponibile al plafond
din.read('D', tipocf, codcli, iniDicInt.year(), tipi, stati, iniDicInt, ad);
din.read('D', _tipocf, _codcli, _ini_dic_int.year(), tipi, stati, _ini_dic_int, ad);
for(int i = 0; i < din.items(); i++)
{
TAssoc_array tabIva = din[i].tabella_iva(true);
for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tabIva.get(); totali != NULL; totali = (TRiepilogo_iva *) tabIva.get())
TAssoc_array tab_iva = din[i].tabella_iva(true);
for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tab_iva.get(); totali != NULL; totali = (TRiepilogo_iva *) tab_iva.get())
{
if(checkIva(totali->cod_iva().codice()))
if(check_iva(totali->cod_iva().codice()))
{
utilizzato += cache().get("%TIP", din[i].tipo().codice()).get_bool("B7") ? -totali->imp_orig() : totali->imp_orig();
}
}
// 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)
if(_soluzione)
{
utilizzato = -UNO;
break;
@ -614,21 +613,21 @@ const real TLi_manager::elabUtil(TToken_string tipi, TToken_string stati, TDate
return utilizzato;
}
bool TLi_manager::testPlafond(TLista_documenti& dout, TLog_report& lerr)
bool TLi_manager::test_plafond(TLista_documenti& dout, TLog_report& lerr)
{
bool err = false;
static TToken_string& use = get_tmp_string();
// Faccio un ragionamento identico a getPlaRes, ma in input ho la lista di documenti appena elaborati
for(int i = 0; i < dout.items() && !err; i++)
{
use.cut(0) << getUse(dout[i], true);
use.cut(0) << get_use(dout[i], true);
if(use.starts_with("ERRORE"))
{
TString msgerr;
msgerr << "Superata dichiarazione di intento cliente N." << dout[i].codcf() << "\n" << use;
lerr.log(2, msgerr);
revertModifiche();
clearModifiche();
revert_modifiche();
clear_modifiche();
err = true;
}
}
@ -637,31 +636,31 @@ bool TLi_manager::testPlafond(TLista_documenti& dout, TLog_report& lerr)
}
/* Per scelte implementative non ha una accuratezza del 100% */
bool TLi_manager::checkUtilizzo(TDocumento& d, real impNC)
bool TLi_manager::check_utilizzo(TDocumento& d, real imp_nc)
{
bool ok = true;
TToken_string lePlafs(d.get("PLAFOND"), ',');
TToken_string le_plafs(d.get("PLAFOND"), ',');
// Se me lo passa la funzione evito di calcolarlo
if(impNC.is_zero())
if(imp_nc.is_zero())
{
for (TRiepilogo_iva * totali = (TRiepilogo_iva *) d.tabella_iva(true).get(); totali != NULL; totali = (TRiepilogo_iva *) d.tabella_iva(true).get())
if(checkIva(totali->cod_iva().codice())) // Se l'iva del documento è diversa non mi interessa
impNC += totali->imp_orig();
if(check_iva(totali->cod_iva().codice())) // Se l'iva del documento è diversa non mi interessa
imp_nc += totali->imp_orig();
}
/* Per sapere se non ho usato il plafond di questa NC controllo innanzitutto se c'è ne abbastanza
* rimasto per coprire la NC, non è il controllo della vita ma toglie già un po' di calcoli */
ok = getPlaRes() > impNC;
ok = get_pla_res() > imp_nc;
// Sucessivamente vado in dettaglio a verificare se sono sempre maggiori (getPlaRes() mi carica anche la variabile "plafondi" per gli altri calcoli)
for(int i = 0; i < lePlafs.items() && ok; i++)
for(int i = 0; i < le_plafs.items() && ok; i++)
{
TToken_string thisPlaf(lePlafs.get(i));
const TString key = make_key(thisPlaf.get_int(_planno), thisPlaf.get_int(_plnumprot));
if(plafondi.find(key) != plafondi.end())
TToken_string this_plaf(le_plafs.get(i));
const TString key = make_key(this_plaf.get_int(_planno), this_plaf.get_int(_plnumprot));
if(_plafondi.find(key) != _plafondi.end())
{
ok = plafondi[key] > static_cast<real>(lePlafs.get(_plimporto));
ok = _plafondi[key] > static_cast<real>(le_plafs.get(_plimporto));
}
else
ok = false;
@ -670,56 +669,56 @@ bool TLi_manager::checkUtilizzo(TDocumento& d, real impNC)
return ok;
}
void TLi_manager::changeStato(const TString& key, const bool stato)
void TLi_manager::change_stato(const TString& key, const bool stato)
{
TRectype Jean_Baptiste_Le_Rond_dAlembert = cache().get(LF_LETINT, key); // Che nome di classe!
Jean_Baptiste_Le_Rond_dAlembert.put("CHIUSA", stato);
Jean_Baptiste_Le_Rond_dAlembert.rewrite(TLocalisamfile(LF_LETINT));
TString skey; skey << key << "|" << stato ? "" : "X"; // Ottimizzazione portami via...
modifiche.insert(std::pair<int, TString>(modifiche.size()+1, skey));
_modifiche.insert(std::pair<int, TString>(_modifiche.size()+1, skey));
}
void TLi_manager::revertModifiche()
void TLi_manager::revert_modifiche()
{
if(!hasModifiche())
if(!has_modifiche())
return;
TLocalisamfile baguette(LF_LETINT);
for(auto it = modifiche.begin(); it != modifiche.end(); ++it)
for(auto it = _modifiche.begin(); it != _modifiche.end(); ++it)
{
TToken_string key = it->second;
TRectype Jean_Baptiste_Le_Rond_dAlembert = cache().get(LF_LETINT, key.get(0)); // Che nome di classe!
Jean_Baptiste_Le_Rond_dAlembert.put("CHIUSA", key.get(1));
Jean_Baptiste_Le_Rond_dAlembert.rewrite(baguette);
}
clearModifiche();
clear_modifiche();
}
TLi_manager::TLi_manager(const char t, const long c, TDate iniDic, TDate finDic)
: tipocf (t), codcli(c), iniDicInt(iniDic), finDicInt(finDic),
codivaDef(ini_get_string(CONFIG_DITTA, "li", "CODIVA")),
codivaAlt(ini_get_string(CONFIG_DITTA, "li", "CODIVALT")),
plafond(ZERO), validPlafond(false), soluzione(false), elabPR(false)
: _tipocf (t), _codcli(c), _ini_dic_int(iniDic), _fin_dic_int(finDic),
_codiva_def(ini_get_string(CONFIG_DITTA, "li", "CODIVA")),
_codiva_alt(ini_get_string(CONFIG_DITTA, "li", "CODIVALT")),
_plafond(ZERO), _valid_plafond(false), _soluzione(false), _elab_pr(false)
{
elabTipiStati();
elabPlafond();
elab_tipi_stati();
elab_plafond();
}
TLi_manager::TLi_manager(const char t, const long c, TDate finDic)
: tipocf (t), codcli(c), finDicInt(finDic),
codivaDef(ini_get_string(CONFIG_DITTA, "li", "CODIVA")),
codivaAlt(ini_get_string(CONFIG_DITTA, "li", "CODIVALT")),
plafond(ZERO), validPlafond(false), soluzione(false), elabPR(false)
: _tipocf (t), _codcli(c), _fin_dic_int(finDic),
_codiva_def(ini_get_string(CONFIG_DITTA, "li", "CODIVA")),
_codiva_alt(ini_get_string(CONFIG_DITTA, "li", "CODIVALT")),
_plafond(ZERO), _valid_plafond(false), _soluzione(false), _elab_pr(false)
{
iniDicInt.set_day(01);
iniDicInt.set_month(01);
iniDicInt.set_year(finDic.year());
elabTipiStati();
elabPlafond();
_ini_dic_int.set_day(01);
_ini_dic_int.set_month(01);
_ini_dic_int.set_year(finDic.year());
elab_tipi_stati();
elab_plafond();
}
static void createTipiStati(TToken_string& tipi, TToken_string& stati)
static void create_tipi_stati(TToken_string& tipi, TToken_string& stati)
{
static const TToken_string tipidoc(ini_get_string(CONFIG_DITTA, "li", "TIPIDOC"));
if(tipi.blank() && stati.blank())
@ -738,17 +737,17 @@ static void createTipiStati(TToken_string& tipi, TToken_string& stati)
}
}
bool generaLiStorico(TDate dataIni)
bool genera_li_storico(const TDate& data_ini)
{
// Apro la tabella dei plafonds con chiave 2 (CODCLI+ANNO+NUMPROT) e per ogni cliente calcolo i plafond dal 2017
TRelation rletint(LF_LETINT);
TString filter = "DAL>="; filter << dataIni.date2ansi();
TString filter = "DAL>="; filter << data_ini.date2ansi();
TCursor cletint(&rletint, filter, 2);
static TToken_string tipi, stati;
createTipiStati(tipi, stati);
create_tipi_stati(tipi, stati);
static TString codIVAP = ini_get_string(CONFIG_DITTA, "li", "CODIVA");
static TString codIVAS = ini_get_string(CONFIG_DITTA, "li", "CODIVALT");
static TString cod_ivap = ini_get_string(CONFIG_DITTA, "li", "CODIVA");
static TString cod_ivas = ini_get_string(CONFIG_DITTA, "li", "CODIVALT");
TProgress_monitor status(cletint.items(), "Aggiornamento plafond");
@ -765,15 +764,15 @@ bool generaLiStorico(TDate dataIni)
continue;
// Date
TDate startCurr = rletint.get_date("DAL"), endCurr;
endCurr = rletint.get_int("CODCLI") == rletintn.get_int("CODCLI") ? --rletintn.get_date("DAL") : NULLDATE;
TDate start_curr = rletint.get_date("DAL"), end_curr;
end_curr = rletint.get_int("CODCLI") == rletintn.get_int("CODCLI") ? --rletintn.get_date("DAL") : NULLDATE;
// Dati lettera
real impLI = rletint.get_real("IMPORTO");
real imp_li = rletint.get_real("IMPORTO");
bool soluzione = rletint.get_int("TIPOOP") == SOLUZIONE_UNICA;
// Adesso che so le date apro tutti i documenti
TLista_documenti din;
din.read('D', 'C', rletint.get_long("CODCLI"), startCurr.year(), tipi, stati, startCurr, endCurr);
din.read('D', 'C', rletint.get_long("CODCLI"), start_curr.year(), tipi, stati, start_curr, end_curr);
for(int i = 0; i < din.items(); i++)
{
#ifdef DBG
@ -781,10 +780,10 @@ bool generaLiStorico(TDate dataIni)
bool tolla = true;
#endif
real utilizzato = ZERO;
TAssoc_array tabIva = din[i].tabella_iva(true);
for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tabIva.get(); totali != NULL; totali = (TRiepilogo_iva *) tabIva.get())
TAssoc_array tab_iva = din[i].tabella_iva(true);
for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tab_iva.get(); totali != NULL; totali = (TRiepilogo_iva *) tab_iva.get())
{
if(totali->cod_iva().codice() == codIVAP || totali->cod_iva().codice() == codIVAS)
if(totali->cod_iva().codice() == cod_ivap || totali->cod_iva().codice() == cod_ivas)
utilizzato += cache().get("%TIP", din[i].tipo().codice()).get_bool("B7") ? -totali->imp_orig() : totali->imp_orig();
}
@ -800,7 +799,7 @@ bool generaLiStorico(TDate dataIni)
}
// Controllo di non superare il plafond
if(impLI >= utilizzato)
if(imp_li >= utilizzato)
{
// Creo la chiave da scrivere e metto tutto dentro
const TString key = make_key(rletint.get_int("ANNO"), rletint.get_int("NUMPROT"));
@ -823,14 +822,14 @@ bool generaLiStorico(TDate dataIni)
return true;
}
bool popolaPlafond(TLista_documenti & din, const TDate& data_elab)
bool popola_plafond(TLista_documenti & din, const TDate& data_elab)
{
std::map<int, TLi_manager*> plafs;
TProgress_monitor mDoc(din.items(), "Generazione plafond nelle fatture");
TProgress_monitor m_doc(din.items(), "Generazione plafond nelle fatture");
bool ok = true;
for(int i = 0; i < din.items() && ok; i++)
{
if (!mDoc.add_status())
if (!m_doc.add_status())
return false;
// Per ogni fattura richiamo il plafond dell'intestatario e faccio le mie elaborazioni
@ -839,15 +838,15 @@ bool popolaPlafond(TLista_documenti & din, const TDate& data_elab)
TLi_manager* app = new TLi_manager(din[i].tipocf(), din[i].codcf(), data_elab);
plafs.insert(std::pair<int, TLi_manager*>(din[i].codcf(), app));
}
TLi_manager& thisPla = *plafs[din[i].codcf()]; // Forget about optimization!
if (!thisPla.hasValidPlafond()) continue;
TLi_manager& this_pla = *plafs[din[i].codcf()]; // Forget about optimization!
if (!this_pla.has_valid_plafond()) continue;
// Calcolo quanto plafond sta utilizzando
real utilizzato = ZERO;
TAssoc_array tabIva = din[i].tabella_iva(true);
for (TRiepilogo_iva * totali = (TRiepilogo_iva *)tabIva.get(); totali != NULL; totali = (TRiepilogo_iva *)tabIva.get())
TAssoc_array tab_iva = din[i].tabella_iva(true);
for (TRiepilogo_iva * totali = (TRiepilogo_iva *)tab_iva.get(); totali != NULL; totali = (TRiepilogo_iva *)tab_iva.get())
{
if (thisPla.checkIva(totali->cod_iva().codice()))
if (this_pla.check_iva(totali->cod_iva().codice()))
utilizzato += cache().get("%TIP", din[i].tipo().codice()).get_bool("B7") ? -totali->imp_orig() : totali->imp_orig();
}
@ -857,12 +856,12 @@ bool popolaPlafond(TLista_documenti & din, const TDate& data_elab)
TToken_string used;
if (din[i].tipo().nota_credito())
{
used = thisPla.incrPlaf(din[i], utilizzato, true);
used = this_pla.incr_plaf(din[i], utilizzato, true);
}
else
{
// Il controllo è andato bene, adesso mi segno i plafond che ho utilizzato nel memo del documento
used = thisPla.consPlaf(utilizzato, true);
used = this_pla.cons_plaf(utilizzato, true);
}
// Rincontrollo che l'utilizzo del pladond sia tutto ok, meglio una volta in più che una in meno!

View File

@ -24,43 +24,43 @@ enum plafStruct { _planno, _plnumprot, _plimporto, _plchiusura, _plNC };
class TLi_manager : TObject
{
TToken_string tipi;
TToken_string stati;
bool validPlafond;
bool soluzione;
bool elabPR;
const char tipocf;
const long codcli;
TToken_string _tipi;
TToken_string _stati;
bool _valid_plafond;
bool _soluzione;
bool _elab_pr;
const char _tipocf;
const long _codcli;
TDate iniDicInt;
TDate finDicInt;
real plafond;
TDate _ini_dic_int;
TDate _fin_dic_int;
real _plafond;
const TString codivaDef;
const TString codivaAlt;
const TString _codiva_def;
const TString _codiva_alt;
// Elenco di plafond con eventuale
// Chiave ANNO|NUMERO(6)
std::map<TString, real> plafondi;
std::map<int, TString> modifiche; // Progressivo, TToken_string(chiave,stato);
void elabTipiStati(); // Preparo due token string con tipi[0] -> stati[0], ...
std::map<TString, real> _plafondi;
std::map<int, TString> _modifiche; // Progressivo, TToken_string(chiave,stato);
void elab_tipi_stati(); // Preparo due token string con tipi[0] -> stati[0], ...
public:
// Getters
// Ritorno il plafond
const real getPlafond() { return plafond; }
const real get_plafond() { return _plafond; }
// Ritorno se il plafond è valido
bool hasValidPlafond() { return validPlafond; }
bool has_valid_plafond() const { return _valid_plafond; }
// Ritorna se è una dichiarazione di tipo soluzione
bool isSoluzione() { return soluzione; }
bool is_soluzione() const { return _soluzione; }
// Funzione che unisce consPlaf e incrPlaf
const TToken_string& getUse(TDocumento& d, const bool write = false);
const TToken_string& get_use(TDocumento& d, const bool write = false);
// "Consuma" il plafond
const TToken_string& consPlaf(real& plafUsed, const bool write = false);
const TToken_string& cons_plaf(real& plaf_used, const bool write = false);
// Da una nota credito passata incremento il plafond
const TToken_string& incrPlaf(TDocumento& d, real impNC = ZERO, const bool write = false);
const TToken_string& incr_plaf(TDocumento& d, real imp_nc = ZERO, const bool write = false);
// Storna un documento che riceve
const TToken_string& stornaDoc(const TDocumento& d, real impDC = ZERO, const bool write = false);
const TToken_string& storna_doc(const TDocumento& d, real imp_dc = ZERO, const bool write = false);
// Storna i documenti dopo a quello che riceve
//void stornaDocs(const TDocumento& d, const bool write = false);
// Ricalcola i documenti dopo quello che riceve
@ -69,41 +69,41 @@ public:
// Functions
// Vado a estrapolare il plafond
void elabPlafond();
void elab_plafond();
// Testo se con i documenti passati supero il plafond
bool testPlafond(TLista_documenti& dout, TLog_report& lerr);
bool test_plafond(TLista_documenti& dout, TLog_report& lerr);
// Controllo se il codice iva è uguale a quello impostato per il calcolo del plafond
bool checkIva(TString cod) { return cod == codivaDef || cod == codivaAlt; }
bool check_iva(const TString& cod) const { return cod == _codiva_def || cod == _codiva_alt; }
// Controllo se il plafond che la NC passata rilascia non è già stato utilizzato
bool checkUtilizzo(TDocumento& d, real impNC = ZERO);
bool check_utilizzo(TDocumento& d, real imp_nc = ZERO);
// Calcolo il rimanente del plafond
const real getPlaRes();
const real get_pla_res();
// Calcolo il rimanente del plafond su tipi e stati documento passati
const real getPlaRes(TToken_string tipi, TToken_string stati);
const real get_pla_res(TToken_string tipi, TToken_string stati);
// Funzione che effettivamente effettua il calcolodalla data della dichiarazione alla data passata
const real elabPlaRes(TToken_string t = "", TToken_string s = "", TDate ad = 0L);
const real elab_pla_res(TToken_string t = "", TToken_string s = "", TDate ad = 0L);
// Ritorna la quantità di plafond utilizzato dalla data della dichiarazione alla data passata
const real elabUtil(TToken_string tipi, TToken_string stati, TDate ad = 0L);
const real elab_util(TToken_string tipi, TToken_string stati, TDate ad = 0L);
// Modifica una lettera e salva la modifica in "modifiche"
void changeStato(const TString& key, const bool stato);
void change_stato(const TString& key, const bool stato);
// Controlla se ci sono delle modifiche da salvare nei plafonds
bool hasModifiche() { return !modifiche.empty(); }
bool has_modifiche() const { return !_modifiche.empty(); }
// Annullo le modifiche
void revertModifiche();
void revert_modifiche();
// Vuoto le modifiche
void clearModifiche() { modifiche.clear(); }
void clear_modifiche() { _modifiche.clear(); }
// Costructors/Destructors
TLi_manager(const char t, const long c, TDate iniDic, TDate finDic);
TLi_manager(const char t, const long c, TDate finDic); // Sets iniDicInt as 01/01/finDic.year()
TLi_manager(const char t, const long c, TDate ini_dic, TDate fin_dic);
TLi_manager(const char t, const long c, TDate fin_dic); // Sets iniDicInt as 01/01/finDic.year()
virtual ~TLi_manager() {}
};
static void createTipiStati(TToken_string& tipi, TToken_string& stati);
bool generaLiStorico(TDate dataIni);
bool popolaPlafond(TLista_documenti& din, const TDate& data_elab);
static void create_tipi_stati(TToken_string& tipi, TToken_string& stati);
bool genera_li_storico(const TDate& data_ini);
bool popola_plafond(TLista_documenti& din, const TDate& data_elab);
#endif

View File

@ -528,7 +528,7 @@ int TMotore_application::write( const TMask& m ) // C 90
}
// Aggiunte per il controllo plafond
if(has_module(LIAUT, CHK_DONGLE) && d.tipo().is_fattura() && ini_get_bool(CONFIG_DITTA, "ve", "USELETTERE") && checkPlafondWrite(d) == -1)
if(has_module(LIAUT, CHK_DONGLE) && d.tipo().is_fattura() && ini_get_bool(CONFIG_DITTA, "ve", "USELETTERE") && check_plafond_write(d) == -1)
{
return _isnowarning;
}
@ -564,7 +564,7 @@ int TMotore_application::rewrite( const TMask& m ) // C 90
d = ((TDocumento_mask&)m).doc(); // Trasferisce il documento da maschera a record
// Aggiunte per il controllo plafond
if(has_module(LIAUT, CHK_DONGLE) && d.tipo().is_fattura() && ini_get_bool(CONFIG_DITTA, "ve", "USELETTERE") && checkPlafondRewrite(d) == -1)
if(has_module(LIAUT, CHK_DONGLE) && d.tipo().is_fattura() && ini_get_bool(CONFIG_DITTA, "ve", "USELETTERE") && check_plafond_rewrite(d) == -1)
{
return _isnowarning;
}
@ -583,7 +583,7 @@ int TMotore_application::rewrite( const TMask& m ) // C 90
bool TMotore_application::remove() // C 90
{
TDocumento& d = (TDocumento &) _rel->curr();
bool ok = checkPlafondDelete(d);
bool ok = check_plafond_delete(d);
if(ok)
{
d.put(DOC_NOTE, "DELETING");
@ -710,7 +710,7 @@ bool TMotore_application::user_create( )
open_files(LF_DOC, LF_RIGHEDOC, LF_CONDV, LF_RCONDV, LF_ANAMAG, LF_SCONTI, LF_UMART, LF_DESLIN, LF_CODCORR,
LF_TAB, LF_TABCOM, LF_CLIFO, LF_CFVEN, LF_INDSP, LF_OCCAS, LF_PCON, LF_MOV, LF_STOMAG,
LF_MOVMAG, LF_RMOVMAG, LF_MAG, LF_SVRIEP, LF_AGENTI, LF_PERCPROV, LF_ATTIV, LF_CAUSALI, 0);
TISAM_recordset num("USE %NUM");
for (bool ok = num.move_first(); ok; ok = num.move_next())
cached_numerazione(num.get("CODTAB").as_string());
@ -1313,48 +1313,47 @@ void TMotore_application::preview()
save_and_print(true, screenvis);
}
int TMotore_application::checkPlafondWrite(TDocumento& d)
int TMotore_application::check_plafond_write(TDocumento& d)
{
TLi_manager plafond(d.tipocf(), d.codcf(), d.data());
if(!plafond.hasValidPlafond()) // Se il cliente non mi interessa
if(!plafond.has_valid_plafond()) // Se il cliente non mi interessa
return NOERR;
TAssoc_array tabIva = d.tabella_iva(true);
TAssoc_array tab_iva = d.tabella_iva(true);
real plaUtil = ZERO;
real pla_util = ZERO;
for (TRiepilogo_iva * totali = static_cast<TRiepilogo_iva *>(tabIva.get()); totali != NULL; totali = static_cast<TRiepilogo_iva *>(tabIva.get()))
for (TRiepilogo_iva * totali = dynamic_cast<TRiepilogo_iva *>(tab_iva.get()); totali != nullptr; totali = dynamic_cast<TRiepilogo_iva *>(tab_iva.get()))
{
if(plafond.checkIva(totali->cod_iva().codice())) // Se l'iva del documento è diversa non mi interessa
if(plafond.check_iva(totali->cod_iva().codice())) // Se l'iva del documento è diversa non mi interessa
{
plaUtil += totali->imp_orig();
pla_util += totali->imp_orig();
}
}
if(plaUtil <= ZERO)
if(pla_util <= ZERO)
{
return NOERR;
}
real plaRes = plafond.getPlaRes();
real pla_res = plafond.get_pla_res();
TToken_string used;
if(d.tipo().nota_credito())
{
used = plafond.incrPlaf(d, plaUtil, true);
used = plafond.incr_plaf(d, pla_util, true);
}
else
{
// Il controllo è andato bene, adesso mi segno i plafond che ho utilizzato nel memo del documento
used = plafond.consPlaf(plaUtil, true);
used = plafond.cons_plaf(pla_util, true);
}
if(used.starts_with("ERRORE"))
{
plafond.revertModifiche();
plafond.revert_modifiche();
TString msg("Attenzione il plafond è stato superato di ");
msg << TCurrency(-(plaRes - plaUtil)).string() << "";
msg << TCurrency(-(pla_res - pla_util)).string() << "";
warning_box(msg);
return -1;
}
@ -1365,39 +1364,39 @@ int TMotore_application::checkPlafondWrite(TDocumento& d)
}
}
int TMotore_application::checkPlafondRewrite(TDocumento& d)
int TMotore_application::check_plafond_rewrite(TDocumento& d)
{
TLi_manager plafond(d.tipocf(), d.codcf(), d.data());
if(!plafond.hasValidPlafond()) // Se il cliente non mi interessa
if(!plafond.has_valid_plafond()) // Se il cliente non mi interessa
return NOERR;
TAssoc_array tabIva = d.tabella_iva(true);
TDocumento oldDoc;
TAssoc_array tab_iva = d.tabella_iva(true);
TDocumento old_doc;
real plaUtil = ZERO;
real pla_util = 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();
for (TRiepilogo_iva * totali = dynamic_cast<TRiepilogo_iva *>(tab_iva.get()); totali != nullptr; totali = dynamic_cast<TRiepilogo_iva *>(tab_iva.get()))
if(plafond.check_iva(totali->cod_iva().codice())) // Se l'iva del documento è diversa non mi interessa
pla_util += totali->imp_orig();
if(plaUtil <= ZERO)
if(pla_util <= ZERO)
return NOERR;
// 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++)
TToken_string le_plafs(d.get("PLAFOND"), ',');
real tot_plaf = ZERO;
for(int i = 0; i < le_plafs.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);
tot_plaf += static_cast<real>(static_cast<TToken_string>(le_plafs.get(i)).get(_plimporto));
}
// Calcolo le differenze tra il plafond attuale da verificare e quello precedente
if(totPlaf == plaUtil)
if(tot_plaf == pla_util)
return NOERR;
real plaRes = plafond.getPlaRes();
real pla_res = plafond.get_pla_res();
TToken_string used;
/* Devo gestire queste modifiche dividendo in 4 parti:
* 1) > vecchio Doc : faccio la differenza nuovo - vecchio e provo a generare un used nuovo
@ -1405,34 +1404,34 @@ int TMotore_application::checkPlafondRewrite(TDocumento& d)
* 3) < vecchio Doc : storno parte del plafond già utilizzato
* 4) < vecchio NC : verifico che il plafond stornato con questa NC non sia stato utilizzato, in caso negativo tutto OK, positivo blocco.
*/
if(totPlaf < plaUtil)
if(tot_plaf < pla_util)
{
if(d.tipo().nota_credito()) // 2
{
plaUtil -= totPlaf;
used = plafond.incrPlaf(d, plaUtil, true);
pla_util -= tot_plaf;
used = plafond.incr_plaf(d, pla_util, true);
}
else // 1
{
plaUtil -= totPlaf;
used = plafond.consPlaf(plaUtil, true);
pla_util -= tot_plaf;
used = plafond.cons_plaf(pla_util, true);
}
}
else
{
if(d.tipo().nota_credito()) // 4
{
if(plafond.checkUtilizzo(d, plaUtil))
if(plafond.check_utilizzo(d, pla_util))
{
TString msg = "Attenzione! Si sta cercando di modificare una Nota di Credito che influisce le seguenti lettere di intento: \n";
for(int i = 0; i < lePlafs.items(); i++)
for(int i = 0; i < le_plafs.items(); i++)
{
msg << i+1 << " - N." << lePlafs.get(_plnumprot) << "\n";
msg << i+1 << " - N." << le_plafs.get(_plnumprot) << "\n";
}
msg << "Vuoi continuare?";
if(yesno_box(msg))
{
used = plafond.stornaDoc(d, totPlaf - plaUtil, true);
used = plafond.storna_doc(d, tot_plaf - pla_util, true);
}
else
return -1;
@ -1442,13 +1441,13 @@ int TMotore_application::checkPlafondRewrite(TDocumento& d)
}
else // 3
{
used = plafond.stornaDoc(d, totPlaf - plaUtil, true);
used = plafond.storna_doc(d, tot_plaf - pla_util, true);
}
}
if(used.starts_with("ERRORE"))
{
plafond.revertModifiche();
plafond.revert_modifiche();
warning_box(used);
return -1;
}
@ -1459,30 +1458,30 @@ int TMotore_application::checkPlafondRewrite(TDocumento& d)
}
}
bool TMotore_application::checkPlafondDelete(TDocumento& d)
bool TMotore_application::check_plafond_delete(TDocumento& d)
{
TLi_manager plafond(d.tipocf(), d.codcf(), d.data());
if(d.get("PLAFOND").blank() || !plafond.hasValidPlafond()) // Se la fattura non ha nulla scritto in plafond non mi interessa
if(d.get("PLAFOND").blank() || !plafond.has_valid_plafond()) // Se la fattura non ha nulla scritto in plafond non mi interessa
return true;
TAssoc_array tabIva = d.tabella_iva(true);
TDocumento oldDoc;
TAssoc_array tab_iva = d.tabella_iva(true);
TDocumento old_doc;
// 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"), ',');
TToken_string le_plafs(d.get("PLAFOND"), ',');
real totPlaf = ZERO;
for(int i = 0; i < lePlafs.items(); i++)
for(int i = 0; i < le_plafs.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);
totPlaf += static_cast<real>(static_cast<TToken_string>(le_plafs.get(i)).get(_plimporto));
}
// Calcolo le differenze tra il plafond attuale da verificare e quello precedente
if(totPlaf == ZERO)
return true;
real plaRes = plafond.getPlaRes();
real pla_res = plafond.get_pla_res();
TToken_string used;
/* Devo gestire queste modifiche dividendo in 4 parti:
* 1) < vecchio Doc : storno parte del plafond già utilizzato
@ -1490,18 +1489,18 @@ bool TMotore_application::checkPlafondDelete(TDocumento& d)
*/
if(d.tipo().nota_credito()) // 2
{
if(plafond.checkUtilizzo(d, totPlaf))
if(plafond.check_utilizzo(d, totPlaf))
{
TString msg = "Attenzione! Si sta cercando di modificare una Nota di Credito che influisce le seguenti lettere di intento: \n";
for(int i = 0; i < lePlafs.items(); i++)
for(int i = 0; i < le_plafs.items(); i++)
{
TToken_string thisPlaf(lePlafs.get(i));
msg << i+1 << " - N." << thisPlaf.get(_plnumprot) << "\n";
TToken_string this_plaf(le_plafs.get(i));
msg << i+1 << " - N." << this_plaf.get(_plnumprot) << "\n";
}
msg << "Vuoi continuare?";
if(yesno_box(msg))
{
used = plafond.stornaDoc(d, totPlaf, true);
used = plafond.storna_doc(d, totPlaf, true);
}
else
return false;
@ -1511,23 +1510,23 @@ bool TMotore_application::checkPlafondDelete(TDocumento& d)
}
else // 1
{
real plafSto = ZERO;
for(int i = 0; i < lePlafs.items(); i++)
real plaf_sto = ZERO;
for(int i = 0; i < le_plafs.items(); i++)
{
TToken_string thisPlaf(lePlafs.get(i));
plafSto += static_cast<real>(thisPlaf.get(_plNC));
TToken_string this_plaf(le_plafs.get(i));
plaf_sto += static_cast<real>(this_plaf.get(_plNC));
}
if(plafSto > ZERO)
if(plaf_sto > ZERO)
{
if(!yesno_box(TR("Attenzione! Si sta cercando di eliminare un documento per cui sono presenti una o più note di variazione per un totale di %s€\nContinuare?"), TCurrency(plafSto).string()))
if(!yesno_box(TR("Attenzione! Si sta cercando di eliminare un documento per cui sono presenti una o più note di variazione per un totale di %s€\nContinuare?"), TCurrency(plaf_sto).string()))
return false;
}
used = plafond.stornaDoc(d, totPlaf, true);
used = plafond.storna_doc(d, totPlaf, true);
}
if(used.starts_with("ERRORE"))
{
plafond.revertModifiche();
plafond.revert_modifiche();
warning_box(used);
return false;
}

View File

@ -109,9 +109,9 @@ public:
virtual const char* get_next_key( );
// Test Plafond
int checkPlafondWrite(TDocumento& d);
int checkPlafondRewrite(TDocumento& d);
bool checkPlafondDelete(TDocumento& d);
int check_plafond_write(TDocumento& d);
int check_plafond_rewrite(TDocumento& d);
bool check_plafond_delete(TDocumento& d);
};
inline TMotore_application& app() { return (TMotore_application &) main_app(); }