Files correlati : Ricompilazione Demo : [ ] Commento :aggiunti files discolatio alla 32 bit git-svn-id: svn://10.65.10.50/trunk@11035 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			303 lines
		
	
	
		
			9.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			303 lines
		
	
	
		
			9.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						|
#include <assoc.h>
 | 
						|
#include <automask.h>
 | 
						|
#include <form.h>
 | 
						|
#include <printer.h>
 | 
						|
#include <recarray.h>
 | 
						|
#include <sort.h>
 | 
						|
#include <strings.h>
 | 
						|
#include <utility.h>
 | 
						|
 | 
						|
#include "..\mg\anamag.h"
 | 
						|
#include "..\mg\mglib.h"
 | 
						|
#include "..\mg\movmag.h"
 | 
						|
#include "..\mg\rmovmag.h"
 | 
						|
#include "dl0.h"
 | 
						|
#include "dl0700a.h"
 | 
						|
#include "dl0700.h"
 | 
						|
 | 
						|
//-----FORM--------------------------------------------------------------------------------------//
 | 
						|
 | 
						|
class TTopten_form : public TForm
 | 
						|
{
 | 
						|
 | 
						|
public:
 | 
						|
  virtual bool validate(TForm_item &cf, TToken_string &s);
 | 
						|
  void set_testata() {set_header(1,TRUE);}
 | 
						|
  void set_pedata() {set_footer(1,FALSE); set_footer(1,TRUE);}
 | 
						|
  TPrint_section& get_line() {return section('B', odd_page);}
 | 
						|
  TTopten_form();
 | 
						|
 | 
						|
  virtual ~TTopten_form();
 | 
						|
};
 | 
						|
  
 | 
						|
TTopten_form::TTopten_form() :TForm ("dl0700a")
 | 
						|
{
 | 
						|
} 
 | 
						|
 | 
						|
TTopten_form::~TTopten_form()
 | 
						|
{ 
 | 
						|
}
 | 
						|
 | 
						|
bool TTopten_form::validate(TForm_item &cf, TToken_string &s)
 | 
						|
{
 | 
						|
  return TForm::validate(cf,s);
 | 
						|
}
 | 
						|
 | 
						|
//-----AUTOMASK---------------------------------------------------------------------------------//
 | 
						|
  
 | 
						|
class TTopten_mask : public TAutomask
 | 
						|
{
 | 
						|
  TRelation * _rel;
 | 
						|
  TCursor * _cur;
 | 
						|
 | 
						|
protected:
 | 
						|
  bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
public:
 | 
						|
 | 
						|
  TTopten_mask();
 | 
						|
  
 | 
						|
  virtual ~TTopten_mask(){};
 | 
						|
};
 | 
						|
  
 | 
						|
TTopten_mask::TTopten_mask() :TAutomask ("dl0700a")
 | 
						|
{
 | 
						|
}  
 | 
						|
  
 | 
						|
