2019-09-10 17:33:59 +02:00
|
|
|
#pragma once
|
|
|
|
#include "applicat.h"
|
|
|
|
#include "f90100a.h"
|
|
|
|
#include <automask.h>
|
2019-09-13 17:06:08 +02:00
|
|
|
#include "execp.h"
|
2019-09-10 17:33:59 +02:00
|
|
|
|
|
|
|
#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 : public TMask
|
|
|
|
{
|
|
|
|
TString _descr;
|
|
|
|
|
|
|
|
void enable_fields(bool en = true);
|
|
|
|
|
2019-09-25 17:43:55 +02:00
|
|
|
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);
|
2019-09-10 17:33:59 +02:00
|
|
|
public:
|
|
|
|
TString& get_descr() { return _descr; }
|
|
|
|
TEstrai_mask();
|
|
|
|
};
|
|
|
|
|
|
|
|
class TEstrai_mask;
|
|
|
|
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<TToken_string> _movs;
|
|
|
|
vector<TToken_string> _esclusi; // Vettore con i movimenti esclusi
|
2019-09-13 17:06:08 +02:00
|
|
|
vector<TToken_string> _esclusi_vect;
|
2019-09-10 17:33:59 +02:00
|
|
|
TToken_string _mov_escl;
|
|
|
|
int _tot_movs;
|
|
|
|
TString _ambiente; // Codice ambiente (codsoc)
|
|
|
|
TString _addr_doc; // Indirizzo documenti cartacei
|
|
|
|
char _tipodoc_escl;
|
|
|
|
char _flagprov_escl;
|
2019-10-28 12:31:23 +01:00
|
|
|
TString _log;
|
2019-09-10 17:33:59 +02:00
|
|
|
|
|
|
|
static const char* traduci_stato(const TString& cod);
|
|
|
|
|
|
|
|
state_fppro check_fppro(int numreg) const;
|
2019-10-28 12:31:23 +01:00
|
|
|
/** 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.
|
|
|
|
*/
|
2019-09-10 17:33:59 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
static TString& drd_attr();
|
|
|
|
TString& drd_tovalues() const;
|
|
|
|
|
2019-10-28 12:31:23 +01:00
|
|
|
/** 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. */
|
2019-09-10 17:33:59 +02:00
|
|
|
TString next_estr_today(char tipo) const;
|
2019-10-28 12:31:23 +01:00
|
|
|
bool esporta() const; /**< Scrittura testata estrazione. Tabella F9DRD. Chiama \a new_extr(). */
|
|
|
|
bool new_extr() const; /**< See \a esporta(). */
|
2019-09-10 17:33:59 +02:00
|
|
|
|
|
|
|
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; }
|
2019-09-13 17:06:08 +02:00
|
|
|
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; }
|
2019-09-25 17:43:55 +02:00
|
|
|
TString get_descr() const { return _estr_msk->get(ES_DESCR); }
|
2019-09-10 17:33:59 +02:00
|
|
|
bool is_provviso() const { return _estr_msk->get(ES_FLAGPROV)[0] == 'P'; }
|
|
|
|
|
2019-09-13 17:06:08 +02:00
|
|
|
//void fill();
|
2019-10-28 12:31:23 +01:00
|
|
|
/** Caricamento di tutti i movimenti data un periodo di data registrazione. */
|
2019-09-10 17:33:59 +02:00
|
|
|
void load();
|
|
|
|
|
|
|
|
public:
|
2019-10-28 12:31:23 +01:00
|
|
|
const TString& get_ambiente() const { return _ambiente; }
|
2019-09-10 17:33:59 +02:00
|
|
|
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; };
|
|
|
|
|
|
|
|
void run_estr_msk() const { _estr_msk->run(); }
|
|
|
|
|
|
|
|
static TMask& descr_msk();
|
|
|
|
|
2019-10-28 12:31:23 +01:00
|
|
|
static void open_new_mask();
|
2019-09-10 17:33:59 +02:00
|
|
|
// 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();
|
2019-09-13 17:06:08 +02:00
|
|
|
static void fill_esclusi();
|
|
|
|
static bool estrai_escl_handler(TMask_field&, KEY key);
|
|
|
|
static bool mov_handler(TMask_field&, KEY key);
|
2019-10-28 12:31:23 +01:00
|
|
|
static bool mov_handler_escl(TMask_field&, KEY key);
|
2019-09-10 17:33:59 +02:00
|
|
|
|
|
|
|
void edit_wa() const;
|
2019-10-28 12:31:23 +01:00
|
|
|
/** 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 */
|
|
|
|
|
|
|
|
// logs
|
|
|
|
|
|
|
|
void print_log();
|
|
|
|
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 */
|
2019-09-10 17:33:59 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
void main_loop() override;
|
2019-09-13 17:06:08 +02:00
|
|
|
|
|
|
|
// Controllo e aggiornamento tabelle F9
|
|
|
|
|
|
|
|
bool create_tables() const; // Creazione tabelle F9
|
2019-10-28 12:31:23 +01:00
|
|
|
bool check_tabelle_f9() const; // Controllo esistenza delle tabelle e in caso le crea
|
2019-09-13 17:06:08 +02:00
|
|
|
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
|
2019-09-16 18:10:27 +02:00
|
|
|
bool check_table() const;
|
2019-09-13 17:06:08 +02:00
|
|
|
TF9_app() : _estr_msk(nullptr), _msk(nullptr), _mov_escl("", '|'), _tot_movs(0), _ambiente(""), _addr_doc(""),
|
2019-10-28 12:31:23 +01:00
|
|
|
_tipodoc_escl('A'), _flagprov_escl('P') { }
|
2019-09-10 17:33:59 +02:00
|
|
|
};
|
2019-09-13 17:06:08 +02:00
|
|
|
|
2019-09-10 17:33:59 +02:00
|
|
|
TF9_app& app();
|
|
|
|
|
|
|
|
class TMonitor_mask : public TAutomask
|
|
|
|
{
|
|
|
|
vector<TToken_string> _fppro;
|
2019-09-13 17:06:08 +02:00
|
|
|
friend class TF9_app;
|
2019-09-10 17:33:59 +02:00
|
|
|
|
2019-09-25 17:43:55 +02:00
|
|
|
static bool save_conf_handler(TMask_field& f, KEY key);
|
2019-09-10 17:33:59 +02:00
|
|
|
|
2019-09-13 17:06:08 +02:00
|
|
|
void controllo_errori() const;
|
2019-09-10 17:33:59 +02:00
|
|
|
// Riempie sheet per visualizzare le estrazioni
|
|
|
|
bool on_key(KEY key) override;
|
|
|
|
static void open_win_estr();
|
|
|
|
void open_win_conf() const;
|
|
|
|
|
2019-10-28 12:31:23 +01:00
|
|
|
void fill() const;
|
2019-09-13 17:06:08 +02:00
|
|
|
|
2019-10-28 12:31:23 +01:00
|
|
|
void delete_pack(bool all = false) const;
|
2019-09-13 17:06:08 +02:00
|
|
|
|
|
|
|
void sel() const;
|
2019-10-28 12:31:23 +01:00
|
|
|
void open_mostra_estrazione();
|
2019-09-13 17:06:08 +02:00
|
|
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly) override;
|
2019-09-10 17:33:59 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
TMonitor_mask() : TAutomask("f90100a")
|
|
|
|
{
|
2019-09-13 17:06:08 +02:00
|
|
|
//disable(DLG_FINDREC);
|
2019-09-10 17:33:59 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class TControllo_mask : public TAutomask
|
|
|
|
{
|
2019-09-13 17:06:08 +02:00
|
|
|
char _ordin;
|
|
|
|
char _verso;
|
|
|
|
int _selected_mov;
|
|
|
|
bool _sel_esclusi;
|
|
|
|
bool _is_escluso;
|
|
|
|
TString _id_estr;
|
2019-10-28 12:31:23 +01:00
|
|
|
char _tipo_doc_err{};
|
2019-09-13 17:06:08 +02:00
|
|
|
|
|
|
|
vector<TToken_string>& import_error_list();
|
|
|
|
void fill();
|
2019-09-10 17:33:59 +02:00
|
|
|
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;
|
|
|
|
void conferma_esclusi() const;
|
|
|
|
void associa();
|
|
|
|
|
|
|
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly) override;
|
|
|
|
|
|
|
|
public:
|
2019-09-13 17:06:08 +02:00
|
|
|
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"); }
|
2019-10-28 12:31:23 +01:00
|
|
|
bool send();
|
|
|
|
static void del_err(const TString& id_estr, int get_int);
|
2019-09-13 17:06:08 +02:00
|
|
|
static char get_errori(const TString& id_estr, vector<TToken_string>& movs);
|
|
|
|
TF9_dberr();
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2019-10-16 14:23:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Getters per semplificare i get dai TRecorset
|
|
|
|
|
|
|
|
const TString& recset_get_string(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);
|