1994-12-28 11:00:21 +00:00
|
|
|
// Rinumerazione movimenti e saldi
|
|
|
|
// fv 12/12/93
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// *TBI* Partenza dall'ultimo movimento stampato
|
|
|
|
// *TBI* Aggiornamento scadenziario
|
|
|
|
// *TBI* Aggiornamento cespiti
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include <applicat.h>
|
|
|
|
#include <isam.h>
|
|
|
|
#include <mask.h>
|
|
|
|
#include <progind.h>
|
|
|
|
#include <sort.h>
|
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
#define FLD_CG41_YEAR 100
|
|
|
|
#define MAX_CNT 300
|
|
|
|
|
|
|
|
#include <mov.h>
|
|
|
|
#include <rmov.h>
|
|
|
|
#include <rmoviva.h>
|
|
|
|
#include <saldi.h>
|
|
|
|
#include <causali.h>
|
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
#include "cglib02.h"
|
1994-12-28 11:00:21 +00:00
|
|
|
|
|
|
|
struct therec {
|
|
|
|
char DATAREG[9];
|
|
|
|
char REG[4];
|
|
|
|
char DATADOC[9];
|
|
|
|
char NUMPROT[9];
|
|
|
|
char ANNOES[5];
|
|
|
|
char NUMREG[8];
|
|
|
|
};
|
|
|
|
|
1998-02-24 10:31:42 +00:00
|
|
|
class CG4100_App : public TSkeleton_application
|
1994-12-28 11:00:21 +00:00
|
|
|
{
|
1995-06-22 14:46:26 +00:00
|
|
|
int _year;
|
1994-12-28 11:00:21 +00:00
|
|
|
char _optype;
|
|
|
|
TMask* _msk;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
bool set_parms();
|
1998-02-24 10:31:42 +00:00
|
|
|
virtual void main_loop();
|
1994-12-28 11:00:21 +00:00
|
|
|
|
|
|
|
void restore_mov(TSystemisamfile& a, TSystemisamfile& b, TSystemisamfile& c);
|
|
|
|
void sort_all();
|
|
|
|
bool sort_mov();
|
|
|
|
bool sort_sal();
|
|
|
|
|
1998-02-24 10:31:42 +00:00
|
|
|
CG4100_App() : _optype('S') {}
|
1994-12-28 11:00:21 +00:00
|
|
|
virtual ~CG4100_App() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1998-02-24 10:31:42 +00:00
|
|
|
bool CG4100_App::set_parms()
|
1994-12-28 11:00:21 +00:00
|
|
|
{
|
1998-02-24 10:31:42 +00:00
|
|
|
_msk->run();
|
|
|
|
|
|
|
|
if (_optype == 'S')
|
|
|
|
_year = _msk->get_int(FLD_CG41_YEAR);
|
|
|
|
else
|
|
|
|
_year = 0;
|
1994-12-28 11:00:21 +00:00
|
|
|
|
1998-02-24 10:31:42 +00:00
|
|
|
return _msk->last_key() == K_ENTER;
|
|
|
|
}
|
1994-12-28 11:00:21 +00:00
|
|
|
|
1998-02-24 10:31:42 +00:00
|
|
|
|
|
|
|
void CG4100_App::main_loop()
|
|
|
|
{
|
1994-12-28 11:00:21 +00:00
|
|
|
if (fexist("__sal__.sav"))
|
|
|
|
warning_box("Un'operazione di riordino saldi si e' conclusa"
|
|
|
|
" impropriamente. Si raccomanda di rieseguirla");
|
|
|
|
|
|
|
|
if (fexist("__mov__.sav"))
|
|
|
|
warning_box("Un'operazione di riordino movimenti si e' conclusa"
|
|
|
|
" impropriamente. Si raccomanda di rieseguirla");
|
|
|
|
|
|
|
|
if (argc() > 2)
|
|
|
|
_optype = toupper(argv(2)[0]);
|
|
|
|
|
|
|
|
_msk = new TMask(_optype == 'S' ? "cg4100b" : "cg4100a");
|
|
|
|
|
|
|
|
if (_optype == 'S')
|
|
|
|
sort_sal();
|
|
|
|
else
|
|
|
|
sort_mov();
|
|
|
|
|
1998-02-24 10:31:42 +00:00
|
|
|
delete _msk;
|
1994-12-28 11:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CG4100_App::restore_mov(TSystemisamfile& mov, TSystemisamfile& rmov,
|
|
|
|
TSystemisamfile& rmoviva)
|
|
|
|
{
|
|
|
|
long rn, rec;
|
|
|
|
if (fexist("__mov__.ind"))
|
|
|
|
{
|
|
|
|
// rebuild all indexes
|
|
|
|
mov.close(); rmov.close(); rmoviva.close();
|
|
|
|
mov.packfile(); rmov.packfile(); rmoviva.packfile();
|
|
|
|
mov.packindex(); rmov.packindex(); rmoviva.packindex();
|
|
|
|
remove("__mov__.ind");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE* fp = fopen("__mov__.sav","r");
|
|
|
|
if (feof(fp))
|
|
|
|
{
|
|
|
|
warning_box("File di ripristino vuoto; il ripristino non e' necessario");
|
|
|
|
remove("__mov__.sav");
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (feof(fp)) break;
|
|
|
|
fscanf(fp,"%ld %ld", &rn, &rec);
|
|
|
|
|
|
|
|
mov.readat(rec);
|
|
|
|
mov.put(MOV_NUMREG,rn);
|
|
|
|
mov.rewrite();
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (feof(fp)) break;
|
|
|
|
fscanf(fp,"%ld",&rec);
|
|
|
|
if (rec == -1l) break;
|
|
|
|
rmov.readat(rec);
|
|
|
|
rmov.put(RMV_NUMREG,rn);
|
|
|
|
rmov.rewrite();
|
|
|
|
}
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (feof(fp)) break;
|
|
|
|
fscanf(fp,"%ld",&rec);
|
|
|
|
if (rec == -1l) break;
|
|
|
|
rmoviva.readat(rec);
|
|
|
|
rmoviva.put(RMI_NUMREG,rn);
|
|
|
|
rmoviva.rewrite();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
remove("__mov__.sav");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CG4100_App::sort_mov()
|
|
|
|
{
|
|
|
|
if (!set_parms())
|
|
|
|
return FALSE;
|
|
|
|
|
1995-05-10 09:26:37 +00:00
|
|
|
TSystemisamfile mov(LF_MOV); mov.open(_excllock);
|
|
|
|
TSystemisamfile rmov(LF_RMOV); rmov.open(_excllock);
|
|
|
|
TSystemisamfile rmoviva(LF_RMOVIVA); rmoviva.open(_excllock);
|
|
|
|
|
1994-12-28 11:00:21 +00:00
|
|
|
mov.indexoff(); rmov.indexoff(); rmoviva.indexoff();
|
|
|
|
mov.first();
|
|
|
|
|
|
|
|
TSort sort(sizeof(struct therec));
|
|
|
|
|
|
|
|
if (fexist("__mov__.sav") || fexist("__mov__.ind"))
|
|
|
|
{
|
|
|
|
// previous operation failed
|
|
|
|
if (yesno_box("Un riordinamento precedente e' fallito.\n"
|
|
|
|
" Ripristino la situazione iniziale ora?" ))
|
|
|
|
restore_mov(mov, rmov, rmoviva);
|
|
|
|
else return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
therec rbuf;
|
|
|
|
|
|
|
|
sort.addsortkey(rbuf.DATAREG - (char*)&rbuf, 8);
|
|
|
|
sort.addsortkey(rbuf.REG - (char*)&rbuf, 3);
|
|
|
|
sort.addsortkey(rbuf.NUMPROT - (char*)&rbuf, 8);
|
|
|
|
sort.addsortkey(rbuf.DATADOC - (char*)&rbuf, 8);
|
|
|
|
sort.addsortkey(rbuf.NUMREG - (char*)&rbuf, 7);
|
|
|
|
|
|
|
|
sort.init();
|
|
|
|
|
|
|
|
TProgind prnd(mov.items(),
|
|
|
|
"Riordino archivio movimenti in corso\nOrdinamento file movimenti...",
|
|
|
|
FALSE,TRUE,30);
|
|
|
|
TString16 s;
|
|
|
|
|
|
|
|
while (!mov.eof())
|
|
|
|
{
|
|
|
|
do_events();
|
|
|
|
TDate d(mov.get(MOV_DATAREG));
|
|
|
|
strcpy(rbuf.DATAREG, d.string(ANSI));
|
|
|
|
strcpy(rbuf.REG, mov.get(MOV_REG));
|
|
|
|
d = mov.get(MOV_DATADOC);
|
|
|
|
s = mov.get(MOV_PROTIVA);
|
|
|
|
if (s.len() > 0 && isdigit(s[s.len() - 1])) s << " ";
|
|
|
|
s.right_just(8);
|
|
|
|
strcpy(rbuf.NUMPROT, (const char *) s);
|
|
|
|
strcpy(rbuf.DATADOC, d.string(ANSI));
|
|
|
|
strcpy(rbuf.ANNOES, mov.get(MOV_ANNOES));
|
|
|
|
strcpy(rbuf.NUMREG, mov.get(MOV_NUMREG));
|
|
|
|
|
|
|
|
sort.sort((char*)&rbuf);
|
|
|
|
mov.next();
|
|
|
|
prnd.addstatus(1);
|
|
|
|
}
|
|
|
|
sort.endsort();
|
|
|
|
|
|
|
|
prnd.setstatus(0);
|
|
|
|
prnd.set_text("Riordino archivio movimenti in corso\nRiscrittura file movimenti...");
|
|
|
|
|
|
|
|
therec* rr;
|
|
|
|
long num = 1;
|
|
|
|
TRecnotype recno;
|
|
|
|
|
|
|
|
while ((rr = (therec*)sort.retrieve()) != NULL)
|
|
|
|
{
|
|
|
|
do_events();
|
|
|
|
if (atol(rr->NUMREG) != num)
|
|
|
|
{
|
|
|
|
// find record
|
|
|
|
mov.curr().zero();
|
|
|
|
mov.put(MOV_NUMREG, rr->NUMREG);
|
|
|
|
|
|
|
|
mov.read();
|
|
|
|
// should never happen
|
|
|
|
CHECK(mov.good(), "Archivio movimenti inconsistente. Questo si' che e' un casino.");
|
|
|
|
|
|
|
|
// retrieve and change NUMREG
|
|
|
|
recno = mov.recno();
|
|
|
|
TString rgn = rr->NUMREG;
|
|
|
|
FILE* fsav = fopen("__mov__.sav","a");
|
|
|
|
fprintf(fsav,"%s %d ", (const char*)rgn, recno);
|
|
|
|
fclose(fsav);
|
|
|
|
|
|
|
|
mov.put(MOV_NUMREG,num);
|
|
|
|
mov.rewriteat(recno);
|
|
|
|
// update linked records
|
|
|
|
|
|
|
|
rmov.curr().zero();
|
|
|
|
rmov.put(RMV_NUMREG,rgn);
|
|
|
|
rmov.read(_isgteq);
|
|
|
|
|
|
|
|
int row = 0;
|
|
|
|
|
|
|
|
while (!rmov.eof() && rgn == rmov.get(RMV_NUMREG) &&
|
|
|
|
row++ < rmov.get_int(RMV_NUMRIG))
|
|
|
|
{
|
|
|
|
recno = rmov.recno();
|
|
|
|
fsav = fopen("__mov__.sav","a");
|
|
|
|
fprintf(fsav,"%ld ", recno);
|
|
|
|
fclose(fsav);
|
|
|
|
rmov.put(RMV_NUMREG,num);
|
|
|
|
rmov.rewriteat(recno);
|
|
|
|
rmov.next();
|
|
|
|
}
|
|
|
|
fsav = fopen("__mov__.sav","a");
|
|
|
|
fprintf(fsav,"-1"); fclose(fsav);
|
|
|
|
|
|
|
|
rmoviva.zero();
|
|
|
|
rmoviva.put(RMI_NUMREG,rgn);
|
|
|
|
rmoviva.read(_isgteq);
|
|
|
|
|
|
|
|
row = 0;
|
|
|
|
|
|
|
|
while (!rmoviva.eof() && rgn == rmoviva.get(RMV_NUMREG) &&
|
|
|
|
row++ < rmoviva.get_int(RMV_NUMRIG))
|
|
|
|
{
|
|
|
|
recno = rmoviva.recno();
|
|
|
|
fsav = fopen("__mov__.sav","a");
|
|
|
|
fprintf(fsav,"%ld ", recno);
|
|
|
|
fclose(fsav);
|
|
|
|
rmoviva.put(RMI_NUMREG,num);
|
|
|
|
rmoviva.rewriteat(recno);
|
|
|
|
rmoviva.next();
|
|
|
|
}
|
|
|
|
fsav = fopen("__mov__.sav","a");
|
|
|
|
fprintf(fsav,"-1"); fclose(fsav);
|
|
|
|
}
|
|
|
|
num++;
|
|
|
|
prnd.addstatus(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
remove("__mov__.sav");
|
|
|
|
|
|
|
|
FILE* fsav = fopen("__mov__.ind","w"); fclose(fsav);
|
|
|
|
|
|
|
|
prnd.set_text("Riordino archivio movimenti in corso\nRicostruzione files indice...");
|
|
|
|
|
|
|
|
// rebuild indexes
|
|
|
|
mov.close(); rmov.close(); rmoviva.close();
|
|
|
|
mov.indexon(); rmov.indexon(); rmoviva.indexon();
|
|
|
|
mov.packfile(); rmov.packfile(); rmoviva.packfile();
|
|
|
|
mov.packindex(); rmov.packindex(); rmoviva.packindex();
|
|
|
|
|
|
|
|
remove("__mov__.ind");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CG4100_App::sort_sal()
|
|
|
|
{
|
|
|
|
if (!set_parms())
|
|
|
|
return FALSE;
|
|
|
|
|
1995-05-10 09:26:37 +00:00
|
|
|
TSystemisamfile saldi(LF_SALDI); saldi.open(_excllock);
|
1994-12-28 11:00:21 +00:00
|
|
|
TLocalisamfile rmov(LF_RMOV);
|
|
|
|
TLocalisamfile causali(LF_CAUSALI);
|
1995-05-10 09:26:37 +00:00
|
|
|
TLocalisamfile mov(LF_MOV);
|
1994-12-28 11:00:21 +00:00
|
|
|
TSaldo_agg sal;
|
1995-05-10 09:26:37 +00:00
|
|
|
|
|
|
|
FILE* fp = fopen ("__sal__.sav","w");
|
|
|
|
fclose(fp);
|
|
|
|
|
1994-12-28 11:00:21 +00:00
|
|
|
int gruppo, conto;
|
1995-06-22 14:46:26 +00:00
|
|
|
const int year = _year;
|
1994-12-28 11:00:21 +00:00
|
|
|
long oldnumreg = 0L, sottoconto;
|
|
|
|
TProgind prnd(rmov.items(),
|
|
|
|
"Riordino archivio saldi in corso\nLettura archivio movimenti...",
|
|
|
|
FALSE,TRUE,30);
|
|
|
|
|
|
|
|
causali.zero();
|
|
|
|
mov.setkey(1);
|
|
|
|
rmov.first();
|
|
|
|
sal.reset();
|
|
|
|
sal.set_anno_es(year);
|
|
|
|
sal.clear_saldi(year);
|
1995-03-02 11:52:18 +00:00
|
|
|
long numreg = 0L;
|
1996-05-20 09:26:39 +00:00
|
|
|
tiposal tsal = normale;
|
|
|
|
bool provvis = FALSE;
|
1995-03-02 11:52:18 +00:00
|
|
|
TDate datareg;
|
|
|
|
|
1994-12-28 11:00:21 +00:00
|
|
|
while (!rmov.eof())
|
|
|
|
{
|
1995-06-22 14:46:26 +00:00
|
|
|
if (_year == rmov.get_int(RMV_ANNOES))
|
1994-12-28 11:00:21 +00:00
|
|
|
{
|
1995-03-02 11:52:18 +00:00
|
|
|
numreg = rmov.get_long(RMV_NUMREG);
|
1996-05-20 09:26:39 +00:00
|
|
|
|
1994-12-28 11:00:21 +00:00
|
|
|
gruppo = rmov.get_int(RMV_GRUPPO);
|
|
|
|
conto = rmov.get_int(RMV_CONTO);
|
1996-05-20 09:26:39 +00:00
|
|
|
sottoconto = rmov.get_long(RMV_SOTTOCONTO);
|
|
|
|
bool scaricato = FALSE;
|
|
|
|
|
1994-12-28 11:00:21 +00:00
|
|
|
if (numreg != oldnumreg)
|
|
|
|
{
|
1995-03-02 11:52:18 +00:00
|
|
|
if (oldnumreg !=0)
|
|
|
|
{
|
|
|
|
if (sal.items() > 0)
|
|
|
|
sal.registra();
|
|
|
|
}
|
1994-12-28 11:00:21 +00:00
|
|
|
oldnumreg = numreg;
|
|
|
|
mov.zero();
|
|
|
|
mov.put(MOV_NUMREG, numreg);
|
|
|
|
mov.read();
|
|
|
|
CHECK(mov.good(),"Archivi movimenti e righe inconsistenti");
|
|
|
|
|
1995-03-02 14:55:20 +00:00
|
|
|
causali.zero();
|
1994-12-28 11:00:21 +00:00
|
|
|
const char* codcaus = mov.get(MOV_CODCAUS);
|
1996-09-04 07:50:26 +00:00
|
|
|
|
|
|
|
tsal = normale;
|
|
|
|
if (*codcaus) // cerca causale per determinare il tipoo del saldo
|
1994-12-28 11:00:21 +00:00
|
|
|
{
|
|
|
|
causali.put(CAU_CODCAUS, codcaus);
|
1996-09-04 07:50:26 +00:00
|
|
|
const int err = causali.read();
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
const char ac = causali.get_char(CAU_MOVAP);
|
|
|
|
if (ac == 'A')
|
|
|
|
tsal = apertura;
|
|
|
|
else
|
|
|
|
if (ac == 'C')
|
|
|
|
tsal = chiusura;
|
|
|
|
}
|
1994-12-28 11:00:21 +00:00
|
|
|
}
|
1996-09-04 07:50:26 +00:00
|
|
|
|
|
|
|
scaricato = mov.get_bool(MOV_SCARCON);
|
|
|
|
provvis = mov.get(MOV_PROVVIS).not_empty();
|
|
|
|
datareg = mov.get_date(MOV_DATAREG);
|
1995-03-02 14:55:20 +00:00
|
|
|
|
|
|
|
sal.reset();
|
1995-06-22 14:46:26 +00:00
|
|
|
sal.set_anno_es(_year);
|
1996-05-20 09:26:39 +00:00
|
|
|
sal.set_tipo_saldo(tsal);
|
1995-03-02 14:55:20 +00:00
|
|
|
sal.set_movprovv(provvis);
|
|
|
|
sal.set_data_ulmov(datareg);
|
|
|
|
sal.set_num_ulmov(oldnumreg);
|
1994-12-28 11:00:21 +00:00
|
|
|
}
|
|
|
|
const char sezione = rmov.get(RMV_SEZIONE)[0];
|
|
|
|
real importo(rmov.get(RMV_IMPORTO));
|
|
|
|
|
1996-05-20 09:26:39 +00:00
|
|
|
sal.aggiorna(gruppo, conto, sottoconto, importo, sezione, TRUE, scaricato);
|
1994-12-28 11:00:21 +00:00
|
|
|
}
|
|
|
|
rmov.next();
|
|
|
|
prnd.addstatus(1);
|
|
|
|
do_events();
|
|
|
|
}
|
1995-03-02 14:55:20 +00:00
|
|
|
|
1994-12-28 11:00:21 +00:00
|
|
|
if (sal.items() > 0)
|
|
|
|
sal.registra();
|
1995-03-02 14:55:20 +00:00
|
|
|
|
1994-12-28 11:00:21 +00:00
|
|
|
remove("__sal__.sav");
|
1995-05-10 09:26:37 +00:00
|
|
|
saldi.close();
|
1994-12-28 11:00:21 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int cg4100(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
CG4100_App main_app;
|
|
|
|
main_app.run(argc, argv, "Ricalcolo Saldi");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|