git-svn-id: svn://10.65.10.50/branches/R_10_00@22657 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			1267 lines
		
	
	
		
			36 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			1267 lines
		
	
	
		
			36 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#include <diction.h>
 | 
						||
#include <lffiles.h>
 | 
						||
#include <progind.h>
 | 
						||
#include <recarray.h>
 | 
						||
#include <relation.h>
 | 
						||
#include <validate.h>
 | 
						||
 | 
						||
#include "fe0100a.h"
 | 
						||
#include "felib.h"
 | 
						||
 | 
						||
#include "../cg/cg2103.h"
 | 
						||
 | 
						||
#include <alleg.h>
 | 
						||
#include <anafis.h>
 | 
						||
#include <anagr.h>
 | 
						||
#include <clifo.h>
 | 
						||
#include <comuni.h>
 | 
						||
#include <doc.h>
 | 
						||
#include <mov.h>
 | 
						||
#include <nditte.h>
 | 
						||
#include <occas.h>
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// Utility
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
real fe_importo_limite(int anno) 
 | 
						||
{ return anno > 2010 ? 3000.0 : 25000.0; }
 | 
						||
 | 
						||
bool fe_is_nota_variazione(const TRectype& mov)
 | 
						||
{
 | 
						||
  const int logicnum = mov.num();
 | 
						||
 | 
						||
  if (logicnum == LF_MOV)
 | 
						||
  {
 | 
						||
    const real totdoc = mov.get_real(MOV_TOTDOC);
 | 
						||
    if (totdoc < ZERO)
 | 
						||
      return true;
 | 
						||
 | 
						||
    const int tipomov = mov.get_int(MOV_TIPOMOV);
 | 
						||
    if (tipomov == 2) // Nota di credito/debito per saldaconto
 | 
						||
       return true;
 | 
						||
 | 
						||
    if (tipomov <= 1)
 | 
						||
    {
 | 
						||
      const TString& tipodoc = mov.get(MOV_TIPODOC);
 | 
						||
      if (tipodoc == "NC" || tipodoc == "ND") // Nota di credito/debito senza saldaconto
 | 
						||
        return true;
 | 
						||
    }
 | 
						||
  } else
 | 
						||
  if (logicnum == LF_ALLEG)
 | 
						||
  {
 | 
						||
    if (mov.get_int(ALL_MODPAG) > 1)
 | 
						||
      return false;
 | 
						||
 | 
						||
    if (mov.get(ALL_NUMRETT).full() || mov.get(ALL_DATARETT).full())
 | 
						||
      return true;
 | 
						||
 | 
						||
    const real importo = mov.get_real(ALL_IMPORTO);
 | 
						||
    const real imposta = mov.get_real(ALL_IMPOSTA);
 | 
						||
    if (importo < ZERO || (importo.is_zero() && imposta < ZERO))
 | 
						||
      return true;
 | 
						||
 | 
						||
    const long numreg = mov.get_long(ALL_PROGR);
 | 
						||
    if (numreg < 900000L)
 | 
						||
    {
 | 
						||
      const TRectype& pn = cache().get(LF_MOV, numreg);
 | 
						||
      if (!pn.empty())
 | 
						||
        return fe_is_nota_variazione(pn);
 | 
						||
    }
 | 
						||
  } else
 | 
						||
  if (logicnum == LF_DOC)
 | 
						||
  {
 | 
						||
    const TString& tipodoc = mov.get(DOC_TIPODOC);
 | 
						||
    const TRectype& td = cache().get("%TIP", tipodoc);
 | 
						||
 | 
						||
    bool yes = td.get_bool("B7");
 | 
						||
    if (!yes)
 | 
						||
    {
 | 
						||
      const TString4 codcaus(td.get("S6"));
 | 
						||
      if (codcaus.full())
 | 
						||
      {
 | 
						||
        const TCausale c(codcaus, mov.get_int(DOC_ANNO));
 | 
						||
        const char sez = c.sezione_clifo();
 | 
						||
        //controllo ulteriore sull'iva
 | 
						||
        TipoIVA tiva = c.reg().iva();
 | 
						||
        const char tcf = mov.get_char(DOC_TIPOCF);
 | 
						||
        if (tiva == nessuna_iva && tcf > ' ')
 | 
						||
          tiva = tcf == 'C' ? iva_vendite : iva_acquisti;
 | 
						||
        if (tiva != nessuna_iva)
 | 
						||
          yes = ((tiva == iva_vendite) ^ (sez == 'D'));
 | 
						||
      }
 | 
						||
    }
 | 
						||
    return yes;
 | 
						||
  }
 | 
						||
 | 
						||
  return false;
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TAnagrafica
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
static const TString& comune_di(const TString& codcom)
 | 
						||
{
 | 
						||
  if (codcom.blank() || codcom.len() != 4)
 | 
						||
    return EMPTY_STRING;
 | 
						||
 | 
						||
  TString8 key; key << " |" << codcom;
 | 
						||
  TString& den = get_tmp_string();
 | 
						||
  den = cache().get(LF_COMUNI, key, COM_DENCOM);
 | 
						||
  den.cut(40);
 | 
						||
  den.trim();
 | 
						||
  return den;
 | 
						||
}
 | 
						||
 | 
						||
static const TString& provincia_di(const TString& codcom)
 | 
						||
{
 | 
						||
  if (codcom.blank() || codcom.len() != 4)
 | 
						||
    return EMPTY_STRING;
 | 
						||
  TString8 key; key << '|' << codcom;
 | 
						||
  TString& prov = get_tmp_string();
 | 
						||
  prov = cache().get(LF_COMUNI, key, COM_PROVCOM);
 | 
						||
  if (prov.len() > 2) prov = "RM";
 | 
						||
  return prov;
 | 
						||
}
 | 
						||
 | 
						||
const TString& TAnagrafica::comune_nascita() const 
 | 
						||
{ return comune_di(_com_nasc); }
 | 
						||
 | 
						||
const TString& TAnagrafica::provincia_nascita() const 
 | 
						||
{ return provincia_di(_com_nasc); }
 | 
						||
 | 
						||
const TString& TAnagrafica::comune_residenza() const 
 | 
						||
{ return comune_di(_com_res); }
 | 
						||
 | 
						||
const TString& TAnagrafica::provincia_residenza() const 
 | 
						||
{ return provincia_di(_com_res); }
 | 
						||
 | 
						||
void TAnagrafica::build_ind_res(const TRectype& rec, const char* ind, const char* civ)
 | 
						||
{
 | 
						||
  TString80 indirizzo = rec.get(ind);
 | 
						||
  if (indirizzo.full())
 | 
						||
  {
 | 
						||
    const TString& numero = rec.get(civ);
 | 
						||
    if (numero.full())
 | 
						||
      indirizzo << ", " << numero;
 | 
						||
    indirizzo.strip_double_spaces();
 | 
						||
    TParagraph_string s(indirizzo, 40);
 | 
						||
    _ind_res = s.get(0);
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
bool TAnagrafica::italiano() const
 | 
						||
{ return _stato_estero <= 0; }
 | 
						||
 | 
						||
const TString& TAnagrafica::stato_estero_UNICO() const 
 | 
						||
{
 | 
						||
  if (italiano())
 | 
						||
    return EMPTY_STRING;
 | 
						||
  TString4 u;
 | 
						||
  u.format("%03d", _stato_estero);
 | 
						||
  const TString& cod = cache().get("%STA", u, "S8"); // S8=UNICO S9=ISTAT
 | 
						||
  if (cod.len() == 3)
 | 
						||
    return cod;
 | 
						||
  return get_tmp_string() = u;
 | 
						||
}
 | 
						||
 | 
						||
void TAnagrafica::split_ragsoc()
 | 
						||
{
 | 
						||
  if (_tipo == 'F')
 | 
						||
  {
 | 
						||
    if (nome().blank())
 | 
						||
    {
 | 
						||
      const int space = _ragsoc.find(' ');
 | 
						||
      if (space > 0)
 | 
						||
      {
 | 
						||
        TString80 nom = _ragsoc.mid(space+1);
 | 
						||
        nom.cut(20);
 | 
						||
        _ragsoc.cut(space);
 | 
						||
        _ragsoc.insert(nom, 30);
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
  else
 | 
						||
    _ragsoc.strip_double_spaces();
 | 
						||
}
 | 
						||
 | 
						||
bool TAnagrafica::init(const TRectype& rec)
 | 
						||
{
 | 
						||
  _tipo = '\0';
 | 
						||
  _stato_estero = 0;
 | 
						||
  _allegato = 0;
 | 
						||
  if (rec.empty())
 | 
						||
    return false;
 | 
						||
 | 
						||
  switch (rec.num())
 | 
						||
  {
 | 
						||
  case LF_OCCAS:
 | 
						||
    _cofi = rec.get(OCC_COFI);
 | 
						||
    _paiv = rec.get(OCC_PAIV);
 | 
						||
    if (_cofi.blank() || _paiv.blank())
 | 
						||
    {
 | 
						||
      const TString& codice = rec.get(OCC_CFPI);
 | 
						||
      if (_cofi.blank() && cf_check("", codice))
 | 
						||
        _cofi = codice;
 | 
						||
      if (_paiv.blank() && pi_check("", codice))
 | 
						||
        _paiv = codice;
 | 
						||
    }
 | 
						||
    _ragsoc = rec.get(OCC_RAGSOC);
 | 
						||
    _data_nasc = rec.get(OCC_DNASC);
 | 
						||
    _com_nasc = rec.get(OCC_COMNASC);
 | 
						||
    _com_res = rec.get(OCC_COM);
 | 
						||
    _loc_res = rec.get(OCC_LOCALITA);
 | 
						||
    build_ind_res(rec, OCC_INDIR, OCC_CIV); 
 | 
						||
    _stato_estero = rec.get_int(OCC_STATO);
 | 
						||
    if (_com_nasc.full() || (!_stato_estero && !real::is_natural(_cofi) || cf_check("", _cofi)))
 | 
						||
      _tipo = 'F';
 | 
						||
    else
 | 
						||
      _tipo = 'G';
 | 
						||
    _allegato = _tipo == 'F' ? 6 : 2;
 | 
						||
    break;
 | 
						||
  case LF_ANAG:
 | 
						||
    _tipo = rec.get_char(ANA_TIPOA);
 | 
						||
    _ragsoc = rec.get(ANA_RAGSOC);
 | 
						||
    _cofi = rec.get(ANA_COFI);
 | 
						||
    _paiv = rec.get(ANA_PAIV);   
 | 
						||
    
 | 
						||
    // Comune di residenza fiscale o domicilio
 | 
						||
    _com_res = rec.get(ANA_COMRF);
 | 
						||
    if (_com_res.empty())
 | 
						||
      _com_res = rec.get(ANA_COMRES);
 | 
						||
    build_ind_res(rec, ANA_INDRES, ANA_CIVRES); 
 | 
						||
    _stato_estero = rec.get_int(ANA_STATORES);
 | 
						||
    
 | 
						||
    // Dati di nascita persone fisiche
 | 
						||
    if (_tipo == 'F')
 | 
						||
    {
 | 
						||
      const TRectype& anafis = cache().get(LF_ANAGFIS, rec.get_long(ANA_CODANAGR));
 | 
						||
      _data_nasc = anafis.get(ANF_DATANASC);
 | 
						||
      _com_nasc = anafis.get(ANF_COMNASC);
 | 
						||
    }
 | 
						||
    else
 | 
						||
      _tipo = 'G';
 | 
						||
    break;
 | 
						||
  case LF_NDITTE:
 | 
						||
    {
 | 
						||
      const char tipoa = rec.get_char(NDT_TIPOA);
 | 
						||
      const bool good = init(LF_ANAG, tipoa, rec.get_long(NDT_CODANAGR));
 | 
						||
      if (tipoa == 'G')
 | 
						||
        _ragsoc = rec.get(NDT_RAGSOC);
 | 
						||
      return good;
 | 
						||
    }
 | 
						||
    break;
 | 
						||
  case LF_CLIFO:
 | 
						||
    _allegato = rec.get_int(CLI_ALLEG);
 | 
						||
    if (_allegato == 4)
 | 
						||
    {
 | 
						||
      const long ca = rec.get_long(CLI_CODALLEG);
 | 
						||
      if (ca > 0)
 | 
						||
        return init(rec.get_char(CLI_TIPOCF), ca, EMPTY_STRING);
 | 
						||
    }
 | 
						||
 
 | 
						||
    _tipo = ' '; // Non faccio assunzioni sulla persona fisica
 | 
						||
 | 
						||
    // Persona Fisica?
 | 
						||
    if (rec.get_char(CLI_TIPOAPER) == 'F' || rec.get(CLI_DATANASC).not_empty()) 
 | 
						||
    {
 | 
						||
      const long cod = rec.get_long(CLI_CODANAGPER);
 | 
						||
      if (cod > 0)
 | 
						||
        init(LF_ANAG, 'F', cod);
 | 
						||
      if (rec.get(CLI_DATANASC).not_empty())
 | 
						||
      {
 | 
						||
        _data_nasc = rec.get(CLI_DATANASC);
 | 
						||
        _tipo = 'F';
 | 
						||
      }
 | 
						||
      if (rec.get(CLI_COMNASC).not_empty())
 | 
						||
        _com_nasc = rec.get(CLI_COMNASC);
 | 
						||
      if (_com_nasc.empty() && rec.get(CLI_STATONASC).not_empty())
 | 
						||
      {
 | 
						||
        const TString80 stato = cache().get("%STA", rec.get(CLI_STATONASC), "S0");
 | 
						||
        TISAM_recordset comuni("USE COMUNI\nFROM CODCOM=Z");
 | 
						||
        double best = 0.75;
 | 
						||
        for (bool ok = comuni.move_first(); ok; ok = comuni.move_next())
 | 
						||
        {
 | 
						||
          const TString& desc = comuni.get(COM_DENCOM).as_string();
 | 
						||
          const double score = xvt_str_fuzzy_compare_ignoring_case(desc, stato);
 | 
						||
          if (score > best)
 | 
						||
          {
 | 
						||
            best = score;
 | 
						||
            _com_nasc = comuni.get(COM_COM).as_string();
 | 
						||
          }
 | 
						||
        }
 | 
						||
      }
 | 
						||
    }
 | 
						||
 | 
						||
    // Assegno codice fiscale e partita IVA se validi, altrimenti mantengo quelli dell'anagrafica
 | 
						||
    if (rec.get(CLI_COFI).not_empty())
 | 
						||
      _cofi = rec.get(CLI_COFI);
 | 
						||
    if (rec.get(CLI_PAIV).not_empty())
 | 
						||
      _paiv = rec.get(CLI_PAIV);
 | 
						||
 | 
						||
    // Ci sono anagrafiche con codice fiscale numerico e partita IVA vuota!
 | 
						||
    // I codici fiscali che cominciano per 8 e 9 sono le associazioni riconosciute e non, rispettivamente.
 | 
						||
    if (_paiv.blank() && pi_check("", _cofi) && _cofi[0] < '8')
 | 
						||
      _paiv = _cofi; 
 | 
						||
 | 
						||
    build_ind_res(rec, CLI_INDCF, CLI_CIVCF); 
 | 
						||
 | 
						||
    // Prevale sempre la ragione sociale del cliente: "Il cliente ha sempre ragione".
 | 
						||
    _ragsoc = rec.get(CLI_RAGSOC);
 | 
						||
    _stato_estero = rec.get_int(CLI_STATOCF);
 | 
						||
    _loc_res = rec.get(CLI_LOCCF);
 | 
						||
 | 
						||
    if (_tipo != 'F' && _tipo != 'G')
 | 
						||
    {
 | 
						||
      switch (_allegato)
 | 
						||
      {
 | 
						||
      case  6: _tipo = 'F'; break;
 | 
						||
      case  7: _tipo = 'G'; break;
 | 
						||
      default: 
 | 
						||
        if (_com_nasc.full())
 | 
						||
          _tipo = 'F';
 | 
						||
        else
 | 
						||
        {
 | 
						||
          _tipo = rec.get_char(CLI_TIPOPERS);
 | 
						||
          if (_tipo != 'F')
 | 
						||
            _tipo = 'G';
 | 
						||
        }
 | 
						||
        break;
 | 
						||
      }
 | 
						||
    }
 | 
						||
    break;
 | 
						||
  case LF_MOV:
 | 
						||
    return init(rec.get_char(MOV_TIPO), rec.get_long(MOV_CODCF), rec.get(MOV_OCFPI));
 | 
						||
  case LF_ALLEG:
 | 
						||
    return init(rec.get_char(ALL_TIPOCF), rec.get_long(ALL_CODCF), rec.get(ALL_OCFPI));
 | 
						||
  default:
 | 
						||
    CHECKD(false, "Record non valido per TAnagrafica ", rec.num());
 | 
						||
    break;
 | 
						||
  }
 | 
						||
  split_ragsoc();
 | 
						||
  
 | 
						||
  return _tipo == 'F' || _tipo == 'G';
 | 
						||
}
 | 
						||
 | 
						||
bool TAnagrafica::init(int num, const TString& codice) 
 | 
						||
{ return init(cache().get(num, codice)); }
 | 
						||
 | 
						||
bool TAnagrafica::init(int num, long codice) 
 | 
						||
{ return init(cache().get(num, codice)); }
 | 
						||
 | 
						||
bool TAnagrafica::init(int num, char tipo, long codice)
 | 
						||
{
 | 
						||
  TString16 key; key << tipo << '|' << codice;
 | 
						||
  return init(cache().get(num, key));
 | 
						||
}
 | 
						||
 | 
						||
bool TAnagrafica::init(char tipocf, long codice, const TString& ocfpi)
 | 
						||
{
 | 
						||
  bool done = false;
 | 
						||
  if (ocfpi.full())
 | 
						||
    done = init(LF_OCCAS, ocfpi);
 | 
						||
  if (!done)
 | 
						||
  {
 | 
						||
    CHECK(tipocf == 'C' || tipocf == 'F', "Tipo cli/for non valido");
 | 
						||
    CHECKD(codice > 0, "Codice cli/for non valido", codice);
 | 
						||
    done = init(LF_CLIFO, tipocf, codice);
 | 
						||
  }
 | 
						||
  return done;
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TContratto
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
bool TContratto::importo_annuale(int anno, real& importo, real& imposta) const
 | 
						||
{
 | 
						||
  if (_rec.empty() || anno < 2010)
 | 
						||
    return false;
 | 
						||
 | 
						||
  // Determina l'indice i [0..3] degli importi del contratto per l'anno richiesto
 | 
						||
  char fld[] = "I3";
 | 
						||
  int i = 3;
 | 
						||
  for (i = 3; i > 0; i--)
 | 
						||
  {
 | 
						||
    fld[1] = '0'+i;
 | 
						||
    const int y = _rec.get_int(fld);
 | 
						||
    if (y > 0 && y <= anno)
 | 
						||
      break;
 | 
						||
  }
 | 
						||
 | 
						||
  // Determina il nome del campo importo corrispondente all'indice i: 0 -> R0; 1 -> R2; 2 -> R4; 3 -> R6
 | 
						||
  fld[0] = 'R';
 | 
						||
  fld[1] = '0'+(i*2);
 | 
						||
  importo = _rec.get_real(fld);
 | 
						||
    
 | 
						||
  fld[1]++; // Il campo imposta <20> sempre quello successivo a quello dell'importo
 | 
						||
  imposta = _rec.get_real(fld);
 | 
						||
 | 
						||
  return importo > ZERO;
 | 
						||
}
 | 
						||
 | 
						||
bool TContratto::importo_figli(int anno, real& importo, real& imposta) const
 | 
						||
{
 | 
						||
  const TString& codtab = _rec.get("CODTAB");
 | 
						||
  const TString& prefix = codtab.left(7);
 | 
						||
  const TString& suffix = codtab.mid(7);
 | 
						||
  
 | 
						||
  TString query; 
 | 
						||
  query << "USE &CON SELECT S1=\"" << suffix << '\"'
 | 
						||
        << "\nFROM CODTAB=\"" << prefix << '\"'
 | 
						||
        << "\nTO   CODTAB=\"" << prefix << '\"';
 | 
						||
 | 
						||
  TISAM_recordset recset(query);
 | 
						||
 | 
						||
  importo = imposta = ZERO;
 | 
						||
  for (bool ok = recset.move_first(); ok; ok = recset.move_next())
 | 
						||
  {
 | 
						||
    const TContratto child(recset.cursor()->curr());
 | 
						||
    real imp, iva; child.importo_figli(anno, imp, iva);
 | 
						||
    importo += imp;
 | 
						||
    imposta += iva;
 | 
						||
  }
 | 
						||
  if (importo <= ZERO)
 | 
						||
    importo_annuale(anno, importo, imposta);
 | 
						||
  
 | 
						||
  return !importo.is_zero();
 | 
						||
}
 | 
						||
 | 
						||
bool TContratto::totale_annuale(int anno, real& importo, real& imposta) const
 | 
						||
{
 | 
						||
  importo = imposta = ZERO;
 | 
						||
  if (!_rec.empty() && anno >= 2010)
 | 
						||
  {
 | 
						||
    const TString& padre = _rec.get("S1");
 | 
						||
    if (padre.full())
 | 
						||
    {
 | 
						||
      const TString& codtab = _rec.get("CODTAB");
 | 
						||
      const TContratto master(codtab[0], atol(codtab.mid(1,6)), padre);
 | 
						||
      master.totale_annuale(anno, importo, imposta);
 | 
						||
    }
 | 
						||
    else
 | 
						||
      importo_figli(anno, importo, imposta);
 | 
						||
  }
 | 
						||
  return importo > ZERO;
 | 
						||
}
 | 
						||
 | 
						||
int TContratto::modalita_pagamento() const
 | 
						||
{
 | 
						||
  int modpag = _rec.get_int("S6");
 | 
						||
  if (modpag != 2 && modpag != 3)
 | 
						||
    modpag = 2;
 | 
						||
  return modpag; 
 | 
						||
}
 | 
						||
 | 
						||
const TString& TContratto::codice_base() const
 | 
						||
{
 | 
						||
  TString80 c = codice(), p = codice_padre();
 | 
						||
  if (p.full())
 | 
						||
  {
 | 
						||
    TAssoc_array antiloop;
 | 
						||
    antiloop.add(c);
 | 
						||
    while (p.full() && !antiloop.is_key(p))    // Verifico loop assurdo
 | 
						||
    {
 | 
						||
      c = p;
 | 
						||
      antiloop.add(c);
 | 
						||
      TString80 key = chiave().left(7);
 | 
						||
      key << p;
 | 
						||
      p = cache().get("&CON", key, "S1");
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return get_tmp_string() = c;
 | 
						||
}
 | 
						||
 | 
						||
bool TContratto::init(const TString& codtab)
 | 
						||
{ return init(cache().get("&CON", codtab)); }
 | 
						||
 | 
						||
bool TContratto::init(char tipocf, long codcf, const TString& codcont)
 | 
						||
{
 | 
						||
  if (tipocf >= 'C' && codcf > 0 && codcont.full())
 | 
						||
  {
 | 
						||
    TString80 key; key.format("%c%6ld%s", tipocf, codcf, (const char*)codcont);
 | 
						||
    return init(key);
 | 
						||
  }
 | 
						||
  else
 | 
						||
    _rec.zero();
 | 
						||
  return false;
 | 
						||
}
 | 
						||
 | 
						||
bool TContratto::init(const TRectype& rec)
 | 
						||
{
 | 
						||
  switch (rec.num())
 | 
						||
  {
 | 
						||
  case LF_TABMOD:
 | 
						||
    _rec = rec;
 | 
						||
    if (!_rec.empty())
 | 
						||
    {
 | 
						||
      int primo_anno = _rec.get_int("I0");
 | 
						||
      if (primo_anno < 2010)
 | 
						||
      {
 | 
						||
        const TDate inizio = _rec.get("D0");
 | 
						||
        primo_anno = inizio.year();
 | 
						||
        if (primo_anno < 2010)
 | 
						||
          primo_anno = 2010;
 | 
						||
        _rec.put("I0", primo_anno);
 | 
						||
      }
 | 
						||
 | 
						||
      real importo = _rec.get("R0");
 | 
						||
      if (importo <= ZERO)
 | 
						||
      {
 | 
						||
        importo = fe_importo_limite(primo_anno);
 | 
						||
        _rec.put("R0", importo);
 | 
						||
      }
 | 
						||
    } 
 | 
						||
    break;
 | 
						||
  case LF_ALLEG:
 | 
						||
    {
 | 
						||
      const char tipocf = rec.get_char(ALL_TIPOCF);
 | 
						||
      const long codcf = rec.get_long(ALL_CODCF);
 | 
						||
      const TString& contr = rec.get(ALL_CONTRATTO);
 | 
						||
      init(tipocf, codcf, contr);
 | 
						||
    }
 | 
						||
    break;
 | 
						||
  case LF_MOV:
 | 
						||
    {
 | 
						||
      const char tipocf = rec.get_char(MOV_TIPO);
 | 
						||
      const long codcf = rec.get_long(MOV_CODCF);
 | 
						||
      const TString& contr = rec.get(MOV_CONTRATTO);
 | 
						||
      init(tipocf, codcf, contr);
 | 
						||
    }
 | 
						||
    break;
 | 
						||
  case LF_DOC:
 | 
						||
    {
 | 
						||
      const char tipocf = rec.get_char(DOC_TIPOCF);
 | 
						||
      const long codcf = rec.get_long(DOC_CODCF);
 | 
						||
      const TString& contr = rec.get(DOC_CONTRATTO);
 | 
						||
      init(tipocf, codcf, contr);
 | 
						||
    }
 | 
						||
    break;
 | 
						||
  default:
 | 
						||
    CHECKD(false, "Record non valido per contratto FE", rec.num());
 | 
						||
    break;
 | 
						||
  }
 | 
						||
  return ok();
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TDati_rilevanti_trc
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
#define AN _alfafld
 | 
						||
#define CF _alfafld
 | 
						||
#define DT _datefld
 | 
						||
#define NU _longzerofld
 | 
						||
#define PI _alfafld
 | 
						||
#define OBBLIG true
 | 
						||
 | 
						||
class TDati_rilevanti_trc : public TObject
 | 
						||
{
 | 
						||
  int _tipo;
 | 
						||
  TAS400_recordset* _recset;
 | 
						||
 | 
						||
protected:
 | 
						||
  bool add_field(int n, int da, int a, int len, const char* descr, TFieldtypes tipo = AN,
 | 
						||
                 const char* def = NULL, bool required = false);
 | 
						||
public:
 | 
						||
  void create_fields(int tipo, TAS400_recordset& recset);
 | 
						||
};
 | 
						||
 | 
						||
 | 
						||
bool TDati_rilevanti_trc::add_field(int n, int da, int a, int len, const char* descr, TFieldtypes tipo,
 | 
						||
                                    const char* def, bool required)
 | 
						||
{
 | 
						||
  CHECKD(descr && *descr, "Campo ignoto ", n);
 | 
						||
  CHECKS(n > 0 && da > 0 && a >= da && a <= 1800 && len == (a-da+1), "Campo inconsistente ", descr);
 | 
						||
  TString8 name;
 | 
						||
  name.format("%d.%d", _tipo, n);
 | 
						||
  bool ok = _recset->create_field(name, da-1, len, tipo, required, def);
 | 
						||
  CHECKS(ok, "Can't create field ", descr);
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
void TDati_rilevanti_trc::create_fields(int tipo, TAS400_recordset& recset)
 | 
						||
{
 | 
						||
  CHECKD(tipo >= 0 && tipo <= 5 || tipo == 9, "Tipo record non valido ", tipo);
 | 
						||
  _tipo = tipo;
 | 
						||
  _recset = &recset;
 | 
						||
  
 | 
						||
  TString4 def; def << _tipo;
 | 
						||
  add_field(1, 1, 1, 1, "Tipo record", NU, def, OBBLIG);
 | 
						||
 | 
						||
  if (_tipo == 0 || _tipo == 9)
 | 
						||
  {
 | 
						||
    add_field( 2,  2,  6, 5, "Codice identificativo fornitura", AN, "ART21", OBBLIG);
 | 
						||
    add_field( 3,  7,  8, 2, "Codice numerico fornitura",       NU, "47",    OBBLIG);
 | 
						||
    add_field( 4,  9,  9, 1, "Tipologia di invio",              NU, "0",     OBBLIG);
 | 
						||
    add_field( 5, 10, 26,17, "Protocollo da sostituire",        AN); // ex NU
 | 
						||
    add_field( 6, 27, 32, 6, "Protocollo documento",            AN); // ex NU
 | 
						||
    
 | 
						||
    add_field( 7, 33, 48,16, "Codice fiscale",                  CF, "",      OBBLIG);
 | 
						||
    add_field( 8, 49, 59,11, "Partita IVA",                     PI);
 | 
						||
    
 | 
						||
    add_field( 9, 60,119,60, "Denominazione",                   AN);
 | 
						||
    add_field(10,120,159,40, "Comune domicilio fiscale",        AN);
 | 
						||
    add_field(11,160,161, 2, "Provincia domicilio fiscale",     AN);
 | 
						||
    
 | 
						||
    add_field(12,162,185,24, "Cognome",                         AN);
 | 
						||
    add_field(13,186,205,20, "Nome",                            AN);
 | 
						||
    add_field(14,206,206, 1, "Sesso",                           AN);
 | 
						||
    add_field(15,207,214, 8, "Data di nascita",                 DT);
 | 
						||
    add_field(16,215,254,40, "Comune o stato di nascita",       AN);
 | 
						||
    add_field(17,255,256, 2, "Provincia di nascita",            AN);
 | 
						||
    
 | 
						||
    add_field(18,257,260, 4, "Anno di riferimento",             NU);
 | 
						||
    add_field(19,261,261, 1, "Comunicazione societ<65> incorp.",   AN, "0",     OBBLIG);
 | 
						||
    add_field(20,262,265, 4, "Progressivo invio telmatico",     NU, "1");
 | 
						||
    add_field(21,266,269, 4, "Numero totale invii telematici",  NU, "1");
 | 
						||
    
 | 
						||
    add_field(22,270,285,16, "Codice fiscale intermediario",    CF);  
 | 
						||
    add_field(23,286,290, 5, "Numero iscrizione C.A.F.",        AN);  // Ex NU
 | 
						||
    add_field(24,291,291, 1, "Impegno alla trasmissione",       AN ); // Ex NU
 | 
						||
    add_field(25,292,299, 8, "Data dell'impegno",               DT);
 | 
						||
    
 | 
						||
    add_field(26,300,1797,1498, "Filler",                       AN);
 | 
						||
    add_field(27,1798,1798,1,"Carattere di controllo",          AN, "A", OBBLIG);
 | 
						||
    add_field(28,1799,1800,2,"Caratteri di fine riga",          AN, "\r\n");
 | 
						||
  } else
 | 
						||
  if (_tipo == 1)
 | 
						||
  {
 | 
						||
    add_field(2, 2,17,16, "Codice fiscale",           CF, "",  OBBLIG);
 | 
						||
    add_field(3,18,25, 8, "Data dell'operazione",     DT);
 | 
						||
    add_field(4,26,26, 1, "Modalit<EFBFBD> di pagamento",    NU, "3", OBBLIG);
 | 
						||
    add_field(5,27,35, 9, "Importo dovuto",           NU); 
 | 
						||
    add_field(6,36,1797,1762, "Filler",               AN);
 | 
						||
    add_field(7,1798,1798,1,"Carattere di controllo", AN, "A", OBBLIG);
 | 
						||
    add_field(8,1799,1800,2,"Caratteri di fine riga", AN, "\r\n");
 | 
						||
  } else 
 | 
						||
  if (_tipo == 2)
 | 
						||
  {
 | 
						||
    add_field( 2, 2,12,11, "Partita IVA",               PI, "",  OBBLIG);
 | 
						||
    add_field( 3,13,20, 8, "Data dell'operazione",      DT);
 | 
						||
    add_field( 4,21,35,15, "Numero della fattura",      AN);
 | 
						||
    add_field( 5,36,36, 1, "Modalit<EFBFBD> di pagamento",     NU, "1", OBBLIG);
 | 
						||
    add_field( 6,37,45, 9, "Importo dovuto",            NU);
 | 
						||
    add_field( 7,46,54, 9, "Imposta",                   NU);
 | 
						||
    add_field( 8,55,55, 1, "Tipologia dell'operazione", NU, "1", OBBLIG);
 | 
						||
    
 | 
						||
    add_field( 9,56,1797,1742, "Filler",                AN);
 | 
						||
    add_field(10,1798,1798,1,"Carattere di controllo",  AN, "A", OBBLIG);
 | 
						||
    add_field(11,1799,1800,2,"Caratteri di fine riga",  AN, "\r\n");
 | 
						||
  } else
 | 
						||
  if (_tipo == 3)
 | 
						||
  {
 | 
						||
    add_field( 2,  2, 25,24, "Cognome",                            AN);
 | 
						||
    add_field( 3, 26, 45,20, "Nome",                               AN);
 | 
						||
    add_field( 4, 46, 53, 8, "Data di nascita",                    DT);
 | 
						||
    add_field( 5, 54, 93,40, "Comune o stato estero di nascita",   AN);
 | 
						||
    add_field( 6, 94, 95, 2, "Provincia di nascita",               AN);
 | 
						||
    add_field( 7, 96, 98, 3, "Stato estero del domicilio",         AN);
 | 
						||
    
 | 
						||
    add_field( 8, 99,158,60, "Ragione sociale",                    AN);
 | 
						||
    add_field( 9,159,198,40, "Citt<EFBFBD> estera della sede legale",     AN);
 | 
						||
    add_field(10,199,201, 3, "Stato estero della sede legale",     AN);
 | 
						||
    add_field(11,202,241,40, "Indirizzo estero della sede legale", AN);
 | 
						||
    
 | 
						||
    add_field(12,242,249, 8, "Data dell'operazione",        DT);
 | 
						||
    add_field(13,250,264,15, "Numero della fattura",        AN);
 | 
						||
    add_field(14,265,265, 1, "Modalit<EFBFBD> di pagamento",       NU, "1", OBBLIG);
 | 
						||
    add_field(15,266,274, 9, "Importo dovuto",              NU);
 | 
						||
    add_field(16,275,283, 9, "Imposta",                     NU);
 | 
						||
    add_field(17,284,284, 1, "Tipologia dell'operazione",   NU, "1", OBBLIG);
 | 
						||
    
 | 
						||
    add_field(18,285,1797,1513, "Filler",                   AN);
 | 
						||
    add_field(19,1798,1798,1,"Carattere di controllo",      AN, "A", OBBLIG);
 | 
						||
    add_field(20,1799,1800,2,"Caratteri di fine riga",      AN, "\r\n");
 | 
						||
  } else
 | 
						||
  if (_tipo == 4)
 | 
						||
  {
 | 
						||
    add_field( 2, 2,12,11, "Partita IVA",                         PI);
 | 
						||
    add_field( 3,13,28,16, "Codice Fiscale",                      CF);
 | 
						||
    add_field( 4,29,36, 8, "Data dell'operazione",                DT, "",  OBBLIG);
 | 
						||
    add_field( 5,37,51,15, "Numero della Nota di Variazione",     AN, "",  OBBLIG);
 | 
						||
    add_field( 6,52,60, 9, "Imponibile Nota di Variazione",       NU);
 | 
						||
    add_field( 7,61,69, 9, "Imposta Nota di Variazione",          NU);
 | 
						||
    add_field( 8,70,77, 8, "Data della Fattura da rettificare",   DT, "",  OBBLIG);
 | 
						||
    add_field( 9,78,92,15, "Numero della Fattura da rettificare", AN, "",  OBBLIG);
 | 
						||
    add_field(10,93,93, 1, "Variazione imponib. (Debito/Credito)",AN);
 | 
						||
    add_field(11,94,94, 1, "Variazione imposta (Debito/Credito)", AN);
 | 
						||
    
 | 
						||
    add_field(11,95,1797,1703, "Filler",                          AN);
 | 
						||
    add_field(12,1798,1798,1,"Carattere di controllo",            AN, "A", OBBLIG);
 | 
						||
    add_field(13,1799,1800,2,"Caratteri di fine riga",            AN, "\r\n");
 | 
						||
  } else
 | 
						||
  if (_tipo == 5)
 | 
						||
  {
 | 
						||
    add_field( 2,  2, 25,24, "Cognome",                             AN);
 | 
						||
    add_field( 3, 26, 45,20, "Nome",                                AN);
 | 
						||
    add_field( 4, 46, 53, 8, "Data di nascita",                     DT);
 | 
						||
    add_field( 5, 54, 93,40, "Comune o stato estero di nascita",    AN);
 | 
						||
    add_field( 6, 94, 95, 2, "Provincia di nascita",                AN);
 | 
						||
    add_field( 7, 96, 98, 3, "Stato estero del domicilio",          AN);
 | 
						||
    add_field( 8, 99,158,60, "Ragione sociale",                     AN);
 | 
						||
    add_field( 9,159,198,40, "Citt<EFBFBD> estera della sede legale",      AN);
 | 
						||
    add_field(10,199,201, 3, "Stato estero della sede legale",      AN);
 | 
						||
    add_field(11,202,241,40, "Indirizzo estero della sede legale",  AN);
 | 
						||
    add_field(12,242,249, 8, "Data dell'operazione",                DT, "",  OBBLIG);
 | 
						||
    add_field(13,250,264,15, "Numero della Nota di Variazione",     AN, "",  OBBLIG);
 | 
						||
    add_field(14,265,273, 9, "Imponibile Nota di Variazione",       NU);
 | 
						||
    add_field(15,274,282, 9, "Imposta Nota di Variazione",          NU);
 | 
						||
    add_field(16,283,290, 8, "Data della Fattura da rettificare",   DT, "",  OBBLIG);
 | 
						||
    add_field(17,291,305,15, "Numero della Fattura da rettificare", AN, "",  OBBLIG);
 | 
						||
    add_field(18,306,306, 1, "Variazione imponib. (Debito/Credito)",AN);
 | 
						||
    add_field(19,307,307, 1, "Variazione imposta (Debito/Credito)", AN);
 | 
						||
    
 | 
						||
    add_field(20,308,1797,1490, "Filler",                           AN);
 | 
						||
    add_field(21,1798,1798,1,"Carattere di controllo",              AN, "A", OBBLIG);
 | 
						||
    add_field(22,1799,1800,2,"Caratteri di fine riga",              AN, "\r\n");
 | 
						||
  }
 | 
						||
  
 | 
						||
  _recset = NULL;
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TDati_rilevanti_set
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
bool TDati_rilevanti_set::set_field(const TAS400_column_info& fi, const TVariant& var)
 | 
						||
{
 | 
						||
  // Salva le date in formato GGMMAAAA invece dello standard ANSI AAAAMMGG
 | 
						||
  if (fi._type == DT && fi._width == 8) 
 | 
						||
  {
 | 
						||
    const TDate d = var.as_date();
 | 
						||
    if (d.ok())
 | 
						||
    {
 | 
						||
      TFixed_string str = d.string(full, '\0', full, full, gma_date);
 | 
						||
      row().overwrite(str, fi._pos);
 | 
						||
    }
 | 
						||
    else
 | 
						||
      row().overwrite("        ", fi._pos);
 | 
						||
    return true;
 | 
						||
  } else
 | 
						||
  // Salva gli importi in formato 000001234 (non possono essere negativi)
 | 
						||
  if (fi._type == NU && fi._width == 9)
 | 
						||
  {
 | 
						||
    TString16 str = var.as_string(); 
 | 
						||
    CHECKS(str[0] != '-', "Importo negativo non ammesso:", (const char*)str);
 | 
						||
    // Tiene la sola parte intera e riempie di zeri
 | 
						||
    const int dot = str.find('.');
 | 
						||
    if (dot >= 0) str.cut(dot);
 | 
						||
    str.right_just(fi._width, '0');
 | 
						||
    row().overwrite(str, fi._pos);
 | 
						||
    return true;
 | 
						||
  } else
 | 
						||
  if (fi._type == AN)
 | 
						||
  {
 | 
						||
    TString256 str = var.as_string();
 | 
						||
    str.upper();
 | 
						||
    str.replace('<EFBFBD>', 'A');
 | 
						||
    str.replace('<EFBFBD>', 'N');
 | 
						||
    str.replace('<EFBFBD>', 'O');
 | 
						||
    str.replace('<EFBFBD>', 'U');
 | 
						||
    row().overwrite(str, fi._pos, fi._width);
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
 | 
						||
  return TAS400_recordset::set_field(fi, var);
 | 
						||
}
 | 
						||
 | 
						||
const TVariant& TDati_rilevanti_set::get_field(const TAS400_column_info& ci) const
 | 
						||
{
 | 
						||
  if (ci._type == DT && ci._width == 8)
 | 
						||
  {
 | 
						||
    const TRecnotype n = current_row();
 | 
						||
    if (n >= 0 && n < items())
 | 
						||
    {
 | 
						||
      const TString& str = row(n).mid(ci._pos, ci._width);
 | 
						||
      const int gg = atoi(str.left(2));
 | 
						||
      const int mm = atoi(str.mid(2,2));
 | 
						||
      const int aa = atoi(str.mid(4,4));
 | 
						||
      if (aa > 1800 && aa < 2100)
 | 
						||
      {
 | 
						||
        TVariant& var = get_tmp_var();
 | 
						||
        var.set(TDate(gg, mm, aa));
 | 
						||
        return var;
 | 
						||
      }
 | 
						||
    }
 | 
						||
    return NULL_VARIANT;
 | 
						||
  }
 | 
						||
  return TAS400_recordset::get_field(ci);
 | 
						||
}
 | 
						||
 | 
						||
int TDati_rilevanti_set::add_header(const TMask& msk, int num_inv, int tot_inv)
 | 
						||
{
 | 
						||
  const TAnagrafica ditta(LF_NDITTE, prefix().get_codditta());
 | 
						||
 | 
						||
  new_rec("0");
 | 
						||
 | 
						||
  const int tipologia = msk.get_int(F_TIPOLOGIA);
 | 
						||
  set(4, tipologia);
 | 
						||
  if (tipologia > 0)
 | 
						||
  {
 | 
						||
    set(5, msk.get(F_PROTELE));
 | 
						||
    set(6, msk.get(F_PROTDOC));
 | 
						||
  }
 | 
						||
 | 
						||
  set(7, ditta.codice_fiscale());
 | 
						||
  set(8, ditta.partita_IVA());
 | 
						||
 | 
						||
  if (ditta.giuridica())
 | 
						||
  {
 | 
						||
    set( 9, ditta.ragione_sociale());
 | 
						||
    set(10, ditta.comune_residenza());
 | 
						||
    set(11, ditta.provincia_residenza());
 | 
						||
  }
 | 
						||
  else
 | 
						||
  {
 | 
						||
    set(12, ditta.cognome());
 | 
						||
    set(13, ditta.nome());
 | 
						||
    set(14, ditta.sesso());
 | 
						||
    set(15, ditta.data_nascita());
 | 
						||
    set(16, ditta.comune_nascita());
 | 
						||
    set(17, ditta.provincia_nascita());
 | 
						||
  }
 | 
						||
  set(18, _anno);
 | 
						||
 | 
						||
  if (tot_inv < 1) tot_inv = 1;
 | 
						||
  if (num_inv <= 0) num_inv = 1;
 | 
						||
  if (num_inv > tot_inv) num_inv = tot_inv;
 | 
						||
  set(20, num_inv);
 | 
						||
  set(21, tot_inv);
 | 
						||
 | 
						||
  const TString& cofi = msk.get(F_INTER_COFI);
 | 
						||
  if (cofi.full())
 | 
						||
  {
 | 
						||
    set(22, cofi);
 | 
						||
    set(23, msk.get(F_INTER_CAF));
 | 
						||
    set(24, msk.get(F_INTER_COM));
 | 
						||
    set(25, msk.get(F_INTER_DATE));
 | 
						||
  }
 | 
						||
  else
 | 
						||
  {
 | 
						||
    set(25, TDate()); // Svuota data impegno
 | 
						||
  }
 | 
						||
 | 
						||
  return tipologia;
 | 
						||
}
 | 
						||
 | 
						||
void TDati_rilevanti_set::add_footer()
 | 
						||
{
 | 
						||
  TString f = row(0);
 | 
						||
  f.overwrite("9");
 | 
						||
  new_rec(f);
 | 
						||
}
 | 
						||
 | 
						||
bool TDati_rilevanti_set::split(const TFilename& name, const TRecnotype maxalleg)
 | 
						||
{
 | 
						||
  const TRecnotype totrec = items();
 | 
						||
  bool done = totrec <= maxalleg;
 | 
						||
  if (!done)
 | 
						||
  {
 | 
						||
    TString msg; 
 | 
						||
    msg.format(FR("Spezzatura del file %s in blocchi da %d righe"), (const char*)name, maxalleg);
 | 
						||
    TProgind pi(totrec, msg);
 | 
						||
 | 
						||
    TDati_rilevanti_set outset(_anno);
 | 
						||
    int f = 0;
 | 
						||
    for (TRecnotype r = 0; r < totrec; r++)
 | 
						||
    {
 | 
						||
      if (!pi.setstatus(r))
 | 
						||
        break; // Procedura interrotta dall'utente
 | 
						||
      outset.new_rec(row(r));
 | 
						||
      if (outset.items() >= maxalleg || r == totrec-1)
 | 
						||
      {
 | 
						||
        // Costruisce il nome del file di invio parziale, es: Spesometro00001_2.txt
 | 
						||
        TFilename outname = name;
 | 
						||
        const TString8 saved_ext = outname.ext();
 | 
						||
        outname.ext(""); outname << '_' << (++f); 
 | 
						||
        outname.ext(saved_ext);
 | 
						||
        done = outset.save_as(outname);
 | 
						||
        if (done)
 | 
						||
          outset.destroy();
 | 
						||
        else
 | 
						||
        {
 | 
						||
          cantwrite_box(outname);
 | 
						||
          break;
 | 
						||
        }
 | 
						||
      }
 | 
						||
    }
 | 
						||
    if (f > 1)
 | 
						||
      message_box(FR("Sono stati generati %d file nella cartella %s"), f, name.path());
 | 
						||
  }
 | 
						||
  return done;
 | 
						||
}
 | 
						||
 | 
						||
void TDati_rilevanti_set::init()
 | 
						||
{
 | 
						||
  TDati_rilevanti_trc trc;
 | 
						||
  for (int i = 0; i <= 5; i++)
 | 
						||
    trc.create_fields(i, *this);
 | 
						||
  trc.create_fields(9, *this);
 | 
						||
 | 
						||
}
 | 
						||
 | 
						||
TDati_rilevanti_set::TDati_rilevanti_set(const TFilename& file)
 | 
						||
                   : TAS400_recordset("AS400(1800,1)"), _anno(2011)
 | 
						||
{
 | 
						||
  init();
 | 
						||
  if (load_file(file) && move_first())
 | 
						||
  {
 | 
						||
    const int anno = get(17).as_int();
 | 
						||
    if (anno > 2010)
 | 
						||
      _anno = anno;
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
TDati_rilevanti_set::TDati_rilevanti_set(int anno) 
 | 
						||
                   : TAS400_recordset("AS400(1800,1)"), _anno(anno)
 | 
						||
{
 | 
						||
  init();
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TCofi_cache
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
TObject* TCofi_cache::find_ragsoc(bool piva, char tipocf, const TString& code)
 | 
						||
{
 | 
						||
  const int fkey = piva ? 5 : 4;
 | 
						||
  const char* kfield = piva ? CLI_PAIV : CLI_COFI;
 | 
						||
  _clifo.setkey(fkey);
 | 
						||
  _clifo.zero();
 | 
						||
  _clifo.put(CLI_TIPOCF, tipocf);
 | 
						||
  _clifo.put(kfield, code);
 | 
						||
  
 | 
						||
  int err = _clifo.read();
 | 
						||
 | 
						||
  if (err == NOERR && _clifo.get_int(CLI_ALLEG) == 4) // Codice Fiscale o Partita IVA doppia
 | 
						||
  {
 | 
						||
    const long codall = _clifo.get_long(CLI_CODALLEG);
 | 
						||
    if (codall > 0)
 | 
						||
    {
 | 
						||
      const TRecnotype recno = _clifo.recno();
 | 
						||
      _clifo.setkey(1);
 | 
						||
      _clifo.put(CLI_TIPOCF, tipocf);
 | 
						||
      _clifo.put(CLI_CODCF, codall);
 | 
						||
      err = _clifo.read();
 | 
						||
      if (err != NOERR || _clifo.get(kfield) != code)
 | 
						||
        err = _clifo.readat(recno);
 | 
						||
      _clifo.setkey(fkey);
 | 
						||
    }
 | 
						||
  }
 | 
						||
 | 
						||
  if (err != NOERR && piva && pi_check("IT", code))
 | 
						||
  {
 | 
						||
    _clifo.put(CLI_TIPOCF, tipocf);
 | 
						||
    _clifo.put(CLI_STATOPAIV, "IT");
 | 
						||
    _clifo.put(CLI_PAIV, code);
 | 
						||
    err = _clifo.read();
 | 
						||
  }
 | 
						||
 | 
						||
  if (err == NOERR)
 | 
						||
    return new TString80(_clifo.get(CLI_RAGSOC));
 | 
						||
 | 
						||
  if (piva && !pi_check("IT", code)) // cerco partite IVA estere
 | 
						||
  {
 | 
						||
    TString query;
 | 
						||
    query << "USE CLIFO SELECT PAIV=\"" << code << '"'
 | 
						||
          << "\nFROM TIPOCF=" << tipocf
 | 
						||
          << "\nTO TIPOCF=" << tipocf;
 | 
						||
    TISAM_recordset clifo(query);
 | 
						||
    if (clifo.move_first())
 | 
						||
      return new TString80(clifo.get(CLI_RAGSOC).as_string());
 | 
						||
  }
 | 
						||
 | 
						||
  _occas.put(OCC_CFPI, code);
 | 
						||
  if (_occas.read() == NOERR)
 | 
						||
  {
 | 
						||
    const TString& cfpi = _occas.get(piva ? OCC_PAIV : OCC_COFI);
 | 
						||
    if (code == cfpi || cfpi.empty())
 | 
						||
      return new TString80(_occas.get(OCC_RAGSOC));
 | 
						||
  }
 | 
						||
 | 
						||
  TString query;
 | 
						||
  query << "USE OCCAS SELECT ";
 | 
						||
  if (piva)
 | 
						||
    query << "PAIV=\"" << code << '"';
 | 
						||
  else
 | 
						||
    query << "COFI=\"" << code << '"';
 | 
						||
  TISAM_recordset occas(query);
 | 
						||
  if (occas.move_first())
 | 
						||
    return new TString80(occas.get(OCC_RAGSOC).as_string());
 | 
						||
  
 | 
						||
  return NULL;
 | 
						||
}
 | 
						||
 | 
						||
TObject* TCofi_cache::key2obj(const char* key)
 | 
						||
{
 | 
						||
  TToken_string chiave(key);
 | 
						||
  const bool paiv = chiave.get_char(0)=='P';
 | 
						||
  const char tipocf = chiave.get_char(1);
 | 
						||
  TString16 code; chiave.get(2, code);
 | 
						||
 | 
						||
  TObject* ragsoc = NULL;
 | 
						||
  if (code.full())
 | 
						||
  {
 | 
						||
    if (tipocf != 'C' && tipocf != 'F')
 | 
						||
    {
 | 
						||
      ragsoc = find_ragsoc(paiv, 'C', code);
 | 
						||
      if (ragsoc == NULL)
 | 
						||
        ragsoc = find_ragsoc(paiv, 'F', code);
 | 
						||
    }
 | 
						||
    else
 | 
						||
      ragsoc = find_ragsoc(paiv, tipocf, code);
 | 
						||
  }
 | 
						||
  return ragsoc;
 | 
						||
}
 | 
						||
 | 
						||
const TString& TCofi_cache::cofi2ragsoc(char tipocf, const TString& cofi) 
 | 
						||
{ 
 | 
						||
  const TString* ragsoc = NULL;
 | 
						||
  if (cofi.full())
 | 
						||
  {
 | 
						||
    TString80 key;
 | 
						||
    key.format("CF|%c|%s", tipocf, (const char*)cofi);
 | 
						||
    ragsoc = (const TString*)objptr(key); 
 | 
						||
  }
 | 
						||
  if (ragsoc == NULL)
 | 
						||
  {
 | 
						||
    TString& str = get_tmp_string();
 | 
						||
    str << TR("C.F. sconosciuto ") << cofi;
 | 
						||
    ragsoc = &str;
 | 
						||
  }
 | 
						||
  return *ragsoc;
 | 
						||
}
 | 
						||
 | 
						||
const TString& TCofi_cache::paiv2ragsoc(char tipocf, const TString& paiv) 
 | 
						||
{ 
 | 
						||
  const TString* ragsoc = NULL;
 | 
						||
  if (paiv.full())
 | 
						||
  {
 | 
						||
    TString80 key;
 | 
						||
    key.format("PI|%c|%s", tipocf, (const char*)paiv);
 | 
						||
    ragsoc = (const TString*)objptr(key); 
 | 
						||
  }
 | 
						||
  if (ragsoc == NULL)
 | 
						||
  {
 | 
						||
    TString& str = get_tmp_string();
 | 
						||
    str << TR("P.I. sconosciuta ") << paiv;
 | 
						||
    ragsoc = &str;
 | 
						||
  }
 | 
						||
  return *ragsoc;
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TDati_rilevanti_rep
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
bool TDati_rilevanti_rep::get_usr_val(const TString& name, TVariant& var) const
 | 
						||
{
 | 
						||
  const TDati_rilevanti_set& set = *(TDati_rilevanti_set*)recordset();
 | 
						||
  const int tipo = set.rec_type()[0] - '0';
 | 
						||
 | 
						||
  if (name == "ANNO")
 | 
						||
  {
 | 
						||
    var.set(set.anno());
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
  if (name == "TIPO")
 | 
						||
  {
 | 
						||
    var.set(tipo);
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
  if (name == "COFI")
 | 
						||
  {
 | 
						||
    switch (tipo)
 | 
						||
    {
 | 
						||
    case  1: var = set.get("1.2"); break;
 | 
						||
    case  4: var = set.get("4.3"); break;
 | 
						||
    default: var.set_null();       break;
 | 
						||
    }
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
  if (name == "PAIV")
 | 
						||
  {
 | 
						||
    switch (tipo)
 | 
						||
    {
 | 
						||
    case  2: var = set.get("2.2"); break;
 | 
						||
    case  4: var = set.get("4.2"); break;
 | 
						||
    default: var.set_null();       break;
 | 
						||
    }
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
  if (name == "RAGSOC")
 | 
						||
  {
 | 
						||
    switch (tipo)
 | 
						||
    {
 | 
						||
    case  1: var = cofi2ragsoc(' ', set.get("1.2").as_string()); break;
 | 
						||
    case  2: 
 | 
						||
      {
 | 
						||
        const char tipocf = set.get("2.8").as_int() == 2 ? 'F' : 'C';
 | 
						||
        var = paiv2ragsoc(tipocf, set.get("2.2").as_string()); 
 | 
						||
      }
 | 
						||
      break;
 | 
						||
    case  3: 
 | 
						||
      var = set.get("3.8");
 | 
						||
      if (var.as_string().blank())
 | 
						||
      {
 | 
						||
        TString80 rs;
 | 
						||
        rs << set.get("3.2") << ' ' << set.get("3.3");
 | 
						||
        var = rs.trim();
 | 
						||
      }
 | 
						||
      break;
 | 
						||
    case  4: 
 | 
						||
      {
 | 
						||
        const TString16 paiv = set.get("4.2").as_string();
 | 
						||
        if (paiv.full())
 | 
						||
          var = paiv2ragsoc(' ', paiv);
 | 
						||
        else
 | 
						||
        {
 | 
						||
          const TString16 cofi = set.get("4.3").as_string();
 | 
						||
          var = cofi2ragsoc(' ', cofi);
 | 
						||
        }
 | 
						||
      }
 | 
						||
      break;
 | 
						||
    case  5: 
 | 
						||
      var = set.get("5.8");
 | 
						||
      if (var.as_string().blank())
 | 
						||
      {
 | 
						||
        TString80 rs;
 | 
						||
        rs << set.get("5.2") << ' ' << set.get("5.3");
 | 
						||
        var = rs.trim();
 | 
						||
      }
 | 
						||
      break;
 | 
						||
    default: var.set_null();       break;
 | 
						||
    }
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
  if (name == "DATAREG")
 | 
						||
  {
 | 
						||
    switch (tipo)
 | 
						||
    {
 | 
						||
    case  1: var = set.get("1.3");  break;
 | 
						||
    case  2: var = set.get("2.3");  break;
 | 
						||
    case  3: var = set.get("3.12"); break;
 | 
						||
    case  4: var = set.get("4.4");  break;
 | 
						||
    case  5: var = set.get("5.12"); break;
 | 
						||
    default: var.set_null();        break;
 | 
						||
    }
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
  if (name == "NUMDOC")
 | 
						||
  {
 | 
						||
    switch (tipo)
 | 
						||
    {
 | 
						||
    case  2: var = set.get("2.4");  break;
 | 
						||
    case  3: var = set.get("3.13"); break;
 | 
						||
    case  4: var = set.get("4.5");  break;
 | 
						||
    case  5: var = set.get("5.13"); break;
 | 
						||
    default: var.set_null();        break;
 | 
						||
    }
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
  if (name == "IMPORTO")
 | 
						||
  {
 | 
						||
    switch (tipo)
 | 
						||
    {
 | 
						||
    case  1: var = set.get("1.5");  break;
 | 
						||
    case  2: var = set.get("2.6");  break;
 | 
						||
    case  3: var = set.get("3.15"); break;
 | 
						||
    case  4: var = set.get("4.6");  break;
 | 
						||
    case  5: var = set.get("5.14"); break;
 | 
						||
    default: var.set_null();        break;
 | 
						||
    }
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
  if (name == "IMPOSTA")
 | 
						||
  {
 | 
						||
    switch (tipo)
 | 
						||
    {
 | 
						||
    case  2: var = set.get("2.7");  break;
 | 
						||
    case  3: var = set.get("3.16"); break;
 | 
						||
    case  4: var = set.get("4.7");  break;
 | 
						||
    case  5: var = set.get("5.15"); break;
 | 
						||
    default: var.set_null();        break;
 | 
						||
    }
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
  if (name == "DATARETT")
 | 
						||
  {
 | 
						||
    switch (tipo)
 | 
						||
    {
 | 
						||
    case  4: var = set.get("4.8");  break;
 | 
						||
    case  5: var = set.get("5.16"); break;
 | 
						||
    default: var.set_null();        break;
 | 
						||
    }
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
  if (name == "NUMRETT")
 | 
						||
  {
 | 
						||
    switch (tipo)
 | 
						||
    {
 | 
						||
    case  4: var = set.get("4.9");  break;
 | 
						||
    case  5: var = set.get("5.17"); break;
 | 
						||
    default: var.set_null();        break;
 | 
						||
    }
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
  if (name == "SIMPORTO")
 | 
						||
  {
 | 
						||
    switch (tipo)
 | 
						||
    {
 | 
						||
    case  4: var = set.get("4.10"); break;
 | 
						||
    case  5: var = set.get("5.18"); break;
 | 
						||
    default: var.set_null();        break;
 | 
						||
    }
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
  if (name == "SIMPOSTA")
 | 
						||
  {
 | 
						||
    switch (tipo)
 | 
						||
    {
 | 
						||
    case  4: var = set.get("4.11"); break;
 | 
						||
    case  5: var = set.get("5.19"); break;
 | 
						||
    default: var.set_null();        break;
 | 
						||
    }
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
  if (name == "MODPAG")
 | 
						||
  {
 | 
						||
    switch (tipo)
 | 
						||
    {
 | 
						||
    case  1: var = set.get("1.4");  break;
 | 
						||
    case  2: var = set.get("2.5");  break;
 | 
						||
    case  3: var = set.get("3.14"); break;
 | 
						||
    default: var.set_null();        break;
 | 
						||
    }
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
  if (name == "TIPOPE")
 | 
						||
  {
 | 
						||
    switch (tipo)
 | 
						||
    {
 | 
						||
    case  2: var = set.get("2.8");  break;
 | 
						||
    case  3: var = set.get("3.17"); break;
 | 
						||
    default: var.set_null();        break;
 | 
						||
    }
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
 | 
						||
 | 
						||
  return TReport::get_usr_val(name, var);
 | 
						||
}
 | 
						||
 | 
						||
TDati_rilevanti_rep::TDati_rilevanti_rep(const TFilename& file)
 | 
						||
{
 | 
						||
  load("fe0100");
 | 
						||
 | 
						||
  TDati_rilevanti_set* set = new TDati_rilevanti_set(file);
 | 
						||
  
 | 
						||
  // Elimina testata e coda
 | 
						||
  set->destroy(0); 
 | 
						||
  set->destroy(set->items()-1); 
 | 
						||
  
 | 
						||
  set_recordset(set);
 | 
						||
}
 |