diff --git a/src/f9/f90.cpp b/src/f9/f90.cpp index b5b912fe0..6c6695de9 100644 --- a/src/f9/f90.cpp +++ b/src/f9/f90.cpp @@ -8,7 +8,9 @@ int main(int argc, char** argv) switch (r) { - default: rt = f90100(argc, argv); break; + default: + case 0: rt = f90100(argc, argv); break; // Programma estrazione pacchetti + case 1: rt = f90200(argc, argv); break; // Tabella categorie documentali } return rt; } diff --git a/src/f9/f90.h b/src/f9/f90.h index cf7bc4c26..7ee732388 100644 --- a/src/f9/f90.h +++ b/src/f9/f90.h @@ -2,5 +2,6 @@ #define __F90_H int f90100(int argc, char* argv[]); +int f90200(int argc, char* argv[]); #endif diff --git a/src/f9/f90100.cpp b/src/f9/f90100.cpp index 83d9273dc..60971ce06 100644 --- a/src/f9/f90100.cpp +++ b/src/f9/f90100.cpp @@ -1,8 +1,5 @@ -#include -#include "applicat.h" #include "lffiles.h" #include "isam.h" -#include "mov.h" #include "../f1/f1lib.h" #include "../fp/fplib.h" #include "urldefid.h" @@ -10,7 +7,6 @@ #include "f90100.h" #include "f901tab.h" #include "f90100b.h" -#include "f90100c.h" #include "f90100d.h" #include "sqlset.h" @@ -26,30 +22,26 @@ #define TAB_BASE_VERSION 100 // Versione base delle tabelle #define SQL_VERSION 102 // Utilizzo questo per controllare la versione attuale delle tabelle e nel caso aggiornarle -SSimple_query& db() -{ - static SSimple_query* db = nullptr; - if (db == nullptr) - { - db = new SSimple_query(); - set_connection(*db); - } - return *db; -} + +TMask& descr_msk(); + +// Doppio puntatore perche' cosi' sono sicuro di puntare alla stessa cosa che sta puntando la variabile +// statica all'interno di questa funzione. +// Vale anche per la inclusi_mask() TMask** esclusi_mask() { static TMask* _esclusi_mask = nullptr; - if(_esclusi_mask == nullptr) + if (_esclusi_mask == nullptr) { _esclusi_mask = new TMask("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 + 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 + sheet_m.set_handler(DLG_USER, TF9_app::mov_handler_escl); // Bottone collega movimento m.field(DLG_FINDREC).disable(); } @@ -59,7 +51,7 @@ TMask** esclusi_mask() TMask** inclusi_mask() { static TMask* _inclusi_mask = nullptr; - if(_inclusi_mask == nullptr) + if (_inclusi_mask == nullptr) { _inclusi_mask = new TMask("f90100d.msk"); TMask& m = *_inclusi_mask; @@ -71,13 +63,7 @@ TMask** inclusi_mask() return &_inclusi_mask; } -const char* check_str(const TString& str) -{ - static TString n_str; n_str.cut(0) << str; - n_str.replace("'", "\'\'"); - n_str.replace(" ", " "); - return (const char*)n_str; -} + //////////////////////////////////////////////////////// @@ -86,84 +72,89 @@ const char* check_str(const TString& str) TEstrai_mask::TEstrai_mask() : TMask("Estrazione", 1, 60, 16) { - add_button_tool(DLG_ELABORA, "Estrai", TOOL_ELABORA); - add_button_tool(DLG_NULL, "", 0); - add_button_tool(DLG_QUIT, "Esci", TOOL_QUIT); + 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_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); + 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); + TDate dt(TODAY); dt.set_day(1); dt.set_month(1); + set(ES_DATAINI, dt); + set(ES_DATAEND, today); } bool TEstrai_mask::estrai_handler(TMask_field& f, KEY key) { - auto& msk = (TEstrai_mask&)f.mask(); // this estrai_mask - const int stato = app().estrai(); + TEstrai_mask& msk = (TEstrai_mask&)f.mask(); // this estrai_mask + TF9_app& a = f9_app(); + + // Estraggo + const int stato = a.estrai(); // Main function + + // Gestione risultato estrazione if (stato == 1) { message_box("Estrazione avvenuta con successo!"); - app().segna_estratti(); + a.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 ... - app().segna_in_errore(); // ...in testata se l'errore e' in scrittura dell'F9DRD + if (stato == 0) // Errore scrittura F9IVA, non segno in errore in testata... + a.segna_in_errore(); // ... se l'errore e' dovuto alla scrittura sul db } - app().print_log(); + a.print_log(); msk.field(ES_DESCR).set(""); msk.stop_run(K_FORCE_CLOSE); - return true; + return true; } void TEstrai_mask::enable_fields(bool en) { - enable(ES_DATAINI, en); - enable(ES_DATAEND, en); - enable(ES_FLAGPROV, en); - enable(ES_TIPODOC, 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; + ((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; + 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; + 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; } @@ -173,18 +164,22 @@ bool TEstrai_mask::dataend_handler(TMask_field& f, KEY key) bool TMonitor_mask::save_conf_handler(TMask_field& f, KEY key) { - TMask& m = f.mask(); - TF9_app& a = app(); - a.set_ambiente(m.get(CF_CODSOC)); - a.set_addr_doc(m.get(CF_ADDRDOC)); - - if(a.get_ambiente().full()) - ini_set_string(CONFIG_DITTA, "F9", AMBIENTE_F9, a.get_ambiente()); - if(a.get_addr_doc().full()) - ini_set_string(CONFIG_DITTA, "F9", ADDRCART_F9, a.get_addr_doc()); - m.close(); - a.edit_wa(); - return true; + TMask& config_mask = f.mask(); + TF9_app& a = f9_app(); + a.set_ambiente (config_mask.get(CF_CODSOC)); + a.set_addr_doc (config_mask.get(CF_ADDRDOC)); + a.set_has_vendext (config_mask.get_bool(CF_VENDEXT)); + a.set_viewmov (config_mask.get_bool(CF_VIEWMOVPRE)); + + if (a.get_ambiente().full()) + ini_set_string(CONFIG_DITTA, "F9", AMBIENTE_F9, a.get_ambiente()); + if (a.get_addr_doc().full()) + ini_set_string(CONFIG_DITTA, "F9", ADDRCART_F9, a.get_addr_doc()); + ini_set_bool(CONFIG_DITTA, PAR_MOD, VENDEXT_F9, a.get_has_vendext()); + ini_set_bool(CONFIG_DITTA, PAR_MOD, VIEWMOV_F9, a.get_viewmov()); + config_mask.close(); + a.edit_wa(); + return true; } void TMonitor_mask::controllo_errori() const @@ -212,75 +207,80 @@ void TMonitor_mask::controllo_errori() const bool TMonitor_mask::on_key(const KEY key) { - return true; + return TAutomask::on_key(key); } void TMonitor_mask::open_win_estr() { - if (!app().get_ambiente().full()) - warning_box("Inserire codice ambiente societa' in configurazione"); - else app().run_estr_msk(); + if (!f9_app().get_ambiente().full()) + warning_box("Inserire codice ambiente societa' in configurazione"); + else f9_app().run_estr_msk(); } void TMonitor_mask::open_win_conf() const { - static TMask* m = nullptr; + static TMask* m = nullptr; - if (m == nullptr) - { - m = new TMask("Configurazione Archiviazione Sostitutiva", 1, 60, 10); + if (m == nullptr) + { + m = new TMask("Configurazione Archiviazione Sostitutiva", 1, 60, 18); - 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_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, 59, 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, 59, 3, ""); - m->add_string(CF_ADDRDOC, 0, "Percorso", 2, 4, 256, "", 40); + m->add_groupbox(CF_CODGROUP, 0, "Codice Ambiente Societa' (WEBAPP):", 1, 0, 59, 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, 59, 3, ""); + m->add_string(CF_ADDRDOC, 0, "Percorso", 2, 4, 256, "", 40); + m->add_groupbox(CF_ESTRGROUP, 0, "Opzioni estrazione", 1, 6, 59, 4, ""); + m->add_boolean(CF_VENDEXT, 0, "Disabilita controllo documenti vendita (no fatturazione vendite)", 2, 7); + m->add_boolean(CF_VIEWMOVPRE, 0, "Visualizza movimenti preparati prima di lanciare l'estrazione", 2, 8); - m->set_handler(DLG_OK, save_conf_handler); + m->set_handler(DLG_OK, save_conf_handler); - m->set(CF_CODSOC, ini_get_string(CONFIG_DITTA, PAR_MOD, AMBIENTE_F9)); - m->set(CF_ADDRDOC, ini_get_string(CONFIG_DITTA, PAR_MOD, ADDRCART_F9)); - } - m->run(); + m->set(CF_CODSOC, ini_get_string(CONFIG_DITTA, PAR_MOD, AMBIENTE_F9)); + m->set(CF_ADDRDOC, ini_get_string(CONFIG_DITTA, PAR_MOD, ADDRCART_F9)); + m->set(CF_VENDEXT, ini_get_bool(CONFIG_DITTA, PAR_MOD, VENDEXT_F9)); + m->set(CF_VIEWMOVPRE, ini_get_bool(CONFIG_DITTA, PAR_MOD, VIEWMOV_F9)); + } + m->run(); } void TMonitor_mask::fill() const { - app()._ambiente = ini_get_string(CONFIG_DITTA, PAR_MOD, AMBIENTE_F9); - app()._addr_doc = ini_get_string(CONFIG_DITTA, PAR_MOD, ADDRCART_F9); + f9_app()._config.ambiente = ini_get_string(CONFIG_DITTA, PAR_MOD, AMBIENTE_F9); + f9_app()._config.addr_doc = ini_get_string(CONFIG_DITTA, PAR_MOD, ADDRCART_F9); TString query; query << "SELECT * FROM F9DRD00K ORDER BY " << DRD_TIME << " DESC;"; - db().sq_set_exec(query, false); + fp_db().sq_set_exec(query, false); TSheet_field& sf = sfield(S_ELAB); sf.hide(); sf.destroy(); int i = 0; - for (bool ok = db().sq_next(); ok; ok = db().sq_next()) + 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(db().sq_get(DRD_STATO) == "09" ? "X" : ""); - row.add(db().sq_get(DRD_ID_EST)); - row.add(db().sq_get_date(DRD_TIME)); - row.add(db().sq_get(DRD_FLAG_PD) == "P" ? "X" : ""); + 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 << db().sq_get(DRD_TIPODOC); + 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(db().sq_get_date(DRD_DATADA)); - row.add(db().sq_get_date(DRD_DATAA)); - row.add(db().sq_get(DRD_UTENTE)); - row.add(db().sq_get(DRD_STATO) << " - " << TF9_app::traduci_stato(db().sq_get(DRD_STATO))); - row.add(db().sq_get(DRD_DESC)); + 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(); @@ -292,7 +292,7 @@ void TMonitor_mask::delete_pack(const bool all) const TSheet_field& sf = sfield(S_ELAB); FOR_EACH_SHEET_ROW(sf, nr, row) { - if(row->get(0)[0] == 'X' || all) + if (row->get(0)[0] == 'X' || all) { flag = true; const TString id_estr(row->get(cid2index(F_IDESTR))); @@ -309,7 +309,7 @@ void TMonitor_mask::delete_pack(const bool all) const " SELECT @stato AS STATO;\n" " END\n" "END"; - db().sq_set_exec(query); + 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" @@ -322,8 +322,8 @@ void TMonitor_mask::delete_pack(const bool all) const " END\n" " SELECT @flag_prov AS FLAG, @stato AS STATO;\n" "END"; - db().sq_set_exec(query); - if(db().sq_get("FLAG") != "P" && db().sq_get("STATO") != "02" && !all) + fp_db().sq_set_exec(query); + if (fp_db().sq_get("FLAG") != "P" && fp_db().sq_get("STATO") != "02" && !all) { warning_box("E' possibile eliminare solo un'estrazione provvisoria o in stato di errore diagnostica gestionale."); return; @@ -332,9 +332,9 @@ void TMonitor_mask::delete_pack(const bool all) const break; } } - if(!flag) + if (!flag) { - if(noyes_box("Eliminare tutti i pacchetti provvisori o in stato di errore gestionale?")) + if (noyes_box("Eliminare tutti i pacchetti provvisori o in stato di errore gestionale?")) delete_pack(true); } fill(); @@ -353,7 +353,7 @@ void TMonitor_mask::sel() const sf.show(); } -void TMonitor_mask::open_mostra_estrazione() +void TMonitor_mask::open_mostra_estrazione() const { TMask& msk = **inclusi_mask(); //fill @@ -365,12 +365,18 @@ void TMonitor_mask::open_mostra_estrazione() { 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 = row; id = row->get(cid2index(F_IDESTR)); break; } } - if(_row == nullptr) + if (_row == nullptr) { message_box("Selezionare un pacchetto."); return; @@ -387,154 +393,77 @@ void TMonitor_mask::open_mostra_estrazione() "FROM " F9_IVA "\n" "WHERE " IVA_IDLAN " = '" << id << "'"; - //REG + DATAREG + PROTIVA + DATAINC + DATA74TER + NUMREG + // REG + DATAREG + PROTIVA + DATAINC + DATA74TER + NUMREG TString sql; TSQL_recordset rec(""); - db().sq_set_exec(query, false); - - for (bool ok = db().sq_next(); ok; ok = db().sq_next()) + fp_db().sq_set_exec(query, false); + + for (bool ok = fp_db().sq_next(); ok; ok = fp_db().sq_next()) { - sql.cut(0) << "SELECT NUMREG, DATAREG, DATADOC, CODCAUS, TIPODOC, MESELIQ, NUMDOC, TOTDOC, CODCF, REG, PROTIVA, DESCR " - "FROM MOV " - "WHERE REG = '" << db().sq_get(IVA_SEZIVA) << "' AND DATADOC=" << TDate(db().sq_get_date(IVA_DATADOC)).date2ansi() << - " AND PROTIVA = " << db().sq_get(IVA_NPROT); + sql.cut(0) << "SELECT NUMREG, DATAREG, DATADOC, CODCAUS, TIPODOC, MESELIQ, NUMDOC, TOTDOC, CODCF, REG, PROTIVA, DESCR\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& row = sf.row(-1); - row.add(" ", 0); - row.add(rec.get(rec.find_column(MOV_NUMREG)).as_string()); - row.add(rec.get(1).as_string()); - row.add(rec.get(2).as_string()); - row.add(rec.get(3).as_string()); - row.add(rec.get(4).as_string()); - row.add(rec.get(5).as_string()); - row.add(rec.get(6).as_string()); - row.add(rec.get(7).as_string()); - row.add(rec.get(8).as_string()); + TToken_string& r = sf.row(-1); + r.add(" ", 0); + r.add(rec.get(rec.find_column(MOV_NUMREG)).as_string()); + r.add(rec.get(1).as_string()); + r.add(rec.get(2).as_string()); + r.add(rec.get(3).as_string()); + r.add(rec.get(4).as_string()); + r.add(rec.get(5).as_string()); + r.add(rec.get(6).as_string()); + r.add(rec.get(7).as_string()); + r.add(rec.get(8).as_string()); // Siamo sicuri? TLocalisamfile clifo(LF_CLIFO); clifo.put(CLI_CODCF, rec.get(7).as_string()); clifo.put(CLI_TIPOCF, _row->get(cid2index(F_TIPODOC))[0] == 'A' ? "F" : "C"); clifo.read(); - row.add(clifo.get(CLI_RAGSOC)); - row.add(TString(rec.get(8).as_string()) << "/" << rec.get(9).as_string()); - row.add(rec.get(10).as_string()); + r.add(clifo.get(CLI_RAGSOC)); + r.add(TString(rec.get(8).as_string()) << "/" << rec.get(9).as_string()); + r.add(rec.get(10).as_string()); } msk.run(); } bool TMonitor_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { - switch (o.dlg()) - { - case DLG_DELREC: + 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_ELABORA: - if (e == fe_button) - { - enable_page(1, false); - open_win_estr(); - } - break; - case DLG_CONFIG: - if (e == fe_button) - open_win_conf(); - break; - case DLG_FINDREC: - if (e == fe_button) - controllo_errori(); - break; + 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_mostra_estrazione(); break; - case B_SHOWESCL: - if(e == fe_button) - { - app().open_esclusi(); - } - break; + case B_SHOWESCL: + if (e == fe_button) + f9_app().open_esclusi(); + break; case F_SEL: - if(e == fe_modify) - { + if (e == fe_modify) sel(); - } - default: break; - } - return true; -} - - -////////////////////////////////////////////////////// -// TF9_dberr -////////////////////////////////////////////////////// - -void TF9_dberr::add_str(const TString& string) -{ - _insert.rtrim(1); - if (_insert[_insert.len() - 1] != '(') - _insert << ", "; - _insert << string << ")"; -} - -void TF9_dberr::add(const TString& string) -{ - TString str; - add_str(str << "'" << string << "'"); -} - -void TF9_dberr::add(const long num) -{ - TString app; - app << num; - add(app); -} - -bool TF9_dberr::send() -{ - bool ok = db().sq_set_exec(_insert); - app().add_sqlerror_msg_log(_insert); - _insert.cut(0) << "INSERT INTO " F9_ERR " VALUES ()"; - return ok; -} - -void TF9_dberr::del_err(const TString& id_estr, int numreg) -{ - TString query; - query << "DELETE FROM " F9_ERR " WHERE IDESTR = '" << id_estr << "' AND NUMREG = '" << numreg << "';"; - db().sq_set_exec(query); -} - -char TF9_dberr::get_errori(const TString& id_estr, vector& movs) -{ - TString query; - query << "SELECT * FROM " F9_ERR " WHERE IDESTR = '" << id_estr << "';"; - db().sq_set_exec(query, false); - for (bool ok = db().sq_next(); ok; ok = db().sq_next()) - { - TToken_string row("", '|'); - row.add("X", 0); - for (int i = 1; i < 15; i++) - { - if (db().sq_get_type_field(i) == _datefld) - row.add(db().sq_get_date(db().sq_get_name_field(i))); - else - row.add(db().sq_get(i)); - } - movs.insert(movs.end(), row); + default: break; } - query.cut(0) << "SELECT " DRD_TIPODOC " FROM " F9_DRD "\n" << - "WHERE " DRD_ID_EST " = '" << id_estr << "'"; - db().sq_set_exec(query); - return db().sq_get((unsigned)0)[0]; -} - -TF9_dberr::TF9_dberr() -{ - _insert.cut(0) << "INSERT INTO " F9_ERR " VALUES ()"; + return true; } @@ -562,7 +491,7 @@ bool TF9_app::select_escl_notify(TSheet_field& s, int row, KEY key) bool TF9_app::controllo_escl_handler(TMask_field& field, KEY key) { - TControllo_mask controllo(app()._head.id_estr, true); + TControllo_mask controllo(f9_app()._estr_escluso->get_id_estr(), true); controllo.run(); return true; } @@ -581,54 +510,6 @@ bool TF9_app::year_handler(TMask_field& field, KEY key) return true; } -int TF9_app::estrai_single(TToken_string& row, char flagprov, char tipodoc) -{ - const int numreg = row.get_int(cid2index(F_NUMREG)); - const char tipo = flagprov; - TLocalisamfile mov(LF_MOV); - mov.put(MOV_NUMREG, numreg); - mov.read(); - _head.flag_prov = flagprov == 'P'; - _head.dal = mov.get(MOV_DATAREG); - _head.al = _head.dal; - _head.tipo_doc = tipodoc; - - _head.cod_soc = _ambiente; - // X indica che e' un'estrazione di un escluso - _head.id_estr.cut(0) << today.date2ansi() << _estr_msk->get(ES_FLAGPROV) << "X" << next_estr_today(tipo); - descr_msk().run(); - _head.descr = descr_msk().get(DES_TEXT); - descr_msk().set(DES_TEXT, ""); - _head.user = user(); - _head.addr_cart = _addr_doc; - - TString err; - _head.stato_estr = prepara_movimenti_escl(get_tipoiva(), numreg, err); - const bool ok = esporta(); // La testata la scrivo sempre. L'iva solo se diagnostica passata. - - if (!ok) - { - TString msg; - msg << "Errore database: impossibile scrivere nuova estrazione.\n" - << db().sq_get_text_error(false); - error_box(msg); - add_sqlerror_msg_log(""); - return -99; - } - else - { - _esclusi.clear(); - _esclusi.insert(_esclusi.end(), row); - if (_head.stato_estr == D_GEST_ERR) - { - warning_box("Attenzione l'estrazione ha prodotto degli errori. \nControllare e correggere eventuali problemi \npremendo il pulsante 'Controllo Estr.'"); - return -2; - } - else - return estrazione_iva(true) ? 1 : 0; - } -} - void TF9_app::add_msg_log(const char* msg) { _log << msg << "\n\n"; @@ -638,17 +519,17 @@ void TF9_app::add_sqlerror_msg_log(const char* query) { TString msg; msg << query << "\n" << - db().sq_get_string_error() << "\n" << - db().sq_get_text_error(); + 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; + /* 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); @@ -665,75 +546,75 @@ void TF9_app::open_esclusi() ym_msk->set(501, today.year()); ym_msk->set_handler(501, year_handler); } - ym_msk->run(); + 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]; - + _tipodoc_escl = ym_msk->get(505)[0]; + // Caricamento esclusi /* LOADING DI QUEL MESE E ANNO */ - app()._esclusi_vect.clear(); - const int anno = ym_msk->get_int(501); - const int mese = ym_msk->get_int(502); + 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); + 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)); - m.add(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); - TString ragsoc; ragsoc = clifo.get(CLI_RAGSOC); - m.add(ragsoc); - m.add(TString(movs.get(MOV_REG)) << "/" << movs.get(MOV_PROTIVA)); - m.add(movs.get(MOV_DESCR)); - app()._esclusi_vect.insert(app()._esclusi_vect.end(), m); - } - } - } - if(app()._esclusi_vect.empty()) - { - warning_box("Non ci sono movimenti esclusi da mostrare"); - return; - } + 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)); + m.add(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); + TString ragsoc; ragsoc = clifo.get(CLI_RAGSOC); + m.add(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) - { - - } + while ((*esclusi_mask())->run() == K_ENTER) + { + + } } void TF9_app::fill_esclusi() { - vector& esclusi = app()._esclusi_vect; + vector& esclusi = f9_app()._esclusi_vect; TSheet_field& sf = (*esclusi_mask())->sfield(S_ESCL); sf.hide(); sf.destroy(); @@ -743,31 +624,62 @@ void TF9_app::fill_esclusi() sf.show(); } +movimento_t TF9_app::escl2mov(TToken_string* row) +{ + movimento_t t; + t.err = row->get(0)[0] == 'X', + 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 = ""; + return t; +} + bool TF9_app::estrai_escl_handler(TMask_field&, KEY key) { TMask* msk = *esclusi_mask(); - vector& _esclusi = app()._esclusi_vect; + 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, ""); + + a._estr_escluso = + new TEstrazione(a.get_ambiente(), a._flagprov_escl, a._tipodoc_escl, descr, a.get_addr_doc(), true); + // Prendo la riga selezionata (e controllo che sia selezionato qualcosa) bool flag = false; FOR_EACH_SHEET_ROW(sf, nr, row) { - if ((*row)[0] == 'X') + if (row->get(0)[0] == 'X') { - const int stato = app().estrai_single(*row, app()._flagprov_escl, app()._tipodoc_escl); + const auto mov = escl2mov(row); + a._estr_escluso->add_mov(mov); + 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 - app().segna_estratti(true, row->get_int(cid2index(F_NUMREG))); + a.segna_estratti(true, mov.numreg); } flag = true; break; } } if (!flag) - message_box("Selezionare almeno un movimento"); + message_box("Selezionare il movimento da estrarre"); else - app().print_log(); + a.print_log(); fill_esclusi(); return true; } @@ -790,7 +702,7 @@ bool TF9_app::mov_handler_escl(TMask_field& f, KEY key) return open_mov(mov); } -TMask& TF9_app::descr_msk() +TMask& descr_msk() { static TMask* m = nullptr; if (m == nullptr) @@ -803,69 +715,85 @@ TMask& TF9_app::descr_msk() return *m; } -void TF9_app::open_new_mask() -{ - -} - void TF9_app::edit_wa() const { - TString query; - query << "DELETE FROM F9WA00K WHERE true;" << - "INSERT INTO F9WA00K (F9PCSOC, F9PPCDC0) VALUES (" << _ambiente << ", " << _addr_doc << ");"; + TString query; + query << "DELETE FROM F9WA00K WHERE true;" << + "INSERT INTO F9WA00K (F9PCSOC, F9PPCDC0) VALUES (" << _config.ambiente << ", " << _config.addr_doc << ");"; } -void TF9_app::load() +int TF9_app::estrai() { - const TDate dataini = get_dataini(); - const TDate dataend = get_dataend(); - const char tipodoc = get_tipodoc(); - const bool flagpro = is_provviso(); - TDate datareg; - - TString query; query << "SELECT * FROM MOV WHERE DATAREG>=" << dataini.date2ansi() << " AND DATAREG<=" << dataend.date2ansi() << ";"; - TSQL_recordset mov(query); - int items = mov.items(); + const TDate dataini = get_dataini(); + const TDate dataend = get_dataend(); + const char tipodoc = get_tipodoc(); + const bool flagpro = is_provviso(); - TProgress_monitor progr(items, "Acquisizione movimenti"); - int i = 0; - const TipoIVA tipo = tipodoc == 'A' ? iva_acquisti : iva_vendite; - TLocalisamfile clifo(LF_CLIFO); - - // Prendo tutti i movimenti a partire da una data e li carico tutti fino alla data finale - _movs.clear(); - 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), ';'); - TCausale caus(recset_get_string(mov, MOV_CODCAUS, 3)); + // Vero e proprio oggetto estrazione + _estrazione = make_shared( + get_ambiente(), // Codice ambiente + flagpro, // Flag prov. + tipodoc, // Tipo doc. + get_descr(), // Descrizione estrazione + get_addr_doc(), // Cartella documenti + false, // Estrazione di un escluso + &dataini, // Data estr. mov dal + &dataend // Data estr. mov al + ); + + // Leggo i movimenti e li carico nell'estrazione. ///////////// + TString query; + query << "SELECT * FROM MOV WHERE DATAREG>=" << dataini.date2ansi() << " AND DATAREG<=" << dataend.date2ansi() << ";"; + TSQL_recordset mov(query); + + TProgress_monitor progr(mov.items(), "Acquisizione movimenti"); + TLocalisamfile clifo(LF_CLIFO); + const TipoIVA tipo = tipodoc == 'A' ? iva_acquisti : iva_vendite; + + // 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)); + const bool stampato = recset_get_bool(mov, MOV_REGST); + const TString& numdoc = recset_get_string(mov, MOV_NUMDOC); // Se definitivo controllo il flag di stampato REGST - if ((flagpro || recset_get_bool(mov, MOV_REGST)) && recset_get_string(mov, MOV_NUMDOC).full() && caus.reg().iva() == tipo - && (elab_f9.items() == 3 && elab_f9.get(2)[0] != 'X' || elab_f9.empty())) // Controllo che non sia escluso - { - TToken_string t("", '|'); - t.add(""); - t.add(recset_get_string(mov, MOV_NUMREG)); - t.add(recset_get_string(mov, MOV_DATAREG)); - t.add(recset_get_string(mov, MOV_DATADOC)); - t.add(recset_get_string(mov, MOV_CODCAUS)); - t.add(recset_get_string(mov, MOV_MESELIQ)); - t.add(recset_get_string(mov, MOV_NUMDOC)); - const real tot = recset_get_real(mov, MOV_TOTDOC) + recset_get_real(mov, MOV_RITFIS) + recset_get_real(mov, MOV_RITSOC); - t.add(tot); - t.add(recset_get_string(mov, MOV_CODCF)); + if ((flagpro || stampato) && numdoc.full() && caus.reg().iva() == tipo && !escluso) // Controllo anche che non sia escluso + { clifo.zero(); clifo.put(CLI_TIPOCF, tipo == iva_acquisti ? "F" : "C"); clifo.put(CLI_CODCF, recset_get_string(mov, MOV_CODCF)); - t.add(clifo.read() == NOERR ? clifo.get(CLI_RAGSOC) : " "); - t.add(TString(recset_get_string(mov, MOV_REG)) << "/" << recset_get_string(mov, MOV_PROTIVA)); - t.add(recset_get_string(mov, MOV_DESCR)); - _movs.insert(_movs.end(), t); - i++; - } - } - _tot_movs = i; + + // Creo il movimento da inserire + movimento_t t; + t.err = false; + t.numreg = recset_get_int(mov, MOV_NUMREG); + t.datareg = recset_get_string(mov, MOV_DATAREG); + t.datadoc = recset_get_string(mov, MOV_DATADOC); + t.codcaus = recset_get_string(mov, MOV_CODCAUS); + t.meseliq = recset_get_int(mov, MOV_MESELIQ); + t.numdoc = recset_get_string(mov, MOV_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); + + // Effettivo inserimento del movimento + _estrazione->add_mov(t); + } + } + + const result_estr result = _estrazione->estrai(); + + // Ricalcolo sheet estrazioni + _msk->fill(); + + return result; } void TF9_app::print_log() @@ -878,477 +806,54 @@ void TF9_app::print_log() 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"; // Deprecated - 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; -} - -state_fppro TF9_app::check_fppro(int numreg) const -{ - TLocalisamfile mov(LF_MOV); - mov.put(MOV_NUMREG, numreg); - if (mov.read() == NOERR && check_causale(mov.get(MOV_CODCAUS))) - { - // Controllo se ho i riferimenti all'FPPRO e verifico che sia tutto ok - const TString& keys_fppro = mov.get(MOV_KEYFPPRO); - if (keys_fppro.full()) - { - TToken_string keys(keys_fppro, ';'); - if (fppro_db().check_reg(keys, numreg)) - return correct; - return reg_with_err; - } - else // Se non ho i riferimenti faccio guessing - { - if (fppro_db().guess_the_doc(mov)) - return guessed; - return no_guessed; - } - } - return not_fa; -} - -const char * TF9_app::prepara_movimenti(TipoIVA tipo) -{ - bool ok = true; - - if (tipo == iva_acquisti) - { - // Controlli per le fatture di acquisto - TProgress_monitor bar(_movs.size(), "Controllo stato movimenti di acquisto"); - - for (auto it = _movs.begin(); it != _movs.end(); ++it) - { - if (!bar.add_status()) - break; - - TToken_string& row = *it; - const int numreg = row.get_int(cid2index(F_NUMREG)); - switch (check_fppro(numreg)) - { - case guessed: - ok &= fppro_db().associa_mov(numreg); - //row.add(fppro_db().get_keys_fppro()); - case correct: - ok &= true; - break; - - case not_fa: - row.add("Non fattura", cid2index(F_DESCRERR)); - case reg_with_err: - row.add("Registrazione con errori", cid2index(F_DESCRERR)); - case no_guessed: - ok &= false; - row.add("X", 0); // Mi segno il movimento che ha un problema - row.add("Non associato a fattura elettr. abbinamento automatico non riuscito. Abbinare manualmente, o escludere", cid2index(F_DESCRERR)); - default: break; - } - } - } - else if (tipo == iva_vendite) + static TString stato; + static TString last_cod; + if (last_cod != cod) { - // Controlli per le fatture di vendita - TProgress_monitor bar(_movs.size(), "Controllo stato movimenti di vendita"); - for (auto it = _movs.begin(); it != _movs.end(); ++it) - { - if (!bar.add_status()) - break; - TToken_string& row = *it; - TString numreg(row.get(1)); - TLocalisamfile mov(LF_MOV); - mov.put(MOV_NUMREG, numreg); - mov.read(); - // Controllo che abbia il riferimento al documento originale generatore del movimento - if (mov.get(MOV_DPROVV).empty() || mov.get(MOV_DANNO).empty() || mov.get(MOV_DCODNUM).empty() || mov.get(MOV_DNDOC).empty()) - { - row.add("X", 0); - row.add("Movimento non collegato a un documento originale. Impossibile estrarre. Escludere?", cid2index(F_DESCRERR)); - ok &= false; - } - else if(!is_doc_xml(mov)) // Quindi controllo che sia un documento xml, se no lo metto in errore e te lo escludi a mano se e' da escludere - { - row.add("X", 0); - row.add("Movimento collegato a un documento senza fatturazione elettronica. Escludere?", cid2index(F_DESCRERR)); - ok &= false; - } - } - } - return ok ? D_GEST_OK : D_GEST_ERR; -} - -// todo: Codice ripetuto andrebbe accorpata con la precedente -const char * TF9_app::prepara_movimenti_escl(TipoIVA tipo, int numreg, TString& err) const -{ - bool ok = true; - if (tipo == iva_acquisti) - { - // Controlli per le fatture di acquisto prepara_movimenti - switch (check_fppro(numreg)) - { - case guessed: - ok &= fppro_db().associa_mov(numreg); - //row.add(fppro_db().get_keys_fppro()); - case correct: - ok &= true; - break; - - case not_fa: - err << "Non fattura"; - case reg_with_err: - err << "Registrazione con errori"; - case no_guessed: - ok &= false; - err.cut(0) << "Non associato a fattura elettr.; abbinamanto automatico non riuscito. Abbinare manualmente."; - default: break; - } + 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"; } - else if (tipo == iva_vendite) - { - // Controlli per le fatture di vendita - TLocalisamfile mov(LF_MOV); - mov.put(MOV_NUMREG, numreg); - mov.read(); - // Controllo che abbia il riferimento al documento originale generatore del movimento - if (mov.get(MOV_DPROVV).empty() || mov.get(MOV_DANNO).empty() || mov.get(MOV_DCODNUM).empty() || mov.get(MOV_DNDOC).empty()) - { - err << "Movimento non collegato a un documento originale. Impossibile estrarre."; - ok &= false; - } - else if (!is_doc_xml(mov)) // Quindi controllo che sia un documento xml, se no lo metto in errore e te lo escludi a mano se e' da escludere - { - err << "Movimento collegato a un documento senza fatturazione elettronica."; - ok &= false; - } - } - return ok ? D_GEST_OK : D_GEST_ERR; -} - -bool TF9_app::is_doc_xml(const TLocalisamfile& mov) -{ - const char provv = mov.get(MOV_DPROVV)[0]; - const int anno = mov.get_int(MOV_DANNO); - const TString& codnum = mov.get(MOV_DCODNUM); - const int numdoc = mov.get_int(MOV_DNDOC); - - const TDocumento doc(provv, anno, codnum, numdoc); - TString hfatt(20), bfatt(50), query; - if(chiave_paf(doc, hfatt, bfatt)) - { - query << "SELECT * FROM PAF0100F WHERE P1_KEYHEADERFATT = '" << hfatt << "' AND P1_KEYBODYFATT = '" << bfatt << "';"; - db().sq_set_exec(query); - return db().sq_items() > 0; - } - return false; -} - -TString TF9_app::next_estr_today(const char tipo) const -{ - char estr[] = {0,0,0,0,0,0,0,0,0}; - TString query; - query << "SELECT TOP 1 " DRD_ID_EST " AS IDESTR\n" - "FROM " F9_DRD "\n" - "WHERE " DRD_ID_EST " LIKE '" << today.date2ansi() << tipo << "%'\n" << - "ORDER BY " DRD_ID_EST " DESC"; - db().sq_set_exec(query); - - const int last_estr = db().sq_items() > 0 ? real(db().sq_get("IDESTR").ltrim(10)).integer() : -1; - - if (last_estr < -1 || last_estr == 99999999) - { - ofstream fout; fout.open("f9err_nextestr.txt"); - if (fout.is_open()) - { - fout << "Errore progressivo nuova estrazione!\n" << today << "\nn:" << last_estr << "\n" << query << "\n"; - fout.close(); - } - TString msg; - fatal_box(msg << "database error: progressivo nuova estrazione. Ultima estrazione: " << last_estr); - } - - sprintf_s(estr, 9, "%08d", last_estr + 1); - return estr; -} - -bool TF9_app::check_periodo_def(const drd& head) -{ - TString query; - // Controllo se ci sono estrazioni (definitive) che si sovrappongono di periodo (con lo stesso tipo) e che non siano in stato di errore - // Nel caso di stato di errore e' invece possibile la ri-estrazione - query << "SELECT *\nFROM F9DRD00K\n" << - "WHERE " << DRD_DATAA << " >= '" << head.dal.date2ansi() << "' AND " DRD_DATADA " <= '" << head.al.date2ansi() << "' AND " - DRD_FLAG_PD " = 'D' AND\n " DRD_STATO " <> '" D_GEST_ERR "' AND " DRD_STATO " <> '" D_WA_ERR "' AND " DRD_STATO " <> '" D_ERR_SOS "' AND " DRD_TIPODOC " = '" << head.tipo_doc << "';"; - db().sq_set_exec(query); - return db().sq_items() == 0; -} - -bool TF9_app::esporta() const -{ - const bool ok = new_extr(); - _msk->fill(); - return ok; -} - -TString& TF9_app::drd_attr() -{ - static TString attr; - attr.cut(0) << DRD_CODSOC ", " DRD_ID_EST ", " DRD_FLAG_PD ", " DRD_DESC - ", " DRD_TIPODOC ", " DRD_DATADA ", " DRD_DATAA ", " DRD_UTENTE ", " DRD_TIME ", " - DRD_STATO ", " DRD_PERC; - return attr; -} - -TString& TF9_app::drd_tovalues() const -{ - static TString str; - return str.cut(0) << "'" << _head.cod_soc << "', '" << _head.id_estr << "', '" << (_head.flag_prov ? "P" : "D") << "', '" << _head.descr << - "', '" << _head.tipo_doc << "', '" << _head.dal.date2ansi() << "', '" << _head.al.date2ansi() << "', '" << _head.user << "', CURRENT_TIMESTAMP, '" << - _head.stato_estr << "', '" << _head.addr_cart << "'"; -} - -bool TF9_app::new_extr() const -{ - TString query; - query << "INSERT INTO " F9_DRD " ( " << drd_attr() << " ) \nVALUES ( " << drd_tovalues() << " );"; - bool ok = db().sq_set_exec(query); - ok = ok && db().sq_commit(); - return ok; -} - -int TF9_app::estrai() -{ - // Carico i movimenti - load(); - - if (_movs.empty()) - { - warning_box("Non esistono movimenti estraibili per il periodo selezionato."); - return -1; - } - - const char tipo = _estr_msk->get(ES_FLAGPROV)[0]; - _head.flag_prov = is_provviso(); - _head.dal = get_dataini(); - _head.al = get_dataend(); - _head.tipo_doc = get_tipodoc(); - if(!_head.flag_prov) // Se estrazione definitiva controllo il periodo che non si sovrapponga alle altre estrazioni def. - { - if (!check_periodo_def(_head)) - { - error_box("Attenzione e' stato inserito un periodo che si sovrappone\nad un'estrazione definitiva gia' esistente. Impossibile procedere"); - return -1; - } - } - _head.cod_soc = _ambiente; - _head.id_estr.cut(0) << today.date2ansi() << _estr_msk->get(ES_FLAGPROV) << "N" << next_estr_today(tipo); - _head.descr = get_descr(); - _head.user = user(); - _head.addr_cart = _addr_doc; - - _head.stato_estr = prepara_movimenti(get_tipoiva()); - const bool ok = esporta(); - - if (!ok) - { - TString msg; - msg << "Errore database: impossibile scrivere nuova estrazione.\n" - << db().sq_get_text_error(false); - error_box(msg); - return -99; - } - else - { - if (_head.stato_estr == D_GEST_ERR) - { - bool ok = export_error_list(); - if (!ok) - warning_box("Errore scrittura db. Controllare log errori."); - else - warning_box("Attenzione l'estrazione ha prodotto degli errori. \nControllare e correggere eventuali problemi \ndal Controllo Estrazione."); - return -2; - } - else - return estrazione_iva() ? 1 : 0; - } -} - -bool TF9_app::estrazione_iva(const bool escluso) -{ - bool stato = true; - TString& codsoc = _ambiente; - TString query; - vector& movs = escluso ? _esclusi : _movs; - - TProgress_monitor bar(movs.size(), "Estrazione dati IVA"); - for(auto it = movs.begin(); it != movs.end(); ++it) - { - if (!bar.add_status()) - break; - - TLocalisamfile mov(LF_MOV); mov.put(MOV_NUMREG, it->get(1)); mov.read(); - TLocalisamfile cli(LF_CLIFO); - cli.put(CLI_TIPOCF, mov.get(MOV_TIPO)); - cli.put(CLI_CODCF, mov.get(MOV_CODCF)); - cli.read(); - TString statopaiv; statopaiv << cli.get(CLI_STATOPAIV); - TString idfisc; - TString numdoc; numdoc << (mov.get(MOV_NUMDOCEXT).full() ? mov.get(MOV_NUMDOCEXT) : mov.get(MOV_NUMDOC)); - if (statopaiv == "IT" || statopaiv.empty()) - { - idfisc << "IT"; - if (cli.get(CLI_PAIV).full()) // Se non ho la partita IVA e' privato quindi non metto niente solo cod. ISO - idfisc << cli.get(CLI_PAIV); - } - else idfisc << statopaiv << cli.get(CLI_COFI); // Esteri - - query.cut(0) << "INSERT INTO " F9_IVA " (\n" - IVA_CODSOC ", " IVA_IDLAN ", " IVA_FLAG_PD ",\n" - IVA_ANNOES ", " IVA_GIVA ", " IVA_TIPOG ",\n" - IVA_DOCXML ", " IVA_TIPOCF ", " IVA_CODCF ",\n" - IVA_RAGSOC ", " IVA_IDFISC ", " IVA_PIVA ",\n" - IVA_CODFIS ", " IVA_CATDOC ", " IVA_CAUSSOS ",\n" - IVA_NUMDOC ", " IVA_DATADOC ", " IVA_SEZIVA ",\n" - IVA_TIPOREG ", " IVA_NPROT ", " IVA_DATPROT; - /*if(is_autofattura(mov)) - { - query << ",\n" - IVA_FORNOR ", " IVA_REGOR ", " IVA_NUMOR ", " IVA_DATAOR; - }*/ - query << ",\n" - IVA_CLASDOC ", " IVA_USERELA ", " IVA_TIMEELA; - if (_head.tipo_doc == 'A') - { - query << ",\n" - IVA_TIPPROT ", " IVA_NUMPROT ", " IVA_ANNPROT ", " IVA_TIMERIC; - } - const long datadoc = mov.get_date(MOV_DATADOC).date2ansi(); - const long datareg = mov.get_date(MOV_DATAREG).date2ansi(); - ; - - const TString& name_reg = TRegistro(TCausale(mov.get(MOV_CODCAUS)).reg()).name(); - query << "\n)\n" << - "VALUES (\n" << - "'" << codsoc << "', '" << _head.id_estr << "', '" << (_head.flag_prov ? "P" : "D") << "',\n" << - "'" << mov.get(MOV_ANNOES) << "', '" << _head.tipo_doc << "', '" << name_reg << "',\n" << - "'" << 'S' << "', '" << mov.get(MOV_TIPO) << "', '" << mov.get(MOV_CODCF) << "',\n" << - "'" << check_str(cli.get(CLI_RAGSOC)) << "', '" << idfisc << "', '" << cli.get(CLI_PAIV) << "',\n" << - "'" << cli.get(CLI_COFI) << "', '" << categoria_doc() << "', '" << caus_sos(mov, get_tipoiva()) << "',\n" << - "'" << numdoc << "', '" << datadoc << "', '" << mov.get(MOV_REG) << "',\n" << - "'" << "" << "', '" << mov.get(MOV_PROTIVA) << "', '" << datareg << "'"; - //if (is_autofattura(mov)) - //{ - // query << ",\n" << - // "'" << "" << "', '" << "" << "', '" << "N ORI" << "', '" << "20010101" << "'"; - //} - query << ",\n" << - "'" << (_head.tipo_doc == 'A' ? "FTA" : "FTV") << "', '" << user() << "', " << "GETDATE()"; - if (_head.tipo_doc == 'A') - { - TToken_string keys(mov.get(MOV_KEYFPPRO), ';'); - fppro_db().set_keys(keys); - query << ",\n" << - "'" << fppro_db().get_tipoprot() << "', '" << fppro_db().get_numprot() << "', '" << fppro_db().get_annoprot() << "', '" << fppro_db().get_dataoraric() << "'"; - } - query << "\n)"; - const bool ok = db().sq_set_exec(query); - - if(!ok) add_sqlerror_msg_log(query); - - stato &= ok; - } - return stato; -} - -bool TF9_app::export_error_list(bool esclusi) -{ - TF9_dberr dberr; - vector& movs = esclusi ? _esclusi : _movs; - bool ok = true; - for (auto it = movs.begin(); it != movs.end(); ++it) - { - if (it->get(0)[0] == 'X') - { - dberr.add(_head.id_estr); - for (int i = 1; i < 15; i++) - { - TString string(it->get(i)); - if (i == 2 || i == 3) // Sono obbligato a far cosi' per aggiungere le date - dberr.add(TDate(it->get(i))); - else if (string.full()) - dberr.add(string); - else - dberr.add(); // Se vuoto metto NULL - } - ok &= dberr.send(); - } - } - return ok; -} - -const char* TF9_app::categoria_doc() -{ - return ""; // todo: -} - -const char* TF9_app::caus_sos(const TLocalisamfile& mov, TipoIVA acquisti) -{ - if (acquisti == iva_acquisti) - { - TToken_string keys(mov.get(MOV_KEYFPPRO)); - fppro_db().set_keys(keys); - return fppro_db().get_tipodoc(); - } - if (acquisti == iva_vendite) - { - const TDocumento doc(mov.get(MOV_DPROVV)[0], mov.get_int(MOV_DANNO), mov.get(MOV_DCODNUM), mov.get_int(MOV_DNDOC)); - static TString tipo_doc_sdi; - return tipo_doc_sdi = doc.tipo().tipo_doc_sdi(); - } - return ""; + return (const char*)stato; } bool TF9_app::is_autofattura(const TLocalisamfile& mov) { - return TCausale(mov.get(MOV_CODCAUS)).tipo_doc() == "AF"; + return TCausale(mov.get(MOV_CODCAUS)).tipo_doc() == "AF"; } bool TF9_app::segna_estratti(const bool escluso, const int numreg) { bool ok = true; - vector escl; + vector escl; if (escluso) - escl.insert(escl.begin(), TToken_string(TString("|") << numreg << "|", '|')); - vector& movs_v = escluso ? escl : _movs; - + escl.insert(escl.begin(), movimento_t{ false, numreg }); + 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) + for (auto it = movs_v.begin(); it != movs_v.end(); ++it) { - TString8 num_reg = it->get(cid2index(F_NUMREG)); + TString8 num_reg(it->numreg); mov.zero(); mov.put(MOV_NUMREG, num_reg); mov.read(); @@ -1360,11 +865,11 @@ bool TF9_app::segna_estratti(const bool escluso, const int numreg) void TF9_app::segna_in_errore() const { - TString query; - query << "UPDATE " F9_DRD "\n" - "SET " DRD_STATO " = '" D_GEST_ERR "'\n" - "WHERE " DRD_ID_EST " = '" << _head.id_estr << "'\n"; - db().sq_set_exec(query); + TString query; + query << "UPDATE " F9_DRD "\n" + "SET " DRD_STATO " = '" D_GEST_ERR "'\n" + "WHERE " DRD_ID_EST " = '" << f9_app()._estrazione->get_id_estr() << "'\n"; + fp_db().sq_set_exec(query); } #ifdef DBG @@ -1372,34 +877,32 @@ void pulisci_mov() { TLocalisamfile mov(LF_MOV); mov.setkey(2); - mov.put(MOV_DATAREG, TDate("01-01-2019")); + mov.put(MOV_DATAREG, TDate("01-01-2002")); mov.read(); do { mov.put(MOV_ELABF9, ""); mov.write(); mov.rewrite(); - }while (mov.next() == NOERR); + } while (mov.next() == NOERR); } #endif void TF9_app::main_loop() { - if(!check_table()) + if (!check_table()) fatal_box("Controllo tabelle modulo fallito."); -#ifdef DBG // Per sicurezza che non venga inserito in release +#ifdef DBG //pulisci_mov(); #endif - _msk = new TMonitor_mask(); - _estr_msk = new TEstrai_mask(); + _msk = make_unique(); + _estr_msk = make_unique(); - _msk->fill(); - - while (_msk->run() != K_QUIT){ } + while (_msk->run() != K_QUIT) {} - delete _msk; - delete _estr_msk; + /*delete _msk; + delete _estr_msk;*/ } bool TF9_app::create_tables() const @@ -1425,8 +928,8 @@ bool TF9_app::check_tabelle_f9() const "SELECT * FROM INFORMATION_SCHEMA.TABLES\n" << "WHERE TABLE_NAME = '" F9_DRD "'))\n" << "SELECT 1 AS EXIST ELSE SELECT 0 AS EXIST"; - db().sq_set_exec(query); - if (db().sq_get("EXIST") != "1") // Se non esiste la tabella la creo + 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; } @@ -1443,7 +946,7 @@ bool TF9_app::aggiorna_tab_f9(int version) const std::ifstream fin; fin.open(file); - if(ok &= fin.is_open()) + if (ok &= fin.is_open()) { while (!fin.eof() && ok) { @@ -1454,11 +957,11 @@ bool TF9_app::aggiorna_tab_f9(int version) const sql += "\n" + appo_line; const int end = sql.find(';'); // Se trovo un comma lancio la query - if(end != int(std::string::npos)) + if (end != int(std::string::npos)) { TString query; query << sql.c_str(); - ok &= db().sq_set_exec(query, false); - ok &= db().sq_commit(); + ok &= fp_db().sq_set_exec(query, false); + ok &= fp_db().sq_commit(); sql.erase(); } } @@ -1481,22 +984,22 @@ bool TF9_app::check_tab_version() const 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 + if (version < SQL_VERSION) // Controllo la versione { - for(; version < SQL_VERSION; version += 2) // Effettuo le modifiche per ogni avanzamento di 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 + 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.put(TABMOD_TABVER, ver); // Avanzo il contatore della versione in TABMOD tabmod.write(); } tabmod.rewrite(); @@ -1505,7 +1008,6 @@ bool TF9_app::check_tab_version() const break; } } - return ok; } @@ -1516,28 +1018,28 @@ bool TF9_app::check_table() const TString msg; std::ofstream fout; fout.open("f9checktaberr.txt"); - fout << db().sq_get_text_error(false) << std::endl; + fout << fp_db().sq_get_text_error(false) << std::endl; fout.close(); - msg << "! Errore controllo database F9: creazione/aggiornamento tabelle.\n" << db().sq_get_text_error() << "\n" << db().sq_get_string_error(); + 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; } -TF9_app& app() +TF9_app& f9_app() { - static TF9_app* app = nullptr; - if(app == nullptr) - app = (TF9_app*)&main_app(); - return *app; + static TF9_app* app = nullptr; + if (app == nullptr) + app = (TF9_app*)&main_app(); + return *app; } int f90100(int argc, char* argv[]) { - TF9_app app; - app.run(argc, argv, TR("Archiviazione Sostitutiva")); - return 0; + TF9_app app; + app.run(argc, argv, TR("Archiviazione Sostitutiva")); + return 0; } @@ -1547,11 +1049,11 @@ int f90100(int argc, char* argv[]) vector& TControllo_mask::import_error_list() { - static vector movs; - movs.clear(); + static vector controllo_mov; + controllo_mov.clear(); TF9_dberr dberr; - _tipo_doc_err = dberr.get_errori(_id_estr, movs); - return movs; + _tipo_doc_err = dberr.get_errori(_id_estr, controllo_mov); + return controllo_mov; } void TControllo_mask::fill() @@ -1559,16 +1061,16 @@ void TControllo_mask::fill() TSheet_field& sf = sfield(S_CONTROLLO); sf.hide(); sf.destroy(); - vector& movs = !_is_escluso ? import_error_list() : app()._esclusi; // Prendo da _esclusi se sto aprendo il controllo dalla maschera degli esclusi + _movs = !_is_escluso ? import_error_list() : f9_app()._esclusi; // Prendo da _esclusi se sto aprendo il controllo dalla maschera degli esclusi - for (auto it = movs.begin(); it != movs.end(); ++it) + for (auto it = _movs.begin(); it != _movs.end(); ++it) { TToken_string& row = sf.row(-1); if (*it->get(0) == 'X') { row = *it; row[0] = (char&)" "; - /*if (!_is_escluso && _tipo_doc_err == 'A' || _is_escluso && app().get_tipoiva_escl() == iva_acquisti) + /*if (!_is_escluso && _tipo_doc_err == 'A' || _is_escluso && f9_app().get_tipoiva_escl() == iva_acquisti) row.add("", cid2index(F_CESCLUDI)); else row.add("X", cid2index(F_CESCLUDI));*/ @@ -1578,7 +1080,7 @@ void TControllo_mask::fill() sf.show(); // Fill fppro sheet - if (!_is_escluso && _tipo_doc_err == 'A' || _is_escluso && app().get_tipoiva_escl() == iva_acquisti) + if (!_is_escluso && _tipo_doc_err == 'A' || _is_escluso && f9_app().get_tipoiva_escl() == iva_acquisti) fill_fppro_sheet(); } @@ -1591,11 +1093,11 @@ void TControllo_mask::fill_fppro_sheet() const 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; + 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" << @@ -1707,17 +1209,16 @@ void TControllo_mask::associa() // todo: levare gli ultimi residui del vecchio if (ok) { // Tolgo il flag di in errore sul vettore in modo da rifare la fill e non venir piu' contato come da controllare - vector& movs = _is_escluso ? app()._esclusi : app()._movs; - auto it = movs.begin(); + auto it = _movs.begin(); int count = -1; - while (count < _selected_mov && it != movs.end()) + while (count < _selected_mov && it != _movs.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) + if (count < _selected_mov) ++it; } - it->add(" ", 0); + it->add(' ', 0); TF9_dberr::del_err(_id_estr, mov_sel->get_int(cid2index(F_CNUMREG))); } } @@ -1726,7 +1227,7 @@ void TControllo_mask::selfatt(TOperable_field& o, const long jolly) const { const TMask& mask = *this; TSheet_field* sf; - if (jolly == 1) // Sheet controllo + if (jolly == 1) // Sheet controllo sf = &mask.sfield(S_CONTROLLO); else sf = &mask.sfield(S_FPPRO); @@ -1762,7 +1263,7 @@ void TControllo_mask::conferma_esclusi() const row->add("Si", cid2index(F_CESCLUSO)); TString query; query << "UPDATE " F9_ERR " SET ESCLUSO = 'Si' WHERE IDESTR = '" << _id_estr << "' AND NUMREG = '" << row->get(cid2index(F_CNUMREG)) << "';"; - db().sq_set_exec(query); + fp_db().sq_set_exec(query); } else { @@ -1773,7 +1274,7 @@ void TControllo_mask::conferma_esclusi() const movs.rewrite(); TString query; query << "UPDATE " F9_ERR " SET ESCLUSO = NULL WHERE IDESTR = '" << _id_estr << "' AND NUMREG = '" << row->get(cid2index(F_CNUMREG)) << "';"; - db().sq_set_exec(query); + fp_db().sq_set_exec(query); } } } @@ -1887,4 +1388,9 @@ bool recset_get_bool(const TRecordset& rec, const char* field) real recset_get_real(const TRecordset& rec, const char* field) { return rec.get(rec.find_column(field)).as_real(); -} \ No newline at end of file +} + +int recset_get_int(const TRecordset& rec, const char* field, const int zero_filled) +{ + return rec.get(rec.find_column(field)).as_int(); +} diff --git a/src/f9/f90100.h b/src/f9/f90100.h index 0ccdaf72b..a231fb3b5 100644 --- a/src/f9/f90100.h +++ b/src/f9/f90100.h @@ -1,54 +1,35 @@ -#pragma once -#include "applicat.h" -#include "f90100a.h" -#include +#ifndef __F90100H__ +#define __F90100H__ + +#define PAR_MOD "F9" +#define AMBIENTE_F9 "CODSOC" // Codice ambiente (codsoc) +#define ADDRCART_F9 "ADDDOC" // Indirizzo documenti cartacei +#define VENDEXT_F9 "VENDEXT" // Flag no vendite con campo +#define VIEWMOV_F9 "VIEWMOVPRE" // Flag visualizza moviementi prima di estrarre + #include "execp.h" +#include "f90100a.h" +#include "f9lib01.h" +#include "mov.h" +#include +#include "applicat.h" -#define PAR_MOD "F9" -#define AMBIENTE_F9 "CODSOC" // Codice ambiente (codsoc) -#define ADDRCART_F9 "ADDDOC" // Indirizzo documenti cartacei - -TDate today(TODAY); - -enum state_fppro -{ - correct = 1, - reg_with_err = -1, - not_fa = -10, // Non e' fattura acquisti - guessed = 100, - no_guessed = 0 -}; - -struct drd -{ - TString cod_soc; - TString id_estr; - bool flag_prov{ true }; - TString descr; - char tipo_doc{ 'A' }; - TDate dal; - TDate al; - TString user; - TString timestamp; - TString4 stato_estr{ "01" }; - TString addr_cart; -}; - -SSimple_query& db(); - +/** class TEstrai_mask + * \brief Piccola maschera "creata a runtime" per avviare l'estrazione. + */ class TEstrai_mask : public TMask { - TString _descr; + TString _descr; - void enable_fields(bool en = true); + void enable_fields(bool en = true); - static bool estrai_handler(TMask_field& f, KEY key); - static bool enable_handler(TMask_field& f, KEY key); - static bool dataini_handler(TMask_field& f, KEY key); - static bool dataend_handler(TMask_field& f, KEY key); + static bool estrai_handler(TMask_field& f, KEY key); + static bool enable_handler(TMask_field& f, KEY key); + static bool dataini_handler(TMask_field& f, KEY key); + static bool dataend_handler(TMask_field& f, KEY key); public: - TString& get_descr() { return _descr; } - TEstrai_mask(); + TString& get_descr() { return _descr; } + TEstrai_mask(); }; class TEstrai_mask; @@ -56,96 +37,73 @@ class TMonitor_mask; class TControllo_mask; class TF9_app : public TSkeleton_application { - //friend class TEstrai_mask; - friend class TMonitor_mask; - friend class TControllo_mask; - drd _head; - TEstrai_mask* _estr_msk; - TMonitor_mask* _msk; - //TControllo_mask* _controllo_msk; - vector _movs; - vector _esclusi; // Vettore con i movimenti esclusi - vector _esclusi_vect; - TToken_string _mov_escl; - int _tot_movs; - TString _ambiente; // Codice ambiente (codsoc) - TString _addr_doc; // Indirizzo documenti cartacei - char _tipodoc_escl; - char _flagprov_escl; - TString _log; + //friend class TEstrai_mask; + friend class TMonitor_mask; + friend class TControllo_mask; + friend class TEstrazione; + + struct config + { + TString ambiente; // Codice ambiente (codsoc) + TString addr_doc; // Indirizzo documenti cartacei + bool vendext; + bool viewmovpre; + } _config; + unique_ptr _estr_msk; + unique_ptr _msk; + vector _movs; + vector _esclusi; // Vettore con i movimenti esclusi + vector _esclusi_vect; + TToken_string _mov_escl; + char _tipodoc_escl; + char _flagprov_escl; + TString _log; + + shared_ptr _estrazione; + TEstrazione* _estr_escluso; + + TDate get_dataini() const { return _estr_msk->get_date(ES_DATAINI); } + TDate get_dataend() const { return _estr_msk->get_date(ES_DATAEND); } + char get_tipodoc() const { return _estr_msk->get(ES_TIPODOC)[0]; } + char get_tipodoc_escl() const { return _tipodoc_escl; } + TipoIVA get_tipoiva() const { return get_tipodoc() == 'A' ? iva_acquisti : iva_vendite; } + TipoIVA get_tipoiva_escl() const { return get_tipodoc_escl() == 'A' ? iva_acquisti : iva_vendite; } + TString get_descr() const { return _estr_msk->get(ES_DESCR); } + bool is_provviso() const { return _estr_msk->get(ES_FLAGPROV)[0] == 'P'; } static const char* traduci_stato(const TString& cod); - state_fppro check_fppro(int numreg) const; - /** DIAGNOSTICA GESTIONALE. - * Controllo lo stato delle fatture: - * Per le fatt. acquisto non collegate a fppro cerca di agganciarle. - * Le fatture di vendita devono essere collegate ad un documento originario. - * - * \return D_GEST_OK (03) se non ci sono errori e l'estrazione puo' continuare. - * \return D_GEST_ERR (02) se la diagnostica ha riportato degli errori. - */ - const char* prepara_movimenti(TipoIVA tipo); - const char* prepara_movimenti_escl(TipoIVA tipo, int numreg, TString& err) const; - static bool is_doc_xml(const TLocalisamfile& mov); - static bool check_periodo_def(const drd& head); + //void fill(); - static TString& drd_attr(); - TString& drd_tovalues() const; - - /** Controlla ultimo id estrazione della giornata e in base al tipo di estrazione, - * genera il progressivo seguente. Chiamata da \a estrai() e \a estrai_single(). - * \return Nuovo id estrazione. */ - TString next_estr_today(char tipo) const; - bool esporta() const; /**< Scrittura testata estrazione. Tabella F9DRD. Chiama \a new_extr(). */ - bool new_extr() const; /**< See \a esporta(). */ - - TDate get_dataini() const { return _estr_msk->get_date(ES_DATAINI); } - TDate get_dataend() const { return _estr_msk->get_date(ES_DATAEND); } - char get_tipodoc() const { return _estr_msk->get(ES_TIPODOC)[0]; } - char get_tipodoc_escl() const { return _tipodoc_escl; } - TipoIVA get_tipoiva() const { return get_tipodoc() == 'A' ? iva_acquisti : iva_vendite; } - TipoIVA get_tipoiva_escl() const { return get_tipodoc_escl() == 'A' ? iva_acquisti : iva_vendite; } - TString get_descr() const { return _estr_msk->get(ES_DESCR); } - bool is_provviso() const { return _estr_msk->get(ES_FLAGPROV)[0] == 'P'; } - - //void fill(); - /** Caricamento di tutti i movimenti data un periodo di data registrazione. */ - void load(); - public: - const TString& get_ambiente() const { return _ambiente; } - const TString& get_addr_doc() const { return _addr_doc; }; - - void set_ambiente(const char* cod) { _ambiente.cut(0) << cod; }; - void set_addr_doc(const char* add) { _addr_doc.cut(0) << add; }; + const TString& get_ambiente() const { return _config.ambiente; } + const TString& get_addr_doc() const { return _config.addr_doc; } + bool get_has_vendext() const { return _config.vendext; } + bool get_viewmov() const { return _config.viewmovpre; } - void run_estr_msk() const { _estr_msk->run(); } + void set_ambiente(const char* cod) { _config.ambiente.cut(0) << cod; } + void set_addr_doc(const char* add) { _config.addr_doc.cut(0) << add; } + void set_has_vendext(const bool flag) { _config.vendext = flag; } + void set_viewmov(const bool flag) { _config.viewmovpre = flag; } - static TMask& descr_msk(); + void run_estr_msk() const { _estr_msk->run(); } - static void open_new_mask(); // Estrazione esclusi static bool select_escl_notify(TSheet_field& s, int row, KEY key); static bool controllo_escl_handler(TMask_field& field, KEY key); static bool year_handler(TMask_field& field, KEY key); void open_esclusi(); static void fill_esclusi(); + static movimento_t escl2mov(TToken_string* row); static bool estrai_escl_handler(TMask_field&, KEY key); static bool mov_handler(TMask_field&, KEY key); static bool mov_handler_escl(TMask_field&, KEY key); - void edit_wa() const; - /** Estrazione per pacchetti "normali" (non da esclusi). - * Viene chiamata dall'handler estrai_handler: bottone estrai nella maschera estrazione. - * - * \return 1 Se l'estrazione e' avvenuta senza errori. - * \return 0 Errore scrittura database iva. - * \return -1 Non esistono movimenti estraibili in quel periodo, o periodo sovrapposto ad altra estrazione. - * \return -2 La diagnostica ha riportato errori. - * \return -99 Errore scrittura F9DRD. */ - int estrai(); - int estrai_single(TToken_string& row, char flagprov, char tipodoc); /**< Estrazione singole per esclusi */ + void edit_wa() const; + /** Caricamento di tutti i movimenti data un periodo di data registrazione. + * \return See TEstrazione::estrai(). + */ + int estrai(); // logs @@ -153,71 +111,63 @@ public: void add_msg_log(const char* msg); void add_sqlerror_msg_log(const char* query); - /** Estrazione dati IVA sia per pacch. normali che per esclusi. Scrittura tabella F9IVA. - * \param escluso Settare a true se si sta estraendo un movimento escluso (estrazione pacchetto singolo, see estrai_single()). - * \return true Scrittura sul db senza errori. - * \return false Errore scrittura db. */ - bool estrazione_iva(bool escluso = false); - bool export_error_list(bool esclusi = false); bool segna_estratti(bool escluso = false, int numreg = 0); /**< Segna su mov che il movimento e' stato estratto */ - void segna_in_errore() const; + void segna_in_errore() const; - static const char* categoria_doc(); - static const char* caus_sos(const TLocalisamfile& mov, TipoIVA acquisti); - static bool is_autofattura(const TLocalisamfile& mov); + static bool is_autofattura(const TLocalisamfile& mov); - void main_loop() override; + void main_loop() override; // Controllo e aggiornamento tabelle F9 - bool create_tables() const; // Creazione tabelle F9 - bool check_tabelle_f9() const; // Controllo esistenza delle tabelle e in caso le crea - bool aggiorna_tab_f9(int version) const; // Aggiorna modifiche alle tabelle F9 come descritto in cima al file .cpp - bool check_tab_version() const; // Controllo della versione e in caso aggiorna le tabelle + bool create_tables() const; /**< Creazione tabelle F9 */ + bool check_tabelle_f9() const; /**< Controllo esistenza delle tabelle e in caso le crea */ + bool aggiorna_tab_f9(int version) const; /**< Aggiorna modifiche alle tabelle F9 come descritto in cima al file .cpp */ + bool check_tab_version() const; /**< Controllo della versione e in caso aggiorna le tabelle */ bool check_table() const; - TF9_app() : _estr_msk(nullptr), _msk(nullptr), _mov_escl("", '|'), _tot_movs(0), _ambiente(""), _addr_doc(""), - _tipodoc_escl('A'), _flagprov_escl('P') { } + TF9_app() : _config({ "", "", false, false }), _estr_msk(nullptr), _msk(nullptr), _mov_escl("", '|'), + _tipodoc_escl('A'), _flagprov_escl('P'), _estrazione(nullptr), _estr_escluso(nullptr) + { } }; - -TF9_app& app(); +TF9_app& f9_app(); class TMonitor_mask : public TAutomask { - vector _fppro; friend class TF9_app; + vector _fppro; - static bool save_conf_handler(TMask_field& f, KEY key); + static bool save_conf_handler(TMask_field& f, KEY key); void controllo_errori() const; - // Riempie sheet per visualizzare le estrazioni - bool on_key(KEY key) override; - static void open_win_estr(); - void open_win_conf() const; - - void fill() const; - void delete_pack(bool all = false) const; - + + // Riempie sheet per visualizzare le estrazioni + void fill() const; + + bool on_field_event(TOperable_field& o, TField_event e, long jolly) override; + bool on_key(KEY key) override; + void open_mostra_estrazione() const; + static void open_win_estr(); + void open_win_conf() const; + void sel() const; - void open_mostra_estrazione(); - bool on_field_event(TOperable_field& o, TField_event e, long jolly) override; - public: - TMonitor_mask() : TAutomask("f90100a") - { - //disable(DLG_FINDREC); - } + TMonitor_mask() : TAutomask("f90100a") { fill(); } }; class TControllo_mask : public TAutomask { - char _ordin; - char _verso; - int _selected_mov; - bool _sel_esclusi; - bool _is_escluso; - TString _id_estr; - char _tipo_doc_err{}; + char _ordin; + char _verso; + int _selected_mov; + bool _sel_esclusi; + bool _is_escluso; + TString _id_estr; + char _tipo_doc_err{}; + vector _movs; + + void associa(); + void conferma_esclusi() const; vector& import_error_list(); void fill(); @@ -227,34 +177,13 @@ class TControllo_mask : public TAutomask TToken_string* selected_mov(); TToken_string* selected_fat() const; - - // Gestisce la selezione multipla negli sheet di controllo movimenti + + /** Gestisce la selezione multipla negli sheet di controllo movimenti */ void selfatt(TOperable_field& o, long jolly) const; - void conferma_esclusi() const; - void associa(); bool on_field_event(TOperable_field& o, TField_event e, long jolly) override; - public: - TControllo_mask(const char* id_estr, bool esclusi = false); -}; - -class TF9_dberr -{ - TString _str; - TString _insert; - - void add_str(const TString& string); -public: - void add(const TString& string); - void add(const TDate& date) { add(date.date2ansi()); } - void add(const char* string) { add(TString(string)); } - void add(long num); - void add() { add_str("NULL"); } - bool send(); - static void del_err(const TString& id_estr, int get_int); - static char get_errori(const TString& id_estr, vector& movs); - TF9_dberr(); + explicit TControllo_mask(const char* id_estr, bool esclusi = false); }; inline bool open_mov(const TRectype& mov) @@ -281,8 +210,14 @@ inline bool open_mov(const TRectype& mov) return ok; } + + + // 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); + +#endif //__F90100H__ \ No newline at end of file diff --git a/src/f9/f90100a.h b/src/f9/f90100a.h index 9cf93a75b..3bd3db2ec 100644 --- a/src/f9/f90100a.h +++ b/src/f9/f90100a.h @@ -1,60 +1,63 @@ // Sheet Pacchetti gia' elaborati -#define S_ELAB 201 -#define F_TEXT 202 +#define S_ELAB 201 +#define F_TEXT 202 #define B_SHOWESTR 203 -#define B_SHOWESCL 204 +#define B_SHOWESCL 204 #define F_SEL 101 -#define F_ARCH_B 102 -#define F_IDESTR 103 -#define F_DATAESTR 104 -#define F_PROV_B 105 -#define F_TIPODOC 106 -#define F_DATADAL 107 -#define F_DATAAL 108 -#define F_USER 109 -#define F_STATESTR 110 -#define F_DESCR_E 111 +#define F_ARCH_B 102 +#define F_IDESTR 103 +#define F_DATAESTR 104 +#define F_PROV_B 105 +#define F_TIPODOC 106 +#define F_DATADAL 107 +#define F_DATAAL 108 +#define F_USER 109 +#define F_STATESTR 110 +#define F_DESCR_E 111 // Campi del vettore _movs per promemoria -#define F_SEL 101 -#define F_NUMREG 102 -#define F_DATAREG 103 -#define F_DATADOC 104 -#define F_CODCAUS 105 -#define F_MESELIQ 106 -#define F_NUMDOC 107 -#define F_IMPTOTDOC 108 -#define F_FORN 109 -#define F_RAGSOC 110 -#define F_PROTIVA 111 -#define F_DESCR 112 -#define F_ESCLUDI 113 -#define F_ESCLUSO 114 -#define F_DESCRERR 115 +// F_SEL 101 +// F_NUMREG 102 +// F_DATAREG 103 +// F_DATADOC 104 +// F_CODCAUS 105 +// F_MESELIQ 106 +// F_NUMDOC 107 +// F_IMPTOTDOC 108 +// F_FORN 109 +// F_RAGSOC 110 +// F_PROTIVA 111 +// F_DESCR 112 +// F_ESCLUDI 113 +// F_ESCLUSO 114 +// F_DESCRERR 115 // Campi maschera finestra runtime estrazione -#define ES_DATAINI 501 -#define ES_DATAEND 502 -#define ES_FLAGPROV 503 -#define ES_TIPODOC 504 -#define ES_DATEGROUP 505 -#define ES_FLAGGROUP 506 -#define ES_TIPOGROUP 507 +#define ES_DATAINI 501 +#define ES_DATAEND 502 +#define ES_FLAGPROV 503 +#define ES_TIPODOC 504 +#define ES_DATEGROUP 505 +#define ES_FLAGGROUP 506 +#define ES_TIPOGROUP 507 #define ES_DESCGROUP 508 #define ES_DESCR 509 // Campi maschera configurazione -#define CF_CODGROUP 501 -#define CF_CODSOC 502 -#define CF_ADDRGROUP 503 -#define CF_ADDRDOC 504 +#define CF_CODGROUP 501 +#define CF_CODSOC 502 +#define CF_ADDRGROUP 503 +#define CF_ADDRDOC 504 +#define CF_ESTRGROUP 505 +#define CF_VENDEXT 506 +#define CF_VIEWMOVPRE 507 // Campi maschera descrizione estrazione -#define DES_TEXT 501 -#define DES_GROUP 502 +#define DES_TEXT 501 +#define DES_GROUP 502 // Campi maschera esclusi -#define ESC_BESTR 501 -#define ESC_BEXIT 502 -#define ESC_SSHEE 503 \ No newline at end of file +#define ESC_BESTR 501 +#define ESC_BEXIT 502 +#define ESC_SSHEE 503 \ No newline at end of file diff --git a/src/f9/f90100a.uml b/src/f9/f90100a.uml index 6d38ccaf7..9f40a026b 100644 --- a/src/f9/f90100a.uml +++ b/src/f9/f90100a.uml @@ -2,12 +2,6 @@ TOOLBAR "topbar" 0 0 0 2 -BUTTON DLG_DELREC 2 2 -BEGIN - PROMPT 1 1 "~Elimina" - PICTURE TOOL_DELREC -END - BUTTON DLG_ELABORA 2 2 BEGIN PROMPT 1 2 "Estrazione" @@ -15,6 +9,12 @@ BEGIN FLAGS "" END +BUTTON DLG_DELREC 2 2 +BEGIN + PROMPT 1 1 "~Elimina" + PICTURE TOOL_DELREC +END + BUTTON DLG_CONFIG 2 2 BEGIN PROMPT 1 3 "Configurazione" diff --git a/src/f9/f90100b.h b/src/f9/f90100b.h index 93a5a7ca2..559ffe0a6 100644 --- a/src/f9/f90100b.h +++ b/src/f9/f90100b.h @@ -1,43 +1,43 @@ // Maschera controllo errori in comune con monitor e esclusi // Sheet Pacchetti gia' elaborati -#define B_ORDER 201 -#define B_ASSOC 202 -#define B_SELESCL 203 -#define B_ESCL 204 +#define B_ORDER 201 +#define B_ASSOC 202 +#define B_SELESCL 203 +#define B_ESCL 204 #define B_ALLESCL 205 // Sheet movimenti da controllare -#define S_CONTROLLO 206 -#define S_FPPRO 207 +#define S_CONTROLLO 206 +#define S_FPPRO 207 // Cambi maschera ordinamento sheet FPPRO -#define F_ORDER 301 -#define F_VERSO 302 +#define F_ORDER 301 +#define F_VERSO 302 -#define F_CSEL 101 -#define F_CNUMREG 102 -#define F_CDATAREG 103 -#define F_CDATADOC 104 -#define F_CCODCAUS 105 -#define F_CMESELIQ 106 -#define F_CNUMDOC 107 +#define F_CSEL 101 +#define F_CNUMREG 102 +#define F_CDATAREG 103 +#define F_CDATADOC 104 +#define F_CCODCAUS 105 +#define F_CMESELIQ 106 +#define F_CNUMDOC 107 #define F_CIMPTOTDOC 108 #define F_CFORN 109 #define F_CRAGSOC 110 -#define F_CPROTIVA 111 -#define F_CDESCR 112 -#define F_CESCLUDI 113 -#define F_CESCLUSO 114 -#define F_CDESCRERR 115 +#define F_CPROTIVA 111 +#define F_CDESCR 112 +#define F_CESCLUDI 113 +#define F_CESCLUSO 114 +#define F_CDESCRERR 115 // Sheet fatture FPPRO da associare -#define F_FSEL 101 -#define F_FTIPODOC 102 -#define F_FDATA 103 -#define F_FNUMDOC 104 -#define F_FIMPTOTDOC 105 -#define F_FFORNITORE 106 -#define F_FRAGSOC 107 -#define F_FSTATOPIVA 108 -#define F_FPIVA 109 -#define F_FPROKEYS 110 \ No newline at end of file +#define F_FSEL 101 +#define F_FTIPODOC 102 +#define F_FDATA 103 +#define F_FNUMDOC 104 +#define F_FIMPTOTDOC 105 +#define F_FFORNITORE 106 +#define F_FRAGSOC 107 +#define F_FSTATOPIVA 108 +#define F_FPIVA 109 +#define F_FPROKEYS 110 \ No newline at end of file diff --git a/src/f9/f90100b.uml b/src/f9/f90100b.uml index 1df4d7a8d..f5a68c7b7 100644 --- a/src/f9/f90100b.uml +++ b/src/f9/f90100b.uml @@ -64,7 +64,7 @@ BEGIN ITEM "Mese\nliquidazione@8" ITEM "Numero\nDocumento@8" ITEM "Totale\nDocumento@8" - ITEM "Fornitore@8" + ITEM "Cliente/\nFornitore@8" ITEM "Ragione\nSociale@8" ITEM "Cod. regis./\nprot.IVA@8" ITEM "Descrizione@8" diff --git a/src/f9/f901tab.h b/src/f9/f901tab.h index cfe38443f..94b246a94 100644 --- a/src/f9/f901tab.h +++ b/src/f9/f901tab.h @@ -1,5 +1,3 @@ -#pragma once - #define F9_WA "F9WA00K" #define F9_DRD "F9DRD00K" #define F9_IVA "F9IVA00K" @@ -7,6 +5,7 @@ #define F9_ERR "F9ERROR" // FILE DRD : DRIVER ESTRAZIONE GIORNALE IVA + #define DRD_CODSOC "F9RCSOC" // A(10) [K] #define DRD_ID_EST "F9RIDES" // A(18) [K] #define DRD_FLAG_PD "F9RFPDE" // A(1) [K] - { P | D } - Flag provvisorio/definitivo @@ -17,7 +16,9 @@ #define DRD_UTENTE "F9RUTEE" // A(10) - Utente estrazione #define DRD_TIME "F9RUHES" // T - Data e ora estrazione #define DRD_STATO "F9RIDAS" // A(2) - { 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 } - Stato estrazione documenti + // Stati ///////////////// + #define IN_DIAGN "01" // 01 = in diagnostica #define D_GEST_ERR "02" // 02 = errore diagnostica gestionale #define D_GEST_OK "03" // 03 = diagnostica gestionale ok, @@ -28,10 +29,12 @@ #define D_ERR_SOS "08" // 08 = errore diagnostica sostitutiva #define ELAB_COMPL "09" // 09 = Pacchetto archiviazione acquisito ////////////////////////// + #define DRD_PERC "F9RPCDC" // A(256) - Perc. copia doc. cartacei WA // FILE IVA : DOCUMENTI ESTRATTI DAL GIORNALE IVA + #define IVA_CODSOC "F9ICSOC" // A(10) [K] - Codice societā #define IVA_IDLAN "F9IIDLA" // A(18) [K] - ID UNIVOCO DI LANCIO #define IVA_FLAG_PD "F9IFPDE" // A(1) [K] - Flag Provvisorio / Definitivo @@ -88,6 +91,7 @@ // FILE DRT : TABELLA CATEGORIE DOCUMENTALI + #define DRT_CODSOC "F9TCSOC" // A(10) [K] - COD.SOCIETĀ #define DRT_CATDOC "F9TCADO" // A(10) [K] - Categoria documento #define DRT_DESCR "F9TDES" // A(30) - Descrizione documento diff --git a/src/f9/f90200.cpp b/src/f9/f90200.cpp index 596028b5a..88d74909b 100644 --- a/src/f9/f90200.cpp +++ b/src/f9/f90200.cpp @@ -5,7 +5,7 @@ #include "tsdb.h" #include "../fp/fplib.h" #include "f901tab.h" -#include "f9lib.h" +#include "f90100.h" /////////////////////////////////////////////////////////////// // TConfigurazione_sostitutiva_msk @@ -68,7 +68,7 @@ public: void TConfigurazione_sostitutiva_app::add_error_log(TString& query) { - _log << "\n" << query << "\n" << db().sq_get_text_error() << "\n" << db().sq_get_string_error(); + _log << "\n" << query << "\n" << fp_db().sq_get_text_error() << "\n" << fp_db().sq_get_string_error(); } void TConfigurazione_sostitutiva_app::main_loop() @@ -89,8 +89,8 @@ void TConfigurazione_sostitutiva_app::main_loop() " INSERT INTO " F9_DRT " ( ) \n" " VALUES ();\n"; } - bool ok = db().sq_set_exec(query, false); - ok &= db().sq_commit(); + bool ok = fp_db().sq_set_exec(query, false); + ok &= fp_db().sq_commit(); if (false) { add_error_log(query); diff --git a/src/f9/f90200a.h b/src/f9/f90200a.h new file mode 100644 index 000000000..b5892aa72 --- /dev/null +++ b/src/f9/f90200a.h @@ -0,0 +1,11 @@ +#define S_CLASSDOC 201 + +#define F_SELCLASS 101 +#define F_CATDOC 102 +#define F_DESCRDOC 103 +#define F_CLASDOCSOS 104 +#define F_CAUSSOS 105 +#define F_CAUSCONT 106 +#define F_TIPOCAUSCONT 107 +#define F_TIPOMOVCONT 108 +#define F_OPERCEE 109 diff --git a/src/f9/f90200a.uml b/src/f9/f90200a.uml new file mode 100644 index 000000000..63ed17295 --- /dev/null +++ b/src/f9/f90200a.uml @@ -0,0 +1,104 @@ +#include "f90200a.h" + +TOOLBAR "topbar" 0 0 0 2 + +BUTTON DLG_OK 2 2 +BEGIN + PROMPT 1 1 "Registra" + PICTURE TOOL_SAVEREC +END + +#include "helpbar.h" +ENDPAGE + +PAGE "Classi Documentali" 0 2 0 0 + +SPREADSHEET S_CLASSDOC -1 -1 +BEGIN + PROMPT 0 0 "Classi Documentali" + ITEM " " + ITEM "Categoria\nDocumento (Codice)@18" + ITEM "Descrizione\nDocumento" + ITEM "Classe Documentale\nSostitutiva@18" + ITEM "Causale per\nSostitutiva (TD01...)@12" + ITEM "Causale\nContabile" + ITEM "Tipo Causale\nContabile" + ITEM "Tipo Movimento\nContabile" + ITEM "Operatore CEE" +END + +ENDPAGE +ENDMASK + + +PAGE "Righe doc" -1 -1 78 13 + +BOOLEAN F_SELCLASS +BEGIN + PROMPT 1 1 "Seleziona" +END + +STRING F_CATDOC 5 +BEGIN + PROMPT 0 0 "Categoria Documento" +END + +STRING F_DESCRDOC 5 +BEGIN + PROMPT 0 0 "Descrizione Documento" +END + +LIST F_CLASDOCSOS 3 24 +BEGIN + PROMPT 0 0 "" + FLAGS "" + ITEM "FTA|FTA - Fattura Acquisti" + ITEM "FTV|FTV - Fattura di Vendita" +END + +LIST F_CAUSSOS 4 33 +BEGIN + PROMPT 0 0 "" + FLAGS "" + ITEM "" + ITEM "TD01|TD01 Fattura" + ITEM "TD02|TD02 Acconto/Anticipo su fattura" + ITEM "TD03|TD03 Acconto/Anticipo su parcella" + ITEM "TD04|TD04 Nota di credito" + ITEM "TD05|TD05 Nota di debito" + ITEM "TD06|TD06 Parcella" + ITEM "TD20|TD20 Autofattura" +END + +STRING F_CAUSCONT 5 +BEGIN + PROMPT 0 0 "Causale Contabile" +END + +STRING F_TIPOCAUSCONT 5 +BEGIN + PROMPT 0 0 "Tipo Causale Contabile" +END + +STRING F_TIPOMOVCONT 5 +BEGIN + PROMPT 0 0 "Tipo Movimento Contabile" +END + +STRING F_OPERCEE 5 +BEGIN + PROMPT 0 0 "Operatore CEE" +END + +ENDPAGE + +TOOLBAR "topbar" 0 0 0 2 +BUTTON DLG_QUIT 2 2 +BEGIN + PROMPT 3 1 "Fine" + MESSAGE EXIT,K_QUIT + PICTURE TOOL_QUIT +END + +ENPAGE +ENDMASK \ No newline at end of file diff --git a/src/f9/f9lib01.cpp b/src/f9/f9lib01.cpp new file mode 100644 index 000000000..7cffd56fb --- /dev/null +++ b/src/f9/f9lib01.cpp @@ -0,0 +1,589 @@ +#include "f9lib01.h" +#include "f1lib.h" +#include "f901tab.h" +#include "progind.h" +#include "clifo.h" +#include +#include "mov.h" +#include "../fp/fplib.h" + +const char* check_str(const TString& str); + +//////////////////////////////////////////////////////// +// TEstrazione +//////////////////////////////////////////////////////// + +const char* TEstrazione::categoria_doc() +{ + return ""; // todo: +} + +const char* TEstrazione::caus_sos(const TLocalisamfile& mov, TipoIVA acquisti) +{ + if (acquisti == iva_acquisti) + { + TToken_string keys(mov.get(MOV_KEYFPPRO)); + fppro_db().set_keys(keys); + return fppro_db().get_tipodoc(); + } + if (acquisti == iva_vendite) + { + const TDocumento doc(mov.get(MOV_DPROVV)[0], mov.get_int(MOV_DANNO), mov.get(MOV_DCODNUM), mov.get_int(MOV_DNDOC)); + static TString tipo_doc_sdi; + return tipo_doc_sdi = doc.tipo().tipo_doc_sdi(); + } + return ""; +} + +state_fppro TEstrazione::check_fppro(int numreg) +{ + TLocalisamfile mov(LF_MOV); + mov.put(MOV_NUMREG, numreg); + if (mov.read() == NOERR && check_causale(mov.get(MOV_CODCAUS))) + { + // Controllo se ho i riferimenti all'FPPRO e verifico che sia tutto ok + const TString& keys_fppro = mov.get(MOV_KEYFPPRO); + if (keys_fppro.full()) + { + TToken_string keys(keys_fppro, ';'); + if (fppro_db().check_reg(keys, numreg)) + return correct; + TString err(fppro_db().get_last_error()); + if (!err.empty()) + error_box(err.cut(0) << "Errore durante il controllo del movimento n. " << numreg << "\n" << err); + return reg_with_err; + } + else // Se non ho i riferimenti faccio guessing + { + if (fppro_db().guess_the_doc(mov)) + return guessed; + return no_guessed; + } + } + return not_fa; +} + +bool TEstrazione::check_periodo_def() const +{ + TString query; + // Controllo se ci sono estrazioni (definitive) che si sovrappongono di periodo (con lo stesso tipo) e che non siano in stato di errore + // Nel caso di stato di errore e' invece possibile la ri-estrazione + query << "SELECT *\nFROM F9DRD00K\n" << + "WHERE " << DRD_DATAA << " >= '" << _head.dal.date2ansi() << "' AND " DRD_DATADA " <= '" << _head.al.date2ansi() << "' AND " + DRD_FLAG_PD " = 'D' AND\n " DRD_STATO " <> '" D_GEST_ERR "' AND " DRD_STATO " <> '" D_WA_ERR "' AND " DRD_STATO " <> '" D_ERR_SOS "' AND " DRD_TIPODOC " = '" << _head.tipo_doc << "';"; + fp_db().sq_set_exec(query); + return fp_db().sq_items() == 0; +} + +bool TEstrazione::is_doc_xml(const TLocalisamfile& mov) +{ + const char provv = mov.get(MOV_DPROVV)[0]; + const int anno = mov.get_int(MOV_DANNO); + const TString& codnum = mov.get(MOV_DCODNUM); + const int numdoc = mov.get_int(MOV_DNDOC); + + const TDocumento doc(provv, anno, codnum, numdoc); + TString hfatt(20), bfatt(50), query; + if (chiave_paf(doc, hfatt, bfatt)) + { + query << "SELECT * FROM PAF0100F WHERE P1_KEYHEADERFATT = '" << hfatt << "' AND P1_KEYBODYFATT = '" << bfatt << "';"; + fp_db().sq_set_exec(query); + return fp_db().sq_items() > 0; + } + return false; +} + +TString& TEstrazione::drd_attr() +{ + static TString attr; + attr.cut(0) << DRD_CODSOC ", " DRD_ID_EST ", " DRD_FLAG_PD ", " DRD_DESC + ", " DRD_TIPODOC ", " DRD_DATADA ", " DRD_DATAA ", " DRD_UTENTE ", " DRD_TIME ", " + DRD_STATO ", " DRD_PERC; + return attr; +} + +TString& TEstrazione::drd_tovalues() const +{ + static TString str; + return str.cut(0) << "'" << _head.cod_soc << "', '" << _head.id_estr << "', '" << (_head.flag_prov ? "P" : "D") << "', '" << _head.descr << + "', '" << _head.tipo_doc << "', '" << _head.dal.date2ansi() << "', '" << _head.al.date2ansi() << "', '" << _head.user << "', CURRENT_TIMESTAMP, '" << + _head.stato_estr << "', '" << _head.addr_cart << "'"; +} + +bool TEstrazione::new_extr() const +{ + TString query; + query << "INSERT INTO " F9_DRD " ( " << drd_attr() << " ) \nVALUES ( " << drd_tovalues() << " );"; + bool ok = fp_db().sq_set_exec(query); + ok = ok && fp_db().sq_commit(); + if (!ok) + write_errorsql_log(query); + return ok; +} + +bool TEstrazione::scrivi_testata_su_db() const +{ + return new_extr(); +} + +bool TEstrazione::export_error_list() const +{ + TF9_dberr dberr; + const vector& movs = _movs; + bool ok = true; + int count = 0; + for (auto it = movs.begin(); it != movs.end(); ++it) + { + if (it->err) + { +#ifdef DBG + if (count == 25) + bool simo = true; + if (it->numreg == 187680) + bool simo = true; +#endif + dberr.add(_head.id_estr); + for (int i = 1; i < 15; i++) + { + TString string(it->get(i)); + + if (i == 2 || i == 3) // Sono obbligato a far cosi' per aggiungere le date + dberr.add(TDate(it->get(i))); + else if (string.full()) + { + string.replace("'", "''"); + dberr.add(string); + } + else + dberr.add(); // Se vuoto metto NULL + } + if (!(ok &= dberr.send())) + break; + ++count; + } + } + return ok; +} + +TString TEstrazione::next_estr_today(char tipo) const +{ + char estr[] = { 0,0,0,0,0,0,0,0,0 }; + TString query; + query << "SELECT TOP 1 " DRD_ID_EST " AS IDESTR\n" + "FROM " F9_DRD "\n" + "WHERE " DRD_ID_EST " LIKE '" << today.date2ansi() << "%'\n" << + "ORDER BY " DRD_ID_EST " DESC"; + fp_db().sq_set_exec(query); + + const int last_estr = fp_db().sq_items() > 0 ? real(fp_db().sq_get("IDESTR").ltrim(10)).integer() : -1; + + if (last_estr < -1 || last_estr == 99999999) + { + ofstream fout; fout.open("f9err_nextestr.txt"); + if (fout.is_open()) + { + fout << "Errore progressivo nuova estrazione!\n" << today << "\nn:" << last_estr << "\n" << query << "\n"; + fout.close(); + } + TString msg; + fatal_box(msg << "database error: progressivo nuova estrazione. Ultima estrazione: " << last_estr); + } + + sprintf_s(estr, 9, "%08d", last_estr + 1); + return TString(estr); +} + +void TEstrazione::write_errorsql_log(const TString& query) const +{ + TString msg; + msg << query << "\n" << + fp_db().sq_get_string_error() << "\n" << + fp_db().sq_get_text_error(); + if (_error_sql->is_open()) + *_error_sql << msg << "\n\n"; +#ifdef DBG + else + warning_box("Impossibile aprire il file f9_TEstrazione_error_sql.txt\nper scrivere errori scrittura db."); +#endif +} + + +// Public methods ///////////////////////////////////////////////////////////////////////////////////////////// + +void TEstrazione::add_mov(const movimento_t& movimento) +{ + _movs.insert(_movs.end(), movimento); +} + +void TEstrazione::aggiorna_stato() const +{ + bool ok; + do + { + TString query; + query << "UPDATE " F9_DRD "\n" \ + "SET " DRD_STATO " = '" << _head.stato_estr << "'\n" \ + "WHERE " DRD_CODSOC " = '" << _head.cod_soc << "'" \ + " AND " DRD_ID_EST " = '" << _head.id_estr << "'" \ + " AND " DRD_FLAG_PD " = '" << _head.flag_prov << "'"; + ok = fp_db().sq_set_exec(query); + ok = ok && fp_db().sq_commit(); + if (!ok) + write_errorsql_log(query); + } while (!ok && yesno_box("Impossibile aggiornare stato dell'estrazione.\nRiprovare?")); +} + +const char* TEstrazione::diagnostica_mov() +{ + bool ok = true; + const TipoIVA tipo = get_tipoiva(); + if (tipo == iva_acquisti) + { + // Controlli per le fatture di acquisto + TProgress_monitor bar(_movs.size(), "Controllo stato movimenti di acquisto"); + + for (auto it = _movs.begin(); it != _movs.end(); ++it) + { + if (!bar.add_status()) + break; + + movimento_t& mov_i = *it; + //const int numreg = row.get_int(cid2index(F_NUMREG)); + const int numreg = mov_i.numreg; + switch (check_fppro(numreg)) + { + case guessed: + ok &= fppro_db().associa_mov(numreg); + //row.add(fppro_db().get_keys_fppro()); + case correct: + ok &= true; + mov_i.state = correct; + break; + + case not_fa: + mov_i.descr_err = "Non fattura"; + mov_i.state = not_fa; + case reg_with_err: + mov_i.descr_err = "Registrazione con errori"; + mov_i.state = reg_with_err; + case no_guessed: + ok &= false; + mov_i.err = true; // Mi segno il movimento che ha un problema + mov_i.descr_err = "Non associato a fattura elettr. abbinamento automatico non riuscito. Abbinare manualmente, o escludere"; + mov_i.state = no_guessed; + default: break; + } + } + } + else if (tipo == iva_vendite) + { + // Controlli per le fatture di vendita + + // Vendite senza controlli. + // C'e' chi se le importa da altri gestionali!!! Sad :( + // Li mortacci loro! + // Bisogna pensare i casi in cui le fatture sono da escludere e non le posso escludere + // Ripensare esclusione vendite + + TProgress_monitor bar(_movs.size(), "Controllo stato movimenti di vendita"); + for (auto it = _movs.begin(); it != _movs.end(); ++it) + { + if (!bar.add_status()) + break; + //TToken_string& row = *it; + movimento_t& row = *it; + TString numreg(row.numreg); + TLocalisamfile mov(LF_MOV); + mov.put(MOV_NUMREG, numreg); + mov.read(); + // Controllo che abbia il riferimento al documento originale generatore del movimento + // todo: modificare controllo in base al flag in configurazione + if (mov.get(MOV_DPROVV).empty() || mov.get(MOV_DANNO).empty() || mov.get(MOV_DCODNUM).empty() || mov.get(MOV_DNDOC).empty()) + { + row.err = true; + row.descr_err = "Movimento non collegato a un documento originale. Impossibile estrarre. Escludere?"; + ok &= false; + } + else if (!is_doc_xml(mov)) // Quindi controllo che sia un documento xml, se no lo metto in errore e te lo escludi a mano, se e' da escludere + { + row.err = true; + row.descr_err = "Movimento collegato a un documento senza fatturazione elettronica. Escludere?"; + ok &= false; + } + } + } + _head.stato_estr = ok ? D_GEST_OK : D_GEST_ERR; + aggiorna_stato(); + return _head.stato_estr; +} + +result_estr TEstrazione::estrai() +{ + // Se non c'e' nessun movimento non sto nemmeno a scrivere il record di estrazione. + // Se estrazione definitiva controllo che il periodo non si sovrapponga alle altre estrazioni def. + // Do' errore ed esco subito. + if (_movs.empty()) + { + warning_box("Non esistono movimenti estraibili per il periodo selezionato."); + return estr_stop; + } + if (!_escluso && !_head.flag_prov && !check_periodo_def()) + { + error_box("Attenzione e' stato inserito un periodo che si sovrappone\nad un'estrazione definitiva gia' esistente. Impossibile procedere."); + return estr_stop; + } + + // Non so come usare questi 18 caaratteri... + // Ci metto un po' di roba anche se sono dati gia' noti in altri campi (I know..) + un numero incrementale. + _head.id_estr.cut(0) << today.date2ansi() << (_head.flag_prov ? "P" : "D") << (!_escluso ? "N" : "X") << + next_estr_today(_head.tipo_doc); + _head.user = user(); + // Eseguo controllo sui movimenti e segno in testata lo stato + _head.stato_estr = IN_DIAGN; // "01" che verra' quasi subito rimpiazzato dal risultato della diagnostica. + if (_escluso) + set_dates(); // Se escluso imposto data inizio e fine uguali + + // Scrivo record estrazione in stato '01'. + const bool ok = scrivi_testata_su_db(); + + if (!ok) + { + TString msg; + msg << "Errore database: impossibile scrivere nuova estrazione.\n" + << fp_db().sq_get_text_error(false); + error_box(msg); + return estr_err_db_drd; + } + + // Faccio partire la diagnostica e mi salvo il nuovo stato. + diagnostica_mov(); + + //_esclusi.clear(); + //_esclusi.insert(_esclusi.end(), row); + if (_head.stato_estr == D_GEST_ERR) + { + warning_box("Attenzione l'estrazione ha prodotto degli errori.\n" \ + "Controllare e correggere eventuali problemi\ndal Controllo Estrazione."); + // Se in errore, esporto lista errori sul db + if (!export_error_list()) + warning_box("Errore scrittura db. Controllare log errori."); + return estr_diag_err; // Errore diagnostica gestionale + } + + // Se va tutto ben fino a qui, posso andare a scrivere nella + // tabella IVA i movimenti. + return estrazione_iva() ? estr_ok : estr_err_db_iva; +} + +bool TEstrazione::estrazione_iva(bool escluso) +{ + bool stato = true; + TString query; + + TProgress_monitor bar(_movs.size(), "Estrazione dati IVA"); + for (auto it = _movs.begin(); it != _movs.end() && stato; ++it) + { + if (!bar.add_status()) + break; + + TLocalisamfile mov(LF_MOV); + TLocalisamfile cli(LF_CLIFO); + mov.put(MOV_NUMREG, it->numreg); + mov.read(); + cli.put(CLI_TIPOCF, mov.get(MOV_TIPO)); + cli.put(CLI_CODCF, mov.get(MOV_CODCF)); + cli.read(); + TString statopaiv; statopaiv << cli.get(CLI_STATOPAIV); + TString idfisc; + TString numdoc; numdoc << (mov.get(MOV_NUMDOCEXT).full() ? mov.get(MOV_NUMDOCEXT) : mov.get(MOV_NUMDOC)); + if (statopaiv == "IT" || statopaiv.empty()) + { + idfisc << "IT"; + if (cli.get(CLI_PAIV).full()) // Se non ho la partita IVA e' privato quindi non metto niente solo cod. ISO + idfisc << cli.get(CLI_PAIV); + } + else idfisc << statopaiv << cli.get(CLI_COFI); // Esteri + + query.cut(0) << "INSERT INTO " F9_IVA " (\n" + IVA_CODSOC ", " IVA_IDLAN ", " IVA_FLAG_PD ",\n" + IVA_ANNOES ", " IVA_GIVA ", " IVA_TIPOG ",\n" + IVA_DOCXML ", " IVA_TIPOCF ", " IVA_CODCF ",\n" + IVA_RAGSOC ", " IVA_IDFISC ", " IVA_PIVA ",\n" + IVA_CODFIS ", " IVA_CATDOC ", " IVA_CAUSSOS ",\n" + IVA_NUMDOC ", " IVA_DATADOC ", " IVA_SEZIVA ",\n" + IVA_TIPOREG ", " IVA_NPROT ", " IVA_DATPROT; + /*if(is_autofattura(mov)) + { + query << ",\n" + IVA_FORNOR ", " IVA_REGOR ", " IVA_NUMOR ", " IVA_DATAOR; + }*/ + query << ",\n" + IVA_CLASDOC ", " IVA_USERELA ", " IVA_TIMEELA; + if (_head.tipo_doc == 'A') + { + query << ",\n" + IVA_TIPPROT ", " IVA_NUMPROT ", " IVA_ANNPROT ", " IVA_TIMERIC; + } + const long datadoc = mov.get_date(MOV_DATADOC).date2ansi(); + const long datareg = mov.get_date(MOV_DATAREG).date2ansi(); + + const TString& name_reg = TRegistro(TCausale(mov.get(MOV_CODCAUS)).reg()).name(); + query << "\n)\n" << + "VALUES (\n" << + "'" << _head.cod_soc << "', '" << _head.id_estr << "', '" << (_head.flag_prov ? "P" : "D") << "',\n" << + "'" << mov.get(MOV_ANNOES) << "', '" << _head.tipo_doc << "', '" << name_reg << "',\n" << + "'" << 'S' << "', '" << mov.get(MOV_TIPO) << "', '" << mov.get(MOV_CODCF) << "',\n" << + "'" << check_str(cli.get(CLI_RAGSOC)) << "', '" << idfisc << "', '" << cli.get(CLI_PAIV) << "',\n" << + "'" << cli.get(CLI_COFI) << "', '" << categoria_doc() << "', '" << caus_sos(mov, get_tipoiva()) << "',\n" << + "'" << numdoc << "', '" << datadoc << "', '" << mov.get(MOV_REG) << "',\n" << + "'" << "" << "', '" << mov.get(MOV_PROTIVA) << "', '" << datareg << "'"; + //if (is_autofattura(mov)) + //{ + // query << ",\n" << + // "'" << "" << "', '" << "" << "', '" << "N ORI" << "', '" << "20010101" << "'"; + //} + query << ",\n" << + "'" << (_head.tipo_doc == 'A' ? "FTA" : "FTV") << "', '" << user() << "', " << "GETDATE()"; + if (_head.tipo_doc == 'A') + { + TToken_string keys(mov.get(MOV_KEYFPPRO), ';'); + fppro_db().set_keys(keys); + query << ",\n" << + "'" << fppro_db().get_tipoprot() << "', '" << fppro_db().get_numprot() << "', '" << fppro_db().get_annoprot() << "', '" << fppro_db().get_dataoraric() << "'"; + } + query << "\n)"; + const bool ok = fp_db().sq_set_exec(query); + if (!ok) + write_errorsql_log(query); + + stato &= ok; + } + return stato; +} + +void TEstrazione::set_dates() +{ + if (_escluso) + { + set_dataini(_movs[0].datareg); + set_dataend(_movs[0].datareg); + } +} + +TEstrazione::TEstrazione(const TString& ambiente, const bool flag_prov, const char tipodoc, const TString& descr, + const TString& addrcart, const bool escluso, const TDate* const dal, const TDate* const al) : _descr(descr) +{ + _head.cod_soc = ambiente; + _head.flag_prov = flag_prov; + _head.descr = descr; + _head.tipo_doc = tipodoc; + if (!escluso && dal != nullptr && al != nullptr) + { + _head.dal = *dal; + _head.al = *al; + } + _head.addr_cart = addrcart; + + _escluso = escluso; + + _error_sql = new fstream; + _error_sql->open("f9_TEstrazione_error_sql.txt"); +} + + + + +////////////////////////////////////////////////////// +// TF9_dberr +////////////////////////////////////////////////////// + +void TF9_dberr::add_str(const TString& string) +{ + _insert.rtrim(1); + if (_insert[_insert.len() - 1] != '(') + _insert << ", "; + _insert << string << ")"; +} + +void TF9_dberr::write_sqlerrlog(const TString& query) const +{ + if (_fout->is_open()) + { + TString msg; + msg << query << "\n" << + fp_db().sq_get_string_error() << "\n" << + fp_db().sq_get_text_error(); + *_fout << msg << "\n"; + } +} + +void TF9_dberr::add(const TString& string) +{ + TString str; + add_str(str << "'" << string << "'"); +} + +void TF9_dberr::add(const long num) +{ + TString app; + app << num; + add(app); +} + +bool TF9_dberr::send() +{ + fp_db().sq_set_exec(_insert); + write_sqlerrlog(_insert); + _insert.cut(0) << "INSERT INTO " F9_ERR " VALUES ()"; + return true; +} + +void TF9_dberr::del_err(const TString& id_estr, int numreg) +{ + TString query; + query << "DELETE FROM " F9_ERR " WHERE IDESTR = '" << id_estr << "' AND NUMREG = '" << numreg << "';"; + fp_db().sq_set_exec(query); +} + +char TF9_dberr::get_errori(const TString& id_estr, vector& controllo_mov) +{ + TString query; + query << "SELECT * FROM " F9_ERR " WHERE IDESTR = '" << id_estr << "';"; + fp_db().sq_set_exec(query, false); + for (bool ok = fp_db().sq_next(); ok; ok = fp_db().sq_next()) + { + TToken_string row("", '|'); + row.add("X"); + for (int i = 1; i < 15; i++) + { + if (fp_db().sq_get_type_field(i) == _datefld) + row.add(fp_db().sq_get_date(fp_db().sq_get_name_field(i))); + else + row.add(fp_db().sq_get(i)); + } + + controllo_mov.insert(controllo_mov.end(), row); + } + query.cut(0) << "SELECT " DRD_TIPODOC " FROM " F9_DRD "\n" << + "WHERE " DRD_ID_EST " = '" << id_estr << "'"; + fp_db().sq_set_exec(query); + return fp_db().sq_get((unsigned)0)[0]; +} + +TF9_dberr::TF9_dberr() +{ + _insert.cut(0) << "INSERT INTO " F9_ERR " VALUES ()"; + _fout = new ofstream; + _fout->open("f9_dberr.txt"); +} + +/////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////// + +const char* check_str(const TString& str) +{ + static TString n_str; n_str.cut(0) << str; + n_str.replace("'", "\'\'"); + n_str.replace(" ", " "); + return (const char*)n_str; +} diff --git a/src/f9/f9lib01.h b/src/f9/f9lib01.h new file mode 100644 index 000000000..15e8140b3 --- /dev/null +++ b/src/f9/f9lib01.h @@ -0,0 +1,202 @@ +#ifndef __F901001H__ +#define __F901001H__ + +#include "strings.h" +#include "date.h" +#include "real.h" +#include +#include + +const TDate today(TODAY); + +struct drd +{ + TString cod_soc; + TString id_estr; + bool flag_prov{ true }; + TString descr; + char tipo_doc{ 'A' }; + TDate dal; + TDate al; + TString user; + TString timestamp; + TString4 stato_estr{ "01" }; + TString addr_cart; +}; + +enum result_estr +{ + estr_ok = 1, // Estrazione e' avvenuta senza errori. + estr_err_db_iva = 0, // Errore scrittura database iva. + estr_stop = -1, // Non esistono movimenti estraibili in quel periodo, o periodo sovrapposto ad altra estrazione. + estr_diag_err = -2, // La diagnostica ha riportato errori. + estr_err_db_drd = -99 // Errore scrittura F9DRD. +}; + +enum state_fppro +{ + correct = 1, + reg_with_err = -1, + not_fa = -10, // Non e' fattura acquisti + guessed = 100, + no_guessed = 0, + null_state = -100 +}; + +typedef struct _movimento_t +{ + bool err; + int numreg; + TDate datareg; + TDate datadoc; + TString codcaus; + int meseliq; + TString numdoc; + real tot; + int codcf; + TString ragsoc; + TString reg_protiva; + TString descr; + state_fppro state; + TString descr_err; + + TString get(int i) const + { + TString a; + switch (i) + { + case 0: return err; + case 1: return a << numreg; + case 2: return (const char*)datareg; + case 3: return (const char*)datadoc; + case 4: return codcaus; + case 5: return a << meseliq; + case 6: return numdoc; + case 7: + a << tot; + if (a == "0") + a << ".0"; + return a; + case 8: return a << codcf; + case 9: return ragsoc; + case 10: return reg_protiva; + case 11: return descr; + case 14: return descr_err; + default: return ""; + } + } +} movimento_t; + +class TEstrazione : public TObject +{ + drd _head; + vector _movs; + fstream* _error_sql; + bool _escluso; + const TString _descr; + + /** Aggiorna stato estrazione. Utilizzato ad esempio dopo la diagnostica per riportare + * il nuovo stato sul db. + */ + void aggiorna_stato() const; + static const char* categoria_doc(); + static const char* caus_sos(const TLocalisamfile& mov, TipoIVA acquisti); + /** CHECK RIFERIMENTO FPPRO + * Per le fatture di acquisto controllo se ho il riferimento nell'FPPRO. + * Altrimenti cerco di capire se riesco a trovare il corrispondente del movimento + * nell'FPPRO ("Guessing"). + * \return \a correct se ho gia' il riferimento e corrisponde effettivamente. + * \return \a reg_with_err se ho il riferimento ma la corrispondenza e' sbagliata. + * \return \a guessed se non ho il riferimento ma sono riuscito a trovarlo a manina. + * \return \a no_guessed se non avevo il riferimento e non sono riuscito a trovarlo. + * \return \a not_fa se il movimento passato non č una fattura. + */ + static state_fppro check_fppro(int numreg); + bool check_periodo_def() const; + TipoIVA get_tipoiva() const { return _head.tipo_doc == 'A' ? iva_acquisti : iva_vendite; } + static bool is_doc_xml(const TLocalisamfile& mov); + + static TString& drd_attr(); + TString& drd_tovalues() const; + bool new_extr() const; /**< See \a scrivi_testata_su_db(). */ + bool scrivi_testata_su_db() const; /**< Scrittura testata estrazione. Tabella F9DRD. Chiama \a new_extr(). */ + bool export_error_list() const; /**< Esporta sheet controllo fatture sul db. */ + + /** Controlla ultimo id estrazione della giornata e in base al tipo di estrazione, + * genera il progressivo seguente. Chiamata da \a estrai() e \a estrai_single(). + * \return Nuovo id estrazione. */ + TString next_estr_today(char tipo) const; + void write_errorsql_log(const TString& query) const; + +public: + + void add_mov(const movimento_t& movimento); + /** DIAGNOSTICA GESTIONALE. + * Controllo lo stato delle fatture: + * Per le fatt. acquisto non collegate a fppro cerca di agganciarle. + * Le fatture di vendita devono essere collegate ad un documento originario. + * Automaticamente aggiorna lo stato nella dell'estrazione, anche sul db (chiama /a aggiorna_stato()). + * + * \return D_GEST_OK (03) se non ci sono errori e l'estrazione puo' continuare. + * \return D_GEST_ERR (02) se la diagnostica ha riportato degli errori. + */ + const char* diagnostica_mov(); + /** Estrazione per pacchetti "normali" (non da esclusi). + * Viene chiamata dall'handler estrai_handler: bottone estrai nella maschera estrazione. + * + * \return estr_ok (1) Se l'estrazione e' avvenuta senza errori. + * \return estr_err_db_iva (0) Errore scrittura database iva. + * \return estr_stop (-1) Non esistono movimenti estraibili in quel periodo, o periodo sovrapposto ad altra estrazione. + * \return estr_diag_err (-2) La diagnostica ha riportato errori. + * \return estr_err_db_drd (-99) Errore scrittura F9DRD. */ + result_estr estrai(); + /** Estrazione dati IVA sia per pacch. normali che per esclusi. Scrittura tabella F9IVA. + * \param escluso Settare a true se si sta estraendo un movimento escluso (estrazione pacchetto singolo, see estrai_single()). + * \return true Scrittura sul db senza errori. + * \return false Errore scrittura db. */ + bool estrazione_iva(bool escluso = false); + + // Getters + TString get_id_estr() const { return _head.id_estr; } + TString4 get_stato_estr() const { return _head.stato_estr; } + const vector& get_movs() const { return _movs; } + + // Setters + void set_provvisorio(bool flag_prov) { _head.flag_prov = flag_prov; } + void set_dataini(const TDate& dal) { _head.dal = dal; } + void set_dataend(const TDate& al) { _head.al = al; } + void set_dates(); // Solo se e' escluso + void set_tipodoc(char tipodoc) { _head.tipo_doc = tipodoc; } + void set_ambiente(const TString& ambiente) { _head.cod_soc = ambiente; } + void set_descr(const TString& descr) { _head.descr = descr; } + void set_addrcart(const TString& addrcart) { _head.addr_cart = addrcart; } + + TEstrazione(const TString& ambiente, bool flag_prov, char tipodoc, const TString& descr, const TString& addrcart, + bool escluso, const TDate* dal = nullptr, const TDate* al = nullptr); +}; + + + + +class TF9_dberr +{ + TString _str; + TString _insert; + ofstream* _fout; + +protected: + void add_str(const TString& string); + void write_sqlerrlog(const TString& query) const; +public: + void add(const TString& string); + void add(const TDate& date) { add(date.date2ansi()); } + void add(const char* string) { add(TString(string)); } + void add(long num); + void add() { add_str("NULL"); } + bool send(); + static void del_err(const TString& id_estr, int numreg); + static char get_errori(const TString& id_estr, vector& controllo_mov); + TF9_dberr(); +}; + +#endif // #ifndef __F901001H__