1995-09-18 10:45:10 +00:00
|
|
|
|
// -------------------------------------------------------------
|
|
|
|
|
// calcolo liquidazioni
|
|
|
|
|
// part 3: utilities
|
|
|
|
|
// fv 2-2-94
|
|
|
|
|
// --------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
1999-07-16 14:59:11 +00:00
|
|
|
|
#include <currency.h>
|
1995-09-18 10:45:10 +00:00
|
|
|
|
#include <utility.h>
|
|
|
|
|
|
2002-02-26 16:20:19 +00:00
|
|
|
|
#include "cglib03.h"
|
1995-09-18 10:45:10 +00:00
|
|
|
|
#include "cg4300.h"
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::is_trim(int x)
|
|
|
|
|
// TRUE se il mese passato e' un trimestre
|
|
|
|
|
{ return x == 3 || x == 6 || x == 9 || x == 12; }
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::is_month_ok_strict(int x, int month)
|
|
|
|
|
// TRUE se il mese passato e' compatibile con il regime
|
|
|
|
|
// di liquidazione e (opz) non e' maggiore di quello scelto
|
|
|
|
|
{
|
|
|
|
|
if (month == -1) month = x;
|
|
|
|
|
return _freqviva == "M" ?
|
|
|
|
|
( x > 0 && x <= month) :
|
|
|
|
|
( x <= month && is_trim(x));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::is_month_plain(int x)
|
|
|
|
|
// la piu' semplice: vero se mese == _month o se fa parte del
|
|
|
|
|
// trimestre indicato da month
|
|
|
|
|
{
|
|
|
|
|
bool ok = x == _month;
|
|
|
|
|
if (!ok && _freqviva == "T")
|
|
|
|
|
{
|
|
|
|
|
// aggiusta al trimestre il mese da calcolare
|
|
|
|
|
int mto = _month;
|
|
|
|
|
mto += 2 - ((mto-1) % 3);
|
|
|
|
|
ok = x > (mto - 3) && x <= mto;
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::is_month_ok(int x, int mtocalc)
|
|
|
|
|
// TRUE se il mese passato e' compatibile con il mese da calcolare
|
|
|
|
|
// rispetto al regime di liquidazione scelto
|
|
|
|
|
{
|
|
|
|
|
bool ret = x == mtocalc;
|
|
|
|
|
if (!ret && _freqviva == "T" && mtocalc != 13)
|
|
|
|
|
{
|
|
|
|
|
// aggiusta al trimestre il mese da calcolare
|
|
|
|
|
mtocalc += 2 - ((mtocalc-1) % 3);
|
|
|
|
|
ret = x > (mtocalc - 3) && x <= mtocalc;
|
|
|
|
|
}
|
|
|
|
|
else if (!ret && mtocalc == 13)
|
|
|
|
|
{
|
|
|
|
|
// per l'annuale ritorna TRUE per tutti i mesi da liquidare
|
|
|
|
|
ret = x <= 13;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TLiquidazione_app::liq_month(int x)
|
|
|
|
|
// ritorna il mese da liquidare (= LIM presente)
|
|
|
|
|
// che corrisponde al mese passato
|
|
|
|
|
{
|
|
|
|
|
if (x == 13 || _freqviva == "M")
|
|
|
|
|
return x;
|
1998-04-30 15:59:34 +00:00
|
|
|
|
else
|
|
|
|
|
return next_trim(x);
|
1995-09-18 10:45:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TLiquidazione_app::next_trim(int x)
|
|
|
|
|
{
|
1998-04-30 15:59:34 +00:00
|
|
|
|
if (x == 13)
|
|
|
|
|
x = 12;
|
1995-09-18 10:45:10 +00:00
|
|
|
|
return x + (2 - ((x-1) % 3));
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-05 15:25:49 +00:00
|
|
|
|
bool TLiquidazione_app::is_in_liq_period(const TDate& d)
|
1995-09-18 10:45:10 +00:00
|
|
|
|
{
|
|
|
|
|
bool ok = FALSE;
|
1996-07-19 09:53:06 +00:00
|
|
|
|
const int y = atoi(_year);
|
2000-05-05 15:25:49 +00:00
|
|
|
|
if (_freqviva == "M")
|
|
|
|
|
{
|
|
|
|
|
ok = d.month() == _month && d.year() == y;
|
|
|
|
|
}
|
1995-09-18 10:45:10 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
const int m = liq_month(_month);
|
1996-07-19 09:53:06 +00:00
|
|
|
|
ok = d.month() > m - 3 && d.month() <= m && d.year() == y;
|
1995-09-18 10:45:10 +00:00
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::is_first_month(int m)
|
|
|
|
|
{
|
1998-05-04 09:34:04 +00:00
|
|
|
|
return _freqviva == "M" ? m == 1 : m == 3;
|
1995-09-18 10:45:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TLiquidazione_app::previous_month(int m)
|
|
|
|
|
{
|
|
|
|
|
// vale per LIM (mese o trimestre precedente)
|
|
|
|
|
if (_freqviva == "M")
|
|
|
|
|
return m == 1 ? 1 : m - 1;
|
1998-04-30 15:59:34 +00:00
|
|
|
|
else
|
|
|
|
|
return m == 3 ? 3 : m - 3;
|
1995-09-18 10:45:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-05 15:25:49 +00:00
|
|
|
|
bool TLiquidazione_app::is_date_ok(const TDate& d, int month, int liqmonth, int year)
|
1998-04-30 15:59:34 +00:00
|
|
|
|
// TRUE se la data passata va considerata nel
|
1995-09-18 10:45:10 +00:00
|
|
|
|
// ricalcolo dei progressivi mensili per il mese e anno
|
1998-04-30 15:59:34 +00:00
|
|
|
|
// selezionati. Vedi cg4301.cpp per maggiori informazioni
|
|
|
|
|
// sul nuovo filtro di selezione movimenti.
|
1995-09-18 10:45:10 +00:00
|
|
|
|
{
|
1998-04-30 15:59:34 +00:00
|
|
|
|
bool ok;
|
|
|
|
|
|
2000-05-05 15:25:49 +00:00
|
|
|
|
if (year < 1998 || _recalc_regis) // Vecchia selezione o calcolo progressivi per stampa registri bollati
|
1998-04-30 15:59:34 +00:00
|
|
|
|
{
|
|
|
|
|
if (d.month() > month || d.year() != atoi(_year))
|
2000-10-03 13:45:12 +00:00
|
|
|
|
return ok = FALSE;
|
1998-04-30 15:59:34 +00:00
|
|
|
|
|
|
|
|
|
if (month == 13)
|
|
|
|
|
ok = d.month() <= month;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (_freqviva == "M") // Guy!!!
|
|
|
|
|
ok = d.month() == month;
|
|
|
|
|
else
|
|
|
|
|
ok = d.month() >= month-2 && d.month() <= month;
|
|
|
|
|
}
|
1998-04-30 15:59:34 +00:00
|
|
|
|
}
|
|
|
|
|
else // Nuova selezione dal 1998 in poi
|
|
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
|
const int regmonth = d.month();
|
|
|
|
|
const int regyear = d.year();
|
1998-04-30 15:59:34 +00:00
|
|
|
|
|
|
|
|
|
if (month <= 12)
|
|
|
|
|
ok = (regmonth == month && liqmonth == 0) || (liqmonth == month);
|
|
|
|
|
else // Annuale, month == 13
|
2000-10-03 13:45:12 +00:00
|
|
|
|
ok = (regyear == year && liqmonth != 12) || (regyear == year + 1 && liqmonth == 12);
|
1998-04-30 15:59:34 +00:00
|
|
|
|
}
|
|
|
|
|
return ok;
|
1995-09-18 10:45:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TLiquidazione_app::add_ventilation(real iva, real howmuch,
|
|
|
|
|
const char* codiva, const char* other)
|
|
|
|
|
{
|
|
|
|
|
_VentItem* vi = NULL;
|
|
|
|
|
for (int i = 0; i < _vent_arr.items(); i++)
|
|
|
|
|
{
|
|
|
|
|
vi = (_VentItem*)&_vent_arr[i];
|
|
|
|
|
if (vi->_codiva == codiva)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (i == _vent_arr.items())
|
|
|
|
|
{
|
|
|
|
|
_vent_arr.add(vi = new _VentItem);
|
|
|
|
|
vi->_aliquota = iva;
|
|
|
|
|
vi->_codiva = codiva;
|
|
|
|
|
vi->_other = other;
|
|
|
|
|
}
|
|
|
|
|
vi->_totale += howmuch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TLiquidazione_app::add_vendite(int month, const char* codreg,
|
|
|
|
|
int tipodet, real& r)
|
|
|
|
|
{
|
|
|
|
|
_VendItem* vi = NULL;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < _vend_arr.items(); i++)
|
|
|
|
|
{
|
|
|
|
|
vi = (_VendItem*)&_vend_arr[i];
|
|
|
|
|
if (vi->_codreg == codreg && vi->_month == month && vi->_tipodet == tipodet)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (i == _vend_arr.items())
|
|
|
|
|
{
|
|
|
|
|
_vend_arr.add(vi = new _VendItem);
|
|
|
|
|
vi->_codreg = codreg;
|
|
|
|
|
vi->_month = month;
|
|
|
|
|
vi->_tipodet = tipodet;
|
|
|
|
|
}
|
|
|
|
|
vi->_totale += r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TLiquidazione_app::add_corrisp(int month, const char* codreg, real& r,
|
|
|
|
|
real& p, int tipodet, const char* codiva,
|
|
|
|
|
const char* codatt)
|
|
|
|
|
{
|
|
|
|
|
_CorrItem* ci = NULL;
|
|
|
|
|
const int nitems = _corr_arr.items();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nitems; i++)
|
|
|
|
|
{
|
|
|
|
|
ci = (_CorrItem*)&_corr_arr[i];
|
|
|
|
|
if (ci->_codreg == codreg && ci->_month == month &&
|
|
|
|
|
ci->_codiva == codiva && ci->_tipodet == tipodet &&
|
|
|
|
|
ci->_codatt == codatt)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (i == nitems)
|
|
|
|
|
{
|
|
|
|
|
_corr_arr.add(ci = new _CorrItem);
|
|
|
|
|
ci->_codreg = codreg;
|
|
|
|
|
ci->_month = month;
|
|
|
|
|
ci->_codiva = codiva;
|
|
|
|
|
ci->_codatt = codatt;
|
|
|
|
|
ci->_tipodet = tipodet;
|
|
|
|
|
ci->_aliquota = p;
|
|
|
|
|
}
|
|
|
|
|
ci->_totale += r;
|
|
|
|
|
}
|
|
|
|
|
|
1996-12-06 08:18:01 +00:00
|
|
|
|
void TLiquidazione_app::lordo2netto(const real& totale, real& imponibile, real& imposta, const real& aliquota)
|
|
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
|
const int dec = TCurrency::get_firm_dec();
|
|
|
|
|
if (dec == 0) // Lire
|
|
|
|
|
{
|
|
|
|
|
imposta = (abs(totale) * aliquota)/(aliquota + 1.00);
|
|
|
|
|
imposta.ceil();
|
|
|
|
|
if (totale.sign() < 0) imposta = -imposta;
|
|
|
|
|
imponibile = totale - imposta;
|
|
|
|
|
// Qui si entra nel regno del mistero: delta e' SEMPRE zero
|
|
|
|
|
const real delta = totale - imponibile - imposta;
|
|
|
|
|
if (!delta.is_zero())
|
|
|
|
|
imposta += delta;
|
|
|
|
|
}
|
|
|
|
|
else // Euro
|
|
|
|
|
{
|
|
|
|
|
imposta = (totale * aliquota)/(aliquota + 1.00);
|
|
|
|
|
imposta.round(dec);
|
|
|
|
|
imponibile = totale - imposta;
|
|
|
|
|
}
|
1996-12-06 08:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TLiquidazione_app::lordo2netto(real& imponibile, real& imposta, const real& aliquota)
|
|
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
|
const real totale = imponibile;
|
1996-12-06 08:18:01 +00:00
|
|
|
|
lordo2netto(totale, imponibile, imposta, aliquota);
|
|
|
|
|
}
|
1995-09-18 10:45:10 +00:00
|
|
|
|
|
1998-04-30 15:59:34 +00:00
|
|
|
|
// Funzione per trovare i PIM: Progressivi liquidazione Iva Mensili.
|
1995-09-18 10:45:10 +00:00
|
|
|
|
bool TLiquidazione_app::look_pim(int month, const char* codatt, const char* codreg,
|
|
|
|
|
const char* tipocr, const char* codiva, int tipodet,
|
|
|
|
|
bool create)
|
|
|
|
|
// ritorna il PIM corrispondente alla chiave passata; se
|
|
|
|
|
// create = TRUE lo crea se non lo trova. Ritorna se c'era
|
|
|
|
|
{
|
|
|
|
|
bool ok = FALSE;
|
|
|
|
|
_pim_r->zero();
|
|
|
|
|
(*_pim_anno) = _year;
|
|
|
|
|
(*_pim_mese) = format("%02d", month);
|
|
|
|
|
(*_pim_codreg) = codreg;
|
|
|
|
|
(*_pim_codiva) = codiva;
|
|
|
|
|
(*_pim_codatt) = codatt;
|
|
|
|
|
(*_pim_tipocr) = tipocr;
|
|
|
|
|
(*_pim_tipodet) = tipodet;
|
|
|
|
|
|
|
|
|
|
TString s = _pim_r->get("CODTAB");
|
|
|
|
|
|
|
|
|
|
_pim->read();
|
|
|
|
|
ok = _pim->good();
|
|
|
|
|
|
|
|
|
|
if (!ok && create)
|
|
|
|
|
{
|
|
|
|
|
_pim_r->zero();
|
|
|
|
|
_pim_r->put("CODTAB",s);
|
|
|
|
|
_pim->write();
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
1998-04-30 15:59:34 +00:00
|
|
|
|
// Le tabelle seguenti (PIS, PRM, PRP) sono vengono introdotte solo dal 1998 in poi.
|
|
|
|
|
// Pertanto il loro utilizzo e' significativo in tale periodo.
|
|
|
|
|
// Funzione per trovare i PIS: Progressivi liquidazione Iva mensili di cui periodo Successivo
|
|
|
|
|
bool TLiquidazione_app::look_pis(int month, const char* codatt, const char* codreg,
|
|
|
|
|
const char* tipocr, const char* codiva, int tipodet,
|
|
|
|
|
bool create)
|
|
|
|
|
{
|
|
|
|
|
bool ok = FALSE;
|
|
|
|
|
_pis_r->zero();
|
|
|
|
|
(*_pis_anno) = _year;
|
|
|
|
|
(*_pis_mese) = format("%02d", month);
|
|
|
|
|
(*_pis_codreg) = codreg;
|
|
|
|
|
(*_pis_codiva) = codiva;
|
|
|
|
|
(*_pis_codatt) = codatt;
|
|
|
|
|
(*_pis_tipocr) = tipocr;
|
|
|
|
|
(*_pis_tipodet) = tipodet;
|
|
|
|
|
|
|
|
|
|
TString s = _pis_r->get("CODTAB");
|
|
|
|
|
|
|
|
|
|
_pis->read();
|
|
|
|
|
ok = _pis->good();
|
|
|
|
|
|
|
|
|
|
if (!ok && create)
|
|
|
|
|
{
|
|
|
|
|
_pis_r->zero();
|
|
|
|
|
_pis_r->put("CODTAB",s);
|
|
|
|
|
_pis->write();
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Funzione per trovare i PRM: Progressivi Registri iva Mensili.
|
|
|
|
|
bool TLiquidazione_app::look_prm(int month, const char* codatt, const char* codreg,
|
|
|
|
|
const char* tipocr, const char* codiva, int tipodet,
|
|
|
|
|
bool create)
|
|
|
|
|
{
|
|
|
|
|
bool ok = FALSE;
|
|
|
|
|
_prm_r->zero();
|
|
|
|
|
(*_prm_anno) = _year;
|
|
|
|
|
(*_prm_mese) = format("%02d", month);
|
|
|
|
|
(*_prm_codreg) = codreg;
|
|
|
|
|
(*_prm_codiva) = codiva;
|
|
|
|
|
(*_prm_codatt) = codatt;
|
|
|
|
|
(*_prm_tipocr) = tipocr;
|
|
|
|
|
(*_prm_tipodet) = tipodet;
|
|
|
|
|
|
|
|
|
|
TString s = _prm_r->get("CODTAB");
|
|
|
|
|
|
|
|
|
|
_prm->read();
|
|
|
|
|
ok = _prm->good();
|
|
|
|
|
|
|
|
|
|
if (!ok && create)
|
|
|
|
|
{
|
|
|
|
|
_prm_r->zero();
|
|
|
|
|
_prm_r->put("CODTAB",s);
|
|
|
|
|
_prm->write();
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Funzione per trovare i PRP: Progressivi Registri iva mensili di cui da periodo Precedente
|
|
|
|
|
bool TLiquidazione_app::look_prp(int month, const char* codatt, const char* codreg,
|
|
|
|
|
const char* tipocr, const char* codiva, int tipodet,
|
|
|
|
|
bool create)
|
|
|
|
|
{
|
|
|
|
|
bool ok = FALSE;
|
|
|
|
|
_prp_r->zero();
|
|
|
|
|
(*_prp_anno) = _year;
|
|
|
|
|
(*_prp_mese) = format("%02d", month);
|
|
|
|
|
(*_prp_codreg) = codreg;
|
|
|
|
|
(*_prp_codiva) = codiva;
|
|
|
|
|
(*_prp_codatt) = codatt;
|
|
|
|
|
(*_prp_tipocr) = tipocr;
|
|
|
|
|
(*_prp_tipodet) = tipodet;
|
|
|
|
|
|
|
|
|
|
TString s = _prp_r->get("CODTAB");
|
|
|
|
|
|
|
|
|
|
_prp->read();
|
|
|
|
|
ok = _prp->good();
|
|
|
|
|
|
|
|
|
|
if (!ok && create)
|
|
|
|
|
{
|
|
|
|
|
_prp_r->zero();
|
|
|
|
|
_prp_r->put("CODTAB",s);
|
|
|
|
|
_prp->write();
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
1995-09-18 10:45:10 +00:00
|
|
|
|
bool TLiquidazione_app::look_plm(int m, const char* a, bool create)
|
|
|
|
|
{
|
|
|
|
|
bool ok = FALSE;
|
|
|
|
|
|
|
|
|
|
_plm_r->zero();
|
1996-12-06 09:25:22 +00:00
|
|
|
|
//(*_plm_codatt) = format("%06ld", atol(a));
|
|
|
|
|
(*_plm_codatt) = format("%6s", a);
|
1995-09-18 10:45:10 +00:00
|
|
|
|
(*_plm_mese) = format("%02d",m);
|
|
|
|
|
(*_plm_anno) = _year;
|
|
|
|
|
|
|
|
|
|
TString s = _plm_r->get("CODTAB");
|
|
|
|
|
_plm->read();
|
|
|
|
|
ok = _plm->good();
|
|
|
|
|
|
|
|
|
|
if (!ok && create)
|
|
|
|
|
{
|
|
|
|
|
_plm_r->zero();
|
|
|
|
|
_plm_r->put("CODTAB",s);
|
|
|
|
|
_plm->write();
|
|
|
|
|
}
|
|
|
|
|
// crea/posiziona tabelle gemelle PAM, PUM, POM
|
|
|
|
|
look_pam(m,a,!ok);
|
|
|
|
|
look_pum(m,a,!ok);
|
|
|
|
|
look_pom(m,a,!ok);
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
1997-11-03 11:41:00 +00:00
|
|
|
|
bool TLiquidazione_app::look_pia(int m, const char* a, const char* cod1, const char* cod2, bool create)
|
|
|
|
|
{
|
|
|
|
|
bool ok = FALSE;
|
|
|
|
|
|
|
|
|
|
(*_pia_codatt) = format("%6s", a);
|
|
|
|
|
(*_pia_mese) = format("%02d",m);
|
|
|
|
|
(*_pia_anno) = _year;
|
|
|
|
|
(*_pia_codord) = cod1;
|
|
|
|
|
(*_pia_codcom) = cod2;
|
|
|
|
|
|
|
|
|
|
TString s = _pia_r->get("CODTAB");
|
|
|
|
|
_pia->read();
|
|
|
|
|
ok = _pia->good();
|
|
|
|
|
|
|
|
|
|
if (!ok && create)
|
|
|
|
|
{
|
|
|
|
|
_pia_r->zero();
|
|
|
|
|
_pia_r->put("CODTAB",s);
|
|
|
|
|
_pia->write();
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
1995-09-18 10:45:10 +00:00
|
|
|
|
bool TLiquidazione_app::look_pum(int m, const char* a, bool create)
|
|
|
|
|
{
|
|
|
|
|
bool ok = FALSE;
|
|
|
|
|
|
|
|
|
|
_pum->zero();
|
1996-12-06 09:25:22 +00:00
|
|
|
|
(*_pum_codatt) = format("%6s", a);
|
1995-09-18 10:45:10 +00:00
|
|
|
|
(*_pum_mese) = format("%02d",m);
|
|
|
|
|
(*_pum_anno) = _year;
|
|
|
|
|
|
|
|
|
|
TString s = _pum->get("CODTAB");
|
|
|
|
|
_pum->read();
|
|
|
|
|
ok = _pum->good();
|
|
|
|
|
|
|
|
|
|
if (!ok && create)
|
|
|
|
|
{
|
|
|
|
|
_pum->zero();
|
|
|
|
|
_pum->put("CODTAB",s);
|
|
|
|
|
_pum->write();
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::look_pom(int m, const char* a, bool create)
|
|
|
|
|
{
|
|
|
|
|
bool ok = FALSE;
|
|
|
|
|
|
|
|
|
|
_pom->zero();
|
1996-12-06 09:25:22 +00:00
|
|
|
|
(*_pom_codatt) = format("%6s", a);
|
1995-09-18 10:45:10 +00:00
|
|
|
|
(*_pom_mese) = format("%02d",m);
|
|
|
|
|
(*_pom_anno) = _year;
|
|
|
|
|
|
|
|
|
|
TString s = _pom->get("CODTAB");
|
|
|
|
|
_pom->read();
|
|
|
|
|
ok = _pom->good();
|
|
|
|
|
|
|
|
|
|
if (!ok && create)
|
|
|
|
|
{
|
|
|
|
|
_pom->zero();
|
|
|
|
|
_pom->put("CODTAB",s);
|
|
|
|
|
_pom->write();
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::look_pam(int m, const char* a, bool create)
|
|
|
|
|
{
|
|
|
|
|
bool ok = FALSE;
|
|
|
|
|
|
|
|
|
|
_pam->zero();
|
1996-12-06 09:25:22 +00:00
|
|
|
|
(*_pam_codatt) = format("%6s", a);
|
1995-09-18 10:45:10 +00:00
|
|
|
|
(*_pam_mese) = format("%02d",m);
|
|
|
|
|
(*_pam_anno) = _year;
|
|
|
|
|
|
|
|
|
|
TString s = _pam->get("CODTAB");
|
|
|
|
|
_pam->read();
|
|
|
|
|
ok = _pam->good();
|
|
|
|
|
|
|
|
|
|
if (!ok && create)
|
|
|
|
|
{
|
|
|
|
|
_pam->zero();
|
|
|
|
|
_pam->put("CODTAB",s);
|
|
|
|
|
_pam->write();
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::look_lim(int m, bool create)
|
|
|
|
|
{
|
|
|
|
|
_lim_r->zero();
|
|
|
|
|
(*_lim_mese) = format("%02d",m);
|
|
|
|
|
(*_lim_anno) = _year;
|
|
|
|
|
|
2002-02-26 16:20:19 +00:00
|
|
|
|
const TString s = _lim_r->get("CODTAB");
|
|
|
|
|
const bool ok = _lim->read() == NOERR;
|
1995-09-18 10:45:10 +00:00
|
|
|
|
if (!ok && create)
|
|
|
|
|
{
|
|
|
|
|
_lim_r->zero();
|
|
|
|
|
_lim_r->put("CODTAB",s);
|
|
|
|
|
_lim->write();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// crea o posiziona la tabella gemella LAM
|
|
|
|
|
look_lam(m, !ok);
|
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::look_lam(int m, bool create)
|
|
|
|
|
{
|
|
|
|
|
_lam_r->zero();
|
|
|
|
|
(*_lam_mese) = format("%02d",m);
|
|
|
|
|
(*_lam_anno) = _year;
|
|
|
|
|
|
2002-02-26 16:20:19 +00:00
|
|
|
|
const TString s = _lam_r->get("CODTAB");
|
|
|
|
|
const bool ok = _lam->read() == NOERR;
|
1995-09-18 10:45:10 +00:00
|
|
|
|
if (!ok && create)
|
|
|
|
|
{
|
|
|
|
|
_lam_r->zero();
|
|
|
|
|
_lam_r->put("CODTAB",s);
|
|
|
|
|
_lam->write();
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::look_pla(const char* a, bool create)
|
|
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
|
_pla_r->zero();
|
|
|
|
|
|
1995-09-18 10:45:10 +00:00
|
|
|
|
// forza il tipoatt a 1
|
2000-10-03 13:45:12 +00:00
|
|
|
|
TString16 buf(a);
|
1996-05-20 13:54:44 +00:00
|
|
|
|
buf.ltrim();
|
|
|
|
|
buf.rtrim(1);
|
|
|
|
|
buf << "1";
|
|
|
|
|
while (buf.len() < 6) buf.insert("0");
|
1995-09-18 10:45:10 +00:00
|
|
|
|
|
1998-05-04 09:34:04 +00:00
|
|
|
|
_pla_r->zero();
|
1995-09-18 10:45:10 +00:00
|
|
|
|
(*_pla_ditta) = format("%05ld", get_firm());
|
|
|
|
|
(*_pla_anno) = _year;
|
1996-05-20 13:54:44 +00:00
|
|
|
|
(*_pla_codatt) = buf;
|
1995-09-18 10:45:10 +00:00
|
|
|
|
|
1998-05-04 09:34:04 +00:00
|
|
|
|
const TString16 s = _pla_r->get("CODTAB");
|
|
|
|
|
bool ok = _pla->read() == NOERR;
|
1995-09-18 10:45:10 +00:00
|
|
|
|
if (!ok && create)
|
|
|
|
|
{
|
|
|
|
|
_pla->zero();
|
|
|
|
|
_pla_r->put("CODTAB",s);
|
|
|
|
|
_pla->write();
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::look_reg(const char* reg)
|
|
|
|
|
{
|
|
|
|
|
TString s(12); s << _year; s << format("%-3s",reg);
|
1996-11-13 10:55:21 +00:00
|
|
|
|
bool rt = TRUE;
|
|
|
|
|
const bool is_key = _reg_arr.is_key(s);
|
|
|
|
|
if (is_key)
|
|
|
|
|
_reg->curr() = (TRectype&) _reg_arr[s];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_reg_r->zero();
|
1997-02-10 17:17:06 +00:00
|
|
|
|
_reg_r->put("CODTAB",s);
|
1997-02-06 18:03:40 +00:00
|
|
|
|
if (_reg->read() == NOERR)
|
1997-02-10 17:17:06 +00:00
|
|
|
|
_reg_arr.add(s,_reg->curr());
|
|
|
|
|
else rt = FALSE;
|
1996-11-13 10:55:21 +00:00
|
|
|
|
}
|
|
|
|
|
return rt;
|
1995-09-18 10:45:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::look_iva(const char* cod)
|
|
|
|
|
{
|
1996-11-13 10:55:21 +00:00
|
|
|
|
bool rt = TRUE;
|
1997-02-10 17:17:06 +00:00
|
|
|
|
TString16 s(cod);
|
1996-11-13 10:55:21 +00:00
|
|
|
|
const bool is_key = _codiva_arr.is_key(cod);
|
1997-02-10 17:17:06 +00:00
|
|
|
|
|
1996-11-13 10:55:21 +00:00
|
|
|
|
if (is_key)
|
1997-02-10 17:17:06 +00:00
|
|
|
|
_iva->curr() = (TRectype&) _codiva_arr[s];
|
1996-11-13 10:55:21 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_iva->zero();
|
1997-02-10 17:17:06 +00:00
|
|
|
|
_iva->put("CODTAB",s);
|
|
|
|
|
if (_iva->read() == NOERR)
|
|
|
|
|
_codiva_arr.add(s,_iva->curr());
|
|
|
|
|
else rt = FALSE;
|
1996-11-13 10:55:21 +00:00
|
|
|
|
}
|
|
|
|
|
return rt;
|
1995-09-18 10:45:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::look_ppa(int month, const char* codatt, int type, bool create)
|
|
|
|
|
{
|
|
|
|
|
_ppa->zero();
|
|
|
|
|
(*_ppa_year) = _year;
|
|
|
|
|
(*_ppa_month) = format("%02d",month);
|
1996-12-06 09:25:22 +00:00
|
|
|
|
(*_ppa_codatt) = format("%6s", codatt);
|
1995-09-18 10:45:10 +00:00
|
|
|
|
(*_ppa_kind) = type;
|
|
|
|
|
TString ctab = _ppa_r->get("CODTAB");
|
|
|
|
|
_ppa->read();
|
|
|
|
|
|
|
|
|
|
bool ok = _ppa->good();
|
|
|
|
|
|
|
|
|
|
if (!ok && create)
|
|
|
|
|
{
|
|
|
|
|
_ppa_r->zero();
|
|
|
|
|
_ppa_r->put("CODTAB",ctab);
|
|
|
|
|
_ppa->write();
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::look_del(int month, int type, bool create)
|
|
|
|
|
{
|
|
|
|
|
// se chiamata con il flag di creazione, aggiorna le info su
|
|
|
|
|
// codici tributo, concessione, conto fiscale anche se la
|
|
|
|
|
// delega esiste gia'
|
|
|
|
|
|
1995-11-08 16:18:13 +00:00
|
|
|
|
// Molto pericoloso chiamare con create = TRUE:
|
|
|
|
|
// se e' gia' stata fatta l'estrazione versamenti
|
|
|
|
|
// e l'utente cambia titcf e isdel sull'anagrafica
|
|
|
|
|
// sono c... suoi!!! (Maurizio)
|
|
|
|
|
// deve rifarsi la delega con l'ESTRAZIONE VERSAMENTI
|
|
|
|
|
// io l'ho lasciato per rispetto del lavoro altrui
|
|
|
|
|
|
1995-09-18 10:45:10 +00:00
|
|
|
|
long ditta = _nditte->curr().get_long("CODDITTA");
|
|
|
|
|
_del->zero();
|
|
|
|
|
(*_del_ditta) = format("%05ld", ditta);
|
|
|
|
|
(*_del_anno) = _year;
|
|
|
|
|
(*_del_mese) = format("%02d", month);
|
|
|
|
|
(*_del_tipo) = format("%1d", type);
|
|
|
|
|
|
|
|
|
|
TString16 ctab = _del->get("CODTAB");
|
|
|
|
|
_del->read();
|
|
|
|
|
|
|
|
|
|
bool ok = _del->good();
|
|
|
|
|
|
|
|
|
|
if (!ok && create)
|
|
|
|
|
{
|
|
|
|
|
_del->zero();
|
|
|
|
|
_del->put("CODTAB",ctab);
|
|
|
|
|
}
|
1995-11-08 16:18:13 +00:00
|
|
|
|
|
|
|
|
|
if (create)
|
1995-09-18 10:45:10 +00:00
|
|
|
|
{
|
|
|
|
|
// vedi se titolare conto fiscale
|
|
|
|
|
bool titcf = FALSE;
|
|
|
|
|
bool isdel = FALSE;
|
1995-10-25 15:04:58 +00:00
|
|
|
|
int uffiva;
|
1995-09-18 10:45:10 +00:00
|
|
|
|
TLocalisamfile anag(LF_ANAG);
|
|
|
|
|
anag.zero();
|
|
|
|
|
anag.put("TIPOA", _nditte->lfile().get("TIPOA"));
|
|
|
|
|
anag.put("CODANAGR", _nditte->lfile().get("CODANAGR"));
|
|
|
|
|
if (anag.read() == NOERR)
|
|
|
|
|
{
|
|
|
|
|
titcf = anag.get_bool("TITCF");
|
1995-10-25 15:04:58 +00:00
|
|
|
|
isdel = anag.get_long("TIPOSTDEL") == 0l;
|
|
|
|
|
uffiva = anag.get_int("UFFIVA");
|
1995-09-18 10:45:10 +00:00
|
|
|
|
}
|
1998-04-30 15:59:34 +00:00
|
|
|
|
|
|
|
|
|
TString16 con;
|
|
|
|
|
TString uva;
|
|
|
|
|
if (titcf)
|
|
|
|
|
look_conc(con, uva); // Legge la concessione se titolare conto fiscale
|
|
|
|
|
|
1995-09-18 10:45:10 +00:00
|
|
|
|
if (!titcf || isdel)
|
|
|
|
|
{
|
|
|
|
|
// non titolare conto fiscale oppure paga con delega:
|
|
|
|
|
// cerca banca
|
|
|
|
|
// codici ABI e CAB da anagrafica ditte
|
1995-10-25 15:04:58 +00:00
|
|
|
|
TString16 abi, cab;
|
1995-11-08 16:18:13 +00:00
|
|
|
|
abi = _nditte->lfile().get("ABIBAN");
|
|
|
|
|
cab = _nditte->lfile().get("CABBAN");
|
1995-09-18 10:45:10 +00:00
|
|
|
|
if (abi.empty())
|
|
|
|
|
{
|
1995-09-27 15:28:09 +00:00
|
|
|
|
TConfig c (CONFIG_STUDIO, "cg");
|
|
|
|
|
abi = c.get("CodABI");
|
|
|
|
|
cab = c.get("CodCAB");
|
1995-11-08 16:18:13 +00:00
|
|
|
|
}
|
1995-09-18 10:45:10 +00:00
|
|
|
|
_del->put("S7", abi);
|
1998-04-30 15:59:34 +00:00
|
|
|
|
_del->put("S8", cab);
|
|
|
|
|
if (titcf && isdel) // Se e' titolare CF e stampa la delega, va riportata anche la conc
|
|
|
|
|
{
|
|
|
|
|
_del->put("S9", con);
|
|
|
|
|
_del->put("S2", uva);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
_del->put("S9", "");
|
|
|
|
|
}
|
1995-11-08 16:18:13 +00:00
|
|
|
|
else
|
1995-09-18 10:45:10 +00:00
|
|
|
|
{
|
|
|
|
|
// non usa delega bensi' bollettino o distinta:
|
|
|
|
|
// cerca concessione comune
|
|
|
|
|
// infila ufficio concessione in S9
|
|
|
|
|
// e descrizione comune in S2
|
1998-04-30 15:59:34 +00:00
|
|
|
|
_del->put("S9", con);
|
|
|
|
|
_del->put("S2", uva);
|
|
|
|
|
_del->put("S7", "");
|
|
|
|
|
_del->put("S8", "");
|
1995-09-18 10:45:10 +00:00
|
|
|
|
}
|
1995-11-08 16:18:13 +00:00
|
|
|
|
} //fine create
|
|
|
|
|
|
|
|
|
|
// le descrizioni sulla delega non vengono
|
|
|
|
|
// memorizzate dai vari programmi di gestione
|
|
|
|
|
// e estrazione ma solo qui.
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
int uffiva;
|
|
|
|
|
TLocalisamfile anag(LF_ANAG);
|
|
|
|
|
anag.zero();
|
|
|
|
|
anag.put("TIPOA", _nditte->lfile().get("TIPOA"));
|
|
|
|
|
anag.put("CODANAGR", _nditte->lfile().get("CODANAGR"));
|
|
|
|
|
if (anag.read() == NOERR)
|
|
|
|
|
uffiva = anag.get_int("UFFIVA");
|
1995-09-18 10:45:10 +00:00
|
|
|
|
|
1995-11-08 16:18:13 +00:00
|
|
|
|
TString16 abi = _del->get("S7");
|
|
|
|
|
TString16 cab = _del->get("S8");
|
|
|
|
|
TString16 con = _del->get("S9");
|
|
|
|
|
|
|
|
|
|
// descrizione banca
|
|
|
|
|
if (abi.not_empty())
|
|
|
|
|
{
|
|
|
|
|
TTable ban("%BAN");
|
|
|
|
|
ban.zero();
|
|
|
|
|
TString codban = format("%05ld", atol(abi));
|
|
|
|
|
if (!cab.empty()) codban << format("%05ld", atol(cab));
|
|
|
|
|
ban.put("CODTAB", codban);
|
|
|
|
|
if (ban.read() == NOERR)
|
|
|
|
|
{
|
|
|
|
|
TString desban(ban.get("S0"));
|
|
|
|
|
_del->put("S1", desban);
|
|
|
|
|
}
|
|
|
|
|
//che rottura: ogni giorno alla prassi cambiano idea!!!
|
|
|
|
|
TTable uiv("%UIV");
|
|
|
|
|
uiv.zero();
|
|
|
|
|
TString16 coduff = format("%03d", uffiva);
|
|
|
|
|
uiv.put("CODTAB", coduff);
|
|
|
|
|
if (uiv.read() == NOERR)
|
|
|
|
|
{
|
|
|
|
|
TString desiva(uiv.get("S0"));
|
|
|
|
|
_del->put("S2", desiva);
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-04-30 15:59:34 +00:00
|
|
|
|
// Descrizione cod. concessione
|
|
|
|
|
if (con.not_empty())
|
1995-11-08 16:18:13 +00:00
|
|
|
|
{
|
|
|
|
|
TString uva;
|
|
|
|
|
if (look_conc(con, uva))
|
|
|
|
|
_del->put("S2", uva);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// scrive codice tributo
|
|
|
|
|
int ctri = 6000;
|
|
|
|
|
if (month == 13 && type == 7)
|
|
|
|
|
ctri = 6035; // acconto IVA annuale (trimestrali?)
|
|
|
|
|
else if (month == 13 && type == 1)
|
|
|
|
|
ctri = 6099; // IVA annuale
|
|
|
|
|
else if (month < 13 && type == 7)
|
1995-09-18 10:45:10 +00:00
|
|
|
|
ctri = 6013; // acconto mensile
|
|
|
|
|
else if (month < 13 && type == 1) // regular
|
|
|
|
|
ctri = _freqviva == "M" ? 6000 + month : 6030 + (month/3);
|
|
|
|
|
|
1995-11-08 16:18:13 +00:00
|
|
|
|
_del->put("S6", format("%d",ctri));
|
|
|
|
|
|
|
|
|
|
if (!ok) _del->write();
|
|
|
|
|
else _del->rewrite();
|
1995-09-18 10:45:10 +00:00
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::look_lia(long ditta, bool create, int year)
|
|
|
|
|
{
|
|
|
|
|
if (year == 0) year = atoi(_year);
|
|
|
|
|
if (ditta == 0l) ditta = get_firm();
|
2002-02-26 16:20:19 +00:00
|
|
|
|
|
1995-09-18 10:45:10 +00:00
|
|
|
|
TString16 y; y.format("%05ld%04d", ditta, year);
|
|
|
|
|
_lia->put("CODTAB", y);
|
2002-02-26 16:20:19 +00:00
|
|
|
|
const bool ok = _lia->read() == NOERR;
|
|
|
|
|
if (!ok)
|
1995-09-18 10:45:10 +00:00
|
|
|
|
{
|
|
|
|
|
_lia->zero();
|
|
|
|
|
_lia->put("CODTAB", y);
|
|
|
|
|
_lia->put("S7", _freqviva);
|
2002-02-26 16:20:19 +00:00
|
|
|
|
if (create)
|
|
|
|
|
_lia->write();
|
1995-09-18 10:45:10 +00:00
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
real TLiquidazione_app::result_liq(int month)
|
|
|
|
|
// risultato esatto della liquidazione del mese month, <0 a credito
|
|
|
|
|
// > 0 a debito; comprende TUTTI, anche il conguaglio prorata in annuale
|
|
|
|
|
{
|
|
|
|
|
real r(0.0);
|
|
|
|
|
// ulteriori detrazioni, acconti, versamenti,
|
|
|
|
|
// rettifiche, conguagli sono gia' compresi in R0
|
|
|
|
|
if (look_lim(month))
|
|
|
|
|
r = _lim->get_real("R0");
|
|
|
|
|
return r;
|
|
|
|
|
}
|
2001-05-01 08:17:07 +00:00
|
|
|
|
|
|
|
|
|
real TLiquidazione_app::iva_da_riportare(int month)
|
|
|
|
|
{
|
|
|
|
|
real idr;
|
|
|
|
|
const int anno = atoi(_year);
|
|
|
|
|
if (month > 12)
|
|
|
|
|
{
|
|
|
|
|
if (_ver->read(anno, 12) == NOERR)
|
|
|
|
|
idr = _ver->get(I_ANNUALE);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (_ver->read(anno, month) == NOERR)
|
|
|
|
|
idr = _ver->get(I_PERIODICO);
|
|
|
|
|
}
|
|
|
|
|
return idr;
|
|
|
|
|
}
|
1995-09-18 10:45:10 +00:00
|
|
|
|
|
|
|
|
|
real TLiquidazione_app::debt_prec(int month)
|
|
|
|
|
{
|
2001-05-01 08:17:07 +00:00
|
|
|
|
real r;
|
1995-09-18 10:45:10 +00:00
|
|
|
|
if (!is_first_month(month))
|
|
|
|
|
{
|
|
|
|
|
if (look_lim(previous_month(month)))
|
|
|
|
|
{
|
|
|
|
|
r = result_liq(previous_month(month));
|
2001-05-01 08:17:07 +00:00
|
|
|
|
if (!(r > ZERO && r < iva_da_riportare(month)))
|
1995-09-18 10:45:10 +00:00
|
|
|
|
r = ZERO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
real TLiquidazione_app::credito_prec(int month)
|
|
|
|
|
// ritorna l'appropriato credito precedente al mese in corso
|
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
real c = ZERO;
|
|
|
|
|
|
1998-04-30 15:59:34 +00:00
|
|
|
|
const bool lia_ok = look_lia();
|
2000-05-05 15:25:49 +00:00
|
|
|
|
const bool old_age = atoi(_year) < 2000 || _lia->get("S9") != "NV";
|
1995-09-18 10:45:10 +00:00
|
|
|
|
|
|
|
|
|
if (is_first_month(month))
|
|
|
|
|
{
|
|
|
|
|
// credito inizio anno
|
1998-04-30 15:59:34 +00:00
|
|
|
|
if (lia_ok)
|
2000-05-05 15:25:49 +00:00
|
|
|
|
{
|
|
|
|
|
// Dal 2000 se S8="NV" il credito precedente non esiste piu'
|
|
|
|
|
if (old_age)
|
|
|
|
|
c = _lia->get_real("R0");
|
|
|
|
|
}
|
1995-09-18 10:45:10 +00:00
|
|
|
|
// e' positivo o 0
|
|
|
|
|
}
|
1997-10-06 15:11:10 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
c = result_liq(previous_month(month));
|
1998-04-30 15:59:34 +00:00
|
|
|
|
if (c.sign() < 0)
|
|
|
|
|
c = abs(c);
|
|
|
|
|
else
|
2000-05-05 15:25:49 +00:00
|
|
|
|
c = ZERO;
|
1998-04-30 15:59:34 +00:00
|
|
|
|
|
2000-05-05 15:25:49 +00:00
|
|
|
|
// Dal 2000 se S8="NV" il credito trasferito non esiste piu'
|
|
|
|
|
if (old_age)
|
1998-04-30 15:59:34 +00:00
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
// Nel caso di trimestrali considera dal trimestre corrispondente a
|
|
|
|
|
// quello impostato+1. Ad es. se m == 1 considera dal I trim. (m=3)
|
|
|
|
|
// se m == 2 idem (m=3). Se m == 3 considera dal II trim. (m=6).
|
|
|
|
|
const int crm = _lia->get_int("I0") + 1;
|
|
|
|
|
if (lia_ok && crm > 1) // Vale dal mese successivo a quello impostato
|
|
|
|
|
{
|
|
|
|
|
// Toglie il Credito Trasferito
|
|
|
|
|
if (month == liq_month(crm))
|
|
|
|
|
c -= _lia->get_real("R15");
|
|
|
|
|
}
|
1998-04-30 15:59:34 +00:00
|
|
|
|
}
|
1997-10-06 15:11:10 +00:00
|
|
|
|
}
|
1995-09-18 10:45:10 +00:00
|
|
|
|
|
1997-10-06 15:11:10 +00:00
|
|
|
|
return c;
|
1995-09-18 10:45:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
real TLiquidazione_app::credito_costo_prec(int month)
|
|
|
|
|
// ritorna l'appropriato credito di costo precedente al mese in corso
|
|
|
|
|
// (travel agency only)
|
|
|
|
|
{
|
|
|
|
|
real c(0.0);
|
1995-10-17 08:49:03 +00:00
|
|
|
|
if (is_first_month(month) || month == 13)
|
1995-09-18 10:45:10 +00:00
|
|
|
|
{
|
|
|
|
|
// credito inizio anno
|
|
|
|
|
if (look_lia())
|
|
|
|
|
c = _lia->get_real("R5");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (look_lim(previous_month(month)))
|
|
|
|
|
// qui il rimborso non c'e'
|
|
|
|
|
c = _lim->get_real("R2");
|
|
|
|
|
}
|
|
|
|
|
look_lim(month);
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
real TLiquidazione_app::versamenti_IVA(int month, const char* types, bool intr)
|
|
|
|
|
{
|
|
|
|
|
real ret(0.0); TToken_string typ(types);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < typ.items(); i++)
|
|
|
|
|
{
|
|
|
|
|
int tp = typ.get_int(i);
|
|
|
|
|
if (look_del(month,tp))
|
|
|
|
|
{
|
1996-06-18 09:29:09 +00:00
|
|
|
|
real importo_dovuto_non_arrotondato(_del->get_real("R2"));
|
|
|
|
|
real interessi(_del->get_real("R1"));
|
|
|
|
|
real importo_dovuto_arrotondato(_del->get_real("R0"));
|
|
|
|
|
real work(importo_dovuto_non_arrotondato);
|
|
|
|
|
|
2002-02-26 16:20:19 +00:00
|
|
|
|
round_imposta(work);
|
1996-06-18 09:29:09 +00:00
|
|
|
|
if (_month == 13 && _freqviva == "T" && importo_dovuto_arrotondato == work)
|
|
|
|
|
ret += importo_dovuto_non_arrotondato; // Questo e' l'importo lordo non arrotondato!!
|
1996-05-20 13:54:44 +00:00
|
|
|
|
else
|
1996-06-18 09:29:09 +00:00
|
|
|
|
ret += importo_dovuto_arrotondato;
|
1996-02-06 16:07:55 +00:00
|
|
|
|
//gli interessi vengono memorizzati solo se si
|
|
|
|
|
//devono pagare (=> nessun controllo su intra)
|
1997-05-29 15:59:04 +00:00
|
|
|
|
if (!(_is_visliq && _freqviva == "T" && _month != 13)) // toglie gli interessi se non siamo in visualiz. o la ditta non e' TRIM o siamo in annuale
|
1996-07-17 10:17:43 +00:00
|
|
|
|
ret -= interessi; // al netto degli interessi
|
1996-06-18 09:29:09 +00:00
|
|
|
|
// In caso di 13a liq e per trimestrali... devo fare la somma
|
|
|
|
|
// degli importi netti dovuti, ecco perche' leggo R2,
|
1996-05-20 13:54:44 +00:00
|
|
|
|
// perche togliendo poi gli interessi ottengo il dovuto netto!
|
1996-06-18 09:29:09 +00:00
|
|
|
|
// Questa casistica vale pero' solo se in R2 c'e' qualcosa(!=0) ed
|
|
|
|
|
// e' relativo all'importo presente in R0. Ovvero:
|
|
|
|
|
// nel caso si estraggano i versamenti trimestrali, i campi R2
|
|
|
|
|
// vengono correttamente compilati. Se poi si modificano a mano i
|
|
|
|
|
// valori di R0 (tramite gestione versamenti, visualizzazione o
|
|
|
|
|
// calcolo acconti) tale importo non e' piu' consistente, ecco quindi
|
|
|
|
|
// il controllo effettuato tra R0 e ROUND(R2). In realta' sarebbe piu'
|
|
|
|
|
// oppurtuno che in gestione versamenti, visualizzazione liquidazione e
|
|
|
|
|
// calcolo acconti, vi sia la possibilita' di modificare anche R2.
|
|
|
|
|
// Tutto cio' e' relativo all'errore MI3386.
|
1995-09-18 10:45:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-26 16:20:19 +00:00
|
|
|
|
// Arrotonda intelligentemente alle 1000 Lire, al centesimo di Euro o all'unit<69> di Euro
|
|
|
|
|
void TLiquidazione_app::round_imposta(real& d) const
|
1997-01-30 16:39:10 +00:00
|
|
|
|
{
|
2002-02-26 16:20:19 +00:00
|
|
|
|
TIva_round ir;
|
|
|
|
|
ir.round(d);
|
2001-05-01 08:17:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TLiquidazione_app::round_alla_lira(real& d, bool sup)
|
|
|
|
|
{
|
|
|
|
|
const int dec = TCurrency::get_firm_dec();
|
|
|
|
|
if (dec == 0) // lire
|
|
|
|
|
{
|
|
|
|
|
if (sup)
|
|
|
|
|
{
|
|
|
|
|
if (d >= ZERO)
|
|
|
|
|
d.ceil(0);
|
|
|
|
|
else
|
|
|
|
|
d.floor(0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
d.round(0);
|
|
|
|
|
}
|
|
|
|
|
else
|
1999-07-16 14:59:11 +00:00
|
|
|
|
d.round(dec);
|
1997-01-30 16:39:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-05-01 08:17:07 +00:00
|
|
|
|
|
1996-12-19 09:21:13 +00:00
|
|
|
|
// Ritorna il parametro della liquidazione differita per la ditta corrente, cosi come
|
|
|
|
|
// e' scritto sui parametri liquidazione (LIA)
|
|
|
|
|
// Se si passa 0 (default) vede prende la ditta correntemente in corso di calcolo
|
|
|
|
|
// Analogamente per l'anno
|
|
|
|
|
bool TLiquidazione_app::is_differita(long firm, int year)
|
|
|
|
|
{
|
|
|
|
|
long d = (firm == 0) ? _nditte->lfile().get_long("CODDITTA") : firm;
|
|
|
|
|
int y = (year == 0) ? atoi(_year) : year;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
if (look_lia(d, atoi(_year) > 0))
|
1996-12-19 09:21:13 +00:00
|
|
|
|
return _lia->get_bool("B1");
|
1998-05-04 09:34:04 +00:00
|
|
|
|
else
|
1996-12-19 09:21:13 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
1995-09-18 10:45:10 +00:00
|
|
|
|
real TLiquidazione_app::aliquota_agvia()
|
|
|
|
|
{
|
2001-05-01 08:17:07 +00:00
|
|
|
|
real r;
|
|
|
|
|
TConfig cnf(CONFIG_STUDIO, "cg");
|
|
|
|
|
const TString& codagv = cnf.get("CodAgv");
|
|
|
|
|
if (codagv.not_empty() && look_iva(codagv)) // Controlla se <20> vuoto! CM600475
|
|
|
|
|
r = _iva->get_real("R0");
|
1995-09-18 10:45:10 +00:00
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
real TLiquidazione_app::interesse_trimestrale(int month)
|
|
|
|
|
{
|
1996-04-24 16:52:46 +00:00
|
|
|
|
month--; month /= 3;
|
|
|
|
|
real r(_ver->get(month)); // month varia da 0 a 4, proprio come da P_1_TRIMESTRE... in poi
|
1995-09-18 10:45:10 +00:00
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TLiquidazione_app::look_conc(TString& uffcon, TString& uffiva)
|
|
|
|
|
{
|
|
|
|
|
// piazza nelle TString passate: l'ufficio concessioni
|
|
|
|
|
// l'ufficio IVA. Quest'ultimo e' preso dall'anagrafica se
|
|
|
|
|
// c'e', dal comune (primo non vuoto) se non
|
|
|
|
|
|
|
|
|
|
// Assume _nditte correctly positioned
|
|
|
|
|
TString ana(_nditte->lfile().get("TIPOA"));
|
|
|
|
|
TString codana(_nditte->lfile().get("CODANAGR"));
|
|
|
|
|
// look anagrafica
|
|
|
|
|
TLocalisamfile anagr(LF_ANAG);
|
|
|
|
|
anagr.zero();
|
|
|
|
|
anagr.put("TIPOA", ana);
|
|
|
|
|
anagr.put("CODANAGR", codana);
|
|
|
|
|
if (anagr.read() != NOERR) return FALSE;
|
|
|
|
|
|
|
|
|
|
// becca comune residenza fiscale
|
|
|
|
|
TString com(anagr.get("COMRF"));
|
|
|
|
|
// se non c'e', residenza
|
|
|
|
|
if (com.empty())
|
|
|
|
|
com = anagr.get("COMRES");
|
|
|
|
|
|
|
|
|
|
if (com.empty()) return FALSE;
|
|
|
|
|
|
|
|
|
|
// becca comune
|
|
|
|
|
TLocalisamfile comuni(LF_COMUNI);
|
|
|
|
|
comuni.zero(); // STATO = "" ovvero ITAGLIA
|
|
|
|
|
comuni.put("COM", com);
|
|
|
|
|
if (comuni.read() != NOERR) return FALSE;
|
|
|
|
|
|
1995-10-25 15:04:58 +00:00
|
|
|
|
const int uffa = comuni.get_int("UFFCONC");
|
|
|
|
|
if (uffcon.empty())
|
|
|
|
|
uffcon = format("%03d",uffa);
|
|
|
|
|
if (uffcon.not_empty())
|
|
|
|
|
{
|
|
|
|
|
TTable ucc("%UCC");
|
|
|
|
|
ucc.zero();
|
|
|
|
|
ucc.put("CODTAB", uffcon);
|
|
|
|
|
if (ucc.read() == NOERR)
|
|
|
|
|
uffiva = ucc.get("S0");
|
|
|
|
|
}
|
1995-09-18 10:45:10 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2000-05-05 15:25:49 +00:00
|
|
|
|
|
|
|
|
|
real TLiquidazione_app::credito_utilizzato(int month, bool iva, bool f24) const
|
|
|
|
|
{
|
|
|
|
|
real credito;
|
|
|
|
|
|
|
|
|
|
TTable lim("LIM");
|
|
|
|
|
TString16 cod;
|
|
|
|
|
for (int m = 1; m <= month; m++)
|
|
|
|
|
{
|
|
|
|
|
cod.format("%s%02d", (const char*)_year, m);
|
|
|
|
|
lim.put("CODTAB", cod);
|
|
|
|
|
if (lim.read() == NOERR)
|
|
|
|
|
{
|
|
|
|
|
if (iva && m < month)
|
|
|
|
|
credito += lim.get_real("R15"); // Credito utilizzato IVA
|
|
|
|
|
if (f24 && m < 13)
|
|
|
|
|
credito += lim.get_real("R16"); // Credito utilizzato F24
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return credito;
|
|
|
|
|
}
|