177 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			177 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
//*****************************************************
 | 
						|
//* Aggiornamento codice attivita' su progressivi IVA *
 | 
						|
//*****************************************************
 | 
						|
#include <mask.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <tabutil.h>
 | 
						|
 | 
						|
#include <mov.h>
 | 
						|
 | 
						|
#include "cg1300.h"  
 | 
						|
#include "cg1304.h"
 | 
						|
#include "cglib01.h"
 | 
						|
 | 
						|
// HIDDEN TAgg_codatt& app() { return (TAgg_codatt&) main_app(); }
 | 
						|
 | 
						|
bool TAgg_codatt::create()
 | 
						|
{
 | 
						|
  open_files(LF_TAB, 0);
 | 
						|
 | 
						|
  return TSkeleton_application::create();
 | 
						|
}
 | 
						|
 | 
						|
bool TAgg_codatt::destroy()
 | 
						|
{ 
 | 
						|
  return TSkeleton_application::destroy();
 | 
						|
}                                
 | 
						|
 | 
						|
void TAgg_codatt::main_loop()
 | 
						|
{
 | 
						|
  TProgind* pri;
 | 
						|
  TMask msk("cg1300c");
 | 
						|
  
 | 
						|
  while (msk.run() == K_ENTER)
 | 
						|
  {
 | 
						|
    pri = new TProgind(2,TR("Aggiornamento in corso..."),FALSE,TRUE,50);
 | 
						|
    _pass = msk.get_bool(F_PASS);
 | 
						|
    if (_pass)
 | 
						|
    {   
 | 
						|
      _anno = msk.get_int(F_ANNO);   
 | 
						|
      _da   = msk.get(F_DA);  //se c'e' _da c'e' anche _a e viceversa
 | 
						|
      _a    = msk.get(F_A);   //_da e' la vecchia attivita'
 | 
						|
      //_a e' la nuova attivita'
 | 
						|
      pri->addstatus(1);
 | 
						|
      aggiorna_att("PIM");
 | 
						|
      aggiorna_att("PUM");
 | 
						|
      aggiorna_att("POM");        
 | 
						|
      aggiorna_att("PAM");
 | 
						|
      aggiorna_att("PPA");
 | 
						|
      aggiorna_att("%PLA");
 | 
						|
      aggiorna_att("PLM");
 | 
						|
    }
 | 
						|
    else 
 | 
						|
    {
 | 
						|
      pri->addstatus(1);
 | 
						|
      cancella_rec();
 | 
						|
    }  
 | 
						|
    pri->addstatus(1);
 | 
						|
    msk.reset();
 | 
						|
    //msk.reset(F_ANNO);    
 | 
						|
    //msk.reset(F_DA);
 | 
						|
    //msk.reset(F_A);
 | 
						|
    delete pri;
 | 
						|
    message_box(TR("Aggiornamento codice attivita' completato"));
 | 
						|
  }         
 | 
						|
}  
 | 
						|
 | 
						|
