Files correlati :ca0.exe,ca0900a.msk,ca3.exe,camenu.men Ricompilazione Demo : [ ] Commento : programma anti-angcas funzionante per il bilancio di commessa; da installare e provare a dinamica git-svn-id: svn://10.65.10.50/branches/R_10_00@21381 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			420 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			420 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <applicat.h>
 | ||
| #include <defmask.h>
 | ||
| 
 | ||
| #include "ca3.h"
 | ||
| #include "ca3883.h"
 | ||
| #include "ca3883a.h"
 | ||
| #include "calib01.h"
 | ||
| #include "calib02.h"
 | ||
| #include "pconana.h"
 | ||
| #include "cdc.h"
 | ||
| #include "fasi.h"
 | ||
| 
 | ||
| 
 | ||
| ////////////////////////////////////////////////////////
 | ||
| //	MASCHERA
 | ||
| ////////////////////////////////////////////////////////
 | ||
| class TPrint_bilancio_cms_mask : public TAnal_report_mask
 | ||
| {
 | ||
| protected:
 | ||
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | ||
|   bool test_compatible_report();
 | ||
| 	
 | ||
| public:
 | ||
|   const TString& get_report_class() const; 
 | ||
|   TPrint_bilancio_cms_mask();
 | ||
|   virtual ~TPrint_bilancio_cms_mask() {}
 | ||
| };
 | ||
| 
 | ||
| const TString& TPrint_bilancio_cms_mask::get_report_class() const
 | ||
| {
 | ||
|   TString& classe = get_tmp_string();
 | ||
|   const int tipostampa = get_int(F_TIPOSTAMPA);
 | ||
|   switch (tipostampa)
 | ||
|   {
 | ||
|   case  4: classe = "ca3800b"; break;
 | ||
|   case  8: classe = "ca3800c"; break;
 | ||
|   default: classe = "ca3800a"; break;
 | ||
|   }   
 | ||
|   return classe;
 | ||
| }
 | ||
| 
 | ||
| bool TPrint_bilancio_cms_mask::test_compatible_report()
 | ||
| {
 | ||
| 	const TString& cls = 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 == cls;
 | ||
|     }
 | ||
|   }
 | ||
|   if (!ok)
 | ||
|   {
 | ||
|     set(F_REPORT, cls);
 | ||
| 		TFilename path = cls;
 | ||
|     path.ext("rep");
 | ||
|     ok = path.custom_path();
 | ||
|   }
 | ||
|   return ok;
 | ||
| }
 | ||
| 
 | ||
