71067401ae
git-svn-id: svn://10.65.10.50/trunk@5000 c028cbd2-c16b-5b4b-a496-9718f37d4682
196 lines
5.1 KiB
C++
Executable File
196 lines
5.1 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <filetext.h>
|
|
#include <execp.h>
|
|
#include <relation.h>
|
|
#include <urldefid.h>
|
|
|
|
#include <anagr.h>
|
|
#include <anafis.h>
|
|
#include <anagiu.h>
|
|
#include <nditte.h>
|
|
#include <unloc.h>
|
|
|
|
class TSESA_anagr : public TApplication
|
|
{
|
|
protected:
|
|
virtual bool menu(MENU_TAG mt);
|
|
virtual bool create();
|
|
|
|
public:
|
|
bool split_address(TString& addr, TString& civ) const;
|
|
int write(TLocalisamfile& file, bool re);
|
|
};
|
|
|
|
bool TSESA_anagr::split_address(TString& addr, TString& civ) const
|
|
{
|
|
bool ok = FALSE;
|
|
char* comma = strchr(addr, ',');
|
|
if (comma == NULL)
|
|
comma = strrchr(addr, ' ');
|
|
if (comma)
|
|
{
|
|
for (const char* c = comma+1; *c; c++)
|
|
{
|
|
if (isdigit(*c))
|
|
{
|
|
*comma = '\0';
|
|
civ = comma+1;
|
|
civ = civ.left(10);
|
|
ok = TRUE;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
addr = addr.left(50);
|
|
return ok;
|
|
}
|
|
|
|
int TSESA_anagr::write(TLocalisamfile& file, bool re)
|
|
{
|
|
int err = re ? file.rewrite() : file.write();
|
|
if (err != NOERR)
|
|
err = re ? file.write() : file.rewrite();
|
|
return err;
|
|
}
|
|
|
|
bool TSESA_anagr::menu(MENU_TAG mt)
|
|
{
|
|
TFilename tmp; tmp.tempdir();
|
|
|
|
TString cmdline(80);
|
|
cmdline << "sesadump ditte " << tmp;
|
|
TExternal_app app(cmdline);
|
|
int err = app.run();
|
|
if (err != 0)
|
|
return error_box("Impossibile eseguire SesaDump.exe");
|
|
|
|
TFilename txt = tmp; txt.add("ditte.txt");
|
|
TFilename ini = tmp; ini.add("ditte.ini");
|
|
TFile_text file(txt, ini);
|
|
err = file.open('r');
|
|
if (err != 0)
|
|
return error_box("Impossibile aprire il file ditte.txt");
|
|
|
|
TLocalisamfile ditte(LF_NDITTE);
|
|
TLocalisamfile anag(LF_ANAG);
|
|
TLocalisamfile anafis(LF_ANAGFIS);
|
|
TLocalisamfile anagiu(LF_ANAGGIU);
|
|
TLocalisamfile unloc(LF_UNLOC);
|
|
|
|
TString ragsoc, comres, locres, indres, civres, capres;
|
|
|
|
TRecord_text rec;
|
|
for (long rig = 1; file.read(rec) == 0; rig++)
|
|
{
|
|
const long codditta = atol(file.get_field(rec, "CODDITTA"));
|
|
if (codditta <= 0)
|
|
{
|
|
error_box("Codice ditta non valido alla riga %ld.", rig);
|
|
continue;
|
|
}
|
|
|
|
const char tipoa = file.get_field(rec, "PERS_FIS") == "S" ? 'F' : 'G';
|
|
ragsoc = file.get_field(rec, "RAGSOC");
|
|
comres = file.get_field(rec, "COMUNE");
|
|
locres = file.get_field(rec, "LOCALITA");
|
|
indres = file.get_field(rec, "INDIR1");
|
|
indres << file.get_field(rec, "INDIR2");
|
|
split_address(indres, civres);
|
|
|
|
ditte.zero();
|
|
ditte.put(NDT_CODDITTA, codditta);
|
|
int err = ditte.read(_isequal, _lock);
|
|
|
|
ditte.put(NDT_CODDITTA, codditta);
|
|
ditte.put(NDT_TIPOA, tipoa);
|
|
ditte.put(NDT_CODANAGR, codditta);
|
|
ditte.put(NDT_RAGSOC, ragsoc);
|
|
|
|
err = write(ditte, err == NOERR);
|
|
if (err != NOERR)
|
|
error_box("Errore %d in scrittura\ndella ditta %ld", err, codditta);
|
|
|
|
anag.put(ANA_TIPOA, tipoa);
|
|
anag.put(ANA_CODANAGR, codditta);
|
|
err = anag.read(_isequal, _lock);
|
|
|
|
anag.put(ANA_TIPOA, tipoa);
|
|
anag.put(ANA_CODANAGR, codditta);
|
|
anag.put(ANA_RAGSOC, ragsoc);
|
|
anag.put(ANA_COMRES, comres);
|
|
anag.put(ANA_INDRES, indres);
|
|
anag.put(ANA_CIVRES, civres);
|
|
anag.put(ANA_CAPRES, capres);
|
|
anag.put(ANA_COFI, file.get_field(rec, "CODFISCALE"));
|
|
anag.put(ANA_PAIV, file.get_field(rec, "PART_IVA"));
|
|
|
|
err = write(anag, err == NOERR);
|
|
if (err != NOERR)
|
|
error_box("Errore %d in scrittura\ndell'anagrafica %ld", err, codditta);
|
|
|
|
if (tipoa == 'F')
|
|
{
|
|
anafis.put(ANF_CODANAGR, codditta);
|
|
err = anafis.read(_isequal, _lock);
|
|
|
|
anafis.put(ANF_CODANAGR, codditta);
|
|
anafis.put(ANF_SESSO, file.get_field(rec, "SESSO"));
|
|
anafis.put(ANF_DATANASC, file.get_field(rec, "NASCITA"));
|
|
anafis.put(ANF_COMNASC, file.get_field(rec, "COMNASC"));
|
|
|
|
err = write(anafis, err == NOERR);
|
|
if (err != NOERR)
|
|
error_box("Errore %d in scrittura\ndella persona fisica %ld", err, codditta);
|
|
}
|
|
else
|
|
{
|
|
anagiu.put(ANG_CODANAGR, codditta);
|
|
err = anagiu.read(_isequal, _lock);
|
|
|
|
anagiu.put(ANG_CODANAGR, codditta);
|
|
anagiu.put(ANG_NATGIU, file.get_field(rec, "NAT_GIURID"));
|
|
|
|
err = write(anagiu, err == NOERR);
|
|
if (err != NOERR)
|
|
error_box("Errore %d in scrittura\ndella persona giuridica %ld", err, codditta);
|
|
}
|
|
|
|
unloc.put(ULC_CODDITTA, codditta);
|
|
unloc.put(ULC_CODULC, 1);
|
|
err = unloc.read(_isequal, _lock);
|
|
|
|
unloc.put(ULC_CODDITTA, codditta);
|
|
unloc.put(ULC_CODULC, 1);
|
|
unloc.put(ULC_COMULC, comres);
|
|
unloc.put(ULC_INDULC, indres);
|
|
unloc.put(ULC_CIVULC, civres);
|
|
unloc.put(ULC_CAPULC, capres);
|
|
unloc.put(ULC_COMCCIAA, comres);
|
|
unloc.put(ULC_COMTRIB, comres);
|
|
|
|
err = write(unloc, err == NOERR);
|
|
if (err != NOERR)
|
|
error_box("Errore %d in scrittura\ndell'unita' locale della ditta %ld", err, codditta);
|
|
}
|
|
|
|
remove(txt);
|
|
remove(ini);
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
bool TSESA_anagr::create()
|
|
{
|
|
dispatch_e_menu(BAR_ITEM(1));
|
|
return TRUE;
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
TSESA_anagr app;
|
|
app.run(argc, argv, "Aggiornamento anagrafiche");
|
|
exit(0);
|
|
return 0;
|
|
}
|
|
|