Files correlati : gli stessi file della 2.1 Ricompilazione Demo : [ ] Commento Riportata la versione 2.1 patch 408 git-svn-id: svn://10.65.10.50/trunk@13463 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			430 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			430 lines
		
	
	
		
			12 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 <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
 | 
						|
  
 | 
						|
  int _decimals;
 | 
						|
	bool _solofronte;
 | 
						|
  
 | 
						|
protected:
 | 
						|
  void print_page(const pagetype p);
 | 
						|
  const bool good() const;
 | 
						|
  virtual bool validate(TForm_item& fld, TToken_string& val);
 | 
						|
  
 | 
						|
  real amm_euro(const TRectype& rec) const; // Ammontare arrotondato
 | 
						|
  
 | 
						|
public:
 | 
						|
  void print();
 | 
						|
  TStampaIntra_form (const char* name, char t, char f, int p, int a, bool sf);
 | 
						|
  virtual ~TStampaIntra_form ();
 | 
						|
};
 | 
						|
 | 
						|
bool TStampaIntra_form::validate(TForm_item& fld, TToken_string& val)
 | 
						|
{                       
 | 
						|
  const TString code(val.get(0)); // prende il primo parametro, il codice del messaggio
 | 
						|
 | 
						|
  if (code== "_IMP")
 | 
						|
  {
 | 
						|
    real num = fld.get();
 | 
						|
    num.round(_decimals);
 | 
						|
    fld.set(num.string());
 | 
						|
    return TRUE;
 | 
						|
  }
 | 
						|
  else
 | 
						|
    if (code== "_ROUND")
 | 
						|
    {
 | 
						|
      real num(fld.get());
 | 
						|
      const int ndec = val.get_int();
 | 
						|
      num.round(ndec);
 | 
						|
      fld.set(num.string());
 | 
						|
      return TRUE;
 | 
						|
    }
 | 
						|
  
 | 
						|
  return TForm::validate(fld, val);
 | 
						|
}
 | 
						|
 | 
						|
TStampaIntra_form::TStampaIntra_form(const char* name, char t, char f, int p, int a, bool sf) : TForm(name)
 | 
						|
{
 | 
						|
  _tipo << t;
 | 
						|
  _frequenza << f;
 | 
						|
  _periodo << p;
 | 
						|
  _anno << a;
 | 
						|
	_solofronte = sf;
 | 
						|
  
 | 
						|
  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");
 | 
						|
  
 | 
						|
  _decimals = is_euro_value(NULL) ? 0 : -3;   // Arrotonda all'Euro o alle 1000 Lire
 | 
						|
}
 | 
						|
 | 
						|
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();
 | 
						|
}
 | 
						|
 | 
						|
// Ricava l'ammontare in Euro arrotondato da un record
 | 
						|
