Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 01.05 patch 282 git-svn-id: svn://10.65.10.50/trunk@8076 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			336 lines
		
	
	
		
			9.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			336 lines
		
	
	
		
			9.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| // Programma di stampa riepiloghi INTRA comunitari
 | |
| //
 | |
| // A fundament of righteous men, a barrow of ideals, the carriage 
 | |
| //   of misjustice crushes all beneath its weels
 | |
| //
 | |
| #include <applicat.h>
 | |
| #include <prefix.h>
 | |
| #include <printer.h>
 | |
| #include <recarray.h>
 | |
| #include <form.h>
 | |
| 
 | |
| #include <nditte.h>
 | |
| 
 | |
| #include "in0.h"
 | |
| #include "in0100a.h"
 | |
| #include "inlib01.h"
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TStampaIntra_form
 | |
| ///////////////////////////////////////////////////////////
 | |
| class TStampaIntra_form : public TForm
 | |
| {
 | |
|   TRecord_array  *_riepiloghi;
 | |
|   TRecord_array  *_rettifiche;
 | |
|   TString16 _tipo, _frequenza, _periodo, _anno;
 | |
|   int _totrow1, _totrow2, _totpag1, _totpag2; // Righe e pagine totali per sezioni...
 | |
|   int _pageno1, _pageno2, _index1, _index2;   // Numero di pagina corrente ed indice di accesso ai TRecord_array
 | |
|   real _tot1, _tot2;                          // Totale ammontare sezione 1 e 2
 | |
|   real _riportoprec1, _riportoprec2;          // Riporto pagina prec. per sezioni 1 e 2
 | |
|   real _totaleprog1, _totaleprog2;            // Totale progressivo per pagina, sezioni 1 e 2
 | |
|   
 | |
| protected:
 | |
|   void print_page(const pagetype p);
 | |
|   const bool good() const;
 | |
|   
 | |
| public:
 | |
|   void print();
 | |
|   TStampaIntra_form (const char* name, char t, char f, int p, int a);
 | |
|   virtual ~TStampaIntra_form ();
 | |
| };
 | |
| 
 | |
| TStampaIntra_form::TStampaIntra_form(const char* name, char t, char f, int p, int a) : TForm(name)
 | |
| {
 | |
|   _tipo << t;
 | |
|   _frequenza << f;
 | |
|   _periodo << p;
 | |
|   _anno << a;
 | |
|   
 | |
|   TRectype dep(cursor()->file(LF_RIEPRETT).curr());
 | |
|   dep.zero();
 | |
|   dep.put("TIPO", t);  dep.put("ANNO", a);
 | |
|   dep.put("PERIODO", p);
 | |
|   _riepiloghi = new TRecord_array(dep, "NUMRIG");
 | |
|   t++;
 | |
|   dep.put("TIPO", t);
 | |
|   _rettifiche = new TRecord_array(dep, "NUMRIG");
 | |
| }
 | |
| 
 | |
| TStampaIntra_form::~TStampaIntra_form()
 | |
| {
 | |
|   if (_riepiloghi)
 | |
|     delete _riepiloghi;
 | |
|   if (_rettifiche)
 | |
|     delete _rettifiche;
 | |
| }
 | |
| 
 | |
| const bool TStampaIntra_form::good() const
 | |
| {
 | |
|   return _index1 <= _riepiloghi->rows() || _index2 <= _rettifiche->rows();
 | |
| }
 | |
| 
 | |
| void TStampaIntra_form::print_page(const pagetype p)
 | |
