1994-12-28 11:00:21 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <tabutil.h>
|
1995-04-20 14:29:00 +00:00
|
|
|
#include <prefix.h>
|
1995-02-13 17:20:26 +00:00
|
|
|
#include <utility.h>
|
1994-12-28 11:00:21 +00:00
|
|
|
|
|
|
|
#include "cg2101.h"
|
|
|
|
#include "cg2103.h"
|
|
|
|
|
|
|
|
#include <mov.h>
|
|
|
|
#include <rmov.h>
|
|
|
|
#include <rmoviva.h>
|
1995-02-14 10:03:05 +00:00
|
|
|
#include <utility.h>
|
1994-12-28 11:00:21 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Movimento di prima nota
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
TMovimentoPN::TMovimentoPN()
|
1995-04-20 14:29:00 +00:00
|
|
|
: TRelation(LF_MOV), _cg(LF_RMOV, "NUMRIG"), _iva(LF_RMOVIVA, "NUMRIG")
|
1994-12-28 11:00:21 +00:00
|
|
|
{
|
|
|
|
add(LF_RMOV, "NUMREG=NUMREG");
|
|
|
|
add(LF_RMOVIVA, "NUMREG=NUMREG");
|
|
|
|
}
|
|
|
|
|
1995-04-20 14:29:00 +00:00
|
|
|
void TMovimentoPN::destroy_rows(long num)
|
|
|
|
{
|
|
|
|
_cg.destroy_rows();
|
|
|
|
_cg.renum_key("NUMREG", num);
|
|
|
|
_iva.destroy_rows();
|
|
|
|
_iva.renum_key("NUMREG", num);
|
1994-12-28 11:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TRectype& TMovimentoPN::cg(int i)
|
|
|
|
{
|
1995-04-20 14:29:00 +00:00
|
|
|
return _cg.row(i >= 0 ? i+1 : -1, TRUE);
|
1994-12-28 11:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TRectype& TMovimentoPN::iva(int i)
|
|
|
|
{
|
1995-04-20 14:29:00 +00:00
|
|
|
return _iva.row(i >= 0 ? i+1 : -1, TRUE);
|
1994-12-28 11:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int TMovimentoPN::read_mov_rows()
|
1995-04-20 14:29:00 +00:00
|
|
|
{
|
|
|
|
const long numreg = lfile().get_long(MOV_NUMREG);
|
|
|
|
|
|
|
|
TRectype cgfilter(LF_RMOV);
|
|
|
|
cgfilter.zero();
|
|
|
|
cgfilter.put(RMV_NUMREG, numreg);
|
|
|
|
_cg.read(cgfilter);
|
|
|
|
|
|
|
|
TRectype ivafilter(LF_RMOVIVA);
|
|
|
|
ivafilter.zero();
|
|
|
|
ivafilter.put(RMI_NUMREG, numreg);
|
|
|
|
_iva.read(ivafilter);
|
1994-12-28 11:00:21 +00:00
|
|
|
|
1995-04-20 14:29:00 +00:00
|
|
|
return _cg.rows();
|
1994-12-28 11:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMovimentoPN::read(TIsamop op, TReclock lockop, TDate& atdate)
|
|
|
|
{
|
1995-06-28 16:33:53 +00:00
|
|
|
const int err = TRelation::read(op, lockop, atdate);
|
1994-12-28 11:00:21 +00:00
|
|
|
if (err == NOERR)
|
|
|
|
{
|
1995-06-28 16:33:53 +00:00
|
|
|
_olddate = file().get("DATAREG"); // Memorizza data operazione per aggiornare i saldi
|
|
|
|
read_mov_rows(); // Riempie i due record array
|
1994-12-28 11:00:21 +00:00
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
char TMovimentoPN::frequenza_versamenti(int year) const
|
|
|
|
{
|
|
|
|
static int last_year = 0;
|
1995-01-18 14:39:53 +00:00
|
|
|
static long last_firm = 0;
|
1994-12-28 11:00:21 +00:00
|
|
|
static char last_freq = ' ';
|
|
|
|
|
1995-04-20 14:29:00 +00:00
|
|
|
const long firm = prefix().get_codditta();
|
1995-01-18 14:39:53 +00:00
|
|
|
|
|
|
|
if (firm != last_firm || year != last_year)
|
1994-12-28 11:00:21 +00:00
|
|
|
{
|
1995-02-13 17:20:26 +00:00
|
|
|
TString16 key; key.format("%05ld%d", firm, year);
|
|
|
|
TTable lia("%LIA");
|
1994-12-28 11:00:21 +00:00
|
|
|
lia.put("CODTAB", key);
|
|
|
|
if (lia.read() != NOERR)
|
|
|
|
{
|
1995-01-19 09:11:01 +00:00
|
|
|
TLocalisamfile nditte(LF_NDITTE);
|
|
|
|
nditte.put("CODDITTA", firm);
|
1994-12-28 11:00:21 +00:00
|
|
|
nditte.read();
|
|
|
|
last_freq = nditte.get_char("FREQVIVA");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
last_freq = lia.get_char("S7");
|
|
|
|
CHECK(last_freq == 'M' || last_freq == 'T', "Frequenza versamenti IVA assurda");
|
1995-04-20 14:29:00 +00:00
|
|
|
|
|
|
|
last_firm = firm;
|
|
|
|
last_year = year;
|
1994-12-28 11:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return last_freq;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TMovimentoPN::date2liq(const TDate& data) const
|
|
|
|
{
|
|
|
|
const int anno = data.year();
|
|
|
|
int mese = data.month();
|
|
|
|
if (frequenza_versamenti(anno) == 'T')
|
|
|
|
mese += 2 - ((mese-1) % 3);
|
|
|
|
return mese;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-12-07 11:09:17 +00:00
|
|
|
bool TMovimentoPN::controlla_liquidazione(const TDate& data, TRegistro& registro, bool reset) const
|
1994-12-28 11:00:21 +00:00
|
|
|
{
|
|
|
|
bool calcolata = FALSE;
|
|
|
|
|
|
|
|
const int anno = data.year();
|
|
|
|
const int mese = date2liq(data);
|
|
|
|
|
|
|
|
// Chiave di LIM: Anno (1-4), Mese (5-6)
|
1995-02-10 17:41:38 +00:00
|
|
|
TString16 key; key.format("%04d%02d", anno, mese);
|
1994-12-28 11:00:21 +00:00
|
|
|
TTable lim("LIM");
|
|
|
|
lim.setkey(1);
|
|
|
|
lim.put("CODTAB", key);
|
|
|
|
if (lim.read() == NOERR)
|
|
|
|
calcolata = lim.get_bool("B1"); // Controlla se calcolata in definitivo
|
|
|
|
|
|
|
|
if (reset && lim.get_bool("B0"))
|
|
|
|
{
|
|
|
|
// Resetta i flag di calcolato sulla liquidazione IVA del mese di registrazione
|
1995-02-28 10:02:55 +00:00
|
|
|
lim.zero("B0"); // calcolato
|
|
|
|
lim.zero("B1"); // definitivo
|
1994-12-28 11:00:21 +00:00
|
|
|
lim.rewrite();
|
|
|
|
}
|
|
|
|
|
1995-12-07 11:09:17 +00:00
|
|
|
if (reset)
|
|
|
|
{
|
|
|
|
const bool att_mista = registro.name().empty() ? FALSE : registro.attivita_mista();
|
|
|
|
const int att = att_mista ? 2 : 1;
|
|
|
|
|
|
|
|
// Chiave di PLM: Anno (1-4), Cod. Att. (5-9), Tipo att. (10-10), Mese (11-12)
|
|
|
|
TTable plm("PLM");
|
|
|
|
for (int a = 1; a <= att; a++)
|
|
|
|
{
|
|
|
|
TString16 chiave;
|
|
|
|
TString16 attivita(registro.attivita()); attivita.right_just(5, '0');
|
|
|
|
chiave << data.year() << attivita << a << format("%02d", data.month());
|
|
|
|
plm.put("CODTAB", chiave);
|
|
|
|
if (plm.read() == NOERR)
|
|
|
|
{
|
|
|
|
const bool calcolato = plm.get_bool("B0");
|
|
|
|
if (calcolato)
|
|
|
|
{
|
|
|
|
plm.zero("B0");
|
|
|
|
plm.rewrite();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-12-28 11:00:21 +00:00
|
|
|
return calcolata;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMovimentoPN::registra(bool re, bool force)
|
|
|
|
{
|
1995-04-20 14:29:00 +00:00
|
|
|
int err = re ? TRelation::rewrite(force) : TRelation::write(force);
|
|
|
|
if (err != NOERR)
|
|
|
|
return err;
|
1995-09-19 15:43:43 +00:00
|
|
|
|
|
|
|
const TRectype& m = curr();
|
|
|
|
const long numreg = m.get_long("NUMREG");
|
1995-04-20 14:29:00 +00:00
|
|
|
|
|
|
|
if (!re)
|
|
|
|
_cg.renum_key("NUMREG", numreg);
|
|
|
|
err = _cg.write(re);
|
|
|
|
if (err != NOERR)
|
|
|
|
return err;
|
1994-12-28 11:00:21 +00:00
|
|
|
|
|
|
|
const int annoiva = m.get_int("ANNOIVA");
|
1995-04-20 14:29:00 +00:00
|
|
|
const TString16 reg(m.get_str("REG"));
|
1994-12-28 11:00:21 +00:00
|
|
|
TRegistro registro(reg, annoiva);
|
|
|
|
const bool att_mista = reg.empty() ? FALSE : registro.attivita_mista();
|
|
|
|
|
1995-04-20 14:29:00 +00:00
|
|
|
for (int i = 0 ; i < iva_items(); i++)
|
1994-12-28 11:00:21 +00:00
|
|
|
{
|
|
|
|
TRectype& r = iva(i);
|
|
|
|
int tipoatt = 1;
|
|
|
|
if (att_mista)
|
|
|
|
{
|
|
|
|
const char tipo = r.get_char("TIPOC");
|
|
|
|
if (tipo <= ' ')
|
|
|
|
{
|
|
|
|
TBill c(r.get_int("GRUPPO"), r.get_int("CONTO"), r.get_long("SOTTOCONTO"));
|
|
|
|
tipoatt = c.tipo_att();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r.put("TIPOATT", tipoatt);
|
|
|
|
}
|
|
|
|
|
1995-04-20 14:29:00 +00:00
|
|
|
if (!re)
|
|
|
|
_iva.renum_key("NUMREG", numreg);
|
|
|
|
err = _iva.write(re);
|
|
|
|
if (err != NOERR)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
1994-12-28 11:00:21 +00:00
|
|
|
// Aggiorna data registrazione e protocollo IVA sul registro
|
|
|
|
const TDate datareg(m.get("DATAREG"));
|
|
|
|
if (reg.not_empty())
|
|
|
|
{
|
|
|
|
const long protiva = m.get_long("PROTIVA");
|
|
|
|
const long uprotiva = m.get_long("UPROTIVA");
|
1995-04-20 14:29:00 +00:00
|
|
|
const long max = protiva > uprotiva ? protiva : uprotiva;
|
|
|
|
registro.update(max, datareg);
|
1994-12-28 11:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Aggiorna flags di ricalcolo liquidazione
|
|
|
|
|
1995-12-07 11:09:17 +00:00
|
|
|
controlla_liquidazione(datareg, registro, TRUE);
|
1994-12-28 11:00:21 +00:00
|
|
|
if (re && datareg != _olddate)
|
1995-12-07 11:09:17 +00:00
|
|
|
controlla_liquidazione(_olddate, registro, TRUE);
|
1994-12-28 11:00:21 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMovimentoPN::write(bool force, TDate&)
|
|
|
|
{
|
1995-04-20 14:29:00 +00:00
|
|
|
return registra(FALSE, force);
|
1994-12-28 11:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMovimentoPN::rewrite(bool force, TDate&)
|
|
|
|
{
|
|
|
|
return registra(TRUE, force);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMovimentoPN::remove(TDate&)
|
1995-07-05 14:38:05 +00:00
|
|
|
{
|
|
|
|
int err = _cg.remove();
|
1995-04-20 14:29:00 +00:00
|
|
|
|
|
|
|
if (err == NOERR)
|
|
|
|
err = _iva.remove();
|
1995-10-11 11:39:50 +00:00
|
|
|
|
1995-07-05 14:38:05 +00:00
|
|
|
if (err == NOERR)
|
|
|
|
err = TRelation::remove();
|
|
|
|
|
1995-10-11 11:39:50 +00:00
|
|
|
if (err == NOERR)
|
1995-12-07 11:09:17 +00:00
|
|
|
{
|
|
|
|
const TRectype& m = curr();
|
|
|
|
const TDate datareg(m.get("DATAREG"));
|
|
|
|
const int annoiva = m.get_int("ANNOIVA");
|
|
|
|
const TString16 reg(m.get_str("REG"));
|
|
|
|
TRegistro registro(reg, annoiva);
|
|
|
|
controlla_liquidazione(datareg, registro, TRUE);
|
1995-10-11 11:39:50 +00:00
|
|
|
}
|
|
|
|
|
1995-04-20 14:29:00 +00:00
|
|
|
return err;
|
1994-12-28 11:00:21 +00:00
|
|
|
}
|
|
|
|
|