Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 1.7 patch 054 aga sul main trunk git-svn-id: svn://10.65.10.50/trunk@9659 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			271 lines
		
	
	
		
			7.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			271 lines
		
	
	
		
			7.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| // Stampa statistiche temporali per agente
 | |
| #include <applicat.h>
 | |
| #include <form.h>
 | |
| #include <mask.h>
 | |
| #include <printer.h>
 | |
| #include <sheet.h>
 | |
| #include <currency.h>
 | |
| 
 | |
| #include "provv.h"
 | |
| #include "agenti.h"
 | |
| 
 | |
| #include "pr1400.h"
 | |
| #include "pr1400a.h"
 | |
| 
 | |
| class TForm_stampaprstat:public TForm
 | |
| {
 | |
|   //TSorted_cursor *_cur;
 | |
|   TString_array  _month_description;
 | |
|   
 | |
| public:
 | |
|   //virtual TCursor* cursor() const { return (TCursor*)_cur; }
 | |
|   //void set_cursor(TSorted_cursor* c) { _cur = c; }
 | |
|   void set_month_descriptions(const TString_array& d) { _month_description = d; }
 | |
|   virtual bool validate(TForm_item& fld, TToken_string& val);
 | |
|   TForm_stampaprstat(const char *name,const char *code) ;
 | |
|   virtual ~TForm_stampaprstat();
 | |
| };
 | |
| 
 | |
| TForm_stampaprstat::TForm_stampaprstat(const char *name,const char *code) 
 | |
|   : TForm(name,code)
 | |
| {
 | |
| }
 | |
| 
 | |
| TForm_stampaprstat::~TForm_stampaprstat() 
 | |
| {
 | |
| }
 | |
| 
 | |
| bool TForm_stampaprstat::validate(TForm_item& fld, TToken_string& val) 
 | |
| {
 | |
|   const TString code(val.get(0)); // Codice del messaggio
 | |
|   if (code == "_MONTHRANGE")    // Per settare la descrizione del range di mesi relativi a questo item
 | |
|   {
 | |
|     const short id = fld.id();
 | |
|     TString& descr = (TString&)_month_description[id - F_MON1];
 | |
|     fld.set(descr);
 | |
|     return TRUE;
 | |
|   }
 | |
|   else                                
 | |
|     if (code == "_FIRMVALUE")    // Per settare la descrizione del range di mesi relativi a questo item
 | |
|     {                 
 | |
|       TForm & f = fld.form();
 | |
|       TRectype & rec = f.cursor()->curr(LF_PROVV);   
 | |
|       TString16 codval(rec.get("CODVAL")); 
 | |
|       if (is_true_value(codval))
 | |
|       {
 | |
|         TCurrency c(fld.get(), codval, rec.get_real("CAMBIO"));
 | |
|        
 | |
|         c.change_to_firm_val();
 | |
|         fld.set(c.get_num().string());
 | |
|       }
 | |
|       return TRUE;      
 | |
|     }     
 | |
|     else
 | |
|       return TForm::validate(fld, val);
 | |
| }
 | |
| 
 | |
| class TStampa_statistiche_app : public TSkeleton_application
 | |
| {
 | |
|   TMask                 *_msk;
 | |
|   TForm_stampaprstat    *_frm;
 | |
|   
 | |
| protected:
 | |
|   virtual bool create();
 | |
|   virtual bool destroy();
 | |
|   virtual void main_loop();
 | |
|   static  bool daterange_handler(TMask_field& f, KEY key);
 | |
|   static  bool agerange_handler(TMask_field& f, KEY key);
 | |
| public:
 | |
|   TStampa_statistiche_app()  {};
 | |
|   ~TStampa_statistiche_app() {};  
 | |
| };
 | |
| 
 | |
| bool TStampa_statistiche_app::daterange_handler(TMask_field& f, KEY key)
 | |