| {
 | |
|   TString16 ws;
 | |
|   char secs[] = { "HBF" };
 | |
|   TPrint_section* ps;
 | |
|   TPrinter& pr = printer();
 | |
| 
 | |
|   for (int sc = 0; sc < 3; sc++)
 | |
|     if ((ps = exist(secs[sc], p, FALSE)) != NULL)
 | |
|     {
 | |
|       const word r = ps->height();
 | |
|       int iterations = 1;
 | |
|       
 | |
|       if (secs[sc] == 'B')
 | |
|         switch(p)
 | |
|         {
 | |
|           case odd_page:
 | |
|             iterations = 10;
 | |
|           break;
 | |
|           case even_page:
 | |
|             iterations = 7;
 | |
|           break;
 | |
|           default:
 | |
|           break;
 | |
|         }
 | |
|       
 | |
|       const bool is_odd_page = p == odd_page;
 | |
|       const bool not_first   = p != first_page;
 | |
|       int& index = is_odd_page ? _index1  : _index2;
 | |
|       int& max   = is_odd_page ? _totrow1 : _totrow2;
 | |
|       // Per le testate ed i footers 1 singola iterazione, per i Body (solo ODD ed EVEN)
 | |
|       // esegue tante iterazioni quante sono le righe per riepiloghi o rettifiche
 | |
|       for (int k = 0; k < iterations; k++)
 | |
|       {
 | |
|         ps->reset();
 | |
|         switch (secs[sc])
 | |
|         {
 | |
|           case 'H':    // Testate...
 | |
|           {
 | |
|             if (p == first_page || (not_first && index <= max))
 | |
|             {
 | |
|               ps->find_field(_frequenza == "M" ? 1 : 2).set(_periodo);
 | |
|               ps->find_field(3).set(_anno);
 | |
|               if (p == first_page)
 | |
|                 ps->find_field(4).set(_frequenza);
 | |
|               ps->update();
 | |
|             }
 | |
|           }
 | |
|           break;
 | |
|           case 'F': // Footers...
 | |
|             if (p == first_page)
 | |
|             {
 | |
|               ws.format("%d", _totpag1);
 | |
|               ps->find_field(1).set(ws);
 | |
|               ws.format("%d", _totrow1);
 | |
|               ps->find_field(2).set(ws);
 | |
|               ps->find_field(3).set(_tot1.string());
 | |
|               ws.format("%d", _totpag2);
 | |
|               ps->find_field(4).set(ws);
 | |
|               ws.format("%d", _totrow2);
 | |
|               ps->find_field(5).set(ws);
 | |
|               ps->find_field(6).set(_tot2.string());
 | |
|               ps->update();
 | |
|             }
 | |
|             else // Footers ODD/EVEN
 | |
|             { 
 | |
|               real & rrip = is_odd_page ? _riportoprec1 : _riportoprec2;
 | |
|               real & rtot = is_odd_page ? _totaleprog1  : _totaleprog2;
 | |
|               int& pgn    = is_odd_page ? _pageno1 : _pageno2;
 | |
|               int& totpgn = is_odd_page ? _totpag1 : _totpag2;
 | |
|               
 | |
|               if (pgn <= totpgn)
 | |
|               {
 | |
|                 ws.format("%d", pgn);
 | |
|                 ps->find_field(1).set(rrip.string());
 | |
|                 ps->find_field(2).set(rtot.string());
 | |
|                 ps->find_field(3).set(ws);
 | |
|                 pgn++;
 | |
|                 ps->update();
 | |
|               }
 | |
|               rrip = rtot;
 | |
|             }
 | |
|           break;
 | |
|           case 'B': // Body! CDB Infame donato per compiacer alle virtu' delle giovani signore/signorine
 | |
|           {         // Spezza il Totem: riunisce la piu' probabile delle ipotesi in un inutile compendio di
 | |
|                     // miserabili ed incomode tentazioni.
 | |
|             if (not_first)
 | |
|             {
 | |
|               TRecord_array* ra   = is_odd_page ? _riepiloghi : _rettifiche;
 | |
|               if (index <= max)
 | |
|               {
 | |
|                 const TRectype& rec = ra->row(index);
 | |
|                 relation()->lfile(LF_RIEPRETT).curr() = rec;
 | |
|                 real & rtot = is_odd_page ? _totaleprog1  : _totaleprog2;
 | |
|                 rtot += rec.get_real("AMMLIRE");
 | |
|                 index++;
 | |
|                 ps->update();
 | |
|               }
 | |
|             }
 | |
|             else
 | |
|               ps->update();
 | |
|           }
 | |
|           break;
 | |
|           default:
 | |
|           break;
 | |
|         }
 | |
| 
 | |
|         for (word j = 0; j < r; j++)
 | |
|         {
 | |
|           TPrintrow& row = ps->row(j);
 | |
|           pr.print(row);
 | |
|         }
 | |
|       }
 | |
|     }
 | |
|     
 | |
|     // No formfeed is needed since Header + n * Body + Footer = 72;
 | |
|     // Where n is the total body size for first_page, 10 for odd_page and 7 for even_page
 | |
| }
 | |
| 
 | |
| void TStampaIntra_form::print()
 | |
