diff --git a/src/cg/cg2100.cpp b/src/cg/cg2100.cpp index 7230996f1..5ea975c7a 100755 --- a/src/cg/cg2100.cpp +++ b/src/cg/cg2100.cpp @@ -1453,6 +1453,16 @@ void TPrimanota_application::write_fppro() "Movimento registrato senza collegamento ai documenti in ingresso."); } +bool TPrimanota_application::has_tot_doc(TToken_string& fppro_keys) +{ + TString query; + query << "SELECT PQ_IMPTOTDOC AS TOT FROM PAA2700F\n" << + "WHERE PQ_KEYPRGINVIO = '" << fppro_keys.get(0) << "' AND PQ_KEYHEADERFATT = '" << fppro_keys.get(1) << "' AND PQ_KEYBODYFATT = '" << fppro_keys.get(2) << "'"; + fp_db().sq_set_exec(query); + const TString tot = fp_db().sq_get("TOT"); + return tot.full() && real(tot) != 0; +} + int TPrimanota_application::write(const TMask& m) { static int lasterr = NOERR; @@ -2258,6 +2268,7 @@ void TPrimanota_application::ini2mask(TConfig& ini, TMask& msk, bool query) } if (_f1_ini && msk.find_by_id(FS_RECALC) != NULL) { + msk.set(F_TOTALE, calcola_imp()); msk.set(F_COLFPPRO, "X"); msk.set(FS_RECALC, ""); } @@ -2440,13 +2451,16 @@ int TPrimanota_application::save_fppro() const TString& keyheaderfatt = fppro_keys.get(); const TString& keybodyfatt = fppro_keys.get(); + // Controllo che i dati corrispondano a quelli nella fattura in ingresso TString where_str; - where_str << " (PZ_DATA = \'" << data_documento.date2ansi() << "\' AND PQ_IMPTOTDOC = \'" << tot_doc << "\' AND PZ_NUMERO = \'" << (!numero_docext.empty() ? numero_docext : numero_doc) << "\') "; + if (has_tot_doc(fppro_keys)) + where_str << " (PZ_DATA = \'" << data_documento.date2ansi() << "\' AND PQ_IMPTOTDOC = \'" << tot_doc << "\' AND PZ_NUMERO = \'" << (!numero_docext.empty() ? numero_docext : numero_doc) << "\') "; + else + where_str << " (PZ_DATA = \'" << data_documento.date2ansi() << "\' AND PZ_NUMERO = \'" << (!numero_docext.empty() ? numero_docext : numero_doc) << "\') "; TString& query = TPro_msk::query_fppro(keyprginvio, keyheaderfatt, keybodyfatt, where_str); fp_db().sq_set_exec(query); - const int n = fp_db().sq_items(); - if (n != 1) + if(has_f1_db(&msk) && fp_db().sq_items() != 1) { warning_box(TString("Attenzione, ") << "al movimento non è stato abbinato nessun documento elettronico.\n" << "Per consentire una corretta archiviazione sostitutiva si consiglia di non confermare la registrazione e di procedere\n" << @@ -2457,12 +2471,10 @@ int TPrimanota_application::save_fppro() const int numreg = fp_db().sq_get_int("PZ_NUMREGCONT"); if (numreg != 0) { - const bool key = noyes_box( - TString("Il documento ") << data_documento.year() << " / " << numero_doc << - " è già stato inserito con la registrazione numero " << numreg << - "\nSi desidera continuare comunque?"); - if(!key) - return pro_notsaved; + TString msg; msg << "Attenzione il documento " << data_documento.year() << " / " << numero_doc << + " appena registrato e' gia' stato inserito con la registrazione numero " << numreg << + "\nControllare e nel caso provvedere a correggere l'associazione del movimento ai documenti in ingresso."; + warning_box(msg); } // Devo controllare che la data operazione sia maggiore della data ric diff --git a/src/cg/cg2102.h b/src/cg/cg2102.h index 9bfc9ecf6..679e326c8 100755 --- a/src/cg/cg2102.h +++ b/src/cg/cg2102.h @@ -217,6 +217,7 @@ protected: // TApplication // Metodo chiamato dalla write e rewrite per salvare su db fatt. void write_fppro(); + static bool has_tot_doc(TToken_string& fppro_keys); // Salvo dati fornitore e registrazione contabile sul db FPPRO int save_fppro(); // Salva sul movimento il riferimento al documento in FPPRO (keys)