Files correlati : ca3.exe ca3299a.rep Ricompilazione Demo : [ ] Commento : 0001399: CG + GC - mancano descrizioni e codici in stampa Lanciando la stampa , senza impostare nessun parametro, manca il codice della commessa e la descrizione del conto contabile git-svn-id: svn://10.65.10.50/trunk@19095 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			649 lines
		
	
	
		
			18 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			649 lines
		
	
	
		
			18 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						||
#include <execp.h>
 | 
						||
#include <progind.h>
 | 
						||
#include <reprint.h>
 | 
						||
 | 
						||
#include "../cg/cglib01.h"
 | 
						||
 | 
						||
#include "commesse.h"
 | 
						||
#include "pconana.h"
 | 
						||
#include "movana.h"
 | 
						||
#include "rmovana.h"
 | 
						||
 | 
						||
#include "ca3.h"
 | 
						||
#include "ca3200.h"
 | 
						||
#include "calib01.h"
 | 
						||
#include "calib02.h"
 | 
						||
#include "camask.h"
 | 
						||
 | 
						||
////////////////////////////////////////////////////////
 | 
						||
//	MASCHERA
 | 
						||
////////////////////////////////////////////////////////
 | 
						||
class TPrint_mastrini_ca_mask : public TAnal_report_mask
 | 
						||
{
 | 
						||
protected:
 | 
						||
  bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						||
	const TString& get_report_class() const; 
 | 
						||
  bool test_compatible_report();
 | 
						||
 | 
						||
public:
 | 
						||
  TPrint_mastrini_ca_mask();
 | 
						||
  virtual ~TPrint_mastrini_ca_mask() {}
 | 
						||
};
 | 
						||
 | 
						||
const TString& TPrint_mastrini_ca_mask::get_report_class() const
 | 
						||
{
 | 
						||
  TString& classe = get_tmp_string();
 | 
						||
  classe = "ca3200a";
 | 
						||
//  const int stp = get_int(F_TIPOCONTI);
 | 
						||
//  classe << (stp == 1 ? 'a' : 'b');   // tipo di report da usare in caso di report multipli
 | 
						||
  return classe;
 | 
						||
}
 | 
						||
 | 
						||
