1994-09-01 16:26:29 +00:00
|
|
|
#include <xvtmacro.h>
|
|
|
|
|
|
|
|
#include "cg2101.h"
|
|
|
|
#include "cg2103.h"
|
|
|
|
|
|
|
|
#include <lffiles.h>
|
|
|
|
#include <mov.h>
|
|
|
|
#include <rmov.h>
|
|
|
|
#include <rmoviva.h>
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Movimento di prima nota
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
TMovimentoPN::TMovimentoPN()
|
|
|
|
: TRelation(LF_MOV), _oldcg(0), _oldiva(0)
|
|
|
|
{
|
|
|
|
add(LF_RMOV, "NUMREG=NUMREG");
|
|
|
|
add(LF_RMOVIVA, "NUMREG=NUMREG");
|
|
|
|
}
|
|
|
|
|
|
|
|
void TMovimentoPN::destroy_rows()
|
|
|
|
{
|
|
|
|
_cg.destroy();
|
|
|
|
_iva.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TRectype& TMovimentoPN::cg(int i)
|
|
|
|
{
|
|
|
|
TRectype* r = (TRectype*)_cg.objptr(i);
|
|
|
|
if (r == NULL)
|
|
|
|
{
|
|
|
|
r = new TRectype(LF_RMOV);
|
|
|
|
_cg.add(r, i);
|
|
|
|
}
|
|
|
|
return *r;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRectype& TMovimentoPN::iva(int i)
|
|
|
|
{
|
|
|
|
TRectype* r = (TRectype*)_iva.objptr(i);
|
|
|
|
if (r == NULL)
|
|
|
|
{
|
|
|
|
r = new TRectype(LF_RMOVIVA);
|
|
|
|
_iva.add(r, i);
|
|
|
|
}
|
|
|
|
return *r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMovimentoPN::read_mov_rows()
|
|
|
|
{
|
|
|
|
const TLocalisamfile* rm = lfile(LF_RMOV);
|
|
|
|
const TLocalisamfile* ri = lfile(LF_RMOVIVA);
|
|
|
|
position_rels();
|
|
|
|
|
|
|
|
destroy_rows();
|
|
|
|
for(bool ok = is_first_match(LF_RMOV); ok; ok = next_match(LF_RMOV))
|
|
|
|
{
|
|
|
|
const int row = rm->get_int(RMV_NUMRIG) - 1;
|
|
|
|
cg(row) = rm->curr();
|
|
|
|
}
|
|
|
|
_oldcg = cg_items();
|
|
|
|
|
|
|
|
for(ok = is_first_match(LF_RMOVIVA); ok; ok = next_match(LF_RMOVIVA))
|
|
|
|
{
|
|
|
|
const int row = ri->get_int(RMI_NUMRIG) - 1;
|
|
|
|
iva(row) = ri->curr();
|
|
|
|
}
|
|
|
|
_oldiva = iva_items();
|
|
|
|
|
|
|
|
return NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMovimentoPN::read(TIsamop op, TReclock lockop, TDate& atdate)
|
|
|
|
{
|
|
|
|
int err = file()->read(op, lockop, atdate);
|
|
|
|
if (err == NOERR) err = read_mov_rows();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMovimentoPN::write_rec(bool re, const TRectype& rec, TLocalisamfile* f)
|
|
|
|
{
|
|
|
|
if (re)
|
|
|
|
{
|
|
|
|
const bool scrivi = f->rewrite(rec) != NOERR;
|
|
|
|
if (scrivi) f->write(rec);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
f->write(rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
return f->status();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMovimentoPN::cancella(TLocalisamfile* f, int da, int a)
|
|
|
|
{
|
|
|
|
const long numreg = lfile()->get_long("NUMREG");
|
|
|
|
for (int i = da; i <= a; i++)
|
|
|
|
{
|
|
|
|
f->zero();
|
|
|
|
f->put("NUMREG", numreg);
|
|
|
|
f->put("NUMRIG", i);
|
|
|
|
if (f->read(_isequal, _lock) == NOERR)
|
|
|
|
f->remove();
|
|
|
|
}
|
|
|
|
return f->status();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMovimentoPN::registra(bool re, bool force)
|
|
|
|
{
|
|
|
|
TLocalisamfile* m = lfile();
|
|
|
|
|
|
|
|
const int err = write_rec(re, m->curr(), m);
|
|
|
|
if (err != NOERR) return err;
|
|
|
|
|
|
|
|
TLocalisamfile* rm = lfile(LF_RMOV);
|
|
|
|
TLocalisamfile* ri = lfile(LF_RMOVIVA);
|
|
|
|
|
|
|
|
const long numreg = m->get_long("NUMREG");
|
|
|
|
|
|
|
|
for (int i = 0 ; i < cg_items(); i++)
|
|
|
|
{
|
|
|
|
if (!re) cg(i).put("NUMREG", numreg);
|
|
|
|
const int err = write_rec(re, cg(i), rm);
|
|
|
|
if (!force && err != NOERR) return err;
|
|
|
|
}
|
|
|
|
if (i < _oldcg)
|
|
|
|
cancella(rm, i+1, _oldcg);
|
|
|
|
_oldcg = cg_items();
|
|
|
|
|
|
|
|
for (i = 0 ; i < iva_items(); i++)
|
|
|
|
{
|
|
|
|
if (!re) iva(i).put("NUMREG", numreg);
|
|
|
|
const int err = write_rec(re, iva(i), ri);
|
|
|
|
if (!force && err != NOERR) return err;
|
|
|
|
}
|
|
|
|
if (i < _oldiva)
|
|
|
|
cancella(ri, i+1, _oldiva);
|
|
|
|
_oldiva = iva_items();
|
|
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMovimentoPN::write(bool force, TDate&)
|
|
|
|
{
|
|
|
|
const TLocalisamfile& r = *lfile();
|
|
|
|
const int annoiva = r.get_int("ANNOIVA");
|
|
|
|
const TString16 reg(r.get("REG"));
|
|
|
|
TRegistro registro(reg, annoiva);
|
|
|
|
|
|
|
|
if (registro.iva() != nessuna_iva)
|
|
|
|
{
|
|
|
|
const bool mista = registro.tipo_attivita() == "M";
|
|
|
|
for (int i = 0; i < iva_items(); i++)
|
|
|
|
{
|
|
|
|
int tipoatt = 1;
|
|
|
|
if (mista)
|
|
|
|
{
|
|
|
|
const int riga = iva(i).get_int("RIGAIMP");
|
|
|
|
if (riga)
|
|
|
|
{
|
|
|
|
const TRectype& r = cg(riga-1);
|
|
|
|
const char tipo = r.get_char("TIPOC");
|
|
|
|
if (tipo == ' ')
|
|
|
|
{
|
|
|
|
TConto c(r.get_int("GRUPPO"), r.get_int("CONTO"), r.get_long("SOTTOCONTO"));
|
|
|
|
TRectype conto(LF_PCON); c.read(conto);
|
|
|
|
const TIndbil ib = (TIndbil)conto.get_int("INDBIL");
|
|
|
|
if (ib == ib_passivita || ib == ib_ricavi)
|
|
|
|
{
|
|
|
|
int ricser = conto.get_int("RICSER");
|
|
|
|
tipoatt = (ricser == 0) ? 2 : 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
iva(i).put("TIPOATT", tipoatt);
|
|
|
|
}
|
|
|
|
}
|
1994-09-07 16:59:33 +00:00
|
|
|
|
1994-09-01 16:26:29 +00:00
|
|
|
_oldcg = _oldiva = 0;
|
|
|
|
int err = registra(FALSE, force);
|
|
|
|
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
1994-09-07 16:59:33 +00:00
|
|
|
const TDate datareg(r.get("DATAREG"));
|
|
|
|
TLibro_giornale gio(datareg.year());
|
|
|
|
gio.update(0L, datareg); // Aggiorna data registrazione sul libro giornale
|
|
|
|
|
1994-09-01 16:26:29 +00:00
|
|
|
if (reg.not_empty())
|
1994-09-07 16:59:33 +00:00
|
|
|
{ // Aggiorna data registrazione e protocollo IVA sul registro
|
1994-09-01 16:26:29 +00:00
|
|
|
const long protiva = r.get_long("PROTIVA");
|
|
|
|
const long uprotiva = r.get_long("UPROTIVA");
|
|
|
|
const TDate datareg = r.get_date("DATAREG");
|
|
|
|
registro.update(max(protiva, uprotiva), datareg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMovimentoPN::rewrite(bool force, TDate&)
|
|
|
|
{
|
|
|
|
return registra(TRUE, force);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMovimentoPN::remove(TDate&)
|
|
|
|
{
|
|
|
|
TLocalisamfile* m = lfile();
|
|
|
|
TLocalisamfile* rm = lfile(LF_RMOV);
|
|
|
|
TLocalisamfile* ri = lfile(LF_RMOVIVA);
|
|
|
|
|
|
|
|
cancella(rm, 1, _oldcg);
|
|
|
|
cancella(ri, 1, _oldiva);
|
|
|
|
m->remove();
|
|
|
|
_oldcg = _oldiva = 0;
|
|
|
|
return m->status();
|
|
|
|
}
|
|
|
|
|