Files correlati : ve6.exe Ricompilazione Demo : [ ] Commento : Riportata la versione 3.1 patch 979 git-svn-id: svn://10.65.10.50/trunk@15623 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			425 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			425 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include "tc0.h"
 | 
						|
#include "tc0701.h"
 | 
						|
#include "tc0700a.h"
 | 
						|
 | 
						|
#include <automask.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <reprint.h>
 | 
						|
 | 
						|
#include <anagr.h>
 | 
						|
#include <anafis.h>
 | 
						|
#include <clifo.h>
 | 
						|
#include <comuni.h>
 | 
						|
#include <causali.h>
 | 
						|
#include <nditte.h>
 | 
						|
#include <mov.h>
 | 
						|
#include <rmov.h>
 | 
						|
#include <rmoviva.h>
 | 
						|
#include <multirel.h>
 | 
						|
 | 
						|
#include "../cg/cglib01.h"
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TTS_mask
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TTS_mask : public TAutomask
 | 
						|
{
 | 
						|
  clock_t _next_update;
 | 
						|
  bool _updating;
 | 
						|
 | 
						|
private:
 | 
						|
  bool apply_filter(const TRecordset& righe) const;
 | 
						|
  void serialize(bool bSave);
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
 | 
						|
public:
 | 
						|
  TTS_mask();
 | 
						|
  ~TTS_mask();
 | 
						|
};
 | 
						|
 | 
						|
bool TTS_mask::apply_filter(const TRecordset& righe) const
 | 
						|
{
 | 
						|
  const TDate dal = get(F_DATA_DA);
 | 
						|
  const TDate al = get(F_DATA_AL);
 | 
						|
  if (dal.ok() || al.ok())
 | 
						|
  {
 | 
						|
    const TDate scad = righe.get("DATASCAD").as_date();
 | 
						|
    if ((dal.ok() && scad < dal) || (al.ok() && scad > al))
 | 
						|
      return false;
 | 
						|
  }
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
bool TTS_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  bool ok = true;
 | 
						|
  switch (o.dlg())
 | 
						|
  {
 | 
						|
  case F_DATA_DA:
 | 
						|
  case F_DATA_AL:
 | 
						|
    break;
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  }
 | 
						|
  return ok;
 | 
						|
}
 | 
						|
 | 
						|