bool TPrint_mastrini_ca_mask::test_compatible_report()
 | 
						||
{
 | 
						||
  TFilename lib = get_report_class();
 | 
						||
  const TString& name = get(F_REPORT);
 | 
						||
  bool ok = name.not_empty();
 | 
						||
  if (ok)
 | 
						||
  {
 | 
						||
    TReport rep; 
 | 
						||
    ok = rep.load(name);
 | 
						||
    if (ok)
 | 
						||
    {
 | 
						||
      const TString& classe = rep.get_class();
 | 
						||
      ok = classe == lib;
 | 
						||
    }
 | 
						||
  }
 | 
						||
  if (!ok)
 | 
						||
  {
 | 
						||
    set(F_REPORT, lib);
 | 
						||
    lib.ext("rep");
 | 
						||
    ok = lib.custom_path();
 | 
						||
  }
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
bool TPrint_mastrini_ca_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						||
{
 | 
						||
  switch (o.dlg())
 | 
						||
  {
 | 
						||
	case F_TIPOCONTI:
 | 
						||
		if (e == fe_init || e == fe_modify)
 | 
						||
		{
 | 
						||
			test_compatible_report();	//in base al tipo di conti da stampare setta i report compatibili (solo nel caso di rep multipli)
 | 
						||
		}
 | 
						||
		break;
 | 
						||
  case F_REPORT:
 | 
						||
    if (e == fe_button)
 | 
						||
    {
 | 
						||
      const TString8 lib = get_report_class();
 | 
						||
      TFilename path = o.get();
 | 
						||
      if (select_custom_file(path, "rep", lib))
 | 
						||
      {
 | 
						||
        path = path.name();
 | 
						||
        path.ext("");
 | 
						||
        o.set(path);
 | 
						||
      }
 | 
						||
    } else
 | 
						||
    if (e == fe_close)
 | 
						||
    {
 | 
						||
      if (!test_compatible_report())
 | 
						||
        return error_box(TR("Impossibile trovare un report compatibile"));
 | 
						||
    }
 | 
						||
    break;
 | 
						||
  case F_ANNO:
 | 
						||
    if (e == fe_modify && !o.empty())
 | 
						||
    {
 | 
						||
      TEsercizi_contabili esc;
 | 
						||
      TDate inies, fines;
 | 
						||
      if (esc.code2range(atoi(o.get()), inies, fines))
 | 
						||
      {
 | 
						||
        set(F_DATAINI, inies);
 | 
						||
        set(F_DATAFIN, fines);
 | 
						||
      }
 | 
						||
    }
 | 
						||
    break;
 | 
						||
	case F_DATAINI:
 | 
						||
	case F_DATAFIN:
 | 
						||
		if (e == fe_close)
 | 
						||
		{
 | 
						||
			const int anno = get_int(F_ANNO);
 | 
						||
			if (anno > 0)	//se viene selezionato un esercizio..
 | 
						||
			{
 | 
						||
				TEsercizi_contabili esc;	//..le date devono essere incluse nell'esercizio selezionato!
 | 
						||
				const TDate data = o.get();
 | 
						||
				if (!data.empty() && esc.date2esc(data) != anno)
 | 
						||
					return error_box(TR("La data deve appartenere all'anno selezionato"));
 | 
						||
			}
 | 
						||
			else	//se l'esercizio <20> vuoto le date diventano obbligatorie!!
 | 
						||
			{
 | 
						||
				if (o.empty())
 | 
						||
					return error_box(TR("La data <20> obbligatoria in quanto manca l'esercizio"));
 | 
						||
			}
 | 
						||
		}
 | 
						||
		break;
 | 
						||
  default: break;
 | 
						||
  }
 | 
						||
	return true;
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
TPrint_mastrini_ca_mask::TPrint_mastrini_ca_mask()
 | 
						||
								:TAnal_report_mask("ca3200")
 | 
						||
{
 | 
						||
  TConfig& cfg = ca_config();
 | 
						||
	const bool use_pdcc = cfg.get_bool("UsePdcc");
 | 
						||
 | 
						||
	const int logicnum = use_pdcc ? LF_PCON : LF_PCONANA;
 | 
						||
	const int nfields = ca_create_fields(*this, 1, logicnum, 2, 4, F_CDC1_INI, F_DES1_INI, 0x0, "#DACONTO");
 | 
						||
	ca_create_fields(*this, 1, logicnum, 2, 10, F_CDC1_FIN, F_DES1_FIN, 0x0, "#ACONTO");
 | 
						||
 | 
						||
	for (int i = 0; i < nfields; i++)
 | 
						||
	{
 | 
						||
		TMask_field& daconto = field(F_CDC1_INI + i);
 | 
						||
		daconto.set_group(1);
 | 
						||
		daconto.check_type(CHECK_NORMAL);
 | 
						||
		TMask_field& aconto = field(F_CDC1_FIN + i);
 | 
						||
		aconto.set_group(2);
 | 
						||
		aconto.check_type(CHECK_NORMAL);
 | 
						||
	}
 | 
						||
	// creazione dei campi della seconda pagina della maschera
 | 
						||
	create_sheet(F_RIGHE);
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////////
 | 
						||
//	RECORDSET PRINCIPALE (caso standard: conti movimentati)
 | 
						||
///////////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TPrint_mastrini_ca_recordset : public TISAM_recordset
 | 
						||
{
 | 
						||
protected:
 | 
						||
	int _anno;
 | 
						||
	int _tipoconti;
 | 
						||
	int _tipimov;
 | 
						||
  TDate _dadata, _adata;
 | 
						||
	long _danumreg, _anumreg;
 | 
						||
  TString _daconto, _aconto, _codcosto, _codcms, _codfas;
 | 
						||
	
 | 
						||
protected:	//da libreria
 | 
						||
	virtual const TVariant& get(const char* column_name) const;
 | 
						||
 | 
						||
protected:
 | 
						||
  static bool mov_filter(const TRelation* rel);
 | 
						||
  bool valid_record(const TRelation& rel) const;
 | 
						||
  virtual void set_custom_filter(TCursor& cur) const;
 | 
						||
	const TImporto& saldo_iniziale(const char* conto) const;
 | 
						||
 | 
						||
public:
 | 
						||
  virtual void set_filter(const TPrint_mastrini_ca_mask& msk, int cms_row);
 | 
						||
  TPrint_mastrini_ca_recordset(const TString& sql) : TISAM_recordset(sql) { }
 | 
						||
};
 | 
						||
 | 
						||
static const TPrint_mastrini_ca_recordset* myself = NULL;
 | 
						||
 | 
						||
//metodo per riconoscere se il record corrente soddisfa i filtri della maschera...strafighissimo!
 | 
						||
bool TPrint_mastrini_ca_recordset::valid_record(const TRelation& rel) const
 | 
						||
{
 | 
						||
	//prima controlla la testata...
 | 
						||
  const TRectype& mov = rel.curr(LF_MOVANA);
 | 
						||
 | 
						||
	const char tipomov = mov.get_char(MOVANA_TIPOMOV);
 | 
						||
	int tipomov_int = 0;
 | 
						||
	switch (tipomov)
 | 
						||
	{
 | 
						||
		case 'P': tipomov_int = 2; break;
 | 
						||
		case 'V': tipomov_int = 4; break;
 | 
						||
		default : tipomov_int = 1; break;
 | 
						||
	}
 | 
						||
	if ((_tipimov & tipomov_int) == 0)
 | 
						||
		return false;
 | 
						||
 | 
						||
  //aggiunta 01/12/08; se non si specifica l'esercizio si DEVE tener conto della DATAREG e non della DATACOMP; quindi..
 | 
						||
  //..deve effettuare tale controllo e controllare se la datareg rientra nell'intervallo di date selezionato sulla maschera
 | 
						||
  if (_anno <= 0)
 | 
						||
  {
 | 
						||
    const TDate datareg = mov.get_date(MOVANA_DATAREG);
 | 
						||
    if (_dadata.ok() && datareg < _dadata)
 | 
						||
      return false;
 | 
						||
    if (_adata.ok() && datareg > _adata)
 | 
						||
      return false;
 | 
						||
  }
 | 
						||
 | 
						||
	//..poi le righe (devono comparire solo le righe con cdc/cms/fsc che appaiono nello sheet)
 | 
						||
	const TRectype& rmov = rel.curr(LF_RMOVANA);
 | 
						||
 | 
						||
  if (_codcosto.not_empty())
 | 
						||
  {
 | 
						||
    const TString& cos = rmov.get(RMOVANA_CODCCOSTO);
 | 
						||
    if (cos != _codcosto)
 | 
						||
      return false;
 | 
						||
  }
 | 
						||
  if (_codcms.not_empty())
 | 
						||
  {
 | 
						||
    const TString& cms = rmov.get(RMOVANA_CODCMS);
 | 
						||
    if (cms != _codcms)
 | 
						||
      return false;
 | 
						||
  }
 | 
						||
  if (_codfas.not_empty())
 | 
						||
  {
 | 
						||
    const TString& fas = rmov.get(RMOVANA_CODFASE);
 | 
						||
    if (fas != _codfas)
 | 
						||
      return false;
 | 
						||
	}
 | 
						||
 | 
						||
  return true;
 | 
						||
}
 | 
						||
 | 
						||
bool TPrint_mastrini_ca_recordset::mov_filter(const TRelation* rel)
 | 
						||
{
 | 
						||
  return myself->valid_record(*rel);
 | 
						||
}
 | 
						||
 | 
						||
void TPrint_mastrini_ca_recordset::set_custom_filter(TCursor& cur) const
 | 
						||
{
 | 
						||
	//filtro sui conti selezionati sulla maschera
 | 
						||
	TRectype darec(cur.curr()), arec(cur.curr());	//record corrente (rmovana (solo movimentati))
 | 
						||
 | 
						||
	if (_daconto.not_empty())
 | 
						||
		darec.put(RMOVANA_CODCONTO, _daconto);
 | 
						||
	if (_dadata.ok() && _anno > 0)
 | 
						||
		darec.put(RMOVANA_DATACOMP, _dadata);
 | 
						||
 | 
						||
	if (_aconto.not_empty())
 | 
						||
		arec.put(RMOVANA_CODCONTO, _aconto);
 | 
						||
	if (_adata.ok() && _anno > 0)
 | 
						||
		arec.put(RMOVANA_DATACOMP, _adata);
 | 
						||
 | 
						||
	cur.setregion(darec, arec);
 | 
						||
 | 
						||
  myself = this;
 | 
						||
  cur.set_filterfunction(mov_filter, true);
 | 
						||
}
 | 
						||
 | 
						||
const TImporto& TPrint_mastrini_ca_recordset::saldo_iniziale(const char* conto) const
 | 
						||
{
 | 
						||
  TAnal_bill bill(conto, _codcosto, _codcms, _codfas);
 | 
						||
	const TSaldanal& saldo = ca_saldo(bill, _dadata, _adata, _tipimov);
 | 
						||
	return saldo._ini;
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
const TVariant& TPrint_mastrini_ca_recordset::get(const char* column_name) const
 | 
						||
{
 | 
						||
  if (strncmp(column_name, "SALDOINI:", 9) == 0)
 | 
						||
  {
 | 
						||
    const TString16 sub_field = column_name+9;
 | 
						||
    const TString& conto = get(RMOVANA_CODCONTO).as_string();
 | 
						||
    const TImporto& saldo_ini = saldo_iniziale(conto);
 | 
						||
 | 
						||
    TVariant& var = get_tmp_var();
 | 
						||
    if (sub_field == "DARE")
 | 
						||
      var = saldo_ini.sezione() == 'D' ? saldo_ini.valore() : ZERO; 
 | 
						||
		else
 | 
						||
      var = saldo_ini.sezione() == 'A' ? saldo_ini.valore() : ZERO; 
 | 
						||
    return var;
 | 
						||
  }
 | 
						||
 | 
						||
  if (strcmp(column_name, "#COSTO") == 0)
 | 
						||
  {
 | 
						||
    TVariant& var = get_tmp_var();
 | 
						||
    var = _codcosto;
 | 
						||
    return var;
 | 
						||
  }
 | 
						||
  if (strcmp(column_name, "#COMMESSA") == 0)
 | 
						||
  {
 | 
						||
    TVariant& var = get_tmp_var();
 | 
						||
    var = _codcms;
 | 
						||
    return var;
 | 
						||
  }
 | 
						||
  if (strcmp(column_name, "#FASE") == 0)
 | 
						||
  {
 | 
						||
    TVariant& var = get_tmp_var();
 | 
						||
    var = _codfas;
 | 
						||
    return var;
 | 
						||
  }
 | 
						||
  return TISAM_recordset::get(column_name);
 | 
						||
}
 | 
						||
 | 
						||
//metodo per caricare i valori nel recordset dalla maschera...fighissimo!!
 | 
						||
void TPrint_mastrini_ca_recordset::set_filter(const TPrint_mastrini_ca_mask& msk, int cms_row)
 | 
						||
{
 | 
						||
  _daconto, _aconto, _codcosto = _codcms = _codfas = "";
 | 
						||
  if (cms_row >= 0)
 | 
						||
  {
 | 
						||
    TSheet_field& sf = msk.sfield(F_RIGHE);
 | 
						||
    TMask& sm = sf.sheet_mask();
 | 
						||
    sf.update_mask(cms_row);
 | 
						||
    TRelation rel(LF_RMOVANA);
 | 
						||
    sm.autosave(rel);
 | 
						||
    _codcosto = rel.curr().get(RMOVANA_CODCCOSTO);
 | 
						||
    _codcms = rel.curr().get(RMOVANA_CODCMS);
 | 
						||
    _codfas = rel.curr().get(RMOVANA_CODFASE);
 | 
						||
  }
 | 
						||
 | 
						||
	for (int i = 0; msk.id2pos(F_CDC1_INI+i) > 0; i++)
 | 
						||
	{
 | 
						||
		_daconto << msk.get(F_CDC1_INI+i);
 | 
						||
		_aconto << msk.get(F_CDC1_FIN+i);
 | 
						||
	}
 | 
						||
 | 
						||
  _dadata = msk.get_date(F_DATAINI);
 | 
						||
  _adata = msk.get_date(F_DATAFIN);
 | 
						||
 | 
						||
	_tipimov = 0;
 | 
						||
	switch (msk.get(F_TIPIMOV)[0])
 | 
						||
	{
 | 
						||
		case 'N': _tipimov = 1; break;
 | 
						||
		case 'P': _tipimov = 6; break;
 | 
						||
		default: _tipimov = 7; break;
 | 
						||
	}
 | 
						||
	_tipoconti = msk.get_int(F_TIPOCONTI);
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
/////////////////////////////////////////////////////////////////////////////////
 | 
						||
//	RECORDSET SECONDARIO (casi alternativi: conti con saldo != 0 e tutti i conti)
 | 
						||
/////////////////////////////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TPrint_mastrini_ca_alternative_recordset : public TPrint_mastrini_ca_recordset
 | 
						||
{
 | 
						||
	TIsamtempfile* _tmp_rmovana;
 | 
						||
protected:
 | 
						||
	const TImporto& saldo_finale(const char* conto) const;
 | 
						||
  virtual void set_custom_filter(TCursor& cur) const;
 | 
						||
 | 
						||
public:
 | 
						||
	virtual void set_filter(const TPrint_mastrini_ca_mask& msk, int cms_row);
 | 
						||
	TPrint_mastrini_ca_alternative_recordset(const TString& sql);
 | 
						||
	~TPrint_mastrini_ca_alternative_recordset() { delete _tmp_rmovana; }
 | 
						||
};
 | 
						||
 | 
						||
TPrint_mastrini_ca_alternative_recordset::TPrint_mastrini_ca_alternative_recordset(const TString& sql)
 | 
						||
																					: TPrint_mastrini_ca_recordset(sql)
 | 
						||
{
 | 
						||
	_tmp_rmovana = NULL;
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
const TImporto& TPrint_mastrini_ca_alternative_recordset::saldo_finale(const char* conto) const
 | 
						||
{
 | 
						||
  TAnal_bill bill(conto, _codcosto, _codcms, _codfas);
 | 
						||
	const TSaldanal& saldo = ca_saldo(bill, _dadata, _adata, _tipimov);
 | 
						||
	return saldo._fin;
 | 
						||
}
 | 
						||
 | 
						||
void TPrint_mastrini_ca_alternative_recordset::set_custom_filter(TCursor& cur) const
 | 
						||
{
 | 
						||
	//crea un file temporaneo che non viene distrutto ad inizio stampa effettiva 
 | 
						||
	TIsamtempfile* tmp = new TIsamtempfile(LF_RMOVANA, "anal", false, false);
 | 
						||
	relation()->replace(tmp);	//sostituisce il vero file rmovana con quello temporaneo
 | 
						||
}
 | 
						||
 | 
						||
void TPrint_mastrini_ca_alternative_recordset::set_filter(const TPrint_mastrini_ca_mask& msk, int cms_row)
 | 
						||
{
 | 
						||
	//se esiste non vuoto il file temporano con tracciato rmovana lo cancella e lo ricrea vuoto
 | 
						||
	if (_tmp_rmovana != NULL)
 | 
						||
		delete _tmp_rmovana;
 | 
						||
 | 
						||
	_tmp_rmovana = new TIsamtempfile(LF_RMOVANA, "anal", true, true);
 | 
						||
 | 
						||
	//prende un po' di dati dalla maschera
 | 
						||
	_daconto, _aconto, _codcosto = _codcms = _codfas = "";
 | 
						||
  if (cms_row >= 0)
 | 
						||
  {
 | 
						||
    TSheet_field& sf = msk.sfield(F_RIGHE);
 | 
						||
    TMask& sm = sf.sheet_mask();
 | 
						||
    sf.update_mask(cms_row);
 | 
						||
    TRelation rel(LF_RMOVANA);
 | 
						||
    sm.autosave(rel);
 | 
						||
    _codcosto = rel.curr().get(RMOVANA_CODCCOSTO);
 | 
						||
    _codcms = rel.curr().get(RMOVANA_CODCMS);
 | 
						||
    _codfas = rel.curr().get(RMOVANA_CODFASE);
 | 
						||
  }
 | 
						||
 | 
						||
	for (int i = 0; msk.id2pos(F_CDC1_INI+i) > 0; i++)
 | 
						||
	{
 | 
						||
		_daconto << msk.get(F_CDC1_INI+i);
 | 
						||
		_aconto << msk.get(F_CDC1_FIN+i);
 | 
						||
	}
 | 
						||
 | 
						||
  _dadata = msk.get_date(F_DATAINI);
 | 
						||
  _adata = msk.get_date(F_DATAFIN);
 | 
						||
  // Riempie le date con valori sensati
 | 
						||
  if (!_dadata.ok() || !_adata.ok())
 | 
						||
  {
 | 
						||
    TEsercizi_contabili esc;
 | 
						||
    const int codes = msk.get_int(F_ANNO);
 | 
						||
    if (esc.exist(codes))
 | 
						||
    {
 | 
						||
      const TEsercizio& esercizio = esc[codes];
 | 
						||
      if (!_dadata.ok())
 | 
						||
        _dadata = esercizio.inizio();
 | 
						||
      if (!_adata.ok())
 | 
						||
        _adata = esercizio.fine();
 | 
						||
    }
 | 
						||
    else
 | 
						||
    {
 | 
						||
      if (!_adata.ok())
 | 
						||
        _adata = TDate(31, 12, 9999);
 | 
						||
    }
 | 
						||
  }
 | 
						||
 | 
						||
	_tipimov = 0;
 | 
						||
	switch (msk.get(F_TIPIMOV)[0])
 | 
						||
	{
 | 
						||
		case 'N': _tipimov = 1; break;
 | 
						||
		case 'P': _tipimov = 6; break;
 | 
						||
		default: _tipimov = 7; break;
 | 
						||
	}
 | 
						||
 | 
						||
	_tipoconti = msk.get_int(F_TIPOCONTI);
 | 
						||
 | 
						||
	//scandisce il piano dei conti analitico creando un cursore con i conti nell'intervallo scelto sulla maschera
 | 
						||
	TPconana_recordset pconana;
 | 
						||
	
 | 
						||
	pconana.set_filter(' ', _daconto, _aconto, _codcosto, _codcms, _codfas,
 | 
						||
                  _dadata, _adata, _tipimov, _tipoconti==1, _tipoconti==2);
 | 
						||
 | 
						||
	const long pconana_items = pconana.items();
 | 
						||
	TProgind pi(pconana_items, TR("Scansione conti..."));
 | 
						||
 | 
						||
	TRelation rel_rmovana(LF_RMOVANA);
 | 
						||
	rel_rmovana.add(LF_MOVANA, "NUMREG==NUMREG");	//aggiunge le testate x avere i tipi mov.
 | 
						||
 | 
						||
	TRectype da_rmovana(LF_RMOVANA);
 | 
						||
	da_rmovana.put(RMOVANA_DATACOMP, _dadata);
 | 
						||
	TRectype a_rmovana(LF_RMOVANA);
 | 
						||
	a_rmovana.put(RMOVANA_DATACOMP, _adata);
 | 
						||
 | 
						||
	TString filtro;
 | 
						||
	if (_codcosto.not_empty())
 | 
						||
		filtro << "(" << RMOVANA_CODCCOSTO << "?=\"" << _codcosto << "*\")";
 | 
						||
	if (_codcms.not_empty())
 | 
						||
	{
 | 
						||
		if (filtro.not_empty())
 | 
						||
			filtro << "&&";
 | 
						||
		filtro << "(" << RMOVANA_CODCMS << "?=\"" << _codcms << "*\")";
 | 
						||
	}
 | 
						||
	if (_codfas.not_empty())
 | 
						||
	{
 | 
						||
		if (filtro.not_empty())
 | 
						||
			filtro << "&&";
 | 
						||
		filtro << "(" << RMOVANA_CODFASE << "?=\"" << _codfas << "*\")";
 | 
						||
	}
 | 
						||
 | 
						||
	//scandisce il piano dei conti..
 | 
						||
  for (bool pok = pconana.move_first(); pok; pok = pconana.move_next())
 | 
						||
	{
 | 
						||
		if (!pi.addstatus(1))
 | 
						||
      break;
 | 
						||
		const TString& conto = pconana.get(PCONANA_CODCONTO).as_string();
 | 
						||
 | 
						||
		//..crea un cursore su rmovana per vedere se i conti selezionati hanno veri movimenti che soddisfano
 | 
						||
		//i parametri del filtro sulla maschera
 | 
						||
		da_rmovana.put(RMOVANA_CODCONTO, conto);
 | 
						||
		a_rmovana.put(RMOVANA_CODCONTO, conto);
 | 
						||
 | 
						||
		TCursor cur_rmovana(&rel_rmovana, filtro, 2, &da_rmovana, &a_rmovana);
 | 
						||
		const long rmovana_items = cur_rmovana.items();
 | 
						||
		bool almeno_uno_aggiunto = false;
 | 
						||
		if (rmovana_items > 0)
 | 
						||
		{
 | 
						||
   		cur_rmovana.freeze();
 | 
						||
			for (cur_rmovana = 0; cur_rmovana.pos() < rmovana_items; ++cur_rmovana)
 | 
						||
			{
 | 
						||
				//deve coincidere anche il tipomov! sarebbe stato troppo semplice...
 | 
						||
				const char tipomov = rel_rmovana.curr(LF_MOVANA).get_char(MOVANA_TIPOMOV);
 | 
						||
				int tipomov_int = 0;
 | 
						||
				switch (tipomov)
 | 
						||
				{
 | 
						||
					case 'P': tipomov_int = 2; break;
 | 
						||
					case 'V': tipomov_int = 4; break;
 | 
						||
					default: tipomov_int = 1; break;
 | 
						||
				}
 | 
						||
				if ((_tipimov & tipomov_int) != 0)
 | 
						||
				{
 | 
						||
					_tmp_rmovana->write(cur_rmovana.curr());	// aggiunge i record al file temporaneo
 | 
						||
					almeno_uno_aggiunto = true;
 | 
						||
				}
 | 
						||
			}
 | 
						||
   		cur_rmovana.freeze(false);
 | 
						||
		}
 | 
						||
		//se non ha aggiunto nemmeno un record valido..
 | 
						||
		//crea un record di rmovana con il solo conto,datacomp e lo aggiunge al file temporaneo
 | 
						||
		if (!almeno_uno_aggiunto)
 | 
						||
		{
 | 
						||
			TRectype fake_rmovana_rec(LF_RMOVANA);
 | 
						||
			fake_rmovana_rec.put(RMOVANA_CODCONTO, conto);
 | 
						||
			fake_rmovana_rec.put(RMOVANA_DATACOMP, _dadata);
 | 
						||
			_tmp_rmovana->write(fake_rmovana_rec);
 | 
						||
		}
 | 
						||
				
 | 
						||
	} //end for su pconana_items
 | 
						||
 | 
						||
}
 | 
						||
 | 
						||
////////////////////////////////////////////////////////
 | 
						||
//	REPORT
 | 
						||
////////////////////////////////////////////////////////
 | 
						||
class TPrint_mastrini_ca_rep : public TAnal_report
 | 
						||
{
 | 
						||
protected:
 | 
						||
	virtual bool set_recordset(const TString& sql);
 | 
						||
 | 
						||
public:
 | 
						||
	void set_filter(const TPrint_mastrini_ca_mask& msk, int cms_row);
 | 
						||
};
 | 
						||
 | 
						||
bool TPrint_mastrini_ca_rep::set_recordset(const TString& sql)
 | 
						||
{
 | 
						||
  TPrint_mastrini_ca_recordset* rs = new TPrint_mastrini_ca_recordset(sql);
 | 
						||
  return TReport::set_recordset(rs);
 | 
						||
}
 | 
						||
 | 
						||
void TPrint_mastrini_ca_rep::set_filter(const TPrint_mastrini_ca_mask& msk, int cms_row)
 | 
						||
{
 | 
						||
	TReport::set_recordset(NULL);	//forza azzeramento file anal.dbf prima di ricostruirlo
 | 
						||
 | 
						||
	const int tipoconti = msk.get_int(F_TIPOCONTI);
 | 
						||
 | 
						||
	TPrint_mastrini_ca_recordset* recset = NULL;
 | 
						||
 | 
						||
	const char* const query ="USE RMOVANA KEY 2\nJOIN MOVANA INTO NUMREG==NUMREG";
 | 
						||
	switch (tipoconti)
 | 
						||
	{
 | 
						||
	case 1:
 | 
						||
		recset = new TPrint_mastrini_ca_recordset(query); 
 | 
						||
		break;
 | 
						||
	default:
 | 
						||
		recset = new TPrint_mastrini_ca_alternative_recordset(query);
 | 
						||
		break;
 | 
						||
	}
 | 
						||
  recset->set_filter(msk, cms_row);
 | 
						||
	TAnal_report::set_recordset(recset);
 | 
						||
}
 | 
						||
 | 
						||
////////////////////////////////////////////////////////
 | 
						||
//	APPLICAZIONE
 | 
						||
////////////////////////////////////////////////////////
 | 
						||
class TPrint_mastrini_ca : public TSkeleton_application
 | 
						||
{
 | 
						||
protected:
 | 
						||
  virtual const char * extra_modules() const {return "cm";} //funziona anche con autorizzazione CM
 | 
						||
  virtual void main_loop();
 | 
						||
};
 | 
						||
 | 
						||
 | 
						||
void TPrint_mastrini_ca::main_loop()
 | 
						||
{
 | 
						||
	TPrint_mastrini_ca_mask mask;
 | 
						||
  while (mask.run() == K_ENTER)
 | 
						||
  {
 | 
						||
		//report e book dei report
 | 
						||
		TReport_book book;
 | 
						||
		TString path = mask.get(F_REPORT);
 | 
						||
		if (path.empty())
 | 
						||
			path = "ca3200a";
 | 
						||
		TPrint_mastrini_ca_rep rep;
 | 
						||
		rep.load(path);
 | 
						||
 | 
						||
  	TSheet_field& sheet = mask.sfield(F_RIGHE);
 | 
						||
		TString video_string;	//stringa che compare nella progind
 | 
						||
    if (sheet.empty())	//se non ci sono righe sullo sheet (selezione su tutte le cms/cdc)...
 | 
						||
		{
 | 
						||
			TToken_string& row = sheet.row(-1);	//crea la prima riga dello sheet
 | 
						||
 | 
						||
      //stabilisce quale <20> il primo livello (tra CDC e CMS)..
 | 
						||
			const TMultilevel_code_info& liv1 = *ca_multilevel_code_info_by_index(0);	
 | 
						||
      const int logic1 = liv1.logic();
 | 
						||
			TISAM_recordset set(logic1 == LF_CDC ? "USE CDC" : "USE COMMESSE");	//..e di conseguenza scrive la use giusta
 | 
						||
 | 
						||
      bool skip_closed = false;
 | 
						||
      if (logic1 == LF_COMMESSE)
 | 
						||
        skip_closed = !yesno_box(TR("E' stata richiesta la stampa di tutte le commesse:\n"
 | 
						||
                                    "Si desidera includere anche le commesse chiuse?"));
 | 
						||
			
 | 
						||
			TProgind pi(set.items(), video_string, true, true);
 | 
						||
			for (bool sok = set.move_first(); sok; sok = set.move_next())	//fighissimo metodo per scandire un file in 1 riga!
 | 
						||
			{
 | 
						||
				if (!pi.addstatus(1))
 | 
						||
					break;
 | 
						||
 | 
						||
        if (skip_closed && set.get(COMMESSE_CHIUSA).as_bool())
 | 
						||
          continue;
 | 
						||
 | 
						||
				row = set.get(0u).as_string();	//prende il valore del primo campo del file (CDC o CMS code)
 | 
						||
				
 | 
						||
        //completa la stringa da visualizzare sulla progind
 | 
						||
				video_string.cut(0) << row << '\n' << set.get(1u);	
 | 
						||
				pi.set_text(video_string);
 | 
						||
 | 
						||
				for (int l = liv1.levels()-2; l >= 0; l--)	//se la struttura <20> a pi<70> livelli costruisce la tokenstring
 | 
						||
					row.insert("|", liv1.total_len(l));
 | 
						||
 | 
						||
				rep.set_filter(mask, 0);	//fa la set filter sulla prima riga (che <20> quella usata)	
 | 
						||
				book.add(rep);
 | 
						||
			}
 | 
						||
			sheet.destroy();	//cancella le commesse aggiunte in automatico sullo sheet
 | 
						||
		}
 | 
						||
		else
 | 
						||
		{
 | 
						||
			FOR_EACH_SHEET_ROW(sheet, r, row)
 | 
						||
			{
 | 
						||
				rep.set_filter(mask, r);
 | 
						||
				book.add(rep);			
 | 
						||
			}
 | 
						||
		}
 | 
						||
 | 
						||
		book.print_or_preview();	//stampa il book dei report
 | 
						||
	}
 | 
						||
}
 | 
						||
 | 
						||
int ca3200(int argc, char* argv[])
 | 
						||
{
 | 
						||
  TPrint_mastrini_ca a;
 | 
						||
  a.run(argc, argv, TR("Stampa mastrini"));
 | 
						||
  return 0;
 | 
						||
} |