Files correlati : Ricompilazione Demo : [ ] Commento :migliorata la riattribuzione campi conai; adesso converte anche anamag e non si fa fregare dai codagg1/2 scritti alla organo di riproduzione maschile di canide git-svn-id: svn://10.65.10.50/trunk@19443 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			2320 lines
		
	
	
		
			59 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			2320 lines
		
	
	
		
			59 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <applicat.h>
 | ||
| #include <extcdecl.h>
 | ||
| #include <mailbox.h>
 | ||
| #include <progind.h>
 | ||
| #include <relation.h>
 | ||
| #include <reputils.h>
 | ||
| #include <sheet.h>
 | ||
| #include <tabutil.h>
 | ||
| #include <urldefid.h>
 | ||
| #include <utility.h>
 | ||
| #include <varrec.h>
 | ||
| 
 | ||
| #include <causali.h>
 | ||
| #include <clifo.h>
 | ||
| #include <mov.h>
 | ||
| #include <pconti.h>
 | ||
| #include <rdoc.h>
 | ||
| #include <rmov.h>
 | ||
| #include <saldi.h>
 | ||
| 
 | ||
| #include "..\cg\cglib02.h"
 | ||
| #include "..\ve\velib.h"
 | ||
| 
 | ||
| /*
 | ||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////
 | ||
| // Applicazione di conversione archivi XBase, valida per tutti e 4 i tipi di DLL
 | ||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////
 | ||
| 
 | ||
| class TConversione_xbase : public TApplication
 | ||
| {
 | ||
| 
 | ||
| protected:
 | ||
|   virtual bool create () ;
 | ||
|   virtual bool destroy();
 | ||
|   void update();
 | ||
|   void convert_dir();
 | ||
|   int  convert_file(int logicnum);
 | ||
| 
 | ||
| public:
 | ||
|   TConversione_xbase()  {}
 | ||
|   ~TConversione_xbase() {}
 | ||
| 
 | ||
| };
 | ||
| 
 | ||
| bool TConversione_xbase::create() // initvar e arrmask
 | ||
| 
 | ||
| {
 | ||
|   TApplication::create();
 | ||
| 
 | ||
|   update();
 | ||
|   return FALSE;
 | ||
| }
 | ||
| 
 | ||
| bool TConversione_xbase::destroy() // releasev e arrmask
 | ||
| 
 | ||
| {
 | ||
|   return TApplication::destroy() ;
 | ||
| }
 | ||
| 
 | ||
| int TConversione_xbase::convert_file(int logicnum)
 | ||
|   
 | ||
| {
 | ||
|   int   err = NOERR;
 | ||
|   TSystemisamfile f(logicnum);
 | ||
|   
 | ||
|   err=f.pack(); // Pack data and index, so rebuild indexes according to present DLL, leaving old indexes
 | ||
| 
 | ||
|   return err;
 | ||
| }
 | ||
| 
 | ||
| void TConversione_xbase::convert_dir()
 | ||
| 
 | ||
| {         
 | ||
|   const TString pref(prefix().name());
 | ||
|   const bool is_com = prefix().is_com(); 
 | ||
|   TDir d;
 | ||
|   
 | ||
|   d.get(LF_DIR);                 
 | ||
|   const int items = (int)d.eod();
 | ||
|   TString80 s("Aggiornamento archivi ");
 | ||
| 
 | ||
|   if (pref == "com") s << "comuni";
 | ||
|   else s << " della ditta " << atol (pref);
 | ||
|   
 | ||
|   TProgind p((long)(items ? items : 1), s, TRUE, TRUE, 70);
 | ||
| 
 | ||
|   p.setstatus(1L);
 | ||
|   
 | ||
|   for (int i = 2; i <= items; i++)
 | ||
|   {                   
 | ||
|     p.setstatus((long)(i+1));
 | ||
|     d.get(i, _nolock, _nordir, _sysdirop);                 
 | ||
| 
 | ||
|     const bool to_convert = (is_com ? d.is_com() : d.is_firm());
 | ||
|     
 | ||
|     if (to_convert && d.len() > 0) 
 | ||
|       convert_file(i);
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| void TConversione_xbase::update()
 | ||
| 
 | ||
| { 
 | ||
|   long firm = get_firm();             
 | ||
|   TString pref;
 | ||
|   if (firm == 0) pref = prefix().name();
 | ||
|   
 | ||
|   do_events();
 | ||
|   begin_wait();
 | ||
|   
 | ||
|   prefix().set("com");
 | ||
|   convert_dir();
 | ||
| 
 | ||
|   TLocalisamfile ditte(LF_NDITTE);
 | ||
|   
 | ||
|   set_autoload_new_files(FALSE);
 | ||
|   for (ditte.first(); !ditte.eof(); ditte.next())
 | ||
|   {
 | ||
|     const long codditta = ditte.get_long("CODDITTA");
 | ||
|     const TRecnotype rec = ditte.recno();
 | ||
|     
 | ||
|     if (prefix().exist(codditta))
 | ||
|     {
 | ||
|       set_firm(codditta);
 | ||
|       convert_dir();
 | ||
|     }
 | ||
|   }
 | ||
|   if (firm > 0) set_firm(firm);
 | ||
|   else prefix().set(pref);
 | ||
|   set_autoload_new_files(TRUE);
 | ||
|   end_wait();
 | ||
| }
 | ||
| */
 | ||
| 
 | ||
| /////////////////////////////////////////////////////////////////////////////////////////
 | ||
| // Applicazione di conversione archivi
 | ||
| /////////////////////////////////////////////////////////////////////////////////////////
 | ||
| 
 | ||
| class TConversione_archivi : public TApplication
 | ||
| {
 | ||
|   int _nconv;
 | ||
|   long _codditta;
 | ||
|   long _oldditta;
 | ||
|   int _error;
 | ||
| 
 | ||
| protected: // TApplication
 | ||
|   virtual bool create() ;                         
 | ||
|   virtual bool destroy() ;                        
 | ||
|   virtual bool menu(MENU_TAG);
 | ||
| 
 | ||
|   // Metodi per convert_profile
 | ||
|   bool to_be_converted(TFilename& name) const;
 | ||
|   bool backup_text_file(TFilename& name, TLog_report& log) const;
 | ||
|   bool rinumera_paragrafo(const TFilename& ini, const char* paragrafo, 
 | ||
|                           const char* contatore, const char* variabile, TLog_report& log) const;
 | ||
|   bool rinumera_maschera(const TFilename& msk, TLog_report& log) const;
 | ||
| 
 | ||
| public:
 | ||
|   bool convert_rmov(TLocalisamfile & rmov, TArray & recs, int nrecs);
 | ||
|   void contropartita_rmov();
 | ||
| 
 | ||
|   void liala(const char* table);
 | ||
|   bool patch_uff(TRectype & rec, const char * const fnames[]);
 | ||
|   bool collate(TRectype & rec, const char * f1, const char * f2);
 | ||
|   void patch_com();
 | ||
|   void zero_770();
 | ||
|   void convert_patty();
 | ||
|   void convert_codconc();
 | ||
|   void convert_profili();
 | ||
|   void convert_caus_attiv();
 | ||
|   void rebuild_indexes();
 | ||
|   void rebuild_dir_indexes();
 | ||
|   void convert_codreg() const;
 | ||
|   void convert_lia_pim() const;
 | ||
|   void build_ver_table() const;
 | ||
|   void convert_forms() const;
 | ||
|   void sort_sal(int year) const;
 | ||
|   void convert_saldi() const;
 | ||
|   void convert_ca7_ql() const;
 | ||
|   void convert_enti_m770() const; 
 | ||
|   void convert_caaf_m770() const; 
 | ||
|   void convert_rver_m770() const;
 | ||
|   void remove_dta_ndx() const;
 | ||
|   void convert_ucs() const;
 | ||
|   void convert_ucc() const;
 | ||
|   void convert_cap() const;
 | ||
|   void convert_uue() const;
 | ||
|   void convert_pim2prm() const;
 | ||
|   void convert_riba_tcf() const;
 | ||
|   void convert_cdc2cms() const;
 | ||
|   void convert_mov2movcms() const;
 | ||
|   void convert_ca7() const;
 | ||
|   void change_ca7(TRectype& rec) const;
 | ||
|   void convert_quadst() const; 
 | ||
|   void convert_clifo_privati(); 
 | ||
| 	void convert_pcon_ivd();
 | ||
| 	void convert_profile(const char * profile_name);
 | ||
|   //roba per conai
 | ||
|   void convert_conai_anamag();
 | ||
|   void convert_conai_rdoc();
 | ||
|   void convert_conai_righe();
 | ||
|   
 | ||
|   TConversione_archivi() : _oldditta(0), _codditta(0), _error(0) {}
 | ||
| };
 | ||
| 
 | ||
| bool TConversione_archivi::create()
 | ||