void TTS_mask::serialize(bool bSave)
 | 
						|
{
 | 
						|
  const char* defpar = "tc";
 | 
						|
  TConfig ini(CONFIG_DITTA, defpar);
 | 
						|
  for (int i = fields()-1; i >= 0; i--)
 | 
						|
  {
 | 
						|
    TMask_field& f = fld(i);
 | 
						|
    const TFieldref* fr = f.field();
 | 
						|
    if (fr != NULL)
 | 
						|
    {
 | 
						|
      if (bSave)
 | 
						|
        fr->write(ini, defpar, f.get());
 | 
						|
      else
 | 
						|
        f.set(fr->read(ini, defpar));
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
TTS_mask::TTS_mask() 
 | 
						|
         : TAutomask("tc0700a"), _updating(false), _next_update(0)
 | 
						|
{
 | 
						|
  serialize(false);
 | 
						|
}
 | 
						|
 | 
						|
TTS_mask::~TTS_mask()
 | 
						|
{
 | 
						|
  serialize(true);
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TTS_campo_sender
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TTS_campo_sender : public TTS_sender
 | 
						|
{
 | 
						|
	TTS_mask * _mask;
 | 
						|
	TAssoc_array _caus_regolarizzazione;
 | 
						|
 | 
						|
protected:
 | 
						|
	virtual TRecordset & movrecset();
 | 
						|
	virtual TRecordset & rmovrecset(const TRecordset & mov);
 | 
						|
	virtual TRecordset & rivarecset(const TRecordset & mov);
 | 
						|
	virtual const TRecordset & clirecset(const char tipocf, const long codcf);
 | 
						|
	virtual TMask & get_mask();
 | 
						|
 | 
						|
protected:
 | 
						|
	virtual bool find_regolarizzazione(TRecordset& mov);
 | 
						|
	virtual const char * decode_causale(const TRecordset& mov);
 | 
						|
	virtual bool test_swap(const TRecordset& mov);
 | 
						|
	virtual bool swap_ritsoc(const TRecordset& mov);
 | 
						|
	virtual bool mov_regolarizzazione(const TRecordset& mov);
 | 
						|
	virtual bool mov_intra(const TRecordset& mov);
 | 
						|
	virtual bool mov_reverse_charge(const TRecordset& mov);
 | 
						|
	virtual long iva11_reverse(const TRecordset & mov);
 | 
						|
 | 
						|
public:
 | 
						|
	virtual void postprocess_movs(TRecordset & mov);
 | 
						|
	virtual bool create();
 | 
						|
	virtual bool destroy();
 | 
						|
 | 
						|
  TTS_campo_sender() : TTS_sender(), _mask(NULL) {}
 | 
						|
	~TTS_campo_sender() {}
 | 
						|
};
 | 
						|
 | 
						|
bool TTS_campo_sender::destroy()
 | 
						|
{
 | 
						|
	delete _mask;
 | 
						|
	return TTS_sender::destroy();
 | 
						|
}
 | 
						|
 | 
						|
TRecordset & TTS_campo_sender::movrecset()
 | 
						|
{
 | 
						|
	const TMask & m = get_mask();
 | 
						|
	const TDate from = m.get_date(F_DATA_DA);
 | 
						|
	const TDate to = m.get_date(F_DATA_AL);
 | 
						|
	TRecordset * mov = get_recset(LF_MOV);
 | 
						|
 | 
						|
	if (mov == NULL)
 | 
						|
	{
 | 
						|
		TString query = "USE MOV KEY 2 SELECT INVIATO!=\"X\"";           
 | 
						|
 | 
						|
		query << "\nFROM DATAREG=#DATA_DA";      
 | 
						|
		query << "\nTO DATAREG=#DATA_AL";      
 | 
						|
	
 | 
						|
		mov = set_recset(LF_MOV, ::create_recordset(query));
 | 
						|
	}
 | 
						|
	mov->set_var("#DATA_DA", TVariant(from));
 | 
						|
  mov->set_var("#DATA_AL", TVariant(to));
 | 
						|
	return *mov;
 | 
						|
}
 | 
						|
 | 
						|
TRecordset & TTS_campo_sender::rmovrecset(const TRecordset & mov)
 | 
						|
{
 | 
						|
	TRecordset * rmov = get_recset(LF_RMOV);
 | 
						|
 | 
						|
	if (rmov == NULL)
 | 
						|
		rmov = set_recset(LF_RMOV, ::create_recordset("USE RMOV\nFROM NUMREG=#NUMREG\nTO NUMREG=#NUMREG"));
 | 
						|
 | 
						|
	const TVariant & numreg = mov.get(MOV_NUMREG);
 | 
						|
	
 | 
						|
	if (numreg != rmov->get("#NUMREG"))
 | 
						|
		rmov->set_var("#NUMREG", numreg);
 | 
						|
	return *rmov;
 | 
						|
}
 | 
						|
 | 
						|
TRecordset & TTS_campo_sender::rivarecset(const TRecordset & mov)
 | 
						|
{
 | 
						|
	TRecordset * rmoviva = get_recset(LF_RMOVIVA);
 | 
						|
 | 
						|
	if (rmoviva == NULL)
 | 
						|
		rmoviva = set_recset(LF_RMOVIVA, ::create_recordset("USE RMOVIVA\nFROM NUMREG=#NUMREG\nTO NUMREG=#NUMREG"));
 | 
						|
 | 
						|
	const TVariant & numreg = mov.get(MOV_NUMREG);
 | 
						|
	
 | 
						|
	if (numreg != rmoviva->get("#NUMREG"))
 | 
						|
		rmoviva->set_var("#NUMREG", numreg);
 | 
						|
	return *rmoviva;
 | 
						|
}
 | 
						|
 | 
						|
const TRecordset& TTS_campo_sender::clirecset(const char tipocf, const long codcf)
 | 
						|
{
 | 
						|
	TRecordset * clifo = get_recset(LF_CLIFO);
 | 
						|
 | 
						|
	if (clifo == NULL)
 | 
						|
		clifo = set_recset(LF_CLIFO, ::create_recordset("USE CLIFO\nFROM TIPOCF=#TIPOCF CODCF=#CODCF\nTO TIPOCF=#TIPOCF CODCF=#CODCF"));
 | 
						|
	TString4 w; w << tipocf;
 | 
						|
	TVariant t(w);
 | 
						|
 | 
						|
	clifo->set_var("#TIPOCF", t);
 | 
						|
	clifo->set_var("#CODCF", codcf);
 | 
						|
  clifo->move_first();
 | 
						|
	return *clifo;
 | 
						|
}
 | 
						|
 | 
						|
bool TTS_campo_sender::test_swap(const TRecordset& mov)
 | 
						|
{
 | 
						|
	TRecordset & rmov = rmovrecset(mov);
 | 
						|
 | 
						|
  rmov.move_first();
 | 
						|
 | 
						|
  const char sez = rmov.get(RMV_SEZIONE).as_string()[0];
 | 
						|
	const bool vendite = mov.get(MOV_TIPO).as_string()[0] != 'F';
 | 
						|
  
 | 
						|
  const bool s = vendite ^ (sez == 'D');
 | 
						|
  return s;
 | 
						|
}
 | 
						|
 | 
						|
bool TTS_campo_sender::swap_ritsoc(const TRecordset& mov)
 | 
						|
{
 | 
						|
	TRecordset & rmov = rmovrecset(mov);
 | 
						|
  bool ok = rmov.move_first();
 | 
						|
  const char sez = rmov.get(RMV_SEZIONE).as_string()[0];
 | 
						|
	char sezrit = sez;
 | 
						|
 | 
						|
	for (; ok; ok = rmov.move_next())
 | 
						|
	{
 | 
						|
		const char tiporiga = rmov.get(RMV_ROWTYPE).as_string()[0];
 | 
						|
 | 
						|
		if (tiporiga =='S')
 | 
						|
		{
 | 
						|
		  sezrit = rmov.get(RMV_SEZIONE).as_string()[0];
 | 
						|
			break;
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
  const bool s = sez != sezrit;
 | 
						|
  return s;
 | 
						|
}
 | 
						|
 | 
						|
bool TTS_campo_sender::mov_regolarizzazione(const TRecordset& mov)
 | 
						|
{
 | 
						|
  const TString& codcaus = mov.get(MOV_CODCAUS).as_string();
 | 
						|
 | 
						|
	return _caus_regolarizzazione.objptr(codcaus) != NULL;
 | 
						|
}
 | 
						|
 | 
						|
bool TTS_campo_sender::mov_intra(const TRecordset& mov)
 | 
						|
{
 | 
						|
  const TRectype& caus = cache().get(LF_CAUSALI, mov.get(MOV_CODCAUS).as_string());
 | 
						|
	
 | 
						|
	return caus.get_bool(CAU_INTRACOM);
 | 
						|
}
 | 
						|
 | 
						|
bool TTS_campo_sender::mov_reverse_charge(const TRecordset& mov)
 | 
						|
{
 | 
						|
  const TRectype& caus = cache().get(LF_CAUSALI, mov.get(MOV_CODCAUS).as_string());
 | 
						|
	const int	regsp = caus.get_int(CAU_REGSPIVA);
 | 
						|
 | 
						|
	return regsp == 13 || regsp == 50 || regsp == 51;
 | 
						|
}
 | 
						|
 | 
						|
TMask & TTS_campo_sender::get_mask()
 | 
						|
{
 | 
						|
	if (_mask == NULL)
 | 
						|
	{
 | 
						|
		_mask = new TTS_mask;
 | 
						|
		TDate to(TODAY);
 | 
						|
		TConfig configtc(CONFIG_DITTA, "tc");
 | 
						|
		const TDate from(configtc.get("TSULTINV"));
 | 
						|
 | 
						|
		to.addmonth(-1);
 | 
						|
		to.set_end_month();
 | 
						|
		if (to <= from)
 | 
						|
		{
 | 
						|
			to = from;
 | 
						|
			to.addmonth(1);
 | 
						|
			to.set_end_month();
 | 
						|
		}
 | 
						|
		_mask->set(F_DATA_DA, from);
 | 
						|
		_mask->set(F_DATA_AL, to);
 | 
						|
	}
 | 
						|
	return * _mask;
 | 
						|
}
 | 
						|
	
 | 
						|
bool TTS_campo_sender::find_regolarizzazione(TRecordset& mov)
 | 
						|
{
 | 
						|
	bool found = false;
 | 
						|
  const TRectype& caus = cache().get(LF_CAUSALI, mov.get(MOV_CODCAUS).as_string());
 | 
						|
	const TString16 causreg =	caus.get(CAU_CODCAUREG);
 | 
						|
	real totdoc = mov.get(MOV_TOTDOC).as_real();
 | 
						|
	const real ritfis = mov.get(MOV_RITFIS).as_real();
 | 
						|
	const real ritsoc = mov.get(MOV_RITSOC).as_real();
 | 
						|
 | 
						|
	if (ritfis != ZERO)
 | 
						|
		totdoc += ritfis;
 | 
						|
  if (ritsoc != ZERO)
 | 
						|
	{
 | 
						|
		if (swap_ritsoc(mov))                      // Somma ritenute sociali con segno
 | 
						|
			totdoc -= ritsoc;
 | 
						|
	  else
 | 
						|
		  totdoc += ritsoc;                        
 | 
						|
	}
 | 
						|
  if (test_swap(mov))
 | 
						|
		totdoc = -totdoc;
 | 
						|
 | 
						|
	const TRecordset & cli = clirecset(mov.get(MOV_TIPO).as_string()[0], mov.get(MOV_CODCF).as_int());
 | 
						|
	const TString16 paiv = cli.get(CLI_PAIV).as_string();
 | 
						|
	const TString16 cf = cli.get(CLI_COFI).as_string();
 | 
						|
 | 
						|
	for (bool ok = mov.move_next(); ok && ! found; ok = mov.move_next())
 | 
						|
	{
 | 
						|
	  const TRectype& caus = cache().get(LF_CAUSALI, mov.get(MOV_CODCAUS).as_string());
 | 
						|
		const TString16 cod = caus.get(CAU_CODCAUS);
 | 
						|
		
 | 
						|
		found = (causreg.full() && cod == causreg) || (causreg.blank() && (_caus_regolarizzazione.objptr(cod) || caus.get_bool(CAU_SOLOIVA)));
 | 
						|
		found &= (totdoc == mov.get(MOV_TOTDOC).as_real());
 | 
						|
 | 
						|
		const TRecordset & clireg = clirecset(mov.get(MOV_TIPO).as_string()[0], mov.get(MOV_CODCF).as_int());
 | 
						|
 | 
						|
		found &= ((paiv.full() && paiv == clireg.get(CLI_PAIV).as_string()) || (paiv.blank() && cf == clireg.get(CLI_COFI).as_string()));
 | 
						|
		if (found)
 | 
						|
			break;
 | 
						|
	}
 | 
						|
 | 
						|
	return found;
 | 
						|
}
 | 
						|
 | 
						|
long TTS_campo_sender::iva11_reverse(const TRecordset & mov)
 | 
						|
{
 | 
						|
  const TRectype& caus = cache().get(LF_CAUSALI, mov.get(MOV_CODCAUS).as_string());
 | 
						|
 | 
						|
	return caus.get_int(CAU_REGSPIVA);
 | 
						|
}
 | 
						|
 | 
						|
const char * TTS_campo_sender::decode_causale(const TRecordset& mov)
 | 
						|
{
 | 
						|
  const TRectype& caus = cache().get(LF_CAUSALI, mov.get(MOV_CODCAUS).as_string());
 | 
						|
	
 | 
						|
	return caus.get(CAU_DESCR);
 | 
						|
}
 | 
						|
 | 
						|
void TTS_campo_sender::postprocess_movs(TRecordset & mov)
 | 
						|
{
 | 
						|
	if (yesno_box(TR("Confermare il traferimento")))
 | 
						|
	{
 | 
						|
		TConfig configtc(CONFIG_DITTA);
 | 
						|
		TMask & m = get_mask();
 | 
						|
 | 
						|
		configtc.set("TSULTINV", m.get_date(F_DATA_AL));
 | 
						|
 | 
						|
		if (mov.items() > 0L)
 | 
						|
		{
 | 
						|
			TProgind pi(mov.items(), TR("Conferma movimenti"), true, true);
 | 
						|
			TLocalisamfile cgmov(LF_MOV);
 | 
						|
		
 | 
						|
			for (bool ok = mov.move_first(); ok; ok = mov.move_next())
 | 
						|
			{
 | 
						|
				if (!pi.addstatus(1))
 | 
						|
					break;
 | 
						|
 | 
						|
				const long numreg = mov.get(MOV_NUMREG).as_int();
 | 
						|
 | 
						|
				cgmov.put(MOV_NUMREG, numreg);
 | 
						|
				if (cgmov.read(_isequal, _lock) == NOERR)
 | 
						|
				{
 | 
						|
					cgmov.put(MOV_INVIATO, true);
 | 
						|
					cgmov.rewrite();
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
bool search_reg(const TRelation& rel, void* pJolly)
 | 
						|
{
 | 
						|
	TAssoc_array * _caus_regolarizzazione =	(TAssoc_array *) pJolly;
 | 
						|
	const bool solaiva = rel.lfile().get_bool(CAU_SOLOIVA);
 | 
						|
	const TString codcaus = rel.lfile().get(CAU_CODCAUREG);
 | 
						|
 | 
						|
	if (solaiva || codcaus.full())
 | 
						|
		_caus_regolarizzazione->add(codcaus, codcaus);
 | 
						|
	
 | 
						|
	return true;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TTS_campo_sender::create()
 | 
						|
{
 | 
						|
	bool ok = TTS_sender::create();
 | 
						|
 | 
						|
	if (ok)
 | 
						|
	{
 | 
						|
		TRelation rel(LF_CAUSALI);
 | 
						|
		TCursor c(&rel);
 | 
						|
	  ok = c.scan(search_reg, &_caus_regolarizzazione, "Ricerca causali di regolarizzazione");
 | 
						|
	}
 | 
						|
	TLocalisamfile clifo(LF_CLIFO);
 | 
						|
	bool big_cli_code = false;
 | 
						|
	
 | 
						|
	clifo.put(CLI_TIPOCF, "C");
 | 
						|
	clifo.put(CLI_CODCF, 100000L);;
 | 
						|
 | 
						|
	if (clifo.read(_isgteq) != _iseof || clifo.get(CLI_TIPOCF) == "F")
 | 
						|
		big_cli_code = true;
 | 
						|
	if (!big_cli_code)
 | 
						|
	{
 | 
						|
		clifo.put(CLI_TIPOCF, "F");
 | 
						|
		clifo.put(CLI_CODCF, 100000L);;
 | 
						|
 | 
						|
		if (clifo.read(_isgteq) != _iseof)
 | 
						|
			big_cli_code = true;
 | 
						|
	}
 | 
						|
 | 
						|
	if (!big_cli_code)
 | 
						|
		riclassifica().add("TSNOHCLI", EMPTY_STRING);
 | 
						|
 | 
						|
	return ok;
 | 
						|
}
 | 
						|
 | 
						|
int tc0700(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TTS_campo_sender app;
 | 
						|
  app.run(argc, argv, TR("Invio a TeamSystem"));
 | 
						|
  return 0;
 | 
						|
}
 |