real TStampaIntra_form::amm_euro(const TRectype& rec) const
 | 
						|
{
 | 
						|
  real amm = rec.get("AMMLIRE");  // Nome obsoleto
 | 
						|
  amm.round(_decimals);
 | 
						|
  return amm;
 | 
						|
}
 | 
						|
 | 
						|
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))
 | 
						|
            {                   
 | 
						|
              if (_frequenza[0] == 'M')
 | 
						|
                ps->find_field(1).set(_periodo); else  
 | 
						|
              if (_frequenza[0] == 'T')
 | 
						|
                ps->find_field(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);
 | 
						|
              ws = _tot2.string();
 | 
						|
              ps->find_field(6).set(ws);
 | 
						|
 | 
						|
              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 = rrip.string();
 | 
						|
                if (!is_odd_page)  // Gestione segno riporto rettifiche
 | 
						|
                {
 | 
						|
                  const bool neg = ws[0] == '-';
 | 
						|
                  ps->find_field(4).set(rrip.is_zero() ? "" : (neg ? "-" : "+"));
 | 
						|
                  if (neg)
 | 
						|
                    ws.ltrim(1);
 | 
						|
                }
 | 
						|
                ps->find_field(1).set(ws);
 | 
						|
 | 
						|
                ws = rtot.string();
 | 
						|
                if (!is_odd_page)  // Gestione segno totale rettifiche
 | 
						|
                {
 | 
						|
                  const bool neg = ws[0] == '-';
 | 
						|
                  ps->find_field(7).set(rtot.is_zero() ? "" : (neg ? "-" : "+"));
 | 
						|
                  if (neg)
 | 
						|
                    ws.ltrim(1);
 | 
						|
                }
 | 
						|
                ps->find_field(2).set(ws);
 | 
						|
 | 
						|
                ws.format("%d", pgn);
 | 
						|
                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()->curr(LF_RIEPRETT) = rec;
 | 
						|
                
 | 
						|
                real ammontare = amm_euro(rec);
 | 
						|
                if (!is_odd_page)  // Rettifiche
 | 
						|
                { 
 | 
						|
                  const TString8 mese = _frequenza[0] == 'M' ? rec.get("PERETT") : "0";
 | 
						|
                  const TString8 trim = _frequenza[0] == 'T' ? rec.get("PERETT") : "0";
 | 
						|
                  ps->find_field(2).set(mese);  
 | 
						|
                  ps->find_field(3).set(trim);
 | 
						|
                  
 | 
						|
                  // Controlla il segno delle rettifiche
 | 
						|
                  if (rec.get_char("SEGNORETT") == '-')
 | 
						|
                    ammontare = -ammontare;  
 | 
						|
                }
 | 
						|
                
 | 
						|
                // Incrementa progressivi
 | 
						|
                real& rtot = is_odd_page ? _totaleprog1 : _totaleprog2;
 | 
						|
                rtot += ammontare;
 | 
						|
                
 | 
						|
                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(TR("Non esistono righe di riepilogo o rettifiche da stampare per il periodo selezionato"));
 | 
						|
    return;
 | 
						|
  }
 | 
						|
  
 | 
						|
  for (int i = 1; i <= _totrow1; i++)
 | 
						|
    _tot1 += amm_euro(_riepiloghi->row(i));
 | 
						|
  
 | 
						|
  for (i = 1; i <= _totrow2; i++)
 | 
						|
  {
 | 
						|
    const TRectype& rec = _rettifiche->row(i);
 | 
						|
    if (rec.get_char("SEGNORETT") == '-')
 | 
						|
      _tot2 -= amm_euro(rec);
 | 
						|
    else
 | 
						|
      _tot2 += amm_euro(rec);
 | 
						|
  }
 | 
						|
  
 | 
						|
  //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(TR("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)
 | 
						|
	bool verygood = good();
 | 
						|
  while (verygood)
 | 
						|
  {
 | 
						|
    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;
 | 
						|
      } 
 | 
						|
      verygood = good();
 | 
						|
			if (_solofronte) verygood = FALSE;
 | 
						|
      if (!verygood || _solofronte)
 | 
						|
        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; }
 | 
						|
  virtual int anno() const { return get_int(R_ANNO); }
 | 
						|
	virtual bool solofronte() const { return get_bool(R_SOLOFRONTE); }
 | 
						|
	virtual bool descrizioni() const { return get_bool(R_DESCRIZIONI); }
 | 
						|
 
 | 
						|
public:
 | 
						|
  void print();
 | 
						|
  TStampaIntra_mask();
 | 
						|
  virtual ~TStampaIntra_mask() { }
 | 
						|
};
 | 
						|
 | 
						|
TStampaIntra_mask::TStampaIntra_mask()
 | 
						|
                 : TIntra_mask("in0100a")
 | 
						|
{ }
 | 
						|
 | 
						|
void TStampaIntra_mask::print()
 | 
						|
{ 
 | 
						|
  const int anno_s = anno();
 | 
						|
	TString16 nomeform;
 | 
						|
	if (descrizioni())
 | 
						|
		nomeform = tipo() == 'A' ? "in0100c" : "in0100d";
 | 
						|
	else
 | 
						|
		nomeform = tipo() == 'A' ? "in0100a" : "in0100b";
 | 
						|
	TStampaIntra_form form((const char*) nomeform, tipo(), frequenza(anno_s), periodo(), anno_s, solofronte());
 | 
						|
  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, TR("Stampa Riepiloghi"));
 | 
						|
  return 0;
 | 
						|
}    
 |