From 8ca1befb4456b74129a935e59451fb9fbc3454e5 Mon Sep 17 00:00:00 2001 From: Mattia Tollari Date: Mon, 18 Mar 2019 16:43:44 +0100 Subject: [PATCH] Patch level : 12.0 736 Files correlati : fp Commento : Corretto monitor fatture passive - Messo una volta sola denominazione in scheda errori fornitori - Aggiunte funzioni clean_cg0 e run_cg0 per gestire files.ini - Sistemato ciclo per chiamata e creazione files.ini --- src/fp/fp0400.cpp | 119 +++++++++++++++++++++++++++------------------- src/fp/fp0400a.h | 2 +- 2 files changed, 70 insertions(+), 51 deletions(-) diff --git a/src/fp/fp0400.cpp b/src/fp/fp0400.cpp index b8f2a4931..aa3ee26b2 100644 --- a/src/fp/fp0400.cpp +++ b/src/fp/fp0400.cpp @@ -12,6 +12,7 @@ #include "sheet.h" #include "execp.h" #include "dongle.h" +#include enum { @@ -28,13 +29,27 @@ enum { filtri = 0, elenco_fe = 1, elenco_err = 2 }; // Enum per bottoni toolbar class TPassive_mask : public TAutomask { protected: + bool _filter_changed; + TFilename tmp_dir; + struct TForn_err + { + int forn_code; + int fatt_err; + }; + + std::map _list_fatt_err; void set_filter_changed(); void select_all(int sheet_field); + // Tasto nuovo: apre nuovo fornitore valorizzando già i dati dalla fattura void new_forn(); // Tasto aggiorna: aggiorna cliente che non corrisponde. void aggiorna_forn(); + void salva_for() const; + void clean_cg0(const TString& filename) const; + void run_cg0(const TString& filename) const; + bool on_field_event(TOperable_field& o, TField_event e, long jolly) override; void next_page(int p) override; // Elenco dei protocolli selezionati @@ -46,24 +61,15 @@ protected: // Aggiunge i protocolli che sono già presenti per le fatture nel db alla tabellina per il filtro void aggiungi_prot() const; void init(); - void load_all_fields(); - TToken_string _forn_code; - TToken_string _list_fatt_err; - bool _filter_changed; - void salva_for() const; - public: void save_all_fields() const; TPassive_mask() : TAutomask("fp0400a"), _filter_changed(true) { + tmp_dir = tmp_dir.tempdir(); load_all_fields(); - _forn_code = ""; - _forn_code.separator('|'); - _list_fatt_err = ""; - _list_fatt_err.separator('|'); } }; @@ -119,8 +125,7 @@ void TPassive_mask::fill() "ORDER BY PZ_ANNOPROT DESC, PZ_TIPOPROT ASC, PZ_NUMPROT DESC"; fp_db().sq_set_exec(query, false); - _forn_code = ""; - _list_fatt_err = ""; + _list_fatt_err.clear(); while(fp_db().sq_next()) { aggiungi_riga(clifo, sf, sf_err); @@ -185,31 +190,27 @@ void TPassive_mask::aggiungi_riga(TLocalisamfile& clifo, TSheet_field& sf, TShee row.add(fp_db().sq_get("TIPO_SDI")); row.add(fp_db().sq_get("NUM_DOC")); // Trasformo formato data da yyyy-mm-gg a italiano - TDate date_t(fp_db().sq_get_date("DATA_DOC")); - row.add(date_t); + row.add(fp_db().sq_get_date("DATA_DOC")); row.add(fp_db().sq_get("TOT_DOC")); - // Dopo aver fatto le ricerche se lo trovo lo segno e lo aggiungo, se no coloro la cella - TString forn_str; forn_str << forn_code; - TString nr_row; nr_row << sf.items(); - if(forn_code < 0) - { - _forn_code.add(forn_str); - _list_fatt_err.add(nr_row); - } - - if (forn_code == 0) row.add("X"); - else row.add(""); + // Decido se mettere o meno il flag + if (forn_code == 0) + row.add("X"); + else + row.add(""); + // Valorizzo le colonne rimanenti o la tabella degli errori if (forn_code >= 0) { row.add(clifo.get(CLI_CODCF)); row.add(clifo.get(CLI_RAGSOC)); } - else + else if (_list_fatt_err.find(denom) == _list_fatt_err.end()) { - //sf.set_back_and_fore_color(COLOR_RED, COLOR_WHITE, 2, sf.cid2index(S_FORNITORE)); - //sf.set_back_and_fore_color(COLOR_RED, COLOR_WHITE, 2, sf.cid2index(S_RAGSOC)); + TForn_err& forn_err = _list_fatt_err[denom]; + forn_err.forn_code = forn_code; + forn_err.fatt_err = sf.items() - 1; + add_row_err_forn(forn_code, sf_err, denom); } @@ -248,7 +249,7 @@ void TPassive_mask::aggiungi_prot() const sf_prot.force_update(); } -void TPassive_mask::add_row_err_forn(int forn_code, TSheet_field& sf_err, TString& denom) +void TPassive_mask::add_row_err_forn(const int forn_code, TSheet_field& sf_err, TString& denom) { TToken_string& row_err = sf_err.row(-1); row_err.add(fp_db().sq_get("COD_PAESE"), 1); @@ -399,15 +400,31 @@ void TPassive_mask::salva_for() const } } +void TPassive_mask::clean_cg0(const TString& filename) const +{ + static TString remove_string; + remove_string.cut(0) << tmp_dir << "\\" << filename << "*.*"; + remove_files(remove_string, false); +} + +void TPassive_mask::run_cg0(const TString& filename) const +{ + static TString run_string; + run_string.cut(0) << "cg0 -1 -i" << tmp_dir << "\\" << filename << "*" << ".ini" << " /u" << user(); + TExternal_app(run_string).run(); +} + void TPassive_mask::new_forn() { TSheet_field& sf = sfield(F_ERR); - TString newf = "fpnewf"; + static const TString newf = "fpnewf"; + clean_cg0(newf); FOR_EACH_SHEET_ROW(sf, nr, row) { - int cod_forn = _forn_code.get_int(nr); // Prendo codice di errore associazione fornitore - - int n_row_elenco = _list_fatt_err.get_int(nr); // Prendo che numero di riga a cui mi riferisco in fatture + const TString denom = row->get(sf.cid2index(S_RAGSERR)); + TForn_err& forn_err = _list_fatt_err[denom]; + const int& cod_forn = forn_err.forn_code; // Prendo codice di errore associazione fornitore + const int& n_row_elenco = forn_err.fatt_err; // Prendo che numero di riga a cui mi riferisco in fatture TSheet_field& f_docs = sfield(F_DOCS); // Prendo SheetField da elenco fatture TToken_string& row_elenco_fatt = f_docs.row(n_row_elenco); // Prendo riga dall'elenco delle fatture TToken_string keys(row_elenco_fatt.get(f_docs.cid2index(S_PROKEY)), ';'); // Dalla riga leggo la chiave del db @@ -424,7 +441,6 @@ void TPassive_mask::new_forn() TString num; num.format("%04d", nr); TFilename newf_ini; - TString temp_path = newf_ini.tempdir(); newf_ini.tempdir() << "\\" << newf << num << ".ini"; TConfig forn_conf(newf_ini, "Transaction"); @@ -444,12 +460,10 @@ void TPassive_mask::new_forn() forn_conf.set("RAGGOR", "O"); forn_conf.set("PADESTIN", row_elenco_fatt.get(sf.cid2index(S_CODSDI))); - TExternal_app app(TString("cg0 -1 -i") << temp_path << "\\" << newf << "*" << ".ini" << " /u" << user()); - app.run(); row->add("", 0); } } - + run_cg0(newf); sf.force_update(); } @@ -457,28 +471,35 @@ void TPassive_mask::aggiorna_forn() { TSheet_field& sf = sfield(F_ERR); static const TString newf = "fpaggf"; + clean_cg0(newf); FOR_EACH_SHEET_ROW(sf, nr, row) { - const int cod_forn = _forn_code.get_int(nr); // Prendo codice di errore associazione fornitore - - const int n_row_elenco = _list_fatt_err.get_int(nr); // Prendos che numero di riga a cui mi riferisco in fatture + const TString denom = row->get(sf.cid2index(S_RAGSERR)); + TForn_err& forn_err = _list_fatt_err[denom]; + const int& cod_forn = forn_err.forn_code; // Prendo codice di errore associazione fornitore + const int& n_row_elenco = forn_err.fatt_err; // Prendo che numero di riga a cui mi riferisco in fatture TSheet_field& f_docs = sfield(F_DOCS); // Prendo SheetField da elenco fatture TToken_string& row_elenco_fatt = f_docs.row(n_row_elenco); // Prendo riga dall'elenco delle fatture if (row->starts_with("X") && cod_forn == no_match_cf) { TLocalisamfile clifo(LF_CLIFO); - bool is_not_gruppo_iva = false; clifo.setkey(5); clifo.put(CLI_TIPOCF, 'F'); - clifo.put(CLI_STATOPAIV, row->get(1)); - clifo.put(CLI_PAIV, row->get(2)); - is_not_gruppo_iva = (clifo.read() == NOERR && clifo.get(CLI_ALLEG) != "G"); - if(is_not_gruppo_iva) + clifo.put(CLI_STATOPAIV, row->get(sf.cid2index(S_STATOERR))); + clifo.put(CLI_PAIV, row->get()); + if(clifo.read() != NOERR) + { + TString msg = "Impossibile trovare il fornitore scelto "; + msg << row->get(sf.cid2index(S_STATOERR)) << " " << row->get(); + warning_box(msg); + continue; + } + + if(clifo.get(CLI_ALLEG) != "G") // Controllo che non sia un gruppo IVA { TString num; num.format("%04d", nr); TFilename newf_ini; - TString temp_path = newf_ini.tempdir(); newf_ini.tempdir() << "\\" << newf << num << ".ini"; TConfig forn_conf(newf_ini, "Transaction"); @@ -487,15 +508,13 @@ void TPassive_mask::aggiorna_forn() forn_conf.set_paragraph("20"); forn_conf.set("TIPOCF", "F"); forn_conf.set("COFI", row->get(sf.cid2index(S_CODFIERR))); - forn_conf.set("CODCF", row_elenco_fatt.get(sf.cid2index(S_FORNITORE))); + forn_conf.set("CODCF", clifo.get(CLI_CODCF)); - TExternal_app app(TString("cg0 -1 -i") << temp_path << "\\" << newf << "*" << ".ini" << " /u" << user()); - message_box(TString("Sto andando a modificare il codice fiscale del fornitore:\n") << row->get(sf.cid2index(S_RAGSERR))); - app.run(); row->add("", 0); } } } + run_cg0(newf); sf.force_update(); } diff --git a/src/fp/fp0400a.h b/src/fp/fp0400a.h index 95c081e50..27b457893 100644 --- a/src/fp/fp0400a.h +++ b/src/fp/fp0400a.h @@ -26,7 +26,7 @@ #define S_PARIVA 111 #define S_CODFISC 112 #define S_ATTACH 113 -#define S_CODSDI 114 +#define S_CODSDI 114 #define S_RAGXML 115 #define S_NPROT 116 #define S_PROKEY 117