Trasferimento anagrafiche clienti/fornitori
git-svn-id: svn://10.65.10.50/branches/R_10_00@23134 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
21d8c1f8f7
commit
2cf261e01a
BIN
bs/BeeStore - Analisi Interfaccia SW Terzi.doc
Normal file
BIN
bs/BeeStore - Analisi Interfaccia SW Terzi.doc
Normal file
Binary file not shown.
@ -39,19 +39,25 @@ bool TParametri_mask::on_field_event(TOperable_field& o, TField_event e, long jo
|
||||
|
||||
class TParametri_ditta : public TConfig_application
|
||||
{
|
||||
TParametri_mask* _pm;
|
||||
|
||||
protected:
|
||||
virtual TMask* create_mask(const TFilename& fname);
|
||||
virtual TMask* get_mask() { return _pm; }
|
||||
virtual void destroy_mask() { delete _pm; }
|
||||
|
||||
public:
|
||||
virtual bool check_autorization() const { return false; }
|
||||
virtual const char* get_mask_name() const { return "bs0100a"; }
|
||||
|
||||
TParametri_ditta() : TConfig_application(CONFIG_DITTA) {}
|
||||
TParametri_ditta() : TConfig_application(CONFIG_DITTA), _pm(NULL) {}
|
||||
};
|
||||
|
||||
TMask* TParametri_ditta::create_mask(const TFilename& fname)
|
||||
{
|
||||
return new TParametri_mask(fname);
|
||||
if (_pm == NULL)
|
||||
_pm = new TParametri_mask(fname);
|
||||
return _pm;
|
||||
}
|
||||
|
||||
int bs0100(int argc, char* argv[])
|
||||
|
@ -4,7 +4,7 @@ ENDPAGE
|
||||
|
||||
PAGE "Parametri Bee Store" 0 2 0 0
|
||||
|
||||
GROUPBOX DLG_NULL 78 5
|
||||
GROUPBOX DLG_NULL 78 4
|
||||
BEGIN
|
||||
PROMPT 1 1 "@bODBC"
|
||||
END
|
||||
|
584
bs/bs0200.cpp
584
bs/bs0200.cpp
@ -1,17 +1,59 @@
|
||||
#include <applicat.h>
|
||||
#include <assoc.h>
|
||||
#include <automask.h>
|
||||
#include <config.h>
|
||||
#include <ODBCrset.h>
|
||||
#include <progind.h>
|
||||
#include <reputils.h>
|
||||
#include <utility.h>
|
||||
|
||||
#include "../mg/mglib.h"
|
||||
#include "../cg/cglib01.h"
|
||||
|
||||
#include "bs0.h"
|
||||
|
||||
#include "../fe/felib.h"
|
||||
#include "../ve/condv.h"
|
||||
#include "../ve/rcondv.h"
|
||||
|
||||
#include <comuni.h>
|
||||
#include <clifo.h>
|
||||
#include <cfven.h>
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TBeeStore_cache
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class TBeeStore_cache : TCache
|
||||
{
|
||||
protected:
|
||||
virtual TObject* key2obj(const char* key)
|
||||
{
|
||||
const char tipo = *key;
|
||||
const long codice = atol(key+1);
|
||||
return new TAnagrafica(LF_CLIFO, tipo, codice);
|
||||
}
|
||||
|
||||
public:
|
||||
const TAnagrafica& anag(char tipo, long codice)
|
||||
{
|
||||
CHECKD((tipo == 'C' || tipo == 'F') && codice > 0L, "Codice cli/for non valido", codice);
|
||||
TString8 key; key.format("%c%06ld", tipo, codice);
|
||||
const TAnagrafica* a = (const TAnagrafica*)objptr(key);
|
||||
return *a;
|
||||
}
|
||||
const TAnagrafica& anag(const TRectype& rec)
|
||||
{
|
||||
const char tipo = rec.get_char(CLI_TIPOCF);
|
||||
const long codice = rec.get_long(CLI_CODCF);
|
||||
return anag(tipo, codice);
|
||||
}
|
||||
const TAnagrafica& anag(const TISAM_recordset& rec)
|
||||
{ return anag(rec.cursor()->curr()); }
|
||||
};
|
||||
|
||||
static TBeeStore_cache _anagr;
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TBeeStore_mask
|
||||
///////////////////////////////////////////////////////////
|
||||
@ -64,17 +106,25 @@ void TBeeStore_mask::autosave() const
|
||||
// TBeeStore_sync
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
typedef bool TFieldEvaluator(const TISAM_recordset& rec, const char* fldname, const char* expr, TVariant& var);
|
||||
|
||||
class TBeeStore_sync : public TSkeleton_application
|
||||
{
|
||||
TString16 _dsn;
|
||||
TFilename _sqlog;
|
||||
TLog_report* _log;
|
||||
|
||||
private:
|
||||
const TString& comune(const TRecordset& recset, const char* fld_cap, const char* fld_den) const;
|
||||
bool split_phone(const TRecordset& odbc, const char* number, TIsamfile& clifo, const char* pre, const char* num) const;
|
||||
void load_clifo(char tipocf);
|
||||
void save_clifo(const TDate& dal, const TDate& al);
|
||||
|
||||
protected:
|
||||
bool save_and_delete_doc(TMov_mag*& doc) const;
|
||||
|
||||
void load_origine_1(TISAM_recordset& out_set, const char* in_table, const TString_array& pairs);
|
||||
void save_origine_2(TISAM_recordset& in_set, const char* out_table, const TString_array& pairs);
|
||||
void save_origine_2(TISAM_recordset& in_set, const char* out_table, const TString_array& pairs, TFieldEvaluator* feval = NULL);
|
||||
|
||||
void sync_table(TISAM_recordset& in_set, const char* out_table,
|
||||
const TString_array& pairs);
|
||||
@ -89,7 +139,9 @@ protected:
|
||||
void sync_catmer (const TDate& dal, const TDate& al);
|
||||
void sync_val (const TDate& dal, const TDate& al);
|
||||
void sync_anamag (const TDate& dal, const TDate& al);
|
||||
void sync_barcode (const TDate& dal, const TDate& al);
|
||||
void sync_scontrini(const TDate& dal, const TDate& al);
|
||||
void sync_clifo (const TDate& dal, const TDate& al);
|
||||
void sync_listino (const TString& listino);
|
||||
|
||||
public:
|
||||
@ -154,7 +206,38 @@ const TString& var2sql(const TVariant& var)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// Carica da Bee Store i record con Origine=1, cioè generati da lui ed eventualmente aggiorna i corrispondenti in Campo
|
||||
// Coverte una qualsiasi espressione in stringa SQL
|
||||
const TString& expr2sql(const TISAM_recordset& set, const char* expr)
|
||||
{
|
||||
TVariant var;
|
||||
TExpression e(expr, _strexpr, true);
|
||||
if (e.numvar() == 0)
|
||||
{
|
||||
if (real::is_natural(expr))
|
||||
var = atoi(expr);
|
||||
else
|
||||
var = expr;
|
||||
} else
|
||||
if (e.numvar() == 1 && xvt_str_same(e.varname(0), expr))
|
||||
{
|
||||
var = set.get(expr);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int v = e.numvar()-1; v >= 0; v--)
|
||||
{
|
||||
var = set.get(e.varname(v));
|
||||
if (var.is_real() || var.is_bool())
|
||||
e.setvar(v, var.as_real());
|
||||
else
|
||||
e.setvar(v, var.as_string());
|
||||
}
|
||||
var = e.as_string();
|
||||
}
|
||||
return var2sql(var);
|
||||
}
|
||||
|
||||
// Carica da BeeStore i record con Origine=1, cioè generati da lui ed eventualmente aggiorna i corrispondenti in Campo
|
||||
void TBeeStore_sync::load_origine_1(TISAM_recordset& out_set, const char* in_table, const TString_array& pairs)
|
||||
{
|
||||
TString str(255);
|
||||
@ -162,7 +245,8 @@ void TBeeStore_sync::load_origine_1(TISAM_recordset& out_set, const char* in_tab
|
||||
FOR_EACH_ARRAY_ROW(pairs, f, row)
|
||||
str << row->get(0) << ',';
|
||||
str.rtrim(1); // toglie ultima virgola
|
||||
str << "\nFROM " << in_table << " WHERE Origine=1;";
|
||||
str << "\nFROM " << in_table << " WHERE (Origine=1);";
|
||||
|
||||
TODBC_recordset odbc(str);
|
||||
const TRecnotype n = odbc.items();
|
||||
if (n > 0)
|
||||
@ -208,7 +292,7 @@ void TBeeStore_sync::load_origine_1(TISAM_recordset& out_set, const char* in_tab
|
||||
TDate dtultagg = odbc.get("DtUltAgg").as_date();
|
||||
if (!dtultagg.ok()) dtultagg = TODAY;
|
||||
|
||||
str.format("record");
|
||||
str = "record";
|
||||
FOR_EACH_TOKEN(key_fields, f)
|
||||
str << ' ' << file.get(f);
|
||||
|
||||
@ -233,7 +317,8 @@ void TBeeStore_sync::load_origine_1(TISAM_recordset& out_set, const char* in_tab
|
||||
}
|
||||
if (dirty)
|
||||
{
|
||||
file.put("UTENTE", "BEESTORE");
|
||||
if (file.curr().exist("UTENTE"))
|
||||
file.put("UTENTE", "BEESTORE");
|
||||
file.put("DATAAGG", dtultagg);
|
||||
}
|
||||
else
|
||||
@ -287,7 +372,7 @@ void TBeeStore_sync::load_origine_1(TISAM_recordset& out_set, const char* in_tab
|
||||
}
|
||||
}
|
||||
|
||||
void TBeeStore_sync::save_origine_2(TISAM_recordset& in_set, const char* out_table, const TString_array& fields)
|
||||
void TBeeStore_sync::save_origine_2(TISAM_recordset& in_set, const char* out_table, const TString_array& fields, TFieldEvaluator* fval)
|
||||
{
|
||||
const TRecnotype n = in_set.items();
|
||||
TString str(255);
|
||||
@ -297,14 +382,17 @@ void TBeeStore_sync::save_origine_2(TISAM_recordset& in_set, const char* out_tab
|
||||
str.cut(0) << "DELETE FROM " << out_table << " WHERE Origine=2;";
|
||||
odbc.exec(str);
|
||||
|
||||
str.format(TR("Esportazione %ld record nella tabella %s"), n, out_table);
|
||||
str.format(TR("Esportazione %ld record in %s"), n, out_table);
|
||||
_log->log(0, "");
|
||||
_log->log(0, str);
|
||||
|
||||
const TRectype& curr = in_set.cursor()->curr();
|
||||
|
||||
TProgress_monitor pi(n, str);
|
||||
for (bool ok = in_set.move_first(); ok; ok = in_set.move_next())
|
||||
{
|
||||
str.cut(0) << "INSERT INTO " << out_table << " (";
|
||||
|
||||
str.cut(0) << "INSERT INTO " << out_table << "\n(";
|
||||
FOR_EACH_ARRAY_ROW(fields, sr, srow)
|
||||
str << (sr ? ", " : "") << srow->get(0);
|
||||
str << ", Origine, Errore, DTUltAgg";
|
||||
@ -312,17 +400,24 @@ void TBeeStore_sync::save_origine_2(TISAM_recordset& in_set, const char* out_tab
|
||||
|
||||
FOR_EACH_ARRAY_ROW(fields, ir, irow)
|
||||
{
|
||||
if (ir)
|
||||
if (ir) str << ", ";
|
||||
if (fval)
|
||||
{
|
||||
str << ", ";
|
||||
if (str.len() - str.rfind('\n') > 80)
|
||||
str << '\n';
|
||||
const char* fname = irow->get(0);
|
||||
const char* fexpr = irow->get();
|
||||
TVariant var;
|
||||
if (fval(in_set, fname, fexpr, var))
|
||||
{
|
||||
str << var2sql(var);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
const TFixed_string cfld = irow->get(1);
|
||||
if (cfld.find("SCONTO")>=0)
|
||||
{
|
||||
real sconto;
|
||||
const TString& exp = in_set.get(cfld).as_string();
|
||||
const TString& exp = curr.get(cfld);
|
||||
if (exp.full())
|
||||
{
|
||||
if (real::is_natural(exp))
|
||||
@ -339,24 +434,39 @@ void TBeeStore_sync::save_origine_2(TISAM_recordset& in_set, const char* out_tab
|
||||
}
|
||||
str << var2sql(sconto);
|
||||
} else
|
||||
if (cfld[0] >= 'A' && cfld[0] <= 'Z')
|
||||
{
|
||||
const TVariant& var = in_set.get(cfld);
|
||||
str << var2sql(var);
|
||||
} else
|
||||
if (cfld.find("->") > 0)
|
||||
{
|
||||
const TVariant& var = in_set.get(cfld);
|
||||
str << var2sql(var);
|
||||
}
|
||||
if ((cfld[0] >= 'A' && cfld[0] <= 'Z') || cfld.find("->") > 0)
|
||||
str << expr2sql(in_set, cfld);
|
||||
else
|
||||
str << cfld;
|
||||
}
|
||||
|
||||
str << ", 2, 0, GETDATE()";
|
||||
str << ");";
|
||||
|
||||
if (odbc.exec(str) <= 0)
|
||||
const long err = odbc.exec(str);
|
||||
if (err <= 0)
|
||||
{
|
||||
TParagraph_string par(str, 75);
|
||||
if (par.items() > 4)
|
||||
{
|
||||
str.cut(0);
|
||||
bool values = false;
|
||||
FOR_EACH_TOKEN(par, s)
|
||||
{
|
||||
if (str.full() && !values)
|
||||
{
|
||||
values = _strnicmp(s, "VALUES", 6) == 0;
|
||||
if (!values)
|
||||
continue;
|
||||
}
|
||||
str << s << '\n';
|
||||
}
|
||||
str.trim();
|
||||
}
|
||||
_log->log(1, str);
|
||||
str.format("SQL error %d", abs(err));
|
||||
_log->log(2, str);
|
||||
}
|
||||
|
||||
if (!pi.add_status())
|
||||
break;
|
||||
@ -371,24 +481,40 @@ void TBeeStore_sync::sync_table(TISAM_recordset& in_set, const char* out_table,
|
||||
save_origine_2(in_set, out_table, fields);
|
||||
}
|
||||
|
||||
TString& append_select_range(TString& q, const TDate& dal, const TDate& al)
|
||||
static TString& build_query(const char* table, const TDate& dal, const TDate& al)
|
||||
{
|
||||
q << "\nSELECT (UTENTE!=\"BEESTORE\")";
|
||||
TString& q = get_tmp_string();
|
||||
q << "USE " << table;
|
||||
if (dal.ok() || al.ok())
|
||||
q << "SELECT BETWEEN(DATAAGG," << dal.date2ansi() << ',' << al.date2ansi() << ")";
|
||||
return q;
|
||||
}
|
||||
|
||||
static TString& build_query(const int logicnum, const TDate& dal, const TDate& al)
|
||||
{
|
||||
const TRectype rec(logicnum);
|
||||
TString& q = get_tmp_string();
|
||||
q << "USE " << logicnum;
|
||||
|
||||
if (rec.exist("UTENTE"))
|
||||
q << " SELECT (UTENTE!=\"BEESTORE\")";
|
||||
|
||||
if ((dal.ok() || al.ok()) && rec.exist("DATAAGG"))
|
||||
{
|
||||
q << "&&(BETWEEN(DATAAGG,"
|
||||
<< dal.date2ansi() << ',' << al.date2ansi() << "))";
|
||||
if (q.find(" SELECT ") < 0)
|
||||
q << " SELECT ";
|
||||
else
|
||||
q << "&&";
|
||||
q << "(BETWEEN(DATAAGG," << dal.date2ansi() << ',' << al.date2ansi() << "))";
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
void TBeeStore_sync::sync_table(const char* table, const char* out_table,
|
||||
const TString_array& fields, const TDate& dal, const TDate& al)
|
||||
{
|
||||
TString q;
|
||||
q << "USE " << table;
|
||||
append_select_range(q, dal, al);
|
||||
|
||||
const TString& q = build_query(table, dal, al);
|
||||
TISAM_recordset set(q);
|
||||
sync_table(set, out_table, fields);
|
||||
}
|
||||
@ -396,8 +522,9 @@ void TBeeStore_sync::sync_table(const char* table, const char* out_table,
|
||||
void TBeeStore_sync::sync_table(const int logicnum, const char* out_table,
|
||||
const TString_array& fields, const TDate& dal, const TDate& al)
|
||||
{
|
||||
TString4 q; q << logicnum;
|
||||
sync_table(q, out_table, fields, dal, al);
|
||||
const TString& q = build_query(logicnum, dal, al);
|
||||
TISAM_recordset set(q);
|
||||
sync_table(set, out_table, fields);
|
||||
}
|
||||
|
||||
void TBeeStore_sync::sync_ums(const TDate& dal, const TDate& al)
|
||||
@ -425,10 +552,12 @@ void TBeeStore_sync::sync_lines(const TDate& dal, const TDate& al)
|
||||
fields.add("CodLinea|CODTAB");
|
||||
fields.add("DSLinea|S0");
|
||||
|
||||
TString query;
|
||||
query << "USE GMC";
|
||||
append_select_range(query, dal, al);
|
||||
query << "&&(CODTAB?='???')";
|
||||
TString query = build_query("GMC", dal, al);
|
||||
if (query.find("SELECT") < 0)
|
||||
query << " SELECT ";
|
||||
else
|
||||
query << "&&";
|
||||
query << "(CODTAB?='???')";
|
||||
|
||||
TISAM_recordset lin(query);
|
||||
sync_table(lin, "tieLineeArt", fields);
|
||||
@ -456,9 +585,7 @@ void TBeeStore_sync::sync_anamag(const TDate& dal, const TDate& al)
|
||||
fields.add("CodCategMerceologica|"ANAMAG_GRMERC);
|
||||
fields.add("Bloccato|"ANAMAG_SOSPESO);
|
||||
|
||||
TString query;
|
||||
query << "USE " << LF_ANAMAG;
|
||||
append_select_range(query, dal, al);
|
||||
TString query = build_query(LF_ANAMAG, dal, al);
|
||||
query << "\nJOIN " << LF_UMART << " INTO CODART==CODART";
|
||||
|
||||
TISAM_recordset art(query);
|
||||
@ -470,6 +597,362 @@ void TBeeStore_sync::sync_anamag(const TDate& dal, const TDate& al)
|
||||
save_origine_2(art, "tieArtVarianti", fields);
|
||||
}
|
||||
|
||||
void TBeeStore_sync::sync_barcode(const TDate& dal, const TDate& al)
|
||||
{
|
||||
TString_array fields;
|
||||
fields.add("CodArticolo|"ANAMAG_CODART);
|
||||
fields.add("BarCode|"ANAMAG_DESCR);
|
||||
|
||||
TString str(255);
|
||||
str << "ODBC(" << _dsn << ")\nSELECT ";
|
||||
FOR_EACH_ARRAY_ROW(fields, f, row)
|
||||
str << row->get(0) << ',';
|
||||
str.rtrim(1); // toglie ultima virgola
|
||||
str << "\nFROM tieArtBarCode WHERE (Origine=1);";
|
||||
|
||||
TODBC_recordset odbc(str);
|
||||
const TRecnotype n = odbc.items();
|
||||
if (n > 0)
|
||||
{
|
||||
TProgress_monitor pi(n, "Importazione codici a barre");
|
||||
for (bool go = odbc.move_first(); go; go = odbc.move_next())
|
||||
{
|
||||
const TCodice_articolo ca = odbc.get("CodArticolo").as_string();
|
||||
const TCodice_articolo bc = odbc.get("BarCode").as_string();
|
||||
int tipo = 0;
|
||||
switch (bc.len())
|
||||
{
|
||||
case 8: tipo = 8; break;
|
||||
case 13: tipo = 1; break;
|
||||
default: break;
|
||||
}
|
||||
if (tipo)
|
||||
{
|
||||
TRecord_array codcor(ca, LF_CODCORR);
|
||||
int n = 0;
|
||||
for (n = codcor.last_row(); n > 0; n = codcor.pred_row(n))
|
||||
{
|
||||
const TRectype& row = codcor.row(n);
|
||||
if (row.get("CODARTALT") == bc && row.get_int("TIPO") == tipo)
|
||||
break; // trovato!
|
||||
}
|
||||
if (n <= 0)
|
||||
{
|
||||
TRectype& row = codcor.row(-1, true); // Add new row
|
||||
row.put("CODARTALT", bc);
|
||||
row.put("TIPO", tipo);
|
||||
codcor.rewrite();
|
||||
}
|
||||
}
|
||||
if (!pi.add_status())
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool ClifoEvaluator(const TISAM_recordset& rec, const char* fldname, const char* expr, TVariant& var)
|
||||
{
|
||||
const TAnagrafica& a = _anagr.anag(rec);
|
||||
|
||||
if (xvt_str_same(fldname, "Cod_PK"))
|
||||
{
|
||||
TLocalisamfile& cfv = rec.cursor()->file(LF_CFVEN);
|
||||
TString80 codprcf = cfv.get(CFV_CODPRCF);
|
||||
if (codprcf.blank() || codprcf[0] == 'C') // Anagrafica gestita da Campo
|
||||
{
|
||||
const char t = cfv.get_char(CLI_TIPOCF);
|
||||
const long c = cfv.get_long(CLI_CODCF);
|
||||
TString8 cod_pk; cod_pk.format("C%06ld%c", c, t);
|
||||
if (cod_pk != codprcf)
|
||||
{
|
||||
cfv.put(CFV_CODPRCF, codprcf = cod_pk);
|
||||
cfv.rewrite();
|
||||
}
|
||||
}
|
||||
var = codprcf;
|
||||
return true;
|
||||
}
|
||||
if (xvt_str_same(fldname, "Cognome"))
|
||||
{
|
||||
if (a.fisica())
|
||||
var = a.cognome();
|
||||
return true;
|
||||
}
|
||||
if (xvt_str_same(fldname, "Nome"))
|
||||
{
|
||||
if (a.fisica())
|
||||
var = a.nome();
|
||||
return true;
|
||||
}
|
||||
if (xvt_str_same(fldname, "Indirizzo"))
|
||||
{
|
||||
TString ind;
|
||||
ind << a.via_residenza() << ',' << a.civico_residenza();
|
||||
const TString& loc = a.localita_residenza();
|
||||
if (loc.full()) ind << ',' << loc;
|
||||
ind.strip_double_spaces();
|
||||
var = ind;
|
||||
return true;
|
||||
}
|
||||
if (xvt_str_same(fldname, "Citta"))
|
||||
{
|
||||
var = a.comune_residenza();
|
||||
return true;
|
||||
}
|
||||
if (xvt_str_same(fldname, "Provincia"))
|
||||
{
|
||||
var = a.provincia_residenza();
|
||||
return true;
|
||||
}
|
||||
if (xvt_str_same(fldname, "ComuneNascita"))
|
||||
{
|
||||
var = a.comune_nascita();
|
||||
return true;
|
||||
}
|
||||
if (xvt_str_same(fldname, "PVNascita"))
|
||||
{
|
||||
var = a.provincia_nascita();
|
||||
return true;
|
||||
}
|
||||
if (xvt_str_same(fldname, "Telefono") || xvt_str_same(fldname, "Cellulare") || xvt_str_same(fldname, "CellulareSMS"))
|
||||
{
|
||||
const char* suff = (*fldname == 'C') ? (strlen(fldname)>9 ? "3" : "2") : "";
|
||||
TString8 pref; pref << "PTEL" << suff;
|
||||
TString80 tele; tele << "TEL" << suff;
|
||||
TString80 str; rec.get(pref).as_string(str); str << ' ' << rec.get(tele).as_string();
|
||||
str.strip_double_spaces();
|
||||
char* s = str.get_buffer();
|
||||
for (const char* f = s; *f; f++)
|
||||
{
|
||||
if (*f == ' ' || (*f >= '0' && *f <= '9'))
|
||||
{
|
||||
if (f > s) *s = *f;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
*s = '\0';
|
||||
}
|
||||
|
||||
if (xvt_str_same(fldname, "Tipo"))
|
||||
{
|
||||
var = a.fisica() ? 1 : 2;
|
||||
return true;
|
||||
}
|
||||
if (xvt_str_same(fldname, "Cliente"))
|
||||
{
|
||||
const char tipocf = rec.get(CLI_TIPOCF).as_string()[0];
|
||||
var = tipocf == 'C';
|
||||
return true;
|
||||
}
|
||||
if (xvt_str_same(fldname, "Fornitore"))
|
||||
{
|
||||
const char tipocf = rec.get(CLI_TIPOCF).as_string()[0];
|
||||
var = tipocf == 'F';
|
||||
return true;
|
||||
}
|
||||
if (_strnicmp(fldname,"Cli_",4) == 0)
|
||||
{
|
||||
const char tipocf = rec.get(CLI_TIPOCF).as_string()[0];
|
||||
return tipocf != 'C';
|
||||
}
|
||||
if (_strnicmp(fldname,"For_",4) == 0)
|
||||
{
|
||||
const char tipocf = rec.get(CLI_TIPOCF).as_string()[0];
|
||||
return tipocf != 'F';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const TString& TBeeStore_sync::comune(const TRecordset& recset, const char* fld_cap, const char* fld_den) const
|
||||
{
|
||||
TString8 cap; if (fld_cap && *fld_cap) cap = recset.get(fld_cap).as_string().left(5);
|
||||
TString80 den; if (fld_den && *fld_den) den = recset.get(fld_den).as_string();
|
||||
return ::cap2comune(cap, den);
|
||||
}
|
||||
|
||||
bool TBeeStore_sync::split_phone(const TRecordset& odbc, const char* number, TIsamfile& clifo, const char* pre, const char* num) const
|
||||
{
|
||||
TString pn = odbc.get(number).as_string();
|
||||
if (pn.full())
|
||||
{
|
||||
pn.strip_double_spaces();
|
||||
const int maxpref = clifo.curr().length(pre);
|
||||
int split = -1;
|
||||
for (int i = 0; pn[i] && i <= maxpref; i++)
|
||||
{
|
||||
if (!isdigit(pn[i]))
|
||||
{
|
||||
split = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (split > 1)
|
||||
{
|
||||
clifo.put(pre, pn.left(split));
|
||||
clifo.put(num, pn.mid(split+1));
|
||||
}
|
||||
else
|
||||
clifo.put(num, pn);
|
||||
}
|
||||
return pn.full();
|
||||
}
|
||||
|
||||
void TBeeStore_sync::load_clifo(char tipocf)
|
||||
{
|
||||
TString str(255);
|
||||
str << "ODBC(" << _dsn << ")\nSELECT * FROM tieAnagCFP WHERE (Origine=1)AND";
|
||||
str << '(' << (tipocf == 'F' ? "Fornitore" : "Cliente") << "=1);";
|
||||
|
||||
TFast_isamfile clifo(LF_CLIFO);
|
||||
|
||||
TODBC_recordset odbc(str);
|
||||
const TRecnotype n = odbc.items();
|
||||
|
||||
str.cut(0) << TR("Importazione ") << (tipocf == 'F' ? TR("Fornitori") : TR("Clienti"));
|
||||
TProgress_monitor pi(n, str);
|
||||
for (bool ok = odbc.move_first(); ok; ok = odbc.move_next())
|
||||
{
|
||||
long codcf = odbc.get(tipocf == 'F' ? "For_CodFor" : "Cli_CodCG").as_int();
|
||||
if (codcf <= 0)
|
||||
{
|
||||
const TString& cod_pk = odbc.get("Cod_PK").as_string();
|
||||
if (cod_pk[0] == 'C' && cod_pk.len() == 8 && cod_pk[7] == tipocf)
|
||||
codcf = atol(cod_pk.mid(1,6));
|
||||
}
|
||||
|
||||
if (codcf > 0)
|
||||
{
|
||||
clifo.put(CLI_TIPOCF, tipocf);
|
||||
clifo.put(CLI_CODCF, codcf);
|
||||
if (clifo.read(_isequal) != NOERR)
|
||||
{
|
||||
clifo.zero();
|
||||
clifo.put(CLI_TIPOCF, tipocf);
|
||||
clifo.put(CLI_CODCF, codcf);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
codcf = 1L;
|
||||
if (tipocf == 'F')
|
||||
{
|
||||
if (clifo.last() == NOERR && clifo.get_char(CLI_TIPOCF)=='F')
|
||||
codcf += clifo.get_long(CLI_CODCF);
|
||||
}
|
||||
else
|
||||
{
|
||||
clifo.put(CLI_TIPOCF, 'F');
|
||||
clifo.put(CLI_CODCF, 0);
|
||||
if (clifo.read(_isgteq) == NOERR)
|
||||
{
|
||||
if (clifo.prev() == NOERR && clifo.get_char(CLI_TIPOCF)=='C')
|
||||
codcf += clifo.get_long(CLI_CODCF);
|
||||
}
|
||||
}
|
||||
clifo.zero();
|
||||
clifo.put(CLI_TIPOCF, tipocf);
|
||||
clifo.put(CLI_CODCF, codcf);
|
||||
clifo.write();
|
||||
|
||||
TLocalisamfile cfv(LF_CFVEN);
|
||||
cfv.put(CFV_TIPOCF, tipocf);
|
||||
cfv.put(CFV_CODCF, codcf);
|
||||
TString8 codprcf; codprcf.format("C%06ld%c", codcf, tipocf);
|
||||
cfv.put(CFV_CODPRCF, codprcf);
|
||||
cfv.write();
|
||||
}
|
||||
clifo.put(CLI_RAGSOC, odbc.get("RagioneSociale").as_string());
|
||||
|
||||
const int tipo = odbc.get("Tipo").as_int(); // 1=Fisica; 2=Giuridica; 3=Aaltro
|
||||
if (tipo == 1)
|
||||
{
|
||||
clifo.put(CLI_SESSO, odbc.get("Sesso").as_string());
|
||||
clifo.put(CLI_DATANASC, odbc.get("DTNascita").as_date());
|
||||
clifo.put(CLI_COMNASC, comune(odbc, "", "ComuneNascita"));
|
||||
clifo.put(CLI_TIPOPERS, 'F');
|
||||
}
|
||||
else
|
||||
clifo.put(CLI_TIPOPERS, 'G');
|
||||
|
||||
TToken_string indirizzo(odbc.get("Indirizzo").as_string(), ',');
|
||||
TString ind = indirizzo.get(0);
|
||||
TString civ = indirizzo.get();
|
||||
TString loc = indirizzo.get();
|
||||
if (civ.len() > 10)
|
||||
{
|
||||
if (loc.full())
|
||||
ind << ' ' << civ;
|
||||
else
|
||||
loc = civ;
|
||||
civ.cut(0);
|
||||
}
|
||||
clifo.put(CLI_INDCF, ind.left(50));
|
||||
|
||||
split_phone(odbc, "Telefono", clifo, CLI_TEL, CLI_PTEL);
|
||||
split_phone(odbc, "Cellulare", clifo, CLI_TEL2, CLI_PTEL2);
|
||||
split_phone(odbc, "CellulareSMS", clifo, CLI_TEL3, CLI_PTEL3);
|
||||
|
||||
clifo.put(CLI_UTENTE, "BEESTORE");
|
||||
TDate dua = odbc.get("DtUltAgg").as_date();
|
||||
if (!dua.ok()) dua = TDate(TODAY);
|
||||
clifo.put(CLI_DATAAGG, dua);
|
||||
|
||||
clifo.rewrite();
|
||||
|
||||
if (!pi.add_status())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void TBeeStore_sync::save_clifo(const TDate& dal, const TDate& al)
|
||||
{
|
||||
TString_array fields;
|
||||
fields.add("Cod_PK|"CLI_CODCF);
|
||||
fields.add("RagSoc|"CLI_RAGSOC);
|
||||
fields.add("Cognome|"CLI_RAGSOC);
|
||||
fields.add("Nome|"CLI_RAGSOC);
|
||||
fields.add("Indirizzo|"CLI_INDCF);
|
||||
fields.add("Citta|"CLI_COMCF);
|
||||
fields.add("Cap|"CLI_CAPCF);
|
||||
fields.add("Provincia|");
|
||||
fields.add("Telefono|TEL");
|
||||
fields.add("Cellulare|TEL2");
|
||||
fields.add("CellulareSMS|TEL3");
|
||||
fields.add("EMail|"CLI_MAIL);
|
||||
fields.add("PartitaIva|"CLI_PAIV);
|
||||
fields.add("CodFiscale|"CLI_COFI);
|
||||
fields.add("Tipo|1");
|
||||
fields.add("Sesso|"CLI_SESSO);
|
||||
fields.add("DTNascita|"CLI_DATANASC);
|
||||
fields.add("ComuneNascita|"CLI_COMNASC);
|
||||
fields.add("PVNascita|");
|
||||
fields.add("Cliente|");
|
||||
fields.add("Fornitore|");
|
||||
fields.add("For_CodFor|"CLI_CODCF);
|
||||
fields.add("For_Blocco|"CLI_SOSPESO);
|
||||
fields.add("Cli_CodCG|"CLI_CODCF);
|
||||
fields.add("Cli_Blocco|"CLI_SOSPESO);
|
||||
fields.add("MagInserAnagrafica|1");
|
||||
fields.add("CodStato|"CLI_STATOCF);
|
||||
fields.add("Annullato|0");
|
||||
|
||||
TString query = build_query(LF_CLIFO, dal, al);
|
||||
query << "\nJOIN " << LF_CFVEN << " INTO TIPOCF==TIPOCF CODCF==CODCF";
|
||||
|
||||
TISAM_recordset clifo(query);
|
||||
save_origine_2(clifo, "tieAnagCFP", fields, ClifoEvaluator);
|
||||
}
|
||||
|
||||
void TBeeStore_sync::sync_clifo(const TDate& dal, const TDate& al)
|
||||
{
|
||||
load_clifo('C');
|
||||
load_clifo('F');
|
||||
save_clifo(dal, al);
|
||||
}
|
||||
|
||||
bool TBeeStore_sync::save_and_delete_doc(TMov_mag*& doc) const
|
||||
{
|
||||
int err = 0;
|
||||
@ -512,9 +995,10 @@ void TBeeStore_sync::sync_listino(const TString& listino)
|
||||
TODBC_recordset prz(str);
|
||||
|
||||
str = "DELETE FROM tiePrzVendita WHERE Origine=1";
|
||||
prz.exec(str);
|
||||
prz.exec(str); // Ignora tutti i listini di BeeStore
|
||||
|
||||
str.cut(0) << "USE " << LF_RCONDV
|
||||
str.cut(0) << "USE " << LF_RCONDV << " SELECT " << LF_ANAMAG << ".CODART!=\"\""
|
||||
<< "\nJOIN " << LF_ANAMAG << " INTO CODART==CODRIGA"
|
||||
<< "\nFROM TIPO=L TIPORIGA=A COD=" << listino
|
||||
<< "\nTO TIPO=L TIPORIGA=A COD=" << listino;
|
||||
TISAM_recordset lis(str);
|
||||
@ -555,7 +1039,7 @@ void TBeeStore_sync::sync_listino(const TString& listino)
|
||||
|
||||
void TBeeStore_sync::sync_scontrini(const TDate& dal, const TDate& al)
|
||||
{
|
||||
const TString8 codcaus = ini_get_string(CONFIG_DITTA, "bs", MOVMAG_CODCAUS);
|
||||
const TString8 codcaus = ini_get_string(CONFIG_DITTA, "bs", MOVMAG_CODCAUS);
|
||||
if (codcaus.blank())
|
||||
{
|
||||
_log->log(2, "Configurare parametri per movimenti Bee Store");
|
||||
@ -603,10 +1087,13 @@ void TBeeStore_sync::sync_scontrini(const TDate& dal, const TDate& al)
|
||||
rdoc.put(RMOVMAG_CODART, mov.get("CodArticolo").as_string());
|
||||
rdoc.put(RMOVMAG_UM, mov.get("CodUntMis").as_string());
|
||||
rdoc.put(RMOVMAG_PREZZO, mov.get("PrzCassaValuta").as_real());
|
||||
if (!pi.add_status())
|
||||
break;
|
||||
}
|
||||
save_and_delete_doc(doc); // Salva ultimo documento in sospeso
|
||||
}
|
||||
|
||||
|
||||
bool TBeeStore_sync::create()
|
||||
{
|
||||
_dsn = ini_get_string(CONFIG_DITTA, "bs", "DSN", "BEESTORE");
|
||||
@ -614,8 +1101,7 @@ bool TBeeStore_sync::create()
|
||||
|
||||
if (_dsn.full())
|
||||
{
|
||||
TTimerind ti(10, TR("Connessione a SQL Server"), false, false);
|
||||
ti.force_update();
|
||||
TProgress_monitor ti(1, TR("Connessione a SQL Server"), false);
|
||||
TString query; query << "ODBC(" << _dsn << ")\nSELECT * FROM tieValute;";
|
||||
TODBC_recordset recset(query);
|
||||
recset.move_first();
|
||||
@ -654,8 +1140,12 @@ void TBeeStore_sync::main_loop()
|
||||
sync_catmer(dal, al);
|
||||
if (mask.get_bool("SyncAnamag"))
|
||||
sync_anamag(dal, al);
|
||||
if (mask.get_bool("SyncBarCode"))
|
||||
sync_barcode(dal, al);
|
||||
if (mask.get_bool("SyncVAL"))
|
||||
sync_val(dal, al);
|
||||
if (mask.get_bool("SyncClifo"))
|
||||
sync_clifo(dal, al);
|
||||
if (mask.get("SyncListino").full())
|
||||
sync_listino(mask.get("SyncListino"));
|
||||
if (mask.get_bool("SyncSontr"))
|
||||
@ -671,6 +1161,6 @@ void TBeeStore_sync::main_loop()
|
||||
int bs0200(int argc, char* argv[])
|
||||
{
|
||||
TBeeStore_sync bss;
|
||||
bss.run(argc, argv, TR("Bee Store"));
|
||||
bss.run(argc, argv, TR("BeeStore Synchronizer"));
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
TOOLBAR "topbar" 0 0 0 2
|
||||
#include <stdbar.h>
|
||||
#include <elabar.h>
|
||||
ENDPAGE
|
||||
|
||||
PAGE "Sincronizzazione Bee Store" 0 2 0 0
|
||||
@ -69,6 +69,19 @@ BEGIN
|
||||
FIELD SyncVAL
|
||||
END
|
||||
|
||||
BOOLEAN 152
|
||||
BEGIN
|
||||
PROMPT 40 3 "Clienti/Fornitori"
|
||||
FIELD SyncClifo
|
||||
END
|
||||
|
||||
BOOLEAN 153
|
||||
BEGIN
|
||||
PROMPT 40 4 "Codici a barre"
|
||||
FIELD SyncBarCode
|
||||
END
|
||||
|
||||
|
||||
GROUPBOX DLG_NULL 78 8
|
||||
BEGIN
|
||||
PROMPT 1 10 "@bFiltri"
|
||||
|
Loading…
x
Reference in New Issue
Block a user