Files correlati : ve0|ve6 Commento : Modificata dichiarazione di intento: - Aggiunta data inizio dichiarazione - Eliminate dichiarazioni di intento "Nel periodo" - Campo adesso sovrascrive i parametri CFVEN riguardanti la dichiarazione di intento - Aggiunto controllo per chi non ha la dichiarazione di intento in Documenti interattivi git-svn-id: svn://10.65.10.50/branches/R_10_00@23666 c028cbd2-c16b-5b4b-a496-9718f37d4682
193 lines
5.4 KiB
C++
193 lines
5.4 KiB
C++
#include "lilib01.h"
|
||
#include <recarray.h>
|
||
|
||
#define SOLUZIONE_UNICA 1
|
||
#define FINO_A_PLAFOND 2
|
||
|
||
void TLi_manager::elabTipiStati(TToken_string& tipi, TToken_string& stati)
|
||
{
|
||
for(int i = 0; i < tipidoc.items(); i++)
|
||
{
|
||
TString app("");
|
||
tipidoc.get(i, app);
|
||
TToken_string statidoc(ini_get_string(CONFIG_DITTA, "li", app), ',');
|
||
for(int j = statidoc.get_int(0); j <= statidoc.get_int(1); j++)
|
||
{
|
||
tipi.add(app);
|
||
stati.add(j);
|
||
}
|
||
}
|
||
}
|
||
|
||
void TLi_manager::elabPlafond()
|
||
{
|
||
TRelation letint(LF_LETINT);
|
||
TRectype filtro(letint.curr());
|
||
filtro.add("CODCLI", codcli);
|
||
|
||
if(year == -1)
|
||
year = TDate(TODAY).year();
|
||
filtro.add("ANNO", year);
|
||
|
||
// Creo un cursore ordinato e prelevo la prima riga non chiusa
|
||
TCursor c_dicint(&letint, "", 2, &filtro, &filtro);
|
||
|
||
validPlafond = false;
|
||
bool done = false;
|
||
|
||
if(c_dicint.items() > 0)
|
||
{
|
||
for(c_dicint = 0; c_dicint.pos() < c_dicint.items() && !done; ++c_dicint)
|
||
{
|
||
TRectype row = c_dicint.curr();
|
||
if(!row.get_bool("CHIUSA"))
|
||
{
|
||
done = true;
|
||
if(row.get_int("TIPOOP") != FINO_A_PLAFOND && row.get_int("TIPOOP") != SOLUZIONE_UNICA) continue;
|
||
|
||
if(row.get_int("TIPOOP") == SOLUZIONE_UNICA) soluzione = true;
|
||
year = row.get_int("ANNO");
|
||
iniDicInt = row.get_date("DAL");
|
||
plafond = row.get_real("IMPORTO");
|
||
validPlafond = true;
|
||
|
||
// Salvo le informazioni nel cliente:
|
||
TRectype cli = cache().get(LF_CFVEN, TString("C|")<<codcli);
|
||
cli.put("VSNRPROT", row.get_int("VSPROT"));
|
||
cli.put("VSDATAREG", row.get_date("VSDATA"));
|
||
cli.put("NSNPROT", row.get_int("NUMPROT"));
|
||
cli.put("NSDATAREG", row.get_date("DATAREG"));
|
||
cli.rewrite(TLocalisamfile(LF_CFVEN));
|
||
}
|
||
}
|
||
}
|
||
if(!validPlafond)
|
||
plafond = -UNO;
|
||
}
|
||
|
||
const real TLi_manager::getPlaRes()
|
||
{
|
||
TToken_string tipi, stati;
|
||
elabTipiStati(tipi, stati);
|
||
return elabPlaRes(tipi, stati);
|
||
}
|
||
|
||
const real TLi_manager::getPlaRes(TToken_string tipi, TToken_string stati)
|
||
{
|
||
return elabPlaRes(tipi, stati);
|
||
}
|
||
|
||
const real TLi_manager::elabPlaRes(TToken_string tipi, TToken_string stati, TDate ad)
|
||
{
|
||
if(!validPlafond)
|
||
return -UNO;
|
||
|
||
real resPlafond = 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, year, tipi, stati, iniDicInt, 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())
|
||
{
|
||
if(totali->cod_iva().codice() == codiva)
|
||
{
|
||
resPlafond -= 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<67> trovato dei documenti vuol dire che il plafond non <20> pi<70> valido
|
||
if(soluzione)
|
||
{
|
||
resPlafond = -UNO;
|
||
break;
|
||
}
|
||
}
|
||
|
||
return resPlafond;
|
||
}
|
||
|
||
const real TLi_manager::elabUtil(TToken_string tipi, TToken_string stati, TDate ad)
|
||
{
|
||
if(!validPlafond)
|
||
return -UNO;
|
||
|
||
real utilizzato = ZERO;
|
||
|
||
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, year, tipi, stati, iniDicInt, 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())
|
||
{
|
||
if(totali->cod_iva().codice() == codiva)
|
||
{
|
||
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<67> trovato dei documenti vuol dire che il plafond non <20> pi<70> valido
|
||
if(soluzione)
|
||
{
|
||
utilizzato = -UNO;
|
||
break;
|
||
}
|
||
}
|
||
|
||
return utilizzato;
|
||
}
|
||
|
||
bool TLi_manager::testPlafond(TLista_documenti dout, TLog_report& lerr)
|
||
{
|
||
bool err = false;
|
||
real resPlafond = getPlaRes();
|
||
real testPlafond = getPlaRes();
|
||
real totFatt;
|
||
int i = 0;
|
||
|
||
// Faccio un ragionamento identico a getPlaRes, ma in input ho la lista di documenti appena elaborati
|
||
for(int i = 0; i < dout.items(); i++)
|
||
{
|
||
TAssoc_array tabIva = dout[i].tabella_iva(true);
|
||
for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tabIva.get(); totali != NULL; totali = (TRiepilogo_iva *) tabIva.get())
|
||
{
|
||
if(totali->cod_iva().codice() == codiva)
|
||
{
|
||
resPlafond -= totali->imp_orig();
|
||
totFatt += totali->imp_orig();
|
||
}
|
||
}
|
||
}
|
||
if(resPlafond < 0)
|
||
{
|
||
err = true; // Alzo il flag dell'errore
|
||
|
||
TString msgerr;
|
||
msgerr << "Superata dichiarazione di intento cliente N." << dout[i].codcf() << "\nPlafond rimanente: " << resPlafond + totFatt << "\nTotale fatture generate: " << totFatt << "\nSforato di: " << -resPlafond << "\n";
|
||
lerr.log(2, msgerr); // 2 <- Errore
|
||
}
|
||
|
||
return err;
|
||
}
|
||
|
||
// TIPOCF, CODCLI, ANNO
|
||
TLi_manager::TLi_manager(const char t, const long c, int y)
|
||
: tipocf(t), codcli(c), year(y), iniDicInt(),
|
||
tipidoc(ini_get_string(CONFIG_DITTA, "li", "TIPIDOC")), codiva(ini_get_string(CONFIG_DITTA, "li", "CODIVA")),
|
||
plafond(-UNO), validPlafond(false), soluzione(false)
|
||
{
|
||
elabPlafond();
|
||
}
|
||
|
||
TLi_manager::~TLi_manager() // Perch<63> se lo sposto nel file .h il programma crasha?
|
||
{
|
||
|
||
} |