1996-11-07 13:48:02 +00:00
|
|
|
// sistema il codice esercizio di tutti i movimenti
|
2007-09-17 15:33:04 +00:00
|
|
|
#include "cg1305.h"
|
|
|
|
#include "cglib01.h"
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
#include <mask.h>
|
|
|
|
#include <progind.h>
|
1997-06-19 14:33:52 +00:00
|
|
|
#include <recarray.h>
|
1996-11-08 09:42:04 +00:00
|
|
|
#include <relation.h>
|
2007-09-17 15:33:04 +00:00
|
|
|
#include <recset.h>
|
1997-06-19 14:33:52 +00:00
|
|
|
|
1996-11-08 09:42:04 +00:00
|
|
|
#include <mov.h>
|
|
|
|
#include <rmov.h>
|
|
|
|
#include <rmoviva.h>
|
1996-11-07 13:48:02 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
static bool aggiorna_righe(TRecord_array& righe, int annoes)
|
1996-11-07 13:48:02 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
bool qualcuno_sbagliato = false;
|
|
|
|
for (int i = righe.last_row(); i > 0; i = righe.pred_row(i))
|
|
|
|
{
|
|
|
|
const TRectype& riga = righe.row(i);
|
|
|
|
const int anno = riga.get_int(RMV_ANNOES);
|
|
|
|
if (anno != annoes)
|
|
|
|
{
|
|
|
|
qualcuno_sbagliato = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (qualcuno_sbagliato)
|
|
|
|
{
|
|
|
|
// Serve per righe iva non zerofilled
|
|
|
|
TString4 sanno; sanno.format("%04d", annoes);
|
|
|
|
righe.renum_key(RMV_ANNOES, sanno);
|
|
|
|
righe.rewrite();
|
|
|
|
}
|
|
|
|
return qualcuno_sbagliato;
|
1996-11-07 13:48:02 +00:00
|
|
|
}
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
void TAgg_codes::main_loop()
|
1996-11-07 13:48:02 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
open_files(LF_MOV, LF_RMOV, LF_RMOVIVA, LF_TAB, 0);
|
|
|
|
|
1996-11-07 13:48:02 +00:00
|
|
|
TMask msk("cg1300d");
|
1996-11-08 09:42:04 +00:00
|
|
|
if (msk.run() == K_ENTER)
|
2007-09-17 15:33:04 +00:00
|
|
|
{
|
|
|
|
long modified_recs=0L;
|
|
|
|
int err = NOERR;
|
1996-11-07 13:48:02 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
TISAM_recordset mov("USE MOV");
|
|
|
|
const TRecnotype nrec = mov.items();
|
1996-11-07 13:48:02 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
if (nrec > 0) // Dummy test for progind destruction
|
1996-11-08 09:42:04 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
TEsercizi_contabili esercizi;
|
|
|
|
TProgind pi(nrec, TR("Aggiornamento in corso..."), true, true);
|
|
|
|
TRecord_array righe(LF_RMOV, RMV_NUMRIG);
|
|
|
|
TRecord_array righeiva(LF_RMOVIVA, RMI_NUMRIG);
|
|
|
|
TRectype riga(LF_RMOV);
|
|
|
|
TRectype rigaiva(LF_RMOVIVA);
|
|
|
|
|
|
|
|
for (bool ok = mov.move_first(); ok && err == NOERR; ok = mov.move_next())
|
|
|
|
{
|
|
|
|
if (!pi.addstatus(1))
|
|
|
|
break;
|
|
|
|
|
|
|
|
const TDate data = mov.get(MOV_DATACOMP).as_date();
|
|
|
|
const int oldcodes = mov.get(MOV_ANNOES).as_int();
|
|
|
|
const int newcodes = esercizi.date2esc(data);
|
|
|
|
bool cambiato = false;
|
|
|
|
|
|
|
|
if (oldcodes != newcodes)
|
|
|
|
{
|
|
|
|
TRectype& curr = mov.cursor()->curr();
|
|
|
|
curr.put(MOV_ANNOES, newcodes);
|
|
|
|
err = curr.rewrite(mov.cursor()->file());
|
|
|
|
cambiato = err == NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
const long numreg = mov.get(MOV_NUMREG).as_int();
|
|
|
|
riga.put(RMV_NUMREG, numreg);
|
|
|
|
righe.read(riga);
|
|
|
|
cambiato |= aggiorna_righe(righe, newcodes);
|
2007-03-07 10:11:15 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
rigaiva.put(RMI_NUMREG, numreg);
|
|
|
|
righeiva.read(rigaiva);
|
|
|
|
cambiato |= aggiorna_righe(righeiva, newcodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cambiato)
|
|
|
|
modified_recs++;
|
|
|
|
}
|
1996-11-08 09:42:04 +00:00
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
|
|
|
|
if (err != NOERR)
|
|
|
|
warning_box(FR("Aggiornamento codice esercizio interrotta. Rilevato errore %d in riscrittura"),err);
|
|
|
|
else
|
|
|
|
message_box(FR("Aggiornamento codice esercizio completata. Modificati %ld movimenti.\nE' necessario procedere col ricalcolo saldi"), modified_recs);
|
1996-11-08 09:42:04 +00:00
|
|
|
}
|
1996-11-07 16:10:34 +00:00
|
|
|
}
|