375 lines
10 KiB
C++
375 lines
10 KiB
C++
|
#include <applicat.h>
|
|||
|
#include <automask.h>
|
|||
|
#include <progind.h>
|
|||
|
|
|||
|
#include <comuni.h>
|
|||
|
|
|||
|
#include "../ve/condv.h"
|
|||
|
|
|||
|
#include "halib.h"
|
|||
|
|
|||
|
#include "ha1200a.h"
|
|||
|
|
|||
|
///////////////////////////////////////////////////////////
|
|||
|
// TAutomask
|
|||
|
///////////////////////////////////////////////////////////
|
|||
|
class TFile2Txt_mask : public TAutomask
|
|||
|
{
|
|||
|
protected:
|
|||
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|||
|
|
|||
|
public:
|
|||
|
TFile2Txt_mask();
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
bool TFile2Txt_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|||
|
{
|
|||
|
switch (o.dlg())
|
|||
|
{
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
TFile2Txt_mask::TFile2Txt_mask() : TAutomask ("ha1200a")
|
|||
|
{
|
|||
|
TConfig config(CONFIG_DITTA, "ha");
|
|||
|
const TString& path = config.get("OutputPath");
|
|||
|
set(F_PATH, path);
|
|||
|
}
|
|||
|
|
|||
|
///////////////////////////////////////
|
|||
|
// TSkeleton_application
|
|||
|
///////////////////////////////////////
|
|||
|
class TFile2Txt : public TSkeleton_application
|
|||
|
{
|
|||
|
TFilename _output_dir;
|
|||
|
|
|||
|
protected:
|
|||
|
void elabora(const TMask& mask);
|
|||
|
|
|||
|
void genera_agenti_txt();
|
|||
|
void genera_clienti_txt();
|
|||
|
void genera_sospesi_txt();
|
|||
|
void genera_righelistini_txt();
|
|||
|
void genera_contratti_txt();
|
|||
|
void genera_promozioni_txt();
|
|||
|
void genera_prodotti_txt();
|
|||
|
void genera_barcode_txt();
|
|||
|
|
|||
|
TFilename genera_path(const TString& prefisso);
|
|||
|
|
|||
|
public:
|
|||
|
virtual void main_loop();
|
|||
|
virtual bool create();
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
TFilename TFile2Txt::genera_path(const TString& prefisso)
|
|||
|
{
|
|||
|
TFilename output_path;
|
|||
|
output_path = _output_dir;
|
|||
|
output_path.add(prefisso);
|
|||
|
output_path.ext(".txt");
|
|||
|
return output_path;
|
|||
|
}
|
|||
|
|
|||
|
void TFile2Txt::genera_agenti_txt()
|
|||
|
{
|
|||
|
//AS400 recordset da riempire (da lui nascer<65> il .txt)
|
|||
|
TEsporta_agenti_recordset agenti;
|
|||
|
|
|||
|
//ISAM recordset con tutti i dati degli archivi Campo (servir<69> per riempire l'AS400 recset)
|
|||
|
TISAM_recordset archivio_agenti("USE AGENTI");
|
|||
|
const long archivio_agenti_items = archivio_agenti.items();
|
|||
|
//scansione ISAM
|
|||
|
TProgind progind(archivio_agenti_items, "Agenti...", false, true);
|
|||
|
for (bool ok = archivio_agenti.move_first(); ok; ok = archivio_agenti.move_next())
|
|||
|
{
|
|||
|
progind.addstatus(1);
|
|||
|
|
|||
|
//riga dell'AS400 recset da riempire
|
|||
|
agenti.new_rec("");
|
|||
|
|
|||
|
agenti.set("CodiceTerminale", 0L);
|
|||
|
TString8 codage = archivio_agenti.get(AGE_CODAGE).as_string();
|
|||
|
codage = codage.right(3);
|
|||
|
agenti.set(AGE_CODAGE, codage);
|
|||
|
agenti.set(AGE_RAGSOC, archivio_agenti.get(AGE_RAGSOC));
|
|||
|
}
|
|||
|
|
|||
|
//prepara il nome corretto del file .txt e lo genera
|
|||
|
TFilename output_path = genera_path("agenti");
|
|||
|
//..e alla fine della fiera salva il file di testo nell directory selezionata
|
|||
|
agenti.save_as(output_path, fmt_text);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//clienti: i commenti del metodo sono nella genera_cliente_txt() della ha1100 (che <20> la mamma di questo)
|
|||
|
void TFile2Txt::genera_clienti_txt()
|
|||
|
{
|
|||
|
TEsporta_clienti_recordset clienti;
|
|||
|
|
|||
|
TString query;
|
|||
|
query << "USE CLIFO";
|
|||
|
query << "\nJOIN CFVEN INTO TIPOCF=TIPOCF CODCF=CODCF";
|
|||
|
query << "\nFROM TIPOCF=C";
|
|||
|
query << "\nTO TIPOCF=C";
|
|||
|
|
|||
|
TISAM_recordset archivio_clienti(query);
|
|||
|
const long archivio_clienti_items = archivio_clienti.items();
|
|||
|
|
|||
|
TProgind progind(archivio_clienti_items, "Clienti...", false, true);
|
|||
|
for (bool ok = archivio_clienti.move_first(); ok; ok = archivio_clienti.move_next())
|
|||
|
{
|
|||
|
progind.addstatus(1);
|
|||
|
|
|||
|
clienti.new_rec("");
|
|||
|
|
|||
|
//il codice terminale <20> il codagente legato al cliente
|
|||
|
TString8 codage = archivio_clienti.get(CFV_CODAG).as_string();
|
|||
|
codage = codage.right(3);
|
|||
|
clienti.set("CodiceTerminale", codage);
|
|||
|
|
|||
|
clienti.set(CLI_CODCF, archivio_clienti.get(CLI_CODCF));
|
|||
|
clienti.set(CLI_RAGSOC, archivio_clienti.get(CLI_RAGSOC));
|
|||
|
|
|||
|
TString80 indcf = archivio_clienti.get(CLI_INDCF).as_string();
|
|||
|
indcf << " " << archivio_clienti.get(CLI_CIVCF).as_string();
|
|||
|
clienti.set(CLI_INDCF, indcf);
|
|||
|
|
|||
|
const TString& statocf = archivio_clienti.get(CLI_STATOCF).as_string();
|
|||
|
if (statocf.blank())
|
|||
|
{
|
|||
|
const TString& comcf = archivio_clienti.get(CLI_COMCF).as_string();
|
|||
|
TToken_string key;
|
|||
|
key.add(statocf);
|
|||
|
key.add(comcf);
|
|||
|
const TRectype& rec_comuni = cache().get(LF_COMUNI, key);
|
|||
|
TString80 dencom = rec_comuni.get(COM_DENCOM);
|
|||
|
clienti.set("Localita", dencom);
|
|||
|
const TString& provcf = rec_comuni.get(COM_PROVCOM);
|
|||
|
clienti.set("Provincia", provcf);
|
|||
|
}
|
|||
|
|
|||
|
clienti.set(CLI_CAPCF, archivio_clienti.get(CLI_CAPCF));
|
|||
|
|
|||
|
clienti.set(CLI_PAIV, archivio_clienti.get(CLI_PAIV));
|
|||
|
|
|||
|
TString4 codpag = archivio_clienti.get(CLI_CODPAG).as_string();
|
|||
|
clienti.set(CLI_CODPAG, codpag);
|
|||
|
|
|||
|
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", archivio_clienti.get(CLI_CODCF).as_int());
|
|||
|
if (contratti.move_last())
|
|||
|
{
|
|||
|
const TString& cod_contr = contratti.get(CONDV_COD).as_string();
|
|||
|
clienti.set("CodiceListino", cod_contr);
|
|||
|
}
|
|||
|
|
|||
|
TString16 ntel = archivio_clienti.get(CLI_PTEL).as_string();
|
|||
|
ntel << archivio_clienti.get(CLI_TEL).as_string();
|
|||
|
clienti.set(CLI_TEL, ntel);
|
|||
|
|
|||
|
clienti.set(CLI_CODCFFATT, archivio_clienti.get(CLI_CODCFFATT));
|
|||
|
|
|||
|
real fido = archivio_clienti.get(CLI_FIDO).as_real();
|
|||
|
fido *= CENTO;
|
|||
|
fido.round();
|
|||
|
clienti.set(CLI_FIDO, fido);
|
|||
|
|
|||
|
const bool sospeso = archivio_clienti.get(CLI_SOSPESO).as_bool();
|
|||
|
TString4 s;
|
|||
|
if (sospeso)
|
|||
|
s='S';
|
|||
|
clienti.set("NoConsegna", TVariant(s));
|
|||
|
|
|||
|
clienti.set(CLI_COFI, archivio_clienti.get(CLI_COFI));
|
|||
|
|
|||
|
const TString& str_sconto = archivio_clienti.get(CFV_SCONTO).as_string();
|
|||
|
clienti.set("ScontoFineFattura", find_sconto(str_sconto));
|
|||
|
|
|||
|
clienti.set(CFV_ASSFIS, archivio_clienti.get(CFV_ASSFIS));
|
|||
|
}
|
|||
|
|
|||
|
TFilename output_path = genera_path("clienti");
|
|||
|
clienti.save_as(output_path, fmt_text);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
void TFile2Txt::genera_sospesi_txt()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
//listini: i commenti del metodo sono nella genera_listino_txt() della ha1100
|
|||
|
void TFile2Txt::genera_righelistini_txt()
|
|||
|
{
|
|||
|
TEsporta_listini_recordset righe_listini;
|
|||
|
|
|||
|
TString query;
|
|||
|
query << "USE RCONDV";
|
|||
|
query << "\nFROM TIPO=L";
|
|||
|
query << "\nTO TIPO=L";
|
|||
|
|
|||
|
TISAM_recordset archivio_rcondv(query);
|
|||
|
const long archivio_rcondv_items = archivio_rcondv.items();
|
|||
|
|
|||
|
TProgind progind(archivio_rcondv_items, "Listini...", false, true);
|
|||
|
for (bool ok = archivio_rcondv.move_first(); ok; ok = archivio_rcondv.move_next())
|
|||
|
{
|
|||
|
progind.addstatus(1);
|
|||
|
|
|||
|
righe_listini.new_rec("");
|
|||
|
|
|||
|
righe_listini.set("CodiceTerminale", 0L);
|
|||
|
righe_listini.set(RCONDV_COD, archivio_rcondv.get(RCONDV_COD));
|
|||
|
TString80 codart = archivio_rcondv.get(RCONDV_CODRIGA).as_string();
|
|||
|
righe_listini.set(RCONDV_CODRIGA, codart);
|
|||
|
|
|||
|
real prezzo = archivio_rcondv.get(RCONDV_PREZZO).as_real();
|
|||
|
if (prezzo.is_zero())
|
|||
|
{
|
|||
|
TToken_string key_umart;
|
|||
|
key_umart.add(codart);
|
|||
|
key_umart.add(1);
|
|||
|
const TRectype& rec_umart = cache().get(LF_UMART, key_umart);
|
|||
|
prezzo = rec_umart.get_real(UMART_PREZZO);
|
|||
|
}
|
|||
|
prezzo *= 1000;
|
|||
|
prezzo.round();
|
|||
|
righe_listini.set(RCONDV_PREZZO, prezzo.integer());
|
|||
|
|
|||
|
const TString& str_sconto = archivio_rcondv.get(RCONDV_SCONTO).as_string();
|
|||
|
righe_listini.set(RCONDV_SCONTO, find_sconto(str_sconto));
|
|||
|
}
|
|||
|
|
|||
|
TFilename output_path = genera_path("listini");
|
|||
|
righe_listini.save_as(output_path, fmt_text);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
void TFile2Txt::genera_contratti_txt()
|
|||
|
{
|
|||
|
TEsporta_contratti_recordset righe_contratti;
|
|||
|
|
|||
|
TString query;
|
|||
|
query << "USE RCONDV";
|
|||
|
query << "JOIN CONDV INTO TIPO=TIPO TIPOCF=TIPOCF CODCF=CODCF COD=COD";
|
|||
|
query << "\nFROM TIPO=C";
|
|||
|
query << "\nTO TIPO=C";
|
|||
|
|
|||
|
TISAM_recordset archivio_rcondv(query);
|
|||
|
const long archivio_rcondv_items = archivio_rcondv.items();
|
|||
|
|
|||
|
TProgind progind(archivio_rcondv_items, "Contratti...", false, true);
|
|||
|
for (bool ok = archivio_rcondv.move_first(); ok; ok = archivio_rcondv.move_next())
|
|||
|
{
|
|||
|
progind.addstatus(1);
|
|||
|
|
|||
|
righe_contratti.new_rec("");
|
|||
|
|
|||
|
const long codcf = archivio_rcondv.get(CONDV_CODCF).as_int();
|
|||
|
righe_contratti.set("CodiceTerminale", find_codag(codcf));
|
|||
|
righe_contratti.set(RCONDV_CODRIGA, archivio_rcondv.get(RCONDV_CODRIGA));
|
|||
|
righe_contratti.set(RCONDV_PREZZO, archivio_rcondv.get(RCONDV_PREZZO));
|
|||
|
const TString& str_sconto = archivio_rcondv.get(RCONDV_SCONTO).as_string();
|
|||
|
righe_contratti.set(RCONDV_SCONTO, find_sconto(str_sconto));
|
|||
|
}
|
|||
|
|
|||
|
TFilename output_path = genera_path("particolari");
|
|||
|
righe_contratti.save_as(output_path, fmt_text);
|
|||
|
}
|
|||
|
|
|||
|
void TFile2Txt::genera_promozioni_txt()
|
|||
|
{
|
|||
|
TEsporta_contratti_recordset righe_offerte;
|
|||
|
|
|||
|
TString query;
|
|||
|
query << "USE RCONDV";
|
|||
|
query << "JOIN CONDV INTO TIPO=TIPO TIPOCF=TIPOCF CODCF=CODCF COD=COD";
|
|||
|
query << "\nFROM TIPO=O";
|
|||
|
query << "\nTO TIPO=O";
|
|||
|
|
|||
|
TISAM_recordset archivio_rcondv(query);
|
|||
|
const long archivio_rcondv_items = archivio_rcondv.items();
|
|||
|
|
|||
|
TProgind progind(archivio_rcondv_items, "Promozioni...", false, true);
|
|||
|
for (bool ok = archivio_rcondv.move_first(); ok; ok = archivio_rcondv.move_next())
|
|||
|
{
|
|||
|
progind.addstatus(1);
|
|||
|
|
|||
|
righe_offerte.new_rec("");
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
TFilename output_path = genera_path("particolari");
|
|||
|
righe_offerte.save_as(output_path, fmt_text);
|
|||
|
}
|
|||
|
|
|||
|
//prodotti: i commenti del metodo sono nella genera_prodotto_txt() della ha1100
|
|||
|
void TFile2Txt::genera_prodotti_txt()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
void TFile2Txt::genera_barcode_txt()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//metodo di alto livello per la gestione delle chiamate
|
|||
|
void TFile2Txt::elabora(const TMask& mask)
|
|||
|
{
|
|||
|
if (mask.get_bool(F_AGENTI))
|
|||
|
genera_agenti_txt();
|
|||
|
|
|||
|
if (mask.get_bool(F_CLIENTI))
|
|||
|
genera_clienti_txt();
|
|||
|
|
|||
|
if (mask.get_bool(F_SOSPESI))
|
|||
|
genera_sospesi_txt();
|
|||
|
|
|||
|
if (mask.get_bool(F_LISTINI))
|
|||
|
genera_righelistini_txt();
|
|||
|
|
|||
|
if (mask.get_bool(F_CONTRATTI))
|
|||
|
genera_contratti_txt();
|
|||
|
|
|||
|
if (mask.get_bool(F_PROMOZIONI))
|
|||
|
genera_promozioni_txt();
|
|||
|
|
|||
|
if (mask.get_bool(F_PRODOTTI))
|
|||
|
genera_prodotti_txt();
|
|||
|
|
|||
|
if (mask.get_bool(F_BARCODE))
|
|||
|
genera_barcode_txt();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
void TFile2Txt::main_loop()
|
|||
|
{
|
|||
|
TFile2Txt_mask mask;
|
|||
|
_output_dir = mask.get(F_PATH);
|
|||
|
while (mask.run() == K_ENTER)
|
|||
|
{
|
|||
|
elabora(mask);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
bool TFile2Txt::create()
|
|||
|
{
|
|||
|
return TSkeleton_application::create();
|
|||
|
}
|
|||
|
|
|||
|
int ha1200(int argc, char* argv[])
|
|||
|
{
|
|||
|
TFile2Txt a;
|
|||
|
a.run(argc, argv, "Generazione .txt da archivi");
|
|||
|
return 0;
|
|||
|
}
|