| {
 | |
|   TPrinter& pr = printer();
 | |
|   
 | |
|   // Calcolo degli ammontare complessivi, totale pagine e righe di dettaglio
 | |
|   // per sezione
 | |
| 
 | |
|   _totrow1 = _riepiloghi->rows();
 | |
|   _totrow2 = _rettifiche->rows();
 | |
|   _totpag1 = _totrow1 % 10 != 0 ? _totrow1 / 10 + 1 : _totrow1 / 10;
 | |
|   _totpag2 = _totrow2 % 7  != 0 ? _totrow2 / 7  + 1 : _totrow2 / 7;
 | |
|   _pageno1 = _pageno2 = 1;
 | |
|   _index1  = _index2 = 1;
 | |
|   
 | |
|   if (_totrow1 + _totrow2 == 0)
 | |
|   {
 | |
|     error_box("Non esistono righe di riepilogo o rettifiche da stampare per il periodo selezionato");
 | |
|     return;
 | |
|   }
 | |
|   
 | |
|   for (int i = 1; i <= _totrow1; i++)
 | |
|     _tot1 += _riepiloghi->row(i).get_real("AMMLIRE");
 | |
|   
 | |
|   for (i = 1; i <= _totrow2; i++)
 | |
|   {
 | |
|     const TRectype& rec = _rettifiche->row(i);
 | |
|     if (rec.get_char("SEGNORETT") == '-')
 | |
|       _tot2 -= rec.get_real("AMMLIRE");
 | |
|     else
 | |
|       _tot2 += rec.get_real("AMMLIRE");
 | |
|   }
 | |
|   
 | |
|   //Posiziona la relazione principale (ditta corrente)
 | |
|   TLocalisamfile& nditte = relation()->lfile(LF_NDITTE);
 | |
| 
 | |
|   nditte.put(NDT_CODDITTA, prefix().get_codditta());
 | |
|   if (relation()->read(_isequal) != NOERR && !yesno_box("Errore nel posizionamento sulla ditta corrente. Continuare?"))
 | |
|     return;
 | |
|   
 | |
|   pr.formlen(height(1));
 | |
|   pr.open(); // Apriti Sesamo! Granello di nulla... ma assai importante nell'antichita'.
 | |
|   
 | |
|   //Posizionamento
 | |
|   if (pr.printtype() == winprinter && pr.is_generic())
 | |
|     arrange_form();
 | |
|     
 | |
|   // Ed ecco qui... il Lievito Svi$$ero (sempre per rimanere in tema di Ali' Baba' ed i 40 Kazzoni)
 | |
|   while (good())
 | |
|   {
 | |
|     for (int pagina = 1; pagina <= 4; pagina++)
 | |
|     {
 | |
|       switch (pagina)
 | |
|       {
 | |
|         case 1:
 | |
|           print_page(first_page);
 | |
|         break;
 | |
|         case 2:
 | |
|         case 3:
 | |
|           print_page(odd_page);
 | |
|         break;
 | |
|         case 4:
 | |
|           print_page(even_page);
 | |
|         break;
 | |
|         default:
 | |
|         break;
 | |
|       }
 | |
|     }
 | |
|   }
 | |
|   // Exhausting all the rest:
 | |
|   // I will get, you dear enemy;
 | |
|   // ..See that people are underhand when asking: "how are you?"
 | |
|   // And so the printer was CLOSED!
 | |
|   pr.close(); // Chiuditi Sesamo
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TStampaIntra_mask
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TStampaIntra_mask : public TIntra_mask
 | |
| {
 | |
|   
 | |
| protected:
 | |
|   virtual short type_field() const { return R_TIPO; }
 | |
|   virtual short period_field() const { return R_PERIODO_M; }
 | |
|  
 | |
| public:
 | |
|   void print();
 | |
|   TStampaIntra_mask();
 | |
|   virtual ~TStampaIntra_mask() { }
 | |
| };
 | |
| 
 | |
| TStampaIntra_mask::TStampaIntra_mask()
 | |
|                  : TIntra_mask("in0100a")
 | |
| { }
 | |
| 
 | |
| void TStampaIntra_mask::print()
 | |
| {
 | |
|   TStampaIntra_form form(tipo() == 'A' ? "in0100a" : "in0100b", tipo(), frequenza(), periodo(), get_int(R_ANNO));
 | |
|   form.print();
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // Applicazione di stampa
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TStampa_intra : public TSkeleton_application
 | |
| {
 | |
|   TStampaIntra_mask* _msk;
 | |
| 
 | |
| protected:
 | |
|   virtual bool create();
 | |
|   virtual bool destroy();
 | |
|   virtual void main_loop();
 | |
| public:
 | |
|   TStampa_intra() {};
 | |
|   virtual ~TStampa_intra() {};
 | |
| };
 | |
| 
 | |
| bool TStampa_intra::create()
 | |
| {
 | |
|   open_files(LF_TABCOM, LF_TAB, LF_CLIFO, LF_MOV, 
 | |
|              LF_INTRA, LF_RINTRA, 0);
 | |
|   _msk = new TStampaIntra_mask;
 | |
|   return TSkeleton_application::create();
 | |
| }
 | |
| 
 | |
| bool TStampa_intra::destroy()
 | |
| {
 | |
|   delete _msk;
 | |
|   return TSkeleton_application::destroy();
 | |
| }
 | |
| 
 | |
| void TStampa_intra::main_loop()
 | |
| {
 | |
|   while (_msk->run()!=K_QUIT)
 | |
|     _msk->print();
 | |
| }
 | |
| 
 | |
| int in0100(int argc, char* argv[])
 | |
| {
 | |
|   TStampa_intra a;
 | |
|   a.run(argc, argv, "Stampa Riepiloghi");
 | |
|   return 0;
 | |
| }    
 |