#ifndef __F90100H__ #define __F90100H__ #define PAR_MOD "F9" #define AMBIENTE_F9 "CODSOC" // Codice ambiente (codsoc) #define ADDRCART_F9 "ADDDOC" // Indirizzo documenti cartacei #define CHECKVEND_F9 "CHECKVEND" // Flag controlli per vendite (quando hai fatt. con Campo) #define CARTEXP_F9 "CARTEXP" // Flag esporta documenti cartacei #define VIEWMOV_F9 "VIEWMOVPRE" // Flag visualizza moviementi prima di estrarre #include "execp.h" #include "f90100a.h" #include "f9lib01.h" #include "mov.h" #include "automask.h" #include "applicat.h" /** class TEstrai_mask * \brief Piccola maschera "creata a runtime" per avviare l'estrazione. */ class TEstrai_mask : public TMask { TString _descr; 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); public: TString& get_descr() { return _descr; } TEstrai_mask(); }; class TF9_app : public TSkeleton_application { //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 cartexp; bool checkvend; bool viewmovpre; } _config; // todo: controllare che siano sqlsafe 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; unique_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'; } // Dato il codice stato estrazione (es. '01') viene restituito il suo significato a parole. static const char* traduci_stato(const TString& cod); public: const TString& get_ambiente() const { return _config.ambiente; } const TString& get_addr_doc() const { return _config.addr_doc; } bool get_has_cartexp() const { return _config.cartexp; } bool get_has_checkvend() const { return _config.checkvend; } bool get_viewmov() const { return _config.viewmovpre; } 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_cartexp(const bool flag) { _config.cartexp = flag; } void set_has_checkvend(const bool flag){ _config.checkvend = flag; } void set_viewmov(const bool flag) { _config.viewmovpre = flag; } /** Esegue la maschera di inserimento opzioni per avviare l'estrazione. */ void run_estr_msk() const { _estr_msk->run(); } // Estrazione esclusi - handlers 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); static bool estrai_escl_handler(TMask_field&, KEY key); void open_esclusi(); static void fill_esclusi(); static movimento_t escl2mov(TToken_string* row); static bool mov_handler(TMask_field&, KEY key); static bool mov_handler_escl(TMask_field&, KEY key); /** Aggiorna tabella F9WA. */ void edit_wa(TString& old_codsoc) const; /** Prepara l'estrazione caricando tutti i movimenti dato un periodo (data registrazione), * e avvia la procedura di estrazione. * \return See \a TEstrazione::estrai(). */ int estrai(); // logs void print_log(); void add_msg_log(const char* msg); void add_sqlerror_msg_log(const char* query); static bool is_autofattura(const TLocalisamfile& mov); /** Segna su mov che il movimento e' stato estratto. */ bool segna_estratti(bool escluso = false, int numreg = 0); /** Segna su DRD che l'estrazione e' in errore diag. gestionale. */ static void segna_in_errore(); // Controllo e aggiornamento tabelle F9 private: 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 f90100.cpp. bool check_tab_version() const; // Controllo della versione e in caso aggiorna le tabelle. public: bool check_table() const; /**< Controllo e aggiornamento versione sql. */ void main_loop() override; TF9_app(); }; inline TF9_app& f9_app() { static TF9_app* app = nullptr; if (app == nullptr) app = (TF9_app*)&main_app(); return *app; } class TMonitor_mask : public TAutomask { friend class TF9_app; vector _fppro; static bool save_conf_handler(TMask_field& f, KEY key); void controllo_errori() 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; public: TMonitor_mask() : TAutomask("f90100a") { fill(); } }; class TControllo_mask : public TAutomask { char _ordin; char _verso; int _selected_mov; bool _sel_esclusi; bool _is_escluso; TString _cod_soc; TString _id_estr; char _tipo_doc_err{}; vector _movs; void associa(); void conferma_esclusi() const; vector& import_error_list(); void fill(); void fill_fppro_sheet() const; TMask& get_win_order(); void open_win_order(); TToken_string* selected_mov(); TToken_string* selected_fat() const; /** Gestisce la selezione multipla negli sheet di controllo movimenti */ void selfatt(TOperable_field& o, long jolly) const; bool on_field_event(TOperable_field& o, TField_event e, long jolly) override; public: explicit TControllo_mask(const char* codsoc, const char* id_estr, bool esclusi = false); }; inline bool open_mov(const TRectype& mov) { TFilename ininame; ininame.temp("lnk", "ini"); { TConfig ini(ininame, "Transaction"); ini.set("Action", "LINK"); ini.set_paragraph("23"); ini.set("NUMREG", mov.get(MOV_NUMREG)); } TString app; app << "cg2.exe -0 -i" << ininame; TExternal_app a(app); bool ok = a.run() == 0; if (ok) { xvt_sys_sleep(500); const TString& result = ini_get_string(ininame, "Transaction", "Result"); ok = result == "OK"; } xvt_fsys_remove_file(ininame); 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__