219 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			219 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <mask.h>
 | 
						|
#include <printapp.h>
 | 
						|
#include <utility.h>
 | 
						|
 | 
						|
#include "at1.h"
 | 
						|
#include "lf.h"
 | 
						|
 | 
						|
// nomi campi maschera
 | 
						|
#include "at1100a.h"
 | 
						|
          
 | 
						|
// nomi dei campi
 | 
						|
#include "soggetti.h"
 | 
						|
#include "donaz.h"
 | 
						|
#include "contsan.h"
 | 
						|
#include "benem.h"
 | 
						|
#include "storico.h"
 | 
						|
#include "sezioni.h"
 | 
						|
 | 
						|
class TChiusura_app : public TPrintapp
 | 
						|
{
 | 
						|
  static bool filter_func_chiusura(const TRelation* rel);
 | 
						|
 | 
						|
	TMask*						_msk;
 | 
						|
	TRelation*   			_rel;
 | 
						|
 | 
						|
	int 							_cur;	
 | 
						|
	TDate							_data_chiusura;
 | 
						|
  TParagraph_string	_operazione;
 | 
						|
	
 | 
						|
	
 | 
						|
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 crea_intestazione();
 | 
						|
	TChiusura_app() : _data_chiusura(TODAY), _operazione("",30) {}
 | 
						|
};
 | 
						|
 | 
						|
HIDDEN inline TChiusura_app& app() { return (TChiusura_app&) main_app(); }
 | 
						|
 | 
						|
void TChiusura_app::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 TChiusura_app::preprocess_page(int file, int counter)
 | 
						|
{
 | 
						|
	_operazione = "Nulla";	
 | 
						|
	
 | 
						|
	TRectype& recsez = current_cursor()->curr(LF_SEZIONI);
 | 
						|
	TRectype& recsog = current_cursor()->curr();
 | 
						|
	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);
 | 
						|
	
 | 
						|
	const TString16 catsog = recsog.get(SOG_CATDON);
 | 
						|
	if (catsog==cat_estinti || catsog==cat_cancellati)
 | 
						|
	{
 | 
						|
		const int totdon = recsog.get_int(SOG_TOTDON);
 | 
						|
		if (totdon >= donemer && donemer != 0)
 | 
						|
		{
 | 
						|
			_operazione = "Passaggio a emeriti";
 | 
						|
			recsog.put(SOG_CATDON,cat_emeriti);
 | 
						|
			filesog.rewrite();
 | 
						|
		}			
 | 
						|
		else
 | 
						|
			_operazione = "Cancellato";
 | 
						|
			filesog.remove();
 | 
						|
	}
 | 
						|
	else
 | 
						|
	{                                   
 | 
						|
		TDate dataultdon = recsog.get(SOG_DATAULTDON);
 | 
						|
		if (dataultdon.ok())
 | 
						|
		{
 | 
						|
			dataultdon.addyear(intesti);
 | 
						|
			if (dataultdon < _data_chiusura)
 | 
						|
			{
 | 
						|
				_operazione = "Passaggio a estinti";
 | 
						|
				recsog.put(SOG_CATDON,cat_estinti);
 | 
						|
				filesog.rewrite();
 | 
						|
			}	
 | 
						|
			else
 | 
						|
				_operazione = "Non doveva essere filtrato: data ancora valida";
 | 
						|
		}
 | 
						|
		else
 | 
						|
			_operazione = "Non doveva essere filtrato: data vuota";
 | 
						|
	}
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void TChiusura_app::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#a", &_operazione);
 | 
						|
}
 | 
						|
 | 
						|
bool TChiusura_app::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 TString16 catsog = recsog.get(SOG_CATDON);
 | 
						|
	filtrato = (catsog == cat_estinti || catsog == cat_cancellati);
 | 
						|
	if (!filtrato && catsog != cat_emeriti)
 | 
						|
	{                                   
 | 
						|
		TDate dataultdon = recsog.get(SOG_DATAULTDON);
 | 
						|
		if (dataultdon.ok())
 | 
						|
		{
 | 
						|
			dataultdon.addyear(intesti);
 | 
						|
			filtrato = (dataultdon < app()._data_chiusura);
 | 
						|
		}				
 | 
						|
	}
 | 
						|
	return filtrato;
 | 
						|
}
 | 
						|
 | 
						|
bool TChiusura_app::set_print(int)
 | 
						|
{
 | 
						|
  KEY tasto;
 | 
						|
  tasto = _msk->run();
 | 
						|
	if (tasto == K_ENTER)
 | 
						|
	{  	
 | 
						|
		_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 TChiusura_app::crea_intestazione()
 | 
						|
{
 | 
						|
	reset_header();
 | 
						|
	
 | 
						|
	TString sep(132);
 | 
						|
	TString16 data_stampa;
 | 
						|
  
 | 
						|
	sep.fill('-');
 | 
						|
	set_header(1, (const char *) sep);
 | 
						|
	sep = "";
 | 
						|
	sep << "Pag. @#";
 | 
						|
	sep.right_just(132); 
 | 
						|
	set_header(2,(const char*) sep);  
 | 
						|
  
 | 
						|
	set_header(2,"@0gCHIUSURA PERIODICA ALLA DATA");
 | 
						|
	data_stampa = _data_chiusura.string();
 | 
						|
	set_header(2,"@30g%10s", (const char*) data_stampa);
 | 
						|
  
 | 
						|
	sep = "";
 | 
						|
	sep.fill('-');
 | 
						|
	set_header(3, (const char *) sep);
 | 
						|
}
 | 
						|
 | 
						|
bool TChiusura_app::user_create()
 | 
						|
{
 | 
						|
	_msk = new TMask("at1100a");
 | 
						|
	_rel = new TRelation(LF_SOGGETTI);
 | 
						|
	_rel->add(LF_SEZIONI,"CODSEZ==CODSEZ|CODSOT==CODSOT");
 | 
						|
 | 
						|
  _cur = add_cursor(new TCursor(_rel, "", 3));	//cursore ordinamento per sezione+sottogruppo+codice
 | 
						|
	return TRUE;
 | 
						|
}	
 | 
						|
 | 
						|
bool TChiusura_app::user_destroy()	
 | 
						|
{
 | 
						|
	delete _rel;
 | 
						|
	delete _msk;
 | 
						|
	return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
int at1100(int argc, char* argv[])
 | 
						|
{
 | 
						|
	TChiusura_app a;
 | 
						|
	a.run(argc, argv, "Chiusura periodica");
 | 
						|
	return 0;
 | 
						|
} |