Files correlati : at3.exe Ricompilazione Demo : [ ] Commento : corretto stampa totali in statistiche (integer non andava bene) git-svn-id: svn://10.65.10.50/trunk@11269 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			827 lines
		
	
	
		
			20 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			827 lines
		
	
	
		
			20 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						|
#include <mask.h>
 | 
						|
#include <printer.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <real.h>
 | 
						|
#include <relation.h>
 | 
						|
#include <tabutil.h>
 | 
						|
#include <urldefid.h>
 | 
						|
#include <utility.h>
 | 
						|
 | 
						|
#include "at3.h"
 | 
						|
 | 
						|
// nomi campi maschera
 | 
						|
#include "at3400a.h"
 | 
						|
          
 | 
						|
// nomi dei campi
 | 
						|
#include "soggetti.h"
 | 
						|
#include "donaz.h"
 | 
						|
#include "atstatd.h"
 | 
						|
#include "sezioni.h"
 | 
						|
 | 
						|
// classe per la definizione di una riga di statistica
 | 
						|
class TRiga : public TObject
 | 
						|
{                             
 | 
						|
	int 					_anno, _mese;
 | 
						|
	TArray				_valori;
 | 
						|
 | 
						|
protected:
 | 
						|
	const TRiga& copy(const TRiga& riga);
 | 
						|
public:
 | 
						|
	const int anno() const { return _anno; }
 | 
						|
	const int mese() const { return _mese; } 
 | 
						|
	TObject* dup() const { return new TRiga(*this); }
 | 
						|
	const TRiga& operator = (const TRiga& riga);
 | 
						|
	const real& operator [] (int colonna) const;
 | 
						|
	void aggiorna_valore(int colonna, const real& numero) ;
 | 
						|
	void azzera_valori();
 | 
						|
	// costruttore
 | 
						|
	TRiga(int anno, int mese) {_anno = anno; _mese = mese;}
 | 
						|
	// costruttore di copia
 | 
						|
	TRiga(const TRiga& riga)  { copy(riga); }
 | 
						|
	virtual ~TRiga() {};
 | 
						|
};
 | 
						|
 | 
						|
const TRiga& TRiga::copy(const TRiga& riga)
 | 
						|
{
 | 
						|
	_anno = riga._anno;
 | 
						|
	_mese = riga._mese;
 | 
						|
	_valori = riga._valori;
 | 
						|
	return (*this);
 | 
						|
}
 | 
						|
 | 
						|
const TRiga& TRiga::operator = (const TRiga& riga)
 | 
						|
{
 | 
						|
	copy(riga);
 | 
						|
	return (*this);
 | 
						|
}
 | 
						|
 | 
						|
const real& TRiga::operator [] (int colonna) const
 | 
						|
{
 | 
						|
	real* valore = (real*)_valori.objptr(colonna);
 | 
						|
	if (valore == NULL)
 | 
						|
		return ZERO;
 | 
						|
	else
 | 
						|
		return *valore;		
 | 
						|
}
 | 
						|
 | 
						|
void TRiga::aggiorna_valore(int colonna, const real& numero)
 | 
						|
{
 | 
						|
	real* valore = (real*)_valori.objptr(colonna);
 | 
						|
	if (valore == NULL)
 | 
						|
		_valori.add(new real(numero), colonna);
 | 
						|
	else
 | 
						|
		*valore += numero;
 | 
						|
}
 | 
						|
  
 | 
						|
void TRiga::azzera_valori()
 | 
						|
{
 | 
						|
	_valori.destroy();
 | 
						|
}
 | 
						|
 | 
						|
class TRiepilogoDonazioni : public TApplication
 | 
						|
{
 | 
						|
	TMask*					_msk;
 | 
						|
	TRelation*   		_rel;
 | 
						|
	TCursor*				_cur;
 | 
						|
	TLocalisamfile* _sezioni;
 | 
						|
	TLocalisamfile* _soggetti;
 | 
						|
	TLocalisamfile* _donaz;
 | 
						|
	TLocalisamfile* _atstatd;
 | 
						|
	TDate						_dataini, _datafin;
 | 
						|
	bool						_primedon, _solotot;
 | 
						|
	bool						_perpunto;
 | 
						|
	TAssoc_array*		_colonne;
 | 
						|
	TArray					_righe;	// array per riepilogo donazioni
 | 
						|
	TArray					_righe_prime; // array per riepilogo prime don		
 | 
						|
	TString16				_sezini, _sotini, _sezfin, _sotfin;
 | 
						|
	int							_sezionistampate;
 | 
						|
 | 
						|
protected:
 | 
						|
	virtual bool create();
 | 
						|
	virtual bool destroy();
 | 
						|
  virtual bool menu(MENU_TAG m);
 | 
						|
	virtual TMask& get_mask() { return *_msk; }
 | 
						|
	virtual TRelation* get_relation() const { return _rel; }
 | 
						|
	int data2row(const int anno, const int mese);
 | 
						|
	bool riepilogo();
 | 
						|
	bool stampa();
 | 
						|
	bool crea_colonne();
 | 
						|
	bool crea_righe();
 | 
						|
	void azzera_righe();
 | 
						|
	void stampa_sezione(TString16 codsez, TString16 codsot);
 | 
						|
	void crea_intestazione();
 | 
						|
	TString16 int2month(const int month);
 | 
						|
public:
 | 
						|
	TRiepilogoDonazioni() {}
 | 
						|
	
 | 
						|
};
 | 
						|
 | 
						|
