Files correlati : bs0.exe Commento : aggiunto un meccanismo di trace nell'importazione bee store Interno: Si attiva mettendo nel paragrafo Main di studio.ini TRACE = X
2005 lines
56 KiB
C++
2005 lines
56 KiB
C++
#include <applicat.h>
|
||
#include <automask.h>
|
||
#include <config.h>
|
||
#include <ODBCrset.h>
|
||
#include <progind.h>
|
||
#include <prefix.h>
|
||
#include <reputils.h>
|
||
#include <tabutil.h>
|
||
#include <utility.h>
|
||
#include "../mg/mglib.h"
|
||
#include "../cg/cglib.h"
|
||
#include "../ve/velib.h"
|
||
#include <doc.h>
|
||
#include <rdoc.h>
|
||
#include "bs0.h"
|
||
#include "bs0500a.h"
|
||
#include "../fe/felib.h"
|
||
#include "../ve/condv.h"
|
||
#include "../ve/rcondv.h"
|
||
#include <comuni.h>
|
||
#include <clifo.h>
|
||
#include <cfven.h>
|
||
#include <rcausali.h>
|
||
#include <transaction.h>
|
||
#include "bsutility.h"
|
||
|
||
#define BS_DTULTAGG "DtUltAgg"
|
||
#define BS_POSNUMDOC 4
|
||
#define BS_FREEROW "-1"
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TImporta_cache
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TImporta_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 TImporta_cache _anagr;
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TImporta_Beestore_mask
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TImporta_Beestore_mask : public TAutomask
|
||
{
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
||
public:
|
||
void autoload();
|
||
void autosave() const;
|
||
|
||
bool get_bool(const char* fld)
|
||
{
|
||
TMask_field* f = find_by_fieldname(fld); return f ? f->get().full() : false;
|
||
}
|
||
|
||
TDate get_date(const char* fld)
|
||
{
|
||
TMask_field* f = find_by_fieldname(fld); return TDate(f ? f->get() : EMPTY_STRING);
|
||
}
|
||
|
||
TImporta_Beestore_mask() : TAutomask("BS0500A") { autoload(); }
|
||
~TImporta_Beestore_mask() { autosave(); }
|
||
};
|
||
|
||
bool TImporta_Beestore_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
if (e == fe_modify && !o.empty())
|
||
{
|
||
const TFieldref* fr = o.field();
|
||
if (fr && fr->name() == "CODCAUSC")
|
||
{
|
||
// Configura righe aggiuntive causale corrispettivi
|
||
TRecord_array rcaus(o.get(), LF_RCAUSALI);
|
||
if (!rcaus.exist(15) && yesno_box(TR("Si desidera configurare la causale per il collegamento a BeeStore?")))
|
||
{
|
||
const char* codice[] = { "BEECN", "BEEBM", "BEECC", "BEEAS", "BEEAL", NULL };
|
||
const char* descr[] = { "Contanti", "Bancomat", "Carta di credito", "Assegni", "Altro", NULL };
|
||
|
||
TTable dpn("%DPN");
|
||
for (int i = 0; codice[i]; i++)
|
||
{
|
||
dpn.put("CODTAB", codice[i]);
|
||
dpn.put("S0", descr[i]);
|
||
dpn.write();
|
||
TRectype& row = rcaus.row(15 + i, true);
|
||
row.put(RCA_CODDESC, codice[i]);
|
||
row.put(RCA_DESC, descr[i]);
|
||
}
|
||
rcaus.rewrite();
|
||
TRectype caus(LF_CAUSALI);
|
||
caus.put(RCA_CODCAUS, o.get());
|
||
caus.edit();
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
void TImporta_Beestore_mask::autoload()
|
||
{
|
||
// Carica i valori default dei parametri dal [bs] in ditta,ini
|
||
FOR_EACH_MASK_FIELD(*this, i, f)
|
||
{
|
||
const TFieldref* fr = f->field();
|
||
if (fr != NULL)
|
||
{
|
||
const TString & name = fr->name();
|
||
|
||
if ( (name == "ImpIMPPARTDOC") || (name == "ImpDoc") || (name == "ImpDirectWrite") )
|
||
f->set(ini_get_bool(CONFIG_DITTA, "BS0500A", name, true) ? "X" : " ");
|
||
else
|
||
f->set(ini_get_string(CONFIG_DITTA, "BS0500A", name));
|
||
}
|
||
}
|
||
|
||
TSheet_field & s = sfield(F_CODNUM);
|
||
int i = 0;
|
||
TString16 suffisso = ini_get_string(CONFIG_DITTA, "BS0500A", "Suffisso", "", i);
|
||
|
||
while (i == 0 || suffisso.full())
|
||
{
|
||
s.set_row_cell(F_SUFFISSO, suffisso, i);
|
||
s.set_row_cell(F_COD_FATTURE, ini_get_string(CONFIG_DITTA, "BS0500A", "NumFatt", "", i), i);
|
||
s.set_row_cell(F_COD_NOTE, ini_get_string(CONFIG_DITTA, "BS0500A", "NumNote", "", i), i);
|
||
s.set_row_cell(F_COD_BOLLE, ini_get_string(CONFIG_DITTA, "BS0500A", "NumBolle", "", i), i);
|
||
s.set_row_cell(F_COD_CARSCAR, ini_get_string(CONFIG_DITTA, "BS0500A", "NumCarScar", "", i), i);
|
||
s.set_row_cell(F_COD_SCONTRINI, ini_get_string(CONFIG_DITTA, "BS0500A", "NumScontr", "", i), i);
|
||
s.set_row_cell(F_COD_GENERICI, ini_get_string(CONFIG_DITTA, "BS0500A", "NumGenerici", "", i), i);
|
||
s.set_row_cell(F_COD_ORDCLI, ini_get_string(CONFIG_DITTA, "BS0500A", "NumOrdcli", "", i), i);
|
||
suffisso = ini_get_string(CONFIG_DITTA, "BS0500A", "Suffisso", "", ++i);
|
||
}
|
||
}
|
||
|
||
void TImporta_Beestore_mask::autosave() const
|
||
{
|
||
// Salva i valori dei parametri in [bs] in ditta,ini
|
||
FOR_EACH_MASK_FIELD(*this, i, f)
|
||
{
|
||
const TFieldref* fr = f->field();
|
||
if (fr != NULL)
|
||
ini_set_string(CONFIG_DITTA, "BS0500A", fr->name(), f->get());
|
||
}
|
||
|
||
TSheet_field & s = sfield(F_CODNUM);
|
||
int rows = s.items();
|
||
int i = 0;
|
||
|
||
for (; i < rows; i++)
|
||
{
|
||
ini_set_string(CONFIG_DITTA, "BS0500A", "Suffisso", s.get_str_row_cell(i, F_SUFFISSO), i);
|
||
ini_set_string(CONFIG_DITTA, "BS0500A", "NumFatt", s.get_str_row_cell(i, F_COD_FATTURE), i);
|
||
ini_set_string(CONFIG_DITTA, "BS0500A", "NumNote", s.get_str_row_cell(i, F_COD_NOTE), i);
|
||
ini_set_string(CONFIG_DITTA, "BS0500A", "NumBolle", s.get_str_row_cell(i, F_COD_BOLLE), i);
|
||
ini_set_string(CONFIG_DITTA, "BS0500A", "NumCarScar", s.get_str_row_cell(i, F_COD_CARSCAR), i);
|
||
ini_set_string(CONFIG_DITTA, "BS0500A", "NumScontr", s.get_str_row_cell(i, F_COD_SCONTRINI), i);
|
||
ini_set_string(CONFIG_DITTA, "BS0500A", "NumGenerici",s.get_str_row_cell(i, F_COD_GENERICI), i);
|
||
ini_set_string(CONFIG_DITTA, "BS0500A", "NumOrdCli", s.get_str_row_cell(i, F_COD_ORDCLI), i);
|
||
}
|
||
while ((ini_get_string(CONFIG_DITTA, "BS0500A", "Suffisso", "", i)).full())
|
||
{
|
||
ini_remove(CONFIG_DITTA, "BS0500A", "Suffisso", i);
|
||
ini_remove(CONFIG_DITTA, "BS0500A", "NumFatt", i);
|
||
ini_remove(CONFIG_DITTA, "BS0500A", "NumNote", i);
|
||
ini_remove(CONFIG_DITTA, "BS0500A", "NumBolle", i);
|
||
ini_remove(CONFIG_DITTA, "BS0500A", "NumCarScar", i);
|
||
ini_remove(CONFIG_DITTA, "BS0500A", "NumScontr", i);
|
||
ini_remove(CONFIG_DITTA, "BS0500A", "NumGenerici", i);
|
||
ini_remove(CONFIG_DITTA, "BS0500A", "NumOrdCli", i);
|
||
i++;
|
||
}
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TImporta_Beestore
|
||
///////////////////////////////////////////////////////////
|
||
|
||
typedef bool TFieldEvaluator(const TISAM_recordset& rec, const char* fldname, const char* expr, TVariant& var);
|
||
typedef enum { imp_aggiungi = 1, imp_aggiorna, imp_entrambi } tipo_importazione;
|
||
|
||
class TImporta_Beestore : public TSkeleton_application
|
||
{
|
||
TString _dsn;
|
||
TString _usr;
|
||
TString _psw;
|
||
TFilename _sqlog;
|
||
TLog_report* _log;
|
||
bool _banche_pres_loaded;
|
||
TAssoc_array _banche_pres;
|
||
bool _direct_write;
|
||
bool _interactive;
|
||
tipo_importazione _tipo_imp;
|
||
|
||
TAssoc_array _nums;
|
||
|
||
bool fill_rec(TRectype & rec, TODBC_recordset& odbc, TAssoc_array& pairs, TString & log_str, const TDate dtultagg, bool fill_key = false);
|
||
bool fill_transaction(TTransaction & transaction, TRectype & rec, TODBC_recordset& odbc, TAssoc_array& pairs, TDate dtultagg);
|
||
bool fill_transaction(TTransaction & transaction, const char * table, TODBC_recordset& odbc, TAssoc_array& pairs, TDate dtultagg);
|
||
const char * build_query(const char* table, TAssoc_array& pairs);
|
||
const TString& comune(const TRecordset& recset, const char* fld_cap, const char* fld_den) const;
|
||
bool split_phone(const TRecordset& odbc, const char* number, TLocalisamfile& clifo, const char* pre, const char* num) const;
|
||
bool split_phone(const TRecordset& odbc, const char* number, TTransaction& transaction, const char* pre, const char* num) const;
|
||
void direct_clifo(char tipocf);
|
||
void transaction_clifo(char tipocf);
|
||
void save_clifo(int cfmask, const TDate& dal, const TDate& al);
|
||
const char * get_num(const TString & suffix, int tipotestata);
|
||
int tipotestata2idx(int tipotestata);
|
||
void add_nomenclatura(const char * nomenclatura);
|
||
|
||
protected:
|
||
bool save_and_delete_doc(TDocumento * doc) const;
|
||
|
||
void import_table(int logicnum, const char* table, TAssoc_array& pairs);
|
||
void import_table(const char * tab, const char* table, TAssoc_array& pairs);
|
||
void direct_table(int logicnum, TODBC_recordset & odbc, TAssoc_array& pairs);
|
||
void direct_table(const char * table, TODBC_recordset & odbc, TAssoc_array& pairs);
|
||
void transaction_table(int logicnum, TODBC_recordset & odbc, TAssoc_array& pairs);
|
||
void transaction_table(const char * table, TODBC_recordset & odbc, TAssoc_array& pairs);
|
||
|
||
void import_iva();
|
||
void import_ums();
|
||
void import_lines();
|
||
void import_catmer();
|
||
void import_val();
|
||
void import_anamag();
|
||
void import_barcode();
|
||
|
||
void direct_doc(TODBC_recordset & odbc, const char * table, const int tipotestata, const char* unitadefault, bool importadoc);
|
||
void transaction_doc(TODBC_recordset & odbc, const char * table, const int tipotestata, const char* unitadefault, bool importadoc);
|
||
void import_doc(const TDate& dal, const TDate& al, int tipotestata,const char* unitadefault, bool importadoc);
|
||
void import_clifo(int cfmask, const TDate& dal, const TDate& al);
|
||
|
||
TToken_string & decode_presentazione(const char* IBAN);
|
||
|
||
public:
|
||
virtual bool create();
|
||
virtual void main_loop();
|
||
};
|
||
|
||
// Carica da BeeStore i record con Origine=1, cio<69> generati da lui ed eventualmente aggiorna i corrispondenti in Campo
|
||
void TImporta_Beestore::add_nomenclatura(const char * nomenclatura)
|
||
{
|
||
if (nomenclatura && *nomenclatura && strlen(nomenclatura) == 8)
|
||
{
|
||
TRectype & rec = (TRectype &)cache().get("%NOC", nomenclatura);
|
||
|
||
if (rec.empty())
|
||
{
|
||
rec.put("CODTAB", nomenclatura);
|
||
rec.put("S0", "Da definire");
|
||
rec.write();
|
||
}
|
||
}
|
||
}
|
||
|
||
bool TImporta_Beestore::fill_rec(TRectype & rec, TODBC_recordset& odbc, TAssoc_array& pairs, TString & log_str, const TDate dtultagg, bool fill_key)
|
||
{
|
||
TString key_str(prefix().get_keyexpr(rec.num()));
|
||
bool dirty = false;
|
||
|
||
if (fill_key)
|
||
rec.zero();
|
||
FOR_EACH_ASSOC_STRING(pairs, obj, odbc_fld, fld)
|
||
{
|
||
bool in_key = key_str.find(fld) >= 0;
|
||
|
||
if ((fill_key && in_key) || (!fill_key && !in_key))
|
||
{
|
||
TString val = odbc.get_string(odbc_fld);
|
||
|
||
if (val.full())
|
||
{
|
||
const bool update = val != rec.get(fld);
|
||
|
||
dirty |= update;
|
||
if (odbc_fld == "codDogana")
|
||
{
|
||
val.strip(".");
|
||
if (val.len() <= 8)
|
||
{
|
||
val.lpad(8, '0');
|
||
add_nomenclatura(val);
|
||
}
|
||
else
|
||
{
|
||
_log->log(2, format(FR("Codice nomenclatura combinata %s errato, non e' stato importato"), (const char *)val));
|
||
continue;
|
||
}
|
||
rec.put(fld, val);
|
||
if (update)
|
||
log_str << " " << fld << "=" << val;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (dirty)
|
||
{
|
||
if (rec.exist(CLI_UTENTE))
|
||
rec.put(CLI_UTENTE, user());
|
||
if (rec.exist(CLI_DATAAGG))
|
||
rec.put(CLI_DATAAGG, dtultagg);
|
||
}
|
||
return dirty;
|
||
}
|
||
|
||
bool TImporta_Beestore::fill_transaction(TTransaction & transaction, TRectype & rec, TODBC_recordset& odbc, TAssoc_array& pairs, TDate dtultagg)
|
||
{
|
||
bool dirty = false;
|
||
|
||
FOR_EACH_ASSOC_STRING(pairs, obj, odbc_fld, fld)
|
||
{
|
||
TString val = odbc.get_string(odbc_fld);
|
||
const bool update = val != rec.get(fld);
|
||
|
||
if (val.full() && odbc_fld == "codDogana")
|
||
{
|
||
val.strip(".");
|
||
|
||
if (val.len() <= 8)
|
||
{
|
||
val.lpad(8, '0');
|
||
add_nomenclatura(val);
|
||
}
|
||
else
|
||
{
|
||
_log->log(2, format(FR("Codice nomenclatura combinata %s errato, non e' stato importato"), (const char *) val));
|
||
continue;
|
||
}
|
||
}
|
||
dirty |= update;
|
||
transaction.set(fld, val, -1, rec.num());
|
||
}
|
||
if (dirty)
|
||
{
|
||
if (rec.exist(CLI_UTENTE))
|
||
transaction.set(CLI_UTENTE, user(), -1, rec.num());
|
||
if (rec.exist(CLI_DATAAGG))
|
||
transaction.set(CLI_DATAAGG, dtultagg, -1, rec.num());
|
||
}
|
||
return dirty;
|
||
}
|
||
|
||
bool TImporta_Beestore::fill_transaction(TTransaction & transaction, const char * table, TODBC_recordset& odbc, TAssoc_array& pairs, TDate dtultagg)
|
||
{
|
||
FOR_EACH_ASSOC_STRING(pairs, obj, odbc_fld, fld)
|
||
{
|
||
const TString& val = odbc.get_string(odbc_fld);
|
||
transaction.set(fld, val, -1, table);
|
||
}
|
||
return true;
|
||
}
|
||
|
||
const char * TImporta_Beestore::build_query(const char* table, TAssoc_array& pairs)
|
||
{
|
||
TString_array fields;
|
||
TString & query = get_tmp_string(255);
|
||
|
||
pairs.get_keys(fields);
|
||
query << "SELECT ";
|
||
FOR_EACH_ARRAY_ROW(fields, f, row)
|
||
query << *row << ',';
|
||
query.rtrim(1); // toglie ultima virgola
|
||
query << "\nFROM " << table << " WHERE (Origine=1);";
|
||
return query;
|
||
}
|
||
|
||
void TImporta_Beestore::import_table(int logicnum, const char* table, TAssoc_array& pairs)
|
||
{
|
||
TString str;
|
||
TODBC_recordset odbc(build_query(table, pairs));
|
||
|
||
odbc.connect(_dsn, _usr, _psw);
|
||
|
||
const TRecnotype n = odbc.items();
|
||
TRACE("Importazione file %s", logicnum);
|
||
|
||
if (n > 0)
|
||
{
|
||
if (_direct_write)
|
||
direct_table(logicnum, odbc, pairs);
|
||
else
|
||
transaction_table(logicnum, odbc, pairs);
|
||
}
|
||
}
|
||
|
||
void TImporta_Beestore::import_table(const char * tab, const char* table, TAssoc_array& pairs)
|
||
{
|
||
TString str;
|
||
TODBC_recordset odbc(build_query(table, pairs));
|
||
|
||
odbc.connect(_dsn, _usr, _psw);
|
||
|
||
const TRecnotype n = odbc.items();
|
||
|
||
TRACE("Importazione tabella %s", tab);
|
||
if (n > 0)
|
||
{
|
||
if (_direct_write)
|
||
direct_table(tab, odbc, pairs);
|
||
else
|
||
transaction_table(tab, odbc, pairs);
|
||
}
|
||
}
|
||
|
||
void TImporta_Beestore::direct_table(int logicnum, TODBC_recordset & odbc, TAssoc_array& pairs)
|
||
{
|
||
TString str;
|
||
TLocalisamfile file(logicnum);
|
||
TRectype & rec = file.curr();
|
||
|
||
str.format(TR("Importazione %ld record dalla tabella %s"), odbc.items(), odbc.table_name());
|
||
_log->log(0, "");
|
||
_log->log(0, str);
|
||
TRACE(str);
|
||
|
||
TProgress_monitor pi(odbc.items(), str);
|
||
|
||
for (bool ok = odbc.move_first(); pi.add_status() && ok; ok = odbc.move_next())
|
||
{
|
||
TDate dtultagg = odbc.get(BS_DTULTAGG).as_date();
|
||
|
||
if (!dtultagg.ok())
|
||
dtultagg = TODAY;
|
||
str = "Record";
|
||
fill_rec(rec, odbc, pairs, str, dtultagg, true);
|
||
int err = file.read(_isequal, _lock);
|
||
const bool elab = (err == NOERR && (_tipo_imp != imp_aggiungi)) ||
|
||
(err != NOERR && (_tipo_imp != imp_aggiorna));
|
||
|
||
if (elab)
|
||
{
|
||
if (err == NOERR)
|
||
{
|
||
bool dirty = false;
|
||
const TDate dataagg = rec.get(CLI_DATAAGG);
|
||
|
||
if (dtultagg >= dataagg)
|
||
{
|
||
dirty = fill_rec(rec, odbc, pairs, str, dtultagg);
|
||
if (!dirty)
|
||
str << " Nessuna variazione pertinente";
|
||
}
|
||
else
|
||
str << " Data di ultimo aggiornamento obsoleta";
|
||
if (dirty)
|
||
{
|
||
if ((err = file.rewrite()) == NOERR)
|
||
_log->log(0, str);
|
||
else
|
||
{
|
||
TString80 err; err << TR("ERRORE ") << err << TR(" aggiornando il ");
|
||
str.insert(err);
|
||
_log->log(2, str);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_log->log(0, str);
|
||
file.reread(_unlock);
|
||
}
|
||
}
|
||
else
|
||
if (err == _iskeynotfound)
|
||
{
|
||
str = "Record";
|
||
fill_rec(rec, odbc, pairs, str, dtultagg, true);
|
||
fill_rec(rec, odbc, pairs, str, dtultagg);
|
||
if ((err = file.write()) == NOERR)
|
||
_log->log(1, str);
|
||
else
|
||
{
|
||
TString80 msg; msg << TR("ERRORE ") << err << TR(" inserendo il ");
|
||
str.insert(msg);
|
||
_log->log(2, str);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void TImporta_Beestore::direct_table(const char * tab, TODBC_recordset & odbc, TAssoc_array& pairs)
|
||
{
|
||
TString str;
|
||
TTable table(tab);
|
||
TRectype & rec = table.curr();
|
||
|
||
str.format(TR("Importazione %ld record dalla tabella %s"), odbc.items(), odbc.table_name());
|
||
_log->log(0, "");
|
||
_log->log(0, str);
|
||
TRACE(str);
|
||
|
||
TProgress_monitor pi(odbc.items(), str);
|
||
|
||
for (bool ok = odbc.move_first(); pi.add_status() && ok; ok = odbc.move_next())
|
||
{
|
||
TDate dtultagg = odbc.get(BS_DTULTAGG).as_date();
|
||
|
||
if (!dtultagg.ok())
|
||
dtultagg = TODAY;
|
||
str = "Record";
|
||
fill_rec(rec, odbc, pairs, str, dtultagg, true);
|
||
int err = table.read(_isequal, _lock);
|
||
const bool elab = (err == NOERR && (_tipo_imp != imp_aggiungi)) ||
|
||
(err != NOERR && (_tipo_imp != imp_aggiorna));
|
||
|
||
if (elab)
|
||
{
|
||
if (err == NOERR)
|
||
{
|
||
bool dirty = false;
|
||
const TDate dataagg = rec.get(CLI_DATAAGG);
|
||
|
||
if (dtultagg >= dataagg)
|
||
{
|
||
if (!(dirty = fill_rec(rec, odbc, pairs, str, dtultagg)))
|
||
str << " Nessuna variazione pertinente";
|
||
}
|
||
else
|
||
str << " Data di ultimo aggiornamento obsoleta";
|
||
if (dirty)
|
||
{
|
||
if ((err = table.rewrite()) == NOERR)
|
||
_log->log(0, str);
|
||
else
|
||
{
|
||
TString80 err; err << TR("ERRORE ") << err << TR(" aggiornando il ");
|
||
str.insert(err);
|
||
_log->log(2, str);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_log->log(0, str);
|
||
table.reread(_unlock);
|
||
}
|
||
}
|
||
else
|
||
if (err == _iskeynotfound)
|
||
{
|
||
str = "Record";
|
||
fill_rec(rec, odbc, pairs, str, dtultagg, true);
|
||
fill_rec(rec, odbc, pairs, str, dtultagg);
|
||
if ((err = table.write()) == NOERR)
|
||
_log->log(1, str);
|
||
else
|
||
{
|
||
TString80 msg; msg << TR("ERRORE ") << err << TR(" inserendo il ");
|
||
str.insert(msg);
|
||
_log->log(2, str);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// Carica da BeeStore i record con Origine=1, cio<69> generati da lui ed eventualmente aggiorna i corrispondenti in Campo
|
||
void TImporta_Beestore::transaction_table(int logicnum, TODBC_recordset & odbc, TAssoc_array& pairs)
|
||
{
|
||
TString str;
|
||
TLocalisamfile file(logicnum);
|
||
TRectype & rec = file.curr();
|
||
|
||
str.format(TR("Importazione %ld record dalla tabella %s"), odbc.items(), odbc.table_name());
|
||
_log->log(0, "");
|
||
_log->log(0, str);
|
||
TRACE(str);
|
||
|
||
TProgress_monitor pi(odbc.items(), str);
|
||
TArray transactions;
|
||
|
||
for (bool ok = odbc.move_first(); pi.add_status() && ok; ok = odbc.move_next())
|
||
{
|
||
TString prefix("F"); prefix << logicnum;
|
||
TTransaction t(TFilename().temp(prefix));
|
||
TDate dtultagg = odbc.get_date(BS_DTULTAGG);
|
||
|
||
if (!dtultagg.ok()) dtultagg = TODAY;
|
||
|
||
fill_rec(rec, odbc, pairs, str, dtultagg, true);
|
||
|
||
const bool found = rec.read() == NOERR;
|
||
const TDate dataagg = rec.get(CLI_DATAAGG);
|
||
const bool elab = (found && (_tipo_imp != imp_aggiungi)) ||
|
||
(!found && (_tipo_imp != imp_aggiorna));
|
||
|
||
if (elab)
|
||
{
|
||
if (found)
|
||
{
|
||
if (dtultagg > dataagg)
|
||
{
|
||
t.set_action(TRANSACTION_MODIFY);
|
||
t.set_mode(transaction_mode_automatic);
|
||
t.set_stop_on_error(false);
|
||
t.set_caller("BEESTORE");
|
||
t.set_firm(get_firm());
|
||
if (fill_transaction(t, rec, odbc, pairs, dtultagg))
|
||
transactions.add(t);
|
||
else
|
||
{
|
||
str << " Nessuna variazione pertinente";
|
||
_log->log(0, str);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
str << " Data di ultimo aggiornamento obsoleta";
|
||
_log->log(0, str);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
t.set_action(TRANSACTION_INSERT);
|
||
t.set_mode(transaction_mode_automatic);
|
||
t.set_stop_on_error(false);
|
||
t.set_caller("BEESTORE");
|
||
t.set_firm(get_firm());
|
||
fill_transaction(t, rec, odbc, pairs, dtultagg);
|
||
transactions.add(t);
|
||
}
|
||
}
|
||
execute_transactions(transactions, *_log, _interactive, str);
|
||
}
|
||
}
|
||
|
||
// Carica da BeeStore i record con Origine=1, cio<69> generati da lui ed eventualmente aggiorna i corrispondenti in Campo
|
||
void TImporta_Beestore::transaction_table(const char * table, TODBC_recordset & odbc, TAssoc_array& pairs)
|
||
{
|
||
TString str;
|
||
TTable file(table);
|
||
TRectype & rec = file.curr();
|
||
|
||
str.format(TR("Importazione %ld record dalla tabella %s"), odbc.items(), odbc.table_name());
|
||
_log->log(0, "");
|
||
_log->log(0, str);
|
||
TRACE(str);
|
||
|
||
TProgress_monitor pi(odbc.items(), str);
|
||
|
||
TArray transactions;
|
||
|
||
for (bool ok = odbc.move_first(); pi.add_status() && ok; ok = odbc.move_next())
|
||
{
|
||
TString prefix("F"); prefix << table;
|
||
TTransaction t(TFilename().temp(prefix), table);
|
||
|
||
fill_rec(rec, odbc, pairs, str, nulldate, true);
|
||
|
||
const bool found = rec.read() == NOERR;
|
||
const bool elab = (found && (_tipo_imp != imp_aggiungi)) ||
|
||
(!found && (_tipo_imp != imp_aggiorna));
|
||
|
||
if (elab)
|
||
{
|
||
if (found)
|
||
{
|
||
t.set_action(TRANSACTION_MODIFY);
|
||
t.set_mode(transaction_mode_automatic);
|
||
t.set_stop_on_error(false);
|
||
t.set_caller("BEESTORE");
|
||
t.set_firm(get_firm());
|
||
if (fill_transaction(t, rec, odbc, pairs, nulldate))
|
||
transactions.add(t);
|
||
else
|
||
{
|
||
str << " Nessuna variazione pertinente";
|
||
_log->log(0, str);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
t.set_action(TRANSACTION_INSERT);
|
||
t.set_mode(transaction_mode_automatic);
|
||
t.set_stop_on_error(false);
|
||
t.set_caller("BEESTORE");
|
||
t.set_firm(get_firm());
|
||
fill_transaction(t, rec, odbc, pairs, nulldate);
|
||
transactions.add(t);
|
||
}
|
||
}
|
||
execute_transactions(transactions, *_log, _interactive, str);
|
||
}
|
||
}
|
||
|
||
void TImporta_Beestore::import_ums()
|
||
{
|
||
TAssoc_array fields;
|
||
|
||
fields.add("CodUntMis", "CODTAB");
|
||
fields.add("DSUntMis", "S0");
|
||
TRACE("Unit<EFBFBD> di misura");
|
||
import_table("%UMS", "tieUntMisura", fields);
|
||
}
|
||
|
||
void TImporta_Beestore::import_iva()
|
||
{
|
||
TAssoc_array fields;
|
||
|
||
fields.add("CodIva", "CODTAB");
|
||
fields.add("CodIvaSt", "CODTAB");
|
||
fields.add("DSIva", "S0");
|
||
fields.add("Aliquota", "R0");
|
||
TRACE("IVA");
|
||
import_table("%IVA", "tieIva", fields);
|
||
}
|
||
|
||
void TImporta_Beestore::import_lines()
|
||
{
|
||
TAssoc_array fields;
|
||
|
||
fields.add("CodLinea", "CODTAB");
|
||
fields.add("DSLinea", "S0");
|
||
TRACE("Linee");
|
||
import_table("GMC", "tieLineeArt", fields);
|
||
}
|
||
|
||
void TImporta_Beestore::import_catmer()
|
||
{
|
||
TAssoc_array fields;
|
||
|
||
fields.add("CodCategoriaMerceologica", "CODTAB");
|
||
fields.add("DSCategoriaMerceologica", "S0");
|
||
// fields.add("CodTipoEtichetta", ""); a che serviva ?
|
||
TRACE("Categorie merceologiche");
|
||
import_table("GMC", "tieCategorieMerceologiche", fields);
|
||
}
|
||
|
||
void TImporta_Beestore::import_anamag()
|
||
{
|
||
TAssoc_array fields;
|
||
|
||
fields.add("CodPadre", ANAMAG_CODART);
|
||
fields.add("DSArticolo", ANAMAG_DESCR);
|
||
fields.add("DSArticoloAgg", ANAMAG_DESCRAGG);
|
||
fields.add("CodIva", ANAMAG_CODIVA);
|
||
fields.add("CodCategMerceologica", ANAMAG_GRMERC);
|
||
fields.add("Bloccato", ANAMAG_SOSPESO);
|
||
fields.add("codDogana", ANAMAG_CLASSDOG);
|
||
TRACE("Anagrafica di magazzino");
|
||
if (_direct_write)
|
||
{
|
||
import_table(LF_ANAMAG, "tieArticoli", fields);
|
||
fields.destroy();
|
||
fields.add("CodPadre", ANAMAG_CODART);
|
||
fields.add("@1", UMART_NRIGA);
|
||
fields.add("CodUntMagazzino", UMART_UM);
|
||
import_table(LF_UMART, "tieArticoli", fields);
|
||
}
|
||
else
|
||
{
|
||
fields.add("CodPadre", FIELD_NAME(LF_UMART, UMART_CODART));
|
||
fields.add("@1", FIELD_NAME(LF_UMART, UMART_NRIGA));
|
||
fields.add("CodUntMagazzino", FIELD_NAME(LF_UMART, UMART_UM));
|
||
import_table(LF_ANAMAG, "tieArticoli", fields);
|
||
}
|
||
import_barcode();
|
||
}
|
||
|
||
void TImporta_Beestore::import_barcode()
|
||
{
|
||
TString_array fields;
|
||
|
||
fields.add("CodArticolo|" ANAMAG_CODART);
|
||
fields.add("BarCode|" ANAMAG_DESCR);
|
||
|
||
TString str(255);
|
||
str << "SELECT ";
|
||
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);
|
||
odbc.connect(_dsn, _usr, _psw);
|
||
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 TString & t = rec.get_string(CLI_TIPOCF);
|
||
const long c = rec.get_long(CLI_CODCF);
|
||
TString8 cod_pk; cod_pk.format("C%06ld%s", c, (const char *) 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();
|
||
if (ind.full())
|
||
{
|
||
const TString& civ = a.civico_residenza();
|
||
if (civ.full()) ind << ',' << civ;
|
||
}
|
||
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_string(pref);
|
||
|
||
str << ' ' << rec.get_string(tele);
|
||
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 TString& tipocf = rec.get_string(CLI_TIPOCF);
|
||
|
||
var = tipocf == "C";
|
||
return true;
|
||
}
|
||
if (xvt_str_same(fldname, "Fornitore"))
|
||
{
|
||
const TString& tipocf = rec.get_string(CLI_TIPOCF);
|
||
|
||
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& TImporta_Beestore::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 TImporta_Beestore::split_phone(const TRecordset& odbc, const char* number, TLocalisamfile& clifo, const char* pre, const char* num) const
|
||
{
|
||
TString pn = odbc.get_string(number);
|
||
|
||
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(pre, "");
|
||
clifo.put(num, pn);
|
||
}
|
||
}
|
||
return pn.full();
|
||
}
|
||
|
||
bool TImporta_Beestore::split_phone(const TRecordset& odbc, const char* number, TTransaction& transaction, const char* pre, const char* num) const
|
||
{
|
||
TString pn = odbc.get_string(number);
|
||
|
||
if (pn.full())
|
||
{
|
||
pn.strip_double_spaces();
|
||
|
||
const int len = pn.len();
|
||
int split = -1;
|
||
|
||
for (int i = 0; i <= len; i++)
|
||
{
|
||
if (!isdigit(pn[i]))
|
||
{
|
||
split = i;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (split > 1)
|
||
{
|
||
transaction.set(pre, pn.left(split), -1, LF_CLIFO);
|
||
transaction.set(num, pn.mid(split + 1), -1, LF_CLIFO);
|
||
}
|
||
else
|
||
transaction.set(num, pn, -1, LF_CLIFO);
|
||
}
|
||
return pn.full();
|
||
}
|
||
|
||
void TImporta_Beestore::direct_clifo(char tipocf)
|
||
{
|
||
TString str(255);
|
||
str << "SELECT * FROM tieAnagCFP WHERE (Origine=1)AND";
|
||
str << '(' << (tipocf == 'F' ? "Fornitore" : " CLIente") << "=1);";
|
||
|
||
TLocalisamfile clifo(LF_CLIFO);
|
||
|
||
TODBC_recordset odbc(str);
|
||
odbc.connect(_dsn, _usr, _psw);
|
||
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(); pi.add_status() && 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));
|
||
}
|
||
|
||
clifo.zero();
|
||
clifo.put(CLI_TIPOCF, tipocf);
|
||
clifo.put(CLI_CODCF, codcf);
|
||
TRACE("%s %ld", tipocf == 'C' ? "Clienti" : "Fornitore", codcf);
|
||
|
||
const int err = clifo.read();
|
||
const bool elab = (err == NOERR && (_tipo_imp != imp_aggiungi)) ||
|
||
(err != NOERR && (_tipo_imp != imp_aggiorna));
|
||
|
||
if (elab)
|
||
{
|
||
if (err != NOERR)
|
||
{
|
||
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("RagSoc").as_string());
|
||
|
||
const int tipo = odbc.get("Tipo").as_int(); // 1=Fisica; 2=Giuridica; 3=Altro
|
||
|
||
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_PTEL, CLI_TEL);
|
||
split_phone(odbc, "Cellulare", clifo, CLI_PTEL2, CLI_TEL2);
|
||
split_phone(odbc, "CellulareSMS", clifo, CLI_PTEL3, CLI_TEL3);
|
||
clifo.put(CLI_MAIL, odbc.get("EMail").as_string());
|
||
|
||
clifo.put(CLI_UTENTE, user());
|
||
|
||
TDate dua = odbc.get_date(BS_DTULTAGG);
|
||
|
||
if (!dua.ok()) dua = TDate(TODAY);
|
||
clifo.put(CLI_DATAAGG, dua);
|
||
clifo.rewrite();
|
||
}
|
||
}
|
||
}
|
||
|
||
void TImporta_Beestore::transaction_clifo(char tipocf) // fare
|
||
{
|
||
TString str(255);
|
||
TArray transactions;
|
||
|
||
str << "SELECT * FROM tieAnagCFP WHERE (Origine=1)AND";
|
||
str << '(' << (tipocf == 'F' ? "Fornitore" : " CLIente") << "=1);";
|
||
|
||
TLocalisamfile clifo(LF_CLIFO);
|
||
TRectype & rec = clifo.curr();
|
||
TODBC_recordset odbc(str);
|
||
|
||
odbc.connect(_dsn, _usr, _psw);
|
||
|
||
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(); pi.add_status() && ok; ok = odbc.move_next())
|
||
{
|
||
TFilename f; f.temp("cf");
|
||
TTransaction t(f);
|
||
TDate dtultagg = odbc.get(BS_DTULTAGG).as_date();
|
||
long codcf = odbc.get_long(tipocf == 'F' ? "For_CodFor" : " CLI_CodCG");
|
||
|
||
if (!dtultagg.ok())
|
||
dtultagg = TODAY;
|
||
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));
|
||
}
|
||
|
||
rec.zero();
|
||
rec.put(CLI_TIPOCF, tipocf);
|
||
if (codcf > 0L)
|
||
rec.put(CLI_CODCF, codcf);
|
||
TRACE("%s %ld", tipocf == 'C' ? "Clienti" : "Fornitore", codcf);
|
||
|
||
bool found = clifo.read() == NOERR;
|
||
const bool elab = (found && (_tipo_imp != imp_aggiungi)) ||
|
||
(!found && (_tipo_imp != imp_aggiorna));
|
||
|
||
if (elab)
|
||
{
|
||
t.set_action(found ? TRANSACTION_MODIFY : TRANSACTION_INSERT);
|
||
t.set_mode(transaction_mode_automatic);
|
||
t.set_stop_on_error(false);
|
||
t.set_caller("BEESTORE");
|
||
t.set_firm(get_firm());
|
||
t.set(CLI_RAGSOC, odbc.get_string("RagSoc"), -1, LF_CLIFO);
|
||
|
||
const int tipo = odbc.get_int("Tipo"); // 1=Fisica; 2=Giuridica; 3=Altro
|
||
|
||
if (tipo == 1)
|
||
{
|
||
t.set(CLI_SESSO, odbc.get_string("Sesso"), -1, LF_CLIFO);
|
||
t.set(CLI_DATANASC, odbc.get_date("DTNascita"), -1, LF_CLIFO);
|
||
t.set(CLI_COMNASC, comune(odbc, "", "ComuneNascita"), -1, LF_CLIFO);
|
||
t.set(CLI_TIPOPERS, 'F', -1, LF_CLIFO);
|
||
}
|
||
else
|
||
t.set(CLI_TIPOPERS, 'G', -1, LF_CLIFO);
|
||
|
||
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);
|
||
}
|
||
t.set(CLI_INDCF, ind.left(50), -1, LF_CLIFO);
|
||
|
||
split_phone(odbc, "Telefono", clifo, CLI_PTEL, CLI_TEL);
|
||
split_phone(odbc, "Cellulare", clifo, CLI_PTEL2, CLI_TEL2);
|
||
split_phone(odbc, "CellulareSMS", clifo, CLI_PTEL3, CLI_TEL3);
|
||
t.set(CLI_MAIL, odbc.get_string("EMail"), -1, LF_CLIFO);
|
||
t.set(CFV_CODPRCF, format("C%06ld%c", codcf, tipocf), -1, LF_CFVEN, 1);
|
||
t.set(CLI_UTENTE, "BEESTORE", -1, LF_CLIFO);
|
||
|
||
TDate dataagg = odbc.get_date(BS_DTULTAGG);
|
||
|
||
if (!dataagg.ok())
|
||
dataagg = TDate(TODAY);
|
||
|
||
t.set(CLI_DATAAGG, dataagg, -1, LF_CLIFO);
|
||
transactions.add(t);
|
||
}
|
||
execute_transactions(transactions, *_log, _interactive, str);
|
||
}
|
||
}
|
||
|
||
void TImporta_Beestore::import_clifo(int cfmask, const TDate& dal, const TDate& al)
|
||
{
|
||
TRACE("Clienti/Fonitori");
|
||
if (_direct_write)
|
||
{
|
||
if (cfmask & 1) direct_clifo('C');
|
||
if (cfmask & 2) direct_clifo('F');
|
||
}
|
||
else
|
||
{
|
||
if (cfmask & 1) transaction_clifo('C');
|
||
if (cfmask & 2) transaction_clifo('F');
|
||
}
|
||
}
|
||
|
||
|
||
void TImporta_Beestore::import_val()
|
||
{
|
||
TAssoc_array fields;
|
||
|
||
fields.add("CodValuta", "CODTAB");
|
||
fields.add("DSValuta2", "S0");
|
||
fields.add("Simbolo", "CODTAB");
|
||
TRACE("Valute");
|
||
import_table("%VAL", "tieValute", fields);
|
||
}
|
||
|
||
int TImporta_Beestore::tipotestata2idx(int tipotestata)
|
||
{
|
||
switch (tipotestata)
|
||
{
|
||
case 1:
|
||
return 2;
|
||
break;
|
||
case 2:
|
||
break;
|
||
case 6:
|
||
return 1;
|
||
break;
|
||
case 9:
|
||
return 6;
|
||
break;
|
||
case 11:
|
||
return 3;
|
||
break;
|
||
case 13:
|
||
return 4;
|
||
break;
|
||
case 14:
|
||
return 5;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
const char * TImporta_Beestore::get_num(const TString & suffix, int tipotestata)
|
||
{
|
||
TString key(suffix);
|
||
|
||
key.trim();
|
||
|
||
TToken_string * nums = (TToken_string *) _nums.objptr(key);
|
||
|
||
if (nums == nullptr)
|
||
nums = (TToken_string *) _nums.objptr(EMPTY_STRING);
|
||
if (nums == nullptr)
|
||
fatal_box(TR("Array delle numerazioni non valido"));
|
||
return nums->get(tipotestata2idx(tipotestata));
|
||
}
|
||
|
||
bool TImporta_Beestore::save_and_delete_doc(TDocumento* doc) const
|
||
{
|
||
int err = 0;
|
||
if (doc != nullptr)
|
||
{
|
||
if (doc->rows() > 0)
|
||
{
|
||
err = doc->write();
|
||
if (err != NOERR)
|
||
{
|
||
TString msg;
|
||
|
||
msg.format(FR("Errore %d in registrazione documento %s/%ld del %s"), err,
|
||
(const char *)doc->get(DOC_CODNUM), doc->get_long(DOC_NDOC), (const char*)doc->get(DOC_DATADOC));
|
||
_log->log(2, msg);
|
||
msg << TR("\nSi desidera proseguire ugualmente?");
|
||
if (noyes_box(msg))
|
||
err = 0;
|
||
}
|
||
}
|
||
safe_delete(doc);
|
||
}
|
||
return err == 0;
|
||
}
|
||
|
||
void TImporta_Beestore::direct_doc(TODBC_recordset & docs, const char * table, const int tipotestata, const char* unitadefault, bool importadoc)
|
||
{
|
||
TString msg(TR("Importazione ")); msg << table;
|
||
TProgress_monitor pi(docs.items(), msg);
|
||
long last = -1, ndoc, codcf;
|
||
TString4 tipocf;
|
||
TToken_string codtestata("", '\\');
|
||
TDocumento* doc = nullptr;
|
||
int contatore = 0;
|
||
int eccezioni_errori = 0;
|
||
TString codpk = "";
|
||
bool elab = false;
|
||
long numdoc;
|
||
|
||
for (bool ok = docs.move_first(); ok; ok = docs.move_next())
|
||
{
|
||
TString wrk = docs.get_string("CodCliente");
|
||
|
||
codtestata = docs.get_string("CodTestata");
|
||
ndoc = codtestata.get_long(BS_POSNUMDOC);
|
||
while (wrk[0] >= 'A')
|
||
wrk.ltrim(1);
|
||
codcf = atol(wrk);
|
||
tipocf = docs.get("TipoIntestatario").as_string();
|
||
|
||
TToken_string key = tipocf;
|
||
|
||
key.add(codcf);
|
||
if (cache().get(LF_CLIFO, key).empty())
|
||
{
|
||
TString msg; msg.format("Attenzione! Per il doc n. %d e' presente il tipo C/F = '%s' con cod = %d \nIl documento verra' saltato.", ndoc, (const char*)tipocf, codcf);
|
||
_log->log(1, msg);
|
||
continue;
|
||
}
|
||
|
||
TString8 tipodoc = tipotestata != 14 ? docs.get_string("TipoDocCE") : get_num("", 14);
|
||
|
||
if (ndoc != last)
|
||
{
|
||
if (ndoc > 0)
|
||
{
|
||
elab = (!doc->nuovo() && (_tipo_imp != imp_aggiungi)) ||
|
||
(doc->nuovo() && (_tipo_imp != imp_aggiorna));
|
||
|
||
if (elab)
|
||
{
|
||
if (!save_and_delete_doc(doc))
|
||
break;
|
||
}
|
||
else
|
||
safe_delete(doc);
|
||
}
|
||
last = ndoc;
|
||
|
||
const TDate datadoc = docs.get_date("DataDoc");
|
||
TString cod_pk = docs.get_string("Cod_PK");
|
||
|
||
TString origine_dc = docs.get_string("Origine");
|
||
|
||
if (tipodoc.full())
|
||
{
|
||
TTipo_documento tipo(tipodoc);
|
||
const TString8 codcaus = tipo.caus_mov();
|
||
TString str = docs.get_string("NumDoc");
|
||
|
||
numdoc = ndoc;
|
||
while (str[0] > 'A')
|
||
str.ltrim(1);
|
||
if (str.full())
|
||
numdoc = atol(str);
|
||
TRACE("%s n. %ld", table, numdoc);
|
||
doc = new TDocumento('D', datadoc.year(), get_num(docs.get_string("SuffNum"), tipotestata), numdoc);
|
||
doc->destroy_rows();
|
||
doc->put(DOC_DATADOC, datadoc);
|
||
doc->put(DOC_TIPODOC, tipodoc);
|
||
if (tipotestata != 14)
|
||
{
|
||
doc->put(DOC_TIPOCF, tipocf);
|
||
doc->put(DOC_CODCF, codcf);
|
||
doc->cli2doc();
|
||
|
||
const TString8 codval = docs.get_string("CodValuta");
|
||
const real cambio = docs.get_string("CambioValuta");
|
||
const TString asp = docs.get_string("AspettoBeni");
|
||
const int ncolli = docs.get_int("NumeroColli");
|
||
// inserire codice pagamento Es. BB02
|
||
doc->put(DOC_CODVAL, codval);
|
||
doc->put(DOC_CAMBIO, cambio);
|
||
|
||
doc->put(DOC_CODPAG, docs.get_string("CodPagamento_FP"));
|
||
doc->put(DOC_CODABIA, docs.get_string("ABI")); //banca di appoggio
|
||
doc->put(DOC_CODCABA, docs.get_string("CAB"));
|
||
|
||
TToken_string bnpkey = decode_presentazione(docs.get_string("NostroContoCorr"));
|
||
|
||
doc->put(DOC_CODABIP, bnpkey.get()); //banca di presentazione
|
||
doc->put(DOC_CODCABP, bnpkey.get());
|
||
doc->put(DOC_PROGBNP, bnpkey.get()); //banca di presentazione
|
||
|
||
doc->put(DOC_NOTE, asp); // l'aspetto dei beni <20> una stringa la devo mettere nelle note
|
||
doc->put(DOC_NCOLLI, ncolli);
|
||
doc->put(DOC_CAUSMAG, codcaus);
|
||
}
|
||
contatore++;
|
||
}
|
||
else
|
||
{
|
||
eccezioni_errori++;
|
||
codpk = cod_pk;
|
||
TString dserrore = docs.get("DSErrore").as_string();
|
||
dserrore.sleft(50);
|
||
dserrore << " TipoDocCe assente o invalido";
|
||
TString update_str = "";
|
||
update_str << "UPDATE tieTBolFat \n SET Errore = 1 , DSErrore = '" << dserrore << "' \n WHERE cod_pk= '" << codpk << "' ";
|
||
TODBC_recordset docs(update_str);
|
||
docs.connect(_dsn, _usr, _psw);
|
||
docs.exec(update_str);
|
||
}
|
||
}
|
||
if (tipodoc.full())
|
||
{
|
||
const int tipoart = docs.get_int("TipoArticolo");
|
||
TRectype& rdoc = doc->new_row("01");
|
||
TString80 codart = docs.get_string("IDArticolo");
|
||
TRACE("%s n. %ld riga %d", table, numdoc, rdoc.get_int(RDOC_NRIGA));
|
||
|
||
if (codart.blank())
|
||
codart = docs.get_string("CodArticolo");
|
||
if (codart == BS_FREEROW)
|
||
codart = "";
|
||
|
||
TString descrizione = docs.get_string("Modello");
|
||
if (descrizione.blank())
|
||
descrizione = docs.get_string("DSRiga");
|
||
if (codart.full())
|
||
{
|
||
rdoc.put(RDOC_CODART, codart);
|
||
if (importadoc && tipoart == 0)
|
||
{
|
||
rdoc.put(RDOC_CODARTMAG, codart);
|
||
rdoc.put(RDOC_CHECKED, "X");
|
||
if (cache().get(LF_ANAMAG, codart).empty())
|
||
{
|
||
TArticolo articolo;
|
||
articolo.put(ANAMAG_CODART, codart);
|
||
|
||
articolo.put(ANAMAG_DESCR, descrizione);
|
||
TString nomenclatura = docs.get_string("CodDogana");
|
||
if (nomenclatura.blank())
|
||
nomenclatura = docs.get_string("CodCategoria");
|
||
nomenclatura.strip(".");
|
||
|
||
if (nomenclatura.len() <= 8)
|
||
{
|
||
nomenclatura.lpad(8, '0');
|
||
add_nomenclatura(nomenclatura);
|
||
articolo.put(ANAMAG_CLASSDOG, nomenclatura);
|
||
}
|
||
else
|
||
_log->log(2, format(FR("Codice nomenclatura combinata %s errato, non e' stato importato"), (const char *) nomenclatura));
|
||
|
||
TRectype& umart = articolo.new_row(LF_UMART);
|
||
TString unitamisura = docs.get_string("CodUntMis");
|
||
if (unitamisura.blank())
|
||
unitamisura = unitadefault;
|
||
umart.put(UMART_UM, unitamisura);
|
||
umart.put(UMART_FC, 1);
|
||
articolo.write();
|
||
}
|
||
}
|
||
if (tipoart == 2) //righe libere
|
||
{
|
||
if (cache().get("SPP", codart).not_empty())
|
||
rdoc.put(RDOC_CODARTMAG, codart);
|
||
}
|
||
else //spese servizi e articoli
|
||
{
|
||
if (cache().get(LF_ANAMAG, codart).not_empty())
|
||
rdoc.put(RDOC_CODARTMAG, codart);
|
||
}
|
||
|
||
rdoc.put(RDOC_CODARTMAG, codart);
|
||
}
|
||
rdoc.put(RDOC_DESCR, descrizione.sleft(50));
|
||
if (descrizione.len() > 50)
|
||
{
|
||
rdoc.put(RDOC_DESCLUNGA, "X");
|
||
rdoc.put(RDOC_DESCEST, descrizione.smid(50));
|
||
}
|
||
rdoc.put(RDOC_CODMAG, docs.get_string("CodMagazzino").left(5));
|
||
rdoc.put(RDOC_CODMAGC, docs.get_string("CodMagazDest").left(5));
|
||
|
||
TString unitamisura = docs.get_string("CodUntMis");
|
||
|
||
if (unitamisura.blank())
|
||
unitamisura = unitadefault;
|
||
rdoc.put(RDOC_UMQTA, docs.get_string("CodUntMis"));
|
||
rdoc.put(RDOC_QTA, docs.get_real("Quantita"));
|
||
rdoc.put(RDOC_PREZZO, docs.get_real("PrzNettoNeg")); // o PrzNettoValuta ??
|
||
rdoc.put(RDOC_CODIVA, docs.get_string("CodIva"));
|
||
|
||
}
|
||
else
|
||
{
|
||
TString dserrore = docs.get("DSErrore").as_string();
|
||
dserrore.sleft(50);
|
||
dserrore << " TipoDocCe assente o invalido";
|
||
TString update_str = "";
|
||
update_str << "UPDATE tieDMovMag \n SET Errore = 1 , DSErrore = '" << dserrore << "' \n WHERE CodTestata= '" << codpk << "' ";
|
||
TODBC_recordset docs(update_str);
|
||
docs.connect(_dsn, _usr, _psw);
|
||
docs.exec(update_str);
|
||
}
|
||
if (!pi.add_status())
|
||
break;
|
||
|
||
}
|
||
elab = (!doc->nuovo() && (_tipo_imp != imp_aggiungi)) ||
|
||
(doc->nuovo() && (_tipo_imp != imp_aggiorna));
|
||
|
||
if (elab)
|
||
save_and_delete_doc(doc); // Salva ultimo documento in sospeso
|
||
else
|
||
safe_delete(doc);
|
||
msg = TR("Documenti importati ");
|
||
msg << contatore << " in " << table;
|
||
_log->log(0, "");
|
||
_log->log(0, msg);
|
||
if (eccezioni_errori > 0)
|
||
{
|
||
msg = TR("Errori in importazione ");
|
||
msg << eccezioni_errori << " in " << table;
|
||
_log->log(2, msg);
|
||
}
|
||
}
|
||
|
||
void TImporta_Beestore::transaction_doc(TODBC_recordset & docs, const char * table, const int tipotestata, const char* unitadefault, bool importadoc)
|
||
{
|
||
TString msg(TR("Importazione ")); msg << table;
|
||
TProgress_monitor pi(docs.items(), msg);
|
||
long last = -1, ndoc, codcf;
|
||
TString4 tipocf;
|
||
TToken_string codtestata("", '\\');
|
||
int contatore = 0;
|
||
int eccezioni_errori = 0;
|
||
int row = 0;
|
||
TString codpk;
|
||
TArray transactions;
|
||
TArray art_transactions;
|
||
TTransaction t("");
|
||
TAssoc_array art_inserted;
|
||
bool nuovo = false;
|
||
bool elab = false;
|
||
|
||
for (bool ok = docs.move_first(); pi.add_status() && ok; ok = docs.move_next())
|
||
{
|
||
TString wrk = docs.get_string("CodCliente");
|
||
TString8 tipodoc = tipotestata != 14 ? docs.get_string("TipoDocCE") : get_num("", 14);
|
||
TString cod_pk = docs.get_string("Cod_PK");
|
||
long numdoc;
|
||
|
||
if (tipodoc.full())
|
||
{
|
||
codtestata = docs.get_string("CodTestata");
|
||
ndoc = codtestata.get_long(BS_POSNUMDOC);
|
||
while (wrk[0] >= 'A')
|
||
wrk.ltrim(1);
|
||
codcf = atol(wrk);
|
||
tipocf = docs.get("TipoIntestatario").as_string();
|
||
if (ndoc != last)
|
||
{
|
||
elab = (!nuovo && (_tipo_imp != imp_aggiungi)) ||
|
||
(nuovo && (_tipo_imp != imp_aggiorna));
|
||
|
||
if (elab && last > 0 && row > 0)
|
||
transactions.add(t);
|
||
last = ndoc;
|
||
row = 0;
|
||
|
||
TString str = docs.get_string("NumDoc");
|
||
|
||
numdoc = ndoc;
|
||
// TString origine_dc = docs.get_string("Origine");
|
||
TTipo_documento tipo(tipodoc);
|
||
const TString8 codcaus = tipo.caus_mov();
|
||
const TDate datadoc = docs.get_date("DataDoc");
|
||
TToken_string key("D");
|
||
|
||
while (str[0] > 'A')
|
||
str.ltrim(1);
|
||
if (str.full())
|
||
numdoc = atol(str);
|
||
TRACE("%s n. %ld", table, numdoc);
|
||
|
||
const TString16 numerazione = get_num(docs.get_string("SuffNum"), tipotestata);
|
||
|
||
t.new_transaction(TFilename().temp("doc"));
|
||
key.add(datadoc.year());
|
||
key.add(numerazione);
|
||
key.add(numdoc);
|
||
nuovo = cache().get(LF_DOC, key).empty();
|
||
t.set_action(nuovo ? TRANSACTION_INSERT : TRANSACTION_MODIFY);
|
||
t.set_mode(transaction_mode_automatic);
|
||
t.set_stop_on_error(true);
|
||
t.set_caller("BEESTORE");
|
||
t.set_firm(get_firm());
|
||
|
||
t.set(DOC_PROVV, "D", -1, LF_DOC);
|
||
t.set(DOC_ANNO, datadoc.year(), -1, LF_DOC);
|
||
t.set(DOC_CODNUM, numerazione, -1, LF_DOC);
|
||
t.set(DOC_NDOC, numdoc, -1, LF_DOC);
|
||
t.set(DOC_DATADOC, datadoc, -1, LF_DOC);
|
||
t.set(DOC_TIPODOC, tipodoc, -1, LF_DOC);
|
||
|
||
if (tipotestata != 14)
|
||
{
|
||
t.set(DOC_TIPOCF, tipocf, -1, LF_DOC);
|
||
t.set(DOC_CODCF, codcf, -1, LF_DOC);
|
||
const TString8 codval = docs.get_string("CodValuta");
|
||
const real cambio = docs.get_real("CambioValuta");
|
||
const TString asp = docs.get_string("AspettoBeni");
|
||
const int ncolli = docs.get_int("NumeroColli");
|
||
|
||
t.set(DOC_CODVAL, codval, -1, LF_DOC);
|
||
t.set(DOC_CAMBIO, cambio, -1, LF_DOC);
|
||
t.set(DOC_CODPAG, docs.get_string("CodPagamento_FP"), -1, LF_DOC);
|
||
t.set(DOC_CODABIA, docs.get_string("ABI"), -1, LF_DOC); //banca di appoggio
|
||
t.set(DOC_CODCABA, docs.get_string("CAB"), -1, LF_DOC);
|
||
|
||
TToken_string bnpkey = decode_presentazione(docs.get_string("NostroContoCorr"));
|
||
|
||
t.set(DOC_CODABIP, bnpkey.get(), -1, LF_DOC); //banca di presentazione
|
||
t.set(DOC_CODCABP, bnpkey.get(), -1, LF_DOC);
|
||
t.set(DOC_PROGBNP, bnpkey.get(), -1, LF_DOC); //banca di presentazione
|
||
t.set(DOC_ASPBENI1, asp.sleft(50), -1, LF_DOC);
|
||
t.set(DOC_ASPBENI2, asp.smid(50), -1, LF_DOC);
|
||
t.set(DOC_NCOLLI, ncolli, -1, LF_DOC);
|
||
t.set(DOC_CAUSMAG, codcaus, -1, LF_DOC);
|
||
}
|
||
contatore++;
|
||
}
|
||
|
||
const int tipoart = docs.get_int("TipoArticolo");
|
||
TString80 codart = docs.get_string("IDArticolo");
|
||
TString descrizione = docs.get_string("Modello");
|
||
if (descrizione.blank())
|
||
descrizione = docs.get_string("DSRiga");
|
||
|
||
if (codart.blank())
|
||
codart = docs.get_string("CodArticolo");
|
||
if (codart == BS_FREEROW)
|
||
codart = "";
|
||
t.set(RDOC_TIPORIGA, "01", -1, LF_RIGHEDOC, ++row);
|
||
TRACE("%s n. %ld riga %d", table, numdoc, row);
|
||
if (codart.full())
|
||
{
|
||
t.set(RDOC_CODART, codart, -1, LF_RIGHEDOC, row);
|
||
|
||
t.set(RDOC_CHECKED, "X", -1, LF_RIGHEDOC, row);
|
||
if (tipoart == 1) //spese servizi
|
||
{
|
||
if (cache().get("SPP", codart).full())
|
||
{
|
||
t.set(RDOC_TIPORIGA, "03", -1, LF_RIGHEDOC, ++row);
|
||
t.set(RDOC_CODARTMAG, codart, -1, LF_RIGHEDOC, row);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (cache().get(LF_ANAMAG, codart).full())
|
||
t.set(RDOC_CODARTMAG, codart, -1, LF_RIGHEDOC, row);
|
||
else
|
||
if (importadoc && tipoart == 0)
|
||
{
|
||
t.set(RDOC_CODARTMAG, codart, -1, LF_RIGHEDOC, row);
|
||
|
||
if (!art_inserted.is_key(codart) && cache().get(LF_ANAMAG, codart).empty())
|
||
{
|
||
TTransaction tart(TFilename().temp("art"));
|
||
|
||
art_inserted.add(codart, codart);
|
||
tart.set_action(TRANSACTION_INSERT);
|
||
tart.set_mode(transaction_mode_automatic);
|
||
tart.set_stop_on_error(false);
|
||
tart.set_caller("BEESTORE");
|
||
tart.set_firm(get_firm());
|
||
tart.set(ANAMAG_CODART, codart, -1, LF_ANAMAG);
|
||
tart.set(ANAMAG_DESCR, descrizione, -1, LF_ANAMAG);
|
||
|
||
TString nomenclatura = docs.get_string("CodDogana");
|
||
|
||
if (nomenclatura.blank())
|
||
nomenclatura = docs.get_string("CodCategoria");
|
||
nomenclatura.strip(".");
|
||
if (nomenclatura.len() <= 8)
|
||
{
|
||
nomenclatura.lpad(8, '0');
|
||
add_nomenclatura(nomenclatura);
|
||
tart.set(ANAMAG_CLASSDOG, nomenclatura, -1, LF_ANAMAG);
|
||
}
|
||
else
|
||
_log->log(2, format(FR("Codice nomenclatura combinata %s errato, non e' stato importato"), (const char *) nomenclatura));
|
||
|
||
TString unitamisura = docs.get_string("CodUntMis");
|
||
|
||
if (unitamisura.blank())
|
||
unitamisura = unitadefault;
|
||
tart.set(UMART_UM, unitamisura, -1, LF_UMART, 1);
|
||
tart.set(UMART_FC, 1, -1, LF_UMART, 1);
|
||
art_transactions.add(tart);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
t.set(RDOC_DESCR, descrizione.sleft(50), -1, LF_RIGHEDOC, row);
|
||
if (descrizione.len() > 50)
|
||
{
|
||
t.set(RDOC_DESCLUNGA, "X", -1, LF_RIGHEDOC, row);
|
||
t.set(RDOC_DESCEST, descrizione.smid(50), -1, LF_RIGHEDOC, row);
|
||
}
|
||
t.set(RDOC_CODMAG, docs.get_string("CodMagazzino").left(5), -1, LF_RIGHEDOC, row);
|
||
t.set(RDOC_CODMAGC, docs.get_string("CodMagazDest").left(5), -1, LF_RIGHEDOC, row);
|
||
|
||
TString unitamisura = docs.get_string("CodUntMis");
|
||
|
||
if (unitamisura.blank())
|
||
unitamisura = unitadefault;
|
||
t.set(RDOC_UMQTA, docs.get_string("CodUntMis"), -1, LF_RIGHEDOC, row);
|
||
t.set(RDOC_QTA, docs.get_real("Quantita"), -1, LF_RIGHEDOC, row);
|
||
t.set(RDOC_PREZZO, docs.get_real("PrzNettoNeg"), -1, LF_RIGHEDOC, row); // o PrzNettoValuta ??
|
||
t.set(RDOC_CODIVA, docs.get_string("CodIva"), -1, LF_RIGHEDOC, row);
|
||
}
|
||
else
|
||
{
|
||
eccezioni_errori++;
|
||
codpk = cod_pk;
|
||
TString dserrore = docs.get("DSErrore").as_string();
|
||
dserrore.sleft(50);
|
||
dserrore << " TipoDocCe assente o invalido";
|
||
TString update_str = "";
|
||
update_str << "UPDATE tieTBolFat \n SET Errore = 1 , DSErrore = '" << dserrore << "' \n WHERE cod_pk= '" << codpk << "' ";
|
||
TODBC_recordset docs(update_str);
|
||
docs.connect(_dsn, _usr, _psw);
|
||
docs.exec(update_str);
|
||
}
|
||
}
|
||
elab = (!nuovo && (_tipo_imp != imp_aggiungi)) ||
|
||
(nuovo && (_tipo_imp != imp_aggiorna));
|
||
|
||
if (elab && last > 0 && row > 0)
|
||
transactions.add(t);
|
||
TRACE("Salvataggio articoli");
|
||
execute_transactions(art_transactions, *_log, _interactive, "Importazione articoli");
|
||
TRACE("Salvataggio %s", table);
|
||
execute_transactions(transactions, *_log, _interactive, msg);
|
||
}
|
||
|
||
void TImporta_Beestore::import_doc(const TDate& dal, const TDate& al, int tipotestata, const char* unitadefault, bool importadoc)
|
||
{
|
||
TString str(255);
|
||
if (tipotestata < 10)
|
||
{
|
||
str << "SELECT tieDMovMag.*,tieTBolFat.* FROM tieDMovMag,tieTBolFat WHERE tieDMovMag.Origine=1 AND tieDMovMag.TipoTestata=2 AND TieTBolFat.TipoDoc=" << tipotestata << " AND tieDMovMag.CodTestata=tieTBolFat.Cod_PK";
|
||
if (dal.ok() || al.ok())
|
||
{
|
||
str << " AND tieTBolFat.DataDoc";
|
||
if (dal.ok() && al.ok())
|
||
str << " BETWEEN " << date2sql(dal, 1) << " AND " << date2sql(al, 2);
|
||
else
|
||
{
|
||
if (dal.ok())
|
||
str << ">=" << date2sql(dal, 1);
|
||
else
|
||
str << "<=" << date2sql(al, 2);
|
||
}
|
||
}
|
||
str << "\nORDER BY CodTestata,NumRiga";
|
||
}
|
||
else
|
||
{
|
||
if (tipotestata == 14)
|
||
str << "SELECT *, NumMov AS NumDoc, DataMov AS DataDoc, \"\" AS SuffNum FROM tieDMovMag";
|
||
else
|
||
str << "SELECT tieDMovMag.*,tieTBolFat.* FROM tieDMovMag,tieTBolFat";
|
||
str << "WHERE Origine=1 AND TipoTestata=" << tipotestata - 10;
|
||
if (dal.ok() || al.ok())
|
||
{
|
||
str << " AND DataMov";
|
||
if (dal.ok() && al.ok())
|
||
str << " BETWEEN " << date2sql(dal, 1) << " AND " << date2sql(al, 2);
|
||
else
|
||
{
|
||
if (dal.ok())
|
||
str << ">=" << date2sql(dal, 1);
|
||
else
|
||
str << "<=" << date2sql(al, 2);
|
||
}
|
||
}
|
||
str << "\nORDER BY NumMov,NumRiga";
|
||
}
|
||
|
||
TODBC_recordset docs(str);
|
||
|
||
docs.connect(_dsn, _usr, _psw);
|
||
switch (tipotestata)
|
||
{
|
||
case 1:
|
||
str = TR("Bolle");
|
||
break;
|
||
case 2:
|
||
str = TR("Fatture");
|
||
break;
|
||
case 6:
|
||
str = TR("Note di credito");
|
||
break;
|
||
case 9:
|
||
str = TR("Ordini");
|
||
break;
|
||
case 11:
|
||
str = TR("Carichi e scarichi");
|
||
break;
|
||
case 13:
|
||
str = TR("Scontrini");
|
||
break;
|
||
case 14:
|
||
str = TR("Generici");
|
||
break;
|
||
default:
|
||
str = TR("Documenti");
|
||
break;
|
||
};
|
||
TRACE(str);
|
||
if (_direct_write)
|
||
direct_doc(docs, str, tipotestata, unitadefault, importadoc);
|
||
else
|
||
transaction_doc(docs, str, tipotestata, unitadefault, importadoc);
|
||
}
|
||
|
||
TToken_string & TImporta_Beestore::decode_presentazione(const char*IBAN)
|
||
{
|
||
TToken_string & key = get_tmp_string(20);
|
||
if (IBAN && *IBAN)
|
||
{
|
||
if (!_banche_pres_loaded)
|
||
{
|
||
TCursor cur(new TRelation ("BNP"));
|
||
const int items = cur.items();
|
||
|
||
for (cur = 0L; cur.pos() < items; ++cur)
|
||
{
|
||
const TString codtab = cur.curr().get("CODTAB");
|
||
const TString iban = cur.curr().get("S3");
|
||
TToken_string bankey = codtab.left(5);
|
||
|
||
bankey.add(codtab.mid(5,5));
|
||
bankey.add(codtab.mid(10));
|
||
_banche_pres.add(iban,bankey);
|
||
}
|
||
_banche_pres_loaded = true;
|
||
}
|
||
TToken_string *keyfound = (TToken_string *)_banche_pres.objptr(IBAN);
|
||
if (keyfound != nullptr)
|
||
key = *keyfound;
|
||
|
||
}
|
||
return key;
|
||
}
|
||
|
||
bool TImporta_Beestore::create()
|
||
{
|
||
open_files(LF_RCAUSALI, LF_CAUSALI, LF_CFVEN, LF_CLIFO, LF_MOVMAG, LF_RMOVMAG, LF_DOC, LF_ANAMAG, LF_UMART, LF_RIGHEDOC, 0);
|
||
_dsn = ini_get_string(CONFIG_DITTA, "BS", "DSN", "BEESTORE");
|
||
_sqlog = ini_get_string(CONFIG_DITTA, "BS", "Log", "");
|
||
_usr = ini_get_string(CONFIG_DITTA, "BS", "USR", "BEESTORE");
|
||
_psw = decode(ini_get_string(CONFIG_DITTA, "BS", "PSW", "BEESTORE"));
|
||
_direct_write = false;
|
||
_interactive = ini_get_bool(CONFIG_DITTA, "BS", "Interactive");
|
||
_direct_write = ini_get_bool(CONFIG_DITTA, "BS", "DirectWrite");
|
||
_banche_pres_loaded = false;
|
||
|
||
if (_dsn.full())
|
||
{
|
||
TProgress_monitor ti(1, TR("Connessione a SQL Server"), false);
|
||
TString query; query << "SELECT * FROM tieValute;";//"ODBC(" << _dsn << ")\nSELECT * FROM tieValute;";
|
||
TODBC_recordset recset(query);
|
||
|
||
if (recset.connect(_dsn, _usr, _psw)) // Dovrebbe connettersi anche con solo _dsn valorizzato
|
||
{
|
||
recset.move_first();
|
||
if (_sqlog.full() && _sqlog.is_relative_path())
|
||
{
|
||
TFilename n; n.tempdir();
|
||
n.add(_sqlog.name());
|
||
_sqlog = n;
|
||
}
|
||
recset.set_log_file(_sqlog);
|
||
return TSkeleton_application::create();
|
||
}
|
||
}
|
||
return error_box(FR("Impossibile connettersi al DSN '%s'"), (const char*)_dsn);
|
||
}
|
||
|
||
void TImporta_Beestore::main_loop()
|
||
{
|
||
TImporta_Beestore_mask mask;
|
||
TSheet_field & s = mask.sfield(F_CODNUM);
|
||
|
||
if (s.items() == 0)
|
||
s.row();
|
||
s.disable_cell(0, F_SUFFISSO);
|
||
|
||
while (mask.run() == K_ENTER)
|
||
{
|
||
int rows = s.items();
|
||
|
||
mask.autosave(); // Rende definitivi tutti i paramentri in [bs]
|
||
_nums.destroy();
|
||
for (int i = 0; i < rows; i++)
|
||
{
|
||
TToken_string codnums;
|
||
TString16 key = s.get_str_row_cell(i, F_SUFFISSO);
|
||
|
||
key.trim();
|
||
for (short id = F_COD_FATTURE; id <= F_COD_ORDCLI; id++)
|
||
codnums.add(s.get_str_row_cell(i, id));
|
||
_nums.add(key, codnums);
|
||
}
|
||
_log = new TLog_report;
|
||
|
||
const TDate dal = mask.get_date("ImpDateFrom");
|
||
const TDate al = mask.get_date("ImpDateTo");
|
||
const bool importa_artdoc = mask.get_bool("ImpIMPPARTDOC");
|
||
|
||
_tipo_imp = (tipo_importazione) atoi(mask.get("ImpTYPE"));
|
||
if (mask.get_bool("ImpUMS"))
|
||
import_ums();
|
||
if (mask.get_bool("ImpIVA"))
|
||
import_iva();
|
||
if (mask.get_bool("ImpLinee"))
|
||
import_lines();
|
||
if (mask.get_bool("ImpCatMer"))
|
||
import_catmer();
|
||
if (mask.get_bool("ImpAnamag"))
|
||
import_anamag();
|
||
if (mask.get_bool("ImpVAL"))
|
||
import_val();
|
||
|
||
int cfmask = 0;
|
||
if (mask.get_bool("ImpClienti")) cfmask |= 1;
|
||
if (mask.get_bool("ImpFornitori")) cfmask |= 2;
|
||
if (cfmask)
|
||
import_clifo(cfmask, dal, al);
|
||
if (mask.get_bool("ImpDoc"))
|
||
{
|
||
const int tipotestata = mask.get_int(F_TIPODOC);
|
||
|
||
import_doc(dal, al, tipotestata, mask.get(F_UNITADEFAULT), importa_artdoc);
|
||
}
|
||
_log->preview();
|
||
safe_delete(_log);
|
||
}
|
||
|
||
}
|
||
|
||
int bs0500(int argc, char* argv[])
|
||
{
|
||
TImporta_Beestore impf;
|
||
impf.run(argc, argv, TR("Import F/B/S"));
|
||
return 0;
|
||
} |