Aggiunta ricezione contabile
git-svn-id: svn://10.65.10.50/trunk@1164 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
2a4fdcc184
commit
6a9d1d2c3f
820
cg/cglib04.cpp
Executable file
820
cg/cglib04.cpp
Executable file
@ -0,0 +1,820 @@
|
||||
// cglib04.cpp
|
||||
|
||||
#include <utility.h>
|
||||
#include <progind.h>
|
||||
#include <stdlib.h>
|
||||
#include "cglib04.h"
|
||||
|
||||
HIDDEN TString80 TMP;
|
||||
|
||||
const int size = 256;
|
||||
|
||||
const char* tracciato = "trc.txt";
|
||||
|
||||
#if XVT_OS == XVT_OS_WIN
|
||||
#include <io.h>
|
||||
int fremove(const char* path)
|
||||
{ return _unlink(path); }
|
||||
#endif
|
||||
|
||||
//ritorna falso se la causale non e' significativa
|
||||
bool look_causale (const char* codcaus)
|
||||
{
|
||||
TString16 caus = codcaus;
|
||||
if (caus == "000")
|
||||
return FALSE;
|
||||
return !caus.blank();
|
||||
}
|
||||
|
||||
bool format_if_zero(TString& field, int len)
|
||||
{
|
||||
if (real::is_natural(field))
|
||||
field.right_just(len, '0');
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
TTransfer_file::TTransfer_file()
|
||||
{
|
||||
_trasfer = NULL;
|
||||
_tot_rec = 0L;
|
||||
_trc.leggi_modulo();
|
||||
}
|
||||
|
||||
TTransfer_file::~TTransfer_file()
|
||||
{
|
||||
if (_trasfer)
|
||||
fclose (_trasfer);
|
||||
}
|
||||
|
||||
void TTransfer_file::close()
|
||||
{
|
||||
if (_trasfer)
|
||||
fclose(_trasfer);
|
||||
}
|
||||
|
||||
bool TTransfer_file::open(const char* path)
|
||||
{
|
||||
if (_trasfer) fclose(_trasfer);
|
||||
|
||||
_trasfer = fopen (path, "r+t");
|
||||
return _trasfer != NULL;
|
||||
}
|
||||
|
||||
const char* TTransfer_file::path(long codditta)
|
||||
{
|
||||
if (codditta)
|
||||
return firm2dir(codditta);
|
||||
else
|
||||
return main_app().get_firm_dir();
|
||||
}
|
||||
|
||||
// Questa funzione ritorna:
|
||||
// - 0 se non vengono rilevate condizioni di ripartenza o di trasferimento
|
||||
// non completato.
|
||||
// - 1 se viene rilevato uno stato di RIPARTENZA CON DATI CONTRADDITORI
|
||||
// - 2 se viene rilevato un trasferimento precedente NON COMPLETATO
|
||||
|
||||
int TTransfer_file::controllo_ripartenza()
|
||||
{
|
||||
TString std;
|
||||
bool flag = FALSE;
|
||||
int var = 0;
|
||||
|
||||
TConfig conf(CONFIG_DITTA);
|
||||
|
||||
std = conf.get("FlStTra");
|
||||
|
||||
if (read_control_rec())
|
||||
flag = TRUE;
|
||||
|
||||
if (std == "" && flag)
|
||||
var = 1;
|
||||
|
||||
if (std == "*" && flag)
|
||||
if (_ult_file != "" || _key != "")
|
||||
var = 1;
|
||||
|
||||
if (std != "" && std != "*")
|
||||
var = 2;
|
||||
|
||||
return var;
|
||||
}
|
||||
|
||||
const char* converti (TString& data_AS400)
|
||||
{
|
||||
TMP = data_AS400.mid(4,2);
|
||||
TMP << "-" << data_AS400.mid(2,2);
|
||||
TMP << "-" << data_AS400.mid(0,2);
|
||||
return TMP;
|
||||
}
|
||||
|
||||
bool TTransfer_file::read_control_rec()
|
||||
{
|
||||
TString16 tmp;
|
||||
|
||||
if (!exist()) return FALSE;
|
||||
|
||||
// va all'inizio del file
|
||||
fseek (_trasfer, 0L, SEEK_SET);
|
||||
const word letti = fread((char*)(const char*)_control_rec,sizeof(char),size,_trasfer);
|
||||
|
||||
TString tiporec = _control_rec.sub(0,2);
|
||||
|
||||
if (tiporec == " 1")
|
||||
{
|
||||
_nultras = atoi(_control_rec.sub(29,32));
|
||||
tmp = _control_rec.sub(32,38);
|
||||
_dataultras = converti(tmp);
|
||||
|
||||
_sigle_file = _control_rec.sub(38,47);
|
||||
_nrec_file = _control_rec.sub(47,101);
|
||||
_ult_file = _control_rec.sub(240,241);
|
||||
_key = _control_rec.sub(241,256);
|
||||
fill_index(_sigle_file,_nrec_file);
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool TTransfer_file::write_control_rec(const char* str, const int size)
|
||||
{
|
||||
if (!exist()) return FALSE;
|
||||
|
||||
fseek(_trasfer, 0, SEEK_SET);
|
||||
const int nscritti = fwrite (str,1,size,_trasfer);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
const char* TTransfer_file::name(int i)
|
||||
{
|
||||
TToken_string data = (TToken_string&)_index[i];
|
||||
return data.get(0);
|
||||
}
|
||||
|
||||
long TTransfer_file::nrec(int i)
|
||||
{
|
||||
TToken_string data = (TToken_string&)_index[i];
|
||||
return data.get_long(1);
|
||||
}
|
||||
|
||||
int TTransfer_file::lenrec(int i)
|
||||
{
|
||||
TToken_string data = (TToken_string&)_index[i];
|
||||
return data.get_int(2);
|
||||
}
|
||||
|
||||
int TTransfer_file::lenrec(char sigla)
|
||||
{
|
||||
const int i = num(sigla);
|
||||
return lenrec(i);
|
||||
}
|
||||
|
||||
long TTransfer_file::start(char sigla)
|
||||
{
|
||||
const int i = num(sigla);
|
||||
return start(i);
|
||||
}
|
||||
|
||||
long TTransfer_file::start(int i)
|
||||
{
|
||||
if (i == 0)
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
TToken_string data = (TToken_string&)_index[i-1];
|
||||
return data.get_long(1) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
long TTransfer_file::end(int i)
|
||||
{
|
||||
TToken_string data = (TToken_string&)_index[i];
|
||||
return data.get_long(4);
|
||||
}
|
||||
|
||||
long TTransfer_file::rec(int i)
|
||||
{
|
||||
long rec = 1;
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
TToken_string data = (TToken_string&)_index[i-1];
|
||||
rec = (data.get_long(1)) + 1;
|
||||
}
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
int TTransfer_file::num(char sigla)
|
||||
{
|
||||
int items = _index.items();
|
||||
TString16 dep;
|
||||
|
||||
for (int i = 0; i < items; i++)
|
||||
{
|
||||
dep = name(i);
|
||||
if ( dep[0] == sigla)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void TTransfer_file::go2rec(const long recnum)
|
||||
{
|
||||
readat(recnum);
|
||||
}
|
||||
|
||||
void TTransfer_file::readat(long recnum)
|
||||
{
|
||||
long pos,offset;
|
||||
|
||||
// name_file | numrec | lenrec | start | end ESEMPIO
|
||||
// w | 100 | 82 | 0 | 8199 DI
|
||||
// p | 130 | 40 | 8200 | 9399 INDICE
|
||||
|
||||
int items = _index.items();
|
||||
|
||||
for (int i = 0;i < items;i++)
|
||||
{
|
||||
if (recnum <= nrec(i))
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
pos = end(i-1) + 1;
|
||||
offset = recnum - nrec(i-1);
|
||||
pos += offset * lenrec(i);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = recnum * lenrec(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
_curpos = recnum;
|
||||
_curfile = name(i);
|
||||
fseek(_trasfer,pos,SEEK_SET);
|
||||
}
|
||||
|
||||
int TTransfer_file::read_rec_trasfer(long numrec, int size)
|
||||
{
|
||||
go2rec(numrec);
|
||||
const word letti = fread((char*)(const char*)_record,sizeof(char),size,_trasfer);
|
||||
return letti;
|
||||
}
|
||||
|
||||
char TTransfer_file::flg_agg()
|
||||
{
|
||||
char flag;
|
||||
|
||||
char sigla = _record.sub(0,1)[0];
|
||||
|
||||
if (sigla == 'W')
|
||||
flag = _control_rec.sub(235,236)[0];
|
||||
|
||||
if (sigla == 'A')
|
||||
flag = _control_rec.sub(236,237)[0];
|
||||
|
||||
if (sigla == 'P')
|
||||
flag = _control_rec.sub(237,238)[0];
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
bool TTransfer_file::numprot_att()
|
||||
{
|
||||
char flag;
|
||||
|
||||
flag = _control_rec.sub(238,239)[0];
|
||||
if (flag == 'X')
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool TTransfer_file::numprot_pas()
|
||||
{
|
||||
char flag;
|
||||
|
||||
flag = _control_rec.sub(239,240)[0];
|
||||
if (flag == 'X')
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char TTransfer_file::flg_agg_IV()
|
||||
{
|
||||
char flag = ' ';
|
||||
|
||||
char sigla = _record.sub(0,1)[0];
|
||||
|
||||
if (sigla == 'P')
|
||||
flag = _control_rec.sub(234,235)[0];
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
void TTransfer_file::put(const char* val, const char* file, int fieldnum,long recnum)
|
||||
{
|
||||
int da = go2field(fieldnum,file,recnum,FALSE);
|
||||
_record.overwrite(val, da);
|
||||
}
|
||||
|
||||
int TTransfer_file::write(long numrec, int size)
|
||||
{
|
||||
go2rec(numrec);
|
||||
const word scritti = fwrite((char*)(const char*)_record,sizeof(char),size,_trasfer);
|
||||
return scritti;
|
||||
}
|
||||
|
||||
void TTransfer_file::writeat(const char* str,int size,int fieldnum,const char* file)
|
||||
{
|
||||
go2field(fieldnum,file);
|
||||
|
||||
const int nscritti = fwrite (str,1,size,_trasfer);
|
||||
}
|
||||
|
||||
void TTransfer_file::writeat(const char* str,int size,int fieldnum,const char* file, const long nrec)
|
||||
{
|
||||
go2field(fieldnum,file,nrec);
|
||||
|
||||
const int nscritti = fwrite (str,1,size,_trasfer);
|
||||
}
|
||||
|
||||
int TTransfer_file::go2field(int fieldnum, const char* file, const long nrec, bool seek)
|
||||
{
|
||||
TString key;
|
||||
int pos_campo;
|
||||
const int size = 256;
|
||||
|
||||
if (nrec < 0)
|
||||
readat(_curpos); // Mi posiziono all' inizio del record
|
||||
else
|
||||
readat(nrec);
|
||||
|
||||
if (!file)
|
||||
key.format("%2s%d",(const char*)_curfile,fieldnum);
|
||||
else
|
||||
key.format("%2s%d", file, fieldnum);
|
||||
|
||||
if (_trc.is_key((const char *) key))
|
||||
{
|
||||
TToken_string * data = (TToken_string *) _trc.objptr(key);
|
||||
|
||||
pos_campo = data->get_int(2);
|
||||
// NB
|
||||
// Nel tracciato parto da 1 (per compatibilita'),
|
||||
// la fseek() conta da 0
|
||||
pos_campo -= 1;
|
||||
|
||||
if (seek)
|
||||
{
|
||||
//pos_campo -= 1;
|
||||
fseek(_trasfer,pos_campo,SEEK_CUR);
|
||||
}
|
||||
}
|
||||
return pos_campo;
|
||||
}
|
||||
|
||||
void TTransfer_file::fill_index(TString& sigle_file,TString& nrec_file)
|
||||
{
|
||||
TToken_string data;
|
||||
char sigla;
|
||||
long nrec,nrecp,start,end;
|
||||
int i;
|
||||
int k = 0;
|
||||
int lrec = 256;
|
||||
|
||||
start = end = 0;
|
||||
|
||||
nrecp = 0L;
|
||||
|
||||
_index.destroy();
|
||||
|
||||
_last_tab = 0;
|
||||
_last_mov = 0;
|
||||
|
||||
for (i = 0; i < sigle_file.len(); i++)
|
||||
{
|
||||
data = "";
|
||||
sigla = sigle_file.mid(i,1)[0];
|
||||
nrec = atol(nrec_file.mid(k,6));
|
||||
|
||||
if (sigla == 'W' || sigla == 'P' || sigla == 'A')
|
||||
{
|
||||
_last_tab++;
|
||||
_last_mov++;
|
||||
}
|
||||
|
||||
if (sigla == 'Z' || sigla == 'U' || sigla == 'B')
|
||||
_last_mov++;
|
||||
|
||||
if (sigla != ' ' && nrec != 0)
|
||||
{
|
||||
data.add(sigla);
|
||||
data.add(nrec + nrecp);
|
||||
data.add(lrec);
|
||||
nrecp += nrec;
|
||||
|
||||
end = (nrecp * lrec) -1;
|
||||
data.add(start);
|
||||
data.add(end);
|
||||
start = end + 1;
|
||||
|
||||
_index.add(data);
|
||||
}
|
||||
k += 6;
|
||||
}
|
||||
|
||||
_tot_rec = nrecp;
|
||||
|
||||
}
|
||||
|
||||
void TTransfer_file::annulla_classi(int g, int c,bool conto)
|
||||
{
|
||||
TLocalisamfile pcon (LF_PCON);
|
||||
|
||||
pcon.setkey(1);
|
||||
pcon.zero();
|
||||
pcon.put("GRUPPO", g);
|
||||
pcon.put("CONTO", c);
|
||||
|
||||
for (pcon.read(); !pcon.eof(); pcon.next())
|
||||
{
|
||||
if (conto)
|
||||
{
|
||||
long sottoc = pcon.get_long("SOTTOCONTO");
|
||||
if (sottoc == 0) continue;
|
||||
}
|
||||
|
||||
int gruppo = pcon.get_int("GRUPPO");
|
||||
int conto = pcon.get_int("CONTO");
|
||||
|
||||
if (gruppo != g || conto != c) break;
|
||||
|
||||
pcon.zero("SEZIVD");
|
||||
pcon.zero("LETTIVD");
|
||||
pcon.zero("NUMRIVD");
|
||||
pcon.zero("NUMIVD");
|
||||
pcon.zero("SEZIVDOPP");
|
||||
pcon.zero("LETTIVDOPP");
|
||||
pcon.zero("NUMRIVDOPP");
|
||||
pcon.zero("NUMIVDOPP");
|
||||
|
||||
pcon.rewrite();
|
||||
}
|
||||
}
|
||||
|
||||
int TTransfer_file::dataes(const TDate& d, int* prevesc, TDate& finesp)
|
||||
{
|
||||
*prevesc = 0;
|
||||
|
||||
TTable esc("ESC");
|
||||
for (int err = esc.first(); err == NOERR; err = esc.next())
|
||||
{
|
||||
const TDate ia(esc.get("D0")); // Data inizio esercizio
|
||||
const TDate fa(esc.get("D1")); // Data fine esercizio
|
||||
const anno = esc.get_int("CODTAB");
|
||||
if (d >= ia && d <= fa)
|
||||
return anno;
|
||||
*prevesc = anno;
|
||||
finesp = fa;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TTransfer_file::write_tmp_mov(TIsamtempfile& tmp_mov, TIsamtempfile& tmp_rmov, const TString& buffer,const int nprog_mov)
|
||||
{
|
||||
TString16 datareg = buffer.sub(15,21);
|
||||
long numreg = atol(buffer.sub(2,8));
|
||||
int numrig = atoi(buffer.sub(8,10));
|
||||
char sezione = buffer.sub(84,85)[0];
|
||||
TString16 importo = buffer.sub(97,108);
|
||||
int gruppo = atoi(buffer.sub(74,76));
|
||||
int conto = atoi(buffer.sub(76,78));
|
||||
long sconto = atol(buffer.sub(78,84));
|
||||
int gruppoc = atoi(buffer.sub(85,87));
|
||||
int contoc = atoi(buffer.sub(87,89));
|
||||
long scontoc = atol(buffer.sub(89,95));
|
||||
TString16 datadoc = buffer.sub(22,28);
|
||||
TString16 numdoc = buffer.sub(28,35);
|
||||
TString16 codcaus = buffer.sub(41,44);
|
||||
TString80 descr = buffer.sub(44,74);
|
||||
TString16 reg = buffer.sub(35,36);
|
||||
//format_if_zero(reg, 3);
|
||||
format_if_zero(codcaus, 3);
|
||||
long protiva = atol(buffer.sub(36,41));
|
||||
long nuprotiva = atol(buffer.sub(108,113));
|
||||
TString16 codpag = buffer.sub(95,97);
|
||||
|
||||
TDate datar(converti(datareg));
|
||||
TDate datad(converti(datadoc));
|
||||
|
||||
int pr;
|
||||
TDate df;
|
||||
const int ar = dataes(datar, &pr, df);
|
||||
int sign = atoi(buffer.sub(21,22));
|
||||
TString16 tipodoc = buffer.sub(220,222);
|
||||
|
||||
tmp_mov.zero();
|
||||
|
||||
TString16 anno;
|
||||
if (sign)
|
||||
{
|
||||
anno.format("%04d", pr);
|
||||
tmp_mov.put(MOV_ANNOES, anno);
|
||||
tmp_mov.put(MOV_DATACOMP, df);
|
||||
}
|
||||
else
|
||||
{
|
||||
anno.format("%04d", ar);
|
||||
tmp_mov.put(MOV_ANNOES, anno);
|
||||
tmp_mov.put(MOV_DATACOMP, datar);
|
||||
}
|
||||
|
||||
// Scrivo testata
|
||||
tmp_mov.put(MOV_DATAREG, datar);
|
||||
tmp_mov.put(MOV_NUMREG, numreg);
|
||||
tmp_mov.put(MOV_DATADOC, datad);
|
||||
tmp_mov.put(MOV_NUMDOC, numdoc);
|
||||
tmp_mov.put(MOV_CODCAUS, codcaus);
|
||||
tmp_mov.put(MOV_REG, reg);
|
||||
tmp_mov.put(MOV_PROTIVA, protiva);
|
||||
tmp_mov.put(MOV_UPROTIVA, nuprotiva);
|
||||
tmp_mov.put(MOV_TIPODOC, tipodoc);
|
||||
tmp_mov.put(MOV_CODPAG, codpag);
|
||||
|
||||
// Scrivo numero progressivo del transfer
|
||||
tmp_mov.put(MOV_NUMGIO, (long)nprog_mov);
|
||||
|
||||
tmp_mov.write();
|
||||
|
||||
tmp_rmov.zero();
|
||||
// Scrivo riga
|
||||
tmp_rmov.put(RMV_NUMREG, numreg);
|
||||
tmp_rmov.put(RMV_NUMRIG, numrig);
|
||||
tmp_rmov.put(RMV_SEZIONE,sezione);
|
||||
tmp_rmov.put(RMV_DATAREG,datar);
|
||||
tmp_rmov.put(RMV_GRUPPO, gruppo);
|
||||
tmp_rmov.put(RMV_CONTO, conto);
|
||||
tmp_rmov.put(RMV_SOTTOCONTO, sconto);
|
||||
tmp_rmov.put(RMV_GRUPPOC, gruppoc);
|
||||
tmp_rmov.put(RMV_CONTOC, contoc);
|
||||
tmp_rmov.put(RMV_SOTTOCONTOC, scontoc);
|
||||
tmp_rmov.put(RMV_DESCR, descr);
|
||||
tmp_rmov.put(RMV_IMPORTO,importo);
|
||||
|
||||
// Scrivo numero progressivo del transfer
|
||||
tmp_rmov.put(RMV_ANNOES, nprog_mov);
|
||||
|
||||
tmp_rmov.write();
|
||||
}
|
||||
|
||||
//
|
||||
// NB
|
||||
// Utilizza ANNO_IVA per metterci il numero progressivo sul transfer
|
||||
//
|
||||
void TTransfer_file::scrivi_nprog_testata(long numreg, long nprog_iva, TIsamtempfile& mov)
|
||||
{
|
||||
mov.zero();
|
||||
mov.put("NUMREG", numreg);
|
||||
if (mov.read() == NOERR)
|
||||
{
|
||||
mov.put(MOV_ANNOIVA, (long)nprog_iva);
|
||||
mov.rewrite();
|
||||
}
|
||||
}
|
||||
|
||||
void TTransfer_file::look_mov(long numreg, const char* d, long cf, TIsamtempfile& mov)
|
||||
{
|
||||
mov.zero();
|
||||
mov.put("NUMREG", numreg);
|
||||
if (mov.read() == NOERR)
|
||||
{
|
||||
mov.put(MOV_DATA74TER, d);
|
||||
mov.put(MOV_CODCF, cf);
|
||||
mov.rewrite();
|
||||
}
|
||||
}
|
||||
|
||||
void TTransfer_file::write_tmp_rmoviva(TIsamtempfile& tmp_rmoviva, TIsamtempfile& tmp_mov, const TString& buffer, const int nprog_iva)
|
||||
{
|
||||
static long numreg = -1L;
|
||||
long numreg_curr = 0L;
|
||||
|
||||
TString16 datareg = buffer.sub(15,21);
|
||||
numreg_curr = atol(buffer.sub(2,8));
|
||||
|
||||
const char* data74 = buffer.sub(55,61);
|
||||
long codcf = atol(buffer.sub(15,21));
|
||||
|
||||
if (numreg < 0L)
|
||||
{
|
||||
if (numreg_curr > 0L)
|
||||
{
|
||||
numreg = numreg_curr;
|
||||
scrivi_nprog_testata(numreg, nprog_iva, tmp_mov);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (numreg_curr != numreg)
|
||||
{
|
||||
numreg = numreg_curr;
|
||||
scrivi_nprog_testata(numreg, nprog_iva, tmp_mov);
|
||||
}
|
||||
|
||||
look_mov(numreg, data74, codcf, tmp_mov);
|
||||
|
||||
int numrig = atoi(buffer.sub(8,10));
|
||||
TString16 codiva = buffer.sub(32,34);
|
||||
TString16 impo = buffer.sub(21,32);
|
||||
TString16 impos = buffer.sub(34,43);
|
||||
int tipocr = atoi(buffer.sub(43,44));
|
||||
int tipodet = atoi(buffer.sub(44,45));
|
||||
int gruppo = atoi(buffer.sub(45,47));
|
||||
int conto = atoi(buffer.sub(47,49));
|
||||
long sottoconto = atol(buffer.sub(49,55));
|
||||
int tipoatt = atoi(buffer.sub(133,134));
|
||||
|
||||
tmp_rmoviva.zero();
|
||||
tmp_rmoviva.put(RMI_NUMREG, numreg);
|
||||
tmp_rmoviva.put(RMI_NUMRIG, numrig);
|
||||
tmp_rmoviva.put(RMI_CODIVA, codiva);
|
||||
tmp_rmoviva.put(RMI_IMPONIBILE, impo);
|
||||
tmp_rmoviva.put(RMI_IMPOSTA, impos);
|
||||
tmp_rmoviva.put(RMI_TIPOCR, tipocr);
|
||||
tmp_rmoviva.put(RMI_TIPODET, tipodet);
|
||||
tmp_rmoviva.put(RMI_TIPOATT, tipoatt);
|
||||
tmp_rmoviva.put(RMI_GRUPPO, gruppo);
|
||||
tmp_rmoviva.put(RMI_CONTO, conto);
|
||||
tmp_rmoviva.put(RMI_SOTTOCONTO, sottoconto);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Scrivo il numero di record del transfer
|
||||
// per aggiornare il transfer nella lista movimenti
|
||||
//
|
||||
tmp_rmoviva.put(RMI_ANNOES, (long)nprog_iva);
|
||||
|
||||
tmp_rmoviva.write();
|
||||
}
|
||||
|
||||
//oltre a fare una copia del trasfer scarica su tre file temp i movimenti di prima nota, ecc.
|
||||
bool TTransfer_file::fcopytemp(const char* orig, const char* dest, bool append)
|
||||
{
|
||||
// conto i dischetti per l'apertura
|
||||
static int disk_num = 0;
|
||||
long totr = 0L;
|
||||
const char* wflag;
|
||||
#if XVT_OS == XVT_OS_SCOUNIX
|
||||
const char* const rflag = "r";
|
||||
if (append)
|
||||
wflag = "a";
|
||||
else
|
||||
wflag = "w";
|
||||
#else
|
||||
const char* const rflag = "rb";
|
||||
if (append)
|
||||
wflag = "ab";
|
||||
else
|
||||
wflag = "wb";
|
||||
#endif
|
||||
|
||||
// Legge numero di rec. del transfer (per la progind)
|
||||
open(orig);
|
||||
if (read_control_rec())
|
||||
totr = tot_rec();
|
||||
close();
|
||||
|
||||
FILE* i = fopen(orig, rflag);
|
||||
if (!i) return error_box("Impossibile leggere il file %s", orig);
|
||||
|
||||
FILE* o = fopen(dest, wflag);
|
||||
CHECKS(o, "Impossibile scrivere il file ", dest);
|
||||
|
||||
const word size = 256;
|
||||
TString buffer(size);
|
||||
TString16 trec;
|
||||
|
||||
TString80 tmpmov = "%";
|
||||
tmpmov << path();
|
||||
tmpmov << "\\" << TEMP_MOV;
|
||||
TString80 tmprmov = "%";
|
||||
tmprmov << path();
|
||||
tmprmov << "\\" << TEMP_RMOV;
|
||||
TString80 tmprmoviva = "%";
|
||||
tmprmoviva << path();
|
||||
tmprmoviva << "\\" << TEMP_RMOVIVA;
|
||||
|
||||
TIsamtempfile tmp_mov (LF_MOV, tmpmov, disk_num ? FALSE : TRUE);
|
||||
TIsamtempfile tmp_rmov(LF_RMOV, tmprmov, disk_num ? FALSE : TRUE);
|
||||
TIsamtempfile tmp_rmoviva(LF_RMOVIVA, tmprmoviva, disk_num ? FALSE : TRUE);
|
||||
|
||||
disk_num++;
|
||||
|
||||
// Numero le righe iva
|
||||
int nprog_iva = 0;
|
||||
// e le testate
|
||||
int nprog_mov = 0;
|
||||
|
||||
bool ok = TRUE;
|
||||
long offset = 0L;
|
||||
|
||||
TProgind pnd (totr,"Trasferimento archivi in corso\nPrego attendere",
|
||||
FALSE, TRUE, 30);
|
||||
|
||||
while (ok)
|
||||
{
|
||||
const word letti = fread((char*)(const char*)buffer, 1, size, i);
|
||||
|
||||
trec = buffer.sub(0,2);
|
||||
|
||||
if (trec == "Z1") //movimento di prima nota
|
||||
{
|
||||
write_tmp_mov(tmp_mov, tmp_rmov, buffer, nprog_mov);
|
||||
nprog_mov++;
|
||||
}
|
||||
|
||||
// Righe iva
|
||||
if (trec == "U1")
|
||||
{
|
||||
write_tmp_rmoviva(tmp_rmoviva, tmp_mov, buffer, nprog_iva);
|
||||
nprog_iva++;
|
||||
}
|
||||
|
||||
ok = fwrite((char*)(const char*)buffer, 1, letti, o) == letti;
|
||||
|
||||
pnd.addstatus (1);
|
||||
|
||||
if (letti < size) break;
|
||||
}
|
||||
if (!ok) error_box("Errore di scrittura: probabile disco pieno!");
|
||||
|
||||
fclose(o);
|
||||
fclose(i);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Mappa dei campi da trasferire
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
void TMappa_trc::leggi_modulo()
|
||||
{
|
||||
TScanner s(tracciato);
|
||||
TString16 key;
|
||||
TToken_string record;
|
||||
|
||||
while (s.ok())
|
||||
{
|
||||
record = s.line();
|
||||
|
||||
TString sigla = record.get(0);
|
||||
long numrec = record.get_long(1);
|
||||
key.format("%2s%d", (const char*)sigla,numrec);
|
||||
|
||||
add(key, record);
|
||||
}
|
||||
long item = items();
|
||||
}
|
||||
|
||||
int TMappa_trc::from(const char* key)
|
||||
{
|
||||
TToken_string * data = (TToken_string *) objptr(key);
|
||||
return data->get_int(2);
|
||||
}
|
||||
|
||||
int TMappa_trc::to(const char* key)
|
||||
{
|
||||
TToken_string * data = (TToken_string *) objptr(key);
|
||||
return data->get_int(3);
|
||||
}
|
||||
|
||||
int TMappa_trc::logicnum(const char* key)
|
||||
{
|
||||
TToken_string * data = (TToken_string *) objptr(key);
|
||||
return data->get_int(4);
|
||||
}
|
||||
|
||||
const char* TMappa_trc::field_name(const char* key)
|
||||
{
|
||||
TToken_string * data = (TToken_string *) objptr(key);
|
||||
return data->get(5);
|
||||
}
|
||||
|
||||
int TMappa_trc::flag(const char* key)
|
||||
{
|
||||
TToken_string * data = (TToken_string *) objptr(key);
|
||||
return data->get_int(6);
|
||||
}
|
157
cg/cglib04.h
Executable file
157
cg/cglib04.h
Executable file
@ -0,0 +1,157 @@
|
||||
// cglib04.h
|
||||
|
||||
#include <applicat.h>
|
||||
#include <config.h>
|
||||
#include <prefix.h>
|
||||
#include <isam.h>
|
||||
#include <stdio.h>
|
||||
#include <array.h>
|
||||
#include <assoc.h>
|
||||
#include <strings.h>
|
||||
#include <scanner.h>
|
||||
#include <tabutil.h>
|
||||
#include <mov.h>
|
||||
#include <rmov.h>
|
||||
#include <rmoviva.h>
|
||||
|
||||
#define TEMP_MOV "tmov"
|
||||
#define TEMP_RMOV "trmov"
|
||||
#define TEMP_RMOVIVA "triva"
|
||||
|
||||
#define SIZE 256
|
||||
|
||||
// Tracciato del record di controllo
|
||||
HIDDEN int pos[15] = {0,15,25,29,32,38,47,234,235,236,237,238,239,240,241};
|
||||
|
||||
const char* converti(TString& data);
|
||||
int fremove(const char* path);
|
||||
bool look_causale(const char* codcaus);
|
||||
bool format_if_zero(TString&, int);
|
||||
|
||||
class TMappa_trc : public TAssoc_array
|
||||
{
|
||||
public :
|
||||
void leggi_modulo();
|
||||
|
||||
int from (const char* key);
|
||||
int to (const char* key);
|
||||
int logicnum (const char* key);
|
||||
const char* field_name (const char* key);
|
||||
int flag (const char* key);
|
||||
|
||||
TMappa_trc() {};
|
||||
};
|
||||
|
||||
class TTransfer_file
|
||||
{
|
||||
FILE* _trasfer;
|
||||
TArray _index;
|
||||
// TAssoc_array _fis_index;
|
||||
TMappa_trc _trc;
|
||||
TString _curfile;
|
||||
TString256 _control_rec; // Buffer per il record di controllo
|
||||
TString256 _record; // Buffer per il record corrente
|
||||
|
||||
long _curpos;
|
||||
long _tot_rec; // Numero totale di record nel transfer
|
||||
int _nultras; // Numero ultimo trasferimento
|
||||
int _last_tab,_last_mov;
|
||||
|
||||
TString16 _dataultras;
|
||||
TString16 _sigle_file;
|
||||
TString _nrec_file;
|
||||
TString _ult_file;
|
||||
TString _key;
|
||||
|
||||
private:
|
||||
// Inizializza l'indice leggendo il record di controllo
|
||||
void fill_index(TString&,TString&);
|
||||
|
||||
// Funzioni utilizzate da fcopytemp()
|
||||
void scrivi_nprog_testata(long numreg, long nprog_iva, TIsamtempfile& mov);
|
||||
void look_mov(long nr, const char* data74, long cf, TIsamtempfile& mov);
|
||||
void write_tmp_mov(TIsamtempfile& mov, TIsamtempfile& rmov,
|
||||
const TString& rec, const int nprog_mov);
|
||||
int dataes(const TDate&, int*, TDate&);
|
||||
void write_tmp_rmoviva(TIsamtempfile& rmov_iva, TIsamtempfile& mov,
|
||||
const TString& rec, const int nprog_iva);
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public:
|
||||
|
||||
const char* path (long codditta = 0);
|
||||
bool open (const char* path);
|
||||
void close ();
|
||||
bool exist() const { return _trasfer != NULL; }
|
||||
|
||||
long get_pos(const char* key);
|
||||
|
||||
// Funzioni che agiscono sul record di controllo del file trasfer.
|
||||
|
||||
bool read_control_rec(); // Legge il record
|
||||
bool write_control_rec(const char* str, const int size); // Scrive una stringa di lunghezza size
|
||||
|
||||
int nultras () const { return _nultras; } // Ritorna il numero ultimo trasferimento
|
||||
const char* dataultras() const { return (const char*) _dataultras; } // Ritorna la data ultimo trasferimento
|
||||
const char* sigle_file() const { return (const char*) _sigle_file; } // Ritorna una stringa contenente le sigle dei file da ricevere
|
||||
const char* nrec_file () const { return (const char*) _nrec_file; } // Ritorna una stringa con il numero totale di record corrispondenti ad ogni sigla dei file da ricevere
|
||||
char flg_agg(); // Ritorna i flag tipo aggiornamento relativi alle tabelle
|
||||
bool numprot_att(); // Ritorna il flag riattribuzione numero protocollo su fatture attive
|
||||
bool numprot_pas(); // Ritorna il flag riattribuzione numero protocollo su fatture passive
|
||||
char flg_agg_IV(); // Ritorna il flag tipo aggiornamento classi piano dei conti
|
||||
const char* ult_file () const { return (const char*) _ult_file; } // Ritorna l'ultima sigla file elaborato
|
||||
const char* key () const { return (const char*) _key; } // Ritorna la chiave ultimo record elaborato
|
||||
const char* record () const { return (const char*) _control_rec; } // Ritorna il record di controllo del trasfer
|
||||
|
||||
// Funzioni per il posizionamento e la gestione dei record del trasfer (escluso il record di controllo)
|
||||
|
||||
// Legge il record del trasfer specificato da numrec
|
||||
int read_rec_trasfer(long numrec, int size=256);
|
||||
const char* read_rec () const { return (const char*) _record; } // Ritorna un record del trasfer
|
||||
|
||||
// Scrive una stringa di lunghezza size nel campo specificato da fieldnum
|
||||
void writeat(const char* str,int size,int fieldnum,const char* file);
|
||||
void writeat(const char* str,int size,int fieldnum,
|
||||
const char* file, const long numrec);
|
||||
|
||||
int write(long numrec, int size=SIZE);
|
||||
|
||||
// Permette di posizionarsi all'interno del record sul campo specificato
|
||||
// da fieldnum sfruttando la Mappa precaricata
|
||||
int go2field(int fieldnum, const char* file=NULL,
|
||||
const long nrec=-1L, bool seek=TRUE);
|
||||
void go2rec (const long numrec);
|
||||
void readat(long recnum); // Si posiziona all'inizio del record specificato da numrec sfruttando l'array indice
|
||||
|
||||
void put(const char* val, const char* file, int fieldnum,long recnum=-1L);
|
||||
|
||||
int controllo_ripartenza();
|
||||
|
||||
// Funzioni per la gestione dell'array indice
|
||||
int last_tab() const { return _last_tab; } // Ritorna la posizione dell'ultima sigla relativa alle tabelle presente nella schiera delle sigle file
|
||||
int last_mov() const { return _last_mov; } // Ritorna la posizione dell'ultima sigla relativa ai movimenti presente nella schiera delle sigle file
|
||||
|
||||
int num(char sigla);
|
||||
const char* name(int i); // Ritorna la sigla di quel file
|
||||
long nrec(int i); // Ritorna il numero di record di quel file
|
||||
int lenrec(int i); // Ritorna la lunghezza del record del trasfer corrispondente a quel file
|
||||
int lenrec(char sigla); // Ritorna la stessa cosa ma con la sigla invece del numero
|
||||
long start(int i); // Inizio del file numero i
|
||||
long start(char sigla); // Inizio del file sigla
|
||||
long end(int i); // Ritorna la posizione in byte corrispondente alla fine di quel file all'interno del trasfer
|
||||
long rec(int i);
|
||||
|
||||
long tot_rec() const { return _tot_rec; }
|
||||
|
||||
void annulla_classi(int g, int c,bool conto);
|
||||
|
||||
// Copia il file trasfer creando tre isam_temp_file per i mov. di prima nota
|
||||
bool fcopytemp (const char*, const char*, bool);
|
||||
|
||||
TMappa_trc& mappa() {return _trc; }
|
||||
|
||||
TTransfer_file();
|
||||
~TTransfer_file();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user