326 lines
10 KiB
C++
326 lines
10 KiB
C++
#ifndef __FPLIB_H
|
||
#define __FPLIB_H
|
||
|
||
#include <tsdb.h>
|
||
#include <utility.h>
|
||
#include <config.h>
|
||
|
||
#include "../ve/velib05.h"
|
||
#include "../fe/felib.h"
|
||
#include <reputils.h>
|
||
#include <vector>
|
||
#include <memory>
|
||
#include <map>
|
||
#include <cg2103.h>
|
||
|
||
#define SQL_FLD "sql/"
|
||
|
||
// Ritorna la connessione al DB paf secondo i parametri impostati nel programma di configurazione
|
||
SSimple_query& fp_db();
|
||
// Controlla il livello di patch installato e aggiorna le tabelle se necessario
|
||
bool check_tables();
|
||
// Compila il numero di documento per la scrittura sui paf
|
||
TString& complete_num_fp(const TCodice_numerazione& codnum, const int numdoc);
|
||
// Genera la chiave per i paf
|
||
bool chiave_paf(const TDocumento& doc, TString& hfatt, TString& bfatt);
|
||
bool chiave_paf(const TRectype& doc, TString& hfatt, TString& bfatt);
|
||
// Ritorna cod sdi, pec o vuoto. Chiama get_coddest()
|
||
TString get_dest_sdi(const char tipocf, const long codcf);
|
||
// Valorizza codice sdi e pec in base alle configurazioni del monitor
|
||
bool get_coddest(const char tipocf, const long codcf, TString& coddest, TString& pec);
|
||
inline const TString& no_special(char a);
|
||
const TString& tipo_doc_sdi(const TDocumento& doc);
|
||
|
||
// Controlli comuni
|
||
bool is_fattura(const TRectype& doc);
|
||
// Si potrebbe standardizzare in TISAM_recordset
|
||
TString& add_filter(const TString& field, const TString& from, const TString& to);
|
||
|
||
// Contenitore di campi di un record di database MSSQLServer
|
||
class TPaf_record : public TObject
|
||
{
|
||
TString8 _table;
|
||
TToken_string _key;
|
||
TAssoc_array _fields;
|
||
|
||
protected:
|
||
void copy(const TPaf_record& rec)
|
||
{
|
||
_table = rec._table;
|
||
_key = rec._key;
|
||
_fields = rec._fields;
|
||
}
|
||
|
||
const TString& var2str(const TString& fld, const TVariant& var) const;
|
||
const TVariant& get(const char* fld) const;
|
||
|
||
public:
|
||
void reset() { _fields.destroy(); }
|
||
void set(const char* fld, const TVariant& var);
|
||
void set(const char* fld, long var);
|
||
void set(const char* fld, const char* var);
|
||
void set(const char* fld, const real& var);
|
||
void set(const char* fld, const TString& var);
|
||
void set(const char* fld, const TDate& var);
|
||
void set(const char* fld, bool var);
|
||
const TString sq_get(const char* fld) const;
|
||
|
||
TString& insert_string();
|
||
bool insert();
|
||
TString& remove_string(bool id_riga = false);
|
||
bool remove();
|
||
bool search();
|
||
bool search(const char* k1, const char* k2, const char* k3 = NULL);
|
||
|
||
virtual TObject* dup() const { return new TPaf_record(*this); }
|
||
virtual bool ok() const { return _table.not_empty(); }
|
||
|
||
TPaf_record& operator=(const TPaf_record& rec)
|
||
{
|
||
copy(rec);
|
||
return *this;
|
||
}
|
||
|
||
TPaf_record(const TPaf_record& rec) { copy(rec); }
|
||
TPaf_record(const char* table);
|
||
};
|
||
|
||
// Gestione PAF
|
||
class TDoc_fp : public TObject
|
||
{
|
||
private:
|
||
TRectype* _doc_rec;
|
||
TRectype _rec_clifo;
|
||
TAnagrafica _ditta;
|
||
TString16 _cofi;
|
||
TFilename _dbname;
|
||
TLog_report* _log;
|
||
TString _logpaf;
|
||
bool _gestioneallegati;
|
||
bool _allegafattura;
|
||
TString _def_fld;
|
||
TString _def_usr_fld;
|
||
bool _to_commit;
|
||
bool _cache_insert;
|
||
vector<TString> _query;
|
||
TString8 _hfatt; // Codice univoco di 6 caratteri dell'ufficio P.A. o di 7 caratteri per un privato
|
||
TString _bfatt; // Codice univoco di 20 caratteri del documento
|
||
TString _conai_str;
|
||
TString _paese;
|
||
bool _enapec;
|
||
bool _privato;
|
||
TString _coddest;
|
||
TString _pec;
|
||
TCausale _caus;
|
||
bool _is_pa;
|
||
bool _has_bolla;
|
||
TString _codivadefault;
|
||
long _index_cassa_previdenziale;
|
||
|
||
// Classe interna per gestire righe aggiuntive in riepilogo
|
||
class TRiepilogo_agg
|
||
{
|
||
public:
|
||
real imponibile;
|
||
real imposta;
|
||
TRiepilogo_agg() : imponibile(ZERO), imposta(ZERO){}
|
||
};
|
||
|
||
std::map<TString, TRiepilogo_agg> _riepilogo_agg;
|
||
|
||
struct
|
||
{
|
||
bool _is_valuta_estera {false}; // Se il documento <20> in valuta estera
|
||
TString4 _cod_val;
|
||
real _cambio;
|
||
} _doc_cambio;
|
||
|
||
|
||
int parse_line(const TString& line, TString& var, TString& val) const;
|
||
bool create_table(TScanner& paf, const TString& table);
|
||
|
||
const TRectype* find_parent_row(const TRectype& rdoc) const;
|
||
int find_ancestors(const TRiga_documento& rdoc, TArray& ancestors) const;
|
||
bool insert(TPaf_record& p);
|
||
bool remove(TPaf_record& p);
|
||
bool save_paf();
|
||
|
||
|
||
protected:
|
||
|
||
/**< Funzioni di controllo */
|
||
/**< Controlli di testata, non <20> const per il calcolo della codizione di pagamento */
|
||
bool check_initial(TDocumentoEsteso& doc);
|
||
/**< Controllo di riga */
|
||
bool check_row(const TRiga_documento& rdoc);
|
||
/**< Controllo riepilogo IVA */
|
||
bool check_riepilogo(const TDocumentoEsteso& doc, const TRiepilogo_iva& riva);
|
||
|
||
|
||
bool initialize(TDocumentoEsteso& doc);
|
||
bool parse_sconto(const TString& formula, TToken_string& sconti) const;
|
||
static bool get_bnp_iban(const TString& abi, const TString& cab, int prg, TString& iban);
|
||
bool get_bank(TDocumento& doc, TString& iban, TString& abi, TString& cab, TString& istituto) const;
|
||
bool get_bank_presentazione(const TDocumento& doc, TString& iban, TString& abi, TString& cab, TString& istituto) const;
|
||
bool get_bank_appoggio(const TDocumento& doc, TString& iban, TString& abi, TString& cab, TString& istituto) const;
|
||
const TString& descrizione(const TRiga_documento& rdoc);
|
||
const TRectype& cco(const TRectype& doc) const; // Contratto/Convenzione/Offerta
|
||
|
||
void log(int severity, const char* msg);
|
||
const char* natura(const TString& codiva) const;
|
||
const char* get_esigibilita_iva(const TDocumentoEsteso& doc);
|
||
void set_IVA(TString codiva, TPaf_record& paf) const;
|
||
void set_IVA(const TRiga_documento& rdoc, TPaf_record& paf) const;
|
||
bool add_row_art(long& riga_art, const TString& codice_tipo, const TString& codice_valore, TPaf_record& paf);
|
||
bool add_row_alleg(TFilename& file, long& nprogr, TPaf_record& paf);
|
||
const TString& converti_prezzo(const real& prezzo) const;
|
||
void set_qta_prezzo(TPaf_record& paf1800f, TRiga_documento* rdoc) const;
|
||
void add_ritenuta(const TDocumentoEsteso& doc, const TSpesa_prest& sp, TPaf_record& paf0700f) const;
|
||
bool add_riepilogo_iva(TPaf_record& paf2200f, const TCodiceIVA& cod_iva, const char* eiva, const real& imponibile = ZERO, const real& imposta = ZERO);
|
||
bool add_cassa_previdenziale(TRiga_documento& rdoc);
|
||
|
||
const TFirm& get_firm();
|
||
|
||
bool export_paf0100f();
|
||
bool export_paf3200f();
|
||
|
||
// Record clifo
|
||
void set_rec_clifo(char tipocf, long codcf);
|
||
|
||
public:
|
||
|
||
bool doc_to_paf(TDocumentoEsteso& doc);
|
||
bool doc_to_paf(const TRectype& rec);
|
||
bool doc_to_paf(const TDoc_key& key);
|
||
bool doc_to_paf(const TFilename& ini);
|
||
bool doc_to_paf();
|
||
TRectype& key_to_doc(const TDoc_key& key);
|
||
// Mostra il log a fine esecuzione
|
||
bool show_log();
|
||
const int commit();
|
||
const int force_commit();
|
||
void set_cache_insert(const bool v) { _cache_insert = v; }
|
||
|
||
|
||
TDoc_fp();
|
||
~TDoc_fp();
|
||
};
|
||
|
||
class TFP_settings : public TObject
|
||
{
|
||
public:
|
||
// Getters
|
||
const TString& get_db_indirizzo() const;
|
||
const TString& get_db_database() const;
|
||
const TString& get_db_str_con() const;
|
||
const TString& get_db_user() const;
|
||
const TString& get_db_password() const;
|
||
const TString& get_fld_dest() const;
|
||
const TString& get_fld_dest_usr() const;
|
||
const TString& get_cofi_tras() const;
|
||
const bool get_gest_alleg() const;
|
||
const bool get_allega_fat() const;
|
||
const bool get_esp_pri_empty() const;
|
||
const bool get_esp_est() const;
|
||
const TString& get_esp_est_cod() const;
|
||
const bool is_f8() const;
|
||
const bool get_check_not_block() const;
|
||
|
||
// Setters
|
||
void set_db_indirizzo(const TString& ind) const;
|
||
void set_db_database(const TString& db) const;
|
||
void set_db_user(const TString& usr) const;
|
||
void set_db_password(const TString& psw) const;
|
||
void set_fld_dest(const TString& fld_dest) const;
|
||
void set_fld_dest_usr(const TString& fld_dest_usr) const;
|
||
void set_cofi_tras(const TString& cofi) const;
|
||
void set_gest_alleg(bool gest_alleg) const;
|
||
void set_allega_fat(bool allega_fatt) const;
|
||
void set_esp_pri_empty(bool esp_pri) const;
|
||
void set_esp_est(bool esp_est) const;
|
||
void set_esp_est_cod(const TString& esp_est_cod) const;
|
||
void set_f8(bool f8) const;
|
||
void set_check_not_block(bool not_block) const;
|
||
};
|
||
|
||
inline TFP_settings& fp_settings()
|
||
{
|
||
static TFP_settings* erbuggo = nullptr;
|
||
if(erbuggo == nullptr)
|
||
{
|
||
erbuggo = new TFP_settings();
|
||
}
|
||
return *erbuggo;
|
||
}
|
||
|
||
class TFP_selected_docs : public TObject
|
||
{
|
||
TRelation _r_tabmod;
|
||
TRectype _flt;
|
||
std::unique_ptr<TCursor> _cur;
|
||
TRectype fill_rectype() const;
|
||
|
||
enum { _codnum, _tipodoc, _dastato, _astato, _tiposdi };
|
||
|
||
public:
|
||
void fill_sheet(TSheet_field& sheet) const;
|
||
inline bool has_selected_docs() const { return _cur->items() > 0; }
|
||
void save_sheet(const TSheet_field& sheet) const;
|
||
|
||
TFP_selected_docs();
|
||
};
|
||
|
||
// Typedef per aiutare a capire cosa sono le chiavi
|
||
typedef TString MCodice_riga;
|
||
typedef TString MTipo_documento;
|
||
|
||
// Mannaggia il fruttivendolo
|
||
class TFP_righe_custom : public TObject
|
||
{
|
||
bool _loaded;
|
||
|
||
struct TCustCol
|
||
{
|
||
TString _col_qta;
|
||
// Le colonne prezzo e imp non sono lette se di default
|
||
TString _col_prezzo;
|
||
TString _col_imponibile;
|
||
};
|
||
|
||
// Mappa con in chiave COD_RIGA, TIPO_DOC
|
||
std::map<MCodice_riga, std::map<MTipo_documento, TCustCol>> _custom_table;
|
||
|
||
void load_map();
|
||
static TCustCol& get_no_custom();
|
||
TCustCol& get(const TString& codriga, const TString& tipodoc);
|
||
|
||
public:
|
||
|
||
static void save_sheet(TSheet_field& sheet_field);
|
||
static void load_sheet(TSheet_field& sheet_field);
|
||
|
||
const TString get_qta(const TString& codriga, const TString& tipodoc) { return get(codriga, tipodoc)._col_qta; }
|
||
const TString get_prezzo(const TString& codriga, const TString& tipodoc) { return get(codriga, tipodoc)._col_prezzo; }
|
||
const TString get_imponibile(const TString& codriga, const TString& tipodoc) { return get(codriga, tipodoc)._col_imponibile; }
|
||
|
||
TFP_righe_custom();
|
||
};
|
||
class TFp_mail_sender
|
||
{
|
||
int _anno;
|
||
TString16 _codnum;
|
||
const TTipo_documento* _tipodoc;
|
||
long _ndoc, _codcf;
|
||
|
||
|
||
public:
|
||
void set_doc(const int anno, const long ndoc, const TFixed_string& codnum, const TFixed_string& tipodoc, const long codcf);
|
||
bool genera_pdf();
|
||
void send();
|
||
|
||
TFp_mail_sender() { }
|
||
TFp_mail_sender(const int anno, const long ndoc, const TFixed_string& codnum, const TFixed_string& tipodoc, const long codcf)
|
||
{ set_doc(anno, ndoc, codnum, tipodoc, codcf); }
|
||
};
|
||
#endif // __FPLIB_H
|