From eb5b5f97f143215c74302865b4f4e0897ea681eb Mon Sep 17 00:00:00 2001 From: Francesco_Fucarino Date: Tue, 6 Apr 2021 15:14:50 +0200 Subject: [PATCH] Patch level : 12.0 1048 Files correlati : bs0.EXE bs0200.cpp Commento : Specifica import su fattura --- src/bs/bs0200.cpp | 165 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) diff --git a/src/bs/bs0200.cpp b/src/bs/bs0200.cpp index 029963756..57ae3b93a 100644 --- a/src/bs/bs0200.cpp +++ b/src/bs/bs0200.cpp @@ -191,6 +191,7 @@ protected: void sync_generici (const TDate& dal , const TDate& al) { sync_mov(4, dal, al);} void sync_clifo (int cfmask, const TDate& dal, const TDate& al); void sync_listino (const TString& listino); + void sync_fatbol(const TDate& dal, const TDate& al); public: virtual bool create(); @@ -1408,6 +1409,168 @@ void TBeeStore_sync::sync_corrisp(const TDate&, const TDate&) } } +void TBeeStore_sync::sync_fatbol(const TDate& dal, const TDate& al) +{ + 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); + str << "SELECT tieDMovMag.*,tieTBolFat.* FROM tieDMovMag,tieTBolFat WHERE tieDMovMag.Origine=1 AND tieDMovMag.TipoTestata=2 AND tieDMovMag.CodTestata=tieTBolFat.Cod_PK"; // verificare + if (dal.ok() || al.ok()) + { + str << " AND DataMov"; + if (dal.ok() && al.ok()) + str << " BETWEEN " << date2sql(dal) << " AND " << date2sql(al); + else + { + if (dal.ok()) + str << ">=" << date2sql(dal); + else + str << "<=" << date2sql(al); + } + } + str << "\nORDER BY NumMov,NumRiga"; + + TODBC_recordset docs(str); + docs.connect(_dsn, _usr, _psw); + TProgress_monitor pi(docs.items(), str); + + long num_doc = -1, nd, codcf; + TString test_doc = "", test_nd; + TString4 tipocf; + TDocumento* doc = nullptr; + int contatore = 0; + for (bool ok = docs.move_first(); ok; ok = docs.move_next()) + { + TToken_string test(docs.get("CodTestata").as_string(), '\\'); + + test_nd = (docs.get("CodTestata").as_string()); + + nd = atol(test.get()); + 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") // verificare + tipocf = "F"; + + if (test_nd != test_doc) + // if (nd != num_doc) + { + if (num_doc > 0 && !save_and_delete_doc(doc)) + break; + /* + if (test_doc != "") + if (test_doc != test_nd) + save_and_delete_doc(doc); + */ + num_doc = nd; + test_doc = test_nd; + + TString tre = test_doc.right(3); + const TDate datadoc = docs.get("DataMov").as_date(); + TString8 numdoc = docs.get("TipoDocCE").as_string(); + TString8 tipodoc = docs.get("TipoDocCE").as_string(); + TString origine_dc = docs.get("Origine").as_string(); + TTipo_documento tipo(tipodoc); + const TString8 codcaus = tipo.caus_mov().blank() ? codcausdef : tipo.caus_mov(); + + //doc = new TDocumento('D', datadoc.year(), numdoc, nd); //meglio usare TDocumento(char provv, int anno, const char* codnum, long numdoc); + doc = new TDocumento('D', datadoc.year(), numdoc, strtol(tre, nullptr, 0)); + + doc->put(DOC_DATADOC, datadoc); + 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(); + const real cambio = docs.get("CambioValuta").as_real(); + const TString asp = docs.get("AspettoBeni").as_string(); + 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); + contatore++; + } + const int tipoart = docs.get("TipoArticolo").as_int(); + TString4 tiporiga = tipoart == 2 ? "04" : "02"; + TRectype& rdoc = doc->new_row("01"); + const TString80 codart = docs.get("CodArticolo").as_string(); + + rdoc.put(RDOC_CODART, codart); + if (tipoart == 2) + { + if (cache().get("SPP", codart).not_empty()) + rdoc.put(RDOC_CODARTMAG, codart); + } + else + { + if (cache().get(LF_ANAMAG, codart).not_empty()) + rdoc.put(RDOC_CODARTMAG, codart); + } + + rdoc.put(RDOC_CODARTMAG, codart); + //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_CODMAG, docs.get("CodMagazzino").as_string().left(5)); + rdoc.put(RDOC_CODMAGC, docs.get("CodMagazDest").as_string().left(5)); + rdoc.put(RDOC_UMQTA, docs.get("CodUntMis").as_string()); + 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()); + real valsconto3(docs.get("Sconto3").as_real()); + TString80 sconto; + + if (valsconto1 != ZERO) + sconto << valsconto1.stringa(6, 2); + if (valsconto2 != ZERO) + { + if (sconto.full()) + sconto << "+"; + sconto << valsconto2.stringa(6, 2); + } + if (valsconto3 != ZERO) + { + if (sconto.full()) + sconto << "+"; + sconto << valsconto3.stringa(6, 2); + } + rdoc.put(RDOC_SCONTO, sconto); + rdoc.put(RDOC_CODIVA, docs.get("CodIva").as_string()); + + if (!pi.add_status()) + break; + + + } + save_and_delete_doc(doc); // Salva ultimo documento in sospeso + str.cut(0); + str.format(TR("Documenti importati %ld record in %s"), contatore, "tieTBolFat"); + _log->log(0, ""); + _log->log(0, str); +} bool TBeeStore_sync::create() { @@ -1481,6 +1644,8 @@ void TBeeStore_sync::main_loop() sync_carscar(dal, al); if (mask.get_bool("SyncGenerici")) sync_generici(dal, al); + if (mask.get_bool("SyncFatBol")) + sync_fatbol(dal, al); _log->preview(); delete _log;