Files correlati : tc2.exe Ricompilazione Demo : [ ] Commento : Corretto segno sui movimenti git-svn-id: svn://10.65.10.50/branches/R_10_00@21692 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			1620 lines
		
	
	
		
			47 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			1620 lines
		
	
	
		
			47 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include "tc2.h"
 | 
						||
#include "tc2700.h"
 | 
						||
#include "tc2700a.h"
 | 
						||
 | 
						||
#include <automask.h>
 | 
						||
#include <lffiles.h>
 | 
						||
#include <progind.h>
 | 
						||
#include <reprint.h>
 | 
						||
 | 
						||
#include <anafis.h>
 | 
						||
#include <anagr.h>
 | 
						||
#include <causali.h>
 | 
						||
#include <clifo.h>
 | 
						||
#include <comuni.h>
 | 
						||
#include "../in/intra.h"
 | 
						||
#include "../in/rintra.h"
 | 
						||
#include <mov.h>
 | 
						||
#include <rmov.h>
 | 
						||
#include <rmoviva.h>
 | 
						||
#include <partite.h>
 | 
						||
#include <scadenze.h>
 | 
						||
#include <multirel.h>
 | 
						||
#include <pconti.h>
 | 
						||
 | 
						||
#include "../cg/cglib01.h"
 | 
						||
#include "../cg/cglib03.h"
 | 
						||
 | 
						||
#define CFLD "C"
 | 
						||
#define INTFLD "INT"
 | 
						||
#define NPFLD  "NP"
 | 
						||
#define NUFLD  "NU"
 | 
						||
#define FLFLD  "FL"
 | 
						||
#define DATEFLD  "DATE"
 | 
						||
 | 
						||
#define CAU  "IPCAU"
 | 
						||
#define CDP  "IPCDP"
 | 
						||
#define IVA  "IPIVA"
 | 
						||
#define ICC	 "IPICC" // aggiungere
 | 
						||
#define NAZ  "IPNAZ"
 | 
						||
#define REG  "IPREG"
 | 
						||
#define VAL  "IPVAL"
 | 
						||
 | 
						||
bool TIP_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 TIP_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 TIP_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));
 | 
						||
    }
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
TIP_mask::TIP_mask(const char * maskname) 
 | 
						||
         : TAutomask(maskname), _updating(false), _next_update(0)
 | 
						||
{
 | 
						||
  serialize(false);
 | 
						||
}
 | 
						||
 | 
						||