HIDDEN inline TRiepilogoDonazioni& app() { return (TRiepilogoDonazioni&) main_app(); }
 | 
						|
 | 
						|
TString16 TRiepilogoDonazioni::int2month(const int month)
 | 
						|
{        
 | 
						|
	TString16 mese = "";
 | 
						|
	switch (month)
 | 
						|
	{
 | 
						|
		case 1:
 | 
						|
			mese << "GENNAIO  ";
 | 
						|
		break;
 | 
						|
		case 2:
 | 
						|
			mese << "FEBBRAIO ";
 | 
						|
		break;
 | 
						|
		case 3:
 | 
						|
			mese << "MARZO    ";
 | 
						|
		break;
 | 
						|
		case 4:
 | 
						|
			mese << "APRILE   ";
 | 
						|
		break;
 | 
						|
		case 5:
 | 
						|
			mese << "MAGGIO   ";
 | 
						|
		break;
 | 
						|
		case 6:
 | 
						|
			mese << "GIUGNO   ";
 | 
						|
		break;
 | 
						|
		case 7:
 | 
						|
			mese << "LUGLIO   ";
 | 
						|
		break;
 | 
						|
		case 8:
 | 
						|
			mese << "AGOSTO   ";
 | 
						|
		break;
 | 
						|
		case 9:
 | 
						|
			mese << "SETTEMBRE";
 | 
						|
		break;
 | 
						|
		case 10:
 | 
						|
			mese << "OTTOBRE  ";
 | 
						|
		break;
 | 
						|
		case 11:
 | 
						|
			mese << "NOVEMBRE ";
 | 
						|
		break;
 | 
						|
		case 12:
 | 
						|
			mese << "DICEMBRE ";
 | 
						|
		break;
 | 
						|
	}
 | 
						|
	return mese;	
 | 
						|
}
 | 
						|
 | 
						|
int TRiepilogoDonazioni::data2row(const int anno, const int mese)
 | 
						|
{
 | 
						|
	const int annoini = _dataini.year();
 | 
						|
	return (anno-annoini)*12 + mese;
 | 
						|
}
 | 
						|
 | 
						|
bool TRiepilogoDonazioni::crea_colonne()
 | 
						|
{                   
 | 
						|
	_colonne->destroy();
 | 
						|
	TTable tdn("TDN");
 | 
						|
	real contatore(ZERO);
 | 
						|
	for (tdn.first(); !tdn.eof(); tdn.next())
 | 
						|
	{ 
 | 
						|
		real* oggetto = new real(contatore);                                
 | 
						|
		_colonne->add((const char*)tdn.get("CODTAB"),(TObject*)oggetto);
 | 
						|
		contatore+=1;
 | 
						|
	}		
 | 
						|
	return !tdn.empty();
 | 
						|
}
 | 
						|
 | 
						|
bool TRiepilogoDonazioni::crea_righe()
 | 
						|
{                     
 | 
						|
	int anno = _dataini.year();
 | 
						|
	int meseini, mesefin;
 | 
						|
	while (anno<=_datafin.year())
 | 
						|
	{            
 | 
						|
		if (anno == _dataini.year())
 | 
						|
			meseini = _dataini.month();
 | 
						|
		else
 | 
						|
			meseini = 1;
 | 
						|
		if (anno == _datafin.year())
 | 
						|
			mesefin = _datafin.month();
 | 
						|
		else
 | 
						|
			mesefin = 12;						
 | 
						|
		for (int mese=meseini;mese<=mesefin;mese++)
 | 
						|
		{		
 | 
						|
			_righe.add(new TRiga(anno, mese), data2row(anno, mese));
 | 
						|
			if (_primedon)
 | 
						|
				_righe_prime.add(new TRiga(anno, mese), data2row(anno, mese));
 | 
						|
		}			
 | 
						|
		anno++;
 | 
						|
	}		
 | 
						|
	return _righe.items()>0;	
 | 
						|
}
 | 
						|
 | 
						|
bool TRiepilogoDonazioni::create()
 | 
						|
{
 | 
						|
	TApplication::create();
 | 
						|
	_msk = new TMask("at3400a");
 | 
						|
	_rel = new TRelation(LF_DONAZ);
 | 
						|
  _rel->add(LF_SOGGETTI, "CODICE==CODICE");
 | 
						|
  _soggetti = new TLocalisamfile(LF_SOGGETTI);
 | 
						|
	_donaz = new TLocalisamfile(LF_DONAZ);
 | 
						|
	_atstatd = new TLocalisamfile(LF_ATSTATD);
 | 
						|
	_sezioni = new TLocalisamfile(LF_SEZIONI);
 | 
						|
	_colonne = new TAssoc_array();
 | 
						|
  dispatch_e_menu(BAR_ITEM(1));
 | 
						|
	return TRUE;
 | 
						|
}	
 | 
						|
 | 
						|