bool TTopten_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{ 
 | 
						|
  switch (o.dlg())
 | 
						|
  {
 | 
						|
  case F_RIGHE:
 | 
						|
    if (e == fe_close)
 | 
						|
    { 
 | 
						|
      TSheet_field& sheet = sfield(F_RIGHE);
 | 
						|
      FOR_EACH_SHEET_ROW (sheet, r, row)   //scansione di tutte le righe dello sheet
 | 
						|
      { 
 | 
						|
        TString8 supporto = row->get(F_SUPPORTO-FIRST_FIELD);
 | 
						|
        if (supporto.blank())
 | 
						|
          return error_box("Indicare il tipo supporto nella riga %d",r+1);
 | 
						|
      }
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  } 
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
//-----SKELETON APPLICATION------------------------------------------------------------------------------------------//
 | 
						|
 | 
						|
class TTopten : public TSkeleton_application
 | 
						|
{
 | 
						|
  TTopten_mask * _mask;
 | 
						|
  TTopten_form * _form;
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual bool create();
 | 
						|
  virtual bool destroy();
 | 
						|
  virtual void main_loop();
 | 
						|
 | 
						|
  void print_header();
 | 
						|
  void print_footer();
 | 
						|
  void print_line(const TString& r, const long j);
 | 
						|
 | 
						|
public:
 | 
						|
  TTopten() {}
 | 
						|
};
 | 
						|
 | 
						|
 | 
						|
bool TTopten::create()
 | 
						|
{
 | 
						|
  open_files(LF_MOVMAG, LF_RMOVMAG, LF_ANAMAG, LF_UMART, LF_MAG, 0);
 | 
						|
  _mask = new TTopten_mask;
 | 
						|
  _form = new TTopten_form();
 | 
						|
  
 | 
						|
  return TSkeleton_application::create();
 | 
						|
}
 | 
						|
 | 
						|
bool TTopten::destroy()
 | 
						|
{
 | 
						|
  delete _mask;
 | 
						|
  delete _form;
 | 
						|
  return TSkeleton_application::destroy();
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void TTopten::print_header()
 | 
						|
{
 | 
						|
  _form->set_testata();
 | 
						|
}
 | 
						|
 | 
						|
void TTopten::print_footer()
 | 
						|
{
 | 
						|
  _form->set_pedata();
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void TTopten::print_line(const TString& result, const long j)
 | 
						|
{
 | 
						|
  TString8 nriga; nriga.format("%4ld",j);
 | 
						|
  TString codart = result.left(20);      //codice articolo
 | 
						|
  codart.trim();
 | 
						|
  TString supporto = result.mid(20,2);   //tipo supporto
 | 
						|
  supporto.trim();
 | 
						|
  real venduto(result.mid(22, 20));        //quantita' venduta
 | 
						|
  real giacenza(result.mid(42, 20));       //giacenza
 | 
						|
 | 
						|
  TString titolo = cache().get(LF_ANAMAG, codart, ANAMAG_DESCR);      //titolo
 | 
						|
  TString artista = cache().get(LF_ANAMAG, codart, ANAMAG_USER2);     //artista
 | 
						|
  TString genere = cache().get(LF_ANAMAG, codart, ANAMAG_GRMERC);     //genere
 | 
						|
 | 
						|
  TPrint_section& section = _form->get_line();
 | 
						|
  _form->find_field('B', odd_page, FF_B_POSIZIONE).set(nriga);
 | 
						|
  _form->find_field('B', odd_page, FF_B_CODART).set(codart);
 | 
						|
  _form->find_field('B', odd_page, FF_B_GIAC).set(giacenza.string());
 | 
						|
  _form->find_field('B', odd_page, FF_B_TITOLO).set(titolo);
 | 
						|
  _form->find_field('B', odd_page, FF_B_ARTISTA).set(artista);
 | 
						|
  _form->find_field('B', odd_page, FF_B_TOTVEND).set(venduto.string());
 | 
						|
  _form->find_field('B', odd_page, FF_B_GENERE).set(genere);
 | 
						|
  _form->find_field('B', odd_page, FF_B_SUPPORTO).set(supporto);
 | 
						|
  
 | 
						|
  section.update();
 | 
						|
  for (word i = 0; i < section.height(); i++)
 | 
						|
   printer().print(section.row(i));
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void TTopten::main_loop()
 | 
						|
{  
 | 
						|
  TSheet_field& sheet = _mask->sfield(F_RIGHE); //crea lo sheet non vuoto
 | 
						|
  sheet.row(0);
 | 
						|
  
 | 
						|
  while (_mask->run() == K_ENTER)
 | 
						|
  {
 | 
						|
    TRelation rel(LF_MOVMAG);    //relazione: file principale rmovmag
 | 
						|
  
 | 
						|
    TDate dataini = _mask->get_date(F_DATAINI);
 | 
						|
    TDate datafine = _mask->get_date(F_DATAFINE);
 | 
						|
    
 | 
						|
    TRectype darec(LF_MOVMAG), arec(LF_MOVMAG);
 | 
						|
    darec.put(MOVMAG_DATAREG, dataini);
 | 
						|
    arec.put(MOVMAG_DATAREG, datafine);
 | 
						|
    
 | 
						|
    TCursor cursore (&rel, "", 3, &darec, &arec);      //scandisce i movimenti con la chiave 2 e codreg 
 | 
						|
    long nitems = cursore.items();                     //incluso nell'intervallo date
 | 
						|
    cursore.freeze();
 | 
						|
    
 | 
						|
    TRectype riga(LF_RMOVMAG);
 | 
						|
    TRecord_array righemov(111,RMOVMAG_NRIG);    //clamoroso recordarray del file 111 (rmovmag)
 | 
						|
    
 | 
						|
    FOR_EACH_SHEET_ROW (sheet, r, row)   //scansione di tutte le righe dello sheet
 | 
						|
    {
 | 
						|
      TAssoc_array topten, topgiac;       //assoc_array che conterranno tutti i record da sortare e stampare
 | 
						|
      const TString8 currsupporto = row->get(F_SUPPORTO-FIRST_FIELD);
 | 
						|
      const TString8 currgenere = row->get(F_GENERE-FIRST_FIELD);
 | 
						|
      const real currdaprezzo = row->get(F_DAPREZZO-FIRST_FIELD);
 | 
						|
      const real curraprezzo = row->get(F_APREZZO-FIRST_FIELD);
 | 
						|
      
 | 
						|
      for (cursore=0;cursore.pos()<nitems;++cursore)
 | 
						|
      { 
 | 
						|
        riga.put(RMOVMAG_NUMREG, cursore.curr().get(MOVMAG_NUMREG));  //per ogni movimento in testata
 | 
						|
        righemov.read(riga);                                          //scandisce tutte le sue righemov
 | 
						|
        for (int i=1; i<=righemov.rows(); i++)
 | 
						|
        {
 | 
						|
          TRectype& rigai = righemov[i];
 | 
						|
          TString8 codcaus = rigai.get(RMOVMAG_CODCAUS);
 | 
						|
          if (codcaus.empty())                                //se il codcaus della rigamov e' vuoto..
 | 
						|
            codcaus = cursore.curr().get(MOVMAG_CODCAUS);     //..lo cerca in testata
 | 
						|
                                                 
 | 
						|
          const TRectype& cau = cache().get("%CAU", codcaus);  //controlla se e' causale di vendita!
 | 
						|
          const int segno = atoi(cau.get("S2").mid(6, 2));
 | 
						|
          if (segno != 0)     //se e' una causale di vendita..
 | 
						|
          {
 | 
						|
            TString codart = rigai.get(RMOVMAG_CODART);              //prende il codart della riga in questione..
 | 
						|
            const TRectype& articolo = cache().get(LF_ANAMAG, codart);
 | 
						|
 | 
						|
            const TString& strdate =  articolo.get(ANAMAG_USER6); //controlla che la eventuale data "fuori catalogo"..
 | 
						|
            if (!real::is_null(strdate))                   //se la data e' 00000000 la vuota (e' meglio)
 | 
						|
            {
 | 
						|
              const TDate oldfashioned = strdate;                             //..sia superiore a dataini o nulla
 | 
						|
              if (oldfashioned < dataini)    //se non lo e' salta al prossimo articolo
 | 
						|
                continue;
 | 
						|
            }
 | 
						|
            
 | 
						|
            const real prezzo = rigai.get(RMOVMAG_PREZZO);        //controllo sui prezzi
 | 
						|
            if (prezzo < currdaprezzo)
 | 
						|
              continue;
 | 
						|
            if (prezzo > curraprezzo && curraprezzo > currdaprezzo)
 | 
						|
              continue;
 | 
						|
              
 | 
						|
            const TString16 umart = rigai.get(RMOVMAG_UM);           //..e sul supporto (um)
 | 
						|
            if (umart != currsupporto)                       
 | 
						|
              continue;
 | 
						|
            
 | 
						|
            if (!currgenere.blank())                             //..e sul genere
 | 
						|
            {  
 | 
						|
              const TString8 genere = articolo.get(ANAMAG_GRMERC);
 | 
						|
              if (genere != currgenere)
 | 
						|
                continue;
 | 
						|
            }
 | 
						|
            
 | 
						|
            codart.left_just(20);                                         //riempie codart in modo che sia 20..
 | 
						|
            codart << umart.left(2);                                 //..ed aggiunge il codice supporto alla stringa
 | 
						|
            real * venduto = (real *) topten.objptr(codart);
 | 
						|
  
 | 
						|
            if (venduto == NULL)
 | 
						|
            {                                                     //se e' un nuovo articolo..
 | 
						|
              venduto = new real;
 | 
						|
              topten.add(codart, venduto);                        //lo aggiunge all'assoc_array con chiave codart(codart+um!)
 | 
						|
              
 | 
						|
              TArticolo_giacenza articolo(codart);   
 | 
						|
              real giacenza = articolo.giacenza_anno("", "", datafine.year());    //anno di riferimento x la giacenza               
 | 
						|
              topgiac.add(codart, giacenza);
 | 
						|
            }
 | 
						|
            *venduto += segno*rigai.get_real(RMOVMAG_QUANT);            //quindi somma il venduto!
 | 
						|
          }
 | 
						|
        }
 | 
						|
  
 | 
						|
      } //fine ciclo scansione movimenti di magazzino
 | 
						|
      
 | 
						|
      // adesso si devono riordinare gli assoc_array in modo da avere i record in ordine di venduto decrescente
 | 
						|
      const int reclen = 62;        
 | 
						|
      TSort s(reclen);    
 | 
						|
      s.addsortkey(22, 20, 'd');
 | 
						|
      s.addsortkey(42, 20, 'd');
 | 
						|
      s.init();
 | 
						|
     
 | 
						|
      FOR_EACH_ASSOC_OBJECT (topten, hobj, chiave, venduto)
 | 
						|
      {                                                  
 | 
						|
        TString80 sortrec = chiave;
 | 
						|
        sortrec << ((real *) venduto)->string(20);    //ordinamento principale per venduto
 | 
						|
        
 | 
						|
        real giacenza = (real&)topgiac[chiave];       //ordinamento secondario per giacenza
 | 
						|
        sortrec << giacenza.string(20);
 | 
						|
        
 | 
						|
        s.sort(sortrec);
 | 
						|
      }                 
 | 
						|
      s.endsort();
 | 
						|
      
 | 
						|
      //scatta la stampa!
 | 
						|
      TString80 result;
 | 
						|
      const long nlinesmax = row->get_long(F_VISUAL-FIRST_FIELD);
 | 
						|
      long nlines = 0;
 | 
						|
      printer().open();
 | 
						|
      print_header();
 | 
						|
      print_footer();
 | 
						|
      for ( result.strncpy(s.retrieve(),reclen); result.not_empty(); result.strncpy(s.retrieve(),reclen))
 | 
						|
      { 
 | 
						|
        print_line(result, ++nlines);
 | 
						|
        if (nlinesmax > 0 && nlines >= nlinesmax)
 | 
						|
          break;
 | 
						|
      }
 | 
						|
      printer().close();
 | 
						|
    }
 | 
						|
  } 
 | 
						|
}
 | 
						|
   
 | 
						|
int dl0700(int argc, char* argv[])
 | 
						|
{ 
 | 
						|
  TTopten a;
 | 
						|
  a.run(argc,argv,"Top Ten");
 | 
						|
  return 0;
 | 
						|
} |