| {
 | ||
|   TApplication::create();
 | ||
| 	const int args = argc();
 | ||
| 
 | ||
|   _nconv = args > 1 ? abs(atoi(argv(1))) : 0;
 | ||
|   if (_nconv > 1)
 | ||
|   {
 | ||
|     _oldditta = get_firm();
 | ||
| 		if (args > 2)
 | ||
| 			_codditta = atol(argv(args - 1));
 | ||
| 		else
 | ||
| 			_codditta = -1;
 | ||
|     if (_codditta >= 0 && _codditta != _oldditta) 
 | ||
|     {
 | ||
|       if (_codditta == 0) prefix().set("com");
 | ||
|       else set_firm(_codditta);
 | ||
|     }
 | ||
|   }
 | ||
|   dispatch_e_menu(MENU_ITEM_ID(1));
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| bool TConversione_archivi::destroy()
 | ||
| {
 | ||
|   if (_codditta >= 0 && _nconv > 1 && _codditta != _oldditta)
 | ||
|   {
 | ||
|     if (_oldditta == 0) prefix().set("com");
 | ||
|     else set_firm(_oldditta);
 | ||
|   }
 | ||
|   if (_error > 0)
 | ||
|   {
 | ||
|     TMessage msg("ba1100", 0, format("%d", _error));
 | ||
|     msg.send();
 | ||
|   }
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| bool TConversione_archivi::menu(MENU_TAG)
 | ||
| {
 | ||
|   switch (_nconv)
 | ||
|   {
 | ||
|   case 1:
 | ||
|   {
 | ||
|     TSystemisamfile f(atoi(argv(2)));
 | ||
|     TFilename lf;
 | ||
| 
 | ||
|     lf.format("%sstd/%s", __ptprf, argv(3));
 | ||
|     if (fexist(lf))
 | ||
|       f.load(lf, '|', '\0', '\n', TRUE, TRUE);
 | ||
|   }
 | ||
|   break;
 | ||
|   case 2:
 | ||
|     liala("LIA"); 
 | ||
|     liala("PLA"); 
 | ||
|     break;   
 | ||
|   case 3:
 | ||
|     if (_codditta == 0)
 | ||
|       patch_com();
 | ||
|   case 4:
 | ||
|     if (_codditta == 0)
 | ||
|       zero_770();
 | ||
|   case 5:
 | ||
|     convert_patty();    
 | ||
|   case 6:
 | ||
|     if (_codditta == 0) 
 | ||
|     {
 | ||
|       convert_codconc();
 | ||
| 
 | ||
|       TSystemisamfile comuni(LF_COMUNI);
 | ||
|    
 | ||
|       comuni.load(format("%sstd/ncom02.txt", __ptprf)); 
 | ||
|       
 | ||
|       //Cancella tutti i vecchi profili, sostituendoli con i nuovi
 | ||
|       convert_profili();
 | ||
|     }  
 | ||
|   case 7:
 | ||
|     if (_codditta == 0)
 | ||
|       convert_caus_attiv();
 | ||
|     break;
 | ||
|   case 8:
 | ||
|     if (_codditta == 0)
 | ||
|       rebuild_indexes(); 
 | ||
|     break;
 | ||
|   case 9: 
 | ||
|     if (_codditta == 0)
 | ||
|       convert_codreg();
 | ||
|     break;
 | ||
|   case 10:
 | ||
|     convert_lia_pim();
 | ||
|     if (_codditta == 0)
 | ||
|       build_ver_table();
 | ||
|     break;  
 | ||
|   case 11:
 | ||
|     if (_codditta == 0)
 | ||
|       convert_ca7_ql();
 | ||
|     break;
 | ||
|   case 12:
 | ||
|     remove_dta_ndx();
 | ||
|     if (_codditta == 0)
 | ||
|     {
 | ||
|       // Rimuove ITALIA dalla tabella stati
 | ||
|       TTable sta("%STA");
 | ||
|       sta.zero();
 | ||
|       if (sta.read() == NOERR) sta.remove();
 | ||
|       // converte i profili
 | ||
|       convert_forms();
 | ||
|     }
 | ||
|     else
 | ||
|       convert_saldi();
 | ||
|     break;
 | ||
|   case 13:
 | ||
|     if (_codditta == 0)
 | ||
|     {
 | ||
|       convert_enti_m770();
 | ||
|       convert_caaf_m770();
 | ||
|       convert_rver_m770();
 | ||
|     }
 | ||
|     break;
 | ||
|   case 14:
 | ||
|     if (_codditta == 0)
 | ||
|     {
 | ||
|       convert_ucs();
 | ||
|       convert_ucc();
 | ||
|     }
 | ||
|     break;  
 | ||
|   case 16:
 | ||
|     if (_codditta == 0)
 | ||
|       convert_uue(); 
 | ||
|     convert_cap();
 | ||
|     break;
 | ||
|   case 17:
 | ||
|     if (_codditta > 0)
 | ||
|       convert_pim2prm(); 
 | ||
|     break;
 | ||
|   case 18:
 | ||
|     if (_codditta > 0)
 | ||
|       convert_riba_tcf(); 
 | ||
|     break;
 | ||
|   case 19:
 | ||
|     if (_codditta > 0)
 | ||
|     {
 | ||
|       convert_cdc2cms();
 | ||
|       convert_mov2movcms();
 | ||
|     }
 | ||
|     break;
 | ||
|   case 20:
 | ||
|     if (_codditta == 0)
 | ||
|     {
 | ||
|       convert_ca7();
 | ||
|       convert_quadst();
 | ||
|     }
 | ||
|     break;
 | ||
|   case 21:
 | ||
| 		convert_clifo_privati(); 
 | ||
|     break;
 | ||
|   case 22:
 | ||
| 		convert_pcon_ivd(); 
 | ||
|     break;
 | ||
|   case 23:
 | ||
| 		convert_profile(argv(2)); 
 | ||
|     break;
 | ||
|   case 24:
 | ||
|     convert_conai_righe();
 | ||
|     break;
 | ||
|   default:
 | ||
|     break;  
 | ||
|   }
 | ||
|   return false;
 | ||
| }
 | ||
| 
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| // Cambia i movimenti contabili in modo che abbiano un
 | ||
| // conto di contropartita e non una riga di riferimento
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| 
 | ||
| bool TConversione_archivi::convert_rmov(TLocalisamfile & rmov, TArray & recs, int nrecs)
 | ||
| {
 | ||
|   const TRecnotype pos = rmov.recno();
 | ||
| 
 | ||
|   for (int i = 0; i < nrecs; i++)
 | ||
|   {
 | ||
|     TRectype & r0 = (TRectype &) recs[i];
 | ||
|     const int rcontr = r0.get_int("RCONTR") - 1;
 | ||
| 
 | ||
|     if (rcontr >= 0 && rcontr < nrecs)
 | ||
|     {
 | ||
|       const TRectype & r1 = (const TRectype &) recs[rcontr];
 | ||
| 
 | ||
|       r0.put(RMV_TIPOCC, r1.get(RMV_TIPOC));
 | ||
|       r0.put(RMV_GRUPPOC, r1.get_int(RMV_GRUPPO));
 | ||
|       r0.put(RMV_CONTOC, r1.get_int(RMV_CONTO));
 | ||
|       r0.put(RMV_SOTTOCONTOC, r1.get_long(RMV_SOTTOCONTO));
 | ||
|     }
 | ||
|     r0.zero("RCONTR");
 | ||
|     if (rmov.rewrite(r0) != NOERR)
 | ||
|     {
 | ||
|       const long reg = r0.get_long(RMV_NUMREG);
 | ||
|       error_box("Non riesco ad aggiornare la riga contabile %ld / %d\nErrore n. %d", reg, i + 1, rmov.status());
 | ||
|       rmov.readat(pos);
 | ||
|       _error = 102;
 | ||
|       return FALSE;
 | ||
|     }
 | ||
|   }
 | ||
|   rmov.readat(pos);
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| void TConversione_archivi::contropartita_rmov()
 | ||
| {
 | ||
|   TDir d;
 | ||
|   d.get(LF_RMOV);
 | ||
|   if (d.eox() == 0) return;
 | ||
| 
 | ||
|   TLocalisamfile rmov(LF_RMOV);
 | ||
|   const TRecnotype nitems = rmov.items();
 | ||
|   TArray recs;
 | ||
|   long oldreg = -1;
 | ||
|   long reg = -1;
 | ||
|   int nrow = 0;
 | ||
|   TProgind p(nitems ? nitems : 1,
 | ||
|              format("Conversione righe di movimento della ditta %ld", get_firm()),
 | ||
|              FALSE, TRUE, 70);
 | ||
|   for (rmov.first(); rmov.good(); rmov.next())
 | ||
|   {
 | ||
|     p.addstatus(1);
 | ||
|     reg = rmov.get_long(RMV_NUMREG);
 | ||
|     if (oldreg != reg)
 | ||
|     {
 | ||
|       if (oldreg > 0)
 | ||
|         if (convert_rmov(rmov, recs, nrow) == FALSE)
 | ||
|           return;
 | ||
|       oldreg = reg;
 | ||
|       nrow = 0;
 | ||
|     }
 | ||
|     recs.add(rmov.curr(), nrow++);
 | ||
|     CHECKD(nrow == rmov.get_int(RMV_NUMRIG), "Missed row ", nrow); 
 | ||
|   } 
 | ||
|   if (oldreg > 0)
 | ||
|     if (convert_rmov(rmov, recs, nrow) == FALSE)
 | ||
|       return;
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| // Passa le tabelle LIA e PLA a %LIA e %PLA
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| 
 | ||
| void TConversione_archivi::liala(const char* table)
 | ||
| {                                                 
 | ||
|   TString16 tab(table);                                            
 | ||
|   TTable lia(tab);
 | ||
|   tab.insert("%", 0);
 | ||
|   TTable cia(tab);
 | ||
| 
 | ||
|   const long n = lia.items()+1;
 | ||
|   TProgind p(n, format("Conversione tabella %s della ditta %ld", table, get_firm()), FALSE, TRUE, 70);
 | ||
|   
 | ||
|   TString16 firm; firm.format("%05ld", get_firm());
 | ||
|   TString16 codtab;
 | ||
|   
 | ||
|   for (lia.first(); lia.good(); lia.next())
 | ||
|   {
 | ||
|     codtab = lia.get("CODTAB");
 | ||
|     codtab.insert(firm, 0);
 | ||
|     lia.put("CODTAB", codtab);
 | ||
|     cia.write(lia.curr());
 | ||
|   }
 | ||
|   
 | ||
|   for (lia.first(); lia.good(); lia.next())
 | ||
|     lia.remove();
 | ||
| }
 | ||
| 
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| // Sposta i codici uffici imposte e uffici IVA nei comuni
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| 
 | ||
| bool TConversione_archivi::collate(TRectype & rec, const char * f1, const char * f2)
 | ||
| { 
 | ||
|   if (rec.get(f1).empty())
 | ||
|   {                              
 | ||
|     TString16 s(rec.get(f2)); 
 | ||
|     
 | ||
|     if (s.not_empty())
 | ||
|     {
 | ||
|       rec.put(f1, s);
 | ||
|       rec.zero(f2); 
 | ||
|       return TRUE;
 | ||
|     }   
 | ||
|   }               
 | ||
|   return FALSE;
 | ||
| }
 | ||
| 
 | ||
| bool TConversione_archivi::patch_uff(TRectype & rec, const char * const fnames[])
 | ||
| {  
 | ||
|   bool updated = collate(rec, fnames[1], fnames[2]);
 | ||
|   updated |= collate(rec, fnames[0], fnames[1]);
 | ||
|   updated |= collate(rec, fnames[1], fnames[2]);
 | ||
|   return updated;
 | ||
| }
 | ||
| 
 | ||
| void TConversione_archivi::patch_com()
 | ||
| {
 | ||
|   TLocalisamfile comuni(LF_COMUNI);    
 | ||
|   const char * const uff_iidd[] = {"UFFIIDD1", "UFFIIDD2", "UFFIIDD3"} ;
 | ||
|   const char * const uff_iva[] = {"UFFIVA1", "UFFIVA2", "UFFIVA3"} ;
 | ||
|   const TRecnotype nitems = comuni.items();
 | ||
|   TProgind p(nitems ? nitems : 1, format("Conversione comuni"), FALSE, TRUE, 70);
 | ||
|   
 | ||
|   for (comuni.first(); comuni.good(); comuni.next())
 | ||
|   {      
 | ||
|     p.addstatus(1);
 | ||
|     bool updated = patch_uff(comuni.curr(), uff_iidd);
 | ||
|     updated = patch_uff(comuni.curr(), uff_iva) || updated;
 | ||
|     if (updated)
 | ||
|       comuni.rewrite();
 | ||
|   }                                                    
 | ||
| }
 | ||
| 
 | ||
| void TConversione_archivi::zero_770()
 | ||
| { 
 | ||
|   TDir d;      
 | ||
|   for (int i = LF_BASE ; i <= LF_DETH; i++)
 | ||
|   {
 | ||
|     d.get(i, _lock, _nordir, _sysdirop); 
 | ||
|     d.reset_eox();
 | ||
|     d.put(i, _nordir, _sysdirop);  
 | ||
|   }      
 | ||
|   
 | ||
|   TFilename files;
 | ||
|   TString_array list;
 | ||
|   
 | ||
|   if (fexist(format("%scom/770", __ptprf)))
 | ||
|   {       
 | ||
|     files.format("%scom/770/%s", __ptprf, "*");   
 | ||
|     list_files(files, list);
 | ||
|     for (int i = list.items()-1; i >= 0; i--)
 | ||
|       remove(list.row(i));               
 | ||
|     list.destroy();  
 | ||
|     xvt_fsys_rmdir(format("%scom/770", __ptprf)); 
 | ||
|   }
 | ||
|   if (fexist(format("%s770", __ptprf)))
 | ||
|   {       
 | ||
|     files.format("%s770/%s", __ptprf, "*");   
 | ||
|     list_files(files, list);
 | ||
|     for (int i = list.items()-1; i >= 0; i--)
 | ||
|       remove(list.row(i));               
 | ||
|     list.destroy();  
 | ||
|     xvt_fsys_rmdir(format("%s770", __ptprf)); 
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| void TConversione_archivi::convert_patty()
 | ||
| {                                      
 | ||
|   {
 | ||
|     TTable ivd("%IVD");
 | ||
|     ivd.zero();
 | ||
|     ivd.put("CODTAB", "9E0023");
 | ||
|     if (ivd.read(_isequal, _lock) == NOERR)
 | ||
|       ivd.remove();
 | ||
|     ivd.put("CODTAB", "9E  23");
 | ||
|     if (ivd.read(_isequal, _lock) == NOERR)
 | ||
|       ivd.remove();  
 | ||
|     ivd.put("CODTAB", "9E    23");
 | ||
|     if (ivd.read(_isequal, _lock) == NOERR)
 | ||
|       ivd.remove();  
 | ||
|   }
 | ||
|   {
 | ||
|     TTable doc("%TPD");
 | ||
|     doc.zero();
 | ||
|     doc.put("CODTAB", "AN");
 | ||
|     if (doc.read(_isequal, _lock) == NOERR)
 | ||
|       doc.remove();
 | ||
|     doc.zero();
 | ||
|     doc.put("CODTAB", "IN");
 | ||
|     if (doc.read(_isequal, _lock) == NOERR)
 | ||
|       doc.remove();
 | ||
|     doc.zero();
 | ||
|     doc.put("CODTAB", "PG");
 | ||
|     if (doc.read(_isequal, _lock) == NOERR)
 | ||
|       doc.remove();
 | ||
|     doc.zero();
 | ||
|     doc.put("CODTAB", "NA");
 | ||
|     if (doc.read(_isequal, _lock) == NOERR)
 | ||
|       doc.remove();
 | ||
|     doc.zero();
 | ||
|     doc.put("CODTAB", "NC");
 | ||
|     if (doc.read(_isequal, _lock) == NOERR)
 | ||
|     {
 | ||
|       doc.put("S0", "Nota di credito");
 | ||
|       doc.put("I0", "9");
 | ||
|       doc.rewrite();
 | ||
|     }
 | ||
|   } 
 | ||
|   TAssoc_array causarr;
 | ||
| 
 | ||
|   TDir d;
 | ||
|   d.get(LF_CAUSALI,_nolock,_nordir,_sysdirop);
 | ||
|   if (d.is_com())
 | ||
|     d.get(LF_CAUSALI,_nolock,_comdir);
 | ||
| 
 | ||
|     if (d.eod() > 0L)
 | ||
|   {
 | ||
|     TLocalisamfile caus(LF_CAUSALI);
 | ||
|     for (caus.first(_lock); caus.good(); caus.next(_lock))
 | ||
|     {
 | ||
|       const TString16 tpd(caus.get("TIPODOC"));
 | ||
|       const TString16 incimm(caus.get("CODCAUSIM"));
 | ||
|       
 | ||
|       if (incimm.not_empty())
 | ||
|         causarr.add(incimm, incimm);
 | ||
|       if (tpd == "AN") caus.zero("TIPODOC");
 | ||
|       else
 | ||
|         if (tpd == "IN") caus.zero("TIPODOC");
 | ||
|         else
 | ||
|           if (tpd == "PG") caus.zero("TIPODOC");
 | ||
|           else
 | ||
|             if (tpd == "NA") caus.put("TIPODOC","NC");   
 | ||
|       
 | ||
|       caus.rewrite();
 | ||
|     }                  
 | ||
|   }             
 | ||
|   const bool topatch = causarr.items() > 0;
 | ||
| 
 | ||
|   d.get(LF_MOV);
 | ||
|   if (d.eod() > 0L)
 | ||
|   {
 | ||
|     TLocalisamfile mov(LF_MOV);
 | ||
|     
 | ||
|     for (mov.first(_lock); mov.good(); mov.next(_lock))
 | ||
|     {
 | ||
|       const TString16 tpd(mov.get("TIPODOC"));
 | ||
|       if (topatch)
 | ||
|       {
 | ||
|         const TString16 codcaus(mov.get("CODCAUS"));
 | ||
|         
 | ||
|         if (causarr.objptr(codcaus) != NULL)
 | ||
|         {
 | ||
|           mov.zero("DATA74TER");
 | ||
|           mov.zero("REG");
 | ||
|           mov.zero("PROTIVA");
 | ||
|           mov.zero("UPROTIVA");
 | ||
|           mov.zero("REGST");
 | ||
|           mov.zero("TIPO");
 | ||
|           mov.zero("CODCF");
 | ||
|           mov.zero("TOTDOC");
 | ||
|           mov.zero("RITFIS");
 | ||
|           mov.zero("RITSOC");
 | ||
|           mov.zero("PROVVIS");
 | ||
|           mov.zero("CODVALI");
 | ||
|           mov.zero("CAMBIOI");
 | ||
|           mov.zero("CORRLIRE");
 | ||
|           mov.zero("CORRVALUTA");
 | ||
|           mov.zero("OCFPI");
 | ||
|           mov.zero("CODPAG");
 | ||
|         }
 | ||
|       }
 | ||
|       if (tpd == "AN") mov.zero("TIPODOC");
 | ||
|       else
 | ||
|         if (tpd == "IN") mov.zero("TIPODOC");
 | ||
|         else
 | ||
|           if (tpd == "PG") mov.zero("TIPODOC");
 | ||
|           else
 | ||
|             if (tpd == "NA") mov.put("TIPODOC","NC");
 | ||
|       mov.rewrite();
 | ||
|     }
 | ||
|   }       
 | ||
|   if (_codditta == 0)
 | ||
|   {     
 | ||
|     TDir d;
 | ||
|     TSystemisamfile f(LF_FORM);
 | ||
|     TFilename lf;
 | ||
|            
 | ||
|     d.get(LF_FORM);
 | ||
|     lf.format("%sstd/lf0054.txt", __ptprf);
 | ||
|     if (fexist(lf) && fexist(d.filename()))
 | ||
|       f.load(lf);
 | ||
|   }
 | ||
| }                                         
 | ||
| 
 | ||
| void TConversione_archivi::convert_caus_attiv()
 | ||
| {                                            
 | ||
|   {
 | ||
|     TLocalisamfile attiv(LF_ATTIV); 
 | ||
|     TProgind p(attiv.items(), "Conversione archivio attivita'", FALSE, TRUE,20);
 | ||
|     p.setstatus(1L);
 | ||
|     for (attiv.first(); !attiv.eof(); attiv.next())
 | ||
|     {
 | ||
|       bool val = attiv.get_bool("ART74/4");
 | ||
|       attiv.put("ART74_4", val);
 | ||
|       attiv.rewrite();
 | ||
|       p.addstatus(1L);
 | ||
|     }                           
 | ||
|   }    
 | ||
|   {
 | ||
|     TLocalisamfile ditte(LF_NDITTE);
 | ||
|     TProgind p(ditte.items(), "Conversione archivi causali", FALSE, TRUE,5);
 | ||
|     p.setstatus(1L);
 | ||
|     set_autoload_new_files(FALSE);
 | ||
|     for (ditte.first(); !ditte.eof(); ditte.next())
 | ||
|     {
 | ||
|       const long codditta = ditte.get_long("CODDITTA");
 | ||
|       if (prefix().exist(codditta))
 | ||
|       {
 | ||
|         p.set_text(format("Ditta: %ld",codditta));
 | ||
|         set_firm(codditta);
 | ||
|         TLocalisamfile caus(LF_CAUSALI);
 | ||
|         caus.zero();
 | ||
|         caus.put("CODCAUS","C08");      
 | ||
|         if (caus.read() == NOERR)       
 | ||
|            caus.put("TIPODOC","FS");    
 | ||
|         caus.rewrite();
 | ||
|       }             
 | ||
|       p.addstatus(1);
 | ||
|     }                               
 | ||
|     p.setstatus(ditte.items());
 | ||
|     prefix().set("com");
 | ||
|     set_autoload_new_files(TRUE);
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| void TConversione_archivi::convert_profili()
 | ||
| {
 | ||
|   TSystemisamfile form(LF_FORM),rform(LF_RFORM);
 | ||
|   TDir d;
 | ||
|   TFilename lf;
 | ||
|        
 | ||
|   d.get(LF_FORM, _nolock, _comdir, _sysdirop);
 | ||
|   d.set_eod(0);
 | ||
|   d.put(LF_FORM, _comdir, _sysdirop);
 | ||
|   form.pack();
 | ||
|   lf.format("%sstd/lf0054.txt", __ptprf);
 | ||
|   if (fexist(lf)) form.load(lf);
 | ||
|   d.get(LF_RFORM, _nolock, _comdir, _sysdirop);
 | ||
|   d.set_eod(0);
 | ||
|   d.put(LF_RFORM, _comdir, _sysdirop);
 | ||
|   rform.pack();
 | ||
| }
 | ||
| 
 | ||
| void TConversione_archivi::convert_codconc()
 | ||
| {     
 | ||
| // costruisce le tabelle di confronto                                 
 | ||
|   TAssoc_array conc_cessate;
 | ||
|   TScanner oc(format("%sstd/oconc00.txt", __ptprf)); 
 | ||
|     
 | ||
|   for (TString16  s(oc.line()); s.not_empty(); s = oc.line()) 
 | ||
|     conc_cessate.add(s);
 | ||
| // (fase 1)
 | ||
| // scorre il file anagrafica  
 | ||
|   TLocalisamfile anagr(LF_ANAG);
 | ||
|   TLocalisamfile comuni(LF_COMUNI);
 | ||
|   int nerr = 0;
 | ||
| // se il file anagrafica non <20> vuoto
 | ||
|   const long anag_items = anagr.items();
 | ||
|   if (anag_items > 0)
 | ||
|   {
 | ||
|     TProgind p(anag_items, "Conversione archivio anagrafica", FALSE, TRUE, 70);
 | ||
|     
 | ||
|     p.setstatus(1L);
 | ||
| 
 | ||
| // per ogni anagrafica  blocca il record
 | ||
|     for (anagr.first(_lock); anagr.good(); anagr.next(_lock))
 | ||
|     {
 | ||
| //   legge il codice comune
 | ||
|       TString16 com = anagr.get("COMRF");
 | ||
| 
 | ||
|       p.addstatus(1);                           
 | ||
|       if (com.empty())
 | ||
|         com = anagr.get("COMRES");
 | ||
| //   se il comune non <20> vuoto recupera il comune       
 | ||
|       if (com.not_empty())
 | ||
|       {                                                                             
 | ||
|         comuni.zero();
 | ||
|         comuni.put("COM", com);
 | ||
| // se non <20> un comune di una nuova provincia e il comune esiste    
 | ||
|         if (!conc_cessate.is_key(com))
 | ||
|         {
 | ||
|           if (comuni.read() == NOERR)
 | ||
|           {                  
 | ||
| //   legge il codice concessione
 | ||
|             TString16 conc(comuni.get("UFFCONC"));
 | ||
| //   se il codice concessione <20> cessato
 | ||
|             if (conc_cessate.is_key(conc))
 | ||
|             {   
 | ||
| //     scrive il codice concessione sull' anagrafica
 | ||
|               anagr.put("UFFCONC", conc);
 | ||
|               anagr.rewrite();
 | ||
|             }
 | ||
| //   altrimenti sblocca il record              
 | ||
|             else
 | ||
|               anagr.read(_iscurr, _unlock);                  
 | ||
|          }
 | ||
| //   altrimenti sblocca il record e conteggia l' errore
 | ||
|           else
 | ||
|           {
 | ||
|             anagr.read(_iscurr, _unlock);
 | ||
|             nerr++;
 | ||
|           }  
 | ||
|         }
 | ||
|       } 
 | ||
| //   altrimenti sblocca il record              
 | ||
|       else
 | ||
|         anagr.read(_iscurr, _unlock);
 | ||
|     }
 | ||
|   }                              
 | ||
| // segnala gli errori
 | ||
| #ifdef DBG
 | ||
|   if (nerr)
 | ||
|     error_box("La conversione della anagrafiche non ha trovato %d comuni", nerr);
 | ||
|   nerr = 0; 
 | ||
| #endif
 | ||
| 
 | ||
| // (fase 2) 
 | ||
| // vuota la tabella concessioni
 | ||
|   {
 | ||
|     TTable uffconc("%UCC");
 | ||
|   
 | ||
|     for (uffconc.first(_lock); uffconc.good(); uffconc.next(_lock))
 | ||
|       uffconc.remove();
 | ||
|    }
 | ||
| // carica la nuova            
 | ||
|    {
 | ||
|      TSystemisamfile tabcom(LF_TABCOM);
 | ||
|    
 | ||
|      tabcom.load(format("%sstd/nconc00.txt", __ptprf)); 
 | ||
|    }  
 | ||
| // (fase 3)
 | ||
| // scorre il file con i codici comuni e le nuove concessioni
 | ||
|   TScanner nc(format("%sstd/ncom00.txt", __ptprf)); 
 | ||
|   TProgind p(comuni.items(), "Conversione archivio comuni", FALSE, TRUE, 70);  
 | ||
|   TToken_string comass;
 | ||
| #ifdef DBG   
 | ||
|   TTable uffconc("%UCC");
 | ||
|   TToken_string concerr;
 | ||
| #endif       
 | ||
| 
 | ||
|   p.setstatus(1L);
 | ||
| // per ogni comune
 | ||
|   for (TToken_string ts(nc.line()); ts.not_empty(); ts = nc.line()) 
 | ||
|   {                          
 | ||
|     p.addstatus(1);
 | ||
| //  cerca il comune
 | ||
|     comuni.zero();
 | ||
|     comuni.put("COM", ts.get());
 | ||
| // se esiste
 | ||
|     if (comuni.read(_isequal, _lock) == NOERR)                     
 | ||
|     {
 | ||
| //   aggiorna il codice concessione sul comune in oggetto
 | ||
|       comuni.put("UFFCONC", ts.get());
 | ||
|       comuni.rewrite();
 | ||
| #ifdef DBG   
 | ||
|       uffconc.zero();
 | ||
|       uffconc.put("CODTAB", comuni.get("UFFCONC"));
 | ||
|       if (uffconc.read() != NOERR)
 | ||
|         concerr.add(comuni.get("UFFCONC")); 
 | ||
| #endif       
 | ||
|     }
 | ||
| //   altrimenti sblocca il record e conteggia l' errore
 | ||
|     else                                               
 | ||
|     {
 | ||
|       comuni.read(_iscurr, _unlock);
 | ||
|       comass.add(ts.get(0));
 | ||
|       nerr++;    
 | ||
|     }
 | ||
|   } 
 | ||
| // segnala gli errori
 | ||
| #ifdef DBG
 | ||
|   if (nerr)
 | ||
|     error_box("La conversione dei comuni non ne ha trovati %d\n Codici : %s", nerr, (const char *) comass);
 | ||
|   if (concerr.not_empty())
 | ||
|     error_box("Le seguenti concessioni sono inesistenti %s", (const char *) concerr);
 | ||
| #endif       
 | ||
| }                                                      
 | ||
| 
 | ||
| void TConversione_archivi::rebuild_indexes()
 | ||
| {  
 | ||
|   do_events();
 | ||
|   begin_wait();
 | ||
|   prefix().set("com");
 | ||
|   rebuild_dir_indexes();
 | ||
|   TSystemisamfile ditte(LF_NDITTE);
 | ||
|   ditte.open();
 | ||
|   
 | ||
|   for (ditte.first(); !ditte.eof(); ditte.next())
 | ||
|   {
 | ||
|     const long codditta = ditte.get_long("CODDITTA");
 | ||
|     const TRecnotype rec = ditte.recno();
 | ||
|     
 | ||
|     if (prefix().exist(codditta))
 | ||
|     {
 | ||
|       ditte.close();
 | ||
|       set_firm(codditta);
 | ||
|       rebuild_dir_indexes();
 | ||
|       ditte.open();
 | ||
|     }
 | ||
|     ditte.readat(rec);
 | ||
|   }
 | ||
|   ditte.close();
 | ||
|   end_wait();
 | ||
| }                                            
 | ||
| 
 | ||
| void TConversione_archivi::rebuild_dir_indexes()
 | ||
| {                                            
 | ||
|   const TString pref(prefix().name());
 | ||
|   const bool is_com = prefix().is_com();
 | ||
|   TDir d;  
 | ||
|   
 | ||
|   d.get(LF_DIR);                 
 | ||
|   const int items = (int)d.eod();
 | ||
|   TString80 s("Ricostruzione indici ");
 | ||
| 
 | ||
|   if (is_com) s << "comuni";
 | ||
|   else s << " della ditta " << atol (pref);
 | ||
|   
 | ||
|   TProgind p(items ? items : 1, s, TRUE, TRUE, 70);
 | ||
| 
 | ||
|   p.setstatus(1);
 | ||
|   
 | ||
|   for (int i = 2; i <= items; i++)
 | ||
|   {  
 | ||
|     p.addstatus(1);
 | ||
|     if (d.len() > 0)
 | ||
|     { 
 | ||
|       d.get(i, _nolock, _nordir, _sysdirop); 
 | ||
|       bool to_create = (is_com ? d.is_com() : d.is_firm());
 | ||
|     
 | ||
|       if (to_create)
 | ||
|       {              
 | ||
|         TBaseisamfile f(i);
 | ||
|         d.get(i);
 | ||
|         TFilename s(d.name());
 | ||
|         s.ext("dbf");
 | ||
|         if (f.is_valid(true) == NOERR && fexist(s))
 | ||
|         {
 | ||
|           TSystemisamfile f(i);
 | ||
|           f.packindex();         
 | ||
|         }
 | ||
|       }
 | ||
|     }
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| void TConversione_archivi::convert_codreg() const
 | ||
| { 
 | ||
| // (fase 1)
 | ||
| // allinea i comuni alle nuove provincie e carica il codice regione
 | ||
| // costruisce la tabella comuni -> nuove provincie
 | ||
| #ifdef DBG
 | ||
|   int nerr = 0;
 | ||
| #endif      
 | ||
|   TAssoc_array compro;
 | ||
|   
 | ||
|   {
 | ||
|     TScanner oc(format("%sstd/tbcompro.txt", __ptprf)); 
 | ||
|     
 | ||
|     for (TToken_string s(oc.line()); s.not_empty(); s = oc.line()) 
 | ||
|     {
 | ||
|       TString16 codcom(s.get(0));
 | ||
|       
 | ||
|       compro.add(codcom, s);
 | ||
|     }                         
 | ||
|   }
 | ||
| 
 | ||
| // costruisce la tabella provincie -> regioni
 | ||
|   TAssoc_array proreg;
 | ||
|   
 | ||
|   {
 | ||
|     TScanner oc(format("%sstd/tbproreg.txt", __ptprf)); 
 | ||
|     
 | ||
|     for (TToken_string s(oc.line()); s.not_empty(); s = oc.line()) 
 | ||
|     {
 | ||
|       TString16 prov(s.get(0));
 | ||
|       TString16 codreg(s.get());
 | ||
|       
 | ||
|       proreg.add(prov, codreg);
 | ||
|     }                         
 | ||
|   }
 | ||
| // scorre il file comuni
 | ||
|   TLocalisamfile comuni(LF_COMUNI);
 | ||
| // se il file comuni non <20> vuoto
 | ||
|   const long com_items = comuni.items();
 | ||
|   if (com_items > 0)
 | ||
|   {
 | ||
|     TProgind p(com_items, "Conversione archivio comuni", FALSE, TRUE, 70);
 | ||
|     
 | ||
|     p.setstatus(1L);
 | ||
| 
 | ||
| // per ogni comune
 | ||
|     for (comuni.first(); comuni.good(); comuni.next())
 | ||
|     {                               
 | ||
|       bool rewrite = FALSE;
 | ||
|       
 | ||
|       p.addstatus(1);               
 | ||
|       const TString & cod = comuni.get("COM");             
 | ||
|       TToken_string * t = (TToken_string *) compro.objptr(cod);
 | ||
|       
 | ||
|       if (t != NULL)
 | ||
|       {                    
 | ||
|         comuni.put("PROVCOM", t->get(1));
 | ||
|         comuni.put("CODISTAT", t->get());
 | ||
|         comuni.put("UFFIVA1", t->get());
 | ||
|         comuni.zero("UFFIVA2");
 | ||
|         comuni.zero("UFFIVA3");
 | ||
|         rewrite = TRUE;
 | ||
|       } 
 | ||
|       
 | ||
|       const TString & prov = comuni.get("PROVCOM");             
 | ||
|       TString16 * s = (TString16 *) proreg.objptr(prov);  
 | ||
|       
 | ||
|       if (s != NULL)
 | ||
|       {                    
 | ||
|         comuni.put("CODREG", *s);
 | ||
|         rewrite = TRUE;
 | ||
|       }       
 | ||
| #ifdef DBG
 | ||
|       else
 | ||
|         nerr++;
 | ||
| #endif      
 | ||
|       if (rewrite)
 | ||
|         comuni.rewrite();
 | ||
|     }
 | ||
|   }                              
 | ||
| 
 | ||
| // (fase 2) 
 | ||
| // compatta la tabella            
 | ||
|   {
 | ||
|      TSystemisamfile tabcom(LF_TABCOM);
 | ||
|    
 | ||
|      tabcom.pack(TRUE,FALSE);
 | ||
|   }         
 | ||
| // vuota la tabella concessioni
 | ||
|   {
 | ||
|     TTable uffconc("%UCC");
 | ||
|   
 | ||
|     for (uffconc.first(_lock); uffconc.good(); uffconc.next(_lock))
 | ||
|       uffconc.remove();
 | ||
|   }
 | ||
| // carica la nuova            
 | ||
|   {
 | ||
|      TSystemisamfile tabcom(LF_TABCOM);
 | ||
|    
 | ||
|      tabcom.load(format("%sstd/nconc01.txt", __ptprf)); 
 | ||
|   }         
 | ||
| // (fase 3)
 | ||
| // vuota la tabella regioni
 | ||
|   {
 | ||
|     TTable regioni("%RGI");
 | ||
|   
 | ||
|     for (regioni.first(_lock); regioni.good(); regioni.next(_lock))
 | ||
|       regioni.remove();
 | ||
|   }
 | ||
| // carica la nuova            
 | ||
|   {
 | ||
|     TSystemisamfile tabcom(LF_TABCOM);
 | ||
|    
 | ||
|     tabcom.load(format("%sstd/nreg00.txt", __ptprf)); 
 | ||
|   }                        
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| void TConversione_archivi::convert_lia_pim() const
 | ||
| {
 | ||
| // converte le Tokenstring contenute in  S1 e S2 di PIM e %LIA, sostituendo | con !
 | ||
|   TString80 s1,s2;
 | ||
|   if (_codditta == 0)    
 | ||
|   {
 | ||
|     TProgind p(10, "Conversione tabella LIA", FALSE, FALSE, 10);
 | ||
|     TTable lia("%LIA");
 | ||
|     for (lia.first(); lia.good(); lia.next())
 | ||
|     {
 | ||
|       s1 = lia.get("S1");
 | ||
|       if (s1.not_empty())
 | ||
|         if (s1.replace('|','!') > 0)
 | ||
|         {
 | ||
|           lia.put("S1",s1);
 | ||
|           lia.rewrite();
 | ||
|         }
 | ||
|     }
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     TProgind p(10, "Conversione tabella PIM", FALSE, FALSE, 10);
 | ||
|     TTable pim("PIM");
 | ||
|     for (pim.first(); pim.good(); pim.next())
 | ||
|     {
 | ||
|       s1 = pim.get("S1");
 | ||
|       s2 = pim.get("S2");
 | ||
|       if (s1.not_empty() || s2.not_empty())
 | ||
|         if ((s1.replace('|','!')+s2.replace('|','!')) > 0)
 | ||
|         {
 | ||
|           pim.put("S1",s1);
 | ||
|           pim.put("S2",s2);
 | ||
|           pim.rewrite();
 | ||
|         }
 | ||
|     }
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| void TConversione_archivi::build_ver_table() const
 | ||
| // Costruisce la tabella %VER con i valori in vigore da Gennaio 1993
 | ||
| {
 | ||
| /* OB600039
 | ||
|   TProgind p(10, "Creazione tabella VER", FALSE, FALSE, 10);
 | ||
|   TTable ver("%VER");
 | ||
|   
 | ||
|   ver.zero();
 | ||
|   // Come chiave si l'inizio del periodo di validita'
 | ||
|   ver.put("CODTAB","199301");
 | ||
|   // Percentuali interessi su versamento IVA per trimestri
 | ||
|   // prima erano memorizzati in prassis.ini, nei parametri studio.
 | ||
|   ver.put("R0","1.5");  ver.put("R1","1.5");
 | ||
|   ver.put("R2","1.5");  ver.put("R3","1.5");  ver.put("R4","1.5");
 | ||
|   // Importi limite versamenti. Prima erano defines all'interno
 | ||
|   // del programma di liquidazione
 | ||
|   ver.put("R5","50500"); ver.put("R7","200000");
 | ||
|   // Percentuale calcolo acconti Base anno precedente
 | ||
|   ver.put("R11","88");ver.put("R12","88");
 | ||
|   
 | ||
|   if (ver.write() != NOERR) ver.rewrite();
 | ||
| */  
 | ||
| }
 | ||
| 
 | ||
| void TConversione_archivi::convert_ca7_ql() const
 | ||
| // Converte la tabella %CA7 e QUADROL
 | ||
| {
 | ||
|   TTable ca7("%CA7");
 | ||
| 
 | ||
|   for (ca7.first(); ca7.good(); ca7.next())
 | ||
|   {
 | ||
|     TString s(ca7.get("S1"));
 | ||
|     real i1(ca7.get("I1"));
 | ||
|     ca7.put("R4",i1);
 | ||
|     ca7.zero("I1");
 | ||
|     if (ca7.get_bool("B1"))
 | ||
|       ca7.put("S2","N");
 | ||
|     if (!ca7.get_bool("B0") && s=="D1")
 | ||
|       ca7.put("S3","F");
 | ||
|     ca7.rewrite();
 | ||
|   }
 | ||
|   
 | ||
|   // Ora converte il quadro L
 | ||
|   TLocalisamfile quadrol(LF_QUAL);
 | ||
|   TString serie,numero;
 | ||
|   for (quadrol.first(); quadrol.good(); quadrol.next())
 | ||
|     if (quadrol.get_char("QLTV") == 'B')
 | ||
|     {
 | ||
|       TRectype com_rec(quadrol.curr());
 | ||
|       serie.format("%05ld",quadrol.get_long("QLSERIE"));
 | ||
|       numero.format("%05ld",quadrol.get_long("QLNUMERO"));
 | ||
|       com_rec.put("QLSERIE",serie);
 | ||
|       com_rec.put("QLNUMERO",numero);
 | ||
|       quadrol.write(com_rec);
 | ||
|       quadrol.remove();
 | ||
|     }
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| // conversione in formato numerico del codice ente
 | ||
| // in modo che i codici inferiori a 10 non siano registrati
 | ||
| // nella forma "1 ","2 ", ecc.
 | ||
| // ma nella forma "01","02", ecc.
 | ||
| void TConversione_archivi::convert_enti_m770() const
 | ||
| {     
 | ||
|   TTable tab("%ENT");
 | ||
|   TString new_cod;
 | ||
|   TString old_cod; 
 | ||
|   int err;      
 | ||
|   
 | ||
|   for (err = tab.first(); err == NOERR; err = tab.next())
 | ||
|   {
 | ||
|     old_cod = tab.get("CODTAB");
 | ||
|     if (old_cod.len() < 2)
 | ||
|     {
 | ||
|       TRectype new_rec(tab.curr());
 | ||
|       new_cod.format("%02d",atoi(old_cod));  
 | ||
|       new_rec.put("CODTAB", new_cod); 
 | ||
|       tab.write(new_rec);
 | ||
|       tab.remove();
 | ||
|     }
 | ||
|   }
 | ||
| }   
 | ||
| 
 | ||
| // conversione in formato numerico del codice caaf
 | ||
| // in modo che i codici inferiori a 10000 non siano registrati
 | ||
| // nella forma "1    ","2    ", ecc.
 | ||
| // ma nella forma "00001","00002", ecc.
 | ||
| void TConversione_archivi::convert_caaf_m770() const
 | ||
| {     
 | ||
|   TTable tab("%CAF");
 | ||
|   TString old_cod;
 | ||
|   TString new_cod; 
 | ||
|   int err;      
 | ||
|   
 | ||
|   for (err = tab.first(); err == NOERR; err = tab.next())
 | ||
|   {
 | ||
|     old_cod = tab.get("CODTAB");
 | ||
|     if (old_cod.len() < 5)
 | ||
|     {
 | ||
|       TRectype new_rec(tab.curr());
 | ||
|       new_cod.format("%05ld",atol(old_cod));  
 | ||
|       new_rec.put("CODTAB", new_cod);  
 | ||
|       tab.write(new_rec);
 | ||
|       tab.remove();
 | ||
|     }
 | ||
|   }
 | ||
| }   
 | ||
| 
 | ||
| 
 | ||
| // conversione del numero progressivo banca 
 | ||
| // per renderlo senmpre zerofilled
 | ||
| void TConversione_archivi::convert_rver_m770() const
 | ||
| {     
 | ||
|   TLocalisamfile lf(LF_RVER);
 | ||
|   long progr_banca; 
 | ||
|   int err;      
 | ||
|   
 | ||
|   for (err = lf.first(); err == NOERR; err = lf.next())
 | ||
|   {
 | ||
|     progr_banca = lf.get_long("PROGBANC");  
 | ||
|     lf.put("PROGBANC", progr_banca);  
 | ||
|     lf.rewrite();
 | ||
|   }
 | ||
| }   
 | ||
| 
 | ||
| 
 | ||
| void TConversione_archivi::remove_dta_ndx() const
 | ||
| {
 | ||
|   TFilename s;
 | ||
|   TString_array list;
 | ||
|   
 | ||
|   for (int j = 0; j < 2; j++)
 | ||
|   {
 | ||
|     s = firm2dir(_codditta);
 | ||
|     s.add(j == 0 ? "*.dta" : "*.ndx");
 | ||
|     const int items = list_files(s, list);
 | ||
|     for (int i = items-1; i >= 0; i--)
 | ||
|       ::remove(list.row(i));
 | ||
|     list.destroy();  
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| void TConversione_archivi::convert_forms() const
 | ||
| // Converte i profili, aggiungendo il valore dell'offset verticale. Solo
 | ||
| // per i forms != PEC
 | ||
| {
 | ||
|   TLocalisamfile rform(LF_RFORM),form(LF_FORM);
 | ||
|   TString nome,nomeprec,cod,codprec;
 | ||
|   int y,ipy;
 | ||
|   TProgind p(5,"Conversione profili in corso...",FALSE,FALSE);
 | ||
|   for (form.first();form.good();form.next())
 | ||
|   {
 | ||
|     nome = form.get("TIPOPROF");
 | ||
|     cod = form.get("CODPROF");
 | ||
|     ipy = form.get_int("IPY");
 | ||
|     if (nome == "PEC" || ipy == 0) continue;
 | ||
|     rform.put("TIPOPROF",nome);
 | ||
|     rform.put("CODPROF",cod);
 | ||
|     for (rform.read(_isgteq);rform.good();rform.next())
 | ||
|     {
 | ||
|       nomeprec = rform.get("TIPOPROF");
 | ||
|       codprec = rform.get("CODPROF");
 | ||
|       if (nomeprec != nome || codprec != cod) break;
 | ||
|       y = rform.get_int("Y");
 | ||
|       if (y > 0)
 | ||
|       {
 | ||
|         y += ipy;
 | ||
|         rform.put("Y",y);
 | ||
|         rform.rewrite();
 | ||
|       }
 | ||
|     }
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| void TConversione_archivi::sort_sal(int year) const
 | ||
| {
 | ||
|   TSystemisamfile saldi(LF_SALDI);  saldi.open(_excllock);
 | ||
|   TLocalisamfile rmov(LF_RMOV);
 | ||
|   TLocalisamfile causali(LF_CAUSALI);
 | ||
|   TLocalisamfile mov(LF_MOV);
 | ||
|   TSaldo_agg sal;
 | ||
| 
 | ||
|   int gruppo, conto;
 | ||
|   long oldnumreg = 0L, sottoconto;
 | ||
|   TString msg("Riordino archivio saldi ditta ");
 | ||
|   msg << _codditta;
 | ||
|   msg << " in corso\nLettura archivio movimenti..."; 
 | ||
|   TProgind prnd(rmov.items(),msg, FALSE,TRUE,30);
 | ||
| 
 | ||
|   causali.zero();
 | ||
|   mov.setkey(1);
 | ||
|   rmov.first(); 
 | ||
|   sal.reset();
 | ||
|   sal.set_anno_es(year);
 | ||
|   sal.clear_saldi(year);
 | ||
|   long numreg = 0L;
 | ||
|   tiposal tsal = normale;
 | ||
|   bool provvis = FALSE;
 | ||
|   TDate datareg;
 | ||
|   
 | ||
|   while (!rmov.eof())
 | ||
|   {
 | ||
|     if (year == rmov.get_int(RMV_ANNOES))
 | ||
|     {
 | ||
|       numreg = rmov.get_long(RMV_NUMREG);
 | ||
|       
 | ||
|       gruppo = rmov.get_int(RMV_GRUPPO);
 | ||
|       conto = rmov.get_int(RMV_CONTO);
 | ||
|       sottoconto = rmov.get_long(RMV_SOTTOCONTO);                     
 | ||
|       bool scaricato = FALSE;
 | ||
|       
 | ||
|       if (numreg != oldnumreg)
 | ||
|       {
 | ||
|         if (oldnumreg !=0)
 | ||
|         {
 | ||
|           if (sal.items() > 0)
 | ||
|             sal.registra();
 | ||
|         }
 | ||
|         oldnumreg = numreg;
 | ||
|         mov.zero();
 | ||
|         mov.put(MOV_NUMREG, numreg);
 | ||
|         mov.read();
 | ||
|         CHECK(mov.good(),"Archivi movimenti e righe inconsistenti");
 | ||
| 
 | ||
|         causali.zero();
 | ||
|         const char* codcaus = mov.get(MOV_CODCAUS); 
 | ||
|         
 | ||
|         tsal = normale;
 | ||
|         if (*codcaus)   // cerca causale per determinare il tipoo del saldo
 | ||
|         {
 | ||
|           causali.put(CAU_CODCAUS, codcaus);
 | ||
|           const int err = causali.read();
 | ||
|           if (err == NOERR)
 | ||
|           {
 | ||
|             const char ac = causali.get_char(CAU_MOVAP);
 | ||
|             if (ac == 'A') 
 | ||
|               tsal = apertura;
 | ||
|             else 
 | ||
|               if (ac == 'C') 
 | ||
|                 tsal = chiusura;
 | ||
|           }  
 | ||
|         }
 | ||
| 
 | ||
|         scaricato = mov.get_bool(MOV_SCARCON);
 | ||
|         provvis   = mov.get(MOV_PROVVIS).not_empty();
 | ||
|         datareg   = mov.get_date(MOV_DATAREG);
 | ||
| 
 | ||
|         sal.reset();
 | ||
|         sal.set_anno_es(year);
 | ||
|         sal.set_tipo_saldo(tsal);
 | ||
|         sal.set_movprovv(provvis);
 | ||
|         sal.set_data_ulmov(datareg);
 | ||
|         sal.set_num_ulmov(oldnumreg);
 | ||
|       }
 | ||
|       const char sezione = rmov.get(RMV_SEZIONE)[0];
 | ||
|       real importo(rmov.get(RMV_IMPORTO));
 | ||
| 
 | ||
|       sal.aggiorna(gruppo, conto, sottoconto, importo, sezione, TRUE, scaricato);
 | ||
|     }
 | ||
|     rmov.next();
 | ||
|     prnd.addstatus(1);
 | ||
|     do_events();
 | ||
|   }
 | ||
| 
 | ||
|   if (sal.items() > 0)
 | ||
|     sal.registra();
 | ||
| 
 | ||
|   saldi.close();
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| void TConversione_archivi::convert_saldi() const
 | ||
| // Effettua il ricalcolo saldi per tutti gli esercizi della ditta corrente
 | ||
| {
 | ||
|   TTable esc("ESC");
 | ||
|   for (esc.first();esc.good();esc.next())
 | ||
|   {
 | ||
|     const int year = atoi(esc.get("CODTAB"));
 | ||
|     if (year == 0) continue;
 | ||
|       sort_sal(year);
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| // Effettua conversioni per tabella uffici centro servizi
 | ||
| void TConversione_archivi::convert_ucs() const
 | ||
| {
 | ||
|   // Carica i Centri Servizi da modificare
 | ||
|   TFilename fn;
 | ||
|   fn.format("%sstd/tbucs00.txt", __ptprf);
 | ||
|   if (fexist(fn))
 | ||
|   {
 | ||
|     TScanner c(fn);
 | ||
|     TToken_string t;
 | ||
|     TTable ucs("%UCS");
 | ||
|   
 | ||
|     for (t = c.line(); t.not_empty(); t = c.line())
 | ||
|     {
 | ||
|       ucs.put("CODTAB",t.get(0));
 | ||
|       if (ucs.read() == NOERR)
 | ||
|         if (ucs.get("S1").empty())
 | ||
|         {
 | ||
|           ucs.put("S1",t.get(1));
 | ||
|           ucs.put("S3",t.get(2));
 | ||
|           ucs.put("S7",t.get(3));
 | ||
|           ucs.put("S6",t.get(4));
 | ||
|           ucs.rewrite();
 | ||
|         }
 | ||
|     }
 | ||
|   }
 | ||
| 
 | ||
|   // Carica il nuovo centro servizi di Cagliari
 | ||
|   fn.format("%sstd/tbucs01.txt", __ptprf);
 | ||
|   if (fexist(fn))
 | ||
|   {
 | ||
|     TSystemisamfile tabcom(LF_TABCOM);
 | ||
|     tabcom.load(fn); 
 | ||
|     // Scorre tutti i comuni della provincia di Cagliari e gli cambia il codice Ufficio Centro Servizi
 | ||
|     TRelation com_rel(LF_COMUNI);
 | ||
|     TCursor cur(&com_rel,"PROVCOM==\"CA\"");
 | ||
|     TRectype& rec = cur.curr();
 | ||
|     const long items = cur.items();
 | ||
|     TProgind p(items,"Conversione comuni in provincia di Cagliari",FALSE,TRUE);
 | ||
|     for (long i = 0; i<items; i++)
 | ||
|     {
 | ||
|       p.addstatus(1L);
 | ||
|       cur = i;
 | ||
|       rec.put("UFFCSERV","104");
 | ||
|       cur.file().rewrite();
 | ||
|     }
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| // Effettua conversioni per uffici concessioni
 | ||
| void TConversione_archivi::convert_ucc() const
 | ||
| {
 | ||
|   // Carica le nuove descrizioni per gli Uffici Concessioni
 | ||
|   TFilename fn;
 | ||
|   fn.format("%sstd/tbucc00.txt", __ptprf);
 | ||
|   if (fexist(fn))
 | ||
|   {
 | ||
|     TScanner c(fn);
 | ||
|     TToken_string t;
 | ||
|     TTable ucc("%UCC");
 | ||
|     TProgind p(1,"Conversione tabella Uffici Concessioni",FALSE,FALSE);
 | ||
|     
 | ||
|     for (t = c.line(); t.not_empty(); t = c.line())
 | ||
|     {
 | ||
|       ucc.put("CODTAB",t.get(0));
 | ||
|       if (ucc.read() == NOERR)
 | ||
|       {
 | ||
|         ucc.put("S2",t.get(1));
 | ||
|         ucc.rewrite();
 | ||
|       }
 | ||
|     }
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| // Effettua conversioni per uffici unici
 | ||
| void TConversione_archivi::convert_uue() const
 | ||
| { 
 | ||
|   TProgind pi(0, "Caricamento tabella Uffici Unici", FALSE, FALSE);
 | ||
|   TSystemisamfile uue(LF_TABCOM);
 | ||
|   TFilename lf; 
 | ||
|   lf = __ptprf; 
 | ||
|   lf.add("std/bacnv16a.txt");
 | ||
|   uue.load(lf);
 | ||
| 
 | ||
|   pi.set_text("Caricamento Uffici Unici nei comuni");
 | ||
|   
 | ||
|   TAssoc_array cod_uue;
 | ||
|   
 | ||
|   TSystemisamfile comuni(LF_COMUNI);
 | ||
|   comuni.open(_excllock);
 | ||
|   
 | ||
|   lf = __ptprf; 
 | ||
|   lf.add("std/bacnv16b.txt");
 | ||
|   TScanner scan16b(lf);
 | ||
|   
 | ||
|   TToken_string line;
 | ||
|   TString16 cod, uff;
 | ||
|   for (line = scan16b.line(); line.not_empty(); line = scan16b.line())
 | ||
|   {
 | ||
|     cod = line.get(0);
 | ||
|     comuni.put("COM", cod);
 | ||
|     int err = comuni.read(_isequal);
 | ||
|     if (err == NOERR)
 | ||
|     { 
 | ||
|       TString16 fieldname, fieldval;
 | ||
|       uff = line.get(1);
 | ||
|       int first_uue = 0;
 | ||
|       for (int uue = 1; uue <= 10; uue++)
 | ||
|       {            
 | ||
|         fieldname = "CODUUE"; fieldname << uue;
 | ||
|         fieldval = comuni.get(fieldname);
 | ||
|         if (first_uue == 0 && atoi(fieldval) == 0)
 | ||
|           first_uue = uue;
 | ||
|         if (fieldval == uff)
 | ||
|         {
 | ||
|           first_uue = 0;
 | ||
|           break;
 | ||
|         }  
 | ||
|       }
 | ||
|       if (first_uue > 0)
 | ||
|       {
 | ||
|         fieldname = "CODUUE"; fieldname << first_uue;
 | ||
|         comuni.put(fieldname, uff);
 | ||
|         err = comuni.rewrite();
 | ||
|       }  
 | ||
|       cod_uue.add(cod, comuni.get("CODUUE1"));
 | ||
|     }
 | ||
|     if (err != NOERR)
 | ||
|       error_box("Impossibile aggiornare l'ufficio unico del comune %s: errore %d", 
 | ||
|                 (const char*)cod, err);  
 | ||
|   }
 | ||
|   comuni.close();
 | ||
|   
 | ||
|   pi.set_text("Caricamento Uffici Unici nelle anagrafiche");
 | ||
|   TSystemisamfile persone(LF_ANAG);                                
 | ||
|   persone.open(_excllock);
 | ||
|   
 | ||
|   for (int err = persone.first(); err == NOERR; err = persone.next())
 | ||
|   {       
 | ||
|     if (persone.get("UFFUUE").empty())
 | ||
|     {
 | ||
|       cod = persone.get("COMRF");
 | ||
|       if (cod.empty())
 | ||
|         cod = persone.get("COMRES");
 | ||
|         
 | ||
|       const TString* uffuue = (const TString*)cod_uue.objptr(cod);  
 | ||
|       if (uffuue)
 | ||
|       {                 
 | ||
|         persone.put("UFFUUE", *uffuue);  
 | ||
|         err = persone.rewrite();
 | ||
|         if (err != NOERR)
 | ||
|           error_box("Impossibile aggiornare l'ufficio unico sulle anagrafiche: errore %d", err);  
 | ||
|       }  
 | ||
|     }  
 | ||
|   }
 | ||
|   persone.close();
 | ||
| }
 | ||
| 
 | ||
| // Effettua conversioni per nuovi cap
 | ||
| void TConversione_archivi::convert_cap() const
 | ||
| {                                     
 | ||
|   if (_codditta != 0)
 | ||
|     return;
 | ||
| 
 | ||
|   TLocalisamfile comuni(LF_COMUNI);
 | ||
|   TFilename lf;
 | ||
|   
 | ||
|   lf.format("%sstd/bacnv16c.txt", __ptprf);
 | ||
| 
 | ||
|   TScanner scan16c(lf);
 | ||
|   TToken_string line;
 | ||
|   TString16 cod, oldcod, newcod;
 | ||
|   
 | ||
|   TAssoc_array cap;
 | ||
|   
 | ||
|   TProgind pi(0, "Aggiornamento CAP sui comuni", FALSE, FALSE);
 | ||
|   for (line = scan16c.line(); line.not_empty(); line = scan16c.line())
 | ||
|   {
 | ||
|     cod = line.get(0);
 | ||
|     oldcod = line.get();
 | ||
|     newcod = line.get();
 | ||
|     
 | ||
|     oldcod.insert(cod, 0);    // La chiave e' comune+cap
 | ||
|     cap.add(oldcod, newcod);
 | ||
|     
 | ||
|     if (_codditta == 0L)
 | ||
|     {
 | ||
|       comuni.put("COM", cod);
 | ||
|       int err = comuni.read(_isequal, _lock);
 | ||
|       if (err == NOERR)
 | ||
|       {
 | ||
|         comuni.put("CAPCOM", newcod);
 | ||
|         err = comuni.rewrite();
 | ||
|       }
 | ||
|       if (err != NOERR)
 | ||
|         error_box("Impossibile aggiornare il cap del comune %s: errore %d", 
 | ||
|                   (const char*)cod, err);  
 | ||
|     }              
 | ||
|   }
 | ||
|   scan16c.close();
 | ||
|   
 | ||
|   TDir dir; 
 | ||
| 
 | ||
|   TString msg;
 | ||
|   TToken_string com_cap(15, ',');
 | ||
|   lf.format("%sstd/bacnv16d.txt", __ptprf);
 | ||
|   TScanner scan16d(lf);
 | ||
|   for (line = scan16d.line(); line.not_empty(); line = scan16d.line())
 | ||
|   {
 | ||
|     const TString16 cod = line.get(0);
 | ||
|     const int logicnum = atoi(cod);
 | ||
|     TLocalisamfile* file = NULL;
 | ||
|     if (logicnum > 0)
 | ||
|       file = new TLocalisamfile(logicnum);
 | ||
|     else
 | ||
|       file = new TTable(cod);
 | ||
|     
 | ||
|     dir.get(file->num(), _nolock, _nordir, _sysdirop);
 | ||
|     const bool good_file = dir.is_com() ^ (_codditta != 0);
 | ||
|     if (!good_file)
 | ||
|     {
 | ||
|       delete file;
 | ||
|       file = NULL;
 | ||
|     }
 | ||
|     
 | ||
|     if (file != NULL)
 | ||
|     {
 | ||
|       msg = "Aggiornamento CAP sul file "; 
 | ||
|       msg << cod;
 | ||
|       pi.set_text(msg);
 | ||
|       
 | ||
|       for (int err = file->first(); err == NOERR; err = file->next())  
 | ||
|       {
 | ||
|         bool dirty = FALSE;
 | ||
|         for (com_cap = line.get(1); com_cap.not_empty(); com_cap = line.get())
 | ||
|         {
 | ||
|           oldcod = file->get(com_cap.get(0));
 | ||
|           const TString16 cap_field = com_cap.get();
 | ||
|           oldcod << file->get(cap_field);
 | ||
|           TString* newcod = (TString*)cap.objptr(oldcod);
 | ||
|           if (newcod)
 | ||
|           {
 | ||
|             file->put(cap_field, *newcod);
 | ||
|             dirty = TRUE;
 | ||
|           }
 | ||
|         } 
 | ||
|         if (dirty)
 | ||
|         {
 | ||
|           int err = file->rewrite();
 | ||
|           if (err != NOERR)
 | ||
|             error_box("Errore di aggiornamento %d", err);
 | ||
|         }    
 | ||
|       }
 | ||
|       delete file;  
 | ||
|     }  
 | ||
|   }
 | ||
|   scan16d.close();
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| // Effettua copia dei PIM in PRM, come richiesto dalla PRASSI
 | ||
| void TConversione_archivi::convert_pim2prm() const
 | ||
| {
 | ||
|   TTable pim("PIM");
 | ||
|   TTable prm("PRM");
 | ||
|   TString anno;
 | ||
| 
 | ||
|   TProgind pi(0, "Copia progressi IVA / progressivi Registri...", FALSE, FALSE);
 | ||
|   for (pim.first(); !pim.eof(); pim.next())
 | ||
|   {
 | ||
|     anno = pim.get("CODTAB").mid(0,4);
 | ||
|     if (atoi(anno) > 1997)
 | ||
|     {
 | ||
|       prm.curr() = pim.curr();
 | ||
|       prm.put("COD", "PRM");
 | ||
|       prm.write(); // Ignora eventuali errori, li scrive solo se non ci sono
 | ||
|     }
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| // Aggiunge il tipo cliente C alle ricevute bancarie
 | ||
| void TConversione_archivi::convert_riba_tcf() const
 | ||
| {
 | ||
|   TLocalisamfile f(LF_EFFETTI);
 | ||
|   TRectype& r = f.curr();     
 | ||
|   long n = f.items();
 | ||
|   TProgind p(n, format("Conversione effetti ditta %ld", get_firm()), FALSE, TRUE, 70);
 | ||
|   p.setstatus(1L);
 | ||
|   for (int err = f.first(); err == NOERR; err = f.next())
 | ||
|   {
 | ||
|     p.addstatus(1L);
 | ||
|     if (r.get("TIPOCF").blank())
 | ||
|     {
 | ||
|       r.put("TIPOCF","C");     
 | ||
|       f.rewrite();
 | ||
|     }   
 | ||
|   }  
 | ||
| }
 | ||
| 
 | ||
| /////////////////////////////////////////////////////////////
 | ||
| // Effettua copia dei CDC in CMS (commesse)
 | ||
| ////////////////////////////////////////////////////////////
 | ||
| void TConversione_archivi::convert_cdc2cms() const
 | ||
| { 
 | ||
|   TRelation rel(LF_TAB);
 | ||
|   TRectype& curr = rel.curr();
 | ||
|   curr.put("COD", "CDC");
 | ||
|   TCursor cursore(&rel, "", 1, &curr, &curr);
 | ||
|   const long items = cursore.items();
 | ||
|   cursore.freeze();
 | ||
| 
 | ||
|   TProgind pi(items, "Conversione tabella da Centri di costo a Commesse...", FALSE, TRUE);
 | ||
|   for (cursore=0; cursore.pos()<items; ++cursore)
 | ||
|   { 
 | ||
|     pi.addstatus(1);
 | ||
|     TString80 codcms = curr.get("CODTAB");
 | ||
|     codcms.lpad(20,'0');
 | ||
|     curr.put("COD", "CMS");
 | ||
|     curr.put("CODTAB",codcms);
 | ||
|     cursore.file().write();
 | ||
|   }                   
 | ||
| }
 | ||
| 
 | ||
| ////////////////////////////////////////////////////////////////////////////
 | ||
| // Effettua copia dei mov in movCMS (commesse)
 | ||
| //Copia il contenuto del campo NUMGIO nel campo CODCMS del file LF_RMOV
 | ||
| ///////////////////////////////////////////////////////////////////////////
 | ||
| void TConversione_archivi::convert_mov2movcms() const
 | ||
| { 
 | ||
|   TRelation rel(LF_RMOV);
 | ||
|   TRectype& curr = rel.curr();
 | ||
|   TCursor cursore(&rel);
 | ||
|   const long items = cursore.items();
 | ||
|   cursore.freeze();
 | ||
| 
 | ||
|   TProgind pi(items, "Conversione movimenti con centro di costo...", FALSE, TRUE);
 | ||
|   
 | ||
|   TString80 str;
 | ||
|   for (cursore=0; cursore.pos()<items; ++cursore)
 | ||
|   { 
 | ||
|     pi.addstatus(1);
 | ||
|     if (curr.get("CODCMS").empty())
 | ||
|     {                                      
 | ||
|       const long numgio = curr.get_long("NUMGIO");
 | ||
|       if (numgio > 0)
 | ||
|       { 
 | ||
|         str.format("%020ld",numgio);
 | ||
|         curr.put("CODCMS", str);
 | ||
|         cursore.file().rewrite();
 | ||
|       }
 | ||
|     }
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| ////////////////////////////////////////////////////////////////
 | ||
| // Effettua conversione campi S1 S2 S3 della tabella comune CA7
 | ||
| ////////////////////////////////////////////////////////////////
 | ||
| void TConversione_archivi::convert_ca7() const
 | ||
| { 
 | ||
|   TRelation rel(LF_TABCOM);
 | ||
|   TRectype& curr = rel.curr();
 | ||
|   curr.put("COD", "CA7");
 | ||
|   TCursor cursore(&rel, "", 1, &curr, &curr);
 | ||
|   const long items = cursore.items();
 | ||
|   cursore.freeze();
 | ||
| 
 | ||
|   TProgind pi(items, "Conversione causali mod.770...", FALSE, TRUE);
 | ||
|   for (cursore=0; cursore.pos()<items; ++cursore)
 | ||
|   { 
 | ||
|     pi.addstatus(1);
 | ||
|     const TString& cods1 = curr.get("S1");
 | ||
|     if (cods1 == "SC" || cods1 == "SE")
 | ||
|     {
 | ||
|       change_ca7(curr);
 | ||
|       curr.put("S1", "LA");
 | ||
|       cursore.file().rewrite();
 | ||
|     }
 | ||
|   }                   
 | ||
| }
 | ||
| 
 | ||
| void TConversione_archivi::change_ca7(TRectype& rec) const
 | ||
| {
 | ||
|   const TString& cods1 = rec.get("S1");
 | ||
|   if (cods1 == "SC") 
 | ||
|   {
 | ||
|     const TString olds2 = "AGHIKLMNPQRST";
 | ||
|     const char* news2   = "ABCDEFGHILMNZ";
 | ||
|     int pos2 = olds2.find(rec.get_char("S2"));
 | ||
|     if (pos2 >= 0)
 | ||
|     {
 | ||
|       rec.put("S2", news2[pos2]);
 | ||
|       rec.zero("S3");
 | ||
|     }
 | ||
|   }
 | ||
|   else                           // Ex Causale SE
 | ||
|   {
 | ||
|     const TString olds3 = "ABCDEFGT";
 | ||
|     const char* news3   = "QRSTUVWZ";
 | ||
|     int pos3 = olds3.find(rec.get_char("S3"));
 | ||
|     if (pos3 >= 0)
 | ||
|     {
 | ||
|       rec.put("S2", news3[pos3]);
 | ||
|       rec.zero("S3");
 | ||
|     }
 | ||
|   } 
 | ||
| } 
 | ||
| 
 | ||
| ////////////////////////////////////////////////////////////////
 | ||
| // Effettua conversione campo QLCODQUA del file 42 (QUAL)
 | ||
| ////////////////////////////////////////////////////////////////
 | ||
| void TConversione_archivi::convert_quadst() const
 | ||
| { 
 | ||
|   TRelation rel(LF_QUAL);
 | ||
|   TRectype& curr = rel.curr();
 | ||
|   TCursor cursore(&rel);
 | ||
|   const long items = cursore.items();
 | ||
|   cursore.freeze();
 | ||
| 
 | ||
|   TProgind pi(items, "Conversione riepilogo quadro ST..", FALSE, TRUE);
 | ||
| 
 | ||
|   for (cursore=0; cursore.pos()<items; ++cursore)
 | ||
|   { 
 | ||
|     pi.addstatus(1);                                     
 | ||
|     const TString& riepst = curr.get("QLCODQUA");
 | ||
|     if (riepst == "SC" || riepst == "SE")
 | ||
|     {
 | ||
|       curr.put("QLCODQUA", "LA");
 | ||
|       cursore.file().rewrite();
 | ||
|     }
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| ////////////////////////////////////////////////////////////////
 | ||
| // Effettua conversione campo ALLEG a 6 se il cliente non ha partita IVA
 | ||
| ////////////////////////////////////////////////////////////////
 | ||
| 
 | ||
| void TConversione_archivi::convert_clifo_privati()
 | ||
| { 
 | ||
|   long firm = get_firm();             
 | ||
|   TString pref;
 | ||
| 
 | ||
|   if (firm == 0)
 | ||
| 		pref = prefix().name();
 | ||
|  
 | ||
| 	TLocalisamfile ditte(LF_NDITTE);
 | ||
|   
 | ||
|   for (ditte.first(); !ditte.eof(); ditte.next())
 | ||
|   {
 | ||
|     const long codditta = ditte.get_long("CODDITTA");
 | ||
|     
 | ||
|     if (prefix().exist(codditta))
 | ||
|     {
 | ||
|       set_firm(codditta);
 | ||
| 		  
 | ||
| 			{
 | ||
| 				TRelation rel(LF_CLIFO);
 | ||
| 				TRectype& curr = rel.curr();
 | ||
| 
 | ||
| 				curr.put(CLI_TIPOCF, "C");
 | ||
| 
 | ||
| 				TCursor cursore(&rel, "(PAIV=='')&&(ALLEG!='6')", 1, &curr, &curr);
 | ||
| 			  const long items = cursore.items();
 | ||
| 				cursore.freeze();
 | ||
| 
 | ||
| 				TProgind pi(items, "Conversione clienti privati..", FALSE, TRUE);
 | ||
| 
 | ||
| 				for (cursore=0; cursore.pos()<items; ++cursore)
 | ||
| 			  {
 | ||
| 						pi.addstatus(1);                                     
 | ||
| 						curr.put(CLI_ALLEG, 6);
 | ||
| 						rel.rewrite();
 | ||
| 				}
 | ||
| 			}
 | ||
|     }
 | ||
|   }
 | ||
|   if (firm > 0)
 | ||
| 		set_firm(firm);
 | ||
|   else
 | ||
| 		prefix().set(pref);
 | ||
| }
 | ||
| 
 | ||
| ////////////////////////////////////////////////////////////////
 | ||
| // Effettua conversione campo NUMIVD E NUMIVDOPP sul piano dei conti
 | ||
| ////////////////////////////////////////////////////////////////
 | ||
| 
 | ||
| void TConversione_archivi::convert_pcon_ivd()
 | ||
| { 
 | ||
|   const long firm = get_firm();             
 | ||
|   const TString pref = firm == 0 ? prefix().name() : "";
 | ||
| 
 | ||
|   TPointer_array firms;
 | ||
|   prefix().firms(firms);
 | ||
|  
 | ||
|   TProgind pf(firms.items(), "Conversione Codici IV Direttiva CEE");
 | ||
| 	for (int f = 0; f < firms.items(); f++)
 | ||
|   {
 | ||
|   	if (!pf.addstatus(1))
 | ||
|       break;
 | ||
|     const long codditta = firms.get_long(f);
 | ||
|     if (set_firm(codditta))
 | ||
| 	  {
 | ||
| 			TRelation rel(LF_PCON);
 | ||
| 			TRectype& curr = rel.curr();
 | ||
| 
 | ||
| 			TCursor cursore(&rel);
 | ||
| 		  const long items = cursore.items();
 | ||
| 			cursore.freeze();
 | ||
| 
 | ||
| 			TProgind pi(items, "Scansione piano dei conti");
 | ||
| 			for (cursore=0; cursore.pos()<items; ++cursore)
 | ||
| 		  {
 | ||
| 				if (!pi.addstatus(1))
 | ||
|           break;
 | ||
| 				
 | ||
|         TString8 numivd = curr.get(PCN_NUMIVD);
 | ||
| 				bool rew = false;
 | ||
| 				if (numivd.len() == 1)
 | ||
| 				{
 | ||
| 					numivd.insert("0");
 | ||
| 					curr.put(PCN_NUMIVD, numivd);
 | ||
| 					rew = true;
 | ||
| 				}
 | ||
| 
 | ||
| 				TString8 numivdopp = curr.get(PCN_NUMIVDOPP);
 | ||
| 				if (numivdopp.len() == 1)
 | ||
| 				{
 | ||
| 					numivdopp.insert("0");
 | ||
| 					curr.put(PCN_NUMIVDOPP, numivdopp);
 | ||
| 					rew = true;
 | ||
| 				}
 | ||
| 				if (rew)
 | ||
| 					rel.rewrite();
 | ||
| 			}
 | ||
|     }
 | ||
|   }
 | ||
|   if (firm > 0)
 | ||
| 		set_firm(firm);
 | ||
|   else
 | ||
| 		prefix().set(pref);
 | ||
| }
 | ||
| 
 | ||
| bool TConversione_archivi::backup_text_file(TFilename& name, TLog_report& log) const
 | ||
| {
 | ||
|   TString msg;
 | ||
|   msg << TR("Elaborazione ") << name;
 | ||
|   log.log(0, "");
 | ||
|   log.log(0, msg);
 | ||
| 
 | ||
|   if (!name.custom_path())
 | ||
|   {
 | ||
|     log.log_error(TR("Il file non esiste!"));
 | ||
|     return false;
 | ||
|   }
 | ||
|   name.lower();
 | ||
|   if (name.find("custom") < 0)
 | ||
|   {
 | ||
|     log.log_error(TR("Il file non e' in una cartella custom!"));
 | ||
|     return false;
 | ||
|   }
 | ||
| 
 | ||
|   TFilename bakname(name);
 | ||
|   bakname << ".bak";
 | ||
|   if (!bakname.exist())
 | ||
|   {
 | ||
|     msg.cut(0) << TR("Copia ") << name << TR(" in ") << bakname;
 | ||
|     log.log(0, msg);
 | ||
|     fcopy(name, bakname);
 | ||
|   }
 | ||
| 
 | ||
|   return true;
 | ||
| }
 | ||
| 
 | ||
| bool TConversione_archivi::rinumera_paragrafo(const TFilename& ininame, const char*paragrafo, 
 | ||
|                                               const char* contatore, const char* variabile,
 | ||
|                                               TLog_report& log) const
 | ||
| {
 | ||
|   TConfig p(ininame, paragrafo);
 | ||
|   
 | ||
|   TString val = p.get( contatore, paragrafo );
 | ||
|   if (val == "*")
 | ||
|     return true; // Lascia stare tutto!
 | ||
|   
 | ||
|   const int ncols = atoi(val);
 | ||
|   const bool ok = p.remove(contatore) || ncols <= 0;
 | ||
|   if (!ok)
 | ||
|   {
 | ||
|     log.log(1, TR("Il file risulta essere gia' stato convertito"));
 | ||
|     return ok;
 | ||
|   }
 | ||
| 
 | ||
|   val = TR("Conversione paragrafo");
 | ||
|   val << " [" << paragrafo << ']';
 | ||
|   log.log(0, val);
 | ||
| 
 | ||
|   TString4 str;
 | ||
|   for (int i = 1; i <= ncols; i++)
 | ||
|   {
 | ||
|     str.format("%d", i);
 | ||
|     val = p.get(str);
 | ||
|     p.remove(str);
 | ||
|     p.set(variabile, val, NULL, true, i - 1);
 | ||
|   }
 | ||
| 
 | ||
|   return ok;
 | ||
| }
 | ||
| 
 | ||
| bool TConversione_archivi::rinumera_maschera(const TFilename& mskname, TLog_report& log) const
 | ||
| {
 | ||
|   TFilename temp; temp.temp("msk");
 | ||
|   if (mskname.exist()) // Dummy test
 | ||
|   {
 | ||
|     TString msg;
 | ||
|   
 | ||
|     TScanner scan(mskname);
 | ||
|     ofstream output(temp);
 | ||
| 
 | ||
|     if (mskname.find("verig") >= 0) // Maschera di riga
 | ||
|     {
 | ||
|       bool killing = false;
 | ||
|       while (!scan.eof())
 | ||
|       {
 | ||
|         TString& line = scan.line();
 | ||
|         if (!killing)
 | ||
|         {    
 | ||
|           // Controllo per ammazzare i campi delle vecchie commesse 140,141,260,261
 | ||
|           if (line.match("?? 14[0,1] [1,2]0*") || line.match("?? 26[0,1] *"))
 | ||
|           {
 | ||
|             msg.cut(0) << TR("Eliminazione campo ") << line;
 | ||
|             log.log(1, msg);
 | ||
|             killing = true; // Comincio a saltar righe fino ad EN
 | ||
|           }
 | ||
|           else
 | ||
|           {
 | ||
|             // Controllo se devo rinumerare i vecchi CODAGG da 142,143 a 152,153
 | ||
|             if (line.match("?? 14[2,3] *"))  // ST 142 12  ->  ST 152 12
 | ||
|             {
 | ||
|               msg.cut(0) << TR("Rinumerazione campo ") << line;
 | ||
|               log.log(1, msg);
 | ||
|               line.overwrite("5", 4); 
 | ||
|             } else 
 | ||
|             if (line.match("IN * 14[2,3]"))  // IN CODART 142  ->  IN CODART 152
 | ||
|             {
 | ||
|               msg.cut(0) << TR("Rinumerazione campo ") << line;
 | ||
|               log.log(1, msg);
 | ||
|               line.overwrite("5", line.len()-2);
 | ||
|             } else
 | ||
|             if (line.match("ST 102 *"))
 | ||
|             {
 | ||
|               msg.cut(0) << TR("Trasformazione campo ") << line;
 | ||
|               log.log(1, msg);
 | ||
|               line = "LI 102 2 50\nBE\nPR 2 2 \"Tipo riga   \"\nFI TIPORIGA\nEN";
 | ||
|               killing = true;  // Elimina contenuto vecchio campo tipo riga
 | ||
|             }
 | ||
|             output << line << endl;
 | ||
|           }
 | ||
|         }
 | ||
|         else
 | ||
|         {
 | ||
|           // Finisco di ammazzare quando raggiungo il token EN
 | ||
|           if (line == "EN")
 | ||
|             killing = false;
 | ||
|         }
 | ||
|       }
 | ||
|     }
 | ||
|     else                        // Maschera di testa
 | ||
|     {
 | ||
|       bool killing = false;
 | ||
|       bool toolbar = false;
 | ||
|       while (!scan.eof())
 | ||
|       {
 | ||
|         TString& line = scan.line();
 | ||
|         if (!killing)
 | ||
|         {    
 | ||
|           // Controllo per ammazzare i campi delle vecchie commesse 188,189,190,191
 | ||
|           if (line.match("?? 18[8,9] *") || line.match("?? 19[0,1] *"))
 | ||
|           {
 | ||
|             msg.cut(0) << TR("Eliminazione campo ") << line;
 | ||
|             log.log(1, msg);
 | ||
|             killing = true; // Comincio a saltar righe fino ad EN
 | ||
|           } else
 | ||
|          if (!toolbar && line.match("TOOLBAR \"*\" *")) // Vecchia toolbar
 | ||
|          {
 | ||
|            toolbar = true;
 | ||
|            log.log(1, TR("Conversione TOOLBAR principale"));
 | ||
|            output << "TOOLBAR \"toolbar\" 0 0 2 0" << endl;  // nuova toolbar
 | ||
|          }
 | ||
|          else
 | ||
|            output << line << endl; // Lascia stare la riga cosi' com'e'
 | ||
|         }
 | ||
|         else
 | ||
|         {
 | ||
|           // Finisco di ammazzare quando raggiungo il token EN
 | ||
|           if (line == "EN")
 | ||
|             killing = false;
 | ||
|         }
 | ||
|       }
 | ||
|     }
 | ||
|   }
 | ||
|   fcopy(temp, mskname);
 | ||
|   temp.fremove();
 | ||
|   return true;
 | ||
| }
 | ||
| 
 | ||
| bool TConversione_archivi::to_be_converted(TFilename& name) const
 | ||
| {
 | ||
|   if (!name.custom_path())     // Non esiste
 | ||
|     return false;
 | ||
|   name.lower();
 | ||
|   if (name.find("custom") < 0) // Non e' in "CUSTOM"
 | ||
|     return false;
 | ||
| 
 | ||
|   if (name.ends_with(".ini"))
 | ||
|   {
 | ||
|     TFilename msk = name.name();
 | ||
|     msk.ext("msk");
 | ||
|     return msk.custom_path(); // Converto un .ini solo se esiste un .msk omonimo
 | ||
|   } else
 | ||
|   if (name.ends_with(".msk"))
 | ||
|   {
 | ||
|     TFilename ini = name.name();
 | ||
|     ini.ext("ini");
 | ||
|     return ini.custom_path(); // Converto un .msk solo se esiste un .ini omonimo
 | ||
|   }
 | ||
|   return false;
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| void TConversione_archivi::convert_profile(const char* profile_name)
 | ||
| { 
 | ||
|   TArray_sheet elenco(-1, -1, -4, -6, 
 | ||
|                       TR("Profili documento da convertire"), HR("@1|Profilo@60"), 0x08);
 | ||
| 
 | ||
|   TFilename name;
 | ||
|   TToken_string row;
 | ||
|   
 | ||
|   if (profile_name && *profile_name)
 | ||
|   {
 | ||
|     name = profile_name;
 | ||
|     name.ext("ini");
 | ||
|     if (to_be_converted(name))
 | ||
|     {
 | ||
|       row = "X";  // preselezionato!
 | ||
|       row.add(name);
 | ||
|       elenco.add(row);
 | ||
|     }
 | ||
|     name = profile_name;
 | ||
|     name.ext("msk");
 | ||
|     if (to_be_converted(name))
 | ||
|     {
 | ||
|       row = "X";  // preselezionato!
 | ||
|       row.add(name);
 | ||
|       elenco.add(row);
 | ||
|     }
 | ||
|   }
 | ||
| 
 | ||
|   if (elenco.items() == 0) // Nessun nome valido specificato sulla riga di comando
 | ||
|   {
 | ||
|     name = prefix().get_studio();
 | ||
|     name.add("custom");
 | ||
|     name.add("*.*");
 | ||
|     TString_array files; list_files(name, files);
 | ||
|     FOR_EACH_ARRAY_ROW(files, i, f) 
 | ||
|     {
 | ||
|       name = *f;
 | ||
|       if (to_be_converted(name))
 | ||
|       {
 | ||
|         row = "X";  // preselezionato
 | ||
|         row.add(*f);
 | ||
|         elenco.add(row);
 | ||
|       }
 | ||
|     }
 | ||
|   }
 | ||
| 
 | ||
|   if (elenco.run() == K_ENTER && elenco.one_checked())
 | ||
|   {
 | ||
|     TLog_report log(TR("Conversione maschere documenti"));
 | ||
|     for (int r = 0; r < elenco.items(); r++) if (elenco.checked(r))
 | ||
|     {
 | ||
|       name = elenco.row(r).get(1);
 | ||
|       if (backup_text_file(name, log))
 | ||
|       {
 | ||
|         if (name.ends_with(".ini"))
 | ||
|         {
 | ||
|           const bool ok = rinumera_paragrafo(name, "SHEET", "NCOLS", "Col", log);
 | ||
|           if (!ok)
 | ||
|             continue; // Gia' elaborato!
 | ||
|           rinumera_paragrafo(name, "RIGHE", "NTIPIRIGA", "Tipo", log);
 | ||
|           rinumera_paragrafo(name, "HANDLERS", "NHANDLER", "Handler", log);
 | ||
|           rinumera_paragrafo(name, "DEFAULT", "NDEFAULTS", "Default", log);
 | ||
|         } 
 | ||
|         else
 | ||
|           rinumera_maschera(name, log);
 | ||
|       }
 | ||
|     }
 | ||
|     log.preview();
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| //////////////////////////////////////////////////////////////////////////////
 | ||
| // Converte le righe documento e anamag in modo da riassegnare i campi CONAI
 | ||
| //////////////////////////////////////////////////////////////////////////////
 | ||
| void TConversione_archivi::convert_conai_anamag()
 | ||
| {
 | ||
|   TConfig ditta(CONFIG_DITTA, "ve");
 | ||
|   TString_array conai_default_vals;
 | ||
|   const char* conai_default_names[CONAI_CLASSES] = {"CONAI_DEFAULT_ACC", "CONAI_DEFAULT_ALL", "CONAI_DEFAULT_CAR", 
 | ||
|                                                     "CONAI_DEFAULT_LEG", "CONAI_DEFAULT_PLA", "CONAI_DEFAULT_VET"};
 | ||
|   const char* conai_default_values[CONAI_CLASSES] = {"AC99", "AL99", "CA40", "LE99", "PL12", "VE99"};
 | ||
| 
 | ||
|   FOR_EACH_CONAI_CLASS(cc)
 | ||
|   {
 | ||
|     const TString& conai_cat = ditta.get(conai_default_names[cc], NULL, -1, conai_default_values[cc]);
 | ||
|     conai_default_vals.add(conai_cat);
 | ||
|   }
 | ||
| 
 | ||
|   //prende solo le righe che hanno un peso conai di carta e/o plastica
 | ||
|   TISAM_recordset anamag("USE ANAMAG\nSELECT (CONCAR>0)||(CONPLA>0)\n");
 | ||
|   const long anamag_items = anamag.items();
 | ||
| 
 | ||
|   TProgind pi(anamag_items, "Gestione anagrafica articoli...", false);
 | ||
|   for (bool ok = anamag.move_first(); ok; ok = anamag.move_next())
 | ||
|   {
 | ||
|     if (!pi.addstatus(1))
 | ||
|       break;
 | ||
| 
 | ||
|     //prende i pesi conai su ciascuna riga
 | ||
|     FOR_EACH_CONAI_CLASS(cc)
 | ||
|     {
 | ||
|       const char* peso_name = conai_peso_name(cc, LF_ANAMAG);
 | ||
|       const real peso = anamag.get(peso_name).as_real();
 | ||
|       //se peso conai > 0, deve scrivere il codice conai nel campo CONAISC
 | ||
|       if (peso > ZERO)
 | ||
|       {
 | ||
|         const char* sottocat = conai_sottocat_name(cc, LF_ANAMAG);
 | ||
|         TFieldref fr(sottocat, LF_ANAMAG);
 | ||
|         fr.write(conai_default_vals.row(cc), anamag.cursor()->curr());
 | ||
|       }
 | ||
|     }
 | ||
|     anamag.cursor()->relation()->rewrite();
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| void TConversione_archivi::convert_conai_rdoc()
 | ||
| {
 | ||
|   //deve considerare tutte le righe documento che abbiano almeno uno tra codagg1 e codagg2 compilato
 | ||
|   TString query;
 | ||
|   query << "USE RDOC\n";
 | ||
|   query << "SELECT (BETWEEN(CODAGG1,\"AC\",\"VE\"))||(BETWEEN(CODAGG2,\"AC01\",\"VE99\"))";
 | ||
|   TISAM_recordset righedoc(query);
 | ||
|   const long righedoc_items = righedoc.items();
 | ||
| 
 | ||
|   TProgind pi(righedoc_items, "Ricostruzione righe documento...", false);
 | ||
| 
 | ||
|   //ci vuole un TVariable_rectype perch<63> il TRectype non ha campi virtuali!
 | ||
|   TVariable_rectype rdoc(LF_RIGHEDOC);
 | ||
|   rdoc.set_memo_fld(RDOC_RG1);
 | ||
|   for (bool ok = righedoc.move_first(); ok; ok = righedoc.move_next())
 | ||
|   {
 | ||
|     //deve prendere dalla riga il valore di codagg2 e confrontarlo con una delle nuove sottocategorie conai
 | ||
|     if (!pi.addstatus(1))
 | ||
|       break;
 | ||
|     rdoc = righedoc.cursor()->curr();
 | ||
|     TString4 codagg2 = rdoc.get(RDOC_CODAGG2);
 | ||
|     TString4 codagg1 = rdoc.get(RDOC_CODAGG1);
 | ||
|     //se codagg2 non <20> 4 caratteri o <20> cazzato (<4) oppure non c'entra un cavolo (>4); quindi deve considerare..
 | ||
|     //..codagg1; se codagg1 <20> lungo 2 va bene lui
 | ||
|     if (codagg2.len() < 4 && codagg1.len() == 2)
 | ||
|     {
 | ||
|       codagg2 = codagg1;
 | ||
|       codagg2 << "99";
 | ||
|     }
 | ||
|     //per prima cosa sistema i codici categoria
 | ||
|     //quale <20> la classe conai? (plastica,carta,vetro,ecc.??)
 | ||
|     const TCONAI_class cc = conai_str2class(codagg2);
 | ||
|     //come si chiama il campo virtuale su rdoc in cui anr<6E> inserito il codice categoria?
 | ||
|     const char* csn = conai_sottocat_name(cc);
 | ||
|     //noto il campo di destinazione ci mette il codice corretto
 | ||
|     rdoc.put(csn, codagg2);
 | ||
|     rdoc.zero(RDOC_CODAGG1);
 | ||
|     rdoc.zero(RDOC_CODAGG2);
 | ||
| 
 | ||
|     //adesso tocca ai pesi conai
 | ||
|     real qtagg1 = rdoc.get_real(RDOC_QTAGG1);
 | ||
|     //la classe <20> sempre quella di prima;il campo virtuale no
 | ||
|     const char* cpn = conai_peso_name(cc);
 | ||
|     //noto il campo di destinazione ci mette il peso conai
 | ||
|     rdoc.put(cpn, qtagg1);
 | ||
|     rdoc.zero(RDOC_QTAGG1);
 | ||
| 
 | ||
|     //scrittura finale del record
 | ||
|     TLocalisamfile f(LF_RIGHEDOC);
 | ||
|     int err = rdoc.rewrite(f);
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| void TConversione_archivi::convert_conai_righe()
 | ||
| {
 | ||
|   //gestione del file anamag
 | ||
|   convert_conai_anamag();
 | ||
|   
 | ||
|   //gestione delle righedoc
 | ||
|   convert_conai_rdoc();
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| // Programma di conversione archivi speciale
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| 
 | ||
| int main(int argc,char** argv)
 | ||
| {
 | ||
|   const int r = (argc > 1) ? abs(atoi(argv[1])) : 0;
 | ||
| 
 | ||
| /*
 | ||
|   if (r==0)
 | ||
|   {
 | ||
|     TConversione_xbase a;
 | ||
|     a.run(argc,argv, TR("Conversione archivi di xBase"));
 | ||
|   }
 | ||
|   else
 | ||
| */
 | ||
|   {
 | ||
|     TConversione_archivi a ;
 | ||
|     a.run(argc, argv, TR("Conversione archivi"));
 | ||
|   }
 | ||
| 
 | ||
|   return 0;
 | ||
| }
 |