284 lines
6.6 KiB
C++
284 lines
6.6 KiB
C++
|
#include <applicat.h>
|
||
|
#include <automask.h>
|
||
|
#include <execp.h>
|
||
|
#include <progind.h>
|
||
|
#include <reprint.h>
|
||
|
#include <reputils.h>
|
||
|
#include <utility.h>
|
||
|
|
||
|
#include "pg0001.h"
|
||
|
#include "pg0001100a.h"
|
||
|
|
||
|
#include "textset.h"
|
||
|
|
||
|
|
||
|
#include "clifo.h"
|
||
|
#include "comuni.h"
|
||
|
#include "doc.h"
|
||
|
#include "rdoc.h"
|
||
|
|
||
|
#include "..\cg\cglib01.h"
|
||
|
#include "..\ve\velib.h"
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// TPaghe_textset
|
||
|
///////////////////////////////////////////////////////////
|
||
|
|
||
|
class TPaghe_recset : public TAS400_recordset
|
||
|
{
|
||
|
TAssoc_array _index;
|
||
|
|
||
|
protected:
|
||
|
void add_field(const char* name = "Filler", char tipo = 'a', int len = 0, int from = -1,
|
||
|
const char* def = NULL);
|
||
|
|
||
|
public:
|
||
|
TPaghe_recset(const char * query);
|
||
|
};
|
||
|
|
||
|
void TPaghe_recset::add_field(const char* name, char tipo, int len, int from,
|
||
|
const char* def)
|
||
|
{
|
||
|
const bool required = false;
|
||
|
const TFieldtypes t = tipo == 'n' ? _longzerofld : _alfafld;
|
||
|
const int pos = from - 1;
|
||
|
if (def && *def)
|
||
|
{
|
||
|
CHECKS(def == NULL || (int)strlen(def) <= len, "Invalid default value ", def);
|
||
|
TVariant var(def); var.convert_to(t);
|
||
|
create_field(name, pos, len, t, required, var);
|
||
|
}
|
||
|
else
|
||
|
create_field(name, pos, len, t, required);
|
||
|
}
|
||
|
|
||
|
|
||
|
TPaghe_recset::TPaghe_recset(const char * query)
|
||
|
: TAS400_recordset(TString("AS400(221)\n") << query)
|
||
|
{
|
||
|
const char a = 'a';
|
||
|
const char n = 'n';
|
||
|
const bool o = true;
|
||
|
const bool f = false;
|
||
|
|
||
|
add_field("CLA01", n, 4, 1);
|
||
|
add_field("CLM01", n, 2, 5);
|
||
|
add_field("CLAZI", n, 9, 7);
|
||
|
add_field("CLF01", a, 4, 16);
|
||
|
add_field("CLCZN", a, 1, 20);
|
||
|
add_field("CLCTR", a, 4, 21);
|
||
|
add_field("CLNCD", n, 3, 25);
|
||
|
add_field("CLILR", n, 11,28);
|
||
|
add_field("CLTEL", a, 1, 39);
|
||
|
add_field("CLANN", a, 1, 40);
|
||
|
add_field("CLDTC", n, 6, 41);
|
||
|
add_field("CLA02", n, 4, 47);
|
||
|
add_field("CLM02", n, 2, 51);
|
||
|
add_field("CLAZ1", n, 9, 53);
|
||
|
add_field("CLPRG", n, 6, 62);
|
||
|
add_field("CLDTV", n, 6, 68);
|
||
|
add_field("CLF02", a, 3, 74);
|
||
|
add_field("CLCDQ", a, 4, 77);
|
||
|
add_field("CLCF1", n, 9, 81);
|
||
|
add_field("CLCF2", n, 9, 90);
|
||
|
add_field("CLCLC", n, 11,99);
|
||
|
add_field("CLRTN", n, 9, 110);
|
||
|
add_field("CLFAT", a, 1, 119);
|
||
|
add_field("CLFSP", a, 1, 120);
|
||
|
add_field("CLTPL", a, 2, 121);
|
||
|
}
|
||
|
|
||
|
// TAutomask
|
||
|
|
||
|
class TPaghe2Doc_mask : public TAutomask
|
||
|
{
|
||
|
protected:
|
||
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
public:
|
||
|
TPaghe2Doc_mask();
|
||
|
virtual ~TPaghe2Doc_mask(){};
|
||
|
};
|
||
|
|
||
|
TPaghe2Doc_mask::TPaghe2Doc_mask() :TAutomask ("pg0001100a")
|
||
|
{
|
||
|
}
|
||
|
|
||
|
bool TPaghe2Doc_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
|
||
|
{
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
HIDDEN bool browse_file_handler(TMask_field& f, KEY k)
|
||
|
{
|
||
|
if (k == K_F9)
|
||
|
{
|
||
|
FILE_SPEC fs; memset(&fs, 0, sizeof(FILE_SPEC));
|
||
|
strcpy(fs.type, "");
|
||
|
strcpy(fs.name, f.get());
|
||
|
xvt_fsys_get_default_dir(&fs.dir);
|
||
|
xvt_fsys_save_dir();
|
||
|
if (xvt_dm_post_file_open(&fs, TR("Selezione file")) == FL_OK)
|
||
|
{
|
||
|
TFilename n;
|
||
|
xvt_fsys_convert_dir_to_str(&fs.dir, n.get_buffer(n.size()), n.size());
|
||
|
n.add(fs.name);
|
||
|
f.set(n);
|
||
|
}
|
||
|
xvt_fsys_restore_dir();
|
||
|
f.set_focus();
|
||
|
}
|
||
|
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// TPaghe2Doc application
|
||
|
///////////////////////////////////////////////////////////
|
||
|
|
||
|
class TPaghe2Doc : public TSkeleton_application
|
||
|
{
|
||
|
TPaghe2Doc_mask* _m;
|
||
|
TLog_report* _log;
|
||
|
bool _errors_logged;
|
||
|
|
||
|
protected:
|
||
|
virtual TRecordset& pagheset(const TMask& m);
|
||
|
|
||
|
public:
|
||
|
virtual bool create();
|
||
|
virtual bool destroy();
|
||
|
virtual void main_loop();
|
||
|
void add_doc(const TRecordset& paghe);
|
||
|
|
||
|
int get_numdoc(const TString& numdocrif, const TDate datadoc, const TString& _codnum, const TString& tipodoc, const long codcf);
|
||
|
//int add_riga_doc(TDocumento* doc, TConfig& config);
|
||
|
TPaghe2Doc() {}
|
||
|
};
|
||
|
|
||
|
TPaghe2Doc& app() { return (TPaghe2Doc&) main_app(); }
|
||
|
|
||
|
|
||
|
bool TPaghe2Doc::create()
|
||
|
{
|
||
|
_m = new TPaghe2Doc_mask();
|
||
|
_m->set_handler(F_INPATH, browse_file_handler);
|
||
|
return TSkeleton_application::create ();
|
||
|
}
|
||
|
|
||
|
bool TPaghe2Doc::destroy()
|
||
|
{
|
||
|
delete _m;
|
||
|
return TApplication::destroy();
|
||
|
}
|
||
|
|
||
|
void TPaghe2Doc::add_doc(const TRecordset& paghe)
|
||
|
{
|
||
|
/*
|
||
|
TString msg; msg << TR("Registrazione n.") << ' ' << mov.get(MOV_NUMREG);
|
||
|
log(0, msg);
|
||
|
if (new_rec("0"))
|
||
|
{
|
||
|
char tipocf = mov.get(MOV_TIPO).as_string()[0];
|
||
|
long codcf = mov.get(MOV_CODCF).as_int();
|
||
|
|
||
|
add_clifor(tipocf, codcf);
|
||
|
add_header(mov);
|
||
|
|
||
|
const bool moviva = !mov.get(MOV_REG).is_empty();
|
||
|
|
||
|
if (moviva)
|
||
|
{
|
||
|
add_datiiva(mov);
|
||
|
add_tot_fattura(mov);
|
||
|
add_conti_ricavo_costo(mov);
|
||
|
}
|
||
|
add_ratei_risconti(mov); // Non ce li abbiamo micca!
|
||
|
add_ulteriori(mov);
|
||
|
add_diversi(mov, moviva);
|
||
|
}
|
||
|
*/
|
||
|
}
|
||
|
|
||
|
TRecordset& TPaghe2Doc::pagheset(const TMask& m)
|
||
|
{
|
||
|
TString query("SELECT * FROM ");
|
||
|
TFilename name = m.get(F_INPATH);
|
||
|
name.add(m.get(F_INFILE));
|
||
|
query << name;
|
||
|
TRecordset* paghe = new TPaghe_recset(query);
|
||
|
return *paghe;
|
||
|
}
|
||
|
|
||
|
void TPaghe2Doc::main_loop()
|
||
|
{
|
||
|
KEY tasto;
|
||
|
tasto = _m->run();
|
||
|
if (tasto == K_ENTER)
|
||
|
{
|
||
|
const char* const title = TR("Importazione documenti da paghe");
|
||
|
_log = new TLog_report(title);
|
||
|
_errors_logged = false;
|
||
|
TRecordset& paghe = pagheset(*_m);
|
||
|
TProgind pi(paghe.items(), TR("Scansione registrazioni"), true, true);
|
||
|
|
||
|
TConfig* docum=NULL;
|
||
|
TDocumento* doc=NULL;
|
||
|
|
||
|
bool error = false;
|
||
|
int ntransac=0; // numero trasnsazione per creare file .ini
|
||
|
int nriga=0; // numero riga doc.
|
||
|
int oldanno = -1;
|
||
|
int oldmese = -1;
|
||
|
long oldcodcf = -1;
|
||
|
for (bool ok = paghe.move_first(); ok; ok = paghe.move_next())
|
||
|
{
|
||
|
if (!pi.addstatus(1))
|
||
|
break;
|
||
|
const int annocomp = paghe.get("CLA01").as_int();
|
||
|
const int mesecomp = paghe.get("CLM01").as_int();
|
||
|
const long codcf = paghe.get("CLAZI").as_int();
|
||
|
if ((annocomp != oldanno) || (mesecomp != oldmese) || (codcf != oldcodcf))
|
||
|
{
|
||
|
if (docum != NULL)
|
||
|
{
|
||
|
delete docum;
|
||
|
docum = NULL;
|
||
|
}
|
||
|
if (error) // cancello il file perch'e la transazione non e' andata bene
|
||
|
{
|
||
|
TFilename pgfile; pgfile.tempdir();
|
||
|
pgfile.add(format("pg000%03d.ini",ntransac));
|
||
|
if (pgfile.exist())
|
||
|
remove_file(pgfile);
|
||
|
}
|
||
|
error = false;
|
||
|
//add_testata(paghe);
|
||
|
}
|
||
|
//add_riga(paghe);
|
||
|
}
|
||
|
TReport_book book;
|
||
|
book.add(*_log);
|
||
|
book.preview();
|
||
|
|
||
|
bool save = true;
|
||
|
if (_errors_logged)
|
||
|
{
|
||
|
save = yesno_box(TR("Sono stati riscontrati uno o piu' errori:\n"
|
||
|
"Si desidera creare i documenti ugualmente?"));
|
||
|
}
|
||
|
delete _log;
|
||
|
_log = NULL;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
int pg0001100(int argc, char* argv[])
|
||
|
{
|
||
|
TPaghe2Doc app;
|
||
|
app.run(argc, argv, TR("Ricezione fatture da paghe"));
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
|