Patch level : 12.0 1066
Files correlati : cg4.exe Commento : Le note di credito per cassa non legate a fattura non venivao liquidate dopo un anno. Interno : Diana Le note di credito 40177 40178 40179 sono state sganciate per liquidarle nma non venivano liquidate ugualmente dopo un anno.
This commit is contained in:
parent
e74a377286
commit
3cdb00e15f
@ -449,7 +449,7 @@ protected:
|
|||||||
bool print_inc_diff_log(int& rw, int tipoatt, int tipoiva);
|
bool print_inc_diff_log(int& rw, int tipoatt, int tipoiva);
|
||||||
bool print_dainc_diff_log(int& rw, int tipoatt, int tipoiva);
|
bool print_dainc_diff_log(int& rw, int tipoatt, int tipoiva);
|
||||||
bool ivadiff_chiusa(const TRectype& mov, const TDate& fine) const;
|
bool ivadiff_chiusa(const TRectype& mov, const TDate& fine) const;
|
||||||
bool sarebbe_maturata(const TRectype& mov, const TDate& inizio, const TDate& fine) const;
|
bool sarebbe_maturata(const TRectype& mov, const TDate& inizio, const TDate& fine, tipo_movimento tm2check = tm_fattura) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -33,16 +33,36 @@
|
|||||||
// ----------------------------------------------------- ******************
|
// ----------------------------------------------------- ******************
|
||||||
|
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
bool check_nreg(long nreg)
|
|
||||||
{
|
|
||||||
long __nreg[] = { 41221L, 0L };
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
while (__nreg[i] > 0L)
|
#define _BREAK(func, par, values) func(par, values);
|
||||||
if (__nreg[i++] == nreg)
|
#define BREAK_DBG _BREAK(check_nreg, __nreg, __values)
|
||||||
|
#define LOAD_VAL load_values()
|
||||||
|
|
||||||
|
const char * load_values()
|
||||||
|
{
|
||||||
|
TFilename dbgname;
|
||||||
|
TFilename filename("dbg");
|
||||||
|
|
||||||
|
filename << main_app().name();
|
||||||
|
dbgname.currdir();
|
||||||
|
dbgname.add(filename);
|
||||||
|
dbgname.ext("ini");
|
||||||
|
return ini_get_string(dbgname, "Main", "Values");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool check_nreg(TToken_string &nreg, TToken_string &values)
|
||||||
|
{
|
||||||
|
long reg = atol(nreg);
|
||||||
|
|
||||||
|
FOR_EACH_TOKEN(values, val)
|
||||||
|
{
|
||||||
|
if (atol(val) == reg)
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#define BREAK_DBG;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool TLiquidazione_app::recalc_all()
|
bool TLiquidazione_app::recalc_all()
|
||||||
@ -639,6 +659,9 @@ bool TLiquidazione_app::ivadiff_chiusa(const TRectype& mov, const TDate& fine) c
|
|||||||
TRectype& rid = id.curr();
|
TRectype& rid = id.curr();
|
||||||
rid.put(MOV_NUMREG, numreg);
|
rid.put(MOV_NUMREG, numreg);
|
||||||
int err = id.read(_isgteq);
|
int err = id.read(_isgteq);
|
||||||
|
TDate data_maturazione = mov.get_date(MOV_DATADOC);
|
||||||
|
|
||||||
|
data_maturazione.addyear();
|
||||||
if (err == NOERR && rid.get_long(MOV_NUMREG) == numreg)
|
if (err == NOERR && rid.get_long(MOV_NUMREG) == numreg)
|
||||||
{
|
{
|
||||||
bool some_pag = false; // Ci sono pagamenti?
|
bool some_pag = false; // Ci sono pagamenti?
|
||||||
@ -646,7 +669,7 @@ bool TLiquidazione_app::ivadiff_chiusa(const TRectype& mov, const TDate& fine) c
|
|||||||
for (; err == NOERR && rid.get_long(MOV_NUMREG) == numreg; err = id.next())
|
for (; err == NOERR && rid.get_long(MOV_NUMREG) == numreg; err = id.next())
|
||||||
{
|
{
|
||||||
const TDate data = rid.get("DATAREGP");
|
const TDate data = rid.get("DATAREGP");
|
||||||
if (data > fine && !_end_cassa)
|
if ((data > fine || data > data_maturazione) && !_end_cassa)
|
||||||
continue;
|
continue;
|
||||||
if (data == fine && rid.get_long("NUMREGP") == numreg && !_end_cassa)
|
if (data == fine && rid.get_long("NUMREGP") == numreg && !_end_cassa)
|
||||||
continue; // Ignora pagamento automatico dopo un anno
|
continue; // Ignora pagamento automatico dopo un anno
|
||||||
@ -660,7 +683,7 @@ bool TLiquidazione_app::ivadiff_chiusa(const TRectype& mov, const TDate& fine) c
|
|||||||
some_pag = true;
|
some_pag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
chiusa = some_pag && tot.valore() < 0.01;
|
chiusa = some_pag && tot.valore() < 0.01;
|
||||||
}
|
}
|
||||||
return chiusa;
|
return chiusa;
|
||||||
}
|
}
|
||||||
@ -675,9 +698,11 @@ static TDate data_maturazione_IVA_diff(const TRectype& mov)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fattura più vecchia di un anno a ente NON pubblico
|
// Fattura più vecchia di un anno a ente NON pubblico
|
||||||
bool TLiquidazione_app::sarebbe_maturata(const TRectype& mov, const TDate& inizio, const TDate& fine) const
|
bool TLiquidazione_app::sarebbe_maturata(const TRectype& mov, const TDate& inizio, const TDate& fine, tipo_movimento tm2check) const
|
||||||
{
|
{
|
||||||
if (mov.get_int(MOV_TIPOMOV) != tm_fattura)
|
const tipo_movimento tm = (tipo_movimento) mov.get_int(MOV_TIPOMOV);
|
||||||
|
|
||||||
|
if (tm != tm2check)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const TDate data_lim = data_maturazione_IVA_diff(mov); // Data limite (un anno dopo quella di riferimento)
|
const TDate data_lim = data_maturazione_IVA_diff(mov); // Data limite (un anno dopo quella di riferimento)
|
||||||
@ -686,8 +711,9 @@ bool TLiquidazione_app::sarebbe_maturata(const TRectype& mov, const TDate& inizi
|
|||||||
|
|
||||||
// La data di riferimento sarebbe quella di consegna della merce, ma non avendola usiamo la data documento.
|
// La data di riferimento sarebbe quella di consegna della merce, ma non avendola usiamo la data documento.
|
||||||
// In assenza della data documento siamo costretti ad usare la data di registrazione
|
// In assenza della data documento siamo costretti ad usare la data di registrazione
|
||||||
const TDate data_reg = mov.get(MOV_DATAREG);
|
TDate data_reg = mov.get(MOV_DATAREG);
|
||||||
const TDate data_doc = mov.get(MOV_DATADOC);
|
TDate data_doc = mov.get(MOV_DATADOC);
|
||||||
|
|
||||||
const TDate data_rif = data_doc.ok() && data_doc < data_reg ? data_doc : data_reg;
|
const TDate data_rif = data_doc.ok() && data_doc < data_reg ? data_doc : data_reg;
|
||||||
|
|
||||||
const long giorni = fine - data_rif;
|
const long giorni = fine - data_rif;
|
||||||
@ -1115,243 +1141,255 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt, TAssoc_array &
|
|||||||
TProgress_monitor pi(items, pimsg, false);
|
TProgress_monitor pi(items, pimsg, false);
|
||||||
|
|
||||||
for (; _cur->pos() < items; ++(*_cur))
|
for (; _cur->pos() < items; ++(*_cur))
|
||||||
{
|
{
|
||||||
if (!pi.set_status(_cur->pos()))
|
if (!pi.set_status(_cur->pos()))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TDate date = _mov->get(MOV_DATAREG);
|
TDate date = _mov->get(MOV_DATAREG);
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
long nr = _mov->get_long(MOV_NUMREG);
|
TToken_string __nreg = _mov->get(MOV_NUMREG);
|
||||||
|
TToken_string __values = LOAD_VAL;
|
||||||
check_nreg(nr);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const int liqmonth = _mov->get_int(MOV_MESELIQ);
|
BREAK_DBG;
|
||||||
const TString4 reg = _mov->get("REG");
|
const int liqmonth = _mov->get_int(MOV_MESELIQ);
|
||||||
const bool isreg = look_reg(reg);
|
const TString4 reg = _mov->get("REG");
|
||||||
|
const bool isreg = look_reg(reg);
|
||||||
const TString4 tipodoc = _mov->get(MOV_TIPODOC);
|
const TString4 tipodoc = _mov->get(MOV_TIPODOC);
|
||||||
const TRegistro & r = cached_registro(_reg->curr());
|
const TRegistro & r = cached_registro(_reg->curr());
|
||||||
const bool corrisp = r.corrispettivi();
|
const bool corrisp = r.corrispettivi();
|
||||||
const tiporeg tipomov = r.tipo_registro();
|
const tiporeg tipomov = r.tipo_registro();
|
||||||
// const bool corrisp = _reg->get_bool("B0");
|
// const bool corrisp = _reg->get_bool("B0");
|
||||||
// const tiporeg tipomov = (tiporeg)_reg->get_int("I0"); // 1=Vendite; 2=Acquisti
|
// const tiporeg tipomov = (tiporeg)_reg->get_int("I0"); // 1=Vendite; 2=Acquisti
|
||||||
tipo_movimento tm = (tipo_movimento) _mov->get_int(MOV_TIPOMOV);
|
tipo_movimento tm = (tipo_movimento)_mov->get_int(MOV_TIPOMOV);
|
||||||
real imp_split_payment;
|
real imp_split_payment;
|
||||||
|
|
||||||
if (tm == tm_nessuno)
|
if (tm == tm_nessuno)
|
||||||
{
|
{
|
||||||
if (tipodoc == "FV" || tipodoc == "FA")
|
if (tipodoc == "FV" || tipodoc == "FA")
|
||||||
tm = tm_fattura; else
|
tm = tm_fattura; else
|
||||||
if (tipodoc == "NC")
|
if (tipodoc == "NC")
|
||||||
tm = tm_nota_credito;
|
tm = tm_nota_credito;
|
||||||
}
|
}
|
||||||
if (_isviaggio)
|
if (_isviaggio)
|
||||||
{
|
{
|
||||||
if (tipomov == vendita && _mov->get_date(MOV_DATA74TER).ok())
|
if (tipomov == vendita && _mov->get_date(MOV_DATA74TER).ok())
|
||||||
date = _mov->get_date(MOV_DATA74TER);
|
date = _mov->get_date(MOV_DATA74TER);
|
||||||
if (date.year() != year_int) // Controlla anno di appartenenza, altrimenti is_date_ok potrebbe non funzionare
|
if (date.year() != year_int) // Controlla anno di appartenenza, altrimenti is_date_ok potrebbe non funzionare
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const TRectype& rcs = _cur->curr(LF_CAUSALI);
|
const TRectype& rcs = _cur->curr(LF_CAUSALI);
|
||||||
const TDate datareg = _mov->get_date(MOV_DATAREG);
|
const TDate datareg = _mov->get_date(MOV_DATAREG);
|
||||||
const TDate datadoc = _mov->get_date(MOV_DATADOC);
|
const TDate datadoc = _mov->get_date(MOV_DATADOC);
|
||||||
const bool fatt_rit_2018 = _mov->get_bool(MOV_RITFATT) && (datareg.year() >= 2018);
|
const bool fatt_rit_2018 = _mov->get_bool(MOV_RITFATT) && (datareg.year() >= 2018);
|
||||||
const int year_diff = datareg.year() - datadoc.year();
|
const int year_diff = datareg.year() - datadoc.year();
|
||||||
const bool dataritind = ((tipomov == acquisto) && fatt_rit_2018) &&
|
const bool dataritind = ((tipomov == acquisto) && fatt_rit_2018) &&
|
||||||
((year_diff > 2) || ((year_diff >= 1) && datareg.month() >= 5));
|
((year_diff > 2) || ((year_diff >= 1) && datareg.month() >= 5));
|
||||||
const bool fattrit = ((tipomov == acquisto) && !dataritind && fatt_rit_2018) && (year_diff >= 1);
|
const bool fattrit = ((tipomov == acquisto) && !dataritind && fatt_rit_2018) && (year_diff >= 1);
|
||||||
const bool fattritind = (atoi(_year) < 2018 && rcs.get_bool(CAU_RITFATT)) || dataritind;
|
const bool fattritind = (atoi(_year) < 2018 && rcs.get_bool(CAU_RITFATT)) || dataritind;
|
||||||
const bool cau_intra = rcs.get_bool(CAU_INTRACOM);
|
const bool cau_intra = rcs.get_bool(CAU_INTRACOM);
|
||||||
const bool cau_valintra = rcs.get_bool(CAU_VALINTRA);
|
const bool cau_valintra = rcs.get_bool(CAU_VALINTRA);
|
||||||
|
|
||||||
// Inizio gestione IVA differita
|
// Inizio gestione IVA differita
|
||||||
const bool iva_diff = _mov->get_bool(MOV_LIQDIFF) && is_IVA_diff(_mov->curr());
|
const bool iva_diff = _mov->get_bool(MOV_LIQDIFF) && is_IVA_diff(_mov->curr());
|
||||||
const bool iva_cass = !iva_diff && !_isviaggio && tm > tm_nessuno && is_IVAxCassa(_mov->curr());
|
const bool iva_cass = !iva_diff && !_isviaggio && tm > tm_nessuno && is_IVAxCassa(_mov->curr());
|
||||||
const bool bIsMovDiff = (iva_diff || iva_cass) && !_recalc_regis; // Aggiunto test su ricalcolo da registri 13-12-2012
|
const bool bIsMovDiff = (iva_diff || iva_cass) && !_recalc_regis; // Aggiunto test su ricalcolo da registri 13-12-2012
|
||||||
bool dok = is_date_ok(date, month, liqmonth, year_int);
|
bool dok = is_date_ok(date, month, liqmonth, year_int);
|
||||||
const bool ic = _mov->get_bool(MOV_IVAXCASSA);
|
const bool ic = _mov->get_bool(MOV_IVAXCASSA);
|
||||||
TPartite_array arrpart; // Partite interessate
|
TPartite_array arrpart; // Partite interessate
|
||||||
TPointer_array pagscatt; // Righe di pagsca interessate
|
TPointer_array pagscatt; // Righe di pagsca interessate
|
||||||
|
|
||||||
#ifdef DBG
|
BREAK_DBG;
|
||||||
check_nreg(nr);
|
if (fattrit)
|
||||||
|
dok = (atoi(_year) == datadoc.year()) && _month == 13;
|
||||||
|
|
||||||
#endif
|
if (bIsMovDiff)
|
||||||
|
{
|
||||||
if (fattrit)
|
if ((tm == tm_fattura) || (tm == tm_nota_credito && !dok))
|
||||||
dok = (atoi(_year) == datadoc.year()) && _month == 13;
|
|
||||||
|
|
||||||
if (bIsMovDiff && tm == tm_fattura)
|
|
||||||
{
|
|
||||||
const bool id_chiusa = ivadiff_chiusa(_mov->curr(), TDate(31,12,inizio.year()-1));
|
|
||||||
if (!dok && id_chiusa)
|
|
||||||
continue; // Salta vecchi movimenti differiti già chiusi
|
|
||||||
|
|
||||||
// Sezione preferita per fatture decisa in base a vendita->'A' o acquisto->'D'
|
|
||||||
const char sezfat = tipomov == vendita ? 'D' : 'A';
|
|
||||||
const char sezpag = (sezfat=='D') ? 'A' : 'D';
|
|
||||||
const long numreg = _mov->get_long(MOV_NUMREG);
|
|
||||||
TDate datainc = fine;
|
|
||||||
real tot_incassato, tot_da_incassare;
|
|
||||||
int flag_pg_nc = 0; // Ci sono pagamenti (0x1) e/o note di credito(0x2) ?
|
|
||||||
bool game_found = false;
|
|
||||||
|
|
||||||
if (has_sc)
|
|
||||||
{
|
{
|
||||||
arrpart.add_numreg(numreg);
|
const bool id_chiusa = ivadiff_chiusa(_mov->curr(), TDate(31, 12, inizio.year() - 1));
|
||||||
const TPartita* p = arrpart.first();
|
if (!dok && id_chiusa)
|
||||||
const int row = p ? p->mov2rig(numreg, 0) : 0;
|
continue; // Salta vecchi movimenti differiti già chiusi
|
||||||
|
|
||||||
game_found = row > 0;
|
// Sezione preferita per fatture decisa in base a vendita->'A' o acquisto->'D'
|
||||||
if (game_found && !id_chiusa)
|
const char sezfat = tipomov == vendita ? 'D' : 'A';
|
||||||
{
|
const char sezpag = (sezfat == 'D') ? 'A' : 'D';
|
||||||
const TRiga_partite& rp = p->riga(row);
|
const long numreg = _mov->get_long(MOV_NUMREG);
|
||||||
|
TDate datainc = fine;
|
||||||
|
real tot_incassato, tot_da_incassare;
|
||||||
|
int flag_pg_nc = 0; // Ci sono pagamenti (0x1) e/o note di credito(0x2) ?
|
||||||
|
bool game_found = false;
|
||||||
|
TImporto residuo;
|
||||||
|
|
||||||
TDate orizzonte = fine; // caso tradizionale
|
BREAK_DBG;
|
||||||
|
if (has_sc)
|
||||||
if (iva_cass)
|
|
||||||
{
|
|
||||||
TDate data_rif = data_maturazione_IVA_diff(_mov->curr());
|
|
||||||
if (data_rif < fine)
|
|
||||||
orizzonte = data_rif;
|
|
||||||
}
|
|
||||||
|
|
||||||
TImporto pg_per, nc_per;
|
|
||||||
bool regular_month = orizzonte >= date;
|
|
||||||
bool first_month = regular_month && date > inizio + 1L;
|
|
||||||
#ifdef DBG
|
|
||||||
check_nreg(nr);
|
|
||||||
if (rp.get_long(PART_NREG) == 100616)
|
|
||||||
int i = 1;
|
|
||||||
#endif
|
|
||||||
flag_pg_nc = rp.calcola_pagato_periodo(first_month ? botime : inizio + 1L, orizzonte, pg_per, nc_per, &pagscatt) && regular_month;
|
|
||||||
if (pagscatt.items() >= 2)
|
|
||||||
{
|
|
||||||
// Fondo tra loro le righe generate dallo stesso pagamento
|
|
||||||
for (int p = pagscatt.last(); p > 0; p--)
|
|
||||||
{
|
|
||||||
const TRectype& p0 = (const TRectype&)pagscatt[p];
|
|
||||||
const TRectype& p1 = (const TRectype&)pagscatt[p - 1];
|
|
||||||
|
|
||||||
if (p0.get_int(PAGSCA_NRIGP) == p1.get_int(PAGSCA_NRIGP))
|
|
||||||
{
|
|
||||||
const real imp = p0.get_real(PAGSCA_IMPORTO);
|
|
||||||
((TRectype&)p1).add(PAGSCA_IMPORTO, imp);
|
|
||||||
pagscatt.destroy(p, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (iva_diff || sarebbe_maturata(_mov->curr(), inizio + 1L, fine) || (iva_cass && _end_cassa))
|
|
||||||
{
|
|
||||||
TPointer_array pagscaold;
|
|
||||||
TImporto pg_tot, nc_tot;
|
|
||||||
|
|
||||||
rp.calcola_pagato_periodo(TDate(0L), orizzonte, pg_tot, nc_tot, &pagscaold);
|
|
||||||
// Controllo se ci siam persi delle note di credito negli anni scorsi
|
|
||||||
if (!nc_tot.is_zero() && pagscaold.items() > pagscatt.items())
|
|
||||||
{
|
|
||||||
FOR_EACH_ARRAY_ITEM(pagscaold, i, obj)
|
|
||||||
{
|
|
||||||
const TRectype& pagsca = *(const TRectype*)obj;
|
|
||||||
const int anno = pagsca.get_int(PAGSCA_ANNO);
|
|
||||||
const int nrigp = pagsca.get_int(PAGSCA_NRIGP);
|
|
||||||
// Appartiene all'anno scorso?
|
|
||||||
if (anno < year_int && nrigp < 999) // 9999 on pagsca -> 999 on ivadiff
|
|
||||||
{
|
|
||||||
const TPartita& p = arrpart.partita(pagsca);
|
|
||||||
const TRiga_partite& rp = p.riga(nrigp);
|
|
||||||
// E' veramente una nota di credito?
|
|
||||||
if (rp.tipo() == tm_nota_credito)
|
|
||||||
{
|
|
||||||
bool found = false;
|
|
||||||
FOR_EACH_ARRAY_ITEM(pagscatt, j, ps)
|
|
||||||
{
|
|
||||||
if (ps == obj)
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found)
|
|
||||||
{
|
|
||||||
TLocalisamfile id(LF_IVADIFF);
|
|
||||||
id.put(RMI_NUMREG, _rmoviva->get(RMI_NUMREG));
|
|
||||||
id.put(RMI_NUMRIG, _rmoviva->get(RMI_NUMRIG));
|
|
||||||
id.put("NUMPRO", nrigp);
|
|
||||||
if (id.read(_isequal) != NOERR || id.get_int("ANNOLIQ") == 0)
|
|
||||||
pagscatt.add(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TImporto incasso = pg_tot;
|
|
||||||
TImporto saldo = rp.importo(false);
|
|
||||||
|
|
||||||
incasso += nc_tot;
|
|
||||||
saldo += incasso;
|
|
||||||
saldo.normalize(sezfat);
|
|
||||||
incasso.normalize(sezpag);
|
|
||||||
if (saldo.valore() > ZERO)
|
|
||||||
tot_da_incassare = saldo.valore();
|
|
||||||
if (incasso.valore() > ZERO)
|
|
||||||
tot_incassato = incasso.valore();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TImporto incasso = pg_per;
|
|
||||||
|
|
||||||
incasso += nc_per;
|
|
||||||
incasso.normalize(sezpag);
|
|
||||||
if (incasso.valore() > ZERO)
|
|
||||||
tot_incassato = incasso.valore();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!game_found) // No saldaconto o partita assente
|
|
||||||
{
|
|
||||||
datainc = iva_diff ? _mov->get_date(MOV_DATAINC) : TDate();
|
|
||||||
if (datainc.ok() && datainc <= fine)
|
|
||||||
tot_incassato = _mov->get_real(MOV_TOTDOC);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// Fattura più vecchia di un anno a ente NON pubblico
|
arrpart.add_numreg(numreg);
|
||||||
if (sarebbe_maturata(_mov->curr(), inizio+1L, fine) || (iva_cass && _end_cassa))
|
|
||||||
tot_da_incassare = _mov->get_real(MOV_TOTDOC);
|
const TPartita* p = arrpart.first();
|
||||||
}
|
|
||||||
}
|
|
||||||
// Simulo incasso se necessario
|
|
||||||
if (iva_cass && tot_da_incassare > ZERO) // già controllato se sarebbe_maturata(_mov->curr(), fine)
|
|
||||||
{
|
|
||||||
tot_incassato = tot_da_incassare;
|
|
||||||
|
|
||||||
datainc = data_maturazione_IVA_diff(_mov->curr());
|
if ((tm == tm_fattura) || (tm == tm_nota_credito && p->prima_fattura() < 0)) // fattura o nota di credito senza fattura
|
||||||
if (iva_cass && _end_cassa && datainc.year() != atoi(_year))
|
{
|
||||||
datainc = data_end_cassa;
|
const int row = p ? p->mov2rig(numreg, 0) : 0;
|
||||||
|
|
||||||
|
if (p != nullptr)
|
||||||
|
residuo = p->calcola_saldo_al(false, inizio);
|
||||||
|
|
||||||
|
game_found = row > 0;
|
||||||
|
if (game_found && !id_chiusa)
|
||||||
|
{
|
||||||
|
const TRiga_partite& rp = p->riga(row);
|
||||||
|
|
||||||
|
TDate orizzonte = fine; // caso tradizionale
|
||||||
|
|
||||||
|
if (iva_cass)
|
||||||
|
{
|
||||||
|
TDate data_rif = data_maturazione_IVA_diff(_mov->curr());
|
||||||
|
if (data_rif < fine)
|
||||||
|
orizzonte = data_rif;
|
||||||
|
}
|
||||||
|
|
||||||
|
TImporto pg_per, nc_per;
|
||||||
|
bool regular_month = orizzonte >= date;
|
||||||
|
bool first_month = regular_month && date > inizio + 1L;
|
||||||
|
|
||||||
|
BREAK_DBG;
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
else
|
if (rp.get_long(PART_NREG) == 100616)
|
||||||
int i = 1;
|
int i = 1;
|
||||||
#endif
|
#endif
|
||||||
_mov->put(MOV_DATAINC, datainc);
|
flag_pg_nc = rp.calcola_pagato_periodo(first_month ? botime : inizio + 1L, orizzonte, pg_per, nc_per, &pagscatt) && regular_month;
|
||||||
if (datainc < date)
|
residuo += pg_per;
|
||||||
datainc = date;
|
if (pagscatt.items() >= 2)
|
||||||
}
|
{
|
||||||
if (tot_incassato > ZERO && is_date_ok(datainc, month, liqmonth, year_int))
|
// Fondo tra loro le righe generate dallo stesso pagamento
|
||||||
{
|
for (int p = pagscatt.last(); p > 0; p--)
|
||||||
flag_pg_nc = 0x1;
|
{
|
||||||
TRectype* pagsca = new TRectype(LF_PAGSCA);
|
const TRectype& p0 = (const TRectype&)pagscatt[p];
|
||||||
pagsca->put(PAGSCA_TIPOC, _mov->get(MOV_TIPO));
|
const TRectype& p1 = (const TRectype&)pagscatt[p - 1];
|
||||||
pagsca->put(PAGSCA_SOTTOCONTO, _mov->get(MOV_CODCF));
|
|
||||||
pagsca->put(PAGSCA_ANNO, year_int);
|
if (p0.get_int(PAGSCA_NRIGP) == p1.get_int(PAGSCA_NRIGP))
|
||||||
pagsca->put(PAGSCA_NRIGA, 1);
|
{
|
||||||
pagsca->put(PAGSCA_NRATA, 1);
|
const real imp = p0.get_real(PAGSCA_IMPORTO);
|
||||||
pagsca->put(PAGSCA_NRIGP, 9999);
|
((TRectype&)p1).add(PAGSCA_IMPORTO, imp);
|
||||||
pagsca->put(PAGSCA_IMPORTO, tot_incassato);
|
pagscatt.destroy(p, true);
|
||||||
pagscatt.add(pagsca);
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (iva_diff || ((abs(residuo.valore()) > UN_CENTESIMO) && sarebbe_maturata(_mov->curr(), inizio + 1L, fine, tm)) || (iva_cass && _end_cassa))
|
||||||
|
{
|
||||||
|
TPointer_array pagscaold;
|
||||||
|
TImporto pg_tot, nc_tot;
|
||||||
|
|
||||||
|
rp.calcola_pagato_periodo(TDate(0L), orizzonte, pg_tot, nc_tot, &pagscaold);
|
||||||
|
// Controllo se ci siam persi delle note di credito negli anni scorsi
|
||||||
|
if (!nc_tot.is_zero() && pagscaold.items() > pagscatt.items())
|
||||||
|
{
|
||||||
|
FOR_EACH_ARRAY_ITEM(pagscaold, i, obj)
|
||||||
|
{
|
||||||
|
const TRectype& pagsca = *(const TRectype*)obj;
|
||||||
|
const int anno = pagsca.get_int(PAGSCA_ANNO);
|
||||||
|
const int nrigp = pagsca.get_int(PAGSCA_NRIGP);
|
||||||
|
// Appartiene all'anno scorso?
|
||||||
|
if (anno < year_int && nrigp < 999) // 9999 on pagsca -> 999 on ivadiff
|
||||||
|
{
|
||||||
|
const TPartita& p = arrpart.partita(pagsca);
|
||||||
|
const TRiga_partite& rp = p.riga(nrigp);
|
||||||
|
// E' veramente una nota di credito?
|
||||||
|
if (rp.tipo() == tm_nota_credito)
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
FOR_EACH_ARRAY_ITEM(pagscatt, j, ps)
|
||||||
|
{
|
||||||
|
if (ps == obj)
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
BREAK_DBG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
TLocalisamfile id(LF_IVADIFF);
|
||||||
|
id.put(RMI_NUMREG, _rmoviva->get(RMI_NUMREG));
|
||||||
|
id.put(RMI_NUMRIG, _rmoviva->get(RMI_NUMRIG));
|
||||||
|
id.put("NUMPRO", nrigp);
|
||||||
|
if (id.read(_isequal) != NOERR || id.get_int("ANNOLIQ") == 0)
|
||||||
|
pagscatt.add(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TImporto incasso = pg_tot;
|
||||||
|
TImporto saldo = rp.importo(false);
|
||||||
|
|
||||||
|
incasso += nc_tot;
|
||||||
|
saldo += incasso;
|
||||||
|
saldo.normalize(sezfat);
|
||||||
|
incasso.normalize(sezpag);
|
||||||
|
if (saldo.valore() > ZERO || (tm == tm_nota_credito && saldo.valore() < ZERO))
|
||||||
|
tot_da_incassare = saldo.valore();
|
||||||
|
if (incasso.valore() > ZERO || (tm == tm_nota_credito && incasso.valore() < ZERO))
|
||||||
|
tot_incassato = incasso.valore();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TImporto incasso = pg_per;
|
||||||
|
|
||||||
|
incasso += nc_per;
|
||||||
|
incasso.normalize(sezpag);
|
||||||
|
if (incasso.valore() > ZERO)
|
||||||
|
tot_incassato = incasso.valore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!game_found) // No saldaconto o partita assente
|
||||||
|
{
|
||||||
|
datainc = iva_diff ? _mov->get_date(MOV_DATAINC) : TDate();
|
||||||
|
if (datainc.ok() && datainc <= fine)
|
||||||
|
tot_incassato = _mov->get_real(MOV_TOTDOC);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Fattura più vecchia di un anno a ente NON pubblico
|
||||||
|
if ((abs(residuo.valore()) > UN_CENTESIMO || !has_sc) && sarebbe_maturata(_mov->curr(), inizio + 1L, fine, tm) || (iva_cass && _end_cassa))
|
||||||
|
tot_da_incassare = _mov->get_real(MOV_TOTDOC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Simulo incasso se necessario
|
||||||
|
if (iva_cass && ((tot_da_incassare > ZERO) || (tm == tm_nota_credito && tot_da_incassare < ZERO))) // già controllato se sarebbe_maturata(_mov->curr(), fine)
|
||||||
|
{
|
||||||
|
tot_incassato = tot_da_incassare;
|
||||||
|
|
||||||
|
datainc = data_maturazione_IVA_diff(_mov->curr());
|
||||||
|
if (iva_cass && _end_cassa && datainc.year() != atoi(_year))
|
||||||
|
datainc = data_end_cassa;
|
||||||
|
#ifdef DBG
|
||||||
|
else
|
||||||
|
BREAK_DBG;
|
||||||
|
#endif
|
||||||
|
_mov->put(MOV_DATAINC, datainc);
|
||||||
|
if (datainc < date)
|
||||||
|
datainc = date;
|
||||||
|
}
|
||||||
|
if ((tot_incassato > ZERO || (tm == tm_nota_credito && tot_incassato < ZERO)) && (!has_sc || abs(residuo.valore()) > UN_CENTESIMO) && is_date_ok(datainc, month, liqmonth, year_int))
|
||||||
|
{
|
||||||
|
flag_pg_nc = 0x1;
|
||||||
|
TRectype* pagsca = new TRectype(LF_PAGSCA);
|
||||||
|
|
||||||
|
pagsca->put(PAGSCA_TIPOC, _mov->get(MOV_TIPO));
|
||||||
|
pagsca->put(PAGSCA_SOTTOCONTO, _mov->get(MOV_CODCF));
|
||||||
|
pagsca->put(PAGSCA_ANNO, year_int);
|
||||||
|
pagsca->put(PAGSCA_NRIGA, 1);
|
||||||
|
pagsca->put(PAGSCA_NRATA, 1);
|
||||||
|
pagsca->put(PAGSCA_NRIGP, 9999);
|
||||||
|
pagsca->put(PAGSCA_IMPORTO, tot_incassato);
|
||||||
|
pagscatt.add(pagsca);
|
||||||
|
}
|
||||||
|
if (flag_pg_nc)
|
||||||
|
dok = true;
|
||||||
}
|
}
|
||||||
if (flag_pg_nc)
|
|
||||||
dok = true;
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* check register present, rmoviva present and date OK
|
* check register present, rmoviva present and date OK
|
||||||
@ -1415,7 +1453,7 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt, TAssoc_array &
|
|||||||
TCodiceIVA civa(codiva);
|
TCodiceIVA civa(codiva);
|
||||||
|
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
check_nreg(nr);
|
BREAK_DBG;
|
||||||
if (tipomov == vendite)
|
if (tipomov == vendite)
|
||||||
int i = 1;
|
int i = 1;
|
||||||
if (!bIsMovDiff && (civa.percentuale() == 20))
|
if (!bIsMovDiff && (civa.percentuale() == 20))
|
||||||
@ -1489,13 +1527,8 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt, TAssoc_array &
|
|||||||
const bool soloiva = cached_causale(codcaus, atoi(_year)).reg().iva() != nessuna_iva && rmoviva.empty();
|
const bool soloiva = cached_causale(codcaus, atoi(_year)).reg().iva() != nessuna_iva && rmoviva.empty();
|
||||||
const TCli_for & clifo = cached_clifor(LF_MOV, _mov->curr());
|
const TCli_for & clifo = cached_clifor(LF_MOV, _mov->curr());
|
||||||
const int tp = clifo.alleg();
|
const int tp = clifo.alleg();
|
||||||
// const TRectype& clifo = cache().get_rec(LF_CLIFO, _mov->get(MOV_TIPO), _mov->get(MOV_CODCF));
|
|
||||||
// const int tp = clifo.get_int(CLI_ALLEG);
|
|
||||||
|
|
||||||
#ifdef DBG
|
|
||||||
check_nreg(nr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
BREAK_DBG;
|
||||||
if ((soloiva &&
|
if ((soloiva &&
|
||||||
(caus_reg.objptr(codcaus) != NULL || tp < 1)) &&
|
(caus_reg.objptr(codcaus) != NULL || tp < 1)) &&
|
||||||
sosp_imp != vol_affari)
|
sosp_imp != vol_affari)
|
||||||
@ -1533,9 +1566,8 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt, TAssoc_array &
|
|||||||
const TDate datareg = _mov->get_date(MOV_DATAREG);
|
const TDate datareg = _mov->get_date(MOV_DATAREG);
|
||||||
int mesereg = liqmonth == 0 ? datareg.month() : liqmonth;
|
int mesereg = liqmonth == 0 ? datareg.month() : liqmonth;
|
||||||
bool ok = is_month_ok(mesereg, month) && (atoi(_year) == datareg.year());
|
bool ok = is_month_ok(mesereg, month) && (atoi(_year) == datareg.year());
|
||||||
#ifdef DBG
|
|
||||||
check_nreg(nr);
|
BREAK_DBG;
|
||||||
#endif
|
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
datafat = datareg;
|
datafat = datareg;
|
||||||
@ -1745,10 +1777,10 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt, TAssoc_array &
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!pag_found)
|
if (!pag_found)
|
||||||
val_iva = civa.scorpora(val_imp, TCurrency::get_firm_dec());
|
val_iva = civa.scorpora(val_imp, TCurrency::get_firm_dec());
|
||||||
else
|
else
|
||||||
civa.scorpora(val_imp, TCurrency::get_firm_dec());
|
civa.scorpora(val_imp, TCurrency::get_firm_dec());
|
||||||
id.curr() = svidrec;
|
id.curr() = svidrec;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1886,7 +1918,7 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt, TAssoc_array &
|
|||||||
bool bMovDiffToAdd = true;
|
bool bMovDiffToAdd = true;
|
||||||
|
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
check_nreg(nr);
|
BREAK_DBG;
|
||||||
if (!bIsMovDiff && (civa.percentuale() == 20))
|
if (!bIsMovDiff && (civa.percentuale() == 20))
|
||||||
real p = imposta_orig / imponibile_orig * CENTO;
|
real p = imposta_orig / imponibile_orig * CENTO;
|
||||||
#endif
|
#endif
|
||||||
@ -2622,13 +2654,13 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt, TAssoc_array &
|
|||||||
if (tipomov == vendita)
|
if (tipomov == vendita)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (codiva=="10" && !incdiff_iva.is_zero())
|
if (codiva == "10" && !incdiff_iva.is_zero())
|
||||||
{
|
{
|
||||||
const real oldv = tab->get("R29");
|
const real oldv = tab->get("R29");
|
||||||
const real newv = oldv + incdiff_iva;
|
const real newv = oldv + incdiff_iva;
|
||||||
const long numreg = _mov->get_long(MOV_NUMREG);
|
const long numreg = _mov->get_long(MOV_NUMREG);
|
||||||
__trace("%s %s\t%s\t%s\t%7ld\t%s\t+\t%s\t=\t%s", tab->name(), (const char*)tab->curr().get("CODTAB"), (const char*)reg, (const char*)tipocr_s,
|
__trace("%s %s\t%s\t%s\t%7ld\t%s\t+\t%s\t=\t%s", tab->name(), (const char*)tab->curr().get("CODTAB"), (const char*)reg, (const char*)tipocr_s,
|
||||||
numreg, oldv.stringa(12, 2), incdiff_iva.stringa(12, 2), newv.stringa(12, 2));
|
numreg, oldv.stringa(12, 2), incdiff_iva.stringa(12, 2), newv.stringa(12, 2));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// fatture vendita a liquidazione differita
|
// fatture vendita a liquidazione differita
|
||||||
|
@ -1570,9 +1570,19 @@ int TLiquidazione_app::print_acc_diff_xcassa(const _DescrItem& d)
|
|||||||
int i = 9;
|
int i = 9;
|
||||||
|
|
||||||
const real& totiva = d._r0;
|
const real& totiva = d._r0;
|
||||||
const real ivadiff_inc = d._r29;
|
real ivadiff_inc = d._r29;
|
||||||
const real ivadiff_pag = d._r33;
|
real ivadiff_pag = d._r33;
|
||||||
|
|
||||||
|
if (ivadiff_inc < ZERO)
|
||||||
|
{
|
||||||
|
ivadiff_pag -= ivadiff_inc;
|
||||||
|
ivadiff_inc = ZERO;
|
||||||
|
}
|
||||||
|
if (ivadiff_pag < ZERO)
|
||||||
|
{
|
||||||
|
ivadiff_inc -= ivadiff_pag;
|
||||||
|
ivadiff_pag = ZERO;
|
||||||
|
}
|
||||||
real ivaxcas_inc, ivaxcas_pag;
|
real ivaxcas_inc, ivaxcas_pag;
|
||||||
|
|
||||||
if (has_module(ICAUT))
|
if (has_module(ICAUT))
|
||||||
@ -2310,6 +2320,16 @@ void TLiquidazione_app::set_grand_2000(_DescrItem& d, int &rw)
|
|||||||
xcasinc_iva_acq -= ind;
|
xcasinc_iva_acq -= ind;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (xcasinc_iva < ZERO)
|
||||||
|
{
|
||||||
|
xcasinc_iva_acq -= xcasinc_iva;
|
||||||
|
xcasinc_iva = ZERO;
|
||||||
|
}
|
||||||
|
if (xcasinc_iva_acq < ZERO)
|
||||||
|
{
|
||||||
|
xcasinc_iva -= xcasinc_iva_acq;
|
||||||
|
xcasinc_iva_acq = ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
TToken_string tt(d._s0);
|
TToken_string tt(d._s0);
|
||||||
real iva_vend(tt.get(0));
|
real iva_vend(tt.get(0));
|
||||||
@ -2355,9 +2375,9 @@ void TLiquidazione_app::set_grand_2000(_DescrItem& d, int &rw)
|
|||||||
if (!_is_visliq)
|
if (!_is_visliq)
|
||||||
iva_vend += rett_debt;
|
iva_vend += rett_debt;
|
||||||
set_row(rw++, FR("@11g@bIVA esigibile@r per il periodo@75g%r"), &iva_vend);
|
set_row(rw++, FR("@11g@bIVA esigibile@r per il periodo@75g%r"), &iva_vend);
|
||||||
if (!diffinc_iva.is_zero())
|
if (diffinc_iva != ZERO)
|
||||||
set_row(rw++,FR("@11g a liquidazione differita@75g%r"), &diffinc_iva);
|
set_row(rw++,FR("@11g a liquidazione differita@75g%r"), &diffinc_iva);
|
||||||
if (!xcasinc_iva.is_zero())
|
if (xcasinc_iva != ZERO)
|
||||||
set_row(rw++,FR("@11g per cassa@75g%r"), &xcasinc_iva);
|
set_row(rw++,FR("@11g per cassa@75g%r"), &xcasinc_iva);
|
||||||
if (_is_visliq)
|
if (_is_visliq)
|
||||||
set_row(rw++,FR("@11g$[r]Rettifiche IVA a debito$[n]@75g%r"), &rett_debt); // Rettifiche modificabili
|
set_row(rw++,FR("@11g$[r]Rettifiche IVA a debito$[n]@75g%r"), &rett_debt); // Rettifiche modificabili
|
||||||
@ -2367,9 +2387,9 @@ void TLiquidazione_app::set_grand_2000(_DescrItem& d, int &rw)
|
|||||||
iva_acq += rett_cred;
|
iva_acq += rett_cred;
|
||||||
iva_acq -= cred_fattrit;
|
iva_acq -= cred_fattrit;
|
||||||
set_row(rw++, FR("@11g@bIVA detraibile@r per il periodo@58g%r"), &iva_acq);
|
set_row(rw++, FR("@11g@bIVA detraibile@r per il periodo@58g%r"), &iva_acq);
|
||||||
if (!diffinc_iva_acq.is_zero())
|
if (diffinc_iva_acq != ZERO)
|
||||||
set_row(rw++,FR("@11g a liquidazione differita@58g%r"), &diffinc_iva_acq);
|
set_row(rw++,FR("@11g a liquidazione differita@58g%r"), &diffinc_iva_acq);
|
||||||
if (!xcasinc_iva_acq.is_zero())
|
if (xcasinc_iva_acq != ZERO)
|
||||||
set_row(rw++,FR("@11g per cassa@58g%r"), &xcasinc_iva_acq);
|
set_row(rw++,FR("@11g per cassa@58g%r"), &xcasinc_iva_acq);
|
||||||
if (_is_visliq)
|
if (_is_visliq)
|
||||||
set_row(rw++,FR("@11g$[r]Rettifiche IVA a credito$[n]@58g%r"), &rett_cred);
|
set_row(rw++,FR("@11g$[r]Rettifiche IVA a credito$[n]@58g%r"), &rett_cred);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user