| {
 | |
|   if (f.to_check(key))
 | |
|   {
 | |
|     TMask& m = f.mask();
 | |
|     TDate from(m.get_date(F_DATEFROM));
 | |
|     TDate to(m.get_date(F_DATETO));
 | |
|     if (from.ok() && to.ok() && (to < from || to.year() != from.year()))
 | |
|       return f.error_box("L'intervallo date specificato non e' corretto");
 | |
|   }
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TStampa_statistiche_app::agerange_handler(TMask_field& f, KEY key)
 | |
| {
 | |
|   if (f.to_check(key))
 | |
|   {
 | |
|     TMask& m = f.mask();
 | |
|     const bool ord_cod = m.get(F_ORDINAMENTO)[0] == 'C';
 | |
|     TString from(m.get(ord_cod ? F_DAAGE : F_DADES));
 | |
|     TString to(m.get(ord_cod ? F_AAGE : F_ADES));
 | |
|     if (from.not_empty() && to.not_empty() && to < from)
 | |
|       return f.error_box("L'intervallo agenti specificato non e' corretto");
 | |
|   }
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TStampa_statistiche_app::create()
 | |
| {
 | |
|   open_files(LF_PROVV,0);
 | |
|   _msk   = new TMask("pr1400") ;
 | |
|   _frm   = new TForm_stampaprstat("pr1400a","");
 | |
|   _msk->set_handler(F_DAAGE,agerange_handler);
 | |
|   _msk->set_handler(F_AAGE,agerange_handler);
 | |
|   _msk->set_handler(F_DADES,agerange_handler);
 | |
|   _msk->set_handler(F_ADES,agerange_handler);
 | |
|   _msk->set_handler(F_DATEFROM,daterange_handler);
 | |
|   _msk->set_handler(F_DATETO,daterange_handler);
 | |
|   
 | |
|   return TSkeleton_application::create();
 | |
| }
 | |
| 
 | |
| void TStampa_statistiche_app::main_loop()
 | |
| {
 | |
|   const char * months[] = { "Gen", "Feb", "Mar", "Apr", "Mag", "Giu",
 | |
|                             "Lug", "Ago", "Set", "Ott", "Nov", "Dic" };
 | |
|   TString_array descriptions;
 | |
|   TString cond;  // Stringa identificante la condizione di raggruppamento
 | |
|   TString desc;  // Stringa per settare la descrizione del range di mesi
 | |
|   TString ds1, ds2; // Date in formato stringa per settare la condizione
 | |
|   TDate date_from, date_to;
 | |
|   TString age_from, age_to;
 | |
|   TString filter_expr;
 | |
|   TArray date_range; // Array di date per settare i range 
 | |
|   
 | |
|   TRectype rec_from(LF_AGENTI), rec_to(LF_AGENTI);
 | |
|   TCursor* cur = (TCursor*)_frm->cursor();
 | |
|   
 | |
|   TSortedfile *provv = new TSortedfile(LF_PROVV,NULL,"CODAGE|DATADOC", "", 2);
 | |
|   cur->relation()->replace(provv, 1, "CODAGE==CODAGE",2);
 | |
|   
 | |
|   while (_msk->run() == K_ENTER)
 | |
|   {
 | |
|     const bool normal_order = _msk->get(F_ORDINAMENTO)[0] != 'R';
 | |
|     date_from = _msk->get_date(F_DATEFROM);
 | |
|     date_to   = _msk->get_date(F_DATETO);
 | |
|     age_from  = _msk->get(normal_order ? F_DAAGE : F_DADES);
 | |
|     age_to    = _msk->get(normal_order ? F_AAGE : F_ADES);
 | |
|     
 | |
|     if (!date_from.ok() || !date_to.ok())
 | |
|     {
 | |
|       error_box("Inserire un range di date valido");
 | |
|       continue;
 | |
|     }
 | |
|     
 | |
|     descriptions.destroy();
 | |
|     date_range.destroy();
 | |
|     
 | |
|     // Setta l'array per il range dei mesi
 | |
|     int month_from = date_from.month();
 | |
|     int month_to   = date_to.month();
 | |
|     int inc_month  = _msk->get_int(F_GROUPMONTH);
 | |
|     for (int m = month_from; m <= month_to; m += inc_month)
 | |
|     {
 | |
|       desc = months[m - 1];
 | |
|       const int index = m + inc_month > 12 ? 12 : m + inc_month - 1;
 | |
|       if (inc_month > 1)
 | |
|       {
 | |
|         desc << "-";
 | |
|         desc << months[index - 1];
 | |
|       }
 | |
|       descriptions.add(desc);
 | |
|     }
 | |
|     
 | |
|     m = descriptions.items();
 | |
|     while (m < 12)
 | |
|     {
 | |
|       descriptions.add(""); // Aggiunge gli elementi vuoti necessari
 | |
|       m++;
 | |
|     }
 | |
|     
 | |
|     _frm->set_month_descriptions(descriptions);
 | |
|     
 | |
|     // Setta i range delle date per raggruppare le sottosezioni
 | |
|     TDate d(date_from);
 | |
|     
 | |
|     for (m = 1; m <= 12; m++)
 | |
|     {
 | |
|       date_range.add(d);
 | |
|       if (d != botime)
 | |
|       {
 | |
|         d.addmonth(inc_month-1);
 | |
|         d.set_end_month();
 | |
|         if (d > date_to)
 | |
|           d = date_to;
 | |
|         date_range.add(d);
 | |
|         d += 1; // Primo giorno del mese successivo
 | |
|         if (d > date_to)
 | |
|           d = botime;
 | |
|       }
 | |
|       else
 | |
|         date_range.add(d); // Tutti quelli che eccedono la data di fine sono botime
 | |
|     }
 | |
|     
 | |
|     // Setta le condizioni di raggruppamento per ognuna delle sottosezioni
 | |
|     // I nomi sono PRS1, PRS2, PRS3... PRS6
 | |
|     for (m = 1; m <= 12; m++)
 | |
|     {
 | |
|       desc.format("PRS%d",m);
 | |
|       TForm_subsection& ssec = (TForm_subsection&)_frm->find_field('B', odd_page, desc); // Sottosezione padre
 | |
|       const int base = 2 * (m-1);
 | |
|       ds1 = ((TDate&) date_range[base]).string(ANSI);
 | |
|       ds2 = ((TDate&) date_range[base+1]).string(ANSI);
 | |
|       cond.format("(ANSI(%d->DATADOC)>=\"%s\") && (ANSI(%d->DATADOC)<=\"%s\") && (%d->NRIGA==\"1\")", 
 | |
|                    LF_PROVV, (const char*)ds1, LF_PROVV, (const char*) ds2, LF_PROVV);
 | |
|       ssec.setcondition(cond, _strexpr);
 | |
|     }
 | |
|     
 | |
|     ds1 = date_from.string(ANSI);
 | |
|     ds2 = date_to.string(ANSI);
 | |
|     filter_expr.format("(ANSI(%d->DATADOC)>=\"%s\") && (ANSI(%d->DATADOC)<=\"%s\")", 
 | |
|                    LF_PROVV, (const char*)ds1, LF_PROVV, (const char*) ds2);
 | |
| 
 | |
|     // Setta il filtro sul sul sortedfile ordinato per data doc
 | |
|     provv->cursor().setfilter(filter_expr);
 | |
|     
 | |
|     // Setta gli estremi (codagente o ragione sociale)
 | |
|     rec_from.zero();
 | |
|     rec_to.zero();
 | |
|     rec_from.put(normal_order ? AGE_CODAGE : AGE_RAGSOC, age_from);
 | |
|     rec_to.put(normal_order ? AGE_CODAGE : AGE_RAGSOC, age_to);
 | |
|     
 | |
|     cur->setkey(normal_order ? 1 : 2); //Ordinamento per codice agente o ragione sociale
 | |
|     cur->setregion(rec_from, rec_to);
 | |
| 
 | |
|     // Stampa el todo
 | |
|     const int hh = 6;
 | |
|     const int fh = 1;
 | |
|     const int fl = printer().formlen();
 | |
|     
 | |
|     int rows[4];         // Righe orizzontali
 | |
|     rows[0] = hh-2;
 | |
|     rows[1] = hh;
 | |
|     rows[2] = fl-1;
 | |
|     rows[3] = 0;
 | |
|     _frm->genera_intestazioni(odd_page, hh-1);
 | |
|     _frm->genera_fincatura(odd_page, hh-2, fl-1, rows);
 | |
|     
 | |
|     _frm->print();
 | |
|     _msk->reset();
 | |
|     
 | |
|   }  
 | |
|   // Do not delete provv please, TRelation in TForm will do that...
 | |
| }
 | |
| 
 | |
| bool TStampa_statistiche_app::destroy()
 | |
| {
 | |
|   delete _msk;
 | |
|   delete _frm;
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| int pr1400(int argc, char* argv[])
 | |
| {
 | |
|   TStampa_statistiche_app  a;
 | |
|   a.run(argc,argv,"Statistiche temporali");
 | |
|   return 0;
 | |
| }
 |