453890fd36
git-svn-id: svn://10.65.10.50/branches/R_10_00@22846 c028cbd2-c16b-5b4b-a496-9718f37d4682
1065 lines
34 KiB
C++
Executable File
1065 lines
34 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <execp.h>
|
|
#include <progind.h>
|
|
#include <utility.h>
|
|
|
|
#include <comuni.h>
|
|
#include <multirel.h>
|
|
#include <scadenze.h>
|
|
#include "../cg/cgsaldac.h"
|
|
#include "../ve/condv.h"
|
|
|
|
#include "halib.h"
|
|
#include "ha1250.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())
|
|
{
|
|
case F_CARICO:
|
|
if ((e == fe_modify || e == fe_init) && o.get().full())
|
|
{
|
|
//in base alla configurazione Hardyca completa i campi chiave sulla maschera così che, in caso..
|
|
//..l'utonto decida di fare una ricerca sui documenti, gli appaiano solo quelli buoni per il trasferimento!
|
|
const TString4 codnum = ini_get_string(CONFIG_DITTA, "ha", "CarDocNum");
|
|
const TString4 stato = ini_get_string(CONFIG_DITTA, "ha", "CarDocSta");
|
|
set(F_CODNUM, codnum);
|
|
set(F_STATO, stato);
|
|
|
|
TBrowse& dacardoc = *efield(F_DA_CARDOC).browse();
|
|
TCursor& cur = *dacardoc.cursor();
|
|
dacardoc.do_input(true);
|
|
const TRecnotype tot = cur.items();
|
|
if (tot > 0)
|
|
{
|
|
cur = tot - 1;
|
|
dacardoc.do_output();
|
|
set(F_A_CARDOC, get(F_DA_CARDOC));
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
TFile2Txt_mask::TFile2Txt_mask() : TAutomask ("ha1200a")
|
|
{
|
|
}
|
|
|
|
///////////////////////////////////////
|
|
// TSkeleton_application
|
|
///////////////////////////////////////
|
|
class TFile2Txt : public THardy_transaction
|
|
{
|
|
protected:
|
|
virtual void elabora(const TMask& mask, TLog_report& log);
|
|
virtual TMask* create_mask() const;
|
|
virtual const char* fake_trans_file() const;
|
|
|
|
bool genera_agenti_txt();
|
|
bool genera_clienti_txt(const long da_codcli);
|
|
bool genera_sospesi_txt(const long da_codcli);
|
|
bool genera_righelistini_txt();
|
|
bool genera_contratti_txt();
|
|
bool genera_promozioni_txt();
|
|
bool genera_prodotti_txt();
|
|
bool genera_barcode_txt();
|
|
bool genera_decodart_txt();
|
|
bool genera_attrezzature_txt();
|
|
bool genera_tabpag_txt();
|
|
bool genera_carico_txt(const TMask& mask);
|
|
bool genera_ripristino_txt(const TMask& mask);
|
|
bool genera_consumi_txt(const TMask& mask);
|
|
|
|
void fill_anagrafica_cliente(const TISAM_recordset& archivio_clienti,
|
|
TEsporta_clienti_recordset& clienti, const bool is_fatt = false);
|
|
|
|
bool genera_nomi_output(const char* nome, TFilename& txt, TFilename& tmp) const;
|
|
bool salva_recordset(TRecordset& recset, const char* nome) const;
|
|
bool accoda_recordset(TRecordset& recset, const char* nome) const;
|
|
bool curr_cod_list(long codcf, TString& list, TString& promo) const;
|
|
|
|
public:
|
|
};
|
|
|
|
bool TFile2Txt::genera_nomi_output(const char* nome, TFilename& txt, TFilename& tmp) const
|
|
{
|
|
txt = _output_path;
|
|
txt.add(nome);
|
|
txt.ext("txt");
|
|
txt.lower();
|
|
|
|
tmp = txt;
|
|
tmp.ext("tmp");
|
|
|
|
return txt.exist();
|
|
}
|
|
|
|
bool TFile2Txt::salva_recordset(TRecordset& recset, const char* nome) const
|
|
{
|
|
TFilename txt_path, tmp_path;
|
|
genera_nomi_output(nome, txt_path, tmp_path);
|
|
const bool ok = recset.save_as(tmp_path, fmt_text);
|
|
if (ok)
|
|
{
|
|
txt_path.fremove(); // Cancello nome.txt (potrebbe esistere)
|
|
::rename(tmp_path, txt_path); // rinomino nome.tmp in nome.txt
|
|
}
|
|
else
|
|
cantwrite_box(tmp_path);
|
|
return ok;
|
|
}
|
|
|
|
bool TFile2Txt::accoda_recordset(TRecordset& recset, const char* nome) const
|
|
{
|
|
TFilename txt_path, tmp_path;
|
|
const bool append = genera_nomi_output(nome, txt_path, tmp_path);
|
|
bool ok = true;
|
|
|
|
if (append)
|
|
{
|
|
// Rinomino il file di destinazione per evitare interferenze dal concentratore
|
|
::rename(txt_path, tmp_path);
|
|
|
|
TFilename local_path;
|
|
local_path.tempdir();
|
|
local_path.add(nome);
|
|
local_path.ext(".txt");
|
|
local_path.lower();
|
|
ok = recset.save_as(local_path, fmt_text);
|
|
if (ok)
|
|
{
|
|
ok = ::fcopy(local_path, tmp_path, true, false);
|
|
if (!ok)
|
|
cantwrite_box(tmp_path);
|
|
local_path.fremove();
|
|
}
|
|
else
|
|
cantwrite_box(local_path);
|
|
|
|
// Ripristino il nome del file di destinazione
|
|
::rename(tmp_path, txt_path);
|
|
}
|
|
else
|
|
ok = salva_recordset(recset, nome);
|
|
|
|
return ok;
|
|
}
|
|
|
|
|
|
bool TFile2Txt::genera_agenti_txt()
|
|
{
|
|
//AS400 recordset da riempire (da lui nascerà il .txt)
|
|
TEsporta_agenti_recordset agenti;
|
|
|
|
//ISAM recordset con tutti i dati degli archivi Campo (servirà 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("");
|
|
|
|
TString8 codage = archivio_agenti.get(AGE_CODAGE).as_string();
|
|
codage = codage.right(3);
|
|
agenti.set("CodiceTerminale", codage);
|
|
agenti.set(AGE_CODAGE, codage);
|
|
agenti.set(AGE_RAGSOC, archivio_agenti.get(AGE_RAGSOC));
|
|
agenti.duplica_capi_zona();
|
|
}
|
|
|
|
return salva_recordset(agenti, "agenti");
|
|
}
|
|
|
|
|
|
void TFile2Txt::fill_anagrafica_cliente(const TISAM_recordset& archivio_clienti,
|
|
TEsporta_clienti_recordset& clienti, const bool is_fatt)
|
|
{
|
|
clienti.set_fatt("RagioneSociale", archivio_clienti.get(CLI_RAGSOC), is_fatt);
|
|
|
|
TString80 indcf = archivio_clienti.get(CLI_INDCF).as_string();
|
|
indcf << " " << archivio_clienti.get(CLI_CIVCF).as_string();
|
|
|
|
clienti.set_fatt("Indirizzo", indcf, is_fatt);
|
|
|
|
const TString80 localitacf = archivio_clienti.get(CLI_LOCCF).as_string();
|
|
clienti.set_fatt("Localita", localitacf, is_fatt);
|
|
|
|
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);
|
|
if (localitacf.blank())
|
|
{
|
|
TString80 dencom = rec_comuni.get(COM_DENCOM);
|
|
clienti.set_fatt("Localita", dencom, is_fatt);
|
|
}
|
|
const TString& provcf = rec_comuni.get(COM_PROVCOM);
|
|
clienti.set_fatt("Provincia", provcf, is_fatt);
|
|
}
|
|
|
|
clienti.set_fatt("CAP", archivio_clienti.get(CLI_CAPCF), is_fatt);
|
|
|
|
clienti.set_fatt("PartitaIVA", archivio_clienti.get(CLI_PAIV), is_fatt);
|
|
clienti.set_fatt("CodiceFiscale", archivio_clienti.get(CLI_COFI), is_fatt);
|
|
}
|
|
|
|
bool TFile2Txt::curr_cod_list(long codcf, TString& codlist, TString& promo) const
|
|
{
|
|
TString16 key; key.format("C|%ld", codcf);
|
|
const TString4 original = cache().get(LF_CFVEN, key, CFV_CODLIST);
|
|
codlist = original; promo.cut(0);
|
|
bool done = codlist.blank();
|
|
while (!done)
|
|
{
|
|
done = true;
|
|
key.format("L||||%s", (const char*)codlist);
|
|
const TRectype& rec = cache().get(LF_CONDV, key);
|
|
promo = rec.get(CONDV_CODLISSUCC);
|
|
if (promo.full())
|
|
{
|
|
TDate datascad = rec.get(CONDV_VALFIN);
|
|
if (datascad.ok())
|
|
{
|
|
while (datascad.wday() >= 6)
|
|
--datascad;
|
|
if (datascad <= TDate(TODAY))
|
|
{
|
|
codlist = promo;
|
|
promo.cut(0);
|
|
done = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (codlist.full() && codlist != original)
|
|
{
|
|
TLocalisamfile clifo(LF_CFVEN);
|
|
clifo.put(CFV_TIPOCF, 'C');
|
|
clifo.put(CFV_CODCF, codcf);
|
|
if (clifo.read(_isequal, _testandlock) == NOERR)
|
|
{
|
|
clifo.put(CFV_CODLIST, codlist);
|
|
clifo.rewrite();
|
|
}
|
|
}
|
|
|
|
return codlist.full();
|
|
}
|
|
|
|
|
|
//clienti: i commenti del metodo sono nella genera_cliente_txt() della ha1100 (che è la mamma di questo)
|
|
bool TFile2Txt::genera_clienti_txt(const long da_codcli)
|
|
{
|
|
//controlla se c'è un codice selezionato da cui partire
|
|
|
|
TEsporta_clienti_recordset clienti;
|
|
|
|
TString query;
|
|
query << "USE CLIFO";
|
|
query << "\nSELECT (SOSPESO!=\"X\")";
|
|
query << "\nJOIN CFVEN INTO TIPOCF=TIPOCF CODCF=CODCF";
|
|
query << "\nFROM TIPOCF=C";
|
|
if (da_codcli > 0L)
|
|
query << " CODCF=" << da_codcli;
|
|
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 è il codagente legato al cliente (codice agente lungo 5, codice terminale lungo 3)
|
|
const TString8 codage = archivio_clienti.get("CFVEN.CODAG").as_string();
|
|
clienti.set("CodiceTerminale", codage.right(3));
|
|
|
|
const long codcf = archivio_clienti.get(CLI_CODCF).as_int();
|
|
clienti.set("CodiceCliente", codcf);
|
|
|
|
//riempie l'anagrafica del cliente principale
|
|
fill_anagrafica_cliente(archivio_clienti, clienti, false);
|
|
|
|
//riempie l'anagrafica del cliente in allegato (se c'è)
|
|
const long codalleg = archivio_clienti.get(CLI_CODALLEG).as_int();
|
|
if (codalleg > 0)
|
|
{
|
|
TString queryna;
|
|
queryna << "USE CLIFO";
|
|
queryna << "\nJOIN CFVEN INTO TIPOCF=TIPOCF CODCF=CODCF";
|
|
queryna << "\nFROM TIPOCF=C CODCF=#CODALLEG";
|
|
queryna << "\nTO TIPOCF=C CODCF=#CODALLEG";
|
|
|
|
TISAM_recordset cliente_allegato(queryna);
|
|
cliente_allegato.set_var("#CODALLEG", codalleg);
|
|
|
|
fill_anagrafica_cliente(cliente_allegato, clienti, true);
|
|
}
|
|
|
|
|
|
const TString4 codpag = archivio_clienti.get(CLI_CODPAG).as_string();
|
|
clienti.set("CodicePagamento", codpag.right(2));
|
|
|
|
//Nel campo CodiceListino ci va il codice del Listino Campo associato al cliente in cfven
|
|
TString4 listino, promo; curr_cod_list(codcf, listino, promo);
|
|
clienti.set("CodiceListino", listino);
|
|
clienti.set("CodicePromozione", promo);
|
|
|
|
const TString& str_sconto = archivio_clienti.get(CFV_SCONTO).as_string();
|
|
clienti.set("ScontoFineFattura", hd_find_sconto(str_sconto));
|
|
|
|
//gestione giri
|
|
//i giri stanno nella tabella di modulo &HGI, con chiave CODTAB=agente-giorno-cliente
|
|
TString query;
|
|
query << "USE &HGI";
|
|
query << "\nSELECT (CODTAB[7,12]=#CODCLI)";
|
|
query << "\nFROM CODTAB=#CODAGE";
|
|
query << "\nTO CODTAB=#CODAGE";
|
|
TISAM_recordset cli_giri_recset(query);
|
|
cli_giri_recset.set_var("#CODCLI", codcf);
|
|
cli_giri_recset.set_var("#CODAGE", codage);
|
|
|
|
for (bool ok = cli_giri_recset.move_first(); ok; ok = cli_giri_recset.move_next())
|
|
{
|
|
const int giorno = cli_giri_recset.get("CODTAB[6,6]").as_int();
|
|
TString8 nome_campo = "Giro0";
|
|
nome_campo << giorno;
|
|
const long ordine = cli_giri_recset.get("I0").as_int();
|
|
clienti.set(nome_campo, ordine);
|
|
}
|
|
|
|
TString80 ntel = archivio_clienti.get(CLI_PTEL).as_string();
|
|
ntel << archivio_clienti.get(CLI_TEL).as_string();
|
|
clienti.set("NumeroTelefono", ntel);
|
|
|
|
clienti.set("EsenteIVA", archivio_clienti.get(CFV_ASSFIS));
|
|
|
|
clienti.set(CLI_CODCFFATT, archivio_clienti.get(CLI_CODCFFATT));
|
|
|
|
TString8 td = archivio_clienti.get("CFVEN.CODLEG").as_string();
|
|
if (td.blank())
|
|
td = "F";
|
|
else
|
|
td.cut(1);
|
|
clienti.set("TipoDoc", td);
|
|
|
|
real fido = archivio_clienti.get(CLI_FIDO).as_real();
|
|
fido *= CENTO;
|
|
fido.round();
|
|
clienti.set("Fido", fido);
|
|
|
|
/*const bool sospeso = archivio_clienti.get(CLI_SOSPESO).as_bool();
|
|
TString4 s;
|
|
if (sospeso)
|
|
s='S';
|
|
clienti.set("NoConsegna", TVariant(s));*/
|
|
|
|
clienti.duplica_capi_zona();
|
|
} //for (bool ok = archivio_clienti.move_first()...
|
|
|
|
return salva_recordset(clienti, "clienti");
|
|
}
|
|
|
|
|
|
bool TFile2Txt::genera_sospesi_txt(const long da_codcli)
|
|
{
|
|
TEsporta_sospesi_recordset sospesi;
|
|
|
|
TString query;
|
|
query << "USE PART";
|
|
query << "\nSELECT (CHIUSA!=\"X\")&&(TIPOMOV=1)";
|
|
query << "\nFROM TIPOC=C SOTTOCONTO=#DACODC";
|
|
query << "\nTO TIPOC=C";
|
|
|
|
TISAM_recordset archivio_part(query);
|
|
archivio_part.set_var("#DACODC", da_codcli);
|
|
const long archivio_part_items = archivio_part.items();
|
|
|
|
TProgind progind(archivio_part_items, "Sospesi...", false, true);
|
|
for (bool ok = archivio_part.move_first(); ok; ok = archivio_part.move_next())
|
|
{
|
|
progind.addstatus(1);
|
|
|
|
//per riempire i campi è necessario un po' di casino sulla partita in esame
|
|
const TRectype& rec_part = archivio_part.cursor()->curr();
|
|
TPartita partita(rec_part);
|
|
//cerca il saldo, il totale del doc originale, il residuo
|
|
TImporto saldo, doc, pag, imp;
|
|
partita.calcola_saldo(saldo, doc, pag, imp);
|
|
saldo.normalize(doc.sezione()); // 29/02/2012
|
|
//solo se il saldo è > 0 crea la nuova riga da esportare nel txt ... così volle Hardy!
|
|
if (saldo.valore() > ZERO && doc.valore() > ZERO)
|
|
{
|
|
sospesi.new_rec("");
|
|
|
|
const int nriga = rec_part.get_int(PART_NRIGA);
|
|
const TRiga_scadenze& scad = partita.rata(nriga, 1);
|
|
const TDate datascad = scad.get_date(SCAD_DATASCAD);
|
|
|
|
//e vai che riempiamo i campi
|
|
const long codcf = rec_part.get_long(PART_SOTTOCONTO); //riprendiamo il codcf come long
|
|
const TString& codage = hd_find_codag(codcf);
|
|
sospesi.set("CodiceTerminale", codage);
|
|
sospesi.set("CodiceCliente", codcf);
|
|
const TString& ndoc = rec_part.get(PART_NUMDOC);
|
|
sospesi.set("NumeroFattura", ndoc);
|
|
const TDate datadoc = rec_part.get_date(PART_DATADOC);
|
|
sospesi.set("DataFattura", hd_format_date6(datadoc));
|
|
real residuo = saldo.valore();
|
|
residuo *= CENTO;
|
|
sospesi.set("ImportoResiduo", residuo);
|
|
sospesi.set("ImpOriginalDoc", doc.valore());
|
|
sospesi.set("DataScadenza", hd_format_date6(datascad));
|
|
|
|
//partita: il codice sul terminalino deve avere il seguente formato (alla cazzo!)
|
|
//anno[4]-numpart[7, allineato a dx]
|
|
TString16 cod_partita;
|
|
const int anno = rec_part.get_int(PART_ANNO);
|
|
const TString& numpart = rec_part.get(PART_NUMPART); //lo si prende così perchè Hardy allinea a destra il saldaconto
|
|
cod_partita << anno << "-" << numpart;
|
|
sospesi.set("Partita", cod_partita);
|
|
sospesi.set("TipoDocumento", "F");
|
|
|
|
sospesi.duplica_capi_zona();
|
|
}
|
|
}
|
|
|
|
return salva_recordset(sospesi, "sospesi");
|
|
}
|
|
|
|
//listini: i commenti del metodo sono nella genera_listino_txt() della ha1100
|
|
bool TFile2Txt::genera_righelistini_txt()
|
|
{
|
|
const TDate oggi(TODAY);
|
|
TEsporta_listini_recordset righe_listini;
|
|
|
|
TAssoc_array promo;
|
|
|
|
TISAM_recordset agenti("USE AGENTI");
|
|
const long agenti_items = agenti.items();
|
|
|
|
TString query;
|
|
query << "USE RCONDV";
|
|
query << "\nJOIN CONDV INTO TIPO=TIPO TIPOCF=TIPOCF CODCF==CODCF COD==COD";
|
|
query << "\nFROM TIPO=L";
|
|
query << "\nTO TIPO=L";
|
|
|
|
TISAM_recordset archivio_rcondv(query);
|
|
const long archivio_rcondv_items = archivio_rcondv.items();
|
|
|
|
TProgind progind(agenti_items, "Listini...");
|
|
|
|
for (bool ak = agenti.move_first(); ak; ak = agenti.move_next())
|
|
{
|
|
if (!progind.addstatus(1))
|
|
break;
|
|
|
|
const TString4 codage = agenti.get(AGE_CODAGE).as_string().right(3);
|
|
for (bool ok = archivio_rcondv.move_first(); ok; ok = archivio_rcondv.move_next())
|
|
{
|
|
const TDate datascad = archivio_rcondv.get("CONDV.VALFIN").as_date();
|
|
if (datascad.ok() && datascad < oggi)
|
|
continue;
|
|
|
|
righe_listini.new_rec("");
|
|
|
|
righe_listini.set("CodiceTerminale", codage);
|
|
righe_listini.set(RCONDV_COD, archivio_rcondv.get(RCONDV_COD));
|
|
const 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, hd_find_sconto(str_sconto));
|
|
}
|
|
}
|
|
|
|
return salva_recordset(righe_listini, "listini");
|
|
}
|
|
|
|
|
|
bool TFile2Txt::genera_contratti_txt()
|
|
{
|
|
const TDate oggi(TODAY);
|
|
TEsporta_contratti_recordset righe_contratti;
|
|
|
|
TString query;
|
|
query << "USE RCONDV";
|
|
query << "\nJOIN CONDV INTO TIPO=TIPO TIPOCF=TIPOCF CODCF==CODCF COD==COD";
|
|
query << "\nFROM TIPO=C TIPOCF=C";
|
|
query << "\nTO TIPO=C TIPOCF=C" ;
|
|
|
|
TISAM_recordset archivio_rcondv(query);
|
|
const long archivio_rcondv_items = archivio_rcondv.items();
|
|
TProgind progind(archivio_rcondv_items, archivio_rcondv.cursor()->file().name());
|
|
|
|
for (bool ok = archivio_rcondv.move_first(); ok; ok = archivio_rcondv.move_next())
|
|
{
|
|
if (!progind.addstatus(1))
|
|
break;
|
|
|
|
const TDate datafine = archivio_rcondv.get("CONDV.VALFIN").as_date();
|
|
if (datafine.ok() && datafine < oggi) // Ignora i contratti scatuti
|
|
continue;
|
|
|
|
righe_contratti.new_rec("");
|
|
|
|
const long codcf = archivio_rcondv.get(CONDV_CODCF).as_int();
|
|
righe_contratti.set("CodiceTerminale", hd_find_codag(codcf));
|
|
righe_contratti.set(CONDV_CODCF, codcf);
|
|
righe_contratti.set(RCONDV_CODRIGA, archivio_rcondv.get(RCONDV_CODRIGA));
|
|
real prezzo = archivio_rcondv.get(RCONDV_PREZZO).as_real();
|
|
prezzo *= 1000;
|
|
prezzo.round();
|
|
righe_contratti.set(RCONDV_PREZZO, prezzo.integer());
|
|
const TString& str_sconto = archivio_rcondv.get(RCONDV_SCONTO).as_string();
|
|
righe_contratti.set(RCONDV_SCONTO, hd_find_sconto(str_sconto));
|
|
|
|
const TDate dataini = archivio_rcondv.get("CONDV.VALIN").as_date();
|
|
righe_contratti.set(CONDV_VALIN, hd_format_date8(dataini));
|
|
righe_contratti.set(CONDV_VALFIN, hd_format_date8(datafine));
|
|
righe_contratti.duplica_capi_zona();
|
|
}
|
|
|
|
return salva_recordset(righe_contratti, "particolari");
|
|
}
|
|
|
|
bool TFile2Txt::genera_promozioni_txt()
|
|
{
|
|
TEsporta_offerte_recordset promo;
|
|
|
|
TAssoc_array promos;
|
|
TDate limite(TODAY); limite -= 31;
|
|
|
|
TISAM_recordset listini("USE CONDV\nFROM TIPO=L\nTO TIPO=L");
|
|
|
|
TProgind progind(listini.items(), TR("Promozioni"));
|
|
for (bool ok = listini.move_first(); ok; ok = listini.move_next())
|
|
{
|
|
const TString& succ = listini.get(CONDV_CODLISSUCC).as_string();
|
|
const TDate datascad = listini.get(CONDV_VALFIN).as_date();
|
|
if (succ.full() && datascad >= limite)
|
|
promos.add(succ);
|
|
}
|
|
for (bool ok = listini.move_first(); ok; ok = listini.move_next())
|
|
{
|
|
const TString& cod = listini.get(CONDV_COD).as_string();
|
|
if (promos.is_key(cod))
|
|
{
|
|
const TDate dataini = listini.get(CONDV_VALIN).as_date();
|
|
TDate datafin = listini.get(CONDV_VALFIN).as_date();
|
|
if (datafin < dataini)
|
|
{
|
|
datafin = dataini;
|
|
datafin.addmonth(3);
|
|
}
|
|
promo.new_rec();
|
|
promo.set(CONDV_COD, cod);
|
|
promo.set(CONDV_CODVAL, cod);
|
|
promo.set(CONDV_VALIN, hd_format_date8(dataini));
|
|
promo.set(CONDV_VALFIN, hd_format_date8(datafin));
|
|
}
|
|
}
|
|
|
|
return salva_recordset(promo, "promo");
|
|
}
|
|
|
|
//prodotti: i commenti del metodo sono nella genera_prodotto_txt() della ha1100
|
|
bool TFile2Txt::genera_prodotti_txt()
|
|
{
|
|
TEsporta_prodotti_recordset prodotti;
|
|
|
|
TString query;
|
|
query << "USE ANAMAG";
|
|
query << "\nSELECT USER1=\"X\"";
|
|
query << "\nJOIN UMART INTO CODART=CODART NRIGA=1";
|
|
|
|
TISAM_recordset archivio_anamag(query);
|
|
const long archivio_anamag_items = archivio_anamag.items();
|
|
|
|
TProgind progind(archivio_anamag_items, TR("Prodotti..."), false, true);
|
|
for (bool ok = archivio_anamag.move_first(); ok; ok = archivio_anamag.move_next())
|
|
{
|
|
progind.addstatus(1);
|
|
|
|
prodotti.new_rec("");
|
|
|
|
prodotti.set(ANAMAG_CODART, archivio_anamag.get(ANAMAG_CODART));
|
|
prodotti.set(ANAMAG_DESCR, archivio_anamag.get(ANAMAG_DESCR));
|
|
real prezzo = archivio_anamag.get("UMART.PREZZO").as_real();
|
|
prezzo *= 1000;
|
|
prezzo.round();
|
|
prodotti.set(UMART_PREZZO, prezzo.integer());
|
|
|
|
const TString& codiva = archivio_anamag.get(ANAMAG_CODIVA).as_string();
|
|
//esportiamo un'aliquota, non un codice iva!
|
|
const real aliq_iva = cache().get("%IVA", codiva, "R0");
|
|
prodotti.set(ANAMAG_CODIVA, aliq_iva.integer());
|
|
|
|
prodotti.set(UMART_UM, archivio_anamag.get("UMART.UM"));
|
|
const TString& str_sconto = archivio_anamag.get(ANAMAG_SCONTO).as_string();
|
|
prodotti.set(ANAMAG_SCONTO, hd_find_sconto(str_sconto));
|
|
|
|
// Flag di prodotto in omaggio da controllare
|
|
prodotti.set("Fascia", archivio_anamag.get(ANAMAG_USER4).as_string().left(1));
|
|
}
|
|
|
|
return salva_recordset(prodotti, "prodotti");
|
|
}
|
|
|
|
bool TFile2Txt::genera_barcode_txt()
|
|
{
|
|
TEsporta_barcode_recordset barcode;
|
|
|
|
TISAM_recordset archivio_codcorr("USE CODCORR SELECT (TIPO=#TIPO)");
|
|
const TString& tipo = ini_get_string(CONFIG_DITTA, "ha", "TipoBarcode");
|
|
archivio_codcorr.set_var("#TIPO", tipo);
|
|
const long archivio_codcorr_items = archivio_codcorr.items();
|
|
|
|
TProgind progind(archivio_codcorr_items, TR("Barcode..."), false, true);
|
|
for (bool ok = archivio_codcorr.move_first(); ok; ok = archivio_codcorr.move_next())
|
|
{
|
|
progind.addstatus(1);
|
|
|
|
barcode.new_rec("");
|
|
barcode.set(CODCORR_CODARTALT, archivio_codcorr.get(CODCORR_CODARTALT));
|
|
barcode.set(CODCORR_CODART, archivio_codcorr.get(CODCORR_CODART));
|
|
barcode.duplica_capi_zona();
|
|
}
|
|
|
|
return salva_recordset(barcode, "barcode");
|
|
}
|
|
|
|
|
|
bool TFile2Txt::genera_decodart_txt()
|
|
{
|
|
TEsporta_decodart_recordset decodart;
|
|
|
|
const char* const query = "USE MULTIREL\nFROM COD=HACOR\nTO COD=HACOR";
|
|
TISAM_recordset archivio_codcorr(query);
|
|
const long archivio_codcorr_items = archivio_codcorr.items();
|
|
|
|
TProgind progind(archivio_codcorr_items, TR("Decodart..."), false, true);
|
|
for (bool ok = archivio_codcorr.move_first(); ok; ok = archivio_codcorr.move_next())
|
|
{
|
|
progind.addstatus(1);
|
|
|
|
decodart.new_rec("");
|
|
decodart.set(CODCORR_CODCF, archivio_codcorr.get(MULTI_FIRST));
|
|
decodart.set(CODCORR_CODART, archivio_codcorr.get(MULTI_SECOND));
|
|
|
|
const TString& data = archivio_codcorr.get(MULTI_DATA).as_string();
|
|
decodart.set(CODCORR_CODARTALT, data.left(6));
|
|
decodart.set(CODCORR_DESCR, data.mid(6, 30));
|
|
decodart.duplica_capi_zona();
|
|
}
|
|
|
|
return salva_recordset(decodart, "decodart");
|
|
}
|
|
|
|
|
|
bool TFile2Txt::genera_attrezzature_txt()
|
|
{
|
|
//esporta le attrezzature (tabella &HAATT)
|
|
TEsporta_attrezzature_recordset attrezzature;
|
|
|
|
//esporta solo le attrezzature legate ad un cliente (quelle con I0=0 non esistono più o sono in sede Hardy)
|
|
TString query;
|
|
query << "USE &ATT";
|
|
query << "\nSELECT I0>0";
|
|
|
|
TISAM_recordset archivio_attr(query);
|
|
const long archivio_attr_items = archivio_attr.items();
|
|
|
|
TProgind progind_att(archivio_attr_items, TR("Attrezzature..."), false, true);
|
|
for (bool ok = archivio_attr.move_first(); ok; ok = archivio_attr.move_next())
|
|
{
|
|
progind_att.addstatus(1);
|
|
|
|
attrezzature.new_rec("");
|
|
|
|
//in base al codice cliente stabilisce quale è il codice agente
|
|
const long codcf = archivio_attr.get("I0").as_int();
|
|
attrezzature.set("CodiceTerminale", hd_find_codag(codcf));
|
|
attrezzature.set("CodiceArticolo", archivio_attr.get("CODTAB[1,5]"));
|
|
attrezzature.set("Progressivo", archivio_attr.get("CODTAB[6,12]").as_int());
|
|
attrezzature.set("Matricola", archivio_attr.get("S0[6,20]"));
|
|
attrezzature.set("DescrAttrezz", archivio_attr.get("S3"));
|
|
attrezzature.set("CodiceCliente", codcf);
|
|
attrezzature.set("CodiceSedeCliente", archivio_attr.get("I1").as_int());
|
|
//occhio alle date
|
|
TDate data_ass = archivio_attr.get("D0").as_date();
|
|
attrezzature.set("DataAssegnamento", hd_format_date8(data_ass));
|
|
TDate data_fabb = archivio_attr.get("D1").as_date();
|
|
attrezzature.set("DataFabbricazione", hd_format_date8(data_fabb));
|
|
attrezzature.duplica_capi_zona();
|
|
}
|
|
|
|
salva_recordset(attrezzature, "attrezzature");
|
|
|
|
|
|
//esporta lo storico attrezzature (tabella &HAHIS)
|
|
TEsporta_storico_attrezzature_recordset storico;
|
|
|
|
//deve esportare solo lo storico delle attrezzature legate ad un cliente non nullo e relative al cliente stesso..
|
|
//..escludendo quindi lo storico dell'attrezzatura che non compete al cliente che l'ha attualmente in uso
|
|
query.cut(0);
|
|
query << "USE &HAHIS";
|
|
query << "\nSELECT (401@->I0>0)&&(401@->I0=I0)";
|
|
query << "\nJOIN &HAATT ALIAS 401 INTO CODTAB=CODTAB[1,12]";
|
|
|
|
TISAM_recordset archivio_storico(query);
|
|
const long archivio_storico_items = archivio_storico.items();
|
|
|
|
TProgind progind_sto(archivio_storico_items, TR("Storico interventi..."), false, true);
|
|
for (bool ok = archivio_storico.move_first(); ok; ok = archivio_storico.move_next())
|
|
{
|
|
progind_sto.addstatus(1);
|
|
|
|
storico.new_rec("");
|
|
|
|
const long codcf = archivio_storico.get("I0").as_int();
|
|
storico.set("CodiceTerminale", hd_find_codag(codcf));
|
|
storico.set("CodiceArticolo", archivio_storico.get("CODTAB[1,5]"));
|
|
storico.set("Progressivo", archivio_storico.get("CODTAB[6,12]").as_int());
|
|
storico.set("ProgrIntervento", archivio_storico.get("CODTAB[13,17]").as_int());
|
|
TDate data_int = archivio_storico.get("D0").as_date();
|
|
storico.set("DataIntervento", hd_format_date8(data_int));
|
|
storico.set("TipoIntervento", archivio_storico.get("S7[1,1]"));
|
|
storico.set("DescrIntervento", archivio_storico.get("S0"));
|
|
storico.set("CodArtIntervento", archivio_storico.get("S3[1,5]"));
|
|
storico.set("UnitaMisura", archivio_storico.get("S6[1,2]"));
|
|
real qta = archivio_storico.get("R0").as_real();
|
|
qta *= CENTO;
|
|
qta.round();
|
|
storico.set("Quantita", qta);
|
|
real importo = archivio_storico.get("R1").as_real();
|
|
importo *= CENTO;
|
|
importo.round();
|
|
storico.set("Importo", importo);
|
|
storico.set("ChiusuraComodato", archivio_storico.get("B0"));
|
|
storico.duplica_capi_zona();
|
|
}
|
|
|
|
return salva_recordset(storico, "storico");
|
|
}
|
|
|
|
bool TFile2Txt::genera_consumi_txt(const TMask& mask)
|
|
{
|
|
// esporta i consumi per cliente
|
|
TEsporta_consumi_recordset consumi;
|
|
|
|
TISAM_recordset archivio_stc("USE &STC SELECT CODTAB[7,9]=='001'");
|
|
const TRecnotype archivio_stc_items = archivio_stc.items();
|
|
|
|
TProgind progind_att(archivio_stc_items, TR("Consumi..."), false, true);
|
|
for (bool ok = archivio_stc.move_first(); ok; ok = archivio_stc.move_next())
|
|
{
|
|
if (!progind_att.addstatus(1))
|
|
break;
|
|
|
|
const TString& codtab = archivio_stc.get("CODTAB").as_string();
|
|
const TString4 grmerc = codtab.mid(6, 3);
|
|
if (grmerc != "001")
|
|
continue; // You never know!
|
|
|
|
consumi.new_rec("");
|
|
|
|
//in base al codice cliente stabilisce quale è il codice agente
|
|
const long codcf = atol(codtab.left(6));
|
|
consumi.set("CodiceTerminale", hd_find_codag(codcf));
|
|
consumi.set("CodiceCliente", codcf);
|
|
consumi.set("Anno", codtab.right(4));
|
|
consumi.set("GruppoMerc", grmerc);
|
|
for (int i = 1; i <= 12; i++)
|
|
{
|
|
TString8 inpfld; inpfld.format("I%d", i);
|
|
TString8 outfld; outfld.format("Qta%d", i);
|
|
consumi.set(outfld, archivio_stc.get(inpfld));
|
|
}
|
|
consumi.set("QtaOmaggi", archivio_stc.get("I0"));
|
|
}
|
|
|
|
return salva_recordset(consumi, "consumi");
|
|
}
|
|
|
|
bool TFile2Txt::genera_tabpag_txt()
|
|
{
|
|
TEsporta_pagamenti_recordset tabpag;
|
|
|
|
TString query;
|
|
query << "USE %CPG";
|
|
query << "\nJOIN %RPG ALIAS 401 INTO CODTAB=CODTAB";
|
|
|
|
TISAM_recordset archivio_pagamenti(query);
|
|
const long archivio_pagamenti_items = archivio_pagamenti.items();
|
|
|
|
TProgind progind(archivio_pagamenti_items, TR("Pagamenti..."), false, true);
|
|
for (bool ok = archivio_pagamenti.move_first(); ok; ok = archivio_pagamenti.move_next())
|
|
{
|
|
progind.addstatus(1);
|
|
|
|
tabpag.new_rec("");
|
|
const TString& codtab = archivio_pagamenti.get("CODTAB").as_string();
|
|
tabpag.set("CodicePagamento", codtab.right(2));
|
|
const TString& cpg_s0 = archivio_pagamenti.get("S0").as_string();
|
|
tabpag.set("DescrPagamento", cpg_s0);
|
|
long giorni = archivio_pagamenti.get("401@.I0").as_int();
|
|
if (giorni <= 0)
|
|
giorni = archivio_pagamenti.get("I3").as_int();
|
|
tabpag.set("GiorniScadenza", giorni);
|
|
tabpag.duplica_capi_zona();
|
|
}
|
|
|
|
return salva_recordset(tabpag, "tabpag");
|
|
}
|
|
|
|
bool TFile2Txt::genera_carico_txt(const TMask& mask)
|
|
{
|
|
TEsporta_carico_recordset carico;
|
|
|
|
TString query;
|
|
query << "USE RDOC";
|
|
query << "\nSELECT (DOC.TIPODOC=#TIPODOC)&&(DOC.STATO=#STATO)";
|
|
query << "\nBY DOC.CODAG NDOC";
|
|
query << "\nJOIN DOC INTO PROVV==PROVV ANNO==ANNO CODNUM==CODNUM NDOC==NDOC";
|
|
query << "\nFROM CODNUM=#CODNUM ANNO=#ANNO PROVV=D NDOC=#DA_NDOC";
|
|
query << "\nTO CODNUM=#CODNUM ANNO=#ANNO PROVV=D NDOC=#A_NDOC";
|
|
|
|
TISAM_recordset archivio_rdoc(query);
|
|
|
|
//parametri dalla configurazione
|
|
TConfig config(CONFIG_DITTA, "ha");
|
|
const TString& tipodoc = config.get("CarDocTip");
|
|
archivio_rdoc.set_var("#TIPODOC", tipodoc);
|
|
const TString& stato_ini = config.get("CarDocSta");
|
|
archivio_rdoc.set_var("#STATO", stato_ini);
|
|
const TString& codnum = config.get("CarDocNum");
|
|
archivio_rdoc.set_var("#CODNUM", codnum);
|
|
|
|
TString4 stato_fin = config.get("CarDocFin");
|
|
if (stato_fin.blank() || stato_fin == stato_ini)
|
|
stato_fin.format("%d", atoi(stato_ini)+1);
|
|
|
|
//parametri dalla maschera
|
|
const long anno = mask.get_long(F_ANNO);
|
|
archivio_rdoc.set_var("#ANNO", anno);
|
|
const long da_ndoc = mask.get_long(F_DA_CARDOC);
|
|
archivio_rdoc.set_var("#DA_NDOC", da_ndoc);
|
|
const long a_ndoc = mask.get_long(F_A_CARDOC);
|
|
archivio_rdoc.set_var("#A_NDOC", a_ndoc);
|
|
|
|
const long archivio_rdoc_items = archivio_rdoc.items();
|
|
|
|
TProgind progind(archivio_rdoc_items, "Documenti carico...", false, true);
|
|
|
|
long last_ndoc = 0;
|
|
|
|
for (bool ok = archivio_rdoc.move_first(); ok; ok = archivio_rdoc.move_next())
|
|
{
|
|
progind.addstatus(1);
|
|
|
|
const long ndoc = archivio_rdoc.get(RDOC_NDOC).as_int();
|
|
if (ndoc != last_ndoc)
|
|
{
|
|
TLocalisamfile& doc = archivio_rdoc.cursor()->file(LF_DOC);
|
|
int err = doc.read(_isequal, _testandlock);
|
|
if (err == NOERR)
|
|
{
|
|
doc.put(DOC_STATO, stato_fin);
|
|
doc.rewrite();
|
|
last_ndoc = ndoc;
|
|
}
|
|
else
|
|
continue;
|
|
}
|
|
|
|
carico.new_rec("");
|
|
|
|
TString8 codage = archivio_rdoc.get("DOC.CODAG").as_string();
|
|
codage = codage.right(3);
|
|
carico.set("CodiceTerminale", codage);
|
|
carico.set("CodiceArticolo", archivio_rdoc.get(RDOC_CODART));
|
|
real qta = archivio_rdoc.get(RDOC_QTA).as_real();
|
|
qta *= CENTO;
|
|
qta.round();
|
|
carico.set("QuantitaCaricata", qta);
|
|
carico.set("CodiceLotto", archivio_rdoc.get(RDOC_LIVELLO));
|
|
}
|
|
|
|
return accoda_recordset(carico, "carico");
|
|
}
|
|
|
|
bool TFile2Txt::genera_ripristino_txt(const TMask& mask)
|
|
{
|
|
TEsporta_carico_recordset ripristino;
|
|
|
|
TString query;
|
|
query << "USE 109 KEY 2";
|
|
query << "\nSELECT (STR(GIAC>0))&&(ANAMAG.USER1!=\"\")";
|
|
query << "\nJOIN ANAMAG INTO CODART==CODART";
|
|
query << "\nFROM ANNOES=#ANNOES CODMAG=#CODMAG";
|
|
query << "\nTO ANNOES=#ANNOES CODMAG=#CODMAG";
|
|
|
|
TISAM_recordset archivio_mag(query);
|
|
|
|
//parametri dalla maschera
|
|
const long annoes = mask.get_long(F_ANNOES);
|
|
archivio_mag.set_var("#ANNOES", annoes);
|
|
const TString& codmag = mask.get(F_CODMAG);
|
|
archivio_mag.set_var("#CODMAG", codmag);
|
|
//il codice terminale è il codice magazzino dell'agente selezionato sulla maschera..
|
|
//..poichè gli agenti devono avere codice lungo 3 zerofilled ed i magazzini Hardy sono..
|
|
//..lunghi 2 e numerici ->...
|
|
TString4 codage;
|
|
codage << 0 << codmag;
|
|
|
|
const long archivio_mag_items = archivio_mag.items();
|
|
|
|
TProgind progind(archivio_mag_items, TR("Ripristino magazzino..."), false, true);
|
|
for (bool ok = archivio_mag.move_first(); ok; ok = archivio_mag.move_next())
|
|
{
|
|
progind.addstatus(1);
|
|
|
|
ripristino.new_rec("");
|
|
|
|
ripristino.set("CodiceTerminale", codage);
|
|
ripristino.set("CodiceArticolo", archivio_mag.get(MAG_CODART));
|
|
real qta = archivio_mag.get(MAG_GIAC).as_real();
|
|
qta *= CENTO;
|
|
qta.round();
|
|
ripristino.set("QuantitaCaricata", qta);
|
|
ripristino.set("CodiceLotto", archivio_mag.get(MAG_LIVELLO));
|
|
}
|
|
|
|
return salva_recordset(ripristino, "carico");
|
|
}
|
|
|
|
//metodo di alto livello per la gestione delle chiamate
|
|
void TFile2Txt::elabora(const TMask& mask, TLog_report& log)
|
|
{
|
|
// a) stoppa il concentratore
|
|
// chiudi_concentratore();
|
|
|
|
//b) esegue le vere elaborazioni
|
|
//------------------------------
|
|
bool go_on = true;
|
|
|
|
if (mask.get_bool(F_AGENTI))
|
|
go_on = genera_agenti_txt();
|
|
|
|
if (mask.get_bool(F_CLIENTI) && go_on)
|
|
{
|
|
const long da_codcli = mask.get_long(F_DA_CODCLI);
|
|
go_on = genera_clienti_txt(da_codcli);
|
|
}
|
|
|
|
if (mask.get_bool(F_SOSPESI) && go_on)
|
|
{
|
|
const long da_codcli = mask.get_long(F_DA_SOSP_CODCLI);
|
|
go_on = genera_sospesi_txt(da_codcli);
|
|
}
|
|
|
|
if (mask.get_bool(F_LISTINI) && go_on)
|
|
go_on = genera_righelistini_txt();
|
|
|
|
if (mask.get_bool(F_CONTRATTI) && go_on)
|
|
go_on = genera_contratti_txt();
|
|
|
|
if (mask.get_bool(F_PROMOZIONI) && go_on)
|
|
go_on = genera_promozioni_txt();
|
|
|
|
if (mask.get_bool(F_PRODOTTI) && go_on)
|
|
go_on = genera_prodotti_txt();
|
|
|
|
if (mask.get_bool(F_BARCODE) && go_on)
|
|
go_on = genera_barcode_txt();
|
|
|
|
if (mask.get_bool(F_DECODART) && go_on)
|
|
go_on = genera_decodart_txt();
|
|
|
|
if (mask.get_bool(F_ATTREZZA) && go_on)
|
|
go_on = genera_attrezzature_txt();
|
|
|
|
if (mask.get_bool(F_TABPAG) && go_on)
|
|
go_on = genera_tabpag_txt();
|
|
|
|
if (mask.get_bool(F_CARICO) && go_on)
|
|
go_on = genera_carico_txt(mask);
|
|
|
|
if (mask.get_bool(F_INIMAG) && go_on)
|
|
go_on = genera_ripristino_txt(mask);
|
|
|
|
if (mask.get_bool(F_CONSUMI) && go_on)
|
|
go_on = genera_consumi_txt(mask);
|
|
|
|
/* Per il momento preferiscono agire manualmente
|
|
//c) lancia il concentratore in modalità di carico
|
|
carica_concentratore();
|
|
|
|
//d) rilancia il concentratore in modalità di trasmissione
|
|
trasmetti_concentratore();
|
|
*/
|
|
}
|
|
|
|
TMask* TFile2Txt::create_mask() const
|
|
{
|
|
TMask* mask = new TFile2Txt_mask;
|
|
mask->set(F_OUTPUT_PATH, _output_path);
|
|
//mask->set(F_CONC_PATH, _conc_path);
|
|
//mask->set(F_TRANS_PATH, _trans_path);
|
|
return mask;
|
|
}
|
|
|
|
const char* TFile2Txt::fake_trans_file() const
|
|
{ return "157"; }
|
|
|
|
int ha1200(int argc, char* argv[])
|
|
{
|
|
TFile2Txt a;
|
|
a.run(argc, argv, TR("Generazione .txt da archivi"));
|
|
return 0;
|
|
}
|