Files correlati : fp0.exe, fp0400a.msk Commento : - Corretto calcolo ritenute fiscali se piu di una - Aggiunta colonna ritenute fiscali nel monitor passive
413 lines
9.5 KiB
C++
413 lines
9.5 KiB
C++
#include "f1lib.h"
|
|
#include "config.h"
|
|
#include "modaut.h"
|
|
#include "cg2103.h"
|
|
#include "cg2102.h"
|
|
#include "execp.h"
|
|
#include "cfven.h"
|
|
#include "reputils.h"
|
|
#include "causali.h"
|
|
#include "clifo.h"
|
|
#include "../fp/fplib.h"
|
|
|
|
//////////////////////////////////////////////////////////
|
|
// TFppro
|
|
//////////////////////////////////////////////////////////
|
|
|
|
TFppro& fppro_db()
|
|
{
|
|
static TFppro* fppro = nullptr;
|
|
if (fppro == nullptr)
|
|
fppro = new TFppro();
|
|
return *fppro;
|
|
}
|
|
|
|
bool TFppro::check_reg(TToken_string& keys, int numreg)
|
|
{
|
|
return get_numreg(keys) == numreg;
|
|
}
|
|
|
|
bool TFppro::guess_the_doc(const TLocalisamfile& mov)
|
|
{
|
|
// Controllo datadoc - numdoc - totdoc - p.iva
|
|
TString query;
|
|
query << "SELECT PQ_KEYPRGINVIO AS KEYPRGINVIO, PQ_KEYHEADERFATT AS KEYHEADERFATT, PQ_KEYBODYFATT AS KEYBODYFATT, P7_DATA AS DATA,\n" <<
|
|
"\tP7_NUMERO AS NUMDOC, PQ_IMPTOTDOC AS IMPTOTDOC, P2_FISCIVAPAESE AS STATOPIVA, P2_FISCIVACOD AS PIVA FROM PAA2700F\n" <<
|
|
"JOIN PAA0700F ON PQ_KEYPRGINVIO = P7_KEYPRGINVIO AND PQ_KEYHEADERFATT = P7_KEYHEADERFATT AND PQ_KEYBODYFATT = P7_KEYBODYFATT\n" <<
|
|
"JOIN PAA0200F ON PQ_KEYPRGINVIO = P2_KEYPRGINVIO AND PQ_KEYHEADERFATT = P2_KEYHEADERFATT AND PQ_KEYBODYFATT = P2_KEYBODYFATT\n";
|
|
_db->sq_set_exec(query);
|
|
|
|
const keys_s keys = { _db->sq_get("KEYPRGINVIO"), _db->sq_get("KEYHEADERFATT"), _db->sq_get("KEYBODYFATT") };
|
|
const TDate data = _db->sq_get_date("DATA");
|
|
const TString numdoc = _db->sq_get("NUMDOC");
|
|
const real imptotdoc(_db->sq_get("IMPTOTDOC"));
|
|
const TString4 statopiva = _db->sq_get("STATOPIVA");
|
|
const TString piva = _db->sq_get("PIVA");
|
|
|
|
// Prendo il fornitore del mov per controllare la p.iva
|
|
TLocalisamfile clifo(LF_CLIFO);
|
|
clifo.put(CLI_TIPOCF, "F");
|
|
const TString& codforn = mov.get(MOV_CODCF);
|
|
clifo.put(CLI_CODCF, codforn);
|
|
clifo.read();
|
|
TString cli_statopiva, cli_piva;
|
|
cli_statopiva << clifo.get(CLI_STATOPAIV);
|
|
cli_piva << clifo.get(CLI_PAIV);
|
|
|
|
bool ok = data == mov.get_date(MOV_DATAREG);
|
|
ok &= numdoc == mov.get(MOV_NUMDOC) || numdoc == mov.get(MOV_NUMDOCEXT);
|
|
ok &= imptotdoc == real(mov.get(MOV_TOTDOC));
|
|
ok &= cli_statopiva.full() && statopiva == cli_statopiva && piva == cli_piva || !cli_statopiva.full() && piva == cli_piva;
|
|
if (ok)
|
|
{
|
|
_keys = keys;
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
void TFppro::get_keys_fppro()
|
|
{
|
|
|
|
}
|
|
|
|
int TFppro::get_numreg()
|
|
{
|
|
if (!_is_set)
|
|
{
|
|
if (set_query())
|
|
return _db->sq_get_int("PZ_NUMREGCONT");
|
|
return -1;
|
|
}
|
|
return _db->sq_get_int("PZ_NUMREGCONT");
|
|
}
|
|
|
|
int TFppro::get_numreg(TToken_string& keys)
|
|
{
|
|
set_keys(keys);
|
|
return get_numreg();
|
|
}
|
|
|
|
TDate TFppro::get_datareg()
|
|
{
|
|
if (!_is_set)
|
|
{
|
|
if (set_query())
|
|
return _db->sq_get_date("PZ_DATAREGCONT");
|
|
return TDate();
|
|
}
|
|
return _db->sq_get_date("PZ_DATAREGCONT");
|
|
}
|
|
|
|
TDate TFppro::get_datareg(TToken_string& keys)
|
|
{
|
|
set_keys(keys);
|
|
if (_is_set)
|
|
return get_datareg();
|
|
return TDate();
|
|
}
|
|
|
|
real TFppro::get_ritenute() const
|
|
{
|
|
real imp = ZERO;
|
|
TString query;
|
|
query << "SELECT P7_IMPORTORIT AS IMPORTO FROM PAA0700F\n" <<
|
|
"WHERE P7_KEYPRGINVIO = '" << _keys.prginvio << "' AND P7_KEYHEADERFATT = '" << _keys.headerfatt << "' AND P7_KEYBODYFATT = '" << _keys.bodyfatt << "'";
|
|
_db->sq_set_exec(query, false);
|
|
for(bool ok = _db->sq_next(); ok; ok = _db->sq_next())
|
|
imp += _db->sq_get_real("IMPORTO");
|
|
return imp;
|
|
}
|
|
|
|
TFppro& TFppro::set_keys(TToken_string& keys)
|
|
{
|
|
if(keys.items() == 3)
|
|
{
|
|
_keys.prginvio = keys.get(0);
|
|
_keys.headerfatt = keys.get(1);
|
|
_keys.bodyfatt = keys.get(2);
|
|
_is_set = false;
|
|
_keys_setted = true;
|
|
}
|
|
_keys_setted = false;
|
|
return *this;
|
|
}
|
|
|
|
TFppro& TFppro::set_keys(keys_s keys)
|
|
{
|
|
if(*keys.prginvio != 0 && *keys.headerfatt != 0 && *keys.bodyfatt != 0)
|
|
{
|
|
_keys = keys;
|
|
_is_set = false;
|
|
_keys_setted = true;
|
|
}
|
|
_is_set = false;
|
|
_keys_setted = false;
|
|
return *this;
|
|
}
|
|
|
|
TDate TFppro::get_data_first_doc() const
|
|
{
|
|
TString query;
|
|
query << "SELECT min(a.DATA) AS DATA \nFROM( \n\tSELECT P7_DATA as DATA \n" <<
|
|
"\tFROM PAA0700F \n\tUNION \n\tSELECT P7_DATA as DATA \n\tFROM PAF0700F \n) a";
|
|
_db->sq_set_exec(query);
|
|
return _db->sq_get_date("DATA");
|
|
}
|
|
|
|
bool TFppro::set_query()
|
|
{
|
|
if (_keys_setted)
|
|
{
|
|
_fppro_query.cut(0) << "SELECT * FROM FPPRO00F " << where_str();
|
|
return _is_set = _db->sq_set_exec(_fppro_query);
|
|
}
|
|
return _is_set = false;
|
|
}
|
|
|
|
const char* TFppro::where_str() const
|
|
{
|
|
TString str;
|
|
str << " WHERE PZ_KEYPRGINVIO = '" << _keys.prginvio << "' AND PZ_KEYHEADERFATT = '" << _keys.headerfatt << "' AND PZ_KEYBODYFATT = '" << _keys.bodyfatt << "'";
|
|
return str;
|
|
}
|
|
|
|
TFppro::TFppro() : _keys({ "\0", "\0", "\0" }), _guess(false), _keys_setted(false), _is_set(false)
|
|
{
|
|
_db = new SSimple_query();
|
|
const bool ok = set_connection(*_db);
|
|
// Non utilizzo l'autocommit, viene gestito manualmente
|
|
if (ok) _db->sq_set_autocommit(false);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////
|
|
// TProtocollo
|
|
//////////////////////////////////////////////////////////
|
|
|
|
TString& TProtocollo::prot_in(const int year, const char* tipoprot, const char* progres)
|
|
{
|
|
static TString protocollo;
|
|
TString tipo(tipoprot);
|
|
if (tipo.empty())
|
|
tipo << "no_prot";
|
|
protocollo.cut(0) << year << "-" << tipo << "/" << progres;
|
|
return protocollo;
|
|
}
|
|
|
|
void TProtocollo::set(const TProtocollo prot)
|
|
{
|
|
_year = prot._year;
|
|
_tipoprot = prot._tipoprot;
|
|
_progres = prot._progres;
|
|
}
|
|
|
|
void TProtocollo::sset(const char* prot)
|
|
{
|
|
TToken_string tok(prot, '-');
|
|
_year = tok.get_int();
|
|
TToken_string p(tok.get(), '/');
|
|
_tipoprot = p.get();
|
|
_progres = p.get();
|
|
}
|
|
|
|
TString& TProtocollo::get_prot() const
|
|
{
|
|
return prot_in(_year, _tipoprot, _progres);
|
|
}
|
|
|
|
void set_ini_codcaus(const TString& codcaus)
|
|
{
|
|
ini_set_string(FILE_CONFIG, FILE_SECTION, F1_CAUS, codcaus);
|
|
}
|
|
|
|
const char* get_ini_codcaus()
|
|
{
|
|
return ini_get_string(FILE_CONFIG, FILE_SECTION, F1_CAUS);
|
|
}
|
|
|
|
const char* get_codcaus(const char * tipodoc, const char* codcf)
|
|
{
|
|
TLocalisamfile cfven(LF_CFVEN);
|
|
cfven.put(CFV_TIPOCF, "F");
|
|
cfven.put(CFV_CODCF, codcf);
|
|
const char* codcaus = "";
|
|
const char* codcausnc = "";
|
|
const bool nc = TString(tipodoc) == "TD04";
|
|
|
|
if (cfven.read() == NOERR)
|
|
{
|
|
codcaus = cfven.get(CFV_CODCAUS);
|
|
codcausnc = cfven.get(CFV_CODCAUSNC);
|
|
}
|
|
|
|
if (nc)
|
|
{
|
|
if (!TString(codcausnc).empty())
|
|
return codcausnc;
|
|
}
|
|
else
|
|
{
|
|
if (!TString(codcaus).empty())
|
|
return codcaus;
|
|
}
|
|
return get_ini_codcaus();
|
|
}
|
|
|
|
bool get_endatareg()
|
|
{
|
|
return ini_get_bool(FILE_CONFIG, FILE_SECTION, "endatareg");
|
|
}
|
|
|
|
TString get_datainireg()
|
|
{
|
|
return ini_get_string(FILE_CONFIG, FILE_SECTION, "datainireg");
|
|
}
|
|
|
|
TString get_dataendreg()
|
|
{
|
|
return ini_get_string(FILE_CONFIG, FILE_SECTION, "dataendreg");
|
|
}
|
|
|
|
bool get_periodprec()
|
|
{
|
|
return ini_get_bool(CONFIG_DITTA, FILE_SECTION, "flag_periodprec");
|
|
}
|
|
|
|
void set_endatareg(bool enable)
|
|
{
|
|
ini_set_bool(FILE_CONFIG, FILE_SECTION, "endatareg", enable);
|
|
}
|
|
|
|
void set_datainireg(const TString& date)
|
|
{
|
|
ini_set_string(FILE_CONFIG, FILE_SECTION, "datainireg", date);
|
|
}
|
|
|
|
void set_dataendreg(const TString& date)
|
|
{
|
|
ini_set_string(FILE_CONFIG, FILE_SECTION, "dataendreg", date);
|
|
}
|
|
|
|
void set_periodprec(bool flag)
|
|
{
|
|
ini_set_bool(CONFIG_DITTA, FILE_SECTION, "flag_periodprec", flag);
|
|
}
|
|
|
|
bool check_causale(const TString& cod_caus, bool acq)
|
|
{
|
|
return
|
|
check_causale(cod_caus, "FA", acq) ||
|
|
check_causale(cod_caus, "BD", acq) ||
|
|
check_causale(cod_caus, "AF", acq) ||
|
|
check_causale(cod_caus, "FF", acq) ||
|
|
check_causale(cod_caus, "NC", acq) ||
|
|
check_causale(cod_caus, "ND", acq);
|
|
}
|
|
|
|
bool check_causale(const TString& cod_caus, const TString& tipo_doc, bool acq)
|
|
{
|
|
const TCausale caus(cod_caus);
|
|
|
|
if(tipo_doc == "FA" || tipo_doc == "BD" || tipo_doc == "AF" || tipo_doc == "FF")
|
|
return caus.tipo_doc() == tipo_doc;
|
|
|
|
if (tipo_doc == "NC" || tipo_doc == "ND")
|
|
{
|
|
bool nota;
|
|
bool nota_iva = false;
|
|
if ((nota = caus.tipo_doc() == tipo_doc))
|
|
{
|
|
if (acq)
|
|
nota_iva = caus.reg().tipo() == iva_acquisti;
|
|
else
|
|
nota_iva = caus.reg().tipo() == iva_vendite;
|
|
}
|
|
return nota && nota_iva;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool check_caus_has_rit(const TString& cod_caus, bool rit)
|
|
{
|
|
TLocalisamfile causali(LF_CAUSALI);
|
|
causali.put(CAU_CODCAUS, cod_caus);
|
|
causali.read();
|
|
return *causali.get(CAU_M770) != '\0';
|
|
}
|
|
|
|
void run_cont_ini(bool liq)
|
|
{
|
|
static TString run_string;
|
|
#ifdef DBG
|
|
run_string.cut(0) << "cg2 -0 -i" << F1_INIREGCONT << "*" << ".ini" << " -f1" << (liq? " -liq" : " ") << " /u" << user();
|
|
#else
|
|
run_string.cut(0) << "cg2 -0 -i" << TFilename().tempdir() << "\\" << F1_INIREGCONT << "*" << ".ini" << " -f1" << (liq ? " -liq" : " ") << " /u" << user();
|
|
#endif
|
|
TExternal_app(run_string).run();
|
|
}
|
|
|
|
void TF1_log::log(int severity, const char* msg)
|
|
{
|
|
if (_log == nullptr)
|
|
{
|
|
_log = new TLog_report("Stato contabilizzazione:");
|
|
// Tento l'eliminazione del file
|
|
std::remove("f1_cg.log");
|
|
}
|
|
|
|
static TString txt;
|
|
txt.cut(0) << msg;
|
|
_log->log(severity, txt);
|
|
// Scrivo anche su file
|
|
std::filebuf fb;
|
|
fb.open("f1_cg.log", std::ios::out | std::ios::app);
|
|
std::ostream os(&fb);
|
|
os << txt << std::endl;
|
|
fb.close();
|
|
}
|
|
|
|
bool TF1_log::show_log()
|
|
{
|
|
if (_log)
|
|
{
|
|
_log->preview();
|
|
delete _log;
|
|
_log = NULL;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool TFppro::set_connection(SSimple_query& s)
|
|
{
|
|
bool ok = true;
|
|
#ifdef DBG
|
|
TString ip = fp_settings().get_db_indirizzo();
|
|
if (ip.upper() != "TESTCAMPO2012")
|
|
{
|
|
if (s.sq_connect("TESTCAMPO2012@campo_fp",
|
|
"fp",
|
|
"fp",
|
|
TSDB_MSSQL) != NOERR)
|
|
{
|
|
warning_box("Impossibile connettersi al DB esterno");
|
|
ok = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
#endif
|
|
if (s.sq_connect(
|
|
fp_settings().get_db_str_con(),
|
|
fp_settings().get_db_user(),
|
|
fp_settings().get_db_password(),
|
|
TSDB_MSSQL) != NOERR)
|
|
{
|
|
warning_box("Impossibile connettersi al DB esterno");
|
|
ok = false;
|
|
}
|
|
#ifdef DBG
|
|
}
|
|
#endif
|
|
return ok;
|
|
} |