366 lines
		
	
	
		
			7.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			366 lines
		
	
	
		
			7.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include "cglib04.h"
 | 
						|
#include "cg2802.h"
 | 
						|
 | 
						|
HIDDEN int date2esc(const TDate& d, int* prevesc)
 | 
						|
{                   
 | 
						|
  if (prevesc) *prevesc = 0;
 | 
						|
  TTable esc("ESC");
 | 
						|
  for (int err = esc.first(); err == NOERR; err = esc.next())
 | 
						|
  {
 | 
						|
    const TDate ia(esc.get("D0"));   // Data inizio esercizio
 | 
						|
    const TDate fa(esc.get("D1"));   // Data fine esercizio
 | 
						|
    const anno = esc.get_int("CODTAB");  
 | 
						|
    if (d >= ia && d <= fa)
 | 
						|
      return anno;
 | 
						|
    if (prevesc) *prevesc = anno; 
 | 
						|
  } 
 | 
						|
  return 0;
 | 
						|
}
 | 
						|
 | 
						|
bool TAnn_mov::create()
 | 
						|
{
 | 
						|
  TApplication::create();
 | 
						|
 | 
						|
  _pcon     = new TLocalisamfile (LF_PCON);
 | 
						|
  _clifo    = new TLocalisamfile (LF_CLIFO);
 | 
						|
  _mov      = new TLocalisamfile (LF_MOV);  
 | 
						|
  
 | 
						|
  TString80 tmpmov = "%";
 | 
						|
  tmpmov  << get_firm_dir();
 | 
						|
  tmpmov << "\\" << TEMP_MOV;
 | 
						|
  TString80 tmprmov = "%";
 | 
						|
  tmprmov << get_firm_dir();         
 | 
						|
  tmprmov << "\\" << TEMP_RMOV;  
 | 
						|
  TString80 tmprmoviva = "%";
 | 
						|
  tmprmoviva << get_firm_dir();     
 | 
						|
  tmprmoviva << "\\" << TEMP_RMOVIVA;                     
 | 
						|
  
 | 
						|
  _tmov     = new TIsamtempfile(LF_MOV, tmpmov, 0);
 | 
						|
  _trmov    = new TIsamtempfile(LF_RMOV, tmprmov, 0);
 | 
						|
  _tiva     = new TIsamtempfile(LF_RMOVIVA, tmprmoviva, 0);
 | 
						|
 | 
						|
  _rec_mov  = new TRectype (LF_MOV);  
 | 
						|
  
 | 
						|
  dispatch_e_menu (BAR_ITEM(1));
 | 
						|
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TAnn_mov::destroy()
 | 
						|
{
 | 
						|
  delete _pcon;
 | 
						|
  delete _clifo;
 | 
						|
  delete _mov;
 | 
						|
  
 | 
						|
  delete _tmov;                  
 | 
						|
  delete _trmov;
 | 
						|
  delete _tiva;
 | 
						|
 | 
						|
  delete _rec_mov;  
 | 
						|
  
 | 
						|
  return TApplication::destroy();
 | 
						|
}                                
 | 
						|
 | 
						|
bool TAnn_mov::set()
 | 
						|
{
 | 
						|
  _dittaric = get_firm();
 | 
						|
  
 | 
						|
  if (!esegui_controlli()) return FALSE;
 | 
						|
  
 | 
						|
  if (!video())
 | 
						|
    return FALSE;
 | 
						|
  
 | 
						|
  return FALSE;
 | 
						|
}
 | 
						|
 | 
						|
bool TAnn_mov::video()
 | 
						|
{   
 | 
						|
  TMask msk ("cg2802a");
 | 
						|
  KEY     tasto;
 | 
						|
  
 | 
						|
  do
 | 
						|
  { 
 | 
						|
    tasto = msk.run();
 | 
						|
    
 | 
						|
    if (tasto != K_ENTER) return FALSE;
 | 
						|
    
 | 
						|
    if (esiste_testata_mov(msk))
 | 
						|
    {
 | 
						|
      TMask mask ("cg2802b");
 | 
						|
      
 | 
						|
      mask.set_handler(F_REGIVA,    codice_registro_hnd);
 | 
						|
      mask.set_handler(F_CODCAUS,   codice_causale_hnd);  
 | 
						|
      
 | 
						|
      setta_campi_maschera(mask);
 | 
						|
      
 | 
						|
      tasto = mask.run();
 | 
						|
      
 | 
						|
      switch (tasto)
 | 
						|
      {
 | 
						|
      case K_ESC :
 | 
						|
        break;
 | 
						|
        
 | 
						|
      case K_QUIT :
 | 
						|
        break;       
 | 
						|
        
 | 
						|
      case K_SAVE :
 | 
						|
      {
 | 
						|
        annulla(mask);
 | 
						|
      }
 | 
						|
        break;
 | 
						|
        
 | 
						|
      default:
 | 
						|
        break;
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
  while (tasto != K_QUIT);                              //K_ENTER
 | 
						|
  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TAnn_mov::esiste_testata_mov(TMask& m)
 | 
						|
{
 | 
						|
  long nrec;
 | 
						|
  
 | 
						|
  _numreg = m.get_long(F_NUMREG);
 | 
						|
  
 | 
						|
  _tmov->setkey(1);
 | 
						|
  _tmov->zero();
 | 
						|
  _tmov->put(MOV_NUMREG, _numreg);
 | 
						|
  
 | 
						|
  if (_tmov->read() == NOERR)
 | 
						|
  { 
 | 
						|
    nrec = _tmov->get_long(MOV_NUMGIO);
 | 
						|
    nrec += _tras_file.start('Z');
 | 
						|
    
 | 
						|
    _tras_file.read_rec_trasfer(nrec);
 | 
						|
    _record = _tras_file.read_rec();
 | 
						|
    
 | 
						|
    char annullato = _record.sub(248,249)[0];
 | 
						|
    
 | 
						|
    if (annullato == 'A')
 | 
						|
      return error_box("Registrazione presente ma gia' ANNULLATA in precedenza");
 | 
						|
    
 | 
						|
    *_rec_mov = _tmov->curr();  
 | 
						|
  }
 | 
						|
  else
 | 
						|
    return error_box("Registrazione richiesta NON PRESENTE tra i movimenti in trasferimento");
 | 
						|
  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
void TAnn_mov::setta_campi_maschera(TMask& m)
 | 
						|
{  
 | 
						|
  TDate   datareg (_rec_mov->get_date(MOV_DATAREG));
 | 
						|
  TDate   datadoc (_rec_mov->get_date(MOV_DATADOC));
 | 
						|
  TString numdoc    = _rec_mov->get     (MOV_NUMDOC);
 | 
						|
  TString regiva    = _rec_mov->get     (MOV_REG);
 | 
						|
  regiva.trim();
 | 
						|
  long    protiva   = _rec_mov->get_long(MOV_PROTIVA);
 | 
						|
  TString codcaus   = _rec_mov->get     (MOV_CODCAUS);
 | 
						|
  
 | 
						|
  m.set(F_NUMREG,    _numreg);
 | 
						|
  m.set(F_DATAREG,   datareg.string());
 | 
						|
  m.set(F_DATADOC,   datadoc.string());
 | 
						|
  m.set(F_NUMDOC,    numdoc);
 | 
						|
  m.set(F_REGIVA,    regiva);
 | 
						|
  m.set(F_PROTIVA,   protiva);
 | 
						|
  m.set(F_CODCAUS,   codcaus);
 | 
						|
 | 
						|
  m.disable(F_NUMREG);
 | 
						|
  m.disable(F_DATAREG);
 | 
						|
  m.disable(F_DATADOC);
 | 
						|
  m.disable(F_NUMDOC);
 | 
						|
  m.disable(F_REGIVA);
 | 
						|
  m.disable(F_PROTIVA);
 | 
						|
  m.disable(F_CODCAUS);
 | 
						|
}   
 | 
						|
 | 
						|
void TAnn_mov::annulla(TMask& m)
 | 
						|
{
 | 
						|
  TRectype* rec_rmov,* rec_riva;
 | 
						|
  rec_rmov = new TRectype (LF_RMOV);
 | 
						|
 | 
						|
  long numreg = m.get_long(F_NUMREG);
 | 
						|
  
 | 
						|
  _trmov->setkey(1);
 | 
						|
  _trmov->zero();
 | 
						|
  _trmov->put(RMV_NUMREG, numreg); 
 | 
						|
  *rec_rmov = _trmov->curr();
 | 
						|
  
 | 
						|
  for (_trmov->read(); !_trmov->eof(); _trmov->next())
 | 
						|
  {
 | 
						|
    if (_trmov->curr() > *rec_rmov) break;
 | 
						|
    
 | 
						|
    long numrec = _trmov->get_int(RMV_ANNOES);
 | 
						|
    numrec += _tras_file.start('Z');
 | 
						|
    
 | 
						|
    _tras_file.read_rec_trasfer(numrec); //Leggo il record della prima nota
 | 
						|
    
 | 
						|
    _tras_file.put("A","Z1",51,numrec);
 | 
						|
    
 | 
						|
    _tras_file.write(numrec);
 | 
						|
  }
 | 
						|
  
 | 
						|
  delete rec_rmov;
 | 
						|
  
 | 
						|
  rec_riva = new TRectype (LF_RMOVIVA);
 | 
						|
 | 
						|
  _tiva->setkey(1);
 | 
						|
  _tiva->zero();
 | 
						|
  _tiva->put(RMI_NUMREG, numreg); 
 | 
						|
  *rec_riva = _tiva->curr();
 | 
						|
  
 | 
						|
  for (_tiva->read(); !_tiva->eof(); _tiva->next())
 | 
						|
  {
 | 
						|
    if (_tiva->curr() > *rec_riva) break;
 | 
						|
    
 | 
						|
    long numrec = _tiva->get_int(RMI_ANNOES);
 | 
						|
    numrec += _tras_file.start('U');
 | 
						|
    
 | 
						|
    _tras_file.read_rec_trasfer(numrec); //Leggo il record della prima nota
 | 
						|
    
 | 
						|
    _tras_file.put("A","U1",51,numrec);
 | 
						|
    
 | 
						|
    _tras_file.write(numrec);
 | 
						|
  }
 | 
						|
  
 | 
						|
  delete rec_riva;  
 | 
						|
}
 | 
						|
 | 
						|
bool TAnn_mov::leggi_trasfer()
 | 
						|
{ 
 | 
						|
  _trasf = _tras_file.path(_dittaric);
 | 
						|
  _trasf << "\\trasfer";
 | 
						|
  
 | 
						|
  _tras_file.open(_trasf);
 | 
						|
  
 | 
						|
  if (_tras_file.exist())
 | 
						|
  {  
 | 
						|
    if (_tras_file.read_control_rec())
 | 
						|
      _control_rec = _tras_file.record();
 | 
						|
    else
 | 
						|
      return error_box("Rilevati gravi errori negli archivi:procedura interrotta");
 | 
						|
  } 
 | 
						|
  else
 | 
						|
    return error_box("Al momento non presenti trasferimenti attivi sulla ditta selezionata");
 | 
						|
  
 | 
						|
  return TRUE; 
 | 
						|
}
 | 
						|
 | 
						|
bool TAnn_mov::codice_registro_hnd(TMask_field& f, KEY k)
 | 
						|
{ 
 | 
						|
  TTable reg ("REG");
 | 
						|
  TString descr,dep;
 | 
						|
  
 | 
						|
  if (k == K_TAB)
 | 
						|
  {              
 | 
						|
    TString codreg = f.get();
 | 
						|
    char    cr     = codreg[0];
 | 
						|
    TDate   datareg (f.mask().get(F_DATAREG));
 | 
						|
    int     anno   = date2esc(datareg);
 | 
						|
    
 | 
						|
    if (isdigit(cr)) 
 | 
						|
      dep.format("%04d%03c", anno, cr);
 | 
						|
    else
 | 
						|
      dep.format("%04d%-3c", anno, cr);
 | 
						|
    
 | 
						|
    reg.zero();
 | 
						|
    reg.put("CODTAB", dep);
 | 
						|
    if (reg.read() == NOERR)
 | 
						|
    {
 | 
						|
      descr = reg.get("S0");
 | 
						|
      f.mask().set(F_DESCRREG, descr);
 | 
						|
    }
 | 
						|
  } 
 | 
						|
  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TAnn_mov::codice_causale_hnd(TMask_field& f, KEY k)
 | 
						|
{
 | 
						|
  TLocalisamfile cau (LF_CAUSALI);
 | 
						|
  TString descr;
 | 
						|
  
 | 
						|
  if (k == K_TAB)
 | 
						|
  {         
 | 
						|
    TString codcau = f.get();
 | 
						|
    
 | 
						|
    cau.setkey(1);
 | 
						|
    cau.zero();
 | 
						|
    cau.put("CODCAUS", codcau);
 | 
						|
    if (cau.read() == NOERR)
 | 
						|
    {
 | 
						|
      descr = cau.get("DESCR");
 | 
						|
      f.mask().set(F_DESCRCAU, descr);
 | 
						|
    }                                 
 | 
						|
  }            
 | 
						|
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TAnn_mov::esegui_controlli()
 | 
						|
{                    
 | 
						|
  TConfig conf(CONFIG_DITTA);           
 | 
						|
  
 | 
						|
  _std = conf.get("FlStTra");
 | 
						|
 | 
						|
  if (!prefix().exist(_dittaric))
 | 
						|
    return error_box("Rilevati GRAVI ERRORI negli archivi: procedura interrotta");
 | 
						|
 | 
						|
  if (!leggi_trasfer())
 | 
						|
    return FALSE;      
 | 
						|
  
 | 
						|
  if (!controlli())
 | 
						|
    return FALSE;
 | 
						|
  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TAnn_mov::controlli()
 | 
						|
{ 
 | 
						|
  if (_std == "M")
 | 
						|
    return error_box("Variazione NON POSSIBILE: trasferimento movimenti gia' iniziato");           
 | 
						|
  
 | 
						|
  if (_std == "*") 
 | 
						|
  {
 | 
						|
    warning_box("Trasferimento interamente completato: proseguire per cancellare il file");    
 | 
						|
    fremove(_trasf);
 | 
						|
    setta_parametri_record(""," ",FALSE);
 | 
						|
    return FALSE;
 | 
						|
  }
 | 
						|
  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
void TAnn_mov::leggi_record_controllo()
 | 
						|
{
 | 
						|
  _tras_file.read_control_rec();
 | 
						|
  _control_rec = _tras_file.record();
 | 
						|
}
 | 
						|
 | 
						|
void TAnn_mov::setta_parametri_record(const TString& sigla,const TString& flag,bool uselab)
 | 
						|
{ 
 | 
						|
  TConfig conf (CONFIG_DITTA);
 | 
						|
  
 | 
						|
  conf.set("FlStTra", flag);
 | 
						|
 | 
						|
  if (uselab)
 | 
						|
  {
 | 
						|
    leggi_record_controllo();
 | 
						|
    _control_rec.overwrite(sigla,240);
 | 
						|
    
 | 
						|
    const int size = 256;
 | 
						|
    
 | 
						|
    _tras_file.write_control_rec(_control_rec, size);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
bool TAnn_mov::menu(MENU_TAG m)
 | 
						|
{
 | 
						|
  if (m == BAR_ITEM(1))
 | 
						|
    return set(); 
 | 
						|
  return FALSE;
 | 
						|
}
 |