bool TRiepilogoDonazioni::destroy()	
 | 
						|
{
 | 
						|
	delete _colonne;
 | 
						|
	delete _sezioni;
 | 
						|
	delete _atstatd;
 | 
						|
	delete _donaz;   
 | 
						|
	delete _soggetti;
 | 
						|
	delete _rel;
 | 
						|
	delete _msk;
 | 
						|
	return TApplication::destroy();
 | 
						|
}
 | 
						|
 | 
						|
bool TRiepilogoDonazioni::menu(MENU_TAG m)
 | 
						|
{ 
 | 
						|
	TMask& msk = get_mask();
 | 
						|
	KEY tasto;
 | 
						|
 	tasto = msk.run();
 | 
						|
 	if (tasto == K_ENTER)
 | 
						|
 	{
 | 
						|
		_dataini = msk.get(F_DATAINI); 		
 | 
						|
		_datafin = msk.get(F_DATAFIN); 		
 | 
						|
		_primedon = msk.get_bool(F_PRIMEDON);
 | 
						|
		_solotot = msk.get_bool(F_SOLOTOT);
 | 
						|
		//_perpunto = msk.get_bool(F_PERPUNTO);
 | 
						|
 		_sezini = _msk->get(F_SEZINI);
 | 
						|
 		_sotini = _msk->get(F_SOTINI);
 | 
						|
 		_sezfin = _msk->get(F_SEZFIN);
 | 
						|
 		_sotfin = _msk->get(F_SOTFIN);
 | 
						|
		if (riepilogo())
 | 
						|
			stampa();
 | 
						|
 	}
 | 
						|
 	return FALSE;
 | 
						|
}  
 | 
						|
 | 
						|
void TRiepilogoDonazioni::crea_intestazione()
 | 
						|
{ 
 | 
						|
	TPrintrow row;
 | 
						|
	TString256 sep;
 | 
						|
	sep = "MENSILE DONAZIONI";
 | 
						|
	//if (_perpunto)
 | 
						|
	//	sep << " PER PUNTO PRELIEVO";
 | 
						|
	if (_dataini.ok())
 | 
						|
	{
 | 
						|
		sep << " dal ";
 | 
						|
		sep << _dataini.string();
 | 
						|
	}
 | 
						|
	if (_datafin.ok())
 | 
						|
	{
 | 
						|
		sep << " al ";
 | 
						|
		sep << _datafin.string();
 | 
						|
	}
 | 
						|
	sep.center_just(80);
 | 
						|
	row.put(sep);
 | 
						|
  row.put("@>", 1);
 | 
						|
  row.put("Pag. @#", 70);
 | 
						|
  printer().setheaderline(2, row);
 | 
						|
  row.reset();
 | 
						|
  printer().setheaderline(3, row);	  
 | 
						|
  sep = "Mese ";
 | 
						|
	TTable tdn("TDN");
 | 
						|
	int pos = 27;
 | 
						|
	for (tdn.first(); !tdn.eof(); tdn.next())
 | 
						|
	{ 
 | 
						|
		sep.overwrite((const char*)tdn.get("CODTAB"),pos);
 | 
						|
		pos = pos+10;
 | 
						|
	}		
 | 
						|
	sep.overwrite("Totale",pos);	
 | 
						|
	row.put(sep);
 | 
						|
	printer().setheaderline(5, row);  
 | 
						|
	sep = "";
 | 
						|
	sep.fill('-',80);
 | 
						|
	row.reset();
 | 
						|
	row.put(sep);
 | 
						|
	printer().setheaderline(6, row);
 | 
						|
}
 | 
						|
 | 
						|
