Files correlati : cg7.exe cg7300a.msk sispac.ini Ricompilazione Demo : [ ] Commento : Aggiunto programma di invio a Sispac per Ruffo git-svn-id: svn://10.65.10.50/trunk@14650 c028cbd2-c16b-5b4b-a496-9718f37d4682
492 lines
12 KiB
C++
Executable File
492 lines
12 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <assoc.h>
|
||
#include <automask.h>
|
||
#include <currency.h>
|
||
#include <filetext.h>
|
||
#include <msksheet.h>
|
||
#include <printer.h>
|
||
#include <recarray.h>
|
||
#include <relation.h>
|
||
#include <sort.h>
|
||
#include <utility.h>
|
||
|
||
#include "cg7.h"
|
||
#include "cg7300a.h"
|
||
|
||
#include <clifo.h>
|
||
#include <mov.h>
|
||
#include <rmov.h>
|
||
#include <rmoviva.h>
|
||
|
||
#define ALIAS_REG 100
|
||
|
||
class TInvioS_file: public TFile_text
|
||
{
|
||
protected:
|
||
virtual void validate(TCursor& cur,TRecord_text &rec, TToken_string &val, TString& str);
|
||
|
||
public:
|
||
TInvioS_file(const TString& file_name);
|
||
virtual ~TInvioS_file() { }
|
||
};
|
||
|
||
TInvioS_file::TInvioS_file(const TString& file_name)
|
||
: TFile_text(file_name, "sispac.ini")
|
||
{
|
||
}
|
||
|
||
class TInvioS_mask : public TAutomask
|
||
{
|
||
protected:
|
||
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
public:
|
||
|
||
TInvioS_mask();
|
||
|
||
virtual ~TInvioS_mask(){};
|
||
};
|
||
|
||
TInvioS_mask::TInvioS_mask() :TAutomask ("cg7300a")
|
||
{
|
||
}
|
||
|
||
bool TInvioS_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case F_CODDITTA:
|
||
if (e==fe_init && o.empty())
|
||
{
|
||
set(F_CODDITTA, main_app().get_firm());
|
||
((TEdit_field&) o).check();
|
||
disable(F_CODDITTA);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
class TInvioS : public TSkeleton_application
|
||
{
|
||
TCursor* _cur;
|
||
TInvioS_mask* _msk;
|
||
TInvioS_file* _trasfile;
|
||
long _nrecords, _nrecsfattvend, _nrecsfattacqu, _nrecsmocontab;
|
||
int _nfiles;
|
||
long _nrecsdettaglio;
|
||
TString16 _descrdettaglio;
|
||
TDate _dataini, _datafin;
|
||
bool _totale, _finemov;
|
||
|
||
protected:
|
||
virtual bool create(void);
|
||
virtual bool destroy(void);
|
||
virtual void main_loop() ;
|
||
void invio_sispac();
|
||
long i_sispac_clifor(const bool invio = TRUE);
|
||
long i_sispac_movcont(const bool invio = TRUE);
|
||
long i_sispac_moviva(const bool invio = TRUE);
|
||
public:
|
||
int get_nfiles() {return _nfiles;};
|
||
long get_nrecords() {return _nrecords;};
|
||
long get_nrecsdettaglio() {return _nrecsdettaglio;};
|
||
TString16& get_descrdettaglio() {return _descrdettaglio;};
|
||
const bool totale() {return _totale;};
|
||
const bool finemov() {return _finemov;};
|
||
TInvioS_file* apri_file(const char* nome);
|
||
void chiudi_file(TInvioS_file* trasfile);
|
||
TInvioS() {} ;
|
||
virtual ~TInvioS() {} ;
|
||
};
|
||
|
||
// restituisce un riferimento all' applicazione
|
||
inline TInvioS& app() { return (TInvioS&) main_app();}
|
||
|
||
// gestione dei messaggi estesi nei campi
|
||
void TInvioS_file::validate(TCursor& cur,TRecord_text &rec, TToken_string &s, TString& str)
|
||
{
|
||
const TString code(s.get(0));
|
||
TString valore;
|
||
if (code == "_FISSO")
|
||
{
|
||
// gestione dei campi fissi per i record delle riba
|
||
// sintassi: _FISSO,!<valore>
|
||
// dove: <valore> <20> la stringa fissa da emettere
|
||
TString in(s.get());
|
||
CHECK(in[0]=='!',"Macro _FISSO senza carattere '!'");
|
||
in.ltrim(1);
|
||
in.trim();
|
||
valore = in;
|
||
}
|
||
else if (code == "_ANNO")
|
||
{
|
||
TDate data(str);
|
||
int anno = data.year();
|
||
valore.format("%ld", anno);
|
||
}
|
||
else if (code == "_MESE")
|
||
{
|
||
TDate data(str);
|
||
int mese = data.month();
|
||
valore.format("%ld", mese);
|
||
}
|
||
else if (code == "_SEZIONE")
|
||
{
|
||
valore = str;
|
||
const char sezione = s.get()[0];
|
||
const char sezriga = cur.curr(LF_RMOV).get_char(RMV_SEZIONE);
|
||
if (sezione != sezriga)
|
||
valore = "";
|
||
}
|
||
else if (code == "_CAUSALE")
|
||
{
|
||
TFilename configname = "cg7300a.ini";
|
||
TConfig configfile(configname);
|
||
TToken_string causali = configfile.get("STANDARD", "CAUSALI");
|
||
const char sezione = cur.curr(LF_RMOV).get_char(RMV_SEZIONE);
|
||
if (sezione == 'D')
|
||
valore = causali.get(0);
|
||
else
|
||
valore = causali.get(1);
|
||
}
|
||
else if (code == "_NUMFILES")
|
||
{
|
||
const int nfiles = app().get_nfiles();
|
||
valore.format("%ld", nfiles);
|
||
}
|
||
else if (code == "_NUMRECORDS")
|
||
{
|
||
const long nrecords = app().get_nrecords();
|
||
valore.format("%ld", nrecords);
|
||
}
|
||
else if (code == "_NUMRECORDSDETTAGLIO")
|
||
{
|
||
const long nrecords = app().get_nrecsdettaglio();
|
||
valore.format("%ld", nrecords);
|
||
}
|
||
else if (code == "_TIPOFILE")
|
||
{
|
||
valore = app().get_descrdettaglio();
|
||
}
|
||
else if (code == "_OPZIONI")
|
||
{
|
||
TString in(s.get());
|
||
TFilename configname = "cg7300a.ini";
|
||
TConfig configfile(configname);
|
||
valore = configfile.get(in, "OPZIONI");
|
||
}
|
||
else if (code == "_OGGI")
|
||
{
|
||
TDate data(TODAY);
|
||
valore = data.string(full, '-', full, full, amg_date);
|
||
valore.strip("-");
|
||
}
|
||
else if (code == "_CODIFICA")
|
||
{
|
||
const char tipocf = str[0];
|
||
if (tipocf == 'C')
|
||
valore = "P";
|
||
else
|
||
valore = "R";
|
||
}
|
||
else if (code == "_NUMDOC")
|
||
{
|
||
if (cur.file("REG").get("I0") == 1)
|
||
valore = cur.curr().get(MOV_NUMDOC);
|
||
else
|
||
valore = cur.curr().get(MOV_PROTIVA);
|
||
}
|
||
else if (code == "_SEGNO")
|
||
{
|
||
TString archivio(s.get());
|
||
TString campo(s.get());
|
||
const real importo = cur.curr(archivio).get_real(campo);
|
||
valore = "+";
|
||
if (importo < 0)
|
||
valore = "-";
|
||
}
|
||
else if (code == "_IMPORTO")
|
||
{
|
||
real importo(str);
|
||
valore = importo.string(0,2);
|
||
valore.strip("-");
|
||
valore.strip("+");
|
||
valore.strip(".");
|
||
}
|
||
else if (code == "_TIPODOC")
|
||
{
|
||
const char tipodoc = str[0];
|
||
valore = (tipodoc == 'F') ? "1" : "2";
|
||
}
|
||
else if (code == "_DIVERSI")
|
||
{
|
||
valore = (app().finemov() ? "X" : " ");
|
||
}
|
||
else if (code == "_TOTALE")
|
||
{
|
||
real importo(ZERO);
|
||
if (app().totale())
|
||
{
|
||
importo = cur.curr(LF_MOV).get_real(MOV_TOTDOC);
|
||
importo+=cur.curr(LF_MOV).get_real(MOV_RITFIS);
|
||
}
|
||
valore = importo.string(11,2);
|
||
valore.strip("-");
|
||
valore.strip("+");
|
||
valore.strip(".");
|
||
}
|
||
else if (code == "_SEGNOTOTALE")
|
||
{
|
||
real importo(ZERO);
|
||
if (app().totale())
|
||
{
|
||
importo = cur.curr(LF_MOV).get_real(MOV_TOTDOC);
|
||
importo+=cur.curr(LF_MOV).get_real(MOV_RITFIS);
|
||
}
|
||
valore = importo.string(11,2);
|
||
valore.trim();
|
||
valore = valore.sub(0,1);
|
||
if (valore[0] != '-' && valore[0] != '+')
|
||
valore = "+";
|
||
}
|
||
else if (code == "_INDIR")
|
||
{
|
||
valore = cur.curr(LF_CLIFO).get(CLI_INDCF);
|
||
valore << ' ' << cur.curr(LF_CLIFO).get(CLI_CIVCF);
|
||
valore.cut(40);
|
||
}
|
||
else if (code == "_GIUFIS")
|
||
{
|
||
const char tipopers = cur.curr(LF_CLIFO).get_char(CLI_TIPOPERS);
|
||
valore = (tipopers == 'F') ? "S" : "N";
|
||
}
|
||
else if (code == "_CONTO")
|
||
{
|
||
int gruppo = cur.curr(LF_CLIFO).get_int(CLI_GRUPPO);
|
||
int conto = cur.curr(LF_CLIFO).get_int(CLI_CONTO);
|
||
long codice = cur.curr(LF_CLIFO).get_int(CLI_CODCF);
|
||
valore.format("%03d%03d%06ld", gruppo, conto, codice);
|
||
}
|
||
else if (code == "_BLACKLIST")
|
||
{
|
||
const bool sospeso = cur.curr(LF_CLIFO).get_bool(CLI_SOSPESO);
|
||
valore = (sospeso == true) ? "S" : " ";
|
||
}
|
||
else NFCHECK("Macro non definita: %s", (const char *)code);
|
||
str = valore;
|
||
}
|
||
|
||
TInvioS_file* TInvioS::apri_file(const char* nome)
|
||
{
|
||
TFilename filename = _msk->get(F_DESTINAZIONE);
|
||
filename.add(nome);
|
||
filename.ext("txt");
|
||
if (filename.exist())
|
||
remove(filename);
|
||
|
||
TInvioS_file* trasfile = new TInvioS_file(filename);
|
||
trasfile->open(filename,'w');
|
||
trasfile->force_record_separator();
|
||
return trasfile;
|
||
}
|
||
|
||
void TInvioS::chiudi_file(TInvioS_file* trasfile)
|
||
{
|
||
trasfile->close();
|
||
delete trasfile;
|
||
}
|
||
|
||
long TInvioS::i_sispac_movcont(const bool invio)
|
||
{
|
||
TRectype da(LF_MOV);
|
||
TRectype a(LF_MOV);
|
||
da.put(MOV_DATAREG, _dataini);
|
||
a.put(MOV_DATAREG, _datafin);
|
||
TRelation rel(LF_MOV);
|
||
rel.add(LF_RMOV, "NUMREG==NUMREG", 1);
|
||
//TCursor cur(&rel, "23->PROTIVA == \"\"", 2, &da, &a);
|
||
TCursor cur(&rel, "", 2, &da, &a);
|
||
|
||
const long cur_items = cur.items();
|
||
if (cur_items != 0)
|
||
{
|
||
cur.freeze();
|
||
TRectype& cur_rec = cur.curr();
|
||
for (cur = 0; cur.pos() < cur_items; ++(cur))
|
||
{
|
||
const long numreg = cur.curr().get_long(MOV_NUMREG);
|
||
bool continua = TRUE;
|
||
while (continua)
|
||
{
|
||
const long numregrig = cur.curr(LF_RMOV).get_long(RMV_NUMREG);
|
||
if (numreg == numregrig)
|
||
{
|
||
if (invio)
|
||
{
|
||
TRectype& cur_rec_righe = cur.curr(LF_RMOV);
|
||
TRecord_text recrighe;
|
||
recrighe.set_type("R");
|
||
cur.save_status();
|
||
_finemov = !(cur.next_match(LF_RMOV, "NUMREG"));
|
||
cur.restore_status();
|
||
_trasfile->autoload(recrighe, cur);
|
||
_trasfile->write(recrighe);
|
||
}
|
||
}
|
||
continua = cur.next_match(LF_RMOV, "NUMREG");
|
||
}
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
|
||
long TInvioS::i_sispac_moviva(const bool invio)
|
||
{
|
||
TRectype da(LF_MOV);
|
||
TRectype a(LF_MOV);
|
||
da.put(MOV_DATAREG, _dataini);
|
||
a.put(MOV_DATAREG, _datafin);
|
||
TRelation rel(LF_MOV);
|
||
rel.add(LF_RMOVIVA, "NUMREG==NUMREG", 1);
|
||
rel.add("REG", "CODTAB[1,4]==ANNOIVA|CODTAB[5,7]==REG", 1);
|
||
TCursor cur(&rel, "", 2, &da, &a);
|
||
const long cur_items = cur.items();
|
||
if (cur_items != 0)
|
||
|
||
{
|
||
cur.freeze();
|
||
TRectype& cur_rec = cur.curr();
|
||
for (cur = 0; cur.pos() < cur_items; ++(cur))
|
||
{
|
||
const long numreg = cur.curr().get_long(MOV_NUMREG);
|
||
bool continua = TRUE;
|
||
while (continua)
|
||
{
|
||
const long numregrig = cur.curr(LF_RMOVIVA).get_long(RMI_NUMREG);
|
||
if (numreg == numregrig)
|
||
{
|
||
if (invio)
|
||
{
|
||
TRectype& cur_rec_righe = cur.curr(LF_RMOVIVA);
|
||
TRecord_text recrighe;
|
||
recrighe.set_type("I");
|
||
cur.save_status();
|
||
_totale = !(cur.next_match(LF_RMOVIVA, "NUMREG"));
|
||
cur.restore_status();
|
||
_trasfile->autoload(recrighe, cur);
|
||
_trasfile->write(recrighe);
|
||
}
|
||
}
|
||
continua = cur.next_match(LF_RMOVIVA, "NUMREG");
|
||
}
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
long TInvioS::i_sispac_clifor(const bool invio)
|
||
{
|
||
TInvioS_file* trasfile = apri_file("clifor.txt");
|
||
TRelation rel(LF_CLIFO);
|
||
TCursor cur(&rel);
|
||
const long cur_items = cur.items();
|
||
if (cur_items != 0 && invio)
|
||
{
|
||
cur.freeze();
|
||
TRectype& cur_rec = cur.curr();
|
||
for (cur = 0; cur.pos() < cur_items; ++(cur))
|
||
{
|
||
TRecord_text rec;
|
||
const char tipocf = cur.curr().get_char(CLI_TIPOCF);
|
||
if (tipocf == 'C')
|
||
rec.set_type("C");
|
||
else
|
||
rec.set_type("F");
|
||
trasfile->autoload(rec, cur);
|
||
trasfile->write(rec);
|
||
}
|
||
}
|
||
chiudi_file(trasfile);
|
||
return cur_items+cur_items;
|
||
}
|
||
|
||
//metodone globale che chiama, come un menu, i vari sottometodi in base alle scelte sulla maschera
|
||
void TInvioS::invio_sispac()
|
||
{
|
||
//prende i parametri dal file di configurazione dell'applicazione
|
||
TFilename configname = "cg7300a.ini";
|
||
TConfig configfile(configname);
|
||
|
||
//prepara il file su cui scrivere, ovvero il _trasfile
|
||
TFilename filename = _msk->get(F_DESTINAZIONE);
|
||
filename.add(configfile.get("FILEMOVIM", "OPZIONI"));
|
||
if (fexist(filename))
|
||
remove(filename);
|
||
|
||
_trasfile = new TInvioS_file(filename);
|
||
_trasfile->open(filename,'w');
|
||
|
||
if (_msk->get_bool(F_CLIFOR))
|
||
i_sispac_clifor();
|
||
if (_msk->get_bool(F_MOVCONT))
|
||
{
|
||
i_sispac_movcont();
|
||
i_sispac_moviva();
|
||
}
|
||
_trasfile->close();
|
||
delete _trasfile;
|
||
_trasfile = NULL;
|
||
}
|
||
|
||
bool TInvioS::create()
|
||
{
|
||
_msk = new TInvioS_mask();
|
||
_trasfile = NULL;
|
||
return TSkeleton_application::create();
|
||
}
|
||
|
||
bool TInvioS::destroy()
|
||
{
|
||
if (_trasfile)
|
||
delete _trasfile;
|
||
delete _msk;
|
||
|
||
return TSkeleton_application::destroy();
|
||
}
|
||
|
||
void TInvioS::main_loop()
|
||
{
|
||
TFilename configname = "cg7300a.ini";
|
||
configname.custom_path();
|
||
TConfig configfile(configname);
|
||
_msk->set(F_NUMEROINVIO, configfile.get_int("NUMEROINVIO","OPZIONI")+1);
|
||
_msk->set(F_DATAINI, configfile.get("DATA","OPZIONI"));
|
||
_msk->set(F_DESTINAZIONE, configfile.get("PERCORSO","OPZIONI"));
|
||
|
||
while (_msk->run() != K_QUIT)
|
||
{
|
||
_totale = false;
|
||
_finemov = false;
|
||
configfile.set("NUMEROINVIO", _msk->get(F_NUMEROINVIO),"OPZIONI");
|
||
configfile.set("DATA", _msk->get_date(F_DATAFIN),"OPZIONI");
|
||
configfile.set("PERCORSO", _msk->get(F_DESTINAZIONE),"OPZIONI");
|
||
configfile.set_paragraph("CAUSALI");
|
||
_dataini = _msk->get_date(F_DATAINI);
|
||
_datafin = _msk->get_date(F_DATAFIN);
|
||
const char tipoinvio = _msk->get(F_TIPOINVIO)[0];
|
||
if (tipoinvio == 'Z')
|
||
invio_sispac();
|
||
}
|
||
}
|
||
|
||
int cg7300(int argc, char **argv)
|
||
{
|
||
TInvioS a;
|
||
a.run(argc, argv, "Invio dati contabilit<69> Sispac/Cosmo");
|
||
return 0;
|
||
}
|
||
|