355 lines
8.3 KiB
C++
355 lines
8.3 KiB
C++
|
#include <applicat.h>
|
||
|
#include <automask.h>
|
||
|
#include <config.h>
|
||
|
#include <execp.h>
|
||
|
#include <filetext.h>
|
||
|
#include <progind.h>
|
||
|
#include <printer.h>
|
||
|
#include <recarray.h>
|
||
|
#include <strings.h>
|
||
|
#include <utility.h>
|
||
|
|
||
|
#include "dt0.h"
|
||
|
#include "dt0400a.h"
|
||
|
|
||
|
#include "clifo.h"
|
||
|
#include "comuni.h"
|
||
|
|
||
|
// TAutomask
|
||
|
|
||
|
class TDT2Doc_mask : public TAutomask
|
||
|
{
|
||
|
protected:
|
||
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
public:
|
||
|
TDT2Doc_mask();
|
||
|
virtual ~TDT2Doc_mask(){};
|
||
|
};
|
||
|
|
||
|
TDT2Doc_mask::TDT2Doc_mask() :TAutomask ("dt0400a")
|
||
|
{
|
||
|
}
|
||
|
|
||
|
bool TDT2Doc_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
|
||
|
{
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
// TFile_text
|
||
|
|
||
|
class TDT2Doc_file: public TFile_text
|
||
|
{
|
||
|
protected:
|
||
|
virtual void validate(TCursor& cur,TRecord_text &rec, TToken_string &val, TString& str);
|
||
|
|
||
|
public:
|
||
|
TDT2Doc_file(const TString& file_name);
|
||
|
virtual ~TDT2Doc_file() { }
|
||
|
};
|
||
|
|
||
|
TDT2Doc_file::TDT2Doc_file(const TString& file_name)
|
||
|
: TFile_text(file_name, "dt0400a.ini")
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void TDT2Doc_file::validate(TCursor& cur,TRecord_text &rec, TToken_string &s, TString& str)
|
||
|
{
|
||
|
const TString code(s.get(0));
|
||
|
TString valore = str;
|
||
|
if (code == "_UPPERCASE")
|
||
|
{
|
||
|
valore.upper();
|
||
|
}
|
||
|
else NFCHECK("Macro non definita: %s", (const char *)code);
|
||
|
str = valore;
|
||
|
}
|
||
|
|
||
|
// TSkeleton_application
|
||
|
|
||
|
class TDT2Doc : public TSkeleton_application
|
||
|
{
|
||
|
TDT2Doc_mask* _msk;
|
||
|
TDT2Doc_file* _trasfile;
|
||
|
TLocalisamfile* _clienti;
|
||
|
TConfig* _configfile;
|
||
|
TRelation* _rel;
|
||
|
TCursor* _cur;
|
||
|
TProgind* _prog;
|
||
|
TAssoc_array* _array_clienti;
|
||
|
|
||
|
public:
|
||
|
bool print_header();
|
||
|
void print_line(const TString& rigastampa = "");
|
||
|
void print_footer();
|
||
|
virtual bool create();
|
||
|
virtual bool destroy();
|
||
|
virtual void main_loop();
|
||
|
bool import_clienti();
|
||
|
bool import_documenti();
|
||
|
const long get_nextcodcf();
|
||
|
TDT2Doc() {}
|
||
|
};
|
||
|
|
||
|
TDT2Doc& app() { return (TDT2Doc&) main_app(); }
|
||
|
|
||
|
bool TDT2Doc::print_header()
|
||
|
{
|
||
|
if (printer().open())
|
||
|
{
|
||
|
TDate oggi(TODAY);
|
||
|
TPrintrow row;
|
||
|
TString256 rigastampa;
|
||
|
rigastampa = "IMPORTAZIONE DOCUMENTI";
|
||
|
rigastampa.center_just(80);
|
||
|
row.put(rigastampa);
|
||
|
row.put("@>", 1);
|
||
|
row.put("Pag. @#", 65);
|
||
|
printer().setheaderline(2, row);
|
||
|
rigastampa = "";
|
||
|
rigastampa.fill('-',80);
|
||
|
row.reset();
|
||
|
row.put(rigastampa);
|
||
|
printer().setheaderline(3, row);
|
||
|
return TRUE;
|
||
|
}
|
||
|
else
|
||
|
return error_box("Errore in apertura stampante.");
|
||
|
}
|
||
|
|
||
|
void TDT2Doc::print_line(const TString& rigastampa)
|
||
|
{
|
||
|
TPrintrow row;
|
||
|
row.reset();
|
||
|
if (rigastampa.not_empty())
|
||
|
{
|
||
|
row.put((const char*) rigastampa);
|
||
|
printer().print(row);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void TDT2Doc::print_footer()
|
||
|
{
|
||
|
printer().formfeed();
|
||
|
printer().close();
|
||
|
}
|
||
|
|
||
|
|
||
|
bool TDT2Doc::create()
|
||
|
{
|
||
|
open_files(LF_CLIFO, 0);
|
||
|
TFilename configname = "dt0400.ini";
|
||
|
configname.custom_path();
|
||
|
_configfile = new TConfig(configname);
|
||
|
_msk = new TDT2Doc_mask();
|
||
|
_clienti = new TLocalisamfile(LF_CLIFO);
|
||
|
_array_clienti = new TAssoc_array();
|
||
|
return TSkeleton_application::create();
|
||
|
}
|
||
|
|
||
|
bool TDT2Doc::destroy()
|
||
|
{
|
||
|
delete _array_clienti;
|
||
|
delete _clienti;
|
||
|
delete _msk;
|
||
|
delete _configfile;
|
||
|
return TApplication::destroy();
|
||
|
}
|
||
|
|
||
|
void TDT2Doc::main_loop()
|
||
|
{
|
||
|
KEY tasto;
|
||
|
_msk->set(F_PERCORSO, _configfile->get("PERCORSO", "OPZIONI"));
|
||
|
tasto = _msk->run();
|
||
|
if (tasto == K_ENTER)
|
||
|
{
|
||
|
if (print_header())
|
||
|
{
|
||
|
_trasfile = new TDT2Doc_file(_msk->get(F_PERCORSO));
|
||
|
import_clienti();
|
||
|
import_documenti();
|
||
|
_configfile->set("PERCORSO", _msk->get(F_PERCORSO), "OPZIONI");
|
||
|
delete _trasfile;
|
||
|
message_box(TR("Importazione documenti completata"));
|
||
|
print_footer();
|
||
|
}
|
||
|
else
|
||
|
error_box("Errore in apertura stampante.");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const long TDT2Doc::get_nextcodcf()
|
||
|
{
|
||
|
TLocalisamfile& clifo = *_clienti;
|
||
|
long codcf = 1L ;
|
||
|
if (!clifo.empty())
|
||
|
{
|
||
|
clifo.zero() ;
|
||
|
clifo.setkey(1) ;
|
||
|
clifo.put(CLI_TIPOCF, 'F');
|
||
|
clifo.read(_isgteq) ;
|
||
|
if (clifo.good())
|
||
|
clifo.prev() ;
|
||
|
clifo.setstatus(NOERR);
|
||
|
}
|
||
|
else clifo.last();
|
||
|
if (clifo.good())
|
||
|
{
|
||
|
const TFixed_string tipocf(clifo.get(CLI_TIPOCF));
|
||
|
if ( tipocf == "C")
|
||
|
{
|
||
|
codcf = clifo.get_long(CLI_CODCF);
|
||
|
if (codcf == 999999)
|
||
|
clifo.prev();
|
||
|
codcf = clifo.get_long(CLI_CODCF)+1;
|
||
|
}
|
||
|
}
|
||
|
return codcf;
|
||
|
}
|
||
|
|
||
|
bool TDT2Doc::import_documenti()
|
||
|
{
|
||
|
// eliminazione files delle elaborazioni precedenti
|
||
|
TString_array transactions;
|
||
|
list_files("ditet*.ini", transactions);
|
||
|
FOR_EACH_ARRAY_ROW(transactions, row, name)
|
||
|
remove(*name);
|
||
|
// lettura file
|
||
|
_trasfile->open('r');
|
||
|
const long dimension = fsize(_msk->get(F_PERCORSO));
|
||
|
TProgind pi(dimension,"Importazione in corso...");
|
||
|
TConfig *docum=NULL;
|
||
|
TString80 stampa;
|
||
|
int err = NOERR;
|
||
|
int ntransac=0;
|
||
|
TRecord_text curr;
|
||
|
while (_trasfile->read(curr) == NOERR && !pi.iscancelled() && err == NOERR)
|
||
|
{
|
||
|
pi.setstatus(_trasfile->read_file()->tellg());
|
||
|
if (curr.type() == "01")
|
||
|
{
|
||
|
ntransac++;
|
||
|
docum = new TConfig(format("ditet%03d.ini",ntransac));
|
||
|
docum->set_paragraph("Transaction");
|
||
|
docum->set("Action","INSERT");
|
||
|
docum->set("Mode","AUTO");
|
||
|
docum->set("Firm",firm);
|
||
|
docum->set_paragraph(format("%d",LF_DOC));
|
||
|
docum->set("ANNO", );
|
||
|
docum->set("PROVV","D");
|
||
|
docum->set("CODNUM",codnum);
|
||
|
docum->set("TIPODOC",tipodoc);
|
||
|
docum->set("DATADOC",datadoc);
|
||
|
docum->set("TIPOCF","F");
|
||
|
docum->set("CODCF",cur.relation()->lfile(LF_RMOV).get(RMV_SOTTOCONTO));
|
||
|
docum->set(DOC_CODABIA,cur.relation()->lfile(LF_CLIFO).get(CLI_CODABI));
|
||
|
docum->set(DOC_CODCABA,cur.relation()->lfile(LF_CLIFO).get(CLI_CODCAB));
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
_trasfile->close();
|
||
|
return TRUE;
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
bool TDT2Doc::import_clienti()
|
||
|
{
|
||
|
// cache per i comuni
|
||
|
TRecord_cache cache_comuni(LF_COMUNI, 2);
|
||
|
_trasfile->open('r');
|
||
|
const long dimension = fsize(_msk->get(F_PERCORSO));
|
||
|
TProgind pi(dimension,"Importazione in corso...");
|
||
|
TRelation rel(LF_CLIFO);
|
||
|
TRectype& reccli = rel.curr();
|
||
|
TLocalisamfile& clifo = rel.lfile();
|
||
|
_array_clienti->destroy();
|
||
|
TString80 stampa;
|
||
|
int err = NOERR;
|
||
|
TRecord_text curr;
|
||
|
while (_trasfile->read(curr) == NOERR && !pi.iscancelled() && err == NOERR)
|
||
|
{
|
||
|
pi.setstatus(_trasfile->read_file()->tellg());
|
||
|
if (curr.type() == "06")
|
||
|
{
|
||
|
TString16 paiv = curr.get(11);
|
||
|
TString80 cofi = curr.get(12);
|
||
|
TString16 statopaiv = " ";
|
||
|
TString80 ragsoc = curr.get(4);
|
||
|
ragsoc << curr.get(5);
|
||
|
if (!cofi.blank())
|
||
|
{
|
||
|
rel.lfile().setkey(4);
|
||
|
reccli.zero();
|
||
|
reccli.put(CLI_TIPOCF, 'C');
|
||
|
reccli.put(CLI_COFI, cofi);
|
||
|
if (reccli.read(rel.lfile())!=NOERR)
|
||
|
{
|
||
|
reccli.zero();
|
||
|
const long codcf = get_nextcodcf();
|
||
|
reccli.put(CLI_TIPOCF, 'C');
|
||
|
reccli.put(CLI_CODCF, codcf);
|
||
|
reccli.put(CLI_RAGSOC, ragsoc);
|
||
|
err = reccli.write(rel.lfile());
|
||
|
if (err != NOERR)
|
||
|
message_box("Errore in scrittura clienti %d", err);
|
||
|
}
|
||
|
}
|
||
|
else if (!paiv.blank())
|
||
|
{
|
||
|
rel.lfile().setkey(5);
|
||
|
reccli.zero();
|
||
|
reccli.put(CLI_TIPOCF, 'C');
|
||
|
reccli.put(CLI_STATOPAIV, statopaiv);
|
||
|
reccli.put(CLI_PAIV, paiv);
|
||
|
if (reccli.read(rel.lfile())!=NOERR)
|
||
|
{
|
||
|
reccli.zero();
|
||
|
const long codcf = get_nextcodcf();
|
||
|
reccli.put(CLI_TIPOCF, 'C');
|
||
|
reccli.put(CLI_CODCF, codcf);
|
||
|
reccli.put(CLI_RAGSOC, ragsoc);
|
||
|
err = reccli.write(rel.lfile());
|
||
|
if (err != NOERR)
|
||
|
message_box("Errore in scrittura clienti %d", err);
|
||
|
}
|
||
|
}
|
||
|
_trasfile->autosave(rel, curr);
|
||
|
TString80 str;
|
||
|
// comune
|
||
|
TString80 dencom = curr.get(9);
|
||
|
dencom.trim();
|
||
|
dencom.upper();
|
||
|
TRectype reccom = cache_comuni.get(dencom);
|
||
|
str = reccom.get(COM_DENCOM);
|
||
|
str.trim();
|
||
|
if (str == dencom)
|
||
|
reccli.put(CLI_COMCF, reccom.get(COM_COM));
|
||
|
else
|
||
|
{
|
||
|
reccli.put(CLI_COMCF, " ");
|
||
|
reccli.put(CLI_LOCCF, dencom);
|
||
|
stampa = "Cliente ";
|
||
|
stampa << reccli.get(CLI_CODCF);
|
||
|
stampa << " - comune " << dencom << " non trovato";
|
||
|
print_line(stampa);
|
||
|
}
|
||
|
rel.rewrite();
|
||
|
// aggiungo il cliente all'array per ritrovarlo sui documenti
|
||
|
const TString16 codcli = rel.curr().get(CLI_CODCF);
|
||
|
const TString16 codclidt = curr.get(3);
|
||
|
if (!_array_clienti->is_key(codclidt))
|
||
|
_array_clienti->add(codclidt, codcli);
|
||
|
}
|
||
|
}
|
||
|
_trasfile->close();
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
int dt0400(int argc, char* argv[])
|
||
|
{
|
||
|
TDT2Doc main_app;
|
||
|
main_app.run(argc, argv, TR("Importazione documenti"));
|
||
|
return TRUE;
|
||
|
}
|
||
|
|