634 lines
16 KiB
C++
634 lines
16 KiB
C++
#include "fplib.h"
|
||
|
||
#include <dongle.h>
|
||
#include <modaut.h>
|
||
|
||
#define FILE_CONFIG CONFIG_DITTA
|
||
#define FILE_SECTION mod2name(FPAUT)
|
||
#define FP_TAB_MOD mod2tabname(FPAUT)
|
||
|
||
#define FP_IP "ip"
|
||
#define FP_DB "db"
|
||
#define FP_USR "usr"
|
||
#define FP_PSW "psw"
|
||
#define FP_FLD_DEST "flddest"
|
||
#define FP_FLD_USR_DEST "fldusrdest"
|
||
#define FP_COFI_TRAS "cofitras"
|
||
#define FP_GEST_ALLEG "gestioneallegati"
|
||
#define FP_ALLEG_FAT "allegafatt"
|
||
#define FP_ESP_PRI "esppri"
|
||
#define FP_ESP_EST "espest"
|
||
#define FP_ESP_EST_COD "espestcod"
|
||
#define FP_F8 "f8"
|
||
#define FP_CHECK_NOT_BLOCK "checknotblock"
|
||
#define FP_MAIL "mail"
|
||
#define FP_NOTA_PIEDE_F "npf" // Nota piede fattura
|
||
#define FP_CHECK_NO_SCONTI_FATT "noscontifatt"
|
||
#define FP_CHECK_NO_EXPORT_PRONTO "noexportpronto"
|
||
#define FP_DATASTARTFATT "datastartfatt"
|
||
#define FP_DATASTARTNEWFATT "startnewtracciato"
|
||
|
||
// Sheet fp0300
|
||
#define FP_SLD_COD "SLD"
|
||
|
||
#define FP_SLD_CODTAB "CODTAB"
|
||
#define FP_SLD_CODNUM "S0"
|
||
#define FP_SLD_TIPODOC "S1"
|
||
#define FP_SLD_DASTATO "I0"
|
||
#define FP_SLD_ASTATO "I1"
|
||
|
||
// Sheet fp0100
|
||
#define FP_SHT_CUST "SCUSTRIG"
|
||
#define FP_SHT_CODTAB FP_SLD_CODTAB
|
||
#define FP_SHT_TIPODOC "S0"
|
||
#define FP_SHT_TIPORIGA "S1"
|
||
#define FP_SHT_COL_QTA "S2"
|
||
#define FP_SHT_COL_PREZZO "S3"
|
||
#define FP_SHT_COL_IMPONIBILE "S4"
|
||
|
||
#define FP_SHT_DEF_QTA RDOC_QTA
|
||
#define FP_SHT_DEF_PREZZO "PREZZONN"
|
||
#define FP_SHT_DEF_IMPONIBILE "IMPNS"
|
||
|
||
const TString& get_db_indirizzo()
|
||
{
|
||
return ini_get_string(FILE_CONFIG, FILE_SECTION, FP_IP);
|
||
}
|
||
|
||
const TString& get_db_database()
|
||
{
|
||
return ini_get_string(FILE_CONFIG, FILE_SECTION, FP_DB);
|
||
}
|
||
|
||
const TString& get_db_str_con()
|
||
{
|
||
TString & strconn = get_tmp_string(128);
|
||
|
||
strconn = get_db_indirizzo();
|
||
strconn << "@" << get_db_database();
|
||
return strconn;
|
||
}
|
||
|
||
const TString& get_db_user()
|
||
{
|
||
return ini_get_string(FILE_CONFIG, FILE_SECTION, FP_USR);
|
||
}
|
||
|
||
const TString& get_db_password()
|
||
{
|
||
TString & pwd = get_tmp_string();
|
||
|
||
pwd = decode(ini_get_string(FILE_CONFIG, FILE_SECTION, FP_PSW));
|
||
return pwd;
|
||
}
|
||
|
||
const TString& get_fld_dest()
|
||
{
|
||
return ini_get_string(FILE_CONFIG, FILE_SECTION, FP_FLD_DEST);
|
||
}
|
||
|
||
const TString& get_fld_dest_usr()
|
||
{
|
||
return ini_get_string(FILE_CONFIG, FILE_SECTION, FP_FLD_USR_DEST, "");
|
||
}
|
||
|
||
const TString& get_cofi_tras()
|
||
{
|
||
return ini_get_string(FILE_CONFIG, FILE_SECTION, FP_COFI_TRAS);
|
||
}
|
||
|
||
const TDate get_data_start_fatt()
|
||
{
|
||
return ini_get_date(FILE_CONFIG, FILE_SECTION, FP_DATASTARTFATT, "01-01-2019");
|
||
}
|
||
|
||
const bool get_gest_alleg()
|
||
{
|
||
return ini_get_bool(FILE_CONFIG, FILE_SECTION, FP_GEST_ALLEG);
|
||
}
|
||
|
||
const bool get_allega_fat()
|
||
{
|
||
return ini_get_bool(FILE_CONFIG, FILE_SECTION, FP_ALLEG_FAT);
|
||
}
|
||
|
||
const bool get_esp_pri_empty()
|
||
{
|
||
return ini_get_bool(FILE_CONFIG, FILE_SECTION, FP_ESP_PRI);
|
||
}
|
||
|
||
const bool get_esp_est()
|
||
{
|
||
return ini_get_bool(FILE_CONFIG, FILE_SECTION, FP_ESP_EST);
|
||
}
|
||
|
||
const TString& get_esp_est_cod()
|
||
{
|
||
return ini_get_string(FILE_CONFIG, FILE_SECTION, FP_ESP_EST_COD, "XXXXXXX");
|
||
}
|
||
|
||
const bool is_f8()
|
||
{
|
||
return ini_get_bool(FILE_CONFIG, FILE_SECTION, FP_F8);
|
||
}
|
||
|
||
const bool get_check_not_block()
|
||
{
|
||
return ini_get_bool(FILE_CONFIG, FILE_SECTION, FP_CHECK_NOT_BLOCK);
|
||
}
|
||
|
||
const TString& get_body_mail(int idx)
|
||
{
|
||
return ini_get_string(FILE_CONFIG, FILE_SECTION, FP_MAIL, "STOpsTOP", idx);
|
||
}
|
||
|
||
const TString& get_npf(const char * tipodoc, int idx)
|
||
{
|
||
TString name; name << FP_NOTA_PIEDE_F << "-" << tipodoc;
|
||
|
||
return ini_get_string(FILE_CONFIG, FILE_SECTION, name, "FERMATIostrega", idx);
|
||
}
|
||
|
||
const TString & get_npf_tipodoc(int indx)
|
||
{
|
||
TString name; name << FP_NOTA_PIEDE_F << "_tipodoc";
|
||
|
||
return ini_get_string(FILE_CONFIG, FILE_SECTION, name, "FERMATIostrega", indx);
|
||
}
|
||
|
||
TDate get_date_start_new_fatt()
|
||
{
|
||
return ini_get_date(CONFIG_DITTA, FILE_SECTION, FP_DATASTARTNEWFATT, "01-01-2021");
|
||
}
|
||
|
||
const bool get_no_sconti_fatt()
|
||
{
|
||
return ini_get_bool(FILE_CONFIG, FILE_SECTION, FP_CHECK_NO_SCONTI_FATT, false);
|
||
}
|
||
|
||
bool get_no_export_pronto()
|
||
{
|
||
return ini_get_bool(FILE_CONFIG, FILE_SECTION, FP_CHECK_NO_EXPORT_PRONTO, false);
|
||
}
|
||
|
||
void set_db_indirizzo(const TString& ind)
|
||
{
|
||
ini_set_string(FILE_CONFIG, FILE_SECTION, FP_IP, ind);
|
||
}
|
||
|
||
void set_db_database(const TString& db)
|
||
{
|
||
ini_set_string(FILE_CONFIG, FILE_SECTION, FP_DB, db);
|
||
}
|
||
|
||
void set_db_user(const TString& usr)
|
||
{
|
||
ini_set_string(FILE_CONFIG, FILE_SECTION, FP_USR, usr);
|
||
}
|
||
|
||
void set_db_password(const TString& psw)
|
||
{
|
||
ini_set_string(FILE_CONFIG, FILE_SECTION, FP_PSW, encode(psw));
|
||
}
|
||
|
||
void set_fld_dest(const TString& fld_dest)
|
||
{
|
||
ini_set_string(FILE_CONFIG, FILE_SECTION, FP_FLD_DEST, fld_dest);
|
||
}
|
||
|
||
void set_fld_dest_usr(const TString& fld_dest_usr)
|
||
{
|
||
ini_set_string(FILE_CONFIG, FILE_SECTION, FP_FLD_USR_DEST, fld_dest_usr);
|
||
}
|
||
|
||
void set_cofi_tras(const TString& cofi)
|
||
{
|
||
ini_set_string(FILE_CONFIG, FILE_SECTION, FP_COFI_TRAS, cofi);
|
||
}
|
||
|
||
void set_gest_alleg(const bool gest_alleg)
|
||
{
|
||
ini_set_bool(FILE_CONFIG, FILE_SECTION, FP_GEST_ALLEG, gest_alleg);
|
||
}
|
||
|
||
void set_allega_fat(const bool allega_fatt)
|
||
{
|
||
ini_set_bool(FILE_CONFIG, FILE_SECTION, FP_ALLEG_FAT, allega_fatt);
|
||
}
|
||
|
||
void set_esp_pri_empty(const bool esp_pri)
|
||
{
|
||
ini_set_bool(FILE_CONFIG, FILE_SECTION, FP_ESP_PRI, esp_pri);
|
||
}
|
||
|
||
void set_esp_est(const bool esp_est)
|
||
{
|
||
ini_set_bool(FILE_CONFIG, FILE_SECTION, FP_ESP_EST, esp_est);
|
||
}
|
||
|
||
void set_esp_est_cod(const TString& esp_est_cod)
|
||
{
|
||
ini_set_string(FILE_CONFIG, FILE_SECTION, FP_ESP_EST_COD, esp_est_cod);
|
||
}
|
||
|
||
void set_f8(const bool f8)
|
||
{
|
||
ini_set_bool(FILE_CONFIG, FILE_SECTION, FP_F8, f8);
|
||
}
|
||
|
||
void set_check_not_block(const bool not_block)
|
||
{
|
||
ini_set_bool(FILE_CONFIG, FILE_SECTION, FP_CHECK_NOT_BLOCK, not_block);
|
||
}
|
||
|
||
void set_body_mail(const char* msg, int idx)
|
||
{
|
||
ini_set_string(FILE_CONFIG, FILE_SECTION, FP_MAIL, msg, idx);
|
||
}
|
||
|
||
// Set nota piede fattura
|
||
void set_npf(const char * tipodoc, const char* msg, int idx)
|
||
{
|
||
TString name; name << FP_NOTA_PIEDE_F << "-" << tipodoc;
|
||
|
||
ini_set_string(FILE_CONFIG, FILE_SECTION, name, msg, idx);
|
||
}
|
||
|
||
void set_no_sconti_fatt(const bool no_sconti_fatt)
|
||
{
|
||
ini_set_bool(FILE_CONFIG, FILE_SECTION, FP_CHECK_NO_SCONTI_FATT, no_sconti_fatt);
|
||
}
|
||
|
||
void set_no_export_pronto(const bool no_export_pronto)
|
||
{
|
||
ini_set_bool(FILE_CONFIG, FILE_SECTION, FP_CHECK_NO_EXPORT_PRONTO, no_export_pronto);
|
||
}
|
||
|
||
void set_data_start_fatt(const char* date)
|
||
{
|
||
ini_set_string(FILE_CONFIG, FILE_SECTION, FP_DATASTARTFATT, date);
|
||
}
|
||
|
||
void set_data_start_new_fatt(const char* date)
|
||
{
|
||
ini_set_string(CONFIG_DITTA, FILE_SECTION, FP_DATASTARTNEWFATT, date);
|
||
}
|
||
|
||
void remove_para_ini(int idx)
|
||
{
|
||
ini_remove(FILE_CONFIG, FILE_SECTION, FP_MAIL, idx);
|
||
}
|
||
|
||
void remove_npf_ini(const char * tipodoc, int idx)
|
||
{
|
||
TString name; name << FP_NOTA_PIEDE_F << "-" << tipodoc;
|
||
|
||
ini_remove(FILE_CONFIG, FILE_SECTION, name, idx);
|
||
}
|
||
|
||
void set_npf_tipodoc(const TString& tipodoc, int indx)
|
||
{
|
||
TString name; name << FP_NOTA_PIEDE_F << "_tipodoc";
|
||
|
||
ini_set_string(FILE_CONFIG, FILE_SECTION, name, tipodoc, indx);
|
||
}
|
||
|
||
// Rimuove linea ini in eccesso per tipodoc per nota piede fattura
|
||
void remove_tipodoc_npf(const int idx)
|
||
{
|
||
TString name; name << FP_NOTA_PIEDE_F << "_tipodoc";
|
||
|
||
ini_remove(FILE_CONFIG, FILE_SECTION, name, idx);
|
||
}
|
||
|
||
TRectype TFP_selected_docs::fill_rectype() const
|
||
{
|
||
TRectype r(LF_TABMOD);
|
||
r.put("MOD", FP_TAB_MOD);
|
||
r.put("COD", FP_SLD_COD);
|
||
return r;
|
||
}
|
||
|
||
void TFP_selected_docs::fill_sheet(TSheet_field& sheet) const
|
||
{
|
||
for(*_cur = 0; _cur->pos() < _cur->items(); ++*_cur)
|
||
{
|
||
TRectype rec = _cur->curr();
|
||
TToken_string& row = sheet.row(-1);
|
||
row.add(rec.get(FP_SLD_CODNUM));
|
||
row.add(rec.get(FP_SLD_TIPODOC));
|
||
row.add(rec.get(FP_SLD_DASTATO));
|
||
row.add(rec.get(FP_SLD_ASTATO));
|
||
row.add(TTipo_documento(rec.get(FP_SLD_TIPODOC)).tipo_doc_sdi());
|
||
}
|
||
}
|
||
|
||
void TFP_selected_docs::save_sheet(const TSheet_field& sheet) const
|
||
{
|
||
// Svuoto il db
|
||
TLocalisamfile tabmod(LF_TABMOD);
|
||
TRectype rec(LF_TABMOD);
|
||
|
||
for (*_cur = 0; _cur->pos() != _cur->items();)
|
||
{
|
||
rec = _cur->curr();
|
||
int err = rec.remove(tabmod);
|
||
}
|
||
|
||
// Carico il db
|
||
|
||
FOR_EACH_SHEET_ROW(sheet, n, r)
|
||
{
|
||
// Chissene anche se copio ogni volta
|
||
rec = fill_rectype();
|
||
static TString num;
|
||
num.cut(0);
|
||
num.format("%08d", n);
|
||
rec.put(FP_SLD_CODTAB, num);
|
||
|
||
// Prendo tutta la riga tranne il cod sdi
|
||
rec.put(FP_SLD_CODNUM, r->get(_codnum));
|
||
rec.put(FP_SLD_TIPODOC, r->get(_tipodoc));
|
||
rec.put(FP_SLD_DASTATO, r->get(_dastato));
|
||
rec.put(FP_SLD_ASTATO, r->get(_astato));
|
||
rec.write(tabmod);
|
||
}
|
||
}
|
||
|
||
TFP_selected_docs::TFP_selected_docs() : _r_tabmod(LF_TABMOD), _flt(fill_rectype())
|
||
{
|
||
_cur.reset(new TCursor(&_r_tabmod, "", 1, &_flt, &_flt));
|
||
}
|
||
|
||
|
||
TFP_righe_custom::TCustCol& TFP_righe_custom::get_no_custom()
|
||
{
|
||
static TCustCol* default_cust_col = nullptr;
|
||
if(default_cust_col == nullptr)
|
||
{
|
||
default_cust_col = new TCustCol();
|
||
}
|
||
return *default_cust_col;
|
||
}
|
||
|
||
TFP_righe_custom::TCustCol& TFP_righe_custom::get(const TString& codriga, const TString& tipodoc)
|
||
{
|
||
if(!_loaded)
|
||
{
|
||
load_map();
|
||
}
|
||
|
||
if(_custom_table.find(codriga) != _custom_table.end())
|
||
{
|
||
if (_custom_table[codriga].find(tipodoc) != _custom_table[codriga].end())
|
||
{
|
||
return _custom_table[codriga][tipodoc];
|
||
}
|
||
else if (_custom_table[codriga].find("") != _custom_table[codriga].end())
|
||
{
|
||
return _custom_table[codriga][""];
|
||
}
|
||
}
|
||
|
||
return get_no_custom();
|
||
}
|
||
|
||
void TFP_nota_piede_f::write_ini_npf(const TString& tipodoc, TToken_string& msg)
|
||
{
|
||
/* Vado a salvare in un config .ini tipo-doc:messaggio su piu righe */
|
||
int indx = 0;
|
||
|
||
// Conto quanti ne avevo salvati prima nel file ini per poi controllare
|
||
// che non sto salvando meno di quelli che ci sono gi<67>
|
||
int previous_indx = 0;
|
||
for (TString row = get_npf(tipodoc, previous_indx); row != "FERMATIostrega"; row = get_npf(tipodoc, previous_indx))
|
||
previous_indx++;
|
||
// Vado a salvare ogni riga nel file ini
|
||
for (const char* row = msg.get(); row; row = msg.get())
|
||
set_npf(tipodoc, row, indx++);
|
||
|
||
if (indx < previous_indx)
|
||
{
|
||
for (int i = indx; i < previous_indx; i++)
|
||
remove_npf_ini(tipodoc, i);
|
||
}
|
||
}
|
||
|
||
void TFP_nota_piede_f::delete_ini_npf(const TString& tipodoc)
|
||
{
|
||
// Conto quanti ne avevo salvati prima nel file ini per poi controllare
|
||
// che non sto salvando meno di quelli che ci sono gi<67>
|
||
int previous_indx = 0;
|
||
for (TString row = get_npf(tipodoc, previous_indx); row != "FERMATIostrega"; row = get_npf(tipodoc, previous_indx))
|
||
previous_indx++;
|
||
for (int i = 0; i < previous_indx; i++)
|
||
remove_npf_ini(tipodoc, i);
|
||
|
||
}
|
||
|
||
// Crea la stringa della nota se su piu righe dal file ini (nometag+indice)
|
||
TString TFP_nota_piede_f::get_ini_npf(const TString& tipodoc)
|
||
{
|
||
TString msg; msg.cut(0);
|
||
|
||
int indx = 0;
|
||
for (TString row = get_npf(tipodoc, indx); row != "FERMATIostrega"; row = get_npf(tipodoc, indx))
|
||
{
|
||
if(indx++ > 0)
|
||
msg << '\n';
|
||
msg << row;
|
||
}
|
||
return msg;
|
||
}
|
||
|
||
void TFP_nota_piede_f::get_load()
|
||
{
|
||
// Prima leggo i tipi doc che ho salvato dall'ini
|
||
TString tipo_get = "";
|
||
int indx = 0;
|
||
while ((tipo_get = get_npf_tipodoc(indx++)) != "FERMATIostrega")
|
||
_tipi_doc.add(tipo_get);
|
||
|
||
const int itms = _tipi_doc.items();
|
||
for (int i = 0; i < itms; i++)
|
||
{
|
||
tipo_get = _tipi_doc.get();
|
||
TString npf = get_ini_npf(tipo_get);
|
||
_nota_piede_fattura.insert({ tipo_get, npf });
|
||
}
|
||
_loaded = true;
|
||
}
|
||
|
||
void TFP_nota_piede_f::load_sheet(TSheet_field& sheet_field)
|
||
{
|
||
sheet_field.hide();
|
||
// Prima leggo i tipi doc che ho salvato dall'ini
|
||
TString tipo_get = "";
|
||
int indx = 0;
|
||
while((tipo_get = get_npf_tipodoc(indx++)) != "FERMATIostrega")
|
||
_tipi_doc.add(tipo_get);
|
||
|
||
int i = 0;
|
||
while (!(tipo_get = _tipi_doc.get()).empty())
|
||
{
|
||
TString npf = get_ini_npf(tipo_get);
|
||
TToken_string& row = sheet_field.row(-1);
|
||
row.add(tipo_get);
|
||
row.add(npf);
|
||
}
|
||
sheet_field.show();
|
||
sheet_field.force_update();
|
||
}
|
||
|
||
void TFP_nota_piede_f::save_npf_spredsheet(TSheet_field& sheet_field)
|
||
{
|
||
const int items_sf = sheet_field.items();
|
||
TString tipo_doc = 0;
|
||
// Salvo le note piede fatt presenti nello spreadsheet
|
||
// Se ho eliminato una nota di un tipodoc devo rimuovere tutte le righe di quel tipodoc
|
||
for (int i = 0; i < items_sf; i++)
|
||
{
|
||
TToken_string row = sheet_field.row(i);
|
||
TToken_string msg(row.get(1), '\n');
|
||
write_ini_npf(tipo_doc = row.get(0), msg);
|
||
_tipi_doc.restart();
|
||
for (int j = 0; j < _tipi_doc.items(); j++)
|
||
if (tipo_doc == _tipi_doc.get()) // Elimino dall'array i tipi doc che sto salvando
|
||
_tipi_doc.destroy(j); // Per controllare che non ne rimangano alcuni in piu`
|
||
}
|
||
|
||
if (_tipi_doc.items() > 0) // E` rimasto qualcuno fuori (<28> stato eliminato un tipodoc rispetto a quelli salvati nel file ini)
|
||
{
|
||
for (int i = 0; i < _tipi_doc.items(); i++) // Per ogni tipodoc rimasto fuori elimino tutte le possibili righe del messaggio
|
||
delete_ini_npf(_tipi_doc.get());
|
||
}
|
||
}
|
||
|
||
void TFP_nota_piede_f::save_new_tipidoc(TSheet_field& sheet_field)
|
||
{
|
||
int n_tipidoc = 0;
|
||
TString npf_get;
|
||
// Conto quanti tipi doc ho nel file ini
|
||
for (int i = 0; (npf_get = get_npf_tipodoc(i)) != "FERMATIostrega"; i++)
|
||
{
|
||
n_tipidoc++;
|
||
_tipi_doc.add(npf_get);
|
||
}
|
||
|
||
// Salvo i nuovi tipidoc
|
||
const int items_sf = sheet_field.items();
|
||
for (int i = 0; i < items_sf; i++)
|
||
{
|
||
TToken_string row = sheet_field.row(i);
|
||
TString tipodoc_sf(row.get(0));
|
||
|
||
set_npf_tipodoc(tipodoc_sf, i);
|
||
}
|
||
|
||
if (items_sf < n_tipidoc)
|
||
for (int i = items_sf; i < n_tipidoc; i++)
|
||
remove_tipodoc_npf(i);
|
||
}
|
||
|
||
void TFP_nota_piede_f::save_sheet(TSheet_field& sheet_field)
|
||
{
|
||
save_new_tipidoc(sheet_field);
|
||
save_npf_spredsheet(sheet_field);
|
||
}
|
||
|
||
const TString& TFP_nota_piede_f::get_nota_piede(const TString& tipo_doc)
|
||
{
|
||
if (!_loaded)
|
||
get_load();
|
||
if(_nota_piede_fattura.find(tipo_doc) != _nota_piede_fattura.end())
|
||
return _nota_piede_fattura[tipo_doc];
|
||
return _null_string;
|
||
}
|
||
|
||
TFP_nota_piede_f::TFP_nota_piede_f() : _loaded(false), _null_string("")
|
||
{
|
||
}
|
||
|
||
void TFP_righe_custom::load_map()
|
||
{
|
||
TRelation rel(LF_TABMOD);
|
||
TRectype rec(LF_TABMOD);
|
||
rec.put("MOD", FP_TAB_MOD);
|
||
rec.put("COD", FP_SHT_CUST);
|
||
TCursor cur(&rel, "", 1, &rec, &rec);
|
||
for (cur = 0; cur.pos() < cur.items(); ++cur)
|
||
{
|
||
rec = cur.curr();
|
||
TCustCol& app = _custom_table[rec.get(FP_SHT_TIPORIGA)][rec.get(FP_SHT_TIPODOC)];
|
||
app._col_qta = rec.get(FP_SHT_COL_QTA).full() ? rec.get(FP_SHT_COL_QTA) : FP_SHT_DEF_QTA;
|
||
app._col_prezzo = rec.get(FP_SHT_COL_PREZZO).full() ? rec.get(FP_SHT_COL_PREZZO) : FP_SHT_DEF_PREZZO;
|
||
app._col_imponibile = rec.get(FP_SHT_COL_IMPONIBILE).full() ? rec.get(FP_SHT_COL_IMPONIBILE) : FP_SHT_DEF_IMPONIBILE;
|
||
}
|
||
|
||
_loaded = true;
|
||
}
|
||
|
||
void TFP_righe_custom::save_sheet(TSheet_field& sheet_field)
|
||
{
|
||
// Svuoto il db
|
||
TLocalisamfile tabmod(LF_TABMOD);
|
||
TRelation rel(LF_TABMOD);
|
||
TRectype rec(LF_TABMOD);
|
||
rec.put("MOD", FP_TAB_MOD);
|
||
rec.put("COD", FP_SHT_CUST);
|
||
TCursor cur(&rel, "", 1, &rec, &rec);
|
||
|
||
for (cur = 0; cur.pos() != cur.items();)
|
||
{
|
||
rec = cur.curr();
|
||
int err = rec.remove(tabmod);
|
||
}
|
||
|
||
// Carico il db
|
||
FOR_EACH_SHEET_ROW(sheet_field, n, r)
|
||
{
|
||
// Chissene anche se copio ogni volta
|
||
rec.put("MOD", FP_TAB_MOD);
|
||
rec.put("COD", FP_SHT_CUST);
|
||
static TString num;
|
||
num.cut(0);
|
||
num.format("%08d", n);
|
||
|
||
rec.put(FP_SHT_CODTAB, num);
|
||
|
||
// Prendo tutta la riga tranne il cod sdi
|
||
rec.put(FP_SHT_TIPODOC, r->get(0));
|
||
rec.put(FP_SHT_TIPORIGA, r->get());
|
||
rec.put(FP_SHT_COL_QTA, r->get());
|
||
rec.put(FP_SHT_COL_PREZZO, r->get());
|
||
rec.put(FP_SHT_COL_IMPONIBILE, r->get());
|
||
|
||
rec.write(tabmod);
|
||
}
|
||
}
|
||
|
||
void TFP_righe_custom::load_sheet(TSheet_field& sheet_field)
|
||
{
|
||
TRelation rel(LF_TABMOD);
|
||
TRectype rec(LF_TABMOD);
|
||
rec.put("MOD", FP_TAB_MOD);
|
||
rec.put("COD", FP_SHT_CUST);
|
||
TCursor cur(&rel, "", 1, &rec, &rec);
|
||
for (cur = 0; cur.pos() < cur.items(); ++cur)
|
||
{
|
||
TToken_string& row = sheet_field.row(-1);
|
||
TRectype& cur_rec = cur.curr();
|
||
row.add(cur_rec.get(FP_SHT_TIPODOC), 0);
|
||
row.add(cur_rec.get(FP_SHT_TIPORIGA));
|
||
row.add(cur_rec.get(FP_SHT_COL_QTA));
|
||
row.add(cur_rec.get(FP_SHT_COL_PREZZO));
|
||
row.add(cur_rec.get(FP_SHT_COL_IMPONIBILE));
|
||
}
|
||
sheet_field.force_update();
|
||
}
|
||
|
||
TFP_righe_custom::TFP_righe_custom() : _loaded(false)
|
||
{
|
||
|
||
}
|