6788cf17ed
git-svn-id: svn://10.65.10.50/branches/R_10_00@23051 c028cbd2-c16b-5b4b-a496-9718f37d4682
191 lines
4.6 KiB
C++
Executable File
191 lines
4.6 KiB
C++
Executable File
//***********************************
|
||
//* Rinumerazione numero protocollo *
|
||
//***********************************
|
||
#include <mask.h>
|
||
#include <progind.h>
|
||
#include <tabutil.h>
|
||
#include <relation.h>
|
||
#include <recarray.h>
|
||
|
||
#include "cg1300.h"
|
||
#include "cg1303.h"
|
||
|
||
#include <causali.h>
|
||
#include <mov.h>
|
||
#include <partite.h>
|
||
|
||
|
||
HIDDEN TAgg_nprot& app() { return (TAgg_nprot&) main_app(); }
|
||
|
||
HIDDEN bool filtra_mov(const TRelation* r)
|
||
{
|
||
const TRectype& mov = r->curr();
|
||
const int annoiva = mov.get_int(MOV_ANNOIVA);
|
||
TString4 reg = mov.get(MOV_REG);
|
||
|
||
const TAgg_nprot& a = app();
|
||
|
||
if (reg.full() && reg != a.reg())
|
||
{
|
||
const TString& codcaus = mov.get(MOV_CODCAUS);
|
||
const TString& truereg = cache().get(LF_CAUSALI, codcaus, CAU_REG);
|
||
if (truereg != reg && truereg == a.reg()) // REG incoerente
|
||
reg = truereg;
|
||
}
|
||
|
||
return a.anno() == annoiva && a.reg() == reg;
|
||
}
|
||
|
||
void TAgg_nprot::main_loop()
|
||
{
|
||
TMask msk("cg1300b");
|
||
|
||
while (msk.run() == K_ENTER)
|
||
{
|
||
_anno = msk.get_int(F_ANNO);
|
||
_reg = msk.get(F_REG);
|
||
|
||
rinumera_prot(msk.get(F_MODE)[0], msk.get_long(F_PROT));
|
||
|
||
msk.reset(F_REG);
|
||
}
|
||
}
|
||
|
||
bool TAgg_nprot::rinumera_prot(char mode, long last_prot)
|
||
{
|
||
TTable reg("REG");
|
||
TString8 s; s.format("%04d%s", _anno, (const char*)_reg);
|
||
reg.put("CODTAB", s);
|
||
if (reg.read() != NOERR)
|
||
return error_box(FR("Impossibile leggere il registro %s del %d"),
|
||
(const char*)_reg, _anno);
|
||
|
||
TFast_isamfile fastmov(LF_MOV);
|
||
TRelation rel (LF_MOV);
|
||
rel.add(LF_PARTITE, "NREG=NUMREG", 2);
|
||
|
||
TLocalisamfile& mov = rel.lfile();
|
||
TLocalisamfile& part= rel.lfile(LF_PARTITE);
|
||
|
||
TCursor cursor(&rel, "", 2);
|
||
cursor.set_filterfunction(filtra_mov);
|
||
|
||
const long nitems = cursor.items();
|
||
if (nitems == 0)
|
||
return warning_box(TR("Non ci sono movimenti da rinumerare"));
|
||
|
||
const bool sc_enabled = ini_get_bool(CONFIG_DITTA,"cg", "GesSal");
|
||
|
||
cursor.freeze();
|
||
cursor = 0L;
|
||
|
||
TProgind p(nitems, TR("Elaborazione in corso...") , FALSE, TRUE);
|
||
|
||
if (mode == 'N' || mode == 'U')
|
||
{
|
||
long protiva, uprotiva;
|
||
for (; cursor.pos() < nitems; ++cursor)
|
||
{
|
||
p.addstatus(1);
|
||
protiva = mov.get_long(MOV_PROTIVA);
|
||
uprotiva = mov.get_long(MOV_UPROTIVA);
|
||
|
||
if (mode == 'U')
|
||
{
|
||
if (mov.get_bool(MOV_REGST))
|
||
{
|
||
last_prot = uprotiva > protiva ? uprotiva : protiva;
|
||
continue;
|
||
}
|
||
break;
|
||
}
|
||
|
||
if (mode == 'N')
|
||
{
|
||
if (protiva != last_prot && uprotiva != last_prot)
|
||
continue;
|
||
else
|
||
{
|
||
if (uprotiva != 0l)
|
||
last_prot = uprotiva;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (last_prot > 0 && mode == 'N')
|
||
{
|
||
if (protiva != last_prot && uprotiva != last_prot) //sono alla fine del file
|
||
return error_box(TR("Non esiste la registrazione con protocollo %ld:\nrinumerazione non avvenuta"), last_prot);
|
||
++cursor;
|
||
}
|
||
}
|
||
|
||
long nprot,uprot,dprot;
|
||
dprot = uprot = 0L;
|
||
nprot = last_prot;
|
||
|
||
long first_nreg = 0, first_nprot = 0;
|
||
long last_nreg = 0, last_nprot = 0;
|
||
|
||
for (; cursor.pos() < nitems; ++cursor)
|
||
{
|
||
p.addstatus(1);
|
||
const long protiva = mov.get_long(MOV_PROTIVA);
|
||
const long uprotiva = mov.get_long(MOV_UPROTIVA);
|
||
const TString& reg = mov.get(MOV_REG);
|
||
|
||
if (mode == 'P') // Modalit<69> speciale COMARI protiva = numdoc
|
||
{
|
||
nprot = mov.get_long(MOV_NUMDOC);
|
||
dprot = uprot = 0;
|
||
}
|
||
else
|
||
{
|
||
nprot = nprot+1+dprot; //stile RPG
|
||
dprot = (uprotiva == 0L) ? 0L : (uprotiva - protiva);
|
||
uprot = (uprotiva == 0L) ? 0L : (nprot + dprot);
|
||
}
|
||
|
||
if (nprot != protiva || uprot != uprotiva || reg != _reg)
|
||
{
|
||
mov.put(MOV_REG, _reg);
|
||
mov.put(MOV_PROTIVA, nprot);
|
||
mov.put(MOV_UPROTIVA, uprot);
|
||
int err = mov.rewrite();
|
||
if (err != NOERR)
|
||
{
|
||
cantwrite_box("Movimenti IVA");
|
||
break;
|
||
}
|
||
}
|
||
|
||
// Aggiorna il nr di prot. iva sul file partite
|
||
if (sc_enabled && rel.is_first_match(LF_PARTITE))
|
||
{
|
||
do
|
||
{
|
||
part.put(PART_PROTIVA,nprot);
|
||
part.rewrite();
|
||
} while (rel.next_match(LF_PARTITE));
|
||
}
|
||
|
||
const long numreg = mov.get_long(MOV_NUMREG);
|
||
if (first_nreg <= 0)
|
||
{
|
||
first_nreg = numreg;
|
||
first_nprot = nprot;
|
||
}
|
||
last_nreg = numreg;
|
||
last_nprot = nprot;
|
||
}
|
||
|
||
reg.put("I5", nprot + dprot);
|
||
reg.rewrite();
|
||
|
||
return message_box(FR("Rinumerazione numero protocollo completata\n"
|
||
"dal movimento %ld (%ld) al movimento %ld (%ld)"),
|
||
first_nreg, first_nprot, last_nreg, last_nprot);
|
||
}
|
||
|