campo-sirio/cg/cg7200.cpp
alex ef2e599769 Patch level : 2.2 237
Files correlati     :
Ricompilazione Demo : [ ]
Commento            :

Riportata la versione 2.2 patch 237


git-svn-id: svn://10.65.10.50/trunk@12773 c028cbd2-c16b-5b4b-a496-9718f37d4682
2005-03-03 15:42:04 +00:00

362 lines
9.1 KiB
C++
Executable File
Raw Blame History

#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 "cg7200a.h"
#include <mov.h>
#include <rmov.h>
#include <rmoviva.h>
#define ALIAS_PCON1 100
#define ALIAS_PCON2 200
class TInvioP_file: public TFile_text
{
protected:
virtual void validate(TCursor& cur,TRecord_text &rec, TToken_string &val, TString& str);
public:
TInvioP_file(const TString& file_name, const TString& config_name);
virtual ~TInvioP_file() { }
};
TInvioP_file::TInvioP_file(const TString& file_name, const TString& config_name)
: TFile_text(file_name, config_name)
{
}
class TInvioP_mask : public TAutomask
{
protected:
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
TInvioP_mask();
virtual ~TInvioP_mask(){};
};
TInvioP_mask::TInvioP_mask() :TAutomask ("cg7200a")
{
}
bool TInvioP_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 TInvioP : public TSkeleton_application
{
TCursor* _cur;
TInvioP_mask* _msk;
TInvioP_file* _trasfile;
TDate _dataini, _datafin;
protected:
virtual bool create(void);
virtual bool destroy(void);
virtual void main_loop() ;
void invio_proforma();
bool i_proforma_movimenti();
bool i_proforma_righe();
bool i_proforma_clifor(char tipocf = 'C');
bool i_proforma_conti();
bool i_proforma_pagamenti();
public:
TInvioP() {};
virtual ~TInvioP() {};
};
// restituisce un riferimento all' applicazione
inline TInvioP& app() { return (TInvioP&) main_app();}
// gestione dei messaggi estesi nei campi
void TInvioP_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 == "_TELEFONO")
{
valore = str;
valore.trim();
str = cur.curr().get("PTEL");
valore << str;
valore.trim();
}
else NFCHECK("Macro non definita: %s", (const char *)code);
str = valore;
}
bool TInvioP::create()
{
open_files(LF_CAUSALI, LF_CLIFO, LF_PCON, LF_MOV, LF_RMOV, LF_RMOVIVA, 0);
_msk = new TInvioP_mask();
_trasfile = NULL;
return TSkeleton_application::create();
}
bool TInvioP::destroy()
{
if (_trasfile)
delete _trasfile;
delete _msk;
return TSkeleton_application::destroy();
}
void TInvioP::main_loop()
{
TFilename configname = "cg7200a.ini";
TConfig configfile(configname);
_msk->set(F_DATAINI, configfile.get("DATA","OPZIONI"));
_msk->set(F_DESTINAZIONE, configfile.get("PERCORSO","OPZIONI"));
while (_msk->run()!=K_QUIT)
{
configfile.set("DATA", _msk->get_date(F_DATAFIN),"OPZIONI");
configfile.set("PERCORSO", _msk->get(F_DESTINAZIONE),"OPZIONI");
_dataini = _msk->get_date(F_DATAINI);
_datafin = _msk->get_date(F_DATAFIN);
const char tipoinvio = _msk->get(F_TIPOINVIO)[0];
if (tipoinvio == 'P')
invio_proforma();
}
}
void TInvioP::invio_proforma()
{
if (_msk->get_bool(F_MOVIMENTI))
{
i_proforma_movimenti();
i_proforma_righe();
}
if (_msk->get_bool(F_CLIENTI))
i_proforma_clifor();
if (_msk->get_bool(F_FORNITORI))
i_proforma_clifor('F');
if (_msk->get_bool(F_CONTI))
i_proforma_conti();
}
bool TInvioP::i_proforma_conti()
{
TFilename configname = "proforma.ini";
TConfig configfile(configname);
TFilename filename = _msk->get(F_DESTINAZIONE);
filename.add("PIANOCON.TXT");
if (fexist(filename))
remove(filename);
_trasfile = new TInvioP_file(filename, configname);
_trasfile->open(filename,'w');
_trasfile->force_record_separator();
TRelation rel(LF_PCON);
TCursor cur(&rel);
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))
{
TRecord_text rec;
rec.set_type("P");
_trasfile->autoload(rec, cur);
_trasfile->write(rec);
}
}
_trasfile->close();
delete _trasfile;
_trasfile = NULL;
return TRUE;
}
bool TInvioP::i_proforma_movimenti()
{
TFilename configname = "proforma.ini";
TConfig configfile(configname);
TFilename filename = _msk->get(F_DESTINAZIONE);
filename.add("REGISTRA.TXT");
if (fexist(filename))
remove(filename);
_trasfile = new TInvioP_file(filename, configname);
_trasfile->open(filename,'w');
_trasfile->force_record_separator();
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_CAUSALI, "CODCAUS==CODCAUS", 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))
{
TRecord_text rec;
rec.set_type("T");
_trasfile->autoload(rec, cur);
_trasfile->write(rec);
}
}
_trasfile->close();
delete _trasfile;
_trasfile = NULL;
return TRUE;
}
bool TInvioP::i_proforma_righe()
{
TFilename configname = "proforma.ini";
TConfig configfile(configname);
TFilename filename = _msk->get(F_DESTINAZIONE);
filename.add("RIGHE.TXT");
if (fexist(filename))
remove(filename);
_trasfile = new TInvioP_file(filename, configname);
_trasfile->open(filename,'w');
_trasfile->force_record_separator();
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(LF_RMOV, "NUMREG==NUMREG", 1);
rel.add(LF_PCON, "GRUPPO==GRUPPO|CONTO==CONTO|SOTTOCONTO==SOTTOCONTO", 1, LF_RMOV, ALIAS_PCON1);
rel.add(LF_PCON, "GRUPPO==GRUPPO|CONTO==CONTO|SOTTOCONTO==SOTTOCONTO", 1, LF_RMOVIVA, ALIAS_PCON2);
bool add(int logicnum, const char* relexprs, int key = 1, int linkto = 0, int alias = 0, bool allow_lock = FALSE);
//rel.add("REG", "CODTAB[1,4]==ANNOIVA|CODTAB[5,7]==REG", 1);
//TString filtro = "(23->PROTIVA != \"\") && ";
//filtro << "(REG->I0 == 1) || (REG->I0 == 2)";
TCursor cur(&rel, "", 2, &da, &a);
//cur.setfilter(filtro, TRUE);
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)
{
TRectype& cur_rec_righe = cur.curr(LF_RMOVIVA);
TRecord_text recrighe;
recrighe.set_type("I");
_trasfile->autoload(recrighe, cur);
_trasfile->write(recrighe);
}
continua = cur.next_match(LF_RMOVIVA, "NUMREG");
}
continua = TRUE;
while (continua)
{
const long numregrig = cur.curr(LF_RMOV).get_long(RMV_NUMREG);
if (numreg == numregrig)
{
TRectype& cur_rec_righe = cur.curr(LF_RMOV);
TRecord_text recrighe;
recrighe.set_type("R");
_trasfile->autoload(recrighe, cur);
_trasfile->write(recrighe);
}
continua = cur.next_match(LF_RMOV, "NUMREG");
}
}
}
_trasfile->close();
delete _trasfile;
_trasfile = NULL;
return TRUE;
}
bool TInvioP::i_proforma_clifor(char tipocf)
{
TFilename configname = "proforma.ini";
TConfig configfile(configname);
TFilename filename = _msk->get(F_DESTINAZIONE);
if (tipocf == 'C')
filename.add("CLIENTI.TXT");
else
filename.add("FORNIT.TXT");
if (fexist(filename))
remove(filename);
_trasfile = new TInvioP_file(filename, configname);
_trasfile->open(filename,'w');
_trasfile->force_record_separator();
TString80 filtro = "";
filtro.format("TIPOCF == \"%c\"", tipocf);
TRelation rel(LF_CLIFO);
rel.add(LF_COMUNI, "STATO==STATOCF|COM==COMCF", 1);
TCursor cur(&rel, filtro);
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))
{
TRecord_text rec;
rec.set_type("C");
_trasfile->autoload(rec, cur);
_trasfile->write(rec);
}
}
_trasfile->close();
delete _trasfile;
_trasfile = NULL;
return TRUE;
}
int cg7200(int argc, char **argv)
{
TInvioP a;
a.run(argc, argv, "Invio dati contabilit<69>");
return 0;
}