Files correlati : Ricompilazione Demo : [ ] Commento :correzioni pro compilazione nuova 2.2 git-svn-id: svn://10.65.10.50/trunk@13393 c028cbd2-c16b-5b4b-a496-9718f37d4682
379 lines
12 KiB
C++
Executable File
379 lines
12 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <filetext.h>
|
|
#include <form.h>
|
|
|
|
#include <mask.h>
|
|
#include <relation.h>
|
|
#include <tabutil.h>
|
|
#include <printer.h>
|
|
#include <progind.h>
|
|
#include <utility.h>
|
|
#include <lffiles.h>
|
|
|
|
#include <sheet.h>
|
|
|
|
#include "..\ve\velib.h"
|
|
#include "..\ve\velib04.h"
|
|
#include "si0400a.h"
|
|
|
|
class TScarico_file;
|
|
class TScaricoAS400: public TSkeleton_application
|
|
{
|
|
TString16 _provenienza; // provenienza
|
|
TDate _data_ini; // data di inizio intervallo
|
|
TDate _data_fine; // data di fine intervallo
|
|
TMask* _msk; // maschera di selezione dati
|
|
TString_array _elaborazioni; // array delle elaborazioni selezionate
|
|
TString_array _tipidoc; // Array di stringhe contenente i tipi documenti da elaborare
|
|
TScarico_file* _trasfile; // file di scarico dati
|
|
TAssoc_array _tracciati;
|
|
|
|
protected: // TApplication
|
|
// Le 4 seguenti non hanno bisogno di commenti
|
|
virtual void main_loop();
|
|
virtual bool create();
|
|
virtual bool destroy();
|
|
// Coontrolla se lo stato ed il tipo del documento sono validi e rispettano la selezione
|
|
bool doc_tipo_stato_ok(const TDocumento* doc);
|
|
// Handler dell'intervallo di date
|
|
static bool handle_data_range(TMask_field& f, KEY k);
|
|
void transfer();
|
|
// costruisce l'array delle elaborazioni scelte
|
|
void build_elaborazioni();
|
|
// costruisce l'array dei tipi doc e relativi stati per una elaborazione
|
|
void build_tipidoc(const TContabilizzazione& cont);
|
|
void scrivi_righe(TAssoc_array& arr_imponibile, TAssoc_array& arr_imposta);
|
|
void record(THash_object& lavoro, TDate& datadoc, TString& codartmag, real& valimponibile, real& valimposta);
|
|
virtual const char * extra_modules() const { return "BA"; }
|
|
public:
|
|
TString16& provenienza() {return _provenienza;};
|
|
TScaricoAS400() {_msk = NULL;};
|
|
virtual ~TScaricoAS400() { }
|
|
};
|
|
|
|
inline TScaricoAS400& app() { return (TScaricoAS400&) main_app(); }
|
|
|
|
/////////////////////////////////////////////////////
|
|
// Classe TScarico_file customizzata dalla TFile_text //
|
|
/////////////////////////////////////////////////////
|
|
class TScarico_file: public TFile_text
|
|
{
|
|
|
|
protected:
|
|
virtual void validate(TCursor& cur,TRecord_text &rec, TToken_string &val, TString& str);
|
|
|
|
public:
|
|
void forza_validate(TRecord_text& rec, TTracciato_record& tr );
|
|
TScarico_file(const TString& file_name, const TString& config_name);
|
|
virtual ~TScarico_file() { }
|
|
};
|
|
|
|
// gestione dei messaggi estesi nei campi
|
|
void TScarico_file::validate(TCursor& cur,TRecord_text &rec, TToken_string &s, TString& str)
|
|
{
|
|
const TString code(s.get(0));
|
|
TString valore;
|
|
if (code == "_PROVENIENZA")
|
|
valore = app().provenienza();
|
|
else if (code == "_DATADOC")
|
|
{
|
|
TDate tmp(str);
|
|
valore = tmp.string(brief,'\0');
|
|
}
|
|
else if (code == "_CURRENCY")
|
|
{
|
|
valore = str;
|
|
int len = atoi(s.get());
|
|
if (len > 0)
|
|
valore.lpad(len);
|
|
}
|
|
else NFCHECK("Macro non definita: %s", (const char *)code);
|
|
str = valore;
|
|
}
|
|
|
|
TScarico_file::TScarico_file(const TString& file_name, const TString& config_name)
|
|
: TFile_text(file_name, config_name)
|
|
{
|
|
}
|
|
|
|
void TScarico_file::forza_validate(TRecord_text& rec, TTracciato_record& tr )
|
|
{
|
|
TString campo;
|
|
TCursor cur(tr.relation());
|
|
TRelation& rel = *cur.relation();
|
|
TArray& a_tc = tr.tracciati_campo();
|
|
int items = a_tc.items();
|
|
for (int i = 0; i < items; i++)
|
|
{
|
|
TTracciato_campo& tc = tr.get(i);
|
|
const TString& message = tc.message();
|
|
if (!message.empty())
|
|
{
|
|
campo = rec.get(i);
|
|
TToken_string msg (message, ',');
|
|
if (!msg.blank())
|
|
{
|
|
validate(cur, rec, msg, campo);
|
|
rec.add(campo, i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// costruisce l'assoc array delle elaborazioni scelte
|
|
void TScaricoAS400::build_elaborazioni()
|
|
{
|
|
_elaborazioni.destroy();
|
|
TString16 str;
|
|
str = _msk->get(F_CODICE_ELAB1);
|
|
if (str.not_empty())
|
|
_elaborazioni.add(str);
|
|
str = _msk->get(F_CODICE_ELAB2);
|
|
if (str.not_empty())
|
|
_elaborazioni.add(str);
|
|
str = _msk->get(F_CODICE_ELAB3);
|
|
if (str.not_empty())
|
|
_elaborazioni.add(str);
|
|
str = _msk->get(F_CODICE_ELAB4);
|
|
if (str.not_empty())
|
|
_elaborazioni.add(str);
|
|
str = _msk->get(F_CODICE_ELAB5);
|
|
if (str.not_empty())
|
|
_elaborazioni.add(str);
|
|
}
|
|
|
|
bool TScaricoAS400::handle_data_range(TMask_field& f, KEY k)
|
|
{
|
|
if (k==K_ENTER && f.dirty())
|
|
{
|
|
TMask& m = f.mask();
|
|
TDate da(m.get_date(F_DATAINI));
|
|
TDate a(m.get_date(F_DATAFIN));
|
|
if (a < da)
|
|
{
|
|
f.error_box("La data di inizio deve essere minore della data di fine.");
|
|
return FALSE;
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void TScaricoAS400::build_tipidoc(const TContabilizzazione& cont)
|
|
{
|
|
_tipidoc.destroy();
|
|
TToken_string t;
|
|
TString16 tipo;
|
|
for (int i=0;i<TElaborazione::_max_tipi_doc_elab;i++)
|
|
{
|
|
tipo = cont.tipo_iniziale(i);
|
|
if (tipo.not_empty())
|
|
{
|
|
t = tipo;
|
|
t.add(cont.stato_iniziale(i)); // Stato iniziale
|
|
_tipidoc.add(t); // Aggiunge questo tipo documento alla lista con il suo stato iniziale
|
|
}
|
|
}
|
|
}
|
|
|
|
bool TScaricoAS400::doc_tipo_stato_ok(const TDocumento* doc)
|
|
// Verifica che il tipo documento corrente esista tra i tipi previsti dalla elaborazione
|
|
// differita selezionata
|
|
{
|
|
bool found = FALSE;
|
|
const TString16 tipo = doc->get(DOC_TIPODOC);
|
|
const char stato = doc->get_char(DOC_STATO);
|
|
const int items = _tipidoc.items();
|
|
for (int i=0;i<items && !found;i++)
|
|
{
|
|
TToken_string& t = _tipidoc.row(i);
|
|
const TString16 tipox(t.get(0));
|
|
const char statox = t.get(1)[0];
|
|
if (tipo == tipox && stato == statox)
|
|
found = TRUE;
|
|
}
|
|
return found;
|
|
}
|
|
|
|
//emetto un record
|
|
void TScaricoAS400::record(THash_object& lavoro, TDate& datadoc, TString& codartmag, real& valimponibile, real& valimposta)
|
|
{
|
|
TTracciato_record& oggetto = (TTracciato_record&)lavoro.obj();
|
|
const TString& tipo = oggetto.type();
|
|
TRecord_text rec(tipo);
|
|
//carico il record da emettere
|
|
_trasfile->autoload(rec, LF_RIGHEDOC);
|
|
_trasfile->add_field(rec, "DATADOC", (const char*) datadoc);
|
|
_trasfile->add_field(rec, "CODARTMAG", (const char*) codartmag);
|
|
TCurrency c(valimponibile);
|
|
TString80 str = c.string();
|
|
str.strip(",");
|
|
_trasfile->add_field(rec, "IMPONIBILE", (const char*) str);
|
|
c = TCurrency(valimposta);
|
|
str = c.string();
|
|
str.strip(",");
|
|
_trasfile->add_field(rec, "IMPOSTA", (const char*) str);
|
|
_trasfile->forza_validate(rec,oggetto);
|
|
_trasfile->write(rec);//emetto i dati su file
|
|
}
|
|
|
|
// creazione dell'applicazione
|
|
bool TScaricoAS400::create()
|
|
{
|
|
open_files(LF_TABCOM, LF_TAB, LF_CLIFO, LF_OCCAS, LF_INDSP, LF_CFVEN, LF_DOC, LF_RIGHEDOC, LF_ANAMAG, LF_MOVMAG, LF_RMOVMAG, LF_CONDV, LF_SVRIEP, LF_AGENTI, LF_PERCPROV, LF_CESS, LF_CAUSALI, 0);
|
|
_msk = new TMask("si0400a");
|
|
_msk->set_handler(F_DATAINI,handle_data_range);
|
|
_msk->set_handler(F_DATAFIN,handle_data_range);
|
|
_trasfile = NULL;
|
|
return TSkeleton_application::create();
|
|
}
|
|
|
|
bool TScaricoAS400::destroy()
|
|
{
|
|
if (_msk) delete _msk;
|
|
if (_trasfile) delete _trasfile;
|
|
return TSkeleton_application::destroy();
|
|
}
|
|
|
|
void TScaricoAS400::main_loop()
|
|
{
|
|
TConfig c(CONFIG_STUDIO, "sipag");
|
|
_msk->set(F_FILESEQ, c.get("FileSeqE"));
|
|
_msk->set(F_FILEMOV, c.get("FileMov"));
|
|
_msk->set(F_CODICE_ELAB1, c.get("CodElab1"));
|
|
_msk->set(F_CODICE_ELAB2, c.get("CodElab2"));
|
|
_msk->set(F_CODICE_ELAB3, c.get("CodElab3"));
|
|
_msk->set(F_CODICE_ELAB4, c.get("CodElab4"));
|
|
_msk->set(F_CODICE_ELAB5, c.get("CodElab5"));
|
|
_msk->set(F_PROVENIENZA, c.get("CodProv"));
|
|
while (_msk->run() == K_ENTER)
|
|
{
|
|
c.set("FileSeqE", _msk->get(F_FILESEQ));
|
|
c.set("FileMov", _msk->get(F_FILEMOV));
|
|
c.set("CodElab1", _msk->get(F_CODICE_ELAB1));
|
|
c.set("CodElab2", _msk->get(F_CODICE_ELAB2));
|
|
c.set("CodElab3", _msk->get(F_CODICE_ELAB3));
|
|
c.set("CodElab4", _msk->get(F_CODICE_ELAB4));
|
|
c.set("CodElab5", _msk->get(F_CODICE_ELAB5));
|
|
c.set("CodProv", _msk->get(F_PROVENIENZA));
|
|
_data_ini = _msk->get_date(F_DATAINI);
|
|
_data_fine = _msk->get_date(F_DATAFIN);
|
|
_provenienza = _msk->get(F_PROVENIENZA);
|
|
|
|
TFilename n(_msk->get(F_FILEMOV));
|
|
if (fexist(n))
|
|
remove(n);
|
|
_trasfile = new TScarico_file(_msk->get(F_FILEMOV), "si0400a.ini");
|
|
_trasfile->open(_msk->get(F_FILEMOV),'w');
|
|
build_elaborazioni();
|
|
transfer();
|
|
delete _trasfile;
|
|
}
|
|
}
|
|
|
|
void TScaricoAS400::transfer()
|
|
{
|
|
_tracciati = _trasfile->tracciati();
|
|
TRelation doc_rel(LF_DOC);
|
|
TRectype da(LF_DOC);
|
|
TRectype a(LF_DOC);
|
|
const int items = _elaborazioni.items();
|
|
long tot = 0L;
|
|
int year_from = _data_ini.year();
|
|
int year_to = _data_fine.year();
|
|
//TString16 codnum;
|
|
TString msg,filt_expr;
|
|
TDate data;
|
|
da.put("DATADOC",_data_ini);
|
|
da.put("PROVV","D");
|
|
da.put("ANNO",year_from);
|
|
a.put("DATADOC",_data_fine);
|
|
a.put("PROVV","D");
|
|
a.put("ANNO",year_to);
|
|
for (int i=0; i<items;i++) // Scorre per tutte le elaborazioni
|
|
{
|
|
const TString16 codelab = (const char*) _elaborazioni.row(i);
|
|
TContabilizzazione cont(codelab);
|
|
if (!cont.empty())
|
|
{
|
|
build_tipidoc(cont);
|
|
|
|
filt_expr = "";
|
|
//codnum = cont.codice_numerazione_iniziale();
|
|
//filt_expr = "CODNUM=\"";
|
|
//filt_expr << codnum << "\"";
|
|
|
|
TCursor doc_cur(&doc_rel,filt_expr,3,&da,&a);
|
|
const long cur_items = doc_cur.items(); // Scorre tutti i documenti che rientrano nell'intervallo selezionato
|
|
if (cur_items == 0)
|
|
continue;
|
|
msg = "Selezione documenti ";
|
|
|
|
//msg << codnum << " dal ";
|
|
msg << " dal ";
|
|
|
|
msg << _data_ini.string() << " al ";
|
|
msg << _data_fine.string();
|
|
#ifdef DBG
|
|
TProgind p(cur_items,msg,TRUE,TRUE,1);
|
|
#else
|
|
TProgind p(cur_items,msg,FALSE,TRUE,1);
|
|
#endif
|
|
long j = 0;
|
|
// Comportamento:
|
|
// - scorre i documenti della numerazione corrente.
|
|
#ifdef DBG
|
|
for (;j<cur_items && !p.iscancelled();j++)
|
|
#else
|
|
for (;j<cur_items;j++)
|
|
#endif
|
|
{
|
|
p.setstatus(j+1);
|
|
doc_cur = j;
|
|
TDocumento* doc = new TDocumento;
|
|
if (doc->read(doc_cur.curr()) == NOERR && // legge il documento
|
|
//codnum == doc->get(DOC_CODNUM) && // patch del cazzo (non l'ho scritto io!!!!)
|
|
doc_tipo_stato_ok(doc)) // controlla che il tipo documento e lo stato siano coerenti con la ELD selezionata
|
|
{
|
|
TDate datadoc = doc->data();
|
|
TString80 codartmag;
|
|
real valimponibile, valimposta;
|
|
const int items = doc->physical_rows();
|
|
int numrig = 1;
|
|
for (int i=1; i<=items; i++)
|
|
{
|
|
const TRiga_documento& rr = (*doc)[i];
|
|
if (rr.is_articolo())
|
|
{
|
|
codartmag = rr.get(RDOC_CODARTMAG);
|
|
valimponibile = rr.imponibile();
|
|
valimposta = rr.imposta();
|
|
THash_object* lavoro = _tracciati.get_hashobj();
|
|
//scandisco tutti i record di un effetto
|
|
for (int i = 0; lavoro != NULL; i++)
|
|
{
|
|
record(*lavoro, datadoc, codartmag, valimponibile, valimposta); //emetto il record
|
|
lavoro = _tracciati.get_hashobj();
|
|
}
|
|
}
|
|
}
|
|
cont.change_doc_status(*doc);
|
|
delete doc;
|
|
}
|
|
else
|
|
delete doc;
|
|
}
|
|
#ifdef DBG
|
|
if (p.iscancelled()) break;
|
|
#endif
|
|
}
|
|
}
|
|
xvtil_statbar_set("");
|
|
}
|
|
|
|
int si0400(int argc, char* argv[])
|
|
{
|
|
TScaricoAS400 a;
|
|
a.run(argc, argv, "Scarico dati per AS/400");
|
|
return 0;
|
|
}
|