TIP_mask::~TIP_mask()
 | 
						||
{
 | 
						||
  serialize(true);
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TCausali_cache
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
TObject* TCausali_cache::key2obj(const char* key)
 | 
						||
{
 | 
						||
  // Metodo bastardo per evitare TToken_string temporanee "a randa"
 | 
						||
  // sfrutto chiave a lunghezza fissa
 | 
						||
  const int anno = atoi(key);
 | 
						||
  const char* codice = key+5;
 | 
						||
  TCausale* pcaus = new TCausale(codice, anno);
 | 
						||
  return pcaus;
 | 
						||
}
 | 
						||
 | 
						||
const TCausale& TCausali_cache::causale(const char* codice, int annoiva)
 | 
						||
{
 | 
						||
  // Metodo bastardo per evitare TToken_string temporanee "a randa"
 | 
						||
  // creo chiave a lunghezza fissa anno+codice = 9999|AAA
 | 
						||
  TString8 key;
 | 
						||
  key.format("%04d|%s", annoiva, codice);
 | 
						||
  return *(const TCausale*)objptr(key);
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TRiclassifica_cache
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
HIDDEN const char* const __tiporicconti = "IPCONTI";
 | 
						||
 | 
						||
TObject* TIPRiclassifica_cache::key2obj(const char* key)
 | 
						||
{
 | 
						||
	TToken_string tok(key);
 | 
						||
	TString8 tab, cod;
 | 
						||
	tok.get(0,tab);
 | 
						||
	tok.get(1, cod);
 | 
						||
	_multirel.put(MULTI_COD, tab);
 | 
						||
	_multirel.put(MULTI_FIRST, cod);
 | 
						||
	_multirel.zero(MULTI_SECOND);
 | 
						||
	if (_multirel.read() == NOERR)
 | 
						||
		return new TString(_multirel.get(MULTI_DATA));
 | 
						||
	return NULL;
 | 
						||
}
 | 
						||
 | 
						||
long TIPRiclassifica_cache::decode(const char* tab, const TString& cod)
 | 
						||
{
 | 
						||
	TToken_string tok;
 | 
						||
	tok.add(tab);
 | 
						||
	tok.add(cod);
 | 
						||
	const TString* ric = (const TString*) objptr(tok);
 | 
						||
	return (ric ? atol(*ric) : 0);
 | 
						||
}
 | 
						||
 | 
						||
const char * TIPRiclassifica_cache::sdecode(const char* tab, const TString& cod)
 | 
						||
{
 | 
						||
	TToken_string tok;
 | 
						||
	tok.add(tab);
 | 
						||
	tok.add(cod);
 | 
						||
	const TString* ric = (const TString*) objptr(tok);
 | 
						||
	return ric ? (const char *) *ric : "";
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
const long IPbill2ricl(char & t, int gr, int co, long so)
 | 
						||
{
 | 
						||
	TRecord_cache *	__conti = NULL;
 | 
						||
 | 
						||
	if (__conti == NULL)
 | 
						||
		__conti = new TRecord_cache(LF_RICLPDC, 1);
 | 
						||
 | 
						||
  long codricl = 0;
 | 
						||
	if (gr > 0)
 | 
						||
	{
 | 
						||
		TToken_string cod;
 | 
						||
		cod.add(__tiporicconti);
 | 
						||
		cod.add(gr);
 | 
						||
		cod.add(co);
 | 
						||
		if (t <= ' ')
 | 
						||
			cod.add(so);
 | 
						||
 | 
						||
		// Provo il sottoconto ma se non riesco provo con conto e poi anche gruppo
 | 
						||
		for (int c = 3; c > 0 && codricl <= 0; c--)
 | 
						||
		{
 | 
						||
			codricl = atol(__conti->get(cod, "CODICE"));
 | 
						||
			cod.add(0, c);
 | 
						||
		}
 | 
						||
	}
 | 
						||
  return codricl;
 | 
						||
}
 | 
						||
 | 
						||
TIP_sender& app() { return (TIP_sender&)main_app(); }
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TIP_textset
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TInt : public TObject
 | 
						||
{
 | 
						||
public:
 | 
						||
	int _int;
 | 
						||
 | 
						||
	TInt(int i) : _int(i) {}
 | 
						||
};
 | 
						||
 | 
						||
 | 
						||
bool TIP_textset::destroy(TRecnotype r)
 | 
						||
{
 | 
						||
	bool ok;
 | 
						||
  ok = TCSV_recordset::destroy(r);
 | 
						||
  return ok; 
 | 
						||
}
 | 
						||
 | 
						||
int TIP_textset::find_column(const char * name)
 | 
						||
{
 | 
						||
	const TString80 fname(name);
 | 
						||
	TInt * i = (TInt *) _colnames.objptr(fname);
 | 
						||
 
 | 
						||
	if (i != NULL)
 | 
						||
		return i->_int;
 | 
						||
	return -1;
 | 
						||
}
 | 
						||
 | 
						||
void TIP_textset::add_field(const char* name, int len, const char * tipo)
 | 
						||
{
 | 
						||
  const TString80 fname(name);
 | 
						||
 | 
						||
	const TString4 strtipo(tipo);
 | 
						||
  TFieldtypes t = _alfafld; 
 | 
						||
	
 | 
						||
	if (strtipo == INTFLD || strtipo == NPFLD)
 | 
						||
	{
 | 
						||
		if (len > 10)
 | 
						||
			len = 10;
 | 
						||
		t = _longzerofld;
 | 
						||
	}
 | 
						||
	else
 | 
						||
		if (strtipo == NUFLD || strtipo == FLFLD)
 | 
						||
		{
 | 
						||
			if (len > 19)
 | 
						||
				len = 19;
 | 
						||
			t = _realfld;
 | 
						||
		}
 | 
						||
		else
 | 
						||
			if (strtipo == DATEFLD)
 | 
						||
			{
 | 
						||
				len = 8;
 | 
						||
				t = _datefld;
 | 
						||
			}
 | 
						||
  create_column(fname, t);
 | 
						||
  TRecordset_column_info& ci = (TRecordset_column_info&) column_info(columns() - 1);
 | 
						||
  ci._width = len;
 | 
						||
	_colnames.add(fname, new TInt(columns() - 1));
 | 
						||
}
 | 
						||
 | 
						||
bool TIP_textset::set(const char* field, const TVariant& var)
 | 
						||
{
 | 
						||
  TString msg;
 | 
						||
	bool ok = true;
 | 
						||
	TString val;
 | 
						||
	int column = find_column(field);
 | 
						||
 | 
						||
	if (column < 0)
 | 
						||
	{
 | 
						||
    msg  << field << ": " << TR("Campo sconosiuto");
 | 
						||
    app().log(2, msg);
 | 
						||
	}
 | 
						||
 | 
						||
	TRecordset_column_info& ci = (TRecordset_column_info&) column_info(column);
 | 
						||
	const int len = ci._width;
 | 
						||
 | 
						||
	switch (var.type())
 | 
						||
  {
 | 
						||
		case _datefld:
 | 
						||
			if (!var.is_zero())
 | 
						||
			{
 | 
						||
				const TDate d = var.as_date();
 | 
						||
				const long ansi = d.date2ansi();
 | 
						||
				val.format("%8ld", ansi);
 | 
						||
				ok = true;
 | 
						||
			}
 | 
						||
			break;
 | 
						||
		case _realfld:
 | 
						||
			if (!var.is_zero())
 | 
						||
			{
 | 
						||
				const real v = var.as_real();
 | 
						||
				val = v.string(0, 2);
 | 
						||
				ok = val.len() <= len;
 | 
						||
			}
 | 
						||
			break;
 | 
						||
		case _longzerofld:
 | 
						||
			if (!var.is_zero())
 | 
						||
			{
 | 
						||
				const long v = var.as_int();
 | 
						||
				val.format("%ld", v );
 | 
						||
				ok = val.len() <= len;
 | 
						||
			}
 | 
						||
			break;
 | 
						||
		default:
 | 
						||
			val = var.as_string().left(len);
 | 
						||
			break;
 | 
						||
	}
 | 
						||
	if (ok)
 | 
						||
		TCSV_recordset::set(column, TVariant(val)); 
 | 
						||
	else
 | 
						||
	{
 | 
						||
    msg  << field << TR(": Valore - ") << val<< TR(" - Lunghezza errata ");
 | 
						||
    app().log(2, msg);
 | 
						||
  }
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TIP_clienti_textset
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
TIP_clienti_textset::TIP_clienti_textset(const char* query) : TIP_textset(query)
 | 
						||
{
 | 
						||
	add_field("ID_Cliente", 6);
 | 
						||
	add_field("Descrizione_1", 40);
 | 
						||
	add_field("Descrizione_2", 40);
 | 
						||
	add_field("Indirizzo", 40);
 | 
						||
	add_field("Citta", 62);
 | 
						||
	add_field("Cap", 9);
 | 
						||
	add_field("ID_Provincia", 2);
 | 
						||
	add_field("ID_Regione", 3);
 | 
						||
	add_field("ID_Nazione_Estera", 3);
 | 
						||
	add_field("Email", 40);
 | 
						||
	add_field("Telefono1_1", 5);
 | 
						||
	add_field("Telefono1_2", 5);
 | 
						||
	add_field("Telefono1_3", 10);
 | 
						||
	add_field("Telefono2_1", 5);
 | 
						||
	add_field("Telefono2_2", 5);
 | 
						||
	add_field("Telefono2_3", 10);
 | 
						||
	add_field("Fax_1", 5);
 | 
						||
	add_field("Fax_2", 5);
 | 
						||
	add_field("Fax_3", 10);
 | 
						||
	add_field("PersonaContattare", 30);
 | 
						||
	add_field("Chiave_Ricerca", 40);
 | 
						||
	add_field("Nota", 80);
 | 
						||
	add_field("Flag_Persona_Fisica", 1);
 | 
						||
	add_field("Sesso", 1);
 | 
						||
	add_field("Data_Nascita", 8);
 | 
						||
	add_field("Citta_Nascita", 62);
 | 
						||
	add_field("Cognome", 25);
 | 
						||
	add_field("Nome", 25);
 | 
						||
	add_field("Indirizzo_Legale", 40);
 | 
						||
	add_field("Citta_Legale", 62);
 | 
						||
	add_field("Cap_Legale", 9);
 | 
						||
	add_field("ID_Provincia_Legale", 2);
 | 
						||
	add_field("ID_Regione_Legale", 3);
 | 
						||
	add_field("ID_ISO_IVA", 2);
 | 
						||
	add_field("Partita_IVA", 12);
 | 
						||
	add_field("Codice_Fiscale", 16);
 | 
						||
	add_field("Codice_Fiscale_Estero", 16);
 | 
						||
	add_field("ID_Conto", 12);
 | 
						||
	add_field("ID_Conto_Fat", 12);
 | 
						||
	add_field("ID_Conto_Pag", 12);
 | 
						||
	add_field("ID_IVA", 12);
 | 
						||
	add_field("ID_Divisa", 3);
 | 
						||
	add_field("Bloccato", 1, INTFLD);
 | 
						||
	add_field("Data_Inizio_Rapporto", 8, DATEFLD);
 | 
						||
	add_field("ID_Tipo_Pagamento_Default", 1);
 | 
						||
	add_field("TitolareP_IVA", 1);
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TIP_fornitori_textset
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
TIP_fornitori_textset::TIP_fornitori_textset(const char* query) : TIP_textset(query)
 | 
						||
{
 | 
						||
	add_field("ID_Cliente", 6);
 | 
						||
	add_field("Descrizione_1", 40);
 | 
						||
	add_field("Descrizione_2", 40);
 | 
						||
	add_field("Indirizzo", 40);
 | 
						||
	add_field("Citta", 62);
 | 
						||
	add_field("Cap", 9);
 | 
						||
	add_field("ID_Provincia", 2);
 | 
						||
	add_field("ID_Regione", 3);
 | 
						||
	add_field("ID_Nazione_Estera", 3);
 | 
						||
	add_field("Email", 40);
 | 
						||
	add_field("Telefono1_1", 5);
 | 
						||
	add_field("Telefono1_2", 5);
 | 
						||
	add_field("Telefono1_3", 10);
 | 
						||
	add_field("Telefono2_1", 5);
 | 
						||
	add_field("Telefono2_2", 5);
 | 
						||
	add_field("Telefono2_3", 10);
 | 
						||
	add_field("Fax_1", 5);
 | 
						||
	add_field("Fax_2", 5);
 | 
						||
	add_field("Fax_3", 10);
 | 
						||
	add_field("PersonaContattare", 30);
 | 
						||
	add_field("Chiave_Ricerca", 40);
 | 
						||
	add_field("Nota", 80);
 | 
						||
	add_field("Flag_Persona_Fisica", 1);
 | 
						||
	add_field("Sesso", 1);
 | 
						||
	add_field("Data_Nascita", 8, DATEFLD);
 | 
						||
	add_field("Citta_Nascita", 62);
 | 
						||
	add_field("Cognome", 25);
 | 
						||
	add_field("Nome", 25);
 | 
						||
	add_field("Indirizzo_Legale", 40);
 | 
						||
	add_field("Citta_Legale", 62);
 | 
						||
	add_field("Cap_Legale", 9);
 | 
						||
	add_field("ID_Provincia_Legale", 2);
 | 
						||
	add_field("ID_Regione_Legale", 3);
 | 
						||
	add_field("ID_ISO_IVA", 2);
 | 
						||
	add_field("Partita_IVA", 12);
 | 
						||
	add_field("Codice_Fiscale", 16);
 | 
						||
	add_field("Codice_Fiscale_Estero", 16);
 | 
						||
	add_field("ID_Conto", 12);
 | 
						||
	add_field("ID_Conto_Fat", 12);
 | 
						||
	add_field("ID_Conto_Pag", 12);
 | 
						||
	add_field("ID_IVA", 12);
 | 
						||
	add_field("ID_Divisa", 3);
 | 
						||
	add_field("Flag_Enasarco", 1);
 | 
						||
	add_field("Data_Inizio_Rapporto", 8, DATEFLD);
 | 
						||
	add_field("Bloccato", 1, INTFLD);
 | 
						||
	add_field("ID_Tipo_Pagamento_Default", 1);
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TIP_scadenze_textset
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
TIP_scadenze_textset::TIP_scadenze_textset(const char* query) : TIP_textset(query)
 | 
						||
{
 | 
						||
	add_field("ID_Scadenza", 10, NPFLD);
 | 
						||
	add_field("Data_Scadenza", 8, DATEFLD);
 | 
						||
	add_field("Importo_Scadenza", 19, NUFLD); 
 | 
						||
	add_field("Importo_Divisa", 19, NUFLD);
 | 
						||
	add_field("ID_Divisa", 3);
 | 
						||
	add_field("ID_Tipo_Pagamento", 1);
 | 
						||
	add_field("ID_Movimento", 10, NPFLD);
 | 
						||
	add_field("Importo_IVASosp", 19, NUFLD);
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TIP_movimenti_textset
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
TIP_movimenti_textset::TIP_movimenti_textset(const char* query)
 | 
						||
             : TIP_textset(query)
 | 
						||
{
 | 
						||
	add_field("ID_Movimento", 10, NPFLD);
 | 
						||
	add_field("Data_Registrazione", 8, DATEFLD);
 | 
						||
	add_field("Data_Comp_Esercizio", 8, DATEFLD);
 | 
						||
	add_field("Data_Comp_LiqIVA", 8, DATEFLD);
 | 
						||
	add_field("Data_Documento", 8, DATEFLD);
 | 
						||
	add_field("Num_Documento", 10);
 | 
						||
	add_field("ID_Causale", 4, CFLD);
 | 
						||
	add_field("Descrizione", 40);
 | 
						||
	add_field("ID_Provvisorio", 2);
 | 
						||
	add_field("ID_RegIVA", 2);
 | 
						||
	add_field("Prot_IVA", 10);
 | 
						||
	add_field("ID_Conto", 12, CFLD);
 | 
						||
	add_field("ID_ContoCompetenza", 12);
 | 
						||
	add_field("ID_SubConto", 6);
 | 
						||
	add_field("Descrizione_Riga", 40);
 | 
						||
	add_field("Importo_Lire", 19, NUFLD);
 | 
						||
	add_field("Imponibile_IVA", 19, NUFLD);
 | 
						||
	add_field("ID_IVA", 3);
 | 
						||
	add_field("Importo_IVA", 19, NUFLD);
 | 
						||
	add_field("Indetraibilit<EFBFBD>", 3, INTFLD); // quanto lunghi gli interi
 | 
						||
	add_field("Importo_Divisa", 19, NUFLD);
 | 
						||
	add_field("ID_Divisa", 3);
 | 
						||
	add_field("Cambio", 19, NUFLD);
 | 
						||
	add_field("ID_Partita", 10);
 | 
						||
	add_field("Anno_Partita", 4, INTFLD);
 | 
						||
	add_field("Data_Inizio_Comp", 8, DATEFLD);
 | 
						||
	add_field("Data_Fine_Comp", 8, DATEFLD);
 | 
						||
	add_field("ID_Forfait", 1);
 | 
						||
	add_field("Tipo_Riga", 1, CFLD);
 | 
						||
	add_field("ID_CauRiga", 2);
 | 
						||
	add_field("ID_RegIVA_Vendite", 2);
 | 
						||
	add_field("Prot_IVA_Vendite", 10);
 | 
						||
	add_field("ID_Scadenza", 10, NUFLD);
 | 
						||
	add_field("TitolareP_IVA", 1);
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TIP_cespiti_textset
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
TIP_cespiti_textset::TIP_cespiti_textset(const char* query)
 | 
						||
             : TIP_textset(query)
 | 
						||
{
 | 
						||
	add_field("ID_Cespite", 6);
 | 
						||
	add_field("ID_CategoriaCespite", 10);
 | 
						||
	add_field("Descrizione", 40);
 | 
						||
	add_field("ID_Attivita", 2);
 | 
						||
	add_field("Ubicazione", 20);
 | 
						||
	add_field("ID_Fornitore", 6);
 | 
						||
	add_field("Data_Documento", 8, DATEFLD);
 | 
						||
	add_field("Num_Documento", 10);
 | 
						||
	add_field("Prot_IVA", 10);
 | 
						||
	add_field("TitoloAcquisto", 1);
 | 
						||
	add_field("Data_Inizio_Utilizzazione", 8, DATEFLD);
 | 
						||
	add_field("Costo", 19, NUFLD);
 | 
						||
	add_field("Flag_IndeducibilitaFiscale", 1);
 | 
						||
	add_field("PercIndeducibilita", 6, FLFLD); // quanto lunghi i float
 | 
						||
	add_field("Limite_Deducibilita", 10, NPFLD);
 | 
						||
	add_field("ValoreMassimoDeducibile", 19, NUFLD);
 | 
						||
	add_field("Flag_Autotrasportatori", 1);
 | 
						||
	add_field("Flag_Manutenzione", 1);
 | 
						||
	add_field("Flag_PubblicoRegistro", 1);
 | 
						||
	add_field("Flag_TecnoTremonti", 1);
 | 
						||
	add_field("CostoAgevolabile", 19, NUFLD);
 | 
						||
	add_field("StatoCespite", 1);
 | 
						||
	add_field("Flag_AmmTecnico", 1);
 | 
						||
	add_field("AliquotaAmmOrdinario", 4, NUFLD);
 | 
						||
	add_field("AliquotaAmmAnticipato", 4, NUFLD);
 | 
						||
	add_field("FondoAmmOrdinario", 19, NUFLD);
 | 
						||
	add_field("FondoAmmAnticipato", 19, NUFLD);
 | 
						||
	add_field("ValoreAmmortizzato", 19, NUFLD);
 | 
						||
	add_field("QuotaNonAmmortizzabile", 19, NUFLD);
 | 
						||
	add_field("Rivalutazioni", 19, NUFLD);
 | 
						||
	add_field("Svalutazioni", 19, NUFLD);
 | 
						||
	add_field("FondoSvalutazione", 19, NUFLD);
 | 
						||
	add_field("EccedenzaPregressa", 19, NUFLD);
 | 
						||
	add_field("SommatoriaDecrementi", 19, NUFLD);
 | 
						||
	add_field("Flag_NonCalcolare", 1);
 | 
						||
	add_field("DecrementoPeriodo", 19, NUFLD);
 | 
						||
	add_field("Flag_RecuperoCivilistico", 1);
 | 
						||
	add_field("Flag_IndeducibileRetroattiva", 1);
 | 
						||
	add_field("Flag_CalcoloPregressiFiscali", 1);
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TIP_categorie_textset
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
TIP_categorie_textset::TIP_categorie_textset(const char* query) : TIP_textset(query)
 | 
						||
{
 | 
						||
	add_field("ID_CategoriaCespite", 10);
 | 
						||
	add_field("Descrizione", 40);
 | 
						||
	add_field("TipoBene", 1);
 | 
						||
	add_field("Flag_StampaLibroImmateriale", 1);
 | 
						||
	add_field("AliquotaAmmOrdinario", 6, FLFLD); // lunghezza
 | 
						||
	add_field("Flag_AmmAnticipato", 1);
 | 
						||
	add_field("AliquotaAmmAnticipato", 6, FLFLD); // lunghezza
 | 
						||
	add_field("ID_ContoAmmAnticipato", 12);
 | 
						||
	add_field("ID_ContoFondoAmmAnticipato", 12);
 | 
						||
	add_field("ID_ContoAmmOrdinario", 12);
 | 
						||
	add_field("ID_ContoFondoAmmOrdinario", 12);
 | 
						||
	add_field("ID_ContoCespite", 12);
 | 
						||
	add_field("Flag_AmmIndiretto", 1);
 | 
						||
	add_field("ID_ContoMinusValenza", 12);
 | 
						||
	add_field("ID_ContoPlusValenza", 12);
 | 
						||
	add_field("Flag_PubblicoRegistro", 1);
 | 
						||
	add_field("ID_ContoSvalutazioni", 12);
 | 
						||
	add_field("ID_ContoRivalutazioni", 12);
 | 
						||
	add_field("ID_ContoFondoSvalutazioni", 12);
 | 
						||
	add_field("ID_ContoSopravvenienzePassive", 12);
 | 
						||
	add_field("Flag_Ammortizzabile", 1);
 | 
						||
	add_field("Flag_StampaLibroNonAmmort", 1);
 | 
						||
	add_field("ID_ContoRiservaRivalutazione", 12);
 | 
						||
	add_field("Flag_CategoriaMinisteriale", 1);
 | 
						||
	add_field("ID_ContoAmmAnticipatoNonDed", 12);
 | 
						||
	add_field("ID_ContoFdoAmmAnticipatoNonDed", 12);
 | 
						||
	add_field("ID_ContoAmmOrdinarioNonDed", 12);
 | 
						||
	add_field("ID_ContoFdoAmmOrdinarioNonDed", 12);
 | 
						||
	add_field("ID_ContoSvalutazioniNonDed", 12);
 | 
						||
	add_field("ID_ContoFdoSvalutazioniNonDed", 12);
 | 
						||
	add_field("ID_ContoRivalutazioniNonTassabile", 12);
 | 
						||
	add_field("ID_ContoRiservaRivalutazioniNonTassabile", 12);
 | 
						||
	add_field("ID_ContoMinusvalenzaNonDed", 12);
 | 
						||
	add_field("ID_ContoPlusvalenzaNonTassabile", 12);
 | 
						||
	add_field("ID_ContoSopravvenienzePassiveNonDed", 12);
 | 
						||
	add_field("ID_TipoCategoria", 1);
 | 
						||
	add_field("ID_VoceBilancio", 1);
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TIP_intra_textset
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
TIP_intra_textset::TIP_intra_textset(const char* query) : TIP_textset(query)
 | 
						||
{
 | 
						||
	add_field("ID_Subconto", 6, CFLD);
 | 
						||
	add_field("ID_Movim_CG", 10, NPFLD);
 | 
						||
	add_field("Data_Riferimento", 8, DATEFLD);
 | 
						||
	add_field("TipoMovimento", 1, NPFLD); // verificare
 | 
						||
	add_field("Importo", 19, NUFLD);
 | 
						||
	add_field("Importo_Divisa", 19, NUFLD); // Importo divisa movimento Intra
 | 
						||
	add_field("SezioneIntra", 1, INTFLD); //Sezione Intra. 0 = non definito, 1=Bis, 2= Ter, 3=Quater, 4=Quinquies
 | 
						||
	add_field("ID_NaturaTransazione", 1); // Codice della natura transazione
 | 
						||
	add_field("ID_NomenclaturaCombinata", 9); // Codice della nomenclatura combinata
 | 
						||
	add_field("ID_CondizioniConsegna", 1); // Condizioni Consegna  <20>C?, <20>D?, <20>E? o <20>F?
 | 
						||
	add_field("ID_ModalitaTrasporto", 1); // Codice della modalit<69> di trasporto
 | 
						||
	add_field("ID_SezioneDoganale", 6); // Sezione Doganale
 | 
						||
	add_field("ID_ProvinciaDest", 2); // Provincia destinazione
 | 
						||
	add_field("ID_NazioneProvenienza", 3); // Codice della nazione di provenienza
 | 
						||
	add_field("ID_NazioneOrigine", 3); // Codice della nazione di origine
 | 
						||
	add_field("MassaNetta", 19, NUFLD); // Massa netta
 | 
						||
	add_field("UnitaSupplementari", 10, NPFLD); // Unit<69> supplementare
 | 
						||
	add_field("ValoreStatistico", 19, NUFLD); // Valore statistico
 | 
						||
	add_field("PeriodoRettifica", 2, INTFLD); // Periodo rettifica (mese o trimestre) (*)
 | 
						||
	add_field("AnnoRettifica", 4, INTFLD); //Anno relativo al periodo di rettifica
 | 
						||
	add_field("Num_Documento", 10); // Alfanumerico: numero documento (Quater/Quinquies)
 | 
						||
	add_field("Data_Documento", 8, DATEFLD); // Data documento: data documento (Quater/Quinqies)
 | 
						||
	add_field("Codice_Servizio", 6); // Codice servizio
 | 
						||
	add_field("Mod_Erogazione", 1); // I = Istantanea, R = A pi<70> riprese
 | 
						||
	add_field("Mod_Incasso",1); // Modalit<69> incasso
 | 
						||
	add_field("Num_Protocollo", 10, NPFLD); // Numero protocollo da indicare nelle righe di rettifica del Quinquies
 | 
						||
	add_field("Prog_Riga", 10, NPFLD); // Progressivo riga (univoco) da indicare nelle righe di rettifica del Quinquies
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TIP_sender
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
void TIP_sender::log(int sev, const char* msg)
 | 
						||
{ 
 | 
						||
	if (_log != NULL)
 | 
						||
	{
 | 
						||
		if (sev > 0)
 | 
						||
		{
 | 
						||
			TString m;
 | 
						||
			m << TR("Record") <<  ": " << msg;
 | 
						||
			_log->log(sev, m); 
 | 
						||
			_errors_logged = true;
 | 
						||
		}
 | 
						||
		else
 | 
						||
			_log->log(sev, msg);
 | 
						||
	}
 | 
						||
}
 | 
						||
 | 
						||
bool TIP_sender::mov_regolarizzazione(const TRecordset& mov)
 | 
						||
{
 | 
						||
  const TString& codcaus = mov.get(MOV_CODCAUS).as_string();
 | 
						||
 | 
						||
	return _caus_regolarizzazione.objptr(codcaus) != NULL;
 | 
						||
}
 | 
						||
 | 
						||
bool TIP_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 TIP_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;
 | 
						||
}
 | 
						||
 | 
						||
bool TIP_sender::test_swap(const TRecordset& mov)
 | 
						||
{
 | 
						||
	const int anno = mov.get(MOV_ANNOIVA).as_int();
 | 
						||
	const TCausale & caus = _causali->causale(mov.get(MOV_CODCAUS).as_string(), anno);
 | 
						||
	char sez = caus.sezione_clifo();
 | 
						||
  const bool vendite = mov.get(MOV_TIPO).as_string()[0] != 'F';
 | 
						||
  
 | 
						||
  const bool s = vendite ^ (sez == 'D');
 | 
						||
  return s;
 | 
						||
}
 | 
						||
 | 
						||
bool TIP_sender::find_regolarizzazione(TRecordset& mov)
 | 
						||
{
 | 
						||
	bool found = false;
 | 
						||
  
 | 
						||
  const TRectype& caus = cache().get(LF_CAUSALI, mov.get(MOV_CODCAUS).as_string());
 | 
						||
	const TString4 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)
 | 
						||
		  totdoc += ritsoc;                        
 | 
						||
  if (test_swap(mov))
 | 
						||
		totdoc = -totdoc;
 | 
						||
 | 
						||
	TToken_string key(mov.get(MOV_TIPO).as_string());
 | 
						||
	key.add(mov.get(MOV_CODCF).as_int());
 | 
						||
	const TRectype & cli = cache().get(LF_CLIFO, key);
 | 
						||
	const TString16 paiv = cli.get(CLI_PAIV);
 | 
						||
	const TString16 cf = cli.get(CLI_COFI);
 | 
						||
	TEsercizi_contabili esc;
 | 
						||
	const TEsercizio & e = esc.esercizio(esc.date2esc(mov.get(MOV_DATAREG).as_date()));
 | 
						||
	const TDate to(e.fine());
 | 
						||
 | 
						||
	for (bool ok = mov.move_next(); ok && ! found; ok = mov.move_next())
 | 
						||
	{
 | 
						||
		const TDate dreg = mov.get(MOV_DATAREG).as_date();
 | 
						||
		if (dreg >to)
 | 
						||
			break;
 | 
						||
	  const TRectype& caus = cache().get(LF_CAUSALI, mov.get(MOV_CODCAUS).as_string());
 | 
						||
		const TString4 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());
 | 
						||
 | 
						||
		key = mov.get(MOV_TIPO).as_string();
 | 
						||
		key.add(mov.get(MOV_CODCF).as_int());
 | 
						||
		const TRectype & clireg = cache().get(LF_CLIFO, key);
 | 
						||
		const TString16 paivreg = clireg.get(CLI_PAIV);
 | 
						||
		const TString16 cfreg = clireg.get(CLI_COFI);
 | 
						||
 | 
						||
		found &= ((paiv.full() && paiv == paivreg) || (paiv.blank() && cf == cfreg));
 | 
						||
		if (found)
 | 
						||
			break;
 | 
						||
	}
 | 
						||
 | 
						||
	return found;
 | 
						||
}
 | 
						||
 | 
						||
const long TIP_sender::bill2ricl(char t, int gr, int co, long so)
 | 
						||
{
 | 
						||
  long codricl = 0;
 | 
						||
	if (gr > 0)
 | 
						||
	{
 | 
						||
		const bool ricl = _riclassifica.is_key(__tiporicconti);
 | 
						||
 | 
						||
		if (ricl)
 | 
						||
		{
 | 
						||
			codricl = ::IPbill2ricl(t, gr, co, so);
 | 
						||
 | 
						||
			if (codricl <= 0)
 | 
						||
			{
 | 
						||
				TString msg;
 | 
						||
				msg << TR("Conto") << " " << gr << " " << co << " " << so  << " :" << TR("Non presente in tabella");
 | 
						||
				log(2, msg);
 | 
						||
			}
 | 
						||
		}
 | 
						||
	}
 | 
						||
  return codricl;
 | 
						||
}
 | 
						||
 | 
						||
const TString & TIP_sender::scod2ricl(const char* tab, const TString& cod)
 | 
						||
{
 | 
						||
  TString & codricl = get_tmp_string();
 | 
						||
	if (cod.full())
 | 
						||
	{
 | 
						||
		const bool ricl = _riclassifica.is_key(tab);
 | 
						||
		const char* err = NULL;
 | 
						||
		if (ricl)
 | 
						||
		{
 | 
						||
			codricl = _tabelle->sdecode(tab, cod);
 | 
						||
			if (codricl.blank())
 | 
						||
				err = TR("Non presente in tabella");  
 | 
						||
		}
 | 
						||
		else
 | 
						||
			codricl = cod;
 | 
						||
		if (err)
 | 
						||
		{
 | 
						||
			TString msg;
 | 
						||
			msg << TR("Codice") << " " <<  cod << " " << TR("Tabella") << " " << tab << " :" << err;
 | 
						||
			log(2, msg);
 | 
						||
		}
 | 
						||
	}
 | 
						||
  return codricl;
 | 
						||
}
 | 
						||
 | 
						||
const TString & TIP_sender::scod2ricl(const char* tab, const TVariant& cod)
 | 
						||
{
 | 
						||
	return scod2ricl(tab, cod.as_string());
 | 
						||
}
 | 
						||
 | 
						||
const long TIP_sender::cod2ricl(const char* tab, const TString& cod)
 | 
						||
{
 | 
						||
  long codricl = 0;
 | 
						||
	if (cod.full())
 | 
						||
	{
 | 
						||
		const bool ricl = _riclassifica.is_key(tab);
 | 
						||
		const char* err = NULL;
 | 
						||
		if (ricl)
 | 
						||
		{
 | 
						||
			codricl = _tabelle->decode(tab, cod);
 | 
						||
			if (codricl <= 0)
 | 
						||
				err = TR("Non presente in tabella");  
 | 
						||
		}
 | 
						||
		else
 | 
						||
		{
 | 
						||
			if (real::is_natural(cod))
 | 
						||
				codricl = atol(cod);
 | 
						||
			else
 | 
						||
				err = TR("Non e' un codice numerico");  
 | 
						||
		}
 | 
						||
		if (err)
 | 
						||
		{
 | 
						||
			TString msg;
 | 
						||
			msg << TR("Codice") << " " <<  cod << " " << TR("Tabella") << " " << tab << " :" << err;
 | 
						||
			log(2, msg);
 | 
						||
		}
 | 
						||
	}
 | 
						||
  return codricl;
 | 
						||
}
 | 
						||
 | 
						||
const long TIP_sender::cod2ricl(const char* tab, const TVariant& cod)
 | 
						||
{
 | 
						||
	return cod2ricl(tab, cod.as_string());
 | 
						||
}
 | 
						||
 | 
						||
const TString & TIP_sender::pag2tipo(const TVariant & codpag)
 | 
						||
{
 | 
						||
	TString & str = get_tmp_string(4);
 | 
						||
	const int tipopag = atoi(cache().get("CPG", codpag.as_string(), "S4"));
 | 
						||
 | 
						||
	str = "";
 | 
						||
	if (tipopag < 2)
 | 
						||
		str = "D";
 | 
						||
	else
 | 
						||
		if (tipopag == 2)
 | 
						||
			str = "T";
 | 
						||
		else
 | 
						||
			if (tipopag == 3)
 | 
						||
				str = "B";
 | 
						||
			else
 | 
						||
				if (tipopag == 5)
 | 
						||
					str = "G";
 | 
						||
				else
 | 
						||
					if (tipopag == 7)
 | 
						||
						str = "T";
 | 
						||
					else
 | 
						||
						if (tipopag == 9)
 | 
						||
							str = "O";
 | 
						||
	return str;
 | 
						||
}
 | 
						||
 | 
						||
const TString & TIP_sender::row2cauriga(TISAM_recordset& rmov, const TCausale & caus)
 | 
						||
{
 | 
						||
	TString & str = get_tmp_string(4);
 | 
						||
	const char tipo = rmov.get(RMV_ROWTYPE).as_string()[0];
 | 
						||
	if (tipo == 'F')
 | 
						||
		str = "P5";
 | 
						||
	else
 | 
						||
		if (tipo == 'S')
 | 
						||
			str = "P6";
 | 
						||
		else
 | 
						||
			if (caus.tipomov() > 2)
 | 
						||
			{
 | 
						||
				TBill c;
 | 
						||
 | 
						||
				caus.bill(0, c);
 | 
						||
				if (c.tipo() == 'F')
 | 
						||
					str = "P7";
 | 
						||
				else
 | 
						||
					if (c.tipo() == 'C')
 | 
						||
						str = "P8";
 | 
						||
			}
 | 
						||
	return str;
 | 
						||
}
 | 
						||
void TIP_sender::get_pref(const TVariant & pref, TVariant & pint, TVariant & pnaz)
 | 
						||
{
 | 
						||
	if (pref.as_string()[0] == '+')
 | 
						||
	{
 | 
						||
		pint = pref.as_string().left(3);
 | 
						||
		pnaz = pref.as_string().mid(3);
 | 
						||
	}
 | 
						||
	else
 | 
						||
		if (pref.as_string().starts_with("00"))
 | 
						||
		{
 | 
						||
			pint = pref.as_string().left(4);
 | 
						||
			pnaz = pref.as_string().mid(4);
 | 
						||
		}
 | 
						||
		else
 | 
						||
		{
 | 
						||
			pint.set_null();
 | 
						||
			pnaz = pref;
 | 
						||
		}
 | 
						||
}
 | 
						||
 | 
						||
const real TIP_sender::ind2perc(const TVariant & tipodet)
 | 
						||
{
 | 
						||
	return real(cache().get("%DET", tipodet.as_string(), "R0")); //verificare
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::add_cli(TISAM_recordset & cli, TIP_clienti_textset & ipcli)
 | 
						||
{
 | 
						||
	TVariant val;
 | 
						||
	TVariant val1;
 | 
						||
	TToken_string key;
 | 
						||
 | 
						||
	ipcli.new_rec();
 | 
						||
	ipcli.set("ID_Cliente", cli.get(CLI_CODCF));
 | 
						||
	ipcli.set("Descrizione_1", cli.get(CLI_RAGSOC).as_string().left(40));
 | 
						||
	ipcli.set("Descrizione_2", cli.get(CLI_RAGSOC).as_string().mid(40));
 | 
						||
	val = cli.get(CLI_INDCF);
 | 
						||
	if (!cli.get(CLI_CIVCF).is_empty())
 | 
						||
	{
 | 
						||
		if (!val.is_empty())
 | 
						||
			val += ", ";
 | 
						||
		val += cli.get(CLI_CIVCF);
 | 
						||
	}
 | 
						||
	ipcli.set("Indirizzo", val);
 | 
						||
	val = cli.get(CLI_LOCCF);
 | 
						||
	if (!val.is_empty())
 | 
						||
		val += " ";
 | 
						||
	key.add(cli.get(CLI_STATOCF).as_string());
 | 
						||
	key.add(cli.get(CLI_COMCF).as_string());
 | 
						||
	
 | 
						||
	const TRectype & comune = cache().get(LF_COMUNI, key);
 | 
						||
	val += comune.get(COM_DENCOM);
 | 
						||
	ipcli.set("Citta", val);
 | 
						||
	ipcli.set("Cap", cli.get(CLI_CAPCF));
 | 
						||
	ipcli.set("ID_Provincia", comune.get(COM_PROVCOM));
 | 
						||
	ipcli.set("ID_Regione", comune.get(COM_CODREG));
 | 
						||
	ipcli.set("ID_Nazione_Estera", scod2ricl(NAZ, cli.get(CLI_STATOCF)));
 | 
						||
	ipcli.set("Email", cli.get(CLI_DOCMAIL));
 | 
						||
	get_pref(cli.get(CLI_PTEL), val, val1);
 | 
						||
	ipcli.set("Telefono1_1", val);
 | 
						||
	ipcli.set("Telefono1_2", val1);
 | 
						||
	ipcli.set("Telefono1_3", cli.get(CLI_TEL));
 | 
						||
	get_pref(cli.get(CLI_PTEL2), val, val1);
 | 
						||
	ipcli.set("Telefono2_1", val);
 | 
						||
	ipcli.set("Telefono2_2", val1);
 | 
						||
	ipcli.set("Telefono2_3", cli.get(CLI_TEL2));
 | 
						||
	get_pref(cli.get(CLI_PFAX), val, val1);
 | 
						||
	ipcli.set("Fax_1", val);
 | 
						||
	ipcli.set("Fax_2", val1);
 | 
						||
	ipcli.set("Fax_3", cli.get(CLI_FAX));
 | 
						||
	ipcli.set("Chiave_Ricerca", cli.get(CLI_RICALT));
 | 
						||
	const bool persona_fisica = cli.get(CLI_TIPOAPER).as_string() == "F";
 | 
						||
	ipcli.set("Flag_Persona_Fisica", persona_fisica ? "S" : "N");
 | 
						||
	if (persona_fisica)
 | 
						||
	{
 | 
						||
		key.cut(0);
 | 
						||
		key.add(cli.get(CLI_TIPOAPER).as_string());
 | 
						||
		key.add(cli.get(CLI_CODANAGPER).as_string());
 | 
						||
		const TRectype & recanag = cache().get(LF_ANAG, key); 
 | 
						||
		const TRectype & recpf = cache().get(LF_ANAGFIS, cli.get(CLI_CODANAGPER).as_string()); 
 | 
						||
 | 
						||
		ipcli.set("Sesso", recpf.get(ANF_SESSO));
 | 
						||
		ipcli.set("Data_Nascita", recpf.get(ANF_DATANASC));
 | 
						||
		key.cut(0);
 | 
						||
		key.add(recpf.get(ANF_STATONASC));
 | 
						||
		key.add(recpf.get(ANF_COMNASC));
 | 
						||
		
 | 
						||
		const TRectype & comunenasc = cache().get(LF_COMUNI, key);
 | 
						||
 | 
						||
		ipcli.set("Citta_Nascita", comunenasc.get(COM_DENCOM));
 | 
						||
		ipcli.set("Cognome", recanag.get(ANA_RAGSOC).left(25));
 | 
						||
		ipcli.set("Nome", recanag.get(ANA_RAGSOC).mid(25));
 | 
						||
	}
 | 
						||
	ipcli.set("ID_ISO_IVA", cli.get(CLI_STATOPAIV));
 | 
						||
	ipcli.set("Partita_IVA", cli.get(CLI_PAIV));
 | 
						||
	const int alleg = cli.get(CLI_ALLEG).as_int();
 | 
						||
	if (alleg != 5)
 | 
						||
		ipcli.set("Codice_Fiscale", cli.get(CLI_COFI));
 | 
						||
	else
 | 
						||
		ipcli.set("Codice_Fiscale_Estero", cli.get(CLI_COFI));
 | 
						||
	if (cli.get(CLI_PAIV).is_empty() && cli.get(CLI_COFI).is_empty())
 | 
						||
	{
 | 
						||
		TString cod = cli.get(CLI_TIPOCF).as_string();
 | 
						||
 | 
						||
		cod << cli.get(CLI_CODCF).as_int();
 | 
						||
		ipcli.set("Codice_Fiscale", cod);
 | 
						||
	}
 | 
						||
	ipcli.set("ID_Conto", bill2ricl(' ', cli.get(CLI_GRUPPO).as_int(), cli.get(CLI_CONTO).as_int(), 0L));
 | 
						||
	ipcli.set("ID_Conto_Fat", bill2ricl(' ', cli.get(CLI_GRUPPORIC).as_int(), cli.get(CLI_CONTORIC).as_int(), cli.get(CLI_SOTTOCRIC).as_int()));
 | 
						||
	ipcli.set("ID_Divisa", scod2ricl(VAL, cli.get(CLI_CODVAL)));
 | 
						||
	ipcli.set("Bloccato", cli.get(CLI_SOSPESO).as_bool() ? "0" : "9");
 | 
						||
	ipcli.set("ID_Tipo_Pagamento_Default", pag2tipo(cli.get(CLI_CODPAG)));
 | 
						||
	ipcli.set("TitolareP_IVA", alleg != 6 ? "S" : "N");
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::transfer_cli(const char * path)
 | 
						||
{
 | 
						||
 | 
						||
	TIP_clienti_textset ipcli;
 | 
						||
	TString query;
 | 
						||
	
 | 
						||
	query << "USE " << LF_CLIFO << '\n' << "FROM " << CLI_TIPOCF << "=\"C\"\n" << "TO " << CLI_TIPOCF << "=\"C\"\n";
 | 
						||
 | 
						||
	TISAM_recordset cli(query);
 | 
						||
  log(0, "Clienti");
 | 
						||
	_errors_logged = false;
 | 
						||
  TProgind pi(cli.items(), TR("Scansione clienti"), true, true);
 | 
						||
 | 
						||
  for (bool ok = cli.move_first(); ok && pi.addstatus(1); ok = cli.move_next())
 | 
						||
		add_cli(cli, ipcli);					
 | 
						||
 | 
						||
  bool save = true;
 | 
						||
	_errors |= _errors_logged;
 | 
						||
  if (_errors_logged)
 | 
						||
    save = yesno_box(TR("Sono stati riscontrati uno o piu' errori:\n"
 | 
						||
                        "Si desidera salvare il file ugualmente?"));
 | 
						||
  if (save)
 | 
						||
  {
 | 
						||
		TFilename name(path);
 | 
						||
 | 
						||
		name.add("clienti.txt");
 | 
						||
		ipcli.save_as(name);
 | 
						||
  }
 | 
						||
}
 | 
						||
void TIP_sender::add_forn(TISAM_recordset & forn, TIP_fornitori_textset & ipforn)
 | 
						||
{
 | 
						||
	TVariant val;
 | 
						||
	TVariant val1;
 | 
						||
	TToken_string key;
 | 
						||
 | 
						||
	ipforn.new_rec();
 | 
						||
	ipforn.set("ID_Cliente", forn.get(CLI_CODCF));
 | 
						||
	ipforn.set("Descrizione_1", forn.get(CLI_RAGSOC).as_string().left(40));
 | 
						||
	ipforn.set("Descrizione_2", forn.get(CLI_RAGSOC).as_string().mid(40));
 | 
						||
	val = forn.get(CLI_INDCF);
 | 
						||
	if (!forn.get(CLI_CIVCF).is_empty())
 | 
						||
	{
 | 
						||
		if (!val.is_empty())
 | 
						||
			val += ", ";
 | 
						||
		val += forn.get(CLI_CIVCF);
 | 
						||
	}
 | 
						||
	ipforn.set("Indirizzo", val);
 | 
						||
	val = forn.get(CLI_LOCCF);
 | 
						||
	if (!val.is_empty())
 | 
						||
		val += " ";
 | 
						||
	key.add(forn.get(CLI_STATOCF).as_string());
 | 
						||
	key.add(forn.get(CLI_COMCF).as_string());
 | 
						||
	
 | 
						||
	const TRectype & comune = cache().get(LF_COMUNI, key);
 | 
						||
	val += comune.get(COM_DENCOM);
 | 
						||
	ipforn.set("Citta", val);
 | 
						||
	ipforn.set("Cap", forn.get(CLI_CAPCF));
 | 
						||
	ipforn.set("ID_Provincia", comune.get(COM_PROVCOM));
 | 
						||
	ipforn.set("ID_Regione", comune.get(COM_CODREG));
 | 
						||
	ipforn.set("ID_Nazione_Estera", scod2ricl(NAZ, forn.get(CLI_STATOCF)));
 | 
						||
	ipforn.set("Email", forn.get(CLI_DOCMAIL));
 | 
						||
	get_pref(forn.get(CLI_PTEL), val, val1);
 | 
						||
	ipforn.set("Telefono1_1", val);
 | 
						||
	ipforn.set("Telefono1_2", val1);
 | 
						||
	ipforn.set("Telefono1_3", forn.get(CLI_TEL));
 | 
						||
	get_pref(forn.get(CLI_PTEL2), val, val1);
 | 
						||
	ipforn.set("Telefono2_1", val);
 | 
						||
	ipforn.set("Telefono2_2", val1);
 | 
						||
	ipforn.set("Telefono2_3", forn.get(CLI_TEL2));
 | 
						||
	get_pref(forn.get(CLI_PFAX), val, val1);
 | 
						||
	ipforn.set("Fax_1", val);
 | 
						||
	ipforn.set("Fax_2", val1);
 | 
						||
	ipforn.set("Fax_3", forn.get(CLI_FAX));
 | 
						||
	ipforn.set("Chiave_Ricerca", forn.get(CLI_RICALT));
 | 
						||
	const bool persona_fisica = forn.get(CLI_TIPOAPER).as_string() == "F";
 | 
						||
	ipforn.set("Flag_Persona_Fisica", persona_fisica ? "S" : "N");
 | 
						||
	if (persona_fisica)
 | 
						||
	{
 | 
						||
		key.cut(0);
 | 
						||
		key.add(forn.get(CLI_TIPOAPER).as_string());
 | 
						||
		key.add(forn.get(CLI_CODANAGPER).as_string());
 | 
						||
		const TRectype & recanag = cache().get(LF_ANAG, key); 
 | 
						||
		const TRectype & recpf = cache().get(LF_ANAGFIS, forn.get(CLI_CODANAGPER).as_string()); 
 | 
						||
 | 
						||
		ipforn.set("Sesso", recpf.get(ANF_SESSO));
 | 
						||
		ipforn.set("Data_Nascita", recpf.get(ANF_DATANASC));
 | 
						||
		key.cut(0);
 | 
						||
		key.add(recpf.get(ANF_STATONASC));
 | 
						||
		key.add(recpf.get(ANF_COMNASC));
 | 
						||
		
 | 
						||
		const TRectype & comunenasc = cache().get(LF_COMUNI, key);
 | 
						||
 | 
						||
		ipforn.set("Citta_Nascita", comunenasc.get(COM_DENCOM));
 | 
						||
		ipforn.set("Cognome", recanag.get(ANA_RAGSOC).left(25));
 | 
						||
		ipforn.set("Nome", recanag.get(ANA_RAGSOC).mid(25));
 | 
						||
	}
 | 
						||
	ipforn.set("ID_ISO_IVA", forn.get(CLI_STATOPAIV));
 | 
						||
	ipforn.set("Partita_IVA", forn.get(CLI_PAIV));
 | 
						||
	const int alleg = forn.get(CLI_ALLEG).as_int();
 | 
						||
	if (alleg != 5)
 | 
						||
		ipforn.set("Codice_Fiscale", forn.get(CLI_COFI));
 | 
						||
	else
 | 
						||
		ipforn.set("Codice_Fiscale_Estero", forn.get(CLI_COFI));
 | 
						||
	ipforn.set("ID_Conto", bill2ricl(' ', forn.get(CLI_GRUPPO).as_int(), forn.get(CLI_CONTO).as_int(), 0L));
 | 
						||
	ipforn.set("ID_Conto_Fat", bill2ricl(' ', forn.get(CLI_GRUPPORIC).as_int(), forn.get(CLI_CONTORIC).as_int(), forn.get(CLI_SOTTOCRIC).as_int()));
 | 
						||
	ipforn.set("ID_Divisa", scod2ricl(VAL, forn.get(CLI_CODVAL)));
 | 
						||
	ipforn.set("Bloccato", forn.get(CLI_SOSPESO).as_bool() ? "0" : "9");
 | 
						||
	ipforn.set("ID_Tipo_Pagamento_Default", pag2tipo(forn.get(CLI_CODPAG)));
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::transfer_forn(const char * path)
 | 
						||
{
 | 
						||
  log(0, "Fornitori");
 | 
						||
 | 
						||
	TIP_fornitori_textset ipforn;
 | 
						||
	TString query;
 | 
						||
	
 | 
						||
	query << "USE " << LF_CLIFO << '\n' << "FROM " << CLI_TIPOCF << "=\"F\"\n" << "TO " << CLI_TIPOCF << "=\"F\"\n";
 | 
						||
 | 
						||
	TISAM_recordset forn(query);
 | 
						||
	_errors_logged = false;
 | 
						||
  TProgind pi(forn.items(), TR("Scansione fornitori"), true, true);
 | 
						||
 | 
						||
  for (bool ok = forn.move_first(); ok && pi.addstatus(1); ok = forn.move_next())
 | 
						||
		add_forn(forn, ipforn);					
 | 
						||
 | 
						||
  bool save = true;
 | 
						||
	_errors |= _errors_logged;
 | 
						||
  if (_errors_logged)
 | 
						||
    save = yesno_box(TR("Sono stati riscontrati uno o piu' errori:\n"
 | 
						||
                        "Si desidera salvare il file ugualmente?"));
 | 
						||
  if (save)
 | 
						||
  {
 | 
						||
		TFilename name(path);
 | 
						||
 | 
						||
		name.add("fornitori.txt");
 | 
						||
		ipforn.save_as(name);
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::add_mov_cg(TISAM_recordset & mov, TIP_movimenti_textset & ipmov, const TVariant & reg_regol, const TVariant & prot_regol, const char tipo)
 | 
						||
{
 | 
						||
	TVariant val;
 | 
						||
	TToken_string key;
 | 
						||
	TString query;
 | 
						||
  const int anno = mov.get(MOV_ANNOIVA).as_int();
 | 
						||
	const TCausale & caus = _causali->causale(mov.get(MOV_CODCAUS).as_string(), anno);
 | 
						||
	char tipocf = mov.get(MOV_TIPO).as_string()[0];
 | 
						||
	long codcf = mov.get(MOV_CODCF).as_int();
 | 
						||
	key.cut(0);
 | 
						||
	key.add(tipocf);
 | 
						||
	key.add(codcf);
 | 
						||
	const int alleg = atoi(cache().get(LF_CLIFO, key, CLI_ALLEG));
 | 
						||
	const TVariant & numreg = mov.get(MOV_NUMREG);
 | 
						||
	
 | 
						||
 | 
						||
	query << "USE " << LF_RMOV << "\nFROM " << RMV_NUMREG << "=" << numreg << "\nTO " << RMV_NUMREG << "=" << numreg << "\n";
 | 
						||
 | 
						||
	TISAM_recordset	rmov(query);
 | 
						||
 | 
						||
  for (bool ok = rmov.move_first(); ok; ok = rmov.move_next())
 | 
						||
	{
 | 
						||
		TString tiporiga = rmov.get(RMV_ROWTYPE).as_string();
 | 
						||
 | 
						||
		if (tipo == ' ' || tipo == tiporiga[0])
 | 
						||
		{
 | 
						||
			ipmov.new_rec();
 | 
						||
			ipmov.set("ID_Movimento", mov.get(MOV_NUMREG));
 | 
						||
			ipmov.set("Data_Registrazione", mov.get(MOV_DATAREG));
 | 
						||
			ipmov.set("Data_Comp_Esercizio", mov.get(MOV_DATACOMP));
 | 
						||
			ipmov.set("Data_Documento", mov.get(MOV_DATADOC));
 | 
						||
			ipmov.set("Num_Documento", mov.get(MOV_NUMDOC));
 | 
						||
			ipmov.set("ID_Causale", scod2ricl(CAU, mov.get(MOV_CODCAUS)));
 | 
						||
			ipmov.set("Descrizione", mov.get(MOV_DESCR).as_string().left(40));
 | 
						||
			// ipmov.set("ID_Provvisorio", 2); // da ferificare???
 | 
						||
			ipmov.set("ID_RegIVA", scod2ricl(REG, mov.get(MOV_REG)));
 | 
						||
			ipmov.set("Prot_IVA", mov.get(MOV_PROTIVA));
 | 
						||
			char tipoconto = rmov.get(RMV_TIPOC).as_string()[0]; 
 | 
						||
			val = bill2ricl(tipoconto, 
 | 
						||
											rmov.get(RMV_GRUPPO).as_int(), 
 | 
						||
											rmov.get(RMV_CONTO).as_int(), 
 | 
						||
											rmov.get(RMV_SOTTOCONTO).as_int());
 | 
						||
			ipmov.set("ID_Conto", val);
 | 
						||
			if (tiporiga == "T" || tipoconto > ' ')
 | 
						||
				ipmov.set("ID_SubConto", mov.get(MOV_CODCF));
 | 
						||
			ipmov.set("Descrizione_Riga", rmov.get(RMV_DESCR).as_string().left(40));
 | 
						||
			ipmov.set("Importo_Lire", rmov.get(RMV_SEZIONE).as_string() == "D" ? rmov.get(RMV_IMPORTO).as_real() : -rmov.get(RMV_IMPORTO).as_real());
 | 
						||
			key = numreg.as_string();
 | 
						||
			key.add(rmov.get(RMV_NUMRIG).as_string());
 | 
						||
			const TRectype & partrec = _part->get(key);
 | 
						||
			ipmov.set("ID_Partita", partrec.get(PART_NUMPART));
 | 
						||
			ipmov.set("Anno_Partita", partrec.get(PART_ANNO));
 | 
						||
			val = "";
 | 
						||
			if (tiporiga == "T")
 | 
						||
				val = "S";
 | 
						||
			else
 | 
						||
				if (tiporiga == "N" || tiporiga == "D")
 | 
						||
					val = "I";
 | 
						||
			ipmov.set("Tipo_Riga", val);
 | 
						||
			ipmov.set("ID_CauRiga", row2cauriga(rmov, caus));
 | 
						||
			ipmov.set("ID_RegIVA_Vendite", reg_regol);
 | 
						||
			ipmov.set("Prot_IVA_Vendite", prot_regol);
 | 
						||
			ipmov.set("TitolareP_IVA", alleg != 6 ? "S" : "N");
 | 
						||
		}
 | 
						||
	}
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::add_mov_iva(TISAM_recordset & mov, TIP_movimenti_textset & ipmov, const TVariant & reg_regol, const TVariant & prot_regol)
 | 
						||
{
 | 
						||
	add_mov_cg(mov, ipmov, reg_regol, prot_regol, 'T');
 | 
						||
  const int anno = mov.get(MOV_ANNOIVA).as_int();
 | 
						||
	const TCausale & caus = _causali->causale(mov.get(MOV_CODCAUS).as_string(), anno);
 | 
						||
//	const char sezione = caus.sezione(2);
 | 
						||
//	const real fattore = (sezione == 'D' ? UNO : -UNO);
 | 
						||
	const TipoIVA tipo = caus.iva();
 | 
						||
	const real fattore = (tipo == iva_acquisti ? UNO : -UNO);
 | 
						||
	char tipocf = mov.get(MOV_TIPO).as_string()[0];
 | 
						||
	long codcf = mov.get(MOV_CODCF).as_int();
 | 
						||
	TToken_string key;
 | 
						||
	key.add(tipocf);
 | 
						||
	key.add(codcf);
 | 
						||
	const int alleg = atoi(cache().get(LF_CLIFO, key, CLI_ALLEG));
 | 
						||
	const TVariant & numreg = mov.get(MOV_NUMREG);
 | 
						||
	TString query;
 | 
						||
	TVariant val;
 | 
						||
 | 
						||
	if (numreg.as_int() == 88L)
 | 
						||
		int i = 1;
 | 
						||
	query << "USE " << LF_RMOVIVA << "\nFROM " << RMI_NUMREG << "=" << numreg << "\nTO " << RMI_NUMREG << "=" << numreg << "\n";
 | 
						||
 | 
						||
	TISAM_recordset	rivamov(query);
 | 
						||
 | 
						||
	for (bool ok = rivamov.move_first(); ok; ok = rivamov.move_next())
 | 
						||
	{
 | 
						||
		ipmov.new_rec();
 | 
						||
		ipmov.set("ID_Movimento", mov.get(MOV_NUMREG));
 | 
						||
		ipmov.set("Data_Registrazione", mov.get(MOV_DATAREG));
 | 
						||
		ipmov.set("Data_Comp_Esercizio", mov.get(MOV_DATACOMP));
 | 
						||
		ipmov.set("Data_Documento", mov.get(MOV_DATADOC));
 | 
						||
		ipmov.set("Num_Documento", mov.get(MOV_NUMDOC));
 | 
						||
		ipmov.set("ID_Causale", scod2ricl(CAU, mov.get(MOV_CODCAUS)));
 | 
						||
		ipmov.set("Descrizione", mov.get(MOV_DESCR).as_string().left(40));
 | 
						||
//				ipmov.set("ID_Provvisorio", 2); da chiarire
 | 
						||
		ipmov.set("ID_RegIVA", scod2ricl(REG, mov.get(MOV_REG)));
 | 
						||
		ipmov.set("Prot_IVA", mov.get(MOV_PROTIVA));
 | 
						||
		const char tipoconto = rivamov.get(RMI_TIPOC).as_string()[0];
 | 
						||
		const long sottoconto = rivamov.get(RMI_SOTTOCONTO).as_int();
 | 
						||
		val = bill2ricl(tipoconto, 
 | 
						||
										rivamov.get(RMI_GRUPPO).as_int(), 
 | 
						||
										rivamov.get(RMI_CONTO).as_int(), 
 | 
						||
										sottoconto);
 | 
						||
		ipmov.set("ID_Conto", val);
 | 
						||
			if (tipoconto > ' ')
 | 
						||
				ipmov.set("ID_SubConto", sottoconto);
 | 
						||
		const real imponibile = rivamov.get(RMI_IMPONIBILE).as_real();
 | 
						||
		const real imposta = rivamov.get(RMI_IMPOSTA).as_real();
 | 
						||
		real impind;
 | 
						||
		real impdet;
 | 
						||
		real ivaind;
 | 
						||
		real ivadet;
 | 
						||
		int tipodet;
 | 
						||
		const real perc = indetraibile_al(rivamov.get(RMI_TIPODET).as_string(), caus, anno, tipodet);
 | 
						||
 | 
						||
		analizza_IVA(imponibile, imposta, perc, false, true, rivamov.get(RMI_CODIVA).as_string(),
 | 
						||
             impdet, ivadet, impind, ivaind); // attenzione ai corrispettivi
 | 
						||
		const real totimp = impdet + impind;
 | 
						||
		ipmov.set("Importo_Lire", totimp * fattore);
 | 
						||
		ipmov.set("Imponibile_IVA", abs(imponibile));
 | 
						||
		ipmov.set("ID_IVA", scod2ricl(IVA, rivamov.get(RMI_CODIVA)));
 | 
						||
		ipmov.set("Importo_IVA", abs(imposta));
 | 
						||
		ipmov.set("Indetraibilit<EFBFBD>", ind2perc(rivamov.get(RMI_TIPODET)));
 | 
						||
		ipmov.set("ID_CauRiga", "" ); // finire
 | 
						||
		ipmov.set("ID_RegIVA_Vendite", reg_regol);
 | 
						||
		ipmov.set("Prot_IVA_Vendite", prot_regol);
 | 
						||
//				ipmov.set("ID_Scadenza", numreg); // verificare
 | 
						||
		ipmov.set("TitolareP_IVA", alleg != 6 ? "S" : "N");
 | 
						||
	}
 | 
						||
	add_mov_cg(mov, ipmov, reg_regol, prot_regol, 'D');
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::add_mov(TISAM_recordset & mov, TIP_movimenti_textset & ipmov)
 | 
						||
{
 | 
						||
  TString msg; msg << TR("Registrazione n.") << ' ' << mov.get(MOV_NUMREG);
 | 
						||
  log(0, msg);
 | 
						||
 | 
						||
	const TRecnotype pos = mov.current_row(); // Salva la posizione
 | 
						||
  const bool is_intra = mov_intra(mov);
 | 
						||
	TVariant reg_regol;
 | 
						||
	TVariant prot_regol;
 | 
						||
 | 
						||
	if (is_intra ||	mov_reverse_charge(mov))
 | 
						||
	{
 | 
						||
		if (find_regolarizzazione(mov))
 | 
						||
		{
 | 
						||
			prot_regol =  mov.get(MOV_PROTIVA).as_int();
 | 
						||
			reg_regol = scod2ricl(REG, mov.get(MOV_REG));
 | 
						||
		}
 | 
						||
		else
 | 
						||
		{
 | 
						||
			if (is_intra)
 | 
						||
				log(2, TR("Manca la regolarizzazione del movimento intra"));
 | 
						||
			else
 | 
						||
				log(2, TR("Manca la regolarizzazione del movimento reverse charge"));
 | 
						||
		}
 | 
						||
		mov.move_to(pos); // Ripristina posizione
 | 
						||
	}
 | 
						||
 | 
						||
	const bool moviva = !mov.get(MOV_REG).is_empty();
 | 
						||
 | 
						||
	if (moviva)
 | 
						||
		add_mov_iva(mov, ipmov, reg_regol, prot_regol);
 | 
						||
	else
 | 
						||
		add_mov_cg(mov,ipmov, reg_regol, prot_regol);
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::transfer_mov(const char * path)
 | 
						||
{
 | 
						||
  log(0, "Movimenti");
 | 
						||
 | 
						||
	TIP_movimenti_textset ipmov;
 | 
						||
	TString query;
 | 
						||
	
 | 
						||
	query << "USE " << LF_MOV << " KEY 2 SELECT " << MOV_INVIATO << "!=\"X\"\n"
 | 
						||
		    << "FROM " << MOV_DATAREG << "=" << _mask->get_date(F_DATA_DA) << "\n"
 | 
						||
				<< "TO " << MOV_DATAREG << "=" << _mask->get_date(F_DATA_AL) << "\n";      
 | 
						||
 | 
						||
	TISAM_recordset mov(query);
 | 
						||
	_errors_logged = false;
 | 
						||
  TProgind pi(mov.items(), TR("Scansione movimenti"), true, true);
 | 
						||
 | 
						||
  for (bool ok = mov.move_first(); ok && pi.addstatus(1); ok = mov.move_next())
 | 
						||
		if (!mov_regolarizzazione(mov))
 | 
						||
			add_mov(mov, ipmov);					
 | 
						||
 | 
						||
  bool save = true;
 | 
						||
	_errors |= _errors_logged;
 | 
						||
  if (_errors_logged)
 | 
						||
    save = yesno_box(TR("Sono stati riscontrati uno o piu' errori:\n"
 | 
						||
                        "Si desidera salvare il file ugualmente?"));
 | 
						||
  if (save)
 | 
						||
  {
 | 
						||
		TFilename name(path);
 | 
						||
 | 
						||
		name.add("movimenti.txt");
 | 
						||
		ipmov.save_as(name);
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::add_scad(TISAM_recordset & mov, TIP_scadenze_textset & ipscad)
 | 
						||
{
 | 
						||
	TToken_string key;
 | 
						||
	const TVariant & numreg = mov.get(MOV_NUMREG);
 | 
						||
  TString msg; msg << TR("Registrazione n.") << ' ' << numreg.as_string();
 | 
						||
  log(0, msg);
 | 
						||
 | 
						||
	key = numreg.as_string();
 | 
						||
	key.add(1);
 | 
						||
	const TRectype & partrec = _part->get(key);
 | 
						||
	TString query;
 | 
						||
	
 | 
						||
	query << "USE " << LF_SCADENZE << "\n"
 | 
						||
				<< "FROM " << SCAD_TIPOCF << "=" << mov.get(MOV_TIPO).as_string() << " " << SCAD_GRUPPO << "=\"\"" << " " << SCAD_CONTO << "=\"\""
 | 
						||
				<< " " << SCAD_SOTTOCONTO << "=" << mov.get(MOV_CODCF).as_string() << " " << SCAD_ANNO << "=" << partrec.get(PART_ANNO)
 | 
						||
				<< " " << SCAD_NUMPART << "=" << partrec.get(PART_NUMPART)	<< " " << SCAD_NRIGA << "=" << partrec.get(PART_NRIGA) << "\n"
 | 
						||
				<< "TO " << SCAD_TIPOCF << "=" << mov.get(MOV_TIPO).as_string() << " " << SCAD_GRUPPO << "=\"\"" << " " << SCAD_CONTO << "=\"\""
 | 
						||
				<< " " << SCAD_SOTTOCONTO << "=" << mov.get(MOV_CODCF).as_string() << " " << SCAD_ANNO << "=" << partrec.get(PART_ANNO)
 | 
						||
				<< " " << SCAD_NUMPART << "=" << partrec.get(PART_NUMPART)	<< " " << SCAD_NRIGA << "=" << partrec.get(PART_NRIGA) << "\n";
 | 
						||
 | 
						||
	TISAM_recordset scad(query);
 | 
						||
 | 
						||
	for (bool ok = scad.move_first(); ok; ok = scad.move_next())
 | 
						||
	{
 | 
						||
		ipscad.new_rec();
 | 
						||
		ipscad.set("ID_Scadenza", ++_ultscadid); 
 | 
						||
		ipscad.set("Data_Scadenza", scad.get(SCAD_DATASCAD));
 | 
						||
		ipscad.set("Importo_Scadenza", scad.get(SCAD_IMPORTO)); 
 | 
						||
		ipscad.set("Importo_Divisa", scad.get(SCAD_IMPORTOVAL));
 | 
						||
		ipscad.set("ID_Divisa", scod2ricl(VAL, mov.get(MOV_CODVAL)));
 | 
						||
		ipscad.set("ID_Tipo_Pagamento", pag2tipo(mov.get(MOV_CODPAG)));
 | 
						||
		ipscad.set("ID_Movimento", numreg);
 | 
						||
	}
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::transfer_scad(const char * path)
 | 
						||
{
 | 
						||
  log(0, "Scadenze");
 | 
						||
 | 
						||
	TIP_scadenze_textset ipscad;
 | 
						||
	TString query;
 | 
						||
	
 | 
						||
	query << "USE " << LF_MOV << " KEY 2 SELECT (" << MOV_INVIATO << "!=\"X\")&&(" << MOV_REG << "!=\"\")\n" 
 | 
						||
		    << "FROM " << MOV_DATAREG << "=" << _mask->get_date(F_DATA_DA) << "\n"
 | 
						||
				<< "TO " << MOV_DATAREG << "=" << _mask->get_date(F_DATA_AL) << "\n";      
 | 
						||
	
 | 
						||
	TISAM_recordset mov(query);
 | 
						||
	_errors_logged = false;
 | 
						||
  TProgind pi(mov.items(), TR("Scansione scadenze"), true, true);
 | 
						||
 | 
						||
  for (bool ok = mov.move_first(); ok && pi.addstatus(1); ok = mov.move_next())
 | 
						||
	{
 | 
						||
	  const int anno = mov.get(MOV_ANNOIVA).as_int();
 | 
						||
		const TCausale & caus = _causali->causale(mov.get(MOV_CODCAUS).as_string(), anno);
 | 
						||
		if (caus.tipomov() > 0 && caus.tipomov() <= 2)
 | 
						||
			add_scad(mov, ipscad);					
 | 
						||
	}
 | 
						||
 | 
						||
  bool save = true;
 | 
						||
	_errors |= _errors_logged;
 | 
						||
  if (_errors_logged)
 | 
						||
    save = yesno_box(TR("Sono stati riscontrati uno o piu' errori:\n"
 | 
						||
                        "Si desidera salvare il file ugualmente?"));
 | 
						||
  if (save)
 | 
						||
  {
 | 
						||
		TFilename name(path);
 | 
						||
 | 
						||
		name.add("scadenze.txt");
 | 
						||
		ipscad.save_as(name);
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::transfer_cesp(const char * path)
 | 
						||
{
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::transfer_cat(const char * path)
 | 
						||
{
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::add_intra(TISAM_recordset & mov, TIP_intra_textset & ipintra)
 | 
						||
{
 | 
						||
	TToken_string key;
 | 
						||
	const TVariant & numreg = mov.get(MOV_NUMREG);
 | 
						||
  TString msg; msg << TR("Registrazione n.") << ' ' << numreg.as_string();
 | 
						||
  log(0, msg);
 | 
						||
 | 
						||
	TString query;
 | 
						||
	
 | 
						||
	query << "USE " << LF_RINTRA << "\n" 
 | 
						||
				<< "JOIN " << LF_INTRA << "INTO " << INTRA_NUMREG << "==" << RINTRA_NUMREG << "\n"
 | 
						||
				<< "FROM " << INTRA_NUMREG << "==" << numreg << "\n" 
 | 
						||
				<< "TO " << INTRA_NUMREG << "==" << numreg << "\n";
 | 
						||
	
 | 
						||
	TISAM_recordset intra(query);
 | 
						||
 | 
						||
	for (bool ok = intra.move_first(); ok; ok = intra.move_next())
 | 
						||
	{
 | 
						||
		ipintra.new_rec();
 | 
						||
		const bool cess = intra.get(INTRA_TIPOCF).as_string() == "C";
 | 
						||
 | 
						||
		ipintra.set("ID_Subconto", intra.get(LF_INTRA, INTRA_CODCF));
 | 
						||
		ipintra.set("ID_Movim_CG", numreg);
 | 
						||
		ipintra.set("Data_Riferimento", intra.get(LF_INTRA, INTRA_DATAREG));
 | 
						||
		ipintra.set("TipoMovimento", cess ? "C" : "A"); // verificare
 | 
						||
		ipintra.set("Importo", intra.get(RINTRA_AMMLIRE));
 | 
						||
		ipintra.set("Importo_Divisa", intra.get(RINTRA_AMMVALUTA));
 | 
						||
		ipintra.set("ID_NaturaTransazione", intra.get(RINTRA_NATURA));
 | 
						||
		ipintra.set("ID_NomenclaturaCombinata", intra.get(RINTRA_NOMENCL));
 | 
						||
		ipintra.set("ID_CondizioniConsegna", scod2ricl(ICC, intra.get(RINTRA_CONSEGNA)));
 | 
						||
		ipintra.set("ID_ModalitaTrasporto", intra.get(RINTRA_TRASPORTO));
 | 
						||
		ipintra.set("ID_ProvinciaDest", intra.get(RINTRA_PROV));
 | 
						||
		ipintra.set("ID_NazioneProvenienza", intra.get(RINTRA_PAESE));
 | 
						||
		ipintra.set("ID_NazioneOrigine", intra.get(RINTRA_PAESEORIG));
 | 
						||
		ipintra.set("MassaNetta", intra.get(RINTRA_MASSAKG));
 | 
						||
		ipintra.set("UnitaSupplementari", intra.get(RINTRA_MASSAUMS));
 | 
						||
		ipintra.set("ValoreStatistico", intra.get(RINTRA_VALSTAT));
 | 
						||
	}
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::transfer_intra(const char * path)
 | 
						||
{
 | 
						||
  log(0, "Intra");
 | 
						||
 | 
						||
	TIP_intra_textset ipintra;
 | 
						||
	TString query;
 | 
						||
	
 | 
						||
	query << "USE " << LF_MOV << " KEY 2 SELECT (" << MOV_INVIATO << "!=\"X\")&&(" << MOV_REG << "!=\"\")\n" 
 | 
						||
		    << "FROM " << MOV_DATAREG << "=" << _mask->get_date(F_DATA_DA) << "\n"
 | 
						||
				<< "TO " << MOV_DATAREG << "=" << _mask->get_date(F_DATA_AL) << "\n";      
 | 
						||
 | 
						||
	TISAM_recordset  mov(query);
 | 
						||
	_errors_logged = false;
 | 
						||
  TProgind pi(mov.items(), TR("Scansione scadenze"), true, true);
 | 
						||
 | 
						||
  for (bool ok = mov.move_first(); ok && pi.addstatus(1); ok = mov.move_next())
 | 
						||
		add_intra(mov, ipintra);					
 | 
						||
 | 
						||
  bool save = true;
 | 
						||
	_errors |= _errors_logged;
 | 
						||
  if (_errors_logged)
 | 
						||
    save = yesno_box(TR("Sono stati riscontrati uno o piu' errori:\n"
 | 
						||
                        "Si desidera salvare il file ugualmente?"));
 | 
						||
  if (save)
 | 
						||
  {
 | 
						||
		TFilename name(path);
 | 
						||
 | 
						||
		name.add("intra.txt");
 | 
						||
		ipintra.save_as(name);
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::set_parameters()
 | 
						||
{
 | 
						||
	TConfig configtc(CONFIG_DITTA, "tc");
 | 
						||
	TAssoc_array& tab = configtc.list_variables();
 | 
						||
		
 | 
						||
	FOR_EACH_ASSOC_STRING(tab, h, k, v)
 | 
						||
	{
 | 
						||
		TString16 var(k);
 | 
						||
 | 
						||
		if (var.starts_with("IPR"))
 | 
						||
		{
 | 
						||
			const bool ric = (*v > ' ') && strchr("1SXY", *v) != NULL;
 | 
						||
 | 
						||
			if (ric)
 | 
						||
			{
 | 
						||
				var.format("IP%s", (const char *)var.mid(3));
 | 
						||
				_riclassifica.add(var, NULL);
 | 
						||
			}
 | 
						||
		}
 | 
						||
	}
 | 
						||
	_ultscadid = configtc.get_long("IPULTSCADID");
 | 
						||
}
 | 
						||
 | 
						||
TMask & TIP_sender::get_mask()
 | 
						||
{
 | 
						||
	if (_mask == NULL)
 | 
						||
	{
 | 
						||
		_mask = new TIP_mask("tc2700a");
 | 
						||
		TDate to(TODAY);
 | 
						||
		TConfig configtc(CONFIG_DITTA, "tc");
 | 
						||
		const TDate from(configtc.get("IPULTINV"));
 | 
						||
 | 
						||
		if (from.ok())
 | 
						||
			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 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 (codcaus.full())
 | 
						||
		_caus_regolarizzazione->add(codcaus, codcaus);
 | 
						||
	
 | 
						||
	return true;
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::postprocess_movs(TRecordset & mov)
 | 
						||
{
 | 
						||
	if (yesno_box(TR("Confermare il traferimento")))
 | 
						||
	{
 | 
						||
		TConfig configtc(CONFIG_DITTA);
 | 
						||
		TMask & m = get_mask();
 | 
						||
 | 
						||
		configtc.set("IPULTINV", m.get_date(F_DATA_AL));
 | 
						||
		configtc.set("IPULTSCADID", _ultscadid);
 | 
						||
 | 
						||
		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 TIP_sender::create()
 | 
						||
{
 | 
						||
	TRelation rel(LF_CAUSALI);
 | 
						||
	TCursor c(&rel);
 | 
						||
  bool ok = c.scan(search_reg, &_caus_regolarizzazione, "Ricerca causali di regolarizzazione");
 | 
						||
	
 | 
						||
	_tabelle = new TIPRiclassifica_cache;
 | 
						||
	_part = new TRecord_cache(LF_PARTITE, 2);
 | 
						||
	_causali = new TCausali_cache;
 | 
						||
	set_parameters();
 | 
						||
	return TSkeleton_application::create();
 | 
						||
}
 | 
						||
 | 
						||
bool TIP_sender::destroy()
 | 
						||
{
 | 
						||
	delete _tabelle;
 | 
						||
	delete _part;
 | 
						||
	delete _causali;
 | 
						||
	delete _mask;
 | 
						||
	return TSkeleton_application::destroy();
 | 
						||
}
 | 
						||
 | 
						||
void TIP_sender::main_loop()
 | 
						||
{
 | 
						||
	TMask & m = get_mask();
 | 
						||
  while (m.run() != K_QUIT)
 | 
						||
  {
 | 
						||
		TFilename path = m.get(F_PATH);
 | 
						||
	
 | 
						||
		_book = new TReport_book;
 | 
						||
		const char* const title = TR("Invio a IPSOA");
 | 
						||
		_log = new TLog_report(title);
 | 
						||
		_errors = false;
 | 
						||
		if (m.get_bool(F_CLIENTI))
 | 
						||
			transfer_cli(path);
 | 
						||
		if (m.get_bool(F_FORNITORI))
 | 
						||
			transfer_forn(path);
 | 
						||
		if (m.get_bool(F_MOVIMENTI))
 | 
						||
			transfer_mov(path);
 | 
						||
		if (m.get_bool(F_SCADENZE))
 | 
						||
			transfer_scad(path);
 | 
						||
		if (m.get_bool(F_CESPITI))
 | 
						||
			transfer_cesp(path);
 | 
						||
		if (m.get_bool(F_CATEGORIE))
 | 
						||
			transfer_cat(path);
 | 
						||
		if (m.get_bool(F_INTRASTAT))
 | 
						||
			transfer_intra(path);
 | 
						||
 | 
						||
	  _book->add(*_log);
 | 
						||
		_book->preview();
 | 
						||
		if (!_errors)
 | 
						||
		{
 | 
						||
			TString query;
 | 
						||
 | 
						||
			query << "USE " << LF_MOV << " KEY 2 SELECT " << MOV_INVIATO << "!=\"X\"\n" << "FROM " << MOV_DATAREG << "=#DATA_DA\n" << "TO " << MOV_DATAREG << "=#DATA_AL";      
 | 
						||
 | 
						||
			TISAM_recordset mov(query);
 | 
						||
			postprocess_movs(mov);
 | 
						||
		}
 | 
						||
		delete _book;
 | 
						||
		delete _log;
 | 
						||
  }
 | 
						||
}
 | 
						||
int tc2700(int argc, char* argv[])
 | 
						||
{
 | 
						||
  TIP_sender app;
 | 
						||
  app.run(argc, argv, TR("Invio a IPSOA"));
 | 
						||
  return 0;
 | 
						||
}
 |