#include #include "f90.h" #include "f90100.h" #include "lffiles.h" #include "isam.h" #include "../f1/f1lib.h" #include "../fp/fplib.h" #include "urldefid.h" #include "progind.h" #include "f901tab.h" #include "f90100b.h" #include "f90100d.h" #include "sqlset.h" #include "f90100c.h" /** \file f90100.cpp * Per aggiornare le tabelle f9 aggiungere nella cartella "sql\f9\" il file sql cosi' fatto: * f9xxxx.sql dove xxxx e' il numero zero-filled della versione delle tabelle, che INCREMENTA DI DUE COME CON LE PATCH, IMPORTANTE! * Aggiornare la definizione qui sotto di SQL_VERSION mettendo la nuova versione. * Fare patch del file sql e dell'eseguibile f90.exe. * Lanciare il programma per eseguire l'aggiornamento. */ #define TABMOD_TABVER "S0" // Campo per la memorizzazione della versione attuale delle tabelle #define TAB_BASE_VERSION 100 // Versione base delle tabelle #define SQL_VERSION 104 // Utilizzo questo per controllare la versione attuale delle tabelle e nel caso aggiornarle //////////////////////////////////////////////////////// // Utilities //////////////////////////////////////////////////////// // Getters per semplificare i get dai TRecorset const TString& recset_get_string(const TRecordset& rec, const char* field, int zero_filled = -1); int recset_get_int(const TRecordset& rec, const char* field, int zero_filled = -1); bool recset_get_bool(const TRecordset& rec, const char* field); real recset_get_real(const TRecordset& rec, const char* field); TDate recset_get_date(const TRecordset& rec, const char* field); TMask& descr_msk() { static std::unique_ptr m = nullptr; if (m == nullptr) { m = std::make_unique("Estrazione", 1, 60, 5); m->add_button_tool(DLG_OK, "Conferma", TOOL_OK); m->add_groupbox(DES_GROUP, 0, "Inserire descrizione estrazione:", 1, 0, 59, 3, ""); m->add_string(DES_TEXT, 0, "Descrizione", 4, 1, 250, "", 40); } return *m; } TMask& esclusi_mask() { static unique_ptr _esclusi_mask = nullptr; if (_esclusi_mask == nullptr) { _esclusi_mask = std::make_unique("f90100c.msk"); TMask& m = *_esclusi_mask; ((TSheet_field&)m.field(S_ESCL)).set_notify(TF9_app::select_escl_notify); // Handler dello sheet per selezione singola m.set_handler(DLG_FINDREC, TF9_app::controllo_escl_handler); // Bottone per aprire maschera di controllo movimenti m.set_handler(B_ESTRAI, TF9_app::estrai_escl_handler); // Bottone estrai TMask& sheet_m = ((TSheet_field&)m.field(S_ESCL)).sheet_mask(); // Maschera dei campi dello sheet sheet_m.set_handler(DLG_USER, TF9_app::mov_handler_escl); // Bottone collega movimento m.field(DLG_FINDREC).disable(); } return *_esclusi_mask; } const TString& recset_get_string(const TRecordset& rec, const char* field, const int zero_filled) { const TString& str = rec.get(rec.find_column(field)).as_string(); if (zero_filled == -1) return str; static TString c; c.cut(0); const int len = str.len(); for (int i = len; i < zero_filled; i++) // Sistemo il codcaus per via del TVariant che non restituisce la stringa esattamente come l'originale c << "0"; c << str; return c; } int recset_get_int(const TRecordset& rec, const char* field, const int zero_filled) { return rec.get(rec.find_column(field)).as_int(); } bool recset_get_bool(const TRecordset& rec, const char* field) { return rec.get(rec.find_column(field)).as_bool(); } real recset_get_real(const TRecordset& rec, const char* field) { return rec.get(rec.find_column(field)).as_real(); } TDate recset_get_date(const TRecordset& rec, const char* field) { return rec.get(rec.find_column(field)).as_date(); } //////////////////////////////////////////////////////// // TEstrai_mask //////////////////////////////////////////////////////// TString TEstrai_mask::get_numdoc_exp_fp(const int numreg) { TLocalisamfile mov(LF_MOV); mov.put(MOV_NUMREG, numreg); if (mov.read() == NOERR) { const TString& dprovv = mov.get(MOV_DPROVV); const int danno = mov.get_int(MOV_DANNO); const TString& dcodnum = mov.get(MOV_DCODNUM); const int dndoc = mov.get_int(MOV_DNDOC); if (!dprovv.empty() && danno != 0 && !dcodnum.empty() && dndoc != 0) { const TDocumento doc(dprovv[0], danno, dcodnum, dndoc); return complete_num_fp(doc.codice_numerazione(), doc.numero()); } } return ""; } int TEstrai_mask::estrai() { const TDate dataini = get_dataini(); const TDate dataend = get_dataend(); const char tipodoc = get_tipodoc(); const bool flagpro = is_provviso(); TFilename path; f9_app().get_spotlite_path(path); // Vero e proprio oggetto estrazione _estrazione = make_unique( F9CONF.get_ambiente(), // Codice ambiente flagpro, // Flag prov. tipodoc, // Tipo doc. get_descr(), // Descrizione estrazione F9CONF.get_addr_doc(), // Cartella documenti false, // Estrazione di un escluso path, // Spotlight path &dataini, // Data estr. mov dal &dataend, // Data estr. mov al F9CONF.get_has_cartexp() // Flag per estrarre anche i doc. cartacei ); // Leggo i movimenti e li carico nell'estrazione. ///////////// TString query; // query << "SELECT * FROM MOV WHERE DATAREG>=" << dataini.date2ansi() << " AND DATAREG<=" << dataend.date2ansi() << ";"; query = "USE MOV KEY 2"; query << "\nFROM DATAREG=" << dataini.date2ansi() << "\nTO DATAREG=" << dataend.date2ansi(); // query = "USE MOV\n" << "SELECT BETWEEN(DATAREG," << dataini.date2ansi() "," << dataend.date2ansi() << ")"; // query << "\nFROM DATAREG=" << dataini.date2ansi() << "\nTO DATAREG=" << dataend.date2ansi(); TISAM_recordset mov(query); TProgress_monitor* progr = new TProgress_monitor(mov.items(), "Acquisizione movimenti", false); TLocalisamfile clifo(LF_CLIFO); const TipoIVA tipo = tipodoc == 'A' ? iva_acquisti : iva_vendite; int count = 0; // Prendo tutti i movimenti a partire da una data e li carico tutti fino alla data finale for (bool ok = mov.move_first(); ok; ok = mov.move_next()) { if (!progr->add_status()) break; TToken_string elab_f9(recset_get_string(mov, MOV_ELABF9), ';'); // Stringa del campo elaborazione f9 nel file mov const bool escluso = !(elab_f9.items() == 3 && elab_f9.get(2)[0] != 'X' || elab_f9.empty()); const TCausale caus(recset_get_string(mov, MOV_CODCAUS, 3), TDate(recset_get_string(mov, MOV_DATAREG)).year()); const bool stampato = recset_get_bool(mov, MOV_REGST); const TRegistro& reg = caus.reg(); const TipoIVA& iva = reg.iva(); TString numdoc = recset_get_string(mov, MOV_NUMDOCEXT); if(numdoc.empty()) numdoc = recset_get_string(mov, MOV_NUMDOC); // Se definitivo controllo il flag di stampato REGST if ((flagpro || stampato) && numdoc.full() && iva == tipo) { clifo.zero(); clifo.put(CLI_TIPOCF, tipo == iva_acquisti ? "F" : "C"); clifo.put(CLI_CODCF, recset_get_string(mov, MOV_CODCF)); // Creo il movimento da inserire movimento_t t; t.err = false; t.numreg = recset_get_int (mov, MOV_NUMREG); t.datareg = recset_get_date (mov, MOV_DATAREG); t.datadoc = recset_get_date (mov, MOV_DATADOC); t.codcaus = recset_get_string (mov, MOV_CODCAUS, 3); t.meseliq = recset_get_int (mov, MOV_MESELIQ); if (tipo == iva_vendite) t.numdoc = get_numdoc_exp_fp(t.numreg); if (t.numdoc.empty()) t.numdoc = numdoc; t.tot = recset_get_real (mov, MOV_TOTDOC) + recset_get_real(mov, MOV_RITFIS) + recset_get_real(mov, MOV_RITSOC); t.codcf = recset_get_int (mov, MOV_CODCF); t.ragsoc = clifo.read() == NOERR ? clifo.get(CLI_RAGSOC) : " "; t.reg_protiva = TString(recset_get_string(mov, MOV_REG)) << "/" << recset_get_string(mov, MOV_PROTIVA); t.descr = recset_get_string (mov, MOV_DESCR); if (escluso) { t.estratto = false; t.descr_estr = movimento_t::escluso; } // Effettivo inserimento del movimento _estrazione->add_mov(t); ++count; } } delete progr; _stats = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Effettiva estrazione. Faccio partire diagnostica e scrittura db. const result_estr result = _estrazione->estrai(); #ifdef DBG TString msg; msg << "total: " << (int)_stats.total << "\n"; if (tipodoc == 'A') { msg << "Movimenti saltati: " << (int)_stats.fa_skip << "\n"; msg << "Movimenti in errore: " << (int)_stats.fa_err << "\n"; msg << "Movimenti estratti: " << (int)_stats.fa_estr << "\n"; msg << "Movimenti senza cat. doc.: " << (int)_stats.fa_nocatdoc; } else { msg << "Movimenti saltati poiche' cartacei: " << (int)_stats.fv_cart_skip << "\n"; msg << "Movimenti in errore: " << (int)_stats.fv_err << "\n"; msg << "Movimenti estratti: " << (int)_stats.fv_estr << "\n"; msg << "Movimenti senza cat. doc.: " << (int)_stats.fv_nocatdoc; } message_box(msg); #endif // Ricalcolo sheet estrazioni f9_app().notify_estraction(); return result; } void TEstrai_mask::segna_in_errore() const { TString query; query << "UPDATE " F9_DRD "\n" "SET " DRD_STATO " = '" D_GEST_ERR "'\n" "WHERE " DRD_ID_EST " = '" << _estrazione->get_id_estr() << "'\n"; fp_db().sq_set_exec(query); } bool TEstrai_mask::estrai_handler(TMask_field& f, KEY key) { TEstrai_mask& msk = (TEstrai_mask&)f.mask(); TF9_app& app = f9_app(); // Estraggo const int stato = msk.estrai(); // Main function // Gestione risultato estrazione if (stato == 1) { message_box("Estrazione avvenuta con successo!"); app.segna_estratti(); } if (stato == 0 || stato == -3) { warning_box("L'estrazione non e' stata completata. Controllare il log degli errori."); if (stato == 0) // Errore scrittura F9IVA, non segno in errore in testata... msk.segna_in_errore(); // ... se l'errore e' dovuto alla scrittura sul db. } app.print_log(); msk.field(ES_DESCR).set(""); msk.stop_run(K_FORCE_CLOSE); return true; } void TEstrai_mask::enable_fields(const bool en) { enable(ES_DATAINI, en); enable(ES_DATAEND, en); enable(ES_FLAGPROV, en); enable(ES_TIPODOC, en); } bool TEstrai_mask::enable_handler(TMask_field& f, KEY key) { ((TEstrai_mask&)f.mask()).enable_fields(); return true; } bool TEstrai_mask::dataini_handler(TMask_field& f, KEY key) { TMask& msk = f.mask(); if (key == K_TAB) { if (msk.get(ES_DATAINI).full() && msk.get(ES_DATAEND).full() && msk.get_date(ES_DATAINI) > msk.get_date(ES_DATAEND)) return f.error_box("La data di inizio non puo' essere maggiore di quella di fine"); } return true; } bool TEstrai_mask::dataend_handler(TMask_field& f, KEY key) { TMask& msk = f.mask(); if (key == K_TAB) { if (msk.get(ES_DATAINI).full() && msk.get(ES_DATAEND).full() && msk.get_date(ES_DATAINI) > msk.get_date(ES_DATAEND)) return f.error_box("La data di fine non puo' essere minore di quella di inizio"); } return true; } TEstrai_mask::TEstrai_mask() : TMask("Estrazione", 1, 60, 16), _estrazione(nullptr) { add_button_tool(DLG_ELABORA, "Estrai", TOOL_ELABORA); add_button_tool(DLG_NULL, "", 0); add_button_tool(DLG_QUIT, "Esci", TOOL_QUIT); add_groupbox(ES_DATEGROUP, 0, "Inserire periodo per estrazione:", 1, 0, 59, 3, ""); add_date (ES_DATAINI, 0, "dal", 4, 1, ""); add_date (ES_DATAEND, 0, " al", 33, 1, ""); add_groupbox(ES_FLAGGROUP, 0, "Selezionare tipo di estrazione:", 1, 3, 28, 3, ""); add_list (ES_FLAGPROV, 0, "Flag provvisorio", 2, 4, 1, "", "P|D", "Provvisorio|Definitivo"); add_groupbox(ES_TIPOGROUP, 0, "Selezionare documenti da estrarre:", 32, 3, 28, 3, ""); add_list (ES_TIPODOC, 0, "Tipi documento", 33, 4, 1, "", "A|V", "Acquisti|Vendite"); add_groupbox(ES_DESCGROUP, 0, "Inserire descrizione estrazione:", 1, 6, 59, 3, ""); add_string (ES_DESCR, 0, "Descrizione", 2, 7, 250, "", 40); TMask::set_handler(DLG_ELABORA, estrai_handler); TMask::set_handler(ES_DATAINI, dataini_handler); TMask::set_handler(ES_DATAEND, dataend_handler); TDate dt(TODAY); dt.set_day(1); dt.set_month(1); set(ES_DATAINI, dt); set(ES_DATAEND, today); } //////////////////////////////////////////////////////// // TMonitor_mask //////////////////////////////////////////////////////// bool TMonitor_mask::save_conf_handler(TMask_field& f, KEY key) { TMask& config_mask = f.mask(); TString old_codsoc = F9CONF.get_ambiente(); if(config_mask.get(CF_CODSOC).empty()) warning_box("Codice Ambiente vuoto. Impossibile salvare i dati."); F9CONF.set_ambiente (config_mask.get(CF_CODSOC)); F9CONF.set_addr_doc (config_mask.get(CF_ADDRDOC)); F9CONF.set_addr_doc_loc (config_mask.get(CF_ADDRDOCLOC)); F9CONF.set_has_cartexp (config_mask.get_bool(CF_CARTEXP)); config_mask.close(); f9_app().edit_wa(old_codsoc); return true; } void TMonitor_mask::controllo_errori() const { TString id_estr, stato; TSheet_field& sf = sfield(S_ELAB); bool flag = false; FOR_EACH_SHEET_ROW(sf, nr, row) { if (row->get(0)[0] == 'X') { id_estr << row->get(cid2index(F_IDESTR)); stato << row->get(cid2index(F_ISTATOESTR)); flag = true; break; } } if (flag) { if(stato.cut(2) == D_GEST_ERR) { TControllo_mask controllo(F9CONF.get_ambiente(), id_estr); controllo.run(); } else warning_box("Impossibile controllare un'estrazione che non e'\nin stato di %s ('" D_GEST_ERR "').", TF9_app::traduci_stato(D_GEST_ERR)); } else warning_box("Selezionare un'estrazione."); } void TMonitor_mask::delete_estr_fld(const TString& idestr) { const TFilename dir = TString() << F9CONF.get_addr_doc_loc() << SLASH << F9CONF.get_ambiente() << SLASH << idestr << SLASH; experimental::filesystem::remove_all((const char*)dir); } void TMonitor_mask::delete_pack(const bool all) const { // Se nello sheet non c'e' selezionata alcuna riga viene richiamata col flag all = true bool flag = false; TSheet_field& sf = sfield(S_ELAB); FOR_EACH_SHEET_ROW(sf, nr, row) { if (row->get(0)[0] == 'X' || all) { flag = true; const TString id_estr(row->get(cid2index(F_IDESTR))); TString query; const TString& codsoc(F9CONF.get_ambiente()); query << "BEGIN\n" " DECLARE @flag_prov CHAR(1), @stato CHAR(2);\n\n" " SELECT @flag_prov = " DRD_FLAG_PD ", @stato = " DRD_STATO "\n" " FROM " F9_DRD "\n" " WHERE " DRD_ID_EST " = '" << id_estr << "';\n\n" " IF (@flag_prov = 'P' OR @stato = '" D_GEST_ERR "' OR @stato = '" IN_DIAGN "' OR @stato = '" D_WA_ERR "' OR @stato = '" D_ERR_SOS "') BEGIN\n" " DELETE FROM " F9_ERR " WHERE " ERR_CODSOC " = '" << codsoc << "' AND " ERR_IDESTR " = '" << id_estr << "';\n" " END\n" " ELSE BEGIN\n" " SELECT @flag_prov AS FLAG, @stato AS STATO;\n" " END\n" "END"; fp_db().sq_set_exec(query); // Elimino testata in DRD, solo se provvis. query.cut(0) << "BEGIN\n" " DECLARE @flag_prov CHAR(1), @stato CHAR(2);\n\n" " SELECT @flag_prov = " DRD_FLAG_PD ", @stato = " DRD_STATO "\n" " FROM " F9_DRD "\n" " WHERE " DRD_ID_EST " = '" << id_estr << "';\n\n" " IF (@flag_prov = 'P' OR @stato = '" D_GEST_ERR "' OR @stato = '" IN_DIAGN "' OR @stato = '" D_WA_ERR "' OR @stato = '" D_ERR_SOS "') BEGIN\n" " DELETE FROM " F9_DRD " WHERE " DRD_CODSOC " = '" << codsoc << "' AND " DRD_ID_EST " = '" << id_estr << "';\n" " DELETE FROM " F9_IVA " WHERE " IVA_CODSOC " = '" << codsoc << "' AND " IVA_IDLAN " = '" << id_estr << "';\n" " DELETE FROM " F9_MOVESTR " WHERE " MES_CODSOC " = '" << codsoc << "' AND " MES_IDESTR " = '" << id_estr << "';\n" " END\n" " SELECT @flag_prov AS FLAG, @stato AS STATO;\n" "END"; fp_db().sq_set_exec(query); TString stato = fp_db().sq_get("STATO"); if (fp_db().sq_get("FLAG") != "P" && stato != D_GEST_ERR && stato != IN_DIAGN && stato != D_WA_ERR && stato != D_ERR_SOS && !all) { warning_box("E' possibile eliminare solo un'estrazione provvisoria\no in uno degli stati di errore se definitiva (02 - 05 - 08)."); return; } fp_db().sq_commit(); delete_estr_fld(id_estr); if (!all) break; } } if (!flag) { if (noyes_box("Eliminare tutti i pacchetti provvisori o in stato di errore gestionale?")) delete_pack(true); } fill(); } void TMonitor_mask::fill() const { TString query; query << "SELECT * FROM " F9_DRD " WHERE " DRD_CODSOC " = '" << F9CONF.get_ambiente() << "' ORDER BY " << DRD_TIME << " DESC;"; fp_db().sq_set_exec(query, false); TSheet_field& sf = sfield(S_ELAB); sf.hide(); sf.destroy(); int i = 0; for (bool ok = fp_db().sq_next(); ok; ok = fp_db().sq_next()) { TString tipo; TToken_string& row = sf.row(i++); row.add(" "); row.add(fp_db().sq_get(DRD_STATO) == "09" ? "X" : ""); row.add(fp_db().sq_get(DRD_ID_EST)); row.add(fp_db().sq_get_date(DRD_TIME)); row.add(fp_db().sq_get(DRD_FLAG_PD) == "P" ? "X" : ""); tipo << fp_db().sq_get(DRD_TIPODOC); if (tipo == "A") tipo << "cquisti"; if (tipo == "V") tipo << "endite"; if (tipo == "C") tipo << "orrispettivi"; row.add(tipo); row.add(fp_db().sq_get_date(DRD_DATADA)); row.add(fp_db().sq_get_date(DRD_DATAA)); row.add(fp_db().sq_get(DRD_UTENTE)); row.add(fp_db().sq_get(DRD_STATO) << " - " << TF9_app::traduci_stato(fp_db().sq_get(DRD_STATO))); row.add(fp_db().sq_get(DRD_DESC)); } sf.force_update(); sf.show(); } bool TMonitor_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) { case DLG_ELABORA: if (e == fe_button) open_win_estr(); break; case DLG_DELREC: if (e == fe_button) delete_pack(); break; case DLG_CONFIG: if (e == fe_button) open_win_conf(); break; case DLG_FINDREC: if (e == fe_button) controllo_errori(); break; case DLG_RECALC: fill(); break; case B_SHOWESTR: open_apri_estr_win(); break; case B_SHOWESCL: if (e == fe_button) f9_app().open_esclusi(); break; case F_SEL: if (e == fe_modify) sel(); default: break; } return true; } void TMonitor_mask::open_apri_estr_win() { static TString last_fill_id = 0; TString id; TToken_string* row_estrazione = nullptr; FOR_EACH_SHEET_ROW(sfield(S_ELAB), nr, row) { if (row->get(0)[0] == 'X') { if (TString(row->get(cid2index(F_STATESTR))).starts_with("02")) { message_box("Impossibile controllare un pacchetto in stato di errore '02'.\n" "Usare il 'Controllo Estrazioni' per vedere i movimenti in errore."); return; } row_estrazione = row; id = row->get(cid2index(F_IDESTR)); break; } } if (row_estrazione == nullptr) { message_box("Selezionare un pacchetto."); return; } if (last_fill_id != id) { _inclusi_mask = std::make_unique(); _inclusi_mask->set_from_row_estrazione(*row_estrazione); _inclusi_mask->fill_estr(); _inclusi_mask->fill_res (); last_fill_id = id; } _inclusi_mask->run(); } void TMonitor_mask::open_win_estr() { if (!F9CONF.get_ambiente().full()) warning_box("Inserire codice ambiente societa' in configurazione"); else f9_app().run_estr_msk(); } void TMonitor_mask::open_win_conf() { static TMask* m = nullptr; if (m == nullptr) { m = new TMask("Configurazione Archiviazione Sostitutiva", 1, 70, 20); m->add_button_tool(DLG_OK, "Conferma", TOOL_OK); m->add_button_tool(DLG_NULL, "", 0); m->add_button_tool(DLG_QUIT, "Esci", TOOL_QUIT); m->add_groupbox (CF_CODGROUP, 0, "Codice Ambiente Societa' (WEBAPP):", 1, 0, 69, 3, ""); m->add_string (CF_CODSOC, 0, "Codice ambiente", 4, 1, 10, "", 10); m->add_groupbox (CF_ADDRGROUP, 0, "Indicare percorso documenti cartacei:", 1, 3, 69, 4, ""); m->add_string (CF_ADDRDOC, 0, "Server", 2, 4, 256, "", 40); m->add_string (CF_ADDRDOCLOC, 0, "Locale", 2, 5, 256, "", 40); m->add_groupbox (CF_ESTRGROUP, 0, "Opzioni estrazione", 1, 7, 69, 4, ""); m->add_boolean (CF_CARTEXP, 0, "Estrai anche documenti cartacei", 2, 8); m->set_handler(DLG_OK, save_conf_handler); m->set(CF_CODSOC, F9CONF.get_ambiente()); m->set(CF_ADDRDOC, F9CONF.get_addr_doc()); m->set(CF_ADDRDOCLOC, F9CONF.get_addr_doc_loc()); m->set(CF_CARTEXP, F9CONF.get_has_cartexp()); } m->run(); } void TMonitor_mask::sel() const { TSheet_field& sf = sfield(S_ELAB); sf.hide(); FOR_EACH_SHEET_ROW(sf, nr, row) { if (*row->get(0) == 'X') row->add("", 0); } sf.force_update(); sf.show(); } TMonitor_mask::TMonitor_mask(): TAutomask("f90100a"), _inclusi_mask(nullptr) { // Controllo che esistano delle categorie documentali. TCategorie_doc catdoc; if (catdoc.get_array_rows().items() == 0 && yesno_box("Attenzione non e' presente alcuna categoria documentale.\nPrecaricare le categorie di default?")) { TString p; p << "f90.exe -1 -d /u" << user(); TExternal_app ext(p); ext.run(); } fill(); } ///////////////////////////////////////////// // TControllo_mask ///////////////////////////////////////////// void TControllo_mask::associa() // todo: levare gli ultimi residui del vecchio funzionamento del controllo errori { TToken_string* mov_sel = selected_mov(); TToken_string* fat_sel = selected_fat(); if (mov_sel == nullptr || fat_sel == nullptr) { warning_box("Selezionare prima un movimento e una fattura elettronica."); return; } TToken_string keys(fat_sel->get(cid2index(F_FPROKEYS)), ';'); fppro_db().set_keys(keys); const bool ok = fppro_db().associa_mov(mov_sel->get_int(cid2index(F_CNUMREG))); if (ok) { // Tolgo il flag di in errore sul vettore in modo da rifare la fill e non venir piu' contato come da controllare auto it = _controllo_mov.begin(); int count = -1; while (count < _selected_mov && it != _controllo_mov.end()) { if (it->get(0)[0] == 'X') // Devo saltare tutti quelli che non hanno il flag e contare solo quelli che ce l'hanno count++; if (count < _selected_mov) ++it; } it->add(' ', 0); TF9_dberr::del_err(_cod_soc, _id_estr, mov_sel->get_int(cid2index(F_CNUMREG))); } } void TControllo_mask::conferma_esclusi() const { const TMask& mask = *this; TSheet_field& sf = mask.sfield(S_CONTROLLO); sf.hide(); FOR_EACH_SHEET_ROW(sf, nr, row) { TLocalisamfile movs(LF_MOV); movs.put(MOV_NUMREG, row->get_int(cid2index(F_CNUMREG))); movs.read(); if (*row->get(cid2index(F_CESCLUDI)) == 'X') { const TDate today(TODAY); TToken_string stato("", ';'); stato.add("", 0); stato.add(today.date2ansi()); stato.add("X"); movs.put(MOV_ELABF9, stato); movs.rewrite(); row->add("Si", cid2index(F_CESCLUSO)); TString query; query << "UPDATE " F9_ERR " SET ESCLUSO = 'Si' WHERE " ERR_CODSOC " = '" << _cod_soc << "' AND IDESTR = '" << _id_estr << "' AND NUMREG = '" << row->get(cid2index(F_CNUMREG)) << "';"; fp_db().sq_set_exec(query); } else { if (movs.get(MOV_ELABF9).full()) { movs.put(MOV_ELABF9, ""); row->add("", cid2index(F_CESCLUSO)); movs.rewrite(); TString query; query << "UPDATE " F9_ERR " SET ESCLUSO = NULL WHERE " ERR_CODSOC " = '" << _cod_soc << "' AND IDESTR = '" << _id_estr << "' AND NUMREG = '" << row->get(cid2index(F_CNUMREG)) << "';"; fp_db().sq_set_exec(query); } } } sf.force_update(); sf.show(); } vector& TControllo_mask::import_error_list() { _controllo_mov.clear(); TF9_dberr dberr; _tipo_doc_err = TF9_dberr::get_errori(_cod_soc, _id_estr, _controllo_mov); return _controllo_mov; } void TControllo_mask::fill() { TSheet_field& sf = sfield(S_CONTROLLO); sf.hide(); sf.destroy(); if (!_is_escluso) import_error_list(); else _controllo_mov = f9_app()._esclusi; for (auto it = _controllo_mov.begin(); it != _controllo_mov.end(); ++it) { TToken_string& row = sf.row(-1); if (*it->get(0) == 'X') { row = *it; row[0] = (char&)" "; } } sf.force_update(); sf.show(); // Fill fppro sheet if (!_is_escluso && _tipo_doc_err == 'A' || _is_escluso && f9_app().get_tipoiva_escl() == iva_acquisti) fill_fppro_sheet(); } void TControllo_mask::fill_fppro_sheet() const { TSheet_field& sf = sfield(S_FPPRO); sf.hide(); sf.destroy(); const char* order; switch (_ordin) { default: case 'D': order = "P7_DATA"; break; case 'N': order = "P7_NUMERO"; break; case 'F': order = "FORNITORE"; break; case 'R': order = "P2_ANADENOMIN"; break; case 'P': order = "P2_FISCIVACOD"; break; } TString query; query << "SELECT PQ_KEYPRGINVIO AS KEYPRGINVIO, PQ_KEYHEADERFATT AS KEYHEADERFATT, PQ_KEYBODYFATT AS KEYBODYFATT,\n" << "PZ_TIPODOC AS TIPODOC, P7_DATA AS DATA, P7_NUMERO AS NUMDOC, PQ_IMPTOTDOC AS IMPTOTDOC,\n" << "CASE\n" << "WHEN PZ_CLIFOR <> '' THEN CAST(PZ_CLIFOR AS NUMERIC(10, 0))\n" << "WHEN PZ_CLIFOR = '' THEN 0\n" << "END AS FORNITORE, " << "P2_ANADENOMIN AS RAGSOC, P2_FISCIVAPAESE AS STATOPIVA, P2_FISCIVACOD AS PIVA FROM PAA2700F\n" << "JOIN PAA0700F ON PQ_KEYPRGINVIO = P7_KEYPRGINVIO AND PQ_KEYHEADERFATT = P7_KEYHEADERFATT AND PQ_KEYBODYFATT = P7_KEYBODYFATT\n" << "JOIN PAA0200F ON PQ_KEYPRGINVIO = P2_KEYPRGINVIO AND PQ_KEYHEADERFATT = P2_KEYHEADERFATT AND PQ_KEYBODYFATT = P2_KEYBODYFATT\n" << "JOIN FPPRO00F ON PQ_KEYPRGINVIO = PZ_KEYPRGINVIO AND PQ_KEYHEADERFATT = PZ_KEYHEADERFATT AND PQ_KEYBODYFATT = PZ_KEYBODYFATT\n" << "WHERE PZ_NUMREGCONT = '0' AND PZ_DATAREGCONT = '2001-01-01' AND P7_DATA >= '" << _datada.date2ansi() << "' AND P7_DATA <= '" << _dataa.date2ansi() << "'\n" << "ORDER BY " << order << " " << (_verso == 'A' ? "ASC" : "DESC") << "\n"; fp_db().sq_set_exec(query, false); for (bool ok = fp_db().sq_next(); ok; ok = fp_db().sq_next()) { TToken_string& row = sf.row(-1); row.add(fp_db().sq_get("TIPODOC"), 1); row.add(fp_db().sq_get_date("DATA")); row.add(fp_db().sq_get("NUMDOC")); row.add(fp_db().sq_get("IMPTOTDOC")); row.add(fp_db().sq_get("FORNITORE")); row.add(fp_db().sq_get("RAGSOC")); row.add(fp_db().sq_get("STATOPIVA")); row.add(fp_db().sq_get("PIVA")); row.add(fp_db().sq_get("KEYPRGINVIO") << ";" << fp_db().sq_get("KEYHEADERFATT") << ";" << fp_db().sq_get("KEYBODYFATT")); } sf.force_update(); sf.show(); } TMask& TControllo_mask::get_win_order() { static TMask* m = nullptr; if (m == nullptr) { m = new TMask("Configurazione Archiviazione Sostitutiva", 1, 60, 16); // TOOLBAR m->add_button_tool(DLG_OK, "Conferma", TOOL_OK); m->add_button_tool(DLG_NULL, "", 0); m->add_button_tool(DLG_QUIT, "Esci", TOOL_QUIT); // Ordinatori m->add_radio(F_ORDER, 0, "@BOrdina per:", 1, 0, 59, "D|N|F|R|P", "DATA|NUMDOC|FORNITORE|RAGSOC|PIVA", "Z"); m->add_radio(F_VERSO, 0, "@BVerso:", 1, 3, 59, "A|D", "Crescente|Decrescente", "Z"); // Filtro date m->add_groupbox (F_ORDDATAG, 0, "@BFiltra per data documento", 1, 6, 59, 3); m->add_date (F_ORDDATADA, 0, "dal", 2, 7); m->add_date (F_ORDDATAA, 0, " al", 22, 7); //m->set_handler(DLG_OK, save_conf_handler); _ordin = ini_get_string(CONFIG_DITTA, INI_PAR_MOD, "ORDINAM", "D")[0]; _verso = ini_get_string(CONFIG_DITTA, INI_PAR_MOD, "VERSO", "A")[0]; m->set(F_ORDER, &_ordin); m->set(F_VERSO, &_verso); m->set(F_ORDDATADA, _datada); m->set(F_ORDDATAA, _dataa); } return *m; } void TControllo_mask::open_win_order() { TMask& m = get_win_order(); m.set(F_ORDDATADA, _datada); m.set(F_ORDDATAA, _dataa); m.run(); _ordin = m.get(F_ORDER)[0]; _verso = m.get(F_VERSO)[0]; _datada = m.get_date(F_ORDDATADA); _dataa = m.get_date(F_ORDDATAA); ini_set_string(CONFIG_DITTA, INI_PAR_MOD, "ORDINAM", &_ordin); ini_set_string(CONFIG_DITTA, INI_PAR_MOD, "VERSO", &_verso); } TToken_string* TControllo_mask::selected_mov() { TSheet_field& movs = sfield(S_CONTROLLO); FOR_EACH_SHEET_ROW(movs, nr, row) { if (row->get(0)[0] == 'X') { _selected_mov = nr; return row; } } return nullptr; } TToken_string* TControllo_mask::selected_fat() const { TSheet_field& fppro = sfield(S_FPPRO); FOR_EACH_SHEET_ROW(fppro, nr, row) { if (row->get(0)[0] == 'X') return row; } return nullptr; } void TControllo_mask::selfatt(TOperable_field& o, const long jolly) const { const TMask& mask = *this; TSheet_field* sf; if (jolly == 1) // Sheet controllo sf = &mask.sfield(S_CONTROLLO); else sf = &mask.sfield(S_FPPRO); sf->hide(); FOR_EACH_SHEET_ROW(*sf, nr, row) { if (*row->get(0) == 'X') row->add("", 0); } sf->force_update(); sf->show(); } bool TControllo_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) { case DLG_USER: if (e == fe_button && jolly > 0) { TSheet_field& sf = sfield(S_CONTROLLO); TToken_string& row = sf.row(sf.selected()); TRectype mov(LF_MOV); mov.put(MOV_NUMREG, row.get(sf.cid2index(F_CNUMREG))); if (open_mov(mov)) fill(); } break; case B_ORDER: if (e == fe_button) { open_win_order(); fill_fppro_sheet(); } break; case B_ASSOC: if (e == fe_button) { associa(); fill(); // Ricarico gli sheet } break; case B_ESCL: if (e == fe_button) { conferma_esclusi(); fill(); } break; case B_SELESCL: if (e == fe_button) { _sel_esclusi = !_sel_esclusi; field(B_ASSOC).enable(!_sel_esclusi); field(B_ESCL).enable(_sel_esclusi); field(B_ALLESCL).enable(_sel_esclusi); sfield(S_CONTROLLO).enable_column(cid2index(F_CESCLUDI), _sel_esclusi); sfield(S_CONTROLLO).force_update(); } break; case B_ALLESCL: if (e == fe_button) { TSheet_field& sf = sfield(S_CONTROLLO); sf.hide(); const bool active = *sf.row(0).get(cid2index(F_CESCLUDI)) == 'X'; FOR_EACH_SHEET_ROW(sf, nr, row) row->add(active ? " " : "X", cid2index(F_CESCLUDI)); sf.force_update(); sf.show(); } break; case S_CONTROLLO: if (e == fe_init) sfield(S_CONTROLLO).enable_column(cid2index(F_CESCLUDI), false); break; case F_CSEL: if (e == fe_modify) selfatt(o, jolly); break; default: break; } return true; } TControllo_mask::TControllo_mask(const char* codsoc, const char* id_estr, const bool esclusi) : TAutomask("f90100b"), _ordin('D'), _verso('A'), _selected_mov(0), _sel_esclusi(false) { _cod_soc = codsoc; _id_estr = id_estr; field(B_ESCL).disable(); field(B_ALLESCL).disable(); get_win_order(); _is_escluso = esclusi; // Fill controllo sheet if (!_is_escluso) import_error_list(); else _controllo_mov = f9_app()._esclusi; _datada = EOTIME; _dataa = 0L; for (auto it = _controllo_mov.begin(); it != _controllo_mov.end(); ++it) { if (*it->get(0) == 'X') { TDate d = it->get(3); if (d < _datada) _datada = d; if (d > _dataa) _dataa = d; } } fill(); } /////////////////////////////////////////////////////////////////////////////// // TApri_estr_msk /////////////////////////////////////////////////////////////////////////////// bool TApri_estr_msk::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) { case DLG_USER: if(e == fe_button) { TSheet_field& sf = sfield(S_INCL); TToken_string& row = sf.row(sf.selected()); TRectype mov(LF_MOV); mov.put(MOV_NUMREG, row.get(sf.cid2index(FI_NUMREG))); open_mov(mov); } break; case B_ISELESCL: if (e == fe_button) inselect_handler(); break; case B_IESCL: if (e == fe_button) inescludi_handler(); break; case B_IALLESCL: if (e == fe_button) inall_handler(); default: break; } return true; } bool TApri_estr_msk::inall_handler() const { TSheet_field& sf = sfield(S_INCL); sf.hide(); const bool active = *sf.row(0).get(cid2index(FI_IESCLUDI)) == 'S'; FOR_EACH_SHEET_ROW(sf, nr, row) row->add(active ? "N" : "S", cid2index(FI_IESCLUDI)); sf.force_update(); sf.show(); return true; } bool TApri_estr_msk::inescludi_handler() const { conferma_esclusi(); return true; } bool TApri_estr_msk::inselect_handler() const { static bool sel_esclusi = false; if (_provv || TF9_app::is_stato_errore(_statoestr)) { sel_esclusi = !sel_esclusi; field(B_IESCL).enable(sel_esclusi); field(B_IALLESCL).enable(sel_esclusi); sfield(S_INCL).enable_column(cid2index(FI_IESCLUDI), sel_esclusi); sfield(S_INCL).force_update(); return true; } warning_box("E' possibile escludere i movimenti solo per pacchetti bloccati\nin stato di errore '" D_WA_ERR " - %s'", TF9_app::traduci_stato(D_WA_ERR)); return false; } void TApri_estr_msk::conferma_esclusi() const { TSheet_field& sf = sfield(S_INCL); sf.hide(); FOR_EACH_SHEET_ROW(sf, nr, row) { TLocalisamfile movs(LF_MOV); movs.put(MOV_NUMREG, row->get_int(cid2index(FI_NUMREG))); movs.read(); if (*row->get(cid2index(FI_IESCLUDI)) == 'S') { const TDate today(TODAY); TToken_string stato("", ';'); stato.add("", 0); stato.add(today.date2ansi()); stato.add("X"); movs.put(MOV_ELABF9, stato); movs.rewrite(); row->add("X", cid2index(FI_IESCLUSO)); } else { if (movs.get(MOV_ELABF9).full()) { movs.put(MOV_ELABF9, ""); row->add("", cid2index(FI_IESCLUSO)); movs.rewrite(); } } } sf.force_update(); sf.show(); } void TApri_estr_msk::fill_estr() const { TString query; query << "SELECT " IVA_SEZIVA ", " IVA_DATADOC ", " IVA_NUMDOC ", " IVA_NPROT "\n" "FROM " F9_IVA "\n" "WHERE " IVA_CODSOC " = '" << F9CONF.get_ambiente() << "' AND " IVA_IDLAN " = '" << _idestr << "'"; // REG + DATAREG + PROTIVA + DATAINC + DATA74TER + NUMREG TString sql; TSQL_recordset rec(""); fp_db().sq_set_exec(query, false); TSheet_field& sf = sfield(S_ESCL); sf.hide(); sf.destroy(); TProgress_monitor prog(fp_db().sq_items(), "Caricamento dati estrazione..."); for (bool ok = fp_db().sq_next(); ok; ok = fp_db().sq_next()) { if (!prog.add_status()) break; sql.cut(0) << "SELECT NUMREG, DATAREG, DATADOC, CODCAUS, TIPODOC, MESELIQ, NUMDOC, TOTDOC, CODCF, REG, PROTIVA, DESCR, ELABF9\n" "FROM MOV\n" "WHERE REG = '" << fp_db().sq_get(IVA_SEZIVA) << "' AND DATADOC='" << TDate(fp_db().sq_get_date(IVA_DATADOC)).date2ansi() << "'" " AND PROTIVA = '" << fp_db().sq_get(IVA_NPROT) << "'"; rec.set(sql); rec.move_first(); TToken_string& r = sf.row(-1); r.add(" ", 0); r.add(rec.get(0).as_string()); // Numreg r.add(rec.get(1).as_string()); // Data reg r.add(rec.get(2).as_string()); // Data doc TString codcaus; codcaus << rec.get(3).as_string(); const int len = codcaus.len(); for (int i = 0; i < 3 - len; ++i) codcaus.add_front("0"); r.add(codcaus); // Cod caus r.add(rec.get(4).as_string()); // Tipo doc r.add(rec.get(5).as_string()); // Mese liq r.add(rec.get(6).as_string()); // Num doc r.add(rec.get(7).as_string()); // Tot doc r.add(rec.get(8).as_string()); // Clifo TLocalisamfile clifo(LF_CLIFO); clifo.put(CLI_CODCF, rec.get(8).as_string()); clifo.put(CLI_TIPOCF, _tipodoc == 'A' ? "F" : "C"); clifo.read(); r.add(clifo.get(CLI_RAGSOC)); // Rag soc r.add(TString(rec.get(9).as_string()) << "/" << rec.get(10).as_string()); // Prot iva r.add(rec.get(11).as_string()); // Descr r.add(""); // Flag escludi r.add(TToken_string(rec.get(12).as_string(), ';').get_bool(2)); // Escluso } sf.force_update(); sf.show(); } void TApri_estr_msk::fill_res() const { TString query; query << "SELECT * FROM " F9_MOVESTR "\n" "WHERE " MES_CODSOC " = '" << F9CONF.get_ambiente() << "' AND " MES_IDESTR " = '" << _idestr << "'"; fp_db().sq_set_exec(query, false); TSheet_field& sf = sfield(S_RES); sf.destroy(); TProgress_monitor prog(fp_db().sq_items(), "Caricamento dati estrazione..."); for (bool ok = fp_db().sq_next(); ok; ok = fp_db().sq_next()) { if (!prog.add_status()) break; TLocalisamfile mov(LF_MOV); mov.put(MOV_NUMREG, fp_db().sq_get(MES_NUMREG)); mov.read(); TToken_string& r = sf.row(-1); r.add(fp_db().sq_get_int(MES_ESTR) ? "X" : " ", 0); // Estratto r.add(mov.get(MOV_NUMREG)); // Numreg r.add(mov.get_date(MOV_DATAREG)); // Data reg r.add(mov.get_date(MOV_DATADOC)); // Data doc r.add(mov.get(MOV_CODCAUS)); // Cod caus r.add(mov.get(MOV_TIPODOC)); // Tipo doc r.add(mov.get_int(MOV_MESELIQ)); // Mese liq r.add(mov.get(MOV_NUMDOC)); // Num doc r.add(mov.get_real(MOV_TOTDOC)); // Tot doc r.add(mov.get_int(MOV_CODCF)); // Clifo TLocalisamfile clifo(LF_CLIFO); clifo.put(CLI_CODCF, mov.get(MOV_CODCF)); clifo.put(CLI_TIPOCF, mov.get(MOV_TIPO)); clifo.read(); r.add(clifo.get(CLI_RAGSOC)); // Rag soc r.add(TString(mov.get(MOV_REG)) << "/" << mov.get(MOV_PROTIVA)); // Prot iva r.add(mov.get(MOV_DESCR)); // Descr r.add(fp_db().sq_get(MES_ERR)); // Descrizione errore } } void TApri_estr_msk::set_from_row_estrazione(TToken_string& row_estrazione) { set(F_IIDESTR, _idestr.cut(0) << row_estrazione.get(cid2index(F_IDESTR))); set(F_IDATA, _dataestr = row_estrazione.get(cid2index(F_DATAESTR))); set(F_IPROV, _provv = *row_estrazione.get(cid2index(F_PROV_B)) == 'X'); set(F_ITIPOD, (_tipodoc = *row_estrazione.get(cid2index(F_TIPODOC))) == 'V' ? "Vendite" : "Acquisti"); (_statoestr.cut(0) << row_estrazione.get(cid2index(F_STATESTR))).cut(2); set(F_ISTATOESTR, TString(_statoestr) << " - " << TF9_app::traduci_stato(_statoestr)); set(F_IDAL, _datadal = row_estrazione.get(cid2index(F_DATADAL))); set(F_IAL, _dataal = row_estrazione.get(cid2index(F_DATAAL))); } TApri_estr_msk::TApri_estr_msk() : TAutomask("f90100d.msk"), _provv(true), _tipodoc('A') { field(B_IESCL).disable(); field(B_IALLESCL).disable(); } //////////////////////////////////////////////////////// // TF9_app //////////////////////////////////////////////////////// const char* TF9_app::traduci_stato(const TString& cod) { static TString stato; static TString last_cod; if (last_cod != cod) { last_cod = cod; stato.cut(0); if (cod == "01") stato << "in diagnostica"; else if (cod == "02") stato << "errore diagnostica gestionale"; else if (cod == "03") stato << "diagnostica gestionale passata"; else if (cod == "04") stato << "controllo WebApp"; else if (cod == "05") stato << "errore diagnostica WebApp"; else if (cod == "06") stato << "diagnostica WebApp passata"; else if (cod == "07") stato << "in elaborazione da sostitutiva"; else if (cod == "08") stato << "errore diagnostica da sostitutiva"; else if (cod == "09") stato << "Archiviato"; } return (const char*)stato; } bool TF9_app::is_stato_errore(const TString& stato_etr) { return stato_etr == D_GEST_ERR || stato_etr == D_WA_ERR || stato_etr == D_ERR_SOS; } void TF9_app::notify_estraction() const { _msk->fill(); } // Estrazione esclusi bool TF9_app::select_escl_notify(TSheet_field& s, int row, KEY key) { TMask_field& field = s; const TMask& mask = field.mask(); TSheet_field& sf = mask.sfield(S_ESCL); sf.hide(); FOR_EACH_SHEET_ROW(sf, nr, riga) { if (*riga->get(0) == 'X') riga->add("", 0); } sf.force_update(); sf.show(); return true; } bool TF9_app::controllo_escl_handler(TMask_field& field, KEY key) { TF9_app& app = f9_app(); TControllo_mask controllo(F9CONF.get_ambiente(), app._estr_escluso->get_id_estr(), true); controllo.run(); return true; } bool TF9_app::year_handler(TMask_field& field, KEY key) { if (key == K_TAB) { const int year = real(field.get()).integer(); if (year <= 2001 || year >= 2100) { error_box("Anno non corretto"); field.mask().set(501, today.year()); } } return true; } void TF9_app::add_msg_log(const char* msg) { _log << msg << "\n\n"; } void TF9_app::add_sqlerror_msg_log(const char* query) { TString msg; msg << query << "\n" << fp_db().sq_get_string_error() << "\n" << fp_db().sq_get_text_error(); add_msg_log(msg); } void TF9_app::open_esclusi() { /* Prima chiedo quale mese e anno visualizzare */ // FINESTRA static TMask* ym_msk = nullptr; if (ym_msk == nullptr) { ym_msk = new TMask("Mostra esclusi", 1, 25, 16); ym_msk->add_button_tool(DLG_OK, "Conferma", TOOL_OK); ym_msk->add_button_tool(DLG_NULL, "", 0); ym_msk->add_button_tool(DLG_QUIT, "Esci", TOOL_QUIT); ym_msk->add_groupbox(507, 0, "Movimenti da visualizzare:", 0, 0, 25, 6); ym_msk->add_number(501, 0, "Anno", 1, 1, 4); ym_msk->add_list(502, 0, "Mese", 1, 2, 8, "", "01|02|03|04|05|06|07|08|09|10|11|12", "Gennaio|Febbraio|Marzo|Aprile|Maggio|Giugno|Luglio|Agosto|Settembre|Ottobre|Novembre|Dicembre"); ym_msk->add_list(503, 0, "Fino al", 1, 3, 9, "", " |01|02|03|04|05|06|07|08|09|10|11|12", " |Gennaio|Febbraio|Marzo|Aprile|Maggio|Giugno|Luglio|Agosto|Settembre|Ottobre|Novembre|Dicembre"); ym_msk->add_groupbox(506, 0, "Selezionare il tipo di estrazione", 0, 6, 25); ym_msk->add_list(504, 0, "Flag Provvisorio", 1, 7, 1, "", "P|D", "Provvisorio|Definitivo"); ym_msk->add_list(505, 0, "Tipo doc.", 1, 4, 1, "", "A|V", "Acquisti|Vendite"); ym_msk->set(501, today.year()); ym_msk->set_handler(501, year_handler); } ym_msk->run(); if (ym_msk->last_key() == K_QUIT) return; _flagprov_escl = ym_msk->get(504)[0]; _tipodoc_escl = ym_msk->get(505)[0]; /* Caricamento esclusi * LOADING DI QUEL MESE E ANNO */ f9_app()._esclusi_vect.clear(); const int anno = ym_msk->get_int(501); const int mese = ym_msk->get_int(502); const int to_m = ym_msk->get_int(503); TLocalisamfile movs(LF_MOV); movs.setkey(2); const TDate from(1, mese, anno); TDate to(from); if (to_m != 0) to.set_month(to_m); to.set_end_month(); movs.put(MOV_DATAREG, from); movs.read(); if (movs.get_date(MOV_DATAREG) >= from && movs.get_date(MOV_DATAREG) <= to) { for (bool ok = true; ok && movs.get_date(MOV_DATAREG) <= to; ok = movs.next() == NOERR) { TToken_string stato(movs.get(MOV_ELABF9), ';'); if (stato.items() == 3 && stato.get(2)[0] == 'X') { TToken_string m("", '|'); m.add("", 0); m.add(movs.get_int(MOV_NUMREG)); m.add(movs.get_date(MOV_DATAREG)); m.add(movs.get_date(MOV_DATADOC)); m.add(movs.get(MOV_CODCAUS)); m.add(movs.get(MOV_MESELIQ)); TString numdoc; numdoc << movs.get(MOV_NUMDOCEXT); m.add(numdoc.full() ? numdoc : movs.get(MOV_NUMDOC)); const real imptot = movs.get_real(MOV_TOTDOC) + movs.get_real(MOV_RITFIS) + movs.get_real(MOV_RITSOC); m.add(imptot); m.add(movs.get_int(MOV_CODCF)); TLocalisamfile clifo(LF_CLIFO); clifo.put(CLI_TIPOCF, movs.get(MOV_TIPO)); clifo.put(CLI_CODCF, movs.get(MOV_CODCF)); m.add(clifo.read() == NOERR ? clifo.get(CLI_RAGSOC) : ""); m.add(TString(movs.get(MOV_REG)) << "/" << movs.get(MOV_PROTIVA)); m.add(movs.get(MOV_DESCR)); f9_app()._esclusi_vect.insert(f9_app()._esclusi_vect.end(), m); } } } if (f9_app()._esclusi_vect.empty()) { warning_box("Non ci sono movimenti esclusi da mostrare"); return; } // Esclusi mask //////////////////////////////// fill_esclusi(); while (esclusi_mask().run() == K_ENTER) { } } void TF9_app::fill_esclusi() { vector& esclusi = f9_app()._esclusi_vect; TSheet_field& sf = esclusi_mask().sfield(S_ESCL); sf.hide(); sf.destroy(); for (auto it = esclusi.begin(); it != esclusi.end(); ++it) sf.row(-1) = *it; sf.force_update(); sf.show(); } movimento_t TF9_app::escl2mov(TToken_string* row) { movimento_t t; t.err = false; t.numreg = row->get_int(1); t.datareg = row->get(2); t.datadoc = row->get(3); t.codcaus = row->get(4); t.meseliq = row->get_int(5); t.numdoc = row->get(6); t.tot = row->get(7); t.codcf = row->get_int(8); t.ragsoc = row->get_int(9); t.reg_protiva = row->get(10); t.descr = row->get(11); t.state = null_state; t.descr_err = ""; // todo: controllo attributi aggiunti. t.estratto = true; t.descr_estr = movimento_t::no_err; return t; } bool TF9_app::estrai_escl_handler(TMask_field&, KEY key) { TMask& msk = esclusi_mask(); TF9_app& a = f9_app(); vector& _esclusi = a._esclusi_vect; TSheet_field& sf = msk.sfield(S_ESCL); descr_msk().run(); const TString descr = descr_msk().get(DES_TEXT); descr_msk().set(DES_TEXT, ""); TFilename path; f9_app().get_spotlite_path(path); a._estr_escluso = new TEstrazione(F9CONF.get_ambiente(), a._flagprov_escl, a._tipodoc_escl, descr, F9CONF.get_addr_doc(), true, path); // Prendo la riga selezionata (e controllo che sia selezionato qualcosa) bool flag = false; FOR_EACH_SHEET_ROW(sf, nr, row) { if (row->get(0)[0] == 'X') { const movimento_t mov = escl2mov(row); a._estr_escluso->add_mov(mov); _stats = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; const int stato = a._estr_escluso->estrai(); if (stato == 1) { _esclusi.erase(_esclusi.begin() + nr); // Tolto il movimento estratto dal vettore e setto come estratto su elabf9 di mov a.segna_estratti(true, mov.numreg); } flag = true; break; } } if (!flag) message_box("Selezionare il movimento da estrarre"); else a.print_log(); fill_esclusi(); return true; } bool TF9_app::mov_handler_escl(TMask_field& f, KEY key) { TSheet_field& sf = esclusi_mask().sfield(S_ESCL); TToken_string& row = sf.row(sf.selected()); TRectype mov(LF_MOV); mov.put(MOV_NUMREG, row.get(sf.cid2index(FE_NUMREG))); return open_mov(mov); } void TF9_app::edit_wa(TString& old_codsoc) const { TString query; if (!old_codsoc.empty()) { query << "DELETE FROM " F9_WA " WHERE " WA_CODSOC " = '" << old_codsoc << "';\n"; fp_db().sq_set_exec(query) && fp_db().sq_commit(); } query.cut(0) << "INSERT INTO " F9_WA " (" WA_CODSOC ", " WA_ADDR_DOC ") VALUES ('" << F9CONF.get_ambiente() << "', '" << F9CONF.get_addr_doc() << "');"; fp_db().sq_set_exec(query) && fp_db().sq_commit(); } void TF9_app::print_log() { ofstream fout; fout.open("f9exp_err.txt"); fout << _log; _log.cut(0); } bool TF9_app::is_autofattura(const TLocalisamfile& mov) { return TCausale(mov.get(MOV_CODCAUS), mov.get_date(MOV_DATAREG).year()).tipo_doc() == "AF"; } bool TF9_app::segna_estratti(const bool escluso, const int numreg) { bool ok = true; vector escl; if (escluso) { TLocalisamfile mov(LF_MOV); mov.put(MOV_NUMREG, numreg); mov.read(); TLocalisamfile clifo(LF_CLIFO); clifo.put(CLI_TIPOCF, mov.get(MOV_TIPO)); clifo.read(); const movimento_t m{ false, numreg, mov.get_date(MOV_DATAREG), mov.get_date(MOV_DATADOC), mov.get(MOV_CODCAUS), mov.get_int(MOV_MESELIQ), !mov.get(MOV_NUMDOCEXT).empty() ? mov.get(MOV_NUMDOCEXT) : mov.get(MOV_NUMDOC), mov.get_real(MOV_TOTDOC), mov.get_int(MOV_CODCF), clifo.get(CLI_RAGSOC), mov.get(MOV_REG), mov.get(MOV_DESCR) }; escl.insert(escl.begin(), m); // todo: datareg? } vector& movs_v = escluso ? escl : _movs; TLocalisamfile mov(LF_MOV); TToken_string elab("", ';'); elab.add("X", 0); elab.add(today.date2ansi()); elab.add(" "); // "[flag estratto];[data estrazione];[flag escluso]" for (auto it = movs_v.begin(); it != movs_v.end(); ++it) { TString8 num_reg; num_reg << it->numreg; mov.zero(); mov.put(MOV_NUMREG, num_reg); mov.read(); mov.put(MOV_ELABF9, elab); ok &= mov.rewrite() == NOERR; } return ok; } bool TF9_app::create_tables() const { bool ok = aggiorna_tab_f9(100); TLocalisamfile tabmod(LF_TABMOD); tabmod.put("MOD", "F9"); tabmod.put("COD", "SQL"); tabmod.put("CODTAB", "VERSION"); char ver[5] = "0000"; sprintf_s(ver, 5, "%04d", 100); tabmod.put(TABMOD_TABVER, ver); tabmod.write(); ok &= tabmod.rewrite() == NOERR; return ok; } bool TF9_app::check_tabelle_f9() const { bool ok = true; TString query; query << "IF (EXISTS (\n" << "SELECT * FROM INFORMATION_SCHEMA.TABLES\n" << "WHERE TABLE_NAME = '" F9_DRD "'))\n" << "SELECT 1 AS EXIST ELSE SELECT 0 AS EXIST"; fp_db().sq_set_exec(query); if (fp_db().sq_get("EXIST") != "1") // Se non esiste la tabella la creo ok &= create_tables(); return ok; } bool TF9_app::aggiorna_tab_f9(int version) const { bool ok = true; TString file; string sql; char ver[5] = "0000"; sprintf_s(ver, 5, "%04d", version); TString name; name << "f9" << ver << ".sql"; file << "sql\\f90\\" << name; std::ifstream fin; fin.open(file); if (ok &= fin.is_open()) { while (!fin.eof() && ok) { std::string appo_line; std::getline(fin, appo_line); if (appo_line[0] == '-' && appo_line[1] == '-') // Se è una riga di commento la salto continue; sql += "\n" + appo_line; const int end = sql.find(';'); // Se trovo un comma lancio la query if (end != int(std::string::npos)) { TString query; query << sql.c_str(); ok &= fp_db().sq_set_exec(query, false); ok &= fp_db().sq_commit(); sql.erase(); } } } else { TString msg; msg << "Impossibile trovare il file di aggiornamento tabelle: " << file; error_box(msg); } return ok; } bool TF9_app::check_tab_version() const { bool ok = true; TLocalisamfile tabmod(LF_TABMOD); tabmod.put("MOD", "F9"); tabmod.put("COD", "SQL"); tabmod.put("CODTAB", "VERSION"); const bool exists = tabmod.read() == NOERR; int version = exists ? real(tabmod.get(TABMOD_TABVER)).integer() : TAB_BASE_VERSION - 2; if (version < SQL_VERSION) // Controllo la versione { for (; version < SQL_VERSION; version += 2) // Effettuo le modifiche per ogni avanzamento di versione { if (ok &= aggiorna_tab_f9(version + 2)) { char ver[5] = "0000"; sprintf_s(ver, 5, "%04d", version + 2); tabmod.put(TABMOD_TABVER, ver); // Avanzo il contatore della versione in TABMOD if (!exists) { tabmod.zero(); tabmod.put("MOD", "F9"); tabmod.put("COD", "SQL"); tabmod.put("CODTAB", "VERSION"); tabmod.put(TABMOD_TABVER, ver); // Avanzo il contatore della versione in TABMOD tabmod.write(); } tabmod.rewrite(); } else break; } } return ok; } bool TF9_app::check_table() const { if (!check_tab_version()) { TString msg; std::ofstream fout; fout.open("f9checktaberr.txt"); fout << fp_db().sq_get_text_error(false) << std::endl; fout.close(); msg << "! Errore controllo database F9: creazione/aggiornamento tabelle.\n" << fp_db().sq_get_text_error() << "\n" << fp_db().sq_get_string_error(); fatal_box(msg); return false; } return true; } #ifdef DBG void pulisci_mov() { TLocalisamfile mov(LF_MOV); mov.setkey(2); mov.put(MOV_DATAREG, TDate("01-01-2002")); mov.read(); do { mov.put(MOV_ELABF9, ""); mov.write(); mov.rewrite(); } while (mov.next() == NOERR); } #endif void TF9_app::main_loop() { if (!check_table()) fatal_box("Controllo tabelle modulo fallito."); #ifdef DBG //pulisci_mov(); #endif _msk = make_unique(); _estr_msk = make_unique(); while (_msk->run() != K_QUIT) { } /*delete _msk; delete _estr_msk;*/ } TF9_app::TF9_app() : _estr_msk(nullptr), _msk(nullptr), _mov_escl("", '|'), _tipodoc_escl('A'), _flagprov_escl('P'), _estr_escluso(nullptr) { } int f90100(const int argc, char* argv[]) { TF9_app app; app.run(argc, argv, TR("Archiviazione Sostitutiva")); return 0; }