bool TRiepilogoDonazioni::stampa()
 | 
						|
{ 
 | 
						|
	if (printer().open())
 | 
						|
	{
 | 
						|
		_sezionistampate = 0;
 | 
						|
		crea_intestazione();
 | 
						|
		TRelation* relstat = new TRelation(LF_ATSTATD);
 | 
						|
		TCursor* curstat = new TCursor(relstat, "", 2);
 | 
						|
		TString16 oldsez = "**";
 | 
						|
		TString16 oldsot = "**";
 | 
						|
		double numero, numprime;
 | 
						|
		TString16 actsez, actsot;
 | 
						|
		TString16 tipodon;
 | 
						|
		int anno, mese;
 | 
						|
		long last = curstat->items();
 | 
						|
	  for ( *curstat=0; curstat->pos() < last; ++(*curstat) )
 | 
						|
	  {
 | 
						|
			actsez = curstat->curr().get(ATS_CODSEZ);																						  	
 | 
						|
			actsot = curstat->curr().get(ATS_CODSOT);		
 | 
						|
			anno = curstat->curr().get_int(ATS_ANNO);		
 | 
						|
			mese = curstat->curr().get_int(ATS_MESE);		
 | 
						|
			tipodon = curstat->curr().get(ATS_TIPODON);		
 | 
						|
			numero = (double)curstat->curr().get_int(ATS_NUMERO);		
 | 
						|
			numprime = (double)curstat->curr().get_int(ATS_NUMPRIME);							
 | 
						|
			if (actsez != oldsez || actsot != oldsot)
 | 
						|
			{                 
 | 
						|
				if (oldsez != "**" && oldsot != "**")
 | 
						|
				{
 | 
						|
					stampa_sezione(oldsez,oldsot);
 | 
						|
					azzera_righe();
 | 
						|
				}
 | 
						|
				oldsez = actsez;
 | 
						|
				oldsot = actsot;
 | 
						|
			}				
 | 
						|
			TRiga& riga = (TRiga&)_righe[data2row(anno,mese)];
 | 
						|
			real& colonna = (real&)_colonne->find((const char*)tipodon);
 | 
						|
			real n = numero;
 | 
						|
			riga.aggiorna_valore((int) colonna.integer(),n);
 | 
						|
			if (_primedon)
 | 
						|
			{
 | 
						|
				TRiga& riga_prime = (TRiga&)_righe_prime[data2row(anno,mese)];
 | 
						|
				n = numprime;
 | 
						|
				riga_prime.aggiorna_valore((int) colonna.integer(), n);
 | 
						|
			}
 | 
						|
		}                             
 | 
						|
		if (oldsez != "**" && oldsot != "**")
 | 
						|
			stampa_sezione(oldsez,oldsot);
 | 
						|
		delete curstat;
 | 
						|
		delete relstat;
 | 
						|
		printer().close();
 | 
						|
		return TRUE;
 | 
						|
	}
 | 
						|
	else
 | 
						|
		return FALSE;		
 | 
						|
}
 | 
						|
 | 
						|
void TRiepilogoDonazioni::azzera_righe()
 | 
						|
{
 | 
						|
	int anno = _dataini.year();
 | 
						|
	int meseini, mesefin;
 | 
						|
	while (anno<=_datafin.year())
 | 
						|
	{            
 | 
						|
		if (anno == _dataini.year())
 | 
						|
			meseini = _dataini.month();
 | 
						|
		else
 | 
						|
			meseini = 1;
 | 
						|
		if (anno == _datafin.year())
 | 
						|
			mesefin = _datafin.month();
 | 
						|
		else
 | 
						|
			mesefin = 12;						
 | 
						|
		for (int mese=meseini;mese<=mesefin;mese++)
 | 
						|
		{
 | 
						|
			TRiga& riga = (TRiga&)_righe[data2row(anno,mese)];
 | 
						|
			riga.azzera_valori();
 | 
						|
			if (_primedon)
 | 
						|
			{
 | 
						|
				TRiga& riga_prime = (TRiga&)_righe_prime[data2row(anno,mese)];
 | 
						|
				riga_prime.azzera_valori();
 | 
						|
			}
 | 
						|
		}			
 | 
						|
		anno++;
 | 
						|
	}		
 | 
						|
}
 | 
						|
 | 
						|
