290 lines
		
	
	
		
			7.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			290 lines
		
	
	
		
			7.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <mask.h>
 | 
						|
#include <printapp.h>
 | 
						|
#include <utility.h>
 | 
						|
#include <lffiles.h>
 | 
						|
 | 
						|
#include "at0.h"
 | 
						|
 | 
						|
// nomi campi maschera
 | 
						|
#include "at0600a.h"
 | 
						|
          
 | 
						|
// nomi dei campi
 | 
						|
#include "soggetti.h"
 | 
						|
#include "donaz.h"
 | 
						|
#include "contsan.h"
 | 
						|
#include "benem.h"
 | 
						|
#include "storico.h"
 | 
						|
#include "sezioni.h"
 | 
						|
 | 
						|
#define ALIAS_CTD			700		// categoria donatori
 | 
						|
 | 
						|
class TChiusuraPeriodica : public TPrintapp
 | 
						|
{
 | 
						|
  static bool filter_func_chiusura(const TRelation* rel);
 | 
						|
 | 
						|
	TMask*						_msk;
 | 
						|
	TRelation*   			_rel;
 | 
						|
	int 							_cur;	
 | 
						|
	TDate							_data_chiusura;
 | 
						|
  TParagraph_string	_operazione;
 | 
						|
  bool							_definitiva;
 | 
						|
  TString16				  _codsez, _codsot;
 | 
						|
	
 | 
						|
protected:
 | 
						|
	virtual bool user_create();
 | 
						|
	virtual bool user_destroy();
 | 
						|
	virtual bool set_print(int m);
 | 
						|
	virtual void set_page(int file, int cnt);
 | 
						|
	virtual bool preprocess_page(int file, int counter);
 | 
						|
	virtual TMask& get_mask() { return *_msk; }
 | 
						|
	
 | 
						|
public:
 | 
						|
  void filtra_sezioni();
 | 
						|
  void header_sezione(const TString16 codsez, const TString16 codsot);
 | 
						|
  void crea_intestazione();
 | 
						|
	TChiusuraPeriodica() : _data_chiusura(TODAY), _operazione("",30) {}
 | 
						|
};
 | 
						|
 | 
						|
HIDDEN inline TChiusuraPeriodica& app() { return (TChiusuraPeriodica&) main_app(); }
 | 
						|
 | 
						|
void TChiusuraPeriodica::filtra_sezioni()
 | 
						|
{
 | 
						|
 	const TString16 sezini = _msk->get(F_SEZINI);
 | 
						|
 	const TString16 sotini = _msk->get(F_SOTINI);
 | 
						|
 	const TString16 sezfin = _msk->get(F_SEZFIN);
 | 
						|
 	const TString16 sotfin = _msk->get(F_SOTFIN);
 | 
						|
  TRectype da(LF_SOGGETTI);
 | 
						|
  TRectype a(LF_SOGGETTI);   
 | 
						|
  if (sezini.not_empty())
 | 
						|
		da.put(SOG_CODSEZ, sezini);
 | 
						|
  if (sotini.not_empty())
 | 
						|
		da.put(SOG_CODSOT, sotini);
 | 
						|
  if (sezfin.not_empty())
 | 
						|
		a.put(SOG_CODSEZ, sezfin);
 | 
						|
  if (sotfin.not_empty())
 | 
						|
		a.put(SOG_CODSOT, sotfin);
 | 
						|
	current_cursor()->setregion(da, a);
 | 
						|
}	
 | 
						|
 | 
						|
 | 
						|