| bool TPrint_bilancio_cms_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | ||
| {
 | ||
|   switch (o.dlg())
 | ||
|   {
 | ||
|   case DLG_PRINT:
 | ||
|     if (e == fe_button)
 | ||
|     {
 | ||
|       main_app().print();
 | ||
|       return false;
 | ||
|     }
 | ||
|     break;
 | ||
|   case DLG_PREVIEW:
 | ||
|     if (e == fe_button)
 | ||
|     {
 | ||
|       main_app().preview();
 | ||
|       return false;
 | ||
|     }
 | ||
|     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_ESERCIZIO:
 | ||
|   case F_FINE_ES:
 | ||
|     if (e == fe_init || e == fe_modify || e == fe_close)
 | ||
|     {
 | ||
|       const int anno = get_int(F_ESERCIZIO);
 | ||
|       if (anno > 0)
 | ||
|       {
 | ||
|         TEsercizi_contabili esc;
 | ||
| 	      TDate datainiesc, datafinesc;
 | ||
| 	      esc.code2range(anno, datainiesc, datafinesc);
 | ||
|         const TDate datafine = get(F_FINE_ES);
 | ||
|         if (datafine < datainiesc || datafine > datafinesc)
 | ||
|           set(F_FINE_ES, datafinesc);
 | ||
|         //deve comunque scrivere l'inizio dell'esercizio che ha scelto (anche se esercizio non esiste!)
 | ||
|         set(F_INIZIO_ES, datainiesc);
 | ||
|       }
 | ||
|     }
 | ||
|     break;
 | ||
|   default: 
 | ||
| 		break;
 | ||
|   }
 | ||
| 	return TAnal_report_mask::on_field_event(o, e, jolly);
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| TPrint_bilancio_cms_mask::TPrint_bilancio_cms_mask()
 | ||
| 												:TAnal_report_mask("ca3800")
 | ||
| {
 | ||
| 	TConfig& cfg = ca_config();
 | ||
| 	const bool use_pdcc = cfg.get_bool("UsePdcc");
 | ||
| 
 | ||
|   const TMultilevel_code_info& pconana_info = ca_multilevel_code_info(LF_PCONANA);
 | ||
|   const int pconana_levels = pconana_info.levels();
 | ||
| 
 | ||
| 	int prefix = cfg.get_int("PdcPrefix");
 | ||
|   if (prefix >= pconana_levels)
 | ||
|     prefix = pconana_levels - 1;
 | ||
| 
 | ||
| 	TToken_string codes, descr;
 | ||
| 	for (int k = prefix; k < pconana_levels; k++)
 | ||
| 	{
 | ||
| 		codes.add(k);
 | ||
| 		descr.add(pconana_info.prompt(k));
 | ||
| 	}
 | ||
| 
 | ||
| 	TList_field& depth_list = lfield(F_DEPTH); 
 | ||
| 	depth_list.replace_items(codes, descr);
 | ||
|   
 | ||
| 	//Controllo se voglio (e posso) usare il conto analitico come prefisso di quello contabile
 | ||
|   if (use_pdcc && prefix > 0)
 | ||
|   {
 | ||
|     if (pconana_levels >= 2 && prefix < pconana_levels && esistono_riclassificazioni())
 | ||
|     {
 | ||
|     	ca_create_fields(*this, 0, LF_PCONANA, 1, 15, F_PRE1, F_PREDES1, 0x0, PCONANA_CODCONTO);
 | ||
| 
 | ||
|       // Nascondi i campi che non fanno parte del prefisso
 | ||
| 	    for (int i = 0; i < pconana_levels; i++)
 | ||
| 	    {
 | ||
|         if (i < prefix)
 | ||
|         {
 | ||
|           field(F_PRE1 + i).check_type(CHECK_REQUIRED);
 | ||
|           field(F_PRE1 + i).set_group(6);
 | ||
|           field(F_PREDES1 + i).set_group(6);
 | ||
|         }
 | ||
|         else
 | ||
|         {
 | ||
|           field(F_PRE1 + i).hide();
 | ||
|           field(F_PREDES1 + i).hide();
 | ||
|         }	//if(i<prefix..
 | ||
|       }	//for(int i=0..
 | ||
|     }	//if(levels>=2..
 | ||
|   }	//if(use_pdcc..
 | ||
| 
 | ||
|   //filtro sui permessi utente (centro di costo e fase)
 | ||
|   if (ca_create_user_select_clause(LF_CDC).full())
 | ||
|     efield(F_CDC).browse()->cursor()->set_filterfunction(ca_filter_function);
 | ||
|   if (ca_create_user_select_clause(LF_FASI).full())
 | ||
|     efield(F_FASE).browse()->cursor()->set_filterfunction(ca_filter_function);
 | ||
| 	
 | ||
|   //***ACHTUNG!!!***
 | ||
|   //Questa chiamata serve per generare i campi fase/commessa esattamente come strutturati nella configurazione..
 | ||
|   //..della contabilita' analitica; ma per il magico Adolfo non servono!!!
 | ||
|   //ca_create_fields(*this, 0, LF_FASI, 2, 8, F_FASE1, F_DESCFASE1);
 | ||
| 	// setta gli handlers a tutti i campi generati della maschera;senza questa chiamata la on_field_event
 | ||
| 	// non puo' funzionare sui campi generati!!!
 | ||
| 	set_handlers();
 | ||
| }
 | ||
| 
 | ||
| ///////////////////////////////////////////////////////////////
 | ||
| //	RECORDSET 
 | ||
| ///////////////////////////////////////////////////////////////
 | ||
| class TPrint_bilancio_cms_recordset : public TPrint_saldana_recordset
 | ||
| {
 | ||
| 
 | ||
| public:
 | ||
|   TPrint_bilancio_cms_recordset() : TPrint_saldana_recordset(8) {}
 | ||
| };
 | ||
| 
 | ||
| 
 | ||
| ////////////////////////////////////////////////////////
 | ||
| //	REPORT
 | ||
| ////////////////////////////////////////////////////////
 | ||
| class TPrint_bilancio_cms_rep : public TCRPA_report
 | ||
| {
 | ||
| 
 | ||
| protected:
 | ||
| 	virtual bool set_recordset();
 | ||
| 	virtual bool get_usr_val(const TString& name, TVariant& var) const;
 | ||
| 
 | ||
| public:
 | ||
| 	void set_filter(const TPrint_bilancio_cms_mask& msk, const TString& curr_fase);
 | ||
| 	TPrint_bilancio_cms_rep(const char* rep_name, const TString& prefix, const int depth, 
 | ||
|                           const bool show_fasi, const bool show_cdc, 
 | ||
|                           const bool show_cms_descr, const bool show_cms_date);
 | ||
| };
 | ||
| 
 | ||
| bool TPrint_bilancio_cms_rep::get_usr_val(const TString& name, TVariant& var) const
 | ||
| {
 | ||
| 	return TReport::get_usr_val(name, var);
 | ||
| }
 | ||
| 
 | ||
| bool TPrint_bilancio_cms_rep::set_recordset()
 | ||
| {
 | ||
|   TPrint_bilancio_cms_recordset* rs = new TPrint_bilancio_cms_recordset();
 | ||
|   return TReport::set_recordset(rs);
 | ||
| }
 | ||
| 
 | ||
| void TPrint_bilancio_cms_rep::set_filter(const TPrint_bilancio_cms_mask& msk, const TString& curr_fase_cdc)
 | ||
| {
 | ||
| 	TPrint_bilancio_cms_recordset* recset = new TPrint_bilancio_cms_recordset(); 
 | ||
| 
 | ||
|   //la set_filter del recordset puo' essere chiamata per fase o per centro di costo; se curr_fase_cdc e' vuota..
 | ||
|   //..e' nel caso della stampa principale dettagliata (ca3800a.rep)
 | ||
|   recset->set_filter(msk, curr_fase_cdc);
 | ||
| 	TReport::set_recordset(recset);
 | ||
| }
 | ||
| 
 | ||
| TPrint_bilancio_cms_rep::TPrint_bilancio_cms_rep(const char* rep_name, const TString& prefix, 
 | ||
|                                                  const int depth, const bool show_fasi, const bool show_cdc,
 | ||
|                                                  const bool show_cms_descr, const bool show_cms_date)
 | ||
| 												:TCRPA_report(rep_name, prefix, depth, show_fasi, show_cdc, show_cms_descr, show_cms_date)
 | ||
| {
 | ||
| }
 | ||
| 
 | ||
| ////////////////////////////////////////////////////////
 | ||
| //	APPLICAZIONE
 | ||
| ////////////////////////////////////////////////////////
 | ||
| class TPrint_bilancio_cms : public TSkeleton_application
 | ||
| {
 | ||
|   TPrint_bilancio_cms_mask* _mask;
 | ||
| 
 | ||
| protected:
 | ||
|   void print_or_preview(const bool stampa);
 | ||
|   virtual void print();
 | ||
|   virtual void preview();
 | ||
| 
 | ||
|   virtual void main_loop();
 | ||
| };
 | ||
| 
 | ||
| void TPrint_bilancio_cms::print()
 | ||
| {
 | ||
|   print_or_preview(true);
 | ||
| }
 | ||
| 
 | ||
| void TPrint_bilancio_cms::preview()
 | ||
| {
 | ||
|   print_or_preview(false);
 | ||
| }
 | ||
| 
 | ||
| void TPrint_bilancio_cms::print_or_preview(const bool stampa)
 | ||
| {
 | ||
| 	//report e book dei report
 | ||
| 	TReport_book book;
 | ||
| 
 | ||
| 	TString80 prefix;
 | ||
|   for (short id = F_PRE1; id <= F_PRE3 && _mask->id2pos(id) > 0; id++)
 | ||
| 	  prefix << _mask->get(id);
 | ||
| 
 | ||
| 	const int depth = _mask->get_int(F_DEPTH);
 | ||
| 	TString path = _mask->get(F_REPORT);
 | ||
| 
 | ||
|   const int tipostampa = _mask->get_int(F_TIPOSTAMPA);
 | ||
|   //fasi
 | ||
|   const bool use_fasi = (tipostampa == 1) || (tipostampa == 3);
 | ||
|   const TString& fase = _mask->get(F_FASE);
 | ||
|   const bool group_fasi = tipostampa == 4;
 | ||
|   const bool show_fasi = use_fasi && fase.empty();
 | ||
| 
 | ||
|   //cdc
 | ||
|   const bool use_cdc = (tipostampa == 2) || (tipostampa == 3);
 | ||
|   const TString& cdc = _mask->get(F_CDC);
 | ||
|   const bool group_cdc = tipostampa == 8;
 | ||
|   const bool show_cdc = use_cdc && cdc.empty();
 | ||
| 
 | ||
|   //descrizioni
 | ||
|   const bool show_cms_descr = _mask->get_bool(F_SHOW_CMS_DESCR);
 | ||
|   const bool show_cms_date = _mask->get_bool(F_SHOW_CMS_DATE);
 | ||
| 
 | ||
| 	if (path.empty())
 | ||
|   {
 | ||
|     path = _mask->get_report_class();
 | ||
|   }
 | ||
| 
 | ||
|   //crea il report in base ai parametri (tipo report,struttura,profondita' di stampa)
 | ||
|   TPrint_bilancio_cms_rep rep(path, prefix, depth, show_fasi, show_cdc, show_cms_descr, show_cms_date);
 | ||
| 
 | ||
|   //se e' una stampa di tipo fasi riassunte (crpa special edition) deve fare lo scanning di tutte le fasi..
 | ||
|   //..singolarmente e stampare un report per ogni fase.Senno' stampa un solo report
 | ||
|   if (group_fasi)
 | ||
|   {
 | ||
|     //stampa tutte le fasi distinte in modo riassuntivo (crpa dedicate)
 | ||
|     TString_array lista_fasi;
 | ||
|     //crea un TString_array con tutte le fasi distinte non ripetute
 | ||
|     TString query;
 | ||
|     query = "USE FASI";
 | ||
| 
 | ||
|     const TString& select = ca_create_user_select_clause(LF_FASI);
 | ||
|     if (select.full())
 | ||
|       query << "\nSELECT " << select; 
 | ||
| 
 | ||
|     TISAM_recordset file_fasi(query);
 | ||
| 
 | ||
|     for (TRecnotype j = 0; file_fasi.move_to(j); j++)
 | ||
|     {
 | ||
|       const TString16 curr_fase = file_fasi.get(FASI_CODFASE).as_string();
 | ||
| 
 | ||
|       if (!curr_fase.empty() && lista_fasi.find(curr_fase) < 0)
 | ||
|         lista_fasi.add(curr_fase);
 | ||
|     }
 | ||
|     lista_fasi.sort();  //ordina alfabeticamente l'arrayone
 | ||
|     const long fasi_distinte = lista_fasi.items();  //numero di controllo
 | ||
| 
 | ||
|     //se la stampa e' con tutte le fasi distinte riassunte (crpa dedicate) fa un rep per fase...
 | ||
|     if (!lista_fasi.empty())
 | ||
|     {     
 | ||
|       //per ogni fase crea un report e lo aggiunge al book
 | ||
|       FOR_EACH_ARRAY_ROW(lista_fasi, i, row)
 | ||
|       {
 | ||
|         TString16 fase = lista_fasi.row(i);
 | ||
|         rep.set_filter(*_mask, fase);
 | ||
|         book.add(rep);
 | ||
|       }
 | ||
|       if (stampa)
 | ||
|         book.print();
 | ||
|       else
 | ||
|         book.preview();
 | ||
|     }
 | ||
| 
 | ||
|   } //if(group_fasi...
 | ||
|   else if (group_cdc)
 | ||
|   {
 | ||
|     //stampa tutte le fasi distinte in modo riassuntivo (crpa dedicate)
 | ||
|     TString_array lista_cdc;
 | ||
|     //crea un TString_array con tutte le fasi distinte non ripetute
 | ||
|     TString query;
 | ||
|     query = "USE CDC";
 | ||
|     //filtra per utente se l'utente ha limitazioni sui CDC
 | ||
|     const TString& select = ca_create_user_select_clause(LF_CDC);
 | ||
|     if (select.full())
 | ||
|       query << "\nSELECT " << select; 
 | ||
| 
 | ||
|     TISAM_recordset file_cdc(query);
 | ||
| 
 | ||
|     for (TRecnotype j = 0; file_cdc.move_to(j); j++)
 | ||
|     {
 | ||
|       const TString& curr_cdc = file_cdc.get(CDC_CODCOSTO).as_string();
 | ||
|       rep.set_filter(*_mask, curr_cdc);
 | ||
|       book.add(rep);
 | ||
| 
 | ||
|     }
 | ||
|     if (stampa)
 | ||
|       book.print();
 | ||
|     else
 | ||
|       book.preview();
 | ||
| 
 | ||
|   } //if(group_cdc...
 | ||
|   else  //...senno' stampa standard in un giro solo
 | ||
|   {		  
 | ||
| 	  rep.set_filter(*_mask, "");	
 | ||
| 	  book.add(rep);
 | ||
|     if (stampa)
 | ||
|       book.print();
 | ||
|     else
 | ||
|       book.preview();
 | ||
|   }
 | ||
|   
 | ||
| }
 | ||
| 
 | ||
| void TPrint_bilancio_cms::main_loop()
 | ||
| {
 | ||
|   _mask = new TPrint_bilancio_cms_mask;
 | ||
|   _mask->run();
 | ||
|   delete _mask;
 | ||
|   _mask = NULL;
 | ||
| }
 | ||
| 
 | ||
| int ca3800(int argc, char* argv[])
 | ||
| {
 | ||
|   TPrint_bilancio_cms a;
 | ||
|   a.run(argc, argv, TR("Stampa bilancio di commessa"));
 | ||
|   return 0;
 | ||
| }
 | ||
| 
 | ||
| //Istruzioni per i programmi ca3800 e ca3900
 | ||
| //------------------------------------------
 | ||
| // CA_3800
 | ||
| // Gestore maschera ca3800 (Analisi Bilancio di Commessa)
 | ||
| // Creatore del report e dell'applicazione
 | ||
| 
 | ||
| // CA_3801
 | ||
| // Gestore dei report a colonne variabili (stampa in base a struttura scelta per il PCONANA). Serve solo per ca3800.
 | ||
| 
 | ||
| // CA_3883
 | ||
| // Gestore del recordset per il calcolo dei valori da mettere sulle stampe (<28> il nucleo dei programmi ca3800 e ca3900)
 | ||
| 
 | ||
| // CA_3900
 | ||
| // Gestore maschera ca3900 (Stima ricavi di competenza)
 | ||
| // Creatore del report e dell'applicazione
 |