diff --git a/src/cg/cg2100.cpp b/src/cg/cg2100.cpp index d135f81aa..0fcaf0980 100755 --- a/src/cg/cg2100.cpp +++ b/src/cg/cg2100.cpp @@ -23,6 +23,14 @@ #include "tsdb.h" #include "../fp/fplib.h" +enum +{ + pro_err = -86552, + pro_noerr = 1, + pro_notsaved = 0, + pro_nofp = -1 +}; + /////////////////////////////////////////////////////////// // Dati incasso immediato /////////////////////////////////////////////////////////// @@ -117,6 +125,13 @@ TMask* TPrimanota_application::load_mask(int n) ism.set_handler(CG_RISCONTO, sheet_risconto_handler); if (!(fexist("fp0.exe") && !fp_settings().get_db_indirizzo().empty() && !fp_settings().is_f8())) m->hide(F_PROTFPPRO); + else + { + m->add_button_tool(DLG_LINK, "Fatture SDI", TOOL_ELABORA); + m->set_handler(DLG_LINK, fppro_mask); + } + + if (_quadratura) m->set_handler(F_ADJUST_IVA, quadratura_handler); } @@ -1034,6 +1049,8 @@ void TPrimanota_application::init_modify_mode(TMask& m) m.enable(F_BOLLACODCLI, causale().tipo_doc() == "BD"); m.enable(F_BOLLARAGCLI, causale().tipo_doc() == "BD"); } + if(!m.field(F_PROTFPPRO).hidden()) + m.set(F_PROTFPPRO, mov.get(MOV_PROGFPPRO)); } // Controlla sulla causale se il segno del totale documento (ritsoc=false) @@ -1547,12 +1564,34 @@ int TPrimanota_application::rewrite(const TMask& m) return err; } +void TPrimanota_application::clean_fppro() const +{ + TMask& msk = curr_mask(); + const KEY last = msk.last_key(); + + if (_mode != MODE_MOD) + return; + if (!fexist("fp0.exe") || fp_settings().get_db_indirizzo().empty() || fp_settings().is_f8()) + return; // Salto il salvataggio in FPPRO + if (last != 127 && last != K_SAVE) // Salto se non sto eliminando + return; + + TString query; + const TString& numreg = msk.get(F_NUMREG); + query << "UPDATE FPPRO00F\n" << + "SET PZ_NUMREGCONT = 0, PZ_DATAREGCONT = '2001-01-01'\n" << + "WHERE PZ_NUMREGCONT = '" << numreg << "'"; + fp_db().sq_set_exec(query); + fp_db().sq_commit(); +} + bool TPrimanota_application::remove() { const bool ok = TRelation_application::remove(); if (ok) { + clean_fppro(); _saldi.registra(); check_saldi(); @@ -2167,13 +2206,15 @@ bool TPrimanota_application::save(bool check_dirty) _swap_mask = false; return true; } - const bool saved_fppro = save_fppro(); + const int fp_code = save_fppro(); const bool saved = TRelation_application::save(check_dirty); - if (saved && saved_fppro) + + if (saved && fp_code > 0 && !save_dbmov()) { - if (!save_dbmov()) - message_box("Attenzione non è stato possibile salvare i riferimenti del documento (in ingresso) nel movimento"); + message_box(TString("ATTENZIONE:") << " non è stato possibile salvare i riferimenti del documento in ingresso per questo movimento.\n" << + "Movimento registrato senza collegamento ai documenti in ingresso."); } + return saved; } @@ -2287,27 +2328,52 @@ void TPrimanota_application::mask2ini(const TMask& msk, TConfig& ini) } } -bool TPrimanota_application::save_fppro() const +int TPrimanota_application::save_fppro() const { TMask& msk = curr_mask(); const KEY last = msk.last_key(); + // Provo a vedere se hanno l'FP: se c'è l'indirizzo controllo che non sia F8 se non c'è non hanno l'FP + if (!fexist("fp0.exe") || fp_settings().get_db_indirizzo().empty() || fp_settings().is_f8()) + return pro_nofp; // Salto il salvataggio in FPPRO + if (!fp_db().sq_is_connect()) + { + message_box("Attenzione connesione al database non riuscita.\nImpossibile collegarsi ai documenti in entrata."); + return pro_nofp; + } + + if (_mode != MODE_INS) + { + if(_mode == MODE_MOD && last == K_SAVE) + { + TString query; + query << "SELECT COUNT(*) AS COUNT FROM FPPRO00F WHERE PZ_NUMREGCONT = '" << msk.get(F_NUMREG) << "'"; + fp_db().sq_set_exec(query); + if (fp_db().sq_get_int("COUNT") != 0) + { + message_box(TString("Attenzione!") << " E' stato modificato un movimento già collegato a un documento in ingresso."); + clean_fppro(); + msk.set(F_PROKEY, ""); + msk.set(F_PROTFPPRO, ""); + save_dbmov(); + } + } + else return pro_notsaved; + } + // Controllo che sto registrando un documento FA Fattura di Acquisto TLocalisamfile clifo(LF_CAUSALI); clifo.setkey(1); clifo.put("CODCAUS", msk.get(F_CODCAUS)); if (clifo.read() != NOERR) - return false; + return pro_notsaved; if (clifo.get("TIPODOC") != "FA") - return false; - // Provo a vedere se hanno l'FP: se c'è l'indirizzo controllo che non sia F8 se non c'è non hanno l'FP - if (!fexist("fp0.exe") || fp_settings().get_db_indirizzo().empty() || fp_settings().is_f8()) - return false; // Salto il salvataggio in FPPRO + return pro_notsaved; if (last != K_SAVE) { // Salto se sto uscendo message_box("La registrazione del movimento non verrà salvata sul database."); - return false; + return pro_notsaved; } const TDate data_operazione(msk.get(F_DATAREG)); @@ -2341,7 +2407,7 @@ bool TPrimanota_application::save_fppro() const else { error_box("Attenzione non è stata inserita ne la partita iva ne il cod.fisc del fornitore:\nimpossibile associarlo in FPPRO"); - return false; + return pro_notsaved; } TString query; @@ -2354,14 +2420,14 @@ bool TPrimanota_application::save_fppro() const const int n = fp_db().sq_items(); if (n != 1) { - message_box("Attenzione non è stato possibile indentificare\nil documento con una specifica fattura in FPPRO"); - return false; + message_box("Attenzione non è stato possibile indentificare\nil documento con una specifica fattura in ingresso"); + return pro_notsaved; } const int numreg = fp_db().sq_get_int("PZ_NUMREGCONT"); if (numreg != 0) { - error_box(TString("Il documento ") << data_documento.year() << " / " << numero_doc << " è già stato inserito con la registrazione numero " << numreg << "\nSalvataggio in FPPRO impossibile."); - return false; + error_box(TString("Il documento ") << data_documento.year() << " / " << numero_doc << " è già stato inserito con la registrazione numero " << numreg << "\nSalvataggio su protocollo in ingresso impossibile."); + return pro_notsaved; } // Devo controllare che la data operazione sia maggiore della data ric @@ -2369,7 +2435,7 @@ bool TPrimanota_application::save_fppro() const if(data_operazione < dataoraric) { error_box("Attenzione non è possibile registrare una fattura\ncon data operazione minore della data di ricezione."); - return false; + return pro_notsaved; } const TString keyprginvio = fp_db().sq_get("PZ_KEYPRGINVIO"); @@ -2387,8 +2453,9 @@ bool TPrimanota_application::save_fppro() const const bool saved = fp_db().sq_commit(); if (!saved) error_box("Attenzione non è stato possibile registrare la fattura nel database."); - return saved; + return saved? pro_noerr : pro_notsaved; } + bool TPrimanota_application::save_dbmov() const { const TMask& msk = curr_mask(); diff --git a/src/cg/cg2100.h b/src/cg/cg2100.h index 3813fb270..a421b9f7d 100755 --- a/src/cg/cg2100.h +++ b/src/cg/cg2100.h @@ -208,10 +208,12 @@ #define F_TOTDOCI 609 #define F_PROTFPPROI 610 #define F_FPPROKEYSI 611 +#define F_SHEET_TEXT 612 +#define F_SHOWALL 613 #define F_SELFPPROS 101 -#define F_DATAS 102 -#define F_DATAORARICS 103 +#define F_DATAORARICS 102 +#define F_DATAS 103 #define F_IMPTOTDOCS 104 #define F_NUMEROS 105 #define F_FISCIVAPAESES 106 diff --git a/src/cg/cg2100c.uml b/src/cg/cg2100c.uml index 2f46ab557..e88fbd652 100755 --- a/src/cg/cg2100c.uml +++ b/src/cg/cg2100c.uml @@ -4,7 +4,6 @@ TOOLBAR "topbar" 0 0 0 2 #include - ENDPAGE PAGE "Testata" -1 -1 77 20 diff --git a/src/cg/cg2102.cpp b/src/cg/cg2102.cpp index fa7e5190a..f435b08df 100755 --- a/src/cg/cg2102.cpp +++ b/src/cg/cg2102.cpp @@ -2215,7 +2215,7 @@ bool TPrimanota_application::num_handler(TMask_field& f, KEY key) { // Riempie a mano i campi necessari nel caso non sia stato usata la ricerca F9 m.set(F_DATAREG, mov.get(MOV_DATAREG), true); - m.set(F_CODCAUS, mov.get(MOV_CODCAUS)); + m.set(F_CODCAUS, mov.get(MOV_CODCAUS)); f.set_focusdirty(false); ok = m.stop_run(K_AUTO_ENTER); @@ -3451,12 +3451,14 @@ bool TPrimanota_application::protiva_handler(TMask_field& f, KEY key) return ok; } -void TPrimanota_application::fppro_mask(TMask_field& f, KEY key) +bool TPrimanota_application::fppro_mask(TMask_field& f, KEY key) { TMask& cg_msk = f.mask(); // Provo a vedere se hanno l'FP: se c'è l'indirizzo controllo che non sia F8 se non c'è non hanno l'FP if (!(fexist("fp0.exe") && !fp_settings().get_db_indirizzo().empty() && !fp_settings().is_f8())) - return; + return true; + if (key != 32 && key != 9) + return true; TMask* msk = new TMask("cgFPPRO"); msk->set_handler(DLG_CONFIG, fppro_handler); @@ -3465,14 +3467,22 @@ void TPrimanota_application::fppro_mask(TMask_field& f, KEY key) msk->set(F_COFIS, cg_msk.get(F_COFI)); msk->set(F_STATOPAIVS, cg_msk.get(F_STATOPAIV)); msk->set(F_PIVAS, cg_msk.get(F_PIVA)); - msk->run(); - // Riporto dati FPPRO su maschera Prima Nota - cg_msk.set(F_NUMDOCEXT, msk->get(F_NUMEROI)); - cg_msk.set(F_NUMDOC, TString(msk->get(F_NUMEROI)).left(7)); - cg_msk.set(F_DATADOC, msk->get(F_DATAI)); - cg_msk.set(F_TOTALE, msk->get(F_TOTDOCI)); - cg_msk.set(F_PROTFPPRO, msk->get(F_PROTFPPROI)); - cg_msk.set(F_PROKEY, msk->get(F_FPPROKEYSI)); + + if(load_fppro_mask(msk)) + { + msk->run(); + // Riporto dati FPPRO su maschera Prima Nota + cg_msk.set(F_NUMDOCEXT, msk->get(F_NUMEROI)); + cg_msk.set(F_NUMDOC, TString(msk->get(F_NUMEROI)).left(7)); + cg_msk.set(F_DATADOC, msk->get(F_DATAI)); + cg_msk.set(F_TOTALE, msk->get(F_TOTDOCI)); + cg_msk.set(F_PROTFPPRO, msk->get(F_PROTFPPROI)); + cg_msk.set(F_PROKEY, msk->get(F_FPPROKEYSI)); + cg_msk.set(F_ANNORIF, cg_msk.get(F_ANNOIVA)); + } + + delete msk; + return true; } @@ -3850,29 +3860,29 @@ bool TPrimanota_application::quadratura_handler(TMask_field& f, KEY key) return true; } - -bool TPrimanota_application::fppro_handler(TMask_field& f, KEY k) +bool TPrimanota_application::load_fppro_mask(TMask* msk, KEY k) { if (k != 32) - return true; - TMask& msk = f.mask(); - //if(msk.curr_page() != 3) - //return true; + return false; // Provo a vedere se hanno l'FP: se c'è l'indirizzo controllo che non sia F8 se non c'è non hanno l'FP if (!fexist("fp0.exe") || fp_settings().get_db_indirizzo().empty() || fp_settings().is_f8()) - return true; // Salto il salvataggio in FPPRO + return false; // Salto il salvataggio in FPPRO + if (!fp_db().sq_is_connect()) + { + message_box("Attenzione connessione al database non riuscita.\nImpossibile collegarsi ai documenti in entrata."); + return false; + } - - const int forn = msk.get_int(F_CODCLIFORS); + const int forn = msk->get_int(F_CODCLIFORS); if (forn == 0) { message_box("Inserire prima il fornitore"); - return true; + return false; } - const TString& codfisc = msk.get(F_COFIS); - const TString& stato_piva = msk.get(F_STATOPAIVS); - const TString& piva = msk.get(F_PIVAS); + const TString& codfisc = msk->get(F_COFIS); + const TString& stato_piva = msk->get(F_STATOPAIVS); + const TString& piva = msk->get(F_PIVAS); TString id_fornitore; if (!piva.empty()) { @@ -3896,20 +3906,24 @@ bool TPrimanota_application::fppro_handler(TMask_field& f, KEY k) "FROM PAA0200F\n" << "JOIN FPPRO00F\n" << " ON P2_KEYPRGINVIO = PZ_KEYPRGINVIO AND P2_KEYHEADERFATT = PZ_KEYHEADERFATT AND P2_KEYBODYFATT = PZ_KEYBODYFATT\n" << "JOIN PAA0100F\n" << " ON P2_KEYPRGINVIO = P1_KEYPRGINVIO AND P2_KEYHEADERFATT = P1_KEYHEADERFATT AND P2_KEYBODYFATT = P1_KEYBODYFATT\n" << "JOIN PAA2700F\n" << "ON P2_KEYPRGINVIO = PQ_KEYPRGINVIO AND P2_KEYHEADERFATT = PQ_KEYHEADERFATT AND P2_KEYBODYFATT = PQ_KEYBODYFATT\n" << - "WHERE " << id_fornitore << ";"; + "WHERE " << id_fornitore << "\n" << + "ORDER BY P1_DATAORARIC ASC;"; fp_db().sq_set_exec(query, false); - TSheet_field& sf = msk.sfield(F_SHEETFPPROS); + TSheet_field& sf = msk->sfield(F_SHEETFPPROS); sf.hide(); + if (sf.items() > 0) + sf.destroy(); while (fp_db().sq_next()) { TString numreg = fp_db().sq_get("PZ_NUMREGCONT"); - if (numreg != "0") + const bool show_all = msk->get_bool(F_SHOWALL); + if (numreg != "0" && !show_all) continue; TToken_string& row = sf.row(-1); row.add("", 0); - row.add(TDate(fp_db().sq_get_date("PZ_DATA"))); row.add(TDate(fp_db().sq_get_date("P1_DATAORARIC"))); + row.add(TDate(fp_db().sq_get_date("PZ_DATA"))); row.add(fp_db().sq_get("PQ_IMPTOTDOC")); row.add(fp_db().sq_get("PZ_NUMERO")); row.add(fp_db().sq_get("P2_FISCIVAPAESE")); @@ -3923,6 +3937,13 @@ bool TPrimanota_application::fppro_handler(TMask_field& f, KEY k) return true; } +bool TPrimanota_application::fppro_handler(TMask_field& f, KEY k) +{ + TMask& msk = f.mask(); + const bool load = load_fppro_mask(&msk, k); + return load; +} + bool TPrimanota_application::fppro_ok_handler(TMask_field& f, KEY k) { if (k != 32) @@ -3933,6 +3954,7 @@ bool TPrimanota_application::fppro_ok_handler(TMask_field& f, KEY k) bool ok = false; TSheet_field& sf = msk.sfield(F_SHEETFPPROS); bool loaded = false; + FOR_EACH_SHEET_ROW(sf, nr, row) { if(!loaded && *row->get(0) == 'X') diff --git a/src/cg/cg2102.h b/src/cg/cg2102.h index 3a62420cc..b8a3b9b60 100755 --- a/src/cg/cg2102.h +++ b/src/cg/cg2102.h @@ -171,7 +171,7 @@ class TPrimanota_application : public TRelation_application static bool fppro_handler(TMask_field& f, KEY k); // Carica spread fppro static bool fppro_ok_handler(TMask_field& f, KEY k); // Riporta doc FPPRO in testata - static void fppro_mask(TMask_field& f, KEY key); + static bool fppro_mask(TMask_field& f, KEY key); void reset_sheet_row(TSheet_field& s, int n); int crea_somma_spese(TImporto& imp); @@ -186,8 +186,10 @@ protected: // TApplication void dump_fatt(TConfig& ini, TPartita & game, int rigafatt, int pref = 0); virtual void ini2mask(TConfig& ini, TMask& msk, bool query); virtual void mask2ini(const TMask& msk, TConfig& ini); - bool save_fppro() const; - // Salva riferimento documento in FPPRO in mov + + static bool load_fppro_mask(TMask* msk, KEY k = 32); + int save_fppro() const; + // Salva sul movimento il riferimento al documento in FPPRO bool save_dbmov() const; virtual bool save(bool check_dirty); @@ -210,6 +212,7 @@ protected: // TRelation_application virtual int read(TMask& m); virtual int write(const TMask& m); virtual int rewrite(const TMask& m); + void clean_fppro() const; virtual bool remove(); virtual void write_enable(bool) {} virtual bool protected_record(TRectype& rec); diff --git a/src/cg/cgFPPRO.uml b/src/cg/cgFPPRO.uml index 876a5fecc..9bdbc1e28 100644 --- a/src/cg/cgFPPRO.uml +++ b/src/cg/cgFPPRO.uml @@ -4,13 +4,13 @@ TOOLBAR "topbar" 0 0 0 2 BUTTON DLG_CONFIG 2 2 BEGIN - PROMPT 3 1 "Carica FPPRO" + PROMPT 3 1 "Ricarica Fatture" PICTURE TOOL_ELABORA END BUTTON DLG_LINK 2 2 BEGIN - PROMPT 3 1 "Collega FPPRO" + PROMPT 3 1 "Riporta Dati" PICTURE TOOL_LINK END @@ -23,7 +23,7 @@ END ENDPAGE -PAGE "FPPRO" -1 -1 77 20 +PAGE "Fatture Ricevute SDI" -1 -1 77 20 NUMBER F_CODCLIFORS 6 BEGIN @@ -33,35 +33,45 @@ END STRING F_COFIS 16 BEGIN - PROMPT 40 1 "C.F. " + PROMPT 35 1 "Cod. Fiscale " FLAGS "D" END STRING F_STATOPAIVS 2 BEGIN - PROMPT 1 2 "STATO P.I." + PROMPT 1 2 "P. IVA" FLAGS "D" END STRING F_PIVAS 12 BEGIN - PROMPT 40 2 "P.I. " + PROMPT 15 2 "" FLAGS "D" END -SPREADSHEET F_SHEETFPPROS 0 5 +TEXT F_SHEET_TEXT BEGIN - PROMPT 0 4 "" - ITEM "SEL" - ITEM "DATA" - ITEM "DATAORARIC" - ITEM "IMPTOTDOCP" - ITEM "NUMERO" - ITEM "FISCIVAPAESE" - ITEM "FISCIVACOD" - ITEM "CODFISCALE" - ITEM "TIPOPROT" - ITEM "PROGRESS" + PROMPT 0 4 "@BSelezionare la fattura, quindi premere 'Riporta Dati'" +END + +BOOLEAN F_SHOWALL +BEGIN + PROMPT 0 5 "Mostra anche fatture già registrate" +END + +SPREADSHEET F_SHEETFPPROS 0 15 +BEGIN + PROMPT 0 6 "" + ITEM " " + ITEM "Data Ricezione" + ITEM "Data Doc." + ITEM "Importo Totale" + ITEM "Numero" + ITEM "Paese" + ITEM "P. IVA" + ITEM "Cod. Fiscale" + ITEM "Tipo Protocollo\nin ingresso" + ITEM "Progressivo di ingresso" END STRING F_NUMEROI 20 diff --git a/src/fp/fplib01.cpp b/src/fp/fplib01.cpp index b558f1787..5541fc7f4 100644 --- a/src/fp/fplib01.cpp +++ b/src/fp/fplib01.cpp @@ -21,8 +21,9 @@ #include #include "../cg/cfban.h" #include "modaut.h" -void set_connection(SSimple_query& s) +bool set_connection(SSimple_query& s) { + bool ok = true; #ifdef DBG TString ip = fp_settings().get_db_indirizzo(); if (ip.upper() != "TESTCAMPO2012") @@ -31,20 +32,27 @@ void set_connection(SSimple_query& s) "fp", "fp", TSDB_MSSQL) != NOERR) - fatal_box("Impossibile connettersi al DB esterno"); + { + warning_box("Impossibile connettersi al DB esterno"); + ok = false; + } } else { #endif - if (s.sq_connect( - fp_settings().get_db_str_con(), - fp_settings().get_db_user(), - fp_settings().get_db_password(), - TSDB_MSSQL) != NOERR) - fatal_box("Impossibile connettersi al DB esterno"); + if (s.sq_connect( + fp_settings().get_db_str_con(), + fp_settings().get_db_user(), + fp_settings().get_db_password(), + TSDB_MSSQL) != NOERR) + { + warning_box("Impossibile connettersi al DB esterno"); + ok = false; + } #ifdef DBG } #endif + return ok; } SSimple_query& fp_db() @@ -53,9 +61,9 @@ SSimple_query& fp_db() if (db == nullptr) { db = new SSimple_query(); - set_connection(*db); + const bool ok = set_connection(*db); // Non utilizzo l'autocommit, viene gestito manualmente - db->sq_set_autocommit(false); + if (ok) db->sq_set_autocommit(false); } return *db; }