bool TChiusuraPeriodica::preprocess_page(int file, int counter)
 | 
						|
{     
 | 
						|
	_operazione = "Non deve essere filtrato";	
 | 
						|
	TRectype& recsez = current_cursor()->curr(LF_SEZIONI);
 | 
						|
	TRectype& recsog = current_cursor()->curr();
 | 
						|
	// salto pagina se cambio sezione
 | 
						|
	const TString16 codsez = recsog.get(SOG_CODSEZ);		
 | 
						|
	const TString16 codsot = recsog.get(SOG_CODSOT);		
 | 
						|
	if ((_codsez!=codsez)||(_codsot!=codsot))
 | 
						|
	{
 | 
						|
		if (_codsez != "**")
 | 
						|
			printer().formfeed();
 | 
						|
		_codsez = codsez;
 | 
						|
		_codsot = codsot;
 | 
						|
		header_sezione(codsez, codsot);
 | 
						|
	}
 | 
						|
	TLocalisamfile& filesog = current_cursor()->file();
 | 
						|
	const TString16 cat_estinti 	 = recsez.get(SEZ_CATESTI);
 | 
						|
	const TString16 cat_cancellati = recsez.get(SEZ_CATCANC);
 | 
						|
	const TString16 cat_emeriti 	 = recsez.get(SEZ_CATEMER);
 | 
						|
	const int intesti = recsez.get_int(SEZ_INTESTI);
 | 
						|
	const int donemer = recsez.get_int(SEZ_DONEMER);
 | 
						|
	if ((cat_estinti.not_empty() && intesti!=0) || cat_cancellati.not_empty() || (cat_emeriti.not_empty() && donemer!=0))	
 | 
						|
	{	
 | 
						|
		const TString16 catsog = recsog.get(SOG_CATDON);
 | 
						|
		if (catsog == cat_cancellati && cat_cancellati.not_empty())
 | 
						|
		{
 | 
						|
			_operazione = "Cancellato";
 | 
						|
			if (_definitiva)	
 | 
						|
				filesog.remove();
 | 
						|
		}
 | 
						|
		else			                  
 | 
						|
		{
 | 
						|
			if ((cat_estinti.not_empty() && intesti!=0) || (cat_emeriti.not_empty() && donemer!=0))			
 | 
						|
			{			
 | 
						|
				bool dimesso = current_cursor()->curr(-ALIAS_CTD).get_bool("B0");
 | 
						|
				if (!dimesso)
 | 
						|
				{	
 | 
						|
					TDate dataultdon = recsog.get(SOG_DATAULTDON);
 | 
						|
					if (dataultdon.ok())
 | 
						|
					{
 | 
						|
						dataultdon.addyear(intesti);
 | 
						|
						if (dataultdon < app()._data_chiusura)
 | 
						|
						{
 | 
						|
							const int totdon = recsog.get_int(SOG_TOTDON);
 | 
						|
							if (cat_emeriti.not_empty() && donemer!=0 && totdon>donemer)
 | 
						|
							{                     
 | 
						|
								_operazione = "da";
 | 
						|
								_operazione << " ";
 | 
						|
								_operazione << catsog;
 | 
						|
								_operazione << " a ";
 | 
						|
								_operazione << cat_emeriti;
 | 
						|
								if (_definitiva)
 | 
						|
								{
 | 
						|
									recsog.put(SOG_CATDON,cat_emeriti);
 | 
						|
									recsog.put(SOG_DATADIM, _data_chiusura);
 | 
						|
									filesog.rewrite();
 | 
						|
								}				
 | 
						|
							}
 | 
						|
							else
 | 
						|
							{
 | 
						|
								if (cat_estinti.not_empty())
 | 
						|
								{
 | 
						|
									_operazione = "da";
 | 
						|
									_operazione << " ";
 | 
						|
									_operazione << catsog;
 | 
						|
									_operazione << " a ";
 | 
						|
									_operazione << cat_estinti;
 | 
						|
									if (_definitiva)
 | 
						|
									{
 | 
						|
										recsog.put(SOG_CATDON,cat_estinti);
 | 
						|
										recsog.put(SOG_DATADIM, _data_chiusura);
 | 
						|
										filesog.rewrite();
 | 
						|
									}					
 | 
						|
								}
 | 
						|
							}
 | 
						|
						}
 | 
						|
					}				
 | 
						|
				}		
 | 
						|
			}				
 | 
						|
		}			
 | 
						|
	}				 
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
void TChiusuraPeriodica::header_sezione(const TString16 codsez, const TString16 codsot)
 | 
						|
{
 | 
						|
	const TString80 densez = current_cursor()->curr(LF_SEZIONI).get(SEZ_DENSEZ);
 | 
						|
	const TString80 densot = current_cursor()->curr(LF_SEZIONI).get(SEZ_DENSOT);
 | 
						|
	TString intestazione(132);
 | 
						|
	intestazione = "Sezione: ";
 | 
						|
	intestazione << codsez;
 | 
						|
	intestazione << "/";
 | 
						|
	intestazione << codsot;
 | 
						|
	intestazione << " ";
 | 
						|
	intestazione << densez;
 | 
						|
	if ((densot.ok())&& (densot.not_empty()))
 | 
						|
	{
 | 
						|
		intestazione << "/";
 | 
						|
		intestazione << densot;
 | 
						|
	}		
 | 
						|
	intestazione.center_just();
 | 
						|
	set_header(1,"@0g%s", (const char*) intestazione);
 | 
						|
	return;
 | 
						|
}
 | 
						|
 | 
						|
void TChiusuraPeriodica::set_page(int file, int cnt)
 | 
						|
{ 
 | 
						|
	set_row(1,"@0g@pn", FLD(LF_SOGGETTI,SOG_CODICE,"########"));
 | 
						|
	set_row(1,"@9g@S", FLD(LF_SOGGETTI,SOG_CATDON));
 | 
						|
	set_row(1,"@12g@S", FLD(LF_SOGGETTI,SOG_COGNOME));
 | 
						|
	set_row(1,"@38g@S", FLD(LF_SOGGETTI,SOG_NOME));
 | 
						|
	set_row(1,"@65g@ld", FLD(LF_SOGGETTI,SOG_DATAULTDON));
 | 
						|
	set_row(1,"@76g@n", FLD(LF_SOGGETTI,SOG_TOTDON));
 | 
						|
	set_row(1,"@80g#a", &_operazione);
 | 
						|
}
 | 
						|
 | 
						|
bool TChiusuraPeriodica::filter_func_chiusura(const TRelation* rel)
 | 
						|
{   
 | 
						|
	bool filtrato = FALSE;
 | 
						|
 | 
						|
	TRectype& recsez = rel->lfile(LF_SEZIONI).curr();
 | 
						|
	TRectype& recsog = rel->lfile().curr();
 | 
						|
	const TString16 cat_estinti 	 = recsez.get(SEZ_CATESTI);
 | 
						|
	const TString16 cat_cancellati = recsez.get(SEZ_CATCANC);
 | 
						|
	const TString16 cat_emeriti 	 = recsez.get(SEZ_CATEMER);
 | 
						|
	const int intesti = recsez.get_int(SEZ_INTESTI);
 | 
						|
	const int donemer = recsez.get_int(SEZ_DONEMER);
 | 
						|
	if ((cat_estinti.not_empty() && intesti!=0) || cat_cancellati.not_empty() || (cat_emeriti.not_empty() && donemer!=0))	
 | 
						|
	{	
 | 
						|
		const TString16 catsog = recsog.get(SOG_CATDON);
 | 
						|
		if (catsog == cat_cancellati && cat_cancellati.not_empty())
 | 
						|
			filtrato = TRUE;	// da cancellare
 | 
						|
		else			                  
 | 
						|
		{
 | 
						|
			if ((cat_estinti.not_empty() && intesti!=0) || (cat_emeriti.not_empty() && donemer!=0))			
 | 
						|
			{			
 | 
						|
				const bool dimesso = rel->lfile(-ALIAS_CTD).get_bool("B0");
 | 
						|
				if (!dimesso)
 | 
						|
				{	
 | 
						|
					TDate dataultdon = recsog.get(SOG_DATAULTDON);
 | 
						|
					if (dataultdon.ok())
 | 
						|
					{
 | 
						|
						dataultdon.addyear(intesti);
 | 
						|
						filtrato = (dataultdon < app()._data_chiusura);
 | 
						|
					}				
 | 
						|
				}		
 | 
						|
			}				
 | 
						|
		}			
 | 
						|
	}				 
 | 
						|
	return filtrato;
 | 
						|
}
 | 
						|
 | 
						|
bool TChiusuraPeriodica::set_print(int)
 | 
						|
{
 | 
						|
  KEY tasto;
 | 
						|
  tasto = _msk->run();
 | 
						|
	if (tasto == K_ENTER)
 | 
						|
	{ 
 | 
						|
  	_codsez = "**";
 | 
						|
  	_codsez = "**";
 | 
						|
		_definitiva = _msk->get_bool(F_DEFINITIVA);
 | 
						|
		_data_chiusura = _msk->get(F_DATA);
 | 
						|
    reset_files(); 
 | 
						|
    add_file(LF_SOGGETTI);
 | 
						|
		filtra_sezioni();
 | 
						|
		current_cursor()->set_filterfunction(filter_func_chiusura,TRUE);
 | 
						|
		reset_print();		
 | 
						|
    crea_intestazione();
 | 
						|
    return TRUE;
 | 
						|
  }
 | 
						|
  else
 | 
						|
    return FALSE;
 | 
						|
}
 | 
						|
 | 
						|
void TChiusuraPeriodica::crea_intestazione()
 | 
						|
{
 | 
						|
	reset_header();
 | 
						|
	TString sep(132);
 | 
						|
	sep = "";
 | 
						|
	if (_definitiva)  
 | 
						|
		sep << "CHIUSURA - DEFINITIVA - ALLA DATA ";
 | 
						|
	else		
 | 
						|
		sep << "CHIUSURA - PROVVISORIA - ALLA DATA ";
 | 
						|
	sep << _data_chiusura.string();		
 | 
						|
	sep.center_just();
 | 
						|
	set_header(2, "@0g%s", (const char*) sep);
 | 
						|
 	TDate data_stampa(TODAY);
 | 
						|
 	set_header(2,"@0g%10s", (const char*) data_stampa.string());
 | 
						|
	sep = "";
 | 
						|
	sep << "Pag. @#";
 | 
						|
	set_header(2, "@120g%s", (const char*) sep);  
 | 
						|
	sep = "";
 | 
						|
	sep.fill('-');
 | 
						|
	set_header(3, (const char *) sep);
 | 
						|
}
 | 
						|
 | 
						|
bool TChiusuraPeriodica::user_create()
 | 
						|
{
 | 
						|
	_msk = new TMask("at0600a");
 | 
						|
	_rel = new TRelation(LF_SOGGETTI);
 | 
						|
	_rel->add(LF_SEZIONI,"CODSEZ==CODSEZ|CODSOT==CODSOT");
 | 
						|
  _rel->add("CTD", "CODTAB==CATDON",1,0,ALIAS_CTD);
 | 
						|
	//cursore ordinamento per sezione+sottogruppo+cognome+nome
 | 
						|
  _cur = add_cursor(new TCursor(_rel, "", 3));
 | 
						|
	return TRUE;
 | 
						|
}	
 | 
						|
 | 
						|
bool TChiusuraPeriodica::user_destroy()	
 | 
						|
{
 | 
						|
	delete _rel;
 | 
						|
	delete _msk;
 | 
						|
	return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
int at0600(int argc, char* argv[])
 | 
						|
{
 | 
						|
	TChiusuraPeriodica a;
 | 
						|
	a.run(argc, argv, "Chiusura periodica");
 | 
						|
	return 0;
 | 
						|
} |