284 lines
6.2 KiB
C++
284 lines
6.2 KiB
C++
|
// OMASA
|
||
|
|
||
|
#include <applicat.h>
|
||
|
#include <automask.h>
|
||
|
#include <config.h>
|
||
|
#include <execp.h>
|
||
|
#include <filetext.h>
|
||
|
#include <progind.h>
|
||
|
#include <utility.h>
|
||
|
|
||
|
#include "cgp4.h"
|
||
|
#include "cgp4100a.h"
|
||
|
#include "cglib01.h"
|
||
|
|
||
|
#include <mov.h>
|
||
|
#include <rmov.h>
|
||
|
|
||
|
|
||
|
#define MAX_CG_ROWS 98
|
||
|
|
||
|
|
||
|
// TAutomask
|
||
|
|
||
|
class TOmasa_mask : public TAutomask
|
||
|
{
|
||
|
protected:
|
||
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
public:
|
||
|
|
||
|
TOmasa_mask();
|
||
|
|
||
|
virtual ~TOmasa_mask(){};
|
||
|
};
|
||
|
|
||
|
TOmasa_mask::TOmasa_mask() :TAutomask ("cgp4100a")
|
||
|
{
|
||
|
}
|
||
|
|
||
|
bool TOmasa_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
|
||
|
{
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
|
||
|
// TFile_text
|
||
|
|
||
|
class TOmasa_file: public TFile_text
|
||
|
{
|
||
|
protected:
|
||
|
virtual void validate(TCursor& cur,TRecord_text &rec, TToken_string &val, TString& str);
|
||
|
|
||
|
public:
|
||
|
|
||
|
TOmasa_file(const TString& file_name);
|
||
|
virtual ~TOmasa_file() { }
|
||
|
};
|
||
|
|
||
|
TOmasa_file::TOmasa_file(const TString& file_name)
|
||
|
: TFile_text(file_name, "omasa.ini")
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void TOmasa_file::validate(TCursor& cur,TRecord_text &rec, TToken_string &s, TString& str)
|
||
|
{
|
||
|
const TString code(s.get(0));
|
||
|
TString valore;
|
||
|
if (code == "_UPPERCASE")
|
||
|
{
|
||
|
valore.upper();
|
||
|
}
|
||
|
else NFCHECK("Macro non definita: %s", (const char *)code);
|
||
|
str = valore;
|
||
|
}
|
||
|
|
||
|
|
||
|
// TSkeleton_application
|
||
|
|
||
|
class TOmasa : public TSkeleton_application
|
||
|
{
|
||
|
TOmasa_mask* _msk;
|
||
|
TOmasa_file* _trasfile;
|
||
|
TConfig* _configfile;
|
||
|
TRelation* _rel;
|
||
|
TCursor* _cur;
|
||
|
TProgind* _prog;
|
||
|
TEsercizi_contabili* _esc;
|
||
|
|
||
|
long _numreg;
|
||
|
|
||
|
protected:
|
||
|
long ultima_registrazione();
|
||
|
void compila_testata(int anno,const TDate& datareg,const TString& codcaus,const TDate& datacomp);
|
||
|
void registra_pn();
|
||
|
|
||
|
public:
|
||
|
virtual bool create();
|
||
|
virtual bool destroy();
|
||
|
virtual void main_loop();
|
||
|
bool transfer();
|
||
|
|
||
|
TOmasa() {}
|
||
|
};
|
||
|
|
||
|
TOmasa& app() { return (TOmasa&) main_app(); }
|
||
|
|
||
|
bool TOmasa::create()
|
||
|
{
|
||
|
open_files(LF_TABCOM, LF_TAB, LF_SALDI, LF_PCON, LF_MOV, LF_RMOV, LF_RMOVIVA,
|
||
|
LF_PARTITE, LF_SCADENZE, LF_PAGSCA, 0);
|
||
|
|
||
|
_configfile = new TConfig("cgp4100a.ini");
|
||
|
_msk = new TOmasa_mask();
|
||
|
_rel = new TRelation (LF_PCON);
|
||
|
_cur = new TCursor(_rel,"((GRUPPO!=\"\")&&(CONTO!=\"\")&&(SOTTOCONTO==\"\"))",1);
|
||
|
_esc = new TEsercizi_contabili;
|
||
|
|
||
|
return TSkeleton_application::create();
|
||
|
}
|
||
|
|
||
|
bool TOmasa::destroy()
|
||
|
{
|
||
|
delete _esc;
|
||
|
delete _cur;
|
||
|
delete _rel;
|
||
|
delete _msk;
|
||
|
delete _configfile;
|
||
|
|
||
|
return TApplication::destroy();
|
||
|
}
|
||
|
|
||
|
long TOmasa::ultima_registrazione()
|
||
|
{
|
||
|
TLocalisamfile mov(LF_MOV);
|
||
|
|
||
|
// Leggo il numero di registrazione dell'ultimo record di mov, e lo
|
||
|
// incremento di uno per ottenere un numero di registrazione sicuramente non esistente.
|
||
|
if (_numreg == 0)
|
||
|
{
|
||
|
mov.last();
|
||
|
_numreg = mov.get_long(MOV_NUMREG) + 1;
|
||
|
}
|
||
|
else
|
||
|
_numreg++;
|
||
|
return _numreg;
|
||
|
}
|
||
|
|
||
|
void TOmasa::main_loop()
|
||
|
{
|
||
|
KEY tasto;
|
||
|
_msk->set(F_PERCORSO, _configfile->get("PERCORSO", "MAIN"));
|
||
|
tasto = _msk->run();
|
||
|
if (tasto == K_ENTER)
|
||
|
{
|
||
|
_numreg = 0;
|
||
|
if (transfer())
|
||
|
{
|
||
|
_configfile->set("PERCORSO", _msk->get(F_PERCORSO), "MAIN");
|
||
|
message_box(TR("Importazione stipendi completata"));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bool TOmasa::transfer()
|
||
|
{
|
||
|
TString_array transactions;
|
||
|
list_files("omat*.ini", transactions);
|
||
|
FOR_EACH_ARRAY_ROW(transactions, row, name)
|
||
|
remove(*name);
|
||
|
int ntransac=0; // contatore di transazione
|
||
|
|
||
|
TConfig* movpn=NULL;
|
||
|
|
||
|
_trasfile = new TOmasa_file(_msk->get(F_PERCORSO));
|
||
|
_trasfile->open(_msk->get(F_PERCORSO),'r');
|
||
|
|
||
|
const long dimension = fsize(_msk->get(F_PERCORSO));
|
||
|
TProgind pi(dimension,"Importazione in corso...");
|
||
|
const TDate datareg = _msk->get_date(F_DATAREG);
|
||
|
const int annoes = _esc->date2esc(datareg);
|
||
|
|
||
|
TString16 olddip = "**";
|
||
|
int numrig = 0;
|
||
|
|
||
|
TRecord_text curr;
|
||
|
while (_trasfile->read(curr) == NOERR)
|
||
|
{
|
||
|
pi.setstatus(_trasfile->read_file()->tellg());
|
||
|
TString impstr = curr.get(F_IMPORTO);
|
||
|
impstr.insert(",",11);
|
||
|
const real importo(impstr);
|
||
|
TString16 contodare = curr.get(F_CONTODARE);
|
||
|
TString16 contoavere = curr.get(F_CONTOAVERE);
|
||
|
if ((!real::is_null(impstr)) && (!contodare.blank() || !contoavere.blank()))
|
||
|
{
|
||
|
|
||
|
TString16 coddip = curr.get(F_CODDIP);
|
||
|
if (coddip != olddip)
|
||
|
{
|
||
|
ntransac++;
|
||
|
movpn = new TConfig(format("omat%04d.ini",ntransac));
|
||
|
movpn->set_paragraph("Transaction");
|
||
|
movpn->set("Action","INSERT");
|
||
|
movpn->set("Mode","AUTO");
|
||
|
|
||
|
movpn->set_paragraph(format("%d",LF_MOV));
|
||
|
|
||
|
movpn->set("ANNOES", annoes);
|
||
|
movpn->set("DATACOMP", datareg);
|
||
|
movpn->set("DATAREG", datareg);
|
||
|
movpn->set("DESCR", "Importazione stipendi");
|
||
|
movpn->set("NUMREG", ultima_registrazione());
|
||
|
numrig = 0;
|
||
|
}
|
||
|
|
||
|
if (!contodare.blank())
|
||
|
{
|
||
|
numrig++;
|
||
|
movpn->set_paragraph(format("%d,%d",LF_RMOV, numrig));
|
||
|
movpn->set("ANNOES", annoes);
|
||
|
movpn->set("NUMREG", _numreg);
|
||
|
movpn->set("DATAREG", datareg);
|
||
|
movpn->set("NUMRIG", numrig);
|
||
|
movpn->set("IMPORTO", importo.string());
|
||
|
movpn->set("SEZIONE", 'D');
|
||
|
movpn->set("CODCMS", F_CENTROCOSTO);
|
||
|
|
||
|
contodare.trim();
|
||
|
TToken_string conto = _configfile->get(contodare, "CONTI");
|
||
|
if (conto.not_empty())
|
||
|
{
|
||
|
movpn->set("GRUPPO", conto.get(0));
|
||
|
movpn->set("CONTO", conto.get(1));
|
||
|
movpn->set("SOTTOCONTO", conto.get(2));
|
||
|
}
|
||
|
}
|
||
|
if (!contoavere.blank())
|
||
|
{
|
||
|
numrig++;
|
||
|
movpn->set_paragraph(format("%d,%d",LF_RMOV, numrig));
|
||
|
movpn->set("ANNOES", annoes);
|
||
|
movpn->set("NUMREG", _numreg);
|
||
|
movpn->set("DATAREG", datareg);
|
||
|
movpn->set("NUMRIG", numrig);
|
||
|
movpn->set("IMPORTO", importo.string());
|
||
|
movpn->set("SEZIONE", 'A');
|
||
|
movpn->set("CODCMS", F_CENTROCOSTO);
|
||
|
|
||
|
contoavere.trim();
|
||
|
TToken_string conto = _configfile->get(contoavere, "CONTI");
|
||
|
if (!conto.blank())
|
||
|
{
|
||
|
movpn->set("GRUPPO", conto.get(0));
|
||
|
movpn->set("CONTO", conto.get(1));
|
||
|
movpn->set("SOTTOCONTO", conto.get(2));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
delete movpn;
|
||
|
if (pi.iscancelled())
|
||
|
return TRUE;
|
||
|
}
|
||
|
}
|
||
|
_trasfile->close();
|
||
|
delete _trasfile;
|
||
|
//TExternal_app primanota("cg2.exe -0 -iosam*.ini ");
|
||
|
//primanota.run();
|
||
|
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
int cgp4100 (int argc, char* argv[])
|
||
|
{
|
||
|
TOmasa main_app;
|
||
|
main_app.run(argc, argv, TR("Importazione stipendi"));
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|