void TRiepilogoDonazioni::stampa_sezione(TString16 codsez, TString16 codsot)
 | 
						|
{ 
 | 
						|
	TPrintrow row;
 | 
						|
	TString256 rigastampa;
 | 
						|
	if (codsez == "ZZ" && codsot == "ZZ")
 | 
						|
	{
 | 
						|
		if (_sezionistampate != 1)
 | 
						|
		{
 | 
						|
			//rigastampa = "RIEPILOGO TOTALE PER TUTTE LE SEZIONI STAMPATE";
 | 
						|
			rigastampa = "";
 | 
						|
			rigastampa << "RIEPILOGO TOTALE SEZIONI DA " << _sezini << '/' << _sotini << " A " << _sezfin << '/' << _sotfin;
 | 
						|
		}	
 | 
						|
	}	
 | 
						|
	else
 | 
						|
	{
 | 
						|
		_sezionistampate++;
 | 
						|
		rigastampa = "Sezione: ";
 | 
						|
		rigastampa << codsez;
 | 
						|
		if (codsot.not_empty())
 | 
						|
		{
 | 
						|
			rigastampa << "/";
 | 
						|
			rigastampa << codsot;
 | 
						|
		}		
 | 
						|
		rigastampa << " ";
 | 
						|
		TLocalisamfile sezioni(LF_SEZIONI);
 | 
						|
		sezioni.setkey(1);
 | 
						|
		sezioni.zero();
 | 
						|
		sezioni.put(SEZ_CODSEZ,codsez);
 | 
						|
		sezioni.put(SEZ_CODSOT,codsot);	
 | 
						|
		if (sezioni.read() == NOERR)
 | 
						|
		{
 | 
						|
			TString80 den = sezioni.get(SEZ_DENSEZ);
 | 
						|
			rigastampa << den;
 | 
						|
			den = sezioni.get(SEZ_DENSOT);
 | 
						|
			if (den.not_empty())
 | 
						|
			{
 | 
						|
				rigastampa << "/";
 | 
						|
				rigastampa << den;
 | 
						|
			}
 | 
						|
		}
 | 
						|
	}		
 | 
						|
	if ((codsez == "ZZ" && codsot == "ZZ" && _sezionistampate != 1) || (codsez != "ZZ"))
 | 
						|
	{
 | 
						|
		rigastampa.center_just(80);
 | 
						|
		row.put(rigastampa);
 | 
						|
	  printer().setheaderline(1, row);
 | 
						|
	  
 | 
						|
	  TRiga rigatotali(0,0);
 | 
						|
		int anno = _dataini.year();
 | 
						|
		int meseini, mesefin;
 | 
						|
		real totalemese = ZERO;
 | 
						|
		TString16 valore;
 | 
						|
		while (anno<=_datafin.year())
 | 
						|
		{            
 | 
						|
			if (anno == _dataini.year())
 | 
						|
				meseini = _dataini.month();
 | 
						|
			else
 | 
						|
				meseini = 1;
 | 
						|
			if (anno == _datafin.year())
 | 
						|
				mesefin = _datafin.month();
 | 
						|
			else
 | 
						|
				mesefin = 12;						
 | 
						|
			for (int mese=meseini;mese<=mesefin;mese++)
 | 
						|
			{
 | 
						|
				TRiga& riga = (TRiga&)_righe[data2row(anno,mese)];
 | 
						|
				row.reset();
 | 
						|
				rigastampa = "";
 | 
						|
				rigastampa.format("%s %4d", (const char*)int2month(mese), anno); 
 | 
						|
				totalemese = ZERO;
 | 
						|
				int pos = 21;
 | 
						|
				for (int i=0;i<_colonne->items();i++)
 | 
						|
				{                      
 | 
						|
					rigatotali.aggiorna_valore(i,riga[i]);
 | 
						|
					totalemese+=riga[i];
 | 
						|
					valore = "";
 | 
						|
					valore.format("%8s",riga[i].string(8,0));
 | 
						|
					rigastampa.overwrite((const char*)valore, pos);
 | 
						|
					pos = pos+10;
 | 
						|
				}           
 | 
						|
				valore = "";
 | 
						|
				valore.format("%8s",totalemese.string(8,0));
 | 
						|
				rigastampa.overwrite((const char*)valore, pos+4);
 | 
						|
				row.put((const char*) rigastampa);
 | 
						|
				printer().print(row);			
 | 
						|
			}			
 | 
						|
			anno++;
 | 
						|
		}		
 | 
						|
		// stampa totali per sezione
 | 
						|
		rigastampa = "";
 | 
						|
		rigastampa.fill('-',80);
 | 
						|
		row.reset();
 | 
						|
		row.put(rigastampa);
 | 
						|
		printer().print(row);
 | 
						|
		row.reset();
 | 
						|
		rigastampa = "";
 | 
						|
		rigastampa = "Totale periodo";
 | 
						|
		totalemese = ZERO;
 | 
						|
		int pos = 21;
 | 
						|
		for (int i=0;i<_colonne->items();i++)
 | 
						|
		{                      
 | 
						|
			totalemese+=rigatotali[i];
 | 
						|
			valore = "";
 | 
						|
			valore.format("%8s",rigatotali[i].string(8,0));
 | 
						|
			rigastampa.overwrite((const char*)valore, pos);
 | 
						|
			pos = pos+10;
 | 
						|
		}           
 | 
						|
		valore = "";
 | 
						|
		valore.format("%8s",totalemese.string(8,0));
 | 
						|
		rigastampa.overwrite((const char*)valore, pos+4);
 | 
						|
		row.put((const char*) rigastampa);
 | 
						|
		printer().print(row);			
 | 
						|
		
 | 
						|
		if (_primedon)
 | 
						|
		{
 | 
						|
			rigatotali.azzera_valori();
 | 
						|
			row.reset();
 | 
						|
			printer().print(row);
 | 
						|
			printer().print(row);
 | 
						|
			printer().print(row);
 | 
						|
			printer().print(row);
 | 
						|
			rigastampa = "RIEPILOGO PRIME DONAZIONI";		
 | 
						|
			rigastampa.center_just(80);
 | 
						|
			row.reset();
 | 
						|
			row.put(rigastampa);
 | 
						|
			printer().print(row);
 | 
						|
			rigastampa = "";
 | 
						|
			rigastampa.fill('-',80);
 | 
						|
			row.reset();
 | 
						|
			row.put(rigastampa);
 | 
						|
			printer().print(row);
 | 
						|
			row.reset();
 | 
						|
			printer().print(row);
 | 
						|
			anno = _dataini.year();
 | 
						|
			while (anno<=_datafin.year())
 | 
						|
			{            
 | 
						|
				if (anno == _dataini.year())
 | 
						|
					meseini = _dataini.month();
 | 
						|
				else
 | 
						|
					meseini = 1;
 | 
						|
				if (anno == _datafin.year())
 | 
						|
					mesefin = _datafin.month();
 | 
						|
				else
 | 
						|
					mesefin = 12;						
 | 
						|
				for (int mese=meseini;mese<=mesefin;mese++)
 | 
						|
				{
 | 
						|
					TRiga& riga = (TRiga&)_righe_prime[data2row(anno,mese)];
 | 
						|
					row.reset();
 | 
						|
					rigastampa = "";
 | 
						|
					rigastampa.format("%s %4d", (const char*)int2month(mese), anno); 
 | 
						|
					totalemese = ZERO;
 | 
						|
					int pos = 21;
 | 
						|
					for (int i=0;i<_colonne->items();i++)
 | 
						|
					{                      
 | 
						|
						rigatotali.aggiorna_valore(i,riga[i]);
 | 
						|
						totalemese+=riga[i];
 | 
						|
						valore = "";
 | 
						|
						valore.format("%8s",riga[i].string(8,0));
 | 
						|
						rigastampa.overwrite((const char*)valore, pos);
 | 
						|
						pos = pos+10;
 | 
						|
					}           
 | 
						|
					valore = "";
 | 
						|
					valore.format("%8s",totalemese.string(8,0));
 | 
						|
					rigastampa.overwrite((const char*)valore, pos+4);
 | 
						|
					row.put((const char*) rigastampa);
 | 
						|
					printer().print(row);			
 | 
						|
				}			
 | 
						|
				anno++;
 | 
						|
			}		
 | 
						|
			// stampa totali per sezione
 | 
						|
			rigastampa = "";
 | 
						|
			rigastampa.fill('-',80);
 | 
						|
			row.reset();
 | 
						|
			row.put(rigastampa);
 | 
						|
			printer().print(row);
 | 
						|
			row.reset();
 | 
						|
			rigastampa = "";
 | 
						|
			rigastampa = "Totale periodo";
 | 
						|
			totalemese = ZERO;
 | 
						|
			int pos = 21;
 | 
						|
			for (int i=0;i<_colonne->items();i++)
 | 
						|
			{                      
 | 
						|
				totalemese+=rigatotali[i];
 | 
						|
				valore = "";
 | 
						|
				valore.format("%8s",rigatotali[i].string(8,0));
 | 
						|
				rigastampa.overwrite((const char*)valore, pos);
 | 
						|
				pos = pos+10;
 | 
						|
			}           
 | 
						|
			valore = "";
 | 
						|
			valore.format("%8s",totalemese.string(8,0));
 | 
						|
			rigastampa.overwrite((const char*)valore, pos+4);
 | 
						|
			row.put((const char*) rigastampa);
 | 
						|
			printer().print(row);			
 | 
						|
			
 | 
						|
			// riepilogo non prime donazione
 | 
						|
			rigatotali.azzera_valori();
 | 
						|
			row.reset();
 | 
						|
			printer().print(row);
 | 
						|
			printer().print(row);
 | 
						|
			printer().print(row);
 | 
						|
			printer().print(row);
 | 
						|
			rigastampa = "RIEPILOGO DONAZIONI NON PRIME";		
 | 
						|
			rigastampa.center_just(80);
 | 
						|
			row.reset();
 | 
						|
			row.put(rigastampa);
 | 
						|
			printer().print(row);
 | 
						|
			rigastampa = "";
 | 
						|
			rigastampa.fill('-',80);
 | 
						|
			row.reset();
 | 
						|
			row.put(rigastampa);
 | 
						|
			printer().print(row);
 | 
						|
			row.reset();
 | 
						|
			printer().print(row);
 | 
						|
			anno = _dataini.year();
 | 
						|
			while (anno<=_datafin.year())
 | 
						|
			{            
 | 
						|
				if (anno == _dataini.year())
 | 
						|
					meseini = _dataini.month();
 | 
						|
				else
 | 
						|
					meseini = 1;
 | 
						|
				if (anno == _datafin.year())
 | 
						|
					mesefin = _datafin.month();
 | 
						|
				else
 | 
						|
					mesefin = 12;						
 | 
						|
				for (int mese=meseini;mese<=mesefin;mese++)
 | 
						|
				{
 | 
						|
					TRiga& rigapri = (TRiga&)_righe_prime[data2row(anno,mese)];
 | 
						|
					TRiga& riga = (TRiga&)_righe[data2row(anno,mese)];
 | 
						|
					row.reset();
 | 
						|
					rigastampa = "";
 | 
						|
					rigastampa.format("%s %4d", (const char*)int2month(mese), anno); 
 | 
						|
					totalemese = ZERO;
 | 
						|
					int pos = 21;
 | 
						|
					for (int i=0;i<_colonne->items();i++)
 | 
						|
					{                      
 | 
						|
						real differenza = riga[i]-rigapri[i]; 
 | 
						|
						rigatotali.aggiorna_valore(i,differenza);
 | 
						|
						totalemese+=differenza;
 | 
						|
						valore = "";
 | 
						|
						valore.format("%8s",differenza.string(8,0));
 | 
						|
						rigastampa.overwrite((const char*)valore, pos);
 | 
						|
						pos = pos+10;
 | 
						|
					}           
 | 
						|
					valore = "";
 | 
						|
					valore.format("%8s",totalemese.string(8,0));
 | 
						|
					rigastampa.overwrite((const char*)valore, pos+4);
 | 
						|
					row.put((const char*) rigastampa);
 | 
						|
					printer().print(row);			
 | 
						|
				}			
 | 
						|
				anno++;
 | 
						|
			}		
 | 
						|
			// stampa totali per sezione
 | 
						|
			rigastampa = "";
 | 
						|
			rigastampa.fill('-',80);
 | 
						|
			row.reset();
 | 
						|
			row.put(rigastampa);
 | 
						|
			printer().print(row);
 | 
						|
			row.reset();
 | 
						|
			rigastampa = "";
 | 
						|
			rigastampa = "Totale periodo";
 | 
						|
			totalemese = ZERO;
 | 
						|
			pos = 21;
 | 
						|
			for (i=0;i<_colonne->items();i++)
 | 
						|
			{                      
 | 
						|
				totalemese+=rigatotali[i];
 | 
						|
				valore = "";
 | 
						|
				valore.format("%8s",rigatotali[i].string(8,0));
 | 
						|
				rigastampa.overwrite((const char*)valore, pos);
 | 
						|
				pos = pos+10;
 | 
						|
			}           
 | 
						|
			valore = "";
 | 
						|
			valore.format("%8s",totalemese.string(8,0));
 | 
						|
			rigastampa.overwrite((const char*)valore, pos+4);
 | 
						|
			row.put((const char*) rigastampa);
 | 
						|
			printer().print(row);			
 | 
						|
		}
 | 
						|
		printer().formfeed();
 | 
						|
	}	
 | 
						|
}
 | 
						|
 | 
						|
