diff --git a/src/fp/fplib.h b/src/fp/fplib.h index 762493ad1..c87027fea 100644 --- a/src/fp/fplib.h +++ b/src/fp/fplib.h @@ -9,15 +9,14 @@ #include "../fe/felib.h" #include #include -#include -#include +//#include #include "../cg/cglib.h" #include #define SQL_FLD "sql/" #define MANCATA_SEND "S" // Se la mail di mancata consegna gi stata inviata P1_ERRINT segnato con "S" -// Typedef per aiutare a capire cosa sono le chiavi +// Typedef per aiutare a capire cosa sono le chiavi grande cazzata typedef TString MCodice_riga; typedef TString MTipo_documento; class TDoc_fp; @@ -349,28 +348,6 @@ inline bool operator==(const TFPBuono_di_consegna& l, const TFPBuono_di_consegna * PERSONALIZZAZIONI FP ***********************************************************************************************************************************************************************/ -struct TFP_row_art -{ - TString _codice_tipo; - TString _codice_valore; - TFP_row_art(const TString& codice_tipo, const TString& codice_valore) : _codice_tipo(codice_tipo), _codice_valore(codice_valore) {} -}; - -struct TFP_adg -{ - TString _tipo_dato; - TString _riferimento_testo; - int _riferimento_numero; - TDate _riferimento_data; - - TFP_adg(const TString& tipo_dato, const TString& riferimento_testo, const int riferimento_numero, - const TDate& riferimento_data) - : _tipo_dato(tipo_dato), - _riferimento_testo(riferimento_testo), - _riferimento_numero(riferimento_numero), - _riferimento_data(riferimento_data) {} -}; - /**< * Classe per la gestione di personalizzazioni FP */ @@ -379,8 +356,6 @@ class TFP_custom : public TMultiple_rectype protected: TString _codcust; TString_array _causale; - vector _articoli; - vector _altri_dati_gestionali; bool _loaded; void init(); int write_rewrite(TBaseisamfile& f, bool re = FALSE) const override; @@ -419,7 +394,7 @@ class TFP_custom_cache { std::map _customs; std::map _cli_custom; - std::unique_ptr _global_custom; + TFP_custom * _global_custom; public: bool has_custom(const TDocumento& doc); @@ -494,7 +469,7 @@ private: TString _def_usr_fld; bool _to_commit; bool _cache_insert; - vector _query; + TString_array _query; TString8 _hfatt; // Codice univoco di 6 caratteri dell'ufficio P.A. o di 7 caratteri per un privato TString _bfatt; // Codice univoco di 20 caratteri del documento TString _conai_str; @@ -640,7 +615,7 @@ private: TString _def_usr_fld; bool _to_commit; bool _cache_insert; - vector _query; + TString_array _query; TString8 _hfatt; // Codice univoco di 6 caratteri dell'ufficio P.A. o di 7 caratteri per un privato TString _bfatt; // Codice univoco di 20 caratteri del Regumento TString _paese; diff --git a/src/fp/fplib01.cpp b/src/fp/fplib01.cpp index 8245d9a60..21dd2114d 100644 --- a/src/fp/fplib01.cpp +++ b/src/fp/fplib01.cpp @@ -71,12 +71,14 @@ bool run_fp_psw_mask() } return false; } + string getline(ifstream& f) { string app; getline(f, app); return app; } + bool check_tables() { /* @@ -144,6 +146,7 @@ bool check_tables() } return true; } + TString& complete_num_fp(const TCodice_numerazione& codnum, const int numdoc) { static const int len_num_doc = TRectype(LF_DOC).length(DOC_NDOC); @@ -241,7 +244,6 @@ bool chiave_paf_mov(const TRectype& mov, const char* tipo_doc_sdi, TString& hfat return hfatt.full() && bfatt.full(); } - bool chiave_paf_doc(const TDocumento& doc, TString& hfatt, TString& bfatt) { hfatt.cut(0); @@ -518,6 +520,7 @@ const TString& TPaf_record::var2str(const TString& fldname, const TVariant& var) } return tmp; } + TString& TPaf_record::remove_string(const bool id_riga) { TString& query = get_tmp_string().cut(0); @@ -546,6 +549,7 @@ TString& TPaf_record::remove_string(const bool id_riga) query.cut(0); // Crea una query sbagliata "WHERE AND": "DELETE FROM [table] WHERE AND [prefix]_KEYPRGINVIO != '';" return query; } + // Elimina il record in base ai campi chiave bool TPaf_record::remove() { @@ -755,6 +759,7 @@ TPaf_record::TPaf_record(const char* table) : _table(table), _key(15, ',') } CHECKS(!_key.empty_items(), "Invalid primary key for table ", table); } + //////////////////////////////////////////////////////// // TPaf_container //////////////////////////////////////////////////////// @@ -768,6 +773,7 @@ bool TPaf_container::clean_and_erase_paf(const TString& hfatt, const TString& bf } return ok; } + void TPaf_container::set_keys_paf(TPaf_record& paf, const TString& hfatt, const TString& bfatt, const bool reset) { if (reset) @@ -776,6 +782,7 @@ void TPaf_container::set_keys_paf(TPaf_record& paf, const TString& hfatt, const paf.set(TString(prefix) << "_KEYHEADERFATT", hfatt); paf.set(TString(prefix) << "_KEYBODYFATT", bfatt); } + const char* TPaf_container::paf_to_prefix(const char * paf) { static TString paf_name; @@ -832,10 +839,12 @@ const char* TPaf_container::paf_to_prefix(const char * paf) return "PW"; return "ERROR"; } + TPaf_record& TPaf_container::get_paf(const char * paf) { return _pafs[paf]; } + TPaf_container::TPaf_container() { _pafs.insert(std::pair("PAF0100F", TPaf_record("PAF0100F"))); @@ -886,15 +895,20 @@ TPaf_container::TPaf_container() // Non invio XML _pafs.insert(std::pair("PAFW300F", TPaf_record("PAFW300F"))); } + /*************************************************************************** * TAncestor ***************************************************************************/ -struct TAncestor : public TObject +class TAncestor : public TObject { TString20 _numdoc; TDate _datadoc; +public: + const TString & numdoc() const { return _numdoc; } + const TDate & datadoc() const { return _datadoc; } TAncestor(const TRectype& rdoc); }; + TAncestor::TAncestor(const TRectype& rdoc) { const int anno = rdoc.get_int(RDOC_ANNO); @@ -912,6 +926,7 @@ TAncestor::TAncestor(const TRectype& rdoc) _numdoc.format("%d/%s/%s", anno, static_cast(codnum), static_cast(numdoc)); _datadoc = doc.get_date(DOC_DATADOC); } + /*************************************************************************** * TFPBuono_di_consegna ***************************************************************************/ @@ -960,6 +975,7 @@ bool TDoc_fp::parse_sconto(const TString& formula, TToken_string& sconti) const } return sconti.full(); } + bool TDoc_fp::get_bnp_iban(const TString& abi, const TString& cab, int nprog, TString& iban) { TTable bnp("BNP"); @@ -979,6 +995,7 @@ bool TDoc_fp::get_bnp_iban(const TString& abi, const TString& cab, int nprog, TS iban = bnp.get("S3"); return err == NOERR; } + bool TDoc_fp::get_bank(TDocumento& doc, TString& iban, TString& abi, TString& cab, TString& istituto) const { bool found = false; @@ -992,6 +1009,7 @@ bool TDoc_fp::get_bank(TDocumento& doc, TString& iban, TString& abi, TString& ca } return found; } + bool TDoc_fp::get_bank_presentazione(const TDocumento& doc, TString& iban, TString& abi, TString& cab, TString& istituto) const { bool found = false; @@ -1032,6 +1050,7 @@ bool TDoc_fp::get_bank_presentazione(const TDocumento& doc, TString& iban, TStri istituto = cache().get("%BAN", abi, "S0"); return found; } + bool TDoc_fp::get_bank_appoggio(const TDocumento& doc, TString& iban, TString& abi, TString& cab, TString& istituto) const { @@ -1061,6 +1080,7 @@ bool TDoc_fp::get_bank_appoggio(const TDocumento& doc, TString& iban, TString& a } return found; } + const TString& TDoc_fp::descrizione(const TRiga_documento& rdoc) { if (rdoc.get_bool(RDOC_DESCLUNGA)) @@ -1080,6 +1100,7 @@ const TString& TDoc_fp::descrizione(const TRiga_documento& rdoc) } return rdoc.get(RDOC_DESCR); } + const TRectype* TDoc_fp::find_parent_row(const TRectype& rdoc) const { const long id = rdoc.get_long(RDOC_DAIDRIGA); @@ -1108,6 +1129,7 @@ const TRectype* TDoc_fp::find_parent_row(const TRectype& rdoc) const } return NULL; } + int TDoc_fp::find_ancestors(const TRiga_documento& rdoc, TArray& ancestors) const { if (rdoc.is_articolo()) @@ -1122,14 +1144,13 @@ int TDoc_fp::find_ancestors(const TRiga_documento& rdoc, TArray& ancestors) cons } return ancestors.items(); } + bool TDoc_fp::insert(TPaf_record& p) { - bool ok; + bool ok = true; + if (_cache_insert) - { - _query.push_back(p.insert_string()); - ok = true; - } + _query.add(p.insert_string()); else { ok = p.insert(); @@ -1141,14 +1162,13 @@ bool TDoc_fp::insert(TPaf_record& p) } return ok; } + bool TDoc_fp::remove(TPaf_record& p) { - bool ok; + bool ok = true; + if (_cache_insert) - { - _query.push_back(p.remove_string()); - ok = true; - } + _query.add(p.remove_string()); else { ok = p.remove(); @@ -1160,23 +1180,26 @@ bool TDoc_fp::remove(TPaf_record& p) } return ok; } + bool TDoc_fp::save_paf() { bool ok = true; if (_cache_insert) { - string query; - for (auto i = _query.begin(); i != _query.end(); ++i) - query += *i; + TString query; + + FOR_EACH_ARRAY_ROW(_query, r, row) + query << *row; ok = fp_db().sq_set_exec(query); if (!ok) { _log.log(2, fp_db().sq_get_token_text_error(1)); - _log.log(2, query.c_str()); + _log.log(2, query); } } return ok; } + bool TDoc_fp::check_initial(TDocumentoEsteso& doc) { bool ok = true; @@ -1218,6 +1241,7 @@ bool TDoc_fp::check_initial(TDocumentoEsteso& doc) } return ok; } + bool TDoc_fp::check_row(const TRiga_documento& rdoc) { bool ok = false; @@ -1240,6 +1264,7 @@ bool TDoc_fp::check_row(const TRiga_documento& rdoc) } return ok; } + bool TDoc_fp::check_riepilogo(const TDocumentoEsteso& doc, const TRiepilogo_iva& riva) { bool ok = true; @@ -1252,6 +1277,7 @@ bool TDoc_fp::check_riepilogo(const TDocumentoEsteso& doc, const TRiepilogo_iva& } return ok; } + bool TDoc_fp::initialize(TDocumentoEsteso& doc) { // Azzero @@ -1304,6 +1330,7 @@ bool TDoc_fp::initialize(TDocumentoEsteso& doc) } return false; } + const TRectype& TDoc_fp::cco(const TRectype& doc) const { TString80 conkey; @@ -1330,7 +1357,8 @@ const TRectype& TDoc_fp::cco(const TRectype& doc) const return tabmod.curr(); } -const char* TDoc_fp::stato_paf() { +const char* TDoc_fp::stato_paf() +{ if (get_no_export_pronto()) { _diagn = true; @@ -1377,49 +1405,10 @@ int TDoc_fp::commit() { r = -1; _log.log(2, fp_db().sq_get_token_text_error(1)); - //_log.log(2, "UPDATE PAF0100F SET P1_GESTIONE = 'P' WHERE P1_GESTIONE = 'D'"); } } _to_commit = false; return r; - - /* - int r = 0; - if (_to_commit) - { - // Controllo stato diagnosticato - - if (!get_no_export_pronto()) - { - if (fp_db().sq_set_exec("UPDATE PAF0100F SET P1_GESTIONE = 'P' WHERE P1_GESTIONE = 'D'AND ")) - { - r += 1; - _log.log(2, "Le fatture sono state esportate correttamente in stato pronto"); - } - else - { - r = -1; - _log.log(2, fp_db().sq_get_token_text_error(1)); - } - } - else - { - _log.log(2, "Le fatture sono state esportate in stato diagnosticato"); - } - if (r >= 0 && fp_db().sq_commit()) - { - r += 2; - } - else - { - r = -1; - _log.log(2, fp_db().sq_get_token_text_error(1)); - _log.log(2, "UPDATE PAF0100F SET P1_GESTIONE = 'P' WHERE P1_GESTIONE = 'D'"); - } - } - _to_commit = false; - return r; - */ } int TDoc_fp::force_commit() @@ -1438,6 +1427,7 @@ const TString & TDoc_fp::natura(const char* codiva) const natura = natura.sleft(2); return natura; } + const char* TDoc_fp::get_esigibilita_iva(const TDocumentoEsteso& doc) { // Esigibilit IVA: Immediata, Differita, Split payment @@ -1448,6 +1438,7 @@ const char* TDoc_fp::get_esigibilita_iva(const TDocumentoEsteso& doc) eiva = "D"; return eiva; } + void TDoc_fp::set_IVA(TString codiva, TPaf_record& paf) const { if (codiva.empty()) @@ -1456,10 +1447,12 @@ void TDoc_fp::set_IVA(TString codiva, TPaf_record& paf) const paf.set("PI_ALIQUOTAIVA", static_cast(cache().get("%IVA", codiva, "R0"))); paf.set("PI_NATURA", natura(codiva)); } + void TDoc_fp::set_IVA(const TRiga_documento& rdoc, TPaf_record& paf) const { set_IVA(rdoc.get(RDOC_CODIVA), paf); } + bool TDoc_fp::add_row_art(long& riga_art, const TString& codice_tipo, const TString& codice_valore, TPaf_record& paf) { paf.set("PY_KEYNLINAR", ++riga_art); @@ -1467,6 +1460,7 @@ bool TDoc_fp::add_row_art(long& riga_art, const TString& codice_tipo, const TStr paf.set("PY_VALOREARTICOLO", codice_valore); return insert(paf); } + bool TDoc_fp::add_row_alleg(TFilename& file, long& nprogr, TPaf_record& paf) { static TString dest_path; @@ -1489,6 +1483,7 @@ bool TDoc_fp::add_row_alleg(TFilename& file, long& nprogr, TPaf_record& paf) return ok; } + const TString& TDoc_fp::converti_prezzo(const real& prezzo) const { TString& ret = get_tmp_string(); @@ -1505,6 +1500,7 @@ const TString& TDoc_fp::converti_prezzo(const real& prezzo) const ret << prezzo; return ret; } + void TDoc_fp::set_qta_prezzo(TPaf_record& paf1800f, TFPRiga_documento* rdoc) const { // Setto l'unit di misura @@ -1549,6 +1545,7 @@ const real calc_ritenuta(const TDocumento& doc) } return imponibile; } + void TDoc_fp::add_ritenuta(const TRiga_documento & rdoc, TPaf_record& paf0700f) const { // @@ -1571,6 +1568,7 @@ void TDoc_fp::add_ritenuta(const TRiga_documento & rdoc, TPaf_record& paf0700f) paf0700f.set("P7_CAUSPAGAM", caus_la); // } + bool TDoc_fp::add_riepilogo_iva(TPaf_record& paf2200f, const TCodiceIVA& cod_iva, const char* eiva, const real& imponibile, const real& imposta) { reset(paf2200f); @@ -1710,10 +1708,12 @@ bool TDoc_fp::export_info_articolo(TFPRiga_documento* rdoc, TPaf_record& paf1900 } return ok; } + const TFirm& TDoc_fp::get_firm() { return prefix().firm(); } + bool TDoc_fp::export_paf0100f() { // @@ -1733,6 +1733,7 @@ bool TDoc_fp::export_paf0100f() // return insert(paf0100f); } + bool TDoc_fp::export_paf3200f() { if (_enapec) @@ -2240,15 +2241,15 @@ bool TDoc_fp::doc_to_paf(TDocumentoEsteso& doc) _has_bolla |= true; const TAncestor& a = dynamic_cast(ancestors[i]); - ancestors_s.insert({ a._numdoc, a._datadoc }); // Per i buoni di consegna lavanderie + ancestors_s.insert({ a.numdoc(), a.datadoc() }); // Per i buoni di consegna lavanderie if (i == 1) { // reset(paf1600f); ddt_linee.set(r); paf1600f.set("PF_RIFNUMLINEA", static_cast(r)); - paf1600f.set("PF_NUMDDDT", a._numdoc); - paf1600f.set("PF_DATADDT", a._datadoc); + paf1600f.set("PF_NUMDDDT", a.numdoc()); + paf1600f.set("PF_DATADDT", a.datadoc()); paf1600f.set("PF_GESTIONE", stato_paf()); ok &= insert(paf1600f); // @@ -2259,8 +2260,8 @@ bool TDoc_fp::doc_to_paf(TDocumentoEsteso& doc) paf1000f.set("P0_KEYHEADERFATT", _hfatt); paf1000f.set("P0_KEYBODYFATT", _bfatt); paf1000f.set("P0_RIFNUMLINEA", static_cast(r)); - paf1000f.set("P0_IDDOC", a._numdoc); - paf1000f.set("P0_DATADOC", a._datadoc); + paf1000f.set("P0_IDDOC", a.numdoc()); + paf1000f.set("P0_DATADOC", a.datadoc()); paf1000f.set("P0_COMMESSACONV", com); paf1000f.set("P0_CODCUP", cup); paf1000f.set("P0_CODCIG", cig); @@ -2940,13 +2941,10 @@ TDoc_fp::~TDoc_fp() bool TReg_fp::insert(TPaf_record& p) { - bool ok; + bool ok = true; if (_cache_insert) - { - _query.push_back(p.insert_string()); - ok = true; - } + _query.add(p.insert_string()); else { ok = p.insert(); @@ -2961,13 +2959,10 @@ bool TReg_fp::insert(TPaf_record& p) bool TReg_fp::remove(TPaf_record& p) { - bool ok; + bool ok = true; if (_cache_insert) - { - _query.push_back(p.remove_string()); - ok = true; - } + _query.add(p.remove_string()); else { ok = p.remove(); @@ -2986,14 +2981,15 @@ bool TReg_fp::save_paf() if (_cache_insert) { - string query; - for (auto i = _query.begin(); i != _query.end(); ++i) - query += *i; + TString query; + + FOR_EACH_ARRAY_ROW(_query, r, row) + query << *row; ok = fp_db().sq_set_exec(query); if (!ok) { _log.log(2, fp_db().sq_get_token_text_error(1)); - _log.log(2, query.c_str()); + _log.log(2, query); } } return ok; diff --git a/src/fp/fplib05.cpp b/src/fp/fplib05.cpp index 5a73e01ad..403acd5f2 100644 --- a/src/fp/fplib05.cpp +++ b/src/fp/fplib05.cpp @@ -237,7 +237,7 @@ TFP_custom& TFP_custom_cache::get_custom(const TDocumento& doc) return _customs[codcust]; } -TFP_custom_cache::TFP_custom_cache() +TFP_custom_cache::TFP_custom_cache() : _global_custom(nullptr) { _customs.clear(); _cli_custom.clear(); @@ -247,9 +247,9 @@ TFP_custom_cache::TFP_custom_cache() for(int ok = local_cust.first(); ok == NOERR; ok = local_cust.next()) { - if(local_cust.get_bool(FPCUST_GLOBAL)) + if (local_cust.get_bool(FPCUST_GLOBAL)) { - _global_custom.reset(new TFP_custom(local_cust.curr())); + _global_custom = new TFP_custom(local_cust.curr()); break; } }