diff --git a/src/bs/bs0300.cpp b/src/bs/bs0300.cpp index c8f9233f1..d30c93a1b 100644 --- a/src/bs/bs0300.cpp +++ b/src/bs/bs0300.cpp @@ -95,29 +95,31 @@ const TString clifo_add_note(TLocalisamfile& cfv, TString& note) class TSknet_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); - } + 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()); } + 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 TSknet_cache _anagr; @@ -130,76 +132,80 @@ static TSknet_cache _anagr; class TSknet_mask : public TAutomask { protected: - virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); + virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); public: - void autoload(); - void autosave() const; + 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); } + bool get_bool(const char* fld) + { + TMask_field* f = find_by_fieldname(fld); return f ? f->get().full() : false; + } - TSknet_mask() : TAutomask("bs0300a") { autoload(); } - ~TSknet_mask() { autosave(); } + TDate get_date(const char* fld) + { + TMask_field* f = find_by_fieldname(fld); return TDate(f ? f->get() : EMPTY_STRING); + } + + TSknet_mask() : TAutomask("bs0300a") { autoload(); } + ~TSknet_mask() { autosave(); } }; bool TSknet_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; +{ + 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 TSknet_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) - f->set(ini_get_string(CONFIG_DITTA, "bs", fr->name())); - } + // 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) + f->set(ini_get_string(CONFIG_DITTA, "bs", fr->name())); + } } void TSknet_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, "bs", fr->name(), f->get()); - } + // 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, "bs", fr->name(), f->get()); + } } /////////////////////////////////////////////////////////// @@ -210,276 +216,277 @@ typedef bool TFieldEvaluator(const TISAM_recordset& rec, const char* fldname, co class TSknet_sync : public TSkeleton_application { - TString _dsn; + TString _dsn; TString _usr; TString _psw; - TFilename _sqlog; - TLog_report* _log; + TFilename _sqlog; + TLog_report* _log; bool hasConai; 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(const char tipocf); - void add_rmov(TMovimentoPN& mov, const real& importo, const TCausale& caus, const char* cod) const; - + 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(const char tipocf); + void add_rmov(TMovimentoPN& mov, const real& importo, const TCausale& caus, const char* cod) const; + protected: - bool save_and_delete_movmag(TMov_mag*& doc) const; - bool save_and_delete_doc(TDocumento*& doc) const; - - void load_their_origine(TISAM_recordset& out_set, const char* in_table, const TString_array& pairs); + bool save_and_delete_movmag(TMov_mag*& doc) const; + bool save_and_delete_doc(TDocumento*& doc) const; - void sync_table(TISAM_recordset& in_set, const char* out_table, - const TString_array& pairs); - void sync_table(const char* in_table, const char* out_table, - const TString_array& fields); - void sync_table(const int logicnum, const char* out_table, - const TString_array& fields); + void load_their_origine(TISAM_recordset& out_set, const char* in_table, const TString_array& pairs); - void sync_iva (); - void sync_ums (); - void sync_val (); - void sync_anamag (); - void sync_doc (); - void sync_clifo (int cfmask); + void sync_table(TISAM_recordset& in_set, const char* out_table, + const TString_array& pairs); + void sync_table(const char* in_table, const char* out_table, + const TString_array& fields); + void sync_table(const int logicnum, const char* out_table, + const TString_array& fields); + + void sync_iva(); + void sync_ums(); + void sync_val(); + void sync_anamag(); + void sync_doc(); + void sync_clifo(int cfmask); void clean(); - + public: - virtual bool create(); - virtual void main_loop(); + virtual bool create(); + virtual void main_loop(); }; // Carica da BeeStore i record con Origine=their_origin(), cioè generati da lui ed eventualmente aggiorna i corrispondenti in Campo void TSknet_sync::load_their_origine(TISAM_recordset& out_set, const char* in_table, const TString_array& pairs) { - TString str(255); - str << "SELECT "; - FOR_EACH_ARRAY_ROW(pairs, f, row) - str << row->get(0) << ','; - str.rtrim(1); // toglie ultima virgola - str << "\nFROM " << in_table << " WHERE (Origine=" << their_origin() << ");"; + TString str(255); + str << "SELECT "; + FOR_EACH_ARRAY_ROW(pairs, f, row) + str << row->get(0) << ','; + str.rtrim(1); // toglie ultima virgola + str << "\nFROM " << in_table << " WHERE (Origine=" << their_origin() << ");"; - TODBC_recordset odbc(str); + TODBC_recordset odbc(str); odbc.connect(_dsn, _usr, _psw); - const TRecnotype n = odbc.items(); - if (n > 0) - { - TLocalisamfile& file = out_set.cursor()->file(); - const RecDes& rd = file.curr().rec_des(); - TToken_string key_fields; - for (int i = 0; i < rd.Ky->NkFields; i++) - { - const int nf = rd.Ky[0].FieldSeq[i] % MaxFields; - key_fields.add(rd.Fd[nf].Name); - } + const TRecnotype n = odbc.items(); + if (n > 0) + { + TLocalisamfile& file = out_set.cursor()->file(); + const RecDes& rd = file.curr().rec_des(); + TToken_string key_fields; + for (int i = 0; i < rd.Ky->NkFields; i++) + { + const int nf = rd.Ky[0].FieldSeq[i] % MaxFields; + key_fields.add(rd.Fd[nf].Name); + } - str.format(TR("Importazione %ld record dalla tabella %s"), n, in_table); - _log->log(0, ""); - _log->log(0, str); - - TProgress_monitor pi(n, str); - for (bool ok = odbc.move_first(); ok; ok = odbc.move_next()) - { - file.zero(); - TString80 cfld, bfld; // Campo field, BeeStore field e cut field + str.format(TR("Importazione %ld record dalla tabella %s"), n, in_table); + _log->log(0, ""); + _log->log(0, str); + + TProgress_monitor pi(n, str); + for (bool ok = odbc.move_first(); ok; ok = odbc.move_next()) + { + file.zero(); + TString80 cfld, bfld; // Campo field, BeeStore field e cut field int ffld, tfld; - FOR_EACH_ARRAY_ROW(pairs, p, row) - { - bfld = row->get(0); - cfld = row->get(); + FOR_EACH_ARRAY_ROW(pairs, p, row) + { + bfld = row->get(0); + cfld = row->get(); ffld = row->get_int(); ffld--; tfld = row->get_int(); tfld--; - const int pos = key_fields.get_pos(cfld); - if (pos >= 0) - { - const TVariant& var = odbc.get(bfld); + const int pos = key_fields.get_pos(cfld); + if (pos >= 0) + { + const TVariant& var = odbc.get(bfld); if (!var.is_null()) { - if(tfld > 0) - file.put(cfld, var.as_string().mid(ffld, tfld-ffld)); + if (tfld > 0) + file.put(cfld, var.as_string().mid(ffld, tfld - ffld)); else file.put(cfld, var.as_string()); } - if (pos == key_fields.items()-1) - break; - } - } - - int err = file.read(_isequal, _lock); - if (err == NOERR) - { - bool dirty = false; - const TDate dataagg = file.get(CLI_DATAAGG); - TDate dtultagg = odbc.get(BS_DTULTAGG).as_date(); - if (!dtultagg.ok()) dtultagg = TODAY; + if (pos == key_fields.items() - 1) + break; + } + } - str = "record"; - FOR_EACH_TOKEN(key_fields, f) - str << ' ' << file.get(f); + int err = file.read(_isequal, _lock); + if (err == NOERR) + { + bool dirty = false; + const TDate dataagg = file.get(CLI_DATAAGG); + TDate dtultagg = odbc.get(BS_DTULTAGG).as_date(); + if (!dtultagg.ok()) dtultagg = TODAY; - if (dtultagg >= dataagg) - { - FOR_EACH_ARRAY_ROW(pairs, r,row) - { - bfld = row->get(0); - cfld = row->get(); + str = "record"; + FOR_EACH_TOKEN(key_fields, f) + str << ' ' << file.get(f); + + if (dtultagg >= dataagg) + { + FOR_EACH_ARRAY_ROW(pairs, r, row) + { + bfld = row->get(0); + cfld = row->get(); ffld = row->get_int(); ffld--; tfld = row->get_int(); tfld--; - if (cfld[0] >= 'A' && cfld.find("->") < 0 && key_fields.get_pos(cfld) < 0) // Aggiorno solo i campi NON chiave - { - const TString& vec = file.get(cfld); - const TString& nov = odbc.get(bfld).as_string(); - if (nov != vec) - { - if (!dirty) - str << ' ' << bfld << "='" << nov << '\''; + if (cfld[0] >= 'A' && cfld.find("->") < 0 && key_fields.get_pos(cfld) < 0) // Aggiorno solo i campi NON chiave + { + const TString& vec = file.get(cfld); + const TString& nov = odbc.get(bfld).as_string(); + if (nov != vec) + { + if (!dirty) + str << ' ' << bfld << "='" << nov << '\''; if (tfld > 0) file.put(cfld, nov.mid(ffld, tfld - ffld)); else file.put(cfld, nov); - dirty = true; - } - } - } - if (dirty) - { - TRectype& rec = file.curr(); - if (rec.exist(CLI_UTENTE)) - rec.put(CLI_UTENTE, ini_get_string(CONFIG_DITTA, "bs", "SKImportUser")); - if (rec.exist(CLI_DATAAGG)) - rec.put(CLI_DATAAGG, dtultagg); - } - else - str << " Nessuna variazione pertinente"; - } - else - str << " Data di ultimo aggiornamento obsoleta"; - if (dirty) - { - if (file.rewrite() == 0) - _log->log(1, 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) - { - file.zero(); - FOR_EACH_ARRAY_ROW(pairs, r,row) - { - bfld = row->get(0); - cfld = row->get(); - ffld = row->get_int(); ffld--; - tfld = row->get_int(); tfld--; - if (cfld[0] >= 'A' && cfld.find("->")) - { - const TString& nov = odbc.get(bfld).as_string(); - if (tfld > 0) - file.put(cfld, nov.mid(ffld, tfld - ffld)); - else - file.put(cfld, nov); - } - } - if (file.write() == 0) - _log->log(1, str); - else - { - TString80 msg; msg << TR("ERRORE ") << err << TR(" inserendo il "); - str.insert(msg); - _log->log(2, str); - } - } - } + dirty = true; + } + } + } + if (dirty) + { + TRectype& rec = file.curr(); + if (rec.exist(CLI_UTENTE)) + rec.put(CLI_UTENTE, ini_get_string(CONFIG_DITTA, "bs", "SKImportUser")); + if (rec.exist(CLI_DATAAGG)) + rec.put(CLI_DATAAGG, dtultagg); + } + else + str << " Nessuna variazione pertinente"; + } + else + str << " Data di ultimo aggiornamento obsoleta"; + if (dirty) + { + if (file.rewrite() != 0) + { + TString80 err; err << TR("ERRORE ") << err << TR(" aggiornando il "); + str.insert(err); + _log->log(2, str); + } + } + else + { + file.reread(_unlock); + } + } + else + if (err == _iskeynotfound) + { + file.zero(); + FOR_EACH_ARRAY_ROW(pairs, r, row) + { + bfld = row->get(0); + cfld = row->get(); + ffld = row->get_int(); ffld--; + tfld = row->get_int(); tfld--; + if (cfld[0] >= 'A' && cfld.find("->")) + { + const TString& nov = odbc.get(bfld).as_string(); + if (tfld > 0) + file.put(cfld, nov.mid(ffld, tfld - ffld)); + else + file.put(cfld, nov); + } + } + if (file.write() == 0) + _log->log(1, str); + else + { + TString80 msg; msg << TR("ERRORE ") << err << TR(" inserendo il "); + str.insert(msg); + _log->log(2, str); + } + } + } } } void TSknet_sync::sync_table(TISAM_recordset& in_set, const char* out_table, const TString_array& fields) { - load_their_origine(in_set, out_table, fields); + load_their_origine(in_set, out_table, fields); } static TString& build_query(const char* table) { - TString& q = get_tmp_string(); - q << "USE " << table; - return q; + TString& q = get_tmp_string(); + q << "USE " << table; + return q; } static TString& build_query(const int logicnum) { - const TRectype rec(logicnum); - TString& q = get_tmp_string(); - q << "USE " << logicnum; + const TRectype rec(logicnum); + TString& q = get_tmp_string(); + q << "USE " << logicnum; - if (rec.exist(CLI_UTENTE)) - q << " SELECT (UTENTE!=\"" << ini_get_string(CONFIG_DITTA, "bs", "SKImportUser") << "\")"; + if (rec.exist(CLI_UTENTE)) + q << " SELECT (UTENTE!=\"" << ini_get_string(CONFIG_DITTA, "bs", "SKImportUser") << "\")"; - return q; + return q; } -void TSknet_sync::sync_table(const char* table, const char* out_table, - const TString_array& fields) +void TSknet_sync::sync_table(const char* table, const char* out_table, + const TString_array& fields) { - const TString& q = build_query(table); - TISAM_recordset set(q); - sync_table(set, out_table, fields); + const TString& q = build_query(table); + TISAM_recordset set(q); + sync_table(set, out_table, fields); } -void TSknet_sync::sync_table(const int logicnum, const char* out_table, - const TString_array& fields ) +void TSknet_sync::sync_table(const int logicnum, const char* out_table, + const TString_array& fields) { - const TString& q = build_query(logicnum); - TISAM_recordset set(q); - sync_table(set, out_table, fields); + const TString& q = build_query(logicnum); + TISAM_recordset set(q); + sync_table(set, out_table, fields); } void TSknet_sync::sync_ums() { - TString_array fields; - fields.add("CodUntMis|CODTAB"); - fields.add("DSUntMis|S0"); - sync_table("%UMS", "tieUntMisura", fields); + TString_array fields; + fields.add("CodUntMis|CODTAB"); + fields.add("DSUntMis|S0"); + sync_table("%UMS", "tieUntMisura", fields); } void TSknet_sync::sync_iva() { - TString_array fields; - fields.add("CodIva|CODTAB"); - fields.add("CodIvaSt|CODTAB"); - fields.add("DSIva|S0"); - fields.add("Aliquota|R0"); + TString_array fields; + fields.add("CodIva|CODTAB"); + fields.add("CodIvaSt|CODTAB"); + fields.add("DSIva|S0"); + fields.add("Aliquota|R0"); - sync_table("%IVA", "tieIva", fields); + sync_table("%IVA", "tieIva", fields); } void TSknet_sync::sync_anamag() { - TString_array fields; - fields.add("CodPadre|" ANAMAG_CODART); - fields.add("DSArticolo|" ANAMAG_DESCR); - fields.add("DSArticoloAgg|" ANAMAG_DESCRAGG "|1|70"); - fields.add("CodUntMagazzino|49->UM"); - fields.add("CodIva|" ANAMAG_CODIVA); - fields.add("CodLinea|" ANAMAG_GRMERC "|1|3"); - fields.add("CodCategMerceologica|" ANAMAG_GRMERC); - fields.add("Bloccato|" ANAMAG_SOSPESO); + TString_array fields; + fields.add("CodPadre|" ANAMAG_CODART); + fields.add("DSArticolo|" ANAMAG_DESCR); + fields.add("DSArticoloAgg|" ANAMAG_DESCRAGG "|1|70"); + fields.add("CodUntMagazzino|49->UM"); + fields.add("CodIva|" ANAMAG_CODIVA); + fields.add("CodLinea|" ANAMAG_GRMERC "|1|3"); + fields.add("CodCategMerceologica|" ANAMAG_GRMERC); + fields.add("ArtGruppo|" ANAMAG_GRUPPOV); + fields.add("ArtConto|" ANAMAG_CONTOV); + fields.add("ArtSottoconto|" ANAMAG_SOTTOCV); + fields.add("Bloccato|" ANAMAG_SOSPESO); - TString query = build_query(LF_ANAMAG); - query << "\nJOIN " << LF_UMART << " INTO CODART==CODART"; + TString query = build_query(LF_ANAMAG); + query << "\nJOIN " << LF_UMART << " INTO CODART==CODART"; - TISAM_recordset art(query); - sync_table(art, "tieArticoli", fields); + TISAM_recordset art(query); + sync_table(art, "tieArticoli", fields); // Controllo se esistono varianti e le aggiungo query.cut(0) << "SELECT * FROM tieArtVarianti where origine=" << their_origin(); @@ -546,14 +553,14 @@ void TSknet_sync::sync_anamag() /* catCON.format("%4 s%4 s%4 s%4 s%4 s%4 s", - odbc.get("CatAC").as_string().left(4), // Categoria Acciaio - odbc.get("CatAL").as_string().left(4), // Categoria Alluminio - odbc.get("CatCA").as_string().left(4), // Categoria Carta - odbc.get("CatLE").as_string().left(4), // Categoria Legno - odbc.get("CatPL").as_string().left(4), // Categoria Plastica - odbc.get("CatVE").as_string().left(4) // Categoria Vetro - ); - */ + odbc.get("CatAC").as_string().left(4), // Categoria Acciaio + odbc.get("CatAL").as_string().left(4), // Categoria Alluminio + odbc.get("CatCA").as_string().left(4), // Categoria Carta + odbc.get("CatLE").as_string().left(4), // Categoria Legno + odbc.get("CatPL").as_string().left(4), // Categoria Plastica + odbc.get("CatVE").as_string().left(4) // Categoria Vetro + ); + */ rart.put(ANAMAG_CONAISC, catCON); rart.put(ANAMAG_CONACC, odbc.get("PesoAC").as_real()); // Peso Acciaio rart.put(ANAMAG_CONALL, odbc.get("PesoAL").as_real()); // Peso Alluminio @@ -564,7 +571,7 @@ void TSknet_sync::sync_anamag() art.rewrite(rart); } else - // EROR! EROR! + // EROR! EROR! { bool tolla = true; } @@ -574,204 +581,204 @@ void TSknet_sync::sync_anamag() static bool ClifoEvaluator(const TISAM_recordset& rec, const char* fldname, const char* expr, TVariant& var) { - const TAnagrafica& a = _anagr.anag(rec); + 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 = rec.get(CLI_TIPOCF).as_string()[0]; - const long c = rec.get(CLI_CODCF).as_int(); - 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(); - 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(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, "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 = rec.get(CLI_TIPOCF).as_string()[0]; + const long c = rec.get(CLI_CODCF).as_int(); + 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(); + 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(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'; - } + 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; + return false; } const TString& TSknet_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); + 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 TSknet_sync::split_phone(const TRecordset& odbc, const char* number, TIsamfile& clifo, const char* pre, const char* num) const +bool TSknet_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; - } - } + 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(pre, ""); - clifo.put(num, pn); - } - } - return pn.full(); + 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(); } void TSknet_sync::load_clifo(const char tipocf) { - TString str(255); - str << "SELECT * FROM tieAnagCFP WHERE (Origine=" << their_origin() << ")AND"; - str << '(' << (tipocf == 'F' ? "Fornitore" : "Cliente") << "=1);"; + TString str(255); + str << "SELECT * FROM tieAnagCFP WHERE (Origine=" << their_origin() << ")AND"; + str << '(' << (tipocf == 'F' ? "Fornitore" : "Cliente") << "=1);"; - TFast_isamfile clifo(LF_CLIFO); + TFast_isamfile clifo(LF_CLIFO); - TODBC_recordset odbc(str); + TODBC_recordset odbc(str); odbc.connect(_dsn, _usr, _psw); - const TRecnotype n = odbc.items(); + 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()) - { + 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()) + { if (odbc.get("Cod_PK").as_string().len() == 1) continue; - 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(); - codcf = atol(cod_pk.mid(1)); - } + 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(); + codcf = atol(cod_pk.mid(1)); + } TLocalisamfile cfv(LF_CFVEN); 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 - { + { + 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 + { // NON É POSSIBILE TString err = "Attenzione è prensente un cliente con codice errato: "; err << odbc.get("Cod_PK").as_string() << " Non verrà importato."; _log->log(2, err); continue; - } + } cfv.put(CFV_TIPOCF, tipocf); cfv.put(CFV_CODCF, codcf); @@ -784,36 +791,37 @@ void TSknet_sync::load_clifo(const char tipocf) cfv.put(CFV_CODPRCF, codprcf); } - clifo.put(CLI_RAGSOC, odbc.get("RagSoc").as_string()); + clifo.put(CLI_RAGSOC, odbc.get("RagSoc").as_string()); clifo.put(CLI_PAIV, odbc.get("PartitaIva").as_string()); - clifo.put(CLI_COFI, odbc.get("CodiceFiscale").as_string()); + clifo.put(CLI_COFI, odbc.get("CodFiscale").as_string()); clifo.put(CLI_MAIL, odbc.get("EMail").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'); + 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); - } + 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)); + clifo.put(CLI_INDCF, ind.left(50)); + clifo.put(CLI_CAPCF, civ); clifo.put(CLI_CAPCF, odbc.get("Cap").as_string()); // Stato @@ -821,7 +829,7 @@ void TSknet_sync::load_clifo(const char tipocf) if (statoISO.empty()) statoISO = "IT"; clifo.put(CLI_STATOPAIV, statoISO); - + // Se lo stato no è Italia devo fare una ricerca scomoda e lenta in %STA if (statoISO != "IT") { @@ -830,7 +838,7 @@ void TSknet_sync::load_clifo(const char tipocf) partCom.zero(); partCom.put("COD", "STA"); TCursor cur(&relCom, "", 1, &partCom, &partCom); - for(cur = 0; cur.pos() < cur.items(); ++cur) + for (cur = 0; cur.pos() < cur.items(); ++cur) if (cur.curr().get("S10") == statoISO) { stato = cur.curr().get("CODTAB"); @@ -845,7 +853,7 @@ void TSknet_sync::load_clifo(const char tipocf) TLocalisamfile isamComuni(LF_COMUNI); comune = odbc.get("Citta").as_string(); - + isamComuni.put("STATO", stato); isamComuni.put("COM", comune); errComuni = isamComuni.read(_isequal); @@ -862,11 +870,11 @@ void TSknet_sync::load_clifo(const char tipocf) clifo.put(CLI_COMCF, comune); - 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); - split_phone(odbc, "Fax", clifo, CLI_PFAX, CLI_FAX); - clifo.put(CLI_MAIL, odbc.get("EMail").as_string()); + 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); + split_phone(odbc, "Fax", clifo, CLI_PFAX, CLI_FAX); + clifo.put(CLI_MAIL, odbc.get("EMail").as_string()); clifo.put(CLI_CODPAG, odbc.get("Cli_CodPagamento").as_string()); if (hasConai) @@ -878,8 +886,8 @@ void TSknet_sync::load_clifo(const char tipocf) cfv.put(CFV_ESPLA, odbc.get("CNEspl").as_string()); // Esenzione Plastica cfv.put(CFV_ESLEG, odbc.get("CNEsle").as_string()); // Esenzione Legno cfv.put(CFV_ESVET, odbc.get("CNEsve").as_string()); // Esenzione Vetro - - // So bad is so good! + + // So bad is so good! TString prodConai; prodConai << (odbc.get("CNPac").as_int() == 1 ? "X" : " "); // Produttore Acciaio prodConai << (odbc.get("CNPal").as_int() == 1 ? "X" : " "); // Produttore Alluminio @@ -943,16 +951,25 @@ void TSknet_sync::load_clifo(const char tipocf) } } + // Abi e Cab sempre, posso anche avere solo il primo dei due + cfb.put("ABI", abi); + cfb.put("CAB", cab); + // Il conto corrente ovviamente solo se è giusto if (err == NOERR) { - cfb.put("ABI", abi); - cfb.put("CAB", cab); cfb.put("NUMCC", contcor); cfb.put("IBAN", iban); } + // Always true + cfv.put(CFV_RAGGEFF, true); + cfv.put(CFV_ADDBOLLI, true); + + // Non ho capito se alla fine mi passa qua i dati o nel campo NOTE + cfv.put(CFV_ASSFIS, tipocf == 'C' ? odbc.get("Cli_CodIva").as_string() : odbc.get("For_CodIva").as_string()); + // Parso il campo Note - TToken_string note (odbc.get("Note").as_string()); + TToken_string note(odbc.get("Note").as_string()); if (!note.blank() && note[note.len() - 1] == '|') note.cut(note.len() - 1); for (int i = 0; i < note.items(); i++) @@ -976,15 +993,17 @@ void TSknet_sync::load_clifo(const char tipocf) nonscd.cut(nonscd.len() - 1); cfv.put(CFV_NONACCEFF, nonacc); cfv.put(CFV_NONSCADEFF, nonscd); - } else + } + else if (token.starts_with("RE=")) { - cfv.put(CFV_RAGGEFF, token == "RE=X"); - } else + // Disabled, always true by analysis + } + else if (token.starts_with("NOTE=")) { TString note = token.mid(5); - if(!note.blank()) + if (!note.blank()) cfv.put(CFV_CODNOTE, clifo_add_note(cfv, note)); } else @@ -1000,22 +1019,31 @@ void TSknet_sync::load_clifo(const char tipocf) clifo.put(CLI_BYMAIL, bymail); clifo.put(CLI_DOCMAIL, email); } + else if (token.starts_with("REF=")) { clifo.put(CLI_REFERENTE, token.mid(4)); } + else if (token.starts_with("EDOC=")) { clifo.put(CLI_BYMAIL, true); clifo.put(CLI_DOCMAIL, token.mid(5)); } + else if (token.starts_with("SCONTO=")) { - clifo.put(CLI_SCONTO, token.mid(7)); + cfv.put(CFV_SCONTO, token.mid(7)); } + else if (token.starts_with("AGENT=")) { - clifo.put(CLI_CODAG, token.mid(6)); + cfv.put(CFV_CODAG, token.mid(6)); + } + else + if (token.starts_with("ASSFIS=")) + { + cfv.put(CFV_ASSFIS, token.mid(7)); } else { @@ -1036,24 +1064,24 @@ void TSknet_sync::load_clifo(const char tipocf) TString user = ini_get_string(CONFIG_DITTA, "BS", "SKImportUser"); if (user.empty()) user = "BEESTORE"; - clifo.put(CLI_UTENTE, user); - TDate dua = odbc.get(BS_DTULTAGG).as_date(); - if (!dua.ok()) dua = TDate(TODAY); - clifo.put(CLI_DATAAGG, dua); - + clifo.put(CLI_UTENTE, user); + TDate dua = odbc.get(BS_DTULTAGG).as_date(); + if (!dua.ok()) dua = TDate(TODAY); + clifo.put(CLI_DATAAGG, dua); + cfb.write_rewrite(); cfv.write_rewrite(); - clifo.write_rewrite(); + clifo.write_rewrite(); - if (!pi.add_status()) - break; - } + if (!pi.add_status()) + break; + } } void TSknet_sync::sync_clifo(int cfmask) { - if (cfmask & 1) load_clifo('C'); - if (cfmask & 2) load_clifo('F'); + if (cfmask & 1) load_clifo('C'); + if (cfmask & 2) load_clifo('F'); } void TSknet_sync::clean() @@ -1101,144 +1129,148 @@ void TSknet_sync::clean() bool TSknet_sync::save_and_delete_movmag(TMov_mag*& doc) const { - int err = 0; - if (doc != NULL) - { - if (doc->rows() > 0) - { - TLocalisamfile mm(LF_MOVMAG); - err = doc->write(mm); - if (err != NOERR) - { - TString msg; - msg.format(FR("Errore %d in registrazione scontrino %ld del %s"), err, - doc->get_long(MOVMAG_NUMREG), (const char*)doc->get(MOVMAG_DATAREG)); - _log->log(2, msg); - msg << TR("\nSi desidera proseguire ugualmente?"); - if (noyes_box(msg)) - err = 0; - } - } - delete doc; - doc = NULL; - } - return err == 0; + int err = 0; + if (doc != NULL) + { + if (doc->rows() > 0) + { + TLocalisamfile mm(LF_MOVMAG); + err = doc->write(mm); + if (err != NOERR) + { + TString msg; + msg.format(FR("Errore %d in registrazione scontrino %ld del %s"), err, + doc->get_long(MOVMAG_NUMREG), (const char*)doc->get(MOVMAG_DATAREG)); + _log->log(2, msg); + msg << TR("\nSi desidera proseguire ugualmente?"); + if (noyes_box(msg)) + err = 0; + } + } + delete doc; + doc = NULL; + } + return err == 0; } bool TSknet_sync::save_and_delete_doc(TDocumento*& doc) const { - int err = 0; - if (doc != NULL) - { - if (doc->rows() > 0) - { - err = doc->write(); - if (err != NOERR) - { - TString msg; + int err = 0; + if (doc != NULL) + { + if (doc->rows() > 0) + { + err = doc->write(); + if (err != NOERR) + { + TString msg; - msg.format(FR("Errore %d in registrazione dcoumento %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; - } - } - delete doc; - doc = NULL; - } - return err == 0; + msg.format(FR("Errore %d in registrazione dcoumento %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; + } + } + delete doc; + doc = NULL; + } + return err == 0; } void TSknet_sync::sync_val() { - TString_array fields; - fields.add("CodValuta|CODTAB"); - fields.add("DSValuta|S0"); - fields.add("Simbolo|CODTAB"); - sync_table("%VAL", "tieValute", fields); + TString_array fields; + fields.add("CodValuta|CODTAB"); + fields.add("DSValuta|S0"); + fields.add("Simbolo|CODTAB"); + sync_table("%VAL", "tieValute", fields); } void TSknet_sync::sync_doc() { - const TString8 codcausdef = ini_get_string(CONFIG_DITTA, "bs", MOVMAG_CODCAUS, "", 2); -/* + const TString8 codcausdef = ini_get_string(CONFIG_DITTA, "bs", MOVMAG_CODCAUS, "", 2); + /* if (codcausdef.blank()) - { - _log->log(2, "Configurare parametri per movimenti Bee Store"); - return; - } -*/ - TString str(255); + { + _log->log(2, "Configurare parametri per movimenti Bee Store"); + return; + } + */ + TString str(255); str << "SELECT tieDMovMag.*, tieTBolFat.*, tieTBolFat.Annullato AS DOCANNULLATO, tieDMovMagCONAI.*\n"; str << "FROM tieDMovMag\nRIGHT JOIN tieTBolFat ON tieDMovMag.CodTestata = tieTBolFat.Cod_PK\n"; - if(hasConai) + if (hasConai) str << "LEFT JOIN tieDMovMagCONAI ON tieDMovMag.Cod_PK = tieDMovMagCONAI.Cod_PK\n"; str << "WHERE tieTBolFat.Origine = " << their_origin(); //str << "WHERE tieDMovMag.Origine = " << their_origin() << " AND tieDMovMag.TipoTestata = 2"; // verificare - str << "\nORDER BY tieTBolFat.Cod_PK,tieDMovMag.NumRiga"; + str << "\nORDER BY tieTBolFat.Cod_PK,tieDMovMag.NumRiga"; - TODBC_recordset docs(str); + TODBC_recordset docs(str); docs.connect(_dsn, _usr, _psw); - TProgress_monitor pi(docs.items(), str); + TProgress_monitor pi(docs.items(), str); - long num_doc = -1, nd, codcf ; + long num_doc = -1, nd, codcf; TString4 tipocf; - TDocumento* doc = NULL; + TDocumento* doc = NULL; - for (bool ok = docs.move_first(); ok; ok = docs.move_next()) - { + for (bool ok = docs.move_first(); ok; ok = docs.move_next()) + { //TToken_string test(docs.get("CodTestata").as_string(), '\\'); const TString keyDoc = docs.get("CodTestata").as_string(); nd = docs.get("NumRif").as_int(); - TString wrk = docs.get("CodCliente").as_string(); - - while(wrk[0] >= 'A') + TString wrk = docs.get("CodCliente").as_string(); + + while (wrk[0] >= 'A') wrk.ltrim(1); - + codcf = atol(wrk); tipocf = docs.get("TipoIntestatario").as_string(); - if (tipocf != "C" && tipocf != "F") - warning_box("Attenzione! Per il doc n.%d è presente il tipo C/F = '%s'\nIl documento verrà saltato.", nd , tipocf); + if ((tipocf != "C" && tipocf != "F") || codcf == 0) + { + TString msg; msg.format("Attenzione! Per il doc n.%d è presente il tipo C/F = '%s' con cod = %d \nIl documento verrà saltato.", nd, tipocf, codcf); + _log->log(1, msg); + continue; + } - if (nd != num_doc) - { - if (num_doc > 0 && !save_and_delete_doc(doc)) - break; - num_doc = nd; - const TDate datadoc = docs.get("DataMov").as_date(); + if (nd != num_doc) + { + if (num_doc > 0 && !save_and_delete_doc(doc)) + break; + num_doc = nd; + const TDate datadoc = docs.get("DataMov").as_date(); TString8 numdoc; TString8 tipodoc; // Controllo se ho ricevuto un codice Campo per il TipoDoc o devo prenderlo dalle impostazioni - if(docs.get("TipoDocCE").is_empty()) + if (docs.get("TipoDocCE").is_empty()) { switch (docs.get("TipoDoc").as_int()) { - case 1: // Bolla - numdoc = ini_get_string(CONFIG_DITTA, "BS", "SKCODNUMBOL"); - tipodoc = ini_get_string(CONFIG_DITTA, "BS", "SKTIPODOCBOL"); - break; - case 2: // Fattura - numdoc = ini_get_string(CONFIG_DITTA, "BS", "SKCODNUMFAT"); - tipodoc = ini_get_string(CONFIG_DITTA, "BS", "SKTIPODOCFAT"); - break; - case 6: // NC - numdoc = ini_get_string(CONFIG_DITTA, "BS", "SKCODNUMNC"); - tipodoc = ini_get_string(CONFIG_DITTA, "BS", "SKTIPODOCNC"); - break; - case 7: // Richiesta Trasferimento da Altro Magazzino - numdoc = ini_get_string(CONFIG_DITTA, "BS", "SKCODNUMTAM"); - tipodoc = ini_get_string(CONFIG_DITTA, "BS", "SKTIPODOCTAM"); - break; - case 9: // Ordine Cliente - numdoc = ini_get_string(CONFIG_DITTA, "BS", "SKCODNUMORC"); - tipodoc = ini_get_string(CONFIG_DITTA, "BS", "SKTIPODOCORC"); - break; - default: - warning_box("Attenzione! Per il doc con codice: %s è presente un tipo documento non supportato.\nIl documento saltato", keyDoc); + case 1: // Bolla + numdoc = ini_get_string(CONFIG_DITTA, "BS", "SKCODNUMBOL"); + tipodoc = ini_get_string(CONFIG_DITTA, "BS", "SKTIPODOCBOL"); + break; + case 2: // Fattura + numdoc = ini_get_string(CONFIG_DITTA, "BS", "SKCODNUMFAT"); + tipodoc = ini_get_string(CONFIG_DITTA, "BS", "SKTIPODOCFAT"); + break; + case 6: // NC + numdoc = ini_get_string(CONFIG_DITTA, "BS", "SKCODNUMNC"); + tipodoc = ini_get_string(CONFIG_DITTA, "BS", "SKTIPODOCNC"); + break; + case 7: // Richiesta Trasferimento da Altro Magazzino + numdoc = ini_get_string(CONFIG_DITTA, "BS", "SKCODNUMTAM"); + tipodoc = ini_get_string(CONFIG_DITTA, "BS", "SKTIPODOCTAM"); + break; + case 9: // Ordine Cliente + numdoc = ini_get_string(CONFIG_DITTA, "BS", "SKCODNUMORC"); + tipodoc = ini_get_string(CONFIG_DITTA, "BS", "SKTIPODOCORC"); + break; + default: + warning_box("Attenzione! Per il doc con codice: %s è presente un tipo documento non supportato.\nIl documento saltato", keyDoc); } } else @@ -1247,7 +1279,7 @@ void TSknet_sync::sync_doc() tipodoc = docs.get("TipoDocCE").as_string(); } - if(numdoc.blank() || tipodoc.blank()) + if (numdoc.blank() || tipodoc.blank()) { _log->log(2, "Configurare parametri per movimenti Bee Store"); return; @@ -1272,22 +1304,22 @@ void TSknet_sync::sync_doc() continue; } } - + /* // Salto i documenti annullati if (docs.get("tieTBolFat.Annullato").as_int() == 1) - continue; + continue; */ - doc = new TDocumento(); - doc->put(DOC_ANNO, datadoc.year()); - doc->put(DOC_DATADOC, datadoc); - doc->put(DOC_NDOC, nd); - doc->put(DOC_PROVV, "D"); - doc->put(DOC_CODNUM, numdoc); - doc->put(DOC_TIPODOC, tipodoc); - doc->put(DOC_TIPOCF, tipocf); - doc->put(DOC_CODCF, codcf); + doc = new TDocumento(); + doc->put(DOC_ANNO, datadoc.year()); + doc->put(DOC_DATADOC, datadoc); + doc->put(DOC_NDOC, nd); + doc->put(DOC_PROVV, "D"); + doc->put(DOC_CODNUM, numdoc); + doc->put(DOC_TIPODOC, tipodoc); + doc->put(DOC_TIPOCF, tipocf); + doc->put(DOC_CODCF, codcf); doc->cli2doc(); const TString8 codval = docs.get("CodValuta").as_string(); @@ -1296,11 +1328,22 @@ void TSknet_sync::sync_doc() const int ncolli = docs.get("NumeroColli").as_int(); doc->put(DOC_CODVAL, codval); - doc->put(DOC_CAMBIO, cambio); - doc->put(DOC_ASPBENI1, asp.sleft(50)); - doc->put(DOC_ASPBENI2, asp.smid(50)); - doc->put(DOC_NCOLLI, ncolli); - doc->put(DOC_CAUSMAG, codcaus); + doc->put(DOC_CAMBIO, cambio); + doc->put(DOC_ASPBENI1, asp.sleft(50)); + doc->put(DOC_ASPBENI2, asp.smid(50)); + doc->put(DOC_NCOLLI, ncolli); + doc->put(DOC_CAUSMAG, codcaus); + + const TString codAg = docs.get("CodAgente").as_string(); + const TString codPag = docs.get("CodPagamento").as_string(); + + if (!codAg.blank()) + doc->put(DOC_CODAG, codAg); + + if (!codPag.blank()) + doc->put(DOC_CODPAG, codPag); + + } const int tipoart = docs.get("TipoArticolo").as_int(); TString4 tiporiga; @@ -1317,7 +1360,7 @@ void TSknet_sync::sync_doc() default: case 0: // Tiporiga 1 -> Merce - tiporiga = "01"; + tiporiga = "01"; break; case 1: // Se la QTA è 0 sarà una spesa a spesa a valore @@ -1349,17 +1392,17 @@ void TSknet_sync::sync_doc() TLocalisamfile codcor(LF_CODCORR); codcor.setkey(2); TRectype rcodcor(LF_CODCORR); rcodcor.put(CODCORR_CODARTALT, codart); - if(codcor.read(rcodcor, _isequal) == NOERR) + if (codcor.read(rcodcor, _isequal) == NOERR) tiporiga = ini_get_string(CONFIG_DITTA, "BS", "SKNumCustomRiga", "14"); } - TRectype& rdoc = doc->new_row(tiporiga); - + TRectype& rdoc = doc->new_row(tiporiga); + rdoc.put(RDOC_CODART, codart); if (tipoart == 2) { - if (cache().get("SPP" , codart).not_empty()) + if (cache().get("SPP", codart).not_empty()) rdoc.put(RDOC_CODARTMAG, codart); } else @@ -1369,24 +1412,24 @@ void TSknet_sync::sync_doc() } rdoc.put(RDOC_CODARTMAG, codart); -// rdoc.check_row(); - + // rdoc.check_row(); + const TString descr = docs.get("DSRiga").as_string(); - + rdoc.put(RDOC_DESCR, descr.sleft(50)); if (descr.len() > 50) { - rdoc.put(RDOC_DESCLUNGA, "X"); - rdoc.put(RDOC_DESCEST, descr.smid(50)); + rdoc.put(RDOC_DESCLUNGA, "X"); + rdoc.put(RDOC_DESCEST, descr.smid(50)); } - rdoc.put(RDOC_CODMAG, docs.get("CodMagazzino").as_string().left(5)); - rdoc.put(RDOC_CODMAGC, docs.get("CodMagazDest").as_string().left(5)); + rdoc.put(RDOC_CODMAG, docs.get("CodMagazzino").as_string().left(5)); + rdoc.put(RDOC_CODMAGC, docs.get("CodMagazDest").as_string().left(5)); TString ums = docs.get("CodUntMis").as_string(); - if(ums.blank() && cache().get("%TRI", tiporiga, "S7") == "M") + if (ums.blank() && cache().get("%TRI", tiporiga, "S7") == "M") ums = ini_get_string(CONFIG_DITTA, "BS", "SKCodUmsDef"); - rdoc.put(RDOC_UMQTA, ums); - rdoc.put(RDOC_QTA, docs.get("Quantita").as_real()); - rdoc.put(RDOC_PREZZO, docs.get("PrzNettoSede").as_real()); // o PrzNettoValuta ?? + rdoc.put(RDOC_UMQTA, ums); + rdoc.put(RDOC_QTA, docs.get("Quantita").as_real()); + rdoc.put(RDOC_PREZZO, docs.get("PrzNettoSede").as_real()); // o PrzNettoValuta ?? real valsconto1(docs.get("Sconto1").as_real()); real valsconto2(docs.get("Sconto2").as_real()); @@ -1423,7 +1466,10 @@ void TSknet_sync::sync_doc() } rdoc.put(RDOC_SCONTO, sconto); - + // Provvigione agenti + rdoc.put(RDOC_PERCPROV, docs.get("PercProvv").as_real()); + + // "CONSCACC", "CONSCALL", "CONSCCAR", "CONSCPLA", "CONSCLEG", "CONSCVET" TString keyCli; keyCli << tipocf << "|" << codcf; if (hasConai && cache().get(LF_CFVEN, keyCli, "ADDCONAI") == "X") @@ -1461,83 +1507,83 @@ void TSknet_sync::sync_doc() } } - if (!pi.add_status()) - break; - } - save_and_delete_doc(doc); // Salva ultimo documento in sospeso + if (!pi.add_status()) + break; + } + save_and_delete_doc(doc); // Salva ultimo documento in sospeso } bool TSknet_sync::create() { - _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")); + _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")); hasConai = ini_get_bool(CONFIG_DITTA, "BS", "SKEnabCONAI", 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 (_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); 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); - + 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 TSknet_sync::main_loop() { - TSknet_mask mask; + TSknet_mask mask; - while (mask.run() == K_ENTER) - { - mask.autosave(); // Rende definitivi tutti i paramentri in [bs] - _log = new TLog_report; + while (mask.run() == K_ENTER) + { + mask.autosave(); // Rende definitivi tutti i paramentri in [bs] + _log = new TLog_report; - if (mask.get_bool("SKSyncUMS")) - sync_ums(); - if (mask.get_bool("SKSyncIVA")) - sync_iva(); - if (mask.get_bool("SKSyncAnamag")) - sync_anamag(); + if (mask.get_bool("SKSyncUMS")) + sync_ums(); + if (mask.get_bool("SKSyncIVA")) + sync_iva(); + if (mask.get_bool("SKSyncAnamag")) + sync_anamag(); - if (mask.get_bool("SKSyncVAL")) - sync_val(); + if (mask.get_bool("SKSyncVAL")) + sync_val(); - int cfmask = 0; - if (mask.get_bool("SKSyncClienti")) cfmask |= 1; - if (mask.get_bool("SKSyncFornitori")) cfmask |= 2; - if (cfmask) - sync_clifo(cfmask); - - if (mask.get_bool("SKSyncDoc")) - sync_doc(); + int cfmask = 0; + if (mask.get_bool("SKSyncClienti")) cfmask |= 1; + if (mask.get_bool("SKSyncFornitori")) cfmask |= 2; + if (cfmask) + sync_clifo(cfmask); + + if (mask.get_bool("SKSyncDoc")) + sync_doc(); _log->log(0, "Procedura terminata!"); - _log->preview(); - delete _log; - _log = NULL; + _log->preview(); + delete _log; + _log = NULL; if (mask.get_bool("SKEmptyOnImp")) clean(); - } + } } int bs0300(int argc, char* argv[]) { - TSknet_sync bss; - bss.run(argc, argv, TR("SKNT Importer")); - return 0; + TSknet_sync bss; + bss.run(argc, argv, TR("SKNT Importer")); + return 0; } \ No newline at end of file