void TAgg_codatt::cancella_rec()
 | 
						|
{
 | 
						|
  TTable plm("PLM"); 
 | 
						|
  for (plm.first(); !plm.eof(); plm.next()) 
 | 
						|
    plm.remove();
 | 
						|
 | 
						|
  TTable pum("PUM");
 | 
						|
  for (pum.first(); !pum.eof(); pum.next()) 
 | 
						|
    pum.remove();
 | 
						|
  
 | 
						|
  TTable pom("POM");  
 | 
						|
  for (pom.first(); !pom.eof(); pom.next()) 
 | 
						|
    pom.remove(); 
 | 
						|
 | 
						|
  TTable pam("PAM");    
 | 
						|
  for (pam.first(); !pam.eof(); pam.next()) 
 | 
						|
    pam.remove();
 | 
						|
 | 
						|
  TTable ppa("PPA");
 | 
						|
  for (ppa.first(); !ppa.eof(); ppa.next()) 
 | 
						|
    ppa.remove(); 
 | 
						|
 | 
						|
  //non e' indicata la vecchia attivita' => :
 | 
						|
  TTable pim("PIM");
 | 
						|
  for (pim.first(); !pim.eof(); pim.next()) 
 | 
						|
  {
 | 
						|
    const TString80 codtab = pim.get("CODTAB");
 | 
						|
    int anno = atoi(codtab.mid(0,4));
 | 
						|
    const TString16 codatt = codtab.mid(4,5);
 | 
						|
    const TString16 codreg = codtab.mid(10,3);
 | 
						|
    if (codreg.not_empty())
 | 
						|
    {
 | 
						|
      TRegistro reg(codreg,anno);
 | 
						|
      if (!reg.name().empty()) //se esiste quel registro (ma perche' non dovrebbe?)
 | 
						|
      {
 | 
						|
        const TString16 cda = reg.attivita();
 | 
						|
        if (codatt != cda)
 | 
						|
        {
 | 
						|
          TRectype vecchio (pim.curr());
 | 
						|
          TRectype nuovo (pim.curr());
 | 
						|
          const TString80 cc = codtab.sub(9);
 | 
						|
          TString80 cod;
 | 
						|
          cod << anno << cda << cc;
 | 
						|
          nuovo.put("CODTAB", cod);
 | 
						|
          pim.write(nuovo);
 | 
						|
          pim.read(vecchio);
 | 
						|
          pim.remove(); 
 | 
						|
        }    
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
  
 | 
						|
  TTable pla("%PLA");
 | 
						|
  TRecfield r_ditta(pla.curr(),"CODTAB",0,4);
 | 
						|
  const long firm = get_firm();
 | 
						|
  for (pla.first(); !pla.eof(); pla.next())
 | 
						|
  {
 | 
						|
    if (firm != (long)r_ditta)
 | 
						|
      continue;
 | 
						|
    pla.remove();
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TAgg_codatt::aggiorna_att(const char* nome)
 | 
						|
{
 | 
						|
  const bool is_pla = nome == "%PLA";
 | 
						|
  const long firm = get_firm();
 | 
						|
  TTable tab(nome); 
 | 
						|
  tab.setkey(1);
 | 
						|
  tab.zero();
 | 
						|
  TString16 chiave; 
 | 
						|
  TString16 old_att(_da); old_att.right_just(5,'0');
 | 
						|
  TString16 new_att(_a); new_att.right_just(5,'0');
 | 
						|
  if (is_pla) chiave << firm;
 | 
						|
  chiave << _anno << old_att;
 | 
						|
  tab.put("CODTAB", chiave);
 | 
						|
  TRectype curr (tab.curr());
 | 
						|
  TRecfield r_ditta(tab.curr(),"CODTAB",0,4);
 | 
						|
  tab.read(_isgteq);
 | 
						|
  for (; !tab.eof(); tab.next())
 | 
						|
  {
 | 
						|
    if (is_pla)
 | 
						|
    {
 | 
						|
      if (firm != (long)r_ditta) break;
 | 
						|
    }
 | 
						|
    else
 | 
						|
      if (tab.curr() != curr) break;
 | 
						|
    
 | 
						|
    const TString80 codtab = tab.get("CODTAB");
 | 
						|
    //const TString16 cod_att = codtab.mid(4,5); //e' uguale a old_att
 | 
						|
    if (old_att != new_att)
 | 
						|
    {
 | 
						|
      TRectype vecchio (tab.curr());
 | 
						|
      TRectype nuovo (tab.curr());
 | 
						|
      TString80 cc;
 | 
						|
      if (is_pla)
 | 
						|
        cc = codtab.sub(13);
 | 
						|
      else
 | 
						|
        cc = codtab.sub(9);
 | 
						|
      TString80 cod;
 | 
						|
      if (is_pla) cod << firm;
 | 
						|
      cod << _anno << new_att << cc;
 | 
						|
      nuovo.put("CODTAB", cod);
 | 
						|
      tab.write(nuovo);
 | 
						|
      tab.read(vecchio);
 | 
						|
      tab.remove();
 | 
						|
    }  
 | 
						|
  }
 | 
						|
}  
 | 
						|
 |