269 lines
6.6 KiB
C++
269 lines
6.6 KiB
C++
|
#include <applicat.h>
|
|||
|
#include <automask.h>
|
|||
|
#include <config.h>
|
|||
|
#include <defmask.h>
|
|||
|
#include <modaut.h>
|
|||
|
#include <progind.h>
|
|||
|
#include <reputils.h>
|
|||
|
#include <textset.h>
|
|||
|
#include <utility.h>
|
|||
|
|
|||
|
#include "ps0398100a.h"
|
|||
|
|
|||
|
///////////////////////////////////////////////
|
|||
|
// MASCHERA
|
|||
|
///////////////////////////////////////////////
|
|||
|
class TTrasferimento_ordini_mask : public TAutomask
|
|||
|
{
|
|||
|
protected:
|
|||
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|||
|
|
|||
|
public:
|
|||
|
TTrasferimento_ordini_mask();
|
|||
|
};
|
|||
|
|
|||
|
TTrasferimento_ordini_mask::TTrasferimento_ordini_mask() : TAutomask("ps0398100a")
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
bool TTrasferimento_ordini_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|||
|
{
|
|||
|
/*switch(o.dlg())
|
|||
|
{
|
|||
|
default:
|
|||
|
break;
|
|||
|
}*/
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
class TTrasferimento_ordini_recordset : public TCSV_recordset
|
|||
|
{
|
|||
|
public:
|
|||
|
TTrasferimento_ordini_recordset(const char* filename);
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
//////////////////////////////////////////////
|
|||
|
// RECORDSET
|
|||
|
/////////////////////////////////////////////
|
|||
|
//creazione del recordset di ogni ordine
|
|||
|
TTrasferimento_ordini_recordset::TTrasferimento_ordini_recordset(const char* filename) : TCSV_recordset("CSV(\";\")")
|
|||
|
{
|
|||
|
load_file(filename);
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
//////////////////////////////////////////////
|
|||
|
// APPLICAZIONE
|
|||
|
/////////////////////////////////////////////
|
|||
|
//Ridistributore di F24 per il computer
|
|||
|
class TTrasferimento_ordini : public TSkeleton_application
|
|||
|
{
|
|||
|
TTrasferimento_ordini_mask* _mask;
|
|||
|
|
|||
|
virtual bool check_autorization() const {return false;}
|
|||
|
|
|||
|
protected:
|
|||
|
virtual const char * extra_modules() const {return "ve";}
|
|||
|
virtual bool create();
|
|||
|
void fill_string(const int curr_nriga, const TString& riga_txt, TString& str);
|
|||
|
bool elabora();
|
|||
|
|
|||
|
public:
|
|||
|
virtual void main_loop();
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
void TTrasferimento_ordini::fill_string(const int curr_nriga, const TString& riga_txt, TString& str)
|
|||
|
{
|
|||
|
switch (curr_nriga)
|
|||
|
{
|
|||
|
case 3:
|
|||
|
str = riga_txt; //indirizzo
|
|||
|
str.trim();
|
|||
|
break;
|
|||
|
case 4:
|
|||
|
str << " " << riga_txt.mid(5, 10); //cap
|
|||
|
str.trim();
|
|||
|
str << " " << riga_txt.mid(15, 30); //citt<74>
|
|||
|
str.trim();
|
|||
|
str << " " << riga_txt.mid(45, 30); //provincia
|
|||
|
str.trim();
|
|||
|
str << " " << riga_txt.mid(75, 30); //nazione
|
|||
|
str.trim();
|
|||
|
break;
|
|||
|
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
bool TTrasferimento_ordini::elabora()
|
|||
|
{
|
|||
|
TFilename src_files = _mask->get(F_PATH_SRC);
|
|||
|
src_files.add("*.txt");
|
|||
|
TString_array src_files_list;
|
|||
|
//dalla cartella origine prende tutti i files .pdf e crea una simpatica lista
|
|||
|
const int n_files_txt = list_files(src_files, src_files_list);
|
|||
|
|
|||
|
const bool delete_src_files = _mask->get_bool(F_ERASE_TRANSFERRED);
|
|||
|
//cartella dove saranno creati i .ini
|
|||
|
TFilename tmp;
|
|||
|
tmp.tempdir();
|
|||
|
tmp.add("ps0398");
|
|||
|
const bool crea_dir = make_dir(tmp);
|
|||
|
//non riesce a crearla! deve dare errore di grave livello!
|
|||
|
if (!crea_dir)
|
|||
|
{
|
|||
|
TString msg;
|
|||
|
msg.format("Impossibile creare la cartella %s !", tmp);
|
|||
|
return error_box(msg);
|
|||
|
}
|
|||
|
|
|||
|
//scansione dello string_array per il trasferimento (con tanto di progind e log)
|
|||
|
TProgind pi(n_files_txt, TR("Acquisizione ordini in corso..."), true, true);
|
|||
|
TLog_report log("ERRORI DI TRASFERIMENTO");
|
|||
|
|
|||
|
for (int i = 0; i < n_files_txt; i++)
|
|||
|
{
|
|||
|
if (!pi.addstatus(1))
|
|||
|
break;
|
|||
|
|
|||
|
//file in formato filename (<28> l'ordine corrente da elaborare)
|
|||
|
const TFilename curr_fname = src_files_list.row(i);
|
|||
|
//creazione del recordset associato al file
|
|||
|
TTrasferimento_ordini_recordset recset(curr_fname);
|
|||
|
//avverte sul log quale file sta elaborando
|
|||
|
TString msg;
|
|||
|
msg.format("Elaborazione file: %s", curr_fname.name());
|
|||
|
log.log(0, msg);
|
|||
|
|
|||
|
//variabili da riempire ad ogni giro
|
|||
|
TString4 curr_tiporiga;
|
|||
|
int curr_nriga = 0;
|
|||
|
long codcf = 0L;
|
|||
|
TString ragsoc;
|
|||
|
TString hd_indsped, ht_indfatt;
|
|||
|
|
|||
|
//comincia il giro sulle righe del recordset
|
|||
|
for (bool ok = recset.move_first(); ok; ok = recset.move_next())
|
|||
|
{
|
|||
|
//riga corrente del file di input
|
|||
|
const TString& riga_txt = recset.get(0L).as_string();
|
|||
|
//gestione cambio riga e cambio sezione
|
|||
|
const TString& tr = riga_txt.left(2);
|
|||
|
if (tr != curr_tiporiga)
|
|||
|
{
|
|||
|
curr_tiporiga = tr;
|
|||
|
curr_nriga = 1;
|
|||
|
}
|
|||
|
else
|
|||
|
curr_nriga ++;
|
|||
|
//trattazione delle varie sezioni
|
|||
|
if (curr_tiporiga == "HF")
|
|||
|
{
|
|||
|
switch (curr_nriga)
|
|||
|
{
|
|||
|
case 1:
|
|||
|
{
|
|||
|
ragsoc = riga_txt.mid(5, 100);
|
|||
|
ragsoc.trim();
|
|||
|
}
|
|||
|
break;
|
|||
|
case 6:
|
|||
|
{
|
|||
|
const long cc = atol(riga_txt.mid(14,6));
|
|||
|
if (cc > 0)
|
|||
|
codcf = cc;
|
|||
|
}
|
|||
|
break;
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
} //if(curr_tiporiga=HF
|
|||
|
|
|||
|
if (curr_tiporiga == "HD")
|
|||
|
fill_string(curr_nriga, riga_txt.mid(5, 100), hd_indsped);
|
|||
|
if (curr_tiporiga == "HT")
|
|||
|
fill_string(curr_nriga, riga_txt.mid(5, 100), ht_indfatt);
|
|||
|
|
|||
|
//gestione delle righe ordine
|
|||
|
if (curr_tiporiga == "RA")
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
} //for(bool ok=recset.move.frst...
|
|||
|
|
|||
|
//per prima cosa controlla se <20> possibile risalire al cliente che ha generato l'ordine..
|
|||
|
//..no cliente...no party!
|
|||
|
if (codcf <= 0)
|
|||
|
{
|
|||
|
TString msg;
|
|||
|
msg.format("Il cliente %s ha codice nullo!", (const char*)ragsoc);
|
|||
|
log.log(1, msg);
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
//per ogni ordine in formato .txt genera un file.ini che andr<64> poi documentizzato
|
|||
|
TFilename ini_fname = tmp;
|
|||
|
ini_fname.add(format("ORD%05ld.ini", i));
|
|||
|
TConfig curr_ini(ini_fname);
|
|||
|
|
|||
|
curr_ini.set_paragraph("Transaction"); //setto il paragrafo [Transaction] del file ini
|
|||
|
|
|||
|
curr_ini.set("Action","INSERT");
|
|||
|
curr_ini.set("Mode","");
|
|||
|
|
|||
|
curr_ini.set_paragraph("33"); //setto il paragrafo [33] del file ini (testata)
|
|||
|
|
|||
|
//eliminazione del file sorgente
|
|||
|
if (delete_src_files)
|
|||
|
{
|
|||
|
const bool src_file_removed = remove_file(curr_fname);
|
|||
|
if (!src_file_removed)
|
|||
|
{
|
|||
|
TString msg;
|
|||
|
msg.format("Impossibile eliminare il file origine %s ", curr_fname.name());
|
|||
|
log.log(1, msg);
|
|||
|
continue;
|
|||
|
}
|
|||
|
}
|
|||
|
} //for(int i...
|
|||
|
|
|||
|
message_box(TR("Acquisizione ordini completata"));
|
|||
|
|
|||
|
const int items = log.recordset()->items();
|
|||
|
if (items > 0)
|
|||
|
log.preview();
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
bool TTrasferimento_ordini::create()
|
|||
|
{
|
|||
|
//se non ha la CG non pu<70> proseguire
|
|||
|
if (!has_module(VEAUT))
|
|||
|
return error_box(TR("Modulo non autorizzato"));
|
|||
|
|
|||
|
return TSkeleton_application::create();
|
|||
|
}
|
|||
|
|
|||
|
void TTrasferimento_ordini::main_loop()
|
|||
|
{
|
|||
|
_mask = new TTrasferimento_ordini_mask;
|
|||
|
if (_mask->run() != K_QUIT)
|
|||
|
elabora();
|
|||
|
|
|||
|
delete _mask;
|
|||
|
_mask = NULL;
|
|||
|
}
|
|||
|
|
|||
|
int ps0398100 (int argc, char **argv)
|
|||
|
{
|
|||
|
TTrasferimento_ordini a;
|
|||
|
a.run(argc,argv, TR("Trasferimento ordini"));
|
|||
|
return true;
|
|||
|
}
|