This commit was manufactured by cvs2svn to create branch 'R_10_00'.
git-svn-id: svn://10.65.10.50/branches/R_10_00@20931 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
4d8165fcae
commit
da23cfb307
284
ha/ha1100.cpp
Executable file
284
ha/ha1100.cpp
Executable file
@ -0,0 +1,284 @@
|
||||
#include <applicat.h>
|
||||
#include <config.h>
|
||||
#include <dongle.h>
|
||||
#include <recarray.h>
|
||||
#include <textset.h>
|
||||
#include <utility.h>
|
||||
|
||||
#include <cfven.h>
|
||||
#include <clifo.h>
|
||||
#include <comuni.h>
|
||||
|
||||
#include "../ve/condv.h"
|
||||
#include "../ve/velib.h"
|
||||
|
||||
|
||||
class THardy_config : public TConfig
|
||||
{
|
||||
public:
|
||||
virtual const TString& get(const char* var, const char* section = NULL, int index = -1, const char* def = "");
|
||||
THardy_config(const char* ini_name);
|
||||
};
|
||||
|
||||
const TString& THardy_config::get(const char* var, const char* section, int index, const char* def)
|
||||
{
|
||||
const TString& original_val = TConfig::get(var, section, index, def);
|
||||
if (original_val[0] == '"' && original_val.ends_with("\""))
|
||||
{
|
||||
TString& val = get_tmp_string();
|
||||
val = original_val;
|
||||
val.rtrim(1);
|
||||
val.ltrim(1);
|
||||
val.trim();
|
||||
return val;
|
||||
}
|
||||
return original_val;
|
||||
}
|
||||
|
||||
THardy_config::THardy_config(const char* ini_name)
|
||||
: TConfig(ini_name, "Transaction")
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Recordset specifici per i dati da trasferire
|
||||
/////////////////////////////////////////////////////////////
|
||||
//classe generica per poter aggiungere pedissequamente i campi seguendo le tracce sulla documentazione
|
||||
#define T_N "N"
|
||||
#define T_2N "2N"
|
||||
#define T_2Nv2N "2N,2N"
|
||||
#define T_X "X"
|
||||
|
||||
class THardy_recordset : public TAS400_recordset
|
||||
{
|
||||
protected:
|
||||
void add_field(const char* name, const char* tipo, int pos, int len);
|
||||
|
||||
public:
|
||||
THardy_recordset(const char* query);
|
||||
};
|
||||
|
||||
//questo è il metodo magico
|
||||
void THardy_recordset::add_field(const char* name, const char* tipo, int pos, int len)
|
||||
{
|
||||
const TFixed_string str_tipo(tipo);
|
||||
if (str_tipo.ends_with("N"))
|
||||
{
|
||||
create_field(name, pos-1, len, _intzerofld);
|
||||
return;
|
||||
}
|
||||
create_field(name, pos-1, len, _alfafld);
|
||||
}
|
||||
|
||||
THardy_recordset::THardy_recordset(const char* query) : TAS400_recordset(query)
|
||||
{}
|
||||
|
||||
|
||||
//Clienti
|
||||
//-------
|
||||
class TEsporta_clienti_recordset : public THardy_recordset
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
TEsporta_clienti_recordset();
|
||||
};
|
||||
|
||||
TEsporta_clienti_recordset::TEsporta_clienti_recordset()
|
||||
: THardy_recordset("AS400(248)")
|
||||
{
|
||||
add_field("CodiceTerminale", T_N, 1, 3);
|
||||
add_field("Segno", T_X, 4, 1);
|
||||
add_field(CLI_CODCF, T_X, 5, 6);
|
||||
add_field(CLI_RAGSOC, T_X, 11, 34);
|
||||
add_field(CLI_INDCF, T_X, 45, 34);
|
||||
add_field(CLI_LOCCF, T_X, 79, 20);
|
||||
add_field(CLI_CAPCF, T_X, 99, 5);
|
||||
add_field("Provincia", T_X, 104, 2);
|
||||
add_field(CLI_PAIV, T_X, 106, 11);
|
||||
add_field(CLI_CODPAG, T_X, 117, 1);
|
||||
add_field("CodiceListino", T_X, 118, 3);
|
||||
add_field("CodicePromozione", T_X, 121, 3);
|
||||
add_field("ScontoFineFattura", T_2Nv2N, 124, 4);
|
||||
//ne mancano ancora parecchi
|
||||
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Applicazione
|
||||
/////////////////////////////////////////////////////////////
|
||||
class TIni2Txt: public TSkeleton_application
|
||||
{
|
||||
TFilename _output_dir;
|
||||
|
||||
protected:
|
||||
void crea_nome_txt(const TString& prefisso, TFilename& output_path);
|
||||
void genera_cliente_txt(TConfig& ini);
|
||||
virtual void main_loop();
|
||||
|
||||
public:
|
||||
TIni2Txt();
|
||||
};
|
||||
|
||||
TIni2Txt::TIni2Txt()
|
||||
{
|
||||
if (user().blank())
|
||||
user() = dongle().administrator();
|
||||
}
|
||||
|
||||
|
||||
//metodo che genera in automatico il nome del file .txt in output (maggggico)
|
||||
void TIni2Txt::crea_nome_txt(const TString& prefisso, TFilename& output_path)
|
||||
{
|
||||
TString_array lista_files;
|
||||
output_path = _output_dir;
|
||||
|
||||
TString wrkstring;
|
||||
wrkstring << prefisso << "??????.txt";
|
||||
output_path.add(wrkstring);
|
||||
|
||||
const int items = list_files(output_path, lista_files);
|
||||
long n = 1;
|
||||
if (items > 0)
|
||||
{
|
||||
lista_files.sort();
|
||||
TFilename ultimo_txt = lista_files.row(items - 1);
|
||||
ultimo_txt = ultimo_txt.name();
|
||||
const long last_txt = atol(ultimo_txt.mid(prefisso.len(), 6));
|
||||
n += last_txt;
|
||||
}
|
||||
|
||||
//risfruttiamo lo stesso filename che risparmiamo
|
||||
output_path = _output_dir;
|
||||
output_path.add(prefisso);
|
||||
TString8 numero;
|
||||
numero.format("%06ld", n);
|
||||
output_path << numero;
|
||||
output_path.ext("txt");
|
||||
}
|
||||
|
||||
|
||||
void TIni2Txt::genera_cliente_txt(TConfig& ini)
|
||||
{
|
||||
//recordset per i clienti
|
||||
TEsporta_clienti_recordset clienti;
|
||||
clienti.new_rec("");
|
||||
|
||||
//controlla il tipo di transazione...
|
||||
TString4 segno = "+";
|
||||
const TString& action = ini.get("Action", "Transaction");
|
||||
if (action == "R")
|
||||
segno = "-";
|
||||
|
||||
//...e poi si lancia a capofitto a riempire il recordset!
|
||||
//campi da clifo (20)
|
||||
//-------------------
|
||||
ini.set_paragraph("20");
|
||||
|
||||
clienti.set("CodiceTerminale", 0L);
|
||||
clienti.set("Segno", segno);
|
||||
clienti.set(CLI_CODCF, ini.get_long(CLI_CODCF));
|
||||
clienti.set(CLI_RAGSOC, ini.get(CLI_RAGSOC));
|
||||
clienti.set(CLI_INDCF, ini.get(CLI_INDCF));
|
||||
clienti.set(CLI_LOCCF, ini.get(CLI_LOCCF));
|
||||
clienti.set(CLI_CAPCF, ini.get(CLI_CAPCF));
|
||||
|
||||
const TString& statocf = ini.get(CLI_STATOCF);
|
||||
if (statocf.blank())
|
||||
{
|
||||
const TString& comcf = ini.get(CLI_COMCF);
|
||||
TToken_string key;
|
||||
key.add(statocf);
|
||||
key.add(comcf);
|
||||
const TString& provcf = cache().get(LF_COMUNI, key, COM_PROVCOM);
|
||||
clienti.set("Provincia", provcf);
|
||||
}
|
||||
|
||||
clienti.set(CLI_PAIV, ini.get(CLI_PAIV));
|
||||
|
||||
const TString& codpag = ini.get(CLI_CODPAG);
|
||||
if (codpag.full())
|
||||
{
|
||||
const TString& tipo_pag = cache().get("%CPG", codpag, "S4");
|
||||
clienti.set(CLI_CODPAG, tipo_pag == "1" ? "1" : "2");
|
||||
}
|
||||
|
||||
TString query;
|
||||
query << "USE CONDV";
|
||||
query << "\nFROM TIPO=C TIPOCF=C CODCF=#CODCF";
|
||||
query << "\nTO TIPO=C TIPOCF=C CODCF=#CODCF";
|
||||
|
||||
TISAM_recordset contratti(query);
|
||||
contratti.set_var("#CODCF", ini.get_long(CLI_CODCF));
|
||||
if (contratti.move_last())
|
||||
{
|
||||
const TString& cod_contr = contratti.get(CONDV_COD).as_string();
|
||||
clienti.set("CodiceListino", cod_contr);
|
||||
}
|
||||
|
||||
//clienti.set("CodicePromozione", );
|
||||
|
||||
|
||||
//campi da cfven(17)
|
||||
//------------------
|
||||
ini.set_paragraph("17");
|
||||
const TString& str_sconto = ini.get(CFV_SCONTO);
|
||||
TString goodexp;
|
||||
real val_perc;
|
||||
if (scontoexpr2perc(str_sconto, false, goodexp, val_perc))
|
||||
{
|
||||
val_perc = CENTO - (val_perc * CENTO);
|
||||
val_perc *= CENTO;
|
||||
val_perc.round();
|
||||
clienti.set("ScontoFineFattura", val_perc);
|
||||
}
|
||||
|
||||
//prepara il nome corretto del file .txt da generare
|
||||
const TString prefisso = "clientivar";
|
||||
TFilename output_path;
|
||||
crea_nome_txt(prefisso, output_path);
|
||||
|
||||
//..e alla fine della fiera salva il file di testo nell directory selezionata
|
||||
clienti.save_as(output_path, fmt_text);
|
||||
}
|
||||
|
||||
void TIni2Txt::main_loop()
|
||||
{
|
||||
//stabilisce una volta per tutte ad inizio programma quale cavolo è la directory dove sbattere i .txt generati
|
||||
TConfig hardy(CONFIG_DITTA, "ha");
|
||||
_output_dir = hardy.get("OuputPath");
|
||||
|
||||
//dalla riga di comando raccatta il path completo del file .ini da tradurre
|
||||
TFilename path = argv(2);
|
||||
if (path.exist())
|
||||
{
|
||||
//crea un config del .ini di tipo Hardy_config con le get astute!
|
||||
THardy_config input_ini_file(path);
|
||||
|
||||
//elabora il .ini
|
||||
TString_array ini_paragraphs;
|
||||
input_ini_file.list_paragraphs(ini_paragraphs);
|
||||
|
||||
//clienti
|
||||
if (ini_paragraphs.find("20") >= 0)
|
||||
genera_cliente_txt(input_ini_file);
|
||||
|
||||
//sospesi
|
||||
|
||||
//listino
|
||||
|
||||
//prodotti
|
||||
|
||||
//barcode
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TIni2Txt a;
|
||||
a.run(argc, argv, "Generazione .txt da .ini");
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user