162 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			162 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <relation.h>
 | 
						|
#include <urldefid.h>
 | 
						|
 | 
						|
#include "sv2.h"
 | 
						|
#include "svlib01.h"
 | 
						|
#include "sv2100a.h"
 | 
						|
 | 
						|
#include "svriep.h"
 | 
						|
 | 
						|
class TRicalcolo_stats : public TApplication
 | 
						|
{
 | 
						|
  TArray _file;  // Array dei files aperti
 | 
						|
  TStats_agg _agg;
 | 
						|
 | 
						|
  void open_files(int logicnum, ...) ;
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual bool menu(MENU_TAG mt);
 | 
						|
  virtual bool create();
 | 
						|
  virtual bool destroy();
 | 
						|
  virtual void on_config_change();
 | 
						|
  
 | 
						|
public:
 | 
						|
  bool kill_stats(const TDate& dfr, const TDate& dto);
 | 
						|
  void calc_stats(const TDate& dfr, const TDate& dto);
 | 
						|
};
 | 
						|
 | 
						|
 | 
						|
void TRicalcolo_stats::open_files(int logicnum, ...)  
 | 
						|
{  
 | 
						|
  va_list marker;
 | 
						|
  va_start(marker, logicnum);
 | 
						|
  while (logicnum > 0)
 | 
						|
  {
 | 
						|
    CHECKD(_file.objptr(logicnum) == NULL, "File gia' aperto: ", logicnum);
 | 
						|
    _file.add(new TLocalisamfile(logicnum), logicnum);
 | 
						|
    logicnum = va_arg(marker, int);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
bool TRicalcolo_stats::create()
 | 
						|
{ 
 | 
						|
  open_files(LF_TABCOM, 0);                       // File comuni
 | 
						|
  open_files(LF_TAB, LF_CLIFO, LF_OCCAS, 0);      // File ditta
 | 
						|
  open_files(LF_CFVEN, LF_DOC, LF_RIGHEDOC, 0);   // File vendite
 | 
						|
  open_files(LF_SVRIEP, 0);                       // File statistiche
 | 
						|
            
 | 
						|
  dispatch_e_menu(BAR_ITEM(1));
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
void TRicalcolo_stats::on_config_change()
 | 
						|
{
 | 
						|
  _agg.init();
 | 
						|
}
 | 
						|
 | 
						|
bool TRicalcolo_stats::destroy()
 | 
						|
{
 | 
						|
  _file.destroy();
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TRicalcolo_stats::kill_stats(const TDate& dfr, const TDate& dto)
 | 
						|
{ 
 | 
						|
  TRelation rel(LF_SVRIEP);
 | 
						|
                          
 | 
						|
  TRectype recfrom(LF_SVRIEP), recto(LF_SVRIEP);
 | 
						|
  
 | 
						|
  if (dfr.ok())              
 | 
						|
  {
 | 
						|
    recfrom.put(SVR_ANNO, dfr.year());
 | 
						|
    recfrom.put(SVR_PERIODO, _agg.date2period(dfr));
 | 
						|
  }
 | 
						|
  if (dto.ok())              
 | 
						|
  {
 | 
						|
    recto.put(SVR_ANNO, dto.year());
 | 
						|
    recto.put(SVR_PERIODO, _agg.date2period(dto));
 | 
						|
  }
 | 
						|
  
 | 
						|
  TCursor cur(&rel, "", 1, &recfrom, &recto);
 | 
						|
  const long items = cur.items();
 | 
						|
  TProgind pi(items, "Azzeramento statistiche", FALSE, TRUE, 60);
 | 
						|
  cur.freeze();
 | 
						|
  
 | 
						|
  int err = NOERR;
 | 
						|
  for (cur = 0; cur.pos() < items; ++cur)
 | 
						|
  {             
 | 
						|
    pi.addstatus(1);
 | 
						|
    err = cur.file().remove();
 | 
						|
    if (err != NOERR)
 | 
						|
      break;
 | 
						|
  }  
 | 
						|
  
 | 
						|
  return err == NOERR;  
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void TRicalcolo_stats::calc_stats(const TDate& dfr, const TDate& dto)
 | 
						|
{
 | 
						|
  TRectype recfrom(LF_DOC), recto(LF_DOC);
 | 
						|
  recfrom.put(DOC_DATADOC, dfr);
 | 
						|
  if (dto.ok())
 | 
						|
    recto.put(DOC_DATADOC, dto);
 | 
						|
  
 | 
						|
  TRelation rel(LF_DOC);
 | 
						|
  TCursor cur(&rel, "PROVV='D'", 3, &recfrom, &recto);
 | 
						|
  const long items = cur.items();
 | 
						|
  TProgind pi(items, "Ricalcolo statistiche", FALSE, TRUE, 60);
 | 
						|
  
 | 
						|
  TDocumento* curr = new TDocumento;
 | 
						|
  cur.file().set_curr(curr);
 | 
						|
  const TDocumento& doc = *curr;
 | 
						|
  
 | 
						|
  long records = 0;
 | 
						|
  _agg.reset();  
 | 
						|
  
 | 
						|
  for (cur = 0; cur.pos() < items; ++cur)
 | 
						|
  {                         
 | 
						|
    pi.addstatus(1);
 | 
						|
    
 | 
						|
    const TTipo_documento& tipodoc = doc.tipo();
 | 
						|
    if (!tipodoc.statistiche())
 | 
						|
      continue;   
 | 
						|
      
 | 
						|
    for (int r = doc.physical_rows(); r > 0; r--)  
 | 
						|
    {
 | 
						|
      const TRiga_documento& rdoc = doc[r];
 | 
						|
      _agg.add(rdoc);
 | 
						|
    }
 | 
						|
    
 | 
						|
    records++;
 | 
						|
    if (records % 1000 == 0)  
 | 
						|
      _agg.update();
 | 
						|
  }
 | 
						|
  _agg.update();
 | 
						|
  if (_agg.empty())
 | 
						|
    message_box("Attenzione: l'archivio riepilogativo delle statistiche ora ricalcolato risulta vuoto");
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TRicalcolo_stats::menu(MENU_TAG)
 | 
						|
{ 
 | 
						|
  TMask m("sv2100a");
 | 
						|
  while (m.run() == K_ENTER)
 | 
						|
  {
 | 
						|
    const TDate dfr(m.get(F_FROMDATE));
 | 
						|
    const TDate dto(m.get(F_TODATE));
 | 
						|
    if (kill_stats(dfr, dto))
 | 
						|
      calc_stats(dfr, dto);
 | 
						|
  }
 | 
						|
  return FALSE;
 | 
						|
}
 | 
						|
 | 
						|
int sv2100(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TRicalcolo_stats app;
 | 
						|
  app.run(argc, argv, "Ricalcolo statistiche");
 | 
						|
  return 0;
 | 
						|
}
 |