Files correlati : Ricompilazione Demo : [ ] Commento : Dalla 5.0: 1) corretto errore in caso di mancanza campo prefix sulla maschera 2) gestite le commessa senza Datafine (Ruffo) git-svn-id: svn://10.65.10.50/trunk@17211 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			315 lines
		
	
	
		
			9.0 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			315 lines
		
	
	
		
			9.0 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.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 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;
 | 
						|
  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..
 | 
						|
	
 | 
						|
  //***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);
 | 
						|
};
 | 
						|
 | 
						|
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)
 | 
						|
												:TCRPA_report(rep_name, prefix, depth, show_fasi, show_cdc)
 | 
						|
{
 | 
						|
}
 | 
						|
 | 
						|
////////////////////////////////////////////////////////
 | 
						|
//	APPLICAZIONE
 | 
						|
////////////////////////////////////////////////////////
 | 
						|
class TPrint_bilancio_cms : public TSkeleton_application
 | 
						|
{
 | 
						|
public:
 | 
						|
  virtual void main_loop();
 | 
						|
};
 | 
						|
 | 
						|
void TPrint_bilancio_cms::main_loop()
 | 
						|
{
 | 
						|
  TPrint_bilancio_cms_mask mask;
 | 
						|
  while (mask.run() == K_ENTER)
 | 
						|
  {
 | 
						|
		//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();
 | 
						|
 | 
						|
		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);
 | 
						|
 | 
						|
    //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
 | 
						|
      TISAM_recordset file_fasi("USE FASI");
 | 
						|
      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);
 | 
						|
        }
 | 
						|
        book.print_or_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
 | 
						|
      TISAM_recordset file_cdc("USE CDC");
 | 
						|
      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);
 | 
						|
 | 
						|
      }
 | 
						|
      book.print_or_preview();
 | 
						|
 | 
						|
    } //if(group_cdc...
 | 
						|
    else  //...senno' stampa standard in un giro solo
 | 
						|
    {		  
 | 
						|
		  rep.set_filter(mask, "");	
 | 
						|
		  book.add(rep);
 | 
						|
      book.print_or_preview();
 | 
						|
    }
 | 
						|
    
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
int ca3800(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TPrint_bilancio_cms a;
 | 
						|
  a.run(argc, argv, TR("Stampa bilancio di commessa"));
 | 
						|
  return 0;
 | 
						|
}
 |