Patch level : 12.0 1140
Files correlati : cg2.exe cg2100c.msk cg2100t.msk Commento: Nelle fatture intra l'identificativo SDI viene recuperato da FPPRO e scritto sulla fattura di acquisto e sulla regolarizzazione
This commit is contained in:
		
							parent
							
								
									1a185af541
								
							
						
					
					
						commit
						702d5a3c92
					
				
							
								
								
									
										293
									
								
								src/f1/f1lib.cpp
									
									
									
									
									
								
							
							
						
						
									
										293
									
								
								src/f1/f1lib.cpp
									
									
									
									
									
								
							@ -20,20 +20,14 @@ TFppro& fppro_db()
 | 
			
		||||
	return *fppro;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TFppro::sql_inj(const TString& str)
 | 
			
		||||
{
 | 
			
		||||
  TString appo; appo << str;
 | 
			
		||||
  appo.upper();
 | 
			
		||||
  return appo.contains("--") || appo.contains("SELECT") || appo.contains("DELETE") || appo.contains("DROP");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TFppro::sql_inj(const keys_s& keys)
 | 
			
		||||
bool TFppro::sql_inj(TToken_string& keys)
 | 
			
		||||
{
 | 
			
		||||
  TToken_string str("", ';');
 | 
			
		||||
  str.add(keys.prginvio);
 | 
			
		||||
  str.add(keys.headerfatt);
 | 
			
		||||
  str.add(keys.bodyfatt);
 | 
			
		||||
  return sql_inj(str);
 | 
			
		||||
 | 
			
		||||
  str.add(keys.get(0));
 | 
			
		||||
  str.add(keys.get(1));
 | 
			
		||||
  str.add(keys.get(2));
 | 
			
		||||
  return str.contains("--") || str.contains("SELECT") || str.contains("DELETE") || str.contains("DROP");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TFppro::check_reg(TToken_string& keys, int numreg)
 | 
			
		||||
@ -44,68 +38,74 @@ bool TFppro::check_reg(TToken_string& keys, int numreg)
 | 
			
		||||
bool TFppro::guess_the_doc(const TLocalisamfile& mov)
 | 
			
		||||
{
 | 
			
		||||
	// 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);
 | 
			
		||||
  TCli_for forn = cached_clifor('F', mov.get_long(MOV_CODCF));
 | 
			
		||||
 | 
			
		||||
  const TString4 statopiva(forn.get(CLI_STATOPAIV));
 | 
			
		||||
	
 | 
			
		||||
	const real tot = mov.get_real(MOV_TOTDOC) + mov.get_real(MOV_RITFIS) + mov.get_real(MOV_RITSOC);
 | 
			
		||||
  TString numdoc = mov.get(MOV_NUMDOCEXT);
 | 
			
		||||
 | 
			
		||||
  if (numdoc.empty())
 | 
			
		||||
    numdoc = mov.get(MOV_NUMDOC);
 | 
			
		||||
	// 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" <<
 | 
			
		||||
    "WHERE P7_DATA = '" << mov.get_date(MOV_DATADOC).date2ansi() << "' AND \n" <<
 | 
			
		||||
		"(P7_NUMERO = '" << numdoc << "' OR P7_NUMERO LIKE '%" << numdoc << "%') AND \n" <<
 | 
			
		||||
		(cli_statopiva.full() ? TString("P2_FISCIVAPAESE = '") << cli_statopiva << "' AND " : "") <<
 | 
			
		||||
    "P2_FISCIVACOD = '" << cli_piva << "' AND \n" << "PQ_IMPTOTDOC = " << tot;
 | 
			
		||||
    "(P7_NUMERO = '" << numdoc << "' OR P7_NUMERO LIKE '%" << numdoc << "%') \n";
 | 
			
		||||
  if (statopiva.full())
 | 
			
		||||
    query << "' AND \n" << "P2_FISCIVAPAESE = '" << statopiva;
 | 
			
		||||
  query << "' AND \n" << "P2_FISCIVACOD = '" << forn.get(CLI_PAIV);
 | 
			
		||||
  if (forn.gruppo_IVA())
 | 
			
		||||
    query << "' AND \n" "P2_COCAZZO = '" << forn.get(CLI_COFI); // cazzo;
 | 
			
		||||
  query << "PQ_IMPTOTDOC = " << tot;
 | 
			
		||||
 | 
			
		||||
	if (_db->sq_set_exec(query) && _db->sq_items() == 1)
 | 
			
		||||
	{
 | 
			
		||||
		_keys = { _db->sq_get("KEYPRGINVIO"), _db->sq_get("KEYHEADERFATT"), _db->sq_get("KEYBODYFATT") };
 | 
			
		||||
    _keys = _db->sq_get("KEYPRGINVIO");
 | 
			
		||||
    _keys.add(_db->sq_get("KEYHEADERFATT"));
 | 
			
		||||
    _keys.add(_db->sq_get("KEYBODYFATT"));
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
		
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* TFppro::get_keys_fppro() const
 | 
			
		||||
const char* TFppro::get_keys_fppro()
 | 
			
		||||
{
 | 
			
		||||
	static TString keys;
 | 
			
		||||
	keys.cut(0) << _keys.prginvio << ";" << _keys.headerfatt << ";" << _keys.bodyfatt;
 | 
			
		||||
	return (const char*)keys;
 | 
			
		||||
	TString& keys = get_tmp_string(64);
 | 
			
		||||
 | 
			
		||||
	keys.cut(0) << _keys.get(0) << ";" << _keys.get(1) << ";" << _keys.get(2);
 | 
			
		||||
	return keys;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int TFppro::get_numreg()
 | 
			
		||||
long TFppro::get_numreg()
 | 
			
		||||
{
 | 
			
		||||
	if (!_is_set)
 | 
			
		||||
	{
 | 
			
		||||
		if (set_query())
 | 
			
		||||
			return _db->sq_get_int("PZ_NUMREGCONT");
 | 
			
		||||
			return _db->sq_get_long("PZ_NUMREGCONT");
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
	return _db->sq_get_int("PZ_NUMREGCONT");
 | 
			
		||||
	return _db->sq_get_long("PZ_NUMREGCONT");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int TFppro::get_numreg(TToken_string& keys)
 | 
			
		||||
long TFppro::get_numreg(TToken_string& keys)
 | 
			
		||||
{
 | 
			
		||||
	set_keys(keys);
 | 
			
		||||
	return get_numreg();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TString TFppro::get_codforn() const
 | 
			
		||||
long TFppro::get_codforn()
 | 
			
		||||
{
 | 
			
		||||
	TString query;
 | 
			
		||||
 | 
			
		||||
	query << "SELECT PZ_CLIFOR FROM FPPRO00F\n" << where_str();
 | 
			
		||||
	_db->sq_set_exec(query);
 | 
			
		||||
	return _db->sq_get("PZ_CLIFOR");
 | 
			
		||||
	return _db->sq_get_long("PZ_CLIFOR");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TDate TFppro::get_datareg()
 | 
			
		||||
@ -127,12 +127,13 @@ TDate TFppro::get_datareg(TToken_string& keys)
 | 
			
		||||
	return TDate();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
real TFppro::get_ritenute() const
 | 
			
		||||
real TFppro::get_ritenute()
 | 
			
		||||
{
 | 
			
		||||
	real imp = ZERO;
 | 
			
		||||
	real imp;
 | 
			
		||||
	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 << "'";
 | 
			
		||||
		"WHERE P7_KEYPRGINVIO = '" << _keys.get(0) << "' AND P7_KEYHEADERFATT = '" << _keys.get(1) << "' AND P7_KEYBODYFATT = '" << _keys.get(2) << "'";
 | 
			
		||||
	_db->sq_set_exec(query, false);
 | 
			
		||||
	for(bool ok = _db->sq_next(); ok; ok = _db->sq_next())
 | 
			
		||||
		imp += _db->sq_get_real("IMPORTO");
 | 
			
		||||
@ -140,66 +141,69 @@ real TFppro::get_ritenute() const
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TFppro& TFppro::set_keys(TToken_string& keys)
 | 
			
		||||
{
 | 
			
		||||
  if (keys.items() == 3)
 | 
			
		||||
  {
 | 
			
		||||
    const keys_s k = { keys.get(0), keys.get(1), keys.get(2) };
 | 
			
		||||
    return set_keys(k);
 | 
			
		||||
  }
 | 
			
		||||
  _is_set       = false;
 | 
			
		||||
	_keys_setted  = false;
 | 
			
		||||
  return *this;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TFppro& TFppro::set_keys(const keys_s& keys)
 | 
			
		||||
{
 | 
			
		||||
  if (sql_inj(keys))
 | 
			
		||||
  {
 | 
			
		||||
    TString msg; msg << "Database error: Possibile SQL INJECTION:\n" << keys;
 | 
			
		||||
    //throw std::exception(msg);
 | 
			
		||||
;
 | 
			
		||||
    error_box(msg);
 | 
			
		||||
    _last_error.cut(0) << msg;
 | 
			
		||||
  }
 | 
			
		||||
  else if (!keys.prginvio.empty() && !keys.headerfatt.empty() && !keys.bodyfatt.empty())
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    TString prginvio = keys.get(0);
 | 
			
		||||
    TString headerfatt = keys.get(1);
 | 
			
		||||
    TString bodyfatt = keys.get(2);
 | 
			
		||||
 | 
			
		||||
    if (prginvio.full() && headerfatt.full() && bodyfatt.full())
 | 
			
		||||
    {
 | 
			
		||||
      _keys = keys;
 | 
			
		||||
      _keys_setted = true;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
    _last_error.cut(0) << "Chiavi settate non valide:\n" << keys;
 | 
			
		||||
      _last_error = "Chiavi settate non valide:\n";
 | 
			
		||||
      _last_error << keys;
 | 
			
		||||
      _keys_setted = false;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  _is_set = false;
 | 
			
		||||
	return *this;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TFppro::associa_mov(const int numreg) const
 | 
			
		||||
bool TFppro::associa_mov(const long numreg)
 | 
			
		||||
{
 | 
			
		||||
	bool ok;
 | 
			
		||||
	TLocalisamfile mov(LF_MOV);
 | 
			
		||||
	mov.put(MOV_NUMREG, numreg);
 | 
			
		||||
	if ((ok = mov.read() == NOERR))
 | 
			
		||||
	{
 | 
			
		||||
		mov.put(MOV_KEYFPPRO, get_keys_fppro());
 | 
			
		||||
		if ((ok = mov.rewrite() == NOERR))	// Scrivo sul movimento il riferimento al fppro
 | 
			
		||||
	TRectype &  mov = (TRectype &) cache().get(LF_MOV, numreg);
 | 
			
		||||
	bool ok = mov.full();
 | 
			
		||||
 | 
			
		||||
  if (ok)
 | 
			
		||||
	{
 | 
			
		||||
		TString query;
 | 
			
		||||
		query << "UPDATE FPPRO00F \nSET " <<
 | 
			
		||||
			"PZ_TIPOCF = 'F', PZ_CLIFOR = '" << mov.get(MOV_CODCF) << "', PZ_NUMREGCONT = '" <<
 | 
			
		||||
			mov.get(MOV_NUMREG) << "', PZ_DATAREGCONT = '" << mov.get_date(MOV_DATAREG).date2ansi() << "'\n" <<
 | 
			
		||||
			fppro_db().where_str() << ";";
 | 
			
		||||
			if (!((ok = _db->sq_set_exec(query) && _db->sq_commit())))	// Se la scrittura sul db fallisce levo sul movimento il riferimento all'fppro
 | 
			
		||||
		ok = _db->sq_set_exec(query) && _db->sq_commit();
 | 
			
		||||
 | 
			
		||||
		if (ok) 	// Scrivo sul movimento il riferimento al fppro
 | 
			
		||||
		{
 | 
			
		||||
				mov.put(MOV_KEYFPPRO, "");
 | 
			
		||||
				mov.rewrite();
 | 
			
		||||
			mov.put(MOV_IDDOCSDI, fppro_db().get_numdoc());
 | 
			
		||||
			mov.put(MOV_DATADOCSDI, fppro_db().get_numdoc());
 | 
			
		||||
			mov.put(MOV_KEYFPPRO, get_keys_fppro());
 | 
			
		||||
			ok = mov.rewrite() == NOERR;
 | 
			
		||||
		}
 | 
			
		||||
		else   // Se la scrittura sul db fallisce levo sul movimento il riferimento all'fppro
 | 
			
		||||
		{
 | 
			
		||||
			mov.zero(MOV_IDDOCSDI);
 | 
			
		||||
			mov.zero(MOV_DATADOCSDI);
 | 
			
		||||
			mov.zero(MOV_KEYFPPRO);
 | 
			
		||||
			mov.rewrite();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* TFppro::get_tipoprot() const
 | 
			
		||||
const TString & TFppro::get_tipoprot()
 | 
			
		||||
{
 | 
			
		||||
	TString query;
 | 
			
		||||
 | 
			
		||||
@ -208,80 +212,98 @@ const char* TFppro::get_tipoprot() const
 | 
			
		||||
	return _db->sq_get("TIPOPROT");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* TFppro::get_numprot() const
 | 
			
		||||
const TString & TFppro::get_numprot()
 | 
			
		||||
{
 | 
			
		||||
	TString query;
 | 
			
		||||
	static TString num;
 | 
			
		||||
 | 
			
		||||
	query << "SELECT PZ_NUMPROT AS NUMPROT FROM FPPRO00F\r\n" << where_str();
 | 
			
		||||
	_db->sq_set_exec(query);
 | 
			
		||||
	return num.cut(0) = _db->sq_get("NUMPROT");
 | 
			
		||||
 | 
			
		||||
  return _db->sq_get("NUMPROT");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* TFppro::get_annoprot() const
 | 
			
		||||
const TString & TFppro::get_annoprot()
 | 
			
		||||
{
 | 
			
		||||
	TString query;
 | 
			
		||||
	static TString anno;
 | 
			
		||||
 | 
			
		||||
	query << "SELECT PZ_ANNOPROT AS ANNOPROT FROM FPPRO00F\r\n" << where_str();
 | 
			
		||||
	_db->sq_set_exec(query);
 | 
			
		||||
	return anno.cut(0) = _db->sq_get("ANNOPROT");
 | 
			
		||||
  return _db->sq_get("ANNOPROT");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* TFppro::get_dataoraric() const
 | 
			
		||||
const TString & TFppro::get_dataoraric()
 | 
			
		||||
{
 | 
			
		||||
	TString query;
 | 
			
		||||
	static TString data;
 | 
			
		||||
  TString & data = get_tmp_string(16);
 | 
			
		||||
	
 | 
			
		||||
  query << "SELECT PZ_DATAORARIC AS DATAORARIC FROM FPPRO00F\r\n" << where_str();
 | 
			
		||||
	_db->sq_set_exec(query);
 | 
			
		||||
	return data.cut(0) << _db->sq_get_date("DATAORARIC").date2ansi();
 | 
			
		||||
  data << _db->sq_get_date("DATAORARIC").date2ansi();
 | 
			
		||||
  return data;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* TFppro::get_tipodoc() const
 | 
			
		||||
const TString & TFppro::get_tipodoc()
 | 
			
		||||
{
 | 
			
		||||
	TString query;
 | 
			
		||||
	static TString tipodoc;
 | 
			
		||||
 | 
			
		||||
	query << "SELECT PZ_TIPODOC AS TIPODOC FROM FPPRO00F\r\n" << where_str();
 | 
			
		||||
	_db->sq_set_exec(query);
 | 
			
		||||
	return tipodoc.cut(0) << _db->sq_get("TIPODOC");
 | 
			
		||||
	return _db->sq_get("TIPODOC");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* TFppro::get_numdoc() const
 | 
			
		||||
const TString & TFppro::get_numdoc()
 | 
			
		||||
{
 | 
			
		||||
  TString query;
 | 
			
		||||
  static TString numdoc;
 | 
			
		||||
 | 
			
		||||
  query << "SELECT PZ_NUMERO AS NUMDOC FROM FPPRO00F\r\n" << where_str();
 | 
			
		||||
  _db->sq_set_exec(query);
 | 
			
		||||
  return numdoc.cut(0) << _db->sq_get("NUMDOC");
 | 
			
		||||
  return _db->sq_get("NUMDOC");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TDate TFppro::get_dataorarioric() const
 | 
			
		||||
TDate TFppro::get_data_doc()
 | 
			
		||||
{
 | 
			
		||||
	TString query;
 | 
			
		||||
 | 
			
		||||
	query << "SELECT PZ_DATA  FROM FPPRO00F\r\n" << where_str();
 | 
			
		||||
	_db->sq_set_exec(query);
 | 
			
		||||
	return _db->sq_get_date("PZ_DATA");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
TDate TFppro::get_dataorarioric()
 | 
			
		||||
{
 | 
			
		||||
	TString query;
 | 
			
		||||
 | 
			
		||||
	query << "SELECT P1_DATAORARIC \nFROM PAA0100F \n" << 
 | 
			
		||||
		"WHERE P1_KEYPRGINVIO = '" << _keys.prginvio << "' AND P1_KEYHEADERFATT = '" << _keys.headerfatt << "' AND P1_KEYBODYFATT = '" << _keys.bodyfatt << "'";
 | 
			
		||||
		"WHERE P1_KEYPRGINVIO = '" << _keys.get(0) << "' AND P1_KEYHEADERFATT = '" << _keys.get(1) << "' AND P1_KEYBODYFATT = '" << _keys.get(2) << "'";
 | 
			
		||||
	_db->sq_set_exec(query);
 | 
			
		||||
	return _db->sq_get_date("P1_DATAORARIC");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int TFppro::get_numregcont() const
 | 
			
		||||
long TFppro::get_numregcont()
 | 
			
		||||
{
 | 
			
		||||
	TString query;
 | 
			
		||||
 | 
			
		||||
	query << "SELECT PZ_NUMREGCONT FROM FPPRO00F\n" << where_str();
 | 
			
		||||
	_db->sq_set_exec(query);
 | 
			
		||||
	return _db->sq_get_int("PZ_NUMREGCONT");
 | 
			
		||||
	return _db->sq_get_long("PZ_NUMREGCONT");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TString TFppro::get_last_error(bool clear)
 | 
			
		||||
{
 | 
			
		||||
  TString l(_last_error);
 | 
			
		||||
  TString & l = get_tmp_string(128);
 | 
			
		||||
    
 | 
			
		||||
  l = _last_error;
 | 
			
		||||
  if(clear)
 | 
			
		||||
    _last_error.cut(0);
 | 
			
		||||
  return l;
 | 
			
		||||
@ -297,14 +319,14 @@ bool TFppro::set_query()
 | 
			
		||||
	return _is_set = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* TFppro::where_str() const
 | 
			
		||||
const char* TFppro::where_str()
 | 
			
		||||
{
 | 
			
		||||
	static TString str;
 | 
			
		||||
	str.cut(0) << " WHERE PZ_KEYPRGINVIO = '" << _keys.prginvio << "' AND PZ_KEYHEADERFATT = '" << _keys.headerfatt << "' AND PZ_KEYBODYFATT = '" << _keys.bodyfatt << "'";
 | 
			
		||||
	str.cut(0) << " WHERE PZ_KEYPRGINVIO = '" << _keys.get(0) << "' AND PZ_KEYHEADERFATT = '" << _keys.get(1) << "' AND PZ_KEYBODYFATT = '" << _keys.get(2) << "'";
 | 
			
		||||
	return str;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TFppro::TFppro() : _keys({ "\0", "\0", "\0" }), _keys_setted(false), _is_set(false)
 | 
			
		||||
TFppro::TFppro() : _keys("", ';'), _keys_setted(false), _is_set(false)
 | 
			
		||||
{
 | 
			
		||||
	_db = new SSimple_query();
 | 
			
		||||
	const bool ok = set_connection(*_db);
 | 
			
		||||
@ -322,13 +344,14 @@ prot_s TProtocollo::get_prot()
 | 
			
		||||
	return prot;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TString& TProtocollo::prot_in(const int year, const char* tipoprot, const char* progres)
 | 
			
		||||
const TString& TProtocollo::prot_in(const int year, const char* tipoprot, const char* progres) const
 | 
			
		||||
{
 | 
			
		||||
	static TString protocollo;
 | 
			
		||||
	TString & protocollo = get_tmp_string(128);
 | 
			
		||||
	TString tipo(tipoprot);
 | 
			
		||||
 | 
			
		||||
	if (tipo.empty())
 | 
			
		||||
		tipo << "no_prot";
 | 
			
		||||
	protocollo.cut(0) << year << "-" << tipo << "/" << progres;
 | 
			
		||||
	protocollo << year << "-" << tipo << "/" << progres;
 | 
			
		||||
	return protocollo;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -348,7 +371,7 @@ void TProtocollo::sset(const char* prot)
 | 
			
		||||
	_progres = p.get();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TString& TProtocollo::get_prot() const
 | 
			
		||||
const TString& TProtocollo::get_prot() const
 | 
			
		||||
{
 | 
			
		||||
	return prot_in(_year, _tipoprot, _progres);
 | 
			
		||||
}
 | 
			
		||||
@ -363,29 +386,21 @@ const char* get_ini_codcaus()
 | 
			
		||||
	return ini_get_string(FILE_CONFIG, FILE_SECTION, F1_CAUS);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* get_codcaus(const char * tipodoc, const long codcf)
 | 
			
		||||
const char* get_codcaus(const char * tipodoc, long codcf)
 | 
			
		||||
{
 | 
			
		||||
	TLocalisamfile cfven(LF_CFVEN);
 | 
			
		||||
	cfven.put(CFV_TIPOCF, "F");
 | 
			
		||||
	cfven.put(CFV_CODCF, codcf);
 | 
			
		||||
	const char* codcaus = "";
 | 
			
		||||
	const char* codcausnc = "";
 | 
			
		||||
  TCli_for f = cached_clifor('F', codcf);
 | 
			
		||||
	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;
 | 
			
		||||
    const TString & codcaus = f.vendite().get(CFV_CODCAUSNC);
 | 
			
		||||
    if (codcaus.full())
 | 
			
		||||
      return codcaus;
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		if (!TString(codcaus).empty())
 | 
			
		||||
    const TString & codcaus = f.vendite().get(CFV_CODCAUS);
 | 
			
		||||
		if (codcaus.full())
 | 
			
		||||
			return codcaus;
 | 
			
		||||
	}
 | 
			
		||||
	return get_ini_codcaus();
 | 
			
		||||
@ -396,12 +411,12 @@ bool get_endatareg()
 | 
			
		||||
	return ini_get_bool(FILE_CONFIG, FILE_SECTION, "endatareg");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TString get_datainireg()
 | 
			
		||||
const TString & get_datainireg()
 | 
			
		||||
{
 | 
			
		||||
	return ini_get_string(FILE_CONFIG, FILE_SECTION, "datainireg");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TString get_dataendreg()
 | 
			
		||||
const TString & get_dataendreg()
 | 
			
		||||
{
 | 
			
		||||
	return ini_get_string(FILE_CONFIG, FILE_SECTION, "dataendreg");
 | 
			
		||||
}
 | 
			
		||||
@ -444,74 +459,42 @@ bool check_causale(const TString& cod_caus, bool acq)
 | 
			
		||||
 | 
			
		||||
bool check_causale(const TString& cod_caus, const TString& tipo_doc, bool acq)
 | 
			
		||||
{
 | 
			
		||||
	const TCausale& caus = cached_causale(cod_caus);
 | 
			
		||||
	const TCausale& c = cached_causale(cod_caus);
 | 
			
		||||
 | 
			
		||||
	if(tipo_doc == "FA" || tipo_doc == "BD" || tipo_doc == "AF" || tipo_doc == "FF")
 | 
			
		||||
		return caus.tipo_doc() == tipo_doc;
 | 
			
		||||
		return c.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 ((nota = c.tipo_doc() == tipo_doc))
 | 
			
		||||
		{
 | 
			
		||||
			if (acq)
 | 
			
		||||
				nota_iva = caus.reg().tipo() == iva_acquisti;
 | 
			
		||||
				nota_iva = c.reg().tipo() == iva_acquisti;
 | 
			
		||||
			else
 | 
			
		||||
				nota_iva = caus.reg().tipo() == iva_vendite;
 | 
			
		||||
				nota_iva = c.reg().tipo() == iva_vendite;
 | 
			
		||||
		}
 | 
			
		||||
		return nota && nota_iva;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool check_caus_has_rit(const TString& cod_caus, bool rit)
 | 
			
		||||
bool check_caus_has_rit(const TString& cod_caus, int year)
 | 
			
		||||
{
 | 
			
		||||
	TLocalisamfile causali(LF_CAUSALI);
 | 
			
		||||
	causali.put(CAU_CODCAUS, cod_caus);
 | 
			
		||||
	causali.read();
 | 
			
		||||
	return *causali.get(CAU_M770) != '\0';
 | 
			
		||||
	const TCausale & c = cached_causale(cod_caus, year);
 | 
			
		||||
		
 | 
			
		||||
  return c.causale_770().full();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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();
 | 
			
		||||
}
 | 
			
		||||
	TString cmd;
 | 
			
		||||
 | 
			
		||||
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");
 | 
			
		||||
	}
 | 
			
		||||
	cmd.cut(0) << "cg2 -0 -i" << TFilename().temp("cg2CONTAB", "ini")  << " -f1" << (liq ? " -liq" : " ") << " /u" << user();
 | 
			
		||||
  
 | 
			
		||||
	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();
 | 
			
		||||
}
 | 
			
		||||
  TExternal_app app(cmd);
 | 
			
		||||
 | 
			
		||||
bool TF1_log::show_log()
 | 
			
		||||
{
 | 
			
		||||
	if (_log)
 | 
			
		||||
	{
 | 
			
		||||
		_log->preview();
 | 
			
		||||
		delete _log;
 | 
			
		||||
		_log = nullptr;
 | 
			
		||||
	}
 | 
			
		||||
	return true;
 | 
			
		||||
  app.run();
 | 
			
		||||
}
 | 
			
		||||
@ -7,8 +7,8 @@
 | 
			
		||||
 | 
			
		||||
#define FILE_CONFIG   CONFIG_DITTA
 | 
			
		||||
#define FILE_SECTION  "f1"
 | 
			
		||||
#define F1_INIREGCONT "cgreg"
 | 
			
		||||
#define F1_CAUS       "caus"
 | 
			
		||||
#define F1_INIREGCONT "cg2CONTAB"
 | 
			
		||||
#define LOG_MSG       0
 | 
			
		||||
#define LOG_WARN      1
 | 
			
		||||
#define LOG_ERR       2
 | 
			
		||||
@ -39,61 +39,46 @@ typedef struct _prot_s
 | 
			
		||||
 */
 | 
			
		||||
class TFppro : public TObject
 | 
			
		||||
{
 | 
			
		||||
  struct keys_s
 | 
			
		||||
  {
 | 
			
		||||
    TString prginvio;
 | 
			
		||||
    TString headerfatt;
 | 
			
		||||
    TString bodyfatt;
 | 
			
		||||
 | 
			
		||||
    operator const char*() const
 | 
			
		||||
    {
 | 
			
		||||
      static TToken_string a("", ';');
 | 
			
		||||
      a.add(prginvio);
 | 
			
		||||
      a.add(headerfatt);
 | 
			
		||||
      a.add(bodyfatt);
 | 
			
		||||
      return a;
 | 
			
		||||
    }
 | 
			
		||||
  } _keys;
 | 
			
		||||
 | 
			
		||||
  TToken_string _keys;
 | 
			
		||||
  SSimple_query* _db;
 | 
			
		||||
  bool    _keys_setted;
 | 
			
		||||
  bool    _is_set;  // Query is setted
 | 
			
		||||
  TString _fppro_query;
 | 
			
		||||
  TString _last_error;
 | 
			
		||||
 | 
			
		||||
  static bool sql_inj(const TString& str);
 | 
			
		||||
  static bool sql_inj(const keys_s& keys);
 | 
			
		||||
  bool sql_inj(TToken_string& keys);
 | 
			
		||||
public:
 | 
			
		||||
  const char* where_str() const;
 | 
			
		||||
  const char* where_str();
 | 
			
		||||
 | 
			
		||||
  bool  check_reg(TToken_string& keys, int numreg);
 | 
			
		||||
  // Se un mov. registrato non e' collegato all'FPPRO cerco di capire qual'e`
 | 
			
		||||
  bool  guess_the_doc(const TLocalisamfile& mov);
 | 
			
		||||
  // Getters
 | 
			
		||||
  const char* get_keys_fppro() const;
 | 
			
		||||
  int         get_numreg();
 | 
			
		||||
  int         get_numreg(TToken_string& keys);
 | 
			
		||||
  TString     get_codforn() const;
 | 
			
		||||
  const char* get_keys_fppro();
 | 
			
		||||
  long        get_numreg();
 | 
			
		||||
  long        get_numreg(TToken_string& keys);
 | 
			
		||||
  long        get_codforn();
 | 
			
		||||
  TDate       get_datareg();
 | 
			
		||||
  TDate       get_datareg(TToken_string& keys);
 | 
			
		||||
  real        get_ritenute() const;
 | 
			
		||||
  real        get_ritenute();
 | 
			
		||||
  TDate       get_data_first_doc() const;
 | 
			
		||||
  TDate       get_dataorarioric() const;
 | 
			
		||||
  int         get_numregcont() const;
 | 
			
		||||
  TDate       get_dataorarioric();
 | 
			
		||||
  long        get_numregcont();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  TString get_last_error(bool clear = true);
 | 
			
		||||
  // Setters
 | 
			
		||||
  bool    set_query();
 | 
			
		||||
  TFppro& set_keys(TToken_string& keys);
 | 
			
		||||
  TFppro& set_keys(const keys_s& keys);
 | 
			
		||||
 | 
			
		||||
  bool associa_mov(int numreg)  const;
 | 
			
		||||
  const char* get_tipoprot()    const;
 | 
			
		||||
  const char* get_numprot()     const;
 | 
			
		||||
  const char* get_annoprot()    const;
 | 
			
		||||
  const char* get_dataoraric()  const;
 | 
			
		||||
  const char* get_tipodoc()     const;
 | 
			
		||||
  const char* get_numdoc()      const;
 | 
			
		||||
  bool associa_mov(long numreg);
 | 
			
		||||
	const TString & get_tipoprot();
 | 
			
		||||
	const TString & get_numprot();
 | 
			
		||||
	const TString & get_annoprot();
 | 
			
		||||
	const TString & get_dataoraric();
 | 
			
		||||
	const TString & get_tipodoc();
 | 
			
		||||
	const TString & get_numdoc();
 | 
			
		||||
	TDate get_data_doc();
 | 
			
		||||
 | 
			
		||||
	TFppro();
 | 
			
		||||
  TFppro(TToken_string& keys) : TFppro() { set_keys(keys); }
 | 
			
		||||
@ -111,36 +96,29 @@ public:
 | 
			
		||||
 | 
			
		||||
  void set(const TProtocollo& prot);
 | 
			
		||||
  void sset(const char*  prot);
 | 
			
		||||
  TString&  get_prot() const;
 | 
			
		||||
  const TString&  get_prot() const;
 | 
			
		||||
  prot_s    get_prot();
 | 
			
		||||
 | 
			
		||||
  int       get_year() const  { return _year; }
 | 
			
		||||
  TString&  get_tipoprot()    { return _tipoprot; }
 | 
			
		||||
  TString&  get_progres()     { return _progres; }
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
  static TString& prot_in(int year, const char* tipoprot, const char* progres);
 | 
			
		||||
 | 
			
		||||
  operator const char*() const { return static_cast<const char*>(get_prot()); }
 | 
			
		||||
  
 | 
			
		||||
  const TString&  get_tipoprot() const { return _tipoprot; }
 | 
			
		||||
  const TString&  get_progres()  const { return _progres; }
 | 
			
		||||
  const TString& prot_in(int year, const char* tipoprot, const char* progres) const;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TF1_log : TObject
 | 
			
		||||
class TF1_log : public TLog_report
 | 
			
		||||
{
 | 
			
		||||
  TLog_report* _log;
 | 
			
		||||
public:
 | 
			
		||||
  TF1_log() : _log(nullptr){}
 | 
			
		||||
  void log(int severity, const char* msg);
 | 
			
		||||
  bool show_log();
 | 
			
		||||
  TF1_log() : TLog_report("Stato contabilizzazione:") {}
 | 
			
		||||
  bool show_log() { export_text("f1_cg.log", 0, false);  return preview(); }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
TFppro&      fppro_db();
 | 
			
		||||
 | 
			
		||||
const char* get_ini_codcaus();
 | 
			
		||||
const char* get_codcaus(const char * tipodoc, const long codcf);
 | 
			
		||||
const char* get_codcaus(const char * tipodoc, long codcf);
 | 
			
		||||
bool        get_endatareg();
 | 
			
		||||
TString     get_datainireg();
 | 
			
		||||
TString     get_dataendreg();
 | 
			
		||||
const TString & get_datainireg();
 | 
			
		||||
const TString &    get_dataendreg();
 | 
			
		||||
bool        get_periodprec(); 
 | 
			
		||||
 | 
			
		||||
void        set_ini_codcaus(const TString& codcaus);
 | 
			
		||||
@ -153,7 +131,7 @@ void        set_periodprec(bool flag);
 | 
			
		||||
bool        check_causale(const TString& cod_caus, bool acq = true);
 | 
			
		||||
// Controlla se il "cod_caus" ha come "tipo_doc" FA o NC (di acquisto)
 | 
			
		||||
bool        check_causale(const TString& cod_caus, const TString& tipo_doc, bool acq = true);
 | 
			
		||||
bool        check_caus_has_rit(const TString& cod_caus, bool rit);
 | 
			
		||||
bool        check_caus_has_rit(const TString& cod_caus, int year = 0);
 | 
			
		||||
void        run_cont_ini(bool liq);
 | 
			
		||||
 | 
			
		||||
#endif // _F1LIB_H_
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user