bool TRiepilogoDonazioni::riepilogo()
 | 
						|
{            
 | 
						|
	if (crea_colonne() && crea_righe())
 | 
						|
	{   
 | 
						|
		// cancello i risultati della elaborazione precedente
 | 
						|
		TLocalisamfile stat(LF_ATSTATD);
 | 
						|
		for (stat.first(); !stat.eof(); stat.next())
 | 
						|
			stat.remove();
 | 
						|
		stat.setkey(2);			
 | 
						|
		// filtro per data
 | 
						|
		TRectype da(LF_DONAZ);
 | 
						|
  	TRectype a (LF_DONAZ);
 | 
						|
  	if (_dataini.ok())
 | 
						|
			da.put(DON_DATADON, _dataini);
 | 
						|
  	if (_datafin.ok())
 | 
						|
			a.put(DON_DATADON, _datafin);
 | 
						|
		_cur = new TCursor(_rel, "", 2, &da, &a);  
 | 
						|
		TString256 filtro = "";
 | 
						|
 | 
						|
		// filtro per sezione/sottogruppo
 | 
						|
	 	if (_sezini.not_empty())
 | 
						|
	 	{
 | 
						|
	 		if (_sotini.not_empty())
 | 
						|
	 		{                    
 | 
						|
	 			filtro << "(";
 | 
						|
	 			filtro << format("(92->CODSEZ > \"%s\")",(const char*)_sezini);
 | 
						|
	 			filtro << " || ";
 | 
						|
	 			filtro << "(" << format("(92->CODSEZ == \"%s\")",(const char*)_sezini);
 | 
						|
	 			filtro << " && ";
 | 
						|
	 			filtro << format("(92->CODSOT >= \"%s\")",(const char*)_sotini);
 | 
						|
	 			filtro << ")";
 | 
						|
	 			filtro << ")";
 | 
						|
	 		}
 | 
						|
	 		else
 | 
						|
		 			filtro << format("(92->CODSEZ >= \"%s\")",(const char*)_sezini);
 | 
						|
	 	}
 | 
						|
	 	if (_sezfin.not_empty())
 | 
						|
	 	{
 | 
						|
 			if (filtro.not_empty())
 | 
						|
 				filtro << " && "; 
 | 
						|
	 	
 | 
						|
	 		if (_sotfin.not_empty())
 | 
						|
	 		{          
 | 
						|
	 			filtro << "(";
 | 
						|
	 			filtro << format("(92->CODSEZ < \"%s\")",(const char*)_sezfin);
 | 
						|
	 			filtro << " || ";
 | 
						|
	 			filtro << "(" << format("(92->CODSEZ == \"%s\")",(const char*)_sezfin);
 | 
						|
	 			filtro << " && ";
 | 
						|
	 			filtro << format("(92->CODSOT <= \"%s\")",(const char*)_sotfin);
 | 
						|
	 			filtro << ")";
 | 
						|
	 			filtro << ")";
 | 
						|
	 		}
 | 
						|
	 		else
 | 
						|
	 			filtro << format("(92->CODSEZ <= \"%s\")",(const char*)_sezfin);
 | 
						|
		}
 | 
						|
		_cur->setfilter((const char*) filtro, TRUE);
 | 
						|
		TString16 codsez, codsot, tipodon;
 | 
						|
		TDate datadon;
 | 
						|
		int anno, mese;
 | 
						|
		long numero;  
 | 
						|
		bool primadon;
 | 
						|
		TRectype& recdon = _cur->curr();
 | 
						|
		TRectype& recsog = _cur->curr(LF_SOGGETTI);
 | 
						|
  	long last = _cur->items();   
 | 
						|
  	TProgind prg (last, "Elaborazione in corso... Prego attendere", FALSE, TRUE, 30);
 | 
						|
  	for ( *_cur=0; _cur->pos() < last; ++(*_cur) )
 | 
						|
  	{
 | 
						|
    	prg.addstatus(1);
 | 
						|
			codsez = recdon.get(DON_CODSEZ);
 | 
						|
			codsot = recdon.get(DON_CODSOT);
 | 
						|
			if (codsez.empty())
 | 
						|
			{
 | 
						|
				codsez = recsog.get(SOG_CODSEZ);
 | 
						|
				codsot = recsog.get(SOG_CODSOT);
 | 
						|
			}
 | 
						|
			datadon = recdon.get_date(DON_DATADON);
 | 
						|
			tipodon = recdon.get(DON_TIPODON);
 | 
						|
			primadon = recdon.get_bool(DON_PRIMADON);
 | 
						|
			anno = datadon.year();
 | 
						|
			mese = datadon.month();
 | 
						|
			if (!_solotot)
 | 
						|
			{
 | 
						|
				stat.zero();
 | 
						|
				stat.put(ATS_CODSEZ, codsez);  	 
 | 
						|
				stat.put(ATS_CODSOT, codsot);  	 
 | 
						|
				stat.put(ATS_ANNO, anno);  	 
 | 
						|
				stat.put(ATS_MESE, mese);  	 
 | 
						|
				stat.put(ATS_TIPODON, tipodon);  	 
 | 
						|
				if (stat.read() == NOERR)
 | 
						|
				{
 | 
						|
					numero = stat.get_long(ATS_NUMERO);
 | 
						|
					numero++;
 | 
						|
					stat.put(ATS_NUMERO, numero);
 | 
						|
					if (_primedon && primadon)
 | 
						|
					{
 | 
						|
						numero = stat.get_long(ATS_NUMPRIME);
 | 
						|
						numero++;
 | 
						|
						stat.put(ATS_NUMPRIME, numero);
 | 
						|
					}
 | 
						|
					stat.rewrite();			
 | 
						|
				}			
 | 
						|
				else
 | 
						|
				{
 | 
						|
					stat.zero();
 | 
						|
					stat.put(ATS_CODSEZ, codsez);  	 
 | 
						|
					stat.put(ATS_CODSOT, codsot);  	 
 | 
						|
					stat.put(ATS_ANNO, anno);  	 
 | 
						|
					stat.put(ATS_MESE, mese);  	 
 | 
						|
					stat.put(ATS_TIPODON, tipodon);  	 
 | 
						|
					numero = 1;
 | 
						|
					stat.put(ATS_NUMERO, numero);
 | 
						|
					if (_primedon && primadon)
 | 
						|
						stat.put(ATS_NUMPRIME, numero);
 | 
						|
					stat.write();
 | 
						|
				}
 | 
						|
			}	
 | 
						|
			stat.zero();
 | 
						|
			stat.put(ATS_CODSEZ, "ZZ");  	 
 | 
						|
			stat.put(ATS_CODSOT, "ZZ");  	 
 | 
						|
			stat.put(ATS_ANNO, anno);  	 
 | 
						|
			stat.put(ATS_MESE, mese);  	 
 | 
						|
			stat.put(ATS_TIPODON, tipodon);  	 
 | 
						|
			if (stat.read() == NOERR)
 | 
						|
			{
 | 
						|
				numero = stat.get_long(ATS_NUMERO);
 | 
						|
				numero++;
 | 
						|
				stat.put(ATS_NUMERO, numero);
 | 
						|
				if (_primedon && primadon)
 | 
						|
				{
 | 
						|
					numero = stat.get_long(ATS_NUMPRIME);
 | 
						|
					numero++;
 | 
						|
					stat.put(ATS_NUMPRIME, numero);
 | 
						|
				}
 | 
						|
				stat.rewrite();			
 | 
						|
			}			
 | 
						|
			else
 | 
						|
			{
 | 
						|
				stat.zero();
 | 
						|
				stat.put(ATS_CODSEZ, "ZZ");  	 
 | 
						|
				stat.put(ATS_CODSOT, "ZZ");  	 
 | 
						|
				stat.put(ATS_ANNO, anno);  	 
 | 
						|
				stat.put(ATS_MESE, mese);  	 
 | 
						|
				stat.put(ATS_TIPODON, tipodon);  	 
 | 
						|
				numero = 1;
 | 
						|
				stat.put(ATS_NUMERO, numero);
 | 
						|
				if (_primedon && primadon)
 | 
						|
					stat.put(ATS_NUMPRIME, numero);
 | 
						|
				stat.write();
 | 
						|
			}
 | 
						|
		}	
 | 
						|
		return (stat.eod() > 0);
 | 
						|
	}		
 | 
						|
	else
 | 
						|
		return FALSE;	
 | 
						|
}         
 | 
						|
 | 
						|
int at3400(int argc, char* argv[])
 | 
						|
{
 | 
						|
	TRiepilogoDonazioni a;
 | 
						|
	a.run(argc, argv, "Riepilogo mensile donazioni");
 | 
						|
	return 0;
 | 
						|
} |