diff --git a/src/fp/fp0100.cpp b/src/fp/fp0100.cpp index f87b3e031..5aa4b88e7 100644 --- a/src/fp/fp0100.cpp +++ b/src/fp/fp0100.cpp @@ -20,6 +20,7 @@ protected: void tipi_import() const; static TMask& get_tmp_msk(const char* title); virtual bool on_key(KEY key); + void delete_row_npf(TOperable_field& o) const; virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); public: @@ -47,6 +48,7 @@ void TParametri_mask::save_all() const fp_settings().set_check_not_block(get_bool(F_CHECK_NOT_BLOCK)); fp_settings().set_no_sconti_fatt(get_bool(F_CHECK_NO_SCONTI)); TFP_righe_custom().save_sheet(sfield(F_FORMPERS)); + TFP_nota_piede_f().save_sheet(sfield(F_NPFSHEET)); } void TParametri_mask::load_all() @@ -64,6 +66,7 @@ void TParametri_mask::load_all() set(F_CHECK_NOT_BLOCK, fp_settings().get_check_not_block()); set(F_CHECK_NO_SCONTI, fp_settings().get_no_sconti_fatt()); TFP_righe_custom().load_sheet(sfield(F_FORMPERS)); + TFP_nota_piede_f().load_sheet(sfield(F_NPFSHEET)); } void TParametri_mask::tipi_import() const @@ -134,6 +137,18 @@ bool TParametri_mask::on_key(KEY key) return true; } +void TParametri_mask::delete_row_npf(TOperable_field& o) const +{ + TSheet_field& sf = sfield(F_NPFSHEET); + + TMask& msk = o.mask(); + const TString& tipodoc_msk = msk.get(S_DOC); + + for(int i=0; i < sf.items(); i++) + if (tipodoc_msk == sf.row(i).get(0)) + sf.destroy(i); +} + bool TParametri_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) @@ -216,6 +231,13 @@ bool TParametri_mask::on_field_event(TOperable_field& o, TField_event e, long jo set(F_ESPORTADOC, ""); } } + case DLG_DELREC: + { + if (e == fe_button) + { + delete_row_npf(o); + } + } break; default: break; diff --git a/src/fp/fp0100a.h b/src/fp/fp0100a.h index 2bad49126..f85275565 100644 --- a/src/fp/fp0100a.h +++ b/src/fp/fp0100a.h @@ -24,4 +24,9 @@ #define S_QTA 103 #define S_PREZZO 104 #define S_IMPONIBILE 105 -#define S_NOTAPF 106 \ No newline at end of file + + +#define F_NPFSHEET 501 + +#define S_DOC 101 +#define S_NOTAPF 102 \ No newline at end of file diff --git a/src/fp/fp0100a.uml b/src/fp/fp0100a.uml index 41bfc3664..ebcbd7356 100644 --- a/src/fp/fp0100a.uml +++ b/src/fp/fp0100a.uml @@ -99,10 +99,8 @@ BEGIN ITEM "Qta" ITEM "Prezzo" ITEM "Imponibile" - ITEM "Nota piede\nFattura@15" END - GROUPBOX DLG_NULL 78 3 BEGIN PROMPT 1 8 "@BControlli preventivi" @@ -123,6 +121,12 @@ BEGIN PROMPT 2 12 "Non esporre sconti in fattura" END +SPREADSHEET F_NPFSHEET 60 6 +BEGIN + PROMPT 1 14 "Inserimento\nNote piede fattura" + ITEM "Tipo\nDoc@4" + ITEM "Nota piede\nFattura@15" +END ENDPAGE @@ -208,6 +212,42 @@ BEGIN OUTPUT S_IMPONIBILE CODTAB END +ENDPAGE + +TOOLBAR "Riga" 0 0 0 2 + +BUTTON DLG_OK 2 2 +BEGIN + PROMPT 1 1 "" +END + + +BUTTON DLG_CANCEL 2 2 +BEGIN + PROMPT 1 1 "" +END + +ENDPAGE + +ENDMASK + + +PAGE "Elementi NPF" -1 -1 60 12 + +STRING S_DOC 4 +BEGIN + PROMPT 1 1 "Tipo doc " + HELP "Lasciare libero per tutti i tipo documento" + USE %TIP + SELECT S3[37,40]!="" + INPUT CODTAB S_TIPODOC + DISPLAY "Codice@10" CODTAB + DISPLAY "Descrizione@50" S0 + DISPLAY "Tipo SDI@10" S3[37,40] + OUTPUT S_TIPODOC CODTAB + FLAG "UPA" +END + MEMO S_NOTAPF 0 0 BEGIN PROMPT 1 6 "Nota piede fattura" @@ -228,6 +268,11 @@ BEGIN PROMPT 1 1 "" END +BUTTON DLG_DELREC 2 2 +BEGIN + PROMPT 1 1 "ELIMINA NOTA" +END + ENDPAGE ENDMASK \ No newline at end of file diff --git a/src/fp/fplib.h b/src/fp/fplib.h index af9a23ea8..aa7ee9950 100644 --- a/src/fp/fplib.h +++ b/src/fp/fplib.h @@ -43,19 +43,37 @@ class TFP_righe_custom : public TObject public: - static void write_ini_npf(TToken_string* r); - static TString get_ini_npf(TString codnum, TString tipodoc); static void save_sheet(TSheet_field& sheet_field); static void load_sheet(TSheet_field& sheet_field); const TString& get_qta(const TString& codriga, const TString& tipodoc) { return get(codriga, tipodoc)._col_qta; } const TString& get_prezzo(const TString& codriga, const TString& tipodoc) { return get(codriga, tipodoc)._col_prezzo; } const TString& get_imponibile(const TString& codriga, const TString& tipodoc) { return get(codriga, tipodoc)._col_imponibile; } - const TString& get_nota_piede(const TString& codriga, const TString& tipodoc) { return get(codriga, tipodoc)._col_nota_piede; } TFP_righe_custom(); }; +class TFP_nota_piede_f +{ + std::map _nota_piede_fattura; + bool _loaded; + TToken_string _tipi_doc; // Array di stringhe dei tipi doc caricati (per capire se ne elimino) + const TString _null_string; + static void write_ini_npf(const TString& tipodoc, TToken_string& msg); // Salva sul file ini la n.p.f. di quel tipodoc + static void delete_ini_npf(const TString& tipodoc); // Rimuove i tipidoc in eccesso (quando si modifica lo spreadsheet) + static TString get_ini_npf(const TString& tipodoc); // Legge dal file ini e restituisce la n.p.f. di quel tipodoc + void get_load(); // Carica la mappa + void save_npf_spredsheet(TSheet_field& sheet_field); + void save_new_tipidoc(TSheet_field& sheet_field); + +public: + void load_sheet(TSheet_field& sheet_field); + void save_sheet(TSheet_field& sheet_field); + const TString& get_nota_piede(const TString& tipo_doc); + + TFP_nota_piede_f(); +}; + enum { no_pdf = -1, pdf_ok = 0, no_alleg = -2}; // Ritorna la connessione al DB paf secondo i parametri impostati nel programma di configurazione @@ -179,6 +197,7 @@ private: int _count_r_conai; bool _nascondi_sconti_righe_fatt; TFP_righe_custom _righe_custom; + TFP_nota_piede_f _riga_npf; // Classe interna per gestire righe aggiuntive in riepilogo class TRiepilogo_agg @@ -288,8 +307,10 @@ public: const bool is_f8() const; const bool get_check_not_block() const; const TString& get_body_mail(int idx = -1) const; - const TString& get_npf(const char* codnum, const char* tipodoc, int idx) const; + const TString& get_npf(const char* tipodoc, int idx) const; const bool get_no_sconti_fatt() const; + // Get tipidoc per NotaPiedeFattura + const TString get_npf_tipodoc(int indx) const; // Setters void set_db_indirizzo(const TString& ind) const; @@ -307,12 +328,13 @@ public: void set_f8(bool f8) const; void set_check_not_block(bool not_block) const; void set_body_mail(const char* msg, int idx = -1) const; - void set_npf(const char * codnum, const char * tipodoc, const char* msg, int idx) const; void set_no_sconti_fatt(const bool no_sconti_fatt) const; + void set_npf(const char * tipodoc, const char* msg, int idx) const; + void set_npf_tipodoc(const TString& tipodoc, int indx) const; void remove_para_ini(int idx); - void remove_npf_ini(const char* codnum, const char* tipodoc, int idx); - void remove_line_npf(const char* codnum, const char* tipodoc, int idx) const; + void remove_npf_ini(const char* tipodoc, int idx); + void remove_tipodoc_npf(int idx) const; }; inline TFP_settings& fp_settings() diff --git a/src/fp/fplib01.cpp b/src/fp/fplib01.cpp index ace5c9015..b558f1787 100644 --- a/src/fp/fplib01.cpp +++ b/src/fp/fplib01.cpp @@ -46,6 +46,7 @@ void set_connection(SSimple_query& s) } #endif } + SSimple_query& fp_db() { static SSimple_query* db = nullptr; @@ -2012,7 +2013,7 @@ bool TDoc_fp::doc_to_paf(TDocumentoEsteso& doc) } } - const TString& nota_piede_fatt = _righe_custom.get_nota_piede(rdoc->tipo().codice(), rdoc->doc().tipo().codice()); + const TString& nota_piede_fatt = _riga_npf.get_nota_piede(doc.tipo().codice()); if(nota_piede_fatt.full()) { reset(paf1800f); diff --git a/src/fp/fplib02.cpp b/src/fp/fplib02.cpp index 575570f64..2bea45d76 100644 --- a/src/fp/fplib02.cpp +++ b/src/fp/fplib02.cpp @@ -126,12 +126,18 @@ const TString& TFP_settings::get_body_mail(int idx) const return ini_get_string(FILE_CONFIG, FILE_SECTION, FP_MAIL, "STOpsTOP", idx); } -const TString& TFP_settings::get_npf(const char * codnum, const char * tipodoc, int idx) const +const TString& TFP_settings::get_npf(const char * tipodoc, int idx) const { - TString name; name << FP_NOTA_PIEDE_F << "_" << codnum << "-" << tipodoc; + TString name; name << FP_NOTA_PIEDE_F << "-" << tipodoc; return ini_get_string(FILE_CONFIG, FILE_SECTION, name, "FERMATIostrega", idx); } +const TString TFP_settings::get_npf_tipodoc(int indx) const +{ + TString name; name << FP_NOTA_PIEDE_F << "_tipodoc"; + return ini_get_string(FILE_CONFIG, FILE_SECTION, name, "FERMATIostrega", indx); +} + const bool TFP_settings::get_no_sconti_fatt() const { return ini_get_bool(FILE_CONFIG, FILE_SECTION, FP_CHECK_NO_SCONTI_FATT, false); @@ -213,9 +219,9 @@ void TFP_settings::set_body_mail(const char* msg, int idx) const } // Set nota piede fattura -void TFP_settings::set_npf(const char * codnum, const char * tipodoc, const char* msg, int idx) const +void TFP_settings::set_npf(const char * tipodoc, const char* msg, int idx) const { - TString name; name << FP_NOTA_PIEDE_F << "_" << codnum << "-" << tipodoc; + TString name; name << FP_NOTA_PIEDE_F << "-" << tipodoc; ini_set_string(FILE_CONFIG, FILE_SECTION, name, msg, idx); } @@ -229,16 +235,22 @@ void TFP_settings::remove_para_ini(int idx) ini_remove(FILE_CONFIG, FILE_SECTION, FP_MAIL, idx); } -void TFP_settings::remove_npf_ini(const char * codnum, const char * tipodoc, int idx) +void TFP_settings::remove_npf_ini(const char * tipodoc, int idx) { - TString name; name << FP_NOTA_PIEDE_F << "_" << codnum << "-" << tipodoc; + TString name; name << FP_NOTA_PIEDE_F << "-" << tipodoc; ini_remove(FILE_CONFIG, FILE_SECTION, name, idx); } -// Rimuove linea ini in eccesso per nota piede fattura -void TFP_settings::remove_line_npf(const char * codnum, const char * tipodoc, int idx) const +void TFP_settings::set_npf_tipodoc(const TString& tipodoc, int indx) const { - TString name; name << FP_NOTA_PIEDE_F << "_" << codnum << "-" << tipodoc; + 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 TFP_settings::remove_tipodoc_npf(const int idx) const +{ + TString name; name << FP_NOTA_PIEDE_F << "_tipodoc"; ini_remove(FILE_CONFIG, FILE_SECTION, name, idx); } @@ -334,36 +346,46 @@ TFP_righe_custom::TCustCol& TFP_righe_custom::get(const TString& codriga, const return get_no_custom(); } -void TFP_righe_custom::write_ini_npf(TToken_string* r) +void TFP_nota_piede_f::write_ini_npf(const TString& tipodoc, TToken_string& msg) { - // Prendo memo di ogni riga e la suddivido per gli a capo - TToken_string msg(r->get(5), '\n'); - /* Vado a salvare in un config .ini tipo-riga/tipo-doc/messaggio su piu righe */ + /* Vado a salvare in un config .ini tipo-doc:messaggio su piu righe */ int indx = 0; - TString codnum, tipodoc; codnum << r->get(1); tipodoc << r->get(0); // Conto quanti ne avevo salvati prima nel file ini per poi controllare // che non sto salvando meno di quelli che ci sono già int previous_indx = 0; - for (TString row = fp_settings().get_npf(codnum, tipodoc, previous_indx); row != "FERMATIostrega"; row = fp_settings().get_npf(codnum, tipodoc, previous_indx)) + for (TString row = fp_settings().get_npf(tipodoc, previous_indx); row != "FERMATIostrega"; row = fp_settings().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()) - fp_settings().set_npf(codnum, tipodoc, row, indx++); + fp_settings().set_npf(tipodoc, row, indx++); if (indx < previous_indx) { for (int i = indx; i < previous_indx; i++) - fp_settings().remove_npf_ini(codnum, tipodoc, indx); + fp_settings().remove_npf_ini(tipodoc, i); } } -TString TFP_righe_custom::get_ini_npf(TString codnum, TString tipodoc) +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à + int previous_indx = 0; + for (TString row = fp_settings().get_npf(tipodoc, previous_indx); row != "FERMATIostrega"; row = fp_settings().get_npf(tipodoc, previous_indx)) + previous_indx++; + for (int i = 0; i < previous_indx; i++) + fp_settings().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 = fp_settings().get_npf(codnum, tipodoc, indx); row != "FERMATIostrega"; row = fp_settings().get_npf(codnum, tipodoc, indx)) + for (TString row = fp_settings().get_npf(tipodoc, indx); row != "FERMATIostrega"; row = fp_settings().get_npf(tipodoc, indx)) { if(indx++ > 0) msg << '\n'; @@ -372,6 +394,113 @@ TString TFP_righe_custom::get_ini_npf(TString codnum, TString tipodoc) 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 = fp_settings().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 = fp_settings().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 (è 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 = fp_settings().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)); + fp_settings().set_npf_tipodoc(tipodoc_sf, i); + } + + if (items_sf < n_tipidoc) + for (int i = items_sf; i < n_tipidoc; i++) + fp_settings().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); @@ -386,7 +515,6 @@ void TFP_righe_custom::load_map() 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; - app._col_nota_piede = rec.get(FP_NOTA_PIEDE_F); } _loaded = true; @@ -428,8 +556,6 @@ void TFP_righe_custom::save_sheet(TSheet_field& sheet_field) rec.put(FP_SHT_COL_IMPONIBILE, r->get()); rec.write(tabmod); - - write_ini_npf(r); } } @@ -449,7 +575,6 @@ void TFP_righe_custom::load_sheet(TSheet_field& sheet_field) 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)); - row.add(get_ini_npf(cur_rec.get(FP_SHT_TIPORIGA), cur_rec.get(FP_SHT_TIPODOC))); } sheet_field.force_update(); }