2017-02-09 14:42:17 +00:00
|
|
|
#include "lilib01.h"
|
2017-02-13 14:33:49 +00:00
|
|
|
#include <recarray.h>
|
2017-02-09 14:42:17 +00:00
|
|
|
|
|
|
|
#define FINO_A_PLAFOND 2
|
|
|
|
|
|
|
|
void TLi_manager::elabTipiStati(TToken_string& tipi, TToken_string& stati)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < tipidoc.items(); i++)
|
|
|
|
{
|
|
|
|
TToken_string statidoc(ini_get_string(CONFIG_DITTA, "li", tipidoc.get(i)), ',');
|
2017-02-13 14:33:49 +00:00
|
|
|
for(int j = statidoc.get_int(0); j <= statidoc.get_int(1); j++)
|
2017-02-09 14:42:17 +00:00
|
|
|
{
|
|
|
|
tipi.add(tipidoc.get(i));
|
2017-02-13 14:33:49 +00:00
|
|
|
stati.add(j);
|
2017-02-09 14:42:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TLi_manager::elabPlafond()
|
|
|
|
{
|
|
|
|
TRelation letint(LF_LETINT);
|
|
|
|
TRectype filtro(letint.curr());
|
|
|
|
filtro.add("CODCLI", codcli);
|
|
|
|
|
|
|
|
if(year != -1)
|
|
|
|
filtro.add("ANNO", year);
|
|
|
|
|
|
|
|
// Creo un cursore ordinato e prelevo la prima riga non chiusa
|
|
|
|
TSorted_cursor c_dicint(&letint, "ANNO-|NUMPROT-", "", 2, &filtro, &filtro);
|
|
|
|
|
|
|
|
validPlafond = false;
|
|
|
|
|
|
|
|
if(c_dicint.items() > 0)
|
|
|
|
{
|
|
|
|
for(c_dicint = 0; c_dicint.pos() < c_dicint.items(); ++c_dicint)
|
|
|
|
{
|
|
|
|
TRectype row = c_dicint.curr();
|
|
|
|
if(!row.get_bool("CHIUSA"))
|
|
|
|
{
|
|
|
|
if(row.get_int("TIPOOP") != FINO_A_PLAFOND)
|
|
|
|
{
|
|
|
|
plafond = -UNO;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
year = row.get_int("ANNO");
|
|
|
|
iniDicInt = row.get_date("VSDATA");
|
|
|
|
plafond = row.get_real("IMPORTO");
|
|
|
|
validPlafond = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
plafond = -UNO;
|
|
|
|
}
|
|
|
|
|
|
|
|
const real TLi_manager::getPlaRes()
|
|
|
|
{
|
|
|
|
if(!validPlafond)
|
|
|
|
return -UNO;
|
|
|
|
|
|
|
|
real resPlafond = plafond;
|
|
|
|
|
|
|
|
TLista_documenti din; // Legge tutti i documenti di input
|
|
|
|
TToken_string tipi, stati;
|
|
|
|
elabTipiStati(tipi, stati);
|
2017-02-13 14:33:49 +00:00
|
|
|
TDate ad(31, 12, year);
|
2017-02-09 14:42:17 +00:00
|
|
|
|
|
|
|
// Trovo tutti i documenti che mi interessano e sottraggo l'imponibile al plafond
|
2017-02-10 09:37:04 +00:00
|
|
|
din.read('D', tipocf, codcli, year, tipi, stati, iniDicInt, ad);
|
|
|
|
|
|
|
|
for(int i = 0; i < din.items(); i++)
|
2017-02-09 14:42:17 +00:00
|
|
|
{
|
|
|
|
TAssoc_array tabIva = din[i].tabella_iva(true);
|
|
|
|
TString numerazione = din[i].numerazione();
|
|
|
|
int numdoc = din[i].numero();
|
|
|
|
int anno = din[i].anno();
|
|
|
|
TRiepilogo_iva * totali = static_cast<TRiepilogo_iva *>(tabIva.get());
|
|
|
|
if(totali->cod_iva() == codiva)
|
|
|
|
{
|
2017-02-13 14:33:49 +00:00
|
|
|
resPlafond -= cache().get("%TIP", din[i].tipo().codice()).get_bool("B7") ? -totali->imp_orig() : totali->imp_orig();
|
2017-02-09 14:42:17 +00:00
|
|
|
}
|
|
|
|
if(resPlafond < 0) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return resPlafond;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TLi_manager::testPlafond(TLista_documenti dout, TLog_report& lerr)
|
|
|
|
{
|
2017-02-10 09:37:04 +00:00
|
|
|
bool err = false;
|
2017-02-09 14:42:17 +00:00
|
|
|
real resPlafond = getPlaRes();
|
2017-02-10 09:37:04 +00:00
|
|
|
real testPlafond = getPlaRes();
|
|
|
|
real totFatt;
|
2017-02-09 14:42:17 +00:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
// Faccio un ragionamento identico a getPlaRes, ma in input ho la lista di documenti appena elaborati
|
2017-02-10 09:37:04 +00:00
|
|
|
for(int i = 0; i < dout.items(); i++)
|
2017-02-09 14:42:17 +00:00
|
|
|
{
|
|
|
|
TAssoc_array tabIva = dout[i].tabella_iva(true);
|
|
|
|
TString numerazione = dout[i].numerazione();
|
|
|
|
int numdoc = dout[i].numero();
|
|
|
|
int anno = dout[i].anno();
|
|
|
|
TRiepilogo_iva * totali = static_cast<TRiepilogo_iva *>(tabIva.get());
|
|
|
|
if(totali->cod_iva() == codiva)
|
|
|
|
{
|
2017-02-10 09:37:04 +00:00
|
|
|
resPlafond -= totali->imp_orig();
|
|
|
|
totFatt += totali->imp_orig();
|
2017-02-09 14:42:17 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-10 09:37:04 +00:00
|
|
|
if(resPlafond < 0)
|
2017-02-09 14:42:17 +00:00
|
|
|
{
|
2017-02-10 09:37:04 +00:00
|
|
|
err = true; // Alzo il flag dell'errore
|
|
|
|
|
|
|
|
TString msgerr;
|
2017-02-10 14:44:27 +00:00
|
|
|
msgerr << "Superata dichiarazione di intento cliente N." << dout[i].codcf() << "\nPlafond rimanente: " << resPlafond + totFatt << "\nTotale fatture generate: " << totFatt << "\nSforato di: " << -resPlafond << "\n";
|
2017-02-10 09:37:04 +00:00
|
|
|
lerr.log(2, msgerr); // 2 <- Errore
|
2017-02-09 14:42:17 +00:00
|
|
|
}
|
2017-02-10 09:37:04 +00:00
|
|
|
|
|
|
|
return err;
|
2017-02-09 14:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
elabPlafond();
|
|
|
|
// Estrapolo il codice iva
|
|
|
|
codiva = TCodiceIVA(ini_get_string(CONFIG_DITTA, "li", "CODIVA"));
|
|
|
|
}
|